mach-h1940.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. #define H1940_LATCH ((void __force __iomem *)0xF8000000)
  54. #define H1940_PA_LATCH S3C2410_CS2
  55. #define H1940_LATCH_BIT(x) (1 << ((x) + 16 - S3C_GPIO_END))
  56. static struct map_desc h1940_iodesc[] __initdata = {
  57. [0] = {
  58. .virtual = (unsigned long)H1940_LATCH,
  59. .pfn = __phys_to_pfn(H1940_PA_LATCH),
  60. .length = SZ_16K,
  61. .type = MT_DEVICE
  62. },
  63. };
  64. #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
  65. #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
  66. #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
  67. static struct s3c2410_uartcfg h1940_uartcfgs[] __initdata = {
  68. [0] = {
  69. .hwport = 0,
  70. .flags = 0,
  71. .ucon = 0x3c5,
  72. .ulcon = 0x03,
  73. .ufcon = 0x51,
  74. },
  75. [1] = {
  76. .hwport = 1,
  77. .flags = 0,
  78. .ucon = 0x245,
  79. .ulcon = 0x03,
  80. .ufcon = 0x00,
  81. },
  82. /* IR port */
  83. [2] = {
  84. .hwport = 2,
  85. .flags = 0,
  86. .uart_flags = UPF_CONS_FLOW,
  87. .ucon = 0x3c5,
  88. .ulcon = 0x43,
  89. .ufcon = 0x51,
  90. }
  91. };
  92. /* Board control latch control */
  93. static unsigned int latch_state;
  94. static void h1940_latch_control(unsigned int clear, unsigned int set)
  95. {
  96. unsigned long flags;
  97. local_irq_save(flags);
  98. latch_state &= ~clear;
  99. latch_state |= set;
  100. __raw_writel(latch_state, H1940_LATCH);
  101. local_irq_restore(flags);
  102. }
  103. static inline int h1940_gpiolib_to_latch(int offset)
  104. {
  105. return 1 << (offset + 16);
  106. }
  107. static void h1940_gpiolib_latch_set(struct gpio_chip *chip,
  108. unsigned offset, int value)
  109. {
  110. int latch_bit = h1940_gpiolib_to_latch(offset);
  111. h1940_latch_control(value ? 0 : latch_bit,
  112. value ? latch_bit : 0);
  113. }
  114. static int h1940_gpiolib_latch_output(struct gpio_chip *chip,
  115. unsigned offset, int value)
  116. {
  117. h1940_gpiolib_latch_set(chip, offset, value);
  118. return 0;
  119. }
  120. static int h1940_gpiolib_latch_get(struct gpio_chip *chip,
  121. unsigned offset)
  122. {
  123. return (latch_state >> (offset + 16)) & 1;
  124. }
  125. struct gpio_chip h1940_latch_gpiochip = {
  126. .base = H1940_LATCH_GPIO(0),
  127. .owner = THIS_MODULE,
  128. .label = "H1940_LATCH",
  129. .ngpio = 16,
  130. .direction_output = h1940_gpiolib_latch_output,
  131. .set = h1940_gpiolib_latch_set,
  132. .get = h1940_gpiolib_latch_get,
  133. };
  134. static void h1940_udc_pullup(enum s3c2410_udc_cmd_e cmd)
  135. {
  136. printk(KERN_DEBUG "udc: pullup(%d)\n",cmd);
  137. switch (cmd)
  138. {
  139. case S3C2410_UDC_P_ENABLE :
  140. gpio_set_value(H1940_LATCH_USB_DP, 1);
  141. break;
  142. case S3C2410_UDC_P_DISABLE :
  143. gpio_set_value(H1940_LATCH_USB_DP, 0);
  144. break;
  145. case S3C2410_UDC_P_RESET :
  146. break;
  147. default:
  148. break;
  149. }
  150. }
  151. static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
  152. .udc_command = h1940_udc_pullup,
  153. .vbus_pin = S3C2410_GPG(5),
  154. .vbus_pin_inverted = 1,
  155. };
  156. static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
  157. .delay = 10000,
  158. .presc = 49,
  159. .oversampling_shift = 2,
  160. .cfg_gpio = s3c24xx_ts_cfg_gpio,
  161. };
  162. /**
  163. * Set lcd on or off
  164. **/
  165. static struct s3c2410fb_display h1940_lcd __initdata = {
  166. .lcdcon5= S3C2410_LCDCON5_FRM565 | \
  167. S3C2410_LCDCON5_INVVLINE | \
  168. S3C2410_LCDCON5_HWSWP,
  169. .type = S3C2410_LCDCON1_TFT,
  170. .width = 240,
  171. .height = 320,
  172. .pixclock = 260000,
  173. .xres = 240,
  174. .yres = 320,
  175. .bpp = 16,
  176. .left_margin = 8,
  177. .right_margin = 20,
  178. .hsync_len = 4,
  179. .upper_margin = 8,
  180. .lower_margin = 7,
  181. .vsync_len = 1,
  182. };
  183. static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
  184. .displays = &h1940_lcd,
  185. .num_displays = 1,
  186. .default_display = 0,
  187. .lpcsel= 0x02,
  188. .gpccon= 0xaa940659,
  189. .gpccon_mask= 0xffffffff,
  190. .gpcup= 0x0000ffff,
  191. .gpcup_mask= 0xffffffff,
  192. .gpdcon= 0xaa84aaa0,
  193. .gpdcon_mask= 0xffffffff,
  194. .gpdup= 0x0000faff,
  195. .gpdup_mask= 0xffffffff,
  196. };
  197. static struct platform_device h1940_device_leds = {
  198. .name = "h1940-leds",
  199. .id = -1,
  200. };
  201. static struct platform_device h1940_device_bluetooth = {
  202. .name = "h1940-bt",
  203. .id = -1,
  204. };
  205. static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
  206. {
  207. switch (power_mode) {
  208. case MMC_POWER_OFF:
  209. gpio_set_value(H1940_LATCH_SD_POWER, 0);
  210. break;
  211. case MMC_POWER_UP:
  212. case MMC_POWER_ON:
  213. gpio_set_value(H1940_LATCH_SD_POWER, 1);
  214. break;
  215. default:
  216. break;
  217. };
  218. }
  219. static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
  220. .gpio_detect = S3C2410_GPF(5),
  221. .gpio_wprotect = S3C2410_GPH(8),
  222. .set_power = h1940_set_mmc_power,
  223. .ocr_avail = MMC_VDD_32_33,
  224. };
  225. static int h1940_backlight_init(struct device *dev)
  226. {
  227. gpio_request(S3C2410_GPB(0), "Backlight");
  228. gpio_direction_output(S3C2410_GPB(0), 0);
  229. s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
  230. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  231. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
  232. return 0;
  233. }
  234. static int h1940_backlight_notify(struct device *dev, int brightness)
  235. {
  236. if (!brightness) {
  237. gpio_direction_output(S3C2410_GPB(0), 1);
  238. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  239. } else {
  240. gpio_direction_output(S3C2410_GPB(0), 0);
  241. s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
  242. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  243. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
  244. }
  245. return brightness;
  246. }
  247. static void h1940_backlight_exit(struct device *dev)
  248. {
  249. gpio_direction_output(S3C2410_GPB(0), 1);
  250. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  251. }
  252. static struct platform_pwm_backlight_data backlight_data = {
  253. .pwm_id = 0,
  254. .max_brightness = 100,
  255. .dft_brightness = 50,
  256. /* tcnt = 0x31 */
  257. .pwm_period_ns = 36296,
  258. .init = h1940_backlight_init,
  259. .notify = h1940_backlight_notify,
  260. .exit = h1940_backlight_exit,
  261. };
  262. static struct platform_device h1940_backlight = {
  263. .name = "pwm-backlight",
  264. .dev = {
  265. .parent = &s3c_device_timer[0].dev,
  266. .platform_data = &backlight_data,
  267. },
  268. .id = -1,
  269. };
  270. static void h1940_lcd_power_set(struct plat_lcd_data *pd,
  271. unsigned int power)
  272. {
  273. int value;
  274. if (!power) {
  275. gpio_set_value(S3C2410_GPC(0), 0);
  276. /* wait for 3ac */
  277. do {
  278. value = gpio_get_value(S3C2410_GPC(6));
  279. } while (value);
  280. gpio_set_value(H1940_LATCH_LCD_P2, 0);
  281. gpio_set_value(H1940_LATCH_LCD_P3, 0);
  282. gpio_set_value(H1940_LATCH_LCD_P4, 0);
  283. gpio_direction_output(S3C2410_GPC(1), 0);
  284. gpio_direction_output(S3C2410_GPC(4), 0);
  285. gpio_set_value(H1940_LATCH_LCD_P1, 0);
  286. gpio_set_value(H1940_LATCH_LCD_P0, 0);
  287. gpio_set_value(S3C2410_GPC(5), 0);
  288. } else {
  289. gpio_set_value(H1940_LATCH_LCD_P0, 1);
  290. gpio_set_value(H1940_LATCH_LCD_P1, 1);
  291. s3c_gpio_cfgpin(S3C2410_GPC(1), S3C_GPIO_SFN(2));
  292. s3c_gpio_cfgpin(S3C2410_GPC(4), S3C_GPIO_SFN(2));
  293. gpio_set_value(S3C2410_GPC(5), 1);
  294. gpio_set_value(S3C2410_GPC(0), 1);
  295. gpio_set_value(H1940_LATCH_LCD_P3, 1);
  296. gpio_set_value(H1940_LATCH_LCD_P2, 1);
  297. gpio_set_value(H1940_LATCH_LCD_P4, 1);
  298. }
  299. }
  300. static struct plat_lcd_data h1940_lcd_power_data = {
  301. .set_power = h1940_lcd_power_set,
  302. };
  303. static struct platform_device h1940_lcd_powerdev = {
  304. .name = "platform-lcd",
  305. .dev.parent = &s3c_device_lcd.dev,
  306. .dev.platform_data = &h1940_lcd_power_data,
  307. };
  308. static struct platform_device *h1940_devices[] __initdata = {
  309. &s3c_device_ohci,
  310. &s3c_device_lcd,
  311. &s3c_device_wdt,
  312. &s3c_device_i2c0,
  313. &s3c_device_iis,
  314. &s3c_device_usbgadget,
  315. &h1940_device_leds,
  316. &h1940_device_bluetooth,
  317. &s3c_device_sdi,
  318. &s3c_device_rtc,
  319. &s3c_device_timer[0],
  320. &h1940_backlight,
  321. &h1940_lcd_powerdev,
  322. &s3c_device_adc,
  323. &s3c_device_ts,
  324. };
  325. static void __init h1940_map_io(void)
  326. {
  327. s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
  328. s3c24xx_init_clocks(0);
  329. s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
  330. /* setup PM */
  331. #ifdef CONFIG_PM_H1940
  332. memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
  333. #endif
  334. s3c_pm_init();
  335. /* Add latch gpio chip, set latch initial value */
  336. h1940_latch_control(0, 0);
  337. WARN_ON(gpiochip_add(&h1940_latch_gpiochip));
  338. }
  339. /* H1940 and RX3715 need to reserve this for suspend */
  340. static void __init h1940_reserve(void)
  341. {
  342. memblock_reserve(0x30003000, 0x1000);
  343. memblock_reserve(0x30081000, 0x1000);
  344. }
  345. static void __init h1940_init_irq(void)
  346. {
  347. s3c24xx_init_irq();
  348. }
  349. static void __init h1940_init(void)
  350. {
  351. u32 tmp;
  352. s3c24xx_fb_set_platdata(&h1940_fb_info);
  353. s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
  354. s3c24xx_udc_set_platdata(&h1940_udc_cfg);
  355. s3c24xx_ts_set_platdata(&h1940_ts_cfg);
  356. s3c_i2c0_set_platdata(NULL);
  357. /* Turn off suspend on both USB ports, and switch the
  358. * selectable USB port to USB device mode. */
  359. s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
  360. S3C2410_MISCCR_USBSUSPND0 |
  361. S3C2410_MISCCR_USBSUSPND1, 0x0);
  362. tmp = (0x78 << S3C24XX_PLLCON_MDIVSHIFT)
  363. | (0x02 << S3C24XX_PLLCON_PDIVSHIFT)
  364. | (0x03 << S3C24XX_PLLCON_SDIVSHIFT);
  365. writel(tmp, S3C2410_UPLLCON);
  366. gpio_request(S3C2410_GPC(0), "LCD power");
  367. gpio_request(S3C2410_GPC(1), "LCD power");
  368. gpio_request(S3C2410_GPC(4), "LCD power");
  369. gpio_request(S3C2410_GPC(5), "LCD power");
  370. gpio_request(S3C2410_GPC(6), "LCD power");
  371. gpio_request(H1940_LATCH_LCD_P0, "LCD power");
  372. gpio_request(H1940_LATCH_LCD_P1, "LCD power");
  373. gpio_request(H1940_LATCH_LCD_P2, "LCD power");
  374. gpio_request(H1940_LATCH_LCD_P3, "LCD power");
  375. gpio_request(H1940_LATCH_LCD_P4, "LCD power");
  376. gpio_request(H1940_LATCH_MAX1698_nSHUTDOWN, "LCD power");
  377. gpio_direction_output(S3C2410_GPC(0), 0);
  378. gpio_direction_output(S3C2410_GPC(1), 0);
  379. gpio_direction_output(S3C2410_GPC(4), 0);
  380. gpio_direction_output(S3C2410_GPC(5), 0);
  381. gpio_direction_input(S3C2410_GPC(6));
  382. gpio_direction_output(H1940_LATCH_LCD_P0, 0);
  383. gpio_direction_output(H1940_LATCH_LCD_P1, 0);
  384. gpio_direction_output(H1940_LATCH_LCD_P2, 0);
  385. gpio_direction_output(H1940_LATCH_LCD_P3, 0);
  386. gpio_direction_output(H1940_LATCH_LCD_P4, 0);
  387. gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  388. gpio_request(H1940_LATCH_USB_DP, "USB pullup");
  389. gpio_direction_output(H1940_LATCH_USB_DP, 0);
  390. gpio_request(H1940_LATCH_SD_POWER, "SD power");
  391. gpio_direction_output(H1940_LATCH_SD_POWER, 0);
  392. platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
  393. }
  394. MACHINE_START(H1940, "IPAQ-H1940")
  395. /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
  396. .phys_io = S3C2410_PA_UART,
  397. .io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
  398. .boot_params = S3C2410_SDRAM_PA + 0x100,
  399. .map_io = h1940_map_io,
  400. .reserve = h1940_reserve,
  401. .init_irq = h1940_init_irq,
  402. .init_machine = h1940_init,
  403. .timer = &s3c24xx_timer,
  404. MACHINE_END