blob: 86ac41544a21d91aa2e17b1b165c2235accb02f5 [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
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +053027/* smart idle, enable wakeup */
28#define SYSCONFIG_WORD 0x14
29
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080030/* mpu gpio */
31static struct __initdata resource omap16xx_mpu_gpio_resources[] = {
32 {
33 .start = OMAP1_MPUIO_VBASE,
34 .end = OMAP1_MPUIO_VBASE + SZ_2K - 1,
35 .flags = IORESOURCE_MEM,
36 },
37 {
38 .start = INT_MPUIO,
39 .flags = IORESOURCE_IRQ,
40 },
41};
42
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070043static struct omap_gpio_reg_offs omap16xx_mpuio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070044 .revision = USHRT_MAX,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070045 .direction = OMAP_MPUIO_IO_CNTL,
46 .datain = OMAP_MPUIO_INPUT_LATCH,
47 .dataout = OMAP_MPUIO_OUTPUT,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070048 .irqstatus = OMAP_MPUIO_GPIO_INT,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070049 .irqenable = OMAP_MPUIO_GPIO_MASKIT,
50 .irqenable_inv = true,
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +053051 .irqctrl = OMAP_MPUIO_GPIO_INT_EDGE,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070052};
53
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080054static struct __initdata omap_gpio_platform_data omap16xx_mpu_gpio_config = {
55 .virtual_irq_start = IH_MPUIO_BASE,
56 .bank_type = METHOD_MPUIO,
57 .bank_width = 16,
Tony Lindgren5de62b82010-12-07 16:26:58 -080058 .bank_stride = 1,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070059 .regs = &omap16xx_mpuio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080060};
61
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -070062static struct platform_device omap16xx_mpu_gpio = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -080063 .name = "omap_gpio",
64 .id = 0,
65 .dev = {
66 .platform_data = &omap16xx_mpu_gpio_config,
67 },
68 .num_resources = ARRAY_SIZE(omap16xx_mpu_gpio_resources),
69 .resource = omap16xx_mpu_gpio_resources,
70};
71
72/* gpio1 */
73static struct __initdata resource omap16xx_gpio1_resources[] = {
74 {
75 .start = OMAP1610_GPIO1_BASE,
76 .end = OMAP1610_GPIO1_BASE + SZ_2K - 1,
77 .flags = IORESOURCE_MEM,
78 },
79 {
80 .start = INT_GPIO_BANK1,
81 .flags = IORESOURCE_IRQ,
82 },
83};
84
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070085static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
Kevin Hilmane5ff4442011-04-22 14:37:16 -070086 .revision = OMAP1610_GPIO_REVISION,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070087 .direction = OMAP1610_GPIO_DIRECTION,
88 .set_dataout = OMAP1610_GPIO_SET_DATAOUT,
89 .clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
90 .datain = OMAP1610_GPIO_DATAIN,
91 .dataout = OMAP1610_GPIO_DATAOUT,
Kevin Hilmaneef4bec2011-04-21 09:17:35 -070092 .irqstatus = OMAP1610_GPIO_IRQSTATUS1,
Kevin Hilman28f3b5a2011-04-21 09:53:06 -070093 .irqenable = OMAP1610_GPIO_IRQENABLE1,
94 .set_irqenable = OMAP1610_GPIO_SET_IRQENABLE1,
95 .clr_irqenable = OMAP1610_GPIO_CLEAR_IRQENABLE1,
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +053096 .wkup_en = OMAP1610_GPIO_WAKEUPENABLE,
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +053097 .edgectrl1 = OMAP1610_GPIO_EDGE_CTRL1,
98 .edgectrl2 = OMAP1610_GPIO_EDGE_CTRL2,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070099};
100
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800101static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = {
102 .virtual_irq_start = IH_GPIO_BASE,
103 .bank_type = METHOD_GPIO_1610,
104 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700105 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800106};
107
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700108static struct platform_device omap16xx_gpio1 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800109 .name = "omap_gpio",
110 .id = 1,
111 .dev = {
112 .platform_data = &omap16xx_gpio1_config,
113 },
114 .num_resources = ARRAY_SIZE(omap16xx_gpio1_resources),
115 .resource = omap16xx_gpio1_resources,
116};
117
118/* gpio2 */
119static struct __initdata resource omap16xx_gpio2_resources[] = {
120 {
121 .start = OMAP1610_GPIO2_BASE,
122 .end = OMAP1610_GPIO2_BASE + SZ_2K - 1,
123 .flags = IORESOURCE_MEM,
124 },
125 {
126 .start = INT_1610_GPIO_BANK2,
127 .flags = IORESOURCE_IRQ,
128 },
129};
130
131static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = {
132 .virtual_irq_start = IH_GPIO_BASE + 16,
133 .bank_type = METHOD_GPIO_1610,
134 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700135 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800136};
137
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700138static struct platform_device omap16xx_gpio2 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800139 .name = "omap_gpio",
140 .id = 2,
141 .dev = {
142 .platform_data = &omap16xx_gpio2_config,
143 },
144 .num_resources = ARRAY_SIZE(omap16xx_gpio2_resources),
145 .resource = omap16xx_gpio2_resources,
146};
147
148/* gpio3 */
149static struct __initdata resource omap16xx_gpio3_resources[] = {
150 {
151 .start = OMAP1610_GPIO3_BASE,
152 .end = OMAP1610_GPIO3_BASE + SZ_2K - 1,
153 .flags = IORESOURCE_MEM,
154 },
155 {
156 .start = INT_1610_GPIO_BANK3,
157 .flags = IORESOURCE_IRQ,
158 },
159};
160
161static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = {
162 .virtual_irq_start = IH_GPIO_BASE + 32,
163 .bank_type = METHOD_GPIO_1610,
164 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700165 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800166};
167
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700168static struct platform_device omap16xx_gpio3 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800169 .name = "omap_gpio",
170 .id = 3,
171 .dev = {
172 .platform_data = &omap16xx_gpio3_config,
173 },
174 .num_resources = ARRAY_SIZE(omap16xx_gpio3_resources),
175 .resource = omap16xx_gpio3_resources,
176};
177
178/* gpio4 */
179static struct __initdata resource omap16xx_gpio4_resources[] = {
180 {
181 .start = OMAP1610_GPIO4_BASE,
182 .end = OMAP1610_GPIO4_BASE + SZ_2K - 1,
183 .flags = IORESOURCE_MEM,
184 },
185 {
186 .start = INT_1610_GPIO_BANK4,
187 .flags = IORESOURCE_IRQ,
188 },
189};
190
191static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = {
192 .virtual_irq_start = IH_GPIO_BASE + 48,
193 .bank_type = METHOD_GPIO_1610,
194 .bank_width = 16,
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700195 .regs = &omap16xx_gpio_regs,
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800196};
197
Janusz Krzysztofik07ad6ab2011-07-04 03:56:15 -0700198static struct platform_device omap16xx_gpio4 = {
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800199 .name = "omap_gpio",
200 .id = 4,
201 .dev = {
202 .platform_data = &omap16xx_gpio4_config,
203 },
204 .num_resources = ARRAY_SIZE(omap16xx_gpio4_resources),
205 .resource = omap16xx_gpio4_resources,
206};
207
208static struct __initdata platform_device * omap16xx_gpio_dev[] = {
209 &omap16xx_mpu_gpio,
210 &omap16xx_gpio1,
211 &omap16xx_gpio2,
212 &omap16xx_gpio3,
213 &omap16xx_gpio4,
214};
215
216/*
217 * omap16xx_gpio_init needs to be done before
218 * machine_init functions access gpio APIs.
219 * Hence omap16xx_gpio_init is a postcore_initcall.
220 */
221static int __init omap16xx_gpio_init(void)
222{
223 int i;
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530224 void __iomem *base;
225 struct resource *res;
226 struct platform_device *pdev;
227 struct omap_gpio_platform_data *pdata;
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800228
229 if (!cpu_is_omap16xx())
230 return -EINVAL;
231
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530232 for (i = 0; i < ARRAY_SIZE(omap16xx_gpio_dev); i++) {
233 pdev = omap16xx_gpio_dev[i];
234 pdata = pdev->dev.platform_data;
235
236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
237 if (unlikely(!res)) {
238 dev_err(&pdev->dev, "Invalid mem resource.\n");
239 return -ENODEV;
240 }
241
242 base = ioremap(res->start, resource_size(res));
243 if (unlikely(!base)) {
244 dev_err(&pdev->dev, "ioremap failed.\n");
245 return -ENOMEM;
246 }
247
248 __raw_writel(SYSCONFIG_WORD, base + OMAP1610_GPIO_SYSCONFIG);
249 iounmap(base);
250
251 /*
252 * Enable system clock for GPIO module.
253 * The CAM_CLK_CTRL *is* really the right place.
254 */
255 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04,
256 ULPD_CAM_CLK_CTRL);
257
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800258 platform_device_register(omap16xx_gpio_dev[i]);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530259 }
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800260
Varadarajan, Charulatha87fe6222010-12-07 16:26:56 -0800261 return 0;
262}
263postcore_initcall(omap16xx_gpio_init);