GNU Linux-libre 5.19-rc6-gnu
[releases.git] / arch / arm / mach-omap1 / gpio7xx.c
1 /*
2  * OMAP7xx specific gpio init
3  *
4  * Copyright (C) 2010 Texas Instruments Incorporated - https://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 #include <linux/platform_data/gpio-omap.h>
21
22 #include "irqs.h"
23 #include "soc.h"
24
25 #define OMAP7XX_GPIO1_BASE              0xfffbc000
26 #define OMAP7XX_GPIO2_BASE              0xfffbc800
27 #define OMAP7XX_GPIO3_BASE              0xfffbd000
28 #define OMAP7XX_GPIO4_BASE              0xfffbd800
29 #define OMAP7XX_GPIO5_BASE              0xfffbe000
30 #define OMAP7XX_GPIO6_BASE              0xfffbe800
31 #define OMAP1_MPUIO_VBASE               OMAP1_MPUIO_BASE
32
33 /* mpu gpio */
34 static struct resource omap7xx_mpu_gpio_resources[] = {
35         {
36                 .start  = OMAP1_MPUIO_VBASE,
37                 .end    = OMAP1_MPUIO_VBASE + SZ_2K - 1,
38                 .flags  = IORESOURCE_MEM,
39         },
40         {
41                 .start  = INT_7XX_MPUIO,
42                 .flags  = IORESOURCE_IRQ,
43         },
44 };
45
46 static struct omap_gpio_reg_offs omap7xx_mpuio_regs = {
47         .revision       = USHRT_MAX,
48         .direction      = OMAP_MPUIO_IO_CNTL / 2,
49         .datain         = OMAP_MPUIO_INPUT_LATCH / 2,
50         .dataout        = OMAP_MPUIO_OUTPUT / 2,
51         .irqstatus      = OMAP_MPUIO_GPIO_INT / 2,
52         .irqenable      = OMAP_MPUIO_GPIO_MASKIT / 2,
53         .irqenable_inv  = true,
54         .irqctrl        = OMAP_MPUIO_GPIO_INT_EDGE >> 1,
55 };
56
57 static struct omap_gpio_platform_data omap7xx_mpu_gpio_config = {
58         .is_mpuio               = true,
59         .bank_width             = 16,
60         .bank_stride            = 2,
61         .regs                   = &omap7xx_mpuio_regs,
62 };
63
64 static struct platform_device omap7xx_mpu_gpio = {
65         .name           = "omap_gpio",
66         .id             = 0,
67         .dev            = {
68                 .platform_data = &omap7xx_mpu_gpio_config,
69         },
70         .num_resources = ARRAY_SIZE(omap7xx_mpu_gpio_resources),
71         .resource = omap7xx_mpu_gpio_resources,
72 };
73
74 /* gpio1 */
75 static struct resource omap7xx_gpio1_resources[] = {
76         {
77                 .start  = OMAP7XX_GPIO1_BASE,
78                 .end    = OMAP7XX_GPIO1_BASE + SZ_2K - 1,
79                 .flags  = IORESOURCE_MEM,
80         },
81         {
82                 .start  = INT_7XX_GPIO_BANK1,
83                 .flags  = IORESOURCE_IRQ,
84         },
85 };
86
87 static struct omap_gpio_reg_offs omap7xx_gpio_regs = {
88         .revision       = USHRT_MAX,
89         .direction      = OMAP7XX_GPIO_DIR_CONTROL,
90         .datain         = OMAP7XX_GPIO_DATA_INPUT,
91         .dataout        = OMAP7XX_GPIO_DATA_OUTPUT,
92         .irqstatus      = OMAP7XX_GPIO_INT_STATUS,
93         .irqenable      = OMAP7XX_GPIO_INT_MASK,
94         .irqenable_inv  = true,
95         .irqctrl        = OMAP7XX_GPIO_INT_CONTROL,
96 };
97
98 static struct omap_gpio_platform_data omap7xx_gpio1_config = {
99         .bank_width             = 32,
100         .regs                   = &omap7xx_gpio_regs,
101 };
102
103 static struct platform_device omap7xx_gpio1 = {
104         .name           = "omap_gpio",
105         .id             = 1,
106         .dev            = {
107                 .platform_data = &omap7xx_gpio1_config,
108         },
109         .num_resources = ARRAY_SIZE(omap7xx_gpio1_resources),
110         .resource = omap7xx_gpio1_resources,
111 };
112
113 /* gpio2 */
114 static struct resource omap7xx_gpio2_resources[] = {
115         {
116                 .start  = OMAP7XX_GPIO2_BASE,
117                 .end    = OMAP7XX_GPIO2_BASE + SZ_2K - 1,
118                 .flags  = IORESOURCE_MEM,
119         },
120         {
121                 .start  = INT_7XX_GPIO_BANK2,
122                 .flags  = IORESOURCE_IRQ,
123         },
124 };
125
126 static struct omap_gpio_platform_data omap7xx_gpio2_config = {
127         .bank_width             = 32,
128         .regs                   = &omap7xx_gpio_regs,
129 };
130
131 static struct platform_device omap7xx_gpio2 = {
132         .name           = "omap_gpio",
133         .id             = 2,
134         .dev            = {
135                 .platform_data = &omap7xx_gpio2_config,
136         },
137         .num_resources = ARRAY_SIZE(omap7xx_gpio2_resources),
138         .resource = omap7xx_gpio2_resources,
139 };
140
141 /* gpio3 */
142 static struct resource omap7xx_gpio3_resources[] = {
143         {
144                 .start  = OMAP7XX_GPIO3_BASE,
145                 .end    = OMAP7XX_GPIO3_BASE + SZ_2K - 1,
146                 .flags  = IORESOURCE_MEM,
147         },
148         {
149                 .start  = INT_7XX_GPIO_BANK3,
150                 .flags  = IORESOURCE_IRQ,
151         },
152 };
153
154 static struct omap_gpio_platform_data omap7xx_gpio3_config = {
155         .bank_width             = 32,
156         .regs                   = &omap7xx_gpio_regs,
157 };
158
159 static struct platform_device omap7xx_gpio3 = {
160         .name           = "omap_gpio",
161         .id             = 3,
162         .dev            = {
163                 .platform_data = &omap7xx_gpio3_config,
164         },
165         .num_resources = ARRAY_SIZE(omap7xx_gpio3_resources),
166         .resource = omap7xx_gpio3_resources,
167 };
168
169 /* gpio4 */
170 static struct resource omap7xx_gpio4_resources[] = {
171         {
172                 .start  = OMAP7XX_GPIO4_BASE,
173                 .end    = OMAP7XX_GPIO4_BASE + SZ_2K - 1,
174                 .flags  = IORESOURCE_MEM,
175         },
176         {
177                 .start  = INT_7XX_GPIO_BANK4,
178                 .flags  = IORESOURCE_IRQ,
179         },
180 };
181
182 static struct omap_gpio_platform_data omap7xx_gpio4_config = {
183         .bank_width             = 32,
184         .regs                   = &omap7xx_gpio_regs,
185 };
186
187 static struct platform_device omap7xx_gpio4 = {
188         .name           = "omap_gpio",
189         .id             = 4,
190         .dev            = {
191                 .platform_data = &omap7xx_gpio4_config,
192         },
193         .num_resources = ARRAY_SIZE(omap7xx_gpio4_resources),
194         .resource = omap7xx_gpio4_resources,
195 };
196
197 /* gpio5 */
198 static struct resource omap7xx_gpio5_resources[] = {
199         {
200                 .start  = OMAP7XX_GPIO5_BASE,
201                 .end    = OMAP7XX_GPIO5_BASE + SZ_2K - 1,
202                 .flags  = IORESOURCE_MEM,
203         },
204         {
205                 .start  = INT_7XX_GPIO_BANK5,
206                 .flags  = IORESOURCE_IRQ,
207         },
208 };
209
210 static struct omap_gpio_platform_data omap7xx_gpio5_config = {
211         .bank_width             = 32,
212         .regs                   = &omap7xx_gpio_regs,
213 };
214
215 static struct platform_device omap7xx_gpio5 = {
216         .name           = "omap_gpio",
217         .id             = 5,
218         .dev            = {
219                 .platform_data = &omap7xx_gpio5_config,
220         },
221         .num_resources = ARRAY_SIZE(omap7xx_gpio5_resources),
222         .resource = omap7xx_gpio5_resources,
223 };
224
225 /* gpio6 */
226 static struct resource omap7xx_gpio6_resources[] = {
227         {
228                 .start  = OMAP7XX_GPIO6_BASE,
229                 .end    = OMAP7XX_GPIO6_BASE + SZ_2K - 1,
230                 .flags  = IORESOURCE_MEM,
231         },
232         {
233                 .start  = INT_7XX_GPIO_BANK6,
234                 .flags  = IORESOURCE_IRQ,
235         },
236 };
237
238 static struct omap_gpio_platform_data omap7xx_gpio6_config = {
239         .bank_width             = 32,
240         .regs                   = &omap7xx_gpio_regs,
241 };
242
243 static struct platform_device omap7xx_gpio6 = {
244         .name           = "omap_gpio",
245         .id             = 6,
246         .dev            = {
247                 .platform_data = &omap7xx_gpio6_config,
248         },
249         .num_resources = ARRAY_SIZE(omap7xx_gpio6_resources),
250         .resource = omap7xx_gpio6_resources,
251 };
252
253 static struct platform_device *omap7xx_gpio_dev[] __initdata = {
254         &omap7xx_mpu_gpio,
255         &omap7xx_gpio1,
256         &omap7xx_gpio2,
257         &omap7xx_gpio3,
258         &omap7xx_gpio4,
259         &omap7xx_gpio5,
260         &omap7xx_gpio6,
261 };
262
263 /*
264  * omap7xx_gpio_init needs to be done before
265  * machine_init functions access gpio APIs.
266  * Hence omap7xx_gpio_init is a postcore_initcall.
267  */
268 static int __init omap7xx_gpio_init(void)
269 {
270         int i;
271
272         if (!cpu_is_omap7xx())
273                 return -EINVAL;
274
275         for (i = 0; i < ARRAY_SIZE(omap7xx_gpio_dev); i++)
276                 platform_device_register(omap7xx_gpio_dev[i]);
277
278         return 0;
279 }
280 postcore_initcall(omap7xx_gpio_init);