blob: 0f399bd0e70e7be70ee1eebc2603f8f877c63f4f [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,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070092};
93
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080094static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = {
95 .virtual_irq_start = IH_GPIO_BASE,
96 .bank_type = METHOD_GPIO_1610,
97 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070098 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080099};
100
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700101static struct platform_device omap16xx_gpio1 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800102 .name = "omap_gpio",
103 .id = 1,
104 .dev = {
105 .platform_data = &omap16xx_gpio1_config,
106 },
107 .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
108 .resource = omap16xx_gpio1_resources,
109};
110
111/* gpio2 */
112static struct __initdata resource omap16xx_gpio2_resources[] = {
113 {
114 .start = OMAP1610_GPIO2_BASE,
115 .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
116 .flags = IORESOURCE_MEM,
117 },
118 {
119 .start = INT_1610_GPIO_BANK2,
120 .flags = IORESOURCE_IRQ,
121 },
122};
123
124static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = {
125 .virtual_irq_start = IH_GPIO_BASE + 16,
126 .bank_type = METHOD_GPIO_1610,
127 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700128 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800129};
130
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700131static struct platform_device omap16xx_gpio2 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800132 .name = "omap_gpio",
133 .id = 2,
134 .dev = {
135 .platform_data = &omap16xx_gpio2_config,
136 },
137 .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
138 .resource = omap16xx_gpio2_resources,
139};
140
141/* gpio3 */
142static struct __initdata resource omap16xx_gpio3_resources[] = {
143 {
144 .start = OMAP1610_GPIO3_BASE,
145 .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
146 .flags = IORESOURCE_MEM,
147 },
148 {
149 .start = INT_1610_GPIO_BANK3,
150 .flags = IORESOURCE_IRQ,
151 },
152};
153
154static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = {
155 .virtual_irq_start = IH_GPIO_BASE + 32,
156 .bank_type = METHOD_GPIO_1610,
157 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700158 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800159};
160
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700161static struct platform_device omap16xx_gpio3 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800162 .name = "omap_gpio",
163 .id = 3,
164 .dev = {
165 .platform_data = &omap16xx_gpio3_config,
166 },
167 .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
168 .resource = omap16xx_gpio3_resources,
169};
170
171/* gpio4 */
172static struct __initdata resource omap16xx_gpio4_resources[] = {
173 {
174 .start = OMAP1610_GPIO4_BASE,
175 .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
176 .flags = IORESOURCE_MEM,
177 },
178 {
179 .start = INT_1610_GPIO_BANK4,
180 .flags = IORESOURCE_IRQ,
181 },
182};
183
184static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = {
185 .virtual_irq_start = IH_GPIO_BASE + 48,
186 .bank_type = METHOD_GPIO_1610,
187 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700188 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800189};
190
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700191static struct platform_device omap16xx_gpio4 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800192 .name = "omap_gpio",
193 .id = 4,
194 .dev = {
195 .platform_data = &omap16xx_gpio4_config,
196 },
197 .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
198 .resource = omap16xx_gpio4_resources,
199};
200
201static struct __initdata platform_device * omap16xx_gpio_dev[] = {
202 &omap16xx_mpu_gpio,
203 &omap16xx_gpio1,
204 &omap16xx_gpio2,
205 &omap16xx_gpio3,
206 &omap16xx_gpio4,
207};
208
209/*
210 * omap16xx_gpio_init needs to be done before
211 * machine_init functions access gpio APIs.
212 * Hence omap16xx_gpio_init is a postcore_initcall.
213 */
214static int __init omap16xx_gpio_init(void)
215{
216 int i;
217
218 if (!cpu_is_omap16xx())
219 return -EINVAL;
220
221 for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++)
222 platform_device_register(omap16xx_gpio_dev[i]);
223
224 gpio_bank_count = ARRAY_SIZE(omap16xx_gpio_dev);
225
226 return 0;
227}
228postcore_initcall(omap16xx_gpio_init);