gpio.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * arch/arm/mach-pnx4008/include/mach/gpio.h
  3. *
  4. * PNX4008 GPIO driver - header file
  5. *
  6. * Author: Dmitry Chigirev <source@mvista.com>
  7. *
  8. * Based on reference code by Iwo Mergler and Z.Tabaaloute from Philips:
  9. * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
  10. *
  11. * 2005 (c) MontaVista Software, Inc. This file is licensed under
  12. * the terms of the GNU General Public License version 2. This program
  13. * is licensed "as is" without any warranty of any kind, whether express
  14. * or implied.
  15. */
  16. #ifndef _PNX4008_GPIO_H_
  17. #define _PNX4008_GPIO_H_
  18. /* Block numbers */
  19. #define GPIO_IN (0)
  20. #define GPIO_OUT (0x100)
  21. #define GPIO_BID (0x200)
  22. #define GPIO_RAM (0x300)
  23. #define GPIO_MUX (0x400)
  24. #define GPIO_TYPE_MASK(K) ((K) & 0x700)
  25. /* INPUT GPIOs */
  26. /* GPI */
  27. #define GPI_00 (GPIO_IN | 0)
  28. #define GPI_01 (GPIO_IN | 1)
  29. #define GPI_02 (GPIO_IN | 2)
  30. #define GPI_03 (GPIO_IN | 3)
  31. #define GPI_04 (GPIO_IN | 4)
  32. #define GPI_05 (GPIO_IN | 5)
  33. #define GPI_06 (GPIO_IN | 6)
  34. #define GPI_07 (GPIO_IN | 7)
  35. #define GPI_08 (GPIO_IN | 8)
  36. #define GPI_09 (GPIO_IN | 9)
  37. #define U1_RX (GPIO_IN | 15)
  38. #define U2_HTCS (GPIO_IN | 16)
  39. #define U2_RX (GPIO_IN | 17)
  40. #define U3_RX (GPIO_IN | 18)
  41. #define U4_RX (GPIO_IN | 19)
  42. #define U5_RX (GPIO_IN | 20)
  43. #define U6_IRRX (GPIO_IN | 21)
  44. #define U7_HCTS (GPIO_IN | 22)
  45. #define U7_RX (GPIO_IN | 23)
  46. /* MISC IN */
  47. #define SPI1_DATIN (GPIO_IN | 25)
  48. #define DISP_SYNC (GPIO_IN | 26)
  49. #define SPI2_DATIN (GPIO_IN | 27)
  50. #define GPI_11 (GPIO_IN | 28)
  51. #define GPIO_IN_MASK 0x1eff83ff
  52. /* OUTPUT GPIOs */
  53. /* GPO */
  54. #define GPO_00 (GPIO_OUT | 0)
  55. #define GPO_01 (GPIO_OUT | 1)
  56. #define GPO_02 (GPIO_OUT | 2)
  57. #define GPO_03 (GPIO_OUT | 3)
  58. #define GPO_04 (GPIO_OUT | 4)
  59. #define GPO_05 (GPIO_OUT | 5)
  60. #define GPO_06 (GPIO_OUT | 6)
  61. #define GPO_07 (GPIO_OUT | 7)
  62. #define GPO_08 (GPIO_OUT | 8)
  63. #define GPO_09 (GPIO_OUT | 9)
  64. #define GPO_10 (GPIO_OUT | 10)
  65. #define GPO_11 (GPIO_OUT | 11)
  66. #define GPO_12 (GPIO_OUT | 12)
  67. #define GPO_13 (GPIO_OUT | 13)
  68. #define GPO_14 (GPIO_OUT | 14)
  69. #define GPO_15 (GPIO_OUT | 15)
  70. #define GPO_16 (GPIO_OUT | 16)
  71. #define GPO_17 (GPIO_OUT | 17)
  72. #define GPO_18 (GPIO_OUT | 18)
  73. #define GPO_19 (GPIO_OUT | 19)
  74. #define GPO_20 (GPIO_OUT | 20)
  75. #define GPO_21 (GPIO_OUT | 21)
  76. #define GPO_22 (GPIO_OUT | 22)
  77. #define GPO_23 (GPIO_OUT | 23)
  78. #define GPIO_OUT_MASK 0xffffff
  79. /* BIDIRECTIONAL GPIOs */
  80. /* RAM pins */
  81. #define RAM_D19 (GPIO_RAM | 0)
  82. #define RAM_D20 (GPIO_RAM | 1)
  83. #define RAM_D21 (GPIO_RAM | 2)
  84. #define RAM_D22 (GPIO_RAM | 3)
  85. #define RAM_D23 (GPIO_RAM | 4)
  86. #define RAM_D24 (GPIO_RAM | 5)
  87. #define RAM_D25 (GPIO_RAM | 6)
  88. #define RAM_D26 (GPIO_RAM | 7)
  89. #define RAM_D27 (GPIO_RAM | 8)
  90. #define RAM_D28 (GPIO_RAM | 9)
  91. #define RAM_D29 (GPIO_RAM | 10)
  92. #define RAM_D30 (GPIO_RAM | 11)
  93. #define RAM_D31 (GPIO_RAM | 12)
  94. #define GPIO_RAM_MASK 0x1fff
  95. /* I/O pins */
  96. #define GPIO_00 (GPIO_BID | 25)
  97. #define GPIO_01 (GPIO_BID | 26)
  98. #define GPIO_02 (GPIO_BID | 27)
  99. #define GPIO_03 (GPIO_BID | 28)
  100. #define GPIO_04 (GPIO_BID | 29)
  101. #define GPIO_05 (GPIO_BID | 30)
  102. #define GPIO_BID_MASK 0x7e000000
  103. /* Non-GPIO multiplexed PIOs. For multiplexing with GPIO, please use GPIO macros */
  104. #define GPIO_SDRAM_SEL (GPIO_MUX | 3)
  105. #define GPIO_MUX_MASK 0x8
  106. /* Extraction/assembly macros */
  107. #define GPIO_BIT_MASK(K) ((K) & 0x1F)
  108. #define GPIO_BIT(K) (1 << GPIO_BIT_MASK(K))
  109. #define GPIO_ISMUX(K) ((GPIO_TYPE_MASK(K) == GPIO_MUX) && (GPIO_BIT(K) & GPIO_MUX_MASK))
  110. #define GPIO_ISRAM(K) ((GPIO_TYPE_MASK(K) == GPIO_RAM) && (GPIO_BIT(K) & GPIO_RAM_MASK))
  111. #define GPIO_ISBID(K) ((GPIO_TYPE_MASK(K) == GPIO_BID) && (GPIO_BIT(K) & GPIO_BID_MASK))
  112. #define GPIO_ISOUT(K) ((GPIO_TYPE_MASK(K) == GPIO_OUT) && (GPIO_BIT(K) & GPIO_OUT_MASK))
  113. #define GPIO_ISIN(K) ((GPIO_TYPE_MASK(K) == GPIO_IN) && (GPIO_BIT(K) & GPIO_IN_MASK))
  114. /* Start Enable Pin Interrupts - table 58 page 66 */
  115. #define SE_PIN_BASE_INT 32
  116. #define SE_U7_RX_INT 63
  117. #define SE_U7_HCTS_INT 62
  118. #define SE_BT_CLKREQ_INT 61
  119. #define SE_U6_IRRX_INT 60
  120. /*59 unused*/
  121. #define SE_U5_RX_INT 58
  122. #define SE_GPI_11_INT 57
  123. #define SE_U3_RX_INT 56
  124. #define SE_U2_HCTS_INT 55
  125. #define SE_U2_RX_INT 54
  126. #define SE_U1_RX_INT 53
  127. #define SE_DISP_SYNC_INT 52
  128. /*51 unused*/
  129. #define SE_SDIO_INT_N 50
  130. #define SE_MSDIO_START_INT 49
  131. #define SE_GPI_06_INT 48
  132. #define SE_GPI_05_INT 47
  133. #define SE_GPI_04_INT 46
  134. #define SE_GPI_03_INT 45
  135. #define SE_GPI_02_INT 44
  136. #define SE_GPI_01_INT 43
  137. #define SE_GPI_00_INT 42
  138. #define SE_SYSCLKEN_PIN_INT 41
  139. #define SE_SPI1_DATAIN_INT 40
  140. #define SE_GPI_07_INT 39
  141. #define SE_SPI2_DATAIN_INT 38
  142. #define SE_GPI_10_INT 37
  143. #define SE_GPI_09_INT 36
  144. #define SE_GPI_08_INT 35
  145. /*34-32 unused*/
  146. /* Start Enable Internal Interrupts - table 57 page 65 */
  147. #define SE_INT_BASE_INT 0
  148. #define SE_TS_IRQ 31
  149. #define SE_TS_P_INT 30
  150. #define SE_TS_AUX_INT 29
  151. /*27-28 unused*/
  152. #define SE_USB_AHB_NEED_CLK_INT 26
  153. #define SE_MSTIMER_INT 25
  154. #define SE_RTC_INT 24
  155. #define SE_USB_NEED_CLK_INT 23
  156. #define SE_USB_INT 22
  157. #define SE_USB_I2C_INT 21
  158. #define SE_USB_OTG_TIMER_INT 20
  159. #define SE_USB_OTG_ATX_INT_N 19
  160. /*18 unused*/
  161. #define SE_DSP_GPIO4_INT 17
  162. #define SE_KEY_IRQ 16
  163. #define SE_DSP_SLAVEPORT_INT 15
  164. #define SE_DSP_GPIO1_INT 14
  165. #define SE_DSP_GPIO0_INT 13
  166. #define SE_DSP_AHB_INT 12
  167. /*11-6 unused*/
  168. #define SE_GPIO_05_INT 5
  169. #define SE_GPIO_04_INT 4
  170. #define SE_GPIO_03_INT 3
  171. #define SE_GPIO_02_INT 2
  172. #define SE_GPIO_01_INT 1
  173. #define SE_GPIO_00_INT 0
  174. #define START_INT_REG_BIT(irq) (1<<((irq)&0x1F))
  175. #define START_INT_ER_REG(irq) IO_ADDRESS((PNX4008_PWRMAN_BASE + 0x20 + (((irq)&(0x1<<5))>>1)))
  176. #define START_INT_RSR_REG(irq) IO_ADDRESS((PNX4008_PWRMAN_BASE + 0x24 + (((irq)&(0x1<<5))>>1)))
  177. #define START_INT_SR_REG(irq) IO_ADDRESS((PNX4008_PWRMAN_BASE + 0x28 + (((irq)&(0x1<<5))>>1)))
  178. #define START_INT_APR_REG(irq) IO_ADDRESS((PNX4008_PWRMAN_BASE + 0x2C + (((irq)&(0x1<<5))>>1)))
  179. extern int pnx4008_gpio_register_pin(unsigned short pin);
  180. extern int pnx4008_gpio_unregister_pin(unsigned short pin);
  181. extern unsigned long pnx4008_gpio_read_pin(unsigned short pin);
  182. extern int pnx4008_gpio_write_pin(unsigned short pin, int output);
  183. extern int pnx4008_gpio_set_pin_direction(unsigned short pin, int output);
  184. extern int pnx4008_gpio_read_pin_direction(unsigned short pin);
  185. extern int pnx4008_gpio_set_pin_mux(unsigned short pin, int output);
  186. extern int pnx4008_gpio_read_pin_mux(unsigned short pin);
  187. static inline void start_int_umask(u8 irq)
  188. {
  189. __raw_writel(__raw_readl(START_INT_ER_REG(irq)) |
  190. START_INT_REG_BIT(irq), START_INT_ER_REG(irq));
  191. }
  192. static inline void start_int_mask(u8 irq)
  193. {
  194. __raw_writel(__raw_readl(START_INT_ER_REG(irq)) &
  195. ~START_INT_REG_BIT(irq), START_INT_ER_REG(irq));
  196. }
  197. static inline void start_int_ack(u8 irq)
  198. {
  199. __raw_writel(START_INT_REG_BIT(irq), START_INT_RSR_REG(irq));
  200. }
  201. static inline void start_int_set_falling_edge(u8 irq)
  202. {
  203. __raw_writel(__raw_readl(START_INT_APR_REG(irq)) &
  204. ~START_INT_REG_BIT(irq), START_INT_APR_REG(irq));
  205. }
  206. static inline void start_int_set_rising_edge(u8 irq)
  207. {
  208. __raw_writel(__raw_readl(START_INT_APR_REG(irq)) |
  209. START_INT_REG_BIT(irq), START_INT_APR_REG(irq));
  210. }
  211. #endif /* _PNX4008_GPIO_H_ */