goldfish: R.I.P.
[openwrt/svn-archive/archive.git] / target / linux / s3c24xx / files-2.6.30 / arch / arm / mach-s3c2442 / mach-gta02.c
1 /*
2 * linux/arch/arm/mach-s3c2442/mach-gta02.c
3 *
4 * S3C2442 Machine Support for the Openmoko Freerunner (GTA02)
5 *
6 * Copyright (C) 2006-2007 by Openmoko, Inc.
7 * Author: Harald Welte <laforge@openmoko.org>
8 * All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 *
25 */
26
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/interrupt.h>
30 #include <linux/list.h>
31 #include <linux/delay.h>
32 #include <linux/timer.h>
33 #include <linux/init.h>
34 #include <linux/workqueue.h>
35 #include <linux/platform_device.h>
36 #include <linux/serial_core.h>
37 #include <linux/spi/spi.h>
38 #include <linux/spi/spi_gpio.h>
39 #include <linux/spi/spi_bitbang.h>
40 #include <linux/mmc/host.h>
41 #include <linux/leds.h>
42 #include <linux/gpio_keys.h>
43
44 #include <linux/mtd/mtd.h>
45 #include <linux/mtd/nand.h>
46 #include <linux/mtd/nand_ecc.h>
47 #include <linux/mtd/partitions.h>
48 #include <linux/mtd/physmap.h>
49
50 #include <linux/i2c.h>
51 #include <linux/backlight.h>
52 #include <linux/regulator/machine.h>
53
54 #include <linux/mfd/pcf50633/core.h>
55 #include <linux/mfd/pcf50633/mbc.h>
56 #include <linux/mfd/pcf50633/adc.h>
57 #include <linux/mfd/pcf50633/gpio.h>
58 #include <linux/mfd/pcf50633/pmic.h>
59
60 #include <linux/lis302dl.h>
61
62 #include <asm/mach/arch.h>
63 #include <asm/mach/map.h>
64 #include <asm/mach/irq.h>
65
66 #include <mach/hardware.h>
67 #include <mach/io.h>
68 #include <asm/irq.h>
69 #include <asm/mach-types.h>
70
71 #include <mach/regs-irq.h>
72 #include <mach/regs-gpio.h>
73 #include <mach/regs-gpioj.h>
74 #include <mach/fb.h>
75 #include <mach/mci.h>
76 #include <mach/ts.h>
77 #include <mach/spi.h>
78 #include <mach/spi-gpio.h>
79 #include <mach/regs-mem.h>
80 #include <plat/pwm.h>
81 #include <mach/cpu.h>
82
83 #include <mach/gta02.h>
84
85 #include <plat/regs-serial.h>
86 #include <plat/nand.h>
87 #include <plat/devs.h>
88 #include <plat/cpu.h>
89 #include <plat/pm.h>
90 #include <plat/udc.h>
91 #include <plat/iic.h>
92 #include <plat/usb-control.h>
93 #include <plat/regs-timer.h>
94 #include <plat/gpio-core.h>
95
96 #include <mach/gta02-pm-gsm.h>
97 #include <mach/gta02-pm-gps.h>
98 #include <mach/gta02-pm-wlan.h>
99
100 #include <linux/jbt6k74.h>
101 #include <linux/glamofb.h>
102 #include <linux/mfd/glamo.h>
103
104 #include <linux/hdq.h>
105 #include <linux/bq27000_battery.h>
106
107 #include <linux/touchscreen/ts_filter_chain.h>
108 #ifdef CONFIG_TOUCHSCREEN_FILTER
109 #include <linux/touchscreen/ts_filter_linear.h>
110 #include <linux/touchscreen/ts_filter_mean.h>
111 #include <linux/touchscreen/ts_filter_median.h>
112 #include <linux/touchscreen/ts_filter_group.h>
113 #endif
114
115 #include <asm/fiq.h>
116
117 #include <linux/gta02-vibrator.h>
118
119 /* arbitrates which sensor IRQ owns the shared SPI bus */
120 static spinlock_t motion_irq_lock;
121
122
123 /* -------------------------------------------------------------------------------
124 * GTA02 FIQ related
125 *
126 * Calls into vibrator and hdq and based on the return values
127 * determines if we the FIQ source be kept alive
128 */
129
130 #define DIVISOR_FROM_US(x) ((x) << 3)
131
132 #ifdef CONFIG_HDQ_GPIO_BITBANG
133 #define FIQ_DIVISOR_HDQ DIVISOR_FROM_US(HDQ_SAMPLE_PERIOD_US)
134 extern int hdq_fiq_handler(void);
135 #endif
136
137 #ifdef CONFIG_LEDS_GTA02_VIBRATOR
138 #define FIQ_DIVISOR_VIBRATOR DIVISOR_FROM_US(100)
139 extern int gta02_vibrator_fiq_handler(void);
140 #endif
141
142 #if defined(CONFIG_LEDS_GTA02_VIBRATOR) || defined(CONFIG_HDQ_GPIO_BITBANG)
143
144 /* Global data related to our fiq source */
145 static u32 gta02_fiq_ack_mask;
146 static struct s3c2410_pwm gta02_fiq_pwm_timer;
147 static u16 gta02_fiq_timer_index;
148 static int gta02_fiq_irq;
149
150 static void gta02_fiq_handler(void)
151 {
152 u16 divisor = 0xffff;
153
154 /* Vibrator servicing */
155
156 /* disable further timer interrupts if nobody has any work
157 * or adjust rate according to who still has work
158 *
159 * CAUTION: it means forground code must disable FIQ around
160 * its own non-atomic S3C2410_INTMSK changes... not common
161 * thankfully and taken care of by the fiq-basis patch
162 */
163
164 #ifdef CONFIG_LEDS_GTA02_VIBRATOR
165 if (gta02_vibrator_fiq_handler())
166 divisor = FIQ_DIVISOR_VIBRATOR;
167 #endif
168
169 #ifdef CONFIG_HDQ_GPIO_BITBANG
170 if (hdq_fiq_handler())
171 divisor = FIQ_DIVISOR_HDQ;
172 #endif
173
174 if (divisor == 0xffff) /* mask the fiq irq source */
175 __raw_writel(__raw_readl(S3C2410_INTMSK) | gta02_fiq_ack_mask,
176 S3C2410_INTMSK);
177 else /* still working, maybe at a different rate */
178 __raw_writel(divisor, S3C2410_TCNTB(gta02_fiq_timer_index));
179
180 __raw_writel(gta02_fiq_ack_mask, S3C2410_SRCPND);
181 }
182
183 static void gta02_fiq_kick(void)
184 {
185 unsigned long flags;
186 u32 tcon;
187
188 /* we have to take care about FIQ because this modification is
189 * non-atomic, FIQ could come in after the read and before the
190 * writeback and its changes to the register would be lost
191 * (platform INTMSK mod code is taken care of already)
192 */
193 local_save_flags(flags);
194 local_fiq_disable();
195 /* allow FIQs to resume */
196 __raw_writel(__raw_readl(S3C2410_INTMSK) &
197 ~(1 << (gta02_fiq_irq - S3C2410_CPUIRQ_OFFSET)),
198 S3C2410_INTMSK);
199 tcon = __raw_readl(S3C2410_TCON) & ~S3C2410_TCON_T3START;
200 /* fake the timer to a count of 1 */
201 __raw_writel(1, S3C2410_TCNTB(gta02_fiq_timer_index));
202 __raw_writel(tcon | S3C2410_TCON_T3MANUALUPD, S3C2410_TCON);
203 __raw_writel(tcon | S3C2410_TCON_T3MANUALUPD | S3C2410_TCON_T3START,
204 S3C2410_TCON);
205 __raw_writel(tcon | S3C2410_TCON_T3START, S3C2410_TCON);
206 local_irq_restore(flags);
207 }
208
209 static int gta02_fiq_enable(void)
210 {
211 int irq_index_fiq = IRQ_TIMER3;
212 int rc = 0;
213
214 local_fiq_disable();
215
216 gta02_fiq_irq = irq_index_fiq;
217 gta02_fiq_ack_mask = 1 << (irq_index_fiq - S3C2410_CPUIRQ_OFFSET);
218 gta02_fiq_timer_index = (irq_index_fiq - IRQ_TIMER0);
219
220 /* set up the timer to operate as a pwm device */
221
222 rc = s3c2410_pwm_init(&gta02_fiq_pwm_timer);
223 if (rc)
224 goto bail;
225
226 gta02_fiq_pwm_timer.timerid = PWM0 + gta02_fiq_timer_index;
227 gta02_fiq_pwm_timer.prescaler = (6 - 1) / 2;
228 gta02_fiq_pwm_timer.divider = S3C2410_TCFG1_MUX3_DIV2;
229 /* default rate == ~32us */
230 gta02_fiq_pwm_timer.counter = gta02_fiq_pwm_timer.comparer = 3000;
231
232 rc = s3c2410_pwm_enable(&gta02_fiq_pwm_timer);
233 if (rc)
234 goto bail;
235
236 s3c2410_pwm_start(&gta02_fiq_pwm_timer);
237
238 /* let our selected interrupt be a magic FIQ interrupt */
239 __raw_writel(gta02_fiq_ack_mask, S3C2410_INTMOD);
240
241 /* it's ready to go as soon as we unmask the source in S3C2410_INTMSK */
242 local_fiq_enable();
243
244 set_fiq_c_handler(gta02_fiq_handler);
245
246 return 0;
247
248 bail:
249 printk(KERN_ERR "Could not initialize FIQ for GTA02: %d\n", rc);
250
251 return rc;
252 }
253
254 static void gta02_fiq_disable(void)
255 {
256 __raw_writel(0, S3C2410_INTMOD);
257 local_fiq_disable();
258 gta02_fiq_irq = 0; /* no active source interrupt now either */
259
260 }
261 /* -------------------- /GTA02 FIQ Handler ------------------------------------- */
262
263 #endif
264
265 /*
266 * this gets called every 1ms when we paniced.
267 */
268
269 static long gta02_panic_blink(long count)
270 {
271 long delay = 0;
272 static long last_blink;
273 static char led;
274
275 if (count - last_blink < 100) /* 200ms period, fast blink */
276 return 0;
277
278 led ^= 1;
279 s3c2410_gpio_cfgpin(GTA02_GPIO_AUX_LED, S3C2410_GPIO_OUTPUT);
280 s3c2410_gpio_setpin(GTA02_GPIO_AUX_LED, led);
281
282 last_blink = count;
283 return delay;
284 }
285
286
287 /**
288 * returns PCB revision information in b9,b8 and b2,b1,b0
289 * Pre-GTA02 A6 returns 0x000
290 * GTA02 A6 returns 0x101
291 * ...
292 */
293
294 int gta02_get_pcb_revision(void)
295 {
296 int n;
297 int u = 0;
298 static unsigned long pinlist[] = {
299 GTA02_PCB_ID1_0,
300 GTA02_PCB_ID1_1,
301 GTA02_PCB_ID1_2,
302 GTA02_PCB_ID2_0,
303 GTA02_PCB_ID2_1,
304 };
305 static int pin_offset[] = {
306 0, 1, 2, 8, 9
307 };
308
309 for (n = 0 ; n < ARRAY_SIZE(pinlist); n++) {
310 /*
311 * set the PCB version GPIO to be pulled-down input
312 * force low briefly first
313 */
314 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_OUTPUT);
315 s3c2410_gpio_setpin(pinlist[n], 0);
316 /* misnomer: it is a pullDOWN in 2442 */
317 s3c2410_gpio_pullup(pinlist[n], 1);
318 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_INPUT);
319
320 udelay(10);
321
322 if (s3c2410_gpio_getpin(pinlist[n]))
323 u |= 1 << pin_offset[n];
324
325 /*
326 * when not being interrogated, all of the revision GPIO
327 * are set to output HIGH without pulldown so no current flows
328 * if they are NC or pulled up.
329 */
330 s3c2410_gpio_setpin(pinlist[n], 1);
331 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_OUTPUT);
332 /* misnomer: it is a pullDOWN in 2442 */
333 s3c2410_gpio_pullup(pinlist[n], 0);
334 }
335
336 return u;
337 }
338
339 struct platform_device gta02_resume_reason_device = {
340 .name = "gta02-resume",
341 .num_resources = 0,
342 };
343
344 static struct map_desc gta02_iodesc[] __initdata = {
345 {
346 .virtual = 0xe0000000,
347 .pfn = __phys_to_pfn(S3C2410_CS3+0x01000000),
348 .length = SZ_1M,
349 .type = MT_DEVICE
350 },
351 };
352
353 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
354 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
355 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
356
357 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
358 [0] = {
359 .hwport = 0,
360 .flags = 0,
361 .ucon = UCON,
362 .ulcon = ULCON,
363 .ufcon = UFCON,
364 },
365 [1] = {
366 .hwport = 1,
367 .flags = 0,
368 .ucon = UCON,
369 .ulcon = ULCON,
370 .ufcon = UFCON,
371 },
372 [2] = {
373 .hwport = 2,
374 .flags = 0,
375 .ucon = UCON,
376 .ulcon = ULCON,
377 .ufcon = UFCON,
378 },
379
380 };
381
382 struct pcf50633 *gta02_pcf;
383
384 #ifdef CONFIG_CHARGER_PCF50633
385 #ifdef CONFIG_HDQ_GPIO_BITBANG
386 static int gta02_get_charger_online_status(void)
387 {
388 struct pcf50633 *pcf = gta02_pcf;
389
390 return pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ONLINE;
391 }
392
393 static int gta02_get_charger_active_status(void)
394 {
395 struct pcf50633 *pcf = gta02_pcf;
396
397 return pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ACTIVE;
398 }
399 #endif
400
401 #define ADC_NOM_CHG_DETECT_1A 6
402 #define ADC_NOM_CHG_DETECT_USB 43
403
404 static void
405 gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
406 {
407 int ma;
408
409 /* Interpret charger type */
410 if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
411
412 /* Stop GPO driving out now that we have a IA charger */
413 pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
414
415 ma = 1000;
416 } else
417 ma = 100;
418
419 pcf50633_mbc_usb_curlim_set(pcf, ma);
420 }
421
422 static struct delayed_work gta02_charger_work;
423 static int gta02_usb_vbus_draw;
424
425 static void gta02_charger_worker(struct work_struct *work)
426 {
427 struct pcf50633 *pcf = gta02_pcf;
428
429 if (gta02_usb_vbus_draw) {
430 pcf50633_mbc_usb_curlim_set(pcf, gta02_usb_vbus_draw);
431 return;
432 } else {
433 #ifdef CONFIG_PCF50633_ADC
434 pcf50633_adc_async_read(pcf,
435 PCF50633_ADCC1_MUX_ADCIN1,
436 PCF50633_ADCC1_AVERAGE_16,
437 gta02_configure_pmu_for_charger, NULL);
438 #else
439 /* If the PCF50633 ADC is disabled we fallback to a 100mA limit for safety. */
440 pcf50633_mbc_usb_curlim_set(pcf, 100);
441 #endif
442 return;
443 }
444 }
445
446 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
447 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
448 {
449 if (irq == PCF50633_IRQ_USBINS) {
450 schedule_delayed_work(&gta02_charger_work,
451 GTA02_CHARGER_CONFIGURE_TIMEOUT);
452 return;
453 } else if (irq == PCF50633_IRQ_USBREM) {
454 cancel_delayed_work_sync(&gta02_charger_work);
455 gta02_usb_vbus_draw = 0;
456 }
457 }
458
459 static void gta02_pmu_force_shutdown(struct pcf50633 *pcf)
460 {
461 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_OOCSHDWN,
462 PCF50633_OOCSHDWN_GOSTDBY, PCF50633_OOCSHDWN_GOSTDBY);
463 }
464
465
466 static void gta02_udc_vbus_draw(unsigned int ma)
467 {
468 if (!gta02_pcf)
469 return;
470
471 gta02_usb_vbus_draw = ma;
472
473 schedule_delayed_work(&gta02_charger_work,
474 GTA02_CHARGER_CONFIGURE_TIMEOUT);
475 }
476
477 static int gta02_udc_vbus_status(void)
478 {
479 struct pcf50633 *pcf = gta02_pcf;
480 if (!gta02_pcf)
481 return -ENODEV;
482
483 return !!(pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ONLINE);
484 }
485
486 #else /* !CONFIG_CHARGER_PCF50633 */
487 #ifdef CONFIG_HDQ_GPIO_BITBANG
488 #define gta02_get_charger_online_status NULL
489 #define gta02_get_charger_active_status NULL
490 #endif
491 #define gta02_pmu_event_callback NULL
492 #define gta02_udc_vbus_draw NULL
493 #define gta02_udc_vbus_status NULL
494 #endif
495
496
497 static struct platform_device gta02_pm_gps_dev = {
498 .name = "gta02-pm-gps",
499 };
500
501 static struct platform_device gta02_pm_bt_dev = {
502 .name = "gta02-pm-bt",
503 };
504
505 static struct platform_device gta02_pm_gsm_dev = {
506 .name = "gta02-pm-gsm",
507 };
508
509 static struct platform_device gta02_pm_wlan_dev = {
510 .name = "gta02-pm-wlan",
511 };
512
513 /* this is called when pc50633 is probed, unfortunately quite late in the
514 * day since it is an I2C bus device. Here we can belatedly define some
515 * platform devices with the advantage that we can mark the pcf50633 as the
516 * parent. This makes them get suspended and resumed with their parent
517 * the pcf50633 still around.
518 */
519
520 static struct platform_device gta02_glamo_dev;
521 static void mangle_glamo_res_by_system_rev(void);
522
523 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf);
524 static void gta02_pmu_regulator_registered(struct pcf50633 *pcf, int id);
525
526 static struct regulator_consumer_supply ldo4_consumers[] = {
527 {
528 .dev = &gta02_pm_bt_dev.dev,
529 .supply = "BT_3V2",
530 },
531 };
532
533 static struct regulator_consumer_supply ldo5_consumers[] = {
534 {
535 .dev = &gta02_pm_gps_dev.dev,
536 .supply = "RF_3V",
537 },
538 };
539
540 static struct regulator_consumer_supply hcldo_consumers[] = {
541 {
542 .dev = &gta02_glamo_dev.dev,
543 .supply = "SD_3V3",
544 },
545 };
546
547 static char *gta02_batteries[] = {
548 "battery",
549 };
550
551 #ifdef CONFIG_CHARGER_PCF50633
552
553 struct pcf50633_platform_data gta02_pcf_pdata = {
554 .resumers = {
555 [0] = PCF50633_INT1_USBINS |
556 PCF50633_INT1_USBREM |
557 PCF50633_INT1_ALARM,
558 [1] = PCF50633_INT2_ONKEYF,
559 [2] = PCF50633_INT3_ONKEY1S,
560 [3] = PCF50633_INT4_LOWSYS |
561 PCF50633_INT4_LOWBAT |
562 PCF50633_INT4_HIGHTMP,
563 },
564
565 .batteries = gta02_batteries,
566 .num_batteries = ARRAY_SIZE(gta02_batteries),
567 .charging_restart_interval = (900 * HZ),
568 .chg_ref_current_ma = 1000,
569
570 .reg_init_data = {
571 [PCF50633_REGULATOR_AUTO] = {
572 .constraints = {
573 .name = "IO_3V3",
574 .min_uV = 3300000,
575 .max_uV = 3300000,
576 .valid_modes_mask = REGULATOR_MODE_NORMAL,
577 .boot_on = 1,
578 .always_on = 1,
579 .apply_uV = 1,
580 .state_mem = {
581 .enabled = 1,
582 },
583 },
584 .num_consumer_supplies = 0,
585 },
586 [PCF50633_REGULATOR_DOWN1] = {
587 .constraints = {
588 .name = "CORE_1V3",
589 .min_uV = 1300000,
590 .max_uV = 1600000,
591 .valid_modes_mask = REGULATOR_MODE_NORMAL,
592 .boot_on = 1,
593 .always_on = 1,
594 .apply_uV = 1,
595 },
596 .num_consumer_supplies = 0,
597 },
598 [PCF50633_REGULATOR_DOWN2] = {
599 .constraints = {
600 .name = "IO_1V8",
601 .min_uV = 1800000,
602 .max_uV = 1800000,
603 .valid_modes_mask = REGULATOR_MODE_NORMAL,
604 .apply_uV = 1,
605 .boot_on = 1,
606 .always_on = 1,
607 .state_mem = {
608 .enabled = 1,
609 },
610 },
611 .num_consumer_supplies = 0,
612 },
613 [PCF50633_REGULATOR_HCLDO] = {
614 .constraints = {
615 .name = "SD_3V3",
616 .min_uV = 2000000,
617 .max_uV = 3300000,
618 .valid_modes_mask = REGULATOR_MODE_NORMAL,
619 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
620 .boot_on = 1,
621 },
622 .num_consumer_supplies = 1,
623 .consumer_supplies = hcldo_consumers,
624 },
625 [PCF50633_REGULATOR_LDO1] = {
626 .constraints = {
627 .name = "GSENSOR_3V3",
628 .min_uV = 3300000,
629 .max_uV = 3300000,
630 .valid_modes_mask = REGULATOR_MODE_NORMAL,
631 .apply_uV = 1,
632 },
633 .num_consumer_supplies = 0,
634 },
635 [PCF50633_REGULATOR_LDO2] = {
636 .constraints = {
637 .name = "CODEC_3V3",
638 .min_uV = 3300000,
639 .max_uV = 3300000,
640 .valid_modes_mask = REGULATOR_MODE_NORMAL,
641 .apply_uV = 1,
642 },
643 .num_consumer_supplies = 0,
644 },
645 [PCF50633_REGULATOR_LDO3] = {
646 .constraints = {
647 .min_uV = 3000000,
648 .max_uV = 3000000,
649 .valid_modes_mask = REGULATOR_MODE_NORMAL,
650 .apply_uV = 1,
651 },
652 .num_consumer_supplies = 0,
653 },
654 [PCF50633_REGULATOR_LDO4] = {
655 .constraints = {
656 .name = "BT_3V2",
657 .min_uV = 3200000,
658 .max_uV = 3200000,
659 .valid_modes_mask = REGULATOR_MODE_NORMAL,
660 .apply_uV = 1,
661 },
662 .num_consumer_supplies = 1,
663 .consumer_supplies = ldo4_consumers,
664 },
665 [PCF50633_REGULATOR_LDO5] = {
666 .constraints = {
667 .name = "RF_3V",
668 .min_uV = 3000000,
669 .max_uV = 3000000,
670 .valid_modes_mask = REGULATOR_MODE_NORMAL,
671 .apply_uV = 1,
672 .state_mem = {
673 .enabled = 1,
674 },
675 },
676 .num_consumer_supplies = 1,
677 .consumer_supplies = ldo5_consumers,
678 },
679 [PCF50633_REGULATOR_LDO6] = {
680 .constraints = {
681 .name = "LCM_3V",
682 .min_uV = 3000000,
683 .max_uV = 3000000,
684 .always_on = 1,
685 .valid_modes_mask = REGULATOR_MODE_NORMAL,
686 .apply_uV = 1,
687 },
688 .num_consumer_supplies = 0,
689 },
690 [PCF50633_REGULATOR_MEMLDO] = {
691 .constraints = {
692 .min_uV = 1800000,
693 .max_uV = 1800000,
694 .valid_modes_mask = REGULATOR_MODE_NORMAL,
695 .state_mem = {
696 .enabled = 1,
697 },
698 },
699 .num_consumer_supplies = 0,
700 },
701
702 },
703 .probe_done = gta02_pmu_attach_child_devices,
704 .regulator_registered = gta02_pmu_regulator_registered,
705 .mbc_event_callback = gta02_pmu_event_callback,
706 .force_shutdown = gta02_pmu_force_shutdown,
707 };
708
709 static void mangle_pmu_pdata_by_system_rev(void)
710 {
711 struct regulator_init_data *reg_init_data;
712
713 reg_init_data = gta02_pcf_pdata.reg_init_data;
714
715 switch (S3C_SYSTEM_REV_ATAG) {
716 case GTA02v1_SYSTEM_REV:
717 /* FIXME: this is only in v1 due to wrong PMU variant */
718 reg_init_data[PCF50633_REGULATOR_DOWN2]
719 .constraints.state_mem.enabled = 1;
720
721 reg_init_data[PCF50633_REGULATOR_LDO1]
722 .constraints.min_uV = 1300000;
723 reg_init_data[PCF50633_REGULATOR_LDO1]
724 .constraints.max_uV = 1300000;
725
726 reg_init_data[PCF50633_REGULATOR_LDO5]
727 .constraints.min_uV = 1500000;
728 reg_init_data[PCF50633_REGULATOR_LDO5]
729 .constraints.max_uV = 1500000;
730
731 reg_init_data[PCF50633_REGULATOR_LDO6]
732 .constraints.min_uV = 0;
733 reg_init_data[PCF50633_REGULATOR_LDO6]
734 .constraints.max_uV = 3300000;
735 reg_init_data[PCF50633_REGULATOR_LDO6]
736 .constraints.apply_uV = 1;
737 break;
738 default:
739 break;
740 }
741 }
742
743 #endif
744
745 #ifdef CONFIG_HDQ_GPIO_BITBANG
746 /* BQ27000 Battery */
747
748 struct bq27000_platform_data bq27000_pdata = {
749 .name = "battery",
750 .rsense_mohms = 20,
751 .hdq_read = hdq_read,
752 .hdq_write = hdq_write,
753 .hdq_initialized = hdq_initialized,
754 .get_charger_online_status = gta02_get_charger_online_status,
755 .get_charger_active_status = gta02_get_charger_active_status
756 };
757
758 struct platform_device bq27000_battery_device = {
759 .name = "bq27000-battery",
760 .dev = {
761 .platform_data = &bq27000_pdata,
762 },
763 };
764
765 /* HDQ */
766
767 static void gta02_hdq_attach_child_devices(struct device *parent_device)
768 {
769 switch (S3C_SYSTEM_REV_ATAG) {
770 case GTA02v5_SYSTEM_REV:
771 case GTA02v6_SYSTEM_REV:
772 bq27000_battery_device.dev.parent = parent_device;
773 platform_device_register(&bq27000_battery_device);
774 break;
775 default:
776 break;
777 }
778 }
779
780 static void gta02_hdq_gpio_direction_out(void)
781 {
782 s3c2410_gpio_cfgpin(GTA02v5_GPIO_HDQ, S3C2410_GPIO_OUTPUT);
783 }
784
785 static void gta02_hdq_gpio_direction_in(void)
786 {
787 s3c2410_gpio_cfgpin(GTA02v5_GPIO_HDQ, S3C2410_GPIO_INPUT);
788 }
789
790 static void gta02_hdq_gpio_set_value(int val)
791 {
792
793 s3c2410_gpio_setpin(GTA02v5_GPIO_HDQ, val);
794 }
795
796 static int gta02_hdq_gpio_get_value(void)
797 {
798 return s3c2410_gpio_getpin(GTA02v5_GPIO_HDQ);
799 }
800
801 static struct resource gta02_hdq_resources[] = {
802 [0] = {
803 .start = GTA02v5_GPIO_HDQ,
804 .end = GTA02v5_GPIO_HDQ,
805 },
806 };
807
808 struct hdq_platform_data gta02_hdq_platform_data = {
809 .attach_child_devices = gta02_hdq_attach_child_devices,
810 .gpio_dir_out = gta02_hdq_gpio_direction_out,
811 .gpio_dir_in = gta02_hdq_gpio_direction_in,
812 .gpio_set = gta02_hdq_gpio_set_value,
813 .gpio_get = gta02_hdq_gpio_get_value,
814
815 .enable_fiq = gta02_fiq_enable,
816 .disable_fiq = gta02_fiq_disable,
817 .kick_fiq = gta02_fiq_kick,
818
819 };
820
821 struct platform_device gta02_hdq_device = {
822 .name = "hdq",
823 .num_resources = 1,
824 .resource = gta02_hdq_resources,
825 .dev = {
826 .platform_data = &gta02_hdq_platform_data,
827 },
828 };
829 #endif
830
831
832 #ifdef CONFIG_LEDS_GTA02_VIBRATOR
833 /* vibrator (child of FIQ) */
834
835 static struct resource gta02_vibrator_resources[] = {
836 [0] = {
837 .start = GTA02_GPIO_VIBRATOR_ON,
838 .end = GTA02_GPIO_VIBRATOR_ON,
839 },
840 };
841 struct gta02_vib_platform_data gta02_vib_pdata = {
842 .enable_fiq = gta02_fiq_enable,
843 .disable_fiq = gta02_fiq_disable,
844 .kick_fiq = gta02_fiq_kick,
845 };
846
847 static struct platform_device gta02_vibrator_dev = {
848 .name = "gta02-vibrator",
849 .num_resources = ARRAY_SIZE(gta02_vibrator_resources),
850 .resource = gta02_vibrator_resources,
851 .dev = {
852 .platform_data = &gta02_vib_pdata,
853 },
854 };
855 #endif
856
857 /* NOR Flash */
858
859 #define GTA02_FLASH_BASE S3C2410_CS3 /* GCS3 */
860 #define GTA02_FLASH_SIZE 0x200000 /* 2MBytes */
861
862 static struct physmap_flash_data gta02_nor_flash_data = {
863 .width = 2,
864 };
865
866 static struct resource gta02_nor_flash_resource = {
867 .start = GTA02_FLASH_BASE,
868 .end = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
869 .flags = IORESOURCE_MEM,
870 };
871
872 static struct platform_device gta02_nor_flash = {
873 .name = "physmap-flash",
874 .id = 0,
875 .dev = {
876 .platform_data = &gta02_nor_flash_data,
877 },
878 .resource = &gta02_nor_flash_resource,
879 .num_resources = 1,
880 };
881
882
883 struct platform_device s3c24xx_pwm_device = {
884 .name = "s3c24xx_pwm",
885 .num_resources = 0,
886 };
887
888 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
889 {
890 I2C_BOARD_INFO("pcf50633", 0x73),
891 .irq = GTA02_IRQ_PCF50633,
892 .platform_data = &gta02_pcf_pdata,
893 },
894 {
895 I2C_BOARD_INFO("wm8753", 0x1a),
896 },
897 };
898
899 static struct s3c2410_nand_set gta02_nand_sets[] = {
900 [0] = {
901 .name = "neo1973-nand",
902 .nr_chips = 1,
903 .flags = S3C2410_NAND_BBT,
904 },
905 };
906
907 /* choose a set of timings derived from S3C@2442B MCP54
908 * data sheet (K5D2G13ACM-D075 MCP Memory)
909 */
910
911 static struct s3c2410_platform_nand gta02_nand_info = {
912 .tacls = 0,
913 .twrph0 = 25,
914 .twrph1 = 15,
915 .nr_sets = ARRAY_SIZE(gta02_nand_sets),
916 .sets = gta02_nand_sets,
917 .software_ecc = 1,
918 };
919
920
921 static void gta02_s3c_mmc_set_power(unsigned char power_mode,
922 unsigned short vdd)
923 {
924 static int is_on = -1;
925 int on;
926
927 on = power_mode == MMC_POWER_ON || power_mode == MMC_POWER_UP;
928 if (is_on != on)
929 gta02_wlan_reset(!on);
930 is_on = on;
931 }
932
933
934 static struct s3c24xx_mci_pdata gta02_s3c_mmc_cfg = {
935 .set_power = gta02_s3c_mmc_set_power,
936 };
937
938 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
939 {
940 switch (cmd) {
941 case S3C2410_UDC_P_ENABLE:
942 printk(KERN_DEBUG "%s S3C2410_UDC_P_ENABLE\n", __func__);
943 s3c2410_gpio_setpin(GTA02_GPIO_USB_PULLUP, 1);
944 break;
945 case S3C2410_UDC_P_DISABLE:
946 printk(KERN_DEBUG "%s S3C2410_UDC_P_DISABLE\n", __func__);
947 s3c2410_gpio_setpin(GTA02_GPIO_USB_PULLUP, 0);
948 break;
949 case S3C2410_UDC_P_RESET:
950 printk(KERN_DEBUG "%s S3C2410_UDC_P_RESET\n", __func__);
951 /* FIXME! */
952 break;
953 default:
954 break;
955 }
956 }
957
958 /* get PMU to set USB current limit accordingly */
959
960 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
961 .vbus_draw = gta02_udc_vbus_draw,
962 .udc_command = gta02_udc_command,
963 /* .get_vbus_status = gta02_udc_vbus_status,*/
964 };
965
966
967 /* Touchscreen configuration. */
968
969 #ifdef CONFIG_TOUCHSCREEN_FILTER
970 const static struct ts_filter_group_configuration gta02_ts_group = {
971 .length = 12,
972 .close_enough = 10,
973 .threshold = 6, /* At least half of the points in a group. */
974 .attempts = 10,
975 };
976
977 const static struct ts_filter_median_configuration gta02_ts_median = {
978 .extent = 20,
979 .decimation_below = 3,
980 .decimation_threshold = 8 * 3,
981 .decimation_above = 4,
982 };
983
984 const static struct ts_filter_mean_configuration gta02_ts_mean = {
985 .length = 4,
986 };
987
988 const static struct ts_filter_linear_configuration gta02_ts_linear = {
989 .constants = {1, 0, 0, 0, 1, 0, 1}, /* Don't modify coords. */
990 .coord0 = 0,
991 .coord1 = 1,
992 };
993 #endif
994
995 const static struct ts_filter_chain_configuration gta02_filter_configuration[] =
996 {
997 #ifdef CONFIG_TOUCHSCREEN_FILTER
998 {&ts_filter_group_api, &gta02_ts_group.config},
999 {&ts_filter_median_api, &gta02_ts_median.config},
1000 {&ts_filter_mean_api, &gta02_ts_mean.config},
1001 {&ts_filter_linear_api, &gta02_ts_linear.config},
1002 #endif
1003 {NULL, NULL},
1004 };
1005
1006 const static struct s3c2410_ts_mach_info gta02_ts_cfg = {
1007 .delay = 10000,
1008 .presc = 0xff, /* slow as we can go */
1009 .filter_config = gta02_filter_configuration,
1010 };
1011
1012
1013
1014 static void gta02_bl_set_intensity(int intensity)
1015 {
1016 struct pcf50633 *pcf = gta02_pcf;
1017 int old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
1018 int ret;
1019
1020 intensity >>= 2;
1021
1022 /*
1023 * One code path that leads here is from a kernel panic. Trying to turn
1024 * the backlight on just gives us a nearly endless stream of complaints
1025 * and accomplishes nothing. We can't win. Just give up.
1026 *
1027 * In the unlikely event that there's another path leading here while
1028 * we're atomic, we print at least a warning.
1029 */
1030 if (in_atomic()) {
1031 printk(KERN_ERR
1032 "gta02_bl_set_intensity called while atomic\n");
1033 return;
1034 }
1035
1036 if (!(pcf50633_reg_read(pcf, PCF50633_REG_LEDENA) & 3))
1037 old_intensity = 0;
1038 else
1039 old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
1040
1041 if (intensity == old_intensity)
1042 return;
1043
1044 /* We can't do this anywhere else */
1045 pcf50633_reg_write(pcf, PCF50633_REG_LEDDIM, 5);
1046
1047 /*
1048 * The PCF50633 cannot handle LEDOUT = 0 (datasheet p60)
1049 * if seen, you have to re-enable the LED unit
1050 */
1051 if (!intensity || !old_intensity)
1052 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0);
1053
1054 if (!intensity) /* illegal to set LEDOUT to 0 */
1055 ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f,
1056 2);
1057 else
1058 ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f,
1059 intensity);
1060
1061 if (intensity)
1062 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 2);
1063
1064 }
1065
1066 static struct generic_bl_info gta02_bl_info = {
1067 .name = "gta02-bl",
1068 .max_intensity = 0xff,
1069 .default_intensity = 0xff,
1070 .set_bl_intensity = gta02_bl_set_intensity,
1071 };
1072
1073 static struct platform_device gta02_bl_dev = {
1074 .name = "generic-bl",
1075 .id = 1,
1076 .dev = {
1077 .platform_data = &gta02_bl_info,
1078 },
1079 };
1080
1081 /* SPI: LCM control interface attached to Glamo3362 */
1082
1083 static void gta02_jbt6k74_reset(int devidx, int level)
1084 {
1085 gpio_set_value(GTA02_GPIO_GLAMO(4), level);
1086 }
1087
1088 static void gta02_jbt6k74_probe_completed(struct device *dev)
1089 {
1090 struct pcf50633 *pcf = gta02_pcf;
1091
1092 /* Switch on backlight. Qi does not do it for us */
1093 pcf50633_reg_write(pcf, PCF50633_REG_LEDOUT, 0x01);
1094 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0x00);
1095 pcf50633_reg_write(pcf, PCF50633_REG_LEDDIM, 0x01);
1096 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0x01);
1097
1098 gta02_bl_dev.dev.parent = dev;
1099 platform_device_register(&gta02_bl_dev);
1100 }
1101
1102 const struct jbt6k74_platform_data jbt6k74_pdata = {
1103 .reset = gta02_jbt6k74_reset,
1104 .probe_completed = gta02_jbt6k74_probe_completed,
1105 };
1106
1107 /*----------- SPI: Accelerometers attached to SPI of s3c244x ----------------- */
1108
1109 void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
1110 {
1111 struct lis302dl_platform_data *pdata = lis->pdata;
1112
1113 if (!resume) {
1114 /*
1115 * we don't want to power them with a high level
1116 * because GSENSOR_3V3 is not up during suspend
1117 */
1118 s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
1119 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1120 s3c2410_gpio_setpin(pdata->pin_mosi, 0);
1121 /* misnomer: it is a pullDOWN in 2442 */
1122 s3c2410_gpio_pullup(pdata->pin_miso, 1);
1123 return;
1124 }
1125
1126 /* back to normal */
1127 s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1128 s3c2410_gpio_setpin(pdata->pin_clk, 1);
1129 /* misnomer: it is a pullDOWN in 2442 */
1130 s3c2410_gpio_pullup(pdata->pin_miso, 0);
1131
1132 s3c2410_gpio_cfgpin(pdata->pin_chip_select, S3C2410_GPIO_OUTPUT);
1133 s3c2410_gpio_cfgpin(pdata->pin_clk, S3C2410_GPIO_OUTPUT);
1134 s3c2410_gpio_cfgpin(pdata->pin_mosi, S3C2410_GPIO_OUTPUT);
1135 s3c2410_gpio_cfgpin(pdata->pin_miso, S3C2410_GPIO_INPUT);
1136
1137 }
1138
1139 struct lis302dl_platform_data lis302_pdata_top = {
1140 .name = "lis302-1 (top)",
1141 .pin_chip_select= S3C2410_GPD12,
1142 .pin_clk = S3C2410_GPG7,
1143 .pin_mosi = S3C2410_GPG6,
1144 .pin_miso = S3C2410_GPG5,
1145 .interrupt = GTA02_IRQ_GSENSOR_1,
1146 .open_drain = 1, /* altered at runtime by PCB rev */
1147 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1148 };
1149
1150 struct lis302dl_platform_data lis302_pdata_bottom = {
1151 .name = "lis302-2 (bottom)",
1152 .pin_chip_select= S3C2410_GPD13,
1153 .pin_clk = S3C2410_GPG7,
1154 .pin_mosi = S3C2410_GPG6,
1155 .pin_miso = S3C2410_GPG5,
1156 .interrupt = GTA02_IRQ_GSENSOR_2,
1157 .open_drain = 1, /* altered at runtime by PCB rev */
1158 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1159 };
1160
1161 static struct spi_board_info gta02_spi_board_info[] = {
1162 {
1163 .modalias = "jbt6k74",
1164 .platform_data = &jbt6k74_pdata,
1165 .controller_data = (void*)GTA02_GPIO_GLAMO(12),
1166 /* irq */
1167 .max_speed_hz = 100 * 1000,
1168 .bus_num = 2,
1169 .chip_select = 0
1170 },
1171 {
1172 .modalias = "lis302dl",
1173 /* platform_data */
1174 .platform_data = &lis302_pdata_top,
1175 /* controller_data */
1176 /* irq */
1177 .max_speed_hz = 100 * 1000,
1178 .bus_num = 3,
1179 .chip_select = 0,
1180 },
1181
1182 {
1183 .modalias = "lis302dl",
1184 /* platform_data */
1185 .platform_data = &lis302_pdata_bottom,
1186 /* controller_data */
1187 /* irq */
1188 .max_speed_hz = 100 * 1000,
1189 .bus_num = 3,
1190 .chip_select = 1,
1191 },
1192
1193 };
1194
1195 static void gta02_lis302_chip_select(struct s3c2410_spigpio_info *info, int csid, int cs)
1196 {
1197
1198 /*
1199 * Huh... "quirk"... CS on this device is not really "CS" like you can
1200 * expect.
1201 *
1202 * When it is 0 it selects SPI interface mode.
1203 * When it is 1 it selects I2C interface mode.
1204 *
1205 * Because we have 2 devices on one interface we have to make sure
1206 * that the "disabled" device (actually in I2C mode) don't think we're
1207 * talking to it.
1208 *
1209 * When we talk to the "enabled" device, the "disabled" device sees
1210 * the clocks as I2C clocks, creating havoc.
1211 *
1212 * I2C sees MOSI going LOW while CLK HIGH as a START action, thus we
1213 * must ensure this is never issued.
1214 */
1215
1216 int cs_gpio, other_cs_gpio;
1217
1218 cs_gpio = csid ? S3C2410_GPD13 : S3C2410_GPD12;
1219 other_cs_gpio = (1 - csid) ? S3C2410_GPD13 : S3C2410_GPD12;
1220
1221
1222 if (cs == BITBANG_CS_ACTIVE) {
1223 s3c2410_gpio_setpin(other_cs_gpio, 1);
1224 s3c2410_gpio_setpin(cs_gpio, 1);
1225 s3c2410_gpio_setpin(info->pin_clk, 1);
1226 s3c2410_gpio_setpin(cs_gpio, 0);
1227 } else {
1228 s3c2410_gpio_setpin(cs_gpio, 1);
1229 s3c2410_gpio_setpin(other_cs_gpio, 1);
1230 }
1231 }
1232
1233 static struct s3c2410_spigpio_info gta02_spigpio_cfg = {
1234 .pin_clk = S3C2410_GPG7,
1235 .pin_mosi = S3C2410_GPG6,
1236 .pin_miso = S3C2410_GPG5,
1237 .bus_num = 3,
1238 .num_chipselect = 2,
1239 .chip_select = gta02_lis302_chip_select,
1240 .non_blocking_transfer = 1,
1241 };
1242
1243 static struct platform_device gta02_spi_gpio_dev = {
1244 .name = "spi_s3c24xx_gpio",
1245 .dev = {
1246 .platform_data = &gta02_spigpio_cfg,
1247 },
1248 };
1249
1250 /*----------- / SPI: Accelerometers attached to SPI of s3c244x ----------------- */
1251
1252 static struct gpio_led gta02_gpio_leds[] = {
1253 {
1254 .name = "gta02-power:orange",
1255 .gpio = GTA02_GPIO_PWR_LED1,
1256 }, {
1257 .name = "gta02-power:blue",
1258 .gpio = GTA02_GPIO_PWR_LED2,
1259 }, {
1260 .name = "gta02-aux:red",
1261 .gpio = GTA02_GPIO_AUX_LED,
1262 },
1263 };
1264
1265 static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
1266 .leds = gta02_gpio_leds,
1267 .num_leds = ARRAY_SIZE(gta02_gpio_leds),
1268 };
1269
1270 struct platform_device gta02_led_dev = {
1271 .name = "leds-gpio",
1272 .id = -1,
1273 .dev = {
1274 .platform_data = &gta02_gpio_leds_pdata,
1275 },
1276 };
1277
1278 static struct gpio_keys_button gta02_buttons[] = {
1279 {
1280 .gpio = GTA02_GPIO_AUX_KEY,
1281 .code = KEY_PHONE,
1282 .desc = "Aux",
1283 .type = EV_KEY,
1284 },
1285 {
1286 .gpio = GTA02_GPIO_HOLD_KEY,
1287 .code = KEY_PAUSE,
1288 .desc = "Hold",
1289 .type = EV_KEY,
1290 },
1291 };
1292
1293 static struct gpio_keys_platform_data gta02_buttons_pdata = {
1294 .buttons = gta02_buttons,
1295 .nbuttons = ARRAY_SIZE(gta02_buttons),
1296 };
1297
1298 static struct platform_device gta02_button_dev = {
1299 .name = "gpio-keys",
1300 .id = -1,
1301 .dev = {
1302 .platform_data = &gta02_buttons_pdata,
1303 },
1304 };
1305
1306 static struct platform_device gta02_pm_usbhost_dev = {
1307 .name = "gta02-pm-host",
1308 };
1309
1310 /* USB */
1311 static struct s3c2410_hcd_info gta02_usb_info = {
1312 .port[0] = {
1313 .flags = S3C_HCDFLG_USED,
1314 },
1315 .port[1] = {
1316 .flags = 0,
1317 },
1318 };
1319
1320 static int glamo_irq_is_wired(void)
1321 {
1322 int rc;
1323 int count = 0;
1324
1325 /*
1326 * GTA02 S-Media IRQs prior to A5 are broken due to a lack of
1327 * a pullup on the INT# line. Check for the bad behaviour.
1328 */
1329 s3c2410_gpio_setpin(S3C2410_GPG4, 0);
1330 s3c2410_gpio_cfgpin(S3C2410_GPG4, S3C2410_GPG4_OUTP);
1331 s3c2410_gpio_cfgpin(S3C2410_GPG4, S3C2410_GPG4_INP);
1332 /*
1333 * we force it low ourselves for a moment and resume being input.
1334 * If there is a pullup, it won't stay low for long. But if the
1335 * level converter is there as on < A5 revision, the weak keeper
1336 * on the input of the LC will hold the line low indefinitiely
1337 */
1338 do
1339 rc = s3c2410_gpio_getpin(S3C2410_GPG4);
1340 while ((!rc) && ((count++) < 10));
1341 if (rc) { /* it got pulled back up, it's good */
1342 printk(KERN_INFO "Detected S-Media IRQ# pullup, "
1343 "enabling interrupt\n");
1344 return 0;
1345 } else /* Gah we can't work with this level converter */
1346 printk(KERN_WARNING "** Detected bad IRQ# circuit found"
1347 " on pre-A5 GTA02: S-Media interrupt disabled **\n");
1348 return -ENODEV;
1349 }
1350
1351 /* Smedia Glamo 3362 */
1352
1353 /*
1354 * we crank down SD Card clock dynamically when GPS is powered
1355 */
1356
1357 static int gta02_glamo_mci_use_slow(void)
1358 {
1359 return gta02_pm_gps_is_on();
1360 }
1361
1362 static void gta02_glamo_external_reset(int level)
1363 {
1364 s3c2410_gpio_setpin(GTA02_GPIO_3D_RESET, level);
1365 s3c2410_gpio_cfgpin(GTA02_GPIO_3D_RESET, S3C2410_GPIO_OUTPUT);
1366 }
1367
1368 /*
1369 static struct fb_videomode gta02_glamo_modes[] = {
1370 {
1371 .name = "480x640",
1372 .xres = 480,
1373 .yres = 640,
1374 .pixclock = 40816,
1375 .left_margin = 8,
1376 .right_margin = 63,
1377 .upper_margin = 2,
1378 .lower_margin = 4,
1379 .hsync_len = 8,
1380 .vsync_len = 2,
1381 .vmode = FB_VMODE_NONINTERLACED,
1382 }, {
1383 .name = "240x320",
1384 .xres = 240,
1385 .yres = 320,
1386 .pixclock = 40816,
1387 .left_margin = 8,
1388 .right_margin = 88,
1389 .upper_margin = 2,
1390 .lower_margin = 2,
1391 .hsync_len = 8,
1392 .vsync_len = 2,
1393 .vmode = FB_VMODE_NONINTERLACED,
1394 }
1395 };*/
1396
1397 static struct fb_videomode gta02_glamo_modes[] = {
1398 {
1399 .name = "480x640",
1400 .xres = 480,
1401 .yres = 640,
1402 .pixclock = 40816,
1403 .left_margin = 8,
1404 .right_margin = 16,
1405 .upper_margin = 2,
1406 .lower_margin = 16,
1407 .hsync_len = 8,
1408 .vsync_len = 2,
1409 .vmode = FB_VMODE_NONINTERLACED,
1410 }, {
1411 .name = "240x320",
1412 .xres = 240,
1413 .yres = 320,
1414 .pixclock = 40816,
1415 .left_margin = 8,
1416 .right_margin = 16,
1417 .upper_margin = 2,
1418 .lower_margin = 16,
1419 .hsync_len = 8,
1420 .vsync_len = 2,
1421 .vmode = FB_VMODE_NONINTERLACED,
1422 }
1423 };
1424
1425
1426 static struct glamo_fb_platform_data gta02_glamo_fb_pdata = {
1427 .width = 43,
1428 .height = 58,
1429
1430 .num_modes = ARRAY_SIZE(gta02_glamo_modes),
1431 .modes = gta02_glamo_modes,
1432 };
1433
1434 static struct glamo_mmc_platform_data gta02_glamo_mmc_pdata = {
1435 .glamo_mmc_use_slow = gta02_glamo_mci_use_slow,
1436 };
1437
1438 static struct glamo_platform_data gta02_glamo_pdata = {
1439 .fb_data = &gta02_glamo_fb_pdata,
1440 .mmc_data = &gta02_glamo_mmc_pdata,
1441 .gpio_base = GTA02_GPIO_GLAMO_BASE,
1442
1443 .osci_clock_rate = 32768,
1444
1445 .glamo_irq_is_wired = glamo_irq_is_wired,
1446 .glamo_external_reset = gta02_glamo_external_reset,
1447 };
1448
1449 static struct resource gta02_glamo_resources[] = {
1450 [0] = {
1451 .start = S3C2410_CS1,
1452 .end = S3C2410_CS1 + 0x1000000 - 1,
1453 .flags = IORESOURCE_MEM,
1454 },
1455 [1] = {
1456 .start = GTA02_IRQ_3D,
1457 .end = GTA02_IRQ_3D,
1458 .flags = IORESOURCE_IRQ,
1459 },
1460 [2] = {
1461 .start = GTA02_GPIO_3D_RESET,
1462 .end = GTA02_GPIO_3D_RESET,
1463 },
1464 };
1465
1466 static struct platform_device gta02_glamo_dev = {
1467 .name = "glamo3362",
1468 .num_resources = ARRAY_SIZE(gta02_glamo_resources),
1469 .resource = gta02_glamo_resources,
1470 .dev = {
1471 .platform_data = &gta02_glamo_pdata,
1472 },
1473 };
1474
1475 static void mangle_glamo_res_by_system_rev(void)
1476 {
1477 switch (S3C_SYSTEM_REV_ATAG) {
1478 case GTA02v1_SYSTEM_REV:
1479 break;
1480 default:
1481 gta02_glamo_resources[2].start = GTA02_GPIO_3D_RESET;
1482 gta02_glamo_resources[2].end = GTA02_GPIO_3D_RESET;
1483 break;
1484 }
1485
1486 switch (S3C_SYSTEM_REV_ATAG) {
1487 case GTA02v1_SYSTEM_REV:
1488 case GTA02v2_SYSTEM_REV:
1489 case GTA02v3_SYSTEM_REV:
1490 /* case GTA02v4_SYSTEM_REV: - FIXME: handle this later */
1491 /* The hardware is missing a pull-up resistor and thus can't
1492 * support the Smedia Glamo IRQ */
1493 gta02_glamo_resources[1].start = 0;
1494 gta02_glamo_resources[1].end = 0;
1495 break;
1496 }
1497 }
1498
1499 struct spi_gpio_platform_data spigpio_platform_data = {
1500 .sck = GTA02_GPIO_GLAMO(10),
1501 .mosi = GTA02_GPIO_GLAMO(11),
1502 .miso = GTA02_GPIO_GLAMO(5),
1503 .num_chipselect = 1,
1504 };
1505
1506 static struct platform_device spigpio_device = {
1507 .name = "spi_gpio",
1508 .id = 2,
1509 .dev = {
1510 .platform_data = &spigpio_platform_data,
1511 .parent = &gta02_glamo_dev.dev,
1512 },
1513 };
1514
1515 static void __init gta02_map_io(void)
1516 {
1517 s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
1518 s3c24xx_init_clocks(12000000);
1519 s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
1520 }
1521
1522 static irqreturn_t gta02_modem_irq(int irq, void *param)
1523 {
1524 /* printk(KERN_DEBUG "modem wakeup interrupt\n");*/
1525 gta_gsm_interrupts++;
1526 return IRQ_HANDLED;
1527 }
1528
1529 static irqreturn_t ar6000_wow_irq(int irq, void *param)
1530 {
1531 /* printk(KERN_DEBUG "ar6000_wow interrupt\n");*/
1532 return IRQ_HANDLED;
1533 }
1534
1535 /*
1536 * hardware_ecc=1|0
1537 */
1538 static char hardware_ecc_str[4] __initdata = "";
1539
1540 static int __init hardware_ecc_setup(char *str)
1541 {
1542 if (str)
1543 strlcpy(hardware_ecc_str, str, sizeof(hardware_ecc_str));
1544 return 1;
1545 }
1546
1547 __setup("hardware_ecc=", hardware_ecc_setup);
1548
1549 /* these are the guys that don't need to be children of PMU */
1550
1551 static struct platform_device *gta02_devices[] __initdata = {
1552 &s3c_device_usb,
1553 &s3c_device_wdt,
1554 &s3c_device_sdi,
1555 &s3c_device_usbgadget,
1556 &s3c_device_nand,
1557 &gta02_nor_flash,
1558
1559 &s3c24xx_pwm_device,
1560 &gta02_led_dev,
1561 &gta02_pm_wlan_dev, /* not dependent on PMU */
1562 &s3c_device_iis,
1563 &s3c_device_i2c0,
1564 };
1565
1566 /* these guys DO need to be children of PMU */
1567
1568 static struct platform_device *gta02_devices_pmu_children[] = {
1569 &s3c_device_ts, /* input 1 */
1570 &gta02_pm_gsm_dev,
1571 &gta02_pm_usbhost_dev,
1572 &gta02_spi_gpio_dev, /* input 2 and 3 */
1573 &gta02_button_dev, /* input 4 */
1574 &gta02_resume_reason_device,
1575 };
1576
1577 static void gta02_register_glamo(void)
1578 {
1579 platform_device_register(&gta02_glamo_dev);
1580 if (gpio_request(GTA02_GPIO_GLAMO(4), "jbt6k74 reset"))
1581 printk("gta02: Failed to request jbt6k74 reset pin\n");
1582 if (gpio_direction_output(GTA02_GPIO_GLAMO(4), 1))
1583 printk("gta02: Failed to configure jbt6k74 reset pin\n");
1584 platform_device_register(&spigpio_device);
1585 }
1586
1587 static void gta02_pmu_regulator_registered(struct pcf50633 *pcf, int id)
1588 {
1589 struct platform_device *regulator, *pdev;
1590
1591 gta02_pcf = pcf;
1592
1593 regulator = pcf->regulator_pdev[id];
1594
1595 switch(id) {
1596 case PCF50633_REGULATOR_LDO4:
1597 pdev = &gta02_pm_bt_dev;
1598 break;
1599 case PCF50633_REGULATOR_LDO5:
1600 pdev = &gta02_pm_gps_dev;
1601 break;
1602 case PCF50633_REGULATOR_HCLDO:
1603 gta02_register_glamo();
1604 return;
1605 default:
1606 return;
1607 }
1608
1609 pdev->dev.parent = &regulator->dev;
1610 platform_device_register(pdev);
1611 }
1612
1613 /* this is called when pc50633 is probed, unfortunately quite late in the
1614 * day since it is an I2C bus device. Here we can belatedly define some
1615 * platform devices with the advantage that we can mark the pcf50633 as the
1616 * parent. This makes them get suspended and resumed with their parent
1617 * the pcf50633 still around.
1618 */
1619
1620 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
1621 {
1622 int n;
1623
1624 for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
1625 gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
1626
1627 mangle_glamo_res_by_system_rev();
1628 platform_add_devices(gta02_devices_pmu_children,
1629 ARRAY_SIZE(gta02_devices_pmu_children));
1630
1631 regulator_has_full_constraints();
1632 }
1633
1634 static void gta02_poweroff(void)
1635 {
1636 pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN,
1637 PCF50633_OOCSHDWN_GOSTDBY, PCF50633_OOCSHDWN_GOSTDBY);
1638 }
1639
1640
1641 /* On hardware rev 5 and earlier the leds are missing a resistor and reading
1642 * from their gpio pins will always return 0, so we have to shadow the
1643 * led states software */
1644 static unsigned long gpb_shadow;
1645 extern struct s3c_gpio_chip s3c24xx_gpios[];
1646
1647 static void gta02_gpb_set(struct gpio_chip *chip,
1648 unsigned offset, int value)
1649 {
1650 void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB0);
1651 unsigned long flags;
1652 unsigned long dat;
1653
1654 local_irq_save(flags);
1655
1656 dat = __raw_readl(base + 0x04) | gpb_shadow;
1657 dat &= ~(1 << offset);
1658 gpb_shadow &= ~(1 << offset);
1659 if (value) {
1660 dat |= 1 << offset;
1661 switch (offset) {
1662 case 0 ... 2:
1663 gpb_shadow |= 1 << offset;
1664 break;
1665 default:
1666 break;
1667 }
1668 }
1669 __raw_writel(dat, base + 0x04);
1670
1671 local_irq_restore(flags);
1672 }
1673
1674 static int gta02_gpb_get(struct gpio_chip *chip, unsigned offset)
1675 {
1676 void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB0);
1677 unsigned long val;
1678
1679 val = __raw_readl(base + 0x04) | gpb_shadow;
1680 val >>= offset;
1681 val &= 1;
1682
1683 return val;
1684 }
1685
1686 static void gta02_hijack_gpb(void) {
1687 s3c24xx_gpios[1].chip.set = gta02_gpb_set;
1688 s3c24xx_gpios[1].chip.get = gta02_gpb_get;
1689 }
1690
1691 static void __init gta02_machine_init(void)
1692 {
1693 int rc;
1694
1695 /* set the panic callback to make AUX blink fast */
1696 panic_blink = gta02_panic_blink;
1697
1698 switch (S3C_SYSTEM_REV_ATAG) {
1699 case GTA02v6_SYSTEM_REV:
1700 /* we need push-pull interrupt from motion sensors */
1701 lis302_pdata_top.open_drain = 0;
1702 lis302_pdata_bottom.open_drain = 0;
1703 break;
1704 default:
1705 break;
1706 }
1707 if (S3C_SYSTEM_REV_ATAG <= GTA02v5_SYSTEM_REV)
1708 gta02_hijack_gpb();
1709
1710 spin_lock_init(&motion_irq_lock);
1711
1712 #ifdef CONFIG_CHARGER_PCF50633
1713 INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
1714 #endif
1715
1716 /* Glamo chip select optimization */
1717 /* *((u32 *)(S3C2410_MEMREG(((1 + 1) << 2)))) = 0x1280; */
1718
1719 /* do not force soft ecc if we are asked to use hardware_ecc */
1720 if (hardware_ecc_str[0] == '1')
1721 gta02_nand_info.software_ecc = 0;
1722
1723 s3c_device_usb.dev.platform_data = &gta02_usb_info;
1724 s3c_device_nand.dev.platform_data = &gta02_nand_info;
1725 s3c_device_sdi.dev.platform_data = &gta02_s3c_mmc_cfg;
1726
1727 /* acc sensor chip selects */
1728 s3c2410_gpio_setpin(S3C2410_GPD12, 1);
1729 s3c2410_gpio_cfgpin(S3C2410_GPD12, S3C2410_GPIO_OUTPUT);
1730 s3c2410_gpio_setpin(S3C2410_GPD13, 1);
1731 s3c2410_gpio_cfgpin(S3C2410_GPD13, S3C2410_GPIO_OUTPUT);
1732
1733
1734 s3c24xx_udc_set_platdata(&gta02_udc_cfg);
1735 s3c_i2c0_set_platdata(NULL);
1736 set_s3c2410ts_info(&gta02_ts_cfg);
1737
1738 mangle_glamo_res_by_system_rev();
1739
1740 i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
1741 spi_register_board_info(gta02_spi_board_info,
1742 ARRAY_SIZE(gta02_spi_board_info));
1743
1744 #ifdef CONFIG_CHARGER_PCF50633
1745 mangle_pmu_pdata_by_system_rev();
1746 #endif
1747
1748 platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
1749
1750 s3c_pm_init();
1751
1752 /* Make sure the modem can wake us up */
1753 set_irq_type(GTA02_IRQ_MODEM, IRQ_TYPE_EDGE_RISING);
1754 rc = request_irq(GTA02_IRQ_MODEM, gta02_modem_irq, IRQF_DISABLED,
1755 "modem", NULL);
1756 if (rc < 0)
1757 printk(KERN_ERR "GTA02: can't request GSM modem wakeup IRQ\n");
1758 enable_irq_wake(GTA02_IRQ_MODEM);
1759
1760 /* Make sure the wifi module can wake us up*/
1761 set_irq_type(GTA02_IRQ_WLAN_GPIO1, IRQ_TYPE_EDGE_RISING);
1762 rc = request_irq(GTA02_IRQ_WLAN_GPIO1, ar6000_wow_irq, IRQF_DISABLED,
1763 "ar6000", NULL);
1764
1765 if (rc < 0)
1766 printk(KERN_ERR "GTA02: can't request ar6k wakeup IRQ\n");
1767 enable_irq_wake(GTA02_IRQ_WLAN_GPIO1);
1768
1769 pm_power_off = gta02_poweroff;
1770
1771 /* Register the HDQ and vibrator as children of pwm device */
1772 #ifdef CONFIG_HDQ_GPIO_BITBANG
1773 gta02_hdq_device.dev.parent = &s3c24xx_pwm_device.dev;
1774 platform_device_register(&gta02_hdq_device);
1775 #endif
1776 #ifdef CONFIG_LEDS_GTA02_VIBRATOR
1777 gta02_vibrator_dev.dev.parent = &s3c24xx_pwm_device.dev;
1778 platform_device_register(&gta02_vibrator_dev);
1779 #endif
1780 }
1781
1782 void DEBUG_LED(int n)
1783 {
1784 switch (n) {
1785 case 0:
1786 s3c2410_gpio_setpin(GTA02_GPIO_PWR_LED1, 1);
1787 break;
1788 case 1:
1789 s3c2410_gpio_setpin(GTA02_GPIO_PWR_LED2, 1);
1790 break;
1791 default:
1792 s3c2410_gpio_setpin(GTA02_GPIO_AUX_LED, 1);
1793 break;
1794 }
1795 }
1796 EXPORT_SYMBOL_GPL(DEBUG_LED);
1797
1798 MACHINE_START(NEO1973_GTA02, "GTA02")
1799 .phys_io = S3C2410_PA_UART,
1800 .io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
1801 .boot_params = S3C2410_SDRAM_PA + 0x100,
1802 .map_io = gta02_map_io,
1803 .init_irq = s3c24xx_init_irq,
1804 .init_machine = gta02_machine_init,
1805 .timer = &s3c24xx_timer,
1806 MACHINE_END