magician.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. /*
  2. * Support for HTC Magician PDA phones:
  3. * i-mate JAM, O2 Xda mini, Orange SPV M500, Qtek s100, Qtek s110
  4. * and T-Mobile MDA Compact.
  5. *
  6. * Copyright (c) 2006-2007 Philipp Zabel
  7. *
  8. * Based on hx4700.c, spitz.c and others.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/delay.h>
  19. #include <linux/gpio.h>
  20. #include <linux/gpio_keys.h>
  21. #include <linux/input.h>
  22. #include <linux/mfd/htc-pasic3.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <linux/pda_power.h>
  25. #include <linux/platform_data/gpio-htc-egpio.h>
  26. #include <linux/pwm.h>
  27. #include <linux/pwm_backlight.h>
  28. #include <linux/regulator/driver.h>
  29. #include <linux/regulator/fixed.h>
  30. #include <linux/regulator/gpio-regulator.h>
  31. #include <linux/regulator/machine.h>
  32. #include <linux/usb/gpio_vbus.h>
  33. #include <linux/platform_data/i2c-pxa.h>
  34. #include <mach/hardware.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/system_info.h>
  38. #include "pxa27x.h"
  39. #include <mach/magician.h>
  40. #include <linux/platform_data/video-pxafb.h>
  41. #include <linux/platform_data/mmc-pxamci.h>
  42. #include <linux/platform_data/irda-pxaficp.h>
  43. #include <linux/platform_data/usb-ohci-pxa27x.h>
  44. #include <linux/regulator/max1586.h>
  45. #include <linux/platform_data/pxa2xx_udc.h>
  46. #include "udc.h"
  47. #include "pxa27x-udc.h"
  48. #include "devices.h"
  49. #include "generic.h"
  50. #include <linux/spi/spi.h>
  51. #include <linux/spi/pxa2xx_spi.h>
  52. #include <linux/spi/ads7846.h>
  53. static unsigned long magician_pin_config[] __initdata = {
  54. /* SDRAM and Static Memory I/O Signals */
  55. GPIO20_nSDCS_2,
  56. GPIO21_nSDCS_3,
  57. GPIO15_nCS_1,
  58. GPIO78_nCS_2, /* PASIC3 */
  59. GPIO79_nCS_3, /* EGPIO CPLD */
  60. GPIO80_nCS_4,
  61. GPIO33_nCS_5,
  62. /* I2C UDA1380 + OV9640 */
  63. GPIO117_I2C_SCL,
  64. GPIO118_I2C_SDA,
  65. /* PWM 0 - LCD backlight */
  66. GPIO16_PWM0_OUT,
  67. /* I2S UDA1380 capture */
  68. GPIO28_I2S_BITCLK_OUT,
  69. GPIO29_I2S_SDATA_IN,
  70. GPIO31_I2S_SYNC,
  71. GPIO113_I2S_SYSCLK,
  72. /* SSP 1 UDA1380 playback */
  73. GPIO23_SSP1_SCLK,
  74. GPIO24_SSP1_SFRM,
  75. GPIO25_SSP1_TXD,
  76. /* SSP 2 TSC2046 touchscreen */
  77. GPIO19_SSP2_SCLK,
  78. MFP_CFG_OUT(GPIO14, AF0, DRIVE_HIGH), /* frame as GPIO */
  79. GPIO89_SSP2_TXD,
  80. GPIO88_SSP2_RXD,
  81. /* MMC/SD/SDHC slot */
  82. GPIO32_MMC_CLK,
  83. GPIO92_MMC_DAT_0,
  84. GPIO109_MMC_DAT_1,
  85. GPIO110_MMC_DAT_2,
  86. GPIO111_MMC_DAT_3,
  87. GPIO112_MMC_CMD,
  88. /* LCD */
  89. GPIOxx_LCD_TFT_16BPP,
  90. /* QCI camera interface */
  91. GPIO12_CIF_DD_7,
  92. GPIO17_CIF_DD_6,
  93. GPIO50_CIF_DD_3,
  94. GPIO51_CIF_DD_2,
  95. GPIO52_CIF_DD_4,
  96. GPIO53_CIF_MCLK,
  97. GPIO54_CIF_PCLK,
  98. GPIO55_CIF_DD_1,
  99. GPIO81_CIF_DD_0,
  100. GPIO82_CIF_DD_5,
  101. GPIO84_CIF_FV,
  102. GPIO85_CIF_LV,
  103. /* Magician specific input GPIOs */
  104. GPIO9_GPIO, /* unknown */
  105. GPIO10_GPIO, /* GSM_IRQ */
  106. GPIO13_GPIO, /* CPLD_IRQ */
  107. GPIO107_GPIO, /* DS1WM_IRQ */
  108. GPIO108_GPIO, /* GSM_READY */
  109. GPIO115_GPIO, /* nPEN_IRQ */
  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 with DS1WM
  399. */
  400. static struct resource pasic3_resources[] = {
  401. [0] = {
  402. .start = PXA_CS2_PHYS,
  403. .end = PXA_CS2_PHYS + 0x1b,
  404. .flags = IORESOURCE_MEM,
  405. },
  406. /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
  407. [1] = {
  408. .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  409. .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  410. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  411. }
  412. };
  413. static struct pasic3_platform_data pasic3_platform_data = {
  414. .clock_rate = 4000000,
  415. };
  416. static struct platform_device pasic3 = {
  417. .name = "pasic3",
  418. .id = -1,
  419. .num_resources = ARRAY_SIZE(pasic3_resources),
  420. .resource = pasic3_resources,
  421. .dev = {
  422. .platform_data = &pasic3_platform_data,
  423. },
  424. };
  425. /*
  426. * PXA UDC
  427. */
  428. static void magician_udc_command(int cmd)
  429. {
  430. if (cmd == PXA2XX_UDC_CMD_CONNECT)
  431. UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
  432. else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
  433. UP2OCR &= ~(UP2OCR_DPPUE | UP2OCR_DPPUBE);
  434. }
  435. static struct pxa2xx_udc_mach_info magician_udc_info __initdata = {
  436. .udc_command = magician_udc_command,
  437. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  438. };
  439. /*
  440. * USB device VBus detection
  441. */
  442. static struct resource gpio_vbus_resource = {
  443. .flags = IORESOURCE_IRQ,
  444. .start = IRQ_MAGICIAN_VBUS,
  445. .end = IRQ_MAGICIAN_VBUS,
  446. };
  447. static struct gpio_vbus_mach_info gpio_vbus_info = {
  448. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  449. .gpio_vbus = EGPIO_MAGICIAN_CABLE_VBUS,
  450. };
  451. static struct platform_device gpio_vbus = {
  452. .name = "gpio-vbus",
  453. .id = -1,
  454. .num_resources = 1,
  455. .resource = &gpio_vbus_resource,
  456. .dev = {
  457. .platform_data = &gpio_vbus_info,
  458. },
  459. };
  460. /*
  461. * External power
  462. */
  463. static int magician_supply_init(struct device *dev)
  464. {
  465. int ret = -1;
  466. ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger");
  467. if (ret) {
  468. pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret);
  469. goto err_ac;
  470. }
  471. ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted");
  472. if (ret) {
  473. pr_err("Cannot request cable detection GPIO (%i)\n", ret);
  474. goto err_usb;
  475. }
  476. return 0;
  477. err_usb:
  478. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  479. err_ac:
  480. return ret;
  481. }
  482. static void magician_set_charge(int flags)
  483. {
  484. if (flags & PDA_POWER_CHARGE_AC) {
  485. pr_debug("Charging from AC\n");
  486. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  487. } else if (flags & PDA_POWER_CHARGE_USB) {
  488. pr_debug("Charging from USB\n");
  489. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
  490. } else {
  491. pr_debug("Charging disabled\n");
  492. gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0);
  493. }
  494. }
  495. static int magician_is_ac_online(void)
  496. {
  497. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  498. gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */
  499. }
  500. static int magician_is_usb_online(void)
  501. {
  502. return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
  503. (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */
  504. }
  505. static void magician_supply_exit(struct device *dev)
  506. {
  507. gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED);
  508. gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
  509. }
  510. static char *magician_supplicants[] = {
  511. "ds2760-battery.0", "backup-battery"
  512. };
  513. static struct pda_power_pdata power_supply_info = {
  514. .init = magician_supply_init,
  515. .exit = magician_supply_exit,
  516. .is_ac_online = magician_is_ac_online,
  517. .is_usb_online = magician_is_usb_online,
  518. .set_charge = magician_set_charge,
  519. .supplied_to = magician_supplicants,
  520. .num_supplicants = ARRAY_SIZE(magician_supplicants),
  521. };
  522. static struct resource power_supply_resources[] = {
  523. [0] = {
  524. .name = "ac",
  525. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  526. IORESOURCE_IRQ_LOWEDGE,
  527. .start = IRQ_MAGICIAN_VBUS,
  528. .end = IRQ_MAGICIAN_VBUS,
  529. },
  530. [1] = {
  531. .name = "usb",
  532. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  533. IORESOURCE_IRQ_LOWEDGE,
  534. .start = IRQ_MAGICIAN_VBUS,
  535. .end = IRQ_MAGICIAN_VBUS,
  536. },
  537. };
  538. static struct platform_device power_supply = {
  539. .name = "pda-power",
  540. .id = -1,
  541. .dev = {
  542. .platform_data = &power_supply_info,
  543. },
  544. .resource = power_supply_resources,
  545. .num_resources = ARRAY_SIZE(power_supply_resources),
  546. };
  547. /*
  548. * Battery charger
  549. */
  550. static struct regulator_consumer_supply bq24022_consumers[] = {
  551. REGULATOR_SUPPLY("vbus_draw", NULL),
  552. REGULATOR_SUPPLY("ac_draw", NULL),
  553. };
  554. static struct regulator_init_data bq24022_init_data = {
  555. .constraints = {
  556. .max_uA = 500000,
  557. .valid_ops_mask = REGULATOR_CHANGE_CURRENT |
  558. REGULATOR_CHANGE_STATUS,
  559. },
  560. .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
  561. .consumer_supplies = bq24022_consumers,
  562. };
  563. static struct gpio bq24022_gpios[] = {
  564. { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
  565. };
  566. static struct gpio_regulator_state bq24022_states[] = {
  567. { .value = 100000, .gpios = (0 << 0) },
  568. { .value = 500000, .gpios = (1 << 0) },
  569. };
  570. static struct gpio_regulator_config bq24022_info = {
  571. .supply_name = "bq24022",
  572. .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
  573. .enable_high = 0,
  574. .enabled_at_boot = 1,
  575. .gpios = bq24022_gpios,
  576. .nr_gpios = ARRAY_SIZE(bq24022_gpios),
  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. /*
  590. * fixed regulator for ads7846
  591. */
  592. static struct regulator_consumer_supply ads7846_supply =
  593. REGULATOR_SUPPLY("vcc", "spi2.0");
  594. static struct regulator_init_data vads7846_regulator = {
  595. .constraints = {
  596. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  597. },
  598. .num_consumer_supplies = 1,
  599. .consumer_supplies = &ads7846_supply,
  600. };
  601. static struct fixed_voltage_config vads7846 = {
  602. .supply_name = "vads7846",
  603. .microvolts = 3300000, /* probably */
  604. .gpio = -EINVAL,
  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