magician.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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/gpio_keys.h>
  19. #include <linux/input.h>
  20. #include <linux/mfd/htc-egpio.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/map.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <asm/gpio.h>
  25. #include <asm/hardware.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/mach/arch.h>
  28. #include <asm/arch/magician.h>
  29. #include <asm/arch/pxa-regs.h>
  30. #include <asm/arch/pxafb.h>
  31. #include <asm/arch/i2c.h>
  32. #include <asm/arch/mmc.h>
  33. #include <asm/arch/irda.h>
  34. #include <asm/arch/ohci.h>
  35. #include "generic.h"
  36. /*
  37. * IRDA
  38. */
  39. static void magician_irda_transceiver_mode(struct device *dev, int mode)
  40. {
  41. gpio_set_value(GPIO83_MAGICIAN_nIR_EN, mode & IR_OFF);
  42. }
  43. static struct pxaficp_platform_data magician_ficp_info = {
  44. .transceiver_cap = IR_SIRMODE | IR_OFF,
  45. .transceiver_mode = magician_irda_transceiver_mode,
  46. };
  47. /*
  48. * GPIO Keys
  49. */
  50. static struct gpio_keys_button magician_button_table[] = {
  51. {KEY_POWER, GPIO0_MAGICIAN_KEY_POWER, 0, "Power button"},
  52. {KEY_ESC, GPIO37_MAGICIAN_KEY_HANGUP, 0, "Hangup button"},
  53. {KEY_F10, GPIO38_MAGICIAN_KEY_CONTACTS, 0, "Contacts button"},
  54. {KEY_CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, 0, "Calendar button"},
  55. {KEY_CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, 0, "Camera button"},
  56. {KEY_UP, GPIO93_MAGICIAN_KEY_UP, 0, "Up button"},
  57. {KEY_DOWN, GPIO94_MAGICIAN_KEY_DOWN, 0, "Down button"},
  58. {KEY_LEFT, GPIO95_MAGICIAN_KEY_LEFT, 0, "Left button"},
  59. {KEY_RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, 0, "Right button"},
  60. {KEY_KPENTER, GPIO97_MAGICIAN_KEY_ENTER, 0, "Action button"},
  61. {KEY_RECORD, GPIO98_MAGICIAN_KEY_RECORD, 0, "Record button"},
  62. {KEY_VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, 0, "Volume up"},
  63. {KEY_VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, 0, "Volume down"},
  64. {KEY_PHONE, GPIO102_MAGICIAN_KEY_PHONE, 0, "Phone button"},
  65. {KEY_PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, 0, "Headset button"},
  66. };
  67. static struct gpio_keys_platform_data gpio_keys_data = {
  68. .buttons = magician_button_table,
  69. .nbuttons = ARRAY_SIZE(magician_button_table),
  70. };
  71. static struct platform_device gpio_keys = {
  72. .name = "gpio-keys",
  73. .dev = {
  74. .platform_data = &gpio_keys_data,
  75. },
  76. .id = -1,
  77. };
  78. /*
  79. * EGPIO (Xilinx CPLD)
  80. *
  81. * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
  82. */
  83. static struct resource egpio_resources[] = {
  84. [0] = {
  85. .start = PXA_CS3_PHYS,
  86. .end = PXA_CS3_PHYS + 0x20,
  87. .flags = IORESOURCE_MEM,
  88. },
  89. [1] = {
  90. .start = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
  91. .end = gpio_to_irq(GPIO13_MAGICIAN_CPLD_IRQ),
  92. .flags = IORESOURCE_IRQ,
  93. },
  94. };
  95. static struct htc_egpio_chip egpio_chips[] = {
  96. [0] = {
  97. .reg_start = 0,
  98. .gpio_base = MAGICIAN_EGPIO(0, 0),
  99. .num_gpios = 24,
  100. .direction = HTC_EGPIO_OUTPUT,
  101. .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
  102. },
  103. [1] = {
  104. .reg_start = 4,
  105. .gpio_base = MAGICIAN_EGPIO(4, 0),
  106. .num_gpios = 24,
  107. .direction = HTC_EGPIO_INPUT,
  108. },
  109. };
  110. static struct htc_egpio_platform_data egpio_info = {
  111. .reg_width = 8,
  112. .bus_width = 32,
  113. .irq_base = IRQ_BOARD_START,
  114. .num_irqs = 4,
  115. .ack_register = 3,
  116. .chip = egpio_chips,
  117. .num_chips = ARRAY_SIZE(egpio_chips),
  118. };
  119. static struct platform_device egpio = {
  120. .name = "htc-egpio",
  121. .id = -1,
  122. .resource = egpio_resources,
  123. .num_resources = ARRAY_SIZE(egpio_resources),
  124. .dev = {
  125. .platform_data = &egpio_info,
  126. },
  127. };
  128. /*
  129. * LCD - Toppoly TD028STEB1
  130. */
  131. static struct pxafb_mode_info toppoly_modes[] = {
  132. {
  133. .pixclock = 96153,
  134. .bpp = 16,
  135. .xres = 240,
  136. .yres = 320,
  137. .hsync_len = 11,
  138. .vsync_len = 3,
  139. .left_margin = 19,
  140. .upper_margin = 2,
  141. .right_margin = 10,
  142. .lower_margin = 2,
  143. .sync = 0,
  144. },
  145. };
  146. static struct pxafb_mach_info toppoly_info = {
  147. .modes = toppoly_modes,
  148. .num_modes = 1,
  149. .fixed_modes = 1,
  150. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  151. .lccr3 = LCCR3_PixRsEdg,
  152. };
  153. /*
  154. * Backlight
  155. */
  156. static void magician_set_bl_intensity(int intensity)
  157. {
  158. if (intensity) {
  159. PWM_CTRL0 = 1;
  160. PWM_PERVAL0 = 0xc8;
  161. PWM_PWDUTY0 = intensity;
  162. pxa_set_cken(CKEN_PWM0, 1);
  163. } else {
  164. pxa_set_cken(CKEN_PWM0, 0);
  165. }
  166. }
  167. static struct generic_bl_info backlight_info = {
  168. .default_intensity = 0x64,
  169. .limit_mask = 0x0b,
  170. .max_intensity = 0xc7,
  171. .set_bl_intensity = magician_set_bl_intensity,
  172. };
  173. static struct platform_device backlight = {
  174. .name = "generic-bl",
  175. .dev = {
  176. .platform_data = &backlight_info,
  177. },
  178. .id = -1,
  179. };
  180. /*
  181. * MMC/SD
  182. */
  183. static int magician_mci_init(struct device *dev,
  184. irq_handler_t detect_irq, void *data)
  185. {
  186. return request_irq(IRQ_MAGICIAN_SD, detect_irq,
  187. IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
  188. "MMC card detect", data);
  189. }
  190. static void magician_mci_setpower(struct device *dev, unsigned int vdd)
  191. {
  192. struct pxamci_platform_data *pdata = dev->platform_data;
  193. gpio_set_value(EGPIO_MAGICIAN_SD_POWER, (1 << vdd) & pdata->ocr_mask);
  194. }
  195. static int magician_mci_get_ro(struct device *dev)
  196. {
  197. return (!gpio_get_value(EGPIO_MAGICIAN_nSD_READONLY));
  198. }
  199. static void magician_mci_exit(struct device *dev, void *data)
  200. {
  201. free_irq(IRQ_MAGICIAN_SD, data);
  202. }
  203. static struct pxamci_platform_data magician_mci_info = {
  204. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  205. .init = magician_mci_init,
  206. .get_ro = magician_mci_get_ro,
  207. .setpower = magician_mci_setpower,
  208. .exit = magician_mci_exit,
  209. };
  210. /*
  211. * USB OHCI
  212. */
  213. static int magician_ohci_init(struct device *dev)
  214. {
  215. UHCHR = (UHCHR | UHCHR_SSEP2 | UHCHR_PCPL | UHCHR_CGR) &
  216. ~(UHCHR_SSEP1 | UHCHR_SSEP3 | UHCHR_SSE);
  217. return 0;
  218. }
  219. static struct pxaohci_platform_data magician_ohci_info = {
  220. .port_mode = PMM_PERPORT_MODE,
  221. .init = magician_ohci_init,
  222. .power_budget = 0,
  223. };
  224. /*
  225. * StrataFlash
  226. */
  227. static void magician_set_vpp(struct map_info *map, int vpp)
  228. {
  229. gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
  230. }
  231. #define PXA_CS_SIZE 0x04000000
  232. static struct resource strataflash_resource = {
  233. .start = PXA_CS0_PHYS,
  234. .end = PXA_CS0_PHYS + PXA_CS_SIZE - 1,
  235. .flags = IORESOURCE_MEM,
  236. };
  237. static struct physmap_flash_data strataflash_data = {
  238. .width = 4,
  239. .set_vpp = magician_set_vpp,
  240. };
  241. static struct platform_device strataflash = {
  242. .name = "physmap-flash",
  243. .id = -1,
  244. .resource = &strataflash_resource,
  245. .num_resources = 1,
  246. .dev = {
  247. .platform_data = &strataflash_data,
  248. },
  249. };
  250. /*
  251. * Platform devices
  252. */
  253. static struct platform_device *devices[] __initdata = {
  254. &gpio_keys,
  255. &egpio,
  256. &backlight,
  257. &strataflash,
  258. };
  259. static void __init magician_init(void)
  260. {
  261. platform_add_devices(devices, ARRAY_SIZE(devices));
  262. pxa_set_i2c_info(NULL);
  263. pxa_set_mci_info(&magician_mci_info);
  264. pxa_set_ohci_info(&magician_ohci_info);
  265. pxa_set_ficp_info(&magician_ficp_info);
  266. set_pxa_fb_info(&toppoly_info);
  267. }
  268. MACHINE_START(MAGICIAN, "HTC Magician")
  269. .phys_io = 0x40000000,
  270. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  271. .boot_params = 0xa0000100,
  272. .map_io = pxa_map_io,
  273. .init_irq = pxa27x_init_irq,
  274. .init_machine = magician_init,
  275. .timer = &pxa_timer,
  276. MACHINE_END