delay.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef _ASM_C6X_DELAY_H
  12. #define _ASM_C6X_DELAY_H
  13. #include <linux/kernel.h>
  14. extern unsigned int ticks_per_ns_scaled;
  15. static inline void __delay(unsigned long loops)
  16. {
  17. uint32_t tmp;
  18. /* 6 cycles per loop */
  19. asm volatile (" mv .s1 %0,%1\n"
  20. "0: [%1] b .s1 0b\n"
  21. " add .l1 -6,%0,%0\n"
  22. " cmplt .l1 1,%0,%1\n"
  23. " nop 3\n"
  24. : "+a"(loops), "=A"(tmp));
  25. }
  26. static inline void _c6x_tickdelay(unsigned int x)
  27. {
  28. uint32_t cnt, endcnt;
  29. asm volatile (" mvc .s2 TSCL,%0\n"
  30. " add .s2x %0,%1,%2\n"
  31. " || mvk .l2 1,B0\n"
  32. "0: [B0] b .s2 0b\n"
  33. " mvc .s2 TSCL,%0\n"
  34. " sub .s2 %0,%2,%0\n"
  35. " cmpgt .l2 0,%0,B0\n"
  36. " nop 2\n"
  37. : "=b"(cnt), "+a"(x), "=b"(endcnt) : : "B0");
  38. }
  39. /* use scaled math to avoid slow division */
  40. #define C6X_NDELAY_SCALE 10
  41. static inline void _ndelay(unsigned int n)
  42. {
  43. _c6x_tickdelay((ticks_per_ns_scaled * n) >> C6X_NDELAY_SCALE);
  44. }
  45. static inline void _udelay(unsigned int n)
  46. {
  47. while (n >= 10) {
  48. _ndelay(10000);
  49. n -= 10;
  50. }
  51. while (n-- > 0)
  52. _ndelay(1000);
  53. }
  54. #define udelay(x) _udelay((unsigned int)(x))
  55. #define ndelay(x) _ndelay((unsigned int)(x))
  56. #endif /* _ASM_C6X_DELAY_H */