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