mach-h1940.c 12 KB

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