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