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