board-qi_lb60: Fix battery platform data.
[librecmc/librecmc.git] / target / linux / xburst / files-2.6.32 / arch / mips / jz4740 / board-qi_lb60.c
1 /*
2  * linux/arch/mips/jz4740/board-qi_lb60.c
3  *
4  * QI_LB60 setup routines.
5  *
6  * Copyright (c) 2009 Qi Hardware inc.,
7  * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 or later
11  * as published by the Free Software Foundation.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/gpio.h>
17
18 #include <asm/mach-jz4740/board-qi_lb60.h>
19 #include <asm/mach-jz4740/platform.h>
20
21 #include <linux/input.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/mtd/jz4740_nand.h>
24 #include <linux/jz4740_fb.h>
25 #include <linux/input/matrix_keypad.h>
26 #include <linux/mtd/jz4740_nand.h>
27 #include <linux/spi/spi.h>
28 #include <linux/spi/spi_gpio.h>
29 #include <linux/power_supply.h>
30 #include <linux/power/jz4740-battery.h>
31 #include <linux/power/gpio-charger.h>
32 #include <linux/mmc/jz4740_mmc.h>
33
34
35 /* NAND */
36 static struct nand_ecclayout qi_lb60_ecclayout_1gb = {
37         .eccbytes = 36,
38         .eccpos = {
39                 6,  7,  8,  9,  10, 11, 12, 13,
40                 14, 15, 16, 17, 18, 19, 20, 21,
41                 22, 23, 24, 25, 26, 27, 28, 29,
42                 30, 31, 32, 33, 34, 35, 36, 37,
43                 38, 39, 40, 41},
44         .oobfree = {
45                 {.offset = 2,
46                  .length = 4},
47                 {.offset = 42,
48                  .length = 22}}
49 };
50
51 static struct mtd_partition qi_lb60_partitions_1gb[] = {
52         { .name = "NAND BOOT partition",
53           .offset = 0 * 0x100000,
54           .size = 4 * 0x100000,
55         },
56         { .name = "NAND KERNEL partition",
57           .offset = 4 * 0x100000,
58           .size = 4 * 0x100000,
59         },
60         { .name = "NAND ROOTFS partition",
61           .offset = 8 * 0x100000,
62           .size = (504 + 512) * 0x100000,
63         },
64 };
65
66 static struct nand_ecclayout qi_lb60_ecclayout_2gb = {
67         .eccbytes = 72,
68         .eccpos = {
69                 12, 13, 14, 15, 16, 17, 18, 19,
70                 20, 21, 22, 23, 24, 25, 26, 27, 
71                 28, 29, 30, 31, 32, 33, 34, 35,
72                 36, 37, 38, 39, 40, 41, 42, 43,
73                 44, 45, 46, 47, 48, 49, 50, 51, 
74                 52, 53, 54, 55, 56, 57, 58, 59, 
75                 60, 61, 62, 63, 64, 65, 66, 67, 
76                 68, 69, 70, 71, 72, 73, 74, 75, 
77                 76, 77, 78, 79, 80, 81, 82, 83},
78         .oobfree = {
79                 {.offset = 2,
80                  .length = 10},
81                 {.offset = 84,
82                  .length = 44}}
83 };
84
85 static struct mtd_partition qi_lb60_partitions_2gb[] = {
86         { .name = "NAND BOOT partition",
87           .offset = 0 * 0x100000,
88           .size = 4 * 0x100000,
89         },
90         { .name = "NAND KERNEL partition",
91           .offset = 4 * 0x100000,
92           .size = 4 * 0x100000,
93         },
94         { .name = "NAND ROOTFS partition",
95           .offset = 8 * 0x100000,
96           .size = (504 + 512 + 1024) * 0x100000,
97         },
98 };
99
100 static void qi_lb60_nand_ident(struct platform_device *pdev,
101                                 struct nand_chip *chip, 
102                                 struct mtd_partition **partitions,
103                                 int *num_partitions)
104 {
105         if (chip->page_shift == 12) {
106                 chip->ecc.layout = &qi_lb60_ecclayout_2gb;
107                 *partitions = qi_lb60_partitions_2gb;
108                 *num_partitions = ARRAY_SIZE(qi_lb60_partitions_2gb);
109         } else {
110                 chip->ecc.layout = &qi_lb60_ecclayout_1gb;
111                 *partitions = qi_lb60_partitions_1gb;
112                 *num_partitions = ARRAY_SIZE(qi_lb60_partitions_1gb);
113         }
114 }
115
116 static struct jz_nand_platform_data qi_lb60_nand_pdata = {
117         .ident_callback = qi_lb60_nand_ident,
118         .busy_gpio = 94,
119 };
120
121
122 /* Keyboard*/
123
124 /* #define KEEP_UART_ALIVE
125  * don't define this. the keyboard and keyboard both work
126  */
127
128 #define KEY_QI_QI       KEY_F13
129 #define KEY_QI_UPRED    KEY_RIGHTALT
130 #define KEY_QI_VOLUP    KEY_VOLUMEUP
131 #define KEY_QI_VOLDOWN  KEY_VOLUMEDOWN
132 #define KEY_QI_FN       KEY_LEFTCTRL
133
134 static const uint32_t qi_lb60_keymap[] = {
135         KEY(0, 0, KEY_F1),      /* S2 */
136         KEY(0, 1, KEY_F2),      /* S3 */
137         KEY(0, 2, KEY_F3),      /* S4 */
138         KEY(0, 3, KEY_F4),      /* S5 */
139         KEY(0, 4, KEY_F5),      /* S6 */
140         KEY(0, 5, KEY_F6),      /* S7 */
141         KEY(0, 6, KEY_F7),      /* S8 */
142
143         KEY(1, 0, KEY_Q),       /* S10 */
144         KEY(1, 1, KEY_W),       /* S11 */
145         KEY(1, 2, KEY_E),       /* S12 */
146         KEY(1, 3, KEY_R),       /* S13 */
147         KEY(1, 4, KEY_T),       /* S14 */
148         KEY(1, 5, KEY_Y),       /* S15 */
149         KEY(1, 6, KEY_U),       /* S16 */
150         KEY(1, 7, KEY_I),       /* S17 */
151         KEY(2, 0, KEY_A),       /* S18 */
152         KEY(2, 1, KEY_S),       /* S19 */
153         KEY(2, 2, KEY_D),       /* S20 */
154         KEY(2, 3, KEY_F),       /* S21 */
155         KEY(2, 4, KEY_G),       /* S22 */
156         KEY(2, 5, KEY_H),       /* S23 */
157         KEY(2, 6, KEY_J),       /* S24 */
158         KEY(2, 7, KEY_K),       /* S25 */
159         KEY(3, 0, KEY_ESC),     /* S26 */
160         KEY(3, 1, KEY_Z),       /* S27 */
161         KEY(3, 2, KEY_X),       /* S28 */
162         KEY(3, 3, KEY_C),       /* S29 */
163         KEY(3, 4, KEY_V),       /* S30 */
164         KEY(3, 5, KEY_B),       /* S31 */
165         KEY(3, 6, KEY_N),       /* S32 */
166         KEY(3, 7, KEY_M),       /* S33 */
167         KEY(4, 0, KEY_TAB),     /* S34 */
168         KEY(4, 1, KEY_CAPSLOCK),        /* S35 */
169         KEY(4, 2, KEY_BACKSLASH),       /* S36 */
170         KEY(4, 3, KEY_APOSTROPHE),      /* S37 */
171         KEY(4, 4, KEY_COMMA),   /* S38 */
172         KEY(4, 5, KEY_DOT),     /* S39 */
173         KEY(4, 6, KEY_SLASH),   /* S40 */
174         KEY(4, 7, KEY_UP),      /* S41 */
175         KEY(5, 0, KEY_O),       /* S42 */
176         KEY(5, 1, KEY_L),       /* S43 */
177         KEY(5, 2, KEY_EQUAL),   /* S44 */
178         KEY(5, 3, KEY_QI_UPRED),        /* S45 */
179         KEY(5, 4, KEY_SPACE),   /* S46 */
180         KEY(5, 5, KEY_QI_QI),   /* S47 */
181         KEY(5, 6, KEY_RIGHTCTRL),       /* S48 */
182         KEY(5, 7, KEY_LEFT),    /* S49 */
183         KEY(6, 0, KEY_F8),      /* S50 */
184         KEY(6, 1, KEY_P),       /* S51 */
185         KEY(6, 2, KEY_BACKSPACE),/* S52 */
186         KEY(6, 3, KEY_ENTER),   /* S53 */
187         KEY(6, 4, KEY_QI_VOLUP),        /* S54 */
188         KEY(6, 5, KEY_QI_VOLDOWN),      /* S55 */
189         KEY(6, 6, KEY_DOWN),    /* S56 */
190         KEY(6, 7, KEY_RIGHT),   /* S57 */
191
192 #ifndef KEEP_UART_ALIVE
193         KEY(7, 0, KEY_LEFTSHIFT),       /* S58 */
194         KEY(7, 1, KEY_LEFTALT), /* S59 */
195         KEY(7, 2, KEY_QI_FN),   /* S60 */
196 #endif
197 };
198
199 static const struct matrix_keymap_data qi_lb60_keymap_data = {
200         .keymap         = qi_lb60_keymap,
201         .keymap_size    = ARRAY_SIZE(qi_lb60_keymap),
202 };
203
204 static const unsigned int qi_lb60_keypad_cols[] = {
205         74, 75, 76, 77, 78, 79, 80, 81,
206 };
207
208 static const unsigned int qi_lb60_keypad_rows[] = {
209         114, 115, 116, 117, 118, 119, 120,
210 #ifndef KEEP_UART_ALIVE
211         122,
212 #endif
213 };
214
215 static struct matrix_keypad_platform_data qi_lb60_pdata = {
216         .keymap_data = &qi_lb60_keymap_data,
217         .col_gpios      = qi_lb60_keypad_cols,
218         .row_gpios      = qi_lb60_keypad_rows,
219         .num_col_gpios  = ARRAY_SIZE(qi_lb60_keypad_cols),
220         .num_row_gpios  = ARRAY_SIZE(qi_lb60_keypad_rows),
221         .col_scan_delay_us      = 10,
222         .debounce_ms            = 10,
223         .wakeup                 = 1,
224         .active_low             = 1,
225 };
226
227 static struct platform_device qi_lb60_keypad = {
228         .name           = "matrix-keypad",
229         .id             = -1,
230         .dev            = {
231                 .platform_data = &qi_lb60_pdata,
232         },
233 };
234
235 /* Display */
236 static struct fb_videomode qi_lb60_video_modes[] = {
237         {
238                 .name = "320x240",
239                 .xres = 320,
240                 .yres = 240,
241                 .pixclock = 700000,
242                 .left_margin = 140,
243                 .right_margin = 273,
244                 .upper_margin = 20,
245                 .lower_margin = 2,
246                 .hsync_len = 1,
247                 .vsync_len = 1,
248                 .sync = 0,
249                 .vmode = FB_VMODE_NONINTERLACED,
250         },
251 };
252
253 static struct jz4740_fb_platform_data qi_lb60_fb_pdata = {
254         .width          = 60,
255         .height         = 45,
256         .num_modes      = ARRAY_SIZE(qi_lb60_video_modes),
257         .modes          = qi_lb60_video_modes,
258         .bpp            = 24,
259         .lcd_type       = JZ_LCD_TYPE_8BIT_SERIAL,
260 };
261
262
263 struct spi_gpio_platform_data spigpio_platform_data = {
264         .sck = JZ_GPIO_PORTC(23),
265         .mosi = JZ_GPIO_PORTC(22),
266         .miso = JZ_GPIO_PORTC(22),
267         .num_chipselect = 1,
268 };
269
270 static struct platform_device spigpio_device = {
271         .name = "spi_gpio",
272         .id   = 1,
273         .dev = {
274                 .platform_data = &spigpio_platform_data,
275         },
276 };
277
278 static struct spi_board_info qi_lb60_spi_board_info[] = {
279         {
280                 .modalias = "gpm940b0",
281                 .controller_data = (void*)JZ_GPIO_PORTC(21),
282                 .chip_select = 0,
283                 .bus_num = 1,
284                 .max_speed_hz = 30 * 1000,
285         },
286 };
287
288 /* Battery */
289 static struct jz_battery_platform_data qi_lb60_battery_pdata = {
290         .gpio_charge = GPIO_CHARG_STAT_N,
291         .gpio_charge_active_low = 1,
292         .info = {
293                 .name = "battery",
294                 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
295                 .voltage_max_design = 4200000,
296                 .voltage_min_design = 3600000,
297         },
298 };
299
300 static char *qi_lb60_batteries[] = {
301         "battery",
302 };
303
304 static struct gpio_charger_platform_data qi_lb60_charger_pdata = {
305         .name = "USB",
306         .type = POWER_SUPPLY_TYPE_USB,
307         .gpio = GPIO_USB_DETE,
308         .gpio_active_low = 1,
309         .batteries = qi_lb60_batteries,
310         .num_batteries = ARRAY_SIZE(qi_lb60_batteries),
311 };
312
313 static struct platform_device qi_lb60_charger_device = {
314         .name = "gpio-charger",
315         .dev = {
316                 .platform_data = &qi_lb60_charger_pdata,
317         },
318 };
319
320 /* GPIO Key: power */
321 static struct gpio_keys_button qi_lb60_gpio_keys_buttons[] = {
322         [0] = {
323                 .code           = KEY_POWER,
324                 .gpio           = GPIO_WAKEUP_N,
325                 .active_low     = 1,
326                 .desc           = "Power",
327                 .wakeup         = 1,
328         },
329 };
330
331 static struct gpio_keys_platform_data qi_lb60_gpio_keys_data = {
332         .nbuttons = ARRAY_SIZE(qi_lb60_gpio_keys_buttons),
333         .buttons = qi_lb60_gpio_keys_buttons,
334 };
335
336 static struct platform_device qi_lb60_gpio_keys = {
337         .name = "gpio-keys",
338         .id =   -1,
339         .dev = {
340                 .platform_data = &qi_lb60_gpio_keys_data,
341         }
342 };
343
344 static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = {
345         .gpio_card_detect       = JZ_GPIO_PORTD(0),
346         .gpio_read_only         = -1,
347         .gpio_power             = JZ_GPIO_PORTD(2),
348         .power_active_low       = 1,
349 };
350
351 static struct platform_device *jz_platform_devices[] __initdata = {
352         &jz4740_usb_ohci_device,
353         &jz4740_usb_gdt_device,
354         &jz4740_mmc_device,
355         &jz4740_nand_device,
356         &qi_lb60_keypad,
357         &spigpio_device,
358         &jz4740_framebuffer_device,
359         &jz4740_i2s_device,
360         &jz4740_codec_device,
361         &jz4740_rtc_device,
362         &jz4740_adc_device,
363         &jz4740_battery_device,
364         &qi_lb60_gpio_keys,
365         &qi_lb60_charger_device,
366 };
367
368 static void __init board_gpio_setup(void)
369 {
370         /* We only need to enable/disable pullup here for pins used in generic
371          * drivers. Everything else is done by the drivers themselfs. */
372         jz_gpio_disable_pullup(GPIO_SD_VCC_EN_N);
373         jz_gpio_disable_pullup(GPIO_SD_CD_N);
374 }
375
376 static int __init qi_lb60_init_platform_devices(void)
377 {
378         jz4740_framebuffer_device.dev.platform_data = &qi_lb60_fb_pdata;
379         jz4740_nand_device.dev.platform_data = &qi_lb60_nand_pdata;
380         jz4740_battery_device.dev.platform_data = &qi_lb60_battery_pdata;
381         jz4740_mmc_device.dev.platform_data = &qi_lb60_mmc_pdata;
382
383         spi_register_board_info(qi_lb60_spi_board_info,
384                                 ARRAY_SIZE(qi_lb60_spi_board_info));
385
386         return platform_add_devices(jz_platform_devices,
387                                         ARRAY_SIZE(jz_platform_devices));
388
389 }
390 extern int jz_gpiolib_init(void);
391 extern int jz_init_clocks(unsigned long extal);
392
393 static __init int board_avt2(char *str)
394 {
395         qi_lb60_mmc_pdata.card_detect_active_low = 1;
396
397         return 1;
398 }
399
400 __setup("avt2", board_avt2);
401
402 static int __init qi_lb60_board_setup(void)
403 {
404         printk("Qi Hardware JZ4740 QI_LB60 setup\n");
405         if (jz_gpiolib_init())
406                 panic("Failed to initalize jz gpio\n");
407         jz_init_clocks(12000000);
408
409         board_gpio_setup();
410
411         if (qi_lb60_init_platform_devices())
412                 panic("Failed to initalize platform devices\n");
413
414         return 0;
415 }
416
417 arch_initcall(qi_lb60_board_setup);