palmld.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. * Hardware definitions for Palm LifeDrive
  3. *
  4. * Author: Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * Based on work of:
  7. * Alex Osborne <ato@meshy.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * (find more info at www.hackndev.com)
  14. *
  15. */
  16. #include <linux/platform_device.h>
  17. #include <linux/delay.h>
  18. #include <linux/irq.h>
  19. #include <linux/gpio_keys.h>
  20. #include <linux/input.h>
  21. #include <linux/pda_power.h>
  22. #include <linux/pwm_backlight.h>
  23. #include <linux/gpio.h>
  24. #include <linux/wm97xx_batt.h>
  25. #include <linux/power_supply.h>
  26. #include <linux/sysdev.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <mach/pxa27x.h>
  31. #include <mach/audio.h>
  32. #include <mach/palmld.h>
  33. #include <mach/mmc.h>
  34. #include <mach/pxafb.h>
  35. #include <mach/irda.h>
  36. #include <mach/pxa27x_keypad.h>
  37. #include <mach/palmasoc.h>
  38. #include "generic.h"
  39. #include "devices.h"
  40. /******************************************************************************
  41. * Pin configuration
  42. ******************************************************************************/
  43. static unsigned long palmld_pin_config[] __initdata = {
  44. /* MMC */
  45. GPIO32_MMC_CLK,
  46. GPIO92_MMC_DAT_0,
  47. GPIO109_MMC_DAT_1,
  48. GPIO110_MMC_DAT_2,
  49. GPIO111_MMC_DAT_3,
  50. GPIO112_MMC_CMD,
  51. GPIO14_GPIO, /* SD detect */
  52. GPIO114_GPIO, /* SD power */
  53. GPIO116_GPIO, /* SD r/o switch */
  54. /* AC97 */
  55. GPIO28_AC97_BITCLK,
  56. GPIO29_AC97_SDATA_IN_0,
  57. GPIO30_AC97_SDATA_OUT,
  58. GPIO31_AC97_SYNC,
  59. GPIO89_AC97_SYSCLK,
  60. GPIO95_AC97_nRESET,
  61. /* IrDA */
  62. GPIO108_GPIO, /* ir disable */
  63. GPIO46_FICP_RXD,
  64. GPIO47_FICP_TXD,
  65. /* MATRIX KEYPAD */
  66. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  67. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  68. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  69. GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  70. GPIO103_KP_MKOUT_0,
  71. GPIO104_KP_MKOUT_1,
  72. GPIO105_KP_MKOUT_2,
  73. /* LCD */
  74. GPIO58_LCD_LDD_0,
  75. GPIO59_LCD_LDD_1,
  76. GPIO60_LCD_LDD_2,
  77. GPIO61_LCD_LDD_3,
  78. GPIO62_LCD_LDD_4,
  79. GPIO63_LCD_LDD_5,
  80. GPIO64_LCD_LDD_6,
  81. GPIO65_LCD_LDD_7,
  82. GPIO66_LCD_LDD_8,
  83. GPIO67_LCD_LDD_9,
  84. GPIO68_LCD_LDD_10,
  85. GPIO69_LCD_LDD_11,
  86. GPIO70_LCD_LDD_12,
  87. GPIO71_LCD_LDD_13,
  88. GPIO72_LCD_LDD_14,
  89. GPIO73_LCD_LDD_15,
  90. GPIO74_LCD_FCLK,
  91. GPIO75_LCD_LCLK,
  92. GPIO76_LCD_PCLK,
  93. GPIO77_LCD_BIAS,
  94. /* PWM */
  95. GPIO16_PWM0_OUT,
  96. /* GPIO KEYS */
  97. GPIO10_GPIO, /* hotsync button */
  98. GPIO12_GPIO, /* power switch */
  99. GPIO15_GPIO, /* lock switch */
  100. /* LEDs */
  101. GPIO52_GPIO, /* green led */
  102. GPIO94_GPIO, /* orange led */
  103. /* PCMCIA */
  104. GPIO48_nPOE,
  105. GPIO49_nPWE,
  106. GPIO50_nPIOR,
  107. GPIO51_nPIOW,
  108. GPIO85_nPCE_1,
  109. GPIO54_nPCE_2,
  110. GPIO79_PSKTSEL,
  111. GPIO55_nPREG,
  112. GPIO56_nPWAIT,
  113. GPIO57_nIOIS16,
  114. GPIO36_GPIO, /* wifi power */
  115. GPIO38_GPIO, /* wifi ready */
  116. GPIO81_GPIO, /* wifi reset */
  117. /* FFUART */
  118. GPIO34_FFUART_RXD,
  119. GPIO39_FFUART_TXD,
  120. /* HDD */
  121. GPIO98_GPIO, /* HDD reset */
  122. GPIO115_GPIO, /* HDD power */
  123. /* MISC */
  124. GPIO13_GPIO, /* earphone detect */
  125. };
  126. /******************************************************************************
  127. * SD/MMC card controller
  128. ******************************************************************************/
  129. static int palmld_mci_init(struct device *dev, irq_handler_t palmld_detect_int,
  130. void *data)
  131. {
  132. int err = 0;
  133. /* Setup an interrupt for detecting card insert/remove events */
  134. err = gpio_request(GPIO_NR_PALMLD_SD_DETECT_N, "SD IRQ");
  135. if (err)
  136. goto err;
  137. err = gpio_direction_input(GPIO_NR_PALMLD_SD_DETECT_N);
  138. if (err)
  139. goto err2;
  140. err = request_irq(gpio_to_irq(GPIO_NR_PALMLD_SD_DETECT_N),
  141. palmld_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  142. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  143. "SD/MMC card detect", data);
  144. if (err) {
  145. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  146. __func__);
  147. goto err2;
  148. }
  149. err = gpio_request(GPIO_NR_PALMLD_SD_POWER, "SD_POWER");
  150. if (err)
  151. goto err3;
  152. err = gpio_direction_output(GPIO_NR_PALMLD_SD_POWER, 0);
  153. if (err)
  154. goto err4;
  155. err = gpio_request(GPIO_NR_PALMLD_SD_READONLY, "SD_READONLY");
  156. if (err)
  157. goto err4;
  158. err = gpio_direction_input(GPIO_NR_PALMLD_SD_READONLY);
  159. if (err)
  160. goto err5;
  161. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  162. return 0;
  163. err5:
  164. gpio_free(GPIO_NR_PALMLD_SD_READONLY);
  165. err4:
  166. gpio_free(GPIO_NR_PALMLD_SD_POWER);
  167. err3:
  168. free_irq(gpio_to_irq(GPIO_NR_PALMLD_SD_DETECT_N), data);
  169. err2:
  170. gpio_free(GPIO_NR_PALMLD_SD_DETECT_N);
  171. err:
  172. return err;
  173. }
  174. static void palmld_mci_exit(struct device *dev, void *data)
  175. {
  176. gpio_free(GPIO_NR_PALMLD_SD_READONLY);
  177. gpio_free(GPIO_NR_PALMLD_SD_POWER);
  178. free_irq(gpio_to_irq(GPIO_NR_PALMLD_SD_DETECT_N), data);
  179. gpio_free(GPIO_NR_PALMLD_SD_DETECT_N);
  180. }
  181. static void palmld_mci_power(struct device *dev, unsigned int vdd)
  182. {
  183. struct pxamci_platform_data *p_d = dev->platform_data;
  184. gpio_set_value(GPIO_NR_PALMLD_SD_POWER, p_d->ocr_mask & (1 << vdd));
  185. }
  186. static int palmld_mci_get_ro(struct device *dev)
  187. {
  188. return gpio_get_value(GPIO_NR_PALMLD_SD_READONLY);
  189. }
  190. static struct pxamci_platform_data palmld_mci_platform_data = {
  191. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  192. .setpower = palmld_mci_power,
  193. .get_ro = palmld_mci_get_ro,
  194. .init = palmld_mci_init,
  195. .exit = palmld_mci_exit,
  196. };
  197. /******************************************************************************
  198. * GPIO keyboard
  199. ******************************************************************************/
  200. static unsigned int palmld_matrix_keys[] = {
  201. KEY(0, 1, KEY_F2),
  202. KEY(0, 2, KEY_UP),
  203. KEY(1, 0, KEY_F3),
  204. KEY(1, 1, KEY_F4),
  205. KEY(1, 2, KEY_RIGHT),
  206. KEY(2, 0, KEY_F1),
  207. KEY(2, 1, KEY_F5),
  208. KEY(2, 2, KEY_DOWN),
  209. KEY(3, 0, KEY_F6),
  210. KEY(3, 1, KEY_ENTER),
  211. KEY(3, 2, KEY_LEFT),
  212. };
  213. static struct pxa27x_keypad_platform_data palmld_keypad_platform_data = {
  214. .matrix_key_rows = 4,
  215. .matrix_key_cols = 3,
  216. .matrix_key_map = palmld_matrix_keys,
  217. .matrix_key_map_size = ARRAY_SIZE(palmld_matrix_keys),
  218. .debounce_interval = 30,
  219. };
  220. /******************************************************************************
  221. * GPIO keys
  222. ******************************************************************************/
  223. static struct gpio_keys_button palmld_pxa_buttons[] = {
  224. {KEY_F8, GPIO_NR_PALMLD_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
  225. {KEY_F9, GPIO_NR_PALMLD_LOCK_SWITCH, 0, "Lock Switch" },
  226. {KEY_POWER, GPIO_NR_PALMLD_POWER_SWITCH, 0, "Power Switch" },
  227. };
  228. static struct gpio_keys_platform_data palmld_pxa_keys_data = {
  229. .buttons = palmld_pxa_buttons,
  230. .nbuttons = ARRAY_SIZE(palmld_pxa_buttons),
  231. };
  232. static struct platform_device palmld_pxa_keys = {
  233. .name = "gpio-keys",
  234. .id = -1,
  235. .dev = {
  236. .platform_data = &palmld_pxa_keys_data,
  237. },
  238. };
  239. /******************************************************************************
  240. * Backlight
  241. ******************************************************************************/
  242. static int palmld_backlight_init(struct device *dev)
  243. {
  244. int ret;
  245. ret = gpio_request(GPIO_NR_PALMLD_BL_POWER, "BL POWER");
  246. if (ret)
  247. goto err;
  248. ret = gpio_direction_output(GPIO_NR_PALMLD_BL_POWER, 0);
  249. if (ret)
  250. goto err2;
  251. ret = gpio_request(GPIO_NR_PALMLD_LCD_POWER, "LCD POWER");
  252. if (ret)
  253. goto err2;
  254. ret = gpio_direction_output(GPIO_NR_PALMLD_LCD_POWER, 0);
  255. if (ret)
  256. goto err3;
  257. return 0;
  258. err3:
  259. gpio_free(GPIO_NR_PALMLD_LCD_POWER);
  260. err2:
  261. gpio_free(GPIO_NR_PALMLD_BL_POWER);
  262. err:
  263. return ret;
  264. }
  265. static int palmld_backlight_notify(int brightness)
  266. {
  267. gpio_set_value(GPIO_NR_PALMLD_BL_POWER, brightness);
  268. gpio_set_value(GPIO_NR_PALMLD_LCD_POWER, brightness);
  269. return brightness;
  270. }
  271. static void palmld_backlight_exit(struct device *dev)
  272. {
  273. gpio_free(GPIO_NR_PALMLD_BL_POWER);
  274. gpio_free(GPIO_NR_PALMLD_LCD_POWER);
  275. }
  276. static struct platform_pwm_backlight_data palmld_backlight_data = {
  277. .pwm_id = 0,
  278. .max_brightness = PALMLD_MAX_INTENSITY,
  279. .dft_brightness = PALMLD_MAX_INTENSITY,
  280. .pwm_period_ns = PALMLD_PERIOD_NS,
  281. .init = palmld_backlight_init,
  282. .notify = palmld_backlight_notify,
  283. .exit = palmld_backlight_exit,
  284. };
  285. static struct platform_device palmld_backlight = {
  286. .name = "pwm-backlight",
  287. .dev = {
  288. .parent = &pxa27x_device_pwm0.dev,
  289. .platform_data = &palmld_backlight_data,
  290. },
  291. };
  292. /******************************************************************************
  293. * IrDA
  294. ******************************************************************************/
  295. static int palmld_irda_startup(struct device *dev)
  296. {
  297. int err;
  298. err = gpio_request(GPIO_NR_PALMLD_IR_DISABLE, "IR DISABLE");
  299. if (err)
  300. goto err;
  301. err = gpio_direction_output(GPIO_NR_PALMLD_IR_DISABLE, 1);
  302. if (err)
  303. gpio_free(GPIO_NR_PALMLD_IR_DISABLE);
  304. err:
  305. return err;
  306. }
  307. static void palmld_irda_shutdown(struct device *dev)
  308. {
  309. gpio_free(GPIO_NR_PALMLD_IR_DISABLE);
  310. }
  311. static void palmld_irda_transceiver_mode(struct device *dev, int mode)
  312. {
  313. gpio_set_value(GPIO_NR_PALMLD_IR_DISABLE, mode & IR_OFF);
  314. pxa2xx_transceiver_mode(dev, mode);
  315. }
  316. static struct pxaficp_platform_data palmld_ficp_platform_data = {
  317. .startup = palmld_irda_startup,
  318. .shutdown = palmld_irda_shutdown,
  319. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  320. .transceiver_mode = palmld_irda_transceiver_mode,
  321. };
  322. /******************************************************************************
  323. * LEDs
  324. ******************************************************************************/
  325. struct gpio_led gpio_leds[] = {
  326. {
  327. .name = "palmld:green:led",
  328. .default_trigger = "none",
  329. .gpio = GPIO_NR_PALMLD_LED_GREEN,
  330. }, {
  331. .name = "palmld:amber:led",
  332. .default_trigger = "none",
  333. .gpio = GPIO_NR_PALMLD_LED_AMBER,
  334. },
  335. };
  336. static struct gpio_led_platform_data gpio_led_info = {
  337. .leds = gpio_leds,
  338. .num_leds = ARRAY_SIZE(gpio_leds),
  339. };
  340. static struct platform_device palmld_leds = {
  341. .name = "leds-gpio",
  342. .id = -1,
  343. .dev = {
  344. .platform_data = &gpio_led_info,
  345. }
  346. };
  347. /******************************************************************************
  348. * Power supply
  349. ******************************************************************************/
  350. static int power_supply_init(struct device *dev)
  351. {
  352. int ret;
  353. ret = gpio_request(GPIO_NR_PALMLD_POWER_DETECT, "CABLE_STATE_AC");
  354. if (ret)
  355. goto err1;
  356. ret = gpio_direction_input(GPIO_NR_PALMLD_POWER_DETECT);
  357. if (ret)
  358. goto err2;
  359. ret = gpio_request(GPIO_NR_PALMLD_USB_DETECT_N, "CABLE_STATE_USB");
  360. if (ret)
  361. goto err2;
  362. ret = gpio_direction_input(GPIO_NR_PALMLD_USB_DETECT_N);
  363. if (ret)
  364. goto err3;
  365. return 0;
  366. err3:
  367. gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
  368. err2:
  369. gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
  370. err1:
  371. return ret;
  372. }
  373. static int palmld_is_ac_online(void)
  374. {
  375. return gpio_get_value(GPIO_NR_PALMLD_POWER_DETECT);
  376. }
  377. static int palmld_is_usb_online(void)
  378. {
  379. return !gpio_get_value(GPIO_NR_PALMLD_USB_DETECT_N);
  380. }
  381. static void power_supply_exit(struct device *dev)
  382. {
  383. gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
  384. gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
  385. }
  386. static char *palmld_supplicants[] = {
  387. "main-battery",
  388. };
  389. static struct pda_power_pdata power_supply_info = {
  390. .init = power_supply_init,
  391. .is_ac_online = palmld_is_ac_online,
  392. .is_usb_online = palmld_is_usb_online,
  393. .exit = power_supply_exit,
  394. .supplied_to = palmld_supplicants,
  395. .num_supplicants = ARRAY_SIZE(palmld_supplicants),
  396. };
  397. static struct platform_device power_supply = {
  398. .name = "pda-power",
  399. .id = -1,
  400. .dev = {
  401. .platform_data = &power_supply_info,
  402. },
  403. };
  404. /******************************************************************************
  405. * WM97xx battery
  406. ******************************************************************************/
  407. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  408. .batt_aux = WM97XX_AUX_ID3,
  409. .temp_aux = WM97XX_AUX_ID2,
  410. .charge_gpio = -1,
  411. .max_voltage = PALMLD_BAT_MAX_VOLTAGE,
  412. .min_voltage = PALMLD_BAT_MIN_VOLTAGE,
  413. .batt_mult = 1000,
  414. .batt_div = 414,
  415. .temp_mult = 1,
  416. .temp_div = 1,
  417. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  418. .batt_name = "main-batt",
  419. };
  420. /******************************************************************************
  421. * aSoC audio
  422. ******************************************************************************/
  423. static struct palm27x_asoc_info palmld_asoc_pdata = {
  424. .jack_gpio = GPIO_NR_PALMLD_EARPHONE_DETECT,
  425. };
  426. static pxa2xx_audio_ops_t palmld_ac97_pdata = {
  427. .reset_gpio = 95,
  428. };
  429. static struct platform_device palmld_asoc = {
  430. .name = "palm27x-asoc",
  431. .id = -1,
  432. .dev = {
  433. .platform_data = &palmld_asoc_pdata,
  434. },
  435. };
  436. /******************************************************************************
  437. * HDD
  438. ******************************************************************************/
  439. static struct platform_device palmld_hdd = {
  440. .name = "pata_palmld",
  441. .id = -1,
  442. };
  443. /******************************************************************************
  444. * Framebuffer
  445. ******************************************************************************/
  446. static struct pxafb_mode_info palmld_lcd_modes[] = {
  447. {
  448. .pixclock = 57692,
  449. .xres = 320,
  450. .yres = 480,
  451. .bpp = 16,
  452. .left_margin = 32,
  453. .right_margin = 1,
  454. .upper_margin = 7,
  455. .lower_margin = 1,
  456. .hsync_len = 4,
  457. .vsync_len = 1,
  458. },
  459. };
  460. static struct pxafb_mach_info palmld_lcd_screen = {
  461. .modes = palmld_lcd_modes,
  462. .num_modes = ARRAY_SIZE(palmld_lcd_modes),
  463. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  464. };
  465. /******************************************************************************
  466. * Power management - standby
  467. ******************************************************************************/
  468. static void __init palmld_pm_init(void)
  469. {
  470. static u32 resume[] = {
  471. 0xe3a00101, /* mov r0, #0x40000000 */
  472. 0xe380060f, /* orr r0, r0, #0x00f00000 */
  473. 0xe590f008, /* ldr pc, [r0, #0x08] */
  474. };
  475. /* copy the bootloader */
  476. memcpy(phys_to_virt(PALMLD_STR_BASE), resume, sizeof(resume));
  477. }
  478. /******************************************************************************
  479. * Machine init
  480. ******************************************************************************/
  481. static struct platform_device *devices[] __initdata = {
  482. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  483. &palmld_pxa_keys,
  484. #endif
  485. &palmld_backlight,
  486. &palmld_leds,
  487. &power_supply,
  488. &palmld_asoc,
  489. &palmld_hdd,
  490. };
  491. static struct map_desc palmld_io_desc[] __initdata = {
  492. {
  493. .virtual = PALMLD_IDE_VIRT,
  494. .pfn = __phys_to_pfn(PALMLD_IDE_PHYS),
  495. .length = PALMLD_IDE_SIZE,
  496. .type = MT_DEVICE
  497. },
  498. {
  499. .virtual = PALMLD_USB_VIRT,
  500. .pfn = __phys_to_pfn(PALMLD_USB_PHYS),
  501. .length = PALMLD_USB_SIZE,
  502. .type = MT_DEVICE
  503. },
  504. };
  505. static void __init palmld_map_io(void)
  506. {
  507. pxa_map_io();
  508. iotable_init(palmld_io_desc, ARRAY_SIZE(palmld_io_desc));
  509. }
  510. static void __init palmld_init(void)
  511. {
  512. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmld_pin_config));
  513. palmld_pm_init();
  514. set_pxa_fb_info(&palmld_lcd_screen);
  515. pxa_set_mci_info(&palmld_mci_platform_data);
  516. pxa_set_ac97_info(&palmld_ac97_pdata);
  517. pxa_set_ficp_info(&palmld_ficp_platform_data);
  518. pxa_set_keypad_info(&palmld_keypad_platform_data);
  519. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  520. platform_add_devices(devices, ARRAY_SIZE(devices));
  521. }
  522. MACHINE_START(PALMLD, "Palm LifeDrive")
  523. .phys_io = PALMLD_PHYS_IO_START,
  524. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  525. .boot_params = 0xa0000100,
  526. .map_io = palmld_map_io,
  527. .init_irq = pxa27x_init_irq,
  528. .timer = &pxa_timer,
  529. .init_machine = palmld_init
  530. MACHINE_END