mach-smartq.c 8.8 KB

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