magician.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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-pasic3.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <linux/pda_power.h>
  25. #include <linux/platform_data/gpio-htc-egpio.h>
  26. #include <linux/pwm.h>
  27. #include <linux/pwm_backlight.h>
  28. #include <linux/regulator/driver.h>
  29. #include <linux/regulator/fixed.h>
  30. #include <linux/regulator/gpio-regulator.h>
  31. #include <linux/regulator/machine.h>
  32. #include <linux/usb/gpio_vbus.h>
  33. #include <linux/i2c/pxa-i2c.h>
  34. #include <mach/hardware.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/system_info.h>
  38. #include "pxa27x.h"
  39. #include <mach/magician.h>
  40. #include <linux/platform_data/video-pxafb.h>
  41. #include <linux/platform_data/mmc-pxamci.h>
  42. #include <linux/platform_data/irda-pxaficp.h>
  43. #include <linux/platform_data/usb-ohci-pxa27x.h>
  44. #include <linux/regulator/max1586.h>
  45. #include <linux/platform_data/pxa2xx_udc.h>
  46. #include "udc.h"
  47. #include "pxa27x-udc.h"
  48. #include "devices.h"
  49. #include "generic.h"
  50. static unsigned long magician_pin_config[] __initdata = {
  51. /* SDRAM and Static Memory I/O Signals */
  52. GPIO20_nSDCS_2,
  53. GPIO21_nSDCS_3,
  54. GPIO15_nCS_1,
  55. GPIO78_nCS_2, /* PASIC3 */
  56. GPIO79_nCS_3, /* EGPIO CPLD */
  57. GPIO80_nCS_4,
  58. GPIO33_nCS_5,
  59. /* I2C UDA1380 + OV9640 */
  60. GPIO117_I2C_SCL,
  61. GPIO118_I2C_SDA,
  62. /* PWM 0 - LCD backlight */
  63. GPIO16_PWM0_OUT,
  64. /* I2S UDA1380 capture */
  65. GPIO28_I2S_BITCLK_OUT,
  66. GPIO29_I2S_SDATA_IN,
  67. GPIO31_I2S_SYNC,
  68. GPIO113_I2S_SYSCLK,
  69. /* SSP 1 UDA1380 playback */
  70. GPIO23_SSP1_SCLK,
  71. GPIO24_SSP1_SFRM,
  72. GPIO25_SSP1_TXD,
  73. /* SSP 2 TSC2046 touchscreen */
  74. GPIO19_SSP2_SCLK,
  75. GPIO14_SSP2_SFRM,
  76. GPIO89_SSP2_TXD,
  77. GPIO88_SSP2_RXD,
  78. /* MMC/SD/SDHC slot */
  79. GPIO32_MMC_CLK,
  80. GPIO92_MMC_DAT_0,
  81. GPIO109_MMC_DAT_1,
  82. GPIO110_MMC_DAT_2,
  83. GPIO111_MMC_DAT_3,
  84. GPIO112_MMC_CMD,
  85. /* LCD */
  86. GPIOxx_LCD_TFT_16BPP,
  87. /* QCI camera interface */
  88. GPIO12_CIF_DD_7,
  89. GPIO17_CIF_DD_6,
  90. GPIO50_CIF_DD_3,
  91. GPIO51_CIF_DD_2,
  92. GPIO52_CIF_DD_4,
  93. GPIO53_CIF_MCLK,
  94. GPIO54_CIF_PCLK,
  95. GPIO55_CIF_DD_1,
  96. GPIO81_CIF_DD_0,
  97. GPIO82_CIF_DD_5,
  98. GPIO84_CIF_FV,
  99. GPIO85_CIF_LV,
  100. /* Magician specific input GPIOs */
  101. GPIO9_GPIO, /* unknown */
  102. GPIO10_GPIO, /* GSM_IRQ */
  103. GPIO13_GPIO, /* CPLD_IRQ */
  104. GPIO107_GPIO, /* DS1WM_IRQ */
  105. GPIO108_GPIO, /* GSM_READY */
  106. GPIO115_GPIO, /* nPEN_IRQ */
  107. };
  108. /*
  109. * IrDA
  110. */
  111. static struct pxaficp_platform_data magician_ficp_info = {
  112. .gpio_pwdown = GPIO83_MAGICIAN_nIR_EN,
  113. .transceiver_cap = IR_SIRMODE | IR_OFF,
  114. .gpio_pwdown_inverted = 0,
  115. };
  116. /*
  117. * GPIO Keys
  118. */
  119. #define INIT_KEY(_code, _gpio, _desc) \
  120. { \
  121. .code = KEY_##_code, \
  122. .gpio = _gpio, \
  123. .desc = _desc, \
  124. .type = EV_KEY, \
  125. .wakeup = 1, \
  126. }
  127. static struct gpio_keys_button magician_button_table[] = {
  128. INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
  129. INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
  130. INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
  131. INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
  132. INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
  133. INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
  134. INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
  135. INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
  136. INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
  137. INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
  138. INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
  139. INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
  140. INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
  141. INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
  142. INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
  143. };
  144. static struct gpio_keys_platform_data gpio_keys_data = {
  145. .buttons = magician_button_table,
  146. .nbuttons = ARRAY_SIZE(magician_button_table),
  147. };
  148. static struct platform_device gpio_keys = {
  149. .name = "gpio-keys",
  150. .dev = {
  151. .platform_data = &gpio_keys_data,
  152. },
  153. .id = -1,
  154. };
  155. /*
  156. * EGPIO (Xilinx CPLD)
  157. *
  158. * 32-bit aligned 8-bit registers
  159. * 16 possible registers (reg windows size), only 7 used:
  160. * 3x output, 1x irq, 3x input
  161. */
  162. static struct resource egpio_resources[] = {
  163. [0] = {
  164. .start = PXA_CS3_PHYS,
  165. .end = PXA_CS3_PHYS + 0x20 - 1,
  166. .flags = IORESOURCE_MEM,
  167. },
  168. [1] = {
  169. .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
  170. .end = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
  171. .flags = IORESOURCE_IRQ,
  172. },
  173. };
  174. static struct htc_egpio_chip egpio_chips[] = {
  175. [0] = {
  176. .reg_start = 0,
  177. .gpio_base = MAGICIAN_EGPIO(0, 0),
  178. .num_gpios = 24,
  179. .direction = HTC_EGPIO_OUTPUT,
  180. /*
  181. * Depends on modules configuration
  182. */
  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. * PXAFB 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 = 226469,
  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: %s\n", on ? "on" : "off");
  246. if (on) {
  247. gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
  248. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
  249. udelay(2000);
  250. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  251. udelay(2000);
  252. /* FIXME: enable LCDC here */
  253. udelay(2000);
  254. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
  255. udelay(2000);
  256. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
  257. } else {
  258. msleep(15);
  259. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
  260. udelay(500);
  261. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
  262. udelay(1000);
  263. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
  264. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  265. }
  266. }
  267. static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
  268. {
  269. pr_debug("Samsung LCD power: %s\n", on ? "on" : "off");
  270. if (on) {
  271. if (system_rev < 3)
  272. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
  273. else
  274. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  275. mdelay(6);
  276. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
  277. mdelay(6); /* Avdd -> Voff >5ms */
  278. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
  279. mdelay(16); /* Voff -> Von >(5+10)ms */
  280. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
  281. } else {
  282. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
  283. mdelay(16);
  284. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
  285. mdelay(6);
  286. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
  287. mdelay(6);
  288. if (system_rev < 3)
  289. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
  290. else
  291. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  292. }
  293. }
  294. static struct pxafb_mach_info toppoly_info = {
  295. .modes = toppoly_modes,
  296. .num_modes = 1,
  297. .fixed_modes = 1,
  298. .lcd_conn = LCD_COLOR_TFT_16BPP,
  299. .pxafb_lcd_power = toppoly_lcd_power,
  300. };
  301. static struct pxafb_mach_info samsung_info = {
  302. .modes = samsung_modes,
  303. .num_modes = 1,
  304. .fixed_modes = 1,
  305. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
  306. LCD_ALTERNATE_MAPPING,
  307. .pxafb_lcd_power = samsung_lcd_power,
  308. };
  309. /*
  310. * Backlight
  311. */
  312. static struct pwm_lookup magician_pwm_lookup[] = {
  313. PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight", NULL, 30923,
  314. PWM_POLARITY_NORMAL),
  315. };
  316. /*
  317. * fixed regulator for pwm_backlight
  318. */
  319. static struct regulator_consumer_supply pwm_backlight_supply[] = {
  320. REGULATOR_SUPPLY("power", "pwm_backlight"),
  321. };
  322. static struct gpio magician_bl_gpios[] = {
  323. { EGPIO_MAGICIAN_BL_POWER, GPIOF_DIR_OUT, "Backlight power" },
  324. { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" },
  325. };
  326. static int magician_backlight_init(struct device *dev)
  327. {
  328. return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios));
  329. }
  330. static int magician_backlight_notify(struct device *dev, int brightness)
  331. {
  332. pr_debug("Brightness = %i\n", brightness);
  333. gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
  334. if (brightness >= 200) {
  335. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
  336. return brightness - 72;
  337. } else {
  338. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
  339. return brightness;
  340. }
  341. }
  342. static void magician_backlight_exit(struct device *dev)
  343. {
  344. gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios));
  345. }
  346. /*
  347. * LCD PWM backlight (main)
  348. *
  349. * MP1521 frequency should be:
  350. * 100-400 Hz = 2 .5*10^6 - 10 *10^6 ns
  351. */
  352. static struct platform_pwm_backlight_data backlight_data = {
  353. .max_brightness = 272,
  354. .dft_brightness = 100,
  355. .enable_gpio = -1,
  356. .init = magician_backlight_init,
  357. .notify = magician_backlight_notify,
  358. .exit = magician_backlight_exit,
  359. };
  360. static struct platform_device backlight = {
  361. .name = "pwm-backlight",
  362. .id = -1,
  363. .dev = {
  364. .parent = &pxa27x_device_pwm0.dev,
  365. .platform_data = &backlight_data,
  366. },
  367. };
  368. /*
  369. * GPIO LEDs, Phone keys backlight, vibra
  370. */
  371. static struct gpio_led gpio_leds[] = {
  372. {
  373. .name = "magician::vibra",
  374. .default_trigger = "none",
  375. .gpio = GPIO22_MAGICIAN_VIBRA_EN,
  376. },
  377. {
  378. .name = "magician::phone_bl",
  379. .default_trigger = "backlight",
  380. .gpio = GPIO103_MAGICIAN_LED_KP,
  381. },
  382. };
  383. static struct gpio_led_platform_data gpio_led_info = {
  384. .leds = gpio_leds,
  385. .num_leds = ARRAY_SIZE(gpio_leds),
  386. };
  387. static struct platform_device leds_gpio = {
  388. .name = "leds-gpio",
  389. .id = -1,
  390. .dev = {
  391. .platform_data = &gpio_led_info,
  392. },
  393. };
  394. /*
  395. * PASIC3 with DS1WM
  396. */
  397. static struct resource pasic3_resources[] = {
  398. [0] = {
  399. .start = PXA_CS2_PHYS,
  400. .end = PXA_CS2_PHYS + 0x1b,
  401. .flags = IORESOURCE_MEM,
  402. },
  403. /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
  404. [1] = {
  405. .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  406. .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  407. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  408. }
  409. };
  410. static struct pasic3_platform_data pasic3_platform_data = {
  411. .clock_rate = 4000000,
  412. };
  413. static struct platform_device pasic3 = {
  414. .name = "pasic3",
  415. .id = -1,
  416. .num_resources = ARRAY_SIZE(pasic3_resources),
  417. .resource = pasic3_resources,
  418. .dev = {
  419. .platform_data = &pasic3_platform_data,
  420. },
  421. };
  422. /*
  423. * PXA UDC
  424. */
  425. static void magician_udc_command(int cmd)
  426. {
  427. if (cmd == PXA2XX_UDC_CMD_CONNECT)
  428. UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
  429. else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
  430. UP2OCR &= ~(UP2OCR_DPPUE | UP2OCR_DPPUBE);
  431. }
  432. static struct pxa2xx_udc_mach_info magician_udc_info __initdata = {
  433. .udc_command = magician_udc_command,
  434. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  435. };
  436. /*
  437. * USB device VBus detection
  438. */
  439. static struct resource gpio_vbus_resource = {
  440. .flags = IORESOURCE_IRQ,
  441. .start = IRQ_MAGICIAN_VBUS,
  442. .end = IRQ_MAGICIAN_VBUS,
  443. };
  444. static struct gpio_vbus_mach_info gpio_vbus_info = {
  445. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  446. .gpio_vbus = EGPIO_MAGICIAN_CABLE_VBUS,
  447. };
  448. static struct platform_device gpio_vbus = {
  449. .name = "gpio-vbus",
  450. .id = -1,
  451. .num_resources = 1,
  452. .resource = &gpio_vbus_resource,
  453. .dev = {
  454. .platform_data = &gpio_vbus_info,
  455. },
  456. };
  457. /*
  458. * External power
  459. */
  460. static int magician_supply_init(struct device *dev)
  461. {
  462. int ret = -1;
  463. ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger");
  464. if (ret) {
  465. pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret);
  466. goto err_ac;
  467. }
  468. ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted");
  469. if (ret) {
  470. pr_err("Cannot request cable detection GPIO (%i)\n", ret);
  471. goto err_usb;
  472. }
  473. return 0;
  474. err_usb:
  475. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  476. err_ac:
  477. return ret;
  478. }
  479. static void magician_set_charge(int flags)
  480. {
  481. if (flags & PDA_POWER_CHARGE_AC) {
  482. pr_debug("Charging from AC\n");
  483. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  484. } else if (flags & PDA_POWER_CHARGE_USB) {
  485. pr_debug("Charging from USB\n");
  486. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  487. } else {
  488. pr_debug("Charging disabled\n");
  489. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0);
  490. }
  491. }
  492. static int magician_is_ac_online(void)
  493. {
  494. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  495. gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */
  496. }
  497. static int magician_is_usb_online(void)
  498. {
  499. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  500. (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */
  501. }
  502. static void magician_supply_exit(struct device *dev)
  503. {
  504. gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED);
  505. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  506. }
  507. static char *magician_supplicants[] = {
  508. "ds2760-battery.0", "backup-battery"
  509. };
  510. static struct pda_power_pdata power_supply_info = {
  511. .init = magician_supply_init,
  512. .exit = magician_supply_exit,
  513. .is_ac_online = magician_is_ac_online,
  514. .is_usb_online = magician_is_usb_online,
  515. .set_charge = magician_set_charge,
  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 | IORESOURCE_IRQ_HIGHEDGE |
  523. IORESOURCE_IRQ_LOWEDGE,
  524. .start = IRQ_MAGICIAN_VBUS,
  525. .end = IRQ_MAGICIAN_VBUS,
  526. },
  527. [1] = {
  528. .name = "usb",
  529. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  530. IORESOURCE_IRQ_LOWEDGE,
  531. .start = IRQ_MAGICIAN_VBUS,
  532. .end = IRQ_MAGICIAN_VBUS,
  533. },
  534. };
  535. static struct platform_device power_supply = {
  536. .name = "pda-power",
  537. .id = -1,
  538. .dev = {
  539. .platform_data = &power_supply_info,
  540. },
  541. .resource = power_supply_resources,
  542. .num_resources = ARRAY_SIZE(power_supply_resources),
  543. };
  544. /*
  545. * Battery charger
  546. */
  547. static struct regulator_consumer_supply bq24022_consumers[] = {
  548. REGULATOR_SUPPLY("vbus_draw", NULL),
  549. REGULATOR_SUPPLY("ac_draw", NULL),
  550. };
  551. static struct regulator_init_data bq24022_init_data = {
  552. .constraints = {
  553. .max_uA = 500000,
  554. .valid_ops_mask = REGULATOR_CHANGE_CURRENT |
  555. REGULATOR_CHANGE_STATUS,
  556. },
  557. .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
  558. .consumer_supplies = bq24022_consumers,
  559. };
  560. static struct gpio bq24022_gpios[] = {
  561. { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
  562. };
  563. static struct gpio_regulator_state bq24022_states[] = {
  564. { .value = 100000, .gpios = (0 << 0) },
  565. { .value = 500000, .gpios = (1 << 0) },
  566. };
  567. static struct gpio_regulator_config bq24022_info = {
  568. .supply_name = "bq24022",
  569. .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
  570. .enable_high = 0,
  571. .enabled_at_boot = 1,
  572. .gpios = bq24022_gpios,
  573. .nr_gpios = ARRAY_SIZE(bq24022_gpios),
  574. .states = bq24022_states,
  575. .nr_states = ARRAY_SIZE(bq24022_states),
  576. .type = REGULATOR_CURRENT,
  577. .init_data = &bq24022_init_data,
  578. };
  579. static struct platform_device bq24022 = {
  580. .name = "gpio-regulator",
  581. .id = -1,
  582. .dev = {
  583. .platform_data = &bq24022_info,
  584. },
  585. };
  586. /*
  587. * Vcore regulator MAX1587A
  588. */
  589. static struct regulator_consumer_supply magician_max1587a_consumers[] = {
  590. REGULATOR_SUPPLY("vcc_core", NULL),
  591. };
  592. static struct regulator_init_data magician_max1587a_v3_info = {
  593. .constraints = {
  594. .name = "vcc_core range",
  595. .min_uV = 700000,
  596. .max_uV = 1475000,
  597. .always_on = 1,
  598. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  599. },
  600. .consumer_supplies = magician_max1587a_consumers,
  601. .num_consumer_supplies = ARRAY_SIZE(magician_max1587a_consumers),
  602. };
  603. static struct max1586_subdev_data magician_max1587a_subdevs[] = {
  604. {
  605. .name = "vcc_core",
  606. .id = MAX1586_V3,
  607. .platform_data = &magician_max1587a_v3_info,
  608. }
  609. };
  610. static struct max1586_platform_data magician_max1587a_info = {
  611. .subdevs = magician_max1587a_subdevs,
  612. .num_subdevs = ARRAY_SIZE(magician_max1587a_subdevs),
  613. /*
  614. * NOTICE measured directly on the PCB (board_id == 0x3a), but
  615. * if R24 is present, it will boost the voltage
  616. * (write 1.475V, get 1.645V and smoke)
  617. */
  618. .v3_gain = MAX1586_GAIN_NO_R24,
  619. };
  620. static struct i2c_board_info magician_pwr_i2c_board_info[] __initdata = {
  621. {
  622. I2C_BOARD_INFO("max1586", 0x14),
  623. .platform_data = &magician_max1587a_info,
  624. },
  625. };
  626. /*
  627. * MMC/SD
  628. */
  629. static int magician_mci_init(struct device *dev,
  630. irq_handler_t detect_irq, void *data)
  631. {
  632. return request_irq(IRQ_MAGICIAN_SD, detect_irq, 0,
  633. "mmc card detect", data);
  634. }
  635. static void magician_mci_exit(struct device *dev, void *data)
  636. {
  637. free_irq(IRQ_MAGICIAN_SD, data);
  638. }
  639. static struct pxamci_platform_data magician_mci_info = {
  640. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  641. .init = magician_mci_init,
  642. .exit = magician_mci_exit,
  643. .gpio_card_detect = -1,
  644. .gpio_card_ro = EGPIO_MAGICIAN_nSD_READONLY,
  645. .gpio_card_ro_invert = 1,
  646. .gpio_power = EGPIO_MAGICIAN_SD_POWER,
  647. };
  648. /*
  649. * USB OHCI
  650. */
  651. static struct pxaohci_platform_data magician_ohci_info = {
  652. .port_mode = PMM_PERPORT_MODE,
  653. /* port1: CSR Bluetooth, port2: OTG with UDC */
  654. .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
  655. .power_budget = 0,
  656. .power_on_delay = 100,
  657. };
  658. /*
  659. * StrataFlash
  660. */
  661. static int magician_flash_init(struct platform_device *pdev)
  662. {
  663. int ret = gpio_request(EGPIO_MAGICIAN_FLASH_VPP, "flash Vpp enable");
  664. if (ret) {
  665. pr_err("Cannot request flash enable GPIO (%i)\n", ret);
  666. return ret;
  667. }
  668. ret = gpio_direction_output(EGPIO_MAGICIAN_FLASH_VPP, 1);
  669. if (ret) {
  670. pr_err("Cannot set direction for flash enable (%i)\n", ret);
  671. gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
  672. }
  673. return ret;
  674. }
  675. static void magician_set_vpp(struct platform_device *pdev, int vpp)
  676. {
  677. gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
  678. }
  679. static void magician_flash_exit(struct platform_device *pdev)
  680. {
  681. gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
  682. }
  683. static struct resource strataflash_resource = {
  684. .start = PXA_CS0_PHYS,
  685. .end = PXA_CS0_PHYS + SZ_64M - 1,
  686. .flags = IORESOURCE_MEM,
  687. };
  688. static struct mtd_partition magician_flash_parts[] = {
  689. {
  690. .name = "Bootloader",
  691. .offset = 0x0,
  692. .size = 0x40000,
  693. .mask_flags = MTD_WRITEABLE, /* EXPERIMENTAL */
  694. },
  695. {
  696. .name = "Linux Kernel",
  697. .offset = 0x40000,
  698. .size = MTDPART_SIZ_FULL,
  699. },
  700. };
  701. /*
  702. * physmap-flash driver
  703. */
  704. static struct physmap_flash_data strataflash_data = {
  705. .width = 4,
  706. .init = magician_flash_init,
  707. .set_vpp = magician_set_vpp,
  708. .exit = magician_flash_exit,
  709. .parts = magician_flash_parts,
  710. .nr_parts = ARRAY_SIZE(magician_flash_parts),
  711. };
  712. static struct platform_device strataflash = {
  713. .name = "physmap-flash",
  714. .id = -1,
  715. .resource = &strataflash_resource,
  716. .num_resources = 1,
  717. .dev = {
  718. .platform_data = &strataflash_data,
  719. },
  720. };
  721. /*
  722. * PXA I2C main controller
  723. */
  724. static struct i2c_pxa_platform_data i2c_info = {
  725. /* OV9640 I2C device doesn't support fast mode */
  726. .fast_mode = 0,
  727. };
  728. /*
  729. * PXA I2C power controller
  730. */
  731. static struct i2c_pxa_platform_data magician_i2c_power_info = {
  732. .fast_mode = 1,
  733. };
  734. /*
  735. * Platform devices
  736. */
  737. static struct platform_device *devices[] __initdata = {
  738. &gpio_keys,
  739. &egpio,
  740. &backlight,
  741. &pasic3,
  742. &bq24022,
  743. &gpio_vbus,
  744. &power_supply,
  745. &strataflash,
  746. &leds_gpio,
  747. };
  748. static struct gpio magician_global_gpios[] = {
  749. { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" },
  750. { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
  751. /* NOTICE valid LCD init sequence */
  752. { GPIO106_MAGICIAN_LCD_DCDC_NRESET, GPIOF_OUT_INIT_LOW, "LCD DCDC nreset" },
  753. { GPIO104_MAGICIAN_LCD_VOFF_EN, GPIOF_OUT_INIT_LOW, "LCD VOFF enable" },
  754. { GPIO105_MAGICIAN_LCD_VON_EN, GPIOF_OUT_INIT_LOW, "LCD VON enable" },
  755. };
  756. static void __init magician_init(void)
  757. {
  758. void __iomem *cpld;
  759. int lcd_select;
  760. int err;
  761. pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
  762. err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
  763. if (err)
  764. pr_err("magician: Failed to request global GPIOs: %d\n", err);
  765. pxa_set_ffuart_info(NULL);
  766. pxa_set_btuart_info(NULL);
  767. pwm_add_table(magician_pwm_lookup, ARRAY_SIZE(magician_pwm_lookup));
  768. pxa_set_ficp_info(&magician_ficp_info);
  769. pxa27x_set_i2c_power_info(&magician_i2c_power_info);
  770. pxa_set_i2c_info(&i2c_info);
  771. i2c_register_board_info(1,
  772. ARRAY_AND_SIZE(magician_pwr_i2c_board_info));
  773. pxa_set_mci_info(&magician_mci_info);
  774. pxa_set_ohci_info(&magician_ohci_info);
  775. pxa_set_udc_info(&magician_udc_info);
  776. /* Check LCD type we have */
  777. cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
  778. if (cpld) {
  779. u8 board_id = __raw_readb(cpld + 0x14);
  780. iounmap(cpld);
  781. system_rev = board_id & 0x7;
  782. lcd_select = board_id & 0x8;
  783. pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
  784. if (lcd_select && (system_rev < 3))
  785. /* NOTICE valid LCD init sequence */
  786. gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
  787. GPIOF_OUT_INIT_LOW, "Samsung LCD Power");
  788. pxa_set_fb_info(NULL,
  789. lcd_select ? &samsung_info : &toppoly_info);
  790. } else
  791. pr_err("LCD detection: CPLD mapping failed\n");
  792. regulator_register_always_on(0, "power", pwm_backlight_supply,
  793. ARRAY_SIZE(pwm_backlight_supply), 5000000);
  794. platform_add_devices(ARRAY_AND_SIZE(devices));
  795. }
  796. MACHINE_START(MAGICIAN, "HTC Magician")
  797. .atag_offset = 0x100,
  798. .map_io = pxa27x_map_io,
  799. .nr_irqs = MAGICIAN_NR_IRQS,
  800. .init_irq = pxa27x_init_irq,
  801. .handle_irq = pxa27x_handle_irq,
  802. .init_machine = magician_init,
  803. .init_time = pxa_timer_init,
  804. .restart = pxa_restart,
  805. MACHINE_END