magician.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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.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 <mach/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 <mach/udc.h>
  47. #include <mach/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. /* I2C */
  108. GPIO117_I2C_SCL,
  109. GPIO118_I2C_SDA,
  110. };
  111. /*
  112. * IrDA
  113. */
  114. static struct pxaficp_platform_data magician_ficp_info = {
  115. .gpio_pwdown = GPIO83_MAGICIAN_nIR_EN,
  116. .transceiver_cap = IR_SIRMODE | IR_OFF,
  117. .gpio_pwdown_inverted = 0,
  118. };
  119. /*
  120. * GPIO Keys
  121. */
  122. #define INIT_KEY(_code, _gpio, _desc) \
  123. { \
  124. .code = KEY_##_code, \
  125. .gpio = _gpio, \
  126. .desc = _desc, \
  127. .type = EV_KEY, \
  128. .wakeup = 1, \
  129. }
  130. static struct gpio_keys_button magician_button_table[] = {
  131. INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
  132. INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
  133. INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
  134. INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
  135. INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
  136. INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
  137. INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
  138. INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
  139. INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
  140. INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
  141. INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
  142. INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
  143. INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
  144. INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
  145. INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
  146. };
  147. static struct gpio_keys_platform_data gpio_keys_data = {
  148. .buttons = magician_button_table,
  149. .nbuttons = ARRAY_SIZE(magician_button_table),
  150. };
  151. static struct platform_device gpio_keys = {
  152. .name = "gpio-keys",
  153. .dev = {
  154. .platform_data = &gpio_keys_data,
  155. },
  156. .id = -1,
  157. };
  158. /*
  159. * EGPIO (Xilinx CPLD)
  160. *
  161. * 32-bit aligned 8-bit registers
  162. * 16 possible registers (reg windows size), only 7 used:
  163. * 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 - 1,
  169. .flags = IORESOURCE_MEM,
  170. },
  171. [1] = {
  172. .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
  173. .end = PXA_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. /*
  184. * Depends on modules configuration
  185. */
  186. .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
  187. },
  188. [1] = {
  189. .reg_start = 4,
  190. .gpio_base = MAGICIAN_EGPIO(4, 0),
  191. .num_gpios = 24,
  192. .direction = HTC_EGPIO_INPUT,
  193. },
  194. };
  195. static struct htc_egpio_platform_data egpio_info = {
  196. .reg_width = 8,
  197. .bus_width = 32,
  198. .irq_base = IRQ_BOARD_START,
  199. .num_irqs = 4,
  200. .ack_register = 3,
  201. .chip = egpio_chips,
  202. .num_chips = ARRAY_SIZE(egpio_chips),
  203. };
  204. static struct platform_device egpio = {
  205. .name = "htc-egpio",
  206. .id = -1,
  207. .resource = egpio_resources,
  208. .num_resources = ARRAY_SIZE(egpio_resources),
  209. .dev = {
  210. .platform_data = &egpio_info,
  211. },
  212. };
  213. /*
  214. * PXAFB LCD - Toppoly TD028STEB1 or Samsung LTP280QV
  215. */
  216. static struct pxafb_mode_info toppoly_modes[] = {
  217. {
  218. .pixclock = 96153,
  219. .bpp = 16,
  220. .xres = 240,
  221. .yres = 320,
  222. .hsync_len = 11,
  223. .vsync_len = 3,
  224. .left_margin = 19,
  225. .upper_margin = 2,
  226. .right_margin = 10,
  227. .lower_margin = 2,
  228. .sync = 0,
  229. },
  230. };
  231. static struct pxafb_mode_info samsung_modes[] = {
  232. {
  233. .pixclock = 226469,
  234. .bpp = 16,
  235. .xres = 240,
  236. .yres = 320,
  237. .hsync_len = 8,
  238. .vsync_len = 4,
  239. .left_margin = 9,
  240. .upper_margin = 4,
  241. .right_margin = 9,
  242. .lower_margin = 4,
  243. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  244. },
  245. };
  246. static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
  247. {
  248. pr_debug("Toppoly LCD power: %s\n", on ? "on" : "off");
  249. if (on) {
  250. gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
  251. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
  252. udelay(2000);
  253. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  254. udelay(2000);
  255. /* FIXME: enable LCDC here */
  256. udelay(2000);
  257. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
  258. udelay(2000);
  259. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
  260. } else {
  261. msleep(15);
  262. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
  263. udelay(500);
  264. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
  265. udelay(1000);
  266. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
  267. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  268. }
  269. }
  270. static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
  271. {
  272. pr_debug("Samsung LCD power: %s\n", on ? "on" : "off");
  273. if (on) {
  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(6);
  279. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
  280. mdelay(6); /* Avdd -> Voff >5ms */
  281. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
  282. mdelay(16); /* Voff -> Von >(5+10)ms */
  283. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
  284. } else {
  285. gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
  286. mdelay(16);
  287. gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
  288. mdelay(6);
  289. gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
  290. mdelay(6);
  291. if (system_rev < 3)
  292. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
  293. else
  294. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  295. }
  296. }
  297. static struct pxafb_mach_info toppoly_info = {
  298. .modes = toppoly_modes,
  299. .num_modes = 1,
  300. .fixed_modes = 1,
  301. .lcd_conn = LCD_COLOR_TFT_16BPP,
  302. .pxafb_lcd_power = toppoly_lcd_power,
  303. };
  304. static struct pxafb_mach_info samsung_info = {
  305. .modes = samsung_modes,
  306. .num_modes = 1,
  307. .fixed_modes = 1,
  308. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
  309. LCD_ALTERNATE_MAPPING,
  310. .pxafb_lcd_power = samsung_lcd_power,
  311. };
  312. /*
  313. * Backlight
  314. */
  315. static struct pwm_lookup magician_pwm_lookup[] = {
  316. PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight", NULL, 30923,
  317. PWM_POLARITY_NORMAL),
  318. };
  319. /*
  320. * fixed regulator for pwm_backlight
  321. */
  322. static struct regulator_consumer_supply pwm_backlight_supply[] = {
  323. REGULATOR_SUPPLY("power", "pwm_backlight"),
  324. };
  325. static struct gpio magician_bl_gpios[] = {
  326. { EGPIO_MAGICIAN_BL_POWER, GPIOF_DIR_OUT, "Backlight power" },
  327. { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" },
  328. };
  329. static int magician_backlight_init(struct device *dev)
  330. {
  331. return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios));
  332. }
  333. static int magician_backlight_notify(struct device *dev, int brightness)
  334. {
  335. pr_debug("Brightness = %i\n", brightness);
  336. gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
  337. if (brightness >= 200) {
  338. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
  339. return brightness - 72;
  340. } else {
  341. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
  342. return brightness;
  343. }
  344. }
  345. static void magician_backlight_exit(struct device *dev)
  346. {
  347. gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios));
  348. }
  349. /*
  350. * LCD PWM backlight (main)
  351. *
  352. * MP1521 frequency should be:
  353. * 100-400 Hz = 2 .5*10^6 - 10 *10^6 ns
  354. */
  355. static struct platform_pwm_backlight_data backlight_data = {
  356. .max_brightness = 272,
  357. .dft_brightness = 100,
  358. .enable_gpio = -1,
  359. .init = magician_backlight_init,
  360. .notify = magician_backlight_notify,
  361. .exit = magician_backlight_exit,
  362. };
  363. static struct platform_device backlight = {
  364. .name = "pwm-backlight",
  365. .id = -1,
  366. .dev = {
  367. .parent = &pxa27x_device_pwm0.dev,
  368. .platform_data = &backlight_data,
  369. },
  370. };
  371. /*
  372. * GPIO LEDs, Phone keys backlight, vibra
  373. */
  374. static struct gpio_led gpio_leds[] = {
  375. {
  376. .name = "magician::vibra",
  377. .default_trigger = "none",
  378. .gpio = GPIO22_MAGICIAN_VIBRA_EN,
  379. },
  380. {
  381. .name = "magician::phone_bl",
  382. .default_trigger = "backlight",
  383. .gpio = GPIO103_MAGICIAN_LED_KP,
  384. },
  385. };
  386. static struct gpio_led_platform_data gpio_led_info = {
  387. .leds = gpio_leds,
  388. .num_leds = ARRAY_SIZE(gpio_leds),
  389. };
  390. static struct platform_device leds_gpio = {
  391. .name = "leds-gpio",
  392. .id = -1,
  393. .dev = {
  394. .platform_data = &gpio_led_info,
  395. },
  396. };
  397. /*
  398. * PASIC3 LEDs
  399. */
  400. static struct pasic3_led pasic3_leds[] = {
  401. {
  402. .led = {
  403. .name = "magician:red",
  404. .default_trigger = "ds2760-battery.0-charging",
  405. },
  406. .hw_num = 0,
  407. .bit2 = PASIC3_BIT2_LED0,
  408. .mask = PASIC3_MASK_LED0,
  409. },
  410. {
  411. .led = {
  412. .name = "magician:green",
  413. .default_trigger = "ds2760-battery.0-charging-or-full",
  414. },
  415. .hw_num = 1,
  416. .bit2 = PASIC3_BIT2_LED1,
  417. .mask = PASIC3_MASK_LED1,
  418. },
  419. {
  420. .led = {
  421. .name = "magician:blue",
  422. .default_trigger = "bluetooth",
  423. },
  424. .hw_num = 2,
  425. .bit2 = PASIC3_BIT2_LED2,
  426. .mask = PASIC3_MASK_LED2,
  427. },
  428. };
  429. static struct pasic3_leds_machinfo pasic3_leds_info = {
  430. .num_leds = ARRAY_SIZE(pasic3_leds),
  431. .power_gpio = EGPIO_MAGICIAN_LED_POWER,
  432. .leds = pasic3_leds,
  433. };
  434. /*
  435. * PASIC3 with DS1WM
  436. */
  437. static struct resource pasic3_resources[] = {
  438. [0] = {
  439. .start = PXA_CS2_PHYS,
  440. .end = PXA_CS2_PHYS + 0x1b,
  441. .flags = IORESOURCE_MEM,
  442. },
  443. /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
  444. [1] = {
  445. .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  446. .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  447. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  448. }
  449. };
  450. static struct pasic3_platform_data pasic3_platform_data = {
  451. .led_pdata = &pasic3_leds_info,
  452. .clock_rate = 4000000,
  453. };
  454. static struct platform_device pasic3 = {
  455. .name = "pasic3",
  456. .id = -1,
  457. .num_resources = ARRAY_SIZE(pasic3_resources),
  458. .resource = pasic3_resources,
  459. .dev = {
  460. .platform_data = &pasic3_platform_data,
  461. },
  462. };
  463. /*
  464. * PXA UDC
  465. */
  466. static void magician_udc_command(int cmd)
  467. {
  468. if (cmd == PXA2XX_UDC_CMD_CONNECT)
  469. UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
  470. else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
  471. UP2OCR &= ~(UP2OCR_DPPUE | UP2OCR_DPPUBE);
  472. }
  473. static struct pxa2xx_udc_mach_info magician_udc_info __initdata = {
  474. .udc_command = magician_udc_command,
  475. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  476. };
  477. /*
  478. * USB device VBus detection
  479. */
  480. static struct resource gpio_vbus_resource = {
  481. .flags = IORESOURCE_IRQ,
  482. .start = IRQ_MAGICIAN_VBUS,
  483. .end = IRQ_MAGICIAN_VBUS,
  484. };
  485. static struct gpio_vbus_mach_info gpio_vbus_info = {
  486. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  487. .gpio_vbus = EGPIO_MAGICIAN_CABLE_VBUS,
  488. };
  489. static struct platform_device gpio_vbus = {
  490. .name = "gpio-vbus",
  491. .id = -1,
  492. .num_resources = 1,
  493. .resource = &gpio_vbus_resource,
  494. .dev = {
  495. .platform_data = &gpio_vbus_info,
  496. },
  497. };
  498. /*
  499. * External power
  500. */
  501. static int magician_supply_init(struct device *dev)
  502. {
  503. int ret = -1;
  504. ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger");
  505. if (ret) {
  506. pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret);
  507. goto err_ac;
  508. }
  509. ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted");
  510. if (ret) {
  511. pr_err("Cannot request cable detection GPIO (%i)\n", ret);
  512. goto err_usb;
  513. }
  514. return 0;
  515. err_usb:
  516. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  517. err_ac:
  518. return ret;
  519. }
  520. static void magician_set_charge(int flags)
  521. {
  522. if (flags & PDA_POWER_CHARGE_AC) {
  523. pr_debug("Charging from AC\n");
  524. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  525. } else if (flags & PDA_POWER_CHARGE_USB) {
  526. pr_debug("Charging from USB\n");
  527. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  528. } else {
  529. pr_debug("Charging disabled\n");
  530. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0);
  531. }
  532. }
  533. static int magician_is_ac_online(void)
  534. {
  535. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  536. gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */
  537. }
  538. static int magician_is_usb_online(void)
  539. {
  540. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  541. (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */
  542. }
  543. static void magician_supply_exit(struct device *dev)
  544. {
  545. gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED);
  546. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  547. }
  548. static char *magician_supplicants[] = {
  549. "ds2760-battery.0", "backup-battery"
  550. };
  551. static struct pda_power_pdata power_supply_info = {
  552. .init = magician_supply_init,
  553. .exit = magician_supply_exit,
  554. .is_ac_online = magician_is_ac_online,
  555. .is_usb_online = magician_is_usb_online,
  556. .set_charge = magician_set_charge,
  557. .supplied_to = magician_supplicants,
  558. .num_supplicants = ARRAY_SIZE(magician_supplicants),
  559. };
  560. static struct resource power_supply_resources[] = {
  561. [0] = {
  562. .name = "ac",
  563. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  564. IORESOURCE_IRQ_LOWEDGE,
  565. .start = IRQ_MAGICIAN_VBUS,
  566. .end = IRQ_MAGICIAN_VBUS,
  567. },
  568. [1] = {
  569. .name = "usb",
  570. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  571. IORESOURCE_IRQ_LOWEDGE,
  572. .start = IRQ_MAGICIAN_VBUS,
  573. .end = IRQ_MAGICIAN_VBUS,
  574. },
  575. };
  576. static struct platform_device power_supply = {
  577. .name = "pda-power",
  578. .id = -1,
  579. .dev = {
  580. .platform_data = &power_supply_info,
  581. },
  582. .resource = power_supply_resources,
  583. .num_resources = ARRAY_SIZE(power_supply_resources),
  584. };
  585. /*
  586. * Battery charger
  587. */
  588. static struct regulator_consumer_supply bq24022_consumers[] = {
  589. REGULATOR_SUPPLY("vbus_draw", NULL),
  590. REGULATOR_SUPPLY("ac_draw", NULL),
  591. };
  592. static struct regulator_init_data bq24022_init_data = {
  593. .constraints = {
  594. .max_uA = 500000,
  595. .valid_ops_mask = REGULATOR_CHANGE_CURRENT |
  596. REGULATOR_CHANGE_STATUS,
  597. },
  598. .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
  599. .consumer_supplies = bq24022_consumers,
  600. };
  601. static struct gpio bq24022_gpios[] = {
  602. { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
  603. };
  604. static struct gpio_regulator_state bq24022_states[] = {
  605. { .value = 100000, .gpios = (0 << 0) },
  606. { .value = 500000, .gpios = (1 << 0) },
  607. };
  608. static struct gpio_regulator_config bq24022_info = {
  609. .supply_name = "bq24022",
  610. .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
  611. .enable_high = 0,
  612. .enabled_at_boot = 1,
  613. .gpios = bq24022_gpios,
  614. .nr_gpios = ARRAY_SIZE(bq24022_gpios),
  615. .states = bq24022_states,
  616. .nr_states = ARRAY_SIZE(bq24022_states),
  617. .type = REGULATOR_CURRENT,
  618. .init_data = &bq24022_init_data,
  619. };
  620. static struct platform_device bq24022 = {
  621. .name = "gpio-regulator",
  622. .id = -1,
  623. .dev = {
  624. .platform_data = &bq24022_info,
  625. },
  626. };
  627. /*
  628. * Vcore regulator MAX1587A
  629. */
  630. static struct regulator_consumer_supply magician_max1587a_consumers[] = {
  631. REGULATOR_SUPPLY("vcc_core", NULL),
  632. };
  633. static struct regulator_init_data magician_max1587a_v3_info = {
  634. .constraints = {
  635. .name = "vcc_core range",
  636. .min_uV = 700000,
  637. .max_uV = 1475000,
  638. .always_on = 1,
  639. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  640. },
  641. .consumer_supplies = magician_max1587a_consumers,
  642. .num_consumer_supplies = ARRAY_SIZE(magician_max1587a_consumers),
  643. };
  644. static struct max1586_subdev_data magician_max1587a_subdevs[] = {
  645. {
  646. .name = "vcc_core",
  647. .id = MAX1586_V3,
  648. .platform_data = &magician_max1587a_v3_info,
  649. }
  650. };
  651. static struct max1586_platform_data magician_max1587a_info = {
  652. .subdevs = magician_max1587a_subdevs,
  653. .num_subdevs = ARRAY_SIZE(magician_max1587a_subdevs),
  654. /*
  655. * NOTICE measured directly on the PCB (board_id == 0x3a), but
  656. * if R24 is present, it will boost the voltage
  657. * (write 1.475V, get 1.645V and smoke)
  658. */
  659. .v3_gain = MAX1586_GAIN_NO_R24,
  660. };
  661. static struct i2c_board_info magician_pwr_i2c_board_info[] __initdata = {
  662. {
  663. I2C_BOARD_INFO("max1586", 0x14),
  664. .platform_data = &magician_max1587a_info,
  665. },
  666. };
  667. /*
  668. * MMC/SD
  669. */
  670. static int magician_mci_init(struct device *dev,
  671. irq_handler_t detect_irq, void *data)
  672. {
  673. return request_irq(IRQ_MAGICIAN_SD, detect_irq, 0,
  674. "mmc card detect", data);
  675. }
  676. static void magician_mci_exit(struct device *dev, void *data)
  677. {
  678. free_irq(IRQ_MAGICIAN_SD, data);
  679. }
  680. static struct pxamci_platform_data magician_mci_info = {
  681. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  682. .init = magician_mci_init,
  683. .exit = magician_mci_exit,
  684. .gpio_card_detect = -1,
  685. .gpio_card_ro = EGPIO_MAGICIAN_nSD_READONLY,
  686. .gpio_card_ro_invert = 1,
  687. .gpio_power = EGPIO_MAGICIAN_SD_POWER,
  688. };
  689. /*
  690. * USB OHCI
  691. */
  692. static struct pxaohci_platform_data magician_ohci_info = {
  693. .port_mode = PMM_PERPORT_MODE,
  694. /* port1: CSR Bluetooth, port2: OTG with UDC */
  695. .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
  696. .power_budget = 0,
  697. .power_on_delay = 100,
  698. };
  699. /*
  700. * StrataFlash
  701. */
  702. static int magician_flash_init(struct platform_device *pdev)
  703. {
  704. int ret = gpio_request(EGPIO_MAGICIAN_FLASH_VPP, "flash Vpp enable");
  705. if (ret) {
  706. pr_err("Cannot request flash enable GPIO (%i)\n", ret);
  707. return ret;
  708. }
  709. ret = gpio_direction_output(EGPIO_MAGICIAN_FLASH_VPP, 1);
  710. if (ret) {
  711. pr_err("Cannot set direction for flash enable (%i)\n", ret);
  712. gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
  713. }
  714. return ret;
  715. }
  716. static void magician_set_vpp(struct platform_device *pdev, int vpp)
  717. {
  718. gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
  719. }
  720. static void magician_flash_exit(struct platform_device *pdev)
  721. {
  722. gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
  723. }
  724. static struct resource strataflash_resource = {
  725. .start = PXA_CS0_PHYS,
  726. .end = PXA_CS0_PHYS + SZ_64M - 1,
  727. .flags = IORESOURCE_MEM,
  728. };
  729. static struct mtd_partition magician_flash_parts[] = {
  730. {
  731. .name = "Bootloader",
  732. .offset = 0x0,
  733. .size = 0x40000,
  734. .mask_flags = MTD_WRITEABLE, /* EXPERIMENTAL */
  735. },
  736. {
  737. .name = "Linux Kernel",
  738. .offset = 0x40000,
  739. .size = MTDPART_SIZ_FULL,
  740. },
  741. };
  742. /*
  743. * physmap-flash driver
  744. */
  745. static struct physmap_flash_data strataflash_data = {
  746. .width = 4,
  747. .init = magician_flash_init,
  748. .set_vpp = magician_set_vpp,
  749. .exit = magician_flash_exit,
  750. .parts = magician_flash_parts,
  751. .nr_parts = ARRAY_SIZE(magician_flash_parts),
  752. };
  753. static struct platform_device strataflash = {
  754. .name = "physmap-flash",
  755. .id = -1,
  756. .resource = &strataflash_resource,
  757. .num_resources = 1,
  758. .dev = {
  759. .platform_data = &strataflash_data,
  760. },
  761. };
  762. /*
  763. * PXA I2C main controller
  764. */
  765. static struct i2c_pxa_platform_data i2c_info = {
  766. /* OV9640 I2C device doesn't support fast mode */
  767. .fast_mode = 0,
  768. };
  769. /*
  770. * PXA I2C power controller
  771. */
  772. static struct i2c_pxa_platform_data magician_i2c_power_info = {
  773. .fast_mode = 1,
  774. };
  775. /*
  776. * Platform devices
  777. */
  778. static struct platform_device *devices[] __initdata = {
  779. &gpio_keys,
  780. &egpio,
  781. &backlight,
  782. &pasic3,
  783. &bq24022,
  784. &gpio_vbus,
  785. &power_supply,
  786. &strataflash,
  787. &leds_gpio,
  788. };
  789. static struct gpio magician_global_gpios[] = {
  790. { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" },
  791. { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
  792. /* NOTICE valid LCD init sequence */
  793. { GPIO106_MAGICIAN_LCD_DCDC_NRESET, GPIOF_OUT_INIT_LOW, "LCD DCDC nreset" },
  794. { GPIO104_MAGICIAN_LCD_VOFF_EN, GPIOF_OUT_INIT_LOW, "LCD VOFF enable" },
  795. { GPIO105_MAGICIAN_LCD_VON_EN, GPIOF_OUT_INIT_LOW, "LCD VON enable" },
  796. };
  797. static void __init magician_init(void)
  798. {
  799. void __iomem *cpld;
  800. int lcd_select;
  801. int err;
  802. pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
  803. err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
  804. if (err)
  805. pr_err("magician: Failed to request global GPIOs: %d\n", err);
  806. pxa_set_ffuart_info(NULL);
  807. pxa_set_btuart_info(NULL);
  808. pwm_add_table(magician_pwm_lookup, ARRAY_SIZE(magician_pwm_lookup));
  809. pxa_set_ficp_info(&magician_ficp_info);
  810. pxa27x_set_i2c_power_info(&magician_i2c_power_info);
  811. pxa_set_i2c_info(&i2c_info);
  812. i2c_register_board_info(1,
  813. ARRAY_AND_SIZE(magician_pwr_i2c_board_info));
  814. pxa_set_mci_info(&magician_mci_info);
  815. pxa_set_ohci_info(&magician_ohci_info);
  816. pxa_set_udc_info(&magician_udc_info);
  817. /* Check LCD type we have */
  818. cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
  819. if (cpld) {
  820. u8 board_id = __raw_readb(cpld + 0x14);
  821. iounmap(cpld);
  822. system_rev = board_id & 0x7;
  823. lcd_select = board_id & 0x8;
  824. pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
  825. if (lcd_select && (system_rev < 3))
  826. /* NOTICE valid LCD init sequence */
  827. gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
  828. GPIOF_OUT_INIT_LOW, "Samsung LCD Power");
  829. pxa_set_fb_info(NULL,
  830. lcd_select ? &samsung_info : &toppoly_info);
  831. } else
  832. pr_err("LCD detection: CPLD mapping failed\n");
  833. regulator_register_always_on(0, "power", pwm_backlight_supply,
  834. ARRAY_SIZE(pwm_backlight_supply), 5000000);
  835. platform_add_devices(ARRAY_AND_SIZE(devices));
  836. }
  837. MACHINE_START(MAGICIAN, "HTC Magician")
  838. .atag_offset = 0x100,
  839. .map_io = pxa27x_map_io,
  840. .nr_irqs = MAGICIAN_NR_IRQS,
  841. .init_irq = pxa27x_init_irq,
  842. .handle_irq = pxa27x_handle_irq,
  843. .init_machine = magician_init,
  844. .init_time = pxa_timer_init,
  845. .restart = pxa_restart,
  846. MACHINE_END