magician.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * Support for HTC Magician PDA phones:
  3. * i-mate JAM, O2 Xda mini, Orange SPV M500, Qtek s100, Qtek s110
  4. * and T-Mobile MDA Compact.
  5. *
  6. * Copyright (c) 2006-2007 Philipp Zabel
  7. *
  8. * Based on hx4700.c, spitz.c and others.
  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. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/delay.h>
  19. #include <linux/gpio.h>
  20. #include <linux/gpio_keys.h>
  21. #include <linux/input.h>
  22. #include <linux/mfd/htc-egpio.h>
  23. #include <linux/mfd/htc-pasic3.h>
  24. #include <linux/mtd/physmap.h>
  25. #include <linux/pda_power.h>
  26. #include <linux/pwm_backlight.h>
  27. #include <mach/hardware.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <mach/magician.h>
  31. #include <mach/mfp-pxa27x.h>
  32. #include <mach/pxa-regs.h>
  33. #include <mach/pxa2xx-regs.h>
  34. #include <mach/pxafb.h>
  35. #include <mach/i2c.h>
  36. #include <mach/mmc.h>
  37. #include <mach/irda.h>
  38. #include <mach/ohci.h>
  39. #include "devices.h"
  40. #include "generic.h"
  41. static unsigned long magician_pin_config[] __initdata = {
  42. /* SDRAM and Static Memory I/O Signals */
  43. GPIO20_nSDCS_2,
  44. GPIO21_nSDCS_3,
  45. GPIO15_nCS_1,
  46. GPIO78_nCS_2, /* PASIC3 */
  47. GPIO79_nCS_3, /* EGPIO CPLD */
  48. GPIO80_nCS_4,
  49. GPIO33_nCS_5,
  50. /* I2C */
  51. GPIO117_I2C_SCL,
  52. GPIO118_I2C_SDA,
  53. /* PWM 0 */
  54. GPIO16_PWM0_OUT,
  55. /* I2S */
  56. GPIO28_I2S_BITCLK_OUT,
  57. GPIO29_I2S_SDATA_IN,
  58. GPIO31_I2S_SYNC,
  59. GPIO113_I2S_SYSCLK,
  60. /* SSP 2 */
  61. GPIO19_SSP2_SCLK,
  62. GPIO14_SSP2_SFRM,
  63. GPIO89_SSP2_TXD,
  64. GPIO88_SSP2_RXD,
  65. /* MMC */
  66. GPIO32_MMC_CLK,
  67. GPIO92_MMC_DAT_0,
  68. GPIO109_MMC_DAT_1,
  69. GPIO110_MMC_DAT_2,
  70. GPIO111_MMC_DAT_3,
  71. GPIO112_MMC_CMD,
  72. /* LCD */
  73. GPIO58_LCD_LDD_0,
  74. GPIO59_LCD_LDD_1,
  75. GPIO60_LCD_LDD_2,
  76. GPIO61_LCD_LDD_3,
  77. GPIO62_LCD_LDD_4,
  78. GPIO63_LCD_LDD_5,
  79. GPIO64_LCD_LDD_6,
  80. GPIO65_LCD_LDD_7,
  81. GPIO66_LCD_LDD_8,
  82. GPIO67_LCD_LDD_9,
  83. GPIO68_LCD_LDD_10,
  84. GPIO69_LCD_LDD_11,
  85. GPIO70_LCD_LDD_12,
  86. GPIO71_LCD_LDD_13,
  87. GPIO72_LCD_LDD_14,
  88. GPIO73_LCD_LDD_15,
  89. GPIO74_LCD_FCLK,
  90. GPIO75_LCD_LCLK,
  91. GPIO76_LCD_PCLK,
  92. GPIO77_LCD_BIAS,
  93. /* QCI */
  94. GPIO12_CIF_DD_7,
  95. GPIO17_CIF_DD_6,
  96. GPIO50_CIF_DD_3,
  97. GPIO51_CIF_DD_2,
  98. GPIO52_CIF_DD_4,
  99. GPIO53_CIF_MCLK,
  100. GPIO54_CIF_PCLK,
  101. GPIO55_CIF_DD_1,
  102. GPIO81_CIF_DD_0,
  103. GPIO82_CIF_DD_5,
  104. GPIO84_CIF_FV,
  105. GPIO85_CIF_LV,
  106. /* Magician specific input GPIOs */
  107. GPIO9_GPIO, /* unknown */
  108. GPIO10_GPIO, /* GSM_IRQ */
  109. GPIO13_GPIO, /* CPLD_IRQ */
  110. GPIO107_GPIO, /* DS1WM_IRQ */
  111. GPIO108_GPIO, /* GSM_READY */
  112. GPIO115_GPIO, /* nPEN_IRQ */
  113. /* I2C */
  114. GPIO117_I2C_SCL,
  115. GPIO118_I2C_SDA,
  116. };
  117. /*
  118. * IRDA
  119. */
  120. static void magician_irda_transceiver_mode(struct device *dev, int mode)
  121. {
  122. gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
  123. pxa2xx_transceiver_mode(dev, mode);
  124. }
  125. static struct pxaficp_platform_data magician_ficp_info = {
  126. .transceiver_cap = IR_SIRMODE | IR_OFF,
  127. .transceiver_mode = magician_irda_transceiver_mode,
  128. };
  129. /*
  130. * GPIO Keys
  131. */
  132. static struct gpio_keys_button magician_button_table[] = {
  133. {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
  134. {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
  135. {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
  136. {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
  137. {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
  138. {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
  139. {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
  140. {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
  141. {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
  142. {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
  143. {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
  144. {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
  145. {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
  146. {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
  147. {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
  148. };
  149. static struct gpio_keys_platform_data gpio_keys_data = {
  150. .buttons = magician_button_table,
  151. .nbuttons = ARRAY_SIZE(magician_button_table),
  152. };
  153. static struct platform_device gpio_keys = {
  154. .name = "gpio-keys",
  155. .dev = {
  156. .platform_data = &gpio_keys_data,
  157. },
  158. .id = -1,
  159. };
  160. /*
  161. * EGPIO (Xilinx CPLD)
  162. *
  163. * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
  164. */
  165. static struct resource egpio_resources[] = {
  166. [0] = {
  167. .start = PXA_CS3_PHYS,
  168. .end = PXA_CS3_PHYS + 0x20,
  169. .flags = IORESOURCE_MEM,
  170. },
  171. [1] = {
  172. .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
  173. .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
  174. .flags = IORESOURCE_IRQ,
  175. },
  176. };
  177. static struct htc_egpio_chip egpio_chips[] = {
  178. [0] = {
  179. .reg_start = 0,
  180. .gpio_base = MAGICIAN_EGPIO(0, 0),
  181. .num_gpios = 24,
  182. .direction = HTC_EGPIO_OUTPUT,
  183. .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
  184. },
  185. [1] = {
  186. .reg_start = 4,
  187. .gpio_base = MAGICIAN_EGPIO(4, 0),
  188. .num_gpios = 24,
  189. .direction = HTC_EGPIO_INPUT,
  190. },
  191. };
  192. static struct htc_egpio_platform_data egpio_info = {
  193. .reg_width = 8,
  194. .bus_width = 32,
  195. .irq_base = IRQ_BOARD_START,
  196. .num_irqs = 4,
  197. .ack_register = 3,
  198. .chip = egpio_chips,
  199. .num_chips = ARRAY_SIZE(egpio_chips),
  200. };
  201. static struct platform_device egpio = {
  202. .name = "htc-egpio",
  203. .id = -1,
  204. .resource = egpio_resources,
  205. .num_resources = ARRAY_SIZE(egpio_resources),
  206. .dev = {
  207. .platform_data = &egpio_info,
  208. },
  209. };
  210. /*
  211. * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
  212. */
  213. static struct pxafb_mode_info toppoly_modes[] = {
  214. {
  215. .pixclock = 96153,
  216. .bpp = 16,
  217. .xres = 240,
  218. .yres = 320,
  219. .hsync_len = 11,
  220. .vsync_len = 3,
  221. .left_margin = 19,
  222. .upper_margin = 2,
  223. .right_margin = 10,
  224. .lower_margin = 2,
  225. .sync = 0,
  226. },
  227. };
  228. static struct pxafb_mode_info samsung_modes[] = {
  229. {
  230. .pixclock = 96153,
  231. .bpp = 16,
  232. .xres = 240,
  233. .yres = 320,
  234. .hsync_len = 8,
  235. .vsync_len = 4,
  236. .left_margin = 9,
  237. .upper_margin = 4,
  238. .right_margin = 9,
  239. .lower_margin = 4,
  240. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  241. },
  242. };
  243. static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
  244. {
  245. pr_debug("Toppoly LCD power\n");
  246. if (on) {
  247. pr_debug("on\n");
  248. gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
  249. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
  250. udelay(2000);
  251. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  252. udelay(2000);
  253. /* FIXME: enable LCDC here */
  254. udelay(2000);
  255. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
  256. udelay(2000);
  257. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
  258. } else {
  259. pr_debug("off\n");
  260. msleep(15);
  261. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
  262. udelay(500);
  263. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
  264. udelay(1000);
  265. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
  266. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  267. }
  268. }
  269. static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
  270. {
  271. pr_debug("Samsung LCD power\n");
  272. if (on) {
  273. pr_debug("on\n");
  274. if (system_rev < 3)
  275. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
  276. else
  277. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  278. mdelay(10);
  279. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
  280. mdelay(10);
  281. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
  282. mdelay(30);
  283. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
  284. mdelay(10);
  285. } else {
  286. pr_debug("off\n");
  287. mdelay(10);
  288. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
  289. mdelay(30);
  290. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
  291. mdelay(10);
  292. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
  293. mdelay(10);
  294. if (system_rev < 3)
  295. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
  296. else
  297. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  298. }
  299. }
  300. static struct pxafb_mach_info toppoly_info = {
  301. .modes = toppoly_modes,
  302. .num_modes = 1,
  303. .fixed_modes = 1,
  304. .lcd_conn = LCD_COLOR_TFT_16BPP,
  305. .pxafb_lcd_power = toppoly_lcd_power,
  306. };
  307. static struct pxafb_mach_info samsung_info = {
  308. .modes = samsung_modes,
  309. .num_modes = 1,
  310. .fixed_modes = 1,
  311. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
  312. LCD_ALTERNATE_MAPPING,
  313. .pxafb_lcd_power = samsung_lcd_power,
  314. };
  315. /*
  316. * Backlight
  317. */
  318. static int magician_backlight_init(struct device *dev)
  319. {
  320. int ret;
  321. ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
  322. if (ret)
  323. goto err;
  324. ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
  325. if (ret)
  326. goto err2;
  327. return 0;
  328. err2:
  329. gpio_free(EGPIO_MAGICIAN_BL_POWER);
  330. err:
  331. return ret;
  332. }
  333. static int magician_backlight_notify(int brightness)
  334. {
  335. gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
  336. if (brightness >= 200) {
  337. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
  338. return brightness - 72;
  339. } else {
  340. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
  341. return brightness;
  342. }
  343. }
  344. static void magician_backlight_exit(struct device *dev)
  345. {
  346. gpio_free(EGPIO_MAGICIAN_BL_POWER);
  347. gpio_free(EGPIO_MAGICIAN_BL_POWER2);
  348. }
  349. static struct platform_pwm_backlight_data backlight_data = {
  350. .pwm_id = 0,
  351. .max_brightness = 272,
  352. .dft_brightness = 100,
  353. .pwm_period_ns = 30923,
  354. .init = magician_backlight_init,
  355. .notify = magician_backlight_notify,
  356. .exit = magician_backlight_exit,
  357. };
  358. static struct platform_device backlight = {
  359. .name = "pwm-backlight",
  360. .id = -1,
  361. .dev = {
  362. .parent = &pxa27x_device_pwm0.dev,
  363. .platform_data = &backlight_data,
  364. },
  365. };
  366. /*
  367. * LEDs
  368. */
  369. static struct gpio_led gpio_leds[] = {
  370. {
  371. .name = "magician::vibra",
  372. .default_trigger = "none",
  373. .gpio = GPIO22_MAGICIAN_VIBRA_EN,
  374. },
  375. {
  376. .name = "magician::phone_bl",
  377. .default_trigger = "none",
  378. .gpio = GPIO103_MAGICIAN_LED_KP,
  379. },
  380. };
  381. static struct gpio_led_platform_data gpio_led_info = {
  382. .leds = gpio_leds,
  383. .num_leds = ARRAY_SIZE(gpio_leds),
  384. };
  385. static struct platform_device leds_gpio = {
  386. .name = "leds-gpio",
  387. .id = -1,
  388. .dev = {
  389. .platform_data = &gpio_led_info,
  390. },
  391. };
  392. static struct pasic3_led pasic3_leds[] = {
  393. {
  394. .led = {
  395. .name = "magician:red",
  396. .default_trigger = "ds2760-battery.0-charging",
  397. },
  398. .hw_num = 0,
  399. .bit2 = PASIC3_BIT2_LED0,
  400. .mask = PASIC3_MASK_LED0,
  401. },
  402. {
  403. .led = {
  404. .name = "magician:green",
  405. .default_trigger = "ds2760-battery.0-charging-or-full",
  406. },
  407. .hw_num = 1,
  408. .bit2 = PASIC3_BIT2_LED1,
  409. .mask = PASIC3_MASK_LED1,
  410. },
  411. {
  412. .led = {
  413. .name = "magician:blue",
  414. .default_trigger = "bluetooth",
  415. },
  416. .hw_num = 2,
  417. .bit2 = PASIC3_BIT2_LED2,
  418. .mask = PASIC3_MASK_LED2,
  419. },
  420. };
  421. static struct platform_device pasic3;
  422. static struct pasic3_leds_machinfo pasic3_leds_info = {
  423. .num_leds = ARRAY_SIZE(pasic3_leds),
  424. .power_gpio = EGPIO_MAGICIAN_LED_POWER,
  425. .leds = pasic3_leds,
  426. };
  427. /*
  428. * PASIC3 with DS1WM
  429. */
  430. static struct resource pasic3_resources[] = {
  431. [0] = {
  432. .start = PXA_CS2_PHYS,
  433. .end = PXA_CS2_PHYS + 0x1b,
  434. .flags = IORESOURCE_MEM,
  435. },
  436. /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
  437. [1] = {
  438. .start = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
  439. .end = gpio_to_irq(GPIO107_MAGICIAN_DS1WM_IRQ),
  440. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  441. }
  442. };
  443. static struct pasic3_platform_data pasic3_platform_data = {
  444. .bus_shift = 2,
  445. .led_pdata = &pasic3_leds_info,
  446. .clock_rate = 4000000,
  447. };
  448. static struct platform_device pasic3 = {
  449. .name = "pasic3",
  450. .id = -1,
  451. .num_resources = ARRAY_SIZE(pasic3_resources),
  452. .resource = pasic3_resources,
  453. .dev = {
  454. .platform_data = &pasic3_platform_data,
  455. },
  456. };
  457. /*
  458. * External power
  459. */
  460. static int power_supply_init(struct device *dev)
  461. {
  462. int ret;
  463. ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
  464. if (ret)
  465. goto err_cs_ac;
  466. ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB");
  467. if (ret)
  468. goto err_cs_usb;
  469. ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN");
  470. if (ret)
  471. goto err_chg_en;
  472. ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN");
  473. if (!ret)
  474. ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0);
  475. if (ret)
  476. goto err_nchg_en;
  477. return 0;
  478. err_nchg_en:
  479. gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
  480. err_chg_en:
  481. gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
  482. err_cs_usb:
  483. gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
  484. err_cs_ac:
  485. return ret;
  486. }
  487. static int magician_is_ac_online(void)
  488. {
  489. return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
  490. }
  491. static int magician_is_usb_online(void)
  492. {
  493. return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
  494. }
  495. static void magician_set_charge(int flags)
  496. {
  497. gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
  498. gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
  499. }
  500. static void power_supply_exit(struct device *dev)
  501. {
  502. gpio_free(GPIO30_MAGICIAN_nCHARGE_EN);
  503. gpio_free(EGPIO_MAGICIAN_CHARGE_EN);
  504. gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB);
  505. gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
  506. }
  507. static char *magician_supplicants[] = {
  508. "ds2760-battery.0", "backup-battery"
  509. };
  510. static struct pda_power_pdata power_supply_info = {
  511. .init = power_supply_init,
  512. .is_ac_online = magician_is_ac_online,
  513. .is_usb_online = magician_is_usb_online,
  514. .set_charge = magician_set_charge,
  515. .exit = power_supply_exit,
  516. .supplied_to = magician_supplicants,
  517. .num_supplicants = ARRAY_SIZE(magician_supplicants),
  518. };
  519. static struct resource power_supply_resources[] = {
  520. [0] = {
  521. .name = "ac",
  522. .flags = IORESOURCE_IRQ,
  523. .start = IRQ_MAGICIAN_AC,
  524. .end = IRQ_MAGICIAN_AC,
  525. },
  526. [1] = {
  527. .name = "usb",
  528. .flags = IORESOURCE_IRQ,
  529. .start = IRQ_MAGICIAN_AC,
  530. .end = IRQ_MAGICIAN_AC,
  531. },
  532. };
  533. static struct platform_device power_supply = {
  534. .name = "pda-power",
  535. .id = -1,
  536. .dev = {
  537. .platform_data = &power_supply_info,
  538. },
  539. .resource = power_supply_resources,
  540. .num_resources = ARRAY_SIZE(power_supply_resources),
  541. };
  542. /*
  543. * MMC/SD
  544. */
  545. static int magician_mci_init(struct device *dev,
  546. irq_handler_t detect_irq, void *data)
  547. {
  548. int err;
  549. err = request_irq(IRQ_MAGICIAN_SD, detect_irq,
  550. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  551. "MMC card detect", data);
  552. if (err)
  553. goto err_request_irq;
  554. err = gpio_request(EGPIO_MAGICIAN_SD_POWER, "SD_POWER");
  555. if (err)
  556. goto err_request_power;
  557. err = gpio_request(EGPIO_MAGICIAN_nSD_READONLY, "nSD_READONLY");
  558. if (err)
  559. goto err_request_readonly;
  560. return 0;
  561. err_request_readonly:
  562. gpio_free(EGPIO_MAGICIAN_SD_POWER);
  563. err_request_power:
  564. free_irq(IRQ_MAGICIAN_SD, data);
  565. err_request_irq:
  566. return err;
  567. }
  568. static void magician_mci_setpower(struct device *dev, unsigned int vdd)
  569. {
  570. struct pxamci_platform_data *pdata = dev->platform_data;
  571. gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
  572. }
  573. static int magician_mci_get_ro(struct device *dev)
  574. {
  575. return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
  576. }
  577. static void magician_mci_exit(struct device *dev, void *data)
  578. {
  579. gpio_free(EGPIO_MAGICIAN_nSD_READONLY);
  580. gpio_free(EGPIO_MAGICIAN_SD_POWER);
  581. free_irq(IRQ_MAGICIAN_SD, data);
  582. }
  583. static struct pxamci_platform_data magician_mci_info = {
  584. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  585. .init = magician_mci_init,
  586. .get_ro = magician_mci_get_ro,
  587. .setpower = magician_mci_setpower,
  588. .exit = magician_mci_exit,
  589. };
  590. /*
  591. * USB OHCI
  592. */
  593. static struct pxaohci_platform_data magician_ohci_info = {
  594. .port_mode = PMM_PERPORT_MODE,
  595. .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
  596. .power_budget = 0,
  597. };
  598. /*
  599. * StrataFlash
  600. */
  601. static void magician_set_vpp(struct map_info *map, int vpp)
  602. {
  603. gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
  604. }
  605. #define PXA_CS_SIZE 0x04000000
  606. static struct resource strataflash_resource = {
  607. .start = PXA_CS0_PHYS,
  608. .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
  609. .flags = IORESOURCE_MEM,
  610. };
  611. static struct physmap_flash_data strataflash_data = {
  612. .width = 4,
  613. .set_vpp = magician_set_vpp,
  614. };
  615. static struct platform_device strataflash = {
  616. .name = "physmap-flash",
  617. .id = -1,
  618. .resource = &strataflash_resource,
  619. .num_resources = 1,
  620. .dev = {
  621. .platform_data = &strataflash_data,
  622. },
  623. };
  624. /*
  625. * Platform devices
  626. */
  627. static struct platform_device *devices[] __initdata = {
  628. &gpio_keys,
  629. &egpio,
  630. &backlight,
  631. &pasic3,
  632. &power_supply,
  633. &strataflash,
  634. &leds_gpio,
  635. };
  636. static void __init magician_init(void)
  637. {
  638. void __iomem *cpld;
  639. int lcd_select;
  640. int err;
  641. gpio_request(GPIO13_MAGICIAN_CPLD_IRQ, "CPLD_IRQ");
  642. gpio_request(GPIO107_MAGICIAN_DS1WM_IRQ, "DS1WM_IRQ");
  643. pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
  644. platform_add_devices(devices, ARRAY_SIZE(devices));
  645. err = gpio_request(GPIO83_MAGICIAN_nIR_EN, "nIR_EN");
  646. if (!err) {
  647. gpio_direction_output(GPIO83_MAGICIAN_nIR_EN, 1);
  648. pxa_set_ficp_info(&magician_ficp_info);
  649. }
  650. pxa_set_i2c_info(NULL);
  651. pxa_set_mci_info(&magician_mci_info);
  652. pxa_set_ohci_info(&magician_ohci_info);
  653. /* Check LCD type we have */
  654. cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
  655. if (cpld) {
  656. u8 board_id = __raw_readb(cpld+0x14);
  657. iounmap(cpld);
  658. system_rev = board_id & 0x7;
  659. lcd_select = board_id & 0x8;
  660. pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
  661. if (lcd_select && (system_rev < 3)) {
  662. gpio_request(GPIO75_MAGICIAN_SAMSUNG_POWER, "SAMSUNG_POWER");
  663. gpio_direction_output(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
  664. }
  665. gpio_request(GPIO104_MAGICIAN_LCD_POWER_1, "LCD_POWER_1");
  666. gpio_request(GPIO105_MAGICIAN_LCD_POWER_2, "LCD_POWER_2");
  667. gpio_request(GPIO106_MAGICIAN_LCD_POWER_3, "LCD_POWER_3");
  668. gpio_direction_output(GPIO104_MAGICIAN_LCD_POWER_1, 0);
  669. gpio_direction_output(GPIO105_MAGICIAN_LCD_POWER_2, 0);
  670. gpio_direction_output(GPIO106_MAGICIAN_LCD_POWER_3, 0);
  671. set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
  672. } else
  673. pr_err("LCD detection: CPLD mapping failed\n");
  674. }
  675. MACHINE_START(MAGICIAN, "HTC Magician")
  676. .phys_io = 0x40000000,
  677. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  678. .boot_params = 0xa0000100,
  679. .map_io = pxa_map_io,
  680. .init_irq = pxa27x_init_irq,
  681. .init_machine = magician_init,
  682. .timer = &pxa_timer,
  683. MACHINE_END