board-qi_lb60.c 13 KB

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