2 * linux/arch/arm/mach-pxa/cm-x270.c
4 * Copyright (C) 2007 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/types.h>
15 #include <linux/platform_device.h>
16 #include <linux/irq.h>
17 #include <linux/sysdev.h>
19 #include <linux/delay.h>
21 #include <linux/dm9000.h>
22 #include <linux/rtc-v3020.h>
23 #include <linux/serial_8250.h>
25 #include <video/mbxfb.h>
27 #include <asm/mach/arch.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/map.h>
31 #include <asm/arch/pxa-regs.h>
32 #include <asm/arch/pxa2xx-regs.h>
33 #include <asm/arch/pxa2xx-gpio.h>
34 #include <asm/arch/pxafb.h>
35 #include <asm/arch/ohci.h>
36 #include <asm/arch/mmc.h>
37 #include <asm/arch/bitfield.h>
38 #include <asm/arch/cm-x270.h>
40 #include <asm/hardware/it8152.h>
43 #include "cm-x270-pci.h"
45 #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
46 #define DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
48 static struct resource cmx270_dm9k_resource[] = {
50 .start = DM9000_PHYS_BASE,
51 .end = DM9000_PHYS_BASE + 4,
52 .flags = IORESOURCE_MEM,
55 .start = DM9000_PHYS_BASE + 8,
56 .end = DM9000_PHYS_BASE + 8 + 500,
57 .flags = IORESOURCE_MEM,
60 .start = CMX270_ETHIRQ,
62 .flags = IORESOURCE_IRQ,
66 /* for the moment we limit ourselves to 32bit IO until some
67 * better IO routines can be written and tested
69 static struct dm9000_plat_data cmx270_dm9k_platdata = {
70 .flags = DM9000_PLATF_32BITONLY,
74 static struct platform_device cmx270_device_dm9k = {
77 .num_resources = ARRAY_SIZE(cmx270_dm9k_resource),
78 .resource = cmx270_dm9k_resource,
80 .platform_data = &cmx270_dm9k_platdata,
85 static struct platform_device cmx270_audio_device = {
86 .name = "pxa2xx-ac97",
90 /* touchscreen controller */
91 static struct platform_device cmx270_ts_device = {
97 static struct resource cmx270_v3020_resource[] = {
99 .start = RTC_PHYS_BASE,
100 .end = RTC_PHYS_BASE + 4,
101 .flags = IORESOURCE_MEM,
105 struct v3020_platform_data cmx270_v3020_pdata = {
109 static struct platform_device cmx270_rtc_device = {
111 .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
112 .resource = cmx270_v3020_resource,
115 .platform_data = &cmx270_v3020_pdata,
122 static struct platform_device cmx270_led_device = {
123 .name = "cm-x270-led",
128 static u64 fb_dma_mask = ~(u64)0;
130 static struct resource cmx270_2700G_resource[] = {
131 /* frame buffer memory including ODFB and External SDRAM */
133 .start = MARATHON_PHYS,
134 .end = MARATHON_PHYS + 0x02000000,
135 .flags = IORESOURCE_MEM,
137 /* Marathon registers */
139 .start = MARATHON_PHYS + 0x03fe0000,
140 .end = MARATHON_PHYS + 0x03ffffff,
141 .flags = IORESOURCE_MEM,
145 static unsigned long save_lcd_regs[10];
147 static int cmx270_marathon_probe(struct fb_info *fb)
149 /* save PXA-270 pin settings before enabling 2700G */
150 save_lcd_regs[0] = GPDR1;
151 save_lcd_regs[1] = GPDR2;
152 save_lcd_regs[2] = GAFR1_U;
153 save_lcd_regs[3] = GAFR2_L;
154 save_lcd_regs[4] = GAFR2_U;
156 /* Disable PXA-270 on-chip controller driving pins */
157 GPDR1 &= ~(0xfc000000);
158 GPDR2 &= ~(0x00c03fff);
159 GAFR1_U &= ~(0xfff00000);
160 GAFR2_L &= ~(0x0fffffff);
161 GAFR2_U &= ~(0x0000f000);
165 static int cmx270_marathon_remove(struct fb_info *fb)
167 GPDR1 = save_lcd_regs[0];
168 GPDR2 = save_lcd_regs[1];
169 GAFR1_U = save_lcd_regs[2];
170 GAFR2_L = save_lcd_regs[3];
171 GAFR2_U = save_lcd_regs[4];
175 static struct mbxfb_platform_data cmx270_2700G_data = {
191 .memsize = 8*1024*1024,
192 .probe = cmx270_marathon_probe,
193 .remove = cmx270_marathon_remove,
196 static struct platform_device cmx270_2700G = {
199 .platform_data = &cmx270_2700G_data,
200 .dma_mask = &fb_dma_mask,
201 .coherent_dma_mask = 0xffffffff,
203 .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
204 .resource = cmx270_2700G_resource,
208 static u64 ata_dma_mask = ~(u64)0;
210 static struct platform_device cmx270_ata = {
211 .name = "pata_cm_x270",
214 .dma_mask = &ata_dma_mask,
215 .coherent_dma_mask = 0xffffffff,
219 /* platform devices */
220 static struct platform_device *platform_devices[] __initdata = {
222 &cmx270_audio_device,
230 /* Map PCI companion and IDE/General Purpose CS statically */
231 static struct map_desc cmx270_io_desc[] __initdata = {
232 [0] = { /* IDE/general purpose space */
233 .virtual = CMX270_IDE104_VIRT,
234 .pfn = __phys_to_pfn(CMX270_IDE104_PHYS),
235 .length = SZ_64M - SZ_8M,
238 [1] = { /* PCI bridge */
239 .virtual = CMX270_IT8152_VIRT,
240 .pfn = __phys_to_pfn(CMX270_IT8152_PHYS),
248 keep these for backwards compatibility, although symbolic names (as
249 e.g. in lpd270.c) looks better
251 #define MTYPE_STN320x240 0
252 #define MTYPE_TFT640x480 1
253 #define MTYPE_CRT640x480 2
254 #define MTYPE_CRT800x600 3
255 #define MTYPE_TFT320x240 6
256 #define MTYPE_STN640x480 7
258 static struct pxafb_mode_info generic_stn_320x240_mode = {
269 .sync = (FB_SYNC_HOR_HIGH_ACT |
270 FB_SYNC_VERT_HIGH_ACT),
274 static struct pxafb_mach_info generic_stn_320x240 = {
275 .modes = &generic_stn_320x240_mode,
278 .lccr3 = (LCCR3_PixClkDiv(0x03) |
285 static struct pxafb_mode_info generic_tft_640x480_mode = {
300 static struct pxafb_mach_info generic_tft_640x480 = {
301 .modes = &generic_tft_640x480_mode,
303 .lccr0 = (LCCR0_PAS),
304 .lccr3 = (LCCR3_PixClkDiv(0x01) |
311 static struct pxafb_mode_info generic_crt_640x480_mode = {
322 .sync = (FB_SYNC_HOR_HIGH_ACT |
323 FB_SYNC_VERT_HIGH_ACT),
327 static struct pxafb_mach_info generic_crt_640x480 = {
328 .modes = &generic_crt_640x480_mode,
330 .lccr0 = (LCCR0_PAS),
331 .lccr3 = (LCCR3_PixClkDiv(0x01) |
337 static struct pxafb_mode_info generic_crt_800x600_mode = {
348 .sync = (FB_SYNC_HOR_HIGH_ACT |
349 FB_SYNC_VERT_HIGH_ACT),
353 static struct pxafb_mach_info generic_crt_800x600 = {
354 .modes = &generic_crt_800x600_mode,
356 .lccr0 = (LCCR0_PAS),
357 .lccr3 = (LCCR3_PixClkDiv(0x02) |
363 static struct pxafb_mode_info generic_tft_320x240_mode = {
378 static struct pxafb_mach_info generic_tft_320x240 = {
379 .modes = &generic_tft_320x240_mode,
381 .lccr0 = (LCCR0_PAS),
382 .lccr3 = (LCCR3_PixClkDiv(0x06) |
389 static struct pxafb_mode_info generic_stn_640x480_mode = {
400 .sync = (FB_SYNC_HOR_HIGH_ACT |
401 FB_SYNC_VERT_HIGH_ACT),
405 static struct pxafb_mach_info generic_stn_640x480 = {
406 .modes = &generic_stn_640x480_mode,
409 .lccr3 = (LCCR3_PixClkDiv(0x02) |
415 static struct pxafb_mach_info *cmx270_display = &generic_crt_640x480;
417 static int __init cmx270_set_display(char *str)
419 int disp_type = simple_strtol(str, NULL, 0);
421 case MTYPE_STN320x240:
422 cmx270_display = &generic_stn_320x240;
424 case MTYPE_TFT640x480:
425 cmx270_display = &generic_tft_640x480;
427 case MTYPE_CRT640x480:
428 cmx270_display = &generic_crt_640x480;
430 case MTYPE_CRT800x600:
431 cmx270_display = &generic_crt_800x600;
433 case MTYPE_TFT320x240:
434 cmx270_display = &generic_tft_320x240;
436 case MTYPE_STN640x480:
437 cmx270_display = &generic_stn_640x480;
439 default: /* fallback to CRT 640x480 */
440 cmx270_display = &generic_crt_640x480;
447 This should be done really early to get proper configuration for
449 Indeed, pxafb parameters can be used istead, but CM-X270 bootloader
450 has limitied line length for kernel command line, and also it will
451 break compatibitlty with proprietary releases already in field.
453 __setup("monitor=", cmx270_set_display);
455 /* PXA27x OHCI controller setup */
456 static int cmx270_ohci_init(struct device *dev)
458 /* Set the Power Control Polarity Low */
459 UHCHR = (UHCHR | UHCHR_PCPL) &
460 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE);
465 static struct pxaohci_platform_data cmx270_ohci_platform_data = {
466 .port_mode = PMM_PERPORT_MODE,
467 .init = cmx270_ohci_init,
471 static int cmx270_mci_init(struct device *dev,
472 irq_handler_t cmx270_detect_int,
478 * setup GPIO for PXA27x MMC controller
480 pxa_gpio_mode(GPIO32_MMCCLK_MD);
481 pxa_gpio_mode(GPIO112_MMCCMD_MD);
482 pxa_gpio_mode(GPIO92_MMCDAT0_MD);
483 pxa_gpio_mode(GPIO109_MMCDAT1_MD);
484 pxa_gpio_mode(GPIO110_MMCDAT2_MD);
485 pxa_gpio_mode(GPIO111_MMCDAT3_MD);
487 /* SB-X270 uses GPIO105 as SD power enable */
488 pxa_gpio_mode(105 | GPIO_OUT);
490 /* card detect IRQ on GPIO 83 */
491 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_MMC_IRQ));
493 err = request_irq(CMX270_MMC_IRQ, cmx270_detect_int,
494 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
495 "MMC card detect", data);
497 printk(KERN_ERR "cmx270_mci_init: MMC/SD: can't"
498 " request MMC card detect IRQ\n");
503 static void cmx270_mci_setpower(struct device *dev, unsigned int vdd)
505 struct pxamci_platform_data *p_d = dev->platform_data;
507 if ((1 << vdd) & p_d->ocr_mask) {
508 printk(KERN_DEBUG "%s: on\n", __func__);
509 GPCR(105) = GPIO_bit(105);
511 GPSR(105) = GPIO_bit(105);
512 printk(KERN_DEBUG "%s: off\n", __func__);
516 static void cmx270_mci_exit(struct device *dev, void *data)
518 free_irq(CMX270_MMC_IRQ, data);
521 static struct pxamci_platform_data cmx270_mci_platform_data = {
522 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
523 .init = cmx270_mci_init,
524 .setpower = cmx270_mci_setpower,
525 .exit = cmx270_mci_exit,
529 static unsigned long sleep_save_msc[10];
531 static int cmx270_suspend(struct sys_device *dev, pm_message_t state)
533 cmx270_pci_suspend();
535 /* save MSC registers */
536 sleep_save_msc[0] = MSC0;
537 sleep_save_msc[1] = MSC1;
538 sleep_save_msc[2] = MSC2;
540 /* setup power saving mode registers */
555 static int cmx270_resume(struct sys_device *dev)
559 /* restore MSC registers */
560 MSC0 = sleep_save_msc[0];
561 MSC1 = sleep_save_msc[1];
562 MSC2 = sleep_save_msc[2];
567 static struct sysdev_class cmx270_pm_sysclass = {
569 .resume = cmx270_resume,
570 .suspend = cmx270_suspend,
573 static struct sys_device cmx270_pm_device = {
574 .cls = &cmx270_pm_sysclass,
577 static int __init cmx270_pm_init(void)
580 error = sysdev_class_register(&cmx270_pm_sysclass);
582 error = sysdev_register(&cmx270_pm_device);
586 static int __init cmx270_pm_init(void) { return 0; }
589 static void __init cmx270_init(void)
593 set_pxa_fb_info(cmx270_display);
595 /* register CM-X270 platform devices */
596 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
598 /* set MCI and OHCI platform parameters */
599 pxa_set_mci_info(&cmx270_mci_platform_data);
600 pxa_set_ohci_info(&cmx270_ohci_platform_data);
602 /* This enables the STUART */
603 pxa_gpio_mode(GPIO46_STRXD_MD);
604 pxa_gpio_mode(GPIO47_STTXD_MD);
606 /* This enables the BTUART */
607 pxa_gpio_mode(GPIO42_BTRXD_MD);
608 pxa_gpio_mode(GPIO43_BTTXD_MD);
609 pxa_gpio_mode(GPIO44_BTCTS_MD);
610 pxa_gpio_mode(GPIO45_BTRTS_MD);
613 static void __init cmx270_init_irq(void)
618 cmx270_pci_init_irq();
620 /* Setup interrupt for dm9000 */
621 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_ETHIRQ));
622 set_irq_type(CMX270_ETHIRQ, IRQT_RISING);
624 /* Setup interrupt for 2700G */
625 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_GFXIRQ));
626 set_irq_type(CMX270_GFXIRQ, IRQT_FALLING);
629 static void __init cmx270_map_io(void)
632 iotable_init(cmx270_io_desc, ARRAY_SIZE(cmx270_io_desc));
636 MACHINE_START(ARMCORE, "Compulab CM-x270")
637 .boot_params = 0xa0000100,
638 .phys_io = 0x40000000,
639 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
640 .map_io = cmx270_map_io,
641 .init_irq = cmx270_init_irq,
643 .init_machine = cmx270_init,