mach-smartq.c 9.6 KB

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