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>
22 #include <mach/irqs.h>
26 #define OMAP1610_GPIO1_BASE 0xfffbe400
27 #define OMAP1610_GPIO2_BASE 0xfffbec00
28 #define OMAP1610_GPIO3_BASE 0xfffbb400
29 #define OMAP1610_GPIO4_BASE 0xfffbbc00
30 #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
32 /* smart idle, enable wakeup */
33 #define SYSCONFIG_WORD 0x14
36 static struct resource omap16xx_mpu_gpio_resources
[] = {
38 .start
= OMAP1_MPUIO_VBASE
,
39 .end
= OMAP1_MPUIO_VBASE
+ SZ_2K
- 1,
40 .flags
= IORESOURCE_MEM
,
44 .flags
= IORESOURCE_IRQ
,
48 static struct omap_gpio_reg_offs omap16xx_mpuio_regs
= {
49 .revision
= USHRT_MAX
,
50 .direction
= OMAP_MPUIO_IO_CNTL
,
51 .datain
= OMAP_MPUIO_INPUT_LATCH
,
52 .dataout
= OMAP_MPUIO_OUTPUT
,
53 .irqstatus
= OMAP_MPUIO_GPIO_INT
,
54 .irqenable
= OMAP_MPUIO_GPIO_MASKIT
,
55 .irqenable_inv
= true,
56 .irqctrl
= OMAP_MPUIO_GPIO_INT_EDGE
,
59 static struct omap_gpio_platform_data omap16xx_mpu_gpio_config
= {
63 .regs
= &omap16xx_mpuio_regs
,
66 static struct platform_device omap16xx_mpu_gpio
= {
70 .platform_data
= &omap16xx_mpu_gpio_config
,
72 .num_resources
= ARRAY_SIZE(omap16xx_mpu_gpio_resources
),
73 .resource
= omap16xx_mpu_gpio_resources
,
77 static struct resource omap16xx_gpio1_resources
[] = {
79 .start
= OMAP1610_GPIO1_BASE
,
80 .end
= OMAP1610_GPIO1_BASE
+ SZ_2K
- 1,
81 .flags
= IORESOURCE_MEM
,
84 .start
= INT_GPIO_BANK1
,
85 .flags
= IORESOURCE_IRQ
,
89 static struct omap_gpio_reg_offs omap16xx_gpio_regs
= {
90 .revision
= OMAP1610_GPIO_REVISION
,
91 .direction
= OMAP1610_GPIO_DIRECTION
,
92 .set_dataout
= OMAP1610_GPIO_SET_DATAOUT
,
93 .clr_dataout
= OMAP1610_GPIO_CLEAR_DATAOUT
,
94 .datain
= OMAP1610_GPIO_DATAIN
,
95 .dataout
= OMAP1610_GPIO_DATAOUT
,
96 .irqstatus
= OMAP1610_GPIO_IRQSTATUS1
,
97 .irqenable
= OMAP1610_GPIO_IRQENABLE1
,
98 .set_irqenable
= OMAP1610_GPIO_SET_IRQENABLE1
,
99 .clr_irqenable
= OMAP1610_GPIO_CLEAR_IRQENABLE1
,
100 .wkup_en
= OMAP1610_GPIO_WAKEUPENABLE
,
101 .edgectrl1
= OMAP1610_GPIO_EDGE_CTRL1
,
102 .edgectrl2
= OMAP1610_GPIO_EDGE_CTRL2
,
105 static struct omap_gpio_platform_data omap16xx_gpio1_config
= {
107 .regs
= &omap16xx_gpio_regs
,
110 static struct platform_device omap16xx_gpio1
= {
114 .platform_data
= &omap16xx_gpio1_config
,
116 .num_resources
= ARRAY_SIZE(omap16xx_gpio1_resources
),
117 .resource
= omap16xx_gpio1_resources
,
121 static struct resource omap16xx_gpio2_resources
[] = {
123 .start
= OMAP1610_GPIO2_BASE
,
124 .end
= OMAP1610_GPIO2_BASE
+ SZ_2K
- 1,
125 .flags
= IORESOURCE_MEM
,
128 .start
= INT_1610_GPIO_BANK2
,
129 .flags
= IORESOURCE_IRQ
,
133 static struct omap_gpio_platform_data omap16xx_gpio2_config
= {
135 .regs
= &omap16xx_gpio_regs
,
138 static struct platform_device omap16xx_gpio2
= {
142 .platform_data
= &omap16xx_gpio2_config
,
144 .num_resources
= ARRAY_SIZE(omap16xx_gpio2_resources
),
145 .resource
= omap16xx_gpio2_resources
,
149 static struct resource omap16xx_gpio3_resources
[] = {
151 .start
= OMAP1610_GPIO3_BASE
,
152 .end
= OMAP1610_GPIO3_BASE
+ SZ_2K
- 1,
153 .flags
= IORESOURCE_MEM
,
156 .start
= INT_1610_GPIO_BANK3
,
157 .flags
= IORESOURCE_IRQ
,
161 static struct omap_gpio_platform_data omap16xx_gpio3_config
= {
163 .regs
= &omap16xx_gpio_regs
,
166 static struct platform_device omap16xx_gpio3
= {
170 .platform_data
= &omap16xx_gpio3_config
,
172 .num_resources
= ARRAY_SIZE(omap16xx_gpio3_resources
),
173 .resource
= omap16xx_gpio3_resources
,
177 static struct resource omap16xx_gpio4_resources
[] = {
179 .start
= OMAP1610_GPIO4_BASE
,
180 .end
= OMAP1610_GPIO4_BASE
+ SZ_2K
- 1,
181 .flags
= IORESOURCE_MEM
,
184 .start
= INT_1610_GPIO_BANK4
,
185 .flags
= IORESOURCE_IRQ
,
189 static struct omap_gpio_platform_data omap16xx_gpio4_config
= {
191 .regs
= &omap16xx_gpio_regs
,
194 static struct platform_device omap16xx_gpio4
= {
198 .platform_data
= &omap16xx_gpio4_config
,
200 .num_resources
= ARRAY_SIZE(omap16xx_gpio4_resources
),
201 .resource
= omap16xx_gpio4_resources
,
204 static struct platform_device
*omap16xx_gpio_dev
[] __initdata
= {
213 * omap16xx_gpio_init needs to be done before
214 * machine_init functions access gpio APIs.
215 * Hence omap16xx_gpio_init is a postcore_initcall.
217 static int __init
omap16xx_gpio_init(void)
221 struct resource
*res
;
222 struct platform_device
*pdev
;
223 struct omap_gpio_platform_data
*pdata
;
225 if (!cpu_is_omap16xx())
229 * Enable system clock for GPIO module.
230 * The CAM_CLK_CTRL *is* really the right place.
232 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL
) | 0x04,
235 for (i
= 0; i
< ARRAY_SIZE(omap16xx_gpio_dev
); i
++) {
236 pdev
= omap16xx_gpio_dev
[i
];
237 pdata
= pdev
->dev
.platform_data
;
239 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
240 if (unlikely(!res
)) {
241 dev_err(&pdev
->dev
, "Invalid mem resource.\n");
245 base
= ioremap(res
->start
, resource_size(res
));
246 if (unlikely(!base
)) {
247 dev_err(&pdev
->dev
, "ioremap failed.\n");
251 __raw_writel(SYSCONFIG_WORD
, base
+ OMAP1610_GPIO_SYSCONFIG
);
254 platform_device_register(omap16xx_gpio_dev
[i
]);
259 postcore_initcall(omap16xx_gpio_init
);