board-qi_lb60.c 13 KB

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