2 * linux/arch/arm/mach-pxa/cm-x2xx.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-x2xx-pci.h"
40 /* virtual addresses for statically mapped regions */
41 #define CMX2XX_VIRT_BASE (0xe8000000)
42 #define CMX2XX_IT8152_VIRT (CMX2XX_VIRT_BASE)
44 #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
45 #define CMX270_DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
48 #define CMX270_GPIO_RED (93)
49 #define CMX270_GPIO_GREEN (94)
52 #define GPIO10_ETHIRQ (10)
53 #define CMX270_GPIO_IT8152_IRQ (22)
54 #define GPIO83_MMC_IRQ (83)
55 #define GPIO95_GFXIRQ (95)
57 #define CMX270_ETHIRQ IRQ_GPIO(GPIO10_ETHIRQ)
58 #define CMX270_MMC_IRQ IRQ_GPIO(GPIO83_MMC_IRQ)
59 #define CMX270_GFXIRQ IRQ_GPIO(GPIO95_GFXIRQ)
61 /* MMC power enable */
62 #define GPIO105_MMC_POWER (105)
64 static unsigned long cmx270_pin_config[] = {
67 GPIO29_AC97_SDATA_IN_0,
68 GPIO30_AC97_SDATA_OUT,
140 /* SDRAM and local bus */
150 GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,
151 GPIO105_GPIO | MFP_LPM_DRIVE_HIGH, /* MMC/SD power */
152 GPIO53_GPIO, /* PC card reset */
155 GPIO11_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */
156 GPIO89_GPIO, /* NAND Ready/Busy */
159 GPIO10_GPIO, /* DM9000 interrupt */
160 GPIO83_GPIO, /* MMC card detect */
163 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
164 static struct resource cmx270_dm9000_resource[] = {
166 .start = CMX270_DM9000_PHYS_BASE,
167 .end = CMX270_DM9000_PHYS_BASE + 3,
168 .flags = IORESOURCE_MEM,
171 .start = CMX270_DM9000_PHYS_BASE + 8,
172 .end = CMX270_DM9000_PHYS_BASE + 8 + 500,
173 .flags = IORESOURCE_MEM,
176 .start = CMX270_ETHIRQ,
177 .end = CMX270_ETHIRQ,
178 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
182 static struct dm9000_plat_data cmx270_dm9000_platdata = {
183 .flags = DM9000_PLATF_32BITONLY,
186 static struct platform_device cmx2xx_dm9000_device = {
189 .num_resources = ARRAY_SIZE(cmx270_dm9000_resource),
191 .platform_data = &cmx270_dm9000_platdata,
195 static void __init cmx2xx_init_dm9000(void)
197 cmx2xx_dm9000_device.resource = cmx270_dm9000_resource,
198 platform_device_register(&cmx2xx_dm9000_device);
201 static inline void cmx2xx_init_dm9000(void) {}
204 /* UCB1400 touchscreen controller */
205 #if defined(CONFIG_TOUCHSCREEN_UCB1400) || defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
206 static struct platform_device cmx2xx_ts_device = {
207 .name = "ucb1400_ts",
211 static void __init cmx2xx_init_touchscreen(void)
213 platform_device_register(&cmx2xx_ts_device);
216 static inline void cmx2xx_init_touchscreen(void) {}
220 #if defined(CONFIG_RTC_DRV_V3020) || defined(CONFIG_RTC_DRV_V3020_MODULE)
221 static struct resource cmx270_v3020_resource[] = {
223 .start = RTC_PHYS_BASE,
224 .end = RTC_PHYS_BASE + 4,
225 .flags = IORESOURCE_MEM,
229 struct v3020_platform_data cmx270_v3020_pdata = {
233 static struct platform_device cmx270_rtc_device = {
235 .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
236 .resource = cmx270_v3020_resource,
239 .platform_data = &cmx270_v3020_pdata,
243 static void __init cmx270_init_rtc(void)
245 platform_device_register(&cmx270_rtc_device);
248 static inline void cmx2xx_init_rtc(void) {}
252 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
253 static struct gpio_led cmx2xx_leds[] = {
255 .name = "cm-x2xx:red",
256 .default_trigger = "nand-disk",
260 .name = "cm-x2xx:green",
261 .default_trigger = "heartbeat",
266 static struct gpio_led_platform_data cmx2xx_gpio_led_pdata = {
267 .num_leds = ARRAY_SIZE(cmx2xx_leds),
271 static struct platform_device cmx2xx_led_device = {
275 .platform_data = &cmx2xx_gpio_led_pdata,
279 static void __init cmx2xx_init_leds(void)
281 cmx2xx_leds[0].gpio = CMX270_GPIO_RED;
282 cmx2xx_leds[1].gpio = CMX270_GPIO_GREEN;
283 platform_device_register(&cmx2xx_led_device);
286 static inline void cmx2xx_init_leds(void) {}
290 #if defined(CONFIG_FB_MBX) || defined(CONFIG_FB_MBX_MODULE)
291 static u64 fb_dma_mask = ~(u64)0;
293 static struct resource cmx270_2700G_resource[] = {
294 /* frame buffer memory including ODFB and External SDRAM */
296 .start = PXA_CS2_PHYS,
297 .end = PXA_CS2_PHYS + 0x01ffffff,
298 .flags = IORESOURCE_MEM,
300 /* Marathon registers */
302 .start = PXA_CS2_PHYS + 0x03fe0000,
303 .end = PXA_CS2_PHYS + 0x03ffffff,
304 .flags = IORESOURCE_MEM,
308 static unsigned long save_lcd_regs[10];
310 static int cmx270_marathon_probe(struct fb_info *fb)
312 /* save PXA-270 pin settings before enabling 2700G */
313 save_lcd_regs[0] = GPDR1;
314 save_lcd_regs[1] = GPDR2;
315 save_lcd_regs[2] = GAFR1_U;
316 save_lcd_regs[3] = GAFR2_L;
317 save_lcd_regs[4] = GAFR2_U;
319 /* Disable PXA-270 on-chip controller driving pins */
320 GPDR1 &= ~(0xfc000000);
321 GPDR2 &= ~(0x00c03fff);
322 GAFR1_U &= ~(0xfff00000);
323 GAFR2_L &= ~(0x0fffffff);
324 GAFR2_U &= ~(0x0000f000);
328 static int cmx270_marathon_remove(struct fb_info *fb)
330 GPDR1 = save_lcd_regs[0];
331 GPDR2 = save_lcd_regs[1];
332 GAFR1_U = save_lcd_regs[2];
333 GAFR2_L = save_lcd_regs[3];
334 GAFR2_U = save_lcd_regs[4];
338 static struct mbxfb_platform_data cmx270_2700G_data = {
354 .memsize = 8*1024*1024,
355 .probe = cmx270_marathon_probe,
356 .remove = cmx270_marathon_remove,
359 static struct platform_device cmx270_2700G = {
362 .platform_data = &cmx270_2700G_data,
363 .dma_mask = &fb_dma_mask,
364 .coherent_dma_mask = 0xffffffff,
366 .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
367 .resource = cmx270_2700G_resource,
371 static void __init cmx270_init_2700G(void)
373 platform_device_register(&cmx270_2700G);
376 static inline void cmx270_init_2700G(void) {}
379 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
382 keep these for backwards compatibility, although symbolic names (as
383 e.g. in lpd270.c) looks better
385 #define MTYPE_STN320x240 0
386 #define MTYPE_TFT640x480 1
387 #define MTYPE_CRT640x480 2
388 #define MTYPE_CRT800x600 3
389 #define MTYPE_TFT320x240 6
390 #define MTYPE_STN640x480 7
392 static struct pxafb_mode_info generic_stn_320x240_mode = {
403 .sync = (FB_SYNC_HOR_HIGH_ACT |
404 FB_SYNC_VERT_HIGH_ACT),
408 static struct pxafb_mach_info generic_stn_320x240 = {
409 .modes = &generic_stn_320x240_mode,
412 .lccr3 = (LCCR3_PixClkDiv(0x03) |
419 static struct pxafb_mode_info generic_tft_640x480_mode = {
434 static struct pxafb_mach_info generic_tft_640x480 = {
435 .modes = &generic_tft_640x480_mode,
437 .lccr0 = (LCCR0_PAS),
438 .lccr3 = (LCCR3_PixClkDiv(0x01) |
445 static struct pxafb_mode_info generic_crt_640x480_mode = {
456 .sync = (FB_SYNC_HOR_HIGH_ACT |
457 FB_SYNC_VERT_HIGH_ACT),
461 static struct pxafb_mach_info generic_crt_640x480 = {
462 .modes = &generic_crt_640x480_mode,
464 .lccr0 = (LCCR0_PAS),
465 .lccr3 = (LCCR3_PixClkDiv(0x01) |
471 static struct pxafb_mode_info generic_crt_800x600_mode = {
482 .sync = (FB_SYNC_HOR_HIGH_ACT |
483 FB_SYNC_VERT_HIGH_ACT),
487 static struct pxafb_mach_info generic_crt_800x600 = {
488 .modes = &generic_crt_800x600_mode,
490 .lccr0 = (LCCR0_PAS),
491 .lccr3 = (LCCR3_PixClkDiv(0x02) |
497 static struct pxafb_mode_info generic_tft_320x240_mode = {
512 static struct pxafb_mach_info generic_tft_320x240 = {
513 .modes = &generic_tft_320x240_mode,
515 .lccr0 = (LCCR0_PAS),
516 .lccr3 = (LCCR3_PixClkDiv(0x06) |
523 static struct pxafb_mode_info generic_stn_640x480_mode = {
534 .sync = (FB_SYNC_HOR_HIGH_ACT |
535 FB_SYNC_VERT_HIGH_ACT),
539 static struct pxafb_mach_info generic_stn_640x480 = {
540 .modes = &generic_stn_640x480_mode,
543 .lccr3 = (LCCR3_PixClkDiv(0x02) |
549 static struct pxafb_mach_info *cmx2xx_display = &generic_crt_640x480;
551 static int __init cmx2xx_set_display(char *str)
553 int disp_type = simple_strtol(str, NULL, 0);
555 case MTYPE_STN320x240:
556 cmx2xx_display = &generic_stn_320x240;
558 case MTYPE_TFT640x480:
559 cmx2xx_display = &generic_tft_640x480;
561 case MTYPE_CRT640x480:
562 cmx2xx_display = &generic_crt_640x480;
564 case MTYPE_CRT800x600:
565 cmx2xx_display = &generic_crt_800x600;
567 case MTYPE_TFT320x240:
568 cmx2xx_display = &generic_tft_320x240;
570 case MTYPE_STN640x480:
571 cmx2xx_display = &generic_stn_640x480;
573 default: /* fallback to CRT 640x480 */
574 cmx2xx_display = &generic_crt_640x480;
581 This should be done really early to get proper configuration for
583 Indeed, pxafb parameters can be used istead, but CM-X2XX bootloader
584 has limitied line length for kernel command line, and also it will
585 break compatibitlty with proprietary releases already in field.
587 __setup("monitor=", cmx2xx_set_display);
589 static void __init cmx2xx_init_display(void)
591 set_pxa_fb_info(cmx2xx_display);
594 static inline void cmx2xx_init_display(void) {}
597 /* PXA27x OHCI controller setup */
598 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
599 static int cmx270_ohci_init(struct device *dev)
601 /* Set the Power Control Polarity Low */
602 UHCHR = (UHCHR | UHCHR_PCPL) &
603 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE);
608 static struct pxaohci_platform_data cmx270_ohci_platform_data = {
609 .port_mode = PMM_PERPORT_MODE,
610 .init = cmx270_ohci_init,
613 static void __init cmx270_init_ohci(void)
615 pxa_set_ohci_info(&cmx270_ohci_platform_data);
618 static inline void cmx270_init_ohci(void) {}
621 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
622 static int cmx270_mci_init(struct device *dev,
623 irq_handler_t cmx270_detect_int,
628 err = gpio_request(GPIO105_MMC_POWER, "MMC/SD power");
630 dev_warn(dev, "power gpio unavailable\n");
634 gpio_direction_output(GPIO105_MMC_POWER, 0);
636 err = request_irq(CMX270_MMC_IRQ, cmx270_detect_int,
637 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
638 "MMC card detect", data);
640 gpio_free(GPIO105_MMC_POWER);
641 dev_err(dev, "cmx270_mci_init: MMC/SD: can't"
642 " request MMC card detect IRQ\n");
648 static void cmx270_mci_setpower(struct device *dev, unsigned int vdd)
650 struct pxamci_platform_data *p_d = dev->platform_data;
652 if ((1 << vdd) & p_d->ocr_mask) {
653 dev_dbg(dev, "power on\n");
654 gpio_set_value(GPIO105_MMC_POWER, 0);
656 gpio_set_value(GPIO105_MMC_POWER, 1);
657 dev_dbg(dev, "power off\n");
661 static void cmx270_mci_exit(struct device *dev, void *data)
663 free_irq(CMX270_MMC_IRQ, data);
664 gpio_free(GPIO105_MMC_POWER);
667 static struct pxamci_platform_data cmx270_mci_platform_data = {
668 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
669 .init = cmx270_mci_init,
670 .setpower = cmx270_mci_setpower,
671 .exit = cmx270_mci_exit,
674 static void __init cmx270_init_mmc(void)
676 pxa_set_mci_info(&cmx270_mci_platform_data);
679 static inline void cmx270_init_mmc(void) {}
683 static unsigned long sleep_save_msc[10];
685 static int cmx2xx_suspend(struct sys_device *dev, pm_message_t state)
687 cmx2xx_pci_suspend();
689 /* save MSC registers */
690 sleep_save_msc[0] = MSC0;
691 sleep_save_msc[1] = MSC1;
692 sleep_save_msc[2] = MSC2;
694 /* setup power saving mode registers */
709 static int cmx2xx_resume(struct sys_device *dev)
713 /* restore MSC registers */
714 MSC0 = sleep_save_msc[0];
715 MSC1 = sleep_save_msc[1];
716 MSC2 = sleep_save_msc[2];
721 static struct sysdev_class cmx2xx_pm_sysclass = {
723 .resume = cmx2xx_resume,
724 .suspend = cmx2xx_suspend,
727 static struct sys_device cmx2xx_pm_device = {
728 .cls = &cmx2xx_pm_sysclass,
731 static int __init cmx2xx_pm_init(void)
734 error = sysdev_class_register(&cmx2xx_pm_sysclass);
736 error = sysdev_register(&cmx2xx_pm_device);
740 static int __init cmx2xx_pm_init(void) { return 0; }
743 #if defined(CONFIG_SND_PXA2XX_AC97) || defined(CONFIG_SND_PXA2XX_AC97_MODULE)
744 static void __init cmx2xx_init_ac97(void)
746 pxa_set_ac97_info(NULL);
749 static inline void cmx2xx_init_ac97(void) {}
752 static void __init cmx270_init(void)
754 pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx270_pin_config));
762 static void __init cmx2xx_init(void)
768 cmx2xx_init_dm9000();
769 cmx2xx_init_display();
771 cmx2xx_init_touchscreen();
775 static void __init cmx2xx_init_irq(void)
779 cmx2xx_pci_init_irq(CMX270_GPIO_IT8152_IRQ);
783 /* Map PCI companion statically */
784 static struct map_desc cmx2xx_io_desc[] __initdata = {
785 [0] = { /* PCI bridge */
786 .virtual = CMX2XX_IT8152_VIRT,
787 .pfn = __phys_to_pfn(PXA_CS4_PHYS),
793 static void __init cmx2xx_map_io(void)
796 iotable_init(cmx2xx_io_desc, ARRAY_SIZE(cmx2xx_io_desc));
798 it8152_base_address = CMX2XX_IT8152_VIRT;
801 static void __init cmx2xx_map_io(void)
807 MACHINE_START(ARMCORE, "Compulab CM-X2XX")
808 .boot_params = 0xa0000100,
809 .phys_io = 0x40000000,
810 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
811 .map_io = cmx2xx_map_io,
812 .init_irq = cmx2xx_init_irq,
814 .init_machine = cmx2xx_init,