spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / arch / arm / mach-s3c64xx / mach-smartq.c
blobce31db136231774e5fda9da7ab1a8103209be02c
1 /*
2 * linux/arch/arm/mach-s3c64xx/mach-smartq.c
4 * Copyright (C) 2010 Maurus Cuelenaere
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.
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>
19 #include <linux/spi/spi_gpio.h>
20 #include <linux/usb/gpio_vbus.h>
22 #include <asm/mach-types.h>
23 #include <asm/mach/map.h>
25 #include <mach/map.h>
26 #include <mach/regs-gpio.h>
27 #include <mach/regs-modem.h>
29 #include <plat/clock.h>
30 #include <plat/cpu.h>
31 #include <plat/devs.h>
32 #include <plat/iic.h>
33 #include <plat/gpio-cfg.h>
34 #include <plat/hwmon.h>
35 #include <plat/regs-serial.h>
36 #include <plat/udc-hs.h>
37 #include <plat/usb-control.h>
38 #include <plat/sdhci.h>
39 #include <plat/ts.h>
41 #include <video/platform_lcd.h>
43 #include "common.h"
45 #define UCON S3C2410_UCON_DEFAULT
46 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
47 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
49 static struct s3c2410_uartcfg smartq_uartcfgs[] __initdata = {
50 [0] = {
51 .hwport = 0,
52 .flags = 0,
53 .ucon = UCON,
54 .ulcon = ULCON,
55 .ufcon = UFCON,
57 [1] = {
58 .hwport = 1,
59 .flags = 0,
60 .ucon = UCON,
61 .ulcon = ULCON,
62 .ufcon = UFCON,
64 [2] = {
65 .hwport = 2,
66 .flags = 0,
67 .ucon = UCON,
68 .ulcon = ULCON,
69 .ufcon = UFCON,
73 static void smartq_usb_host_powercontrol(int port, int to)
75 pr_debug("%s(%d, %d)\n", __func__, port, to);
77 if (port == 0) {
78 gpio_set_value(S3C64XX_GPL(0), to);
79 gpio_set_value(S3C64XX_GPL(1), to);
83 static irqreturn_t smartq_usb_host_ocirq(int irq, void *pw)
85 struct s3c2410_hcd_info *info = pw;
87 if (gpio_get_value(S3C64XX_GPL(10)) == 0) {
88 pr_debug("%s: over-current irq (oc detected)\n", __func__);
89 s3c2410_usb_report_oc(info, 3);
90 } else {
91 pr_debug("%s: over-current irq (oc cleared)\n", __func__);
92 s3c2410_usb_report_oc(info, 0);
95 return IRQ_HANDLED;
98 static void smartq_usb_host_enableoc(struct s3c2410_hcd_info *info, int on)
100 int ret;
102 /* This isn't present on a SmartQ 5 board */
103 if (machine_is_smartq5())
104 return;
106 if (on) {
107 ret = request_irq(gpio_to_irq(S3C64XX_GPL(10)),
108 smartq_usb_host_ocirq, IRQF_DISABLED |
109 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
110 "USB host overcurrent", info);
111 if (ret != 0)
112 pr_err("failed to request usb oc irq: %d\n", ret);
113 } else {
114 free_irq(gpio_to_irq(S3C64XX_GPL(10)), info);
118 static struct s3c2410_hcd_info smartq_usb_host_info = {
119 .port[0] = {
120 .flags = S3C_HCDFLG_USED
122 .port[1] = {
123 .flags = 0
126 .power_control = smartq_usb_host_powercontrol,
127 .enable_oc = smartq_usb_host_enableoc,
130 static struct gpio_vbus_mach_info smartq_usb_otg_vbus_pdata = {
131 .gpio_vbus = S3C64XX_GPL(9),
132 .gpio_pullup = -1,
133 .gpio_vbus_inverted = true,
136 static struct platform_device smartq_usb_otg_vbus_dev = {
137 .name = "gpio-vbus",
138 .dev.platform_data = &smartq_usb_otg_vbus_pdata,
141 static int smartq_bl_init(struct device *dev)
143 s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2));
145 return 0;
148 static struct platform_pwm_backlight_data smartq_backlight_data = {
149 .pwm_id = 1,
150 .max_brightness = 1000,
151 .dft_brightness = 600,
152 .pwm_period_ns = 1000000000 / (1000 * 20),
153 .init = smartq_bl_init,
156 static struct platform_device smartq_backlight_device = {
157 .name = "pwm-backlight",
158 .dev = {
159 .parent = &s3c_device_timer[1].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 int __init smartq_lcd_setup_gpio(void)
192 int ret;
194 ret = gpio_request(S3C64XX_GPM(3), "LCD power");
195 if (ret < 0)
196 return ret;
198 /* turn power off */
199 gpio_direction_output(S3C64XX_GPM(3), 0);
201 return 0;
204 /* GPM0 -> CS */
205 static struct spi_gpio_platform_data smartq_lcd_control = {
206 .sck = S3C64XX_GPM(1),
207 .mosi = S3C64XX_GPM(2),
208 .miso = S3C64XX_GPM(2),
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 void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power)
219 gpio_direction_output(S3C64XX_GPM(3), power);
222 static struct plat_lcd_data smartq_lcd_power_data = {
223 .set_power = smartq_lcd_power_set,
226 static struct platform_device smartq_lcd_power_device = {
227 .name = "platform-lcd",
228 .dev.parent = &s3c_device_fb.dev,
229 .dev.platform_data = &smartq_lcd_power_data,
232 static struct i2c_board_info smartq_i2c_devs[] __initdata = {
233 { I2C_BOARD_INFO("wm8987", 0x1a), },
236 static struct platform_device *smartq_devices[] __initdata = {
237 &s3c_device_hsmmc1, /* Init iNAND first, ... */
238 &s3c_device_hsmmc0, /* ... then the external SD card */
239 &s3c_device_hsmmc2,
240 &s3c_device_adc,
241 &s3c_device_fb,
242 &s3c_device_hwmon,
243 &s3c_device_i2c0,
244 &s3c_device_ohci,
245 &s3c_device_rtc,
246 &s3c_device_timer[1],
247 &s3c_device_ts,
248 &s3c_device_usb_hsotg,
249 &s3c64xx_device_iis0,
250 &smartq_backlight_device,
251 &smartq_lcd_control_device,
252 &smartq_lcd_power_device,
253 &smartq_usb_otg_vbus_dev,
256 static void __init smartq_lcd_mode_set(void)
258 u32 tmp;
260 /* set the LCD type */
261 tmp = __raw_readl(S3C64XX_SPCON);
262 tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK;
263 tmp |= S3C64XX_SPCON_LCD_SEL_RGB;
264 __raw_writel(tmp, S3C64XX_SPCON);
266 /* remove the LCD bypass */
267 tmp = __raw_readl(S3C64XX_MODEM_MIFPCON);
268 tmp &= ~MIFPCON_LCD_BYPASS;
269 __raw_writel(tmp, S3C64XX_MODEM_MIFPCON);
272 static void smartq_power_off(void)
274 gpio_direction_output(S3C64XX_GPK(15), 1);
277 static int __init smartq_power_off_init(void)
279 int ret;
281 ret = gpio_request(S3C64XX_GPK(15), "Power control");
282 if (ret < 0) {
283 pr_err("%s: failed to get GPK15\n", __func__);
284 return ret;
287 /* leave power on */
288 gpio_direction_output(S3C64XX_GPK(15), 0);
290 pm_power_off = smartq_power_off;
292 return ret;
295 static int __init smartq_usb_host_init(void)
297 int ret;
299 ret = gpio_request(S3C64XX_GPL(0), "USB power control");
300 if (ret < 0) {
301 pr_err("%s: failed to get GPL0\n", __func__);
302 return ret;
305 ret = gpio_request(S3C64XX_GPL(1), "USB host power control");
306 if (ret < 0) {
307 pr_err("%s: failed to get GPL1\n", __func__);
308 goto err;
311 if (!machine_is_smartq5()) {
312 /* This isn't present on a SmartQ 5 board */
313 ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent");
314 if (ret < 0) {
315 pr_err("%s: failed to get GPL10\n", __func__);
316 goto err2;
320 /* turn power off */
321 gpio_direction_output(S3C64XX_GPL(0), 0);
322 gpio_direction_output(S3C64XX_GPL(1), 0);
323 if (!machine_is_smartq5())
324 gpio_direction_input(S3C64XX_GPL(10));
326 s3c_device_ohci.dev.platform_data = &smartq_usb_host_info;
328 return 0;
330 err2:
331 gpio_free(S3C64XX_GPL(1));
332 err:
333 gpio_free(S3C64XX_GPL(0));
334 return ret;
337 static int __init smartq_usb_otg_init(void)
339 clk_xusbxti.rate = 12000000;
341 return 0;
344 static int __init smartq_wifi_init(void)
346 int ret;
348 ret = gpio_request(S3C64XX_GPK(1), "wifi control");
349 if (ret < 0) {
350 pr_err("%s: failed to get GPK1\n", __func__);
351 return ret;
354 ret = gpio_request(S3C64XX_GPK(2), "wifi reset");
355 if (ret < 0) {
356 pr_err("%s: failed to get GPK2\n", __func__);
357 gpio_free(S3C64XX_GPK(1));
358 return ret;
361 /* turn power on */
362 gpio_direction_output(S3C64XX_GPK(1), 1);
364 /* reset device */
365 gpio_direction_output(S3C64XX_GPK(2), 0);
366 mdelay(100);
367 gpio_set_value(S3C64XX_GPK(2), 1);
368 gpio_direction_input(S3C64XX_GPK(2));
370 return 0;
373 static struct map_desc smartq_iodesc[] __initdata = {};
374 void __init smartq_map_io(void)
376 s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc));
377 s3c24xx_init_clocks(12000000);
378 s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs));
380 smartq_lcd_mode_set();
383 void __init smartq_machine_init(void)
385 s3c_i2c0_set_platdata(NULL);
386 s3c_hwmon_set_platdata(&smartq_hwmon_pdata);
387 s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata);
388 s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata);
389 s3c24xx_ts_set_platdata(&smartq_touchscreen_pdata);
391 i2c_register_board_info(0, smartq_i2c_devs,
392 ARRAY_SIZE(smartq_i2c_devs));
394 WARN_ON(smartq_lcd_setup_gpio());
395 WARN_ON(smartq_power_off_init());
396 WARN_ON(smartq_usb_host_init());
397 WARN_ON(smartq_usb_otg_init());
398 WARN_ON(smartq_wifi_init());
400 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));