ARM: imx: dynamically allocate imx2-wdt devices
[pandora-kernel.git] / arch / arm / mach-imx / devices.c
1 /*
2  * Author: MontaVista Software, Inc.
3  *       <source@mvista.com>
4  *
5  * Based on the OMAP devices.c
6  *
7  * 2005 (c) MontaVista Software, Inc. This file is licensed under the
8  * terms of the GNU General Public License version 2. This program is
9  * licensed "as is" without any warranty of any kind, whether express
10  * or implied.
11  *
12  * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
13  * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
14  * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
15  * Copyright (c) 2008 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
16  * Copyright (c) 2008 Darius Augulis <darius.augulis@teltonika.lt>
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License
20  * as published by the Free Software Foundation; either version 2
21  * of the License, or (at your option) any later version.
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
30  * MA 02110-1301, USA.
31  */
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/platform_device.h>
36 #include <linux/gpio.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/serial.h>
39
40 #include <mach/irqs.h>
41 #include <mach/hardware.h>
42 #include <mach/common.h>
43 #include <mach/mmc.h>
44
45 #include "devices.h"
46
47 #if defined(CONFIG_ARCH_MX1)
48 /* GPIO port description */
49 static struct mxc_gpio_port imx_gpio_ports[] = {
50         {
51                 .chip.label = "gpio-0",
52                 .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR),
53                 .irq = MX1_GPIO_INT_PORTA,
54                 .virtual_irq_start = MXC_GPIO_IRQ_START,
55         }, {
56                 .chip.label = "gpio-1",
57                 .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x100),
58                 .irq = MX1_GPIO_INT_PORTB,
59                 .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
60         }, {
61                 .chip.label = "gpio-2",
62                 .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x200),
63                 .irq = MX1_GPIO_INT_PORTC,
64                 .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
65         }, {
66                 .chip.label = "gpio-3",
67                 .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x300),
68                 .irq = MX1_GPIO_INT_PORTD,
69                 .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
70         }
71 };
72
73 int __init imx1_register_gpios(void)
74 {
75         return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
76 }
77 #endif
78
79 #if defined(CONFIG_MACH_MX21) || defined(CONFIG_MACH_MX27)
80 /*
81  * lcdc:
82  * - i.MX1: the basic controller
83  * - i.MX21: to be checked
84  * - i.MX27: like i.MX1, with slightly variations
85  */
86 static struct resource mxc_fb[] = {
87         {
88                 .start = MX2x_LCDC_BASE_ADDR,
89                 .end = MX2x_LCDC_BASE_ADDR + SZ_4K - 1,
90                 .flags = IORESOURCE_MEM,
91         }, {
92                 .start = MX2x_INT_LCDC,
93                 .end = MX2x_INT_LCDC,
94                 .flags = IORESOURCE_IRQ,
95         }
96 };
97
98 /* mxc lcd driver */
99 struct platform_device mxc_fb_device = {
100         .name = "imx-fb",
101         .id = 0,
102         .num_resources = ARRAY_SIZE(mxc_fb),
103         .resource = mxc_fb,
104         .dev = {
105                 .coherent_dma_mask = DMA_BIT_MASK(32),
106         },
107 };
108
109 static struct resource mxc_pwm_resources[] = {
110         {
111                 .start = MX2x_PWM_BASE_ADDR,
112                 .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
113                 .flags = IORESOURCE_MEM,
114         }, {
115                 .start = MX2x_INT_PWM,
116                 .end = MX2x_INT_PWM,
117                 .flags = IORESOURCE_IRQ,
118         }
119 };
120
121 struct platform_device mxc_pwm_device = {
122         .name = "mxc_pwm",
123         .id = 0,
124         .num_resources = ARRAY_SIZE(mxc_pwm_resources),
125         .resource = mxc_pwm_resources,
126 };
127
128 #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq)                 \
129         static struct resource mxc_sdhc_resources ## n[] = {            \
130                 {                                                       \
131                         .start = baseaddr,                              \
132                         .end = baseaddr + SZ_4K - 1,                    \
133                         .flags = IORESOURCE_MEM,                        \
134                 }, {                                                    \
135                         .start = irq,                                   \
136                         .end = irq,                                     \
137                         .flags = IORESOURCE_IRQ,                        \
138                 }, {                                                    \
139                         .start = dmareq,                                \
140                         .end = dmareq,                                  \
141                         .flags = IORESOURCE_DMA,                        \
142                 },                                                      \
143         };                                                              \
144                                                                         \
145         static u64 mxc_sdhc ## n ## _dmamask = DMA_BIT_MASK(32);        \
146                                                                         \
147         struct platform_device mxc_sdhc_device ## n = {                 \
148                 .name = "mxc-mmc",                                      \
149                 .id = n,                                                \
150                 .dev = {                                                \
151                         .dma_mask = &mxc_sdhc ## n ## _dmamask,         \
152                         .coherent_dma_mask = DMA_BIT_MASK(32),          \
153                 },                                                      \
154                 .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n),   \
155                 .resource = mxc_sdhc_resources ## n,            \
156         }
157
158 DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
159 DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
160
161 #ifdef CONFIG_MACH_MX27
162 static struct resource otg_resources[] = {
163         {
164                 .start = MX27_USBOTG_BASE_ADDR,
165                 .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
166                 .flags = IORESOURCE_MEM,
167         }, {
168                 .start = MX27_INT_USB3,
169                 .end = MX27_INT_USB3,
170                 .flags = IORESOURCE_IRQ,
171         },
172 };
173
174 static u64 otg_dmamask = DMA_BIT_MASK(32);
175
176 /* OTG gadget device */
177 struct platform_device mxc_otg_udc_device = {
178         .name           = "fsl-usb2-udc",
179         .id             = -1,
180         .dev            = {
181                 .dma_mask               = &otg_dmamask,
182                 .coherent_dma_mask      = DMA_BIT_MASK(32),
183         },
184         .resource       = otg_resources,
185         .num_resources  = ARRAY_SIZE(otg_resources),
186 };
187
188 /* OTG host */
189 struct platform_device mxc_otg_host = {
190         .name = "mxc-ehci",
191         .id = 0,
192         .dev = {
193                 .coherent_dma_mask = DMA_BIT_MASK(32),
194                 .dma_mask = &otg_dmamask,
195         },
196         .resource = otg_resources,
197         .num_resources = ARRAY_SIZE(otg_resources),
198 };
199
200 /* USB host 1 */
201
202 static u64 usbh1_dmamask = DMA_BIT_MASK(32);
203
204 static struct resource mxc_usbh1_resources[] = {
205         {
206                 .start = MX27_USBOTG_BASE_ADDR + 0x200,
207                 .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
208                 .flags = IORESOURCE_MEM,
209         }, {
210                 .start = MX27_INT_USB1,
211                 .end = MX27_INT_USB1,
212                 .flags = IORESOURCE_IRQ,
213         },
214 };
215
216 struct platform_device mxc_usbh1 = {
217         .name = "mxc-ehci",
218         .id = 1,
219         .dev = {
220                 .coherent_dma_mask = DMA_BIT_MASK(32),
221                 .dma_mask = &usbh1_dmamask,
222         },
223         .resource = mxc_usbh1_resources,
224         .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
225 };
226
227 /* USB host 2 */
228 static u64 usbh2_dmamask = DMA_BIT_MASK(32);
229
230 static struct resource mxc_usbh2_resources[] = {
231         {
232                 .start = MX27_USBOTG_BASE_ADDR + 0x400,
233                 .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
234                 .flags = IORESOURCE_MEM,
235         }, {
236                 .start = MX27_INT_USB2,
237                 .end = MX27_INT_USB2,
238                 .flags = IORESOURCE_IRQ,
239         },
240 };
241
242 struct platform_device mxc_usbh2 = {
243         .name = "mxc-ehci",
244         .id = 2,
245         .dev = {
246                 .coherent_dma_mask = DMA_BIT_MASK(32),
247                 .dma_mask = &usbh2_dmamask,
248         },
249         .resource = mxc_usbh2_resources,
250         .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
251 };
252 #endif
253
254 /* GPIO port description */
255 #define DEFINE_MXC_GPIO_PORT_IRQ(SOC, n, _irq)                          \
256         {                                                               \
257                 .chip.label = "gpio-" #n,                               \
258                 .irq = _irq,                                            \
259                 .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR +        \
260                                 n * 0x100),                             \
261                 .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32,       \
262         }
263
264 #define DEFINE_MXC_GPIO_PORT(SOC, n)                                    \
265         {                                                               \
266                 .chip.label = "gpio-" #n,                               \
267                 .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR +        \
268                                 n * 0x100),                             \
269                 .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32,       \
270         }
271
272 #define DEFINE_MXC_GPIO_PORTS(SOC, pfx)                                 \
273         static struct mxc_gpio_port pfx ## _gpio_ports[] = {            \
274                 DEFINE_MXC_GPIO_PORT_IRQ(SOC, 0, SOC ## _INT_GPIO),     \
275                 DEFINE_MXC_GPIO_PORT(SOC, 1),                           \
276                 DEFINE_MXC_GPIO_PORT(SOC, 2),                           \
277                 DEFINE_MXC_GPIO_PORT(SOC, 3),                           \
278                 DEFINE_MXC_GPIO_PORT(SOC, 4),                           \
279                 DEFINE_MXC_GPIO_PORT(SOC, 5),                           \
280         }
281
282 #ifdef CONFIG_MACH_MX21
283 DEFINE_MXC_GPIO_PORTS(MX21, imx21);
284
285 int __init imx21_register_gpios(void)
286 {
287         return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
288 }
289 #endif
290
291 #ifdef CONFIG_MACH_MX27
292 DEFINE_MXC_GPIO_PORTS(MX27, imx27);
293
294 int __init imx27_register_gpios(void)
295 {
296         return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
297 }
298 #endif
299
300 #ifdef CONFIG_MACH_MX21
301 static struct resource mx21_usbhc_resources[] = {
302         {
303                 .start  = MX21_USBOTG_BASE_ADDR,
304                 .end    = MX21_USBOTG_BASE_ADDR + SZ_8K - 1,
305                 .flags  = IORESOURCE_MEM,
306         },
307         {
308                 .start          = MX21_INT_USBHOST,
309                 .end            = MX21_INT_USBHOST,
310                 .flags          = IORESOURCE_IRQ,
311         },
312 };
313
314 struct platform_device mx21_usbhc_device = {
315         .name           = "imx21-hcd",
316         .id             = 0,
317         .dev            = {
318                 .dma_mask = &mx21_usbhc_device.dev.coherent_dma_mask,
319                 .coherent_dma_mask = DMA_BIT_MASK(32),
320         },
321         .num_resources  = ARRAY_SIZE(mx21_usbhc_resources),
322         .resource       = mx21_usbhc_resources,
323 };
324 #endif
325
326 static struct resource imx_kpp_resources[] = {
327         {
328                 .start  = MX2x_KPP_BASE_ADDR,
329                 .end    = MX2x_KPP_BASE_ADDR + 0xf,
330                 .flags  = IORESOURCE_MEM
331         }, {
332                 .start  = MX2x_INT_KPP,
333                 .end    = MX2x_INT_KPP,
334                 .flags  = IORESOURCE_IRQ,
335         },
336 };
337
338 struct platform_device imx_kpp_device = {
339         .name = "imx-keypad",
340         .id = -1,
341         .num_resources = ARRAY_SIZE(imx_kpp_resources),
342         .resource = imx_kpp_resources,
343 };
344
345 #endif