Linux 5.7.6
[linux/fpc-iii.git] / arch / arm / mach-s3c64xx / mach-smartq.c
blob5025db607c0fbaa80b575c387749448e03f8bf77
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (C) 2010 Maurus Cuelenaere
5 #include <linux/delay.h>
6 #include <linux/fb.h>
7 #include <linux/gpio.h>
8 #include <linux/gpio/machine.h>
9 #include <linux/init.h>
10 #include <linux/platform_device.h>
11 #include <linux/pwm.h>
12 #include <linux/pwm_backlight.h>
13 #include <linux/serial_core.h>
14 #include <linux/serial_s3c.h>
15 #include <linux/spi/spi_gpio.h>
16 #include <linux/platform_data/s3c-hsotg.h>
18 #include <asm/mach-types.h>
19 #include <asm/mach/map.h>
21 #include <mach/map.h>
22 #include <mach/regs-gpio.h>
23 #include <mach/gpio-samsung.h>
25 #include <plat/cpu.h>
26 #include <plat/devs.h>
27 #include <linux/platform_data/i2c-s3c2410.h>
28 #include <plat/gpio-cfg.h>
29 #include <linux/platform_data/hwmon-s3c.h>
30 #include <linux/platform_data/usb-ohci-s3c2410.h>
31 #include <plat/sdhci.h>
32 #include <linux/platform_data/touchscreen-s3c2410.h>
34 #include <video/platform_lcd.h>
35 #include <plat/samsung-time.h>
37 #include "common.h"
38 #include "mach-smartq.h"
39 #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)
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,
53 [1] = {
54 .hwport = 1,
55 .flags = 0,
56 .ucon = UCON,
57 .ulcon = ULCON,
58 .ufcon = UFCON,
60 [2] = {
61 .hwport = 2,
62 .flags = 0,
63 .ucon = UCON,
64 .ulcon = ULCON,
65 .ufcon = UFCON,
69 static void smartq_usb_host_powercontrol(int port, int to)
71 pr_debug("%s(%d, %d)\n", __func__, port, to);
73 if (port == 0) {
74 gpio_set_value(S3C64XX_GPL(0), to);
75 gpio_set_value(S3C64XX_GPL(1), to);
79 static irqreturn_t smartq_usb_host_ocirq(int irq, void *pw)
81 struct s3c2410_hcd_info *info = pw;
83 if (gpio_get_value(S3C64XX_GPL(10)) == 0) {
84 pr_debug("%s: over-current irq (oc detected)\n", __func__);
85 s3c2410_usb_report_oc(info, 3);
86 } else {
87 pr_debug("%s: over-current irq (oc cleared)\n", __func__);
88 s3c2410_usb_report_oc(info, 0);
91 return IRQ_HANDLED;
94 static void smartq_usb_host_enableoc(struct s3c2410_hcd_info *info, int on)
96 int ret;
98 /* This isn't present on a SmartQ 5 board */
99 if (machine_is_smartq5())
100 return;
102 if (on) {
103 ret = request_irq(gpio_to_irq(S3C64XX_GPL(10)),
104 smartq_usb_host_ocirq,
105 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
106 "USB host overcurrent", info);
107 if (ret != 0)
108 pr_err("failed to request usb oc irq: %d\n", ret);
109 } else {
110 free_irq(gpio_to_irq(S3C64XX_GPL(10)), info);
114 static struct s3c2410_hcd_info smartq_usb_host_info = {
115 .port[0] = {
116 .flags = S3C_HCDFLG_USED
118 .port[1] = {
119 .flags = 0
122 .power_control = smartq_usb_host_powercontrol,
123 .enable_oc = smartq_usb_host_enableoc,
126 static struct gpiod_lookup_table smartq_usb_otg_vbus_gpiod_table = {
127 .dev_id = "gpio-vbus",
128 .table = {
129 GPIO_LOOKUP("GPL", 9, "vbus", GPIO_ACTIVE_LOW),
130 { },
134 static struct platform_device smartq_usb_otg_vbus_dev = {
135 .name = "gpio-vbus",
138 static struct pwm_lookup smartq_pwm_lookup[] = {
139 PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", NULL,
140 1000000000 / (1000 * 20), PWM_POLARITY_NORMAL),
143 static int smartq_bl_init(struct device *dev)
145 s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2));
147 return 0;
150 static struct platform_pwm_backlight_data smartq_backlight_data = {
151 .max_brightness = 1000,
152 .dft_brightness = 600,
153 .init = smartq_bl_init,
156 static struct platform_device smartq_backlight_device = {
157 .name = "pwm-backlight",
158 .dev = {
159 .parent = &samsung_device_pwm.dev,
160 .platform_data = &smartq_backlight_data,
164 static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata = {
165 .delay = 65535,
166 .presc = 99,
167 .oversampling_shift = 4,
170 static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata = {
171 .max_width = 4,
172 .cd_type = S3C_SDHCI_CD_PERMANENT,
175 static struct s3c_hwmon_pdata smartq_hwmon_pdata __initdata = {
176 /* Battery voltage (?-4.2V) */
177 .in[0] = &(struct s3c_hwmon_chcfg) {
178 .name = "smartq:battery-voltage",
179 .mult = 3300,
180 .div = 2048,
182 /* Reference voltage (1.2V) */
183 .in[1] = &(struct s3c_hwmon_chcfg) {
184 .name = "smartq:reference-voltage",
185 .mult = 3300,
186 .div = 4096,
190 static struct dwc2_hsotg_plat smartq_hsotg_pdata;
192 static int __init smartq_lcd_setup_gpio(void)
194 int ret;
196 ret = gpio_request(S3C64XX_GPM(3), "LCD power");
197 if (ret < 0)
198 return ret;
200 /* turn power off */
201 gpio_direction_output(S3C64XX_GPM(3), 0);
203 return 0;
206 /* GPM0 -> CS */
207 static struct spi_gpio_platform_data smartq_lcd_control = {
208 .num_chipselect = 1,
211 static struct platform_device smartq_lcd_control_device = {
212 .name = "spi_gpio",
213 .id = 1,
214 .dev.platform_data = &smartq_lcd_control,
217 static struct gpiod_lookup_table smartq_lcd_control_gpiod_table = {
218 .dev_id = "spi_gpio",
219 .table = {
220 GPIO_LOOKUP("GPIOM", 1,
221 "sck", GPIO_ACTIVE_HIGH),
222 GPIO_LOOKUP("GPIOM", 2,
223 "mosi", GPIO_ACTIVE_HIGH),
224 GPIO_LOOKUP("GPIOM", 3,
225 "miso", GPIO_ACTIVE_HIGH),
226 GPIO_LOOKUP("GPIOM", 0,
227 "cs", GPIO_ACTIVE_HIGH),
228 { },
232 static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power)
234 gpio_direction_output(S3C64XX_GPM(3), power);
237 static struct plat_lcd_data smartq_lcd_power_data = {
238 .set_power = smartq_lcd_power_set,
241 static struct platform_device smartq_lcd_power_device = {
242 .name = "platform-lcd",
243 .dev.parent = &s3c_device_fb.dev,
244 .dev.platform_data = &smartq_lcd_power_data,
247 static struct i2c_board_info smartq_i2c_devs[] __initdata = {
248 { I2C_BOARD_INFO("wm8987", 0x1a), },
251 static struct platform_device *smartq_devices[] __initdata = {
252 &s3c_device_hsmmc1, /* Init iNAND first, ... */
253 &s3c_device_hsmmc0, /* ... then the external SD card */
254 &s3c_device_hsmmc2,
255 &s3c_device_adc,
256 &s3c_device_fb,
257 &s3c_device_hwmon,
258 &s3c_device_i2c0,
259 &s3c_device_ohci,
260 &s3c_device_rtc,
261 &samsung_device_pwm,
262 &s3c_device_usb_hsotg,
263 &s3c64xx_device_iis0,
264 &smartq_backlight_device,
265 &smartq_lcd_control_device,
266 &smartq_lcd_power_device,
267 &smartq_usb_otg_vbus_dev,
270 static void __init smartq_lcd_mode_set(void)
272 u32 tmp;
274 /* set the LCD type */
275 tmp = __raw_readl(S3C64XX_SPCON);
276 tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK;
277 tmp |= S3C64XX_SPCON_LCD_SEL_RGB;
278 __raw_writel(tmp, S3C64XX_SPCON);
280 /* remove the LCD bypass */
281 tmp = __raw_readl(S3C64XX_MODEM_MIFPCON);
282 tmp &= ~MIFPCON_LCD_BYPASS;
283 __raw_writel(tmp, S3C64XX_MODEM_MIFPCON);
286 static void smartq_power_off(void)
288 gpio_direction_output(S3C64XX_GPK(15), 1);
291 static int __init smartq_power_off_init(void)
293 int ret;
295 ret = gpio_request(S3C64XX_GPK(15), "Power control");
296 if (ret < 0) {
297 pr_err("%s: failed to get GPK15\n", __func__);
298 return ret;
301 /* leave power on */
302 gpio_direction_output(S3C64XX_GPK(15), 0);
304 pm_power_off = smartq_power_off;
306 return ret;
309 static int __init smartq_usb_host_init(void)
311 int ret;
313 ret = gpio_request(S3C64XX_GPL(0), "USB power control");
314 if (ret < 0) {
315 pr_err("%s: failed to get GPL0\n", __func__);
316 return ret;
319 ret = gpio_request(S3C64XX_GPL(1), "USB host power control");
320 if (ret < 0) {
321 pr_err("%s: failed to get GPL1\n", __func__);
322 goto err;
325 if (!machine_is_smartq5()) {
326 /* This isn't present on a SmartQ 5 board */
327 ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent");
328 if (ret < 0) {
329 pr_err("%s: failed to get GPL10\n", __func__);
330 goto err2;
334 /* turn power off */
335 gpio_direction_output(S3C64XX_GPL(0), 0);
336 gpio_direction_output(S3C64XX_GPL(1), 0);
337 if (!machine_is_smartq5())
338 gpio_direction_input(S3C64XX_GPL(10));
340 s3c_device_ohci.dev.platform_data = &smartq_usb_host_info;
342 return 0;
344 err2:
345 gpio_free(S3C64XX_GPL(1));
346 err:
347 gpio_free(S3C64XX_GPL(0));
348 return ret;
351 static int __init smartq_wifi_init(void)
353 int ret;
355 ret = gpio_request(S3C64XX_GPK(1), "wifi control");
356 if (ret < 0) {
357 pr_err("%s: failed to get GPK1\n", __func__);
358 return ret;
361 ret = gpio_request(S3C64XX_GPK(2), "wifi reset");
362 if (ret < 0) {
363 pr_err("%s: failed to get GPK2\n", __func__);
364 gpio_free(S3C64XX_GPK(1));
365 return ret;
368 /* turn power on */
369 gpio_direction_output(S3C64XX_GPK(1), 1);
371 /* reset device */
372 gpio_direction_output(S3C64XX_GPK(2), 0);
373 mdelay(100);
374 gpio_set_value(S3C64XX_GPK(2), 1);
375 gpio_direction_input(S3C64XX_GPK(2));
377 return 0;
380 static struct map_desc smartq_iodesc[] __initdata = {};
381 void __init smartq_map_io(void)
383 s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc));
384 s3c64xx_set_xtal_freq(12000000);
385 s3c64xx_set_xusbxti_freq(12000000);
386 s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs));
387 samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
389 smartq_lcd_mode_set();
392 static struct gpiod_lookup_table smartq_audio_gpios = {
393 .dev_id = "smartq-audio",
394 .table = {
395 GPIO_LOOKUP("GPL", 12, "headphone detect", 0),
396 GPIO_LOOKUP("GPK", 12, "amplifiers shutdown", 0),
397 { },
401 void __init smartq_machine_init(void)
403 s3c_i2c0_set_platdata(NULL);
404 dwc2_hsotg_set_platdata(&smartq_hsotg_pdata);
405 s3c_hwmon_set_platdata(&smartq_hwmon_pdata);
406 s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata);
407 s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata);
408 s3c64xx_ts_set_platdata(&smartq_touchscreen_pdata);
410 i2c_register_board_info(0, smartq_i2c_devs,
411 ARRAY_SIZE(smartq_i2c_devs));
413 WARN_ON(smartq_lcd_setup_gpio());
414 WARN_ON(smartq_power_off_init());
415 WARN_ON(smartq_usb_host_init());
416 WARN_ON(smartq_wifi_init());
418 pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup));
419 gpiod_add_lookup_table(&smartq_lcd_control_gpiod_table);
420 gpiod_add_lookup_table(&smartq_usb_otg_vbus_gpiod_table);
421 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));
423 gpiod_add_lookup_table(&smartq_audio_gpios);
424 platform_device_register_simple("smartq-audio", -1, NULL, 0);