magician.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Support for HTC Magician PDA phones:
  4. * i-mate JAM, O2 Xda mini, Orange SPV M500, Qtek s100, Qtek s110
  5. * and T-Mobile MDA Compact.
  6. *
  7. * Copyright (c) 2006-2007 Philipp Zabel
  8. *
  9. * Based on hx4700.c, spitz.c and others.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/delay.h>
  15. #include <linux/gpio.h>
  16. #include <linux/gpio/machine.h>
  17. #include <linux/gpio_keys.h>
  18. #include <linux/input.h>
  19. #include <linux/mfd/htc-pasic3.h>
  20. #include <linux/mtd/physmap.h>
  21. #include <linux/pda_power.h>
  22. #include <linux/platform_data/gpio-htc-egpio.h>
  23. #include <linux/pwm.h>
  24. #include <linux/pwm_backlight.h>
  25. #include <linux/regulator/driver.h>
  26. #include <linux/regulator/fixed.h>
  27. #include <linux/regulator/gpio-regulator.h>
  28. #include <linux/regulator/machine.h>
  29. #include <linux/platform_data/i2c-pxa.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/system_info.h>
  33. #include "pxa27x.h"
  34. #include "addr-map.h"
  35. #include "magician.h"
  36. #include <linux/platform_data/video-pxafb.h>
  37. #include <linux/platform_data/mmc-pxamci.h>
  38. #include <linux/platform_data/irda-pxaficp.h>
  39. #include <linux/platform_data/usb-ohci-pxa27x.h>
  40. #include <linux/regulator/max1586.h>
  41. #include <linux/platform_data/pxa2xx_udc.h>
  42. #include "udc.h"
  43. #include "pxa27x-udc.h"
  44. #include "devices.h"
  45. #include "generic.h"
  46. #include <linux/spi/spi.h>
  47. #include <linux/spi/pxa2xx_spi.h>
  48. #include <linux/spi/ads7846.h>
  49. #include <sound/uda1380.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. MFP_CFG_OUT(GPIO14, AF0, DRIVE_HIGH), /* frame as GPIO */
  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. .init = magician_backlight_init,
  356. .notify = magician_backlight_notify,
  357. .exit = magician_backlight_exit,
  358. };
  359. static struct platform_device backlight = {
  360. .name = "pwm-backlight",
  361. .id = -1,
  362. .dev = {
  363. .parent = &pxa27x_device_pwm0.dev,
  364. .platform_data = &backlight_data,
  365. },
  366. };
  367. /*
  368. * GPIO LEDs, Phone keys backlight, vibra
  369. */
  370. static struct gpio_led gpio_leds[] = {
  371. {
  372. .name = "magician::vibra",
  373. .default_trigger = "none",
  374. .gpio = GPIO22_MAGICIAN_VIBRA_EN,
  375. },
  376. {
  377. .name = "magician::phone_bl",
  378. .default_trigger = "backlight",
  379. .gpio = GPIO103_MAGICIAN_LED_KP,
  380. },
  381. };
  382. static struct gpio_led_platform_data gpio_led_info = {
  383. .leds = gpio_leds,
  384. .num_leds = ARRAY_SIZE(gpio_leds),
  385. };
  386. static struct platform_device leds_gpio = {
  387. .name = "leds-gpio",
  388. .id = -1,
  389. .dev = {
  390. .platform_data = &gpio_led_info,
  391. },
  392. };
  393. /*
  394. * PASIC3 with DS1WM
  395. */
  396. static struct resource pasic3_resources[] = {
  397. [0] = {
  398. .start = PXA_CS2_PHYS,
  399. .end = PXA_CS2_PHYS + 0x1b,
  400. .flags = IORESOURCE_MEM,
  401. },
  402. /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
  403. [1] = {
  404. .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  405. .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  406. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  407. }
  408. };
  409. static struct pasic3_platform_data pasic3_platform_data = {
  410. .clock_rate = 4000000,
  411. };
  412. static struct platform_device pasic3 = {
  413. .name = "pasic3",
  414. .id = -1,
  415. .num_resources = ARRAY_SIZE(pasic3_resources),
  416. .resource = pasic3_resources,
  417. .dev = {
  418. .platform_data = &pasic3_platform_data,
  419. },
  420. };
  421. /*
  422. * PXA UDC
  423. */
  424. static void magician_udc_command(int cmd)
  425. {
  426. if (cmd == PXA2XX_UDC_CMD_CONNECT)
  427. UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
  428. else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
  429. UP2OCR &= ~(UP2OCR_DPPUE | UP2OCR_DPPUBE);
  430. }
  431. static struct pxa2xx_udc_mach_info magician_udc_info __initdata = {
  432. .udc_command = magician_udc_command,
  433. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  434. };
  435. /*
  436. * USB device VBus detection
  437. */
  438. static struct resource gpio_vbus_resource = {
  439. .flags = IORESOURCE_IRQ,
  440. .start = IRQ_MAGICIAN_VBUS,
  441. .end = IRQ_MAGICIAN_VBUS,
  442. };
  443. static struct gpiod_lookup_table gpio_vbus_gpiod_table = {
  444. .dev_id = "gpio-vbus",
  445. .table = {
  446. /*
  447. * EGPIO on register 4 index 1, the second EGPIO chip
  448. * starts at register 4 so this will be at index 1 on that
  449. * chip.
  450. */
  451. GPIO_LOOKUP("htc-egpio-1", 1,
  452. "vbus", GPIO_ACTIVE_HIGH),
  453. GPIO_LOOKUP("gpio-pxa", GPIO27_MAGICIAN_USBC_PUEN,
  454. "pullup", GPIO_ACTIVE_HIGH),
  455. { },
  456. },
  457. };
  458. static struct platform_device gpio_vbus = {
  459. .name = "gpio-vbus",
  460. .id = -1,
  461. .num_resources = 1,
  462. .resource = &gpio_vbus_resource,
  463. };
  464. /*
  465. * External power
  466. */
  467. static int magician_supply_init(struct device *dev)
  468. {
  469. int ret = -1;
  470. ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger");
  471. if (ret) {
  472. pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret);
  473. goto err_ac;
  474. }
  475. ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted");
  476. if (ret) {
  477. pr_err("Cannot request cable detection GPIO (%i)\n", ret);
  478. goto err_usb;
  479. }
  480. return 0;
  481. err_usb:
  482. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  483. err_ac:
  484. return ret;
  485. }
  486. static void magician_set_charge(int flags)
  487. {
  488. if (flags & PDA_POWER_CHARGE_AC) {
  489. pr_debug("Charging from AC\n");
  490. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  491. } else if (flags & PDA_POWER_CHARGE_USB) {
  492. pr_debug("Charging from USB\n");
  493. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  494. } else {
  495. pr_debug("Charging disabled\n");
  496. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0);
  497. }
  498. }
  499. static int magician_is_ac_online(void)
  500. {
  501. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  502. gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */
  503. }
  504. static int magician_is_usb_online(void)
  505. {
  506. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  507. (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */
  508. }
  509. static void magician_supply_exit(struct device *dev)
  510. {
  511. gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED);
  512. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  513. }
  514. static char *magician_supplicants[] = {
  515. "ds2760-battery.0", "backup-battery"
  516. };
  517. static struct pda_power_pdata power_supply_info = {
  518. .init = magician_supply_init,
  519. .exit = magician_supply_exit,
  520. .is_ac_online = magician_is_ac_online,
  521. .is_usb_online = magician_is_usb_online,
  522. .set_charge = magician_set_charge,
  523. .supplied_to = magician_supplicants,
  524. .num_supplicants = ARRAY_SIZE(magician_supplicants),
  525. };
  526. static struct resource power_supply_resources[] = {
  527. [0] = {
  528. .name = "ac",
  529. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  530. IORESOURCE_IRQ_LOWEDGE,
  531. .start = IRQ_MAGICIAN_VBUS,
  532. .end = IRQ_MAGICIAN_VBUS,
  533. },
  534. [1] = {
  535. .name = "usb",
  536. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  537. IORESOURCE_IRQ_LOWEDGE,
  538. .start = IRQ_MAGICIAN_VBUS,
  539. .end = IRQ_MAGICIAN_VBUS,
  540. },
  541. };
  542. static struct platform_device power_supply = {
  543. .name = "pda-power",
  544. .id = -1,
  545. .dev = {
  546. .platform_data = &power_supply_info,
  547. },
  548. .resource = power_supply_resources,
  549. .num_resources = ARRAY_SIZE(power_supply_resources),
  550. };
  551. /*
  552. * Battery charger
  553. */
  554. static struct regulator_consumer_supply bq24022_consumers[] = {
  555. REGULATOR_SUPPLY("vbus_draw", NULL),
  556. REGULATOR_SUPPLY("ac_draw", NULL),
  557. };
  558. static struct regulator_init_data bq24022_init_data = {
  559. .constraints = {
  560. .max_uA = 500000,
  561. .valid_ops_mask = REGULATOR_CHANGE_CURRENT |
  562. REGULATOR_CHANGE_STATUS,
  563. },
  564. .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
  565. .consumer_supplies = bq24022_consumers,
  566. };
  567. static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW };
  568. static struct gpio_regulator_state bq24022_states[] = {
  569. { .value = 100000, .gpios = (0 << 0) },
  570. { .value = 500000, .gpios = (1 << 0) },
  571. };
  572. static struct gpio_regulator_config bq24022_info = {
  573. .supply_name = "bq24022",
  574. .enabled_at_boot = 1,
  575. .gflags = bq24022_gpiod_gflags,
  576. .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags),
  577. .states = bq24022_states,
  578. .nr_states = ARRAY_SIZE(bq24022_states),
  579. .type = REGULATOR_CURRENT,
  580. .init_data = &bq24022_init_data,
  581. };
  582. static struct platform_device bq24022 = {
  583. .name = "gpio-regulator",
  584. .id = -1,
  585. .dev = {
  586. .platform_data = &bq24022_info,
  587. },
  588. };
  589. static struct gpiod_lookup_table bq24022_gpiod_table = {
  590. .dev_id = "gpio-regulator",
  591. .table = {
  592. GPIO_LOOKUP("htc-egpio-0", EGPIO_MAGICIAN_BQ24022_ISET2 - MAGICIAN_EGPIO_BASE,
  593. NULL, GPIO_ACTIVE_HIGH),
  594. GPIO_LOOKUP("gpio-pxa", GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
  595. "enable", GPIO_ACTIVE_LOW),
  596. { },
  597. },
  598. };
  599. /*
  600. * fixed regulator for ads7846
  601. */
  602. static struct regulator_consumer_supply ads7846_supply =
  603. REGULATOR_SUPPLY("vcc", "spi2.0");
  604. static struct regulator_init_data vads7846_regulator = {
  605. .constraints = {
  606. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  607. },
  608. .num_consumer_supplies = 1,
  609. .consumer_supplies = &ads7846_supply,
  610. };
  611. static struct fixed_voltage_config vads7846 = {
  612. .supply_name = "vads7846",
  613. .microvolts = 3300000, /* probably */
  614. .startup_delay = 0,
  615. .init_data = &vads7846_regulator,
  616. };
  617. static struct platform_device vads7846_device = {
  618. .name = "reg-fixed-voltage",
  619. .id = -1,
  620. .dev = {
  621. .platform_data = &vads7846,
  622. },
  623. };
  624. /*
  625. * Vcore regulator MAX1587A
  626. */
  627. static struct regulator_consumer_supply magician_max1587a_consumers[] = {
  628. REGULATOR_SUPPLY("vcc_core", NULL),
  629. };
  630. static struct regulator_init_data magician_max1587a_v3_info = {
  631. .constraints = {
  632. .name = "vcc_core range",
  633. .min_uV = 700000,
  634. .max_uV = 1475000,
  635. .always_on = 1,
  636. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  637. },
  638. .consumer_supplies = magician_max1587a_consumers,
  639. .num_consumer_supplies = ARRAY_SIZE(magician_max1587a_consumers),
  640. };
  641. static struct max1586_subdev_data magician_max1587a_subdevs[] = {
  642. {
  643. .name = "vcc_core",
  644. .id = MAX1586_V3,
  645. .platform_data = &magician_max1587a_v3_info,
  646. }
  647. };
  648. static struct max1586_platform_data magician_max1587a_info = {
  649. .subdevs = magician_max1587a_subdevs,
  650. .num_subdevs = ARRAY_SIZE(magician_max1587a_subdevs),
  651. /*
  652. * NOTICE measured directly on the PCB (board_id == 0x3a), but
  653. * if R24 is present, it will boost the voltage
  654. * (write 1.475V, get 1.645V and smoke)
  655. */
  656. .v3_gain = MAX1586_GAIN_NO_R24,
  657. };
  658. static struct i2c_board_info magician_pwr_i2c_board_info[] __initdata = {
  659. {
  660. I2C_BOARD_INFO("max1586", 0x14),
  661. .platform_data = &magician_max1587a_info,
  662. },
  663. };
  664. /*
  665. * MMC/SD
  666. */
  667. static int magician_mci_init(struct device *dev,
  668. irq_handler_t detect_irq, void *data)
  669. {
  670. return request_irq(IRQ_MAGICIAN_SD, detect_irq, 0,
  671. "mmc card detect", data);
  672. }
  673. static void magician_mci_exit(struct device *dev, void *data)
  674. {
  675. free_irq(IRQ_MAGICIAN_SD, data);
  676. }
  677. static struct pxamci_platform_data magician_mci_info = {
  678. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  679. .init = magician_mci_init,
  680. .exit = magician_mci_exit,
  681. .gpio_card_ro_invert = 1,
  682. };
  683. /*
  684. * Write protect on EGPIO register 5 index 4, this is on the second HTC
  685. * EGPIO chip which starts at register 4, so we need offset 8+4=12 on that
  686. * particular chip.
  687. */
  688. #define EGPIO_MAGICIAN_nSD_READONLY_OFFSET 12
  689. /*
  690. * Power on EGPIO register 2 index 0, so this is on the first HTC EGPIO chip
  691. * starting at register 0 so we need offset 2*8+0 = 16 on that chip.
  692. */
  693. #define EGPIO_MAGICIAN_nSD_POWER_OFFSET 16
  694. static struct gpiod_lookup_table magician_mci_gpio_table = {
  695. .dev_id = "pxa2xx-mci.0",
  696. .table = {
  697. GPIO_LOOKUP("htc-egpio-1", EGPIO_MAGICIAN_nSD_READONLY_OFFSET,
  698. "wp", GPIO_ACTIVE_HIGH),
  699. GPIO_LOOKUP("htc-egpio-0", EGPIO_MAGICIAN_nSD_POWER_OFFSET,
  700. "power", GPIO_ACTIVE_HIGH),
  701. { },
  702. },
  703. };
  704. /*
  705. * USB OHCI
  706. */
  707. static struct pxaohci_platform_data magician_ohci_info = {
  708. .port_mode = PMM_PERPORT_MODE,
  709. /* port1: CSR Bluetooth, port2: OTG with UDC */
  710. .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
  711. .power_budget = 0,
  712. .power_on_delay = 100,
  713. };
  714. /*
  715. * StrataFlash
  716. */
  717. static int magician_flash_init(struct platform_device *pdev)
  718. {
  719. int ret = gpio_request(EGPIO_MAGICIAN_FLASH_VPP, "flash Vpp enable");
  720. if (ret) {
  721. pr_err("Cannot request flash enable GPIO (%i)\n", ret);
  722. return ret;
  723. }
  724. ret = gpio_direction_output(EGPIO_MAGICIAN_FLASH_VPP, 1);
  725. if (ret) {
  726. pr_err("Cannot set direction for flash enable (%i)\n", ret);
  727. gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
  728. }
  729. return ret;
  730. }
  731. static void magician_set_vpp(struct platform_device *pdev, int vpp)
  732. {
  733. gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
  734. }
  735. static void magician_flash_exit(struct platform_device *pdev)
  736. {
  737. gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
  738. }
  739. static struct resource strataflash_resource = {
  740. .start = PXA_CS0_PHYS,
  741. .end = PXA_CS0_PHYS + SZ_64M - 1,
  742. .flags = IORESOURCE_MEM,
  743. };
  744. static struct mtd_partition magician_flash_parts[] = {
  745. {
  746. .name = "Bootloader",
  747. .offset = 0x0,
  748. .size = 0x40000,
  749. .mask_flags = MTD_WRITEABLE, /* EXPERIMENTAL */
  750. },
  751. {
  752. .name = "Linux Kernel",
  753. .offset = 0x40000,
  754. .size = MTDPART_SIZ_FULL,
  755. },
  756. };
  757. /*
  758. * physmap-flash driver
  759. */
  760. static struct physmap_flash_data strataflash_data = {
  761. .width = 4,
  762. .init = magician_flash_init,
  763. .set_vpp = magician_set_vpp,
  764. .exit = magician_flash_exit,
  765. .parts = magician_flash_parts,
  766. .nr_parts = ARRAY_SIZE(magician_flash_parts),
  767. };
  768. static struct platform_device strataflash = {
  769. .name = "physmap-flash",
  770. .id = -1,
  771. .resource = &strataflash_resource,
  772. .num_resources = 1,
  773. .dev = {
  774. .platform_data = &strataflash_data,
  775. },
  776. };
  777. /*
  778. * audio support
  779. */
  780. static struct uda1380_platform_data uda1380_info = {
  781. .gpio_power = EGPIO_MAGICIAN_CODEC_POWER,
  782. .gpio_reset = EGPIO_MAGICIAN_CODEC_RESET,
  783. .dac_clk = UDA1380_DAC_CLK_WSPLL,
  784. };
  785. static struct i2c_board_info magician_audio_i2c_board_info[] = {
  786. {
  787. I2C_BOARD_INFO("uda1380", 0x18),
  788. .platform_data = &uda1380_info,
  789. },
  790. };
  791. static struct gpiod_lookup_table magician_audio_gpio_table = {
  792. .dev_id = "magician-audio",
  793. .table = {
  794. GPIO_LOOKUP("htc-egpio-0",
  795. EGPIO_MAGICIAN_SPK_POWER - MAGICIAN_EGPIO_BASE,
  796. "SPK_POWER", GPIO_ACTIVE_HIGH),
  797. GPIO_LOOKUP("htc-egpio-0",
  798. EGPIO_MAGICIAN_EP_POWER - MAGICIAN_EGPIO_BASE,
  799. "EP_POWER", GPIO_ACTIVE_HIGH),
  800. GPIO_LOOKUP("htc-egpio-0",
  801. EGPIO_MAGICIAN_MIC_POWER - MAGICIAN_EGPIO_BASE,
  802. "MIC_POWER", GPIO_ACTIVE_HIGH),
  803. GPIO_LOOKUP("htc-egpio-0",
  804. EGPIO_MAGICIAN_IN_SEL0 - MAGICIAN_EGPIO_BASE,
  805. "IN_SEL0", GPIO_ACTIVE_HIGH),
  806. GPIO_LOOKUP("htc-egpio-0",
  807. EGPIO_MAGICIAN_IN_SEL1 - MAGICIAN_EGPIO_BASE,
  808. "IN_SEL1", GPIO_ACTIVE_HIGH),
  809. { },
  810. },
  811. };
  812. static void magician_audio_init(void)
  813. {
  814. i2c_register_board_info(0,
  815. ARRAY_AND_SIZE(magician_audio_i2c_board_info));
  816. gpiod_add_lookup_table(&magician_audio_gpio_table);
  817. platform_device_register_simple("magician-audio", -1, NULL, 0);
  818. }
  819. /*
  820. * PXA I2C main controller
  821. */
  822. static struct i2c_pxa_platform_data i2c_info = {
  823. /* OV9640 I2C device doesn't support fast mode */
  824. .fast_mode = 0,
  825. };
  826. /*
  827. * PXA I2C power controller
  828. */
  829. static struct i2c_pxa_platform_data magician_i2c_power_info = {
  830. .fast_mode = 1,
  831. };
  832. /*
  833. * Touchscreen
  834. */
  835. static struct ads7846_platform_data ads7846_pdata = {
  836. .model = 7846,
  837. .x_plate_ohms = 317,
  838. .y_plate_ohms = 500,
  839. .pressure_max = 1023, /* with x plate ohms it will overflow 255 */
  840. .debounce_max = 3, /* first readout is always bad */
  841. .debounce_tol = 30,
  842. .debounce_rep = 0,
  843. .gpio_pendown = GPIO115_MAGICIAN_nPEN_IRQ,
  844. .keep_vref_on = 1,
  845. .wakeup = true,
  846. .vref_delay_usecs = 100,
  847. .penirq_recheck_delay_usecs = 100,
  848. };
  849. struct pxa2xx_spi_chip tsc2046_chip_info = {
  850. .tx_threshold = 1,
  851. .rx_threshold = 2,
  852. .timeout = 64,
  853. };
  854. static struct pxa2xx_spi_controller magician_spi_info = {
  855. .num_chipselect = 1,
  856. .enable_dma = 1,
  857. };
  858. static struct gpiod_lookup_table magician_spi_gpio_table = {
  859. .dev_id = "spi2",
  860. .table = {
  861. /* NOTICE must be GPIO, incompatibility with hw PXA SPI framing */
  862. GPIO_LOOKUP_IDX("gpio-pxa", GPIO14_MAGICIAN_TSC2046_CS, "cs", 0, GPIO_ACTIVE_LOW),
  863. { },
  864. },
  865. };
  866. static struct spi_board_info ads7846_spi_board_info[] __initdata = {
  867. {
  868. .modalias = "ads7846",
  869. .bus_num = 2,
  870. .max_speed_hz = 2500000,
  871. .platform_data = &ads7846_pdata,
  872. .controller_data = &tsc2046_chip_info,
  873. .irq = PXA_GPIO_TO_IRQ(GPIO115_MAGICIAN_nPEN_IRQ),
  874. },
  875. };
  876. /*
  877. * Platform devices
  878. */
  879. static struct platform_device *devices[] __initdata = {
  880. &gpio_keys,
  881. &egpio,
  882. &backlight,
  883. &pasic3,
  884. &bq24022,
  885. &gpio_vbus,
  886. &power_supply,
  887. &strataflash,
  888. &leds_gpio,
  889. &vads7846_device,
  890. };
  891. static struct gpio magician_global_gpios[] = {
  892. { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" },
  893. { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
  894. /* NOTICE valid LCD init sequence */
  895. { GPIO106_MAGICIAN_LCD_DCDC_NRESET, GPIOF_OUT_INIT_LOW, "LCD DCDC nreset" },
  896. { GPIO104_MAGICIAN_LCD_VOFF_EN, GPIOF_OUT_INIT_LOW, "LCD VOFF enable" },
  897. { GPIO105_MAGICIAN_LCD_VON_EN, GPIOF_OUT_INIT_LOW, "LCD VON enable" },
  898. };
  899. static void __init magician_init(void)
  900. {
  901. void __iomem *cpld;
  902. int lcd_select;
  903. int err;
  904. pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
  905. err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
  906. if (err)
  907. pr_err("magician: Failed to request global GPIOs: %d\n", err);
  908. pxa_set_ffuart_info(NULL);
  909. pxa_set_btuart_info(NULL);
  910. pwm_add_table(magician_pwm_lookup, ARRAY_SIZE(magician_pwm_lookup));
  911. pxa_set_ficp_info(&magician_ficp_info);
  912. pxa27x_set_i2c_power_info(&magician_i2c_power_info);
  913. pxa_set_i2c_info(&i2c_info);
  914. i2c_register_board_info(1,
  915. ARRAY_AND_SIZE(magician_pwr_i2c_board_info));
  916. gpiod_add_lookup_table(&magician_mci_gpio_table);
  917. pxa_set_mci_info(&magician_mci_info);
  918. pxa_set_ohci_info(&magician_ohci_info);
  919. pxa_set_udc_info(&magician_udc_info);
  920. /* Check LCD type we have */
  921. cpld = ioremap(PXA_CS3_PHYS, 0x1000);
  922. if (cpld) {
  923. u8 board_id = __raw_readb(cpld + 0x14);
  924. iounmap(cpld);
  925. system_rev = board_id & 0x7;
  926. lcd_select = board_id & 0x8;
  927. pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
  928. if (lcd_select && (system_rev < 3))
  929. /* NOTICE valid LCD init sequence */
  930. gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
  931. GPIOF_OUT_INIT_LOW, "Samsung LCD Power");
  932. pxa_set_fb_info(NULL,
  933. lcd_select ? &samsung_info : &toppoly_info);
  934. } else
  935. pr_err("LCD detection: CPLD mapping failed\n");
  936. gpiod_add_lookup_table(&magician_spi_gpio_table);
  937. pxa2xx_set_spi_info(2, &magician_spi_info);
  938. spi_register_board_info(ARRAY_AND_SIZE(ads7846_spi_board_info));
  939. regulator_register_always_on(0, "power", pwm_backlight_supply,
  940. ARRAY_SIZE(pwm_backlight_supply), 5000000);
  941. gpiod_add_lookup_table(&bq24022_gpiod_table);
  942. gpiod_add_lookup_table(&gpio_vbus_gpiod_table);
  943. platform_add_devices(ARRAY_AND_SIZE(devices));
  944. magician_audio_init();
  945. }
  946. MACHINE_START(MAGICIAN, "HTC Magician")
  947. .atag_offset = 0x100,
  948. .map_io = pxa27x_map_io,
  949. .nr_irqs = MAGICIAN_NR_IRQS,
  950. .init_irq = pxa27x_init_irq,
  951. .handle_irq = pxa27x_handle_irq,
  952. .init_machine = magician_init,
  953. .init_time = pxa_timer_init,
  954. .restart = pxa_restart,
  955. MACHINE_END