gpio7xx.c 6.7 KB

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