gpio7xx.c 6.5 KB

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