1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2010 Maurus Cuelenaere
5 #include <linux/delay.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>
22 #include "regs-gpio.h"
23 #include "gpio-samsung.h"
27 #include <linux/platform_data/i2c-s3c2410.h>
29 #include <linux/platform_data/hwmon-s3c.h>
30 #include <linux/platform_data/usb-ohci-s3c2410.h>
32 #include <linux/platform_data/touchscreen-s3c2410.h>
34 #include <video/platform_lcd.h>
37 #include "mach-smartq.h"
38 #include "regs-modem-s3c64xx.h"
40 #define UCON S3C2410_UCON_DEFAULT
41 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
42 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
44 static struct s3c2410_uartcfg smartq_uartcfgs[] __initdata = {
68 static void smartq_usb_host_powercontrol(int port, int to)
70 pr_debug("%s(%d, %d)\n", __func__, port, to);
73 gpio_set_value(S3C64XX_GPL(0), to);
74 gpio_set_value(S3C64XX_GPL(1), to);
78 static irqreturn_t smartq_usb_host_ocirq(int irq, void *pw)
80 struct s3c2410_hcd_info *info = pw;
82 if (gpio_get_value(S3C64XX_GPL(10)) == 0) {
83 pr_debug("%s: over-current irq (oc detected)\n", __func__);
84 s3c2410_usb_report_oc(info, 3);
86 pr_debug("%s: over-current irq (oc cleared)\n", __func__);
87 s3c2410_usb_report_oc(info, 0);
93 static void smartq_usb_host_enableoc(struct s3c2410_hcd_info *info, int on)
97 /* This isn't present on a SmartQ 5 board */
98 if (machine_is_smartq5())
102 ret = request_irq(gpio_to_irq(S3C64XX_GPL(10)),
103 smartq_usb_host_ocirq,
104 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
105 "USB host overcurrent", info);
107 pr_err("failed to request usb oc irq: %d\n", ret);
109 free_irq(gpio_to_irq(S3C64XX_GPL(10)), info);
113 static struct s3c2410_hcd_info smartq_usb_host_info = {
115 .flags = S3C_HCDFLG_USED
121 .power_control = smartq_usb_host_powercontrol,
122 .enable_oc = smartq_usb_host_enableoc,
125 static struct gpiod_lookup_table smartq_usb_otg_vbus_gpiod_table = {
126 .dev_id = "gpio-vbus",
128 GPIO_LOOKUP("GPL", 9, "vbus", GPIO_ACTIVE_LOW),
133 static struct platform_device smartq_usb_otg_vbus_dev = {
137 static struct pwm_lookup smartq_pwm_lookup[] = {
138 PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", NULL,
139 1000000000 / (1000 * 20), PWM_POLARITY_NORMAL),
142 static int smartq_bl_init(struct device *dev)
144 s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2));
149 static struct platform_pwm_backlight_data smartq_backlight_data = {
150 .max_brightness = 1000,
151 .dft_brightness = 600,
152 .init = smartq_bl_init,
155 static struct platform_device smartq_backlight_device = {
156 .name = "pwm-backlight",
158 .parent = &samsung_device_pwm.dev,
159 .platform_data = &smartq_backlight_data,
163 static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata = {
166 .oversampling_shift = 4,
169 static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata = {
171 .cd_type = S3C_SDHCI_CD_PERMANENT,
174 static struct s3c_hwmon_pdata smartq_hwmon_pdata __initdata = {
175 /* Battery voltage (?-4.2V) */
176 .in[0] = &(struct s3c_hwmon_chcfg) {
177 .name = "smartq:battery-voltage",
181 /* Reference voltage (1.2V) */
182 .in[1] = &(struct s3c_hwmon_chcfg) {
183 .name = "smartq:reference-voltage",
189 static struct dwc2_hsotg_plat smartq_hsotg_pdata;
191 static int __init smartq_lcd_setup_gpio(void)
195 ret = gpio_request(S3C64XX_GPM(3), "LCD power");
200 gpio_direction_output(S3C64XX_GPM(3), 0);
206 static struct spi_gpio_platform_data smartq_lcd_control = {
210 static struct platform_device smartq_lcd_control_device = {
213 .dev.platform_data = &smartq_lcd_control,
216 static struct gpiod_lookup_table smartq_lcd_control_gpiod_table = {
217 .dev_id = "spi_gpio",
219 GPIO_LOOKUP("GPIOM", 1,
220 "sck", GPIO_ACTIVE_HIGH),
221 GPIO_LOOKUP("GPIOM", 2,
222 "mosi", GPIO_ACTIVE_HIGH),
223 GPIO_LOOKUP("GPIOM", 3,
224 "miso", GPIO_ACTIVE_HIGH),
225 GPIO_LOOKUP("GPIOM", 0,
226 "cs", GPIO_ACTIVE_HIGH),
231 static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power)
233 gpio_direction_output(S3C64XX_GPM(3), power);
236 static struct plat_lcd_data smartq_lcd_power_data = {
237 .set_power = smartq_lcd_power_set,
240 static struct platform_device smartq_lcd_power_device = {
241 .name = "platform-lcd",
242 .dev.parent = &s3c_device_fb.dev,
243 .dev.platform_data = &smartq_lcd_power_data,
246 static struct i2c_board_info smartq_i2c_devs[] __initdata = {
247 { I2C_BOARD_INFO("wm8987", 0x1a), },
250 static struct platform_device *smartq_devices[] __initdata = {
251 &s3c_device_hsmmc1, /* Init iNAND first, ... */
252 &s3c_device_hsmmc0, /* ... then the external SD card */
261 &s3c_device_usb_hsotg,
262 &s3c64xx_device_iis0,
263 &smartq_backlight_device,
264 &smartq_lcd_control_device,
265 &smartq_lcd_power_device,
266 &smartq_usb_otg_vbus_dev,
269 static void __init smartq_lcd_mode_set(void)
273 /* set the LCD type */
274 tmp = __raw_readl(S3C64XX_SPCON);
275 tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK;
276 tmp |= S3C64XX_SPCON_LCD_SEL_RGB;
277 __raw_writel(tmp, S3C64XX_SPCON);
279 /* remove the LCD bypass */
280 tmp = __raw_readl(S3C64XX_MODEM_MIFPCON);
281 tmp &= ~MIFPCON_LCD_BYPASS;
282 __raw_writel(tmp, S3C64XX_MODEM_MIFPCON);
285 static void smartq_power_off(void)
287 gpio_direction_output(S3C64XX_GPK(15), 1);
290 static int __init smartq_power_off_init(void)
294 ret = gpio_request(S3C64XX_GPK(15), "Power control");
296 pr_err("%s: failed to get GPK15\n", __func__);
301 gpio_direction_output(S3C64XX_GPK(15), 0);
303 pm_power_off = smartq_power_off;
308 static int __init smartq_usb_host_init(void)
312 ret = gpio_request(S3C64XX_GPL(0), "USB power control");
314 pr_err("%s: failed to get GPL0\n", __func__);
318 ret = gpio_request(S3C64XX_GPL(1), "USB host power control");
320 pr_err("%s: failed to get GPL1\n", __func__);
324 if (!machine_is_smartq5()) {
325 /* This isn't present on a SmartQ 5 board */
326 ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent");
328 pr_err("%s: failed to get GPL10\n", __func__);
334 gpio_direction_output(S3C64XX_GPL(0), 0);
335 gpio_direction_output(S3C64XX_GPL(1), 0);
336 if (!machine_is_smartq5())
337 gpio_direction_input(S3C64XX_GPL(10));
339 s3c_device_ohci.dev.platform_data = &smartq_usb_host_info;
344 gpio_free(S3C64XX_GPL(1));
346 gpio_free(S3C64XX_GPL(0));
350 static int __init smartq_wifi_init(void)
354 ret = gpio_request(S3C64XX_GPK(1), "wifi control");
356 pr_err("%s: failed to get GPK1\n", __func__);
360 ret = gpio_request(S3C64XX_GPK(2), "wifi reset");
362 pr_err("%s: failed to get GPK2\n", __func__);
363 gpio_free(S3C64XX_GPK(1));
368 gpio_direction_output(S3C64XX_GPK(1), 1);
371 gpio_direction_output(S3C64XX_GPK(2), 0);
373 gpio_set_value(S3C64XX_GPK(2), 1);
374 gpio_direction_input(S3C64XX_GPK(2));
379 static struct map_desc smartq_iodesc[] __initdata = {};
380 void __init smartq_map_io(void)
382 s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc));
383 s3c64xx_set_xtal_freq(12000000);
384 s3c64xx_set_xusbxti_freq(12000000);
385 s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs));
386 s3c64xx_set_timer_source(S3C64XX_PWM3, S3C64XX_PWM4);
388 smartq_lcd_mode_set();
391 static struct gpiod_lookup_table smartq_audio_gpios = {
392 .dev_id = "smartq-audio",
394 GPIO_LOOKUP("GPL", 12, "headphone detect", 0),
395 GPIO_LOOKUP("GPK", 12, "amplifiers shutdown", 0),
400 void __init smartq_machine_init(void)
402 s3c_i2c0_set_platdata(NULL);
403 dwc2_hsotg_set_platdata(&smartq_hsotg_pdata);
404 s3c_hwmon_set_platdata(&smartq_hwmon_pdata);
405 s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata);
406 s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata);
407 s3c64xx_ts_set_platdata(&smartq_touchscreen_pdata);
409 i2c_register_board_info(0, smartq_i2c_devs,
410 ARRAY_SIZE(smartq_i2c_devs));
412 WARN_ON(smartq_lcd_setup_gpio());
413 WARN_ON(smartq_power_off_init());
414 WARN_ON(smartq_usb_host_init());
415 WARN_ON(smartq_wifi_init());
417 pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup));
418 gpiod_add_lookup_table(&smartq_lcd_control_gpiod_table);
419 gpiod_add_lookup_table(&smartq_usb_otg_vbus_gpiod_table);
420 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));
422 gpiod_add_lookup_table(&smartq_audio_gpios);
423 platform_device_register_simple("smartq-audio", -1, NULL, 0);