mach-h1940.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /* linux/arch/arm/mach-s3c2410/mach-h1940.c
  2. *
  3. * Copyright (c) 2003-2005 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * http://www.handhelds.org/projects/h1940.html
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/list.h>
  17. #include <linux/memblock.h>
  18. #include <linux/timer.h>
  19. #include <linux/init.h>
  20. #include <linux/sysdev.h>
  21. #include <linux/serial_core.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/io.h>
  24. #include <linux/gpio.h>
  25. #include <linux/pwm_backlight.h>
  26. #include <video/platform_lcd.h>
  27. #include <linux/mmc/host.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <asm/mach/irq.h>
  31. #include <mach/hardware.h>
  32. #include <asm/irq.h>
  33. #include <asm/mach-types.h>
  34. #include <plat/regs-serial.h>
  35. #include <mach/regs-lcd.h>
  36. #include <mach/regs-clock.h>
  37. #include <mach/regs-gpio.h>
  38. #include <mach/gpio-fns.h>
  39. #include <mach/gpio-nrs.h>
  40. #include <mach/h1940.h>
  41. #include <mach/h1940-latch.h>
  42. #include <mach/fb.h>
  43. #include <plat/udc.h>
  44. #include <plat/iic.h>
  45. #include <plat/gpio-cfg.h>
  46. #include <plat/clock.h>
  47. #include <plat/devs.h>
  48. #include <plat/cpu.h>
  49. #include <plat/pll.h>
  50. #include <plat/pm.h>
  51. #include <plat/mci.h>
  52. #include <plat/ts.h>
  53. static struct map_desc h1940_iodesc[] __initdata = {
  54. [0] = {
  55. .virtual = (unsigned long)H1940_LATCH,
  56. .pfn = __phys_to_pfn(H1940_PA_LATCH),
  57. .length = SZ_16K,
  58. .type = MT_DEVICE
  59. },
  60. };
  61. #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
  62. #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
  63. #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
  64. static struct s3c2410_uartcfg h1940_uartcfgs[] __initdata = {
  65. [0] = {
  66. .hwport = 0,
  67. .flags = 0,
  68. .ucon = 0x3c5,
  69. .ulcon = 0x03,
  70. .ufcon = 0x51,
  71. },
  72. [1] = {
  73. .hwport = 1,
  74. .flags = 0,
  75. .ucon = 0x245,
  76. .ulcon = 0x03,
  77. .ufcon = 0x00,
  78. },
  79. /* IR port */
  80. [2] = {
  81. .hwport = 2,
  82. .flags = 0,
  83. .uart_flags = UPF_CONS_FLOW,
  84. .ucon = 0x3c5,
  85. .ulcon = 0x43,
  86. .ufcon = 0x51,
  87. }
  88. };
  89. /* Board control latch control */
  90. static unsigned int latch_state = H1940_LATCH_DEFAULT;
  91. void h1940_latch_control(unsigned int clear, unsigned int set)
  92. {
  93. unsigned long flags;
  94. local_irq_save(flags);
  95. latch_state &= ~clear;
  96. latch_state |= set;
  97. __raw_writel(latch_state, H1940_LATCH);
  98. local_irq_restore(flags);
  99. }
  100. EXPORT_SYMBOL_GPL(h1940_latch_control);
  101. static void h1940_udc_pullup(enum s3c2410_udc_cmd_e cmd)
  102. {
  103. printk(KERN_DEBUG "udc: pullup(%d)\n",cmd);
  104. switch (cmd)
  105. {
  106. case S3C2410_UDC_P_ENABLE :
  107. h1940_latch_control(0, H1940_LATCH_USB_DP);
  108. break;
  109. case S3C2410_UDC_P_DISABLE :
  110. h1940_latch_control(H1940_LATCH_USB_DP, 0);
  111. break;
  112. case S3C2410_UDC_P_RESET :
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
  119. .udc_command = h1940_udc_pullup,
  120. .vbus_pin = S3C2410_GPG(5),
  121. .vbus_pin_inverted = 1,
  122. };
  123. static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
  124. .delay = 10000,
  125. .presc = 49,
  126. .oversampling_shift = 2,
  127. .cfg_gpio = s3c24xx_ts_cfg_gpio,
  128. };
  129. /**
  130. * Set lcd on or off
  131. **/
  132. static struct s3c2410fb_display h1940_lcd __initdata = {
  133. .lcdcon5= S3C2410_LCDCON5_FRM565 | \
  134. S3C2410_LCDCON5_INVVLINE | \
  135. S3C2410_LCDCON5_HWSWP,
  136. .type = S3C2410_LCDCON1_TFT,
  137. .width = 240,
  138. .height = 320,
  139. .pixclock = 260000,
  140. .xres = 240,
  141. .yres = 320,
  142. .bpp = 16,
  143. .left_margin = 8,
  144. .right_margin = 20,
  145. .hsync_len = 4,
  146. .upper_margin = 8,
  147. .lower_margin = 7,
  148. .vsync_len = 1,
  149. };
  150. static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
  151. .displays = &h1940_lcd,
  152. .num_displays = 1,
  153. .default_display = 0,
  154. .lpcsel= 0x02,
  155. .gpccon= 0xaa940659,
  156. .gpccon_mask= 0xffffffff,
  157. .gpcup= 0x0000ffff,
  158. .gpcup_mask= 0xffffffff,
  159. .gpdcon= 0xaa84aaa0,
  160. .gpdcon_mask= 0xffffffff,
  161. .gpdup= 0x0000faff,
  162. .gpdup_mask= 0xffffffff,
  163. };
  164. static struct platform_device h1940_device_leds = {
  165. .name = "h1940-leds",
  166. .id = -1,
  167. };
  168. static struct platform_device h1940_device_bluetooth = {
  169. .name = "h1940-bt",
  170. .id = -1,
  171. };
  172. static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
  173. .gpio_detect = S3C2410_GPF(5),
  174. .gpio_wprotect = S3C2410_GPH(8),
  175. .set_power = NULL,
  176. .ocr_avail = MMC_VDD_32_33,
  177. };
  178. static int h1940_backlight_init(struct device *dev)
  179. {
  180. gpio_request(S3C2410_GPB(0), "Backlight");
  181. gpio_direction_output(S3C2410_GPB(0), 0);
  182. s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
  183. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  184. return 0;
  185. }
  186. static void h1940_backlight_exit(struct device *dev)
  187. {
  188. gpio_direction_output(S3C2410_GPB(0), 1);
  189. }
  190. static struct platform_pwm_backlight_data backlight_data = {
  191. .pwm_id = 0,
  192. .max_brightness = 100,
  193. .dft_brightness = 50,
  194. /* tcnt = 0x31 */
  195. .pwm_period_ns = 36296,
  196. .init = h1940_backlight_init,
  197. .exit = h1940_backlight_exit,
  198. };
  199. static struct platform_device h1940_backlight = {
  200. .name = "pwm-backlight",
  201. .dev = {
  202. .parent = &s3c_device_timer[0].dev,
  203. .platform_data = &backlight_data,
  204. },
  205. .id = -1,
  206. };
  207. static void h1940_lcd_power_set(struct plat_lcd_data *pd,
  208. unsigned int power)
  209. {
  210. int value;
  211. if (!power) {
  212. /* set to 3ec */
  213. gpio_direction_output(S3C2410_GPC(0), 0);
  214. /* wait for 3ac */
  215. do {
  216. value = gpio_get_value(S3C2410_GPC(6));
  217. } while (value);
  218. /* set to 38c */
  219. gpio_direction_output(S3C2410_GPC(5), 0);
  220. } else {
  221. /* Set to 3ac */
  222. gpio_direction_output(S3C2410_GPC(5), 1);
  223. /* Set to 3ad */
  224. gpio_direction_output(S3C2410_GPC(0), 1);
  225. }
  226. }
  227. static struct plat_lcd_data h1940_lcd_power_data = {
  228. .set_power = h1940_lcd_power_set,
  229. };
  230. static struct platform_device h1940_lcd_powerdev = {
  231. .name = "platform-lcd",
  232. .dev.parent = &s3c_device_lcd.dev,
  233. .dev.platform_data = &h1940_lcd_power_data,
  234. };
  235. static struct platform_device *h1940_devices[] __initdata = {
  236. &s3c_device_ohci,
  237. &s3c_device_lcd,
  238. &s3c_device_wdt,
  239. &s3c_device_i2c0,
  240. &s3c_device_iis,
  241. &s3c_device_usbgadget,
  242. &h1940_device_leds,
  243. &h1940_device_bluetooth,
  244. &s3c_device_sdi,
  245. &s3c_device_rtc,
  246. &s3c_device_timer[0],
  247. &h1940_backlight,
  248. &h1940_lcd_powerdev,
  249. &s3c_device_adc,
  250. &s3c_device_ts,
  251. };
  252. static void __init h1940_map_io(void)
  253. {
  254. s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
  255. s3c24xx_init_clocks(0);
  256. s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
  257. /* setup PM */
  258. #ifdef CONFIG_PM_H1940
  259. memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
  260. #endif
  261. s3c_pm_init();
  262. }
  263. /* H1940 and RX3715 need to reserve this for suspend */
  264. static void __init h1940_reserve(void)
  265. {
  266. memblock_reserve(0x30003000, 0x1000);
  267. memblock_reserve(0x30081000, 0x1000);
  268. }
  269. static void __init h1940_init_irq(void)
  270. {
  271. s3c24xx_init_irq();
  272. }
  273. static void __init h1940_init(void)
  274. {
  275. u32 tmp;
  276. s3c24xx_fb_set_platdata(&h1940_fb_info);
  277. s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
  278. s3c24xx_udc_set_platdata(&h1940_udc_cfg);
  279. s3c24xx_ts_set_platdata(&h1940_ts_cfg);
  280. s3c_i2c0_set_platdata(NULL);
  281. /* Turn off suspend on both USB ports, and switch the
  282. * selectable USB port to USB device mode. */
  283. s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
  284. S3C2410_MISCCR_USBSUSPND0 |
  285. S3C2410_MISCCR_USBSUSPND1, 0x0);
  286. tmp = (0x78 << S3C24XX_PLLCON_MDIVSHIFT)
  287. | (0x02 << S3C24XX_PLLCON_PDIVSHIFT)
  288. | (0x03 << S3C24XX_PLLCON_SDIVSHIFT);
  289. writel(tmp, S3C2410_UPLLCON);
  290. gpio_request(S3C2410_GPC(0), "LCD power");
  291. gpio_request(S3C2410_GPC(5), "LCD power");
  292. gpio_request(S3C2410_GPC(6), "LCD power");
  293. gpio_direction_input(S3C2410_GPC(6));
  294. platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
  295. }
  296. MACHINE_START(H1940, "IPAQ-H1940")
  297. /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
  298. .phys_io = S3C2410_PA_UART,
  299. .io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
  300. .boot_params = S3C2410_SDRAM_PA + 0x100,
  301. .map_io = h1940_map_io,
  302. .reserve = h1940_reserve,
  303. .init_irq = h1940_init_irq,
  304. .init_machine = h1940_init,
  305. .timer = &s3c24xx_timer,
  306. MACHINE_END