mach-smartq.c 8.6 KB

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