blob: 46bb57a8cb7dcd56b582c63c7b9557bf06fbafb9 [file] [log] [blame]
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -08001/*
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
19#include <linux/gpio.h>
20
21#define OMAP1610_GPIO1_BASE 0xfffbe400
22#define OMAP1610_GPIO2_BASE 0xfffbec00
23#define OMAP1610_GPIO3_BASE 0xfffbb400
24#define OMAP1610_GPIO4_BASE 0xfffbbc00
25#define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
26
27/* mpu gpio */
28static struct __initdata resource omap16xx_mpu_gpio_resources[] = {
29 {
30 .start = OMAP1_MPUIO_VBASE,
31 .end = OMAP1_MPUIO_VBASE + SZ_2K - 1,
32 .flags = IORESOURCE_MEM,
33 },
34 {
35 .start = INT_MPUIO,
36 .flags = IORESOURCE_IRQ,
37 },
38};
39
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070040static struct omap_gpio_reg_offs omap16xx_mpuio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070041 .revision = USHRT_MAX,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070042 .direction = OMAP_MPUIO_IO_CNTL,
43 .datain = OMAP_MPUIO_INPUT_LATCH,
44 .dataout = OMAP_MPUIO_OUTPUT,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070045 .irqstatus = OMAP_MPUIO_GPIO_INT,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070046 .irqenable = OMAP_MPUIO_GPIO_MASKIT,
47 .irqenable_inv = true,
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +053048 .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070049};
50
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080051static struct __initdata omap_gpio_platform_data omap16xx_mpu_gpio_config = {
52 .virtual_irq_start = IH_MPUIO_BASE,
53 .bank_type = METHOD_MPUIO,
54 .bank_width = 16,
Tony Lindgren5de62b82010-12-07 16:26:58 -080055 .bank_stride = 1,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070056 .regs = &omap16xx_mpuio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080057};
58
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -070059static struct platform_device omap16xx_mpu_gpio = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080060 .name = "omap_gpio",
61 .id = 0,
62 .dev = {
63 .platform_data = &omap16xx_mpu_gpio_config,
64 },
65 .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources),
66 .resource = omap16xx_mpu_gpio_resources,
67};
68
69/* gpio1 */
70static struct __initdata resource omap16xx_gpio1_resources[] = {
71 {
72 .start = OMAP1610_GPIO1_BASE,
73 .end = OMAP1610_GPIO1_BASE + SZ_2K - 1,
74 .flags = IORESOURCE_MEM,
75 },
76 {
77 .start = INT_GPIO_BANK1,
78 .flags = IORESOURCE_IRQ,
79 },
80};
81
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070082static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070083 .revision = OMAP1610_GPIO_REVISION,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070084 .direction = OMAP1610_GPIO_DIRECTION,
85 .set_dataout = OMAP1610_GPIO_SET_DATAOUT,
86 .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
87 .datain = OMAP1610_GPIO_DATAIN,
88 .dataout = OMAP1610_GPIO_DATAOUT,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070089 .irqstatus = OMAP1610_GPIO_IRQSTATUS1,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070090 .irqenable = OMAP1610_GPIO_IRQENABLE1,
91 .set_irqenable = OMAP1610_GPIO_SET_IRQENABLE1,
92 .clr_irqenable = OMAP1610_GPIO_CLEAR_IRQENABLE1,
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +053093 .wkup_en = OMAP1610_GPIO_WAKEUPENABLE,
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +053094 .edgectrl1 = OMAP1610_GPIO_EDGE_CTRL1,
95 .edgectrl2 = OMAP1610_GPIO_EDGE_CTRL2,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070096};
97
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080098static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = {
99 .virtual_irq_start = IH_GPIO_BASE,
100 .bank_type = METHOD_GPIO_1610,
101 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700102 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800103};
104
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700105static struct platform_device omap16xx_gpio1 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800106 .name = "omap_gpio",
107 .id = 1,
108 .dev = {
109 .platform_data = &omap16xx_gpio1_config,
110 },
111 .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
112 .resource = omap16xx_gpio1_resources,
113};
114
115/* gpio2 */
116static struct __initdata resource omap16xx_gpio2_resources[] = {
117 {
118 .start = OMAP1610_GPIO2_BASE,
119 .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
120 .flags = IORESOURCE_MEM,
121 },
122 {
123 .start = INT_1610_GPIO_BANK2,
124 .flags = IORESOURCE_IRQ,
125 },
126};
127
128static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = {
129 .virtual_irq_start = IH_GPIO_BASE + 16,
130 .bank_type = METHOD_GPIO_1610,
131 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700132 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800133};
134
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700135static struct platform_device omap16xx_gpio2 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800136 .name = "omap_gpio",
137 .id = 2,
138 .dev = {
139 .platform_data = &omap16xx_gpio2_config,
140 },
141 .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
142 .resource = omap16xx_gpio2_resources,
143};
144
145/* gpio3 */
146static struct __initdata resource omap16xx_gpio3_resources[] = {
147 {
148 .start = OMAP1610_GPIO3_BASE,
149 .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
150 .flags = IORESOURCE_MEM,
151 },
152 {
153 .start = INT_1610_GPIO_BANK3,
154 .flags = IORESOURCE_IRQ,
155 },
156};
157
158static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = {
159 .virtual_irq_start = IH_GPIO_BASE + 32,
160 .bank_type = METHOD_GPIO_1610,
161 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700162 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800163};
164
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700165static struct platform_device omap16xx_gpio3 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800166 .name = "omap_gpio",
167 .id = 3,
168 .dev = {
169 .platform_data = &omap16xx_gpio3_config,
170 },
171 .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
172 .resource = omap16xx_gpio3_resources,
173};
174
175/* gpio4 */
176static struct __initdata resource omap16xx_gpio4_resources[] = {
177 {
178 .start = OMAP1610_GPIO4_BASE,
179 .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
180 .flags = IORESOURCE_MEM,
181 },
182 {
183 .start = INT_1610_GPIO_BANK4,
184 .flags = IORESOURCE_IRQ,
185 },
186};
187
188static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = {
189 .virtual_irq_start = IH_GPIO_BASE + 48,
190 .bank_type = METHOD_GPIO_1610,
191 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700192 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800193};
194
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700195static struct platform_device omap16xx_gpio4 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800196 .name = "omap_gpio",
197 .id = 4,
198 .dev = {
199 .platform_data = &omap16xx_gpio4_config,
200 },
201 .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
202 .resource = omap16xx_gpio4_resources,
203};
204
205static struct __initdata platform_device * omap16xx_gpio_dev[] = {
206 &omap16xx_mpu_gpio,
207 &omap16xx_gpio1,
208 &omap16xx_gpio2,
209 &omap16xx_gpio3,
210 &omap16xx_gpio4,
211};
212
213/*
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.
217 */
218static int __init omap16xx_gpio_init(void)
219{
220 int i;
221
222 if (!cpu_is_omap16xx())
223 return -EINVAL;
224
225 for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++)
226 platform_device_register(omap16xx_gpio_dev[i]);
227
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800228 return 0;
229}
230postcore_initcall(omap16xx_gpio_init);