gpio16xx.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * OMAP16xx 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. #define OMAP1610_GPIO1_BASE 0xfffbe400
  20. #define OMAP1610_GPIO2_BASE 0xfffbec00
  21. #define OMAP1610_GPIO3_BASE 0xfffbb400
  22. #define OMAP1610_GPIO4_BASE 0xfffbbc00
  23. #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
  24. /* mpu gpio */
  25. static struct __initdata resource omap16xx_mpu_gpio_resources[] = {
  26. {
  27. .start = OMAP1_MPUIO_VBASE,
  28. .end = OMAP1_MPUIO_VBASE + SZ_2K - 1,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. {
  32. .start = INT_MPUIO,
  33. .flags = IORESOURCE_IRQ,
  34. },
  35. };
  36. static struct omap_gpio_reg_offs omap16xx_mpuio_regs = {
  37. .direction = OMAP_MPUIO_IO_CNTL,
  38. .datain = OMAP_MPUIO_INPUT_LATCH,
  39. .dataout = OMAP_MPUIO_OUTPUT,
  40. .irqstatus = OMAP_MPUIO_GPIO_INT,
  41. };
  42. static struct __initdata omap_gpio_platform_data omap16xx_mpu_gpio_config = {
  43. .virtual_irq_start = IH_MPUIO_BASE,
  44. .bank_type = METHOD_MPUIO,
  45. .bank_width = 16,
  46. .bank_stride = 1,
  47. .regs = &omap16xx_mpuio_regs,
  48. };
  49. static struct __initdata platform_device omap16xx_mpu_gpio = {
  50. .name = "omap_gpio",
  51. .id = 0,
  52. .dev = {
  53. .platform_data = &omap16xx_mpu_gpio_config,
  54. },
  55. .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources),
  56. .resource = omap16xx_mpu_gpio_resources,
  57. };
  58. /* gpio1 */
  59. static struct __initdata resource omap16xx_gpio1_resources[] = {
  60. {
  61. .start = OMAP1610_GPIO1_BASE,
  62. .end = OMAP1610_GPIO1_BASE + SZ_2K - 1,
  63. .flags = IORESOURCE_MEM,
  64. },
  65. {
  66. .start = INT_GPIO_BANK1,
  67. .flags = IORESOURCE_IRQ,
  68. },
  69. };
  70. static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
  71. .direction = OMAP1610_GPIO_DIRECTION,
  72. .set_dataout = OMAP1610_GPIO_SET_DATAOUT,
  73. .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
  74. .datain = OMAP1610_GPIO_DATAIN,
  75. .dataout = OMAP1610_GPIO_DATAOUT,
  76. .irqstatus = OMAP1610_GPIO_IRQSTATUS1,
  77. };
  78. static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = {
  79. .virtual_irq_start = IH_GPIO_BASE,
  80. .bank_type = METHOD_GPIO_1610,
  81. .bank_width = 16,
  82. .regs = &omap16xx_gpio_regs,
  83. };
  84. static struct __initdata platform_device omap16xx_gpio1 = {
  85. .name = "omap_gpio",
  86. .id = 1,
  87. .dev = {
  88. .platform_data = &omap16xx_gpio1_config,
  89. },
  90. .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
  91. .resource = omap16xx_gpio1_resources,
  92. };
  93. /* gpio2 */
  94. static struct __initdata resource omap16xx_gpio2_resources[] = {
  95. {
  96. .start = OMAP1610_GPIO2_BASE,
  97. .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
  98. .flags = IORESOURCE_MEM,
  99. },
  100. {
  101. .start = INT_1610_GPIO_BANK2,
  102. .flags = IORESOURCE_IRQ,
  103. },
  104. };
  105. static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = {
  106. .virtual_irq_start = IH_GPIO_BASE + 16,
  107. .bank_type = METHOD_GPIO_1610,
  108. .bank_width = 16,
  109. .regs = &omap16xx_gpio_regs,
  110. };
  111. static struct __initdata platform_device omap16xx_gpio2 = {
  112. .name = "omap_gpio",
  113. .id = 2,
  114. .dev = {
  115. .platform_data = &omap16xx_gpio2_config,
  116. },
  117. .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
  118. .resource = omap16xx_gpio2_resources,
  119. };
  120. /* gpio3 */
  121. static struct __initdata resource omap16xx_gpio3_resources[] = {
  122. {
  123. .start = OMAP1610_GPIO3_BASE,
  124. .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
  125. .flags = IORESOURCE_MEM,
  126. },
  127. {
  128. .start = INT_1610_GPIO_BANK3,
  129. .flags = IORESOURCE_IRQ,
  130. },
  131. };
  132. static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = {
  133. .virtual_irq_start = IH_GPIO_BASE + 32,
  134. .bank_type = METHOD_GPIO_1610,
  135. .bank_width = 16,
  136. .regs = &omap16xx_gpio_regs,
  137. };
  138. static struct __initdata platform_device omap16xx_gpio3 = {
  139. .name = "omap_gpio",
  140. .id = 3,
  141. .dev = {
  142. .platform_data = &omap16xx_gpio3_config,
  143. },
  144. .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
  145. .resource = omap16xx_gpio3_resources,
  146. };
  147. /* gpio4 */
  148. static struct __initdata resource omap16xx_gpio4_resources[] = {
  149. {
  150. .start = OMAP1610_GPIO4_BASE,
  151. .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
  152. .flags = IORESOURCE_MEM,
  153. },
  154. {
  155. .start = INT_1610_GPIO_BANK4,
  156. .flags = IORESOURCE_IRQ,
  157. },
  158. };
  159. static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = {
  160. .virtual_irq_start = IH_GPIO_BASE + 48,
  161. .bank_type = METHOD_GPIO_1610,
  162. .bank_width = 16,
  163. .regs = &omap16xx_gpio_regs,
  164. };
  165. static struct __initdata platform_device omap16xx_gpio4 = {
  166. .name = "omap_gpio",
  167. .id = 4,
  168. .dev = {
  169. .platform_data = &omap16xx_gpio4_config,
  170. },
  171. .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
  172. .resource = omap16xx_gpio4_resources,
  173. };
  174. static struct __initdata platform_device * omap16xx_gpio_dev[] = {
  175. &omap16xx_mpu_gpio,
  176. &omap16xx_gpio1,
  177. &omap16xx_gpio2,
  178. &omap16xx_gpio3,
  179. &omap16xx_gpio4,
  180. };
  181. /*
  182. * omap16xx_gpio_init needs to be done before
  183. * machine_init functions access gpio APIs.
  184. * Hence omap16xx_gpio_init is a postcore_initcall.
  185. */
  186. static int __init omap16xx_gpio_init(void)
  187. {
  188. int i;
  189. if (!cpu_is_omap16xx())
  190. return -EINVAL;
  191. for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++)
  192. platform_device_register(omap16xx_gpio_dev[i]);
  193. gpio_bank_count = ARRAY_SIZE(omap16xx_gpio_dev);
  194. return 0;
  195. }
  196. postcore_initcall(omap16xx_gpio_init);