| 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 | #include "clock.h" |
| 35 | |
| 36 | /* NAND */ |
| 37 | static struct nand_ecclayout qi_lb60_ecclayout_1gb = { |
| 38 | .eccbytes = 36, |
| 39 | .eccpos = { |
| 40 | 6, 7, 8, 9, 10, 11, 12, 13, |
| 41 | 14, 15, 16, 17, 18, 19, 20, 21, |
| 42 | 22, 23, 24, 25, 26, 27, 28, 29, |
| 43 | 30, 31, 32, 33, 34, 35, 36, 37, |
| 44 | 38, 39, 40, 41}, |
| 45 | .oobfree = { |
| 46 | {.offset = 2, |
| 47 | .length = 4}, |
| 48 | {.offset = 42, |
| 49 | .length = 22}} |
| 50 | }; |
| 51 | |
| 52 | static struct mtd_partition qi_lb60_partitions_1gb[] = { |
| 53 | { .name = "NAND BOOT partition", |
| 54 | .offset = 0 * 0x100000, |
| 55 | .size = 4 * 0x100000, |
| 56 | }, |
| 57 | { .name = "NAND KERNEL partition", |
| 58 | .offset = 4 * 0x100000, |
| 59 | .size = 4 * 0x100000, |
| 60 | }, |
| 61 | { .name = "NAND ROOTFS partition", |
| 62 | .offset = 8 * 0x100000, |
| 63 | .size = (504 + 512) * 0x100000, |
| 64 | }, |
| 65 | }; |
| 66 | |
| 67 | static struct nand_ecclayout qi_lb60_ecclayout_2gb = { |
| 68 | .eccbytes = 72, |
| 69 | .eccpos = { |
| 70 | 12, 13, 14, 15, 16, 17, 18, 19, |
| 71 | 20, 21, 22, 23, 24, 25, 26, 27, |
| 72 | 28, 29, 30, 31, 32, 33, 34, 35, |
| 73 | 36, 37, 38, 39, 40, 41, 42, 43, |
| 74 | 44, 45, 46, 47, 48, 49, 50, 51, |
| 75 | 52, 53, 54, 55, 56, 57, 58, 59, |
| 76 | 60, 61, 62, 63, 64, 65, 66, 67, |
| 77 | 68, 69, 70, 71, 72, 73, 74, 75, |
| 78 | 76, 77, 78, 79, 80, 81, 82, 83}, |
| 79 | .oobfree = { |
| 80 | {.offset = 2, |
| 81 | .length = 10}, |
| 82 | {.offset = 84, |
| 83 | .length = 44}} |
| 84 | }; |
| 85 | |
| 86 | static struct mtd_partition qi_lb60_partitions_2gb[] = { |
| 87 | { .name = "NAND BOOT partition", |
| 88 | .offset = 0 * 0x100000, |
| 89 | .size = 4 * 0x100000, |
| 90 | }, |
| 91 | { .name = "NAND KERNEL partition", |
| 92 | .offset = 4 * 0x100000, |
| 93 | .size = 4 * 0x100000, |
| 94 | }, |
| 95 | { .name = "NAND ROOTFS partition", |
| 96 | .offset = 8 * 0x100000, |
| 97 | .size = 256 * 0x100000, |
| 98 | }, |
| 99 | { .name = "NAND DATA partition", |
| 100 | .offset = 264 * 0x100000, |
| 101 | .size = 1784 * 0x100000, |
| 102 | }, |
| 103 | }; |
| 104 | |
| 105 | static void qi_lb60_nand_ident(struct platform_device *pdev, |
| 106 | struct nand_chip *chip, |
| 107 | struct mtd_partition **partitions, |
| 108 | int *num_partitions) |
| 109 | { |
| 110 | if (chip->page_shift == 12) { |
| 111 | chip->ecc.layout = &qi_lb60_ecclayout_2gb; |
| 112 | *partitions = qi_lb60_partitions_2gb; |
| 113 | *num_partitions = ARRAY_SIZE(qi_lb60_partitions_2gb); |
| 114 | } else { |
| 115 | chip->ecc.layout = &qi_lb60_ecclayout_1gb; |
| 116 | *partitions = qi_lb60_partitions_1gb; |
| 117 | *num_partitions = ARRAY_SIZE(qi_lb60_partitions_1gb); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static struct jz_nand_platform_data qi_lb60_nand_pdata = { |
| 122 | .ident_callback = qi_lb60_nand_ident, |
| 123 | .busy_gpio = 94, |
| 124 | }; |
| 125 | |
| 126 | /* Keyboard*/ |
| 127 | #define KEY_QI_VOLUP KEY_F11 |
| 128 | #define KEY_QI_VOLDOWN KEY_F12 |
| 129 | #define KEY_QI_QI KEY_F13 |
| 130 | #define KEY_QI_ACUTE KEY_GRAVE |
| 131 | #define KEY_QI_FN KEY_LEFTCTRL |
| 132 | #define KEY_QI_UPRED KEY_RIGHTALT |
| 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_QI_ACUTE), /* 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 | KEY(7, 0, KEY_LEFTSHIFT), /* S58 */ |
| 192 | KEY(7, 1, KEY_LEFTALT), /* S59 */ |
| 193 | KEY(7, 2, KEY_QI_FN), /* S60 */ |
| 194 | }; |
| 195 | |
| 196 | static const struct matrix_keymap_data qi_lb60_keymap_data = { |
| 197 | .keymap = qi_lb60_keymap, |
| 198 | .keymap_size = ARRAY_SIZE(qi_lb60_keymap), |
| 199 | }; |
| 200 | |
| 201 | static const unsigned int qi_lb60_keypad_cols[] = { |
| 202 | 74, 75, 76, 77, 78, 79, 80, 81, |
| 203 | }; |
| 204 | |
| 205 | static const unsigned int qi_lb60_keypad_rows[] = { |
| 206 | 114, 115, 116, 117, 118, 119, 120, 122, |
| 207 | }; |
| 208 | |
| 209 | static struct matrix_keypad_platform_data qi_lb60_pdata = { |
| 210 | .keymap_data = &qi_lb60_keymap_data, |
| 211 | .col_gpios = qi_lb60_keypad_cols, |
| 212 | .row_gpios = qi_lb60_keypad_rows, |
| 213 | .num_col_gpios = ARRAY_SIZE(qi_lb60_keypad_cols), |
| 214 | .num_row_gpios = ARRAY_SIZE(qi_lb60_keypad_rows), |
| 215 | .col_scan_delay_us = 10, |
| 216 | .debounce_ms = 10, |
| 217 | .wakeup = 1, |
| 218 | .active_low = 1, |
| 219 | }; |
| 220 | |
| 221 | static struct platform_device qi_lb60_keypad = { |
| 222 | .name = "matrix-keypad", |
| 223 | .id = -1, |
| 224 | .dev = { |
| 225 | .platform_data = &qi_lb60_pdata, |
| 226 | }, |
| 227 | }; |
| 228 | |
| 229 | /* Display */ |
| 230 | static struct fb_videomode qi_lb60_video_modes[] = { |
| 231 | { |
| 232 | .name = "320x240", |
| 233 | .xres = 320, |
| 234 | .yres = 240, |
| 235 | .refresh = 30, |
| 236 | .left_margin = 140, |
| 237 | .right_margin = 273, |
| 238 | .upper_margin = 20, |
| 239 | .lower_margin = 2, |
| 240 | .hsync_len = 1, |
| 241 | .vsync_len = 1, |
| 242 | .sync = 0, |
| 243 | .vmode = FB_VMODE_NONINTERLACED, |
| 244 | }, |
| 245 | }; |
| 246 | |
| 247 | static struct jz4740_fb_platform_data qi_lb60_fb_pdata = { |
| 248 | .width = 60, |
| 249 | .height = 45, |
| 250 | .num_modes = ARRAY_SIZE(qi_lb60_video_modes), |
| 251 | .modes = qi_lb60_video_modes, |
| 252 | .bpp = 24, |
| 253 | .lcd_type = JZ_LCD_TYPE_8BIT_SERIAL, |
| 254 | .pixclk_falling_edge = 1, |
| 255 | }; |
| 256 | |
| 257 | |
| 258 | struct spi_gpio_platform_data spigpio_platform_data = { |
| 259 | .sck = JZ_GPIO_PORTC(23), |
| 260 | .mosi = JZ_GPIO_PORTC(22), |
| 261 | .miso = JZ_GPIO_PORTC(22), |
| 262 | .num_chipselect = 1, |
| 263 | }; |
| 264 | |
| 265 | static struct platform_device spigpio_device = { |
| 266 | .name = "spi_gpio", |
| 267 | .id = 1, |
| 268 | .dev = { |
| 269 | .platform_data = &spigpio_platform_data, |
| 270 | }, |
| 271 | }; |
| 272 | |
| 273 | static struct spi_board_info qi_lb60_spi_board_info[] = { |
| 274 | { |
| 275 | .modalias = "gpm940b0", |
| 276 | .controller_data = (void*)JZ_GPIO_PORTC(21), |
| 277 | .chip_select = 0, |
| 278 | .bus_num = 1, |
| 279 | .max_speed_hz = 30 * 1000, |
| 280 | }, |
| 281 | }; |
| 282 | |
| 283 | /* Battery */ |
| 284 | static struct jz_battery_platform_data qi_lb60_battery_pdata = { |
| 285 | .gpio_charge = GPIO_CHARG_STAT_N, |
| 286 | .gpio_charge_active_low = 1, |
| 287 | .info = { |
| 288 | .name = "battery", |
| 289 | .technology = POWER_SUPPLY_TECHNOLOGY_LIPO, |
| 290 | .voltage_max_design = 4200000, |
| 291 | .voltage_min_design = 3600000, |
| 292 | }, |
| 293 | }; |
| 294 | |
| 295 | static char *qi_lb60_batteries[] = { |
| 296 | "battery", |
| 297 | }; |
| 298 | |
| 299 | static struct gpio_charger_platform_data qi_lb60_charger_pdata = { |
| 300 | .name = "USB", |
| 301 | .type = POWER_SUPPLY_TYPE_USB, |
| 302 | .gpio = GPIO_USB_DETE, |
| 303 | .gpio_active_low = 1, |
| 304 | .batteries = qi_lb60_batteries, |
| 305 | .num_batteries = ARRAY_SIZE(qi_lb60_batteries), |
| 306 | }; |
| 307 | |
| 308 | static struct platform_device qi_lb60_charger_device = { |
| 309 | .name = "gpio-charger", |
| 310 | .dev = { |
| 311 | .platform_data = &qi_lb60_charger_pdata, |
| 312 | }, |
| 313 | }; |
| 314 | |
| 315 | /* GPIO Key: power */ |
| 316 | static struct gpio_keys_button qi_lb60_gpio_keys_buttons[] = { |
| 317 | [0] = { |
| 318 | .code = KEY_POWER, |
| 319 | .gpio = GPIO_WAKEUP_N, |
| 320 | .active_low = 1, |
| 321 | .desc = "Power", |
| 322 | .wakeup = 1, |
| 323 | }, |
| 324 | }; |
| 325 | |
| 326 | static struct gpio_keys_platform_data qi_lb60_gpio_keys_data = { |
| 327 | .nbuttons = ARRAY_SIZE(qi_lb60_gpio_keys_buttons), |
| 328 | .buttons = qi_lb60_gpio_keys_buttons, |
| 329 | }; |
| 330 | |
| 331 | static struct platform_device qi_lb60_gpio_keys = { |
| 332 | .name = "gpio-keys", |
| 333 | .id = -1, |
| 334 | .dev = { |
| 335 | .platform_data = &qi_lb60_gpio_keys_data, |
| 336 | } |
| 337 | }; |
| 338 | |
| 339 | static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = { |
| 340 | .gpio_card_detect = JZ_GPIO_PORTD(0), |
| 341 | .gpio_read_only = -1, |
| 342 | .gpio_power = JZ_GPIO_PORTD(2), |
| 343 | .power_active_low = 1, |
| 344 | }; |
| 345 | |
| 346 | static struct platform_device *jz_platform_devices[] __initdata = { |
| 347 | &jz4740_usb_ohci_device, |
| 348 | &jz4740_usb_gdt_device, |
| 349 | &jz4740_mmc_device, |
| 350 | &jz4740_nand_device, |
| 351 | &qi_lb60_keypad, |
| 352 | &spigpio_device, |
| 353 | &jz4740_framebuffer_device, |
| 354 | &jz4740_i2s_device, |
| 355 | &jz4740_codec_device, |
| 356 | &jz4740_rtc_device, |
| 357 | &jz4740_adc_device, |
| 358 | &jz4740_battery_device, |
| 359 | &qi_lb60_gpio_keys, |
| 360 | &qi_lb60_charger_device, |
| 361 | }; |
| 362 | |
| 363 | static void __init board_gpio_setup(void) |
| 364 | { |
| 365 | /* We only need to enable/disable pullup here for pins used in generic |
| 366 | * drivers. Everything else is done by the drivers themselfs. */ |
| 367 | jz_gpio_disable_pullup(GPIO_SD_VCC_EN_N); |
| 368 | jz_gpio_disable_pullup(GPIO_SD_CD_N); |
| 369 | } |
| 370 | |
| 371 | static int __init qi_lb60_init_platform_devices(void) |
| 372 | { |
| 373 | jz4740_framebuffer_device.dev.platform_data = &qi_lb60_fb_pdata; |
| 374 | jz4740_nand_device.dev.platform_data = &qi_lb60_nand_pdata; |
| 375 | jz4740_battery_device.dev.platform_data = &qi_lb60_battery_pdata; |
| 376 | jz4740_mmc_device.dev.platform_data = &qi_lb60_mmc_pdata; |
| 377 | |
| 378 | spi_register_board_info(qi_lb60_spi_board_info, |
| 379 | ARRAY_SIZE(qi_lb60_spi_board_info)); |
| 380 | |
| 381 | return platform_add_devices(jz_platform_devices, |
| 382 | ARRAY_SIZE(jz_platform_devices)); |
| 383 | |
| 384 | } |
| 385 | |
| 386 | struct jz4740_clock_board_data jz4740_clock_bdata = { |
| 387 | .ext_rate = 12000000, |
| 388 | .rtc_rate = 32768, |
| 389 | }; |
| 390 | |
| 391 | extern int jz_gpiolib_init(void); |
| 392 | |
| 393 | static __init int board_avt2(char *str) |
| 394 | { |
| 395 | qi_lb60_mmc_pdata.card_detect_active_low = 1; |
| 396 | qi_lb60_mmc_pdata.power_active_low = 1; |
| 397 | |
| 398 | return 1; |
| 399 | } |
| 400 | |
| 401 | __setup("avt2", board_avt2); |
| 402 | |
| 403 | static int __init qi_lb60_board_setup(void) |
| 404 | { |
| 405 | printk("Qi Hardware JZ4740 QI_LB60 setup\n"); |
| 406 | if (jz_gpiolib_init()) |
| 407 | panic("Failed to initalize jz gpio\n"); |
| 408 | |
| 409 | jz4740_clock_init(); |
| 410 | board_gpio_setup(); |
| 411 | |
| 412 | if (qi_lb60_init_platform_devices()) |
| 413 | panic("Failed to initalize platform devices\n"); |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | arch_initcall(qi_lb60_board_setup); |
| 419 | |