blob: 5ab63eab0ff5f18b52476172d90db7ee0d6afeeb [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,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070050};
51
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080052static struct __initdata omap_gpio_platform_data omap7xx_mpu_gpio_config = {
53 .virtual_irq_start = IH_MPUIO_BASE,
54 .bank_type = METHOD_MPUIO,
55 .bank_width = 32,
Tony Lindgren5de62b82010-12-07 16:26:58 -080056 .bank_stride = 2,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070057 .regs = &omap7xx_mpuio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080058};
59
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -070060static struct platform_device omap7xx_mpu_gpio = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080061 .name = "omap_gpio",
62 .id = 0,
63 .dev = {
64 .platform_data = &omap7xx_mpu_gpio_config,
65 },
66 .num_resources = ARRAY_SIZE(omap7xx_mpu_gpio_resources),
67 .resource = omap7xx_mpu_gpio_resources,
68};
69
70/* gpio1 */
71static struct __initdata resource omap7xx_gpio1_resources[] = {
72 {
73 .start = OMAP7XX_GPIO1_BASE,
74 .end = OMAP7XX_GPIO1_BASE + SZ_2K - 1,
75 .flags = IORESOURCE_MEM,
76 },
77 {
78 .start = INT_7XX_GPIO_BANK1,
79 .flags = IORESOURCE_IRQ,
80 },
81};
82
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070083static struct omap_gpio_reg_offs omap7xx_gpio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070084 .revision = USHRT_MAX,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070085 .direction = OMAP7XX_GPIO_DIR_CONTROL,
86 .datain = OMAP7XX_GPIO_DATA_INPUT,
87 .dataout = OMAP7XX_GPIO_DATA_OUTPUT,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070088 .irqstatus = OMAP7XX_GPIO_INT_STATUS,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070089 .irqenable = OMAP7XX_GPIO_INT_MASK,
90 .irqenable_inv = true,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070091};
92
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080093static struct __initdata omap_gpio_platform_data omap7xx_gpio1_config = {
94 .virtual_irq_start = IH_GPIO_BASE,
95 .bank_type = METHOD_GPIO_7XX,
96 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070097 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -080098};
99
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700100static struct platform_device omap7xx_gpio1 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800101 .name = "omap_gpio",
102 .id = 1,
103 .dev = {
104 .platform_data = &omap7xx_gpio1_config,
105 },
106 .num_resources = ARRAY_SIZE(omap7xx_gpio1_resources),
107 .resource = omap7xx_gpio1_resources,
108};
109
110/* gpio2 */
111static struct __initdata resource omap7xx_gpio2_resources[] = {
112 {
113 .start = OMAP7XX_GPIO2_BASE,
114 .end = OMAP7XX_GPIO2_BASE + SZ_2K - 1,
115 .flags = IORESOURCE_MEM,
116 },
117 {
118 .start = INT_7XX_GPIO_BANK2,
119 .flags = IORESOURCE_IRQ,
120 },
121};
122
123static struct __initdata omap_gpio_platform_data omap7xx_gpio2_config = {
124 .virtual_irq_start = IH_GPIO_BASE + 32,
125 .bank_type = METHOD_GPIO_7XX,
126 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700127 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800128};
129
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700130static struct platform_device omap7xx_gpio2 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800131 .name = "omap_gpio",
132 .id = 2,
133 .dev = {
134 .platform_data = &omap7xx_gpio2_config,
135 },
136 .num_resources = ARRAY_SIZE(omap7xx_gpio2_resources),
137 .resource = omap7xx_gpio2_resources,
138};
139
140/* gpio3 */
141static struct __initdata resource omap7xx_gpio3_resources[] = {
142 {
143 .start = OMAP7XX_GPIO3_BASE,
144 .end = OMAP7XX_GPIO3_BASE + SZ_2K - 1,
145 .flags = IORESOURCE_MEM,
146 },
147 {
148 .start = INT_7XX_GPIO_BANK3,
149 .flags = IORESOURCE_IRQ,
150 },
151};
152
153static struct __initdata omap_gpio_platform_data omap7xx_gpio3_config = {
154 .virtual_irq_start = IH_GPIO_BASE + 64,
155 .bank_type = METHOD_GPIO_7XX,
156 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700157 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800158};
159
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700160static struct platform_device omap7xx_gpio3 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800161 .name = "omap_gpio",
162 .id = 3,
163 .dev = {
164 .platform_data = &omap7xx_gpio3_config,
165 },
166 .num_resources = ARRAY_SIZE(omap7xx_gpio3_resources),
167 .resource = omap7xx_gpio3_resources,
168};
169
170/* gpio4 */
171static struct __initdata resource omap7xx_gpio4_resources[] = {
172 {
173 .start = OMAP7XX_GPIO4_BASE,
174 .end = OMAP7XX_GPIO4_BASE + SZ_2K - 1,
175 .flags = IORESOURCE_MEM,
176 },
177 {
178 .start = INT_7XX_GPIO_BANK4,
179 .flags = IORESOURCE_IRQ,
180 },
181};
182
183static struct __initdata omap_gpio_platform_data omap7xx_gpio4_config = {
184 .virtual_irq_start = IH_GPIO_BASE + 96,
185 .bank_type = METHOD_GPIO_7XX,
186 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700187 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800188};
189
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700190static struct platform_device omap7xx_gpio4 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800191 .name = "omap_gpio",
192 .id = 4,
193 .dev = {
194 .platform_data = &omap7xx_gpio4_config,
195 },
196 .num_resources = ARRAY_SIZE(omap7xx_gpio4_resources),
197 .resource = omap7xx_gpio4_resources,
198};
199
200/* gpio5 */
201static struct __initdata resource omap7xx_gpio5_resources[] = {
202 {
203 .start = OMAP7XX_GPIO5_BASE,
204 .end = OMAP7XX_GPIO5_BASE + SZ_2K - 1,
205 .flags = IORESOURCE_MEM,
206 },
207 {
208 .start = INT_7XX_GPIO_BANK5,
209 .flags = IORESOURCE_IRQ,
210 },
211};
212
213static struct __initdata omap_gpio_platform_data omap7xx_gpio5_config = {
214 .virtual_irq_start = IH_GPIO_BASE + 128,
215 .bank_type = METHOD_GPIO_7XX,
216 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700217 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800218};
219
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700220static struct platform_device omap7xx_gpio5 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800221 .name = "omap_gpio",
222 .id = 5,
223 .dev = {
224 .platform_data = &omap7xx_gpio5_config,
225 },
226 .num_resources = ARRAY_SIZE(omap7xx_gpio5_resources),
227 .resource = omap7xx_gpio5_resources,
228};
229
230/* gpio6 */
231static struct __initdata resource omap7xx_gpio6_resources[] = {
232 {
233 .start = OMAP7XX_GPIO6_BASE,
234 .end = OMAP7XX_GPIO6_BASE + SZ_2K - 1,
235 .flags = IORESOURCE_MEM,
236 },
237 {
238 .start = INT_7XX_GPIO_BANK6,
239 .flags = IORESOURCE_IRQ,
240 },
241};
242
243static struct __initdata omap_gpio_platform_data omap7xx_gpio6_config = {
244 .virtual_irq_start = IH_GPIO_BASE + 160,
245 .bank_type = METHOD_GPIO_7XX,
246 .bank_width = 32,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700247 .regs = &omap7xx_gpio_regs,
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800248};
249
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700250static struct platform_device omap7xx_gpio6 = {
Varadarajan, Charulatha9d523422010-12-07 16:26:56 -0800251 .name = "omap_gpio",
252 .id = 6,
253 .dev = {
254 .platform_data = &omap7xx_gpio6_config,
255 },
256 .num_resources = ARRAY_SIZE(omap7xx_gpio6_resources),
257 .resource = omap7xx_gpio6_resources,
258};
259
260static struct __initdata platform_device * omap7xx_gpio_dev[] = {
261 &omap7xx_mpu_gpio,
262 &omap7xx_gpio1,
263 &omap7xx_gpio2,
264 &omap7xx_gpio3,
265 &omap7xx_gpio4,
266 &omap7xx_gpio5,
267 &omap7xx_gpio6,
268};
269
270/*
271 * omap7xx_gpio_init needs to be done before
272 * machine_init functions access gpio APIs.
273 * Hence omap7xx_gpio_init is a postcore_initcall.
274 */
275static int __init omap7xx_gpio_init(void)
276{
277 int i;
278
279 if (!cpu_is_omap7xx())
280 return -EINVAL;
281
282 for (i = 0; i < ARRAY_SIZE(omap7xx_gpio_dev); i++)
283 platform_device_register(omap7xx_gpio_dev[i]);
284
285 gpio_bank_count = ARRAY_SIZE(omap7xx_gpio_dev);
286
287 return 0;
288}
289postcore_initcall(omap7xx_gpio_init);