mach-h1940.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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 struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
  137. .vbus_pin = S3C2410_GPG(5),
  138. .vbus_pin_inverted = 1,
  139. .pullup_pin = H1940_LATCH_USB_DP,
  140. };
  141. static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
  142. .delay = 10000,
  143. .presc = 49,
  144. .oversampling_shift = 2,
  145. .cfg_gpio = s3c24xx_ts_cfg_gpio,
  146. };
  147. /**
  148. * Set lcd on or off
  149. **/
  150. static struct s3c2410fb_display h1940_lcd __initdata = {
  151. .lcdcon5= S3C2410_LCDCON5_FRM565 | \
  152. S3C2410_LCDCON5_INVVLINE | \
  153. S3C2410_LCDCON5_HWSWP,
  154. .type = S3C2410_LCDCON1_TFT,
  155. .width = 240,
  156. .height = 320,
  157. .pixclock = 260000,
  158. .xres = 240,
  159. .yres = 320,
  160. .bpp = 16,
  161. .left_margin = 8,
  162. .right_margin = 20,
  163. .hsync_len = 4,
  164. .upper_margin = 8,
  165. .lower_margin = 7,
  166. .vsync_len = 1,
  167. };
  168. static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
  169. .displays = &h1940_lcd,
  170. .num_displays = 1,
  171. .default_display = 0,
  172. .lpcsel= 0x02,
  173. .gpccon= 0xaa940659,
  174. .gpccon_mask= 0xffffffff,
  175. .gpcup= 0x0000ffff,
  176. .gpcup_mask= 0xffffffff,
  177. .gpdcon= 0xaa84aaa0,
  178. .gpdcon_mask= 0xffffffff,
  179. .gpdup= 0x0000faff,
  180. .gpdup_mask= 0xffffffff,
  181. };
  182. static struct platform_device h1940_device_leds = {
  183. .name = "h1940-leds",
  184. .id = -1,
  185. };
  186. static struct platform_device h1940_device_bluetooth = {
  187. .name = "h1940-bt",
  188. .id = -1,
  189. };
  190. static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
  191. {
  192. switch (power_mode) {
  193. case MMC_POWER_OFF:
  194. gpio_set_value(H1940_LATCH_SD_POWER, 0);
  195. break;
  196. case MMC_POWER_UP:
  197. case MMC_POWER_ON:
  198. gpio_set_value(H1940_LATCH_SD_POWER, 1);
  199. break;
  200. default:
  201. break;
  202. };
  203. }
  204. static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
  205. .gpio_detect = S3C2410_GPF(5),
  206. .gpio_wprotect = S3C2410_GPH(8),
  207. .set_power = h1940_set_mmc_power,
  208. .ocr_avail = MMC_VDD_32_33,
  209. };
  210. static int h1940_backlight_init(struct device *dev)
  211. {
  212. gpio_request(S3C2410_GPB(0), "Backlight");
  213. gpio_direction_output(S3C2410_GPB(0), 0);
  214. s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
  215. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  216. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
  217. return 0;
  218. }
  219. static int h1940_backlight_notify(struct device *dev, int brightness)
  220. {
  221. if (!brightness) {
  222. gpio_direction_output(S3C2410_GPB(0), 1);
  223. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  224. } else {
  225. gpio_direction_output(S3C2410_GPB(0), 0);
  226. s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
  227. s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
  228. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
  229. }
  230. return brightness;
  231. }
  232. static void h1940_backlight_exit(struct device *dev)
  233. {
  234. gpio_direction_output(S3C2410_GPB(0), 1);
  235. gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  236. }
  237. static struct platform_pwm_backlight_data backlight_data = {
  238. .pwm_id = 0,
  239. .max_brightness = 100,
  240. .dft_brightness = 50,
  241. /* tcnt = 0x31 */
  242. .pwm_period_ns = 36296,
  243. .init = h1940_backlight_init,
  244. .notify = h1940_backlight_notify,
  245. .exit = h1940_backlight_exit,
  246. };
  247. static struct platform_device h1940_backlight = {
  248. .name = "pwm-backlight",
  249. .dev = {
  250. .parent = &s3c_device_timer[0].dev,
  251. .platform_data = &backlight_data,
  252. },
  253. .id = -1,
  254. };
  255. static void h1940_lcd_power_set(struct plat_lcd_data *pd,
  256. unsigned int power)
  257. {
  258. int value;
  259. if (!power) {
  260. gpio_set_value(S3C2410_GPC(0), 0);
  261. /* wait for 3ac */
  262. do {
  263. value = gpio_get_value(S3C2410_GPC(6));
  264. } while (value);
  265. gpio_set_value(H1940_LATCH_LCD_P2, 0);
  266. gpio_set_value(H1940_LATCH_LCD_P3, 0);
  267. gpio_set_value(H1940_LATCH_LCD_P4, 0);
  268. gpio_direction_output(S3C2410_GPC(1), 0);
  269. gpio_direction_output(S3C2410_GPC(4), 0);
  270. gpio_set_value(H1940_LATCH_LCD_P1, 0);
  271. gpio_set_value(H1940_LATCH_LCD_P0, 0);
  272. gpio_set_value(S3C2410_GPC(5), 0);
  273. } else {
  274. gpio_set_value(H1940_LATCH_LCD_P0, 1);
  275. gpio_set_value(H1940_LATCH_LCD_P1, 1);
  276. s3c_gpio_cfgpin(S3C2410_GPC(1), S3C_GPIO_SFN(2));
  277. s3c_gpio_cfgpin(S3C2410_GPC(4), S3C_GPIO_SFN(2));
  278. gpio_set_value(S3C2410_GPC(5), 1);
  279. gpio_set_value(S3C2410_GPC(0), 1);
  280. gpio_set_value(H1940_LATCH_LCD_P3, 1);
  281. gpio_set_value(H1940_LATCH_LCD_P2, 1);
  282. gpio_set_value(H1940_LATCH_LCD_P4, 1);
  283. }
  284. }
  285. static struct plat_lcd_data h1940_lcd_power_data = {
  286. .set_power = h1940_lcd_power_set,
  287. };
  288. static struct platform_device h1940_lcd_powerdev = {
  289. .name = "platform-lcd",
  290. .dev.parent = &s3c_device_lcd.dev,
  291. .dev.platform_data = &h1940_lcd_power_data,
  292. };
  293. static struct uda1380_platform_data uda1380_info = {
  294. .gpio_power = H1940_LATCH_UDA_POWER,
  295. .gpio_reset = S3C2410_GPA(12),
  296. .dac_clk = UDA1380_DAC_CLK_SYSCLK,
  297. };
  298. static struct i2c_board_info h1940_i2c_devices[] = {
  299. {
  300. I2C_BOARD_INFO("uda1380", 0x1a),
  301. .platform_data = &uda1380_info,
  302. },
  303. };
  304. static struct platform_device *h1940_devices[] __initdata = {
  305. &s3c_device_ohci,
  306. &s3c_device_lcd,
  307. &s3c_device_wdt,
  308. &s3c_device_i2c0,
  309. &s3c_device_iis,
  310. &samsung_asoc_dma,
  311. &s3c_device_usbgadget,
  312. &h1940_device_leds,
  313. &h1940_device_bluetooth,
  314. &s3c_device_sdi,
  315. &s3c_device_rtc,
  316. &s3c_device_timer[0],
  317. &h1940_backlight,
  318. &h1940_lcd_powerdev,
  319. &s3c_device_adc,
  320. &s3c_device_ts,
  321. };
  322. static void __init h1940_map_io(void)
  323. {
  324. s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
  325. s3c24xx_init_clocks(0);
  326. s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
  327. /* setup PM */
  328. #ifdef CONFIG_PM_H1940
  329. memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
  330. #endif
  331. s3c_pm_init();
  332. /* Add latch gpio chip, set latch initial value */
  333. h1940_latch_control(0, 0);
  334. WARN_ON(gpiochip_add(&h1940_latch_gpiochip));
  335. }
  336. /* H1940 and RX3715 need to reserve this for suspend */
  337. static void __init h1940_reserve(void)
  338. {
  339. memblock_reserve(0x30003000, 0x1000);
  340. memblock_reserve(0x30081000, 0x1000);
  341. }
  342. static void __init h1940_init_irq(void)
  343. {
  344. s3c24xx_init_irq();
  345. }
  346. static void __init h1940_init(void)
  347. {
  348. u32 tmp;
  349. s3c24xx_fb_set_platdata(&h1940_fb_info);
  350. s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
  351. s3c24xx_udc_set_platdata(&h1940_udc_cfg);
  352. s3c24xx_ts_set_platdata(&h1940_ts_cfg);
  353. s3c_i2c0_set_platdata(NULL);
  354. /* Turn off suspend on both USB ports, and switch the
  355. * selectable USB port to USB device mode. */
  356. s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
  357. S3C2410_MISCCR_USBSUSPND0 |
  358. S3C2410_MISCCR_USBSUSPND1, 0x0);
  359. tmp = (0x78 << S3C24XX_PLLCON_MDIVSHIFT)
  360. | (0x02 << S3C24XX_PLLCON_PDIVSHIFT)
  361. | (0x03 << S3C24XX_PLLCON_SDIVSHIFT);
  362. writel(tmp, S3C2410_UPLLCON);
  363. gpio_request(S3C2410_GPC(0), "LCD power");
  364. gpio_request(S3C2410_GPC(1), "LCD power");
  365. gpio_request(S3C2410_GPC(4), "LCD power");
  366. gpio_request(S3C2410_GPC(5), "LCD power");
  367. gpio_request(S3C2410_GPC(6), "LCD power");
  368. gpio_request(H1940_LATCH_LCD_P0, "LCD power");
  369. gpio_request(H1940_LATCH_LCD_P1, "LCD power");
  370. gpio_request(H1940_LATCH_LCD_P2, "LCD power");
  371. gpio_request(H1940_LATCH_LCD_P3, "LCD power");
  372. gpio_request(H1940_LATCH_LCD_P4, "LCD power");
  373. gpio_request(H1940_LATCH_MAX1698_nSHUTDOWN, "LCD power");
  374. gpio_direction_output(S3C2410_GPC(0), 0);
  375. gpio_direction_output(S3C2410_GPC(1), 0);
  376. gpio_direction_output(S3C2410_GPC(4), 0);
  377. gpio_direction_output(S3C2410_GPC(5), 0);
  378. gpio_direction_input(S3C2410_GPC(6));
  379. gpio_direction_output(H1940_LATCH_LCD_P0, 0);
  380. gpio_direction_output(H1940_LATCH_LCD_P1, 0);
  381. gpio_direction_output(H1940_LATCH_LCD_P2, 0);
  382. gpio_direction_output(H1940_LATCH_LCD_P3, 0);
  383. gpio_direction_output(H1940_LATCH_LCD_P4, 0);
  384. gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
  385. gpio_request(H1940_LATCH_SD_POWER, "SD power");
  386. gpio_direction_output(H1940_LATCH_SD_POWER, 0);
  387. platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
  388. i2c_register_board_info(0, h1940_i2c_devices,
  389. ARRAY_SIZE(h1940_i2c_devices));
  390. }
  391. MACHINE_START(H1940, "IPAQ-H1940")
  392. /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
  393. .boot_params = S3C2410_SDRAM_PA + 0x100,
  394. .map_io = h1940_map_io,
  395. .reserve = h1940_reserve,
  396. .init_irq = h1940_init_irq,
  397. .init_machine = h1940_init,
  398. .timer = &s3c24xx_timer,
  399. MACHINE_END