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