[xburst] Add 2.6.35 patches
[openwrt/svn-archive/archive.git] / target / linux / xburst / patches-2.6.35 / 020-add-qi_lb60-board-support.patch
1 From e0548316a6aa5b9fa0df8126a4f0f749fdc5176a Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 17 Jul 2010 11:16:29 +0000
4 Subject: [PATCH] MIPS: JZ4740: Add qi_lb60 board support
5
6 Add support for the qi_lb60 (a.k.a QI Ben NanoNote) clamshell device.
7
8 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
9 Cc: linux-mips@linux-mips.org
10 Cc: linux-kernel@vger.kernel.org
11 Patchwork: https://patchwork.linux-mips.org/patch/1472/
12 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
13 ---
14 arch/mips/jz4740/Kconfig | 4 +
15 arch/mips/jz4740/Makefile | 2 +
16 arch/mips/jz4740/board-qi_lb60.c | 495 ++++++++++++++++++++++++++++++++++++++
17 3 files changed, 501 insertions(+), 0 deletions(-)
18 create mode 100644 arch/mips/jz4740/board-qi_lb60.c
19
20 diff --git a/arch/mips/jz4740/Kconfig b/arch/mips/jz4740/Kconfig
21 index 8a5e850..3e7141f 100644
22 --- a/arch/mips/jz4740/Kconfig
23 +++ b/arch/mips/jz4740/Kconfig
24 @@ -1,6 +1,10 @@
25 choice
26 prompt "Machine type"
27 depends on MACH_JZ4740
28 + default JZ4740_QI_LB60
29 +
30 +config JZ4740_QI_LB60
31 + bool "Qi Hardware Ben NanoNote"
32
33 endchoice
34
35 diff --git a/arch/mips/jz4740/Makefile b/arch/mips/jz4740/Makefile
36 index a803ccb..a604eae 100644
37 --- a/arch/mips/jz4740/Makefile
38 +++ b/arch/mips/jz4740/Makefile
39 @@ -11,6 +11,8 @@ obj-$(CONFIG_DEBUG_FS) += clock-debugfs.o
40
41 # board specific support
42
43 +obj-$(CONFIG_JZ4740_QI_LB60) += board-qi_lb60.o
44 +
45 # PM support
46
47 obj-$(CONFIG_PM) += pm.o
48 diff --git a/arch/mips/jz4740/board-qi_lb60.c b/arch/mips/jz4740/board-qi_lb60.c
49 new file mode 100644
50 index 0000000..d19732a
51 --- /dev/null
52 +++ b/arch/mips/jz4740/board-qi_lb60.c
53 @@ -0,0 +1,495 @@
54 +/*
55 + * linux/arch/mips/jz4740/board-qi_lb60.c
56 + *
57 + * QI_LB60 board support
58 + *
59 + * Copyright (c) 2009 Qi Hardware inc.,
60 + * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
61 + * Copyright 2010, Lars-Petrer Clausen <lars@metafoo.de>
62 + *
63 + * This program is free software; you can redistribute it and/or modify
64 + * it under the terms of the GNU General Public License version 2 or later
65 + * as published by the Free Software Foundation.
66 + */
67 +
68 +#include <linux/kernel.h>
69 +#include <linux/init.h>
70 +#include <linux/gpio.h>
71 +
72 +#include <linux/input.h>
73 +#include <linux/gpio_keys.h>
74 +#include <linux/input/matrix_keypad.h>
75 +#include <linux/spi/spi.h>
76 +#include <linux/spi/spi_gpio.h>
77 +#include <linux/power_supply.h>
78 +#include <linux/power/jz4740-battery.h>
79 +#include <linux/power/gpio-charger.h>
80 +
81 +#include <asm/mach-jz4740/jz4740_fb.h>
82 +#include <asm/mach-jz4740/jz4740_mmc.h>
83 +#include <asm/mach-jz4740/jz4740_nand.h>
84 +
85 +#include <linux/regulator/fixed.h>
86 +#include <linux/regulator/machine.h>
87 +
88 +#include <linux/leds_pwm.h>
89 +
90 +#include <asm/mach-jz4740/platform.h>
91 +
92 +#include "clock.h"
93 +
94 +static bool is_avt2;
95 +
96 +/* GPIOs */
97 +#define QI_LB60_GPIO_SD_CD JZ_GPIO_PORTD(0)
98 +#define QI_LB60_GPIO_SD_VCC_EN_N JZ_GPIO_PORTD(2)
99 +
100 +#define QI_LB60_GPIO_KEYOUT(x) (JZ_GPIO_PORTC(10) + (x))
101 +#define QI_LB60_GPIO_KEYIN(x) (JZ_GPIO_PORTD(18) + (x))
102 +#define QI_LB60_GPIO_KEYIN8 JZ_GPIO_PORTD(26)
103 +
104 +/* NAND */
105 +static struct nand_ecclayout qi_lb60_ecclayout_1gb = {
106 +/* .eccbytes = 36,
107 + .eccpos = {
108 + 6, 7, 8, 9, 10, 11, 12, 13,
109 + 14, 15, 16, 17, 18, 19, 20, 21,
110 + 22, 23, 24, 25, 26, 27, 28, 29,
111 + 30, 31, 32, 33, 34, 35, 36, 37,
112 + 38, 39, 40, 41
113 + },*/
114 + .oobfree = {
115 + { .offset = 2, .length = 4 },
116 + { .offset = 42, .length = 22 }
117 + },
118 +};
119 +
120 +/* Early prototypes of the QI LB60 had only 1GB of NAND.
121 + * In order to support these devices aswell the partition and ecc layout is
122 + * initalized depending on the NAND size */
123 +static struct mtd_partition qi_lb60_partitions_1gb[] = {
124 + {
125 + .name = "NAND BOOT partition",
126 + .offset = 0 * 0x100000,
127 + .size = 4 * 0x100000,
128 + },
129 + {
130 + .name = "NAND KERNEL partition",
131 + .offset = 4 * 0x100000,
132 + .size = 4 * 0x100000,
133 + },
134 + {
135 + .name = "NAND ROOTFS partition",
136 + .offset = 8 * 0x100000,
137 + .size = (504 + 512) * 0x100000,
138 + },
139 +};
140 +
141 +static struct nand_ecclayout qi_lb60_ecclayout_2gb = {
142 +/* .eccbytes = 72,
143 + .eccpos = {
144 + 12, 13, 14, 15, 16, 17, 18, 19,
145 + 20, 21, 22, 23, 24, 25, 26, 27,
146 + 28, 29, 30, 31, 32, 33, 34, 35,
147 + 36, 37, 38, 39, 40, 41, 42, 43,
148 + 44, 45, 46, 47, 48, 49, 50, 51,
149 + 52, 53, 54, 55, 56, 57, 58, 59,
150 + 60, 61, 62, 63, 64, 65, 66, 67,
151 + 68, 69, 70, 71, 72, 73, 74, 75,
152 + 76, 77, 78, 79, 80, 81, 82, 83
153 + },*/
154 + .oobfree = {
155 + { .offset = 2, .length = 10 },
156 + { .offset = 84, .length = 44 },
157 + },
158 +};
159 +
160 +static struct mtd_partition qi_lb60_partitions_2gb[] = {
161 + {
162 + .name = "NAND BOOT partition",
163 + .offset = 0 * 0x100000,
164 + .size = 4 * 0x100000,
165 + },
166 + {
167 + .name = "NAND KERNEL partition",
168 + .offset = 4 * 0x100000,
169 + .size = 4 * 0x100000,
170 + },
171 + {
172 + .name = "NAND ROOTFS partition",
173 + .offset = 8 * 0x100000,
174 + .size = (504 + 512 + 1024) * 0x100000,
175 + },
176 +};
177 +
178 +static void qi_lb60_nand_ident(struct platform_device *pdev,
179 + struct nand_chip *chip, struct mtd_partition **partitions,
180 + int *num_partitions)
181 +{
182 + if (chip->page_shift == 12) {
183 + chip->ecc.layout = &qi_lb60_ecclayout_2gb;
184 + *partitions = qi_lb60_partitions_2gb;
185 + *num_partitions = ARRAY_SIZE(qi_lb60_partitions_2gb);
186 + } else {
187 + chip->ecc.layout = &qi_lb60_ecclayout_1gb;
188 + *partitions = qi_lb60_partitions_1gb;
189 + *num_partitions = ARRAY_SIZE(qi_lb60_partitions_1gb);
190 + }
191 +}
192 +
193 +static struct jz_nand_platform_data qi_lb60_nand_pdata = {
194 + .ident_callback = qi_lb60_nand_ident,
195 + .busy_gpio = 94,
196 +};
197 +
198 +/* Keyboard*/
199 +
200 +#define KEY_QI_QI KEY_F13
201 +#define KEY_QI_UPRED KEY_RIGHTALT
202 +#define KEY_QI_VOLUP KEY_VOLUMEUP
203 +#define KEY_QI_VOLDOWN KEY_VOLUMEDOWN
204 +#define KEY_QI_FN KEY_LEFTCTRL
205 +
206 +static const uint32_t qi_lb60_keymap[] = {
207 + KEY(0, 0, KEY_F1), /* S2 */
208 + KEY(0, 1, KEY_F2), /* S3 */
209 + KEY(0, 2, KEY_F3), /* S4 */
210 + KEY(0, 3, KEY_F4), /* S5 */
211 + KEY(0, 4, KEY_F5), /* S6 */
212 + KEY(0, 5, KEY_F6), /* S7 */
213 + KEY(0, 6, KEY_F7), /* S8 */
214 +
215 + KEY(1, 0, KEY_Q), /* S10 */
216 + KEY(1, 1, KEY_W), /* S11 */
217 + KEY(1, 2, KEY_E), /* S12 */
218 + KEY(1, 3, KEY_R), /* S13 */
219 + KEY(1, 4, KEY_T), /* S14 */
220 + KEY(1, 5, KEY_Y), /* S15 */
221 + KEY(1, 6, KEY_U), /* S16 */
222 + KEY(1, 7, KEY_I), /* S17 */
223 + KEY(2, 0, KEY_A), /* S18 */
224 + KEY(2, 1, KEY_S), /* S19 */
225 + KEY(2, 2, KEY_D), /* S20 */
226 + KEY(2, 3, KEY_F), /* S21 */
227 + KEY(2, 4, KEY_G), /* S22 */
228 + KEY(2, 5, KEY_H), /* S23 */
229 + KEY(2, 6, KEY_J), /* S24 */
230 + KEY(2, 7, KEY_K), /* S25 */
231 + KEY(3, 0, KEY_ESC), /* S26 */
232 + KEY(3, 1, KEY_Z), /* S27 */
233 + KEY(3, 2, KEY_X), /* S28 */
234 + KEY(3, 3, KEY_C), /* S29 */
235 + KEY(3, 4, KEY_V), /* S30 */
236 + KEY(3, 5, KEY_B), /* S31 */
237 + KEY(3, 6, KEY_N), /* S32 */
238 + KEY(3, 7, KEY_M), /* S33 */
239 + KEY(4, 0, KEY_TAB), /* S34 */
240 + KEY(4, 1, KEY_CAPSLOCK), /* S35 */
241 + KEY(4, 2, KEY_BACKSLASH), /* S36 */
242 + KEY(4, 3, KEY_APOSTROPHE), /* S37 */
243 + KEY(4, 4, KEY_COMMA), /* S38 */
244 + KEY(4, 5, KEY_DOT), /* S39 */
245 + KEY(4, 6, KEY_SLASH), /* S40 */
246 + KEY(4, 7, KEY_UP), /* S41 */
247 + KEY(5, 0, KEY_O), /* S42 */
248 + KEY(5, 1, KEY_L), /* S43 */
249 + KEY(5, 2, KEY_EQUAL), /* S44 */
250 + KEY(5, 3, KEY_QI_UPRED), /* S45 */
251 + KEY(5, 4, KEY_SPACE), /* S46 */
252 + KEY(5, 5, KEY_QI_QI), /* S47 */
253 + KEY(5, 6, KEY_RIGHTCTRL), /* S48 */
254 + KEY(5, 7, KEY_LEFT), /* S49 */
255 + KEY(6, 0, KEY_F8), /* S50 */
256 + KEY(6, 1, KEY_P), /* S51 */
257 + KEY(6, 2, KEY_BACKSPACE),/* S52 */
258 + KEY(6, 3, KEY_ENTER), /* S53 */
259 + KEY(6, 4, KEY_QI_VOLUP), /* S54 */
260 + KEY(6, 5, KEY_QI_VOLDOWN), /* S55 */
261 + KEY(6, 6, KEY_DOWN), /* S56 */
262 + KEY(6, 7, KEY_RIGHT), /* S57 */
263 +
264 + KEY(7, 0, KEY_LEFTSHIFT), /* S58 */
265 + KEY(7, 1, KEY_LEFTALT), /* S59 */
266 + KEY(7, 2, KEY_QI_FN), /* S60 */
267 +};
268 +
269 +static const struct matrix_keymap_data qi_lb60_keymap_data = {
270 + .keymap = qi_lb60_keymap,
271 + .keymap_size = ARRAY_SIZE(qi_lb60_keymap),
272 +};
273 +
274 +static const unsigned int qi_lb60_keypad_cols[] = {
275 + QI_LB60_GPIO_KEYOUT(0),
276 + QI_LB60_GPIO_KEYOUT(1),
277 + QI_LB60_GPIO_KEYOUT(2),
278 + QI_LB60_GPIO_KEYOUT(3),
279 + QI_LB60_GPIO_KEYOUT(4),
280 + QI_LB60_GPIO_KEYOUT(5),
281 + QI_LB60_GPIO_KEYOUT(6),
282 + QI_LB60_GPIO_KEYOUT(7),
283 +};
284 +
285 +static const unsigned int qi_lb60_keypad_rows[] = {
286 + QI_LB60_GPIO_KEYIN(0),
287 + QI_LB60_GPIO_KEYIN(1),
288 + QI_LB60_GPIO_KEYIN(2),
289 + QI_LB60_GPIO_KEYIN(3),
290 + QI_LB60_GPIO_KEYIN(4),
291 + QI_LB60_GPIO_KEYIN(5),
292 + QI_LB60_GPIO_KEYIN(7),
293 + QI_LB60_GPIO_KEYIN8,
294 +};
295 +
296 +static struct matrix_keypad_platform_data qi_lb60_pdata = {
297 + .keymap_data = &qi_lb60_keymap_data,
298 + .col_gpios = qi_lb60_keypad_cols,
299 + .row_gpios = qi_lb60_keypad_rows,
300 + .num_col_gpios = ARRAY_SIZE(qi_lb60_keypad_cols),
301 + .num_row_gpios = ARRAY_SIZE(qi_lb60_keypad_rows),
302 + .col_scan_delay_us = 10,
303 + .debounce_ms = 10,
304 + .wakeup = 1,
305 + .active_low = 1,
306 +};
307 +
308 +static struct platform_device qi_lb60_keypad = {
309 + .name = "matrix-keypad",
310 + .id = -1,
311 + .dev = {
312 + .platform_data = &qi_lb60_pdata,
313 + },
314 +};
315 +
316 +/* Display */
317 +static struct fb_videomode qi_lb60_video_modes[] = {
318 + {
319 + .name = "320x240",
320 + .xres = 320,
321 + .yres = 240,
322 + .refresh = 30,
323 + .left_margin = 140,
324 + .right_margin = 273,
325 + .upper_margin = 20,
326 + .lower_margin = 2,
327 + .hsync_len = 1,
328 + .vsync_len = 1,
329 + .sync = 0,
330 + .vmode = FB_VMODE_NONINTERLACED,
331 + },
332 +};
333 +
334 +static struct jz4740_fb_platform_data qi_lb60_fb_pdata = {
335 + .width = 60,
336 + .height = 45,
337 + .num_modes = ARRAY_SIZE(qi_lb60_video_modes),
338 + .modes = qi_lb60_video_modes,
339 + .bpp = 24,
340 + .lcd_type = JZ_LCD_TYPE_8BIT_SERIAL,
341 + .pixclk_falling_edge = 1,
342 +};
343 +
344 +struct spi_gpio_platform_data spigpio_platform_data = {
345 + .sck = JZ_GPIO_PORTC(23),
346 + .mosi = JZ_GPIO_PORTC(22),
347 + .miso = -1,
348 + .num_chipselect = 1,
349 +};
350 +
351 +static struct platform_device spigpio_device = {
352 + .name = "spi_gpio",
353 + .id = 1,
354 + .dev = {
355 + .platform_data = &spigpio_platform_data,
356 + },
357 +};
358 +
359 +static struct spi_board_info qi_lb60_spi_board_info[] = {
360 + {
361 + .modalias = "ili8960",
362 + .controller_data = (void *)JZ_GPIO_PORTC(21),
363 + .chip_select = 0,
364 + .bus_num = 1,
365 + .max_speed_hz = 30 * 1000,
366 + .mode = SPI_3WIRE,
367 + },
368 +};
369 +
370 +/* Battery */
371 +static struct jz_battery_platform_data qi_lb60_battery_pdata = {
372 + .gpio_charge = JZ_GPIO_PORTC(27),
373 + .gpio_charge_active_low = 1,
374 + .info = {
375 + .name = "battery",
376 + .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
377 + .voltage_max_design = 4200000,
378 + .voltage_min_design = 3600000,
379 + },
380 +};
381 +
382 +/* GPIO Key: power */
383 +static struct gpio_keys_button qi_lb60_gpio_keys_buttons[] = {
384 + [0] = {
385 + .code = KEY_POWER,
386 + .gpio = JZ_GPIO_PORTD(29),
387 + .active_low = 1,
388 + .desc = "Power",
389 + .wakeup = 1,
390 + },
391 +};
392 +
393 +static struct gpio_keys_platform_data qi_lb60_gpio_keys_data = {
394 + .nbuttons = ARRAY_SIZE(qi_lb60_gpio_keys_buttons),
395 + .buttons = qi_lb60_gpio_keys_buttons,
396 +};
397 +
398 +static struct platform_device qi_lb60_gpio_keys = {
399 + .name = "gpio-keys",
400 + .id = -1,
401 + .dev = {
402 + .platform_data = &qi_lb60_gpio_keys_data,
403 + }
404 +};
405 +
406 +static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = {
407 + .gpio_card_detect = QI_LB60_GPIO_SD_CD,
408 + .gpio_read_only = -1,
409 + .gpio_power = QI_LB60_GPIO_SD_VCC_EN_N,
410 + .power_active_low = 1,
411 +};
412 +
413 +/* OHCI */
414 +static struct regulator_consumer_supply avt2_usb_regulator_consumer =
415 + REGULATOR_SUPPLY("vbus", "jz4740-ohci");
416 +
417 +static struct regulator_init_data avt2_usb_regulator_init_data = {
418 + .num_consumer_supplies = 1,
419 + .consumer_supplies = &avt2_usb_regulator_consumer,
420 + .constraints = {
421 + .name = "USB power",
422 + .min_uV = 5000000,
423 + .max_uV = 5000000,
424 + .valid_modes_mask = REGULATOR_MODE_NORMAL,
425 + .valid_ops_mask = REGULATOR_CHANGE_STATUS,
426 + },
427 +};
428 +
429 +static struct fixed_voltage_config avt2_usb_regulator_data = {
430 + .supply_name = "USB power",
431 + .microvolts = 5000000,
432 + .gpio = JZ_GPIO_PORTB(17),
433 + .init_data = &avt2_usb_regulator_init_data,
434 +};
435 +
436 +static struct platform_device avt2_usb_regulator_device = {
437 + .name = "reg-fixed-voltage",
438 + .id = -1,
439 + .dev = {
440 + .platform_data = &avt2_usb_regulator_data,
441 + }
442 +};
443 +
444 +/* beeper */
445 +static struct platform_device qi_lb60_pwm_beeper = {
446 + .name = "pwm-beeper",
447 + .id = -1,
448 + .dev = {
449 + .platform_data = (void *)4,
450 + },
451 +};
452 +
453 +/* charger */
454 +static char *qi_lb60_batteries[] = {
455 + "battery",
456 +};
457 +
458 +static struct gpio_charger_platform_data qi_lb60_charger_pdata = {
459 + .name = "usb",
460 + .type = POWER_SUPPLY_TYPE_USB,
461 + .gpio = JZ_GPIO_PORTD(28),
462 + .gpio_active_low = 1,
463 + .batteries = qi_lb60_batteries,
464 + .num_batteries = ARRAY_SIZE(qi_lb60_batteries),
465 +};
466 +
467 +static struct platform_device qi_lb60_charger_device = {
468 + .name = "gpio-charger",
469 + .dev = {
470 + .platform_data = &qi_lb60_charger_pdata,
471 + },
472 +};
473 +
474 +
475 +static struct platform_device *jz_platform_devices[] __initdata = {
476 + &jz4740_udc_device,
477 + &jz4740_mmc_device,
478 + &jz4740_nand_device,
479 + &qi_lb60_keypad,
480 + &spigpio_device,
481 + &jz4740_framebuffer_device,
482 + &jz4740_pcm_device,
483 + &jz4740_i2s_device,
484 + &jz4740_codec_device,
485 + &jz4740_rtc_device,
486 + &jz4740_adc_device,
487 + &qi_lb60_gpio_keys,
488 + &qi_lb60_pwm_beeper,
489 + &qi_lb60_charger_device,
490 +};
491 +
492 +static void __init board_gpio_setup(void)
493 +{
494 + /* We only need to enable/disable pullup here for pins used in generic
495 + * drivers. Everything else is done by the drivers themselfs. */
496 + jz_gpio_disable_pullup(QI_LB60_GPIO_SD_VCC_EN_N);
497 + jz_gpio_disable_pullup(QI_LB60_GPIO_SD_CD);
498 +}
499 +
500 +static int __init qi_lb60_init_platform_devices(void)
501 +{
502 + jz4740_framebuffer_device.dev.platform_data = &qi_lb60_fb_pdata;
503 + jz4740_nand_device.dev.platform_data = &qi_lb60_nand_pdata;
504 + jz4740_adc_device.dev.platform_data = &qi_lb60_battery_pdata;
505 + jz4740_mmc_device.dev.platform_data = &qi_lb60_mmc_pdata;
506 +
507 + jz4740_serial_device_register();
508 +
509 + spi_register_board_info(qi_lb60_spi_board_info,
510 + ARRAY_SIZE(qi_lb60_spi_board_info));
511 +
512 + if (is_avt2) {
513 + platform_device_register(&avt2_usb_regulator_device);
514 + platform_device_register(&jz4740_usb_ohci_device);
515 + }
516 +
517 + return platform_add_devices(jz_platform_devices,
518 + ARRAY_SIZE(jz_platform_devices));
519 +
520 +}
521 +
522 +struct jz4740_clock_board_data jz4740_clock_bdata = {
523 + .ext_rate = 12000000,
524 + .rtc_rate = 32768,
525 +};
526 +
527 +static __init int board_avt2(char *str)
528 +{
529 + qi_lb60_mmc_pdata.card_detect_active_low = 1;
530 + is_avt2 = true;
531 +
532 + return 1;
533 +}
534 +__setup("avt2", board_avt2);
535 +
536 +static int __init qi_lb60_board_setup(void)
537 +{
538 + printk(KERN_INFO "Qi Hardware JZ4740 QI %s setup\n",
539 + is_avt2 ? "AVT2" : "LB60");
540 +
541 + board_gpio_setup();
542 +
543 + if (qi_lb60_init_platform_devices())
544 + panic("Failed to initalize platform devices\n");
545 +
546 + return 0;
547 +}
548 +arch_initcall(qi_lb60_board_setup);
549 --
550 1.5.6.5
551