mach-smartq.c 9.7 KB

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