magician.c 24 KB

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