cti.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef __ASMARM_CTI_H
  2. #define __ASMARM_CTI_H
  3. #include <asm/io.h>
  4. /* The registers' definition is from section 3.2 of
  5. * Embedded Cross Trigger Revision: r0p0
  6. */
  7. #define CTICONTROL 0x000
  8. #define CTISTATUS 0x004
  9. #define CTILOCK 0x008
  10. #define CTIPROTECTION 0x00C
  11. #define CTIINTACK 0x010
  12. #define CTIAPPSET 0x014
  13. #define CTIAPPCLEAR 0x018
  14. #define CTIAPPPULSE 0x01c
  15. #define CTIINEN 0x020
  16. #define CTIOUTEN 0x0A0
  17. #define CTITRIGINSTATUS 0x130
  18. #define CTITRIGOUTSTATUS 0x134
  19. #define CTICHINSTATUS 0x138
  20. #define CTICHOUTSTATUS 0x13c
  21. #define CTIPERIPHID0 0xFE0
  22. #define CTIPERIPHID1 0xFE4
  23. #define CTIPERIPHID2 0xFE8
  24. #define CTIPERIPHID3 0xFEC
  25. #define CTIPCELLID0 0xFF0
  26. #define CTIPCELLID1 0xFF4
  27. #define CTIPCELLID2 0xFF8
  28. #define CTIPCELLID3 0xFFC
  29. /* The below are from section 3.6.4 of
  30. * CoreSight v1.0 Architecture Specification
  31. */
  32. #define LOCKACCESS 0xFB0
  33. #define LOCKSTATUS 0xFB4
  34. /* write this value to LOCKACCESS will unlock the module, and
  35. * other value will lock the module
  36. */
  37. #define LOCKCODE 0xC5ACCE55
  38. /**
  39. * struct cti - cross trigger interface struct
  40. * @base: mapped virtual address for the cti base
  41. * @irq: irq number for the cti
  42. * @trig_out_for_irq: triger out number which will cause
  43. * the @irq happen
  44. *
  45. * cti struct used to operate cti registers.
  46. */
  47. struct cti {
  48. void __iomem *base;
  49. int irq;
  50. int trig_out_for_irq;
  51. };
  52. /**
  53. * cti_init - initialize the cti instance
  54. * @cti: cti instance
  55. * @base: mapped virtual address for the cti base
  56. * @irq: irq number for the cti
  57. * @trig_out: triger out number which will cause
  58. * the @irq happen
  59. *
  60. * called by machine code to pass the board dependent
  61. * @base, @irq and @trig_out to cti.
  62. */
  63. static inline void cti_init(struct cti *cti,
  64. void __iomem *base, int irq, int trig_out)
  65. {
  66. cti->base = base;
  67. cti->irq = irq;
  68. cti->trig_out_for_irq = trig_out;
  69. }
  70. /**
  71. * cti_map_trigger - use the @chan to map @trig_in to @trig_out
  72. * @cti: cti instance
  73. * @trig_in: trigger in number
  74. * @trig_out: trigger out number
  75. * @channel: channel number
  76. *
  77. * This function maps one trigger in of @trig_in to one trigger
  78. * out of @trig_out using the channel @chan.
  79. */
  80. static inline void cti_map_trigger(struct cti *cti,
  81. int trig_in, int trig_out, int chan)
  82. {
  83. void __iomem *base = cti->base;
  84. unsigned long val;
  85. val = __raw_readl(base + CTIINEN + trig_in * 4);
  86. val |= BIT(chan);
  87. __raw_writel(val, base + CTIINEN + trig_in * 4);
  88. val = __raw_readl(base + CTIOUTEN + trig_out * 4);
  89. val |= BIT(chan);
  90. __raw_writel(val, base + CTIOUTEN + trig_out * 4);
  91. }
  92. /**
  93. * cti_enable - enable the cti module
  94. * @cti: cti instance
  95. *
  96. * enable the cti module
  97. */
  98. static inline void cti_enable(struct cti *cti)
  99. {
  100. __raw_writel(0x1, cti->base + CTICONTROL);
  101. }
  102. /**
  103. * cti_disable - disable the cti module
  104. * @cti: cti instance
  105. *
  106. * enable the cti module
  107. */
  108. static inline void cti_disable(struct cti *cti)
  109. {
  110. __raw_writel(0, cti->base + CTICONTROL);
  111. }
  112. /**
  113. * cti_irq_ack - clear the cti irq
  114. * @cti: cti instance
  115. *
  116. * clear the cti irq
  117. */
  118. static inline void cti_irq_ack(struct cti *cti)
  119. {
  120. void __iomem *base = cti->base;
  121. unsigned long val;
  122. val = __raw_readl(base + CTIINTACK);
  123. val |= BIT(cti->trig_out_for_irq);
  124. __raw_writel(val, base + CTIINTACK);
  125. }
  126. /**
  127. * cti_unlock - unlock cti module
  128. * @cti: cti instance
  129. *
  130. * unlock the cti module, or else any writes to the cti
  131. * module is not allowed.
  132. */
  133. static inline void cti_unlock(struct cti *cti)
  134. {
  135. void __iomem *base = cti->base;
  136. unsigned long val;
  137. val = __raw_readl(base + LOCKSTATUS);
  138. if (val & 1) {
  139. val = LOCKCODE;
  140. __raw_writel(val, base + LOCKACCESS);
  141. }
  142. }
  143. /**
  144. * cti_lock - lock cti module
  145. * @cti: cti instance
  146. *
  147. * lock the cti module, so any writes to the cti
  148. * module will be not allowed.
  149. */
  150. static inline void cti_lock(struct cti *cti)
  151. {
  152. void __iomem *base = cti->base;
  153. unsigned long val;
  154. val = __raw_readl(base + LOCKSTATUS);
  155. if (!(val & 1)) {
  156. val = ~LOCKCODE;
  157. __raw_writel(val, base + LOCKACCESS);
  158. }
  159. }
  160. #endif