blob: 1eb47e2760d8aa3a878833c7ac7af1f3609c6ecc [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,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070048};
49
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080050static struct __initdata omap_gpio_platform_data omap16xx_mpu_gpio_config = {
51 .virtual_irq_start = IH_MPUIO_BASE,
52 .bank_type = METHOD_MPUIO,
53 .bank_width = 16,
Tony Lindgren5de62b82010-12-07 16:26:58 -080054 .bank_stride = 1,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070055 .regs = &omap16xx_mpuio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080056};
57
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -070058static struct platform_device omap16xx_mpu_gpio = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080059 .name = "omap_gpio",
60 .id = 0,
61 .dev = {
62 .platform_data = &omap16xx_mpu_gpio_config,
63 },
64 .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources),
65 .resource = omap16xx_mpu_gpio_resources,
66};
67
68/* gpio1 */
69static struct __initdata resource omap16xx_gpio1_resources[] = {
70 {
71 .start = OMAP1610_GPIO1_BASE,
72 .end = OMAP1610_GPIO1_BASE + SZ_2K - 1,
73 .flags = IORESOURCE_MEM,
74 },
75 {
76 .start = INT_GPIO_BANK1,
77 .flags = IORESOURCE_IRQ,
78 },
79};
80
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070081static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070082 .revision = OMAP1610_GPIO_REVISION,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070083 .direction = OMAP1610_GPIO_DIRECTION,
84 .set_dataout = OMAP1610_GPIO_SET_DATAOUT,
85 .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
86 .datain = OMAP1610_GPIO_DATAIN,
87 .dataout = OMAP1610_GPIO_DATAOUT,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070088 .irqstatus = OMAP1610_GPIO_IRQSTATUS1,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070089 .irqenable = OMAP1610_GPIO_IRQENABLE1,
90 .set_irqenable = OMAP1610_GPIO_SET_IRQENABLE1,
91 .clr_irqenable = OMAP1610_GPIO_CLEAR_IRQENABLE1,
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +053092 .wkup_en = OMAP1610_GPIO_WAKEUPENABLE,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070093};
94
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080095static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = {
96 .virtual_irq_start = IH_GPIO_BASE,
97 .bank_type = METHOD_GPIO_1610,
98 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070099 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800100};
101
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700102static struct platform_device omap16xx_gpio1 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800103 .name = "omap_gpio",
104 .id = 1,
105 .dev = {
106 .platform_data = &omap16xx_gpio1_config,
107 },
108 .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
109 .resource = omap16xx_gpio1_resources,
110};
111
112/* gpio2 */
113static struct __initdata resource omap16xx_gpio2_resources[] = {
114 {
115 .start = OMAP1610_GPIO2_BASE,
116 .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
117 .flags = IORESOURCE_MEM,
118 },
119 {
120 .start = INT_1610_GPIO_BANK2,
121 .flags = IORESOURCE_IRQ,
122 },
123};
124
125static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = {
126 .virtual_irq_start = IH_GPIO_BASE + 16,
127 .bank_type = METHOD_GPIO_1610,
128 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700129 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800130};
131
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700132static struct platform_device omap16xx_gpio2 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800133 .name = "omap_gpio",
134 .id = 2,
135 .dev = {
136 .platform_data = &omap16xx_gpio2_config,
137 },
138 .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
139 .resource = omap16xx_gpio2_resources,
140};
141
142/* gpio3 */
143static struct __initdata resource omap16xx_gpio3_resources[] = {
144 {
145 .start = OMAP1610_GPIO3_BASE,
146 .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
147 .flags = IORESOURCE_MEM,
148 },
149 {
150 .start = INT_1610_GPIO_BANK3,
151 .flags = IORESOURCE_IRQ,
152 },
153};
154
155static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = {
156 .virtual_irq_start = IH_GPIO_BASE + 32,
157 .bank_type = METHOD_GPIO_1610,
158 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700159 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800160};
161
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700162static struct platform_device omap16xx_gpio3 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800163 .name = "omap_gpio",
164 .id = 3,
165 .dev = {
166 .platform_data = &omap16xx_gpio3_config,
167 },
168 .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
169 .resource = omap16xx_gpio3_resources,
170};
171
172/* gpio4 */
173static struct __initdata resource omap16xx_gpio4_resources[] = {
174 {
175 .start = OMAP1610_GPIO4_BASE,
176 .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
177 .flags = IORESOURCE_MEM,
178 },
179 {
180 .start = INT_1610_GPIO_BANK4,
181 .flags = IORESOURCE_IRQ,
182 },
183};
184
185static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = {
186 .virtual_irq_start = IH_GPIO_BASE + 48,
187 .bank_type = METHOD_GPIO_1610,
188 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700189 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800190};
191
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700192static struct platform_device omap16xx_gpio4 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800193 .name = "omap_gpio",
194 .id = 4,
195 .dev = {
196 .platform_data = &omap16xx_gpio4_config,
197 },
198 .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
199 .resource = omap16xx_gpio4_resources,
200};
201
202static struct __initdata platform_device * omap16xx_gpio_dev[] = {
203 &omap16xx_mpu_gpio,
204 &omap16xx_gpio1,
205 &omap16xx_gpio2,
206 &omap16xx_gpio3,
207 &omap16xx_gpio4,
208};
209
210/*
211 * omap16xx_gpio_init needs to be done before
212 * machine_init functions access gpio APIs.
213 * Hence omap16xx_gpio_init is a postcore_initcall.
214 */
215static int __init omap16xx_gpio_init(void)
216{
217 int i;
218
219 if (!cpu_is_omap16xx())
220 return -EINVAL;
221
222 for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++)
223 platform_device_register(omap16xx_gpio_dev[i]);
224
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800225 return 0;
226}
227postcore_initcall(omap16xx_gpio_init);