magician.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*
  2. * Support for HTC Magician PDA phones:
  3. * i-mate JAM, O2 Xda mini, Orange SPV M500, Qtek s100, Qtek s110
  4. * and T-Mobile MDA Compact.
  5. *
  6. * Copyright (c) 2006-2007 Philipp Zabel
  7. *
  8. * Based on hx4700.c, spitz.c and others.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/delay.h>
  19. #include <linux/gpio.h>
  20. #include <linux/gpio_keys.h>
  21. #include <linux/input.h>
  22. #include <linux/mfd/htc-egpio.h>
  23. #include <linux/mfd/htc-pasic3.h>
  24. #include <linux/mtd/physmap.h>
  25. #include <linux/pda_power.h>
  26. #include <linux/pwm_backlight.h>
  27. #include <linux/regulator/driver.h>
  28. #include <linux/regulator/gpio-regulator.h>
  29. #include <linux/regulator/machine.h>
  30. #include <linux/usb/gpio_vbus.h>
  31. #include <linux/i2c/pxa-i2c.h>
  32. #include <mach/hardware.h>
  33. #include <asm/mach-types.h>
  34. #include <asm/mach/arch.h>
  35. #include <asm/system_info.h>
  36. #include <mach/pxa27x.h>
  37. #include <mach/magician.h>
  38. #include <mach/pxafb.h>
  39. #include <mach/mmc.h>
  40. #include <mach/irda.h>
  41. #include <mach/ohci.h>
  42. #include "devices.h"
  43. #include "generic.h"
  44. static unsigned long magician_pin_config[] __initdata = {
  45. /* SDRAM and Static Memory I/O Signals */
  46. GPIO20_nSDCS_2,
  47. GPIO21_nSDCS_3,
  48. GPIO15_nCS_1,
  49. GPIO78_nCS_2, /* PASIC3 */
  50. GPIO79_nCS_3, /* EGPIO CPLD */
  51. GPIO80_nCS_4,
  52. GPIO33_nCS_5,
  53. /* I2C */
  54. GPIO117_I2C_SCL,
  55. GPIO118_I2C_SDA,
  56. /* PWM 0 */
  57. GPIO16_PWM0_OUT,
  58. /* I2S */
  59. GPIO28_I2S_BITCLK_OUT,
  60. GPIO29_I2S_SDATA_IN,
  61. GPIO31_I2S_SYNC,
  62. GPIO113_I2S_SYSCLK,
  63. /* SSP 1 */
  64. GPIO23_SSP1_SCLK,
  65. GPIO24_SSP1_SFRM,
  66. GPIO25_SSP1_TXD,
  67. /* SSP 2 */
  68. GPIO19_SSP2_SCLK,
  69. GPIO14_SSP2_SFRM,
  70. GPIO89_SSP2_TXD,
  71. GPIO88_SSP2_RXD,
  72. /* MMC */
  73. GPIO32_MMC_CLK,
  74. GPIO92_MMC_DAT_0,
  75. GPIO109_MMC_DAT_1,
  76. GPIO110_MMC_DAT_2,
  77. GPIO111_MMC_DAT_3,
  78. GPIO112_MMC_CMD,
  79. /* LCD */
  80. GPIOxx_LCD_TFT_16BPP,
  81. /* QCI */
  82. GPIO12_CIF_DD_7,
  83. GPIO17_CIF_DD_6,
  84. GPIO50_CIF_DD_3,
  85. GPIO51_CIF_DD_2,
  86. GPIO52_CIF_DD_4,
  87. GPIO53_CIF_MCLK,
  88. GPIO54_CIF_PCLK,
  89. GPIO55_CIF_DD_1,
  90. GPIO81_CIF_DD_0,
  91. GPIO82_CIF_DD_5,
  92. GPIO84_CIF_FV,
  93. GPIO85_CIF_LV,
  94. /* Magician specific input GPIOs */
  95. GPIO9_GPIO, /* unknown */
  96. GPIO10_GPIO, /* GSM_IRQ */
  97. GPIO13_GPIO, /* CPLD_IRQ */
  98. GPIO107_GPIO, /* DS1WM_IRQ */
  99. GPIO108_GPIO, /* GSM_READY */
  100. GPIO115_GPIO, /* nPEN_IRQ */
  101. /* I2C */
  102. GPIO117_I2C_SCL,
  103. GPIO118_I2C_SDA,
  104. };
  105. /*
  106. * IRDA
  107. */
  108. static struct pxaficp_platform_data magician_ficp_info = {
  109. .gpio_pwdown = GPIO83_MAGICIAN_nIR_EN,
  110. .transceiver_cap = IR_SIRMODE | IR_OFF,
  111. };
  112. /*
  113. * GPIO Keys
  114. */
  115. #define INIT_KEY(_code, _gpio, _desc) \
  116. { \
  117. .code = KEY_##_code, \
  118. .gpio = _gpio, \
  119. .desc = _desc, \
  120. .type = EV_KEY, \
  121. .wakeup = 1, \
  122. }
  123. static struct gpio_keys_button magician_button_table[] = {
  124. INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
  125. INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
  126. INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
  127. INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
  128. INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
  129. INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
  130. INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
  131. INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
  132. INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
  133. INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
  134. INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
  135. INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
  136. INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
  137. INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
  138. INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
  139. };
  140. static struct gpio_keys_platform_data gpio_keys_data = {
  141. .buttons = magician_button_table,
  142. .nbuttons = ARRAY_SIZE(magician_button_table),
  143. };
  144. static struct platform_device gpio_keys = {
  145. .name = "gpio-keys",
  146. .dev = {
  147. .platform_data = &gpio_keys_data,
  148. },
  149. .id = -1,
  150. };
  151. /*
  152. * EGPIO (Xilinx CPLD)
  153. *
  154. * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
  155. */
  156. static struct resource egpio_resources[] = {
  157. [0] = {
  158. .start = PXA_CS3_PHYS,
  159. .end = PXA_CS3_PHYS + 0x20 - 1,
  160. .flags = IORESOURCE_MEM,
  161. },
  162. [1] = {
  163. .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
  164. .end = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
  165. .flags = IORESOURCE_IRQ,
  166. },
  167. };
  168. static struct htc_egpio_chip egpio_chips[] = {
  169. [0] = {
  170. .reg_start = 0,
  171. .gpio_base = MAGICIAN_EGPIO(0, 0),
  172. .num_gpios = 24,
  173. .direction = HTC_EGPIO_OUTPUT,
  174. .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
  175. },
  176. [1] = {
  177. .reg_start = 4,
  178. .gpio_base = MAGICIAN_EGPIO(4, 0),
  179. .num_gpios = 24,
  180. .direction = HTC_EGPIO_INPUT,
  181. },
  182. };
  183. static struct htc_egpio_platform_data egpio_info = {
  184. .reg_width = 8,
  185. .bus_width = 32,
  186. .irq_base = IRQ_BOARD_START,
  187. .num_irqs = 4,
  188. .ack_register = 3,
  189. .chip = egpio_chips,
  190. .num_chips = ARRAY_SIZE(egpio_chips),
  191. };
  192. static struct platform_device egpio = {
  193. .name = "htc-egpio",
  194. .id = -1,
  195. .resource = egpio_resources,
  196. .num_resources = ARRAY_SIZE(egpio_resources),
  197. .dev = {
  198. .platform_data = &egpio_info,
  199. },
  200. };
  201. /*
  202. * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
  203. */
  204. static struct pxafb_mode_info toppoly_modes[] = {
  205. {
  206. .pixclock = 96153,
  207. .bpp = 16,
  208. .xres = 240,
  209. .yres = 320,
  210. .hsync_len = 11,
  211. .vsync_len = 3,
  212. .left_margin = 19,
  213. .upper_margin = 2,
  214. .right_margin = 10,
  215. .lower_margin = 2,
  216. .sync = 0,
  217. },
  218. };
  219. static struct pxafb_mode_info samsung_modes[] = {
  220. {
  221. .pixclock = 96153,
  222. .bpp = 16,
  223. .xres = 240,
  224. .yres = 320,
  225. .hsync_len = 8,
  226. .vsync_len = 4,
  227. .left_margin = 9,
  228. .upper_margin = 4,
  229. .right_margin = 9,
  230. .lower_margin = 4,
  231. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  232. },
  233. };
  234. static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
  235. {
  236. pr_debug("Toppoly LCD power\n");
  237. if (on) {
  238. pr_debug("on\n");
  239. gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
  240. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
  241. udelay(2000);
  242. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  243. udelay(2000);
  244. /* FIXME: enable LCDC here */
  245. udelay(2000);
  246. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
  247. udelay(2000);
  248. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
  249. } else {
  250. pr_debug("off\n");
  251. msleep(15);
  252. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
  253. udelay(500);
  254. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
  255. udelay(1000);
  256. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
  257. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  258. }
  259. }
  260. static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
  261. {
  262. pr_debug("Samsung LCD power\n");
  263. if (on) {
  264. pr_debug("on\n");
  265. if (system_rev < 3)
  266. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
  267. else
  268. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  269. mdelay(10);
  270. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
  271. mdelay(10);
  272. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
  273. mdelay(30);
  274. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
  275. mdelay(10);
  276. } else {
  277. pr_debug("off\n");
  278. mdelay(10);
  279. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
  280. mdelay(30);
  281. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
  282. mdelay(10);
  283. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
  284. mdelay(10);
  285. if (system_rev < 3)
  286. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
  287. else
  288. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  289. }
  290. }
  291. static struct pxafb_mach_info toppoly_info = {
  292. .modes = toppoly_modes,
  293. .num_modes = 1,
  294. .fixed_modes = 1,
  295. .lcd_conn = LCD_COLOR_TFT_16BPP,
  296. .pxafb_lcd_power = toppoly_lcd_power,
  297. };
  298. static struct pxafb_mach_info samsung_info = {
  299. .modes = samsung_modes,
  300. .num_modes = 1,
  301. .fixed_modes = 1,
  302. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
  303. LCD_ALTERNATE_MAPPING,
  304. .pxafb_lcd_power = samsung_lcd_power,
  305. };
  306. /*
  307. * Backlight
  308. */
  309. static struct gpio magician_bl_gpios[] = {
  310. { EGPIO_MAGICIAN_BL_POWER, GPIOF_DIR_OUT, "Backlight power" },
  311. { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" },
  312. };
  313. static int magician_backlight_init(struct device *dev)
  314. {
  315. return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios));
  316. }
  317. static int magician_backlight_notify(struct device *dev, int brightness)
  318. {
  319. gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
  320. if (brightness >= 200) {
  321. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
  322. return brightness - 72;
  323. } else {
  324. gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
  325. return brightness;
  326. }
  327. }
  328. static void magician_backlight_exit(struct device *dev)
  329. {
  330. gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios));
  331. }
  332. static struct platform_pwm_backlight_data backlight_data = {
  333. .pwm_id = 0,
  334. .max_brightness = 272,
  335. .dft_brightness = 100,
  336. .pwm_period_ns = 30923,
  337. .init = magician_backlight_init,
  338. .notify = magician_backlight_notify,
  339. .exit = magician_backlight_exit,
  340. };
  341. static struct platform_device backlight = {
  342. .name = "pwm-backlight",
  343. .id = -1,
  344. .dev = {
  345. .parent = &pxa27x_device_pwm0.dev,
  346. .platform_data = &backlight_data,
  347. },
  348. };
  349. /*
  350. * LEDs
  351. */
  352. static struct gpio_led gpio_leds[] = {
  353. {
  354. .name = "magician::vibra",
  355. .default_trigger = "none",
  356. .gpio = GPIO22_MAGICIAN_VIBRA_EN,
  357. },
  358. {
  359. .name = "magician::phone_bl",
  360. .default_trigger = "backlight",
  361. .gpio = GPIO103_MAGICIAN_LED_KP,
  362. },
  363. };
  364. static struct gpio_led_platform_data gpio_led_info = {
  365. .leds = gpio_leds,
  366. .num_leds = ARRAY_SIZE(gpio_leds),
  367. };
  368. static struct platform_device leds_gpio = {
  369. .name = "leds-gpio",
  370. .id = -1,
  371. .dev = {
  372. .platform_data = &gpio_led_info,
  373. },
  374. };
  375. static struct pasic3_led pasic3_leds[] = {
  376. {
  377. .led = {
  378. .name = "magician:red",
  379. .default_trigger = "ds2760-battery.0-charging",
  380. },
  381. .hw_num = 0,
  382. .bit2 = PASIC3_BIT2_LED0,
  383. .mask = PASIC3_MASK_LED0,
  384. },
  385. {
  386. .led = {
  387. .name = "magician:green",
  388. .default_trigger = "ds2760-battery.0-charging-or-full",
  389. },
  390. .hw_num = 1,
  391. .bit2 = PASIC3_BIT2_LED1,
  392. .mask = PASIC3_MASK_LED1,
  393. },
  394. {
  395. .led = {
  396. .name = "magician:blue",
  397. .default_trigger = "bluetooth",
  398. },
  399. .hw_num = 2,
  400. .bit2 = PASIC3_BIT2_LED2,
  401. .mask = PASIC3_MASK_LED2,
  402. },
  403. };
  404. static struct pasic3_leds_machinfo pasic3_leds_info = {
  405. .num_leds = ARRAY_SIZE(pasic3_leds),
  406. .power_gpio = EGPIO_MAGICIAN_LED_POWER,
  407. .leds = pasic3_leds,
  408. };
  409. /*
  410. * PASIC3 with DS1WM
  411. */
  412. static struct resource pasic3_resources[] = {
  413. [0] = {
  414. .start = PXA_CS2_PHYS,
  415. .end = PXA_CS2_PHYS + 0x1b,
  416. .flags = IORESOURCE_MEM,
  417. },
  418. /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
  419. [1] = {
  420. .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  421. .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
  422. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  423. }
  424. };
  425. static struct pasic3_platform_data pasic3_platform_data = {
  426. .led_pdata = &pasic3_leds_info,
  427. .clock_rate = 4000000,
  428. };
  429. static struct platform_device pasic3 = {
  430. .name = "pasic3",
  431. .id = -1,
  432. .num_resources = ARRAY_SIZE(pasic3_resources),
  433. .resource = pasic3_resources,
  434. .dev = {
  435. .platform_data = &pasic3_platform_data,
  436. },
  437. };
  438. /*
  439. * USB "Transceiver"
  440. */
  441. static struct resource gpio_vbus_resource = {
  442. .flags = IORESOURCE_IRQ,
  443. .start = IRQ_MAGICIAN_VBUS,
  444. .end = IRQ_MAGICIAN_VBUS,
  445. };
  446. static struct gpio_vbus_mach_info gpio_vbus_info = {
  447. .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
  448. .gpio_vbus = EGPIO_MAGICIAN_CABLE_STATE_USB,
  449. };
  450. static struct platform_device gpio_vbus = {
  451. .name = "gpio-vbus",
  452. .id = -1,
  453. .num_resources = 1,
  454. .resource = &gpio_vbus_resource,
  455. .dev = {
  456. .platform_data = &gpio_vbus_info,
  457. },
  458. };
  459. /*
  460. * External power
  461. */
  462. static int power_supply_init(struct device *dev)
  463. {
  464. return gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
  465. }
  466. static int magician_is_ac_online(void)
  467. {
  468. return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
  469. }
  470. static void power_supply_exit(struct device *dev)
  471. {
  472. gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
  473. }
  474. static char *magician_supplicants[] = {
  475. "ds2760-battery.0", "backup-battery"
  476. };
  477. static struct pda_power_pdata power_supply_info = {
  478. .init = power_supply_init,
  479. .is_ac_online = magician_is_ac_online,
  480. .exit = power_supply_exit,
  481. .supplied_to = magician_supplicants,
  482. .num_supplicants = ARRAY_SIZE(magician_supplicants),
  483. };
  484. static struct resource power_supply_resources[] = {
  485. [0] = {
  486. .name = "ac",
  487. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  488. IORESOURCE_IRQ_LOWEDGE,
  489. .start = IRQ_MAGICIAN_VBUS,
  490. .end = IRQ_MAGICIAN_VBUS,
  491. },
  492. [1] = {
  493. .name = "usb",
  494. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  495. IORESOURCE_IRQ_LOWEDGE,
  496. .start = IRQ_MAGICIAN_VBUS,
  497. .end = IRQ_MAGICIAN_VBUS,
  498. },
  499. };
  500. static struct platform_device power_supply = {
  501. .name = "pda-power",
  502. .id = -1,
  503. .dev = {
  504. .platform_data = &power_supply_info,
  505. },
  506. .resource = power_supply_resources,
  507. .num_resources = ARRAY_SIZE(power_supply_resources),
  508. };
  509. /*
  510. * Battery charger
  511. */
  512. static struct regulator_consumer_supply bq24022_consumers[] = {
  513. {
  514. .supply = "vbus_draw",
  515. },
  516. {
  517. .supply = "ac_draw",
  518. },
  519. };
  520. static struct regulator_init_data bq24022_init_data = {
  521. .constraints = {
  522. .max_uA = 500000,
  523. .valid_ops_mask = REGULATOR_CHANGE_CURRENT | REGULATOR_CHANGE_STATUS,
  524. },
  525. .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
  526. .consumer_supplies = bq24022_consumers,
  527. };
  528. static struct gpio bq24022_gpios[] = {
  529. { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
  530. };
  531. static struct gpio_regulator_state bq24022_states[] = {
  532. { .value = 100000, .gpios = (0 << 0) },
  533. { .value = 500000, .gpios = (1 << 0) },
  534. };
  535. static struct gpio_regulator_config bq24022_info = {
  536. .supply_name = "bq24022",
  537. .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
  538. .enable_high = 0,
  539. .enabled_at_boot = 0,
  540. .gpios = bq24022_gpios,
  541. .nr_gpios = ARRAY_SIZE(bq24022_gpios),
  542. .states = bq24022_states,
  543. .nr_states = ARRAY_SIZE(bq24022_states),
  544. .type = REGULATOR_CURRENT,
  545. .init_data = &bq24022_init_data,
  546. };
  547. static struct platform_device bq24022 = {
  548. .name = "gpio-regulator",
  549. .id = -1,
  550. .dev = {
  551. .platform_data = &bq24022_info,
  552. },
  553. };
  554. /*
  555. * MMC/SD
  556. */
  557. static int magician_mci_init(struct device *dev,
  558. irq_handler_t detect_irq, void *data)
  559. {
  560. return request_irq(IRQ_MAGICIAN_SD, detect_irq,
  561. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  562. "mmc card detect", data);
  563. }
  564. static void magician_mci_exit(struct device *dev, void *data)
  565. {
  566. free_irq(IRQ_MAGICIAN_SD, data);
  567. }
  568. static struct pxamci_platform_data magician_mci_info = {
  569. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  570. .init = magician_mci_init,
  571. .exit = magician_mci_exit,
  572. .gpio_card_detect = -1,
  573. .gpio_card_ro = EGPIO_MAGICIAN_nSD_READONLY,
  574. .gpio_card_ro_invert = 1,
  575. .gpio_power = EGPIO_MAGICIAN_SD_POWER,
  576. };
  577. /*
  578. * USB OHCI
  579. */
  580. static struct pxaohci_platform_data magician_ohci_info = {
  581. .port_mode = PMM_PERPORT_MODE,
  582. .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
  583. .power_budget = 0,
  584. };
  585. /*
  586. * StrataFlash
  587. */
  588. static void magician_set_vpp(struct platform_device *pdev, int vpp)
  589. {
  590. gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
  591. }
  592. static struct resource strataflash_resource = {
  593. .start = PXA_CS0_PHYS,
  594. .end = PXA_CS0_PHYS + SZ_64M - 1,
  595. .flags = IORESOURCE_MEM,
  596. };
  597. static struct physmap_flash_data strataflash_data = {
  598. .width = 4,
  599. .set_vpp = magician_set_vpp,
  600. };
  601. static struct platform_device strataflash = {
  602. .name = "physmap-flash",
  603. .id = -1,
  604. .resource = &strataflash_resource,
  605. .num_resources = 1,
  606. .dev = {
  607. .platform_data = &strataflash_data,
  608. },
  609. };
  610. /*
  611. * I2C
  612. */
  613. static struct i2c_pxa_platform_data i2c_info = {
  614. .fast_mode = 1,
  615. };
  616. /*
  617. * Platform devices
  618. */
  619. static struct platform_device *devices[] __initdata = {
  620. &gpio_keys,
  621. &egpio,
  622. &backlight,
  623. &pasic3,
  624. &bq24022,
  625. &gpio_vbus,
  626. &power_supply,
  627. &strataflash,
  628. &leds_gpio,
  629. };
  630. static struct gpio magician_global_gpios[] = {
  631. { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" },
  632. { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
  633. { GPIO104_MAGICIAN_LCD_POWER_1, GPIOF_OUT_INIT_LOW, "LCD power 1" },
  634. { GPIO105_MAGICIAN_LCD_POWER_2, GPIOF_OUT_INIT_LOW, "LCD power 2" },
  635. { GPIO106_MAGICIAN_LCD_POWER_3, GPIOF_OUT_INIT_LOW, "LCD power 3" },
  636. { GPIO83_MAGICIAN_nIR_EN, GPIOF_OUT_INIT_HIGH, "nIR_EN" },
  637. };
  638. static void __init magician_init(void)
  639. {
  640. void __iomem *cpld;
  641. int lcd_select;
  642. int err;
  643. pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
  644. err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
  645. if (err)
  646. pr_err("magician: Failed to request GPIOs: %d\n", err);
  647. pxa_set_ffuart_info(NULL);
  648. pxa_set_btuart_info(NULL);
  649. pxa_set_stuart_info(NULL);
  650. platform_add_devices(ARRAY_AND_SIZE(devices));
  651. pxa_set_ficp_info(&magician_ficp_info);
  652. pxa27x_set_i2c_power_info(NULL);
  653. pxa_set_i2c_info(&i2c_info);
  654. pxa_set_mci_info(&magician_mci_info);
  655. pxa_set_ohci_info(&magician_ohci_info);
  656. /* Check LCD type we have */
  657. cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
  658. if (cpld) {
  659. u8 board_id = __raw_readb(cpld+0x14);
  660. iounmap(cpld);
  661. system_rev = board_id & 0x7;
  662. lcd_select = board_id & 0x8;
  663. pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
  664. if (lcd_select && (system_rev < 3))
  665. gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
  666. GPIOF_OUT_INIT_LOW, "SAMSUNG_POWER");
  667. pxa_set_fb_info(NULL, lcd_select ? &samsung_info : &toppoly_info);
  668. } else
  669. pr_err("LCD detection: CPLD mapping failed\n");
  670. }
  671. MACHINE_START(MAGICIAN, "HTC Magician")
  672. .atag_offset = 0x100,
  673. .map_io = pxa27x_map_io,
  674. .nr_irqs = MAGICIAN_NR_IRQS,
  675. .init_irq = pxa27x_init_irq,
  676. .handle_irq = pxa27x_handle_irq,
  677. .init_machine = magician_init,
  678. .timer = &pxa_timer,
  679. .restart = pxa_restart,
  680. MACHINE_END