magician.c 18 KB

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