Commit | Line | Data |
---|---|---|
a2f7bffa MC |
1 | /* |
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> | |
334a1c70 | 19 | #include <linux/serial_s3c.h> |
49f91b9e | 20 | #include <linux/spi/spi_gpio.h> |
a2f7bffa | 21 | #include <linux/usb/gpio_vbus.h> |
126625e1 | 22 | #include <linux/platform_data/s3c-hsotg.h> |
a2f7bffa MC |
23 | |
24 | #include <asm/mach-types.h> | |
25 | #include <asm/mach/map.h> | |
26 | ||
27 | #include <mach/map.h> | |
28 | #include <mach/regs-gpio.h> | |
b0161caa | 29 | #include <mach/gpio-samsung.h> |
a2f7bffa | 30 | |
a2f7bffa MC |
31 | #include <plat/cpu.h> |
32 | #include <plat/devs.h> | |
436d42c6 | 33 | #include <linux/platform_data/i2c-s3c2410.h> |
a2f7bffa | 34 | #include <plat/gpio-cfg.h> |
436d42c6 | 35 | #include <linux/platform_data/hwmon-s3c.h> |
436d42c6 | 36 | #include <linux/platform_data/usb-ohci-s3c2410.h> |
a2f7bffa | 37 | #include <plat/sdhci.h> |
436d42c6 | 38 | #include <linux/platform_data/touchscreen-s3c2410.h> |
a2f7bffa MC |
39 | |
40 | #include <video/platform_lcd.h> | |
04a49b71 | 41 | #include <plat/samsung-time.h> |
a2f7bffa | 42 | |
b024043b | 43 | #include "common.h" |
a81c1970 | 44 | #include "regs-modem.h" |
b024043b | 45 | |
a2f7bffa MC |
46 | #define UCON S3C2410_UCON_DEFAULT |
47 | #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE) | |
48 | #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE) | |
49 | ||
50 | static 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 | ||
74 | static 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 | ||
84 | static 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 | ||
99 | static 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)), | |
fa53d5cd | 109 | smartq_usb_host_ocirq, |
a2f7bffa MC |
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 | ||
119 | static 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 | ||
131 | static 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 | ||
137 | static struct platform_device smartq_usb_otg_vbus_dev = { | |
138 | .name = "gpio-vbus", | |
139 | .dev.platform_data = &smartq_usb_otg_vbus_pdata, | |
140 | }; | |
141 | ||
9e978f09 | 142 | static int smartq_bl_init(struct device *dev) |
a2f7bffa MC |
143 | { |
144 | s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2)); | |
145 | ||
146 | return 0; | |
147 | } | |
148 | ||
149 | static 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), | |
a63652f1 | 154 | .enable_gpio = -1, |
a2f7bffa MC |
155 | .init = smartq_bl_init, |
156 | }; | |
157 | ||
158 | static struct platform_device smartq_backlight_device = { | |
159 | .name = "pwm-backlight", | |
160 | .dev = { | |
7fa33bdb | 161 | .parent = &samsung_device_pwm.dev, |
a2f7bffa MC |
162 | .platform_data = &smartq_backlight_data, |
163 | }, | |
164 | }; | |
165 | ||
166 | static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata = { | |
167 | .delay = 65535, | |
168 | .presc = 99, | |
169 | .oversampling_shift = 4, | |
170 | }; | |
171 | ||
172 | static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata = { | |
173 | .max_width = 4, | |
eeda5fcb | 174 | .cd_type = S3C_SDHCI_CD_PERMANENT, |
a2f7bffa MC |
175 | }; |
176 | ||
177 | static struct s3c_hwmon_pdata smartq_hwmon_pdata __initdata = { | |
178 | /* Battery voltage (?-4.2V) */ | |
179 | .in[0] = &(struct s3c_hwmon_chcfg) { | |
180 | .name = "smartq:battery-voltage", | |
181 | .mult = 3300, | |
182 | .div = 2048, | |
183 | }, | |
184 | /* Reference voltage (1.2V) */ | |
185 | .in[1] = &(struct s3c_hwmon_chcfg) { | |
186 | .name = "smartq:reference-voltage", | |
187 | .mult = 3300, | |
188 | .div = 4096, | |
189 | }, | |
190 | }; | |
191 | ||
99f6e1f5 JS |
192 | static struct s3c_hsotg_plat smartq_hsotg_pdata; |
193 | ||
49f91b9e MC |
194 | static int __init smartq_lcd_setup_gpio(void) |
195 | { | |
196 | int ret; | |
197 | ||
198 | ret = gpio_request(S3C64XX_GPM(3), "LCD power"); | |
199 | if (ret < 0) | |
200 | return ret; | |
201 | ||
202 | /* turn power off */ | |
203 | gpio_direction_output(S3C64XX_GPM(3), 0); | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
208 | /* GPM0 -> CS */ | |
209 | static struct spi_gpio_platform_data smartq_lcd_control = { | |
210 | .sck = S3C64XX_GPM(1), | |
211 | .mosi = S3C64XX_GPM(2), | |
212 | .miso = S3C64XX_GPM(2), | |
213 | }; | |
214 | ||
215 | static struct platform_device smartq_lcd_control_device = { | |
216 | .name = "spi-gpio", | |
217 | .id = 1, | |
218 | .dev.platform_data = &smartq_lcd_control, | |
219 | }; | |
220 | ||
a2f7bffa MC |
221 | static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power) |
222 | { | |
223 | gpio_direction_output(S3C64XX_GPM(3), power); | |
224 | } | |
225 | ||
226 | static struct plat_lcd_data smartq_lcd_power_data = { | |
227 | .set_power = smartq_lcd_power_set, | |
228 | }; | |
229 | ||
230 | static struct platform_device smartq_lcd_power_device = { | |
231 | .name = "platform-lcd", | |
232 | .dev.parent = &s3c_device_fb.dev, | |
233 | .dev.platform_data = &smartq_lcd_power_data, | |
234 | }; | |
235 | ||
4e13c0ea MC |
236 | static struct i2c_board_info smartq_i2c_devs[] __initdata = { |
237 | { I2C_BOARD_INFO("wm8987", 0x1a), }, | |
238 | }; | |
239 | ||
a2f7bffa MC |
240 | static struct platform_device *smartq_devices[] __initdata = { |
241 | &s3c_device_hsmmc1, /* Init iNAND first, ... */ | |
242 | &s3c_device_hsmmc0, /* ... then the external SD card */ | |
243 | &s3c_device_hsmmc2, | |
244 | &s3c_device_adc, | |
245 | &s3c_device_fb, | |
246 | &s3c_device_hwmon, | |
247 | &s3c_device_i2c0, | |
248 | &s3c_device_ohci, | |
249 | &s3c_device_rtc, | |
7fa33bdb | 250 | &samsung_device_pwm, |
a2f7bffa MC |
251 | &s3c_device_ts, |
252 | &s3c_device_usb_hsotg, | |
4e13c0ea | 253 | &s3c64xx_device_iis0, |
a2f7bffa | 254 | &smartq_backlight_device, |
49f91b9e | 255 | &smartq_lcd_control_device, |
a2f7bffa MC |
256 | &smartq_lcd_power_device, |
257 | &smartq_usb_otg_vbus_dev, | |
258 | }; | |
259 | ||
260 | static void __init smartq_lcd_mode_set(void) | |
261 | { | |
262 | u32 tmp; | |
263 | ||
264 | /* set the LCD type */ | |
265 | tmp = __raw_readl(S3C64XX_SPCON); | |
266 | tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK; | |
267 | tmp |= S3C64XX_SPCON_LCD_SEL_RGB; | |
268 | __raw_writel(tmp, S3C64XX_SPCON); | |
269 | ||
270 | /* remove the LCD bypass */ | |
271 | tmp = __raw_readl(S3C64XX_MODEM_MIFPCON); | |
272 | tmp &= ~MIFPCON_LCD_BYPASS; | |
273 | __raw_writel(tmp, S3C64XX_MODEM_MIFPCON); | |
274 | } | |
275 | ||
276 | static void smartq_power_off(void) | |
277 | { | |
278 | gpio_direction_output(S3C64XX_GPK(15), 1); | |
279 | } | |
280 | ||
281 | static int __init smartq_power_off_init(void) | |
282 | { | |
283 | int ret; | |
284 | ||
285 | ret = gpio_request(S3C64XX_GPK(15), "Power control"); | |
286 | if (ret < 0) { | |
287 | pr_err("%s: failed to get GPK15\n", __func__); | |
288 | return ret; | |
289 | } | |
290 | ||
291 | /* leave power on */ | |
292 | gpio_direction_output(S3C64XX_GPK(15), 0); | |
293 | ||
a2f7bffa MC |
294 | pm_power_off = smartq_power_off; |
295 | ||
296 | return ret; | |
297 | } | |
298 | ||
299 | static int __init smartq_usb_host_init(void) | |
300 | { | |
301 | int ret; | |
302 | ||
303 | ret = gpio_request(S3C64XX_GPL(0), "USB power control"); | |
304 | if (ret < 0) { | |
305 | pr_err("%s: failed to get GPL0\n", __func__); | |
306 | return ret; | |
307 | } | |
308 | ||
309 | ret = gpio_request(S3C64XX_GPL(1), "USB host power control"); | |
310 | if (ret < 0) { | |
311 | pr_err("%s: failed to get GPL1\n", __func__); | |
312 | goto err; | |
313 | } | |
314 | ||
315 | if (!machine_is_smartq5()) { | |
316 | /* This isn't present on a SmartQ 5 board */ | |
317 | ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent"); | |
318 | if (ret < 0) { | |
319 | pr_err("%s: failed to get GPL10\n", __func__); | |
320 | goto err2; | |
321 | } | |
322 | } | |
323 | ||
324 | /* turn power off */ | |
325 | gpio_direction_output(S3C64XX_GPL(0), 0); | |
326 | gpio_direction_output(S3C64XX_GPL(1), 0); | |
327 | if (!machine_is_smartq5()) | |
328 | gpio_direction_input(S3C64XX_GPL(10)); | |
329 | ||
330 | s3c_device_ohci.dev.platform_data = &smartq_usb_host_info; | |
331 | ||
332 | return 0; | |
333 | ||
334 | err2: | |
335 | gpio_free(S3C64XX_GPL(1)); | |
336 | err: | |
337 | gpio_free(S3C64XX_GPL(0)); | |
338 | return ret; | |
339 | } | |
340 | ||
a2f7bffa MC |
341 | static int __init smartq_wifi_init(void) |
342 | { | |
343 | int ret; | |
344 | ||
345 | ret = gpio_request(S3C64XX_GPK(1), "wifi control"); | |
346 | if (ret < 0) { | |
347 | pr_err("%s: failed to get GPK1\n", __func__); | |
348 | return ret; | |
349 | } | |
350 | ||
351 | ret = gpio_request(S3C64XX_GPK(2), "wifi reset"); | |
352 | if (ret < 0) { | |
353 | pr_err("%s: failed to get GPK2\n", __func__); | |
354 | gpio_free(S3C64XX_GPK(1)); | |
355 | return ret; | |
356 | } | |
357 | ||
358 | /* turn power on */ | |
359 | gpio_direction_output(S3C64XX_GPK(1), 1); | |
360 | ||
361 | /* reset device */ | |
362 | gpio_direction_output(S3C64XX_GPK(2), 0); | |
363 | mdelay(100); | |
364 | gpio_set_value(S3C64XX_GPK(2), 1); | |
365 | gpio_direction_input(S3C64XX_GPK(2)); | |
366 | ||
367 | return 0; | |
368 | } | |
369 | ||
370 | static struct map_desc smartq_iodesc[] __initdata = {}; | |
371 | void __init smartq_map_io(void) | |
372 | { | |
373 | s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc)); | |
b69f460d TF |
374 | s3c64xx_set_xtal_freq(12000000); |
375 | s3c64xx_set_xusbxti_freq(12000000); | |
a2f7bffa | 376 | s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs)); |
04a49b71 | 377 | samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4); |
a2f7bffa MC |
378 | |
379 | smartq_lcd_mode_set(); | |
380 | } | |
381 | ||
382 | void __init smartq_machine_init(void) | |
383 | { | |
384 | s3c_i2c0_set_platdata(NULL); | |
99f6e1f5 | 385 | s3c_hsotg_set_platdata(&smartq_hsotg_pdata); |
a2f7bffa MC |
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); | |
390 | ||
4e13c0ea MC |
391 | i2c_register_board_info(0, smartq_i2c_devs, |
392 | ARRAY_SIZE(smartq_i2c_devs)); | |
393 | ||
49f91b9e | 394 | WARN_ON(smartq_lcd_setup_gpio()); |
a2f7bffa MC |
395 | WARN_ON(smartq_power_off_init()); |
396 | WARN_ON(smartq_usb_host_init()); | |
a2f7bffa MC |
397 | WARN_ON(smartq_wifi_init()); |
398 | ||
399 | platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices)); | |
400 | } |