gpio16xx.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. /* smart idle, enable wakeup */
  25. #define SYSCONFIG_WORD 0x14
  26. /* mpu gpio */
  27. static struct __initdata resource omap16xx_mpu_gpio_resources[] = {
  28. {
  29. .start = OMAP1_MPUIO_VBASE,
  30. .end = OMAP1_MPUIO_VBASE + SZ_2K - 1,
  31. .flags = IORESOURCE_MEM,
  32. },
  33. {
  34. .start = INT_MPUIO,
  35. .flags = IORESOURCE_IRQ,
  36. },
  37. };
  38. static struct omap_gpio_reg_offs omap16xx_mpuio_regs = {
  39. .revision = USHRT_MAX,
  40. .direction = OMAP_MPUIO_IO_CNTL,
  41. .datain = OMAP_MPUIO_INPUT_LATCH,
  42. .dataout = OMAP_MPUIO_OUTPUT,
  43. .irqstatus = OMAP_MPUIO_GPIO_INT,
  44. .irqenable = OMAP_MPUIO_GPIO_MASKIT,
  45. .irqenable_inv = true,
  46. .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE,
  47. };
  48. static struct __initdata omap_gpio_platform_data omap16xx_mpu_gpio_config = {
  49. .is_mpuio = true,
  50. .bank_width = 16,
  51. .bank_stride = 1,
  52. .regs = &omap16xx_mpuio_regs,
  53. };
  54. static struct platform_device omap16xx_mpu_gpio = {
  55. .name = "omap_gpio",
  56. .id = 0,
  57. .dev = {
  58. .platform_data = &omap16xx_mpu_gpio_config,
  59. },
  60. .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources),
  61. .resource = omap16xx_mpu_gpio_resources,
  62. };
  63. /* gpio1 */
  64. static struct __initdata resource omap16xx_gpio1_resources[] = {
  65. {
  66. .start = OMAP1610_GPIO1_BASE,
  67. .end = OMAP1610_GPIO1_BASE + SZ_2K - 1,
  68. .flags = IORESOURCE_MEM,
  69. },
  70. {
  71. .start = INT_GPIO_BANK1,
  72. .flags = IORESOURCE_IRQ,
  73. },
  74. };
  75. static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
  76. .revision = OMAP1610_GPIO_REVISION,
  77. .direction = OMAP1610_GPIO_DIRECTION,
  78. .set_dataout = OMAP1610_GPIO_SET_DATAOUT,
  79. .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
  80. .datain = OMAP1610_GPIO_DATAIN,
  81. .dataout = OMAP1610_GPIO_DATAOUT,
  82. .irqstatus = OMAP1610_GPIO_IRQSTATUS1,
  83. .irqenable = OMAP1610_GPIO_IRQENABLE1,
  84. .set_irqenable = OMAP1610_GPIO_SET_IRQENABLE1,
  85. .clr_irqenable = OMAP1610_GPIO_CLEAR_IRQENABLE1,
  86. .wkup_en = OMAP1610_GPIO_WAKEUPENABLE,
  87. .edgectrl1 = OMAP1610_GPIO_EDGE_CTRL1,
  88. .edgectrl2 = OMAP1610_GPIO_EDGE_CTRL2,
  89. };
  90. static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = {
  91. .bank_width = 16,
  92. .regs = &omap16xx_gpio_regs,
  93. };
  94. static struct platform_device omap16xx_gpio1 = {
  95. .name = "omap_gpio",
  96. .id = 1,
  97. .dev = {
  98. .platform_data = &omap16xx_gpio1_config,
  99. },
  100. .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
  101. .resource = omap16xx_gpio1_resources,
  102. };
  103. /* gpio2 */
  104. static struct __initdata resource omap16xx_gpio2_resources[] = {
  105. {
  106. .start = OMAP1610_GPIO2_BASE,
  107. .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
  108. .flags = IORESOURCE_MEM,
  109. },
  110. {
  111. .start = INT_1610_GPIO_BANK2,
  112. .flags = IORESOURCE_IRQ,
  113. },
  114. };
  115. static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = {
  116. .bank_width = 16,
  117. .regs = &omap16xx_gpio_regs,
  118. };
  119. static struct platform_device omap16xx_gpio2 = {
  120. .name = "omap_gpio",
  121. .id = 2,
  122. .dev = {
  123. .platform_data = &omap16xx_gpio2_config,
  124. },
  125. .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
  126. .resource = omap16xx_gpio2_resources,
  127. };
  128. /* gpio3 */
  129. static struct __initdata resource omap16xx_gpio3_resources[] = {
  130. {
  131. .start = OMAP1610_GPIO3_BASE,
  132. .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
  133. .flags = IORESOURCE_MEM,
  134. },
  135. {
  136. .start = INT_1610_GPIO_BANK3,
  137. .flags = IORESOURCE_IRQ,
  138. },
  139. };
  140. static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = {
  141. .bank_width = 16,
  142. .regs = &omap16xx_gpio_regs,
  143. };
  144. static struct platform_device omap16xx_gpio3 = {
  145. .name = "omap_gpio",
  146. .id = 3,
  147. .dev = {
  148. .platform_data = &omap16xx_gpio3_config,
  149. },
  150. .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
  151. .resource = omap16xx_gpio3_resources,
  152. };
  153. /* gpio4 */
  154. static struct __initdata resource omap16xx_gpio4_resources[] = {
  155. {
  156. .start = OMAP1610_GPIO4_BASE,
  157. .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
  158. .flags = IORESOURCE_MEM,
  159. },
  160. {
  161. .start = INT_1610_GPIO_BANK4,
  162. .flags = IORESOURCE_IRQ,
  163. },
  164. };
  165. static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = {
  166. .bank_width = 16,
  167. .regs = &omap16xx_gpio_regs,
  168. };
  169. static struct platform_device omap16xx_gpio4 = {
  170. .name = "omap_gpio",
  171. .id = 4,
  172. .dev = {
  173. .platform_data = &omap16xx_gpio4_config,
  174. },
  175. .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
  176. .resource = omap16xx_gpio4_resources,
  177. };
  178. static struct __initdata platform_device * omap16xx_gpio_dev[] = {
  179. &omap16xx_mpu_gpio,
  180. &omap16xx_gpio1,
  181. &omap16xx_gpio2,
  182. &omap16xx_gpio3,
  183. &omap16xx_gpio4,
  184. };
  185. /*
  186. * omap16xx_gpio_init needs to be done before
  187. * machine_init functions access gpio APIs.
  188. * Hence omap16xx_gpio_init is a postcore_initcall.
  189. */
  190. static int __init omap16xx_gpio_init(void)
  191. {
  192. int i;
  193. void __iomem *base;
  194. struct resource *res;
  195. struct platform_device *pdev;
  196. struct omap_gpio_platform_data *pdata;
  197. if (!cpu_is_omap16xx())
  198. return -EINVAL;
  199. /*
  200. * Enable system clock for GPIO module.
  201. * The CAM_CLK_CTRL *is* really the right place.
  202. */
  203. omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04,
  204. ULPD_CAM_CLK_CTRL);
  205. for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++) {
  206. pdev = omap16xx_gpio_dev[i];
  207. pdata = pdev->dev.platform_data;
  208. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  209. if (unlikely(!res)) {
  210. dev_err(&pdev->dev, "Invalid mem resource.\n");
  211. return -ENODEV;
  212. }
  213. base = ioremap(res->start, resource_size(res));
  214. if (unlikely(!base)) {
  215. dev_err(&pdev->dev, "ioremap failed.\n");
  216. return -ENOMEM;
  217. }
  218. __raw_writel(SYSCONFIG_WORD, base + OMAP1610_GPIO_SYSCONFIG);
  219. iounmap(base);
  220. platform_device_register(omap16xx_gpio_dev[i]);
  221. }
  222. return 0;
  223. }
  224. postcore_initcall(omap16xx_gpio_init);