[ARM] pxa: add simple gpio debug LEDs support for zylonite
[linux-2.6] / arch / arm / mach-pxa / zylonite.c
1 /*
2  * linux/arch/arm/mach-pxa/zylonite.c
3  *
4  * Support for the PXA3xx Development Platform (aka Zylonite)
5  *
6  * Copyright (C) 2006 Marvell International Ltd.
7  *
8  * 2007-09-04: eric miao <eric.miao@marvell.com>
9  *             rewrite to align with latest kernel
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/module.h>
17 #include <linux/kernel.h>
18 #include <linux/interrupt.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/pwm_backlight.h>
22
23 #include <asm/mach-types.h>
24 #include <asm/mach/arch.h>
25 #include <asm/hardware.h>
26 #include <asm/arch/audio.h>
27 #include <asm/arch/gpio.h>
28 #include <asm/arch/pxafb.h>
29 #include <asm/arch/zylonite.h>
30 #include <asm/arch/mmc.h>
31 #include <asm/arch/pxa27x_keypad.h>
32 #include <asm/arch/pxa3xx_nand.h>
33
34 #include "devices.h"
35 #include "generic.h"
36
37 #define MAX_SLOTS       3
38 struct platform_mmc_slot zylonite_mmc_slot[MAX_SLOTS];
39
40 int gpio_eth_irq;
41 int gpio_debug_led1;
42 int gpio_debug_led2;
43
44 int wm9713_irq;
45
46 int lcd_id;
47 int lcd_orientation;
48
49 static struct resource smc91x_resources[] = {
50         [0] = {
51                 .start  = ZYLONITE_ETH_PHYS + 0x300,
52                 .end    = ZYLONITE_ETH_PHYS + 0xfffff,
53                 .flags  = IORESOURCE_MEM,
54         },
55         [1] = {
56                 .start  = -1,   /* for run-time assignment */
57                 .end    = -1,
58                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
59         }
60 };
61
62 static struct platform_device smc91x_device = {
63         .name           = "smc91x",
64         .id             = 0,
65         .num_resources  = ARRAY_SIZE(smc91x_resources),
66         .resource       = smc91x_resources,
67 };
68
69 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
70 static struct gpio_led zylonite_debug_leds[] = {
71         [0] = {
72                 .name                   = "zylonite:yellow:1",
73                 .default_trigger        = "heartbeat",
74         },
75         [1] = {
76                 .name                   = "zylonite:yellow:2",
77                 .default_trigger        = "default-on",
78         },
79 };
80
81 static struct gpio_led_platform_data zylonite_debug_leds_info = {
82         .leds           = zylonite_debug_leds,
83         .num_leds       = ARRAY_SIZE(zylonite_debug_leds),
84 };
85
86 static struct platform_device zylonite_device_leds = {
87         .name           = "leds-gpio",
88         .id             = -1,
89         .dev            = {
90                 .platform_data = &zylonite_debug_leds_info,
91         }
92 };
93
94 static void __init zylonite_init_leds(void)
95 {
96         zylonite_debug_leds[0].gpio = gpio_debug_led1;
97         zylonite_debug_leds[1].gpio = gpio_debug_led2;
98
99         platform_device_register(&zylonite_device_leds);
100 }
101 #else
102 static inline void zylonite_init_leds(void) {}
103 #endif
104
105 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
106 static struct platform_pwm_backlight_data zylonite_backlight_data = {
107         .pwm_id         = 3,
108         .max_brightness = 100,
109         .dft_brightness = 100,
110         .pwm_period_ns  = 10000,
111 };
112
113 static struct platform_device zylonite_backlight_device = {
114         .name           = "pwm-backlight",
115         .dev            = {
116                 .parent = &pxa27x_device_pwm1.dev,
117                 .platform_data  = &zylonite_backlight_data,
118         },
119 };
120
121 static struct pxafb_mode_info toshiba_ltm035a776c_mode = {
122         .pixclock               = 110000,
123         .xres                   = 240,
124         .yres                   = 320,
125         .bpp                    = 16,
126         .hsync_len              = 4,
127         .left_margin            = 6,
128         .right_margin           = 4,
129         .vsync_len              = 2,
130         .upper_margin           = 2,
131         .lower_margin           = 3,
132         .sync                   = FB_SYNC_VERT_HIGH_ACT,
133 };
134
135 static struct pxafb_mode_info toshiba_ltm04c380k_mode = {
136         .pixclock               = 50000,
137         .xres                   = 640,
138         .yres                   = 480,
139         .bpp                    = 16,
140         .hsync_len              = 1,
141         .left_margin            = 0x9f,
142         .right_margin           = 1,
143         .vsync_len              = 44,
144         .upper_margin           = 0,
145         .lower_margin           = 0,
146         .sync                   = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
147 };
148
149 static struct pxafb_mach_info zylonite_toshiba_lcd_info = {
150         .num_modes              = 1,
151         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
152 };
153
154 static struct pxafb_mode_info sharp_ls037_modes[] = {
155         [0] = {
156                 .pixclock       = 158000,
157                 .xres           = 240,
158                 .yres           = 320,
159                 .bpp            = 16,
160                 .hsync_len      = 4,
161                 .left_margin    = 39,
162                 .right_margin   = 39,
163                 .vsync_len      = 1,
164                 .upper_margin   = 2,
165                 .lower_margin   = 3,
166                 .sync           = 0,
167         },
168         [1] = {
169                 .pixclock       = 39700,
170                 .xres           = 480,
171                 .yres           = 640,
172                 .bpp            = 16,
173                 .hsync_len      = 8,
174                 .left_margin    = 81,
175                 .right_margin   = 81,
176                 .vsync_len      = 1,
177                 .upper_margin   = 2,
178                 .lower_margin   = 7,
179                 .sync           = 0,
180         },
181 };
182
183 static struct pxafb_mach_info zylonite_sharp_lcd_info = {
184         .modes                  = sharp_ls037_modes,
185         .num_modes              = 2,
186         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
187 };
188
189 static void __init zylonite_init_lcd(void)
190 {
191         platform_device_register(&zylonite_backlight_device);
192
193         if (lcd_id & 0x20) {
194                 set_pxa_fb_info(&zylonite_sharp_lcd_info);
195                 return;
196         }
197
198         /* legacy LCD panels, it would be handy here if LCD panel type can
199          * be decided at run-time
200          */
201         if (1)
202                 zylonite_toshiba_lcd_info.modes = &toshiba_ltm035a776c_mode;
203         else
204                 zylonite_toshiba_lcd_info.modes = &toshiba_ltm04c380k_mode;
205
206         set_pxa_fb_info(&zylonite_toshiba_lcd_info);
207 }
208 #else
209 static inline void zylonite_init_lcd(void) {}
210 #endif
211
212 #if defined(CONFIG_MMC)
213 static int zylonite_mci_ro(struct device *dev)
214 {
215         struct platform_device *pdev = to_platform_device(dev);
216
217         return gpio_get_value(zylonite_mmc_slot[pdev->id].gpio_wp);
218 }
219
220 static int zylonite_mci_init(struct device *dev,
221                              irq_handler_t zylonite_detect_int,
222                              void *data)
223 {
224         struct platform_device *pdev = to_platform_device(dev);
225         int err, cd_irq, gpio_cd, gpio_wp;
226
227         cd_irq = gpio_to_irq(zylonite_mmc_slot[pdev->id].gpio_cd);
228         gpio_cd = zylonite_mmc_slot[pdev->id].gpio_cd;
229         gpio_wp = zylonite_mmc_slot[pdev->id].gpio_wp;
230
231         /*
232          * setup GPIO for Zylonite MMC controller
233          */
234         err = gpio_request(gpio_cd, "mmc card detect");
235         if (err)
236                 goto err_request_cd;
237         gpio_direction_input(gpio_cd);
238
239         err = gpio_request(gpio_wp, "mmc write protect");
240         if (err)
241                 goto err_request_wp;
242         gpio_direction_input(gpio_wp);
243
244         err = request_irq(cd_irq, zylonite_detect_int,
245                           IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
246                           "MMC card detect", data);
247         if (err) {
248                 printk(KERN_ERR "%s: MMC/SD/SDIO: "
249                                 "can't request card detect IRQ\n", __func__);
250                 goto err_request_irq;
251         }
252
253         return 0;
254
255 err_request_irq:
256         gpio_free(gpio_wp);
257 err_request_wp:
258         gpio_free(gpio_cd);
259 err_request_cd:
260         return err;
261 }
262
263 static void zylonite_mci_exit(struct device *dev, void *data)
264 {
265         struct platform_device *pdev = to_platform_device(dev);
266         int cd_irq, gpio_cd, gpio_wp;
267
268         cd_irq = gpio_to_irq(zylonite_mmc_slot[pdev->id].gpio_cd);
269         gpio_cd = zylonite_mmc_slot[pdev->id].gpio_cd;
270         gpio_wp = zylonite_mmc_slot[pdev->id].gpio_wp;
271
272         free_irq(cd_irq, data);
273         gpio_free(gpio_cd);
274         gpio_free(gpio_wp);
275 }
276
277 static struct pxamci_platform_data zylonite_mci_platform_data = {
278         .detect_delay   = 20,
279         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
280         .init           = zylonite_mci_init,
281         .exit           = zylonite_mci_exit,
282         .get_ro         = zylonite_mci_ro,
283 };
284
285 static struct pxamci_platform_data zylonite_mci2_platform_data = {
286         .detect_delay   = 20,
287         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
288 };
289
290 static void __init zylonite_init_mmc(void)
291 {
292         pxa_set_mci_info(&zylonite_mci_platform_data);
293         pxa3xx_set_mci2_info(&zylonite_mci2_platform_data);
294         if (cpu_is_pxa310())
295                 pxa3xx_set_mci3_info(&zylonite_mci_platform_data);
296 }
297 #else
298 static inline void zylonite_init_mmc(void) {}
299 #endif
300
301 #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
302 static unsigned int zylonite_matrix_key_map[] = {
303         /* KEY(row, col, key_code) */
304         KEY(0, 0, KEY_A), KEY(0, 1, KEY_B), KEY(0, 2, KEY_C), KEY(0, 5, KEY_D),
305         KEY(1, 0, KEY_E), KEY(1, 1, KEY_F), KEY(1, 2, KEY_G), KEY(1, 5, KEY_H),
306         KEY(2, 0, KEY_I), KEY(2, 1, KEY_J), KEY(2, 2, KEY_K), KEY(2, 5, KEY_L),
307         KEY(3, 0, KEY_M), KEY(3, 1, KEY_N), KEY(3, 2, KEY_O), KEY(3, 5, KEY_P),
308         KEY(5, 0, KEY_Q), KEY(5, 1, KEY_R), KEY(5, 2, KEY_S), KEY(5, 5, KEY_T),
309         KEY(6, 0, KEY_U), KEY(6, 1, KEY_V), KEY(6, 2, KEY_W), KEY(6, 5, KEY_X),
310         KEY(7, 1, KEY_Y), KEY(7, 2, KEY_Z),
311
312         KEY(4, 4, KEY_0), KEY(1, 3, KEY_1), KEY(4, 1, KEY_2), KEY(1, 4, KEY_3),
313         KEY(2, 3, KEY_4), KEY(4, 2, KEY_5), KEY(2, 4, KEY_6), KEY(3, 3, KEY_7),
314         KEY(4, 3, KEY_8), KEY(3, 4, KEY_9),
315
316         KEY(4, 5, KEY_SPACE),
317         KEY(5, 3, KEY_KPASTERISK),      /* * */
318         KEY(5, 4, KEY_KPDOT),           /* #" */
319
320         KEY(0, 7, KEY_UP),
321         KEY(1, 7, KEY_DOWN),
322         KEY(2, 7, KEY_LEFT),
323         KEY(3, 7, KEY_RIGHT),
324         KEY(2, 6, KEY_HOME),
325         KEY(3, 6, KEY_END),
326         KEY(6, 4, KEY_DELETE),
327         KEY(6, 6, KEY_BACK),
328         KEY(6, 3, KEY_CAPSLOCK),        /* KEY_LEFTSHIFT), */
329
330         KEY(4, 6, KEY_ENTER),           /* scroll push */
331         KEY(5, 7, KEY_ENTER),           /* keypad action */
332
333         KEY(0, 4, KEY_EMAIL),
334         KEY(5, 6, KEY_SEND),
335         KEY(4, 0, KEY_CALENDAR),
336         KEY(7, 6, KEY_RECORD),
337         KEY(6, 7, KEY_VOLUMEUP),
338         KEY(7, 7, KEY_VOLUMEDOWN),
339
340         KEY(0, 6, KEY_F22),     /* soft1 */
341         KEY(1, 6, KEY_F23),     /* soft2 */
342         KEY(0, 3, KEY_AUX),     /* contact */
343 };
344
345 static struct pxa27x_keypad_platform_data zylonite_keypad_info = {
346         .matrix_key_rows        = 8,
347         .matrix_key_cols        = 8,
348         .matrix_key_map         = zylonite_matrix_key_map,
349         .matrix_key_map_size    = ARRAY_SIZE(zylonite_matrix_key_map),
350
351         .enable_rotary0         = 1,
352         .rotary0_up_key         = KEY_UP,
353         .rotary0_down_key       = KEY_DOWN,
354
355         .debounce_interval      = 30,
356 };
357
358 static void __init zylonite_init_keypad(void)
359 {
360         pxa_set_keypad_info(&zylonite_keypad_info);
361 }
362 #else
363 static inline void zylonite_init_keypad(void) {}
364 #endif
365
366 #if defined(CONFIG_MTD_NAND_PXA3xx) || defined(CONFIG_MTD_NAND_PXA3xx_MODULE)
367 static struct mtd_partition zylonite_nand_partitions[] = {
368         [0] = {
369                 .name        = "Bootloader",
370                 .offset      = 0,
371                 .size        = 0x060000,
372                 .mask_flags  = MTD_WRITEABLE, /* force read-only */
373         },
374         [1] = {
375                 .name        = "Kernel",
376                 .offset      = 0x060000,
377                 .size        = 0x200000,
378                 .mask_flags  = MTD_WRITEABLE, /* force read-only */
379         },
380         [2] = {
381                 .name        = "Filesystem",
382                 .offset      = 0x0260000,
383                 .size        = 0x3000000,     /* 48M - rootfs */
384         },
385         [3] = {
386                 .name        = "MassStorage",
387                 .offset      = 0x3260000,
388                 .size        = 0x3d40000,
389         },
390         [4] = {
391                 .name        = "BBT",
392                 .offset      = 0x6FA0000,
393                 .size        = 0x80000,
394                 .mask_flags  = MTD_WRITEABLE,  /* force read-only */
395         },
396         /* NOTE: we reserve some blocks at the end of the NAND flash for
397          * bad block management, and the max number of relocation blocks
398          * differs on different platforms. Please take care with it when
399          * defining the partition table.
400          */
401 };
402
403 static struct pxa3xx_nand_platform_data zylonite_nand_info = {
404         .enable_arbiter = 1,
405         .parts          = zylonite_nand_partitions,
406         .nr_parts       = ARRAY_SIZE(zylonite_nand_partitions),
407 };
408
409 static void __init zylonite_init_nand(void)
410 {
411         pxa3xx_set_nand_info(&zylonite_nand_info);
412 }
413 #else
414 static inline void zylonite_init_nand(void) {}
415 #endif /* CONFIG_MTD_NAND_PXA3xx || CONFIG_MTD_NAND_PXA3xx_MODULE */
416
417 static void __init zylonite_init(void)
418 {
419         /* board-processor specific initialization */
420         zylonite_pxa300_init();
421         zylonite_pxa320_init();
422
423         /*
424          * Note: We depend that the bootloader set
425          * the correct value to MSC register for SMC91x.
426          */
427         smc91x_resources[1].start = gpio_to_irq(gpio_eth_irq);
428         smc91x_resources[1].end   = gpio_to_irq(gpio_eth_irq);
429         platform_device_register(&smc91x_device);
430
431         pxa_set_ac97_info(NULL);
432         zylonite_init_lcd();
433         zylonite_init_mmc();
434         zylonite_init_keypad();
435         zylonite_init_nand();
436         zylonite_init_leds();
437 }
438
439 MACHINE_START(ZYLONITE, "PXA3xx Platform Development Kit (aka Zylonite)")
440         .phys_io        = 0x40000000,
441         .boot_params    = 0xa0000100,
442         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
443         .map_io         = pxa_map_io,
444         .init_irq       = pxa3xx_init_irq,
445         .timer          = &pxa_timer,
446         .init_machine   = zylonite_init,
447 MACHINE_END