z2.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /*
  2. * linux/arch/arm/mach-pxa/z2.c
  3. *
  4. * Support for the Zipit Z2 Handheld device.
  5. *
  6. * Copyright (C) 2009-2010 Marek Vasut <marek.vasut@gmail.com>
  7. *
  8. * Based on research and code by: Ken McGuire
  9. * Based on mainstone.c as modified for the Zipit Z2.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/platform_device.h>
  16. #include <linux/mtd/mtd.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <linux/pwm_backlight.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/spi/libertas_spi.h>
  22. #include <linux/spi/lms283gf05.h>
  23. #include <linux/power_supply.h>
  24. #include <linux/mtd/physmap.h>
  25. #include <linux/gpio.h>
  26. #include <linux/gpio_keys.h>
  27. #include <linux/delay.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <mach/pxa27x.h>
  31. #include <mach/mfp-pxa27x.h>
  32. #include <mach/z2.h>
  33. #include <mach/pxafb.h>
  34. #include <mach/mmc.h>
  35. #include <mach/pxa27x_keypad.h>
  36. #include <mach/pxa2xx_spi.h>
  37. #include <plat/i2c.h>
  38. #include "generic.h"
  39. #include "devices.h"
  40. /******************************************************************************
  41. * Pin configuration
  42. ******************************************************************************/
  43. static unsigned long z2_pin_config[] = {
  44. /* LCD - 16bpp Active TFT */
  45. GPIO58_LCD_LDD_0,
  46. GPIO59_LCD_LDD_1,
  47. GPIO60_LCD_LDD_2,
  48. GPIO61_LCD_LDD_3,
  49. GPIO62_LCD_LDD_4,
  50. GPIO63_LCD_LDD_5,
  51. GPIO64_LCD_LDD_6,
  52. GPIO65_LCD_LDD_7,
  53. GPIO66_LCD_LDD_8,
  54. GPIO67_LCD_LDD_9,
  55. GPIO68_LCD_LDD_10,
  56. GPIO69_LCD_LDD_11,
  57. GPIO70_LCD_LDD_12,
  58. GPIO71_LCD_LDD_13,
  59. GPIO72_LCD_LDD_14,
  60. GPIO73_LCD_LDD_15,
  61. GPIO74_LCD_FCLK,
  62. GPIO75_LCD_LCLK,
  63. GPIO76_LCD_PCLK,
  64. GPIO77_LCD_BIAS,
  65. GPIO19_GPIO, /* LCD reset */
  66. GPIO88_GPIO, /* LCD chipselect */
  67. /* PWM */
  68. GPIO115_PWM1_OUT, /* Keypad Backlight */
  69. GPIO11_PWM2_OUT, /* LCD Backlight */
  70. /* MMC */
  71. GPIO32_MMC_CLK,
  72. GPIO112_MMC_CMD,
  73. GPIO92_MMC_DAT_0,
  74. GPIO109_MMC_DAT_1,
  75. GPIO110_MMC_DAT_2,
  76. GPIO111_MMC_DAT_3,
  77. GPIO96_GPIO, /* SD detect */
  78. /* STUART */
  79. GPIO46_STUART_RXD,
  80. GPIO47_STUART_TXD,
  81. /* Keypad */
  82. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  83. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  84. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  85. GPIO34_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  86. GPIO38_KP_MKIN_4 | WAKEUP_ON_LEVEL_HIGH,
  87. GPIO16_KP_MKIN_5 | WAKEUP_ON_LEVEL_HIGH,
  88. GPIO17_KP_MKIN_6 | WAKEUP_ON_LEVEL_HIGH,
  89. GPIO103_KP_MKOUT_0,
  90. GPIO104_KP_MKOUT_1,
  91. GPIO105_KP_MKOUT_2,
  92. GPIO106_KP_MKOUT_3,
  93. GPIO107_KP_MKOUT_4,
  94. GPIO108_KP_MKOUT_5,
  95. GPIO35_KP_MKOUT_6,
  96. GPIO41_KP_MKOUT_7,
  97. /* I2C */
  98. GPIO117_I2C_SCL,
  99. GPIO118_I2C_SDA,
  100. /* SSP1 */
  101. GPIO23_SSP1_SCLK, /* SSP1_SCK */
  102. GPIO25_SSP1_TXD, /* SSP1_TXD */
  103. GPIO26_SSP1_RXD, /* SSP1_RXD */
  104. /* SSP2 */
  105. GPIO22_SSP2_SCLK, /* SSP2_SCK */
  106. GPIO13_SSP2_TXD, /* SSP2_TXD */
  107. GPIO40_SSP2_RXD, /* SSP2_RXD */
  108. /* LEDs */
  109. GPIO10_GPIO, /* WiFi LED */
  110. GPIO83_GPIO, /* Charging LED */
  111. GPIO85_GPIO, /* Charged LED */
  112. /* I2S */
  113. GPIO28_I2S_BITCLK_OUT,
  114. GPIO29_I2S_SDATA_IN,
  115. GPIO30_I2S_SDATA_OUT,
  116. GPIO31_I2S_SYNC,
  117. GPIO113_I2S_SYSCLK,
  118. /* MISC */
  119. GPIO0_GPIO, /* AC power detect */
  120. GPIO1_GPIO, /* Power button */
  121. GPIO37_GPIO, /* Headphone detect */
  122. GPIO98_GPIO, /* Lid switch */
  123. GPIO14_GPIO, /* WiFi Reset */
  124. GPIO15_GPIO, /* WiFi Power */
  125. GPIO24_GPIO, /* WiFi CS */
  126. GPIO36_GPIO, /* WiFi IRQ */
  127. GPIO88_GPIO, /* LCD CS */
  128. };
  129. /******************************************************************************
  130. * NOR Flash
  131. ******************************************************************************/
  132. #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
  133. static struct resource z2_flash_resource = {
  134. .start = PXA_CS0_PHYS,
  135. .end = PXA_CS0_PHYS + SZ_8M - 1,
  136. .flags = IORESOURCE_MEM,
  137. };
  138. static struct mtd_partition z2_flash_parts[] = {
  139. {
  140. .name = "U-Boot Bootloader",
  141. .offset = 0x0,
  142. .size = 0x40000,
  143. }, {
  144. .name = "U-Boot Environment",
  145. .offset = 0x40000,
  146. .size = 0x60000,
  147. }, {
  148. .name = "Flash",
  149. .offset = 0x60000,
  150. .size = MTDPART_SIZ_FULL,
  151. },
  152. };
  153. static struct physmap_flash_data z2_flash_data = {
  154. .width = 2,
  155. .parts = z2_flash_parts,
  156. .nr_parts = ARRAY_SIZE(z2_flash_parts),
  157. };
  158. static struct platform_device z2_flash = {
  159. .name = "physmap-flash",
  160. .id = -1,
  161. .resource = &z2_flash_resource,
  162. .num_resources = 1,
  163. .dev = {
  164. .platform_data = &z2_flash_data,
  165. },
  166. };
  167. static void __init z2_nor_init(void)
  168. {
  169. platform_device_register(&z2_flash);
  170. }
  171. #else
  172. static inline void z2_nor_init(void) {}
  173. #endif
  174. /******************************************************************************
  175. * Backlight
  176. ******************************************************************************/
  177. #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
  178. static struct platform_pwm_backlight_data z2_backlight_data[] = {
  179. [0] = {
  180. /* Keypad Backlight */
  181. .pwm_id = 1,
  182. .max_brightness = 1023,
  183. .dft_brightness = 512,
  184. .pwm_period_ns = 1260320,
  185. },
  186. [1] = {
  187. /* LCD Backlight */
  188. .pwm_id = 2,
  189. .max_brightness = 1023,
  190. .dft_brightness = 512,
  191. .pwm_period_ns = 1260320,
  192. },
  193. };
  194. static struct platform_device z2_backlight_devices[2] = {
  195. {
  196. .name = "pwm-backlight",
  197. .id = 0,
  198. .dev = {
  199. .platform_data = &z2_backlight_data[1],
  200. },
  201. },
  202. {
  203. .name = "pwm-backlight",
  204. .id = 1,
  205. .dev = {
  206. .platform_data = &z2_backlight_data[0],
  207. },
  208. },
  209. };
  210. static void __init z2_pwm_init(void)
  211. {
  212. platform_device_register(&z2_backlight_devices[0]);
  213. platform_device_register(&z2_backlight_devices[1]);
  214. }
  215. #else
  216. static inline void z2_pwm_init(void) {}
  217. #endif
  218. /******************************************************************************
  219. * Framebuffer
  220. ******************************************************************************/
  221. #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
  222. static struct pxafb_mode_info z2_lcd_modes[] = {
  223. {
  224. .pixclock = 192000,
  225. .xres = 240,
  226. .yres = 320,
  227. .bpp = 16,
  228. .left_margin = 4,
  229. .right_margin = 8,
  230. .upper_margin = 4,
  231. .lower_margin = 8,
  232. .hsync_len = 4,
  233. .vsync_len = 4,
  234. },
  235. };
  236. static struct pxafb_mach_info z2_lcd_screen = {
  237. .modes = z2_lcd_modes,
  238. .num_modes = ARRAY_SIZE(z2_lcd_modes),
  239. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_BIAS_ACTIVE_LOW |
  240. LCD_ALTERNATE_MAPPING,
  241. };
  242. static void __init z2_lcd_init(void)
  243. {
  244. set_pxa_fb_info(&z2_lcd_screen);
  245. }
  246. #else
  247. static inline void z2_lcd_init(void) {}
  248. #endif
  249. /******************************************************************************
  250. * SD/MMC card controller
  251. ******************************************************************************/
  252. #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
  253. static struct pxamci_platform_data z2_mci_platform_data = {
  254. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  255. .gpio_card_detect = GPIO96_ZIPITZ2_SD_DETECT,
  256. .gpio_power = -1,
  257. .gpio_card_ro = -1,
  258. .detect_delay_ms = 200,
  259. };
  260. static void __init z2_mmc_init(void)
  261. {
  262. pxa_set_mci_info(&z2_mci_platform_data);
  263. }
  264. #else
  265. static inline void z2_mmc_init(void) {}
  266. #endif
  267. /******************************************************************************
  268. * LEDs
  269. ******************************************************************************/
  270. #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  271. struct gpio_led z2_gpio_leds[] = {
  272. {
  273. .name = "z2:green:wifi",
  274. .default_trigger = "none",
  275. .gpio = GPIO10_ZIPITZ2_LED_WIFI,
  276. .active_low = 1,
  277. }, {
  278. .name = "z2:green:charged",
  279. .default_trigger = "none",
  280. .gpio = GPIO85_ZIPITZ2_LED_CHARGED,
  281. .active_low = 1,
  282. }, {
  283. .name = "z2:amber:charging",
  284. .default_trigger = "none",
  285. .gpio = GPIO83_ZIPITZ2_LED_CHARGING,
  286. .active_low = 1,
  287. },
  288. };
  289. static struct gpio_led_platform_data z2_gpio_led_info = {
  290. .leds = z2_gpio_leds,
  291. .num_leds = ARRAY_SIZE(z2_gpio_leds),
  292. };
  293. static struct platform_device z2_leds = {
  294. .name = "leds-gpio",
  295. .id = -1,
  296. .dev = {
  297. .platform_data = &z2_gpio_led_info,
  298. }
  299. };
  300. static void __init z2_leds_init(void)
  301. {
  302. platform_device_register(&z2_leds);
  303. }
  304. #else
  305. static inline void z2_leds_init(void) {}
  306. #endif
  307. /******************************************************************************
  308. * GPIO keyboard
  309. ******************************************************************************/
  310. #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
  311. static unsigned int z2_matrix_keys[] = {
  312. KEY(0, 0, KEY_OPTION),
  313. KEY(1, 0, KEY_UP),
  314. KEY(2, 0, KEY_DOWN),
  315. KEY(3, 0, KEY_LEFT),
  316. KEY(4, 0, KEY_RIGHT),
  317. KEY(5, 0, KEY_END),
  318. KEY(6, 0, KEY_KPPLUS),
  319. KEY(0, 1, KEY_HOME),
  320. KEY(1, 1, KEY_Q),
  321. KEY(2, 1, KEY_I),
  322. KEY(3, 1, KEY_G),
  323. KEY(4, 1, KEY_X),
  324. KEY(5, 1, KEY_ENTER),
  325. KEY(6, 1, KEY_KPMINUS),
  326. KEY(0, 2, KEY_PAGEUP),
  327. KEY(1, 2, KEY_W),
  328. KEY(2, 2, KEY_O),
  329. KEY(3, 2, KEY_H),
  330. KEY(4, 2, KEY_C),
  331. KEY(5, 2, KEY_LEFTALT),
  332. KEY(0, 3, KEY_PAGEDOWN),
  333. KEY(1, 3, KEY_E),
  334. KEY(2, 3, KEY_P),
  335. KEY(3, 3, KEY_J),
  336. KEY(4, 3, KEY_V),
  337. KEY(5, 3, KEY_LEFTSHIFT),
  338. KEY(0, 4, KEY_ESC),
  339. KEY(1, 4, KEY_R),
  340. KEY(2, 4, KEY_A),
  341. KEY(3, 4, KEY_K),
  342. KEY(4, 4, KEY_B),
  343. KEY(5, 4, KEY_LEFTCTRL),
  344. KEY(0, 5, KEY_TAB),
  345. KEY(1, 5, KEY_T),
  346. KEY(2, 5, KEY_S),
  347. KEY(3, 5, KEY_L),
  348. KEY(4, 5, KEY_N),
  349. KEY(5, 5, KEY_SPACE),
  350. KEY(0, 6, KEY_STOPCD),
  351. KEY(1, 6, KEY_Y),
  352. KEY(2, 6, KEY_D),
  353. KEY(3, 6, KEY_BACKSPACE),
  354. KEY(4, 6, KEY_M),
  355. KEY(5, 6, KEY_COMMA),
  356. KEY(0, 7, KEY_PLAYCD),
  357. KEY(1, 7, KEY_U),
  358. KEY(2, 7, KEY_F),
  359. KEY(3, 7, KEY_Z),
  360. KEY(4, 7, KEY_SEMICOLON),
  361. KEY(5, 7, KEY_DOT),
  362. };
  363. static struct pxa27x_keypad_platform_data z2_keypad_platform_data = {
  364. .matrix_key_rows = 7,
  365. .matrix_key_cols = 8,
  366. .matrix_key_map = z2_matrix_keys,
  367. .matrix_key_map_size = ARRAY_SIZE(z2_matrix_keys),
  368. .debounce_interval = 30,
  369. };
  370. static void __init z2_mkp_init(void)
  371. {
  372. pxa_set_keypad_info(&z2_keypad_platform_data);
  373. }
  374. #else
  375. static inline void z2_mkp_init(void) {}
  376. #endif
  377. /******************************************************************************
  378. * GPIO keys
  379. ******************************************************************************/
  380. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  381. static struct gpio_keys_button z2_pxa_buttons[] = {
  382. {KEY_POWER, GPIO1_ZIPITZ2_POWER_BUTTON, 0, "Power Button" },
  383. {KEY_CLOSE, GPIO98_ZIPITZ2_LID_BUTTON, 0, "Lid Button" },
  384. };
  385. static struct gpio_keys_platform_data z2_pxa_keys_data = {
  386. .buttons = z2_pxa_buttons,
  387. .nbuttons = ARRAY_SIZE(z2_pxa_buttons),
  388. };
  389. static struct platform_device z2_pxa_keys = {
  390. .name = "gpio-keys",
  391. .id = -1,
  392. .dev = {
  393. .platform_data = &z2_pxa_keys_data,
  394. },
  395. };
  396. static void __init z2_keys_init(void)
  397. {
  398. platform_device_register(&z2_pxa_keys);
  399. }
  400. #else
  401. static inline void z2_keys_init(void) {}
  402. #endif
  403. /******************************************************************************
  404. * SSP Devices - WiFi and LCD control
  405. ******************************************************************************/
  406. #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
  407. /* WiFi */
  408. static int z2_lbs_spi_setup(struct spi_device *spi)
  409. {
  410. int ret = 0;
  411. ret = gpio_request(GPIO15_ZIPITZ2_WIFI_POWER, "WiFi Power");
  412. if (ret)
  413. goto err;
  414. ret = gpio_direction_output(GPIO15_ZIPITZ2_WIFI_POWER, 1);
  415. if (ret)
  416. goto err2;
  417. ret = gpio_request(GPIO14_ZIPITZ2_WIFI_RESET, "WiFi Reset");
  418. if (ret)
  419. goto err2;
  420. ret = gpio_direction_output(GPIO14_ZIPITZ2_WIFI_RESET, 0);
  421. if (ret)
  422. goto err3;
  423. /* Reset the card */
  424. mdelay(180);
  425. gpio_set_value(GPIO14_ZIPITZ2_WIFI_RESET, 1);
  426. mdelay(20);
  427. spi->bits_per_word = 16;
  428. spi->mode = SPI_MODE_2,
  429. spi_setup(spi);
  430. return 0;
  431. err3:
  432. gpio_free(GPIO14_ZIPITZ2_WIFI_RESET);
  433. err2:
  434. gpio_free(GPIO15_ZIPITZ2_WIFI_POWER);
  435. err:
  436. return ret;
  437. };
  438. static int z2_lbs_spi_teardown(struct spi_device *spi)
  439. {
  440. gpio_set_value(GPIO14_ZIPITZ2_WIFI_RESET, 0);
  441. gpio_set_value(GPIO15_ZIPITZ2_WIFI_POWER, 0);
  442. gpio_free(GPIO14_ZIPITZ2_WIFI_RESET);
  443. gpio_free(GPIO15_ZIPITZ2_WIFI_POWER);
  444. return 0;
  445. };
  446. static struct pxa2xx_spi_chip z2_lbs_chip_info = {
  447. .rx_threshold = 8,
  448. .tx_threshold = 8,
  449. .timeout = 1000,
  450. .gpio_cs = GPIO24_ZIPITZ2_WIFI_CS,
  451. };
  452. static struct libertas_spi_platform_data z2_lbs_pdata = {
  453. .use_dummy_writes = 1,
  454. .setup = z2_lbs_spi_setup,
  455. .teardown = z2_lbs_spi_teardown,
  456. };
  457. /* LCD */
  458. static struct pxa2xx_spi_chip lms283_chip_info = {
  459. .rx_threshold = 1,
  460. .tx_threshold = 1,
  461. .timeout = 64,
  462. .gpio_cs = GPIO88_ZIPITZ2_LCD_CS,
  463. };
  464. static const struct lms283gf05_pdata lms283_pdata = {
  465. .reset_gpio = GPIO19_ZIPITZ2_LCD_RESET,
  466. };
  467. static struct spi_board_info spi_board_info[] __initdata = {
  468. {
  469. .modalias = "libertas_spi",
  470. .platform_data = &z2_lbs_pdata,
  471. .controller_data = &z2_lbs_chip_info,
  472. .irq = gpio_to_irq(GPIO36_ZIPITZ2_WIFI_IRQ),
  473. .max_speed_hz = 13000000,
  474. .bus_num = 1,
  475. .chip_select = 0,
  476. },
  477. {
  478. .modalias = "lms283gf05",
  479. .controller_data = &lms283_chip_info,
  480. .platform_data = &lms283_pdata,
  481. .max_speed_hz = 400000,
  482. .bus_num = 2,
  483. .chip_select = 0,
  484. },
  485. };
  486. static struct pxa2xx_spi_master pxa_ssp1_master_info = {
  487. .clock_enable = CKEN_SSP,
  488. .num_chipselect = 1,
  489. .enable_dma = 1,
  490. };
  491. static struct pxa2xx_spi_master pxa_ssp2_master_info = {
  492. .clock_enable = CKEN_SSP2,
  493. .num_chipselect = 1,
  494. };
  495. static void __init z2_spi_init(void)
  496. {
  497. pxa2xx_set_spi_info(1, &pxa_ssp1_master_info);
  498. pxa2xx_set_spi_info(2, &pxa_ssp2_master_info);
  499. spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
  500. }
  501. #else
  502. static inline void z2_spi_init(void) {}
  503. #endif
  504. /******************************************************************************
  505. * Machine init
  506. ******************************************************************************/
  507. static void __init z2_init(void)
  508. {
  509. pxa2xx_mfp_config(ARRAY_AND_SIZE(z2_pin_config));
  510. z2_lcd_init();
  511. z2_mmc_init();
  512. z2_mkp_init();
  513. pxa_set_i2c_info(NULL);
  514. z2_spi_init();
  515. z2_nor_init();
  516. z2_pwm_init();
  517. z2_leds_init();
  518. z2_keys_init();
  519. }
  520. MACHINE_START(ZIPIT2, "Zipit Z2")
  521. .phys_io = 0x40000000,
  522. .boot_params = 0xa0000100,
  523. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  524. .map_io = pxa_map_io,
  525. .init_irq = pxa27x_init_irq,
  526. .timer = &pxa_timer,
  527. .init_machine = z2_init,
  528. MACHINE_END