ARM: imx: dynamically allocate mx1-camera device
[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 #ifdef CONFIG_MACH_MX27
82 static struct resource mx27_camera_resources[] = {
83         {
84                .start = MX27_CSI_BASE_ADDR,
85                .end = MX27_CSI_BASE_ADDR + 0x1f,
86                .flags = IORESOURCE_MEM,
87         }, {
88                .start = MX27_EMMA_PRP_BASE_ADDR,
89                .end = MX27_EMMA_PRP_BASE_ADDR + 0x1f,
90                .flags = IORESOURCE_MEM,
91         }, {
92                .start = MX27_INT_CSI,
93                .end = MX27_INT_CSI,
94                .flags = IORESOURCE_IRQ,
95         },{
96                .start = MX27_INT_EMMAPRP,
97                .end = MX27_INT_EMMAPRP,
98                .flags = IORESOURCE_IRQ,
99         },
100 };
101 struct platform_device mx27_camera_device = {
102         .name = "mx2-camera",
103         .id = 0,
104         .num_resources = ARRAY_SIZE(mx27_camera_resources),
105         .resource = mx27_camera_resources,
106         .dev = {
107                 .coherent_dma_mask = 0xffffffff,
108         },
109 };
110 #endif
111
112 /* Watchdog: i.MX1 has seperate driver, i.MX21 and i.MX27 are equal */
113 static struct resource mxc_wdt_resources[] = {
114         {
115                 .start = MX2x_WDOG_BASE_ADDR,
116                 .end = MX2x_WDOG_BASE_ADDR + SZ_4K - 1,
117                 .flags = IORESOURCE_MEM,
118         },
119 };
120
121 struct platform_device mxc_wdt = {
122         .name = "imx2-wdt",
123         .id = 0,
124         .num_resources = ARRAY_SIZE(mxc_wdt_resources),
125         .resource = mxc_wdt_resources,
126 };
127
128 /*
129  * lcdc:
130  * - i.MX1: the basic controller
131  * - i.MX21: to be checked
132  * - i.MX27: like i.MX1, with slightly variations
133  */
134 static struct resource mxc_fb[] = {
135         {
136                 .start = MX2x_LCDC_BASE_ADDR,
137                 .end = MX2x_LCDC_BASE_ADDR + SZ_4K - 1,
138                 .flags = IORESOURCE_MEM,
139         }, {
140                 .start = MX2x_INT_LCDC,
141                 .end = MX2x_INT_LCDC,
142                 .flags = IORESOURCE_IRQ,
143         }
144 };
145
146 /* mxc lcd driver */
147 struct platform_device mxc_fb_device = {
148         .name = "imx-fb",
149         .id = 0,
150         .num_resources = ARRAY_SIZE(mxc_fb),
151         .resource = mxc_fb,
152         .dev = {
153                 .coherent_dma_mask = DMA_BIT_MASK(32),
154         },
155 };
156
157 static struct resource mxc_pwm_resources[] = {
158         {
159                 .start = MX2x_PWM_BASE_ADDR,
160                 .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
161                 .flags = IORESOURCE_MEM,
162         }, {
163                 .start = MX2x_INT_PWM,
164                 .end = MX2x_INT_PWM,
165                 .flags = IORESOURCE_IRQ,
166         }
167 };
168
169 struct platform_device mxc_pwm_device = {
170         .name = "mxc_pwm",
171         .id = 0,
172         .num_resources = ARRAY_SIZE(mxc_pwm_resources),
173         .resource = mxc_pwm_resources,
174 };
175
176 #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq)                 \
177         static struct resource mxc_sdhc_resources ## n[] = {            \
178                 {                                                       \
179                         .start = baseaddr,                              \
180                         .end = baseaddr + SZ_4K - 1,                    \
181                         .flags = IORESOURCE_MEM,                        \
182                 }, {                                                    \
183                         .start = irq,                                   \
184                         .end = irq,                                     \
185                         .flags = IORESOURCE_IRQ,                        \
186                 }, {                                                    \
187                         .start = dmareq,                                \
188                         .end = dmareq,                                  \
189                         .flags = IORESOURCE_DMA,                        \
190                 },                                                      \
191         };                                                              \
192                                                                         \
193         static u64 mxc_sdhc ## n ## _dmamask = DMA_BIT_MASK(32);        \
194                                                                         \
195         struct platform_device mxc_sdhc_device ## n = {                 \
196                 .name = "mxc-mmc",                                      \
197                 .id = n,                                                \
198                 .dev = {                                                \
199                         .dma_mask = &mxc_sdhc ## n ## _dmamask,         \
200                         .coherent_dma_mask = DMA_BIT_MASK(32),          \
201                 },                                                      \
202                 .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n),   \
203                 .resource = mxc_sdhc_resources ## n,            \
204         }
205
206 DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
207 DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
208
209 #ifdef CONFIG_MACH_MX27
210 static struct resource otg_resources[] = {
211         {
212                 .start = MX27_USBOTG_BASE_ADDR,
213                 .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
214                 .flags = IORESOURCE_MEM,
215         }, {
216                 .start = MX27_INT_USB3,
217                 .end = MX27_INT_USB3,
218                 .flags = IORESOURCE_IRQ,
219         },
220 };
221
222 static u64 otg_dmamask = DMA_BIT_MASK(32);
223
224 /* OTG gadget device */
225 struct platform_device mxc_otg_udc_device = {
226         .name           = "fsl-usb2-udc",
227         .id             = -1,
228         .dev            = {
229                 .dma_mask               = &otg_dmamask,
230                 .coherent_dma_mask      = DMA_BIT_MASK(32),
231         },
232         .resource       = otg_resources,
233         .num_resources  = ARRAY_SIZE(otg_resources),
234 };
235
236 /* OTG host */
237 struct platform_device mxc_otg_host = {
238         .name = "mxc-ehci",
239         .id = 0,
240         .dev = {
241                 .coherent_dma_mask = DMA_BIT_MASK(32),
242                 .dma_mask = &otg_dmamask,
243         },
244         .resource = otg_resources,
245         .num_resources = ARRAY_SIZE(otg_resources),
246 };
247
248 /* USB host 1 */
249
250 static u64 usbh1_dmamask = DMA_BIT_MASK(32);
251
252 static struct resource mxc_usbh1_resources[] = {
253         {
254                 .start = MX27_USBOTG_BASE_ADDR + 0x200,
255                 .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
256                 .flags = IORESOURCE_MEM,
257         }, {
258                 .start = MX27_INT_USB1,
259                 .end = MX27_INT_USB1,
260                 .flags = IORESOURCE_IRQ,
261         },
262 };
263
264 struct platform_device mxc_usbh1 = {
265         .name = "mxc-ehci",
266         .id = 1,
267         .dev = {
268                 .coherent_dma_mask = DMA_BIT_MASK(32),
269                 .dma_mask = &usbh1_dmamask,
270         },
271         .resource = mxc_usbh1_resources,
272         .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
273 };
274
275 /* USB host 2 */
276 static u64 usbh2_dmamask = DMA_BIT_MASK(32);
277
278 static struct resource mxc_usbh2_resources[] = {
279         {
280                 .start = MX27_USBOTG_BASE_ADDR + 0x400,
281                 .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
282                 .flags = IORESOURCE_MEM,
283         }, {
284                 .start = MX27_INT_USB2,
285                 .end = MX27_INT_USB2,
286                 .flags = IORESOURCE_IRQ,
287         },
288 };
289
290 struct platform_device mxc_usbh2 = {
291         .name = "mxc-ehci",
292         .id = 2,
293         .dev = {
294                 .coherent_dma_mask = DMA_BIT_MASK(32),
295                 .dma_mask = &usbh2_dmamask,
296         },
297         .resource = mxc_usbh2_resources,
298         .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
299 };
300 #endif
301
302 /* GPIO port description */
303 #define DEFINE_MXC_GPIO_PORT_IRQ(SOC, n, _irq)                          \
304         {                                                               \
305                 .chip.label = "gpio-" #n,                               \
306                 .irq = _irq,                                            \
307                 .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR +        \
308                                 n * 0x100),                             \
309                 .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32,       \
310         }
311
312 #define DEFINE_MXC_GPIO_PORT(SOC, n)                                    \
313         {                                                               \
314                 .chip.label = "gpio-" #n,                               \
315                 .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR +        \
316                                 n * 0x100),                             \
317                 .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32,       \
318         }
319
320 #define DEFINE_MXC_GPIO_PORTS(SOC, pfx)                                 \
321         static struct mxc_gpio_port pfx ## _gpio_ports[] = {            \
322                 DEFINE_MXC_GPIO_PORT_IRQ(SOC, 0, SOC ## _INT_GPIO),     \
323                 DEFINE_MXC_GPIO_PORT(SOC, 1),                           \
324                 DEFINE_MXC_GPIO_PORT(SOC, 2),                           \
325                 DEFINE_MXC_GPIO_PORT(SOC, 3),                           \
326                 DEFINE_MXC_GPIO_PORT(SOC, 4),                           \
327                 DEFINE_MXC_GPIO_PORT(SOC, 5),                           \
328         }
329
330 #ifdef CONFIG_MACH_MX21
331 DEFINE_MXC_GPIO_PORTS(MX21, imx21);
332
333 int __init imx21_register_gpios(void)
334 {
335         return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
336 }
337 #endif
338
339 #ifdef CONFIG_MACH_MX27
340 DEFINE_MXC_GPIO_PORTS(MX27, imx27);
341
342 int __init imx27_register_gpios(void)
343 {
344         return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
345 }
346 #endif
347
348 #ifdef CONFIG_MACH_MX21
349 static struct resource mx21_usbhc_resources[] = {
350         {
351                 .start  = MX21_USBOTG_BASE_ADDR,
352                 .end    = MX21_USBOTG_BASE_ADDR + SZ_8K - 1,
353                 .flags  = IORESOURCE_MEM,
354         },
355         {
356                 .start          = MX21_INT_USBHOST,
357                 .end            = MX21_INT_USBHOST,
358                 .flags          = IORESOURCE_IRQ,
359         },
360 };
361
362 struct platform_device mx21_usbhc_device = {
363         .name           = "imx21-hcd",
364         .id             = 0,
365         .dev            = {
366                 .dma_mask = &mx21_usbhc_device.dev.coherent_dma_mask,
367                 .coherent_dma_mask = DMA_BIT_MASK(32),
368         },
369         .num_resources  = ARRAY_SIZE(mx21_usbhc_resources),
370         .resource       = mx21_usbhc_resources,
371 };
372 #endif
373
374 static struct resource imx_kpp_resources[] = {
375         {
376                 .start  = MX2x_KPP_BASE_ADDR,
377                 .end    = MX2x_KPP_BASE_ADDR + 0xf,
378                 .flags  = IORESOURCE_MEM
379         }, {
380                 .start  = MX2x_INT_KPP,
381                 .end    = MX2x_INT_KPP,
382                 .flags  = IORESOURCE_IRQ,
383         },
384 };
385
386 struct platform_device imx_kpp_device = {
387         .name = "imx-keypad",
388         .id = -1,
389         .num_resources = ARRAY_SIZE(imx_kpp_resources),
390         .resource = imx_kpp_resources,
391 };
392
393 #endif