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