gpio16xx.c 5.8 KB

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