cti.h 3.6 KB

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