mach-h1940.c 7.5 KB

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