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 MC |
30 | |
31 | #include <plat/clock.h> | |
32 | #include <plat/cpu.h> | |
33 | #include <plat/devs.h> | |
436d42c6 | 34 | #include <linux/platform_data/i2c-s3c2410.h> |
a2f7bffa | 35 | #include <plat/gpio-cfg.h> |
436d42c6 | 36 | #include <linux/platform_data/hwmon-s3c.h> |
436d42c6 | 37 | #include <linux/platform_data/usb-ohci-s3c2410.h> |
a2f7bffa | 38 | #include <plat/sdhci.h> |
436d42c6 | 39 | #include <linux/platform_data/touchscreen-s3c2410.h> |
a2f7bffa MC |
40 | |
41 | #include <video/platform_lcd.h> | |
04a49b71 | 42 | #include <plat/samsung-time.h> |
a2f7bffa | 43 | |
b024043b | 44 | #include "common.h" |
a81c1970 | 45 | #include "regs-modem.h" |
b024043b | 46 | |
a2f7bffa MC |
47 | #define UCON S3C2410_UCON_DEFAULT |
48 | #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE) | |
49 | #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE) | |
50 | ||
51 | static struct s3c2410_uartcfg smartq_uartcfgs[] __initdata = { | |
52 | [0] = { | |
53 | .hwport = 0, | |
54 | .flags = 0, | |
55 | .ucon = UCON, | |
56 | .ulcon = ULCON, | |
57 | .ufcon = UFCON, | |
58 | }, | |
59 | [1] = { | |
60 | .hwport = 1, | |
61 | .flags = 0, | |
62 | .ucon = UCON, | |
63 | .ulcon = ULCON, | |
64 | .ufcon = UFCON, | |
65 | }, | |
66 | [2] = { | |
67 | .hwport = 2, | |
68 | .flags = 0, | |
69 | .ucon = UCON, | |
70 | .ulcon = ULCON, | |
71 | .ufcon = UFCON, | |
72 | }, | |
73 | }; | |
74 | ||
75 | static void smartq_usb_host_powercontrol(int port, int to) | |
76 | { | |
77 | pr_debug("%s(%d, %d)\n", __func__, port, to); | |
78 | ||
79 | if (port == 0) { | |
80 | gpio_set_value(S3C64XX_GPL(0), to); | |
81 | gpio_set_value(S3C64XX_GPL(1), to); | |
82 | } | |
83 | } | |
84 | ||
85 | static irqreturn_t smartq_usb_host_ocirq(int irq, void *pw) | |
86 | { | |
87 | struct s3c2410_hcd_info *info = pw; | |
88 | ||
89 | if (gpio_get_value(S3C64XX_GPL(10)) == 0) { | |
90 | pr_debug("%s: over-current irq (oc detected)\n", __func__); | |
91 | s3c2410_usb_report_oc(info, 3); | |
92 | } else { | |
93 | pr_debug("%s: over-current irq (oc cleared)\n", __func__); | |
94 | s3c2410_usb_report_oc(info, 0); | |
95 | } | |
96 | ||
97 | return IRQ_HANDLED; | |
98 | } | |
99 | ||
100 | static void smartq_usb_host_enableoc(struct s3c2410_hcd_info *info, int on) | |
101 | { | |
102 | int ret; | |
103 | ||
104 | /* This isn't present on a SmartQ 5 board */ | |
105 | if (machine_is_smartq5()) | |
106 | return; | |
107 | ||
108 | if (on) { | |
109 | ret = request_irq(gpio_to_irq(S3C64XX_GPL(10)), | |
fa53d5cd | 110 | smartq_usb_host_ocirq, |
a2f7bffa MC |
111 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
112 | "USB host overcurrent", info); | |
113 | if (ret != 0) | |
114 | pr_err("failed to request usb oc irq: %d\n", ret); | |
115 | } else { | |
116 | free_irq(gpio_to_irq(S3C64XX_GPL(10)), info); | |
117 | } | |
118 | } | |
119 | ||
120 | static struct s3c2410_hcd_info smartq_usb_host_info = { | |
121 | .port[0] = { | |
122 | .flags = S3C_HCDFLG_USED | |
123 | }, | |
124 | .port[1] = { | |
125 | .flags = 0 | |
126 | }, | |
127 | ||
128 | .power_control = smartq_usb_host_powercontrol, | |
129 | .enable_oc = smartq_usb_host_enableoc, | |
130 | }; | |
131 | ||
132 | static struct gpio_vbus_mach_info smartq_usb_otg_vbus_pdata = { | |
133 | .gpio_vbus = S3C64XX_GPL(9), | |
134 | .gpio_pullup = -1, | |
135 | .gpio_vbus_inverted = true, | |
136 | }; | |
137 | ||
138 | static struct platform_device smartq_usb_otg_vbus_dev = { | |
139 | .name = "gpio-vbus", | |
140 | .dev.platform_data = &smartq_usb_otg_vbus_pdata, | |
141 | }; | |
142 | ||
9e978f09 | 143 | static int smartq_bl_init(struct device *dev) |
a2f7bffa MC |
144 | { |
145 | s3c_gpio_cfgpin(S3C64XX_GPF(15), S3C_GPIO_SFN(2)); | |
146 | ||
147 | return 0; | |
148 | } | |
149 | ||
150 | static struct platform_pwm_backlight_data smartq_backlight_data = { | |
151 | .pwm_id = 1, | |
152 | .max_brightness = 1000, | |
153 | .dft_brightness = 600, | |
154 | .pwm_period_ns = 1000000000 / (1000 * 20), | |
a63652f1 | 155 | .enable_gpio = -1, |
a2f7bffa MC |
156 | .init = smartq_bl_init, |
157 | }; | |
158 | ||
159 | static struct platform_device smartq_backlight_device = { | |
160 | .name = "pwm-backlight", | |
161 | .dev = { | |
7fa33bdb | 162 | .parent = &samsung_device_pwm.dev, |
a2f7bffa MC |
163 | .platform_data = &smartq_backlight_data, |
164 | }, | |
165 | }; | |
166 | ||
167 | static struct s3c2410_ts_mach_info smartq_touchscreen_pdata __initdata = { | |
168 | .delay = 65535, | |
169 | .presc = 99, | |
170 | .oversampling_shift = 4, | |
171 | }; | |
172 | ||
173 | static struct s3c_sdhci_platdata smartq_internal_hsmmc_pdata = { | |
174 | .max_width = 4, | |
eeda5fcb | 175 | .cd_type = S3C_SDHCI_CD_PERMANENT, |
a2f7bffa MC |
176 | }; |
177 | ||
178 | static struct s3c_hwmon_pdata smartq_hwmon_pdata __initdata = { | |
179 | /* Battery voltage (?-4.2V) */ | |
180 | .in[0] = &(struct s3c_hwmon_chcfg) { | |
181 | .name = "smartq:battery-voltage", | |
182 | .mult = 3300, | |
183 | .div = 2048, | |
184 | }, | |
185 | /* Reference voltage (1.2V) */ | |
186 | .in[1] = &(struct s3c_hwmon_chcfg) { | |
187 | .name = "smartq:reference-voltage", | |
188 | .mult = 3300, | |
189 | .div = 4096, | |
190 | }, | |
191 | }; | |
192 | ||
99f6e1f5 JS |
193 | static struct s3c_hsotg_plat smartq_hsotg_pdata; |
194 | ||
49f91b9e MC |
195 | static int __init smartq_lcd_setup_gpio(void) |
196 | { | |
197 | int ret; | |
198 | ||
199 | ret = gpio_request(S3C64XX_GPM(3), "LCD power"); | |
200 | if (ret < 0) | |
201 | return ret; | |
202 | ||
203 | /* turn power off */ | |
204 | gpio_direction_output(S3C64XX_GPM(3), 0); | |
205 | ||
206 | return 0; | |
207 | } | |
208 | ||
209 | /* GPM0 -> CS */ | |
210 | static struct spi_gpio_platform_data smartq_lcd_control = { | |
211 | .sck = S3C64XX_GPM(1), | |
212 | .mosi = S3C64XX_GPM(2), | |
213 | .miso = S3C64XX_GPM(2), | |
214 | }; | |
215 | ||
216 | static struct platform_device smartq_lcd_control_device = { | |
217 | .name = "spi-gpio", | |
218 | .id = 1, | |
219 | .dev.platform_data = &smartq_lcd_control, | |
220 | }; | |
221 | ||
a2f7bffa MC |
222 | static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power) |
223 | { | |
224 | gpio_direction_output(S3C64XX_GPM(3), power); | |
225 | } | |
226 | ||
227 | static struct plat_lcd_data smartq_lcd_power_data = { | |
228 | .set_power = smartq_lcd_power_set, | |
229 | }; | |
230 | ||
231 | static struct platform_device smartq_lcd_power_device = { | |
232 | .name = "platform-lcd", | |
233 | .dev.parent = &s3c_device_fb.dev, | |
234 | .dev.platform_data = &smartq_lcd_power_data, | |
235 | }; | |
236 | ||
4e13c0ea MC |
237 | static struct i2c_board_info smartq_i2c_devs[] __initdata = { |
238 | { I2C_BOARD_INFO("wm8987", 0x1a), }, | |
239 | }; | |
240 | ||
a2f7bffa MC |
241 | static struct platform_device *smartq_devices[] __initdata = { |
242 | &s3c_device_hsmmc1, /* Init iNAND first, ... */ | |
243 | &s3c_device_hsmmc0, /* ... then the external SD card */ | |
244 | &s3c_device_hsmmc2, | |
245 | &s3c_device_adc, | |
246 | &s3c_device_fb, | |
247 | &s3c_device_hwmon, | |
248 | &s3c_device_i2c0, | |
249 | &s3c_device_ohci, | |
250 | &s3c_device_rtc, | |
7fa33bdb | 251 | &samsung_device_pwm, |
a2f7bffa MC |
252 | &s3c_device_ts, |
253 | &s3c_device_usb_hsotg, | |
4e13c0ea | 254 | &s3c64xx_device_iis0, |
a2f7bffa | 255 | &smartq_backlight_device, |
49f91b9e | 256 | &smartq_lcd_control_device, |
a2f7bffa MC |
257 | &smartq_lcd_power_device, |
258 | &smartq_usb_otg_vbus_dev, | |
259 | }; | |
260 | ||
261 | static void __init smartq_lcd_mode_set(void) | |
262 | { | |
263 | u32 tmp; | |
264 | ||
265 | /* set the LCD type */ | |
266 | tmp = __raw_readl(S3C64XX_SPCON); | |
267 | tmp &= ~S3C64XX_SPCON_LCD_SEL_MASK; | |
268 | tmp |= S3C64XX_SPCON_LCD_SEL_RGB; | |
269 | __raw_writel(tmp, S3C64XX_SPCON); | |
270 | ||
271 | /* remove the LCD bypass */ | |
272 | tmp = __raw_readl(S3C64XX_MODEM_MIFPCON); | |
273 | tmp &= ~MIFPCON_LCD_BYPASS; | |
274 | __raw_writel(tmp, S3C64XX_MODEM_MIFPCON); | |
275 | } | |
276 | ||
277 | static void smartq_power_off(void) | |
278 | { | |
279 | gpio_direction_output(S3C64XX_GPK(15), 1); | |
280 | } | |
281 | ||
282 | static int __init smartq_power_off_init(void) | |
283 | { | |
284 | int ret; | |
285 | ||
286 | ret = gpio_request(S3C64XX_GPK(15), "Power control"); | |
287 | if (ret < 0) { | |
288 | pr_err("%s: failed to get GPK15\n", __func__); | |
289 | return ret; | |
290 | } | |
291 | ||
292 | /* leave power on */ | |
293 | gpio_direction_output(S3C64XX_GPK(15), 0); | |
294 | ||
a2f7bffa MC |
295 | pm_power_off = smartq_power_off; |
296 | ||
297 | return ret; | |
298 | } | |
299 | ||
300 | static int __init smartq_usb_host_init(void) | |
301 | { | |
302 | int ret; | |
303 | ||
304 | ret = gpio_request(S3C64XX_GPL(0), "USB power control"); | |
305 | if (ret < 0) { | |
306 | pr_err("%s: failed to get GPL0\n", __func__); | |
307 | return ret; | |
308 | } | |
309 | ||
310 | ret = gpio_request(S3C64XX_GPL(1), "USB host power control"); | |
311 | if (ret < 0) { | |
312 | pr_err("%s: failed to get GPL1\n", __func__); | |
313 | goto err; | |
314 | } | |
315 | ||
316 | if (!machine_is_smartq5()) { | |
317 | /* This isn't present on a SmartQ 5 board */ | |
318 | ret = gpio_request(S3C64XX_GPL(10), "USB host overcurrent"); | |
319 | if (ret < 0) { | |
320 | pr_err("%s: failed to get GPL10\n", __func__); | |
321 | goto err2; | |
322 | } | |
323 | } | |
324 | ||
325 | /* turn power off */ | |
326 | gpio_direction_output(S3C64XX_GPL(0), 0); | |
327 | gpio_direction_output(S3C64XX_GPL(1), 0); | |
328 | if (!machine_is_smartq5()) | |
329 | gpio_direction_input(S3C64XX_GPL(10)); | |
330 | ||
331 | s3c_device_ohci.dev.platform_data = &smartq_usb_host_info; | |
332 | ||
333 | return 0; | |
334 | ||
335 | err2: | |
336 | gpio_free(S3C64XX_GPL(1)); | |
337 | err: | |
338 | gpio_free(S3C64XX_GPL(0)); | |
339 | return ret; | |
340 | } | |
341 | ||
a2f7bffa MC |
342 | static int __init smartq_wifi_init(void) |
343 | { | |
344 | int ret; | |
345 | ||
346 | ret = gpio_request(S3C64XX_GPK(1), "wifi control"); | |
347 | if (ret < 0) { | |
348 | pr_err("%s: failed to get GPK1\n", __func__); | |
349 | return ret; | |
350 | } | |
351 | ||
352 | ret = gpio_request(S3C64XX_GPK(2), "wifi reset"); | |
353 | if (ret < 0) { | |
354 | pr_err("%s: failed to get GPK2\n", __func__); | |
355 | gpio_free(S3C64XX_GPK(1)); | |
356 | return ret; | |
357 | } | |
358 | ||
359 | /* turn power on */ | |
360 | gpio_direction_output(S3C64XX_GPK(1), 1); | |
361 | ||
362 | /* reset device */ | |
363 | gpio_direction_output(S3C64XX_GPK(2), 0); | |
364 | mdelay(100); | |
365 | gpio_set_value(S3C64XX_GPK(2), 1); | |
366 | gpio_direction_input(S3C64XX_GPK(2)); | |
367 | ||
368 | return 0; | |
369 | } | |
370 | ||
371 | static struct map_desc smartq_iodesc[] __initdata = {}; | |
372 | void __init smartq_map_io(void) | |
373 | { | |
374 | s3c64xx_init_io(smartq_iodesc, ARRAY_SIZE(smartq_iodesc)); | |
b69f460d TF |
375 | s3c64xx_set_xtal_freq(12000000); |
376 | s3c64xx_set_xusbxti_freq(12000000); | |
a2f7bffa | 377 | s3c24xx_init_uarts(smartq_uartcfgs, ARRAY_SIZE(smartq_uartcfgs)); |
04a49b71 | 378 | samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4); |
a2f7bffa MC |
379 | |
380 | smartq_lcd_mode_set(); | |
381 | } | |
382 | ||
383 | void __init smartq_machine_init(void) | |
384 | { | |
385 | s3c_i2c0_set_platdata(NULL); | |
99f6e1f5 | 386 | s3c_hsotg_set_platdata(&smartq_hsotg_pdata); |
a2f7bffa MC |
387 | s3c_hwmon_set_platdata(&smartq_hwmon_pdata); |
388 | s3c_sdhci1_set_platdata(&smartq_internal_hsmmc_pdata); | |
389 | s3c_sdhci2_set_platdata(&smartq_internal_hsmmc_pdata); | |
390 | s3c24xx_ts_set_platdata(&smartq_touchscreen_pdata); | |
391 | ||
4e13c0ea MC |
392 | i2c_register_board_info(0, smartq_i2c_devs, |
393 | ARRAY_SIZE(smartq_i2c_devs)); | |
394 | ||
49f91b9e | 395 | WARN_ON(smartq_lcd_setup_gpio()); |
a2f7bffa MC |
396 | WARN_ON(smartq_power_off_init()); |
397 | WARN_ON(smartq_usb_host_init()); | |
a2f7bffa MC |
398 | WARN_ON(smartq_wifi_init()); |
399 | ||
400 | platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices)); | |
401 | } |