/kern_oII/arch/arm/mach-pxa/magician.c

http://omnia2droid.googlecode.com/ · C · 826 lines · 646 code · 105 blank · 75 comment · 17 complexity · 006a8b0ec275e73dd202c38d467cc971 MD5 · raw file

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