blob: 207a23cfa1a0e3d7af36ed26f847cbf1343f62eb [file] [log] [blame]
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -08001/*
2 * OMAP7xx 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
19#include <linux/gpio.h>
20
21#define OMAP7XX_GPIO1_BASE 0xfffbc000
22#define OMAP7XX_GPIO2_BASE 0xfffbc800
23#define OMAP7XX_GPIO3_BASE 0xfffbd000
24#define OMAP7XX_GPIO4_BASE 0xfffbd800
25#define OMAP7XX_GPIO5_BASE 0xfffbe000
26#define OMAP7XX_GPIO6_BASE 0xfffbe800
27#define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
28
29/* mpu gpio */
30static struct __initdata resource omap7xx_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_7XX_MPUIO,
38 .flags = IORESOURCE_IRQ,
39 },
40};
41
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070042static struct omap_gpio_reg_offs omap7xx_mpuio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070043 .revision = USHRT_MAX,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070044 .direction = OMAP_MPUIO_IO_CNTL / 2,
45 .datain = OMAP_MPUIO_INPUT_LATCH / 2,
46 .dataout = OMAP_MPUIO_OUTPUT / 2,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070047 .irqstatus = OMAP_MPUIO_GPIO_INT / 2,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070048 .irqenable = OMAP_MPUIO_GPIO_MASKIT / 2,
49 .irqenable_inv = true,
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +053050 .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE >> 1,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070051};
52
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080053static struct __initdata omap_gpio_platform_data omap7xx_mpu_gpio_config = {
54 .virtual_irq_start = IH_MPUIO_BASE,
55 .bank_type = METHOD_MPUIO,
56 .bank_width = 32,
Tony Lindgren5de62b82010-12-07 16:26:58 -080057 .bank_stride = 2,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070058 .regs = &omap7xx_mpuio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080059};
60
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -070061static struct platform_device omap7xx_mpu_gpio = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080062 .name = "omap_gpio",
63 .id = 0,
64 .dev = {
65 .platform_data = &omap7xx_mpu_gpio_config,
66 },
67 .num_resources = ARRAY_SIZE(omap7xx_mpu_gpio_resources),
68 .resource = omap7xx_mpu_gpio_resources,
69};
70
71/* gpio1 */
72static struct __initdata resource omap7xx_gpio1_resources[] = {
73 {
74 .start = OMAP7XX_GPIO1_BASE,
75 .end = OMAP7XX_GPIO1_BASE + SZ_2K - 1,
76 .flags = IORESOURCE_MEM,
77 },
78 {
79 .start = INT_7XX_GPIO_BANK1,
80 .flags = IORESOURCE_IRQ,
81 },
82};
83
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070084static struct omap_gpio_reg_offs omap7xx_gpio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070085 .revision = USHRT_MAX,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070086 .direction = OMAP7XX_GPIO_DIR_CONTROL,
87 .datain = OMAP7XX_GPIO_DATA_INPUT,
88 .dataout = OMAP7XX_GPIO_DATA_OUTPUT,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070089 .irqstatus = OMAP7XX_GPIO_INT_STATUS,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070090 .irqenable = OMAP7XX_GPIO_INT_MASK,
91 .irqenable_inv = true,
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +053092 .irqctrl = OMAP7XX_GPIO_INT_CONTROL,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070093};
94
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080095static struct __initdata omap_gpio_platform_data omap7xx_gpio1_config = {
96 .virtual_irq_start = IH_GPIO_BASE,
97 .bank_type = METHOD_GPIO_7XX,
98 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070099 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800100};
101
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700102static struct platform_device omap7xx_gpio1 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800103 .name = "omap_gpio",
104 .id = 1,
105 .dev = {
106 .platform_data = &omap7xx_gpio1_config,
107 },
108 .num_resources = ARRAY_SIZE(omap7xx_gpio1_resources),
109 .resource = omap7xx_gpio1_resources,
110};
111
112/* gpio2 */
113static struct __initdata resource omap7xx_gpio2_resources[] = {
114 {
115 .start = OMAP7XX_GPIO2_BASE,
116 .end = OMAP7XX_GPIO2_BASE + SZ_2K - 1,
117 .flags = IORESOURCE_MEM,
118 },
119 {
120 .start = INT_7XX_GPIO_BANK2,
121 .flags = IORESOURCE_IRQ,
122 },
123};
124
125static struct __initdata omap_gpio_platform_data omap7xx_gpio2_config = {
126 .virtual_irq_start = IH_GPIO_BASE + 32,
127 .bank_type = METHOD_GPIO_7XX,
128 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700129 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800130};
131
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700132static struct platform_device omap7xx_gpio2 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800133 .name = "omap_gpio",
134 .id = 2,
135 .dev = {
136 .platform_data = &omap7xx_gpio2_config,
137 },
138 .num_resources = ARRAY_SIZE(omap7xx_gpio2_resources),
139 .resource = omap7xx_gpio2_resources,
140};
141
142/* gpio3 */
143static struct __initdata resource omap7xx_gpio3_resources[] = {
144 {
145 .start = OMAP7XX_GPIO3_BASE,
146 .end = OMAP7XX_GPIO3_BASE + SZ_2K - 1,
147 .flags = IORESOURCE_MEM,
148 },
149 {
150 .start = INT_7XX_GPIO_BANK3,
151 .flags = IORESOURCE_IRQ,
152 },
153};
154
155static struct __initdata omap_gpio_platform_data omap7xx_gpio3_config = {
156 .virtual_irq_start = IH_GPIO_BASE + 64,
157 .bank_type = METHOD_GPIO_7XX,
158 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700159 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800160};
161
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700162static struct platform_device omap7xx_gpio3 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800163 .name = "omap_gpio",
164 .id = 3,
165 .dev = {
166 .platform_data = &omap7xx_gpio3_config,
167 },
168 .num_resources = ARRAY_SIZE(omap7xx_gpio3_resources),
169 .resource = omap7xx_gpio3_resources,
170};
171
172/* gpio4 */
173static struct __initdata resource omap7xx_gpio4_resources[] = {
174 {
175 .start = OMAP7XX_GPIO4_BASE,
176 .end = OMAP7XX_GPIO4_BASE + SZ_2K - 1,
177 .flags = IORESOURCE_MEM,
178 },
179 {
180 .start = INT_7XX_GPIO_BANK4,
181 .flags = IORESOURCE_IRQ,
182 },
183};
184
185static struct __initdata omap_gpio_platform_data omap7xx_gpio4_config = {
186 .virtual_irq_start = IH_GPIO_BASE + 96,
187 .bank_type = METHOD_GPIO_7XX,
188 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700189 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800190};
191
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700192static struct platform_device omap7xx_gpio4 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800193 .name = "omap_gpio",
194 .id = 4,
195 .dev = {
196 .platform_data = &omap7xx_gpio4_config,
197 },
198 .num_resources = ARRAY_SIZE(omap7xx_gpio4_resources),
199 .resource = omap7xx_gpio4_resources,
200};
201
202/* gpio5 */
203static struct __initdata resource omap7xx_gpio5_resources[] = {
204 {
205 .start = OMAP7XX_GPIO5_BASE,
206 .end = OMAP7XX_GPIO5_BASE + SZ_2K - 1,
207 .flags = IORESOURCE_MEM,
208 },
209 {
210 .start = INT_7XX_GPIO_BANK5,
211 .flags = IORESOURCE_IRQ,
212 },
213};
214
215static struct __initdata omap_gpio_platform_data omap7xx_gpio5_config = {
216 .virtual_irq_start = IH_GPIO_BASE + 128,
217 .bank_type = METHOD_GPIO_7XX,
218 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700219 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800220};
221
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700222static struct platform_device omap7xx_gpio5 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800223 .name = "omap_gpio",
224 .id = 5,
225 .dev = {
226 .platform_data = &omap7xx_gpio5_config,
227 },
228 .num_resources = ARRAY_SIZE(omap7xx_gpio5_resources),
229 .resource = omap7xx_gpio5_resources,
230};
231
232/* gpio6 */
233static struct __initdata resource omap7xx_gpio6_resources[] = {
234 {
235 .start = OMAP7XX_GPIO6_BASE,
236 .end = OMAP7XX_GPIO6_BASE + SZ_2K - 1,
237 .flags = IORESOURCE_MEM,
238 },
239 {
240 .start = INT_7XX_GPIO_BANK6,
241 .flags = IORESOURCE_IRQ,
242 },
243};
244
245static struct __initdata omap_gpio_platform_data omap7xx_gpio6_config = {
246 .virtual_irq_start = IH_GPIO_BASE + 160,
247 .bank_type = METHOD_GPIO_7XX,
248 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700249 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800250};
251
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700252static struct platform_device omap7xx_gpio6 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800253 .name = "omap_gpio",
254 .id = 6,
255 .dev = {
256 .platform_data = &omap7xx_gpio6_config,
257 },
258 .num_resources = ARRAY_SIZE(omap7xx_gpio6_resources),
259 .resource = omap7xx_gpio6_resources,
260};
261
262static struct __initdata platform_device * omap7xx_gpio_dev[] = {
263 &omap7xx_mpu_gpio,
264 &omap7xx_gpio1,
265 &omap7xx_gpio2,
266 &omap7xx_gpio3,
267 &omap7xx_gpio4,
268 &omap7xx_gpio5,
269 &omap7xx_gpio6,
270};
271
272/*
273 * omap7xx_gpio_init needs to be done before
274 * machine_init functions access gpio APIs.
275 * Hence omap7xx_gpio_init is a postcore_initcall.
276 */
277static int __init omap7xx_gpio_init(void)
278{
279 int i;
280
281 if (!cpu_is_omap7xx())
282 return -EINVAL;
283
284 for (i = 0; i < ARRAY_SIZE(omap7xx_gpio_dev); i++)
285 platform_device_register(omap7xx_gpio_dev[i]);
286
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800287 return 0;
288}
289postcore_initcall(omap7xx_gpio_init);