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_backlight.h>
31 #include <linux/i2c.h>
32 #include <linux/i2c/pca953x.h>
33 #include <linux/i2c/pxa-i2c.h>
35 #include <linux/mfd/da903x.h>
36 #include <linux/regulator/machine.h>
37 #include <linux/power_supply.h>
38 #include <linux/apm-emulation.h>
40 #include <linux/spi/spi.h>
41 #include <linux/spi/spi_gpio.h>
42 #include <linux/spi/tdo24m.h>
44 #include <asm/mach-types.h>
45 #include <asm/mach/arch.h>
46 #include <asm/setup.h>
48 #include <mach/pxa300.h>
49 #include <mach/pxa27x-udc.h>
50 #include <mach/pxafb.h>
52 #include <mach/ohci.h>
53 #include <plat/pxa3xx_nand.h>
54 #include <mach/audio.h>
55 #include <mach/pxa3xx-u2d.h>
57 #include <asm/mach/map.h>
62 #define CM_X300_ETH_PHYS 0x08000010
64 #define GPIO82_MMC_IRQ (82)
65 #define GPIO85_MMC_WP (85)
67 #define CM_X300_MMC_IRQ IRQ_GPIO(GPIO82_MMC_IRQ)
69 #define GPIO95_RTC_CS (95)
70 #define GPIO96_RTC_WR (96)
71 #define GPIO97_RTC_RD (97)
72 #define GPIO98_RTC_IO (98)
74 #define GPIO_ULPI_PHY_RST (127)
76 static mfp_cfg_t cm_x3xx_mfp_cfg
[] __initdata
= {
101 GPIO112_UART2_RXD
| MFP_LPM_EDGE_FALL
,
103 GPIO114_UART2_CTS
| MFP_LPM_EDGE_BOTH
,
107 GPIO110_UART3_RXD
| MFP_LPM_EDGE_FALL
,
110 GPIO23_AC97_nACRESET
,
113 GPIO25_AC97_SDATA_IN_0
,
114 GPIO27_AC97_SDATA_OUT
,
118 GPIO115_KP_MKIN_0
| MFP_LPM_EDGE_BOTH
,
119 GPIO116_KP_MKIN_1
| MFP_LPM_EDGE_BOTH
,
120 GPIO117_KP_MKIN_2
| MFP_LPM_EDGE_BOTH
,
121 GPIO118_KP_MKIN_3
| MFP_LPM_EDGE_BOTH
,
122 GPIO119_KP_MKIN_4
| MFP_LPM_EDGE_BOTH
,
123 GPIO120_KP_MKIN_5
| MFP_LPM_EDGE_BOTH
,
124 GPIO2_2_KP_MKIN_6
| MFP_LPM_EDGE_BOTH
,
125 GPIO3_2_KP_MKIN_7
| MFP_LPM_EDGE_BOTH
,
135 GPIO4_MMC1_DAT1
| MFP_LPM_EDGE_BOTH
,
139 GPIO8_MMC1_CMD
, /* CMD0 for slot 0 */
143 GPIO10_MMC2_DAT1
| MFP_LPM_EDGE_BOTH
,
150 GPIO30_UART1_RXD
| MFP_LPM_EDGE_FALL
,
155 GPIO34_UART1_DSR
| MFP_LPM_EDGE_FALL
,
160 GPIO82_GPIO
| MFP_PULL_HIGH
, /* MMC CD */
161 GPIO85_GPIO
, /* MMC WP */
162 GPIO99_GPIO
, /* Ethernet IRQ */
165 GPIO95_GPIO
| MFP_LPM_DRIVE_HIGH
, /* RTC CS */
166 GPIO96_GPIO
| MFP_LPM_DRIVE_HIGH
, /* RTC WR */
167 GPIO97_GPIO
| MFP_LPM_DRIVE_HIGH
, /* RTC RD */
168 GPIO98_GPIO
, /* RTC IO */
178 static mfp_cfg_t cm_x3xx_rev_lt130_mfp_cfg
[] __initdata
= {
180 GPIO79_GPIO
, /* LED */
181 GPIO77_GPIO
, /* WiFi reset */
182 GPIO78_GPIO
, /* BT reset */
185 static mfp_cfg_t cm_x3xx_rev_ge130_mfp_cfg
[] __initdata
= {
187 GPIO76_GPIO
, /* LED */
188 GPIO71_GPIO
, /* WiFi reset */
189 GPIO70_GPIO
, /* BT reset */
192 static mfp_cfg_t cm_x310_mfp_cfg
[] __initdata
= {
197 GPIO30_ULPI_DATA_OUT_0
,
198 GPIO31_ULPI_DATA_OUT_1
,
199 GPIO32_ULPI_DATA_OUT_2
,
200 GPIO33_ULPI_DATA_OUT_3
,
201 GPIO34_ULPI_DATA_OUT_4
,
202 GPIO35_ULPI_DATA_OUT_5
,
203 GPIO36_ULPI_DATA_OUT_6
,
204 GPIO37_ULPI_DATA_OUT_7
,
206 /* external PHY reset pin */
219 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
220 static struct resource dm9000_resources
[] = {
222 .start
= CM_X300_ETH_PHYS
,
223 .end
= CM_X300_ETH_PHYS
+ 0x3,
224 .flags
= IORESOURCE_MEM
,
227 .start
= CM_X300_ETH_PHYS
+ 0x4,
228 .end
= CM_X300_ETH_PHYS
+ 0x4 + 500,
229 .flags
= IORESOURCE_MEM
,
232 .start
= IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99
)),
233 .end
= IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO99
)),
234 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
,
238 static struct dm9000_plat_data cm_x300_dm9000_platdata
= {
239 .flags
= DM9000_PLATF_16BITONLY
| DM9000_PLATF_NO_EEPROM
,
242 static struct platform_device dm9000_device
= {
245 .num_resources
= ARRAY_SIZE(dm9000_resources
),
246 .resource
= dm9000_resources
,
248 .platform_data
= &cm_x300_dm9000_platdata
,
253 static void __init
cm_x300_init_dm9000(void)
255 platform_device_register(&dm9000_device
);
258 static inline void cm_x300_init_dm9000(void) {}
262 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
263 static struct pxafb_mode_info cm_x300_lcd_modes
[] = {
292 static struct pxafb_mach_info cm_x300_lcd
= {
293 .modes
= cm_x300_lcd_modes
,
294 .num_modes
= ARRAY_SIZE(cm_x300_lcd_modes
),
295 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
,
298 static void __init
cm_x300_init_lcd(void)
300 pxa_set_fb_info(NULL
, &cm_x300_lcd
);
303 static inline void cm_x300_init_lcd(void) {}
306 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
307 static struct platform_pwm_backlight_data cm_x300_backlight_data
= {
309 .max_brightness
= 100,
310 .dft_brightness
= 100,
311 .pwm_period_ns
= 10000,
314 static struct platform_device cm_x300_backlight_device
= {
315 .name
= "pwm-backlight",
317 .parent
= &pxa27x_device_pwm0
.dev
,
318 .platform_data
= &cm_x300_backlight_data
,
322 static void cm_x300_init_bl(void)
324 platform_device_register(&cm_x300_backlight_device
);
327 static inline void cm_x300_init_bl(void) {}
330 #if defined(CONFIG_SPI_GPIO) || defined(CONFIG_SPI_GPIO_MODULE)
331 #define GPIO_LCD_BASE (144)
332 #define GPIO_LCD_DIN (GPIO_LCD_BASE + 8) /* aux_gpio3_0 */
333 #define GPIO_LCD_DOUT (GPIO_LCD_BASE + 9) /* aux_gpio3_1 */
334 #define GPIO_LCD_SCL (GPIO_LCD_BASE + 10) /* aux_gpio3_2 */
335 #define GPIO_LCD_CS (GPIO_LCD_BASE + 11) /* aux_gpio3_3 */
336 #define LCD_SPI_BUS_NUM (1)
338 static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata
= {
340 .mosi
= GPIO_LCD_DIN
,
341 .miso
= GPIO_LCD_DOUT
,
345 static struct platform_device cm_x300_spi_gpio
= {
347 .id
= LCD_SPI_BUS_NUM
,
349 .platform_data
= &cm_x300_spi_gpio_pdata
,
353 static struct tdo24m_platform_data cm_x300_tdo24m_pdata
= {
357 static struct spi_board_info cm_x300_spi_devices
[] __initdata
= {
359 .modalias
= "tdo24m",
360 .max_speed_hz
= 1000000,
361 .bus_num
= LCD_SPI_BUS_NUM
,
363 .controller_data
= (void *) GPIO_LCD_CS
,
364 .platform_data
= &cm_x300_tdo24m_pdata
,
368 static void __init
cm_x300_init_spi(void)
370 spi_register_board_info(cm_x300_spi_devices
,
371 ARRAY_SIZE(cm_x300_spi_devices
));
372 platform_device_register(&cm_x300_spi_gpio
);
375 static inline void cm_x300_init_spi(void) {}
378 #if defined(CONFIG_SND_PXA2XX_LIB_AC97)
379 static void __init
cm_x300_init_ac97(void)
381 pxa_set_ac97_info(NULL
);
384 static inline void cm_x300_init_ac97(void) {}
387 #if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
388 static struct mtd_partition cm_x300_nand_partitions
[] = {
393 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
397 .offset
= MTDPART_OFS_APPEND
,
399 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
402 .name
= "Environment",
403 .offset
= MTDPART_OFS_APPEND
,
408 .offset
= MTDPART_OFS_APPEND
,
409 .size
= SZ_256K
+ SZ_1M
,
410 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
414 .offset
= MTDPART_OFS_APPEND
,
419 .offset
= MTDPART_OFS_APPEND
,
420 .size
= MTDPART_SIZ_FULL
,
424 static struct pxa3xx_nand_platform_data cm_x300_nand_info
= {
427 .parts
= cm_x300_nand_partitions
,
428 .nr_parts
= ARRAY_SIZE(cm_x300_nand_partitions
),
431 static void __init
cm_x300_init_nand(void)
433 pxa3xx_set_nand_info(&cm_x300_nand_info
);
436 static inline void cm_x300_init_nand(void) {}
439 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
440 static struct pxamci_platform_data cm_x300_mci_platform_data
= {
441 .detect_delay_ms
= 200,
442 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
443 .gpio_card_detect
= GPIO82_MMC_IRQ
,
444 .gpio_card_ro
= GPIO85_MMC_WP
,
448 /* The second MMC slot of CM-X300 is hardwired to Libertas card and has
449 no detection/ro pins */
450 static int cm_x300_mci2_init(struct device
*dev
,
451 irq_handler_t cm_x300_detect_int
,
457 static void cm_x300_mci2_exit(struct device
*dev
, void *data
)
461 static struct pxamci_platform_data cm_x300_mci2_platform_data
= {
462 .detect_delay_ms
= 200,
463 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
464 .init
= cm_x300_mci2_init
,
465 .exit
= cm_x300_mci2_exit
,
466 .gpio_card_detect
= -1,
471 static void __init
cm_x300_init_mmc(void)
473 pxa_set_mci_info(&cm_x300_mci_platform_data
);
474 pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data
);
477 static inline void cm_x300_init_mmc(void) {}
480 #if defined(CONFIG_PXA310_ULPI)
481 static struct clk
*pout_clk
;
483 static int cm_x300_ulpi_phy_reset(void)
488 err
= gpio_request_one(GPIO_ULPI_PHY_RST
, GPIOF_OUT_INIT_LOW
,
491 pr_err("failed to request ULPI reset GPIO: %d\n", err
);
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("failed to get CLK_POUT: %d\n", err
);
516 clk_enable(pout_clk
);
518 err
= cm_x300_ulpi_phy_reset();
520 clk_disable(pout_clk
);
528 static void cm_x300_u2d_exit(struct device
*dev
)
530 if (cpu_is_pxa310()) {
531 clk_disable(pout_clk
);
536 static struct pxa3xx_u2d_platform_data cm_x300_u2d_platform_data
= {
537 .ulpi_mode
= ULPI_SER_6PIN
,
538 .init
= cm_x300_u2d_init
,
539 .exit
= cm_x300_u2d_exit
,
542 static void cm_x300_init_u2d(void)
544 pxa3xx_set_u2d_info(&cm_x300_u2d_platform_data
);
547 static inline void cm_x300_init_u2d(void) {}
550 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
551 static int cm_x300_ohci_init(struct device
*dev
)
555 | UP2OCR_HXOE
| UP2OCR_DMPDE
| UP2OCR_DPPDE
;
560 static struct pxaohci_platform_data cm_x300_ohci_platform_data
= {
561 .port_mode
= PMM_PERPORT_MODE
,
562 .flags
= ENABLE_PORT_ALL
| POWER_CONTROL_LOW
,
563 .init
= cm_x300_ohci_init
,
566 static void __init
cm_x300_init_ohci(void)
568 pxa_set_ohci_info(&cm_x300_ohci_platform_data
);
571 static inline void cm_x300_init_ohci(void) {}
574 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
575 static struct gpio_led cm_x300_leds
[] = {
577 .name
= "cm-x300:green",
578 .default_trigger
= "heartbeat",
583 static struct gpio_led_platform_data cm_x300_gpio_led_pdata
= {
584 .num_leds
= ARRAY_SIZE(cm_x300_leds
),
585 .leds
= cm_x300_leds
,
588 static struct platform_device cm_x300_led_device
= {
592 .platform_data
= &cm_x300_gpio_led_pdata
,
596 static void __init
cm_x300_init_leds(void)
598 if (system_rev
< 130)
599 cm_x300_leds
[0].gpio
= 79;
601 cm_x300_leds
[0].gpio
= 76;
603 platform_device_register(&cm_x300_led_device
);
606 static inline void cm_x300_init_leds(void) {}
609 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
611 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0
= {
615 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1
= {
619 static struct i2c_board_info cm_x300_gpio_ext_info
[] = {
621 I2C_BOARD_INFO("pca9555", 0x24),
622 .platform_data
= &cm_x300_gpio_ext_pdata_0
,
625 I2C_BOARD_INFO("pca9555", 0x25),
626 .platform_data
= &cm_x300_gpio_ext_pdata_1
,
630 static void __init
cm_x300_init_i2c(void)
632 pxa_set_i2c_info(NULL
);
633 i2c_register_board_info(0, cm_x300_gpio_ext_info
,
634 ARRAY_SIZE(cm_x300_gpio_ext_info
));
637 static inline void cm_x300_init_i2c(void) {}
640 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
641 struct v3020_platform_data cm_x300_v3020_pdata
= {
643 .gpio_cs
= GPIO95_RTC_CS
,
644 .gpio_wr
= GPIO96_RTC_WR
,
645 .gpio_rd
= GPIO97_RTC_RD
,
646 .gpio_io
= GPIO98_RTC_IO
,
649 static struct platform_device cm_x300_rtc_device
= {
653 .platform_data
= &cm_x300_v3020_pdata
,
657 static void __init
cm_x300_init_rtc(void)
659 platform_device_register(&cm_x300_rtc_device
);
662 static inline void cm_x300_init_rtc(void) {}
666 struct power_supply_info cm_x300_psy_info
= {
668 .technology
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
669 .voltage_max_design
= 4200000,
670 .voltage_min_design
= 3000000,
674 static void cm_x300_battery_low(void)
676 #if defined(CONFIG_APM_EMULATION)
677 apm_queue_event(APM_LOW_BATTERY
);
681 static void cm_x300_battery_critical(void)
683 #if defined(CONFIG_APM_EMULATION)
684 apm_queue_event(APM_CRITICAL_SUSPEND
);
688 struct da9030_battery_info cm_x300_battery_info
= {
689 .battery_info
= &cm_x300_psy_info
,
691 .charge_milliamp
= 1000,
692 .charge_millivolt
= 4200,
696 .vbat_charge_start
= 4100,
697 .vbat_charge_stop
= 4200,
698 .vbat_charge_restart
= 4000,
707 .batmon_interval
= 0,
709 .battery_low
= cm_x300_battery_low
,
710 .battery_critical
= cm_x300_battery_critical
,
713 static struct regulator_consumer_supply buck2_consumers
[] = {
716 .supply
= "vcc_core",
720 static struct regulator_init_data buck2_data
= {
727 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
730 .num_consumer_supplies
= ARRAY_SIZE(buck2_consumers
),
731 .consumer_supplies
= buck2_consumers
,
735 struct da903x_subdev_info cm_x300_da9030_subdevs
[] = {
737 .name
= "da903x-battery",
739 .platform_data
= &cm_x300_battery_info
,
742 .name
= "da903x-regulator",
743 .id
= DA9030_ID_BUCK2
,
744 .platform_data
= &buck2_data
,
748 static struct da903x_platform_data cm_x300_da9030_info
= {
749 .num_subdevs
= ARRAY_SIZE(cm_x300_da9030_subdevs
),
750 .subdevs
= cm_x300_da9030_subdevs
,
753 static struct i2c_board_info cm_x300_pmic_info
= {
754 I2C_BOARD_INFO("da9030", 0x49),
756 .platform_data
= &cm_x300_da9030_info
,
759 static struct i2c_pxa_platform_data cm_x300_pwr_i2c_info
= {
763 static void __init
cm_x300_init_da9030(void)
765 pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info
);
766 i2c_register_board_info(1, &cm_x300_pmic_info
, 1);
767 irq_set_irq_wake(IRQ_WAKEUP0
, 1);
770 /* wi2wi gpio setting for system_rev >= 130 */
771 static struct gpio cm_x300_wi2wi_gpios
[] __initdata
= {
772 { 71, GPIOF_OUT_INIT_HIGH
, "wlan en" },
773 { 70, GPIOF_OUT_INIT_HIGH
, "bt reset" },
776 static void __init
cm_x300_init_wi2wi(void)
778 int bt_reset
, wlan_en
;
781 if (system_rev
< 130) {
782 cm_x300_wi2wi_gpios
[0].gpio
= 77; /* wlan en */
783 cm_x300_wi2wi_gpios
[1].gpio
= 78; /* bt reset */
786 /* Libertas and CSR reset */
787 err
= gpio_request_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios
));
789 pr_err("failed to request wifi/bt gpios: %d\n", err
);
794 gpio_set_value(bt_reset
, 0);
796 gpio_set_value(bt_reset
, 1);
803 static void __init
cm_x300_init_mfp(void)
805 /* board-processor specific GPIO initialization */
806 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_mfp_cfg
));
808 if (system_rev
< 130)
809 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_lt130_mfp_cfg
));
811 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_ge130_mfp_cfg
));
814 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x310_mfp_cfg
));
817 static void __init
cm_x300_init(void)
821 pxa_set_btuart_info(NULL
);
822 pxa_set_stuart_info(NULL
);
824 pxa_set_ffuart_info(NULL
);
826 cm_x300_init_da9030();
827 cm_x300_init_dm9000();
838 cm_x300_init_wi2wi();
842 static void __init
cm_x300_fixup(struct machine_desc
*mdesc
, struct tag
*tags
,
843 char **cmdline
, struct meminfo
*mi
)
845 /* Make sure that mi->bank[0].start = PHYS_ADDR */
846 for (; tags
->hdr
.size
; tags
= tag_next(tags
))
847 if (tags
->hdr
.tag
== ATAG_MEM
&&
848 tags
->u
.mem
.start
== 0x80000000) {
849 tags
->u
.mem
.start
= 0xa0000000;
854 MACHINE_START(CM_X300
, "CM-X300 module")
855 .boot_params
= 0xa0000100,
856 .map_io
= pxa3xx_map_io
,
857 .init_irq
= pxa3xx_init_irq
,
858 .handle_irq
= pxa3xx_handle_irq
,
860 .init_machine
= cm_x300_init
,
861 .fixup
= cm_x300_fixup
,