Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6
[pandora-kernel.git] / arch / arm / mach-pxa / cm-x2xx.c
1 /*
2  * linux/arch/arm/mach-pxa/cm-x2xx.c
3  *
4  * Copyright (C) 2008 CompuLab, Ltd.
5  * Mike Rapoport <mike@compulab.co.il>
6  *
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.
10  */
11
12 #include <linux/platform_device.h>
13 #include <linux/sysdev.h>
14 #include <linux/irq.h>
15 #include <linux/gpio.h>
16
17 #include <linux/dm9000.h>
18 #include <linux/leds.h>
19
20 #include <asm/mach/arch.h>
21 #include <asm/mach-types.h>
22 #include <asm/mach/map.h>
23
24 #include <mach/pxa2xx-regs.h>
25 #include <mach/audio.h>
26 #include <mach/pxafb.h>
27
28 #include <asm/hardware/it8152.h>
29
30 #include "generic.h"
31 #include "cm-x2xx-pci.h"
32
33 extern void cmx255_init(void);
34 extern void cmx270_init(void);
35
36 /* reserve IRQs for IT8152 */
37 #define CMX2XX_NR_IRQS          (IRQ_BOARD_START + 40)
38
39 /* virtual addresses for statically mapped regions */
40 #define CMX2XX_VIRT_BASE        (0xe8000000)
41 #define CMX2XX_IT8152_VIRT      (CMX2XX_VIRT_BASE)
42
43 /* physical address if local-bus attached devices */
44 #define CMX255_DM9000_PHYS_BASE (PXA_CS1_PHYS + (8 << 22))
45 #define CMX270_DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
46
47 /* leds */
48 #define CMX255_GPIO_RED         (27)
49 #define CMX255_GPIO_GREEN       (32)
50 #define CMX270_GPIO_RED         (93)
51 #define CMX270_GPIO_GREEN       (94)
52
53 /* GPIO IRQ usage */
54 #define GPIO22_ETHIRQ           (22)
55 #define GPIO10_ETHIRQ           (10)
56 #define CMX255_GPIO_IT8152_IRQ  (0)
57 #define CMX270_GPIO_IT8152_IRQ  (22)
58
59 #define CMX255_ETHIRQ           IRQ_GPIO(GPIO22_ETHIRQ)
60 #define CMX270_ETHIRQ           IRQ_GPIO(GPIO10_ETHIRQ)
61
62 #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
63 static struct resource cmx255_dm9000_resource[] = {
64         [0] = {
65                 .start = CMX255_DM9000_PHYS_BASE,
66                 .end   = CMX255_DM9000_PHYS_BASE + 3,
67                 .flags = IORESOURCE_MEM,
68         },
69         [1] = {
70                 .start = CMX255_DM9000_PHYS_BASE + 4,
71                 .end   = CMX255_DM9000_PHYS_BASE + 4 + 500,
72                 .flags = IORESOURCE_MEM,
73         },
74         [2] = {
75                 .start = CMX255_ETHIRQ,
76                 .end   = CMX255_ETHIRQ,
77                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
78         }
79 };
80
81 static struct resource cmx270_dm9000_resource[] = {
82         [0] = {
83                 .start = CMX270_DM9000_PHYS_BASE,
84                 .end   = CMX270_DM9000_PHYS_BASE + 3,
85                 .flags = IORESOURCE_MEM,
86         },
87         [1] = {
88                 .start = CMX270_DM9000_PHYS_BASE + 8,
89                 .end   = CMX270_DM9000_PHYS_BASE + 8 + 500,
90                 .flags = IORESOURCE_MEM,
91         },
92         [2] = {
93                 .start = CMX270_ETHIRQ,
94                 .end   = CMX270_ETHIRQ,
95                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
96         }
97 };
98
99 static struct dm9000_plat_data cmx270_dm9000_platdata = {
100         .flags          = DM9000_PLATF_32BITONLY | DM9000_PLATF_NO_EEPROM,
101 };
102
103 static struct platform_device cmx2xx_dm9000_device = {
104         .name           = "dm9000",
105         .id             = 0,
106         .num_resources  = ARRAY_SIZE(cmx270_dm9000_resource),
107         .dev            = {
108                 .platform_data = &cmx270_dm9000_platdata,
109         }
110 };
111
112 static void __init cmx2xx_init_dm9000(void)
113 {
114         if (cpu_is_pxa25x())
115                 cmx2xx_dm9000_device.resource = cmx255_dm9000_resource;
116         else
117                 cmx2xx_dm9000_device.resource = cmx270_dm9000_resource;
118         platform_device_register(&cmx2xx_dm9000_device);
119 }
120 #else
121 static inline void cmx2xx_init_dm9000(void) {}
122 #endif
123
124 /* UCB1400 touchscreen controller */
125 #if defined(CONFIG_TOUCHSCREEN_UCB1400) || defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
126 static struct platform_device cmx2xx_ts_device = {
127         .name           = "ucb1400_core",
128         .id             = -1,
129 };
130
131 static void __init cmx2xx_init_touchscreen(void)
132 {
133         platform_device_register(&cmx2xx_ts_device);
134 }
135 #else
136 static inline void cmx2xx_init_touchscreen(void) {}
137 #endif
138
139 /* CM-X270 LEDs */
140 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
141 static struct gpio_led cmx2xx_leds[] = {
142         [0] = {
143                 .name = "cm-x2xx:red",
144                 .default_trigger = "nand-disk",
145                 .active_low = 1,
146         },
147         [1] = {
148                 .name = "cm-x2xx:green",
149                 .default_trigger = "heartbeat",
150                 .active_low = 1,
151         },
152 };
153
154 static struct gpio_led_platform_data cmx2xx_gpio_led_pdata = {
155         .num_leds = ARRAY_SIZE(cmx2xx_leds),
156         .leds = cmx2xx_leds,
157 };
158
159 static struct platform_device cmx2xx_led_device = {
160         .name           = "leds-gpio",
161         .id             = -1,
162         .dev            = {
163                 .platform_data = &cmx2xx_gpio_led_pdata,
164         },
165 };
166
167 static void __init cmx2xx_init_leds(void)
168 {
169         if (cpu_is_pxa25x()) {
170                 cmx2xx_leds[0].gpio = CMX255_GPIO_RED;
171                 cmx2xx_leds[1].gpio = CMX255_GPIO_GREEN;
172         } else {
173                 cmx2xx_leds[0].gpio = CMX270_GPIO_RED;
174                 cmx2xx_leds[1].gpio = CMX270_GPIO_GREEN;
175         }
176         platform_device_register(&cmx2xx_led_device);
177 }
178 #else
179 static inline void cmx2xx_init_leds(void) {}
180 #endif
181
182 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
183 /*
184   Display definitions
185   keep these for backwards compatibility, although symbolic names (as
186   e.g. in lpd270.c) looks better
187 */
188 #define MTYPE_STN320x240        0
189 #define MTYPE_TFT640x480        1
190 #define MTYPE_CRT640x480        2
191 #define MTYPE_CRT800x600        3
192 #define MTYPE_TFT320x240        6
193 #define MTYPE_STN640x480        7
194
195 static struct pxafb_mode_info generic_stn_320x240_mode = {
196         .pixclock       = 76923,
197         .bpp            = 8,
198         .xres           = 320,
199         .yres           = 240,
200         .hsync_len      = 3,
201         .vsync_len      = 2,
202         .left_margin    = 3,
203         .upper_margin   = 0,
204         .right_margin   = 3,
205         .lower_margin   = 0,
206         .sync           = (FB_SYNC_HOR_HIGH_ACT |
207                            FB_SYNC_VERT_HIGH_ACT),
208         .cmap_greyscale = 0,
209 };
210
211 static struct pxafb_mach_info generic_stn_320x240 = {
212         .modes          = &generic_stn_320x240_mode,
213         .num_modes      = 1,
214         .lcd_conn       = LCD_COLOR_STN_8BPP | LCD_PCLK_EDGE_FALL |\
215                           LCD_AC_BIAS_FREQ(0xff),
216         .cmap_inverse   = 0,
217         .cmap_static    = 0,
218 };
219
220 static struct pxafb_mode_info generic_tft_640x480_mode = {
221         .pixclock       = 38461,
222         .bpp            = 8,
223         .xres           = 640,
224         .yres           = 480,
225         .hsync_len      = 60,
226         .vsync_len      = 2,
227         .left_margin    = 70,
228         .upper_margin   = 10,
229         .right_margin   = 70,
230         .lower_margin   = 5,
231         .sync           = 0,
232         .cmap_greyscale = 0,
233 };
234
235 static struct pxafb_mach_info generic_tft_640x480 = {
236         .modes          = &generic_tft_640x480_mode,
237         .num_modes      = 1,
238         .lcd_conn       = LCD_COLOR_TFT_8BPP | LCD_PCLK_EDGE_FALL |\
239                           LCD_AC_BIAS_FREQ(0xff),
240         .cmap_inverse   = 0,
241         .cmap_static    = 0,
242 };
243
244 static struct pxafb_mode_info generic_crt_640x480_mode = {
245         .pixclock       = 38461,
246         .bpp            = 8,
247         .xres           = 640,
248         .yres           = 480,
249         .hsync_len      = 63,
250         .vsync_len      = 2,
251         .left_margin    = 81,
252         .upper_margin   = 33,
253         .right_margin   = 16,
254         .lower_margin   = 10,
255         .sync           = (FB_SYNC_HOR_HIGH_ACT |
256                            FB_SYNC_VERT_HIGH_ACT),
257         .cmap_greyscale = 0,
258 };
259
260 static struct pxafb_mach_info generic_crt_640x480 = {
261         .modes          = &generic_crt_640x480_mode,
262         .num_modes      = 1,
263         .lcd_conn       = LCD_COLOR_TFT_8BPP | LCD_AC_BIAS_FREQ(0xff),
264         .cmap_inverse   = 0,
265         .cmap_static    = 0,
266 };
267
268 static struct pxafb_mode_info generic_crt_800x600_mode = {
269         .pixclock       = 28846,
270         .bpp            = 8,
271         .xres           = 800,
272         .yres           = 600,
273         .hsync_len      = 63,
274         .vsync_len      = 2,
275         .left_margin    = 26,
276         .upper_margin   = 21,
277         .right_margin   = 26,
278         .lower_margin   = 11,
279         .sync           = (FB_SYNC_HOR_HIGH_ACT |
280                            FB_SYNC_VERT_HIGH_ACT),
281         .cmap_greyscale = 0,
282 };
283
284 static struct pxafb_mach_info generic_crt_800x600 = {
285         .modes          = &generic_crt_800x600_mode,
286         .num_modes      = 1,
287         .lcd_conn       = LCD_COLOR_TFT_8BPP | LCD_AC_BIAS_FREQ(0xff),
288         .cmap_inverse   = 0,
289         .cmap_static    = 0,
290 };
291
292 static struct pxafb_mode_info generic_tft_320x240_mode = {
293         .pixclock       = 134615,
294         .bpp            = 16,
295         .xres           = 320,
296         .yres           = 240,
297         .hsync_len      = 63,
298         .vsync_len      = 7,
299         .left_margin    = 75,
300         .upper_margin   = 0,
301         .right_margin   = 15,
302         .lower_margin   = 15,
303         .sync           = 0,
304         .cmap_greyscale = 0,
305 };
306
307 static struct pxafb_mach_info generic_tft_320x240 = {
308         .modes          = &generic_tft_320x240_mode,
309         .num_modes      = 1,
310         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_AC_BIAS_FREQ(0xff),
311         .cmap_inverse   = 0,
312         .cmap_static    = 0,
313 };
314
315 static struct pxafb_mode_info generic_stn_640x480_mode = {
316         .pixclock       = 57692,
317         .bpp            = 8,
318         .xres           = 640,
319         .yres           = 480,
320         .hsync_len      = 4,
321         .vsync_len      = 2,
322         .left_margin    = 10,
323         .upper_margin   = 5,
324         .right_margin   = 10,
325         .lower_margin   = 5,
326         .sync           = (FB_SYNC_HOR_HIGH_ACT |
327                            FB_SYNC_VERT_HIGH_ACT),
328         .cmap_greyscale = 0,
329 };
330
331 static struct pxafb_mach_info generic_stn_640x480 = {
332         .modes          = &generic_stn_640x480_mode,
333         .num_modes      = 1,
334         .lcd_conn       = LCD_COLOR_STN_8BPP | LCD_AC_BIAS_FREQ(0xff),
335         .cmap_inverse   = 0,
336         .cmap_static    = 0,
337 };
338
339 static struct pxafb_mach_info *cmx2xx_display = &generic_crt_640x480;
340
341 static int __init cmx2xx_set_display(char *str)
342 {
343         int disp_type = simple_strtol(str, NULL, 0);
344         switch (disp_type) {
345         case MTYPE_STN320x240:
346                 cmx2xx_display = &generic_stn_320x240;
347                 break;
348         case MTYPE_TFT640x480:
349                 cmx2xx_display = &generic_tft_640x480;
350                 break;
351         case MTYPE_CRT640x480:
352                 cmx2xx_display = &generic_crt_640x480;
353                 break;
354         case MTYPE_CRT800x600:
355                 cmx2xx_display = &generic_crt_800x600;
356                 break;
357         case MTYPE_TFT320x240:
358                 cmx2xx_display = &generic_tft_320x240;
359                 break;
360         case MTYPE_STN640x480:
361                 cmx2xx_display = &generic_stn_640x480;
362                 break;
363         default: /* fallback to CRT 640x480 */
364                 cmx2xx_display = &generic_crt_640x480;
365                 break;
366         }
367         return 1;
368 }
369
370 /*
371    This should be done really early to get proper configuration for
372    frame buffer.
373    Indeed, pxafb parameters can be used istead, but CM-X2XX bootloader
374    has limitied line length for kernel command line, and also it will
375    break compatibitlty with proprietary releases already in field.
376 */
377 __setup("monitor=", cmx2xx_set_display);
378
379 static void __init cmx2xx_init_display(void)
380 {
381         set_pxa_fb_info(cmx2xx_display);
382 }
383 #else
384 static inline void cmx2xx_init_display(void) {}
385 #endif
386
387 #ifdef CONFIG_PM
388 static unsigned long sleep_save_msc[10];
389
390 static int cmx2xx_suspend(struct sys_device *dev, pm_message_t state)
391 {
392         cmx2xx_pci_suspend();
393
394         /* save MSC registers */
395         sleep_save_msc[0] = MSC0;
396         sleep_save_msc[1] = MSC1;
397         sleep_save_msc[2] = MSC2;
398
399         /* setup power saving mode registers */
400         PCFR = 0x0;
401         PSLR = 0xff400000;
402         PMCR  = 0x00000005;
403         PWER  = 0x80000000;
404         PFER  = 0x00000000;
405         PRER  = 0x00000000;
406         PGSR0 = 0xC0018800;
407         PGSR1 = 0x004F0002;
408         PGSR2 = 0x6021C000;
409         PGSR3 = 0x00020000;
410
411         return 0;
412 }
413
414 static int cmx2xx_resume(struct sys_device *dev)
415 {
416         cmx2xx_pci_resume();
417
418         /* restore MSC registers */
419         MSC0 = sleep_save_msc[0];
420         MSC1 = sleep_save_msc[1];
421         MSC2 = sleep_save_msc[2];
422
423         return 0;
424 }
425
426 static struct sysdev_class cmx2xx_pm_sysclass = {
427         .name = "pm",
428         .resume = cmx2xx_resume,
429         .suspend = cmx2xx_suspend,
430 };
431
432 static struct sys_device cmx2xx_pm_device = {
433         .cls = &cmx2xx_pm_sysclass,
434 };
435
436 static int __init cmx2xx_pm_init(void)
437 {
438         int error;
439         error = sysdev_class_register(&cmx2xx_pm_sysclass);
440         if (error == 0)
441                 error = sysdev_register(&cmx2xx_pm_device);
442         return error;
443 }
444 #else
445 static int __init cmx2xx_pm_init(void) { return 0; }
446 #endif
447
448 #if defined(CONFIG_SND_PXA2XX_AC97) || defined(CONFIG_SND_PXA2XX_AC97_MODULE)
449 static void __init cmx2xx_init_ac97(void)
450 {
451         pxa_set_ac97_info(NULL);
452 }
453 #else
454 static inline void cmx2xx_init_ac97(void) {}
455 #endif
456
457 static void __init cmx2xx_init(void)
458 {
459         pxa_set_ffuart_info(NULL);
460         pxa_set_btuart_info(NULL);
461         pxa_set_stuart_info(NULL);
462
463         cmx2xx_pm_init();
464
465         if (cpu_is_pxa25x())
466                 cmx255_init();
467         else
468                 cmx270_init();
469
470         cmx2xx_init_dm9000();
471         cmx2xx_init_display();
472         cmx2xx_init_ac97();
473         cmx2xx_init_touchscreen();
474         cmx2xx_init_leds();
475 }
476
477 static void __init cmx2xx_init_irq(void)
478 {
479         pxa27x_init_irq();
480
481         if (cpu_is_pxa25x()) {
482                 pxa25x_init_irq();
483                 cmx2xx_pci_init_irq(CMX255_GPIO_IT8152_IRQ);
484         } else {
485                 pxa27x_init_irq();
486                 cmx2xx_pci_init_irq(CMX270_GPIO_IT8152_IRQ);
487         }
488 }
489
490 #ifdef CONFIG_PCI
491 /* Map PCI companion statically */
492 static struct map_desc cmx2xx_io_desc[] __initdata = {
493         [0] = { /* PCI bridge */
494                 .virtual        = CMX2XX_IT8152_VIRT,
495                 .pfn            = __phys_to_pfn(PXA_CS4_PHYS),
496                 .length         = SZ_64M,
497                 .type           = MT_DEVICE
498         },
499 };
500
501 static void __init cmx2xx_map_io(void)
502 {
503         pxa_map_io();
504         iotable_init(cmx2xx_io_desc, ARRAY_SIZE(cmx2xx_io_desc));
505
506         it8152_base_address = CMX2XX_IT8152_VIRT;
507 }
508 #else
509 static void __init cmx2xx_map_io(void)
510 {
511         pxa_map_io();
512 }
513 #endif
514
515 MACHINE_START(ARMCORE, "Compulab CM-X2XX")
516         .boot_params    = 0xa0000100,
517         .map_io         = cmx2xx_map_io,
518         .nr_irqs        = CMX2XX_NR_IRQS,
519         .init_irq       = cmx2xx_init_irq,
520         .timer          = &pxa_timer,
521         .init_machine   = cmx2xx_init,
522 MACHINE_END