board-qi_lb60.c 12 KB

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