mach-smartq.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * linux/arch/arm/mach-s3c64xx/mach-smartq.c
  3. *
  4. * Copyright (C) 2010 Maurus Cuelenaere
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/delay.h>
  12. #include <linux/fb.h>
  13. #include <linux/gpio.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pwm_backlight.h>
  17. #include <linux/serial_core.h>
  18. #include <linux/usb/gpio_vbus.h>
  19. #include <asm/mach-types.h>
  20. #include <asm/mach/map.h>
  21. #include <mach/map.h>
  22. #include <mach/regs-gpio.h>
  23. #include <mach/regs-modem.h>
  24. #include <plat/clock.h>
  25. #include <plat/cpu.h>
  26. #include <plat/devs.h>
  27. #include <plat/iic.h>
  28. #include <plat/gpio-cfg.h>
  29. #include <plat/hwmon.h>
  30. #include <plat/regs-serial.h>
  31. #include <plat/udc-hs.h>
  32. #include <plat/usb-control.h>
  33. #include <plat/sdhci.h>
  34. #include <plat/ts.h>
  35. #include <video/platform_lcd.h>
  36. #define UCON S3C2410_UCON_DEFAULT
  37. #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
  38. #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
  39. static struct s3c2410_uartcfg smartq_uartcfgs[] __initdata = {
  40. [0] = {
  41. .hwport = 0,
  42. .flags = 0,
  43. .ucon = UCON,
  44. .ulcon = ULCON,
  45. .ufcon = UFCON,
  46. },
  47. [1] = {
  48. .hwport = 1,
  49. .flags = 0,
  50. .ucon = UCON,
  51. .ulcon = ULCON,
  52. .ufcon = UFCON,
  53. },
  54. [2] = {
  55. .hwport = 2,
  56. .flags = 0,
  57. .ucon = UCON,
  58. .ulcon = ULCON,
  59. .ufcon = UFCON,
  60. },
  61. };
  62. static void smartq_usb_host_powercontrol(int port, int to)
  63. {
  64. pr_debug("%s(%d, %d)\n", __func__, port, to);
  65. if (port == 0) {
  66. gpio_set_value(S3C64XX_GPL(0), to);
  67. gpio_set_value(S3C64XX_GPL(1), to);
  68. }
  69. }
  70. static irqreturn_t smartq_usb_host_ocirq(int irq, void *pw)
  71. {
  72. struct s3c2410_hcd_info *info = pw;
  73. if (gpio_get_value(S3C64XX_GPL(10)) == 0) {
  74. pr_debug("%s: over-current irq (oc detected)\n", __func__);
  75. s3c2410_usb_report_oc(info, 3);
  76. } else {
  77. pr_debug("%s: over-current irq (oc cleared)\n", __func__);
  78. s3c2410_usb_report_oc(info, 0);
  79. }
  80. return IRQ_HANDLED;
  81. }
  82. static void smartq_usb_host_enableoc(struct s3c2410_hcd_info *info, int on)
  83. {
  84. int ret;
  85. /* This isn't present on a SmartQ 5 board */
  86. if (machine_is_smartq5())
  87. return;
  88. if (on) {
  89. ret = request_irq(gpio_to_irq(S3C64XX_GPL(10)),
  90. smartq_usb_host_ocirq, IRQF_DISABLED |
  91. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  92. "USB host overcurrent", info);
  93. if (ret != 0)
  94. pr_err("failed to request usb oc irq: %d\n", ret);
  95. } else {
  96. free_irq(gpio_to_irq(S3C64XX_GPL(10)), info);
  97. }
  98. }
  99. static struct s3c2410_hcd_info smartq_usb_host_info = {
  100. .port[0] = {
  101. .flags = S3C_HCDFLG_USED
  102. },
  103. .port[1] = {
  104. .flags = 0
  105. },
  106. .power_control = smartq_usb_host_powercontrol,
  107. .enable_oc = smartq_usb_host_enableoc,
  108. };
  109. static struct gpio_vbus_mach_info smartq_usb_otg_vbus_pdata = {
  110. .gpio_vbus = S3C64XX_GPL(9),
  111. .gpio_pullup = -1,
  112. .gpio_vbus_inverted = true,
  113. };
  114. static struct platform_device smartq_usb_otg_vbus_dev = {
  115. .name = "gpio-vbus",
  116. .dev.platform_data = &smartq_usb_otg_vbus_pdata,
  117. };
  118. static int __init smartq_bl_init(struct device *dev)
  119. {
  120. s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2));
  121. return 0;
  122. }
  123. static struct platform_pwm_backlight_data smartq_backlight_data = {
  124. .pwm_id = 1,
  125. .max_brightness = 1000,
  126. .dft_brightness = 600,
  127. .pwm_period_ns = 1000000000 / (1000 * 20),
  128. .init = smartq_bl_init,
  129. };
  130. static struct platform_device smartq_backlight_device = {
  131. .name = "pwm-backlight",
  132. .dev = {
  133. .parent = &s3c_device_timer[1].dev,
  134. .platform_data = &smartq_backlight_data,
  135. },
  136. };
  137. static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata = {
  138. .delay = 65535,
  139. .presc = 99,
  140. .oversampling_shift = 4,
  141. };
  142. static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata = {
  143. .max_width = 4,
  144. /*.broken_card_detection = true,*/
  145. };
  146. static struct s3c_hwmon_pdata smartq_hwmon_pdata __initdata = {
  147. /* Battery voltage (?-4.2V) */
  148. .in[0] = &(struct s3c_hwmon_chcfg) {
  149. .name = "smartq:battery-voltage",
  150. .mult = 3300,
  151. .div = 2048,
  152. },
  153. /* Reference voltage (1.2V) */
  154. .in[1] = &(struct s3c_hwmon_chcfg) {
  155. .name = "smartq:reference-voltage",
  156. .mult = 3300,
  157. .div = 4096,
  158. },
  159. };
  160. static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power)
  161. {
  162. gpio_direction_output(S3C64XX_GPM(3), power);
  163. }
  164. static struct plat_lcd_data smartq_lcd_power_data = {
  165. .set_power = smartq_lcd_power_set,
  166. };
  167. static struct platform_device smartq_lcd_power_device = {
  168. .name = "platform-lcd",
  169. .dev.parent = &s3c_device_fb.dev,
  170. .dev.platform_data = &smartq_lcd_power_data,
  171. };
  172. static struct platform_device *smartq_devices[] __initdata = {
  173. &s3c_device_hsmmc1, /* Init iNAND first, ... */
  174. &s3c_device_hsmmc0, /* ... then the external SD card */
  175. &s3c_device_hsmmc2,
  176. &s3c_device_adc,
  177. &s3c_device_fb,
  178. &s3c_device_hwmon,
  179. &s3c_device_i2c0,
  180. &s3c_device_ohci,
  181. &s3c_device_rtc,
  182. &s3c_device_timer[1],
  183. &s3c_device_ts,
  184. &s3c_device_usb_hsotg,
  185. &smartq_backlight_device,
  186. &smartq_lcd_power_device,
  187. &smartq_usb_otg_vbus_dev,
  188. };
  189. static void __init smartq_lcd_mode_set(void)
  190. {
  191. u32 tmp;
  192. /* set the LCD type */
  193. tmp = __raw_readl(S3C64XX_SPCON);
  194. tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK;
  195. tmp |= S3C64XX_SPCON_LCD_SEL_RGB;
  196. __raw_writel(tmp, S3C64XX_SPCON);
  197. /* remove the LCD bypass */
  198. tmp = __raw_readl(S3C64XX_MODEM_MIFPCON);
  199. tmp &= ~MIFPCON_LCD_BYPASS;
  200. __raw_writel(tmp, S3C64XX_MODEM_MIFPCON);
  201. }
  202. static void smartq_power_off(void)
  203. {
  204. gpio_direction_output(S3C64XX_GPK(15), 1);
  205. }
  206. static int __init smartq_power_off_init(void)
  207. {
  208. int ret;
  209. ret = gpio_request(S3C64XX_GPK(15), "Power control");
  210. if (ret < 0) {
  211. pr_err("%s: failed to get GPK15\n", __func__);
  212. return ret;
  213. }
  214. /* leave power on */
  215. gpio_direction_output(S3C64XX_GPK(15), 0);
  216. pm_power_off = smartq_power_off;
  217. return ret;
  218. }
  219. static int __init smartq_usb_host_init(void)
  220. {
  221. int ret;
  222. ret = gpio_request(S3C64XX_GPL(0), "USB power control");
  223. if (ret < 0) {
  224. pr_err("%s: failed to get GPL0\n", __func__);
  225. return ret;
  226. }
  227. ret = gpio_request(S3C64XX_GPL(1), "USB host power control");
  228. if (ret < 0) {
  229. pr_err("%s: failed to get GPL1\n", __func__);
  230. goto err;
  231. }
  232. if (!machine_is_smartq5()) {
  233. /* This isn't present on a SmartQ 5 board */
  234. ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent");
  235. if (ret < 0) {
  236. pr_err("%s: failed to get GPL10\n", __func__);
  237. goto err2;
  238. }
  239. }
  240. /* turn power off */
  241. gpio_direction_output(S3C64XX_GPL(0), 0);
  242. gpio_direction_output(S3C64XX_GPL(1), 0);
  243. if (!machine_is_smartq5())
  244. gpio_direction_input(S3C64XX_GPL(10));
  245. s3c_device_ohci.dev.platform_data = &smartq_usb_host_info;
  246. return 0;
  247. err2:
  248. gpio_free(S3C64XX_GPL(1));
  249. err:
  250. gpio_free(S3C64XX_GPL(0));
  251. return ret;
  252. }
  253. static int __init smartq_usb_otg_init(void)
  254. {
  255. clk_xusbxti.rate = 12000000;
  256. return 0;
  257. }
  258. static int __init smartq_wifi_init(void)
  259. {
  260. int ret;
  261. ret = gpio_request(S3C64XX_GPK(1), "wifi control");
  262. if (ret < 0) {
  263. pr_err("%s: failed to get GPK1\n", __func__);
  264. return ret;
  265. }
  266. ret = gpio_request(S3C64XX_GPK(2), "wifi reset");
  267. if (ret < 0) {
  268. pr_err("%s: failed to get GPK2\n", __func__);
  269. gpio_free(S3C64XX_GPK(1));
  270. return ret;
  271. }
  272. /* turn power on */
  273. gpio_direction_output(S3C64XX_GPK(1), 1);
  274. /* reset device */
  275. gpio_direction_output(S3C64XX_GPK(2), 0);
  276. mdelay(100);
  277. gpio_set_value(S3C64XX_GPK(2), 1);
  278. gpio_direction_input(S3C64XX_GPK(2));
  279. return 0;
  280. }
  281. static struct map_desc smartq_iodesc[] __initdata = {};
  282. void __init smartq_map_io(void)
  283. {
  284. s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc));
  285. s3c24xx_init_clocks(12000000);
  286. s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs));
  287. smartq_lcd_mode_set();
  288. }
  289. void __init smartq_machine_init(void)
  290. {
  291. s3c_i2c0_set_platdata(NULL);
  292. s3c_hwmon_set_platdata(&smartq_hwmon_pdata);
  293. s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata);
  294. s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata);
  295. s3c24xx_ts_set_platdata(&smartq_touchscreen_pdata);
  296. WARN_ON(smartq_power_off_init());
  297. WARN_ON(smartq_usb_host_init());
  298. WARN_ON(smartq_usb_otg_init());
  299. WARN_ON(smartq_wifi_init());
  300. platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));
  301. }