Merge branch 'fb' into devel
[sfrench/cifs-2.6.git] / 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
22 #include <asm/mach-types.h>
23 #include <asm/mach/arch.h>
24 #include <asm/hardware.h>
25 #include <asm/arch/gpio.h>
26 #include <asm/arch/pxafb.h>
27 #include <asm/arch/zylonite.h>
28 #include <asm/arch/mmc.h>
29 #include <asm/arch/pxa27x_keypad.h>
30
31 #include "generic.h"
32
33 #define MAX_SLOTS       3
34 struct platform_mmc_slot zylonite_mmc_slot[MAX_SLOTS];
35
36 int gpio_backlight;
37 int gpio_eth_irq;
38
39 int wm9713_irq;
40
41 int lcd_id;
42 int lcd_orientation;
43
44 static struct resource smc91x_resources[] = {
45         [0] = {
46                 .start  = ZYLONITE_ETH_PHYS + 0x300,
47                 .end    = ZYLONITE_ETH_PHYS + 0xfffff,
48                 .flags  = IORESOURCE_MEM,
49         },
50         [1] = {
51                 .start  = -1,   /* for run-time assignment */
52                 .end    = -1,
53                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
54         }
55 };
56
57 static struct platform_device smc91x_device = {
58         .name           = "smc91x",
59         .id             = 0,
60         .num_resources  = ARRAY_SIZE(smc91x_resources),
61         .resource       = smc91x_resources,
62 };
63
64 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
65 static void zylonite_backlight_power(int on)
66 {
67         gpio_set_value(gpio_backlight, on);
68 }
69
70 static struct pxafb_mode_info toshiba_ltm035a776c_mode = {
71         .pixclock               = 110000,
72         .xres                   = 240,
73         .yres                   = 320,
74         .bpp                    = 16,
75         .hsync_len              = 4,
76         .left_margin            = 6,
77         .right_margin           = 4,
78         .vsync_len              = 2,
79         .upper_margin           = 2,
80         .lower_margin           = 3,
81         .sync                   = FB_SYNC_VERT_HIGH_ACT,
82 };
83
84 static struct pxafb_mode_info toshiba_ltm04c380k_mode = {
85         .pixclock               = 50000,
86         .xres                   = 640,
87         .yres                   = 480,
88         .bpp                    = 16,
89         .hsync_len              = 1,
90         .left_margin            = 0x9f,
91         .right_margin           = 1,
92         .vsync_len              = 44,
93         .upper_margin           = 0,
94         .lower_margin           = 0,
95         .sync                   = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
96 };
97
98 static struct pxafb_mach_info zylonite_toshiba_lcd_info = {
99         .num_modes              = 1,
100         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
101         .pxafb_backlight_power  = zylonite_backlight_power,
102 };
103
104 static struct pxafb_mode_info sharp_ls037_modes[] = {
105         [0] = {
106                 .pixclock       = 158000,
107                 .xres           = 240,
108                 .yres           = 320,
109                 .bpp            = 16,
110                 .hsync_len      = 4,
111                 .left_margin    = 39,
112                 .right_margin   = 39,
113                 .vsync_len      = 1,
114                 .upper_margin   = 2,
115                 .lower_margin   = 3,
116                 .sync           = 0,
117         },
118         [1] = {
119                 .pixclock       = 39700,
120                 .xres           = 480,
121                 .yres           = 640,
122                 .bpp            = 16,
123                 .hsync_len      = 8,
124                 .left_margin    = 81,
125                 .right_margin   = 81,
126                 .vsync_len      = 1,
127                 .upper_margin   = 2,
128                 .lower_margin   = 7,
129                 .sync           = 0,
130         },
131 };
132
133 static struct pxafb_mach_info zylonite_sharp_lcd_info = {
134         .modes                  = sharp_ls037_modes,
135         .num_modes              = 2,
136         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
137         .pxafb_backlight_power  = zylonite_backlight_power,
138 };
139
140 static void __init zylonite_init_lcd(void)
141 {
142         /* backlight GPIO: output, default on */
143         gpio_direction_output(gpio_backlight, 1);
144
145         if (lcd_id & 0x20) {
146                 set_pxa_fb_info(&zylonite_sharp_lcd_info);
147                 return;
148         }
149
150         /* legacy LCD panels, it would be handy here if LCD panel type can
151          * be decided at run-time
152          */
153         if (1)
154                 zylonite_toshiba_lcd_info.modes = &toshiba_ltm035a776c_mode;
155         else
156                 zylonite_toshiba_lcd_info.modes = &toshiba_ltm04c380k_mode;
157
158         set_pxa_fb_info(&zylonite_toshiba_lcd_info);
159 }
160 #else
161 static inline void zylonite_init_lcd(void) {}
162 #endif
163
164 #if defined(CONFIG_MMC)
165 static int zylonite_mci_ro(struct device *dev)
166 {
167         struct platform_device *pdev = to_platform_device(dev);
168
169         return gpio_get_value(zylonite_mmc_slot[pdev->id].gpio_wp);
170 }
171
172 static int zylonite_mci_init(struct device *dev,
173                              irq_handler_t zylonite_detect_int,
174                              void *data)
175 {
176         struct platform_device *pdev = to_platform_device(dev);
177         int err, cd_irq, gpio_cd, gpio_wp;
178
179         cd_irq = gpio_to_irq(zylonite_mmc_slot[pdev->id].gpio_cd);
180         gpio_cd = zylonite_mmc_slot[pdev->id].gpio_cd;
181         gpio_wp = zylonite_mmc_slot[pdev->id].gpio_wp;
182
183         /*
184          * setup GPIO for Zylonite MMC controller
185          */
186         err = gpio_request(gpio_cd, "mmc card detect");
187         if (err)
188                 goto err_request_cd;
189         gpio_direction_input(gpio_cd);
190
191         err = gpio_request(gpio_wp, "mmc write protect");
192         if (err)
193                 goto err_request_wp;
194         gpio_direction_input(gpio_wp);
195
196         err = request_irq(cd_irq, zylonite_detect_int,
197                           IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
198                           "MMC card detect", data);
199         if (err) {
200                 printk(KERN_ERR "%s: MMC/SD/SDIO: "
201                                 "can't request card detect IRQ\n", __func__);
202                 goto err_request_irq;
203         }
204
205         return 0;
206
207 err_request_irq:
208         gpio_free(gpio_wp);
209 err_request_wp:
210         gpio_free(gpio_cd);
211 err_request_cd:
212         return err;
213 }
214
215 static void zylonite_mci_exit(struct device *dev, void *data)
216 {
217         struct platform_device *pdev = to_platform_device(dev);
218         int cd_irq, gpio_cd, gpio_wp;
219
220         cd_irq = gpio_to_irq(zylonite_mmc_slot[pdev->id].gpio_cd);
221         gpio_cd = zylonite_mmc_slot[pdev->id].gpio_cd;
222         gpio_wp = zylonite_mmc_slot[pdev->id].gpio_wp;
223
224         free_irq(cd_irq, data);
225         gpio_free(gpio_cd);
226         gpio_free(gpio_wp);
227 }
228
229 static struct pxamci_platform_data zylonite_mci_platform_data = {
230         .detect_delay   = 20,
231         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
232         .init           = zylonite_mci_init,
233         .exit           = zylonite_mci_exit,
234         .get_ro         = zylonite_mci_ro,
235 };
236
237 static struct pxamci_platform_data zylonite_mci2_platform_data = {
238         .detect_delay   = 20,
239         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
240 };
241
242 static void __init zylonite_init_mmc(void)
243 {
244         pxa_set_mci_info(&zylonite_mci_platform_data);
245         pxa3xx_set_mci2_info(&zylonite_mci2_platform_data);
246         if (cpu_is_pxa310())
247                 pxa3xx_set_mci3_info(&zylonite_mci_platform_data);
248 }
249 #else
250 static inline void zylonite_init_mmc(void) {}
251 #endif
252
253 #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULES)
254 static unsigned int zylonite_matrix_key_map[] = {
255         /* KEY(row, col, key_code) */
256         KEY(0, 0, KEY_A), KEY(0, 1, KEY_B), KEY(0, 2, KEY_C), KEY(0, 5, KEY_D),
257         KEY(1, 0, KEY_E), KEY(1, 1, KEY_F), KEY(1, 2, KEY_G), KEY(1, 5, KEY_H),
258         KEY(2, 0, KEY_I), KEY(2, 1, KEY_J), KEY(2, 2, KEY_K), KEY(2, 5, KEY_L),
259         KEY(3, 0, KEY_M), KEY(3, 1, KEY_N), KEY(3, 2, KEY_O), KEY(3, 5, KEY_P),
260         KEY(5, 0, KEY_Q), KEY(5, 1, KEY_R), KEY(5, 2, KEY_S), KEY(5, 5, KEY_T),
261         KEY(6, 0, KEY_U), KEY(6, 1, KEY_V), KEY(6, 2, KEY_W), KEY(6, 5, KEY_X),
262         KEY(7, 1, KEY_Y), KEY(7, 2, KEY_Z),
263
264         KEY(4, 4, KEY_0), KEY(1, 3, KEY_1), KEY(4, 1, KEY_2), KEY(1, 4, KEY_3),
265         KEY(2, 3, KEY_4), KEY(4, 2, KEY_5), KEY(2, 4, KEY_6), KEY(3, 3, KEY_7),
266         KEY(4, 3, KEY_8), KEY(3, 4, KEY_9),
267
268         KEY(4, 5, KEY_SPACE),
269         KEY(5, 3, KEY_KPASTERISK),      /* * */
270         KEY(5, 4, KEY_KPDOT),           /* #" */
271
272         KEY(0, 7, KEY_UP),
273         KEY(1, 7, KEY_DOWN),
274         KEY(2, 7, KEY_LEFT),
275         KEY(3, 7, KEY_RIGHT),
276         KEY(2, 6, KEY_HOME),
277         KEY(3, 6, KEY_END),
278         KEY(6, 4, KEY_DELETE),
279         KEY(6, 6, KEY_BACK),
280         KEY(6, 3, KEY_CAPSLOCK),        /* KEY_LEFTSHIFT), */
281
282         KEY(4, 6, KEY_ENTER),           /* scroll push */
283         KEY(5, 7, KEY_ENTER),           /* keypad action */
284
285         KEY(0, 4, KEY_EMAIL),
286         KEY(5, 6, KEY_SEND),
287         KEY(4, 0, KEY_CALENDAR),
288         KEY(7, 6, KEY_RECORD),
289         KEY(6, 7, KEY_VOLUMEUP),
290         KEY(7, 7, KEY_VOLUMEDOWN),
291
292         KEY(0, 6, KEY_F22),     /* soft1 */
293         KEY(1, 6, KEY_F23),     /* soft2 */
294         KEY(0, 3, KEY_AUX),     /* contact */
295 };
296
297 static struct pxa27x_keypad_platform_data zylonite_keypad_info = {
298         .matrix_key_rows        = 8,
299         .matrix_key_cols        = 8,
300         .matrix_key_map         = zylonite_matrix_key_map,
301         .matrix_key_map_size    = ARRAY_SIZE(zylonite_matrix_key_map),
302
303         .enable_rotary0         = 1,
304         .rotary0_up_key         = KEY_UP,
305         .rotary0_down_key       = KEY_DOWN,
306
307         .debounce_interval      = 30,
308 };
309
310 static void __init zylonite_init_keypad(void)
311 {
312         pxa_set_keypad_info(&zylonite_keypad_info);
313 }
314 #else
315 static inline void zylonite_init_keypad(void) {}
316 #endif
317
318 static void __init zylonite_init(void)
319 {
320         /* board-processor specific initialization */
321         zylonite_pxa300_init();
322         zylonite_pxa320_init();
323
324         /*
325          * Note: We depend that the bootloader set
326          * the correct value to MSC register for SMC91x.
327          */
328         smc91x_resources[1].start = gpio_to_irq(gpio_eth_irq);
329         smc91x_resources[1].end   = gpio_to_irq(gpio_eth_irq);
330         platform_device_register(&smc91x_device);
331
332         zylonite_init_lcd();
333         zylonite_init_mmc();
334         zylonite_init_keypad();
335 }
336
337 MACHINE_START(ZYLONITE, "PXA3xx Platform Development Kit (aka Zylonite)")
338         .phys_io        = 0x40000000,
339         .boot_params    = 0xa0000100,
340         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
341         .map_io         = pxa_map_io,
342         .init_irq       = pxa3xx_init_irq,
343         .timer          = &pxa_timer,
344         .init_machine   = zylonite_init,
345 MACHINE_END