ARM: imx: dynamically register mxc-mmc devices
[pandora-kernel.git] / arch / arm / mach-imx / mach-mx21ads.c
1 /*
2  *  Copyright (C) 2000 Deep Blue Solutions Ltd
3  *  Copyright (C) 2002 Shane Nay (shane@minirl.com)
4  *  Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16
17 #include <linux/platform_device.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/physmap.h>
20 #include <linux/gpio.h>
21 #include <mach/common.h>
22 #include <mach/hardware.h>
23 #include <asm/mach-types.h>
24 #include <asm/mach/arch.h>
25 #include <asm/mach/time.h>
26 #include <asm/mach/map.h>
27 #include <mach/iomux-mx21.h>
28 #include <mach/mxc_nand.h>
29
30 #include "devices-imx21.h"
31 #include "devices.h"
32
33 /*
34  * Memory-mapped I/O on MX21ADS base board
35  */
36 #define MX21ADS_MMIO_BASE_ADDR   0xf5000000
37 #define MX21ADS_MMIO_SIZE        SZ_16M
38
39 #define MX21ADS_REG_ADDR(offset)    (void __force __iomem *) \
40                 (MX21ADS_MMIO_BASE_ADDR + (offset))
41
42 #define MX21ADS_CS8900A_IRQ         IRQ_GPIOE(11)
43 #define MX21ADS_CS8900A_IOBASE_REG  MX21ADS_REG_ADDR(0x000000)
44 #define MX21ADS_ST16C255_IOBASE_REG MX21ADS_REG_ADDR(0x200000)
45 #define MX21ADS_VERSION_REG         MX21ADS_REG_ADDR(0x400000)
46 #define MX21ADS_IO_REG              MX21ADS_REG_ADDR(0x800000)
47
48 /* MX21ADS_IO_REG bit definitions */
49 #define MX21ADS_IO_SD_WP        0x0001 /* read */
50 #define MX21ADS_IO_TP6          0x0001 /* write */
51 #define MX21ADS_IO_SW_SEL       0x0002 /* read */
52 #define MX21ADS_IO_TP7          0x0002 /* write */
53 #define MX21ADS_IO_RESET_E_UART 0x0004
54 #define MX21ADS_IO_RESET_BASE   0x0008
55 #define MX21ADS_IO_CSI_CTL2     0x0010
56 #define MX21ADS_IO_CSI_CTL1     0x0020
57 #define MX21ADS_IO_CSI_CTL0     0x0040
58 #define MX21ADS_IO_UART1_EN     0x0080
59 #define MX21ADS_IO_UART4_EN     0x0100
60 #define MX21ADS_IO_LCDON        0x0200
61 #define MX21ADS_IO_IRDA_EN      0x0400
62 #define MX21ADS_IO_IRDA_FIR_SEL 0x0800
63 #define MX21ADS_IO_IRDA_MD0_B   0x1000
64 #define MX21ADS_IO_IRDA_MD1     0x2000
65 #define MX21ADS_IO_LED4_ON      0x4000
66 #define MX21ADS_IO_LED3_ON      0x8000
67
68 static const int mx21ads_pins[] __initconst = {
69
70         /* CS8900A */
71         (GPIO_PORTE | GPIO_GPIO | GPIO_IN | 11),
72
73         /* UART1 */
74         PE12_PF_UART1_TXD,
75         PE13_PF_UART1_RXD,
76         PE14_PF_UART1_CTS,
77         PE15_PF_UART1_RTS,
78
79         /* UART3 (IrDA) - only TXD and RXD */
80         PE8_PF_UART3_TXD,
81         PE9_PF_UART3_RXD,
82
83         /* UART4 */
84         PB26_AF_UART4_RTS,
85         PB28_AF_UART4_TXD,
86         PB29_AF_UART4_CTS,
87         PB31_AF_UART4_RXD,
88
89         /* LCDC */
90         PA5_PF_LSCLK,
91         PA6_PF_LD0,
92         PA7_PF_LD1,
93         PA8_PF_LD2,
94         PA9_PF_LD3,
95         PA10_PF_LD4,
96         PA11_PF_LD5,
97         PA12_PF_LD6,
98         PA13_PF_LD7,
99         PA14_PF_LD8,
100         PA15_PF_LD9,
101         PA16_PF_LD10,
102         PA17_PF_LD11,
103         PA18_PF_LD12,
104         PA19_PF_LD13,
105         PA20_PF_LD14,
106         PA21_PF_LD15,
107         PA22_PF_LD16,
108         PA24_PF_REV,     /* Sharp panel dedicated signal */
109         PA25_PF_CLS,     /* Sharp panel dedicated signal */
110         PA26_PF_PS,      /* Sharp panel dedicated signal */
111         PA27_PF_SPL_SPR, /* Sharp panel dedicated signal */
112         PA28_PF_HSYNC,
113         PA29_PF_VSYNC,
114         PA30_PF_CONTRAST,
115         PA31_PF_OE_ACD,
116
117         /* MMC/SDHC */
118         PE18_PF_SD1_D0,
119         PE19_PF_SD1_D1,
120         PE20_PF_SD1_D2,
121         PE21_PF_SD1_D3,
122         PE22_PF_SD1_CMD,
123         PE23_PF_SD1_CLK,
124
125         /* NFC */
126         PF0_PF_NRFB,
127         PF1_PF_NFCE,
128         PF2_PF_NFWP,
129         PF3_PF_NFCLE,
130         PF4_PF_NFALE,
131         PF5_PF_NFRE,
132         PF6_PF_NFWE,
133         PF7_PF_NFIO0,
134         PF8_PF_NFIO1,
135         PF9_PF_NFIO2,
136         PF10_PF_NFIO3,
137         PF11_PF_NFIO4,
138         PF12_PF_NFIO5,
139         PF13_PF_NFIO6,
140         PF14_PF_NFIO7,
141 };
142
143 /* ADS's NOR flash: 2x AM29BDS128HE9VKI on 32-bit bus */
144 static struct physmap_flash_data mx21ads_flash_data = {
145         .width = 4,
146 };
147
148 static struct resource mx21ads_flash_resource = {
149         .start = MX21_CS0_BASE_ADDR,
150         .end = MX21_CS0_BASE_ADDR + 0x02000000 - 1,
151         .flags = IORESOURCE_MEM,
152 };
153
154 static struct platform_device mx21ads_nor_mtd_device = {
155         .name = "physmap-flash",
156         .id = 0,
157         .dev = {
158                 .platform_data = &mx21ads_flash_data,
159         },
160         .num_resources = 1,
161         .resource = &mx21ads_flash_resource,
162 };
163
164 static const struct imxuart_platform_data uart_pdata_rts __initconst = {
165         .flags = IMXUART_HAVE_RTSCTS,
166 };
167
168 static const struct imxuart_platform_data uart_pdata_norts __initconst = {
169 };
170
171 static int mx21ads_fb_init(struct platform_device *pdev)
172 {
173         u16 tmp;
174
175         tmp = __raw_readw(MX21ADS_IO_REG);
176         tmp |= MX21ADS_IO_LCDON;
177         __raw_writew(tmp, MX21ADS_IO_REG);
178         return 0;
179 }
180
181 static void mx21ads_fb_exit(struct platform_device *pdev)
182 {
183         u16 tmp;
184
185         tmp = __raw_readw(MX21ADS_IO_REG);
186         tmp &= ~MX21ADS_IO_LCDON;
187         __raw_writew(tmp, MX21ADS_IO_REG);
188 }
189
190 /*
191  * Connected is a portrait Sharp-QVGA display
192  * of type: LQ035Q7DB02
193  */
194 static struct imx_fb_videomode mx21ads_modes[] = {
195         {
196                 .mode = {
197                         .name           = "Sharp-LQ035Q7",
198                         .refresh        = 60,
199                         .xres           = 240,
200                         .yres           = 320,
201                         .pixclock       = 188679, /* in ps (5.3MHz) */
202                         .hsync_len      = 2,
203                         .left_margin    = 6,
204                         .right_margin   = 16,
205                         .vsync_len      = 1,
206                         .upper_margin   = 8,
207                         .lower_margin   = 10,
208                 },
209                 .pcr            = 0xfb108bc7,
210                 .bpp            = 16,
211         },
212 };
213
214 static const struct imx_fb_platform_data mx21ads_fb_data __initconst = {
215         .mode = mx21ads_modes,
216         .num_modes = ARRAY_SIZE(mx21ads_modes),
217
218         .pwmr           = 0x00a903ff,
219         .lscr1          = 0x00120300,
220         .dmacr          = 0x00020008,
221
222         .init = mx21ads_fb_init,
223         .exit = mx21ads_fb_exit,
224 };
225
226 static int mx21ads_sdhc_get_ro(struct device *dev)
227 {
228         return (__raw_readw(MX21ADS_IO_REG) & MX21ADS_IO_SD_WP) ? 1 : 0;
229 }
230
231 static int mx21ads_sdhc_init(struct device *dev, irq_handler_t detect_irq,
232         void *data)
233 {
234         return request_irq(IRQ_GPIOD(25), detect_irq,
235                 IRQF_TRIGGER_FALLING, "mmc-detect", data);
236 }
237
238 static void mx21ads_sdhc_exit(struct device *dev, void *data)
239 {
240         free_irq(IRQ_GPIOD(25), data);
241 }
242
243 static const struct imxmmc_platform_data mx21ads_sdhc_pdata __initconst = {
244         .ocr_avail = MMC_VDD_29_30 | MMC_VDD_30_31, /* 3.0V */
245         .get_ro = mx21ads_sdhc_get_ro,
246         .init = mx21ads_sdhc_init,
247         .exit = mx21ads_sdhc_exit,
248 };
249
250 static const struct mxc_nand_platform_data
251 mx21ads_nand_board_info __initconst = {
252         .width = 1,
253         .hw_ecc = 1,
254 };
255
256 static struct map_desc mx21ads_io_desc[] __initdata = {
257         /*
258          * Memory-mapped I/O on MX21ADS Base board:
259          *   - CS8900A Ethernet controller
260          *   - ST16C2552CJ UART
261          *   - CPU and Base board version
262          *   - Base board I/O register
263          */
264         {
265                 .virtual = MX21ADS_MMIO_BASE_ADDR,
266                 .pfn = __phys_to_pfn(MX21_CS1_BASE_ADDR),
267                 .length = MX21ADS_MMIO_SIZE,
268                 .type = MT_DEVICE,
269         },
270 };
271
272 static void __init mx21ads_map_io(void)
273 {
274         mx21_map_io();
275         iotable_init(mx21ads_io_desc, ARRAY_SIZE(mx21ads_io_desc));
276 }
277
278 static struct platform_device *platform_devices[] __initdata = {
279         &mx21ads_nor_mtd_device,
280 };
281
282 static void __init mx21ads_board_init(void)
283 {
284         mxc_gpio_setup_multiple_pins(mx21ads_pins, ARRAY_SIZE(mx21ads_pins),
285                         "mx21ads");
286
287         imx21_add_imx_uart0(&uart_pdata_rts);
288         imx21_add_imx_uart2(&uart_pdata_norts);
289         imx21_add_imx_uart3(&uart_pdata_rts);
290         imx21_add_imx_fb(&mx21ads_fb_data);
291         imx21_add_mxc_mmc(0, &mx21ads_sdhc_pdata);
292         imx21_add_mxc_nand(&mx21ads_nand_board_info);
293
294         platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
295 }
296
297 static void __init mx21ads_timer_init(void)
298 {
299         mx21_clocks_init(32768, 26000000);
300 }
301
302 static struct sys_timer mx21ads_timer = {
303         .init   = mx21ads_timer_init,
304 };
305
306 MACHINE_START(MX21ADS, "Freescale i.MX21ADS")
307         /* maintainer: Freescale Semiconductor, Inc. */
308         .boot_params    = MX21_PHYS_OFFSET + 0x100,
309         .map_io         = mx21ads_map_io,
310         .init_irq       = mx21_init_irq,
311         .init_machine   = mx21ads_board_init,
312         .timer          = &mx21ads_timer,
313 MACHINE_END