cti.h 3.6 KB

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