OSDN Git Service

ARM: pxa: Add gpio descriptor lookup tables for MMC CD/WP
[uclinux-h8/linux.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/leds.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/gpio/machine.h>
23 #include <linux/pwm.h>
24 #include <linux/pwm_backlight.h>
25 #include <linux/smc91x.h>
26
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include "pxa3xx.h"
30 #include <mach/audio.h>
31 #include <linux/platform_data/video-pxafb.h>
32 #include "zylonite.h"
33 #include <linux/platform_data/mmc-pxamci.h>
34 #include <linux/platform_data/usb-ohci-pxa27x.h>
35 #include <linux/platform_data/keypad-pxa27x.h>
36 #include <linux/platform_data/mtd-nand-pxa3xx.h>
37
38 #include "devices.h"
39 #include "generic.h"
40
41 int gpio_eth_irq;
42 int gpio_debug_led1;
43 int gpio_debug_led2;
44
45 int wm9713_irq;
46
47 int lcd_id;
48 int lcd_orientation;
49
50 static struct resource smc91x_resources[] = {
51         [0] = {
52                 .start  = ZYLONITE_ETH_PHYS + 0x300,
53                 .end    = ZYLONITE_ETH_PHYS + 0xfffff,
54                 .flags  = IORESOURCE_MEM,
55         },
56         [1] = {
57                 .start  = -1,   /* for run-time assignment */
58                 .end    = -1,
59                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
60         }
61 };
62
63 static struct smc91x_platdata zylonite_smc91x_info = {
64         .flags  = SMC91X_USE_8BIT | SMC91X_USE_16BIT |
65                   SMC91X_NOWAIT | SMC91X_USE_DMA,
66 };
67
68 static struct platform_device smc91x_device = {
69         .name           = "smc91x",
70         .id             = 0,
71         .num_resources  = ARRAY_SIZE(smc91x_resources),
72         .resource       = smc91x_resources,
73         .dev            = {
74                 .platform_data = &zylonite_smc91x_info,
75         },
76 };
77
78 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
79 static struct gpio_led zylonite_debug_leds[] = {
80         [0] = {
81                 .name                   = "zylonite:yellow:1",
82                 .default_trigger        = "heartbeat",
83         },
84         [1] = {
85                 .name                   = "zylonite:yellow:2",
86                 .default_trigger        = "default-on",
87         },
88 };
89
90 static struct gpio_led_platform_data zylonite_debug_leds_info = {
91         .leds           = zylonite_debug_leds,
92         .num_leds       = ARRAY_SIZE(zylonite_debug_leds),
93 };
94
95 static struct platform_device zylonite_device_leds = {
96         .name           = "leds-gpio",
97         .id             = -1,
98         .dev            = {
99                 .platform_data = &zylonite_debug_leds_info,
100         }
101 };
102
103 static void __init zylonite_init_leds(void)
104 {
105         zylonite_debug_leds[0].gpio = gpio_debug_led1;
106         zylonite_debug_leds[1].gpio = gpio_debug_led2;
107
108         platform_device_register(&zylonite_device_leds);
109 }
110 #else
111 static inline void zylonite_init_leds(void) {}
112 #endif
113
114 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
115 static struct pwm_lookup zylonite_pwm_lookup[] = {
116         PWM_LOOKUP("pxa27x-pwm.1", 1, "pwm-backlight.0", NULL, 10000,
117                    PWM_POLARITY_NORMAL),
118 };
119
120 static struct platform_pwm_backlight_data zylonite_backlight_data = {
121         .max_brightness = 100,
122         .dft_brightness = 100,
123         .enable_gpio    = -1,
124 };
125
126 static struct platform_device zylonite_backlight_device = {
127         .name           = "pwm-backlight",
128         .dev            = {
129                 .parent = &pxa27x_device_pwm1.dev,
130                 .platform_data  = &zylonite_backlight_data,
131         },
132 };
133
134 static struct pxafb_mode_info toshiba_ltm035a776c_mode = {
135         .pixclock               = 110000,
136         .xres                   = 240,
137         .yres                   = 320,
138         .bpp                    = 16,
139         .hsync_len              = 4,
140         .left_margin            = 6,
141         .right_margin           = 4,
142         .vsync_len              = 2,
143         .upper_margin           = 2,
144         .lower_margin           = 3,
145         .sync                   = FB_SYNC_VERT_HIGH_ACT,
146 };
147
148 static struct pxafb_mode_info toshiba_ltm04c380k_mode = {
149         .pixclock               = 50000,
150         .xres                   = 640,
151         .yres                   = 480,
152         .bpp                    = 16,
153         .hsync_len              = 1,
154         .left_margin            = 0x9f,
155         .right_margin           = 1,
156         .vsync_len              = 44,
157         .upper_margin           = 0,
158         .lower_margin           = 0,
159         .sync                   = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
160 };
161
162 static struct pxafb_mach_info zylonite_toshiba_lcd_info = {
163         .num_modes              = 1,
164         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
165 };
166
167 static struct pxafb_mode_info sharp_ls037_modes[] = {
168         [0] = {
169                 .pixclock       = 158000,
170                 .xres           = 240,
171                 .yres           = 320,
172                 .bpp            = 16,
173                 .hsync_len      = 4,
174                 .left_margin    = 39,
175                 .right_margin   = 39,
176                 .vsync_len      = 1,
177                 .upper_margin   = 2,
178                 .lower_margin   = 3,
179                 .sync           = 0,
180         },
181         [1] = {
182                 .pixclock       = 39700,
183                 .xres           = 480,
184                 .yres           = 640,
185                 .bpp            = 16,
186                 .hsync_len      = 8,
187                 .left_margin    = 81,
188                 .right_margin   = 81,
189                 .vsync_len      = 1,
190                 .upper_margin   = 2,
191                 .lower_margin   = 7,
192                 .sync           = 0,
193         },
194 };
195
196 static struct pxafb_mach_info zylonite_sharp_lcd_info = {
197         .modes                  = sharp_ls037_modes,
198         .num_modes              = 2,
199         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
200 };
201
202 static void __init zylonite_init_lcd(void)
203 {
204         pwm_add_table(zylonite_pwm_lookup, ARRAY_SIZE(zylonite_pwm_lookup));
205         platform_device_register(&zylonite_backlight_device);
206
207         if (lcd_id & 0x20) {
208                 pxa_set_fb_info(NULL, &zylonite_sharp_lcd_info);
209                 return;
210         }
211
212         /* legacy LCD panels, it would be handy here if LCD panel type can
213          * be decided at run-time
214          */
215         if (1)
216                 zylonite_toshiba_lcd_info.modes = &toshiba_ltm035a776c_mode;
217         else
218                 zylonite_toshiba_lcd_info.modes = &toshiba_ltm04c380k_mode;
219
220         pxa_set_fb_info(NULL, &zylonite_toshiba_lcd_info);
221 }
222 #else
223 static inline void zylonite_init_lcd(void) {}
224 #endif
225
226 #if defined(CONFIG_MMC)
227 static struct pxamci_platform_data zylonite_mci_platform_data = {
228         .detect_delay_ms= 200,
229         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
230         .gpio_card_detect = EXT_GPIO(0),
231         .gpio_card_ro   = EXT_GPIO(2),
232         .gpio_power     = -1,
233 };
234
235 #define PCA9539A_MCI_CD 0
236 #define PCA9539A_MCI1_CD 1
237 #define PCA9539A_MCI_WP 2
238 #define PCA9539A_MCI1_WP 3
239 #define PCA9539A_MCI3_CD 30
240 #define PCA9539A_MCI3_WP 31
241
242 static struct gpiod_lookup_table zylonite_mci_gpio_table = {
243         .dev_id = "pxa2xx-mci.0",
244         .table = {
245                 GPIO_LOOKUP("i2c-pca9539-a", PCA9539A_MCI_CD,
246                             "cd", GPIO_ACTIVE_LOW),
247                 GPIO_LOOKUP("i2c-pca9539-a", PCA9539A_MCI_WP,
248                             "wp", GPIO_ACTIVE_LOW),
249                 { },
250         },
251 };
252
253 static struct pxamci_platform_data zylonite_mci2_platform_data = {
254         .detect_delay_ms= 200,
255         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
256         .gpio_card_detect = EXT_GPIO(1),
257         .gpio_card_ro   = EXT_GPIO(3),
258         .gpio_power     = -1,
259 };
260
261 static struct gpiod_lookup_table zylonite_mci2_gpio_table = {
262         .dev_id = "pxa2xx-mci.1",
263         .table = {
264                 GPIO_LOOKUP("i2c-pca9539-a", PCA9539A_MCI1_CD,
265                             "cd", GPIO_ACTIVE_LOW),
266                 GPIO_LOOKUP("i2c-pca9539-a", PCA9539A_MCI1_WP,
267                             "wp", GPIO_ACTIVE_LOW),
268                 { },
269         },
270 };
271
272 static struct pxamci_platform_data zylonite_mci3_platform_data = {
273         .detect_delay_ms= 200,
274         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
275         .gpio_card_detect = EXT_GPIO(30),
276         .gpio_card_ro   = EXT_GPIO(31),
277         .gpio_power     = -1,
278 };
279
280 static struct gpiod_lookup_table zylonite_mci3_gpio_table = {
281         .dev_id = "pxa2xx-mci.2",
282         .table = {
283                 GPIO_LOOKUP("i2c-pca9539-a", PCA9539A_MCI3_CD,
284                             "cd", GPIO_ACTIVE_LOW),
285                 GPIO_LOOKUP("i2c-pca9539-a", PCA9539A_MCI3_WP,
286                             "wp", GPIO_ACTIVE_LOW),
287                 { },
288         },
289 };
290
291 static void __init zylonite_init_mmc(void)
292 {
293         gpiod_add_lookup_table(&zylonite_mci_gpio_table);
294         pxa_set_mci_info(&zylonite_mci_platform_data);
295         gpiod_add_lookup_table(&zylonite_mci2_gpio_table);
296         pxa3xx_set_mci2_info(&zylonite_mci2_platform_data);
297         if (cpu_is_pxa310()) {
298                 gpiod_add_lookup_table(&zylonite_mci3_gpio_table);
299                 pxa3xx_set_mci3_info(&zylonite_mci3_platform_data);
300         }
301 }
302 #else
303 static inline void zylonite_init_mmc(void) {}
304 #endif
305
306 #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
307 static const unsigned int zylonite_matrix_key_map[] = {
308         /* KEY(row, col, key_code) */
309         KEY(0, 0, KEY_A), KEY(0, 1, KEY_B), KEY(0, 2, KEY_C), KEY(0, 5, KEY_D),
310         KEY(1, 0, KEY_E), KEY(1, 1, KEY_F), KEY(1, 2, KEY_G), KEY(1, 5, KEY_H),
311         KEY(2, 0, KEY_I), KEY(2, 1, KEY_J), KEY(2, 2, KEY_K), KEY(2, 5, KEY_L),
312         KEY(3, 0, KEY_M), KEY(3, 1, KEY_N), KEY(3, 2, KEY_O), KEY(3, 5, KEY_P),
313         KEY(5, 0, KEY_Q), KEY(5, 1, KEY_R), KEY(5, 2, KEY_S), KEY(5, 5, KEY_T),
314         KEY(6, 0, KEY_U), KEY(6, 1, KEY_V), KEY(6, 2, KEY_W), KEY(6, 5, KEY_X),
315         KEY(7, 1, KEY_Y), KEY(7, 2, KEY_Z),
316
317         KEY(4, 4, KEY_0), KEY(1, 3, KEY_1), KEY(4, 1, KEY_2), KEY(1, 4, KEY_3),
318         KEY(2, 3, KEY_4), KEY(4, 2, KEY_5), KEY(2, 4, KEY_6), KEY(3, 3, KEY_7),
319         KEY(4, 3, KEY_8), KEY(3, 4, KEY_9),
320
321         KEY(4, 5, KEY_SPACE),
322         KEY(5, 3, KEY_KPASTERISK),      /* * */
323         KEY(5, 4, KEY_KPDOT),           /* #" */
324
325         KEY(0, 7, KEY_UP),
326         KEY(1, 7, KEY_DOWN),
327         KEY(2, 7, KEY_LEFT),
328         KEY(3, 7, KEY_RIGHT),
329         KEY(2, 6, KEY_HOME),
330         KEY(3, 6, KEY_END),
331         KEY(6, 4, KEY_DELETE),
332         KEY(6, 6, KEY_BACK),
333         KEY(6, 3, KEY_CAPSLOCK),        /* KEY_LEFTSHIFT), */
334
335         KEY(4, 6, KEY_ENTER),           /* scroll push */
336         KEY(5, 7, KEY_ENTER),           /* keypad action */
337
338         KEY(0, 4, KEY_EMAIL),
339         KEY(5, 6, KEY_SEND),
340         KEY(4, 0, KEY_CALENDAR),
341         KEY(7, 6, KEY_RECORD),
342         KEY(6, 7, KEY_VOLUMEUP),
343         KEY(7, 7, KEY_VOLUMEDOWN),
344
345         KEY(0, 6, KEY_F22),     /* soft1 */
346         KEY(1, 6, KEY_F23),     /* soft2 */
347         KEY(0, 3, KEY_AUX),     /* contact */
348 };
349
350 static struct matrix_keymap_data zylonite_matrix_keymap_data = {
351         .keymap                 = zylonite_matrix_key_map,
352         .keymap_size            = ARRAY_SIZE(zylonite_matrix_key_map),
353 };
354
355 static struct pxa27x_keypad_platform_data zylonite_keypad_info = {
356         .matrix_key_rows        = 8,
357         .matrix_key_cols        = 8,
358         .matrix_keymap_data     = &zylonite_matrix_keymap_data,
359
360         .enable_rotary0         = 1,
361         .rotary0_up_key         = KEY_UP,
362         .rotary0_down_key       = KEY_DOWN,
363
364         .debounce_interval      = 30,
365 };
366
367 static void __init zylonite_init_keypad(void)
368 {
369         pxa_set_keypad_info(&zylonite_keypad_info);
370 }
371 #else
372 static inline void zylonite_init_keypad(void) {}
373 #endif
374
375 #if IS_ENABLED(CONFIG_MTD_NAND_MARVELL)
376 static struct mtd_partition zylonite_nand_partitions[] = {
377         [0] = {
378                 .name        = "Bootloader",
379                 .offset      = 0,
380                 .size        = 0x060000,
381                 .mask_flags  = MTD_WRITEABLE, /* force read-only */
382         },
383         [1] = {
384                 .name        = "Kernel",
385                 .offset      = 0x060000,
386                 .size        = 0x200000,
387                 .mask_flags  = MTD_WRITEABLE, /* force read-only */
388         },
389         [2] = {
390                 .name        = "Filesystem",
391                 .offset      = 0x0260000,
392                 .size        = 0x3000000,     /* 48M - rootfs */
393         },
394         [3] = {
395                 .name        = "MassStorage",
396                 .offset      = 0x3260000,
397                 .size        = 0x3d40000,
398         },
399         [4] = {
400                 .name        = "BBT",
401                 .offset      = 0x6FA0000,
402                 .size        = 0x80000,
403                 .mask_flags  = MTD_WRITEABLE,  /* force read-only */
404         },
405         /* NOTE: we reserve some blocks at the end of the NAND flash for
406          * bad block management, and the max number of relocation blocks
407          * differs on different platforms. Please take care with it when
408          * defining the partition table.
409          */
410 };
411
412 static struct pxa3xx_nand_platform_data zylonite_nand_info = {
413         .parts          = zylonite_nand_partitions,
414         .nr_parts       = ARRAY_SIZE(zylonite_nand_partitions),
415 };
416
417 static void __init zylonite_init_nand(void)
418 {
419         pxa3xx_set_nand_info(&zylonite_nand_info);
420 }
421 #else
422 static inline void zylonite_init_nand(void) {}
423 #endif /* IS_ENABLED(CONFIG_MTD_NAND_MARVELL) */
424
425 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
426 static struct pxaohci_platform_data zylonite_ohci_info = {
427         .port_mode      = PMM_PERPORT_MODE,
428         .flags          = ENABLE_PORT1 | ENABLE_PORT2 |
429                           POWER_CONTROL_LOW | POWER_SENSE_LOW,
430 };
431
432 static void __init zylonite_init_ohci(void)
433 {
434         pxa_set_ohci_info(&zylonite_ohci_info);
435 }
436 #else
437 static inline void zylonite_init_ohci(void) {}
438 #endif /* CONFIG_USB_OHCI_HCD || CONFIG_USB_OHCI_HCD_MODULE */
439
440 static void __init zylonite_init(void)
441 {
442         pxa_set_ffuart_info(NULL);
443         pxa_set_btuart_info(NULL);
444         pxa_set_stuart_info(NULL);
445
446         /* board-processor specific initialization */
447         zylonite_pxa300_init();
448         zylonite_pxa320_init();
449
450         /*
451          * Note: We depend that the bootloader set
452          * the correct value to MSC register for SMC91x.
453          */
454         smc91x_resources[1].start = PXA_GPIO_TO_IRQ(gpio_eth_irq);
455         smc91x_resources[1].end   = PXA_GPIO_TO_IRQ(gpio_eth_irq);
456         platform_device_register(&smc91x_device);
457
458         pxa_set_ac97_info(NULL);
459         zylonite_init_lcd();
460         zylonite_init_mmc();
461         zylonite_init_keypad();
462         zylonite_init_nand();
463         zylonite_init_leds();
464         zylonite_init_ohci();
465 }
466
467 MACHINE_START(ZYLONITE, "PXA3xx Platform Development Kit (aka Zylonite)")
468         .atag_offset    = 0x100,
469         .map_io         = pxa3xx_map_io,
470         .nr_irqs        = ZYLONITE_NR_IRQS,
471         .init_irq       = pxa3xx_init_irq,
472         .handle_irq     = pxa3xx_handle_irq,
473         .init_time      = pxa_timer_init,
474         .init_machine   = zylonite_init,
475         .restart        = pxa_restart,
476 MACHINE_END