1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * linux/arch/mips/jz4740/board-qi_lb60.c
5 * QI_LB60 board support
7 * Copyright (c) 2009 Qi Hardware inc.,
8 * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
9 * Copyright 2010, Lars-Peter Clausen <lars@metafoo.de>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/gpio.h>
15 #include <linux/gpio/machine.h>
17 #include <linux/input.h>
18 #include <linux/gpio_keys.h>
19 #include <linux/input/matrix_keypad.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/spi_gpio.h>
22 #include <linux/pinctrl/machine.h>
23 #include <linux/pinctrl/pinconf-generic.h>
24 #include <linux/power_supply.h>
25 #include <linux/power/jz4740-battery.h>
26 #include <linux/power/gpio-charger.h>
27 #include <linux/pwm.h>
29 #include <linux/platform_data/jz4740/jz4740_nand.h>
31 #include <asm/mach-jz4740/gpio.h>
32 #include <asm/mach-jz4740/jz4740_fb.h>
33 #include <asm/mach-jz4740/jz4740_mmc.h>
35 #include <linux/regulator/fixed.h>
36 #include <linux/regulator/machine.h>
38 #include <asm/mach-jz4740/platform.h>
41 #define QI_LB60_GPIO_KEYOUT(x) (JZ_GPIO_PORTC(10) + (x))
42 #define QI_LB60_GPIO_KEYIN(x) (JZ_GPIO_PORTD(18) + (x))
43 #define QI_LB60_GPIO_KEYIN8 JZ_GPIO_PORTD(26)
47 /* Early prototypes of the QI LB60 had only 1GB of NAND.
48 * In order to support these devices as well the partition and ecc layout is
49 * initialized depending on the NAND size */
50 static struct mtd_partition qi_lb60_partitions_1gb[] = {
52 .name = "NAND BOOT partition",
53 .offset = 0 * 0x100000,
57 .name = "NAND KERNEL partition",
58 .offset = 4 * 0x100000,
62 .name = "NAND ROOTFS partition",
63 .offset = 8 * 0x100000,
64 .size = (504 + 512) * 0x100000,
68 static struct mtd_partition qi_lb60_partitions_2gb[] = {
70 .name = "NAND BOOT partition",
71 .offset = 0 * 0x100000,
75 .name = "NAND KERNEL partition",
76 .offset = 4 * 0x100000,
80 .name = "NAND ROOTFS partition",
81 .offset = 8 * 0x100000,
82 .size = (504 + 512 + 1024) * 0x100000,
86 static int qi_lb60_ooblayout_ecc(struct mtd_info *mtd, int section,
87 struct mtd_oob_region *oobregion)
92 oobregion->length = 36;
93 oobregion->offset = 6;
95 if (mtd->oobsize == 128) {
96 oobregion->length *= 2;
97 oobregion->offset *= 2;
103 static int qi_lb60_ooblayout_free(struct mtd_info *mtd, int section,
104 struct mtd_oob_region *oobregion)
106 int eccbytes = 36, eccoff = 6;
111 if (mtd->oobsize == 128) {
117 oobregion->offset = 2;
118 oobregion->length = eccoff - 2;
120 oobregion->offset = eccoff + eccbytes;
121 oobregion->length = mtd->oobsize - oobregion->offset;
127 static const struct mtd_ooblayout_ops qi_lb60_ooblayout_ops = {
128 .ecc = qi_lb60_ooblayout_ecc,
129 .free = qi_lb60_ooblayout_free,
132 static void qi_lb60_nand_ident(struct platform_device *pdev,
133 struct mtd_info *mtd, struct mtd_partition **partitions,
136 struct nand_chip *chip = mtd_to_nand(mtd);
138 if (chip->page_shift == 12) {
139 *partitions = qi_lb60_partitions_2gb;
140 *num_partitions = ARRAY_SIZE(qi_lb60_partitions_2gb);
142 *partitions = qi_lb60_partitions_1gb;
143 *num_partitions = ARRAY_SIZE(qi_lb60_partitions_1gb);
146 mtd_set_ooblayout(mtd, &qi_lb60_ooblayout_ops);
149 static struct jz_nand_platform_data qi_lb60_nand_pdata = {
150 .ident_callback = qi_lb60_nand_ident,
154 static struct gpiod_lookup_table qi_lb60_nand_gpio_table = {
155 .dev_id = "jz4740-nand.0",
157 GPIO_LOOKUP("GPIOC", 30, "busy", 0),
165 #define KEY_QI_QI KEY_F13
166 #define KEY_QI_UPRED KEY_RIGHTALT
167 #define KEY_QI_VOLUP KEY_VOLUMEUP
168 #define KEY_QI_VOLDOWN KEY_VOLUMEDOWN
169 #define KEY_QI_FN KEY_LEFTCTRL
171 static const uint32_t qi_lb60_keymap[] = {
172 KEY(0, 0, KEY_F1), /* S2 */
173 KEY(0, 1, KEY_F2), /* S3 */
174 KEY(0, 2, KEY_F3), /* S4 */
175 KEY(0, 3, KEY_F4), /* S5 */
176 KEY(0, 4, KEY_F5), /* S6 */
177 KEY(0, 5, KEY_F6), /* S7 */
178 KEY(0, 6, KEY_F7), /* S8 */
180 KEY(1, 0, KEY_Q), /* S10 */
181 KEY(1, 1, KEY_W), /* S11 */
182 KEY(1, 2, KEY_E), /* S12 */
183 KEY(1, 3, KEY_R), /* S13 */
184 KEY(1, 4, KEY_T), /* S14 */
185 KEY(1, 5, KEY_Y), /* S15 */
186 KEY(1, 6, KEY_U), /* S16 */
187 KEY(1, 7, KEY_I), /* S17 */
188 KEY(2, 0, KEY_A), /* S18 */
189 KEY(2, 1, KEY_S), /* S19 */
190 KEY(2, 2, KEY_D), /* S20 */
191 KEY(2, 3, KEY_F), /* S21 */
192 KEY(2, 4, KEY_G), /* S22 */
193 KEY(2, 5, KEY_H), /* S23 */
194 KEY(2, 6, KEY_J), /* S24 */
195 KEY(2, 7, KEY_K), /* S25 */
196 KEY(3, 0, KEY_ESC), /* S26 */
197 KEY(3, 1, KEY_Z), /* S27 */
198 KEY(3, 2, KEY_X), /* S28 */
199 KEY(3, 3, KEY_C), /* S29 */
200 KEY(3, 4, KEY_V), /* S30 */
201 KEY(3, 5, KEY_B), /* S31 */
202 KEY(3, 6, KEY_N), /* S32 */
203 KEY(3, 7, KEY_M), /* S33 */
204 KEY(4, 0, KEY_TAB), /* S34 */
205 KEY(4, 1, KEY_CAPSLOCK), /* S35 */
206 KEY(4, 2, KEY_BACKSLASH), /* S36 */
207 KEY(4, 3, KEY_APOSTROPHE), /* S37 */
208 KEY(4, 4, KEY_COMMA), /* S38 */
209 KEY(4, 5, KEY_DOT), /* S39 */
210 KEY(4, 6, KEY_SLASH), /* S40 */
211 KEY(4, 7, KEY_UP), /* S41 */
212 KEY(5, 0, KEY_O), /* S42 */
213 KEY(5, 1, KEY_L), /* S43 */
214 KEY(5, 2, KEY_EQUAL), /* S44 */
215 KEY(5, 3, KEY_QI_UPRED), /* S45 */
216 KEY(5, 4, KEY_SPACE), /* S46 */
217 KEY(5, 5, KEY_QI_QI), /* S47 */
218 KEY(5, 6, KEY_RIGHTCTRL), /* S48 */
219 KEY(5, 7, KEY_LEFT), /* S49 */
220 KEY(6, 0, KEY_F8), /* S50 */
221 KEY(6, 1, KEY_P), /* S51 */
222 KEY(6, 2, KEY_BACKSPACE),/* S52 */
223 KEY(6, 3, KEY_ENTER), /* S53 */
224 KEY(6, 4, KEY_QI_VOLUP), /* S54 */
225 KEY(6, 5, KEY_QI_VOLDOWN), /* S55 */
226 KEY(6, 6, KEY_DOWN), /* S56 */
227 KEY(6, 7, KEY_RIGHT), /* S57 */
229 KEY(7, 0, KEY_LEFTSHIFT), /* S58 */
230 KEY(7, 1, KEY_LEFTALT), /* S59 */
231 KEY(7, 2, KEY_QI_FN), /* S60 */
234 static const struct matrix_keymap_data qi_lb60_keymap_data = {
235 .keymap = qi_lb60_keymap,
236 .keymap_size = ARRAY_SIZE(qi_lb60_keymap),
239 static const unsigned int qi_lb60_keypad_cols[] = {
240 QI_LB60_GPIO_KEYOUT(0),
241 QI_LB60_GPIO_KEYOUT(1),
242 QI_LB60_GPIO_KEYOUT(2),
243 QI_LB60_GPIO_KEYOUT(3),
244 QI_LB60_GPIO_KEYOUT(4),
245 QI_LB60_GPIO_KEYOUT(5),
246 QI_LB60_GPIO_KEYOUT(6),
247 QI_LB60_GPIO_KEYOUT(7),
250 static const unsigned int qi_lb60_keypad_rows[] = {
251 QI_LB60_GPIO_KEYIN(0),
252 QI_LB60_GPIO_KEYIN(1),
253 QI_LB60_GPIO_KEYIN(2),
254 QI_LB60_GPIO_KEYIN(3),
255 QI_LB60_GPIO_KEYIN(4),
256 QI_LB60_GPIO_KEYIN(5),
257 QI_LB60_GPIO_KEYIN(6),
261 static struct matrix_keypad_platform_data qi_lb60_pdata = {
262 .keymap_data = &qi_lb60_keymap_data,
263 .col_gpios = qi_lb60_keypad_cols,
264 .row_gpios = qi_lb60_keypad_rows,
265 .num_col_gpios = ARRAY_SIZE(qi_lb60_keypad_cols),
266 .num_row_gpios = ARRAY_SIZE(qi_lb60_keypad_rows),
267 .col_scan_delay_us = 10,
273 static struct platform_device qi_lb60_keypad = {
274 .name = "matrix-keypad",
277 .platform_data = &qi_lb60_pdata,
282 static struct fb_videomode qi_lb60_video_modes[] = {
295 .vmode = FB_VMODE_NONINTERLACED,
299 static struct jz4740_fb_platform_data qi_lb60_fb_pdata = {
302 .num_modes = ARRAY_SIZE(qi_lb60_video_modes),
303 .modes = qi_lb60_video_modes,
305 .lcd_type = JZ_LCD_TYPE_8BIT_SERIAL,
306 .pixclk_falling_edge = 1,
309 struct spi_gpio_platform_data qi_lb60_spigpio_platform_data = {
313 static struct platform_device qi_lb60_spigpio_device = {
317 .platform_data = &qi_lb60_spigpio_platform_data,
321 static struct gpiod_lookup_table qi_lb60_spigpio_gpio_table = {
322 .dev_id = "spi_gpio",
324 GPIO_LOOKUP("GPIOC", 23,
325 "sck", GPIO_ACTIVE_HIGH),
326 GPIO_LOOKUP("GPIOC", 22,
327 "mosi", GPIO_ACTIVE_HIGH),
328 GPIO_LOOKUP("GPIOC", 21,
329 "cs", GPIO_ACTIVE_HIGH),
334 static struct spi_board_info qi_lb60_spi_board_info[] = {
336 .modalias = "ili8960",
339 .max_speed_hz = 30 * 1000,
345 static struct jz_battery_platform_data qi_lb60_battery_pdata = {
346 .gpio_charge = JZ_GPIO_PORTC(27),
347 .gpio_charge_active_low = 1,
350 .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
351 .voltage_max_design = 4200000,
352 .voltage_min_design = 3600000,
356 /* GPIO Key: power */
357 static struct gpio_keys_button qi_lb60_gpio_keys_buttons[] = {
360 .gpio = JZ_GPIO_PORTD(29),
367 static struct gpio_keys_platform_data qi_lb60_gpio_keys_data = {
368 .nbuttons = ARRAY_SIZE(qi_lb60_gpio_keys_buttons),
369 .buttons = qi_lb60_gpio_keys_buttons,
372 static struct platform_device qi_lb60_gpio_keys = {
376 .platform_data = &qi_lb60_gpio_keys_data,
380 static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = {
381 /* Intentionally left blank */
384 static struct gpiod_lookup_table qi_lb60_mmc_gpio_table = {
385 .dev_id = "jz4740-mmc.0",
387 GPIO_LOOKUP("GPIOD", 0, "cd", GPIO_ACTIVE_HIGH),
388 GPIO_LOOKUP("GPIOD", 2, "power", GPIO_ACTIVE_LOW),
394 static struct pwm_lookup qi_lb60_pwm_lookup[] = {
395 PWM_LOOKUP("jz4740-pwm", 4, "pwm-beeper", NULL, 0,
396 PWM_POLARITY_NORMAL),
399 static struct platform_device qi_lb60_pwm_beeper = {
400 .name = "pwm-beeper",
405 static char *qi_lb60_batteries[] = {
409 static struct gpio_charger_platform_data qi_lb60_charger_pdata = {
411 .type = POWER_SUPPLY_TYPE_USB,
412 .gpio = JZ_GPIO_PORTD(28),
413 .gpio_active_low = 1,
414 .supplied_to = qi_lb60_batteries,
415 .num_supplicants = ARRAY_SIZE(qi_lb60_batteries),
418 static struct platform_device qi_lb60_charger_device = {
419 .name = "gpio-charger",
421 .platform_data = &qi_lb60_charger_pdata,
426 static struct platform_device qi_lb60_audio_device = {
427 .name = "qi-lb60-audio",
431 static struct gpiod_lookup_table qi_lb60_audio_gpio_table = {
432 .dev_id = "qi-lb60-audio",
434 GPIO_LOOKUP("GPIOB", 29, "snd", 0),
435 GPIO_LOOKUP("GPIOD", 4, "amp", 0),
440 static struct platform_device *jz_platform_devices[] __initdata = {
442 &jz4740_udc_xceiv_device,
446 &qi_lb60_spigpio_device,
447 &jz4740_framebuffer_device,
450 &jz4740_codec_device,
456 &qi_lb60_charger_device,
457 &qi_lb60_audio_device,
460 static unsigned long pin_cfg_bias_disable[] = {
461 PIN_CONFIG_BIAS_DISABLE,
464 static struct pinctrl_map pin_map[] __initdata = {
465 /* NAND pin configuration */
466 PIN_MAP_MUX_GROUP_DEFAULT("jz4740-nand",
467 "10010000.pin-controller", "nand-cs1", "nand"),
469 /* fbdev pin configuration */
470 PIN_MAP_MUX_GROUP("jz4740-fb", PINCTRL_STATE_DEFAULT,
471 "10010000.pin-controller", "lcd-8bit", "lcd"),
472 PIN_MAP_MUX_GROUP("jz4740-fb", PINCTRL_STATE_SLEEP,
473 "10010000.pin-controller", "lcd-no-pins", "lcd"),
475 /* MMC pin configuration */
476 PIN_MAP_MUX_GROUP_DEFAULT("jz4740-mmc.0",
477 "10010000.pin-controller", "mmc-1bit", "mmc"),
478 PIN_MAP_MUX_GROUP_DEFAULT("jz4740-mmc.0",
479 "10010000.pin-controller", "mmc-4bit", "mmc"),
480 PIN_MAP_CONFIGS_PIN_DEFAULT("jz4740-mmc.0",
481 "10010000.pin-controller", "PD0", pin_cfg_bias_disable),
482 PIN_MAP_CONFIGS_PIN_DEFAULT("jz4740-mmc.0",
483 "10010000.pin-controller", "PD2", pin_cfg_bias_disable),
485 /* PWM pin configuration */
486 PIN_MAP_MUX_GROUP_DEFAULT("jz4740-pwm",
487 "10010000.pin-controller", "pwm4", "pwm4"),
491 static int __init qi_lb60_init_platform_devices(void)
493 jz4740_framebuffer_device.dev.platform_data = &qi_lb60_fb_pdata;
494 jz4740_nand_device.dev.platform_data = &qi_lb60_nand_pdata;
495 jz4740_adc_device.dev.platform_data = &qi_lb60_battery_pdata;
496 jz4740_mmc_device.dev.platform_data = &qi_lb60_mmc_pdata;
498 gpiod_add_lookup_table(&qi_lb60_audio_gpio_table);
499 gpiod_add_lookup_table(&qi_lb60_nand_gpio_table);
500 gpiod_add_lookup_table(&qi_lb60_spigpio_gpio_table);
501 gpiod_add_lookup_table(&qi_lb60_mmc_gpio_table);
503 spi_register_board_info(qi_lb60_spi_board_info,
504 ARRAY_SIZE(qi_lb60_spi_board_info));
506 pwm_add_table(qi_lb60_pwm_lookup, ARRAY_SIZE(qi_lb60_pwm_lookup));
507 pinctrl_register_mappings(pin_map, ARRAY_SIZE(pin_map));
509 return platform_add_devices(jz_platform_devices,
510 ARRAY_SIZE(jz_platform_devices));
514 static int __init qi_lb60_board_setup(void)
516 printk(KERN_INFO "Qi Hardware JZ4740 QI LB60 setup\n");
518 if (qi_lb60_init_platform_devices())
519 panic("Failed to initialize platform devices");
523 arch_initcall(qi_lb60_board_setup);