blob: d64395f26a3e101d0f8826701da811c4a9e1ae42 [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>
Russell King4a730712008-05-18 13:11:02 +010026#include <linux/pwm_backlight.h>
Lennert Buytenheke9937d42006-03-28 21:08:13 +010027
28#include <asm/types.h>
29#include <asm/setup.h>
30#include <asm/memory.h>
31#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/hardware.h>
Lennert Buytenheke9937d42006-03-28 21:08:13 +010033#include <asm/irq.h>
34#include <asm/sizes.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39#include <asm/mach/flash.h>
40
Eric Miao51c62982009-01-02 23:17:22 +080041#include <mach/pxa27x.h>
Eric Miaoda065a02009-01-06 18:29:01 +080042#include <mach/gpio.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010043#include <mach/lpd270.h>
44#include <mach/audio.h>
45#include <mach/pxafb.h>
46#include <mach/mmc.h>
47#include <mach/irda.h>
48#include <mach/ohci.h>
Lennert Buytenheke9937d42006-03-28 21:08:13 +010049
50#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010051#include "devices.h"
Lennert Buytenheke9937d42006-03-28 21:08:13 +010052
Eric Miaofd90ff22008-09-11 15:53:50 +080053static unsigned long lpd270_pin_config[] __initdata = {
54 /* Chip Selects */
55 GPIO15_nCS_1, /* Mainboard Flash */
56 GPIO78_nCS_2, /* CPLD + Ethernet */
57
58 /* LCD - 16bpp Active TFT */
59 GPIO58_LCD_LDD_0,
60 GPIO59_LCD_LDD_1,
61 GPIO60_LCD_LDD_2,
62 GPIO61_LCD_LDD_3,
63 GPIO62_LCD_LDD_4,
64 GPIO63_LCD_LDD_5,
65 GPIO64_LCD_LDD_6,
66 GPIO65_LCD_LDD_7,
67 GPIO66_LCD_LDD_8,
68 GPIO67_LCD_LDD_9,
69 GPIO68_LCD_LDD_10,
70 GPIO69_LCD_LDD_11,
71 GPIO70_LCD_LDD_12,
72 GPIO71_LCD_LDD_13,
73 GPIO72_LCD_LDD_14,
74 GPIO73_LCD_LDD_15,
75 GPIO74_LCD_FCLK,
76 GPIO75_LCD_LCLK,
77 GPIO76_LCD_PCLK,
78 GPIO77_LCD_BIAS,
79 GPIO16_PWM0_OUT, /* Backlight */
80
81 /* USB Host */
82 GPIO88_USBH1_PWR,
83 GPIO89_USBH1_PEN,
84
85 /* AC97 */
86 GPIO45_AC97_SYSCLK,
87
88 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
89};
Lennert Buytenheke9937d42006-03-28 21:08:13 +010090
91static unsigned int lpd270_irq_enabled;
92
93static void lpd270_mask_irq(unsigned int irq)
94{
95 int lpd270_irq = irq - LPD270_IRQ(0);
96
97 __raw_writew(~(1 << lpd270_irq), LPD270_INT_STATUS);
98
99 lpd270_irq_enabled &= ~(1 << lpd270_irq);
100 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
101}
102
103static void lpd270_unmask_irq(unsigned int irq)
104{
105 int lpd270_irq = irq - LPD270_IRQ(0);
106
107 lpd270_irq_enabled |= 1 << lpd270_irq;
108 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
109}
110
David Brownell38c677c2006-08-01 22:26:25 +0100111static struct irq_chip lpd270_irq_chip = {
112 .name = "CPLD",
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100113 .ack = lpd270_mask_irq,
114 .mask = lpd270_mask_irq,
115 .unmask = lpd270_unmask_irq,
116};
117
Russell King10dd5ce2006-11-23 11:41:32 +0000118static void lpd270_irq_handler(unsigned int irq, struct irq_desc *desc)
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100119{
120 unsigned long pending;
121
122 pending = __raw_readw(LPD270_INT_STATUS) & lpd270_irq_enabled;
123 do {
124 GEDR(0) = GPIO_bit(0); /* clear useless edge notification */
125 if (likely(pending)) {
126 irq = LPD270_IRQ(0) + __ffs(pending);
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100127 generic_handle_irq(irq);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100128
129 pending = __raw_readw(LPD270_INT_STATUS) &
130 lpd270_irq_enabled;
131 }
132 } while (pending);
133}
134
135static void __init lpd270_init_irq(void)
136{
137 int irq;
138
Eric Miaocd491042007-06-22 04:14:09 +0100139 pxa27x_init_irq();
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100140
141 __raw_writew(0, LPD270_INT_MASK);
142 __raw_writew(0, LPD270_INT_STATUS);
143
144 /* setup extra LogicPD PXA270 irqs */
145 for (irq = LPD270_IRQ(2); irq <= LPD270_IRQ(4); irq++) {
146 set_irq_chip(irq, &lpd270_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +0000147 set_irq_handler(irq, handle_level_irq);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100148 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
149 }
150 set_irq_chained_handler(IRQ_GPIO(0), lpd270_irq_handler);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100151 set_irq_type(IRQ_GPIO(0), IRQ_TYPE_EDGE_FALLING);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100152}
153
154
155#ifdef CONFIG_PM
156static int lpd270_irq_resume(struct sys_device *dev)
157{
158 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
159 return 0;
160}
161
162static struct sysdev_class lpd270_irq_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +0100163 .name = "cpld_irq",
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100164 .resume = lpd270_irq_resume,
165};
166
167static struct sys_device lpd270_irq_device = {
168 .cls = &lpd270_irq_sysclass,
169};
170
171static int __init lpd270_irq_device_init(void)
172{
Russell King720046d2008-04-24 15:13:36 +0100173 int ret = -ENODEV;
174 if (machine_is_logicpd_pxa270()) {
175 ret = sysdev_class_register(&lpd270_irq_sysclass);
176 if (ret == 0)
177 ret = sysdev_register(&lpd270_irq_device);
178 }
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100179 return ret;
180}
181
182device_initcall(lpd270_irq_device_init);
183#endif
184
185
186static struct resource smc91x_resources[] = {
187 [0] = {
188 .start = LPD270_ETH_PHYS,
189 .end = (LPD270_ETH_PHYS + 0xfffff),
190 .flags = IORESOURCE_MEM,
191 },
192 [1] = {
193 .start = LPD270_ETHERNET_IRQ,
194 .end = LPD270_ETHERNET_IRQ,
195 .flags = IORESOURCE_IRQ,
196 },
197};
198
199static struct platform_device smc91x_device = {
200 .name = "smc91x",
201 .id = 0,
202 .num_resources = ARRAY_SIZE(smc91x_resources),
203 .resource = smc91x_resources,
204};
205
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100206static struct resource lpd270_flash_resources[] = {
207 [0] = {
208 .start = PXA_CS0_PHYS,
209 .end = PXA_CS0_PHYS + SZ_64M - 1,
210 .flags = IORESOURCE_MEM,
211 },
212 [1] = {
213 .start = PXA_CS1_PHYS,
214 .end = PXA_CS1_PHYS + SZ_64M - 1,
215 .flags = IORESOURCE_MEM,
216 },
217};
218
219static struct mtd_partition lpd270_flash0_partitions[] = {
220 {
221 .name = "Bootloader",
222 .size = 0x00040000,
223 .offset = 0,
224 .mask_flags = MTD_WRITEABLE /* force read-only */
225 }, {
226 .name = "Kernel",
227 .size = 0x00400000,
228 .offset = 0x00040000,
229 }, {
230 .name = "Filesystem",
231 .size = MTDPART_SIZ_FULL,
232 .offset = 0x00440000
233 },
234};
235
236static struct flash_platform_data lpd270_flash_data[2] = {
237 {
238 .name = "processor-flash",
239 .map_name = "cfi_probe",
240 .parts = lpd270_flash0_partitions,
241 .nr_parts = ARRAY_SIZE(lpd270_flash0_partitions),
242 }, {
243 .name = "mainboard-flash",
244 .map_name = "cfi_probe",
245 .parts = NULL,
246 .nr_parts = 0,
247 }
248};
249
250static struct platform_device lpd270_flash_device[2] = {
251 {
252 .name = "pxa2xx-flash",
253 .id = 0,
254 .dev = {
255 .platform_data = &lpd270_flash_data[0],
256 },
257 .resource = &lpd270_flash_resources[0],
258 .num_resources = 1,
259 }, {
260 .name = "pxa2xx-flash",
261 .id = 1,
262 .dev = {
263 .platform_data = &lpd270_flash_data[1],
264 },
265 .resource = &lpd270_flash_resources[1],
266 .num_resources = 1,
267 },
268};
269
Russell King4a730712008-05-18 13:11:02 +0100270static struct platform_pwm_backlight_data lpd270_backlight_data = {
271 .pwm_id = 0,
272 .max_brightness = 1,
273 .dft_brightness = 1,
274 .pwm_period_ns = 78770,
275};
276
277static struct platform_device lpd270_backlight_device = {
278 .name = "pwm-backlight",
279 .dev = {
280 .parent = &pxa27x_device_pwm0.dev,
281 .platform_data = &lpd270_backlight_data,
282 },
283};
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100284
285/* 5.7" TFT QVGA (LoLo display number 1) */
Richard Purdied14b2722006-09-20 22:54:21 +0100286static struct pxafb_mode_info sharp_lq057q3dc02_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100287 .pixclock = 150000,
288 .xres = 320,
289 .yres = 240,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100290 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100291 .hsync_len = 0x14,
292 .left_margin = 0x28,
293 .right_margin = 0x0a,
294 .vsync_len = 0x02,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100295 .upper_margin = 0x08,
296 .lower_margin = 0x14,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100297 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100298};
299
300static struct pxafb_mach_info sharp_lq057q3dc02 = {
301 .modes = &sharp_lq057q3dc02_mode,
302 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800303 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
304 LCD_ALTERNATE_MAPPING,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100305};
306
307/* 12.1" TFT SVGA (LoLo display number 2) */
Richard Purdied14b2722006-09-20 22:54:21 +0100308static struct pxafb_mode_info sharp_lq121s1dg31_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100309 .pixclock = 50000,
310 .xres = 800,
311 .yres = 600,
312 .bpp = 16,
313 .hsync_len = 0x05,
314 .left_margin = 0x52,
315 .right_margin = 0x05,
316 .vsync_len = 0x04,
317 .upper_margin = 0x14,
318 .lower_margin = 0x0a,
319 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100320};
321
322static struct pxafb_mach_info sharp_lq121s1dg31 = {
323 .modes = &sharp_lq121s1dg31_mode,
324 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800325 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
326 LCD_ALTERNATE_MAPPING,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100327};
328
329/* 3.6" TFT QVGA (LoLo display number 3) */
Richard Purdied14b2722006-09-20 22:54:21 +0100330static struct pxafb_mode_info sharp_lq036q1da01_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100331 .pixclock = 150000,
332 .xres = 320,
333 .yres = 240,
334 .bpp = 16,
335 .hsync_len = 0x0e,
336 .left_margin = 0x04,
337 .right_margin = 0x0a,
338 .vsync_len = 0x03,
339 .upper_margin = 0x03,
340 .lower_margin = 0x03,
341 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100342};
343
344static struct pxafb_mach_info sharp_lq036q1da01 = {
345 .modes = &sharp_lq036q1da01_mode,
346 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800347 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
348 LCD_ALTERNATE_MAPPING,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100349};
350
351/* 6.4" TFT VGA (LoLo display number 5) */
Richard Purdied14b2722006-09-20 22:54:21 +0100352static struct pxafb_mode_info sharp_lq64d343_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100353 .pixclock = 25000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100354 .xres = 640,
355 .yres = 480,
356 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100357 .hsync_len = 0x31,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100358 .left_margin = 0x89,
359 .right_margin = 0x19,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100360 .vsync_len = 0x12,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100361 .upper_margin = 0x22,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100362 .lower_margin = 0x00,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100363 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100364};
365
366static struct pxafb_mach_info sharp_lq64d343 = {
367 .modes = &sharp_lq64d343_mode,
368 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800369 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
370 LCD_ALTERNATE_MAPPING,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100371};
372
373/* 10.4" TFT VGA (LoLo display number 7) */
Richard Purdied14b2722006-09-20 22:54:21 +0100374static struct pxafb_mode_info sharp_lq10d368_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100375 .pixclock = 25000,
376 .xres = 640,
377 .yres = 480,
378 .bpp = 16,
379 .hsync_len = 0x31,
380 .left_margin = 0x89,
381 .right_margin = 0x19,
382 .vsync_len = 0x12,
383 .upper_margin = 0x22,
384 .lower_margin = 0x00,
385 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100386};
387
388static struct pxafb_mach_info sharp_lq10d368 = {
389 .modes = &sharp_lq10d368_mode,
390 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800391 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
392 LCD_ALTERNATE_MAPPING,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100393};
394
395/* 3.5" TFT QVGA (LoLo display number 8) */
Richard Purdied14b2722006-09-20 22:54:21 +0100396static struct pxafb_mode_info sharp_lq035q7db02_20_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100397 .pixclock = 150000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100398 .xres = 240,
399 .yres = 320,
400 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100401 .hsync_len = 0x0e,
402 .left_margin = 0x0a,
403 .right_margin = 0x0a,
404 .vsync_len = 0x03,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100405 .upper_margin = 0x05,
406 .lower_margin = 0x14,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100407 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100408};
409
410static struct pxafb_mach_info sharp_lq035q7db02_20 = {
411 .modes = &sharp_lq035q7db02_20_mode,
412 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800413 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
414 LCD_ALTERNATE_MAPPING,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100415};
416
Lennert Buytenhek65660292006-06-29 16:06:30 +0100417static struct pxafb_mach_info *lpd270_lcd_to_use;
418
419static int __init lpd270_set_lcd(char *str)
420{
421 if (!strnicmp(str, "lq057q3dc02", 11)) {
422 lpd270_lcd_to_use = &sharp_lq057q3dc02;
423 } else if (!strnicmp(str, "lq121s1dg31", 11)) {
424 lpd270_lcd_to_use = &sharp_lq121s1dg31;
425 } else if (!strnicmp(str, "lq036q1da01", 11)) {
426 lpd270_lcd_to_use = &sharp_lq036q1da01;
427 } else if (!strnicmp(str, "lq64d343", 8)) {
428 lpd270_lcd_to_use = &sharp_lq64d343;
429 } else if (!strnicmp(str, "lq10d368", 8)) {
430 lpd270_lcd_to_use = &sharp_lq10d368;
431 } else if (!strnicmp(str, "lq035q7db02-20", 14)) {
432 lpd270_lcd_to_use = &sharp_lq035q7db02_20;
433 } else {
434 printk(KERN_INFO "lpd270: unknown lcd panel [%s]\n", str);
435 }
436
437 return 1;
438}
439
440__setup("lcd=", lpd270_set_lcd);
441
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100442static struct platform_device *platform_devices[] __initdata = {
443 &smc91x_device,
Russell King4a730712008-05-18 13:11:02 +0100444 &lpd270_backlight_device,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100445 &lpd270_flash_device[0],
446 &lpd270_flash_device[1],
447};
448
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100449static struct pxaohci_platform_data lpd270_ohci_platform_data = {
450 .port_mode = PMM_PERPORT_MODE,
Eric Miao097b5332008-09-27 15:49:57 +0800451 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100452};
453
454static void __init lpd270_init(void)
455{
Eric Miaofd90ff22008-09-11 15:53:50 +0800456 pxa2xx_mfp_config(ARRAY_AND_SIZE(lpd270_pin_config));
457
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100458 lpd270_flash_data[0].width = (BOOT_DEF & 1) ? 2 : 4;
459 lpd270_flash_data[1].width = 4;
460
461 /*
462 * System bus arbiter setting:
463 * - Core_Park
464 * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
465 */
466 ARB_CNTRL = ARB_CORE_PARK | 0x234;
467
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100468 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
469
Mark Brown9f19d632008-06-10 12:30:05 +0100470 pxa_set_ac97_info(NULL);
471
Lennert Buytenhek65660292006-06-29 16:06:30 +0100472 if (lpd270_lcd_to_use != NULL)
473 set_pxa_fb_info(lpd270_lcd_to_use);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100474
475 pxa_set_ohci_info(&lpd270_ohci_platform_data);
476}
477
478
479static struct map_desc lpd270_io_desc[] __initdata = {
480 {
481 .virtual = LPD270_CPLD_VIRT,
482 .pfn = __phys_to_pfn(LPD270_CPLD_PHYS),
483 .length = LPD270_CPLD_SIZE,
484 .type = MT_DEVICE,
485 },
486};
487
488static void __init lpd270_map_io(void)
489{
490 pxa_map_io();
491 iotable_init(lpd270_io_desc, ARRAY_SIZE(lpd270_io_desc));
492
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100493 /* 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