2 * linux/arch/arm/mach-pxa/cm-x300.c
4 * Support for the CompuLab CM-X300 modules
6 * Copyright (C) 2008,2009 CompuLab Ltd.
8 * Mike Rapoport <mike@compulab.co.il>
9 * Igor Grinberg <grinberg@compulab.co.il>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/interrupt.h>
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/platform_device.h>
22 #include <linux/clk.h>
24 #include <linux/gpio.h>
25 #include <linux/dm9000.h>
26 #include <linux/leds.h>
27 #include <linux/rtc-v3020.h>
28 #include <linux/pwm_backlight.h>
30 #include <linux/i2c.h>
31 #include <linux/i2c/pca953x.h>
32 #include <linux/i2c/pxa-i2c.h>
34 #include <linux/mfd/da903x.h>
35 #include <linux/regulator/machine.h>
36 #include <linux/power_supply.h>
37 #include <linux/apm-emulation.h>
39 #include <linux/spi/spi.h>
40 #include <linux/spi/spi_gpio.h>
41 #include <linux/spi/tdo24m.h>
43 #include <asm/mach-types.h>
44 #include <asm/mach/arch.h>
45 #include <asm/setup.h>
47 #include <mach/pxa300.h>
48 #include <mach/pxa27x-udc.h>
49 #include <mach/pxafb.h>
51 #include <mach/ohci.h>
52 #include <plat/pxa3xx_nand.h>
53 #include <mach/audio.h>
54 #include <mach/pxa3xx-u2d.h>
56 #include <asm/mach/map.h>
61 #define CM_X300_ETH_PHYS 0x08000010
63 #define GPIO82_MMC_IRQ (82)
64 #define GPIO85_MMC_WP (85)
66 #define CM_X300_MMC_IRQ IRQ_GPIO(GPIO82_MMC_IRQ)
68 #define GPIO95_RTC_CS (95)
69 #define GPIO96_RTC_WR (96)
70 #define GPIO97_RTC_RD (97)
71 #define GPIO98_RTC_IO (98)
73 #define GPIO_ULPI_PHY_RST (127)
75 static mfp_cfg_t cm_x3xx_mfp_cfg
[] __initdata
= {
100 GPIO112_UART2_RXD
| MFP_LPM_EDGE_FALL
,
102 GPIO114_UART2_CTS
| MFP_LPM_EDGE_BOTH
,
106 GPIO110_UART3_RXD
| MFP_LPM_EDGE_FALL
,
109 GPIO23_AC97_nACRESET
,
112 GPIO25_AC97_SDATA_IN_0
,
113 GPIO27_AC97_SDATA_OUT
,
117 GPIO115_KP_MKIN_0
| MFP_LPM_EDGE_BOTH
,
118 GPIO116_KP_MKIN_1
| MFP_LPM_EDGE_BOTH
,
119 GPIO117_KP_MKIN_2
| MFP_LPM_EDGE_BOTH
,
120 GPIO118_KP_MKIN_3
| MFP_LPM_EDGE_BOTH
,
121 GPIO119_KP_MKIN_4
| MFP_LPM_EDGE_BOTH
,
122 GPIO120_KP_MKIN_5
| MFP_LPM_EDGE_BOTH
,
123 GPIO2_2_KP_MKIN_6
| MFP_LPM_EDGE_BOTH
,
124 GPIO3_2_KP_MKIN_7
| MFP_LPM_EDGE_BOTH
,
134 GPIO4_MMC1_DAT1
| MFP_LPM_EDGE_BOTH
,
138 GPIO8_MMC1_CMD
, /* CMD0 for slot 0 */
142 GPIO10_MMC2_DAT1
| MFP_LPM_EDGE_BOTH
,
149 GPIO30_UART1_RXD
| MFP_LPM_EDGE_FALL
,
154 GPIO34_UART1_DSR
| MFP_LPM_EDGE_FALL
,
159 GPIO82_GPIO
| MFP_PULL_HIGH
, /* MMC CD */
160 GPIO85_GPIO
, /* MMC WP */
161 GPIO99_GPIO
, /* Ethernet IRQ */
164 GPIO95_GPIO
, /* RTC CS */
165 GPIO96_GPIO
, /* RTC WR */
166 GPIO97_GPIO
, /* RTC RD */
167 GPIO98_GPIO
, /* RTC IO */
177 static mfp_cfg_t cm_x3xx_rev_lt130_mfp_cfg
[] __initdata
= {
179 GPIO79_GPIO
, /* LED */
180 GPIO77_GPIO
, /* WiFi reset */
181 GPIO78_GPIO
, /* BT reset */
184 static mfp_cfg_t cm_x3xx_rev_ge130_mfp_cfg
[] __initdata
= {
186 GPIO76_GPIO
, /* LED */
187 GPIO71_GPIO
, /* WiFi reset */
188 GPIO70_GPIO
, /* BT reset */
191 static mfp_cfg_t cm_x310_mfp_cfg
[] __initdata
= {
196 GPIO30_ULPI_DATA_OUT_0
,
197 GPIO31_ULPI_DATA_OUT_1
,
198 GPIO32_ULPI_DATA_OUT_2
,
199 GPIO33_ULPI_DATA_OUT_3
,
200 GPIO34_ULPI_DATA_OUT_4
,
201 GPIO35_ULPI_DATA_OUT_5
,
202 GPIO36_ULPI_DATA_OUT_6
,
203 GPIO37_ULPI_DATA_OUT_7
,
205 /* external PHY reset pin */
218 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
219 static struct resource dm9000_resources
[] = {
221 .start
= CM_X300_ETH_PHYS
,
222 .end
= CM_X300_ETH_PHYS
+ 0x3,
223 .flags
= IORESOURCE_MEM
,
226 .start
= CM_X300_ETH_PHYS
+ 0x4,
227 .end
= CM_X300_ETH_PHYS
+ 0x4 + 500,
228 .flags
= IORESOURCE_MEM
,
231 .start
= IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99
)),
232 .end
= IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99
)),
233 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
,
237 static struct dm9000_plat_data cm_x300_dm9000_platdata
= {
238 .flags
= DM9000_PLATF_16BITONLY
| DM9000_PLATF_NO_EEPROM
,
241 static struct platform_device dm9000_device
= {
244 .num_resources
= ARRAY_SIZE(dm9000_resources
),
245 .resource
= dm9000_resources
,
247 .platform_data
= &cm_x300_dm9000_platdata
,
252 static void __init
cm_x300_init_dm9000(void)
254 platform_device_register(&dm9000_device
);
257 static inline void cm_x300_init_dm9000(void) {}
261 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
262 static struct pxafb_mode_info cm_x300_lcd_modes
[] = {
291 static struct pxafb_mach_info cm_x300_lcd
= {
292 .modes
= cm_x300_lcd_modes
,
293 .num_modes
= ARRAY_SIZE(cm_x300_lcd_modes
),
294 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
,
297 static void __init
cm_x300_init_lcd(void)
299 set_pxa_fb_info(&cm_x300_lcd
);
302 static inline void cm_x300_init_lcd(void) {}
305 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
306 static struct platform_pwm_backlight_data cm_x300_backlight_data
= {
308 .max_brightness
= 100,
309 .dft_brightness
= 100,
310 .pwm_period_ns
= 10000,
313 static struct platform_device cm_x300_backlight_device
= {
314 .name
= "pwm-backlight",
316 .parent
= &pxa27x_device_pwm0
.dev
,
317 .platform_data
= &cm_x300_backlight_data
,
321 static void cm_x300_init_bl(void)
323 platform_device_register(&cm_x300_backlight_device
);
326 static inline void cm_x300_init_bl(void) {}
329 #if defined(CONFIG_SPI_GPIO) || defined(CONFIG_SPI_GPIO_MODULE)
330 #define GPIO_LCD_BASE (144)
331 #define GPIO_LCD_DIN (GPIO_LCD_BASE + 8) /* aux_gpio3_0 */
332 #define GPIO_LCD_DOUT (GPIO_LCD_BASE + 9) /* aux_gpio3_1 */
333 #define GPIO_LCD_SCL (GPIO_LCD_BASE + 10) /* aux_gpio3_2 */
334 #define GPIO_LCD_CS (GPIO_LCD_BASE + 11) /* aux_gpio3_3 */
335 #define LCD_SPI_BUS_NUM (1)
337 static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata
= {
339 .mosi
= GPIO_LCD_DIN
,
340 .miso
= GPIO_LCD_DOUT
,
344 static struct platform_device cm_x300_spi_gpio
= {
346 .id
= LCD_SPI_BUS_NUM
,
348 .platform_data
= &cm_x300_spi_gpio_pdata
,
352 static struct tdo24m_platform_data cm_x300_tdo24m_pdata
= {
356 static struct spi_board_info cm_x300_spi_devices
[] __initdata
= {
358 .modalias
= "tdo24m",
359 .max_speed_hz
= 1000000,
360 .bus_num
= LCD_SPI_BUS_NUM
,
362 .controller_data
= (void *) GPIO_LCD_CS
,
363 .platform_data
= &cm_x300_tdo24m_pdata
,
367 static void __init
cm_x300_init_spi(void)
369 spi_register_board_info(cm_x300_spi_devices
,
370 ARRAY_SIZE(cm_x300_spi_devices
));
371 platform_device_register(&cm_x300_spi_gpio
);
374 static inline void cm_x300_init_spi(void) {}
377 #if defined(CONFIG_SND_PXA2XX_LIB_AC97)
378 static void __init
cm_x300_init_ac97(void)
380 pxa_set_ac97_info(NULL
);
383 static inline void cm_x300_init_ac97(void) {}
386 #if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
387 static struct mtd_partition cm_x300_nand_partitions
[] = {
392 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
396 .offset
= MTDPART_OFS_APPEND
,
398 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
401 .name
= "Environment",
402 .offset
= MTDPART_OFS_APPEND
,
407 .offset
= MTDPART_OFS_APPEND
,
408 .size
= SZ_256K
+ SZ_1M
,
409 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
413 .offset
= MTDPART_OFS_APPEND
,
418 .offset
= MTDPART_OFS_APPEND
,
419 .size
= MTDPART_SIZ_FULL
,
423 static struct pxa3xx_nand_platform_data cm_x300_nand_info
= {
426 .parts
= cm_x300_nand_partitions
,
427 .nr_parts
= ARRAY_SIZE(cm_x300_nand_partitions
),
430 static void __init
cm_x300_init_nand(void)
432 pxa3xx_set_nand_info(&cm_x300_nand_info
);
435 static inline void cm_x300_init_nand(void) {}
438 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
439 static struct pxamci_platform_data cm_x300_mci_platform_data
= {
440 .detect_delay_ms
= 200,
441 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
442 .gpio_card_detect
= GPIO82_MMC_IRQ
,
443 .gpio_card_ro
= GPIO85_MMC_WP
,
447 /* The second MMC slot of CM-X300 is hardwired to Libertas card and has
448 no detection/ro pins */
449 static int cm_x300_mci2_init(struct device
*dev
,
450 irq_handler_t cm_x300_detect_int
,
456 static void cm_x300_mci2_exit(struct device
*dev
, void *data
)
460 static struct pxamci_platform_data cm_x300_mci2_platform_data
= {
461 .detect_delay_ms
= 200,
462 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
463 .init
= cm_x300_mci2_init
,
464 .exit
= cm_x300_mci2_exit
,
465 .gpio_card_detect
= -1,
470 static void __init
cm_x300_init_mmc(void)
472 pxa_set_mci_info(&cm_x300_mci_platform_data
);
473 pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data
);
476 static inline void cm_x300_init_mmc(void) {}
479 #if defined(CONFIG_PXA310_ULPI)
480 static struct clk
*pout_clk
;
482 static int cm_x300_ulpi_phy_reset(void)
487 err
= gpio_request(GPIO_ULPI_PHY_RST
, "ulpi reset");
489 pr_err("%s: failed to request ULPI reset GPIO: %d\n",
494 gpio_direction_output(GPIO_ULPI_PHY_RST
, 0);
496 gpio_set_value(GPIO_ULPI_PHY_RST
, 1);
499 gpio_free(GPIO_ULPI_PHY_RST
);
504 static inline int cm_x300_u2d_init(struct device
*dev
)
508 if (cpu_is_pxa310()) {
509 /* CLK_POUT is connected to the ULPI PHY */
510 pout_clk
= clk_get(NULL
, "CLK_POUT");
511 if (IS_ERR(pout_clk
)) {
512 err
= PTR_ERR(pout_clk
);
513 pr_err("%s: failed to get CLK_POUT: %d\n",
517 clk_enable(pout_clk
);
519 err
= cm_x300_ulpi_phy_reset();
521 clk_disable(pout_clk
);
529 static void cm_x300_u2d_exit(struct device
*dev
)
531 if (cpu_is_pxa310()) {
532 clk_disable(pout_clk
);
537 static struct pxa3xx_u2d_platform_data cm_x300_u2d_platform_data
= {
538 .ulpi_mode
= ULPI_SER_6PIN
,
539 .init
= cm_x300_u2d_init
,
540 .exit
= cm_x300_u2d_exit
,
543 static void cm_x300_init_u2d(void)
545 pxa3xx_set_u2d_info(&cm_x300_u2d_platform_data
);
548 static inline void cm_x300_init_u2d(void) {}
551 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
552 static int cm_x300_ohci_init(struct device
*dev
)
556 | UP2OCR_HXOE
| UP2OCR_DMPDE
| UP2OCR_DPPDE
;
561 static struct pxaohci_platform_data cm_x300_ohci_platform_data
= {
562 .port_mode
= PMM_PERPORT_MODE
,
563 .flags
= ENABLE_PORT_ALL
| POWER_CONTROL_LOW
,
564 .init
= cm_x300_ohci_init
,
567 static void __init
cm_x300_init_ohci(void)
569 pxa_set_ohci_info(&cm_x300_ohci_platform_data
);
572 static inline void cm_x300_init_ohci(void) {}
575 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
576 static struct gpio_led cm_x300_leds
[] = {
578 .name
= "cm-x300:green",
579 .default_trigger
= "heartbeat",
584 static struct gpio_led_platform_data cm_x300_gpio_led_pdata
= {
585 .num_leds
= ARRAY_SIZE(cm_x300_leds
),
586 .leds
= cm_x300_leds
,
589 static struct platform_device cm_x300_led_device
= {
593 .platform_data
= &cm_x300_gpio_led_pdata
,
597 static void __init
cm_x300_init_leds(void)
599 if (system_rev
< 130)
600 cm_x300_leds
[0].gpio
= 79;
602 cm_x300_leds
[0].gpio
= 76;
604 platform_device_register(&cm_x300_led_device
);
607 static inline void cm_x300_init_leds(void) {}
610 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
612 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0
= {
616 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1
= {
620 static struct i2c_board_info cm_x300_gpio_ext_info
[] = {
622 I2C_BOARD_INFO("pca9555", 0x24),
623 .platform_data
= &cm_x300_gpio_ext_pdata_0
,
626 I2C_BOARD_INFO("pca9555", 0x25),
627 .platform_data
= &cm_x300_gpio_ext_pdata_1
,
631 static void __init
cm_x300_init_i2c(void)
633 pxa_set_i2c_info(NULL
);
634 i2c_register_board_info(0, cm_x300_gpio_ext_info
,
635 ARRAY_SIZE(cm_x300_gpio_ext_info
));
638 static inline void cm_x300_init_i2c(void) {}
641 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
642 struct v3020_platform_data cm_x300_v3020_pdata
= {
644 .gpio_cs
= GPIO95_RTC_CS
,
645 .gpio_wr
= GPIO96_RTC_WR
,
646 .gpio_rd
= GPIO97_RTC_RD
,
647 .gpio_io
= GPIO98_RTC_IO
,
650 static struct platform_device cm_x300_rtc_device
= {
654 .platform_data
= &cm_x300_v3020_pdata
,
658 static void __init
cm_x300_init_rtc(void)
660 platform_device_register(&cm_x300_rtc_device
);
663 static inline void cm_x300_init_rtc(void) {}
667 struct power_supply_info cm_x300_psy_info
= {
669 .technology
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
670 .voltage_max_design
= 4200000,
671 .voltage_min_design
= 3000000,
675 static void cm_x300_battery_low(void)
677 #if defined(CONFIG_APM_EMULATION)
678 apm_queue_event(APM_LOW_BATTERY
);
682 static void cm_x300_battery_critical(void)
684 #if defined(CONFIG_APM_EMULATION)
685 apm_queue_event(APM_CRITICAL_SUSPEND
);
689 struct da9030_battery_info cm_x300_battery_info
= {
690 .battery_info
= &cm_x300_psy_info
,
692 .charge_milliamp
= 1000,
693 .charge_millivolt
= 4200,
697 .vbat_charge_start
= 4100,
698 .vbat_charge_stop
= 4200,
699 .vbat_charge_restart
= 4000,
708 .batmon_interval
= 0,
710 .battery_low
= cm_x300_battery_low
,
711 .battery_critical
= cm_x300_battery_critical
,
714 static struct regulator_consumer_supply buck2_consumers
[] = {
717 .supply
= "vcc_core",
721 static struct regulator_init_data buck2_data
= {
728 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
731 .num_consumer_supplies
= ARRAY_SIZE(buck2_consumers
),
732 .consumer_supplies
= buck2_consumers
,
736 struct da903x_subdev_info cm_x300_da9030_subdevs
[] = {
738 .name
= "da903x-battery",
740 .platform_data
= &cm_x300_battery_info
,
743 .name
= "da903x-regulator",
744 .id
= DA9030_ID_BUCK2
,
745 .platform_data
= &buck2_data
,
749 static struct da903x_platform_data cm_x300_da9030_info
= {
750 .num_subdevs
= ARRAY_SIZE(cm_x300_da9030_subdevs
),
751 .subdevs
= cm_x300_da9030_subdevs
,
754 static struct i2c_board_info cm_x300_pmic_info
= {
755 I2C_BOARD_INFO("da9030", 0x49),
757 .platform_data
= &cm_x300_da9030_info
,
760 static struct i2c_pxa_platform_data cm_x300_pwr_i2c_info
= {
764 static void __init
cm_x300_init_da9030(void)
766 pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info
);
767 i2c_register_board_info(1, &cm_x300_pmic_info
, 1);
768 irq_set_irq_wake(IRQ_WAKEUP0
, 1);
771 static void __init
cm_x300_init_wi2wi(void)
773 int bt_reset
, wlan_en
;
776 if (system_rev
< 130) {
784 /* Libertas and CSR reset */
785 err
= gpio_request(wlan_en
, "wlan en");
787 pr_err("CM-X300: failed to request wlan en gpio: %d\n", err
);
789 gpio_direction_output(wlan_en
, 1);
793 err
= gpio_request(bt_reset
, "bt reset");
795 pr_err("CM-X300: failed to request bt reset gpio: %d\n", err
);
797 gpio_direction_output(bt_reset
, 1);
799 gpio_set_value(bt_reset
, 0);
801 gpio_set_value(bt_reset
, 1);
807 static void __init
cm_x300_init_mfp(void)
809 /* board-processor specific GPIO initialization */
810 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_mfp_cfg
));
812 if (system_rev
< 130)
813 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_lt130_mfp_cfg
));
815 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_ge130_mfp_cfg
));
818 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x310_mfp_cfg
));
821 static void __init
cm_x300_init(void)
825 pxa_set_btuart_info(NULL
);
826 pxa_set_stuart_info(NULL
);
828 pxa_set_ffuart_info(NULL
);
830 cm_x300_init_da9030();
831 cm_x300_init_dm9000();
842 cm_x300_init_wi2wi();
846 static void __init
cm_x300_fixup(struct machine_desc
*mdesc
, struct tag
*tags
,
847 char **cmdline
, struct meminfo
*mi
)
849 /* Make sure that mi->bank[0].start = PHYS_ADDR */
850 for (; tags
->hdr
.size
; tags
= tag_next(tags
))
851 if (tags
->hdr
.tag
== ATAG_MEM
&&
852 tags
->u
.mem
.start
== 0x80000000) {
853 tags
->u
.mem
.start
= 0xa0000000;
858 MACHINE_START(CM_X300
, "CM-X300 module")
859 .boot_params
= 0xa0000100,
860 .map_io
= pxa3xx_map_io
,
861 .init_irq
= pxa3xx_init_irq
,
863 .init_machine
= cm_x300_init
,
864 .fixup
= cm_x300_fixup
,