board-qi_lb60.c 11 KB

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