at v5.4 64 lines 1.6 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Port on Texas Instruments TMS320C6x architecture 4 * 5 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated 6 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) 7 */ 8#ifndef _ASM_C6X_DELAY_H 9#define _ASM_C6X_DELAY_H 10 11#include <linux/kernel.h> 12 13extern unsigned int ticks_per_ns_scaled; 14 15static inline void __delay(unsigned long loops) 16{ 17 uint32_t tmp; 18 19 /* 6 cycles per loop */ 20 asm volatile (" mv .s1 %0,%1\n" 21 "0: [%1] b .s1 0b\n" 22 " add .l1 -6,%0,%0\n" 23 " cmplt .l1 1,%0,%1\n" 24 " nop 3\n" 25 : "+a"(loops), "=A"(tmp)); 26} 27 28static inline void _c6x_tickdelay(unsigned int x) 29{ 30 uint32_t cnt, endcnt; 31 32 asm volatile (" mvc .s2 TSCL,%0\n" 33 " add .s2x %0,%1,%2\n" 34 " || mvk .l2 1,B0\n" 35 "0: [B0] b .s2 0b\n" 36 " mvc .s2 TSCL,%0\n" 37 " sub .s2 %0,%2,%0\n" 38 " cmpgt .l2 0,%0,B0\n" 39 " nop 2\n" 40 : "=b"(cnt), "+a"(x), "=b"(endcnt) : : "B0"); 41} 42 43/* use scaled math to avoid slow division */ 44#define C6X_NDELAY_SCALE 10 45 46static inline void _ndelay(unsigned int n) 47{ 48 _c6x_tickdelay((ticks_per_ns_scaled * n) >> C6X_NDELAY_SCALE); 49} 50 51static inline void _udelay(unsigned int n) 52{ 53 while (n >= 10) { 54 _ndelay(10000); 55 n -= 10; 56 } 57 while (n-- > 0) 58 _ndelay(1000); 59} 60 61#define udelay(x) _udelay((unsigned int)(x)) 62#define ndelay(x) _ndelay((unsigned int)(x)) 63 64#endif /* _ASM_C6X_DELAY_H */