2 * OMAP16xx specific gpio init
4 * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
7 * Charulatha V <charu@ti.com>
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.
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.
19 #include <linux/gpio.h>
20 #include <linux/platform_data/gpio-omap.h>
21 #include <linux/soc/ti/omap1-io.h>
27 #define OMAP1610_GPIO1_BASE 0xfffbe400
28 #define OMAP1610_GPIO2_BASE 0xfffbec00
29 #define OMAP1610_GPIO3_BASE 0xfffbb400
30 #define OMAP1610_GPIO4_BASE 0xfffbbc00
31 #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
33 /* smart idle, enable wakeup */
34 #define SYSCONFIG_WORD 0x14
37 static struct resource omap16xx_mpu_gpio_resources[] = {
39 .start = OMAP1_MPUIO_VBASE,
40 .end = OMAP1_MPUIO_VBASE + SZ_2K - 1,
41 .flags = IORESOURCE_MEM,
45 .flags = IORESOURCE_IRQ,
49 static struct omap_gpio_reg_offs omap16xx_mpuio_regs = {
50 .revision = USHRT_MAX,
51 .direction = OMAP_MPUIO_IO_CNTL,
52 .datain = OMAP_MPUIO_INPUT_LATCH,
53 .dataout = OMAP_MPUIO_OUTPUT,
54 .irqstatus = OMAP_MPUIO_GPIO_INT,
55 .irqenable = OMAP_MPUIO_GPIO_MASKIT,
56 .irqenable_inv = true,
57 .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE,
60 static struct omap_gpio_platform_data omap16xx_mpu_gpio_config = {
64 .regs = &omap16xx_mpuio_regs,
67 static struct platform_device omap16xx_mpu_gpio = {
71 .platform_data = &omap16xx_mpu_gpio_config,
73 .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources),
74 .resource = omap16xx_mpu_gpio_resources,
78 static struct resource omap16xx_gpio1_resources[] = {
80 .start = OMAP1610_GPIO1_BASE,
81 .end = OMAP1610_GPIO1_BASE + SZ_2K - 1,
82 .flags = IORESOURCE_MEM,
85 .start = INT_GPIO_BANK1,
86 .flags = IORESOURCE_IRQ,
90 static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
91 .revision = OMAP1610_GPIO_REVISION,
92 .direction = OMAP1610_GPIO_DIRECTION,
93 .set_dataout = OMAP1610_GPIO_SET_DATAOUT,
94 .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
95 .datain = OMAP1610_GPIO_DATAIN,
96 .dataout = OMAP1610_GPIO_DATAOUT,
97 .irqstatus = OMAP1610_GPIO_IRQSTATUS1,
98 .irqenable = OMAP1610_GPIO_IRQENABLE1,
99 .set_irqenable = OMAP1610_GPIO_SET_IRQENABLE1,
100 .clr_irqenable = OMAP1610_GPIO_CLEAR_IRQENABLE1,
101 .wkup_en = OMAP1610_GPIO_WAKEUPENABLE,
102 .edgectrl1 = OMAP1610_GPIO_EDGE_CTRL1,
103 .edgectrl2 = OMAP1610_GPIO_EDGE_CTRL2,
106 static struct omap_gpio_platform_data omap16xx_gpio1_config = {
108 .regs = &omap16xx_gpio_regs,
111 static struct platform_device omap16xx_gpio1 = {
115 .platform_data = &omap16xx_gpio1_config,
117 .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
118 .resource = omap16xx_gpio1_resources,
122 static struct resource omap16xx_gpio2_resources[] = {
124 .start = OMAP1610_GPIO2_BASE,
125 .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
126 .flags = IORESOURCE_MEM,
129 .start = INT_1610_GPIO_BANK2,
130 .flags = IORESOURCE_IRQ,
134 static struct omap_gpio_platform_data omap16xx_gpio2_config = {
136 .regs = &omap16xx_gpio_regs,
139 static struct platform_device omap16xx_gpio2 = {
143 .platform_data = &omap16xx_gpio2_config,
145 .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
146 .resource = omap16xx_gpio2_resources,
150 static struct resource omap16xx_gpio3_resources[] = {
152 .start = OMAP1610_GPIO3_BASE,
153 .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
154 .flags = IORESOURCE_MEM,
157 .start = INT_1610_GPIO_BANK3,
158 .flags = IORESOURCE_IRQ,
162 static struct omap_gpio_platform_data omap16xx_gpio3_config = {
164 .regs = &omap16xx_gpio_regs,
167 static struct platform_device omap16xx_gpio3 = {
171 .platform_data = &omap16xx_gpio3_config,
173 .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
174 .resource = omap16xx_gpio3_resources,
178 static struct resource omap16xx_gpio4_resources[] = {
180 .start = OMAP1610_GPIO4_BASE,
181 .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
182 .flags = IORESOURCE_MEM,
185 .start = INT_1610_GPIO_BANK4,
186 .flags = IORESOURCE_IRQ,
190 static struct omap_gpio_platform_data omap16xx_gpio4_config = {
192 .regs = &omap16xx_gpio_regs,
195 static struct platform_device omap16xx_gpio4 = {
199 .platform_data = &omap16xx_gpio4_config,
201 .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
202 .resource = omap16xx_gpio4_resources,
205 static struct platform_device *omap16xx_gpio_dev[] __initdata = {
214 * omap16xx_gpio_init needs to be done before
215 * machine_init functions access gpio APIs.
216 * Hence omap16xx_gpio_init is a postcore_initcall.
218 static int __init omap16xx_gpio_init(void)
222 struct resource *res;
223 struct platform_device *pdev;
224 struct omap_gpio_platform_data *pdata;
226 if (!cpu_is_omap16xx())
230 * Enable system clock for GPIO module.
231 * The CAM_CLK_CTRL *is* really the right place.
233 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04,
236 for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++) {
237 pdev = omap16xx_gpio_dev[i];
238 pdata = pdev->dev.platform_data;
240 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
241 if (unlikely(!res)) {
242 dev_err(&pdev->dev, "Invalid mem resource.\n");
246 base = ioremap(res->start, resource_size(res));
247 if (unlikely(!base)) {
248 dev_err(&pdev->dev, "ioremap failed.\n");
252 __raw_writel(SYSCONFIG_WORD, base + OMAP1610_GPIO_SYSCONFIG);
255 platform_device_register(omap16xx_gpio_dev[i]);
260 postcore_initcall(omap16xx_gpio_init);