blob: 6fd7b8b753fcc45b19222616a596bd7ef4b29783 [file] [log] [blame]
Lennert Buytenheke9937d42006-03-28 21:08:13 +01001/*
2 * linux/arch/arm/mach-pxa/lpd270.c
3 *
4 * Support for the LogicPD PXA270 Card Engine.
5 * Derived from the mainstone code, which carries these notices:
6 *
7 * Author: Nicolas Pitre
8 * Created: Nov 05, 2002
9 * Copyright: MontaVista Software Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/sysdev.h>
19#include <linux/interrupt.h>
20#include <linux/sched.h>
21#include <linux/bitops.h>
22#include <linux/fb.h>
23#include <linux/ioport.h>
24#include <linux/mtd/mtd.h>
25#include <linux/mtd/partitions.h>
26
27#include <asm/types.h>
28#include <asm/setup.h>
29#include <asm/memory.h>
30#include <asm/mach-types.h>
31#include <asm/hardware.h>
32#include <asm/irq.h>
33#include <asm/sizes.h>
34
35#include <asm/mach/arch.h>
36#include <asm/mach/map.h>
37#include <asm/mach/irq.h>
38#include <asm/mach/flash.h>
39
40#include <asm/arch/pxa-regs.h>
Russell King8785a8f2008-01-14 17:02:33 +000041#include <asm/arch/pxa2xx-regs.h>
eric miaoa683b142008-03-03 09:44:25 +080042#include <asm/arch/pxa2xx-gpio.h>
Lennert Buytenheke9937d42006-03-28 21:08:13 +010043#include <asm/arch/lpd270.h>
44#include <asm/arch/audio.h>
45#include <asm/arch/pxafb.h>
46#include <asm/arch/mmc.h>
47#include <asm/arch/irda.h>
48#include <asm/arch/ohci.h>
49
50#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010051#include "devices.h"
Lennert Buytenheke9937d42006-03-28 21:08:13 +010052
53
54static unsigned int lpd270_irq_enabled;
55
56static void lpd270_mask_irq(unsigned int irq)
57{
58 int lpd270_irq = irq - LPD270_IRQ(0);
59
60 __raw_writew(~(1 << lpd270_irq), LPD270_INT_STATUS);
61
62 lpd270_irq_enabled &= ~(1 << lpd270_irq);
63 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
64}
65
66static void lpd270_unmask_irq(unsigned int irq)
67{
68 int lpd270_irq = irq - LPD270_IRQ(0);
69
70 lpd270_irq_enabled |= 1 << lpd270_irq;
71 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
72}
73
David Brownell38c677c2006-08-01 22:26:25 +010074static struct irq_chip lpd270_irq_chip = {
75 .name = "CPLD",
Lennert Buytenheke9937d42006-03-28 21:08:13 +010076 .ack = lpd270_mask_irq,
77 .mask = lpd270_mask_irq,
78 .unmask = lpd270_unmask_irq,
79};
80
Russell King10dd5ce2006-11-23 11:41:32 +000081static void lpd270_irq_handler(unsigned int irq, struct irq_desc *desc)
Lennert Buytenheke9937d42006-03-28 21:08:13 +010082{
83 unsigned long pending;
84
85 pending = __raw_readw(LPD270_INT_STATUS) & lpd270_irq_enabled;
86 do {
87 GEDR(0) = GPIO_bit(0); /* clear useless edge notification */
88 if (likely(pending)) {
89 irq = LPD270_IRQ(0) + __ffs(pending);
90 desc = irq_desc + irq;
Linus Torvalds0cd61b62006-10-06 10:53:39 -070091 desc_handle_irq(irq, desc);
Lennert Buytenheke9937d42006-03-28 21:08:13 +010092
93 pending = __raw_readw(LPD270_INT_STATUS) &
94 lpd270_irq_enabled;
95 }
96 } while (pending);
97}
98
99static void __init lpd270_init_irq(void)
100{
101 int irq;
102
Eric Miaocd491042007-06-22 04:14:09 +0100103 pxa27x_init_irq();
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100104
105 __raw_writew(0, LPD270_INT_MASK);
106 __raw_writew(0, LPD270_INT_STATUS);
107
108 /* setup extra LogicPD PXA270 irqs */
109 for (irq = LPD270_IRQ(2); irq <= LPD270_IRQ(4); irq++) {
110 set_irq_chip(irq, &lpd270_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +0000111 set_irq_handler(irq, handle_level_irq);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100112 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
113 }
114 set_irq_chained_handler(IRQ_GPIO(0), lpd270_irq_handler);
115 set_irq_type(IRQ_GPIO(0), IRQT_FALLING);
116}
117
118
119#ifdef CONFIG_PM
120static int lpd270_irq_resume(struct sys_device *dev)
121{
122 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
123 return 0;
124}
125
126static struct sysdev_class lpd270_irq_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +0100127 .name = "cpld_irq",
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100128 .resume = lpd270_irq_resume,
129};
130
131static struct sys_device lpd270_irq_device = {
132 .cls = &lpd270_irq_sysclass,
133};
134
135static int __init lpd270_irq_device_init(void)
136{
Russell King720046d2008-04-24 15:13:36 +0100137 int ret = -ENODEV;
138 if (machine_is_logicpd_pxa270()) {
139 ret = sysdev_class_register(&lpd270_irq_sysclass);
140 if (ret == 0)
141 ret = sysdev_register(&lpd270_irq_device);
142 }
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100143 return ret;
144}
145
146device_initcall(lpd270_irq_device_init);
147#endif
148
149
150static struct resource smc91x_resources[] = {
151 [0] = {
152 .start = LPD270_ETH_PHYS,
153 .end = (LPD270_ETH_PHYS + 0xfffff),
154 .flags = IORESOURCE_MEM,
155 },
156 [1] = {
157 .start = LPD270_ETHERNET_IRQ,
158 .end = LPD270_ETHERNET_IRQ,
159 .flags = IORESOURCE_IRQ,
160 },
161};
162
163static struct platform_device smc91x_device = {
164 .name = "smc91x",
165 .id = 0,
166 .num_resources = ARRAY_SIZE(smc91x_resources),
167 .resource = smc91x_resources,
168};
169
170static struct platform_device lpd270_audio_device = {
171 .name = "pxa2xx-ac97",
172 .id = -1,
173};
174
175static struct resource lpd270_flash_resources[] = {
176 [0] = {
177 .start = PXA_CS0_PHYS,
178 .end = PXA_CS0_PHYS + SZ_64M - 1,
179 .flags = IORESOURCE_MEM,
180 },
181 [1] = {
182 .start = PXA_CS1_PHYS,
183 .end = PXA_CS1_PHYS + SZ_64M - 1,
184 .flags = IORESOURCE_MEM,
185 },
186};
187
188static struct mtd_partition lpd270_flash0_partitions[] = {
189 {
190 .name = "Bootloader",
191 .size = 0x00040000,
192 .offset = 0,
193 .mask_flags = MTD_WRITEABLE /* force read-only */
194 }, {
195 .name = "Kernel",
196 .size = 0x00400000,
197 .offset = 0x00040000,
198 }, {
199 .name = "Filesystem",
200 .size = MTDPART_SIZ_FULL,
201 .offset = 0x00440000
202 },
203};
204
205static struct flash_platform_data lpd270_flash_data[2] = {
206 {
207 .name = "processor-flash",
208 .map_name = "cfi_probe",
209 .parts = lpd270_flash0_partitions,
210 .nr_parts = ARRAY_SIZE(lpd270_flash0_partitions),
211 }, {
212 .name = "mainboard-flash",
213 .map_name = "cfi_probe",
214 .parts = NULL,
215 .nr_parts = 0,
216 }
217};
218
219static struct platform_device lpd270_flash_device[2] = {
220 {
221 .name = "pxa2xx-flash",
222 .id = 0,
223 .dev = {
224 .platform_data = &lpd270_flash_data[0],
225 },
226 .resource = &lpd270_flash_resources[0],
227 .num_resources = 1,
228 }, {
229 .name = "pxa2xx-flash",
230 .id = 1,
231 .dev = {
232 .platform_data = &lpd270_flash_data[1],
233 },
234 .resource = &lpd270_flash_resources[1],
235 .num_resources = 1,
236 },
237};
238
239static void lpd270_backlight_power(int on)
240{
241 if (on) {
242 pxa_gpio_mode(GPIO16_PWM0_MD);
Eric Miao7053acb2007-04-05 04:07:20 +0100243 pxa_set_cken(CKEN_PWM0, 1);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100244 PWM_CTRL0 = 0;
245 PWM_PWDUTY0 = 0x3ff;
246 PWM_PERVAL0 = 0x3ff;
247 } else {
248 PWM_CTRL0 = 0;
249 PWM_PWDUTY0 = 0x0;
250 PWM_PERVAL0 = 0x3FF;
Eric Miao7053acb2007-04-05 04:07:20 +0100251 pxa_set_cken(CKEN_PWM0, 0);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100252 }
253}
254
255/* 5.7" TFT QVGA (LoLo display number 1) */
Richard Purdied14b2722006-09-20 22:54:21 +0100256static struct pxafb_mode_info sharp_lq057q3dc02_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100257 .pixclock = 150000,
258 .xres = 320,
259 .yres = 240,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100260 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100261 .hsync_len = 0x14,
262 .left_margin = 0x28,
263 .right_margin = 0x0a,
264 .vsync_len = 0x02,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100265 .upper_margin = 0x08,
266 .lower_margin = 0x14,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100267 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100268};
269
270static struct pxafb_mach_info sharp_lq057q3dc02 = {
271 .modes = &sharp_lq057q3dc02_mode,
272 .num_modes = 1,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100273 .lccr0 = 0x07800080,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100274 .lccr3 = 0x00400000,
275 .pxafb_backlight_power = lpd270_backlight_power,
276};
277
278/* 12.1" TFT SVGA (LoLo display number 2) */
Richard Purdied14b2722006-09-20 22:54:21 +0100279static struct pxafb_mode_info sharp_lq121s1dg31_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100280 .pixclock = 50000,
281 .xres = 800,
282 .yres = 600,
283 .bpp = 16,
284 .hsync_len = 0x05,
285 .left_margin = 0x52,
286 .right_margin = 0x05,
287 .vsync_len = 0x04,
288 .upper_margin = 0x14,
289 .lower_margin = 0x0a,
290 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100291};
292
293static struct pxafb_mach_info sharp_lq121s1dg31 = {
294 .modes = &sharp_lq121s1dg31_mode,
295 .num_modes = 1,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100296 .lccr0 = 0x07800080,
297 .lccr3 = 0x00400000,
298 .pxafb_backlight_power = lpd270_backlight_power,
299};
300
301/* 3.6" TFT QVGA (LoLo display number 3) */
Richard Purdied14b2722006-09-20 22:54:21 +0100302static struct pxafb_mode_info sharp_lq036q1da01_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100303 .pixclock = 150000,
304 .xres = 320,
305 .yres = 240,
306 .bpp = 16,
307 .hsync_len = 0x0e,
308 .left_margin = 0x04,
309 .right_margin = 0x0a,
310 .vsync_len = 0x03,
311 .upper_margin = 0x03,
312 .lower_margin = 0x03,
313 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100314};
315
316static struct pxafb_mach_info sharp_lq036q1da01 = {
317 .modes = &sharp_lq036q1da01_mode,
318 .num_modes = 1,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100319 .lccr0 = 0x07800080,
320 .lccr3 = 0x00400000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100321 .pxafb_backlight_power = lpd270_backlight_power,
322};
323
324/* 6.4" TFT VGA (LoLo display number 5) */
Richard Purdied14b2722006-09-20 22:54:21 +0100325static struct pxafb_mode_info sharp_lq64d343_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100326 .pixclock = 25000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100327 .xres = 640,
328 .yres = 480,
329 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100330 .hsync_len = 0x31,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100331 .left_margin = 0x89,
332 .right_margin = 0x19,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100333 .vsync_len = 0x12,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100334 .upper_margin = 0x22,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100335 .lower_margin = 0x00,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100336 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100337};
338
339static struct pxafb_mach_info sharp_lq64d343 = {
340 .modes = &sharp_lq64d343_mode,
341 .num_modes = 1,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100342 .lccr0 = 0x07800080,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100343 .lccr3 = 0x00400000,
344 .pxafb_backlight_power = lpd270_backlight_power,
345};
346
347/* 10.4" TFT VGA (LoLo display number 7) */
Richard Purdied14b2722006-09-20 22:54:21 +0100348static struct pxafb_mode_info sharp_lq10d368_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100349 .pixclock = 25000,
350 .xres = 640,
351 .yres = 480,
352 .bpp = 16,
353 .hsync_len = 0x31,
354 .left_margin = 0x89,
355 .right_margin = 0x19,
356 .vsync_len = 0x12,
357 .upper_margin = 0x22,
358 .lower_margin = 0x00,
359 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100360};
361
362static struct pxafb_mach_info sharp_lq10d368 = {
363 .modes = &sharp_lq10d368_mode,
364 .num_modes = 1,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100365 .lccr0 = 0x07800080,
366 .lccr3 = 0x00400000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100367 .pxafb_backlight_power = lpd270_backlight_power,
368};
369
370/* 3.5" TFT QVGA (LoLo display number 8) */
Richard Purdied14b2722006-09-20 22:54:21 +0100371static struct pxafb_mode_info sharp_lq035q7db02_20_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100372 .pixclock = 150000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100373 .xres = 240,
374 .yres = 320,
375 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100376 .hsync_len = 0x0e,
377 .left_margin = 0x0a,
378 .right_margin = 0x0a,
379 .vsync_len = 0x03,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100380 .upper_margin = 0x05,
381 .lower_margin = 0x14,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100382 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100383};
384
385static struct pxafb_mach_info sharp_lq035q7db02_20 = {
386 .modes = &sharp_lq035q7db02_20_mode,
387 .num_modes = 1,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100388 .lccr0 = 0x07800080,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100389 .lccr3 = 0x00400000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100390 .pxafb_backlight_power = lpd270_backlight_power,
391};
392
Lennert Buytenhek65660292006-06-29 16:06:30 +0100393static struct pxafb_mach_info *lpd270_lcd_to_use;
394
395static int __init lpd270_set_lcd(char *str)
396{
397 if (!strnicmp(str, "lq057q3dc02", 11)) {
398 lpd270_lcd_to_use = &sharp_lq057q3dc02;
399 } else if (!strnicmp(str, "lq121s1dg31", 11)) {
400 lpd270_lcd_to_use = &sharp_lq121s1dg31;
401 } else if (!strnicmp(str, "lq036q1da01", 11)) {
402 lpd270_lcd_to_use = &sharp_lq036q1da01;
403 } else if (!strnicmp(str, "lq64d343", 8)) {
404 lpd270_lcd_to_use = &sharp_lq64d343;
405 } else if (!strnicmp(str, "lq10d368", 8)) {
406 lpd270_lcd_to_use = &sharp_lq10d368;
407 } else if (!strnicmp(str, "lq035q7db02-20", 14)) {
408 lpd270_lcd_to_use = &sharp_lq035q7db02_20;
409 } else {
410 printk(KERN_INFO "lpd270: unknown lcd panel [%s]\n", str);
411 }
412
413 return 1;
414}
415
416__setup("lcd=", lpd270_set_lcd);
417
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100418static struct platform_device *platform_devices[] __initdata = {
419 &smc91x_device,
420 &lpd270_audio_device,
421 &lpd270_flash_device[0],
422 &lpd270_flash_device[1],
423};
424
425static int lpd270_ohci_init(struct device *dev)
426{
427 /* setup Port1 GPIO pin. */
428 pxa_gpio_mode(88 | GPIO_ALT_FN_1_IN); /* USBHPWR1 */
429 pxa_gpio_mode(89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
430
431 /* Set the Power Control Polarity Low and Power Sense
432 Polarity Low to active low. */
433 UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
434 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
435
436 return 0;
437}
438
439static struct pxaohci_platform_data lpd270_ohci_platform_data = {
440 .port_mode = PMM_PERPORT_MODE,
441 .init = lpd270_ohci_init,
442};
443
444static void __init lpd270_init(void)
445{
446 lpd270_flash_data[0].width = (BOOT_DEF & 1) ? 2 : 4;
447 lpd270_flash_data[1].width = 4;
448
449 /*
450 * System bus arbiter setting:
451 * - Core_Park
452 * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
453 */
454 ARB_CNTRL = ARB_CORE_PARK | 0x234;
455
456 /*
457 * On LogicPD PXA270, we route AC97_SYSCLK via GPIO45.
458 */
459 pxa_gpio_mode(GPIO45_SYSCLK_AC97_MD);
460
461 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
462
Lennert Buytenhek65660292006-06-29 16:06:30 +0100463 if (lpd270_lcd_to_use != NULL)
464 set_pxa_fb_info(lpd270_lcd_to_use);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100465
466 pxa_set_ohci_info(&lpd270_ohci_platform_data);
467}
468
469
470static struct map_desc lpd270_io_desc[] __initdata = {
471 {
472 .virtual = LPD270_CPLD_VIRT,
473 .pfn = __phys_to_pfn(LPD270_CPLD_PHYS),
474 .length = LPD270_CPLD_SIZE,
475 .type = MT_DEVICE,
476 },
477};
478
479static void __init lpd270_map_io(void)
480{
481 pxa_map_io();
482 iotable_init(lpd270_io_desc, ARRAY_SIZE(lpd270_io_desc));
483
484 /* initialize sleep mode regs (wake-up sources, etc) */
485 PGSR0 = 0x00008800;
486 PGSR1 = 0x00000002;
487 PGSR2 = 0x0001FC00;
488 PGSR3 = 0x00001F81;
489 PWER = 0xC0000002;
490 PRER = 0x00000002;
491 PFER = 0x00000002;
492
493 /* for use I SRAM as framebuffer. */
494 PSLR |= 0x00000F04;
495 PCFR = 0x00000066;
496}
497
498MACHINE_START(LOGICPD_PXA270, "LogicPD PXA270 Card Engine")
499 /* Maintainer: Peter Barada */
500 .phys_io = 0x40000000,
501 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
502 .boot_params = 0xa0000100,
503 .map_io = lpd270_map_io,
504 .init_irq = lpd270_init_irq,
505 .timer = &pxa_timer,
506 .init_machine = lpd270_init,
507MACHINE_END