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/gpio/machine.h>
27 #include <linux/dm9000.h>
28 #include <linux/leds.h>
29 #include <linux/platform_data/rtc-v3020.h>
30 #include <linux/pwm.h>
31 #include <linux/pwm_backlight.h>
33 #include <linux/i2c.h>
34 #include <linux/platform_data/pca953x.h>
35 #include <linux/platform_data/i2c-pxa.h>
37 #include <linux/mfd/da903x.h>
38 #include <linux/regulator/machine.h>
39 #include <linux/power_supply.h>
40 #include <linux/apm-emulation.h>
42 #include <linux/spi/spi.h>
43 #include <linux/spi/spi_gpio.h>
44 #include <linux/spi/tdo24m.h>
46 #include <asm/mach-types.h>
47 #include <asm/mach/arch.h>
48 #include <asm/setup.h>
49 #include <asm/system_info.h>
52 #include "pxa27x-udc.h"
53 #include <linux/platform_data/video-pxafb.h>
54 #include <linux/platform_data/mmc-pxamci.h>
55 #include <linux/platform_data/usb-ohci-pxa27x.h>
56 #include <linux/platform_data/mtd-nand-pxa3xx.h>
57 #include <mach/audio.h>
58 #include <linux/platform_data/usb-pxa3xx-ulpi.h>
60 #include <asm/mach/map.h>
65 #define CM_X300_ETH_PHYS 0x08000010
67 #define GPIO82_MMC_IRQ (82)
68 #define GPIO85_MMC_WP (85)
70 #define CM_X300_MMC_IRQ PXA_GPIO_TO_IRQ(GPIO82_MMC_IRQ)
72 #define GPIO95_RTC_CS (95)
73 #define GPIO96_RTC_WR (96)
74 #define GPIO97_RTC_RD (97)
75 #define GPIO98_RTC_IO (98)
77 #define GPIO_ULPI_PHY_RST (127)
79 static mfp_cfg_t cm_x3xx_mfp_cfg[] __initdata = {
104 GPIO112_UART2_RXD | MFP_LPM_EDGE_FALL,
106 GPIO114_UART2_CTS | MFP_LPM_EDGE_BOTH,
110 GPIO110_UART3_RXD | MFP_LPM_EDGE_FALL,
113 GPIO23_AC97_nACRESET,
116 GPIO25_AC97_SDATA_IN_0,
117 GPIO27_AC97_SDATA_OUT,
121 GPIO115_KP_MKIN_0 | MFP_LPM_EDGE_BOTH,
122 GPIO116_KP_MKIN_1 | MFP_LPM_EDGE_BOTH,
123 GPIO117_KP_MKIN_2 | MFP_LPM_EDGE_BOTH,
124 GPIO118_KP_MKIN_3 | MFP_LPM_EDGE_BOTH,
125 GPIO119_KP_MKIN_4 | MFP_LPM_EDGE_BOTH,
126 GPIO120_KP_MKIN_5 | MFP_LPM_EDGE_BOTH,
127 GPIO2_2_KP_MKIN_6 | MFP_LPM_EDGE_BOTH,
128 GPIO3_2_KP_MKIN_7 | MFP_LPM_EDGE_BOTH,
138 GPIO4_MMC1_DAT1 | MFP_LPM_EDGE_BOTH,
142 GPIO8_MMC1_CMD, /* CMD0 for slot 0 */
146 GPIO10_MMC2_DAT1 | MFP_LPM_EDGE_BOTH,
153 GPIO30_UART1_RXD | MFP_LPM_EDGE_FALL,
158 GPIO34_UART1_DSR | MFP_LPM_EDGE_FALL,
163 GPIO82_GPIO | MFP_PULL_HIGH, /* MMC CD */
164 GPIO85_GPIO, /* MMC WP */
165 GPIO99_GPIO, /* Ethernet IRQ */
168 GPIO95_GPIO | MFP_LPM_DRIVE_HIGH, /* RTC CS */
169 GPIO96_GPIO | MFP_LPM_DRIVE_HIGH, /* RTC WR */
170 GPIO97_GPIO | MFP_LPM_DRIVE_HIGH, /* RTC RD */
171 GPIO98_GPIO, /* RTC IO */
181 static mfp_cfg_t cm_x3xx_rev_lt130_mfp_cfg[] __initdata = {
183 GPIO79_GPIO, /* LED */
184 GPIO77_GPIO, /* WiFi reset */
185 GPIO78_GPIO, /* BT reset */
188 static mfp_cfg_t cm_x3xx_rev_ge130_mfp_cfg[] __initdata = {
190 GPIO76_GPIO, /* LED */
191 GPIO71_GPIO, /* WiFi reset */
192 GPIO70_GPIO, /* BT reset */
195 static mfp_cfg_t cm_x310_mfp_cfg[] __initdata = {
200 GPIO30_ULPI_DATA_OUT_0,
201 GPIO31_ULPI_DATA_OUT_1,
202 GPIO32_ULPI_DATA_OUT_2,
203 GPIO33_ULPI_DATA_OUT_3,
204 GPIO34_ULPI_DATA_OUT_4,
205 GPIO35_ULPI_DATA_OUT_5,
206 GPIO36_ULPI_DATA_OUT_6,
207 GPIO37_ULPI_DATA_OUT_7,
209 /* external PHY reset pin */
222 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
223 static struct resource dm9000_resources[] = {
225 .start = CM_X300_ETH_PHYS,
226 .end = CM_X300_ETH_PHYS + 0x3,
227 .flags = IORESOURCE_MEM,
230 .start = CM_X300_ETH_PHYS + 0x4,
231 .end = CM_X300_ETH_PHYS + 0x4 + 500,
232 .flags = IORESOURCE_MEM,
235 .start = PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO99)),
236 .end = PXA_GPIO_TO_IRQ(mfp_to_gpio(MFP_PIN_GPIO99)),
237 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
241 static struct dm9000_plat_data cm_x300_dm9000_platdata = {
242 .flags = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
245 static struct platform_device dm9000_device = {
248 .num_resources = ARRAY_SIZE(dm9000_resources),
249 .resource = dm9000_resources,
251 .platform_data = &cm_x300_dm9000_platdata,
256 static void __init cm_x300_init_dm9000(void)
258 platform_device_register(&dm9000_device);
261 static inline void cm_x300_init_dm9000(void) {}
265 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
266 static struct pxafb_mode_info cm_x300_lcd_modes[] = {
295 static struct pxafb_mach_info cm_x300_lcd = {
296 .modes = cm_x300_lcd_modes,
297 .num_modes = ARRAY_SIZE(cm_x300_lcd_modes),
298 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
301 static void __init cm_x300_init_lcd(void)
303 pxa_set_fb_info(NULL, &cm_x300_lcd);
306 static inline void cm_x300_init_lcd(void) {}
309 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
310 static struct pwm_lookup cm_x300_pwm_lookup[] = {
311 PWM_LOOKUP("pxa27x-pwm.0", 1, "pwm-backlight.0", NULL, 10000,
312 PWM_POLARITY_NORMAL),
315 static struct platform_pwm_backlight_data cm_x300_backlight_data = {
316 .max_brightness = 100,
317 .dft_brightness = 100,
321 static struct platform_device cm_x300_backlight_device = {
322 .name = "pwm-backlight",
324 .parent = &pxa27x_device_pwm0.dev,
325 .platform_data = &cm_x300_backlight_data,
329 static void cm_x300_init_bl(void)
331 pwm_add_table(cm_x300_pwm_lookup, ARRAY_SIZE(cm_x300_pwm_lookup));
332 platform_device_register(&cm_x300_backlight_device);
335 static inline void cm_x300_init_bl(void) {}
338 #if defined(CONFIG_SPI_GPIO) || defined(CONFIG_SPI_GPIO_MODULE)
339 #define GPIO_LCD_BASE (144)
340 #define GPIO_LCD_DIN (GPIO_LCD_BASE + 8) /* aux_gpio3_0 */
341 #define GPIO_LCD_DOUT (GPIO_LCD_BASE + 9) /* aux_gpio3_1 */
342 #define GPIO_LCD_SCL (GPIO_LCD_BASE + 10) /* aux_gpio3_2 */
343 #define GPIO_LCD_CS (GPIO_LCD_BASE + 11) /* aux_gpio3_3 */
344 #define LCD_SPI_BUS_NUM (1)
346 static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata = {
350 static struct platform_device cm_x300_spi_gpio = {
352 .id = LCD_SPI_BUS_NUM,
354 .platform_data = &cm_x300_spi_gpio_pdata,
358 static struct gpiod_lookup_table cm_x300_spi_gpiod_table = {
359 .dev_id = "spi_gpio",
361 GPIO_LOOKUP("gpio-pxa", GPIO_LCD_SCL,
362 "sck", GPIO_ACTIVE_HIGH),
363 GPIO_LOOKUP("gpio-pxa", GPIO_LCD_DIN,
364 "mosi", GPIO_ACTIVE_HIGH),
365 GPIO_LOOKUP("gpio-pxa", GPIO_LCD_DOUT,
366 "miso", GPIO_ACTIVE_HIGH),
367 GPIO_LOOKUP("gpio-pxa", GPIO_LCD_CS,
368 "cs", GPIO_ACTIVE_HIGH),
373 static struct tdo24m_platform_data cm_x300_tdo24m_pdata = {
377 static struct spi_board_info cm_x300_spi_devices[] __initdata = {
379 .modalias = "tdo24m",
380 .max_speed_hz = 1000000,
381 .bus_num = LCD_SPI_BUS_NUM,
383 .platform_data = &cm_x300_tdo24m_pdata,
387 static void __init cm_x300_init_spi(void)
389 spi_register_board_info(cm_x300_spi_devices,
390 ARRAY_SIZE(cm_x300_spi_devices));
391 gpiod_add_lookup_table(&cm_x300_spi_gpiod_table);
392 platform_device_register(&cm_x300_spi_gpio);
395 static inline void cm_x300_init_spi(void) {}
398 #if defined(CONFIG_SND_PXA2XX_LIB_AC97)
399 static void __init cm_x300_init_ac97(void)
401 pxa_set_ac97_info(NULL);
404 static inline void cm_x300_init_ac97(void) {}
407 #if IS_ENABLED(CONFIG_MTD_NAND_MARVELL)
408 static struct mtd_partition cm_x300_nand_partitions[] = {
413 .mask_flags = MTD_WRITEABLE, /* force read-only */
417 .offset = MTDPART_OFS_APPEND,
419 .mask_flags = MTD_WRITEABLE, /* force read-only */
422 .name = "Environment",
423 .offset = MTDPART_OFS_APPEND,
428 .offset = MTDPART_OFS_APPEND,
429 .size = SZ_256K + SZ_1M,
430 .mask_flags = MTD_WRITEABLE, /* force read-only */
434 .offset = MTDPART_OFS_APPEND,
439 .offset = MTDPART_OFS_APPEND,
440 .size = MTDPART_SIZ_FULL,
444 static struct pxa3xx_nand_platform_data cm_x300_nand_info = {
446 .parts = cm_x300_nand_partitions,
447 .nr_parts = ARRAY_SIZE(cm_x300_nand_partitions),
450 static void __init cm_x300_init_nand(void)
452 pxa3xx_set_nand_info(&cm_x300_nand_info);
455 static inline void cm_x300_init_nand(void) {}
458 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
459 static struct pxamci_platform_data cm_x300_mci_platform_data = {
460 .detect_delay_ms = 200,
461 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
464 static struct gpiod_lookup_table cm_x300_mci_gpio_table = {
465 .dev_id = "pxa2xx-mci.0",
467 /* Card detect on GPIO 82 */
468 GPIO_LOOKUP("gpio-pxa", GPIO82_MMC_IRQ, "cd", GPIO_ACTIVE_LOW),
469 /* Write protect on GPIO 85 */
470 GPIO_LOOKUP("gpio-pxa", GPIO85_MMC_WP, "wp", GPIO_ACTIVE_LOW),
475 /* The second MMC slot of CM-X300 is hardwired to Libertas card and has
476 no detection/ro pins */
477 static int cm_x300_mci2_init(struct device *dev,
478 irq_handler_t cm_x300_detect_int,
484 static void cm_x300_mci2_exit(struct device *dev, void *data)
488 static struct pxamci_platform_data cm_x300_mci2_platform_data = {
489 .detect_delay_ms = 200,
490 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
491 .init = cm_x300_mci2_init,
492 .exit = cm_x300_mci2_exit,
495 static void __init cm_x300_init_mmc(void)
497 gpiod_add_lookup_table(&cm_x300_mci_gpio_table);
498 pxa_set_mci_info(&cm_x300_mci_platform_data);
499 pxa3xx_set_mci2_info(&cm_x300_mci2_platform_data);
502 static inline void cm_x300_init_mmc(void) {}
505 #if defined(CONFIG_PXA310_ULPI)
506 static struct clk *pout_clk;
508 static int cm_x300_ulpi_phy_reset(void)
513 err = gpio_request_one(GPIO_ULPI_PHY_RST, GPIOF_OUT_INIT_LOW,
516 pr_err("failed to request ULPI reset GPIO: %d\n", err);
521 gpio_set_value(GPIO_ULPI_PHY_RST, 1);
524 gpio_free(GPIO_ULPI_PHY_RST);
529 static int cm_x300_u2d_init(struct device *dev)
533 if (cpu_is_pxa310()) {
534 /* CLK_POUT is connected to the ULPI PHY */
535 pout_clk = clk_get(NULL, "CLK_POUT");
536 if (IS_ERR(pout_clk)) {
537 err = PTR_ERR(pout_clk);
538 pr_err("failed to get CLK_POUT: %d\n", err);
541 clk_prepare_enable(pout_clk);
543 err = cm_x300_ulpi_phy_reset();
545 clk_disable(pout_clk);
553 static void cm_x300_u2d_exit(struct device *dev)
555 if (cpu_is_pxa310()) {
556 clk_disable_unprepare(pout_clk);
561 static struct pxa3xx_u2d_platform_data cm_x300_u2d_platform_data = {
562 .ulpi_mode = ULPI_SER_6PIN,
563 .init = cm_x300_u2d_init,
564 .exit = cm_x300_u2d_exit,
567 static void __init cm_x300_init_u2d(void)
569 pxa3xx_set_u2d_info(&cm_x300_u2d_platform_data);
572 static inline void cm_x300_init_u2d(void) {}
575 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
576 static int cm_x300_ohci_init(struct device *dev)
580 | UP2OCR_HXOE | UP2OCR_DMPDE | UP2OCR_DPPDE;
585 static struct pxaohci_platform_data cm_x300_ohci_platform_data = {
586 .port_mode = PMM_PERPORT_MODE,
587 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW,
588 .init = cm_x300_ohci_init,
591 static void __init cm_x300_init_ohci(void)
593 pxa_set_ohci_info(&cm_x300_ohci_platform_data);
596 static inline void cm_x300_init_ohci(void) {}
599 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
600 static struct gpio_led cm_x300_leds[] = {
602 .name = "cm-x300:green",
603 .default_trigger = "heartbeat",
608 static struct gpio_led_platform_data cm_x300_gpio_led_pdata = {
609 .num_leds = ARRAY_SIZE(cm_x300_leds),
610 .leds = cm_x300_leds,
613 static struct platform_device cm_x300_led_device = {
617 .platform_data = &cm_x300_gpio_led_pdata,
621 static void __init cm_x300_init_leds(void)
623 if (system_rev < 130)
624 cm_x300_leds[0].gpio = 79;
626 cm_x300_leds[0].gpio = 76;
628 platform_device_register(&cm_x300_led_device);
631 static inline void cm_x300_init_leds(void) {}
634 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
636 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_0 = {
640 static struct pca953x_platform_data cm_x300_gpio_ext_pdata_1 = {
644 static struct i2c_board_info cm_x300_gpio_ext_info[] = {
646 I2C_BOARD_INFO("pca9555", 0x24),
647 .platform_data = &cm_x300_gpio_ext_pdata_0,
650 I2C_BOARD_INFO("pca9555", 0x25),
651 .platform_data = &cm_x300_gpio_ext_pdata_1,
655 static void __init cm_x300_init_i2c(void)
657 pxa_set_i2c_info(NULL);
658 i2c_register_board_info(0, cm_x300_gpio_ext_info,
659 ARRAY_SIZE(cm_x300_gpio_ext_info));
662 static inline void cm_x300_init_i2c(void) {}
665 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
666 struct v3020_platform_data cm_x300_v3020_pdata = {
668 .gpio_cs = GPIO95_RTC_CS,
669 .gpio_wr = GPIO96_RTC_WR,
670 .gpio_rd = GPIO97_RTC_RD,
671 .gpio_io = GPIO98_RTC_IO,
674 static struct platform_device cm_x300_rtc_device = {
678 .platform_data = &cm_x300_v3020_pdata,
682 static void __init cm_x300_init_rtc(void)
684 platform_device_register(&cm_x300_rtc_device);
687 static inline void cm_x300_init_rtc(void) {}
691 struct power_supply_info cm_x300_psy_info = {
693 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
694 .voltage_max_design = 4200000,
695 .voltage_min_design = 3000000,
699 static void cm_x300_battery_low(void)
701 #if defined(CONFIG_APM_EMULATION)
702 apm_queue_event(APM_LOW_BATTERY);
706 static void cm_x300_battery_critical(void)
708 #if defined(CONFIG_APM_EMULATION)
709 apm_queue_event(APM_CRITICAL_SUSPEND);
713 struct da9030_battery_info cm_x300_battery_info = {
714 .battery_info = &cm_x300_psy_info,
716 .charge_milliamp = 1000,
717 .charge_millivolt = 4200,
721 .vbat_charge_start = 4100,
722 .vbat_charge_stop = 4200,
723 .vbat_charge_restart = 4000,
732 .batmon_interval = 0,
734 .battery_low = cm_x300_battery_low,
735 .battery_critical = cm_x300_battery_critical,
738 static struct regulator_consumer_supply buck2_consumers[] = {
739 REGULATOR_SUPPLY("vcc_core", NULL),
742 static struct regulator_init_data buck2_data = {
749 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
752 .num_consumer_supplies = ARRAY_SIZE(buck2_consumers),
753 .consumer_supplies = buck2_consumers,
757 struct da903x_subdev_info cm_x300_da9030_subdevs[] = {
759 .name = "da903x-battery",
761 .platform_data = &cm_x300_battery_info,
764 .name = "da903x-regulator",
765 .id = DA9030_ID_BUCK2,
766 .platform_data = &buck2_data,
770 static struct da903x_platform_data cm_x300_da9030_info = {
771 .num_subdevs = ARRAY_SIZE(cm_x300_da9030_subdevs),
772 .subdevs = cm_x300_da9030_subdevs,
775 static struct i2c_board_info cm_x300_pmic_info = {
776 I2C_BOARD_INFO("da9030", 0x49),
778 .platform_data = &cm_x300_da9030_info,
781 static struct i2c_pxa_platform_data cm_x300_pwr_i2c_info = {
785 static void __init cm_x300_init_da9030(void)
787 pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info);
788 i2c_register_board_info(1, &cm_x300_pmic_info, 1);
789 irq_set_irq_wake(IRQ_WAKEUP0, 1);
792 /* wi2wi gpio setting for system_rev >= 130 */
793 static struct gpio cm_x300_wi2wi_gpios[] __initdata = {
794 { 71, GPIOF_OUT_INIT_HIGH, "wlan en" },
795 { 70, GPIOF_OUT_INIT_HIGH, "bt reset" },
798 static void __init cm_x300_init_wi2wi(void)
802 if (system_rev < 130) {
803 cm_x300_wi2wi_gpios[0].gpio = 77; /* wlan en */
804 cm_x300_wi2wi_gpios[1].gpio = 78; /* bt reset */
807 /* Libertas and CSR reset */
808 err = gpio_request_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios));
810 pr_err("failed to request wifi/bt gpios: %d\n", err);
815 gpio_set_value(cm_x300_wi2wi_gpios[1].gpio, 0);
817 gpio_set_value(cm_x300_wi2wi_gpios[1].gpio, 1);
819 gpio_free_array(ARRAY_AND_SIZE(cm_x300_wi2wi_gpios));
823 static void __init cm_x300_init_mfp(void)
825 /* board-processor specific GPIO initialization */
826 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_mfp_cfg));
828 if (system_rev < 130)
829 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_lt130_mfp_cfg));
831 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x3xx_rev_ge130_mfp_cfg));
834 pxa3xx_mfp_config(ARRAY_AND_SIZE(cm_x310_mfp_cfg));
837 static void __init cm_x300_init(void)
841 pxa_set_btuart_info(NULL);
842 pxa_set_stuart_info(NULL);
844 pxa_set_ffuart_info(NULL);
846 cm_x300_init_da9030();
847 cm_x300_init_dm9000();
858 cm_x300_init_wi2wi();
861 regulator_has_full_constraints();
864 static void __init cm_x300_fixup(struct tag *tags, char **cmdline)
866 /* Make sure that mi->bank[0].start = PHYS_ADDR */
867 for (; tags->hdr.size; tags = tag_next(tags))
868 if (tags->hdr.tag == ATAG_MEM &&
869 tags->u.mem.start == 0x80000000) {
870 tags->u.mem.start = 0xa0000000;
875 MACHINE_START(CM_X300, "CM-X300 module")
876 .atag_offset = 0x100,
877 .map_io = pxa3xx_map_io,
878 .nr_irqs = PXA_NR_IRQS,
879 .init_irq = pxa3xx_init_irq,
880 .handle_irq = pxa3xx_handle_irq,
881 .init_time = pxa_timer_init,
882 .init_machine = cm_x300_init,
883 .fixup = cm_x300_fixup,
884 .restart = pxa_restart,