blob: 86d980b448fd0bc272e1e0cf1ab616f0e32ab24e [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>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/pwm_backlight.h>
18#include <linux/serial_core.h>
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +020019#include <linux/spi/spi_gpio.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020020#include <linux/usb/gpio_vbus.h>
Lukasz Majewski126625e2012-05-09 13:16:53 +020021#include <linux/platform_data/s3c-hsotg.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020022
23#include <asm/mach-types.h>
24#include <asm/mach/map.h>
25
26#include <mach/map.h>
27#include <mach/regs-gpio.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020028
29#include <plat/clock.h>
30#include <plat/cpu.h>
31#include <plat/devs.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020032#include <linux/platform_data/i2c-s3c2410.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020033#include <plat/gpio-cfg.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020034#include <linux/platform_data/hwmon-s3c.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020035#include <plat/regs-serial.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020036#include <linux/platform_data/usb-ohci-s3c2410.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020037#include <plat/sdhci.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020038#include <linux/platform_data/touchscreen-s3c2410.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020039
40#include <video/platform_lcd.h>
Romain Naour04a49b72013-01-09 18:47:04 -080041#include <plat/samsung-time.h>
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020042
Kukjin Kimb024043b2011-12-22 23:27:42 +010043#include "common.h"
Kukjin Kima81c1972013-01-02 13:24:12 -080044#include "regs-modem.h"
Kukjin Kimb024043b2011-12-22 23:27:42 +010045
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +020046#define UCON S3C2410_UCON_DEFAULT
47#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
48#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
49
50static struct s3c2410_uartcfg smartq_uartcfgs[] __initdata = {
51 [0] = {
52 .hwport = 0,
53 .flags = 0,
54 .ucon = UCON,
55 .ulcon = ULCON,
56 .ufcon = UFCON,
57 },
58 [1] = {
59 .hwport = 1,
60 .flags = 0,
61 .ucon = UCON,
62 .ulcon = ULCON,
63 .ufcon = UFCON,
64 },
65 [2] = {
66 .hwport = 2,
67 .flags = 0,
68 .ucon = UCON,
69 .ulcon = ULCON,
70 .ufcon = UFCON,
71 },
72};
73
74static void smartq_usb_host_powercontrol(int port, int to)
75{
76 pr_debug("%s(%d, %d)\n", __func__, port, to);
77
78 if (port == 0) {
79 gpio_set_value(S3C64XX_GPL(0), to);
80 gpio_set_value(S3C64XX_GPL(1), to);
81 }
82}
83
84static irqreturn_t smartq_usb_host_ocirq(int irq, void *pw)
85{
86 struct s3c2410_hcd_info *info = pw;
87
88 if (gpio_get_value(S3C64XX_GPL(10)) == 0) {
89 pr_debug("%s: over-current irq (oc detected)\n", __func__);
90 s3c2410_usb_report_oc(info, 3);
91 } else {
92 pr_debug("%s: over-current irq (oc cleared)\n", __func__);
93 s3c2410_usb_report_oc(info, 0);
94 }
95
96 return IRQ_HANDLED;
97}
98
99static void smartq_usb_host_enableoc(struct s3c2410_hcd_info *info, int on)
100{
101 int ret;
102
103 /* This isn't present on a SmartQ 5 board */
104 if (machine_is_smartq5())
105 return;
106
107 if (on) {
108 ret = request_irq(gpio_to_irq(S3C64XX_GPL(10)),
109 smartq_usb_host_ocirq, IRQF_DISABLED |
110 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
111 "USB host overcurrent", info);
112 if (ret != 0)
113 pr_err("failed to request usb oc irq: %d\n", ret);
114 } else {
115 free_irq(gpio_to_irq(S3C64XX_GPL(10)), info);
116 }
117}
118
119static struct s3c2410_hcd_info smartq_usb_host_info = {
120 .port[0] = {
121 .flags = S3C_HCDFLG_USED
122 },
123 .port[1] = {
124 .flags = 0
125 },
126
127 .power_control = smartq_usb_host_powercontrol,
128 .enable_oc = smartq_usb_host_enableoc,
129};
130
131static struct gpio_vbus_mach_info smartq_usb_otg_vbus_pdata = {
132 .gpio_vbus = S3C64XX_GPL(9),
133 .gpio_pullup = -1,
134 .gpio_vbus_inverted = true,
135};
136
137static struct platform_device smartq_usb_otg_vbus_dev = {
138 .name = "gpio-vbus",
139 .dev.platform_data = &smartq_usb_otg_vbus_pdata,
140};
141
Uwe Kleine-König9e978f02010-09-02 09:14:20 +0100142static int smartq_bl_init(struct device *dev)
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200143{
144 s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2));
145
146 return 0;
147}
148
149static struct platform_pwm_backlight_data smartq_backlight_data = {
150 .pwm_id = 1,
151 .max_brightness = 1000,
152 .dft_brightness = 600,
153 .pwm_period_ns = 1000000000 / (1000 * 20),
154 .init = smartq_bl_init,
155};
156
157static struct platform_device smartq_backlight_device = {
158 .name = "pwm-backlight",
159 .dev = {
Tomasz Figa7fa33bd2013-03-09 15:37:53 +0100160 .parent = &samsung_device_pwm.dev,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200161 .platform_data = &smartq_backlight_data,
162 },
163};
164
165static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata = {
166 .delay = 65535,
167 .presc = 99,
168 .oversampling_shift = 4,
169};
170
171static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata = {
172 .max_width = 4,
Maurus Cuelenaereeeda5fc2010-08-13 21:17:54 +0200173 .cd_type = S3C_SDHCI_CD_PERMANENT,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200174};
175
176static 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",
180 .mult = 3300,
181 .div = 2048,
182 },
183 /* Reference voltage (1.2V) */
184 .in[1] = &(struct s3c_hwmon_chcfg) {
185 .name = "smartq:reference-voltage",
186 .mult = 3300,
187 .div = 4096,
188 },
189};
190
Joonyoung Shim99f6e1f2012-03-07 04:23:47 -0800191static struct s3c_hsotg_plat smartq_hsotg_pdata;
192
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +0200193static int __init smartq_lcd_setup_gpio(void)
194{
195 int ret;
196
197 ret = gpio_request(S3C64XX_GPM(3), "LCD power");
198 if (ret < 0)
199 return ret;
200
201 /* turn power off */
202 gpio_direction_output(S3C64XX_GPM(3), 0);
203
204 return 0;
205}
206
207/* GPM0 -> CS */
208static struct spi_gpio_platform_data smartq_lcd_control = {
209 .sck = S3C64XX_GPM(1),
210 .mosi = S3C64XX_GPM(2),
211 .miso = S3C64XX_GPM(2),
212};
213
214static struct platform_device smartq_lcd_control_device = {
215 .name = "spi-gpio",
216 .id = 1,
217 .dev.platform_data = &smartq_lcd_control,
218};
219
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200220static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power)
221{
222 gpio_direction_output(S3C64XX_GPM(3), power);
223}
224
225static struct plat_lcd_data smartq_lcd_power_data = {
226 .set_power = smartq_lcd_power_set,
227};
228
229static struct platform_device smartq_lcd_power_device = {
230 .name = "platform-lcd",
231 .dev.parent = &s3c_device_fb.dev,
232 .dev.platform_data = &smartq_lcd_power_data,
233};
234
Maurus Cuelenaere4e13c0e2010-08-13 21:17:59 +0200235static struct i2c_board_info smartq_i2c_devs[] __initdata = {
236 { I2C_BOARD_INFO("wm8987", 0x1a), },
237};
238
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200239static struct platform_device *smartq_devices[] __initdata = {
240 &s3c_device_hsmmc1, /* Init iNAND first, ... */
241 &s3c_device_hsmmc0, /* ... then the external SD card */
242 &s3c_device_hsmmc2,
243 &s3c_device_adc,
244 &s3c_device_fb,
245 &s3c_device_hwmon,
246 &s3c_device_i2c0,
247 &s3c_device_ohci,
248 &s3c_device_rtc,
Tomasz Figa7fa33bd2013-03-09 15:37:53 +0100249 &samsung_device_pwm,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200250 &s3c_device_ts,
251 &s3c_device_usb_hsotg,
Maurus Cuelenaere4e13c0e2010-08-13 21:17:59 +0200252 &s3c64xx_device_iis0,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200253 &smartq_backlight_device,
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +0200254 &smartq_lcd_control_device,
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200255 &smartq_lcd_power_device,
256 &smartq_usb_otg_vbus_dev,
257};
258
259static void __init smartq_lcd_mode_set(void)
260{
261 u32 tmp;
262
263 /* set the LCD type */
264 tmp = __raw_readl(S3C64XX_SPCON);
265 tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK;
266 tmp |= S3C64XX_SPCON_LCD_SEL_RGB;
267 __raw_writel(tmp, S3C64XX_SPCON);
268
269 /* remove the LCD bypass */
270 tmp = __raw_readl(S3C64XX_MODEM_MIFPCON);
271 tmp &= ~MIFPCON_LCD_BYPASS;
272 __raw_writel(tmp, S3C64XX_MODEM_MIFPCON);
273}
274
275static void smartq_power_off(void)
276{
277 gpio_direction_output(S3C64XX_GPK(15), 1);
278}
279
280static int __init smartq_power_off_init(void)
281{
282 int ret;
283
284 ret = gpio_request(S3C64XX_GPK(15), "Power control");
285 if (ret < 0) {
286 pr_err("%s: failed to get GPK15\n", __func__);
287 return ret;
288 }
289
290 /* leave power on */
291 gpio_direction_output(S3C64XX_GPK(15), 0);
292
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200293 pm_power_off = smartq_power_off;
294
295 return ret;
296}
297
298static int __init smartq_usb_host_init(void)
299{
300 int ret;
301
302 ret = gpio_request(S3C64XX_GPL(0), "USB power control");
303 if (ret < 0) {
304 pr_err("%s: failed to get GPL0\n", __func__);
305 return ret;
306 }
307
308 ret = gpio_request(S3C64XX_GPL(1), "USB host power control");
309 if (ret < 0) {
310 pr_err("%s: failed to get GPL1\n", __func__);
311 goto err;
312 }
313
314 if (!machine_is_smartq5()) {
315 /* This isn't present on a SmartQ 5 board */
316 ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent");
317 if (ret < 0) {
318 pr_err("%s: failed to get GPL10\n", __func__);
319 goto err2;
320 }
321 }
322
323 /* turn power off */
324 gpio_direction_output(S3C64XX_GPL(0), 0);
325 gpio_direction_output(S3C64XX_GPL(1), 0);
326 if (!machine_is_smartq5())
327 gpio_direction_input(S3C64XX_GPL(10));
328
329 s3c_device_ohci.dev.platform_data = &smartq_usb_host_info;
330
331 return 0;
332
333err2:
334 gpio_free(S3C64XX_GPL(1));
335err:
336 gpio_free(S3C64XX_GPL(0));
337 return ret;
338}
339
340static int __init smartq_usb_otg_init(void)
341{
342 clk_xusbxti.rate = 12000000;
343
344 return 0;
345}
346
347static int __init smartq_wifi_init(void)
348{
349 int ret;
350
351 ret = gpio_request(S3C64XX_GPK(1), "wifi control");
352 if (ret < 0) {
353 pr_err("%s: failed to get GPK1\n", __func__);
354 return ret;
355 }
356
357 ret = gpio_request(S3C64XX_GPK(2), "wifi reset");
358 if (ret < 0) {
359 pr_err("%s: failed to get GPK2\n", __func__);
360 gpio_free(S3C64XX_GPK(1));
361 return ret;
362 }
363
364 /* turn power on */
365 gpio_direction_output(S3C64XX_GPK(1), 1);
366
367 /* reset device */
368 gpio_direction_output(S3C64XX_GPK(2), 0);
369 mdelay(100);
370 gpio_set_value(S3C64XX_GPK(2), 1);
371 gpio_direction_input(S3C64XX_GPK(2));
372
373 return 0;
374}
375
376static struct map_desc smartq_iodesc[] __initdata = {};
377void __init smartq_map_io(void)
378{
379 s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc));
380 s3c24xx_init_clocks(12000000);
381 s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs));
Romain Naour04a49b72013-01-09 18:47:04 -0800382 samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200383
384 smartq_lcd_mode_set();
385}
386
387void __init smartq_machine_init(void)
388{
389 s3c_i2c0_set_platdata(NULL);
Joonyoung Shim99f6e1f2012-03-07 04:23:47 -0800390 s3c_hsotg_set_platdata(&smartq_hsotg_pdata);
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200391 s3c_hwmon_set_platdata(&smartq_hwmon_pdata);
392 s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata);
393 s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata);
394 s3c24xx_ts_set_platdata(&smartq_touchscreen_pdata);
395
Maurus Cuelenaere4e13c0e2010-08-13 21:17:59 +0200396 i2c_register_board_info(0, smartq_i2c_devs,
397 ARRAY_SIZE(smartq_i2c_devs));
398
Maurus Cuelenaere49f91b92010-08-13 21:17:52 +0200399 WARN_ON(smartq_lcd_setup_gpio());
Maurus Cuelenaerea2f7bff2010-05-20 11:35:50 +0200400 WARN_ON(smartq_power_off_init());
401 WARN_ON(smartq_usb_host_init());
402 WARN_ON(smartq_usb_otg_init());
403 WARN_ON(smartq_wifi_init());
404
405 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));
406}