Merge branch 'for-2.6.30' into for-2.6.31
[linux-2.6] / arch / arm / mach-pxa / cm-x300.c
1 /*
2  * linux/arch/arm/mach-pxa/cm-x300.c
3  *
4  * Support for the CompuLab CM-X300 modules
5  *
6  * Copyright (C) 2008 CompuLab Ltd.
7  *
8  * Mike Rapoport <mike@compulab.co.il>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/interrupt.h>
18 #include <linux/init.h>
19 #include <linux/platform_device.h>
20
21 #include <linux/gpio.h>
22 #include <linux/dm9000.h>
23 #include <linux/leds.h>
24
25 #include <linux/i2c.h>
26 #include <linux/i2c/pca953x.h>
27
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30
31 #include <mach/pxa300.h>
32 #include <mach/pxafb.h>
33 #include <mach/mmc.h>
34 #include <mach/ohci.h>
35 #include <mach/i2c.h>
36 #include <mach/pxa3xx_nand.h>
37
38 #include <asm/mach/map.h>
39
40 #include "generic.h"
41
42 #define CM_X300_ETH_PHYS        0x08000010
43
44 #define GPIO82_MMC2_IRQ         (82)
45 #define GPIO85_MMC2_WP          (85)
46
47 #define CM_X300_MMC2_IRQ        IRQ_GPIO(GPIO82_MMC2_IRQ)
48
49 static mfp_cfg_t cm_x300_mfp_cfg[] __initdata = {
50         /* LCD */
51         GPIO54_LCD_LDD_0,
52         GPIO55_LCD_LDD_1,
53         GPIO56_LCD_LDD_2,
54         GPIO57_LCD_LDD_3,
55         GPIO58_LCD_LDD_4,
56         GPIO59_LCD_LDD_5,
57         GPIO60_LCD_LDD_6,
58         GPIO61_LCD_LDD_7,
59         GPIO62_LCD_LDD_8,
60         GPIO63_LCD_LDD_9,
61         GPIO64_LCD_LDD_10,
62         GPIO65_LCD_LDD_11,
63         GPIO66_LCD_LDD_12,
64         GPIO67_LCD_LDD_13,
65         GPIO68_LCD_LDD_14,
66         GPIO69_LCD_LDD_15,
67         GPIO72_LCD_FCLK,
68         GPIO73_LCD_LCLK,
69         GPIO74_LCD_PCLK,
70         GPIO75_LCD_BIAS,
71
72         /* BTUART */
73         GPIO111_UART2_RTS,
74         GPIO112_UART2_RXD | MFP_LPM_EDGE_FALL,
75         GPIO113_UART2_TXD,
76         GPIO114_UART2_CTS | MFP_LPM_EDGE_BOTH,
77
78         /* STUART */
79         GPIO109_UART3_TXD,
80         GPIO110_UART3_RXD | MFP_LPM_EDGE_FALL,
81
82         /* AC97 */
83         GPIO23_AC97_nACRESET,
84         GPIO24_AC97_SYSCLK,
85         GPIO29_AC97_BITCLK,
86         GPIO25_AC97_SDATA_IN_0,
87         GPIO27_AC97_SDATA_OUT,
88         GPIO28_AC97_SYNC,
89
90         /* Keypad */
91         GPIO115_KP_MKIN_0 | MFP_LPM_EDGE_BOTH,
92         GPIO116_KP_MKIN_1 | MFP_LPM_EDGE_BOTH,
93         GPIO117_KP_MKIN_2 | MFP_LPM_EDGE_BOTH,
94         GPIO118_KP_MKIN_3 | MFP_LPM_EDGE_BOTH,
95         GPIO119_KP_MKIN_4 | MFP_LPM_EDGE_BOTH,
96         GPIO120_KP_MKIN_5 | MFP_LPM_EDGE_BOTH,
97         GPIO2_2_KP_MKIN_6 | MFP_LPM_EDGE_BOTH,
98         GPIO3_2_KP_MKIN_7 | MFP_LPM_EDGE_BOTH,
99         GPIO121_KP_MKOUT_0,
100         GPIO122_KP_MKOUT_1,
101         GPIO123_KP_MKOUT_2,
102         GPIO124_KP_MKOUT_3,
103         GPIO125_KP_MKOUT_4,
104         GPIO4_2_KP_MKOUT_5,
105
106         /* MMC1 */
107         GPIO3_MMC1_DAT0,
108         GPIO4_MMC1_DAT1 | MFP_LPM_EDGE_BOTH,
109         GPIO5_MMC1_DAT2,
110         GPIO6_MMC1_DAT3,
111         GPIO7_MMC1_CLK,
112         GPIO8_MMC1_CMD, /* CMD0 for slot 0 */
113
114         /* MMC2 */
115         GPIO9_MMC2_DAT0,
116         GPIO10_MMC2_DAT1 | MFP_LPM_EDGE_BOTH,
117         GPIO11_MMC2_DAT2,
118         GPIO12_MMC2_DAT3,
119         GPIO13_MMC2_CLK,
120         GPIO14_MMC2_CMD,
121
122         /* FFUART */
123         GPIO30_UART1_RXD | MFP_LPM_EDGE_FALL,
124         GPIO31_UART1_TXD,
125         GPIO32_UART1_CTS,
126         GPIO37_UART1_RTS,
127         GPIO33_UART1_DCD,
128         GPIO34_UART1_DSR | MFP_LPM_EDGE_FALL,
129         GPIO35_UART1_RI,
130         GPIO36_UART1_DTR,
131
132         /* GPIOs */
133         GPIO79_GPIO,                    /* LED */
134         GPIO82_GPIO | MFP_PULL_HIGH,    /* MMC CD */
135         GPIO85_GPIO,                    /* MMC WP */
136         GPIO99_GPIO,                    /* Ethernet IRQ */
137
138         /* Standard I2C */
139         GPIO21_I2C_SCL,
140         GPIO22_I2C_SDA,
141 };
142
143 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
144 static struct resource dm9000_resources[] = {
145         [0] = {
146                 .start  = CM_X300_ETH_PHYS,
147                 .end    = CM_X300_ETH_PHYS + 0x3,
148                 .flags  = IORESOURCE_MEM,
149         },
150         [1] = {
151                 .start  = CM_X300_ETH_PHYS + 0x4,
152                 .end    = CM_X300_ETH_PHYS + 0x4 + 500,
153                 .flags  = IORESOURCE_MEM,
154         },
155         [2] = {
156                 .start  = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99)),
157                 .end    = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99)),
158                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
159         }
160 };
161
162 static struct dm9000_plat_data cm_x300_dm9000_platdata = {
163         .flags          = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
164 };
165
166 static struct platform_device dm9000_device = {
167         .name           = "dm9000",
168         .id             = 0,
169         .num_resources  = ARRAY_SIZE(dm9000_resources),
170         .resource       = dm9000_resources,
171         .dev            = {
172                 .platform_data = &cm_x300_dm9000_platdata,
173         }
174
175 };
176
177 static void __init cm_x300_init_dm9000(void)
178 {
179         platform_device_register(&dm9000_device);
180 }
181 #else
182 static inline void cm_x300_init_dm9000(void) {}
183 #endif
184
185 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
186 static struct pxafb_mode_info cm_x300_lcd_modes[] = {
187         [0] = {
188                 .pixclock       = 38000,
189                 .bpp            = 16,
190                 .xres           = 480,
191                 .yres           = 640,
192                 .hsync_len      = 8,
193                 .vsync_len      = 2,
194                 .left_margin    = 8,
195                 .upper_margin   = 0,
196                 .right_margin   = 24,
197                 .lower_margin   = 4,
198                 .cmap_greyscale = 0,
199         },
200         [1] = {
201                 .pixclock       = 153800,
202                 .bpp            = 16,
203                 .xres           = 240,
204                 .yres           = 320,
205                 .hsync_len      = 8,
206                 .vsync_len      = 2,
207                 .left_margin    = 8,
208                 .upper_margin   = 2,
209                 .right_margin   = 88,
210                 .lower_margin   = 2,
211                 .cmap_greyscale = 0,
212         },
213 };
214
215 static struct pxafb_mach_info cm_x300_lcd = {
216         .modes                  = cm_x300_lcd_modes,
217         .num_modes              = 2,
218         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
219 };
220
221 static void __init cm_x300_init_lcd(void)
222 {
223         set_pxa_fb_info(&cm_x300_lcd);
224 }
225 #else
226 static inline void cm_x300_init_lcd(void) {}
227 #endif
228
229 #if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
230 static struct mtd_partition cm_x300_nand_partitions[] = {
231         [0] = {
232                 .name        = "OBM",
233                 .offset      = 0,
234                 .size        = SZ_256K,
235                 .mask_flags  = MTD_WRITEABLE, /* force read-only */
236         },
237         [1] = {
238                 .name        = "U-Boot",
239                 .offset      = MTDPART_OFS_APPEND,
240                 .size        = SZ_256K,
241                 .mask_flags  = MTD_WRITEABLE, /* force read-only */
242         },
243         [2] = {
244                 .name        = "Environment",
245                 .offset      = MTDPART_OFS_APPEND,
246                 .size        = SZ_256K,
247         },
248         [3] = {
249                 .name        = "reserved",
250                 .offset      = MTDPART_OFS_APPEND,
251                 .size        = SZ_256K + SZ_1M,
252                 .mask_flags  = MTD_WRITEABLE, /* force read-only */
253         },
254         [4] = {
255                 .name        = "kernel",
256                 .offset      = MTDPART_OFS_APPEND,
257                 .size        = SZ_4M,
258         },
259         [5] = {
260                 .name        = "fs",
261                 .offset      = MTDPART_OFS_APPEND,
262                 .size        = MTDPART_SIZ_FULL,
263         },
264 };
265
266 static struct pxa3xx_nand_platform_data cm_x300_nand_info = {
267         .enable_arbiter = 1,
268         .parts          = cm_x300_nand_partitions,
269         .nr_parts       = ARRAY_SIZE(cm_x300_nand_partitions),
270 };
271
272 static void __init cm_x300_init_nand(void)
273 {
274         pxa3xx_set_nand_info(&cm_x300_nand_info);
275 }
276 #else
277 static inline void cm_x300_init_nand(void) {}
278 #endif
279
280 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
281 /* The first MMC slot of CM-X300 is hardwired to Libertas card and has
282    no detection/ro pins */
283 static int cm_x300_mci_init(struct device *dev,
284                             irq_handler_t cm_x300_detect_int,
285                             void *data)
286 {
287         return 0;
288 }
289
290 static void cm_x300_mci_exit(struct device *dev, void *data)
291 {
292 }
293
294 static struct pxamci_platform_data cm_x300_mci_platform_data = {
295         .detect_delay   = 20,
296         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
297         .init           = cm_x300_mci_init,
298         .exit           = cm_x300_mci_exit,
299 };
300
301 static int cm_x300_mci2_ro(struct device *dev)
302 {
303         return gpio_get_value(GPIO85_MMC2_WP);
304 }
305
306 static int cm_x300_mci2_init(struct device *dev,
307                              irq_handler_t cm_x300_detect_int,
308                              void *data)
309 {
310         int err;
311
312         /*
313          * setup GPIO for CM-X300 MMC controller
314          */
315         err = gpio_request(GPIO82_MMC2_IRQ, "mmc card detect");
316         if (err)
317                 goto err_request_cd;
318         gpio_direction_input(GPIO82_MMC2_IRQ);
319
320         err = gpio_request(GPIO85_MMC2_WP, "mmc write protect");
321         if (err)
322                 goto err_request_wp;
323         gpio_direction_input(GPIO85_MMC2_WP);
324
325         err = request_irq(CM_X300_MMC2_IRQ, cm_x300_detect_int,
326                           IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
327                           "MMC card detect", data);
328         if (err) {
329                 printk(KERN_ERR "%s: MMC/SD/SDIO: "
330                                 "can't request card detect IRQ\n", __func__);
331                 goto err_request_irq;
332         }
333
334         return 0;
335
336 err_request_irq:
337         gpio_free(GPIO85_MMC2_WP);
338 err_request_wp:
339         gpio_free(GPIO82_MMC2_IRQ);
340 err_request_cd:
341         return err;
342 }
343
344 static void cm_x300_mci2_exit(struct device *dev, void *data)
345 {
346         free_irq(CM_X300_MMC2_IRQ, data);
347         gpio_free(GPIO82_MMC2_IRQ);
348         gpio_free(GPIO85_MMC2_WP);
349 }
350
351 static struct pxamci_platform_data cm_x300_mci2_platform_data = {
352         .detect_delay   = 20,
353         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
354         .init           = cm_x300_mci2_init,
355         .exit           = cm_x300_mci2_exit,
356         .get_ro         = cm_x300_mci2_ro,
357 };
358
359 static void __init cm_x300_init_mmc(void)
360 {
361         pxa_set_mci_info(&cm_x300_mci_platform_data);
362         pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data);
363 }
364 #else
365 static inline void cm_x300_init_mmc(void) {}
366 #endif
367
368 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
369 static struct pxaohci_platform_data cm_x300_ohci_platform_data = {
370         .port_mode      = PMM_PERPORT_MODE,
371         .flags          = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
372 };
373
374 static void __init cm_x300_init_ohci(void)
375 {
376         pxa_set_ohci_info(&cm_x300_ohci_platform_data);
377 }
378 #else
379 static inline void cm_x300_init_ohci(void) {}
380 #endif
381
382 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
383 static struct gpio_led cm_x300_leds[] = {
384         [0] = {
385                 .name = "cm-x300:green",
386                 .default_trigger = "heartbeat",
387                 .gpio = 79,
388                 .active_low = 1,
389         },
390 };
391
392 static struct gpio_led_platform_data cm_x300_gpio_led_pdata = {
393         .num_leds = ARRAY_SIZE(cm_x300_leds),
394         .leds = cm_x300_leds,
395 };
396
397 static struct platform_device cm_x300_led_device = {
398         .name           = "leds-gpio",
399         .id             = -1,
400         .dev            = {
401                 .platform_data = &cm_x300_gpio_led_pdata,
402         },
403 };
404
405 static void __init cm_x300_init_leds(void)
406 {
407         platform_device_register(&cm_x300_led_device);
408 }
409 #else
410 static inline void cm_x300_init_leds(void) {}
411 #endif
412
413 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
414 /* PCA9555 */
415 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0 = {
416         .gpio_base = 128,
417 };
418
419 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1 = {
420         .gpio_base = 144,
421 };
422
423 static struct i2c_board_info cm_x300_gpio_ext_info[] = {
424         [0] = {
425                 I2C_BOARD_INFO("pca9555", 0x24),
426                 .platform_data = &cm_x300_gpio_ext_pdata_0,
427         },
428         [1] = {
429                 I2C_BOARD_INFO("pca9555", 0x25),
430                 .platform_data = &cm_x300_gpio_ext_pdata_1,
431         },
432 };
433
434 static void __init cm_x300_init_i2c(void)
435 {
436         pxa_set_i2c_info(NULL);
437         i2c_register_board_info(0, cm_x300_gpio_ext_info,
438                                 ARRAY_SIZE(cm_x300_gpio_ext_info));
439 }
440 #else
441 static inline void cm_x300_init_i2c(void) {}
442 #endif
443
444 static void __init cm_x300_init(void)
445 {
446         /* board-processor specific GPIO initialization */
447         pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x300_mfp_cfg));
448
449         cm_x300_init_dm9000();
450         cm_x300_init_lcd();
451         cm_x300_init_ohci();
452         cm_x300_init_mmc();
453         cm_x300_init_nand();
454         cm_x300_init_leds();
455         cm_x300_init_i2c();
456 }
457
458 MACHINE_START(CM_X300, "CM-X300 module")
459         .phys_io        = 0x40000000,
460         .boot_params    = 0xa0000100,
461         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
462         .map_io         = pxa_map_io,
463         .init_irq       = pxa3xx_init_irq,
464         .timer          = &pxa_timer,
465         .init_machine   = cm_x300_init,
466 MACHINE_END