2 * Support for CompuLab EM-X270 platform
4 * Copyright (C) 2007, 2008 CompuLab, Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/irq.h>
13 #include <linux/platform_device.h>
15 #include <linux/dm9000.h>
16 #include <linux/rtc-v3020.h>
17 #include <linux/mtd/nand.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/mtd/physmap.h>
20 #include <linux/input.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/gpio.h>
23 #include <linux/mfd/da903x.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/tdo24m.h>
28 #include <media/soc_camera.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
33 #include <mach/mfp-pxa27x.h>
34 #include <mach/pxa-regs.h>
35 #include <mach/pxa27x-udc.h>
36 #include <mach/audio.h>
37 #include <mach/pxafb.h>
38 #include <mach/ohci.h>
40 #include <mach/pxa27x_keypad.h>
42 #include <mach/camera.h>
43 #include <mach/pxa2xx_spi.h>
49 #define GPIO41_ETHIRQ (41)
50 #define GPIO13_MMC_CD (13)
51 #define EM_X270_ETHIRQ IRQ_GPIO(GPIO41_ETHIRQ)
53 /* NAND control GPIOs */
54 #define GPIO11_NAND_CS (11)
55 #define GPIO56_NAND_RB (56)
57 /* Miscelaneous GPIOs */
58 #define GPIO93_CAM_RESET (93)
59 #define GPIO95_MMC_WP (95)
61 static unsigned long em_x270_pin_config[] = {
64 GPIO29_AC97_SDATA_IN_0,
65 GPIO30_AC97_SDATA_OUT,
129 GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
130 GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
131 GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
132 GPIO34_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
133 GPIO39_KP_MKIN_4 | WAKEUP_ON_LEVEL_HIGH,
134 GPIO99_KP_MKIN_5 | WAKEUP_ON_LEVEL_HIGH,
135 GPIO91_KP_MKIN_6 | WAKEUP_ON_LEVEL_HIGH,
136 GPIO36_KP_MKIN_7 | WAKEUP_ON_LEVEL_HIGH,
158 /* SDRAM and local bus */
167 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH, /* sleep/resume button */
168 GPIO95_GPIO, /* MMC Write protect */
171 GPIO20_GPIO | MFP_LPM_DRIVE_LOW, /* GPRS_PWEN */
172 GPIO93_GPIO | MFP_LPM_DRIVE_LOW, /* Camera reset */
173 GPIO115_GPIO | MFP_LPM_DRIVE_LOW, /* WLAN_PWEN */
176 GPIO11_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */
177 GPIO56_GPIO, /* NAND Ready/Busy */
180 GPIO13_GPIO, /* MMC card detect */
181 GPIO41_GPIO, /* DM9000 interrupt */
184 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
185 static struct resource em_x270_dm9000_resource[] = {
187 .start = PXA_CS2_PHYS,
188 .end = PXA_CS2_PHYS + 3,
189 .flags = IORESOURCE_MEM,
192 .start = PXA_CS2_PHYS + 8,
193 .end = PXA_CS2_PHYS + 8 + 0x3f,
194 .flags = IORESOURCE_MEM,
197 .start = EM_X270_ETHIRQ,
198 .end = EM_X270_ETHIRQ,
199 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
203 static struct dm9000_plat_data em_x270_dm9000_platdata = {
204 .flags = DM9000_PLATF_32BITONLY,
207 static struct platform_device em_x270_dm9000 = {
210 .num_resources = ARRAY_SIZE(em_x270_dm9000_resource),
211 .resource = em_x270_dm9000_resource,
213 .platform_data = &em_x270_dm9000_platdata,
217 static void __init em_x270_init_dm9000(void)
219 platform_device_register(&em_x270_dm9000);
222 static inline void em_x270_init_dm9000(void) {}
226 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
227 static struct resource em_x270_v3020_resource[] = {
229 .start = PXA_CS4_PHYS,
230 .end = PXA_CS4_PHYS + 3,
231 .flags = IORESOURCE_MEM,
235 static struct v3020_platform_data em_x270_v3020_platdata = {
239 static struct platform_device em_x270_rtc = {
241 .num_resources = ARRAY_SIZE(em_x270_v3020_resource),
242 .resource = em_x270_v3020_resource,
245 .platform_data = &em_x270_v3020_platdata,
249 static void __init em_x270_init_rtc(void)
251 platform_device_register(&em_x270_rtc);
254 static inline void em_x270_init_rtc(void) {}
258 #if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
259 static inline void nand_cs_on(void)
261 gpio_set_value(GPIO11_NAND_CS, 0);
264 static void nand_cs_off(void)
268 gpio_set_value(GPIO11_NAND_CS, 1);
271 /* hardware specific access to control-lines */
272 static void em_x270_nand_cmd_ctl(struct mtd_info *mtd, int dat,
275 struct nand_chip *this = mtd->priv;
276 unsigned long nandaddr = (unsigned long)this->IO_ADDR_W;
280 if (ctrl & NAND_CTRL_CHANGE) {
282 nandaddr |= (1 << 3);
284 nandaddr &= ~(1 << 3);
286 nandaddr |= (1 << 2);
288 nandaddr &= ~(1 << 2);
296 this->IO_ADDR_W = (void __iomem *)nandaddr;
297 if (dat != NAND_CMD_NONE)
298 writel(dat, this->IO_ADDR_W);
303 /* read device ready pin */
304 static int em_x270_nand_device_ready(struct mtd_info *mtd)
308 return gpio_get_value(GPIO56_NAND_RB);
311 static struct mtd_partition em_x270_partition_info[] = {
319 .offset = MTDPART_OFS_APPEND,
320 .size = MTDPART_SIZ_FULL
324 static const char *em_x270_part_probes[] = { "cmdlinepart", NULL };
326 struct platform_nand_data em_x270_nand_platdata = {
330 .nr_partitions = ARRAY_SIZE(em_x270_partition_info),
331 .partitions = em_x270_partition_info,
333 .part_probe_types = em_x270_part_probes,
337 .dev_ready = em_x270_nand_device_ready,
339 .cmd_ctrl = em_x270_nand_cmd_ctl,
343 static struct resource em_x270_nand_resource[] = {
345 .start = PXA_CS1_PHYS,
346 .end = PXA_CS1_PHYS + 12,
347 .flags = IORESOURCE_MEM,
351 static struct platform_device em_x270_nand = {
353 .num_resources = ARRAY_SIZE(em_x270_nand_resource),
354 .resource = em_x270_nand_resource,
357 .platform_data = &em_x270_nand_platdata,
361 static void __init em_x270_init_nand(void)
365 err = gpio_request(GPIO11_NAND_CS, "NAND CS");
367 pr_warning("EM-X270: failed to request NAND CS gpio\n");
371 gpio_direction_output(GPIO11_NAND_CS, 1);
373 err = gpio_request(GPIO56_NAND_RB, "NAND R/B");
375 pr_warning("EM-X270: failed to request NAND R/B gpio\n");
376 gpio_free(GPIO11_NAND_CS);
380 gpio_direction_input(GPIO56_NAND_RB);
382 platform_device_register(&em_x270_nand);
385 static inline void em_x270_init_nand(void) {}
388 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
389 static struct mtd_partition em_x270_nor_parts[] = {
391 .name = "Bootloader",
392 .offset = 0x00000000,
394 .mask_flags = MTD_WRITEABLE /* force read-only */
396 .name = "Environment",
397 .offset = 0x00050000,
401 .offset = 0x00060000,
403 .mask_flags = MTD_WRITEABLE /* force read-only */
405 .name = "Splashscreen",
406 .offset = 0x000b0000,
411 static struct physmap_flash_data em_x270_nor_data[] = {
414 .parts = em_x270_nor_parts,
415 .nr_parts = ARRAY_SIZE(em_x270_nor_parts),
419 static struct resource em_x270_nor_flash_resource = {
420 .start = PXA_CS0_PHYS,
421 .end = PXA_CS0_PHYS + SZ_1M - 1,
422 .flags = IORESOURCE_MEM,
425 static struct platform_device em_x270_physmap_flash = {
426 .name = "physmap-flash",
429 .resource = &em_x270_nor_flash_resource,
431 .platform_data = &em_x270_nor_data,
435 static void __init em_x270_init_nor(void)
437 platform_device_register(&em_x270_physmap_flash);
440 static inline void em_x270_init_nor(void) {}
443 /* PXA27x OHCI controller setup */
444 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
445 static int em_x270_ohci_init(struct device *dev)
447 /* enable port 2 transiever */
448 UP2OCR = UP2OCR_HXS | UP2OCR_HXOE;
453 static struct pxaohci_platform_data em_x270_ohci_platform_data = {
454 .port_mode = PMM_PERPORT_MODE,
455 .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
456 .init = em_x270_ohci_init,
459 static void __init em_x270_init_ohci(void)
461 pxa_set_ohci_info(&em_x270_ohci_platform_data);
464 static inline void em_x270_init_ohci(void) {}
467 /* MCI controller setup */
468 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
469 static struct regulator *em_x270_sdio_ldo;
471 static int em_x270_mci_init(struct device *dev,
472 irq_handler_t em_x270_detect_int,
477 em_x270_sdio_ldo = regulator_get(dev, "vcc sdio");
478 if (IS_ERR(em_x270_sdio_ldo)) {
479 dev_err(dev, "can't request SDIO power supply: %ld\n",
480 PTR_ERR(em_x270_sdio_ldo));
481 return PTR_ERR(em_x270_sdio_ldo);
484 err = request_irq(gpio_to_irq(GPIO13_MMC_CD), em_x270_detect_int,
485 IRQF_DISABLED | IRQF_TRIGGER_RISING |
486 IRQF_TRIGGER_FALLING,
487 "MMC card detect", data);
489 dev_err(dev, "can't request MMC card detect IRQ: %d\n", err);
493 err = gpio_request(GPIO95_MMC_WP, "MMC WP");
495 dev_err(dev, "can't request MMC write protect: %d\n", err);
499 gpio_direction_input(GPIO95_MMC_WP);
504 free_irq(gpio_to_irq(GPIO13_MMC_CD), data);
506 regulator_put(em_x270_sdio_ldo);
511 static void em_x270_mci_setpower(struct device *dev, unsigned int vdd)
513 struct pxamci_platform_data* p_d = dev->platform_data;
515 if ((1 << vdd) & p_d->ocr_mask) {
516 int vdd_uV = (2000 + (vdd - __ffs(MMC_VDD_20_21)) * 100) * 1000;
518 regulator_set_voltage(em_x270_sdio_ldo, vdd_uV, vdd_uV);
519 regulator_enable(em_x270_sdio_ldo);
521 regulator_disable(em_x270_sdio_ldo);
525 static void em_x270_mci_exit(struct device *dev, void *data)
527 free_irq(gpio_to_irq(GPIO13_MMC_CD), data);
530 static int em_x270_mci_get_ro(struct device *dev)
532 return gpio_get_value(GPIO95_MMC_WP);
535 static struct pxamci_platform_data em_x270_mci_platform_data = {
536 .ocr_mask = MMC_VDD_20_21|MMC_VDD_21_22|MMC_VDD_22_23|
537 MMC_VDD_24_25|MMC_VDD_25_26|MMC_VDD_26_27|
538 MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
539 MMC_VDD_30_31|MMC_VDD_31_32,
540 .init = em_x270_mci_init,
541 .setpower = em_x270_mci_setpower,
542 .get_ro = em_x270_mci_get_ro,
543 .exit = em_x270_mci_exit,
546 static void __init em_x270_init_mmc(void)
548 em_x270_mci_platform_data.detect_delay = msecs_to_jiffies(250);
549 pxa_set_mci_info(&em_x270_mci_platform_data);
552 static inline void em_x270_init_mmc(void) {}
556 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
557 static struct pxafb_mode_info em_x270_lcd_modes[] = {
586 static struct pxafb_mach_info em_x270_lcd = {
587 .modes = em_x270_lcd_modes,
589 .lcd_conn = LCD_COLOR_TFT_16BPP,
592 static void __init em_x270_init_lcd(void)
594 set_pxa_fb_info(&em_x270_lcd);
597 static inline void em_x270_init_lcd(void) {}
600 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
601 static struct pxa2xx_spi_master em_x270_spi_info = {
605 static struct pxa2xx_spi_chip em_x270_tdo24m_chip = {
610 static struct tdo24m_platform_data em_x270_tdo24m_pdata = {
614 static struct spi_board_info em_x270_spi_devices[] __initdata = {
616 .modalias = "tdo24m",
617 .max_speed_hz = 1000000,
620 .controller_data = &em_x270_tdo24m_chip,
621 .platform_data = &em_x270_tdo24m_pdata,
625 static void __init em_x270_init_spi(void)
627 pxa2xx_set_spi_info(1, &em_x270_spi_info);
628 spi_register_board_info(ARRAY_AND_SIZE(em_x270_spi_devices));
631 static inline void em_x270_init_spi(void) {}
634 #if defined(CONFIG_SND_PXA2XX_AC97) || defined(CONFIG_SND_PXA2XX_AC97_MODULE)
635 static void __init em_x270_init_ac97(void)
637 pxa_set_ac97_info(NULL);
640 static inline void em_x270_init_ac97(void) {}
643 #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
644 static unsigned int em_x270_matrix_keys[] = {
645 KEY(0, 0, KEY_A), KEY(1, 0, KEY_UP), KEY(2, 1, KEY_B),
646 KEY(0, 2, KEY_LEFT), KEY(1, 1, KEY_ENTER), KEY(2, 0, KEY_RIGHT),
647 KEY(0, 1, KEY_C), KEY(1, 2, KEY_DOWN), KEY(2, 2, KEY_D),
650 struct pxa27x_keypad_platform_data em_x270_keypad_info = {
651 /* code map for the matrix keys */
652 .matrix_key_rows = 3,
653 .matrix_key_cols = 3,
654 .matrix_key_map = em_x270_matrix_keys,
655 .matrix_key_map_size = ARRAY_SIZE(em_x270_matrix_keys),
658 static void __init em_x270_init_keypad(void)
660 pxa_set_keypad_info(&em_x270_keypad_info);
663 static inline void em_x270_init_keypad(void) {}
666 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
667 static struct gpio_keys_button gpio_keys_button[] = {
669 .desc = "sleep/wakeup",
677 static struct gpio_keys_platform_data em_x270_gpio_keys_data = {
678 .buttons = gpio_keys_button,
682 static struct platform_device em_x270_gpio_keys = {
686 .platform_data = &em_x270_gpio_keys_data,
690 static void __init em_x270_init_gpio_keys(void)
692 platform_device_register(&em_x270_gpio_keys);
695 static inline void em_x270_init_gpio_keys(void) {}
698 /* Quick Capture Interface and sensor setup */
699 #if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
700 static struct regulator *em_x270_camera_ldo;
702 static int em_x270_sensor_init(struct device *dev)
706 ret = gpio_request(GPIO93_CAM_RESET, "camera reset");
710 gpio_direction_output(GPIO93_CAM_RESET, 0);
712 em_x270_camera_ldo = regulator_get(NULL, "vcc cam");
713 if (em_x270_camera_ldo == NULL) {
714 gpio_free(GPIO93_CAM_RESET);
718 ret = regulator_enable(em_x270_camera_ldo);
720 regulator_put(em_x270_camera_ldo);
721 gpio_free(GPIO93_CAM_RESET);
725 gpio_set_value(GPIO93_CAM_RESET, 1);
730 struct pxacamera_platform_data em_x270_camera_platform_data = {
731 .init = em_x270_sensor_init,
732 .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
733 PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
737 static int em_x270_sensor_power(struct device *dev, int on)
740 int is_on = regulator_is_enabled(em_x270_camera_ldo);
745 gpio_set_value(GPIO93_CAM_RESET, !on);
748 ret = regulator_enable(em_x270_camera_ldo);
750 ret = regulator_disable(em_x270_camera_ldo);
755 gpio_set_value(GPIO93_CAM_RESET, on);
760 static struct soc_camera_link iclink = {
762 .power = em_x270_sensor_power,
765 static struct i2c_board_info em_x270_i2c_cam_info[] = {
767 I2C_BOARD_INFO("mt9m111", 0x48),
768 .platform_data = &iclink,
772 static struct i2c_pxa_platform_data em_x270_i2c_info = {
776 static void __init em_x270_init_camera(void)
778 pxa_set_i2c_info(&em_x270_i2c_info);
779 i2c_register_board_info(0, ARRAY_AND_SIZE(em_x270_i2c_cam_info));
780 pxa_set_camera_info(&em_x270_camera_platform_data);
783 static inline void em_x270_init_camera(void) {}
786 /* DA9030 related initializations */
787 #define REGULATOR_CONSUMER(_name, _dev, _supply) \
788 static struct regulator_consumer_supply _name##_consumers[] = { \
795 REGULATOR_CONSUMER(ldo3, NULL, "vcc gps");
796 REGULATOR_CONSUMER(ldo5, NULL, "vcc cam");
797 REGULATOR_CONSUMER(ldo10, &pxa_device_mci.dev, "vcc sdio");
798 REGULATOR_CONSUMER(ldo12, NULL, "vcc usb");
799 REGULATOR_CONSUMER(ldo19, NULL, "vcc gprs");
801 #define REGULATOR_INIT(_ldo, _min_uV, _max_uV, _ops_mask) \
802 static struct regulator_init_data _ldo##_data = { \
809 .valid_ops_mask = _ops_mask, \
811 .num_consumer_supplies = ARRAY_SIZE(_ldo##_consumers), \
812 .consumer_supplies = _ldo##_consumers, \
815 REGULATOR_INIT(ldo3, 3200000, 3200000, REGULATOR_CHANGE_STATUS);
816 REGULATOR_INIT(ldo5, 3000000, 3000000, REGULATOR_CHANGE_STATUS);
817 REGULATOR_INIT(ldo10, 2000000, 3200000,
818 REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE);
819 REGULATOR_INIT(ldo12, 3000000, 3000000, REGULATOR_CHANGE_STATUS);
820 REGULATOR_INIT(ldo19, 3200000, 3200000, REGULATOR_CHANGE_STATUS);
822 struct led_info em_x270_led_info = {
823 .name = "em-x270:orange",
824 .default_trigger = "battery-charging-or-full",
827 #define DA9030_SUBDEV(_name, _id, _pdata) \
829 .name = "da903x-" #_name, \
830 .id = DA9030_ID_##_id, \
831 .platform_data = _pdata, \
834 #define DA9030_LDO(num) DA9030_SUBDEV(regulator, LDO##num, &ldo##num##_data)
836 struct da903x_subdev_info em_x270_da9030_subdevs[] = {
843 DA9030_SUBDEV(led, LED_PC, &em_x270_led_info),
844 DA9030_SUBDEV(backlight, WLED, &em_x270_led_info),
847 static struct da903x_platform_data em_x270_da9030_info = {
848 .num_subdevs = ARRAY_SIZE(em_x270_da9030_subdevs),
849 .subdevs = em_x270_da9030_subdevs,
852 static struct i2c_board_info em_x270_i2c_pmic_info = {
853 I2C_BOARD_INFO("da9030", 0x49),
855 .platform_data = &em_x270_da9030_info,
858 static struct i2c_pxa_platform_data em_x270_pwr_i2c_info = {
862 static void __init em_x270_init_da9030(void)
864 pxa27x_set_i2c_power_info(&em_x270_pwr_i2c_info);
865 i2c_register_board_info(1, &em_x270_i2c_pmic_info, 1);
868 static void __init em_x270_init(void)
870 pxa2xx_mfp_config(ARRAY_AND_SIZE(em_x270_pin_config));
872 em_x270_init_da9030();
873 em_x270_init_dm9000();
880 em_x270_init_keypad();
881 em_x270_init_gpio_keys();
883 em_x270_init_camera();
887 MACHINE_START(EM_X270, "Compulab EM-X270")
888 .boot_params = 0xa0000100,
889 .phys_io = 0x40000000,
890 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
891 .map_io = pxa_map_io,
892 .init_irq = pxa27x_init_irq,
894 .init_machine = em_x270_init,