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.
15 #define pr_fmt(fmt) "%s: " fmt, __func__
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/interrupt.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/platform_device.h>
23 #include <linux/clk.h>
25 #include <linux/gpio.h>
26 #include <linux/dm9000.h>
27 #include <linux/leds.h>
28 #include <linux/rtc-v3020.h>
29 #include <linux/pwm.h>
30 #include <linux/pwm_backlight.h>
32 #include <linux/i2c.h>
33 #include <linux/platform_data/pca953x.h>
34 #include <linux/i2c/pxa-i2c.h>
36 #include <linux/mfd/da903x.h>
37 #include <linux/regulator/machine.h>
38 #include <linux/power_supply.h>
39 #include <linux/apm-emulation.h>
41 #include <linux/spi/spi.h>
42 #include <linux/spi/spi_gpio.h>
43 #include <linux/spi/tdo24m.h>
45 #include <asm/mach-types.h>
46 #include <asm/mach/arch.h>
47 #include <asm/setup.h>
48 #include <asm/system_info.h>
50 #include <mach/pxa300.h>
51 #include <mach/pxa27x-udc.h>
52 #include <linux/platform_data/video-pxafb.h>
53 #include <linux/platform_data/mmc-pxamci.h>
54 #include <linux/platform_data/usb-ohci-pxa27x.h>
55 #include <linux/platform_data/mtd-nand-pxa3xx.h>
56 #include <mach/audio.h>
57 #include <linux/platform_data/usb-pxa3xx-ulpi.h>
59 #include <asm/mach/map.h>
64 #define CM_X300_ETH_PHYS 0x08000010
66 #define GPIO82_MMC_IRQ (82)
67 #define GPIO85_MMC_WP (85)
69 #define CM_X300_MMC_IRQ PXA_GPIO_TO_IRQ(GPIO82_MMC_IRQ)
71 #define GPIO95_RTC_CS (95)
72 #define GPIO96_RTC_WR (96)
73 #define GPIO97_RTC_RD (97)
74 #define GPIO98_RTC_IO (98)
76 #define GPIO_ULPI_PHY_RST (127)
78 static mfp_cfg_t cm_x3xx_mfp_cfg
[] __initdata
= {
103 GPIO112_UART2_RXD
| MFP_LPM_EDGE_FALL
,
105 GPIO114_UART2_CTS
| MFP_LPM_EDGE_BOTH
,
109 GPIO110_UART3_RXD
| MFP_LPM_EDGE_FALL
,
112 GPIO23_AC97_nACRESET
,
115 GPIO25_AC97_SDATA_IN_0
,
116 GPIO27_AC97_SDATA_OUT
,
120 GPIO115_KP_MKIN_0
| MFP_LPM_EDGE_BOTH
,
121 GPIO116_KP_MKIN_1
| MFP_LPM_EDGE_BOTH
,
122 GPIO117_KP_MKIN_2
| MFP_LPM_EDGE_BOTH
,
123 GPIO118_KP_MKIN_3
| MFP_LPM_EDGE_BOTH
,
124 GPIO119_KP_MKIN_4
| MFP_LPM_EDGE_BOTH
,
125 GPIO120_KP_MKIN_5
| MFP_LPM_EDGE_BOTH
,
126 GPIO2_2_KP_MKIN_6
| MFP_LPM_EDGE_BOTH
,
127 GPIO3_2_KP_MKIN_7
| MFP_LPM_EDGE_BOTH
,
137 GPIO4_MMC1_DAT1
| MFP_LPM_EDGE_BOTH
,
141 GPIO8_MMC1_CMD
, /* CMD0 for slot 0 */
145 GPIO10_MMC2_DAT1
| MFP_LPM_EDGE_BOTH
,
152 GPIO30_UART1_RXD
| MFP_LPM_EDGE_FALL
,
157 GPIO34_UART1_DSR
| MFP_LPM_EDGE_FALL
,
162 GPIO82_GPIO
| MFP_PULL_HIGH
, /* MMC CD */
163 GPIO85_GPIO
, /* MMC WP */
164 GPIO99_GPIO
, /* Ethernet IRQ */
167 GPIO95_GPIO
| MFP_LPM_DRIVE_HIGH
, /* RTC CS */
168 GPIO96_GPIO
| MFP_LPM_DRIVE_HIGH
, /* RTC WR */
169 GPIO97_GPIO
| MFP_LPM_DRIVE_HIGH
, /* RTC RD */
170 GPIO98_GPIO
, /* RTC IO */
180 static mfp_cfg_t cm_x3xx_rev_lt130_mfp_cfg
[] __initdata
= {
182 GPIO79_GPIO
, /* LED */
183 GPIO77_GPIO
, /* WiFi reset */
184 GPIO78_GPIO
, /* BT reset */
187 static mfp_cfg_t cm_x3xx_rev_ge130_mfp_cfg
[] __initdata
= {
189 GPIO76_GPIO
, /* LED */
190 GPIO71_GPIO
, /* WiFi reset */
191 GPIO70_GPIO
, /* BT reset */
194 static mfp_cfg_t cm_x310_mfp_cfg
[] __initdata
= {
199 GPIO30_ULPI_DATA_OUT_0
,
200 GPIO31_ULPI_DATA_OUT_1
,
201 GPIO32_ULPI_DATA_OUT_2
,
202 GPIO33_ULPI_DATA_OUT_3
,
203 GPIO34_ULPI_DATA_OUT_4
,
204 GPIO35_ULPI_DATA_OUT_5
,
205 GPIO36_ULPI_DATA_OUT_6
,
206 GPIO37_ULPI_DATA_OUT_7
,
208 /* external PHY reset pin */
221 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
222 static struct resource dm9000_resources
[] = {
224 .start
= CM_X300_ETH_PHYS
,
225 .end
= CM_X300_ETH_PHYS
+ 0x3,
226 .flags
= IORESOURCE_MEM
,
229 .start
= CM_X300_ETH_PHYS
+ 0x4,
230 .end
= CM_X300_ETH_PHYS
+ 0x4 + 500,
231 .flags
= IORESOURCE_MEM
,
234 .start
= PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO99
)),
235 .end
= PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO99
)),
236 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
,
240 static struct dm9000_plat_data cm_x300_dm9000_platdata
= {
241 .flags
= DM9000_PLATF_16BITONLY
| DM9000_PLATF_NO_EEPROM
,
244 static struct platform_device dm9000_device
= {
247 .num_resources
= ARRAY_SIZE(dm9000_resources
),
248 .resource
= dm9000_resources
,
250 .platform_data
= &cm_x300_dm9000_platdata
,
255 static void __init
cm_x300_init_dm9000(void)
257 platform_device_register(&dm9000_device
);
260 static inline void cm_x300_init_dm9000(void) {}
264 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
265 static struct pxafb_mode_info cm_x300_lcd_modes
[] = {
294 static struct pxafb_mach_info cm_x300_lcd
= {
295 .modes
= cm_x300_lcd_modes
,
296 .num_modes
= ARRAY_SIZE(cm_x300_lcd_modes
),
297 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
,
300 static void __init
cm_x300_init_lcd(void)
302 pxa_set_fb_info(NULL
, &cm_x300_lcd
);
305 static inline void cm_x300_init_lcd(void) {}
308 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
309 static struct pwm_lookup cm_x300_pwm_lookup
[] = {
310 PWM_LOOKUP("pxa27x-pwm.0", 1, "pwm-backlight.0", NULL
, 10000,
311 PWM_POLARITY_NORMAL
),
314 static struct platform_pwm_backlight_data cm_x300_backlight_data
= {
315 .max_brightness
= 100,
316 .dft_brightness
= 100,
320 static struct platform_device cm_x300_backlight_device
= {
321 .name
= "pwm-backlight",
323 .parent
= &pxa27x_device_pwm0
.dev
,
324 .platform_data
= &cm_x300_backlight_data
,
328 static void cm_x300_init_bl(void)
330 pwm_add_table(cm_x300_pwm_lookup
, ARRAY_SIZE(cm_x300_pwm_lookup
));
331 platform_device_register(&cm_x300_backlight_device
);
334 static inline void cm_x300_init_bl(void) {}
337 #if defined(CONFIG_SPI_GPIO) || defined(CONFIG_SPI_GPIO_MODULE)
338 #define GPIO_LCD_BASE (144)
339 #define GPIO_LCD_DIN (GPIO_LCD_BASE + 8) /* aux_gpio3_0 */
340 #define GPIO_LCD_DOUT (GPIO_LCD_BASE + 9) /* aux_gpio3_1 */
341 #define GPIO_LCD_SCL (GPIO_LCD_BASE + 10) /* aux_gpio3_2 */
342 #define GPIO_LCD_CS (GPIO_LCD_BASE + 11) /* aux_gpio3_3 */
343 #define LCD_SPI_BUS_NUM (1)
345 static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata
= {
347 .mosi
= GPIO_LCD_DIN
,
348 .miso
= GPIO_LCD_DOUT
,
352 static struct platform_device cm_x300_spi_gpio
= {
354 .id
= LCD_SPI_BUS_NUM
,
356 .platform_data
= &cm_x300_spi_gpio_pdata
,
360 static struct tdo24m_platform_data cm_x300_tdo24m_pdata
= {
364 static struct spi_board_info cm_x300_spi_devices
[] __initdata
= {
366 .modalias
= "tdo24m",
367 .max_speed_hz
= 1000000,
368 .bus_num
= LCD_SPI_BUS_NUM
,
370 .controller_data
= (void *) GPIO_LCD_CS
,
371 .platform_data
= &cm_x300_tdo24m_pdata
,
375 static void __init
cm_x300_init_spi(void)
377 spi_register_board_info(cm_x300_spi_devices
,
378 ARRAY_SIZE(cm_x300_spi_devices
));
379 platform_device_register(&cm_x300_spi_gpio
);
382 static inline void cm_x300_init_spi(void) {}
385 #if defined(CONFIG_SND_PXA2XX_LIB_AC97)
386 static void __init
cm_x300_init_ac97(void)
388 pxa_set_ac97_info(NULL
);
391 static inline void cm_x300_init_ac97(void) {}
394 #if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
395 static struct mtd_partition cm_x300_nand_partitions
[] = {
400 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
404 .offset
= MTDPART_OFS_APPEND
,
406 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
409 .name
= "Environment",
410 .offset
= MTDPART_OFS_APPEND
,
415 .offset
= MTDPART_OFS_APPEND
,
416 .size
= SZ_256K
+ SZ_1M
,
417 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
421 .offset
= MTDPART_OFS_APPEND
,
426 .offset
= MTDPART_OFS_APPEND
,
427 .size
= MTDPART_SIZ_FULL
,
431 static struct pxa3xx_nand_platform_data cm_x300_nand_info
= {
435 .parts
[0] = cm_x300_nand_partitions
,
436 .nr_parts
[0] = ARRAY_SIZE(cm_x300_nand_partitions
),
439 static void __init
cm_x300_init_nand(void)
441 pxa3xx_set_nand_info(&cm_x300_nand_info
);
444 static inline void cm_x300_init_nand(void) {}
447 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
448 static struct pxamci_platform_data cm_x300_mci_platform_data
= {
449 .detect_delay_ms
= 200,
450 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
451 .gpio_card_detect
= GPIO82_MMC_IRQ
,
452 .gpio_card_ro
= GPIO85_MMC_WP
,
456 /* The second MMC slot of CM-X300 is hardwired to Libertas card and has
457 no detection/ro pins */
458 static int cm_x300_mci2_init(struct device
*dev
,
459 irq_handler_t cm_x300_detect_int
,
465 static void cm_x300_mci2_exit(struct device
*dev
, void *data
)
469 static struct pxamci_platform_data cm_x300_mci2_platform_data
= {
470 .detect_delay_ms
= 200,
471 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
472 .init
= cm_x300_mci2_init
,
473 .exit
= cm_x300_mci2_exit
,
474 .gpio_card_detect
= -1,
479 static void __init
cm_x300_init_mmc(void)
481 pxa_set_mci_info(&cm_x300_mci_platform_data
);
482 pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data
);
485 static inline void cm_x300_init_mmc(void) {}
488 #if defined(CONFIG_PXA310_ULPI)
489 static struct clk
*pout_clk
;
491 static int cm_x300_ulpi_phy_reset(void)
496 err
= gpio_request_one(GPIO_ULPI_PHY_RST
, GPIOF_OUT_INIT_LOW
,
499 pr_err("failed to request ULPI reset GPIO: %d\n", err
);
504 gpio_set_value(GPIO_ULPI_PHY_RST
, 1);
507 gpio_free(GPIO_ULPI_PHY_RST
);
512 static inline int cm_x300_u2d_init(struct device
*dev
)
516 if (cpu_is_pxa310()) {
517 /* CLK_POUT is connected to the ULPI PHY */
518 pout_clk
= clk_get(NULL
, "CLK_POUT");
519 if (IS_ERR(pout_clk
)) {
520 err
= PTR_ERR(pout_clk
);
521 pr_err("failed to get CLK_POUT: %d\n", err
);
524 clk_enable(pout_clk
);
526 err
= cm_x300_ulpi_phy_reset();
528 clk_disable(pout_clk
);
536 static void cm_x300_u2d_exit(struct device
*dev
)
538 if (cpu_is_pxa310()) {
539 clk_disable(pout_clk
);
544 static struct pxa3xx_u2d_platform_data cm_x300_u2d_platform_data
= {
545 .ulpi_mode
= ULPI_SER_6PIN
,
546 .init
= cm_x300_u2d_init
,
547 .exit
= cm_x300_u2d_exit
,
550 static void cm_x300_init_u2d(void)
552 pxa3xx_set_u2d_info(&cm_x300_u2d_platform_data
);
555 static inline void cm_x300_init_u2d(void) {}
558 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
559 static int cm_x300_ohci_init(struct device
*dev
)
563 | UP2OCR_HXOE
| UP2OCR_DMPDE
| UP2OCR_DPPDE
;
568 static struct pxaohci_platform_data cm_x300_ohci_platform_data
= {
569 .port_mode
= PMM_PERPORT_MODE
,
570 .flags
= ENABLE_PORT_ALL
| POWER_CONTROL_LOW
,
571 .init
= cm_x300_ohci_init
,
574 static void __init
cm_x300_init_ohci(void)
576 pxa_set_ohci_info(&cm_x300_ohci_platform_data
);
579 static inline void cm_x300_init_ohci(void) {}
582 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
583 static struct gpio_led cm_x300_leds
[] = {
585 .name
= "cm-x300:green",
586 .default_trigger
= "heartbeat",
591 static struct gpio_led_platform_data cm_x300_gpio_led_pdata
= {
592 .num_leds
= ARRAY_SIZE(cm_x300_leds
),
593 .leds
= cm_x300_leds
,
596 static struct platform_device cm_x300_led_device
= {
600 .platform_data
= &cm_x300_gpio_led_pdata
,
604 static void __init
cm_x300_init_leds(void)
606 if (system_rev
< 130)
607 cm_x300_leds
[0].gpio
= 79;
609 cm_x300_leds
[0].gpio
= 76;
611 platform_device_register(&cm_x300_led_device
);
614 static inline void cm_x300_init_leds(void) {}
617 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
619 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0
= {
623 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1
= {
627 static struct i2c_board_info cm_x300_gpio_ext_info
[] = {
629 I2C_BOARD_INFO("pca9555", 0x24),
630 .platform_data
= &cm_x300_gpio_ext_pdata_0
,
633 I2C_BOARD_INFO("pca9555", 0x25),
634 .platform_data
= &cm_x300_gpio_ext_pdata_1
,
638 static void __init
cm_x300_init_i2c(void)
640 pxa_set_i2c_info(NULL
);
641 i2c_register_board_info(0, cm_x300_gpio_ext_info
,
642 ARRAY_SIZE(cm_x300_gpio_ext_info
));
645 static inline void cm_x300_init_i2c(void) {}
648 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
649 struct v3020_platform_data cm_x300_v3020_pdata
= {
651 .gpio_cs
= GPIO95_RTC_CS
,
652 .gpio_wr
= GPIO96_RTC_WR
,
653 .gpio_rd
= GPIO97_RTC_RD
,
654 .gpio_io
= GPIO98_RTC_IO
,
657 static struct platform_device cm_x300_rtc_device
= {
661 .platform_data
= &cm_x300_v3020_pdata
,
665 static void __init
cm_x300_init_rtc(void)
667 platform_device_register(&cm_x300_rtc_device
);
670 static inline void cm_x300_init_rtc(void) {}
674 struct power_supply_info cm_x300_psy_info
= {
676 .technology
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
677 .voltage_max_design
= 4200000,
678 .voltage_min_design
= 3000000,
682 static void cm_x300_battery_low(void)
684 #if defined(CONFIG_APM_EMULATION)
685 apm_queue_event(APM_LOW_BATTERY
);
689 static void cm_x300_battery_critical(void)
691 #if defined(CONFIG_APM_EMULATION)
692 apm_queue_event(APM_CRITICAL_SUSPEND
);
696 struct da9030_battery_info cm_x300_battery_info
= {
697 .battery_info
= &cm_x300_psy_info
,
699 .charge_milliamp
= 1000,
700 .charge_millivolt
= 4200,
704 .vbat_charge_start
= 4100,
705 .vbat_charge_stop
= 4200,
706 .vbat_charge_restart
= 4000,
715 .batmon_interval
= 0,
717 .battery_low
= cm_x300_battery_low
,
718 .battery_critical
= cm_x300_battery_critical
,
721 static struct regulator_consumer_supply buck2_consumers
[] = {
722 REGULATOR_SUPPLY("vcc_core", NULL
),
725 static struct regulator_init_data buck2_data
= {
732 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
735 .num_consumer_supplies
= ARRAY_SIZE(buck2_consumers
),
736 .consumer_supplies
= buck2_consumers
,
740 struct da903x_subdev_info cm_x300_da9030_subdevs
[] = {
742 .name
= "da903x-battery",
744 .platform_data
= &cm_x300_battery_info
,
747 .name
= "da903x-regulator",
748 .id
= DA9030_ID_BUCK2
,
749 .platform_data
= &buck2_data
,
753 static struct da903x_platform_data cm_x300_da9030_info
= {
754 .num_subdevs
= ARRAY_SIZE(cm_x300_da9030_subdevs
),
755 .subdevs
= cm_x300_da9030_subdevs
,
758 static struct i2c_board_info cm_x300_pmic_info
= {
759 I2C_BOARD_INFO("da9030", 0x49),
761 .platform_data
= &cm_x300_da9030_info
,
764 static struct i2c_pxa_platform_data cm_x300_pwr_i2c_info
= {
768 static void __init
cm_x300_init_da9030(void)
770 pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info
);
771 i2c_register_board_info(1, &cm_x300_pmic_info
, 1);
772 irq_set_irq_wake(IRQ_WAKEUP0
, 1);
775 /* wi2wi gpio setting for system_rev >= 130 */
776 static struct gpio cm_x300_wi2wi_gpios
[] __initdata
= {
777 { 71, GPIOF_OUT_INIT_HIGH
, "wlan en" },
778 { 70, GPIOF_OUT_INIT_HIGH
, "bt reset" },
781 static void __init
cm_x300_init_wi2wi(void)
785 if (system_rev
< 130) {
786 cm_x300_wi2wi_gpios
[0].gpio
= 77; /* wlan en */
787 cm_x300_wi2wi_gpios
[1].gpio
= 78; /* bt reset */
790 /* Libertas and CSR reset */
791 err
= gpio_request_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios
));
793 pr_err("failed to request wifi/bt gpios: %d\n", err
);
798 gpio_set_value(cm_x300_wi2wi_gpios
[1].gpio
, 0);
800 gpio_set_value(cm_x300_wi2wi_gpios
[1].gpio
, 1);
802 gpio_free_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios
));
806 static void __init
cm_x300_init_mfp(void)
808 /* board-processor specific GPIO initialization */
809 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_mfp_cfg
));
811 if (system_rev
< 130)
812 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_lt130_mfp_cfg
));
814 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_ge130_mfp_cfg
));
817 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x310_mfp_cfg
));
820 static void __init
cm_x300_init(void)
824 pxa_set_btuart_info(NULL
);
825 pxa_set_stuart_info(NULL
);
827 pxa_set_ffuart_info(NULL
);
829 cm_x300_init_da9030();
830 cm_x300_init_dm9000();
841 cm_x300_init_wi2wi();
844 regulator_has_full_constraints();
847 static void __init
cm_x300_fixup(struct tag
*tags
, char **cmdline
)
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 .atag_offset
= 0x100,
860 .map_io
= pxa3xx_map_io
,
861 .nr_irqs
= PXA_NR_IRQS
,
862 .init_irq
= pxa3xx_init_irq
,
863 .handle_irq
= pxa3xx_handle_irq
,
864 .init_time
= pxa_timer_init
,
865 .init_machine
= cm_x300_init
,
866 .fixup
= cm_x300_fixup
,
867 .restart
= pxa_restart
,