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