2 * linux/arch/arm/mach-pxa/cm-x270.c
4 * Copyright (C) 2007, 2008 CompuLab, Ltd.
5 * 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/platform_device.h>
13 #include <linux/sysdev.h>
14 #include <linux/irq.h>
15 #include <linux/gpio.h>
17 #include <linux/dm9000.h>
18 #include <linux/rtc-v3020.h>
19 #include <video/mbxfb.h>
20 #include <linux/leds.h>
22 #include <asm/mach/arch.h>
23 #include <asm/mach-types.h>
24 #include <asm/mach/map.h>
26 #include <mach/pxa2xx-regs.h>
27 #include <mach/mfp-pxa27x.h>
28 #include <mach/pxa-regs.h>
29 #include <mach/audio.h>
30 #include <mach/pxafb.h>
31 #include <mach/ohci.h>
33 #include <mach/bitfield.h>
35 #include <asm/hardware/it8152.h>
38 #include "cm-x270-pci.h"
40 /* virtual addresses for statically mapped regions */
41 #define CMX270_VIRT_BASE (0xe8000000)
42 #define CMX270_IT8152_VIRT (CMX270_VIRT_BASE)
44 #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
45 #define DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
48 #define GPIO10_ETHIRQ (10)
49 #define GPIO22_IT8152_IRQ (22)
50 #define GPIO83_MMC_IRQ (83)
51 #define GPIO95_GFXIRQ (95)
53 #define CMX270_ETHIRQ IRQ_GPIO(GPIO10_ETHIRQ)
54 #define CMX270_IT8152_IRQ IRQ_GPIO(GPIO22_IT8152_IRQ)
55 #define CMX270_MMC_IRQ IRQ_GPIO(GPIO83_MMC_IRQ)
56 #define CMX270_GFXIRQ IRQ_GPIO(GPIO95_GFXIRQ)
58 /* MMC power enable */
59 #define GPIO105_MMC_POWER (105)
61 static unsigned long cmx270_pin_config[] = {
64 GPIO29_AC97_SDATA_IN_0,
65 GPIO30_AC97_SDATA_OUT,
137 /* SDRAM and local bus */
147 GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,
148 GPIO105_GPIO | MFP_LPM_DRIVE_HIGH, /* MMC/SD power */
149 GPIO53_GPIO, /* PC card reset */
152 GPIO11_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */
153 GPIO89_GPIO, /* NAND Ready/Busy */
156 GPIO10_GPIO, /* DM9000 interrupt */
157 GPIO83_GPIO, /* MMC card detect */
160 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
161 static struct resource cmx270_dm9000_resource[] = {
163 .start = DM9000_PHYS_BASE,
164 .end = DM9000_PHYS_BASE + 4,
165 .flags = IORESOURCE_MEM,
168 .start = DM9000_PHYS_BASE + 8,
169 .end = DM9000_PHYS_BASE + 8 + 500,
170 .flags = IORESOURCE_MEM,
173 .start = CMX270_ETHIRQ,
174 .end = CMX270_ETHIRQ,
175 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
179 static struct dm9000_plat_data cmx270_dm9000_platdata = {
180 .flags = DM9000_PLATF_32BITONLY,
183 static struct platform_device cmx270_dm9000_device = {
186 .num_resources = ARRAY_SIZE(cmx270_dm9000_resource),
187 .resource = cmx270_dm9000_resource,
189 .platform_data = &cmx270_dm9000_platdata,
193 static void __init cmx270_init_dm9000(void)
195 platform_device_register(&cmx270_dm9000_device);
198 static inline void cmx270_init_dm9000(void) {}
201 /* UCB1400 touchscreen controller */
202 #if defined(CONFIG_TOUCHSCREEN_UCB1400) || defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
203 static struct platform_device cmx270_ts_device = {
204 .name = "ucb1400_ts",
208 static void __init cmx270_init_touchscreen(void)
210 platform_device_register(&cmx270_ts_device);
213 static inline void cmx270_init_touchscreen(void) {}
217 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
218 static struct resource cmx270_v3020_resource[] = {
220 .start = RTC_PHYS_BASE,
221 .end = RTC_PHYS_BASE + 4,
222 .flags = IORESOURCE_MEM,
226 struct v3020_platform_data cmx270_v3020_pdata = {
230 static struct platform_device cmx270_rtc_device = {
232 .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
233 .resource = cmx270_v3020_resource,
236 .platform_data = &cmx270_v3020_pdata,
240 static void __init cmx270_init_rtc(void)
242 platform_device_register(&cmx270_rtc_device);
245 static inline void cmx270_init_rtc(void) {}
249 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
250 static struct gpio_led cmx270_leds[] = {
252 .name = "cm-x270:red",
253 .default_trigger = "nand-disk",
258 .name = "cm-x270:green",
259 .default_trigger = "heartbeat",
265 static struct gpio_led_platform_data cmx270_gpio_led_pdata = {
266 .num_leds = ARRAY_SIZE(cmx270_leds),
270 static struct platform_device cmx270_led_device = {
274 .platform_data = &cmx270_gpio_led_pdata,
278 static void __init cmx270_init_leds(void)
280 platform_device_register(&cmx270_led_device);
283 static inline void cmx270_init_leds(void) {}
287 #if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
288 static u64 fb_dma_mask = ~(u64)0;
290 static struct resource cmx270_2700G_resource[] = {
291 /* frame buffer memory including ODFB and External SDRAM */
293 .start = PXA_CS2_PHYS,
294 .end = PXA_CS2_PHYS + 0x01ffffff,
295 .flags = IORESOURCE_MEM,
297 /* Marathon registers */
299 .start = PXA_CS2_PHYS + 0x03fe0000,
300 .end = PXA_CS2_PHYS + 0x03ffffff,
301 .flags = IORESOURCE_MEM,
305 static unsigned long save_lcd_regs[10];
307 static int cmx270_marathon_probe(struct fb_info *fb)
309 /* save PXA-270 pin settings before enabling 2700G */
310 save_lcd_regs[0] = GPDR1;
311 save_lcd_regs[1] = GPDR2;
312 save_lcd_regs[2] = GAFR1_U;
313 save_lcd_regs[3] = GAFR2_L;
314 save_lcd_regs[4] = GAFR2_U;
316 /* Disable PXA-270 on-chip controller driving pins */
317 GPDR1 &= ~(0xfc000000);
318 GPDR2 &= ~(0x00c03fff);
319 GAFR1_U &= ~(0xfff00000);
320 GAFR2_L &= ~(0x0fffffff);
321 GAFR2_U &= ~(0x0000f000);
325 static int cmx270_marathon_remove(struct fb_info *fb)
327 GPDR1 = save_lcd_regs[0];
328 GPDR2 = save_lcd_regs[1];
329 GAFR1_U = save_lcd_regs[2];
330 GAFR2_L = save_lcd_regs[3];
331 GAFR2_U = save_lcd_regs[4];
335 static struct mbxfb_platform_data cmx270_2700G_data = {
351 .memsize = 8*1024*1024,
352 .probe = cmx270_marathon_probe,
353 .remove = cmx270_marathon_remove,
356 static struct platform_device cmx270_2700G = {
359 .platform_data = &cmx270_2700G_data,
360 .dma_mask = &fb_dma_mask,
361 .coherent_dma_mask = 0xffffffff,
363 .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
364 .resource = cmx270_2700G_resource,
368 static void __init cmx270_init_2700G(void)
370 platform_device_register(&cmx270_2700G);
373 static inline void cmx270_init_2700G(void) {}
376 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
379 keep these for backwards compatibility, although symbolic names (as
380 e.g. in lpd270.c) looks better
382 #define MTYPE_STN320x240 0
383 #define MTYPE_TFT640x480 1
384 #define MTYPE_CRT640x480 2
385 #define MTYPE_CRT800x600 3
386 #define MTYPE_TFT320x240 6
387 #define MTYPE_STN640x480 7
389 static struct pxafb_mode_info generic_stn_320x240_mode = {
400 .sync = (FB_SYNC_HOR_HIGH_ACT |
401 FB_SYNC_VERT_HIGH_ACT),
405 static struct pxafb_mach_info generic_stn_320x240 = {
406 .modes = &generic_stn_320x240_mode,
409 .lccr3 = (LCCR3_PixClkDiv(0x03) |
416 static struct pxafb_mode_info generic_tft_640x480_mode = {
431 static struct pxafb_mach_info generic_tft_640x480 = {
432 .modes = &generic_tft_640x480_mode,
434 .lccr0 = (LCCR0_PAS),
435 .lccr3 = (LCCR3_PixClkDiv(0x01) |
442 static struct pxafb_mode_info generic_crt_640x480_mode = {
453 .sync = (FB_SYNC_HOR_HIGH_ACT |
454 FB_SYNC_VERT_HIGH_ACT),
458 static struct pxafb_mach_info generic_crt_640x480 = {
459 .modes = &generic_crt_640x480_mode,
461 .lccr0 = (LCCR0_PAS),
462 .lccr3 = (LCCR3_PixClkDiv(0x01) |
468 static struct pxafb_mode_info generic_crt_800x600_mode = {
479 .sync = (FB_SYNC_HOR_HIGH_ACT |
480 FB_SYNC_VERT_HIGH_ACT),
484 static struct pxafb_mach_info generic_crt_800x600 = {
485 .modes = &generic_crt_800x600_mode,
487 .lccr0 = (LCCR0_PAS),
488 .lccr3 = (LCCR3_PixClkDiv(0x02) |
494 static struct pxafb_mode_info generic_tft_320x240_mode = {
509 static struct pxafb_mach_info generic_tft_320x240 = {
510 .modes = &generic_tft_320x240_mode,
512 .lccr0 = (LCCR0_PAS),
513 .lccr3 = (LCCR3_PixClkDiv(0x06) |
520 static struct pxafb_mode_info generic_stn_640x480_mode = {
531 .sync = (FB_SYNC_HOR_HIGH_ACT |
532 FB_SYNC_VERT_HIGH_ACT),
536 static struct pxafb_mach_info generic_stn_640x480 = {
537 .modes = &generic_stn_640x480_mode,
540 .lccr3 = (LCCR3_PixClkDiv(0x02) |
546 static struct pxafb_mach_info *cmx270_display = &generic_crt_640x480;
548 static int __init cmx270_set_display(char *str)
550 int disp_type = simple_strtol(str, NULL, 0);
552 case MTYPE_STN320x240:
553 cmx270_display = &generic_stn_320x240;
555 case MTYPE_TFT640x480:
556 cmx270_display = &generic_tft_640x480;
558 case MTYPE_CRT640x480:
559 cmx270_display = &generic_crt_640x480;
561 case MTYPE_CRT800x600:
562 cmx270_display = &generic_crt_800x600;
564 case MTYPE_TFT320x240:
565 cmx270_display = &generic_tft_320x240;
567 case MTYPE_STN640x480:
568 cmx270_display = &generic_stn_640x480;
570 default: /* fallback to CRT 640x480 */
571 cmx270_display = &generic_crt_640x480;
578 This should be done really early to get proper configuration for
580 Indeed, pxafb parameters can be used istead, but CM-X270 bootloader
581 has limitied line length for kernel command line, and also it will
582 break compatibitlty with proprietary releases already in field.
584 __setup("monitor=", cmx270_set_display);
586 static void __init cmx270_init_display(void)
588 set_pxa_fb_info(cmx270_display);
591 static inline void cmx270_init_display(void) {}
594 /* PXA27x OHCI controller setup */
595 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
596 static int cmx270_ohci_init(struct device *dev)
598 /* Set the Power Control Polarity Low */
599 UHCHR = (UHCHR | UHCHR_PCPL) &
600 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE);
605 static struct pxaohci_platform_data cmx270_ohci_platform_data = {
606 .port_mode = PMM_PERPORT_MODE,
607 .init = cmx270_ohci_init,
610 static void __init cmx270_init_ohci(void)
612 pxa_set_ohci_info(&cmx270_ohci_platform_data);
615 static inline void cmx270_init_ohci(void) {}
618 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
619 static int cmx270_mci_init(struct device *dev,
620 irq_handler_t cmx270_detect_int,
625 err = gpio_request(GPIO105_MMC_POWER, "MMC/SD power");
627 dev_warn(dev, "power gpio unavailable\n");
631 gpio_direction_output(GPIO105_MMC_POWER, 0);
633 err = request_irq(CMX270_MMC_IRQ, cmx270_detect_int,
634 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
635 "MMC card detect", data);
637 gpio_free(GPIO105_MMC_POWER);
638 dev_err(dev, "cmx270_mci_init: MMC/SD: can't"
639 " request MMC card detect IRQ\n");
645 static void cmx270_mci_setpower(struct device *dev, unsigned int vdd)
647 struct pxamci_platform_data *p_d = dev->platform_data;
649 if ((1 << vdd) & p_d->ocr_mask) {
650 dev_dbg(dev, "power on\n");
651 gpio_set_value(GPIO105_MMC_POWER, 0);
653 gpio_set_value(GPIO105_MMC_POWER, 1);
654 dev_dbg(dev, "power off\n");
658 static void cmx270_mci_exit(struct device *dev, void *data)
660 free_irq(CMX270_MMC_IRQ, data);
661 gpio_free(GPIO105_MMC_POWER);
664 static struct pxamci_platform_data cmx270_mci_platform_data = {
665 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
666 .init = cmx270_mci_init,
667 .setpower = cmx270_mci_setpower,
668 .exit = cmx270_mci_exit,
671 static void __init cmx270_init_mmc(void)
673 pxa_set_mci_info(&cmx270_mci_platform_data);
676 static inline void cmx270_init_mmc(void) {}
680 static unsigned long sleep_save_msc[10];
682 static int cmx270_suspend(struct sys_device *dev, pm_message_t state)
684 cmx270_pci_suspend();
686 /* save MSC registers */
687 sleep_save_msc[0] = MSC0;
688 sleep_save_msc[1] = MSC1;
689 sleep_save_msc[2] = MSC2;
691 /* setup power saving mode registers */
706 static int cmx270_resume(struct sys_device *dev)
710 /* restore MSC registers */
711 MSC0 = sleep_save_msc[0];
712 MSC1 = sleep_save_msc[1];
713 MSC2 = sleep_save_msc[2];
718 static struct sysdev_class cmx270_pm_sysclass = {
720 .resume = cmx270_resume,
721 .suspend = cmx270_suspend,
724 static struct sys_device cmx270_pm_device = {
725 .cls = &cmx270_pm_sysclass,
728 static int __init cmx270_pm_init(void)
731 error = sysdev_class_register(&cmx270_pm_sysclass);
733 error = sysdev_register(&cmx270_pm_device);
737 static int __init cmx270_pm_init(void) { return 0; }
740 #if defined(CONFIG_SND_PXA2XX_AC97) || defined(CONFIG_SND_PXA2XX_AC97_MODULE)
741 static void __init cmx270_init_ac97(void)
743 pxa_set_ac97_info(NULL);
746 static inline void cmx270_init_ac97(void) {}
749 static void __init cmx270_init(void)
753 pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
755 cmx270_init_dm9000();
757 cmx270_init_display();
761 cmx270_init_touchscreen();
766 static void __init cmx270_init_irq(void)
770 cmx270_pci_init_irq(GPIO22_IT8152_IRQ);
774 /* Map PCI companion statically */
775 static struct map_desc cmx270_io_desc[] __initdata = {
776 [0] = { /* PCI bridge */
777 .virtual = CMX270_IT8152_VIRT,
778 .pfn = __phys_to_pfn(PXA_CS4_PHYS),
784 static void __init cmx270_map_io(void)
787 iotable_init(cmx270_io_desc, ARRAY_SIZE(cmx270_io_desc));
789 it8152_base_address = CMX270_IT8152_VIRT;
792 static void __init cmx270_map_io(void)
798 MACHINE_START(ARMCORE, "Compulab CM-x270")
799 .boot_params = 0xa0000100,
800 .phys_io = 0x40000000,
801 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
802 .map_io = cmx270_map_io,
803 .init_irq = cmx270_init_irq,
805 .init_machine = cmx270_init,