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/audio.h>
35 #include <asm/arch/pxafb.h>
36 #include <asm/arch/ohci.h>
37 #include <asm/arch/mmc.h>
38 #include <asm/arch/bitfield.h>
39 #include <asm/arch/cm-x270.h>
41 #include <asm/hardware/it8152.h>
44 #include "cm-x270-pci.h"
46 #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
47 #define DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
49 static struct resource cmx270_dm9k_resource[] = {
51 .start = DM9000_PHYS_BASE,
52 .end = DM9000_PHYS_BASE + 4,
53 .flags = IORESOURCE_MEM,
56 .start = DM9000_PHYS_BASE + 8,
57 .end = DM9000_PHYS_BASE + 8 + 500,
58 .flags = IORESOURCE_MEM,
61 .start = CMX270_ETHIRQ,
63 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
67 /* for the moment we limit ourselves to 32bit IO until some
68 * better IO routines can be written and tested
70 static struct dm9000_plat_data cmx270_dm9k_platdata = {
71 .flags = DM9000_PLATF_32BITONLY,
75 static struct platform_device cmx270_device_dm9k = {
78 .num_resources = ARRAY_SIZE(cmx270_dm9k_resource),
79 .resource = cmx270_dm9k_resource,
81 .platform_data = &cmx270_dm9k_platdata,
85 /* touchscreen controller */
86 static struct platform_device cmx270_ts_device = {
92 static struct resource cmx270_v3020_resource[] = {
94 .start = RTC_PHYS_BASE,
95 .end = RTC_PHYS_BASE + 4,
96 .flags = IORESOURCE_MEM,
100 struct v3020_platform_data cmx270_v3020_pdata = {
104 static struct platform_device cmx270_rtc_device = {
106 .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
107 .resource = cmx270_v3020_resource,
110 .platform_data = &cmx270_v3020_pdata,
117 static struct platform_device cmx270_led_device = {
118 .name = "cm-x270-led",
123 static u64 fb_dma_mask = ~(u64)0;
125 static struct resource cmx270_2700G_resource[] = {
126 /* frame buffer memory including ODFB and External SDRAM */
128 .start = MARATHON_PHYS,
129 .end = MARATHON_PHYS + 0x02000000,
130 .flags = IORESOURCE_MEM,
132 /* Marathon registers */
134 .start = MARATHON_PHYS + 0x03fe0000,
135 .end = MARATHON_PHYS + 0x03ffffff,
136 .flags = IORESOURCE_MEM,
140 static unsigned long save_lcd_regs[10];
142 static int cmx270_marathon_probe(struct fb_info *fb)
144 /* save PXA-270 pin settings before enabling 2700G */
145 save_lcd_regs[0] = GPDR1;
146 save_lcd_regs[1] = GPDR2;
147 save_lcd_regs[2] = GAFR1_U;
148 save_lcd_regs[3] = GAFR2_L;
149 save_lcd_regs[4] = GAFR2_U;
151 /* Disable PXA-270 on-chip controller driving pins */
152 GPDR1 &= ~(0xfc000000);
153 GPDR2 &= ~(0x00c03fff);
154 GAFR1_U &= ~(0xfff00000);
155 GAFR2_L &= ~(0x0fffffff);
156 GAFR2_U &= ~(0x0000f000);
160 static int cmx270_marathon_remove(struct fb_info *fb)
162 GPDR1 = save_lcd_regs[0];
163 GPDR2 = save_lcd_regs[1];
164 GAFR1_U = save_lcd_regs[2];
165 GAFR2_L = save_lcd_regs[3];
166 GAFR2_U = save_lcd_regs[4];
170 static struct mbxfb_platform_data cmx270_2700G_data = {
186 .memsize = 8*1024*1024,
187 .probe = cmx270_marathon_probe,
188 .remove = cmx270_marathon_remove,
191 static struct platform_device cmx270_2700G = {
194 .platform_data = &cmx270_2700G_data,
195 .dma_mask = &fb_dma_mask,
196 .coherent_dma_mask = 0xffffffff,
198 .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
199 .resource = cmx270_2700G_resource,
203 static u64 ata_dma_mask = ~(u64)0;
205 static struct platform_device cmx270_ata = {
206 .name = "pata_cm_x270",
209 .dma_mask = &ata_dma_mask,
210 .coherent_dma_mask = 0xffffffff,
214 /* platform devices */
215 static struct platform_device *platform_devices[] __initdata = {
224 /* Map PCI companion and IDE/General Purpose CS statically */
225 static struct map_desc cmx270_io_desc[] __initdata = {
226 [0] = { /* IDE/general purpose space */
227 .virtual = CMX270_IDE104_VIRT,
228 .pfn = __phys_to_pfn(CMX270_IDE104_PHYS),
229 .length = SZ_64M - SZ_8M,
232 [1] = { /* PCI bridge */
233 .virtual = CMX270_IT8152_VIRT,
234 .pfn = __phys_to_pfn(CMX270_IT8152_PHYS),
242 keep these for backwards compatibility, although symbolic names (as
243 e.g. in lpd270.c) looks better
245 #define MTYPE_STN320x240 0
246 #define MTYPE_TFT640x480 1
247 #define MTYPE_CRT640x480 2
248 #define MTYPE_CRT800x600 3
249 #define MTYPE_TFT320x240 6
250 #define MTYPE_STN640x480 7
252 static struct pxafb_mode_info generic_stn_320x240_mode = {
263 .sync = (FB_SYNC_HOR_HIGH_ACT |
264 FB_SYNC_VERT_HIGH_ACT),
268 static struct pxafb_mach_info generic_stn_320x240 = {
269 .modes = &generic_stn_320x240_mode,
272 .lccr3 = (LCCR3_PixClkDiv(0x03) |
279 static struct pxafb_mode_info generic_tft_640x480_mode = {
294 static struct pxafb_mach_info generic_tft_640x480 = {
295 .modes = &generic_tft_640x480_mode,
297 .lccr0 = (LCCR0_PAS),
298 .lccr3 = (LCCR3_PixClkDiv(0x01) |
305 static struct pxafb_mode_info generic_crt_640x480_mode = {
316 .sync = (FB_SYNC_HOR_HIGH_ACT |
317 FB_SYNC_VERT_HIGH_ACT),
321 static struct pxafb_mach_info generic_crt_640x480 = {
322 .modes = &generic_crt_640x480_mode,
324 .lccr0 = (LCCR0_PAS),
325 .lccr3 = (LCCR3_PixClkDiv(0x01) |
331 static struct pxafb_mode_info generic_crt_800x600_mode = {
342 .sync = (FB_SYNC_HOR_HIGH_ACT |
343 FB_SYNC_VERT_HIGH_ACT),
347 static struct pxafb_mach_info generic_crt_800x600 = {
348 .modes = &generic_crt_800x600_mode,
350 .lccr0 = (LCCR0_PAS),
351 .lccr3 = (LCCR3_PixClkDiv(0x02) |
357 static struct pxafb_mode_info generic_tft_320x240_mode = {
372 static struct pxafb_mach_info generic_tft_320x240 = {
373 .modes = &generic_tft_320x240_mode,
375 .lccr0 = (LCCR0_PAS),
376 .lccr3 = (LCCR3_PixClkDiv(0x06) |
383 static struct pxafb_mode_info generic_stn_640x480_mode = {
394 .sync = (FB_SYNC_HOR_HIGH_ACT |
395 FB_SYNC_VERT_HIGH_ACT),
399 static struct pxafb_mach_info generic_stn_640x480 = {
400 .modes = &generic_stn_640x480_mode,
403 .lccr3 = (LCCR3_PixClkDiv(0x02) |
409 static struct pxafb_mach_info *cmx270_display = &generic_crt_640x480;
411 static int __init cmx270_set_display(char *str)
413 int disp_type = simple_strtol(str, NULL, 0);
415 case MTYPE_STN320x240:
416 cmx270_display = &generic_stn_320x240;
418 case MTYPE_TFT640x480:
419 cmx270_display = &generic_tft_640x480;
421 case MTYPE_CRT640x480:
422 cmx270_display = &generic_crt_640x480;
424 case MTYPE_CRT800x600:
425 cmx270_display = &generic_crt_800x600;
427 case MTYPE_TFT320x240:
428 cmx270_display = &generic_tft_320x240;
430 case MTYPE_STN640x480:
431 cmx270_display = &generic_stn_640x480;
433 default: /* fallback to CRT 640x480 */
434 cmx270_display = &generic_crt_640x480;
441 This should be done really early to get proper configuration for
443 Indeed, pxafb parameters can be used istead, but CM-X270 bootloader
444 has limitied line length for kernel command line, and also it will
445 break compatibitlty with proprietary releases already in field.
447 __setup("monitor=", cmx270_set_display);
449 /* PXA27x OHCI controller setup */
450 static int cmx270_ohci_init(struct device *dev)
452 /* Set the Power Control Polarity Low */
453 UHCHR = (UHCHR | UHCHR_PCPL) &
454 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE);
459 static struct pxaohci_platform_data cmx270_ohci_platform_data = {
460 .port_mode = PMM_PERPORT_MODE,
461 .init = cmx270_ohci_init,
465 static int cmx270_mci_init(struct device *dev,
466 irq_handler_t cmx270_detect_int,
472 * setup GPIO for PXA27x MMC controller
474 pxa_gpio_mode(GPIO32_MMCCLK_MD);
475 pxa_gpio_mode(GPIO112_MMCCMD_MD);
476 pxa_gpio_mode(GPIO92_MMCDAT0_MD);
477 pxa_gpio_mode(GPIO109_MMCDAT1_MD);
478 pxa_gpio_mode(GPIO110_MMCDAT2_MD);
479 pxa_gpio_mode(GPIO111_MMCDAT3_MD);
481 /* SB-X270 uses GPIO105 as SD power enable */
482 pxa_gpio_mode(105 | GPIO_OUT);
484 /* card detect IRQ on GPIO 83 */
485 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_MMC_IRQ));
487 err = request_irq(CMX270_MMC_IRQ, cmx270_detect_int,
488 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
489 "MMC card detect", data);
491 printk(KERN_ERR "cmx270_mci_init: MMC/SD: can't"
492 " request MMC card detect IRQ\n");
497 static void cmx270_mci_setpower(struct device *dev, unsigned int vdd)
499 struct pxamci_platform_data *p_d = dev->platform_data;
501 if ((1 << vdd) & p_d->ocr_mask) {
502 printk(KERN_DEBUG "%s: on\n", __func__);
503 GPCR(105) = GPIO_bit(105);
505 GPSR(105) = GPIO_bit(105);
506 printk(KERN_DEBUG "%s: off\n", __func__);
510 static void cmx270_mci_exit(struct device *dev, void *data)
512 free_irq(CMX270_MMC_IRQ, data);
515 static struct pxamci_platform_data cmx270_mci_platform_data = {
516 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
517 .init = cmx270_mci_init,
518 .setpower = cmx270_mci_setpower,
519 .exit = cmx270_mci_exit,
523 static unsigned long sleep_save_msc[10];
525 static int cmx270_suspend(struct sys_device *dev, pm_message_t state)
527 cmx270_pci_suspend();
529 /* save MSC registers */
530 sleep_save_msc[0] = MSC0;
531 sleep_save_msc[1] = MSC1;
532 sleep_save_msc[2] = MSC2;
534 /* setup power saving mode registers */
549 static int cmx270_resume(struct sys_device *dev)
553 /* restore MSC registers */
554 MSC0 = sleep_save_msc[0];
555 MSC1 = sleep_save_msc[1];
556 MSC2 = sleep_save_msc[2];
561 static struct sysdev_class cmx270_pm_sysclass = {
563 .resume = cmx270_resume,
564 .suspend = cmx270_suspend,
567 static struct sys_device cmx270_pm_device = {
568 .cls = &cmx270_pm_sysclass,
571 static int __init cmx270_pm_init(void)
574 error = sysdev_class_register(&cmx270_pm_sysclass);
576 error = sysdev_register(&cmx270_pm_device);
580 static int __init cmx270_pm_init(void) { return 0; }
583 static void __init cmx270_init(void)
587 set_pxa_fb_info(cmx270_display);
589 /* register CM-X270 platform devices */
590 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
591 pxa_set_ac97_info(NULL);
593 /* set MCI and OHCI platform parameters */
594 pxa_set_mci_info(&cmx270_mci_platform_data);
595 pxa_set_ohci_info(&cmx270_ohci_platform_data);
597 /* This enables the STUART */
598 pxa_gpio_mode(GPIO46_STRXD_MD);
599 pxa_gpio_mode(GPIO47_STTXD_MD);
601 /* This enables the BTUART */
602 pxa_gpio_mode(GPIO42_BTRXD_MD);
603 pxa_gpio_mode(GPIO43_BTTXD_MD);
604 pxa_gpio_mode(GPIO44_BTCTS_MD);
605 pxa_gpio_mode(GPIO45_BTRTS_MD);
608 static void __init cmx270_init_irq(void)
613 cmx270_pci_init_irq();
615 /* Setup interrupt for dm9000 */
616 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_ETHIRQ));
617 set_irq_type(CMX270_ETHIRQ, IRQT_RISING);
619 /* Setup interrupt for 2700G */
620 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_GFXIRQ));
621 set_irq_type(CMX270_GFXIRQ, IRQT_FALLING);
624 static void __init cmx270_map_io(void)
627 iotable_init(cmx270_io_desc, ARRAY_SIZE(cmx270_io_desc));
631 MACHINE_START(ARMCORE, "Compulab CM-x270")
632 .boot_params = 0xa0000100,
633 .phys_io = 0x40000000,
634 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
635 .map_io = cmx270_map_io,
636 .init_irq = cmx270_init_irq,
638 .init_machine = cmx270_init,