blob: 2a2fa0620133cdee7086e44034764e703bfefd2a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/mach-h1940.c
2 *
3 * Copyright (c) 2003-2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * http://www.handhelds.org/projects/h1940.html
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012*/
13
14#include <linux/kernel.h>
15#include <linux/types.h>
16#include <linux/interrupt.h>
17#include <linux/list.h>
Russell King8d717a52010-05-22 19:47:18 +010018#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/timer.h>
20#include <linux/init.h>
Ben Dooks333a42e2007-05-20 11:55:53 +010021#include <linux/sysdev.h>
Ben Dooksb6d1f542006-12-17 23:22:26 +010022#include <linux/serial_core.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010023#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010024#include <linux/io.h>
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +010025#include <linux/gpio.h>
Arnaud Patard (Rtp)bbb1c832011-01-06 21:52:46 +020026#include <linux/input.h>
27#include <linux/gpio_keys.h>
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +010028#include <linux/pwm_backlight.h>
Vasily Khoruzhick68730b42010-09-27 09:32:49 +030029#include <linux/i2c.h>
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020030#include <linux/leds.h>
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +020031#include <linux/pda_power.h>
32#include <linux/s3c_adc_battery.h>
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +020033#include <linux/delay.h>
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020034
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +010035#include <video/platform_lcd.h>
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +010036
37#include <linux/mmc/host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include <asm/mach/arch.h>
40#include <asm/mach/map.h>
41#include <asm/mach/irq.h>
42
Russell Kinga09e64f2008-08-05 16:14:15 +010043#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/irq.h>
45#include <asm/mach-types.h>
46
Ben Dooksa2b7ba92008-10-07 22:26:09 +010047#include <plat/regs-serial.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010048#include <mach/regs-lcd.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010049#include <mach/regs-clock.h>
Arnaud Patardf92273c2005-09-09 13:10:10 -070050
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +010051#include <mach/regs-gpio.h>
52#include <mach/gpio-fns.h>
53#include <mach/gpio-nrs.h>
54
Russell Kinga09e64f2008-08-05 16:14:15 +010055#include <mach/h1940.h>
56#include <mach/h1940-latch.h>
57#include <mach/fb.h>
Ben Dooks57bd4b92008-10-30 10:14:37 +000058#include <plat/udc.h>
Ben Dooks3e1b7762008-10-31 16:14:40 +000059#include <plat/iic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Ben Dooks40b956f2010-05-04 14:38:49 +090061#include <plat/gpio-cfg.h>
Ben Dooksd5120ae2008-10-07 23:09:51 +010062#include <plat/clock.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010063#include <plat/devs.h>
64#include <plat/cpu.h>
Ben Dookse24b8642008-10-21 14:06:34 +010065#include <plat/pll.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010066#include <plat/pm.h>
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +010067#include <plat/mci.h>
Maurus Cuelenaere73e59b12010-05-04 13:12:41 +020068#include <plat/ts.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Vasily Khoruzhick68730b42010-09-27 09:32:49 +030070#include <sound/uda1380.h>
71
Vasily Khoruzhick14477092010-09-08 12:39:46 +030072#define H1940_LATCH ((void __force __iomem *)0xF8000000)
73
74#define H1940_PA_LATCH S3C2410_CS2
75
76#define H1940_LATCH_BIT(x) (1 << ((x) + 16 - S3C_GPIO_END))
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078static struct map_desc h1940_iodesc[] __initdata = {
Ben Dookse1981682006-02-10 22:40:51 +000079 [0] = {
80 .virtual = (unsigned long)H1940_LATCH,
81 .pfn = __phys_to_pfn(H1940_PA_LATCH),
82 .length = SZ_16K,
83 .type = MT_DEVICE
84 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87#define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
88#define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
89#define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
90
Ben Dooks66a9b492006-06-18 23:04:05 +010091static struct s3c2410_uartcfg h1940_uartcfgs[] __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 [0] = {
93 .hwport = 0,
94 .flags = 0,
95 .ucon = 0x3c5,
96 .ulcon = 0x03,
97 .ufcon = 0x51,
98 },
99 [1] = {
100 .hwport = 1,
101 .flags = 0,
102 .ucon = 0x245,
103 .ulcon = 0x03,
104 .ufcon = 0x00,
105 },
106 /* IR port */
107 [2] = {
108 .hwport = 2,
109 .flags = 0,
110 .uart_flags = UPF_CONS_FLOW,
111 .ucon = 0x3c5,
112 .ulcon = 0x43,
113 .ufcon = 0x51,
114 }
115};
116
Ben Dookse1981682006-02-10 22:40:51 +0000117/* Board control latch control */
118
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300119static unsigned int latch_state;
Ben Dookse1981682006-02-10 22:40:51 +0000120
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300121static void h1940_latch_control(unsigned int clear, unsigned int set)
Ben Dookse1981682006-02-10 22:40:51 +0000122{
123 unsigned long flags;
124
125 local_irq_save(flags);
126
127 latch_state &= ~clear;
128 latch_state |= set;
129
130 __raw_writel(latch_state, H1940_LATCH);
131
132 local_irq_restore(flags);
133}
134
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300135static inline int h1940_gpiolib_to_latch(int offset)
136{
137 return 1 << (offset + 16);
138}
139
140static void h1940_gpiolib_latch_set(struct gpio_chip *chip,
141 unsigned offset, int value)
142{
143 int latch_bit = h1940_gpiolib_to_latch(offset);
144
145 h1940_latch_control(value ? 0 : latch_bit,
146 value ? latch_bit : 0);
147}
148
149static int h1940_gpiolib_latch_output(struct gpio_chip *chip,
150 unsigned offset, int value)
151{
152 h1940_gpiolib_latch_set(chip, offset, value);
153 return 0;
154}
155
156static int h1940_gpiolib_latch_get(struct gpio_chip *chip,
157 unsigned offset)
158{
159 return (latch_state >> (offset + 16)) & 1;
160}
161
162struct gpio_chip h1940_latch_gpiochip = {
163 .base = H1940_LATCH_GPIO(0),
164 .owner = THIS_MODULE,
165 .label = "H1940_LATCH",
166 .ngpio = 16,
167 .direction_output = h1940_gpiolib_latch_output,
168 .set = h1940_gpiolib_latch_set,
169 .get = h1940_gpiolib_latch_get,
170};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Arnaud Patard71a9c422007-02-13 00:21:26 +0100172static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
Ben Dooks070276d2009-05-17 22:32:23 +0100173 .vbus_pin = S3C2410_GPG(5),
Arnaud Patard71a9c422007-02-13 00:21:26 +0100174 .vbus_pin_inverted = 1,
Lars-Peter Clausene27c3c52011-03-07 08:42:00 +0100175 .pullup_pin = H1940_LATCH_USB_DP,
Arnaud Patard71a9c422007-02-13 00:21:26 +0100176};
177
Arnaud Patardce8877b2009-12-23 19:25:05 +0000178static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
179 .delay = 10000,
180 .presc = 49,
181 .oversampling_shift = 2,
Naveen Krishna5bfdca12010-05-18 20:44:27 +0900182 .cfg_gpio = s3c24xx_ts_cfg_gpio,
Arnaud Patardce8877b2009-12-23 19:25:05 +0000183};
Arnaud Patard71a9c422007-02-13 00:21:26 +0100184
Arnaud Patardf92273c2005-09-09 13:10:10 -0700185/**
186 * Set lcd on or off
187 **/
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700188static struct s3c2410fb_display h1940_lcd __initdata = {
Krzysztof Heltf28ef572007-10-16 01:28:58 -0700189 .lcdcon5= S3C2410_LCDCON5_FRM565 | \
190 S3C2410_LCDCON5_INVVLINE | \
191 S3C2410_LCDCON5_HWSWP,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700192
Krzysztof Helt1f411532007-10-16 01:28:57 -0700193 .type = S3C2410_LCDCON1_TFT,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700194 .width = 240,
195 .height = 320,
Krzysztof Helt69816692007-10-16 01:29:06 -0700196 .pixclock = 260000,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700197 .xres = 240,
198 .yres = 320,
199 .bpp = 16,
Mike Solovyev26be1b72010-05-12 15:38:00 +0400200 .left_margin = 8,
201 .right_margin = 20,
Krzysztof Helt93d11f52007-10-16 01:29:00 -0700202 .hsync_len = 4,
Krzysztof Helt5f20f692007-10-16 01:28:59 -0700203 .upper_margin = 8,
204 .lower_margin = 7,
Krzysztof Helt93d11f52007-10-16 01:29:00 -0700205 .vsync_len = 1,
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700206};
207
208static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700209 .displays = &h1940_lcd,
210 .num_displays = 1,
211 .default_display = 0,
212
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200213 .lpcsel = 0x02,
214 .gpccon = 0xaa940659,
215 .gpccon_mask = 0xffffc0f0,
216 .gpcup = 0x0000ffff,
217 .gpcup_mask = 0xffffffff,
218 .gpdcon = 0xaa84aaa0,
219 .gpdcon_mask = 0xffffffff,
220 .gpdup = 0x0000faff,
221 .gpdup_mask = 0xffffffff,
Arnaud Patardf92273c2005-09-09 13:10:10 -0700222};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200224static int power_supply_init(struct device *dev)
225{
226 return gpio_request(S3C2410_GPF(2), "cable plugged");
227}
228
229static int h1940_is_ac_online(void)
230{
231 return !gpio_get_value(S3C2410_GPF(2));
232}
233
234static void power_supply_exit(struct device *dev)
235{
236 gpio_free(S3C2410_GPF(2));
237}
238
239static char *h1940_supplicants[] = {
240 "main-battery",
241 "backup-battery",
242};
243
244static struct pda_power_pdata power_supply_info = {
245 .init = power_supply_init,
246 .is_ac_online = h1940_is_ac_online,
247 .exit = power_supply_exit,
248 .supplied_to = h1940_supplicants,
249 .num_supplicants = ARRAY_SIZE(h1940_supplicants),
250};
251
252static struct resource power_supply_resources[] = {
253 [0] = {
254 .name = "ac",
255 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE |
256 IORESOURCE_IRQ_HIGHEDGE,
257 .start = IRQ_EINT2,
258 .end = IRQ_EINT2,
259 },
260};
261
262static struct platform_device power_supply = {
263 .name = "pda-power",
264 .id = -1,
265 .dev = {
266 .platform_data =
267 &power_supply_info,
268 },
269 .resource = power_supply_resources,
270 .num_resources = ARRAY_SIZE(power_supply_resources),
271};
272
273static const struct s3c_adc_bat_thresh bat_lut_noac[] = {
274 { .volt = 4070, .cur = 162, .level = 100},
275 { .volt = 4040, .cur = 165, .level = 95},
276 { .volt = 4016, .cur = 164, .level = 90},
277 { .volt = 3996, .cur = 166, .level = 85},
278 { .volt = 3971, .cur = 168, .level = 80},
279 { .volt = 3951, .cur = 168, .level = 75},
280 { .volt = 3931, .cur = 170, .level = 70},
281 { .volt = 3903, .cur = 172, .level = 65},
282 { .volt = 3886, .cur = 172, .level = 60},
283 { .volt = 3858, .cur = 176, .level = 55},
284 { .volt = 3842, .cur = 176, .level = 50},
285 { .volt = 3818, .cur = 176, .level = 45},
286 { .volt = 3789, .cur = 180, .level = 40},
287 { .volt = 3769, .cur = 180, .level = 35},
288 { .volt = 3749, .cur = 184, .level = 30},
289 { .volt = 3732, .cur = 184, .level = 25},
290 { .volt = 3716, .cur = 184, .level = 20},
291 { .volt = 3708, .cur = 184, .level = 15},
292 { .volt = 3716, .cur = 96, .level = 10},
293 { .volt = 3700, .cur = 96, .level = 5},
294 { .volt = 3684, .cur = 96, .level = 0},
295};
296
297static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
298 { .volt = 4130, .cur = 0, .level = 100},
299 { .volt = 3982, .cur = 0, .level = 50},
300 { .volt = 3854, .cur = 0, .level = 10},
301 { .volt = 3841, .cur = 0, .level = 0},
302};
303
304int h1940_bat_init(void)
305{
306 int ret;
307
308 ret = gpio_request(H1940_LATCH_SM803_ENABLE, "h1940-charger-enable");
309 if (ret)
310 return ret;
311 gpio_direction_output(H1940_LATCH_SM803_ENABLE, 0);
312
313 return 0;
314
315}
316
317void h1940_bat_exit(void)
318{
319 gpio_free(H1940_LATCH_SM803_ENABLE);
320}
321
322void h1940_enable_charger(void)
323{
324 gpio_set_value(H1940_LATCH_SM803_ENABLE, 1);
325}
326
327void h1940_disable_charger(void)
328{
329 gpio_set_value(H1940_LATCH_SM803_ENABLE, 0);
330}
331
332static struct s3c_adc_bat_pdata h1940_bat_cfg = {
333 .init = h1940_bat_init,
334 .exit = h1940_bat_exit,
335 .enable_charger = h1940_enable_charger,
336 .disable_charger = h1940_disable_charger,
337 .gpio_charge_finished = S3C2410_GPF(3),
338 .gpio_inverted = 1,
339 .lut_noac = bat_lut_noac,
340 .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
341 .lut_acin = bat_lut_acin,
342 .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin),
343 .volt_channel = 0,
344 .current_channel = 1,
345 .volt_mult = 4056,
346 .current_mult = 1893,
347 .internal_impedance = 200,
348 .backup_volt_channel = 3,
349 /* TODO Check backup volt multiplier */
350 .backup_volt_mult = 4056,
351 .backup_volt_min = 0,
352 .backup_volt_max = 4149288
353};
354
355static struct platform_device h1940_battery = {
356 .name = "s3c-adc-battery",
357 .id = -1,
358 .dev = {
359 .parent = &s3c_device_adc.dev,
360 .platform_data = &h1940_bat_cfg,
361 },
362};
363
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200364DEFINE_SPINLOCK(h1940_blink_spin);
365
366int h1940_led_blink_set(unsigned gpio, int state,
367 unsigned long *delay_on, unsigned long *delay_off)
368{
369 int blink_gpio, check_gpio1, check_gpio2;
370
371 switch (gpio) {
372 case H1940_LATCH_LED_GREEN:
373 blink_gpio = S3C2410_GPA(7);
374 check_gpio1 = S3C2410_GPA(1);
375 check_gpio2 = S3C2410_GPA(3);
376 break;
377 case H1940_LATCH_LED_RED:
378 blink_gpio = S3C2410_GPA(1);
379 check_gpio1 = S3C2410_GPA(7);
380 check_gpio2 = S3C2410_GPA(3);
381 break;
382 default:
383 blink_gpio = S3C2410_GPA(3);
384 check_gpio1 = S3C2410_GPA(1);
385 check_gpio1 = S3C2410_GPA(7);
386 break;
387 }
388
389 if (delay_on && delay_off && !*delay_on && !*delay_off)
390 *delay_on = *delay_off = 500;
391
392 spin_lock(&h1940_blink_spin);
393
394 switch (state) {
395 case GPIO_LED_NO_BLINK_LOW:
396 case GPIO_LED_NO_BLINK_HIGH:
397 if (!gpio_get_value(check_gpio1) &&
398 !gpio_get_value(check_gpio2))
399 gpio_set_value(H1940_LATCH_LED_FLASH, 0);
400 gpio_set_value(blink_gpio, 0);
401 if (gpio_is_valid(gpio))
402 gpio_set_value(gpio, state);
403 break;
404 case GPIO_LED_BLINK:
405 if (gpio_is_valid(gpio))
406 gpio_set_value(gpio, 0);
407 gpio_set_value(H1940_LATCH_LED_FLASH, 1);
408 gpio_set_value(blink_gpio, 1);
409 break;
410 }
411
412 spin_unlock(&h1940_blink_spin);
413
414 return 0;
415}
416EXPORT_SYMBOL(h1940_led_blink_set);
417
418static struct gpio_led h1940_leds_desc[] = {
419 {
420 .name = "Green",
Vasily Khoruzhick9edb2402011-03-17 20:04:57 +0200421 .default_trigger = "main-battery-full",
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200422 .gpio = H1940_LATCH_LED_GREEN,
423 .retain_state_suspended = 1,
424 },
425 {
426 .name = "Red",
Vasily Khoruzhick9edb2402011-03-17 20:04:57 +0200427 .default_trigger
428 = "main-battery-charging-blink-full-solid",
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200429 .gpio = H1940_LATCH_LED_RED,
430 .retain_state_suspended = 1,
431 },
432};
433
434static struct gpio_led_platform_data h1940_leds_pdata = {
435 .num_leds = ARRAY_SIZE(h1940_leds_desc),
436 .leds = h1940_leds_desc,
437 .gpio_blink_set = h1940_led_blink_set,
438};
439
Ben Dooksff34aaa2009-09-28 12:45:47 +0900440static struct platform_device h1940_device_leds = {
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200441 .name = "leds-gpio",
442 .id = -1,
443 .dev = {
444 .platform_data = &h1940_leds_pdata,
445 },
Arnaud Patardd2a76022007-02-13 00:50:34 +0100446};
447
Ben Dooksff34aaa2009-09-28 12:45:47 +0900448static struct platform_device h1940_device_bluetooth = {
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100449 .name = "h1940-bt",
450 .id = -1,
451};
452
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300453static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
454{
455 switch (power_mode) {
456 case MMC_POWER_OFF:
457 gpio_set_value(H1940_LATCH_SD_POWER, 0);
458 break;
459 case MMC_POWER_UP:
460 case MMC_POWER_ON:
461 gpio_set_value(H1940_LATCH_SD_POWER, 1);
462 break;
463 default:
464 break;
465 };
466}
467
Ben Dooks22c810a2010-01-18 16:24:22 +0900468static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +0100469 .gpio_detect = S3C2410_GPF(5),
470 .gpio_wprotect = S3C2410_GPH(8),
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300471 .set_power = h1940_set_mmc_power,
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +0100472 .ocr_avail = MMC_VDD_32_33,
473};
474
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100475static int h1940_backlight_init(struct device *dev)
476{
477 gpio_request(S3C2410_GPB(0), "Backlight");
478
Ben Dooksdb61ac52010-05-04 11:40:51 +0900479 gpio_direction_output(S3C2410_GPB(0), 0);
Ben Dooksfb378742010-05-06 11:03:50 +0900480 s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +0900481 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300482 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100483
484 return 0;
485}
486
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300487static int h1940_backlight_notify(struct device *dev, int brightness)
488{
489 if (!brightness) {
490 gpio_direction_output(S3C2410_GPB(0), 1);
491 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
492 } else {
493 gpio_direction_output(S3C2410_GPB(0), 0);
494 s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
495 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
496 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
497 }
498 return brightness;
499}
500
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100501static void h1940_backlight_exit(struct device *dev)
502{
Ben Dooksdb61ac52010-05-04 11:40:51 +0900503 gpio_direction_output(S3C2410_GPB(0), 1);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300504 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100505}
506
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300507
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100508static struct platform_pwm_backlight_data backlight_data = {
509 .pwm_id = 0,
510 .max_brightness = 100,
511 .dft_brightness = 50,
512 /* tcnt = 0x31 */
513 .pwm_period_ns = 36296,
514 .init = h1940_backlight_init,
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300515 .notify = h1940_backlight_notify,
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100516 .exit = h1940_backlight_exit,
517};
518
519static struct platform_device h1940_backlight = {
520 .name = "pwm-backlight",
521 .dev = {
522 .parent = &s3c_device_timer[0].dev,
523 .platform_data = &backlight_data,
524 },
525 .id = -1,
526};
527
528static void h1940_lcd_power_set(struct plat_lcd_data *pd,
529 unsigned int power)
530{
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200531 int value, retries = 100;
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100532
533 if (!power) {
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300534 gpio_set_value(S3C2410_GPC(0), 0);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100535 /* wait for 3ac */
536 do {
Ben Dooksdb61ac52010-05-04 11:40:51 +0900537 value = gpio_get_value(S3C2410_GPC(6));
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200538 } while (value && retries--);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300539
540 gpio_set_value(H1940_LATCH_LCD_P2, 0);
541 gpio_set_value(H1940_LATCH_LCD_P3, 0);
542 gpio_set_value(H1940_LATCH_LCD_P4, 0);
543
544 gpio_direction_output(S3C2410_GPC(1), 0);
545 gpio_direction_output(S3C2410_GPC(4), 0);
546
547 gpio_set_value(H1940_LATCH_LCD_P1, 0);
548 gpio_set_value(H1940_LATCH_LCD_P0, 0);
549
550 gpio_set_value(S3C2410_GPC(5), 0);
551
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100552 } else {
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300553 gpio_set_value(H1940_LATCH_LCD_P0, 1);
554 gpio_set_value(H1940_LATCH_LCD_P1, 1);
555
Vasily Khoruzhick25d391c2011-01-06 21:52:50 +0200556 gpio_direction_input(S3C2410_GPC(1));
557 gpio_direction_input(S3C2410_GPC(4));
558 mdelay(10);
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300559 s3c_gpio_cfgpin(S3C2410_GPC(1), S3C_GPIO_SFN(2));
560 s3c_gpio_cfgpin(S3C2410_GPC(4), S3C_GPIO_SFN(2));
561
562 gpio_set_value(S3C2410_GPC(5), 1);
563 gpio_set_value(S3C2410_GPC(0), 1);
564
565 gpio_set_value(H1940_LATCH_LCD_P3, 1);
566 gpio_set_value(H1940_LATCH_LCD_P2, 1);
567 gpio_set_value(H1940_LATCH_LCD_P4, 1);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100568 }
569}
570
571static struct plat_lcd_data h1940_lcd_power_data = {
572 .set_power = h1940_lcd_power_set,
573};
574
575static struct platform_device h1940_lcd_powerdev = {
576 .name = "platform-lcd",
577 .dev.parent = &s3c_device_lcd.dev,
578 .dev.platform_data = &h1940_lcd_power_data,
579};
580
Vasily Khoruzhick68730b42010-09-27 09:32:49 +0300581static struct uda1380_platform_data uda1380_info = {
582 .gpio_power = H1940_LATCH_UDA_POWER,
583 .gpio_reset = S3C2410_GPA(12),
584 .dac_clk = UDA1380_DAC_CLK_SYSCLK,
585};
586
587static struct i2c_board_info h1940_i2c_devices[] = {
588 {
589 I2C_BOARD_INFO("uda1380", 0x1a),
590 .platform_data = &uda1380_info,
591 },
592};
593
Arnaud Patard (Rtp)bbb1c832011-01-06 21:52:46 +0200594#define DECLARE_BUTTON(p, k, n, w) \
595 { \
596 .gpio = p, \
597 .code = k, \
598 .desc = n, \
599 .wakeup = w, \
600 .active_low = 1, \
601 }
602
603static struct gpio_keys_button h1940_buttons[] = {
604 DECLARE_BUTTON(S3C2410_GPF(0), KEY_POWER, "Power", 1),
605 DECLARE_BUTTON(S3C2410_GPF(6), KEY_ENTER, "Select", 1),
606 DECLARE_BUTTON(S3C2410_GPF(7), KEY_RECORD, "Record", 0),
607 DECLARE_BUTTON(S3C2410_GPG(0), KEY_F11, "Calendar", 0),
608 DECLARE_BUTTON(S3C2410_GPG(2), KEY_F12, "Contacts", 0),
609 DECLARE_BUTTON(S3C2410_GPG(3), KEY_MAIL, "Mail", 0),
610 DECLARE_BUTTON(S3C2410_GPG(6), KEY_LEFT, "Left_arrow", 0),
611 DECLARE_BUTTON(S3C2410_GPG(7), KEY_HOMEPAGE, "Home", 0),
612 DECLARE_BUTTON(S3C2410_GPG(8), KEY_RIGHT, "Right_arrow", 0),
613 DECLARE_BUTTON(S3C2410_GPG(9), KEY_UP, "Up_arrow", 0),
614 DECLARE_BUTTON(S3C2410_GPG(10), KEY_DOWN, "Down_arrow", 0),
615};
616
617static struct gpio_keys_platform_data h1940_buttons_data = {
618 .buttons = h1940_buttons,
619 .nbuttons = ARRAY_SIZE(h1940_buttons),
620};
621
622static struct platform_device h1940_dev_buttons = {
623 .name = "gpio-keys",
624 .id = -1,
625 .dev = {
626 .platform_data = &h1940_buttons_data,
627 }
628};
629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630static struct platform_device *h1940_devices[] __initdata = {
Arnaud Patard (Rtp)bbb1c832011-01-06 21:52:46 +0200631 &h1940_dev_buttons,
Ben Dooksb8132482009-11-23 00:13:39 +0000632 &s3c_device_ohci,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 &s3c_device_lcd,
634 &s3c_device_wdt,
Ben Dooks3e1b7762008-10-31 16:14:40 +0000635 &s3c_device_i2c0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 &s3c_device_iis,
Jassi Brar83e37b82010-11-22 15:35:53 +0900637 &samsung_asoc_dma,
Arnaud Patard71a9c422007-02-13 00:21:26 +0100638 &s3c_device_usbgadget,
Ben Dooksff34aaa2009-09-28 12:45:47 +0900639 &h1940_device_leds,
640 &h1940_device_bluetooth,
arnaud.patard@rtp-net.org3909b9f2009-11-17 14:54:56 +0100641 &s3c_device_sdi,
arnaud.patard@rtp-net.org13733d52009-11-17 14:54:57 +0100642 &s3c_device_rtc,
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100643 &s3c_device_timer[0],
644 &h1940_backlight,
645 &h1940_lcd_powerdev,
Arnaud Patard17dcd132010-04-22 10:47:43 +0200646 &s3c_device_adc,
647 &s3c_device_ts,
Vasily Khoruzhicka8e99852011-01-06 21:52:49 +0200648 &power_supply,
649 &h1940_battery,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650};
651
Ben Dooks5fe10ab2005-09-20 17:24:33 +0100652static void __init h1940_map_io(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
654 s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
655 s3c24xx_init_clocks(0);
656 s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
Ben Dooks90733412006-12-06 01:50:24 +0100657
658 /* setup PM */
659
Krzysztof Heltb1dfe1f2007-03-19 15:10:20 +0100660#ifdef CONFIG_PM_H1940
Ben Dooks90733412006-12-06 01:50:24 +0100661 memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
Krzysztof Heltb1dfe1f2007-03-19 15:10:20 +0100662#endif
Ben Dooks4e59c252008-12-12 00:24:18 +0000663 s3c_pm_init();
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300664
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300665 /* Add latch gpio chip, set latch initial value */
666 h1940_latch_control(0, 0);
Vasily Khoruzhick14477092010-09-08 12:39:46 +0300667 WARN_ON(gpiochip_add(&h1940_latch_gpiochip));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
Russell King98c672c2010-05-22 18:18:57 +0100670/* H1940 and RX3715 need to reserve this for suspend */
671static void __init h1940_reserve(void)
672{
Russell King8d717a52010-05-22 19:47:18 +0100673 memblock_reserve(0x30003000, 0x1000);
674 memblock_reserve(0x30081000, 0x1000);
Russell King98c672c2010-05-22 18:18:57 +0100675}
676
Ben Dooks5fe10ab2005-09-20 17:24:33 +0100677static void __init h1940_init_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
679 s3c24xx_init_irq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
Ben Dooks5fe10ab2005-09-20 17:24:33 +0100682static void __init h1940_init(void)
Arnaud Patardf92273c2005-09-09 13:10:10 -0700683{
Arnaud Patard71a9c422007-02-13 00:21:26 +0100684 u32 tmp;
685
Krzysztof Helt09fe75f2007-10-16 01:28:56 -0700686 s3c24xx_fb_set_platdata(&h1940_fb_info);
Ben Dooks22c810a2010-01-18 16:24:22 +0900687 s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
Arnaud Patard71a9c422007-02-13 00:21:26 +0100688 s3c24xx_udc_set_platdata(&h1940_udc_cfg);
Arnaud Patardce8877b2009-12-23 19:25:05 +0000689 s3c24xx_ts_set_platdata(&h1940_ts_cfg);
Ben Dooks3e1b7762008-10-31 16:14:40 +0000690 s3c_i2c0_set_platdata(NULL);
Arnaud Patard71a9c422007-02-13 00:21:26 +0100691
692 /* Turn off suspend on both USB ports, and switch the
693 * selectable USB port to USB device mode. */
694
695 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
696 S3C2410_MISCCR_USBSUSPND0 |
697 S3C2410_MISCCR_USBSUSPND1, 0x0);
698
Ben Dookse24b8642008-10-21 14:06:34 +0100699 tmp = (0x78 << S3C24XX_PLLCON_MDIVSHIFT)
700 | (0x02 << S3C24XX_PLLCON_PDIVSHIFT)
701 | (0x03 << S3C24XX_PLLCON_SDIVSHIFT);
Arnaud Patard71a9c422007-02-13 00:21:26 +0100702 writel(tmp, S3C2410_UPLLCON);
Ben Dooks57e51712007-04-20 11:19:16 +0100703
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100704 gpio_request(S3C2410_GPC(0), "LCD power");
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300705 gpio_request(S3C2410_GPC(1), "LCD power");
706 gpio_request(S3C2410_GPC(4), "LCD power");
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100707 gpio_request(S3C2410_GPC(5), "LCD power");
708 gpio_request(S3C2410_GPC(6), "LCD power");
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300709 gpio_request(H1940_LATCH_LCD_P0, "LCD power");
710 gpio_request(H1940_LATCH_LCD_P1, "LCD power");
711 gpio_request(H1940_LATCH_LCD_P2, "LCD power");
712 gpio_request(H1940_LATCH_LCD_P3, "LCD power");
713 gpio_request(H1940_LATCH_LCD_P4, "LCD power");
714 gpio_request(H1940_LATCH_MAX1698_nSHUTDOWN, "LCD power");
715 gpio_direction_output(S3C2410_GPC(0), 0);
716 gpio_direction_output(S3C2410_GPC(1), 0);
717 gpio_direction_output(S3C2410_GPC(4), 0);
718 gpio_direction_output(S3C2410_GPC(5), 0);
Ben Dooksdb61ac52010-05-04 11:40:51 +0900719 gpio_direction_input(S3C2410_GPC(6));
Vasily Khoruzhick53193dd2010-09-27 09:28:00 +0300720 gpio_direction_output(H1940_LATCH_LCD_P0, 0);
721 gpio_direction_output(H1940_LATCH_LCD_P1, 0);
722 gpio_direction_output(H1940_LATCH_LCD_P2, 0);
723 gpio_direction_output(H1940_LATCH_LCD_P3, 0);
724 gpio_direction_output(H1940_LATCH_LCD_P4, 0);
725 gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
arnaud.patard@rtp-net.org22e649f2009-11-17 14:54:58 +0100726
Vasily Khoruzhick48cd65a2010-09-27 00:27:41 +0300727 gpio_request(H1940_LATCH_SD_POWER, "SD power");
728 gpio_direction_output(H1940_LATCH_SD_POWER, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
Vasily Khoruzhick68730b42010-09-27 09:32:49 +0300731
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +0200732 gpio_request(S3C2410_GPA(1), "Red LED blink");
733 gpio_request(S3C2410_GPA(3), "Blue LED blink");
734 gpio_request(S3C2410_GPA(7), "Green LED blink");
735 gpio_request(H1940_LATCH_LED_FLASH, "LED blink");
736 gpio_direction_output(S3C2410_GPA(1), 0);
737 gpio_direction_output(S3C2410_GPA(3), 0);
738 gpio_direction_output(S3C2410_GPA(7), 0);
739 gpio_direction_output(H1940_LATCH_LED_FLASH, 0);
740
Vasily Khoruzhick68730b42010-09-27 09:32:49 +0300741 i2c_register_board_info(0, h1940_i2c_devices,
742 ARRAY_SIZE(h1940_i2c_devices));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743}
744
745MACHINE_START(H1940, "IPAQ-H1940")
Ben Dooksafdd2252010-05-07 09:24:05 +0900746 /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 .boot_params = S3C2410_SDRAM_PA + 0x100,
748 .map_io = h1940_map_io,
Russell King98c672c2010-05-22 18:18:57 +0100749 .reserve = h1940_reserve,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .init_irq = h1940_init_irq,
751 .init_machine = h1940_init,
752 .timer = &s3c24xx_timer,
753MACHINE_END