blob: 5ca9c5c4807e101c50e23f25d5b968bfde4e34f8 [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>
Russell Kinga09e64f2008-08-05 16:14:15 +010042#include <mach/lpd270.h>
43#include <mach/audio.h>
44#include <mach/pxafb.h>
45#include <mach/mmc.h>
46#include <mach/irda.h>
47#include <mach/ohci.h>
Lennert Buytenheke9937d42006-03-28 21:08:13 +010048
49#include "generic.h"
Russell King46c41e62007-05-15 15:39:36 +010050#include "devices.h"
Lennert Buytenheke9937d42006-03-28 21:08:13 +010051
Eric Miaofd90ff22008-09-11 15:53:50 +080052static unsigned long lpd270_pin_config[] __initdata = {
53 /* Chip Selects */
54 GPIO15_nCS_1, /* Mainboard Flash */
55 GPIO78_nCS_2, /* CPLD + Ethernet */
56
57 /* LCD - 16bpp Active TFT */
58 GPIO58_LCD_LDD_0,
59 GPIO59_LCD_LDD_1,
60 GPIO60_LCD_LDD_2,
61 GPIO61_LCD_LDD_3,
62 GPIO62_LCD_LDD_4,
63 GPIO63_LCD_LDD_5,
64 GPIO64_LCD_LDD_6,
65 GPIO65_LCD_LDD_7,
66 GPIO66_LCD_LDD_8,
67 GPIO67_LCD_LDD_9,
68 GPIO68_LCD_LDD_10,
69 GPIO69_LCD_LDD_11,
70 GPIO70_LCD_LDD_12,
71 GPIO71_LCD_LDD_13,
72 GPIO72_LCD_LDD_14,
73 GPIO73_LCD_LDD_15,
74 GPIO74_LCD_FCLK,
75 GPIO75_LCD_LCLK,
76 GPIO76_LCD_PCLK,
77 GPIO77_LCD_BIAS,
78 GPIO16_PWM0_OUT, /* Backlight */
79
80 /* USB Host */
81 GPIO88_USBH1_PWR,
82 GPIO89_USBH1_PEN,
83
84 /* AC97 */
85 GPIO45_AC97_SYSCLK,
86
87 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
88};
Lennert Buytenheke9937d42006-03-28 21:08:13 +010089
90static unsigned int lpd270_irq_enabled;
91
92static void lpd270_mask_irq(unsigned int irq)
93{
94 int lpd270_irq = irq - LPD270_IRQ(0);
95
96 __raw_writew(~(1 << lpd270_irq), LPD270_INT_STATUS);
97
98 lpd270_irq_enabled &= ~(1 << lpd270_irq);
99 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
100}
101
102static void lpd270_unmask_irq(unsigned int irq)
103{
104 int lpd270_irq = irq - LPD270_IRQ(0);
105
106 lpd270_irq_enabled |= 1 << lpd270_irq;
107 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
108}
109
David Brownell38c677c2006-08-01 22:26:25 +0100110static struct irq_chip lpd270_irq_chip = {
111 .name = "CPLD",
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100112 .ack = lpd270_mask_irq,
113 .mask = lpd270_mask_irq,
114 .unmask = lpd270_unmask_irq,
115};
116
Russell King10dd5ce2006-11-23 11:41:32 +0000117static void lpd270_irq_handler(unsigned int irq, struct irq_desc *desc)
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100118{
119 unsigned long pending;
120
121 pending = __raw_readw(LPD270_INT_STATUS) & lpd270_irq_enabled;
122 do {
123 GEDR(0) = GPIO_bit(0); /* clear useless edge notification */
124 if (likely(pending)) {
125 irq = LPD270_IRQ(0) + __ffs(pending);
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100126 generic_handle_irq(irq);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100127
128 pending = __raw_readw(LPD270_INT_STATUS) &
129 lpd270_irq_enabled;
130 }
131 } while (pending);
132}
133
134static void __init lpd270_init_irq(void)
135{
136 int irq;
137
Eric Miaocd491042007-06-22 04:14:09 +0100138 pxa27x_init_irq();
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100139
140 __raw_writew(0, LPD270_INT_MASK);
141 __raw_writew(0, LPD270_INT_STATUS);
142
143 /* setup extra LogicPD PXA270 irqs */
144 for (irq = LPD270_IRQ(2); irq <= LPD270_IRQ(4); irq++) {
145 set_irq_chip(irq, &lpd270_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +0000146 set_irq_handler(irq, handle_level_irq);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100147 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
148 }
149 set_irq_chained_handler(IRQ_GPIO(0), lpd270_irq_handler);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100150 set_irq_type(IRQ_GPIO(0), IRQ_TYPE_EDGE_FALLING);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100151}
152
153
154#ifdef CONFIG_PM
155static int lpd270_irq_resume(struct sys_device *dev)
156{
157 __raw_writew(lpd270_irq_enabled, LPD270_INT_MASK);
158 return 0;
159}
160
161static struct sysdev_class lpd270_irq_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +0100162 .name = "cpld_irq",
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100163 .resume = lpd270_irq_resume,
164};
165
166static struct sys_device lpd270_irq_device = {
167 .cls = &lpd270_irq_sysclass,
168};
169
170static int __init lpd270_irq_device_init(void)
171{
Russell King720046d2008-04-24 15:13:36 +0100172 int ret = -ENODEV;
173 if (machine_is_logicpd_pxa270()) {
174 ret = sysdev_class_register(&lpd270_irq_sysclass);
175 if (ret == 0)
176 ret = sysdev_register(&lpd270_irq_device);
177 }
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100178 return ret;
179}
180
181device_initcall(lpd270_irq_device_init);
182#endif
183
184
185static struct resource smc91x_resources[] = {
186 [0] = {
187 .start = LPD270_ETH_PHYS,
188 .end = (LPD270_ETH_PHYS + 0xfffff),
189 .flags = IORESOURCE_MEM,
190 },
191 [1] = {
192 .start = LPD270_ETHERNET_IRQ,
193 .end = LPD270_ETHERNET_IRQ,
194 .flags = IORESOURCE_IRQ,
195 },
196};
197
198static struct platform_device smc91x_device = {
199 .name = "smc91x",
200 .id = 0,
201 .num_resources = ARRAY_SIZE(smc91x_resources),
202 .resource = smc91x_resources,
203};
204
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100205static struct resource lpd270_flash_resources[] = {
206 [0] = {
207 .start = PXA_CS0_PHYS,
208 .end = PXA_CS0_PHYS + SZ_64M - 1,
209 .flags = IORESOURCE_MEM,
210 },
211 [1] = {
212 .start = PXA_CS1_PHYS,
213 .end = PXA_CS1_PHYS + SZ_64M - 1,
214 .flags = IORESOURCE_MEM,
215 },
216};
217
218static struct mtd_partition lpd270_flash0_partitions[] = {
219 {
220 .name = "Bootloader",
221 .size = 0x00040000,
222 .offset = 0,
223 .mask_flags = MTD_WRITEABLE /* force read-only */
224 }, {
225 .name = "Kernel",
226 .size = 0x00400000,
227 .offset = 0x00040000,
228 }, {
229 .name = "Filesystem",
230 .size = MTDPART_SIZ_FULL,
231 .offset = 0x00440000
232 },
233};
234
235static struct flash_platform_data lpd270_flash_data[2] = {
236 {
237 .name = "processor-flash",
238 .map_name = "cfi_probe",
239 .parts = lpd270_flash0_partitions,
240 .nr_parts = ARRAY_SIZE(lpd270_flash0_partitions),
241 }, {
242 .name = "mainboard-flash",
243 .map_name = "cfi_probe",
244 .parts = NULL,
245 .nr_parts = 0,
246 }
247};
248
249static struct platform_device lpd270_flash_device[2] = {
250 {
251 .name = "pxa2xx-flash",
252 .id = 0,
253 .dev = {
254 .platform_data = &lpd270_flash_data[0],
255 },
256 .resource = &lpd270_flash_resources[0],
257 .num_resources = 1,
258 }, {
259 .name = "pxa2xx-flash",
260 .id = 1,
261 .dev = {
262 .platform_data = &lpd270_flash_data[1],
263 },
264 .resource = &lpd270_flash_resources[1],
265 .num_resources = 1,
266 },
267};
268
Russell King4a730712008-05-18 13:11:02 +0100269static struct platform_pwm_backlight_data lpd270_backlight_data = {
270 .pwm_id = 0,
271 .max_brightness = 1,
272 .dft_brightness = 1,
273 .pwm_period_ns = 78770,
274};
275
276static struct platform_device lpd270_backlight_device = {
277 .name = "pwm-backlight",
278 .dev = {
279 .parent = &pxa27x_device_pwm0.dev,
280 .platform_data = &lpd270_backlight_data,
281 },
282};
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100283
284/* 5.7" TFT QVGA (LoLo display number 1) */
Richard Purdied14b2722006-09-20 22:54:21 +0100285static struct pxafb_mode_info sharp_lq057q3dc02_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100286 .pixclock = 150000,
287 .xres = 320,
288 .yres = 240,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100289 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100290 .hsync_len = 0x14,
291 .left_margin = 0x28,
292 .right_margin = 0x0a,
293 .vsync_len = 0x02,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100294 .upper_margin = 0x08,
295 .lower_margin = 0x14,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100296 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100297};
298
299static struct pxafb_mach_info sharp_lq057q3dc02 = {
300 .modes = &sharp_lq057q3dc02_mode,
301 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800302 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
303 LCD_ALTERNATE_MAPPING,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100304};
305
306/* 12.1" TFT SVGA (LoLo display number 2) */
Richard Purdied14b2722006-09-20 22:54:21 +0100307static struct pxafb_mode_info sharp_lq121s1dg31_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100308 .pixclock = 50000,
309 .xres = 800,
310 .yres = 600,
311 .bpp = 16,
312 .hsync_len = 0x05,
313 .left_margin = 0x52,
314 .right_margin = 0x05,
315 .vsync_len = 0x04,
316 .upper_margin = 0x14,
317 .lower_margin = 0x0a,
318 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100319};
320
321static struct pxafb_mach_info sharp_lq121s1dg31 = {
322 .modes = &sharp_lq121s1dg31_mode,
323 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800324 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
325 LCD_ALTERNATE_MAPPING,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100326};
327
328/* 3.6" TFT QVGA (LoLo display number 3) */
Richard Purdied14b2722006-09-20 22:54:21 +0100329static struct pxafb_mode_info sharp_lq036q1da01_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100330 .pixclock = 150000,
331 .xres = 320,
332 .yres = 240,
333 .bpp = 16,
334 .hsync_len = 0x0e,
335 .left_margin = 0x04,
336 .right_margin = 0x0a,
337 .vsync_len = 0x03,
338 .upper_margin = 0x03,
339 .lower_margin = 0x03,
340 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100341};
342
343static struct pxafb_mach_info sharp_lq036q1da01 = {
344 .modes = &sharp_lq036q1da01_mode,
345 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800346 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
347 LCD_ALTERNATE_MAPPING,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100348};
349
350/* 6.4" TFT VGA (LoLo display number 5) */
Richard Purdied14b2722006-09-20 22:54:21 +0100351static struct pxafb_mode_info sharp_lq64d343_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100352 .pixclock = 25000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100353 .xres = 640,
354 .yres = 480,
355 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100356 .hsync_len = 0x31,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100357 .left_margin = 0x89,
358 .right_margin = 0x19,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100359 .vsync_len = 0x12,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100360 .upper_margin = 0x22,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100361 .lower_margin = 0x00,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100362 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100363};
364
365static struct pxafb_mach_info sharp_lq64d343 = {
366 .modes = &sharp_lq64d343_mode,
367 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800368 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
369 LCD_ALTERNATE_MAPPING,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100370};
371
372/* 10.4" TFT VGA (LoLo display number 7) */
Richard Purdied14b2722006-09-20 22:54:21 +0100373static struct pxafb_mode_info sharp_lq10d368_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100374 .pixclock = 25000,
375 .xres = 640,
376 .yres = 480,
377 .bpp = 16,
378 .hsync_len = 0x31,
379 .left_margin = 0x89,
380 .right_margin = 0x19,
381 .vsync_len = 0x12,
382 .upper_margin = 0x22,
383 .lower_margin = 0x00,
384 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100385};
386
387static struct pxafb_mach_info sharp_lq10d368 = {
388 .modes = &sharp_lq10d368_mode,
389 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800390 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
391 LCD_ALTERNATE_MAPPING,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100392};
393
394/* 3.5" TFT QVGA (LoLo display number 8) */
Richard Purdied14b2722006-09-20 22:54:21 +0100395static struct pxafb_mode_info sharp_lq035q7db02_20_mode = {
Lennert Buytenhek65660292006-06-29 16:06:30 +0100396 .pixclock = 150000,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100397 .xres = 240,
398 .yres = 320,
399 .bpp = 16,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100400 .hsync_len = 0x0e,
401 .left_margin = 0x0a,
402 .right_margin = 0x0a,
403 .vsync_len = 0x03,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100404 .upper_margin = 0x05,
405 .lower_margin = 0x14,
Lennert Buytenhek65660292006-06-29 16:06:30 +0100406 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Richard Purdied14b2722006-09-20 22:54:21 +0100407};
408
409static struct pxafb_mach_info sharp_lq035q7db02_20 = {
410 .modes = &sharp_lq035q7db02_20_mode,
411 .num_modes = 1,
Eric Miao0219e832008-09-11 15:59:23 +0800412 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
413 LCD_ALTERNATE_MAPPING,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100414};
415
Lennert Buytenhek65660292006-06-29 16:06:30 +0100416static struct pxafb_mach_info *lpd270_lcd_to_use;
417
418static int __init lpd270_set_lcd(char *str)
419{
420 if (!strnicmp(str, "lq057q3dc02", 11)) {
421 lpd270_lcd_to_use = &sharp_lq057q3dc02;
422 } else if (!strnicmp(str, "lq121s1dg31", 11)) {
423 lpd270_lcd_to_use = &sharp_lq121s1dg31;
424 } else if (!strnicmp(str, "lq036q1da01", 11)) {
425 lpd270_lcd_to_use = &sharp_lq036q1da01;
426 } else if (!strnicmp(str, "lq64d343", 8)) {
427 lpd270_lcd_to_use = &sharp_lq64d343;
428 } else if (!strnicmp(str, "lq10d368", 8)) {
429 lpd270_lcd_to_use = &sharp_lq10d368;
430 } else if (!strnicmp(str, "lq035q7db02-20", 14)) {
431 lpd270_lcd_to_use = &sharp_lq035q7db02_20;
432 } else {
433 printk(KERN_INFO "lpd270: unknown lcd panel [%s]\n", str);
434 }
435
436 return 1;
437}
438
439__setup("lcd=", lpd270_set_lcd);
440
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100441static struct platform_device *platform_devices[] __initdata = {
442 &smc91x_device,
Russell King4a730712008-05-18 13:11:02 +0100443 &lpd270_backlight_device,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100444 &lpd270_flash_device[0],
445 &lpd270_flash_device[1],
446};
447
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100448static struct pxaohci_platform_data lpd270_ohci_platform_data = {
449 .port_mode = PMM_PERPORT_MODE,
Eric Miao097b5332008-09-27 15:49:57 +0800450 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100451};
452
453static void __init lpd270_init(void)
454{
Eric Miaofd90ff22008-09-11 15:53:50 +0800455 pxa2xx_mfp_config(ARRAY_AND_SIZE(lpd270_pin_config));
456
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100457 lpd270_flash_data[0].width = (BOOT_DEF & 1) ? 2 : 4;
458 lpd270_flash_data[1].width = 4;
459
460 /*
461 * System bus arbiter setting:
462 * - Core_Park
463 * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4
464 */
465 ARB_CNTRL = ARB_CORE_PARK | 0x234;
466
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100467 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
468
Mark Brown9f19d632008-06-10 12:30:05 +0100469 pxa_set_ac97_info(NULL);
470
Lennert Buytenhek65660292006-06-29 16:06:30 +0100471 if (lpd270_lcd_to_use != NULL)
472 set_pxa_fb_info(lpd270_lcd_to_use);
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100473
474 pxa_set_ohci_info(&lpd270_ohci_platform_data);
475}
476
477
478static struct map_desc lpd270_io_desc[] __initdata = {
479 {
480 .virtual = LPD270_CPLD_VIRT,
481 .pfn = __phys_to_pfn(LPD270_CPLD_PHYS),
482 .length = LPD270_CPLD_SIZE,
483 .type = MT_DEVICE,
484 },
485};
486
487static void __init lpd270_map_io(void)
488{
489 pxa_map_io();
490 iotable_init(lpd270_io_desc, ARRAY_SIZE(lpd270_io_desc));
491
Lennert Buytenheke9937d42006-03-28 21:08:13 +0100492 /* for use I SRAM as framebuffer. */
493 PSLR |= 0x00000F04;
494 PCFR = 0x00000066;
495}
496
497MACHINE_START(LOGICPD_PXA270, "LogicPD PXA270 Card Engine")
498 /* Maintainer: Peter Barada */
499 .phys_io = 0x40000000,
500 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
501 .boot_params = 0xa0000100,
502 .map_io = lpd270_map_io,
503 .init_irq = lpd270_init_irq,
504 .timer = &pxa_timer,
505 .init_machine = lpd270_init,
506MACHINE_END