gpio16xx.c 6.4 KB

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