gpio16xx.c 6.4 KB

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