palmld.c 14 KB

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