gpio7xx.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * OMAP7xx specific gpio init
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * Author:
  7. * Charulatha V <charu@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/gpio.h>
  19. #include <linux/platform_data/gpio-omap.h>
  20. #define OMAP7XX_GPIO1_BASE 0xfffbc000
  21. #define OMAP7XX_GPIO2_BASE 0xfffbc800
  22. #define OMAP7XX_GPIO3_BASE 0xfffbd000
  23. #define OMAP7XX_GPIO4_BASE 0xfffbd800
  24. #define OMAP7XX_GPIO5_BASE 0xfffbe000
  25. #define OMAP7XX_GPIO6_BASE 0xfffbe800
  26. #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
  27. /* mpu gpio */
  28. static struct __initdata resource omap7xx_mpu_gpio_resources[] = {
  29. {
  30. .start = OMAP1_MPUIO_VBASE,
  31. .end = OMAP1_MPUIO_VBASE + SZ_2K - 1,
  32. .flags = IORESOURCE_MEM,
  33. },
  34. {
  35. .start = INT_7XX_MPUIO,
  36. .flags = IORESOURCE_IRQ,
  37. },
  38. };
  39. static struct omap_gpio_reg_offs omap7xx_mpuio_regs = {
  40. .revision = USHRT_MAX,
  41. .direction = OMAP_MPUIO_IO_CNTL / 2,
  42. .datain = OMAP_MPUIO_INPUT_LATCH / 2,
  43. .dataout = OMAP_MPUIO_OUTPUT / 2,
  44. .irqstatus = OMAP_MPUIO_GPIO_INT / 2,
  45. .irqenable = OMAP_MPUIO_GPIO_MASKIT / 2,
  46. .irqenable_inv = true,
  47. .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE >> 1,
  48. };
  49. static struct __initdata omap_gpio_platform_data omap7xx_mpu_gpio_config = {
  50. .is_mpuio = true,
  51. .bank_width = 16,
  52. .bank_stride = 2,
  53. .regs = &omap7xx_mpuio_regs,
  54. };
  55. static struct platform_device omap7xx_mpu_gpio = {
  56. .name = "omap_gpio",
  57. .id = 0,
  58. .dev = {
  59. .platform_data = &omap7xx_mpu_gpio_config,
  60. },
  61. .num_resources = ARRAY_SIZE(omap7xx_mpu_gpio_resources),
  62. .resource = omap7xx_mpu_gpio_resources,
  63. };
  64. /* gpio1 */
  65. static struct __initdata resource omap7xx_gpio1_resources[] = {
  66. {
  67. .start = OMAP7XX_GPIO1_BASE,
  68. .end = OMAP7XX_GPIO1_BASE + SZ_2K - 1,
  69. .flags = IORESOURCE_MEM,
  70. },
  71. {
  72. .start = INT_7XX_GPIO_BANK1,
  73. .flags = IORESOURCE_IRQ,
  74. },
  75. };
  76. static struct omap_gpio_reg_offs omap7xx_gpio_regs = {
  77. .revision = USHRT_MAX,
  78. .direction = OMAP7XX_GPIO_DIR_CONTROL,
  79. .datain = OMAP7XX_GPIO_DATA_INPUT,
  80. .dataout = OMAP7XX_GPIO_DATA_OUTPUT,
  81. .irqstatus = OMAP7XX_GPIO_INT_STATUS,
  82. .irqenable = OMAP7XX_GPIO_INT_MASK,
  83. .irqenable_inv = true,
  84. .irqctrl = OMAP7XX_GPIO_INT_CONTROL,
  85. };
  86. static struct __initdata omap_gpio_platform_data omap7xx_gpio1_config = {
  87. .bank_width = 32,
  88. .regs = &omap7xx_gpio_regs,
  89. };
  90. static struct platform_device omap7xx_gpio1 = {
  91. .name = "omap_gpio",
  92. .id = 1,
  93. .dev = {
  94. .platform_data = &omap7xx_gpio1_config,
  95. },
  96. .num_resources = ARRAY_SIZE(omap7xx_gpio1_resources),
  97. .resource = omap7xx_gpio1_resources,
  98. };
  99. /* gpio2 */
  100. static struct __initdata resource omap7xx_gpio2_resources[] = {
  101. {
  102. .start = OMAP7XX_GPIO2_BASE,
  103. .end = OMAP7XX_GPIO2_BASE + SZ_2K - 1,
  104. .flags = IORESOURCE_MEM,
  105. },
  106. {
  107. .start = INT_7XX_GPIO_BANK2,
  108. .flags = IORESOURCE_IRQ,
  109. },
  110. };
  111. static struct __initdata omap_gpio_platform_data omap7xx_gpio2_config = {
  112. .bank_width = 32,
  113. .regs = &omap7xx_gpio_regs,
  114. };
  115. static struct platform_device omap7xx_gpio2 = {
  116. .name = "omap_gpio",
  117. .id = 2,
  118. .dev = {
  119. .platform_data = &omap7xx_gpio2_config,
  120. },
  121. .num_resources = ARRAY_SIZE(omap7xx_gpio2_resources),
  122. .resource = omap7xx_gpio2_resources,
  123. };
  124. /* gpio3 */
  125. static struct __initdata resource omap7xx_gpio3_resources[] = {
  126. {
  127. .start = OMAP7XX_GPIO3_BASE,
  128. .end = OMAP7XX_GPIO3_BASE + SZ_2K - 1,
  129. .flags = IORESOURCE_MEM,
  130. },
  131. {
  132. .start = INT_7XX_GPIO_BANK3,
  133. .flags = IORESOURCE_IRQ,
  134. },
  135. };
  136. static struct __initdata omap_gpio_platform_data omap7xx_gpio3_config = {
  137. .bank_width = 32,
  138. .regs = &omap7xx_gpio_regs,
  139. };
  140. static struct platform_device omap7xx_gpio3 = {
  141. .name = "omap_gpio",
  142. .id = 3,
  143. .dev = {
  144. .platform_data = &omap7xx_gpio3_config,
  145. },
  146. .num_resources = ARRAY_SIZE(omap7xx_gpio3_resources),
  147. .resource = omap7xx_gpio3_resources,
  148. };
  149. /* gpio4 */
  150. static struct __initdata resource omap7xx_gpio4_resources[] = {
  151. {
  152. .start = OMAP7XX_GPIO4_BASE,
  153. .end = OMAP7XX_GPIO4_BASE + SZ_2K - 1,
  154. .flags = IORESOURCE_MEM,
  155. },
  156. {
  157. .start = INT_7XX_GPIO_BANK4,
  158. .flags = IORESOURCE_IRQ,
  159. },
  160. };
  161. static struct __initdata omap_gpio_platform_data omap7xx_gpio4_config = {
  162. .bank_width = 32,
  163. .regs = &omap7xx_gpio_regs,
  164. };
  165. static struct platform_device omap7xx_gpio4 = {
  166. .name = "omap_gpio",
  167. .id = 4,
  168. .dev = {
  169. .platform_data = &omap7xx_gpio4_config,
  170. },
  171. .num_resources = ARRAY_SIZE(omap7xx_gpio4_resources),
  172. .resource = omap7xx_gpio4_resources,
  173. };
  174. /* gpio5 */
  175. static struct __initdata resource omap7xx_gpio5_resources[] = {
  176. {
  177. .start = OMAP7XX_GPIO5_BASE,
  178. .end = OMAP7XX_GPIO5_BASE + SZ_2K - 1,
  179. .flags = IORESOURCE_MEM,
  180. },
  181. {
  182. .start = INT_7XX_GPIO_BANK5,
  183. .flags = IORESOURCE_IRQ,
  184. },
  185. };
  186. static struct __initdata omap_gpio_platform_data omap7xx_gpio5_config = {
  187. .bank_width = 32,
  188. .regs = &omap7xx_gpio_regs,
  189. };
  190. static struct platform_device omap7xx_gpio5 = {
  191. .name = "omap_gpio",
  192. .id = 5,
  193. .dev = {
  194. .platform_data = &omap7xx_gpio5_config,
  195. },
  196. .num_resources = ARRAY_SIZE(omap7xx_gpio5_resources),
  197. .resource = omap7xx_gpio5_resources,
  198. };
  199. /* gpio6 */
  200. static struct __initdata resource omap7xx_gpio6_resources[] = {
  201. {
  202. .start = OMAP7XX_GPIO6_BASE,
  203. .end = OMAP7XX_GPIO6_BASE + SZ_2K - 1,
  204. .flags = IORESOURCE_MEM,
  205. },
  206. {
  207. .start = INT_7XX_GPIO_BANK6,
  208. .flags = IORESOURCE_IRQ,
  209. },
  210. };
  211. static struct __initdata omap_gpio_platform_data omap7xx_gpio6_config = {
  212. .bank_width = 32,
  213. .regs = &omap7xx_gpio_regs,
  214. };
  215. static struct platform_device omap7xx_gpio6 = {
  216. .name = "omap_gpio",
  217. .id = 6,
  218. .dev = {
  219. .platform_data = &omap7xx_gpio6_config,
  220. },
  221. .num_resources = ARRAY_SIZE(omap7xx_gpio6_resources),
  222. .resource = omap7xx_gpio6_resources,
  223. };
  224. static struct __initdata platform_device * omap7xx_gpio_dev[] = {
  225. &omap7xx_mpu_gpio,
  226. &omap7xx_gpio1,
  227. &omap7xx_gpio2,
  228. &omap7xx_gpio3,
  229. &omap7xx_gpio4,
  230. &omap7xx_gpio5,
  231. &omap7xx_gpio6,
  232. };
  233. /*
  234. * omap7xx_gpio_init needs to be done before
  235. * machine_init functions access gpio APIs.
  236. * Hence omap7xx_gpio_init is a postcore_initcall.
  237. */
  238. static int __init omap7xx_gpio_init(void)
  239. {
  240. int i;
  241. if (!cpu_is_omap7xx())
  242. return -EINVAL;
  243. for (i = 0; i < ARRAY_SIZE(omap7xx_gpio_dev); i++)
  244. platform_device_register(omap7xx_gpio_dev[i]);
  245. return 0;
  246. }
  247. postcore_initcall(omap7xx_gpio_init);