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/pxafb.h>
33 #include <asm/arch/ohci.h>
34 #include <asm/arch/mmc.h>
35 #include <asm/arch/bitfield.h>
36 #include <asm/arch/cm-x270.h>
38 #include <asm/hardware/it8152.h>
41 #include "cm-x270-pci.h"
43 #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
44 #define DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
46 static struct resource cmx270_dm9k_resource
[] = {
48 .start
= DM9000_PHYS_BASE
,
49 .end
= DM9000_PHYS_BASE
+ 4,
50 .flags
= IORESOURCE_MEM
,
53 .start
= DM9000_PHYS_BASE
+ 8,
54 .end
= DM9000_PHYS_BASE
+ 8 + 500,
55 .flags
= IORESOURCE_MEM
,
58 .start
= CMX270_ETHIRQ
,
60 .flags
= IORESOURCE_IRQ
,
64 /* for the moment we limit ourselves to 32bit IO until some
65 * better IO routines can be written and tested
67 static struct dm9000_plat_data cmx270_dm9k_platdata
= {
68 .flags
= DM9000_PLATF_32BITONLY
,
72 static struct platform_device cmx270_device_dm9k
= {
75 .num_resources
= ARRAY_SIZE(cmx270_dm9k_resource
),
76 .resource
= cmx270_dm9k_resource
,
78 .platform_data
= &cmx270_dm9k_platdata
,
83 static struct platform_device cmx270_audio_device
= {
84 .name
= "pxa2xx-ac97",
88 /* touchscreen controller */
89 static struct platform_device cmx270_ts_device
= {
95 static struct resource cmx270_v3020_resource
[] = {
97 .start
= RTC_PHYS_BASE
,
98 .end
= RTC_PHYS_BASE
+ 4,
99 .flags
= IORESOURCE_MEM
,
103 struct v3020_platform_data cmx270_v3020_pdata
= {
107 static struct platform_device cmx270_rtc_device
= {
109 .num_resources
= ARRAY_SIZE(cmx270_v3020_resource
),
110 .resource
= cmx270_v3020_resource
,
113 .platform_data
= &cmx270_v3020_pdata
,
120 static struct platform_device cmx270_led_device
= {
121 .name
= "cm-x270-led",
126 static u64 fb_dma_mask
= ~(u64
)0;
128 static struct resource cmx270_2700G_resource
[] = {
129 /* frame buffer memory including ODFB and External SDRAM */
131 .start
= MARATHON_PHYS
,
132 .end
= MARATHON_PHYS
+ 0x02000000,
133 .flags
= IORESOURCE_MEM
,
135 /* Marathon registers */
137 .start
= MARATHON_PHYS
+ 0x03fe0000,
138 .end
= MARATHON_PHYS
+ 0x03ffffff,
139 .flags
= IORESOURCE_MEM
,
143 static unsigned long save_lcd_regs
[10];
145 static int cmx270_marathon_probe(struct fb_info
*fb
)
147 /* save PXA-270 pin settings before enabling 2700G */
148 save_lcd_regs
[0] = GPDR1
;
149 save_lcd_regs
[1] = GPDR2
;
150 save_lcd_regs
[2] = GAFR1_U
;
151 save_lcd_regs
[3] = GAFR2_L
;
152 save_lcd_regs
[4] = GAFR2_U
;
154 /* Disable PXA-270 on-chip controller driving pins */
155 GPDR1
&= ~(0xfc000000);
156 GPDR2
&= ~(0x00c03fff);
157 GAFR1_U
&= ~(0xfff00000);
158 GAFR2_L
&= ~(0x0fffffff);
159 GAFR2_U
&= ~(0x0000f000);
163 static int cmx270_marathon_remove(struct fb_info
*fb
)
165 GPDR1
= save_lcd_regs
[0];
166 GPDR2
= save_lcd_regs
[1];
167 GAFR1_U
= save_lcd_regs
[2];
168 GAFR2_L
= save_lcd_regs
[3];
169 GAFR2_U
= save_lcd_regs
[4];
173 static struct mbxfb_platform_data cmx270_2700G_data
= {
189 .memsize
= 8*1024*1024,
190 .probe
= cmx270_marathon_probe
,
191 .remove
= cmx270_marathon_remove
,
194 static struct platform_device cmx270_2700G
= {
197 .platform_data
= &cmx270_2700G_data
,
198 .dma_mask
= &fb_dma_mask
,
199 .coherent_dma_mask
= 0xffffffff,
201 .num_resources
= ARRAY_SIZE(cmx270_2700G_resource
),
202 .resource
= cmx270_2700G_resource
,
206 static u64 ata_dma_mask
= ~(u64
)0;
208 static struct platform_device cmx270_ata
= {
209 .name
= "pata_cm_x270",
212 .dma_mask
= &ata_dma_mask
,
213 .coherent_dma_mask
= 0xffffffff,
217 /* platform devices */
218 static struct platform_device
*platform_devices
[] __initdata
= {
220 &cmx270_audio_device
,
228 /* Map PCI companion and IDE/General Purpose CS statically */
229 static struct map_desc cmx270_io_desc
[] __initdata
= {
230 [0] = { /* IDE/general purpose space */
231 .virtual = CMX270_IDE104_VIRT
,
232 .pfn
= __phys_to_pfn(CMX270_IDE104_PHYS
),
233 .length
= SZ_64M
- SZ_8M
,
236 [1] = { /* PCI bridge */
237 .virtual = CMX270_IT8152_VIRT
,
238 .pfn
= __phys_to_pfn(CMX270_IT8152_PHYS
),
246 keep these for backwards compatibility, although symbolic names (as
247 e.g. in lpd270.c) looks better
249 #define MTYPE_STN320x240 0
250 #define MTYPE_TFT640x480 1
251 #define MTYPE_CRT640x480 2
252 #define MTYPE_CRT800x600 3
253 #define MTYPE_TFT320x240 6
254 #define MTYPE_STN640x480 7
256 static struct pxafb_mode_info generic_stn_320x240_mode
= {
267 .sync
= (FB_SYNC_HOR_HIGH_ACT
|
268 FB_SYNC_VERT_HIGH_ACT
),
272 static struct pxafb_mach_info generic_stn_320x240
= {
273 .modes
= &generic_stn_320x240_mode
,
276 .lccr3
= (LCCR3_PixClkDiv(0x03) |
283 static struct pxafb_mode_info generic_tft_640x480_mode
= {
298 static struct pxafb_mach_info generic_tft_640x480
= {
299 .modes
= &generic_tft_640x480_mode
,
301 .lccr0
= (LCCR0_PAS
),
302 .lccr3
= (LCCR3_PixClkDiv(0x01) |
309 static struct pxafb_mode_info generic_crt_640x480_mode
= {
320 .sync
= (FB_SYNC_HOR_HIGH_ACT
|
321 FB_SYNC_VERT_HIGH_ACT
),
325 static struct pxafb_mach_info generic_crt_640x480
= {
326 .modes
= &generic_crt_640x480_mode
,
328 .lccr0
= (LCCR0_PAS
),
329 .lccr3
= (LCCR3_PixClkDiv(0x01) |
335 static struct pxafb_mode_info generic_crt_800x600_mode
= {
346 .sync
= (FB_SYNC_HOR_HIGH_ACT
|
347 FB_SYNC_VERT_HIGH_ACT
),
351 static struct pxafb_mach_info generic_crt_800x600
= {
352 .modes
= &generic_crt_800x600_mode
,
354 .lccr0
= (LCCR0_PAS
),
355 .lccr3
= (LCCR3_PixClkDiv(0x02) |
361 static struct pxafb_mode_info generic_tft_320x240_mode
= {
376 static struct pxafb_mach_info generic_tft_320x240
= {
377 .modes
= &generic_tft_320x240_mode
,
379 .lccr0
= (LCCR0_PAS
),
380 .lccr3
= (LCCR3_PixClkDiv(0x06) |
387 static struct pxafb_mode_info generic_stn_640x480_mode
= {
398 .sync
= (FB_SYNC_HOR_HIGH_ACT
|
399 FB_SYNC_VERT_HIGH_ACT
),
403 static struct pxafb_mach_info generic_stn_640x480
= {
404 .modes
= &generic_stn_640x480_mode
,
407 .lccr3
= (LCCR3_PixClkDiv(0x02) |
413 static struct pxafb_mach_info
*cmx270_display
= &generic_crt_640x480
;
415 static int __init
cmx270_set_display(char *str
)
417 int disp_type
= simple_strtol(str
, NULL
, 0);
419 case MTYPE_STN320x240
:
420 cmx270_display
= &generic_stn_320x240
;
422 case MTYPE_TFT640x480
:
423 cmx270_display
= &generic_tft_640x480
;
425 case MTYPE_CRT640x480
:
426 cmx270_display
= &generic_crt_640x480
;
428 case MTYPE_CRT800x600
:
429 cmx270_display
= &generic_crt_800x600
;
431 case MTYPE_TFT320x240
:
432 cmx270_display
= &generic_tft_320x240
;
434 case MTYPE_STN640x480
:
435 cmx270_display
= &generic_stn_640x480
;
437 default: /* fallback to CRT 640x480 */
438 cmx270_display
= &generic_crt_640x480
;
445 This should be done really early to get proper configuration for
447 Indeed, pxafb parameters can be used istead, but CM-X270 bootloader
448 has limitied line length for kernel command line, and also it will
449 break compatibitlty with proprietary releases already in field.
451 __setup("monitor=", cmx270_set_display
);
453 /* PXA27x OHCI controller setup */
454 static int cmx270_ohci_init(struct device
*dev
)
456 /* Set the Power Control Polarity Low */
457 UHCHR
= (UHCHR
| UHCHR_PCPL
) &
458 ~(UHCHR_SSEP1
| UHCHR_SSEP2
| UHCHR_SSE
);
463 static struct pxaohci_platform_data cmx270_ohci_platform_data
= {
464 .port_mode
= PMM_PERPORT_MODE
,
465 .init
= cmx270_ohci_init
,
469 static int cmx270_mci_init(struct device
*dev
,
470 irq_handler_t cmx270_detect_int
,
476 * setup GPIO for PXA27x MMC controller
478 pxa_gpio_mode(GPIO32_MMCCLK_MD
);
479 pxa_gpio_mode(GPIO112_MMCCMD_MD
);
480 pxa_gpio_mode(GPIO92_MMCDAT0_MD
);
481 pxa_gpio_mode(GPIO109_MMCDAT1_MD
);
482 pxa_gpio_mode(GPIO110_MMCDAT2_MD
);
483 pxa_gpio_mode(GPIO111_MMCDAT3_MD
);
485 /* SB-X270 uses GPIO105 as SD power enable */
486 pxa_gpio_mode(105 | GPIO_OUT
);
488 /* card detect IRQ on GPIO 83 */
489 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_MMC_IRQ
));
491 err
= request_irq(CMX270_MMC_IRQ
, cmx270_detect_int
,
492 IRQF_DISABLED
| IRQF_TRIGGER_FALLING
,
493 "MMC card detect", data
);
495 printk(KERN_ERR
"cmx270_mci_init: MMC/SD: can't"
496 " request MMC card detect IRQ\n");
501 static void cmx270_mci_setpower(struct device
*dev
, unsigned int vdd
)
503 struct pxamci_platform_data
*p_d
= dev
->platform_data
;
505 if ((1 << vdd
) & p_d
->ocr_mask
) {
506 printk(KERN_DEBUG
"%s: on\n", __FUNCTION__
);
507 GPCR(105) = GPIO_bit(105);
509 GPSR(105) = GPIO_bit(105);
510 printk(KERN_DEBUG
"%s: off\n", __FUNCTION__
);
514 static void cmx270_mci_exit(struct device
*dev
, void *data
)
516 free_irq(CMX270_MMC_IRQ
, data
);
519 static struct pxamci_platform_data cmx270_mci_platform_data
= {
520 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
521 .init
= cmx270_mci_init
,
522 .setpower
= cmx270_mci_setpower
,
523 .exit
= cmx270_mci_exit
,
527 static unsigned long sleep_save_msc
[10];
529 static int cmx270_suspend(struct sys_device
*dev
, pm_message_t state
)
531 cmx270_pci_suspend();
533 /* save MSC registers */
534 sleep_save_msc
[0] = MSC0
;
535 sleep_save_msc
[1] = MSC1
;
536 sleep_save_msc
[2] = MSC2
;
538 /* setup power saving mode registers */
553 static int cmx270_resume(struct sys_device
*dev
)
557 /* restore MSC registers */
558 MSC0
= sleep_save_msc
[0];
559 MSC1
= sleep_save_msc
[1];
560 MSC2
= sleep_save_msc
[2];
565 static struct sysdev_class cmx270_pm_sysclass
= {
567 .resume
= cmx270_resume
,
568 .suspend
= cmx270_suspend
,
571 static struct sys_device cmx270_pm_device
= {
572 .cls
= &cmx270_pm_sysclass
,
575 static int __init
cmx270_pm_init(void)
578 error
= sysdev_class_register(&cmx270_pm_sysclass
);
580 error
= sysdev_register(&cmx270_pm_device
);
584 static int __init
cmx270_pm_init(void) { return 0; }
587 static void __init
cmx270_init(void)
591 set_pxa_fb_info(cmx270_display
);
593 /* register CM-X270 platform devices */
594 platform_add_devices(platform_devices
, ARRAY_SIZE(platform_devices
));
596 /* set MCI and OHCI platform parameters */
597 pxa_set_mci_info(&cmx270_mci_platform_data
);
598 pxa_set_ohci_info(&cmx270_ohci_platform_data
);
600 /* This enables the STUART */
601 pxa_gpio_mode(GPIO46_STRXD_MD
);
602 pxa_gpio_mode(GPIO47_STTXD_MD
);
604 /* This enables the BTUART */
605 pxa_gpio_mode(GPIO42_BTRXD_MD
);
606 pxa_gpio_mode(GPIO43_BTTXD_MD
);
607 pxa_gpio_mode(GPIO44_BTCTS_MD
);
608 pxa_gpio_mode(GPIO45_BTRTS_MD
);
611 static void __init
cmx270_init_irq(void)
616 cmx270_pci_init_irq();
618 /* Setup interrupt for dm9000 */
619 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_ETHIRQ
));
620 set_irq_type(CMX270_ETHIRQ
, IRQT_RISING
);
622 /* Setup interrupt for 2700G */
623 pxa_gpio_mode(IRQ_TO_GPIO(CMX270_GFXIRQ
));
624 set_irq_type(CMX270_GFXIRQ
, IRQT_FALLING
);
627 static void __init
cmx270_map_io(void)
630 iotable_init(cmx270_io_desc
, ARRAY_SIZE(cmx270_io_desc
));
634 MACHINE_START(ARMCORE
, "Compulab CM-x270")
635 .boot_params
= 0xa0000100,
636 .phys_io
= 0x40000000,
637 .io_pg_offst
= (io_p2v(0x40000000) >> 18) & 0xfffc,
638 .map_io
= cmx270_map_io
,
639 .init_irq
= cmx270_init_irq
,
641 .init_machine
= cmx270_init
,