x86: cpa self-test, WARN_ON()
[wrt350n-kernel.git] / arch / arm / mach-pxa / cm-x270.c
blob28cfd71c032d2bf533621ef6f3503968e6668f7c
1 /*
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>
13 #include <linux/pm.h>
14 #include <linux/fb.h>
15 #include <linux/platform_device.h>
16 #include <linux/irq.h>
17 #include <linux/sysdev.h>
18 #include <linux/io.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>
40 #include "generic.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[] = {
47 [0] = {
48 .start = DM9000_PHYS_BASE,
49 .end = DM9000_PHYS_BASE + 4,
50 .flags = IORESOURCE_MEM,
52 [1] = {
53 .start = DM9000_PHYS_BASE + 8,
54 .end = DM9000_PHYS_BASE + 8 + 500,
55 .flags = IORESOURCE_MEM,
57 [2] = {
58 .start = CMX270_ETHIRQ,
59 .end = 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,
71 /* Ethernet device */
72 static struct platform_device cmx270_device_dm9k = {
73 .name = "dm9000",
74 .id = 0,
75 .num_resources = ARRAY_SIZE(cmx270_dm9k_resource),
76 .resource = cmx270_dm9k_resource,
77 .dev = {
78 .platform_data = &cmx270_dm9k_platdata,
82 /* audio device */
83 static struct platform_device cmx270_audio_device = {
84 .name = "pxa2xx-ac97",
85 .id = -1,
88 /* touchscreen controller */
89 static struct platform_device cmx270_ts_device = {
90 .name = "ucb1400_ts",
91 .id = -1,
94 /* RTC */
95 static struct resource cmx270_v3020_resource[] = {
96 [0] = {
97 .start = RTC_PHYS_BASE,
98 .end = RTC_PHYS_BASE + 4,
99 .flags = IORESOURCE_MEM,
103 struct v3020_platform_data cmx270_v3020_pdata = {
104 .leftshift = 16,
107 static struct platform_device cmx270_rtc_device = {
108 .name = "v3020",
109 .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
110 .resource = cmx270_v3020_resource,
111 .id = -1,
112 .dev = {
113 .platform_data = &cmx270_v3020_pdata,
118 * CM-X270 LEDs
120 static struct platform_device cmx270_led_device = {
121 .name = "cm-x270-led",
122 .id = -1,
125 /* 2700G graphics */
126 static u64 fb_dma_mask = ~(u64)0;
128 static struct resource cmx270_2700G_resource[] = {
129 /* frame buffer memory including ODFB and External SDRAM */
130 [0] = {
131 .start = MARATHON_PHYS,
132 .end = MARATHON_PHYS + 0x02000000,
133 .flags = IORESOURCE_MEM,
135 /* Marathon registers */
136 [1] = {
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);
160 return 0;
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];
170 return 0;
173 static struct mbxfb_platform_data cmx270_2700G_data = {
174 .xres = {
175 .min = 240,
176 .max = 1200,
177 .defval = 640,
179 .yres = {
180 .min = 240,
181 .max = 1200,
182 .defval = 480,
184 .bpp = {
185 .min = 16,
186 .max = 32,
187 .defval = 16,
189 .memsize = 8*1024*1024,
190 .probe = cmx270_marathon_probe,
191 .remove = cmx270_marathon_remove,
194 static struct platform_device cmx270_2700G = {
195 .name = "mbx-fb",
196 .dev = {
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,
203 .id = -1,
206 static u64 ata_dma_mask = ~(u64)0;
208 static struct platform_device cmx270_ata = {
209 .name = "pata_cm_x270",
210 .id = -1,
211 .dev = {
212 .dma_mask = &ata_dma_mask,
213 .coherent_dma_mask = 0xffffffff,
217 /* platform devices */
218 static struct platform_device *platform_devices[] __initdata = {
219 &cmx270_device_dm9k,
220 &cmx270_audio_device,
221 &cmx270_rtc_device,
222 &cmx270_2700G,
223 &cmx270_led_device,
224 &cmx270_ts_device,
225 &cmx270_ata,
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,
234 .type = MT_DEVICE
236 [1] = { /* PCI bridge */
237 .virtual = CMX270_IT8152_VIRT,
238 .pfn = __phys_to_pfn(CMX270_IT8152_PHYS),
239 .length = SZ_64M,
240 .type = MT_DEVICE
245 Display definitions
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 = {
257 .pixclock = 76923,
258 .bpp = 8,
259 .xres = 320,
260 .yres = 240,
261 .hsync_len = 3,
262 .vsync_len = 2,
263 .left_margin = 3,
264 .upper_margin = 0,
265 .right_margin = 3,
266 .lower_margin = 0,
267 .sync = (FB_SYNC_HOR_HIGH_ACT |
268 FB_SYNC_VERT_HIGH_ACT),
269 .cmap_greyscale = 0,
272 static struct pxafb_mach_info generic_stn_320x240 = {
273 .modes = &generic_stn_320x240_mode,
274 .num_modes = 1,
275 .lccr0 = 0,
276 .lccr3 = (LCCR3_PixClkDiv(0x03) |
277 LCCR3_Acb(0xff) |
278 LCCR3_PCP),
279 .cmap_inverse = 0,
280 .cmap_static = 0,
283 static struct pxafb_mode_info generic_tft_640x480_mode = {
284 .pixclock = 38461,
285 .bpp = 8,
286 .xres = 640,
287 .yres = 480,
288 .hsync_len = 60,
289 .vsync_len = 2,
290 .left_margin = 70,
291 .upper_margin = 10,
292 .right_margin = 70,
293 .lower_margin = 5,
294 .sync = 0,
295 .cmap_greyscale = 0,
298 static struct pxafb_mach_info generic_tft_640x480 = {
299 .modes = &generic_tft_640x480_mode,
300 .num_modes = 1,
301 .lccr0 = (LCCR0_PAS),
302 .lccr3 = (LCCR3_PixClkDiv(0x01) |
303 LCCR3_Acb(0xff) |
304 LCCR3_PCP),
305 .cmap_inverse = 0,
306 .cmap_static = 0,
309 static struct pxafb_mode_info generic_crt_640x480_mode = {
310 .pixclock = 38461,
311 .bpp = 8,
312 .xres = 640,
313 .yres = 480,
314 .hsync_len = 63,
315 .vsync_len = 2,
316 .left_margin = 81,
317 .upper_margin = 33,
318 .right_margin = 16,
319 .lower_margin = 10,
320 .sync = (FB_SYNC_HOR_HIGH_ACT |
321 FB_SYNC_VERT_HIGH_ACT),
322 .cmap_greyscale = 0,
325 static struct pxafb_mach_info generic_crt_640x480 = {
326 .modes = &generic_crt_640x480_mode,
327 .num_modes = 1,
328 .lccr0 = (LCCR0_PAS),
329 .lccr3 = (LCCR3_PixClkDiv(0x01) |
330 LCCR3_Acb(0xff)),
331 .cmap_inverse = 0,
332 .cmap_static = 0,
335 static struct pxafb_mode_info generic_crt_800x600_mode = {
336 .pixclock = 28846,
337 .bpp = 8,
338 .xres = 800,
339 .yres = 600,
340 .hsync_len = 63,
341 .vsync_len = 2,
342 .left_margin = 26,
343 .upper_margin = 21,
344 .right_margin = 26,
345 .lower_margin = 11,
346 .sync = (FB_SYNC_HOR_HIGH_ACT |
347 FB_SYNC_VERT_HIGH_ACT),
348 .cmap_greyscale = 0,
351 static struct pxafb_mach_info generic_crt_800x600 = {
352 .modes = &generic_crt_800x600_mode,
353 .num_modes = 1,
354 .lccr0 = (LCCR0_PAS),
355 .lccr3 = (LCCR3_PixClkDiv(0x02) |
356 LCCR3_Acb(0xff)),
357 .cmap_inverse = 0,
358 .cmap_static = 0,
361 static struct pxafb_mode_info generic_tft_320x240_mode = {
362 .pixclock = 134615,
363 .bpp = 16,
364 .xres = 320,
365 .yres = 240,
366 .hsync_len = 63,
367 .vsync_len = 7,
368 .left_margin = 75,
369 .upper_margin = 0,
370 .right_margin = 15,
371 .lower_margin = 15,
372 .sync = 0,
373 .cmap_greyscale = 0,
376 static struct pxafb_mach_info generic_tft_320x240 = {
377 .modes = &generic_tft_320x240_mode,
378 .num_modes = 1,
379 .lccr0 = (LCCR0_PAS),
380 .lccr3 = (LCCR3_PixClkDiv(0x06) |
381 LCCR3_Acb(0xff) |
382 LCCR3_PCP),
383 .cmap_inverse = 0,
384 .cmap_static = 0,
387 static struct pxafb_mode_info generic_stn_640x480_mode = {
388 .pixclock = 57692,
389 .bpp = 8,
390 .xres = 640,
391 .yres = 480,
392 .hsync_len = 4,
393 .vsync_len = 2,
394 .left_margin = 10,
395 .upper_margin = 5,
396 .right_margin = 10,
397 .lower_margin = 5,
398 .sync = (FB_SYNC_HOR_HIGH_ACT |
399 FB_SYNC_VERT_HIGH_ACT),
400 .cmap_greyscale = 0,
403 static struct pxafb_mach_info generic_stn_640x480 = {
404 .modes = &generic_stn_640x480_mode,
405 .num_modes = 1,
406 .lccr0 = 0,
407 .lccr3 = (LCCR3_PixClkDiv(0x02) |
408 LCCR3_Acb(0xff)),
409 .cmap_inverse = 0,
410 .cmap_static = 0,
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);
418 switch (disp_type) {
419 case MTYPE_STN320x240:
420 cmx270_display = &generic_stn_320x240;
421 break;
422 case MTYPE_TFT640x480:
423 cmx270_display = &generic_tft_640x480;
424 break;
425 case MTYPE_CRT640x480:
426 cmx270_display = &generic_crt_640x480;
427 break;
428 case MTYPE_CRT800x600:
429 cmx270_display = &generic_crt_800x600;
430 break;
431 case MTYPE_TFT320x240:
432 cmx270_display = &generic_tft_320x240;
433 break;
434 case MTYPE_STN640x480:
435 cmx270_display = &generic_stn_640x480;
436 break;
437 default: /* fallback to CRT 640x480 */
438 cmx270_display = &generic_crt_640x480;
439 break;
441 return 1;
445 This should be done really early to get proper configuration for
446 frame buffer.
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);
460 return 0;
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,
471 void *data)
473 int err;
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);
494 if (err)
495 printk(KERN_ERR "cmx270_mci_init: MMC/SD: can't"
496 " request MMC card detect IRQ\n");
498 return err;
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);
508 } else {
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,
526 #ifdef CONFIG_PM
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 */
539 PCFR = 0x0;
540 PSLR = 0xff400000;
541 PMCR = 0x00000005;
542 PWER = 0x80000000;
543 PFER = 0x00000000;
544 PRER = 0x00000000;
545 PGSR0 = 0xC0018800;
546 PGSR1 = 0x004F0002;
547 PGSR2 = 0x6021C000;
548 PGSR3 = 0x00020000;
550 return 0;
553 static int cmx270_resume(struct sys_device *dev)
555 cmx270_pci_resume();
557 /* restore MSC registers */
558 MSC0 = sleep_save_msc[0];
559 MSC1 = sleep_save_msc[1];
560 MSC2 = sleep_save_msc[2];
562 return 0;
565 static struct sysdev_class cmx270_pm_sysclass = {
566 .name = "pm",
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)
577 int error;
578 error = sysdev_class_register(&cmx270_pm_sysclass);
579 if (error == 0)
580 error = sysdev_register(&cmx270_pm_device);
581 return error;
583 #else
584 static int __init cmx270_pm_init(void) { return 0; }
585 #endif
587 static void __init cmx270_init(void)
589 cmx270_pm_init();
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)
613 pxa27x_init_irq();
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)
629 pxa_map_io();
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,
640 .timer = &pxa_timer,
641 .init_machine = cmx270_init,
642 MACHINE_END