magician.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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_keys.h>
  20. #include <linux/input.h>
  21. #include <linux/mfd/htc-egpio.h>
  22. #include <linux/mtd/mtd.h>
  23. #include <linux/mtd/map.h>
  24. #include <linux/mtd/physmap.h>
  25. #include <linux/pda_power.h>
  26. #include <asm/gpio.h>
  27. #include <asm/hardware.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/arch/magician.h>
  31. #include <asm/arch/pxa-regs.h>
  32. #include <asm/arch/pxafb.h>
  33. #include <asm/arch/i2c.h>
  34. #include <asm/arch/mmc.h>
  35. #include <asm/arch/irda.h>
  36. #include <asm/arch/ohci.h>
  37. #include "generic.h"
  38. /*
  39. * IRDA
  40. */
  41. static void magician_irda_transceiver_mode(struct device *dev, int mode)
  42. {
  43. gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
  44. }
  45. static struct pxaficp_platform_data magician_ficp_info = {
  46. .transceiver_cap = IR_SIRMODE | IR_OFF,
  47. .transceiver_mode = magician_irda_transceiver_mode,
  48. };
  49. /*
  50. * GPIO Keys
  51. */
  52. static struct gpio_keys_button magician_button_table[] = {
  53. {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
  54. {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
  55. {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
  56. {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
  57. {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
  58. {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
  59. {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
  60. {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
  61. {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
  62. {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
  63. {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
  64. {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
  65. {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
  66. {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
  67. {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
  68. };
  69. static struct gpio_keys_platform_data gpio_keys_data = {
  70. .buttons = magician_button_table,
  71. .nbuttons = ARRAY_SIZE(magician_button_table),
  72. };
  73. static struct platform_device gpio_keys = {
  74. .name = "gpio-keys",
  75. .dev = {
  76. .platform_data = &gpio_keys_data,
  77. },
  78. .id = -1,
  79. };
  80. /*
  81. * EGPIO (Xilinx CPLD)
  82. *
  83. * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
  84. */
  85. static struct resource egpio_resources[] = {
  86. [0] = {
  87. .start = PXA_CS3_PHYS,
  88. .end = PXA_CS3_PHYS + 0x20,
  89. .flags = IORESOURCE_MEM,
  90. },
  91. [1] = {
  92. .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
  93. .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
  94. .flags = IORESOURCE_IRQ,
  95. },
  96. };
  97. static struct htc_egpio_chip egpio_chips[] = {
  98. [0] = {
  99. .reg_start = 0,
  100. .gpio_base = MAGICIAN_EGPIO(0, 0),
  101. .num_gpios = 24,
  102. .direction = HTC_EGPIO_OUTPUT,
  103. .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
  104. },
  105. [1] = {
  106. .reg_start = 4,
  107. .gpio_base = MAGICIAN_EGPIO(4, 0),
  108. .num_gpios = 24,
  109. .direction = HTC_EGPIO_INPUT,
  110. },
  111. };
  112. static struct htc_egpio_platform_data egpio_info = {
  113. .reg_width = 8,
  114. .bus_width = 32,
  115. .irq_base = IRQ_BOARD_START,
  116. .num_irqs = 4,
  117. .ack_register = 3,
  118. .chip = egpio_chips,
  119. .num_chips = ARRAY_SIZE(egpio_chips),
  120. };
  121. static struct platform_device egpio = {
  122. .name = "htc-egpio",
  123. .id = -1,
  124. .resource = egpio_resources,
  125. .num_resources = ARRAY_SIZE(egpio_resources),
  126. .dev = {
  127. .platform_data = &egpio_info,
  128. },
  129. };
  130. /*
  131. * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
  132. */
  133. static struct pxafb_mode_info toppoly_modes[] = {
  134. {
  135. .pixclock = 96153,
  136. .bpp = 16,
  137. .xres = 240,
  138. .yres = 320,
  139. .hsync_len = 11,
  140. .vsync_len = 3,
  141. .left_margin = 19,
  142. .upper_margin = 2,
  143. .right_margin = 10,
  144. .lower_margin = 2,
  145. .sync = 0,
  146. },
  147. };
  148. static struct pxafb_mode_info samsung_modes[] = {
  149. {
  150. .pixclock = 96153,
  151. .bpp = 16,
  152. .xres = 240,
  153. .yres = 320,
  154. .hsync_len = 8,
  155. .vsync_len = 4,
  156. .left_margin = 9,
  157. .upper_margin = 4,
  158. .right_margin = 9,
  159. .lower_margin = 4,
  160. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  161. },
  162. };
  163. static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
  164. {
  165. pr_debug("Toppoly LCD power\n");
  166. if (on) {
  167. pr_debug("on\n");
  168. gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
  169. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
  170. udelay(2000);
  171. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  172. udelay(2000);
  173. /* FIXME: enable LCDC here */
  174. udelay(2000);
  175. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
  176. udelay(2000);
  177. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
  178. } else {
  179. pr_debug("off\n");
  180. msleep(15);
  181. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
  182. udelay(500);
  183. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
  184. udelay(1000);
  185. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
  186. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  187. }
  188. }
  189. static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
  190. {
  191. pr_debug("Samsung LCD power\n");
  192. if (on) {
  193. pr_debug("on\n");
  194. if (system_rev < 3)
  195. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
  196. else
  197. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
  198. mdelay(10);
  199. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
  200. mdelay(10);
  201. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
  202. mdelay(30);
  203. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
  204. mdelay(10);
  205. } else {
  206. pr_debug("off\n");
  207. mdelay(10);
  208. gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
  209. mdelay(30);
  210. gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
  211. mdelay(10);
  212. gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
  213. mdelay(10);
  214. if (system_rev < 3)
  215. gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
  216. else
  217. gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
  218. }
  219. }
  220. static struct pxafb_mach_info toppoly_info = {
  221. .modes = toppoly_modes,
  222. .num_modes = 1,
  223. .fixed_modes = 1,
  224. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  225. .lccr3 = LCCR3_PixRsEdg,
  226. .pxafb_lcd_power = toppoly_lcd_power,
  227. };
  228. static struct pxafb_mach_info samsung_info = {
  229. .modes = samsung_modes,
  230. .num_modes = 1,
  231. .fixed_modes = 1,
  232. .lccr0 = LCCR0_LDDALT | LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  233. .lccr3 = LCCR3_PixFlEdg,
  234. .pxafb_lcd_power = samsung_lcd_power,
  235. };
  236. /*
  237. * Backlight
  238. */
  239. static void magician_set_bl_intensity(int intensity)
  240. {
  241. if (intensity) {
  242. PWM_CTRL0 = 1;
  243. PWM_PERVAL0 = 0xc8;
  244. PWM_PWDUTY0 = intensity;
  245. pxa_set_cken(CKEN_PWM0, 1);
  246. } else {
  247. pxa_set_cken(CKEN_PWM0, 0);
  248. }
  249. }
  250. static struct generic_bl_info backlight_info = {
  251. .default_intensity = 0x64,
  252. .limit_mask = 0x0b,
  253. .max_intensity = 0xc7,
  254. .set_bl_intensity = magician_set_bl_intensity,
  255. };
  256. static struct platform_device backlight = {
  257. .name = "generic-bl",
  258. .dev = {
  259. .platform_data = &backlight_info,
  260. },
  261. .id = -1,
  262. };
  263. /*
  264. * External power
  265. */
  266. static int magician_is_ac_online(void)
  267. {
  268. return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
  269. }
  270. static int magician_is_usb_online(void)
  271. {
  272. return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB);
  273. }
  274. static void magician_set_charge(int flags)
  275. {
  276. gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags);
  277. gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags);
  278. }
  279. static struct pda_power_pdata power_supply_info = {
  280. .is_ac_online = magician_is_ac_online,
  281. .is_usb_online = magician_is_usb_online,
  282. .set_charge = magician_set_charge,
  283. };
  284. static struct resource power_supply_resources[] = {
  285. [0] = {
  286. .name = "ac",
  287. .flags = IORESOURCE_IRQ,
  288. .start = IRQ_MAGICIAN_AC,
  289. .end = IRQ_MAGICIAN_AC,
  290. },
  291. [1] = {
  292. .name = "usb",
  293. .flags = IORESOURCE_IRQ,
  294. .start = IRQ_MAGICIAN_AC,
  295. .end = IRQ_MAGICIAN_AC,
  296. },
  297. };
  298. static struct platform_device power_supply = {
  299. .name = "pda-power",
  300. .id = -1,
  301. .dev = {
  302. .platform_data = &power_supply_info,
  303. },
  304. .resource = power_supply_resources,
  305. .num_resources = ARRAY_SIZE(power_supply_resources),
  306. };
  307. /*
  308. * MMC/SD
  309. */
  310. static int magician_mci_init(struct device *dev,
  311. irq_handler_t detect_irq, void *data)
  312. {
  313. return request_irq(IRQ_MAGICIAN_SD, detect_irq,
  314. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  315. "MMC card detect", data);
  316. }
  317. static void magician_mci_setpower(struct device *dev, unsigned int vdd)
  318. {
  319. struct pxamci_platform_data *pdata = dev->platform_data;
  320. gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
  321. }
  322. static int magician_mci_get_ro(struct device *dev)
  323. {
  324. return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
  325. }
  326. static void magician_mci_exit(struct device *dev, void *data)
  327. {
  328. free_irq(IRQ_MAGICIAN_SD, data);
  329. }
  330. static struct pxamci_platform_data magician_mci_info = {
  331. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  332. .init = magician_mci_init,
  333. .get_ro = magician_mci_get_ro,
  334. .setpower = magician_mci_setpower,
  335. .exit = magician_mci_exit,
  336. };
  337. /*
  338. * USB OHCI
  339. */
  340. static int magician_ohci_init(struct device *dev)
  341. {
  342. UHCHR = (UHCHR | UHCHR_SSEP2 | UHCHR_PCPL | UHCHR_CGR) &
  343. ~(UHCHR_SSEP1 | UHCHR_SSEP3 | UHCHR_SSE);
  344. return 0;
  345. }
  346. static struct pxaohci_platform_data magician_ohci_info = {
  347. .port_mode = PMM_PERPORT_MODE,
  348. .init = magician_ohci_init,
  349. .power_budget = 0,
  350. };
  351. /*
  352. * StrataFlash
  353. */
  354. static void magician_set_vpp(struct map_info *map, int vpp)
  355. {
  356. gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
  357. }
  358. #define PXA_CS_SIZE 0x04000000
  359. static struct resource strataflash_resource = {
  360. .start = PXA_CS0_PHYS,
  361. .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
  362. .flags = IORESOURCE_MEM,
  363. };
  364. static struct physmap_flash_data strataflash_data = {
  365. .width = 4,
  366. .set_vpp = magician_set_vpp,
  367. };
  368. static struct platform_device strataflash = {
  369. .name = "physmap-flash",
  370. .id = -1,
  371. .resource = &strataflash_resource,
  372. .num_resources = 1,
  373. .dev = {
  374. .platform_data = &strataflash_data,
  375. },
  376. };
  377. /*
  378. * Platform devices
  379. */
  380. static struct platform_device *devices[] __initdata = {
  381. &gpio_keys,
  382. &egpio,
  383. &backlight,
  384. &power_supply,
  385. &strataflash,
  386. };
  387. static void __init magician_init(void)
  388. {
  389. void __iomem *cpld;
  390. int lcd_select;
  391. platform_add_devices(devices, ARRAY_SIZE(devices));
  392. pxa_set_i2c_info(NULL);
  393. pxa_set_mci_info(&magician_mci_info);
  394. pxa_set_ohci_info(&magician_ohci_info);
  395. pxa_set_ficp_info(&magician_ficp_info);
  396. /* Check LCD type we have */
  397. cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
  398. if (cpld) {
  399. u8 board_id = __raw_readb(cpld+0x14);
  400. system_rev = board_id & 0x7;
  401. lcd_select = board_id & 0x8;
  402. iounmap(cpld);
  403. pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
  404. if (lcd_select && (system_rev < 3))
  405. pxa_gpio_mode(GPIO75_MAGICIAN_SAMSUNG_POWER_MD);
  406. pxa_gpio_mode(GPIO104_MAGICIAN_LCD_POWER_1_MD);
  407. pxa_gpio_mode(GPIO105_MAGICIAN_LCD_POWER_2_MD);
  408. pxa_gpio_mode(GPIO106_MAGICIAN_LCD_POWER_3_MD);
  409. set_pxa_fb_info(lcd_select ? &samsung_info : &toppoly_info);
  410. } else
  411. pr_err("LCD detection: CPLD mapping failed\n");
  412. }
  413. MACHINE_START(MAGICIAN, "HTC Magician")
  414. .phys_io = 0x40000000,
  415. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  416. .boot_params = 0xa0000100,
  417. .map_io = pxa_map_io,
  418. .init_irq = pxa27x_init_irq,
  419. .init_machine = magician_init,
  420. .timer = &pxa_timer,
  421. MACHINE_END