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