mach-smartq.c 9.6 KB

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