1 /*
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 */
30 static 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 
42 static struct __initdata omap_gpio_platform_data omap7xx_mpu_gpio_config = {
43 	.virtual_irq_start	= IH_MPUIO_BASE,
44 	.bank_type		= METHOD_MPUIO,
45 	.bank_width		= 32,
46 	.bank_stride		= 2,
47 };
48 
49 static struct __initdata platform_device omap7xx_mpu_gpio = {
50 	.name           = "omap_gpio",
51 	.id             = 0,
52 	.dev            = {
53 		.platform_data = &omap7xx_mpu_gpio_config,
54 	},
55 	.num_resources = ARRAY_SIZE(omap7xx_mpu_gpio_resources),
56 	.resource = omap7xx_mpu_gpio_resources,
57 };
58 
59 /* gpio1 */
60 static struct __initdata resource omap7xx_gpio1_resources[] = {
61 	{
62 		.start	= OMAP7XX_GPIO1_BASE,
63 		.end	= OMAP7XX_GPIO1_BASE + SZ_2K - 1,
64 		.flags	= IORESOURCE_MEM,
65 	},
66 	{
67 		.start	= INT_7XX_GPIO_BANK1,
68 		.flags	= IORESOURCE_IRQ,
69 	},
70 };
71 
72 static struct __initdata omap_gpio_platform_data omap7xx_gpio1_config = {
73 	.virtual_irq_start	= IH_GPIO_BASE,
74 	.bank_type		= METHOD_GPIO_7XX,
75 	.bank_width		= 32,
76 };
77 
78 static struct __initdata platform_device omap7xx_gpio1 = {
79 	.name           = "omap_gpio",
80 	.id             = 1,
81 	.dev            = {
82 		.platform_data = &omap7xx_gpio1_config,
83 	},
84 	.num_resources = ARRAY_SIZE(omap7xx_gpio1_resources),
85 	.resource = omap7xx_gpio1_resources,
86 };
87 
88 /* gpio2 */
89 static struct __initdata resource omap7xx_gpio2_resources[] = {
90 	{
91 		.start	= OMAP7XX_GPIO2_BASE,
92 		.end	= OMAP7XX_GPIO2_BASE + SZ_2K - 1,
93 		.flags	= IORESOURCE_MEM,
94 	},
95 	{
96 		.start	= INT_7XX_GPIO_BANK2,
97 		.flags	= IORESOURCE_IRQ,
98 	},
99 };
100 
101 static struct __initdata omap_gpio_platform_data omap7xx_gpio2_config = {
102 	.virtual_irq_start	= IH_GPIO_BASE + 32,
103 	.bank_type		= METHOD_GPIO_7XX,
104 	.bank_width		= 32,
105 };
106 
107 static struct __initdata platform_device omap7xx_gpio2 = {
108 	.name           = "omap_gpio",
109 	.id             = 2,
110 	.dev            = {
111 		.platform_data = &omap7xx_gpio2_config,
112 	},
113 	.num_resources = ARRAY_SIZE(omap7xx_gpio2_resources),
114 	.resource = omap7xx_gpio2_resources,
115 };
116 
117 /* gpio3 */
118 static struct __initdata resource omap7xx_gpio3_resources[] = {
119 	{
120 		.start	= OMAP7XX_GPIO3_BASE,
121 		.end	= OMAP7XX_GPIO3_BASE + SZ_2K - 1,
122 		.flags	= IORESOURCE_MEM,
123 	},
124 	{
125 		.start	= INT_7XX_GPIO_BANK3,
126 		.flags	= IORESOURCE_IRQ,
127 	},
128 };
129 
130 static struct __initdata omap_gpio_platform_data omap7xx_gpio3_config = {
131 	.virtual_irq_start	= IH_GPIO_BASE + 64,
132 	.bank_type		= METHOD_GPIO_7XX,
133 	.bank_width		= 32,
134 };
135 
136 static struct __initdata platform_device omap7xx_gpio3 = {
137 	.name           = "omap_gpio",
138 	.id             = 3,
139 	.dev            = {
140 		.platform_data = &omap7xx_gpio3_config,
141 	},
142 	.num_resources = ARRAY_SIZE(omap7xx_gpio3_resources),
143 	.resource = omap7xx_gpio3_resources,
144 };
145 
146 /* gpio4 */
147 static struct __initdata resource omap7xx_gpio4_resources[] = {
148 	{
149 		.start	= OMAP7XX_GPIO4_BASE,
150 		.end	= OMAP7XX_GPIO4_BASE + SZ_2K - 1,
151 		.flags	= IORESOURCE_MEM,
152 	},
153 	{
154 		.start	= INT_7XX_GPIO_BANK4,
155 		.flags	= IORESOURCE_IRQ,
156 	},
157 };
158 
159 static struct __initdata omap_gpio_platform_data omap7xx_gpio4_config = {
160 	.virtual_irq_start	= IH_GPIO_BASE + 96,
161 	.bank_type		= METHOD_GPIO_7XX,
162 	.bank_width		= 32,
163 };
164 
165 static struct __initdata platform_device omap7xx_gpio4 = {
166 	.name           = "omap_gpio",
167 	.id             = 4,
168 	.dev            = {
169 		.platform_data = &omap7xx_gpio4_config,
170 	},
171 	.num_resources = ARRAY_SIZE(omap7xx_gpio4_resources),
172 	.resource = omap7xx_gpio4_resources,
173 };
174 
175 /* gpio5 */
176 static struct __initdata resource omap7xx_gpio5_resources[] = {
177 	{
178 		.start	= OMAP7XX_GPIO5_BASE,
179 		.end	= OMAP7XX_GPIO5_BASE + SZ_2K - 1,
180 		.flags	= IORESOURCE_MEM,
181 	},
182 	{
183 		.start	= INT_7XX_GPIO_BANK5,
184 		.flags	= IORESOURCE_IRQ,
185 	},
186 };
187 
188 static struct __initdata omap_gpio_platform_data omap7xx_gpio5_config = {
189 	.virtual_irq_start	= IH_GPIO_BASE + 128,
190 	.bank_type		= METHOD_GPIO_7XX,
191 	.bank_width		= 32,
192 };
193 
194 static struct __initdata platform_device omap7xx_gpio5 = {
195 	.name           = "omap_gpio",
196 	.id             = 5,
197 	.dev            = {
198 		.platform_data = &omap7xx_gpio5_config,
199 	},
200 	.num_resources = ARRAY_SIZE(omap7xx_gpio5_resources),
201 	.resource = omap7xx_gpio5_resources,
202 };
203 
204 /* gpio6 */
205 static struct __initdata resource omap7xx_gpio6_resources[] = {
206 	{
207 		.start	= OMAP7XX_GPIO6_BASE,
208 		.end	= OMAP7XX_GPIO6_BASE + SZ_2K - 1,
209 		.flags	= IORESOURCE_MEM,
210 	},
211 	{
212 		.start	= INT_7XX_GPIO_BANK6,
213 		.flags	= IORESOURCE_IRQ,
214 	},
215 };
216 
217 static struct __initdata omap_gpio_platform_data omap7xx_gpio6_config = {
218 	.virtual_irq_start	= IH_GPIO_BASE + 160,
219 	.bank_type		= METHOD_GPIO_7XX,
220 	.bank_width		= 32,
221 };
222 
223 static struct __initdata platform_device omap7xx_gpio6 = {
224 	.name           = "omap_gpio",
225 	.id             = 6,
226 	.dev            = {
227 		.platform_data = &omap7xx_gpio6_config,
228 	},
229 	.num_resources = ARRAY_SIZE(omap7xx_gpio6_resources),
230 	.resource = omap7xx_gpio6_resources,
231 };
232 
233 static struct __initdata platform_device * omap7xx_gpio_dev[] = {
234 	&omap7xx_mpu_gpio,
235 	&omap7xx_gpio1,
236 	&omap7xx_gpio2,
237 	&omap7xx_gpio3,
238 	&omap7xx_gpio4,
239 	&omap7xx_gpio5,
240 	&omap7xx_gpio6,
241 };
242 
243 /*
244  * omap7xx_gpio_init needs to be done before
245  * machine_init functions access gpio APIs.
246  * Hence omap7xx_gpio_init is a postcore_initcall.
247  */
omap7xx_gpio_init(void)248 static int __init omap7xx_gpio_init(void)
249 {
250 	int i;
251 
252 	if (!cpu_is_omap7xx())
253 		return -EINVAL;
254 
255 	for (i = 0; i < ARRAY_SIZE(omap7xx_gpio_dev); i++)
256 		platform_device_register(omap7xx_gpio_dev[i]);
257 
258 	gpio_bank_count = ARRAY_SIZE(omap7xx_gpio_dev);
259 
260 	return 0;
261 }
262 postcore_initcall(omap7xx_gpio_init);
263