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/usb/gpio_vbus.h>
17 #include <linux/platform_data/s3c-hsotg.h>
19 #include <asm/mach-types.h>
20 #include <asm/mach/map.h>
23 #include <mach/regs-gpio.h>
24 #include <mach/gpio-samsung.h>
27 #include <plat/devs.h>
28 #include <linux/platform_data/i2c-s3c2410.h>
29 #include <plat/gpio-cfg.h>
30 #include <linux/platform_data/hwmon-s3c.h>
31 #include <linux/platform_data/usb-ohci-s3c2410.h>
32 #include <plat/sdhci.h>
33 #include <linux/platform_data/touchscreen-s3c2410.h>
35 #include <video/platform_lcd.h>
36 #include <plat/samsung-time.h>
39 #include "mach-smartq.h"
40 #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)
46 static struct s3c2410_uartcfg smartq_uartcfgs
[] __initdata
= {
70 static void smartq_usb_host_powercontrol(int port
, int to
)
72 pr_debug("%s(%d, %d)\n", __func__
, port
, to
);
75 gpio_set_value(S3C64XX_GPL(0), to
);
76 gpio_set_value(S3C64XX_GPL(1), to
);
80 static irqreturn_t
smartq_usb_host_ocirq(int irq
, void *pw
)
82 struct s3c2410_hcd_info
*info
= pw
;
84 if (gpio_get_value(S3C64XX_GPL(10)) == 0) {
85 pr_debug("%s: over-current irq (oc detected)\n", __func__
);
86 s3c2410_usb_report_oc(info
, 3);
88 pr_debug("%s: over-current irq (oc cleared)\n", __func__
);
89 s3c2410_usb_report_oc(info
, 0);
95 static void smartq_usb_host_enableoc(struct s3c2410_hcd_info
*info
, int on
)
99 /* This isn't present on a SmartQ 5 board */
100 if (machine_is_smartq5())
104 ret
= request_irq(gpio_to_irq(S3C64XX_GPL(10)),
105 smartq_usb_host_ocirq
,
106 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
107 "USB host overcurrent", info
);
109 pr_err("failed to request usb oc irq: %d\n", ret
);
111 free_irq(gpio_to_irq(S3C64XX_GPL(10)), info
);
115 static struct s3c2410_hcd_info smartq_usb_host_info
= {
117 .flags
= S3C_HCDFLG_USED
123 .power_control
= smartq_usb_host_powercontrol
,
124 .enable_oc
= smartq_usb_host_enableoc
,
127 static struct gpio_vbus_mach_info smartq_usb_otg_vbus_pdata
= {
128 .gpio_vbus
= S3C64XX_GPL(9),
130 .gpio_vbus_inverted
= true,
133 static struct platform_device smartq_usb_otg_vbus_dev
= {
135 .dev
.platform_data
= &smartq_usb_otg_vbus_pdata
,
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));
150 static struct platform_pwm_backlight_data smartq_backlight_data
= {
151 .max_brightness
= 1000,
152 .dft_brightness
= 600,
154 .init
= smartq_bl_init
,
157 static struct platform_device smartq_backlight_device
= {
158 .name
= "pwm-backlight",
160 .parent
= &samsung_device_pwm
.dev
,
161 .platform_data
= &smartq_backlight_data
,
165 static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata
= {
168 .oversampling_shift
= 4,
171 static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata
= {
173 .cd_type
= S3C_SDHCI_CD_PERMANENT
,
176 static struct s3c_hwmon_pdata smartq_hwmon_pdata __initdata
= {
177 /* Battery voltage (?-4.2V) */
178 .in
[0] = &(struct s3c_hwmon_chcfg
) {
179 .name
= "smartq:battery-voltage",
183 /* Reference voltage (1.2V) */
184 .in
[1] = &(struct s3c_hwmon_chcfg
) {
185 .name
= "smartq:reference-voltage",
191 static struct dwc2_hsotg_plat smartq_hsotg_pdata
;
193 static int __init
smartq_lcd_setup_gpio(void)
197 ret
= gpio_request(S3C64XX_GPM(3), "LCD power");
202 gpio_direction_output(S3C64XX_GPM(3), 0);
208 static struct spi_gpio_platform_data smartq_lcd_control
= {
212 static struct platform_device smartq_lcd_control_device
= {
215 .dev
.platform_data
= &smartq_lcd_control
,
218 static struct gpiod_lookup_table smartq_lcd_control_gpiod_table
= {
219 .dev_id
= "spi_gpio",
221 GPIO_LOOKUP("GPIOM", 1,
222 "sck", GPIO_ACTIVE_HIGH
),
223 GPIO_LOOKUP("GPIOM", 2,
224 "mosi", GPIO_ACTIVE_HIGH
),
225 GPIO_LOOKUP("GPIOM", 3,
226 "miso", GPIO_ACTIVE_HIGH
),
227 GPIO_LOOKUP("GPIOM", 0,
228 "cs", GPIO_ACTIVE_HIGH
),
233 static void smartq_lcd_power_set(struct plat_lcd_data
*pd
, unsigned int power
)
235 gpio_direction_output(S3C64XX_GPM(3), power
);
238 static struct plat_lcd_data smartq_lcd_power_data
= {
239 .set_power
= smartq_lcd_power_set
,
242 static struct platform_device smartq_lcd_power_device
= {
243 .name
= "platform-lcd",
244 .dev
.parent
= &s3c_device_fb
.dev
,
245 .dev
.platform_data
= &smartq_lcd_power_data
,
248 static struct i2c_board_info smartq_i2c_devs
[] __initdata
= {
249 { I2C_BOARD_INFO("wm8987", 0x1a), },
252 static struct platform_device
*smartq_devices
[] __initdata
= {
253 &s3c_device_hsmmc1
, /* Init iNAND first, ... */
254 &s3c_device_hsmmc0
, /* ... then the external SD card */
263 &s3c_device_usb_hsotg
,
264 &s3c64xx_device_iis0
,
265 &smartq_backlight_device
,
266 &smartq_lcd_control_device
,
267 &smartq_lcd_power_device
,
268 &smartq_usb_otg_vbus_dev
,
271 static void __init
smartq_lcd_mode_set(void)
275 /* set the LCD type */
276 tmp
= __raw_readl(S3C64XX_SPCON
);
277 tmp
&= ~S3C64XX_SPCON_LCD_SEL_MASK
;
278 tmp
|= S3C64XX_SPCON_LCD_SEL_RGB
;
279 __raw_writel(tmp
, S3C64XX_SPCON
);
281 /* remove the LCD bypass */
282 tmp
= __raw_readl(S3C64XX_MODEM_MIFPCON
);
283 tmp
&= ~MIFPCON_LCD_BYPASS
;
284 __raw_writel(tmp
, S3C64XX_MODEM_MIFPCON
);
287 static void smartq_power_off(void)
289 gpio_direction_output(S3C64XX_GPK(15), 1);
292 static int __init
smartq_power_off_init(void)
296 ret
= gpio_request(S3C64XX_GPK(15), "Power control");
298 pr_err("%s: failed to get GPK15\n", __func__
);
303 gpio_direction_output(S3C64XX_GPK(15), 0);
305 pm_power_off
= smartq_power_off
;
310 static int __init
smartq_usb_host_init(void)
314 ret
= gpio_request(S3C64XX_GPL(0), "USB power control");
316 pr_err("%s: failed to get GPL0\n", __func__
);
320 ret
= gpio_request(S3C64XX_GPL(1), "USB host power control");
322 pr_err("%s: failed to get GPL1\n", __func__
);
326 if (!machine_is_smartq5()) {
327 /* This isn't present on a SmartQ 5 board */
328 ret
= gpio_request(S3C64XX_GPL(10), "USB host overcurrent");
330 pr_err("%s: failed to get GPL10\n", __func__
);
336 gpio_direction_output(S3C64XX_GPL(0), 0);
337 gpio_direction_output(S3C64XX_GPL(1), 0);
338 if (!machine_is_smartq5())
339 gpio_direction_input(S3C64XX_GPL(10));
341 s3c_device_ohci
.dev
.platform_data
= &smartq_usb_host_info
;
346 gpio_free(S3C64XX_GPL(1));
348 gpio_free(S3C64XX_GPL(0));
352 static int __init
smartq_wifi_init(void)
356 ret
= gpio_request(S3C64XX_GPK(1), "wifi control");
358 pr_err("%s: failed to get GPK1\n", __func__
);
362 ret
= gpio_request(S3C64XX_GPK(2), "wifi reset");
364 pr_err("%s: failed to get GPK2\n", __func__
);
365 gpio_free(S3C64XX_GPK(1));
370 gpio_direction_output(S3C64XX_GPK(1), 1);
373 gpio_direction_output(S3C64XX_GPK(2), 0);
375 gpio_set_value(S3C64XX_GPK(2), 1);
376 gpio_direction_input(S3C64XX_GPK(2));
381 static struct map_desc smartq_iodesc
[] __initdata
= {};
382 void __init
smartq_map_io(void)
384 s3c64xx_init_io(smartq_iodesc
, ARRAY_SIZE(smartq_iodesc
));
385 s3c64xx_set_xtal_freq(12000000);
386 s3c64xx_set_xusbxti_freq(12000000);
387 s3c24xx_init_uarts(smartq_uartcfgs
, ARRAY_SIZE(smartq_uartcfgs
));
388 samsung_set_timer_source(SAMSUNG_PWM3
, SAMSUNG_PWM4
);
390 smartq_lcd_mode_set();
393 static struct gpiod_lookup_table smartq_audio_gpios
= {
394 .dev_id
= "smartq-audio",
396 GPIO_LOOKUP("GPL", 12, "headphone detect", 0),
397 GPIO_LOOKUP("GPK", 12, "amplifiers shutdown", 0),
402 void __init
smartq_machine_init(void)
404 s3c_i2c0_set_platdata(NULL
);
405 dwc2_hsotg_set_platdata(&smartq_hsotg_pdata
);
406 s3c_hwmon_set_platdata(&smartq_hwmon_pdata
);
407 s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata
);
408 s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata
);
409 s3c64xx_ts_set_platdata(&smartq_touchscreen_pdata
);
411 i2c_register_board_info(0, smartq_i2c_devs
,
412 ARRAY_SIZE(smartq_i2c_devs
));
414 WARN_ON(smartq_lcd_setup_gpio());
415 WARN_ON(smartq_power_off_init());
416 WARN_ON(smartq_usb_host_init());
417 WARN_ON(smartq_wifi_init());
419 pwm_add_table(smartq_pwm_lookup
, ARRAY_SIZE(smartq_pwm_lookup
));
420 gpiod_add_lookup_table(&smartq_lcd_control_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);