z2.c 14 KB

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