blob: 936a63fc68d51644977cb800a2662e9b725fe200 [file] [log] [blame]
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +02001/*
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
12#include <linux/delay.h>
13#include <linux/fb.h>
14#include <linux/gpio.h>
Arnd Bergmanndf0cc2d2014-07-09 11:09:42 +020015#include <linux/gpio/machine.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020016#include <linux/init.h>
17#include <linux/platform_device.h>
Thierry Reding4dddfb82015-10-13 05:04:24 +090018#include <linux/pwm.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020019#include <linux/pwm_backlight.h>
20#include <linux/serial_core.h>
Tushar Behera334a1c72014-02-14 10:32:45 +090021#include <linux/serial_s3c.h>
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +020022#include <linux/spi/spi_gpio.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020023#include <linux/usb/gpio_vbus.h>
Lukasz Majewski126625e2012-05-09 13:16:53 +020024#include <linux/platform_data/s3c-hsotg.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020025
26#include <asm/mach-types.h>
27#include <asm/mach/map.h>
28
29#include <mach/map.h>
30#include <mach/regs-gpio.h>
Linus Walleijb0161ca2014-01-14 14:24:24 +010031#include <mach/gpio-samsung.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020032
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020033#include <plat/cpu.h>
34#include <plat/devs.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020035#include <linux/platform_data/i2c-s3c2410.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020036#include <plat/gpio-cfg.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020037#include <linux/platform_data/hwmon-s3c.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020038#include <linux/platform_data/usb-ohci-s3c2410.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020039#include <plat/sdhci.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020040#include <linux/platform_data/touchscreen-s3c2410.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020041
42#include <video/platform_lcd.h>
Romain Naour04a49b72013-01-09 18:47:04 -080043#include <plat/samsung-time.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020044
Kukjin Kimb024043b2011-12-22 23:27:42 +010045#include "common.h"
Kukjin Kima81c1972013-01-02 13:24:12 -080046#include "regs-modem.h"
Kukjin Kimb024043b2011-12-22 23:27:42 +010047
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020048#define UCON S3C2410_UCON_DEFAULT
49#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
50#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
51
52static struct s3c2410_uartcfg smartq_uartcfgs[] __initdata = {
53 [0] = {
54 .hwport = 0,
55 .flags = 0,
56 .ucon = UCON,
57 .ulcon = ULCON,
58 .ufcon = UFCON,
59 },
60 [1] = {
61 .hwport = 1,
62 .flags = 0,
63 .ucon = UCON,
64 .ulcon = ULCON,
65 .ufcon = UFCON,
66 },
67 [2] = {
68 .hwport = 2,
69 .flags = 0,
70 .ucon = UCON,
71 .ulcon = ULCON,
72 .ufcon = UFCON,
73 },
74};
75
76static void smartq_usb_host_powercontrol(int port, int to)
77{
78 pr_debug("%s(%d, %d)\n", __func__, port, to);
79
80 if (port == 0) {
81 gpio_set_value(S3C64XX_GPL(0), to);
82 gpio_set_value(S3C64XX_GPL(1), to);
83 }
84}
85
86static irqreturn_t smartq_usb_host_ocirq(int irq, void *pw)
87{
88 struct s3c2410_hcd_info *info = pw;
89
90 if (gpio_get_value(S3C64XX_GPL(10)) == 0) {
91 pr_debug("%s: over-current irq (oc detected)\n", __func__);
92 s3c2410_usb_report_oc(info, 3);
93 } else {
94 pr_debug("%s: over-current irq (oc cleared)\n", __func__);
95 s3c2410_usb_report_oc(info, 0);
96 }
97
98 return IRQ_HANDLED;
99}
100
101static void smartq_usb_host_enableoc(struct s3c2410_hcd_info *info, int on)
102{
103 int ret;
104
105 /* This isn't present on a SmartQ 5 board */
106 if (machine_is_smartq5())
107 return;
108
109 if (on) {
110 ret = request_irq(gpio_to_irq(S3C64XX_GPL(10)),
Michael Opdenackerfa53d5c2013-12-12 07:05:19 +0900111 smartq_usb_host_ocirq,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200112 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
113 "USB host overcurrent", info);
114 if (ret != 0)
115 pr_err("failed to request usb oc irq: %d\n", ret);
116 } else {
117 free_irq(gpio_to_irq(S3C64XX_GPL(10)), info);
118 }
119}
120
121static struct s3c2410_hcd_info smartq_usb_host_info = {
122 .port[0] = {
123 .flags = S3C_HCDFLG_USED
124 },
125 .port[1] = {
126 .flags = 0
127 },
128
129 .power_control = smartq_usb_host_powercontrol,
130 .enable_oc = smartq_usb_host_enableoc,
131};
132
133static struct gpio_vbus_mach_info smartq_usb_otg_vbus_pdata = {
134 .gpio_vbus = S3C64XX_GPL(9),
135 .gpio_pullup = -1,
136 .gpio_vbus_inverted = true,
137};
138
139static struct platform_device smartq_usb_otg_vbus_dev = {
140 .name = "gpio-vbus",
141 .dev.platform_data = &smartq_usb_otg_vbus_pdata,
142};
143
Thierry Reding4dddfb82015-10-13 05:04:24 +0900144static struct pwm_lookup smartq_pwm_lookup[] = {
145 PWM_LOOKUP("samsung-pwm", 1, "pwm-backlight.0", NULL,
146 1000000000 / (1000 * 20), PWM_POLARITY_NORMAL),
147};
148
Uwe Kleine-König9e978f02010-09-02 09:14:20 +0100149static int smartq_bl_init(struct device *dev)
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200150{
151 s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2));
152
153 return 0;
154}
155
156static struct platform_pwm_backlight_data smartq_backlight_data = {
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200157 .max_brightness = 1000,
158 .dft_brightness = 600,
Thierry Redinga63652f2013-08-30 12:19:52 +0200159 .enable_gpio = -1,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200160 .init = smartq_bl_init,
161};
162
163static struct platform_device smartq_backlight_device = {
164 .name = "pwm-backlight",
165 .dev = {
Tomasz Figa7fa33bd2013-03-09 15:37:53 +0100166 .parent = &samsung_device_pwm.dev,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200167 .platform_data = &smartq_backlight_data,
168 },
169};
170
171static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata = {
172 .delay = 65535,
173 .presc = 99,
174 .oversampling_shift = 4,
175};
176
177static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata = {
178 .max_width = 4,
Maurus Cuelenaereeeda5fc2010-08-13 21:17:54 +0200179 .cd_type = S3C_SDHCI_CD_PERMANENT,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200180};
181
182static struct s3c_hwmon_pdata smartq_hwmon_pdata __initdata = {
183 /* Battery voltage (?-4.2V) */
184 .in[0] = &(struct s3c_hwmon_chcfg) {
185 .name = "smartq:battery-voltage",
186 .mult = 3300,
187 .div = 2048,
188 },
189 /* Reference voltage (1.2V) */
190 .in[1] = &(struct s3c_hwmon_chcfg) {
191 .name = "smartq:reference-voltage",
192 .mult = 3300,
193 .div = 4096,
194 },
195};
196
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500197static struct dwc2_hsotg_plat smartq_hsotg_pdata;
Joonyoung Shim99f6e1f2012-03-07 04:23:47 -0800198
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +0200199static int __init smartq_lcd_setup_gpio(void)
200{
201 int ret;
202
203 ret = gpio_request(S3C64XX_GPM(3), "LCD power");
204 if (ret < 0)
205 return ret;
206
207 /* turn power off */
208 gpio_direction_output(S3C64XX_GPM(3), 0);
209
210 return 0;
211}
212
213/* GPM0 -> CS */
214static struct spi_gpio_platform_data smartq_lcd_control = {
215 .sck = S3C64XX_GPM(1),
216 .mosi = S3C64XX_GPM(2),
217 .miso = S3C64XX_GPM(2),
218};
219
220static struct platform_device smartq_lcd_control_device = {
221 .name = "spi-gpio",
222 .id = 1,
223 .dev.platform_data = &smartq_lcd_control,
224};
225
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200226static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power)
227{
228 gpio_direction_output(S3C64XX_GPM(3), power);
229}
230
231static struct plat_lcd_data smartq_lcd_power_data = {
232 .set_power = smartq_lcd_power_set,
233};
234
235static struct platform_device smartq_lcd_power_device = {
236 .name = "platform-lcd",
237 .dev.parent = &s3c_device_fb.dev,
238 .dev.platform_data = &smartq_lcd_power_data,
239};
240
Maurus Cuelenaere4e13c0e2010-08-13 21:17:59 +0200241static struct i2c_board_info smartq_i2c_devs[] __initdata = {
242 { I2C_BOARD_INFO("wm8987", 0x1a), },
243};
244
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200245static struct platform_device *smartq_devices[] __initdata = {
246 &s3c_device_hsmmc1, /* Init iNAND first, ... */
247 &s3c_device_hsmmc0, /* ... then the external SD card */
248 &s3c_device_hsmmc2,
249 &s3c_device_adc,
250 &s3c_device_fb,
251 &s3c_device_hwmon,
252 &s3c_device_i2c0,
253 &s3c_device_ohci,
254 &s3c_device_rtc,
Tomasz Figa7fa33bd2013-03-09 15:37:53 +0100255 &samsung_device_pwm,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200256 &s3c_device_usb_hsotg,
Maurus Cuelenaere4e13c0e2010-08-13 21:17:59 +0200257 &s3c64xx_device_iis0,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200258 &smartq_backlight_device,
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +0200259 &smartq_lcd_control_device,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200260 &smartq_lcd_power_device,
261 &smartq_usb_otg_vbus_dev,
262};
263
264static void __init smartq_lcd_mode_set(void)
265{
266 u32 tmp;
267
268 /* set the LCD type */
269 tmp = __raw_readl(S3C64XX_SPCON);
270 tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK;
271 tmp |= S3C64XX_SPCON_LCD_SEL_RGB;
272 __raw_writel(tmp, S3C64XX_SPCON);
273
274 /* remove the LCD bypass */
275 tmp = __raw_readl(S3C64XX_MODEM_MIFPCON);
276 tmp &= ~MIFPCON_LCD_BYPASS;
277 __raw_writel(tmp, S3C64XX_MODEM_MIFPCON);
278}
279
280static void smartq_power_off(void)
281{
282 gpio_direction_output(S3C64XX_GPK(15), 1);
283}
284
285static int __init smartq_power_off_init(void)
286{
287 int ret;
288
289 ret = gpio_request(S3C64XX_GPK(15), "Power control");
290 if (ret < 0) {
291 pr_err("%s: failed to get GPK15\n", __func__);
292 return ret;
293 }
294
295 /* leave power on */
296 gpio_direction_output(S3C64XX_GPK(15), 0);
297
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200298 pm_power_off = smartq_power_off;
299
300 return ret;
301}
302
303static int __init smartq_usb_host_init(void)
304{
305 int ret;
306
307 ret = gpio_request(S3C64XX_GPL(0), "USB power control");
308 if (ret < 0) {
309 pr_err("%s: failed to get GPL0\n", __func__);
310 return ret;
311 }
312
313 ret = gpio_request(S3C64XX_GPL(1), "USB host power control");
314 if (ret < 0) {
315 pr_err("%s: failed to get GPL1\n", __func__);
316 goto err;
317 }
318
319 if (!machine_is_smartq5()) {
320 /* This isn't present on a SmartQ 5 board */
321 ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent");
322 if (ret < 0) {
323 pr_err("%s: failed to get GPL10\n", __func__);
324 goto err2;
325 }
326 }
327
328 /* turn power off */
329 gpio_direction_output(S3C64XX_GPL(0), 0);
330 gpio_direction_output(S3C64XX_GPL(1), 0);
331 if (!machine_is_smartq5())
332 gpio_direction_input(S3C64XX_GPL(10));
333
334 s3c_device_ohci.dev.platform_data = &smartq_usb_host_info;
335
336 return 0;
337
338err2:
339 gpio_free(S3C64XX_GPL(1));
340err:
341 gpio_free(S3C64XX_GPL(0));
342 return ret;
343}
344
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200345static int __init smartq_wifi_init(void)
346{
347 int ret;
348
349 ret = gpio_request(S3C64XX_GPK(1), "wifi control");
350 if (ret < 0) {
351 pr_err("%s: failed to get GPK1\n", __func__);
352 return ret;
353 }
354
355 ret = gpio_request(S3C64XX_GPK(2), "wifi reset");
356 if (ret < 0) {
357 pr_err("%s: failed to get GPK2\n", __func__);
358 gpio_free(S3C64XX_GPK(1));
359 return ret;
360 }
361
362 /* turn power on */
363 gpio_direction_output(S3C64XX_GPK(1), 1);
364
365 /* reset device */
366 gpio_direction_output(S3C64XX_GPK(2), 0);
367 mdelay(100);
368 gpio_set_value(S3C64XX_GPK(2), 1);
369 gpio_direction_input(S3C64XX_GPK(2));
370
371 return 0;
372}
373
374static struct map_desc smartq_iodesc[] __initdata = {};
375void __init smartq_map_io(void)
376{
377 s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc));
Tomasz Figab69f4602013-08-26 02:00:38 +0900378 s3c64xx_set_xtal_freq(12000000);
379 s3c64xx_set_xusbxti_freq(12000000);
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200380 s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs));
Romain Naour04a49b72013-01-09 18:47:04 -0800381 samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200382
383 smartq_lcd_mode_set();
384}
385
Arnd Bergmanndf0cc2d2014-07-09 11:09:42 +0200386static struct gpiod_lookup_table smartq_audio_gpios = {
387 .dev_id = "smartq-audio",
388 .table = {
389 GPIO_LOOKUP("GPL", 12, "headphone detect", 0),
390 GPIO_LOOKUP("GPK", 12, "amplifiers shutdown", 0),
391 { },
392 },
393};
394
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200395void __init smartq_machine_init(void)
396{
397 s3c_i2c0_set_platdata(NULL);
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500398 dwc2_hsotg_set_platdata(&smartq_hsotg_pdata);
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200399 s3c_hwmon_set_platdata(&smartq_hwmon_pdata);
400 s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata);
401 s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata);
Arnd Bergmanna829ae52015-03-02 09:47:23 +0100402 s3c64xx_ts_set_platdata(&smartq_touchscreen_pdata);
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200403
Maurus Cuelenaere4e13c0e2010-08-13 21:17:59 +0200404 i2c_register_board_info(0, smartq_i2c_devs,
405 ARRAY_SIZE(smartq_i2c_devs));
406
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +0200407 WARN_ON(smartq_lcd_setup_gpio());
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200408 WARN_ON(smartq_power_off_init());
409 WARN_ON(smartq_usb_host_init());
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200410 WARN_ON(smartq_wifi_init());
411
Thierry Reding4dddfb82015-10-13 05:04:24 +0900412 pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup));
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200413 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));
Arnd Bergmanndf0cc2d2014-07-09 11:09:42 +0200414
415 gpiod_add_lookup_table(&smartq_audio_gpios);
416 platform_device_register_simple("smartq-audio", -1, NULL, 0);
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200417}