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