aa350a1fe78a4ba86a81f6f347515cea131a6b74
[kernel.git] / arch / arm / mach-s3c2440 / 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/pcf50633.h>
49 #include <linux/lis302dl.h>
50
51 #include <asm/mach/arch.h>
52 #include <asm/mach/map.h>
53 #include <asm/mach/irq.h>
54
55 #include <mach/hardware.h>
56 #include <mach/io.h>
57 #include <asm/irq.h>
58 #include <asm/mach-types.h>
59
60 #include <mach/regs-irq.h>
61 #include <mach/regs-gpio.h>
62 #include <mach/regs-gpioj.h>
63 #include <mach/fb.h>
64 #include <asm/arch/mci.h>
65 #include <asm/arch/ts.h>
66 #include <mach/spi.h>
67 #include <asm/arch/spi-gpio.h>
68 #include <mach/usb-control.h>
69 #include <mach/regs-mem.h>
70
71 #include <asm/arch/gta02.h>
72
73 #include <asm/plat-s3c/regs-serial.h>
74 #include <asm/plat-s3c/nand.h>
75 #include <asm/plat-s3c24xx/devs.h>
76 #include <asm/plat-s3c24xx/cpu.h>
77 #include <asm/plat-s3c24xx/pm.h>
78 #include <asm/plat-s3c24xx/udc.h>
79 #include <asm/plat-s3c24xx/neo1973.h>
80 #include <asm/arch-s3c2410/neo1973-pm-gsm.h>
81
82 #include <linux/jbt6k74.h>
83
84 #include <linux/glamofb.h>
85
86 #include <asm/arch/fiq_ipc_gta02.h>
87 #include "fiq_c_isr.h"
88 #include <linux/gta02_hdq.h>
89 #include <linux/bq27000_battery.h>
90
91 #include "../plat-s3c24xx/neo1973_pm_gps.h"
92
93 /* arbitrates which sensor IRQ owns the shared SPI bus */
94 static spinlock_t motion_irq_lock;
95
96 /* the dependency of jbt / LCM on pcf50633 resume */
97 struct resume_dependency resume_dep_jbt_pcf;
98 /* the dependency of jbt / LCM on glamo resume */
99 struct resume_dependency resume_dep_jbt_glamo;
100 /* the dependency of Glamo MCI on pcf50633 resume (has to power SD slot) */
101 struct resume_dependency resume_dep_glamo_mci_pcf;
102
103
104 static int gta02_charger_online_status;
105 static int gta02_charger_active_status;
106
107 /* define FIQ IPC struct */
108 /*
109  * contains stuff FIQ ISR modifies and normal kernel code can see and use
110  * this is defined in <asm/arch/fiq_ipc_gta02.h>, you should customize
111  * the definition in there and include the same definition in your kernel
112  * module that wants to interoperate with your FIQ code.
113  */
114 struct fiq_ipc fiq_ipc;
115 EXPORT_SYMBOL(fiq_ipc);
116
117 #define DIVISOR_FROM_US(x) ((x) << 1)
118
119 #define FIQ_DIVISOR_VIBRATOR DIVISOR_FROM_US(100)
120
121 #ifdef CONFIG_GTA02_HDQ
122 /* HDQ specific */
123 #define HDQ_SAMPLE_PERIOD_US 20
124 /* private HDQ FSM state -- all other info interesting for caller in fiq_ipc */
125 static enum hdq_bitbang_states hdq_state;
126 static u8 hdq_ctr;
127 static u8 hdq_ctr2;
128 static u8 hdq_bit;
129 static u8 hdq_shifter;
130 static u8 hdq_tx_data_done;
131
132 #define FIQ_DIVISOR_HDQ DIVISOR_FROM_US(HDQ_SAMPLE_PERIOD_US)
133 #endif
134 /* define FIQ ISR */
135
136 FIQ_HANDLER_START()
137 /* define your locals here -- no initializers though */
138         u16 divisor;
139 FIQ_HANDLER_ENTRY(256, 512)
140 /* Your ISR here :-) */
141         divisor = 0xffff;
142
143         /* Vibrator servicing */
144
145         if (fiq_ipc.vib_pwm_latched || fiq_ipc.vib_pwm) { /* not idle */
146                 if (((u8)_fiq_count_fiqs) == fiq_ipc.vib_pwm_latched)
147                         neo1973_gpb_setpin(fiq_ipc.vib_gpio_pin, 0);
148                 if (((u8)_fiq_count_fiqs) == 0) {
149                         fiq_ipc.vib_pwm_latched = fiq_ipc.vib_pwm;
150                         if (fiq_ipc.vib_pwm_latched)
151                                 neo1973_gpb_setpin(fiq_ipc.vib_gpio_pin, 1);
152                 }
153                 divisor = FIQ_DIVISOR_VIBRATOR;
154         }
155
156 #ifdef CONFIG_GTA02_HDQ
157         /* HDQ servicing */
158
159         switch (hdq_state) {
160         case HDQB_IDLE:
161                 if (fiq_ipc.hdq_request_ctr == fiq_ipc.hdq_transaction_ctr)
162                         break;
163                 hdq_ctr = 210 / HDQ_SAMPLE_PERIOD_US;
164                 s3c2410_gpio_setpin(fiq_ipc.hdq_gpio_pin, 0);
165                 s3c2410_gpio_cfgpin(fiq_ipc.hdq_gpio_pin, S3C2410_GPIO_OUTPUT);
166                 hdq_tx_data_done = 0;
167                 hdq_state = HDQB_TX_BREAK;
168                 break;
169
170         case HDQB_TX_BREAK: /* issue low for > 190us */
171                 if (--hdq_ctr == 0) {
172                         hdq_ctr = 60 / HDQ_SAMPLE_PERIOD_US;
173                         hdq_state = HDQB_TX_BREAK_RECOVERY;
174                         s3c2410_gpio_setpin(fiq_ipc.hdq_gpio_pin, 1);
175                 }
176                 break;
177
178         case HDQB_TX_BREAK_RECOVERY: /* issue low for > 40us */
179                 if (--hdq_ctr)
180                         break;
181                 hdq_shifter = fiq_ipc.hdq_ads;
182                 hdq_bit = 8; /* 8 bits of ads / rw */
183                 hdq_tx_data_done = 0; /* doing ads */
184                 /* fallthru on last one */
185         case HDQB_ADS_CALC:
186                 if (hdq_shifter & 1)
187                         hdq_ctr = 50 / HDQ_SAMPLE_PERIOD_US;
188                 else
189                         hdq_ctr = 120 / HDQ_SAMPLE_PERIOD_US;
190                 /* carefully precompute the other phase length */
191                 hdq_ctr2 = (210 - (hdq_ctr * HDQ_SAMPLE_PERIOD_US)) /
192                                 HDQ_SAMPLE_PERIOD_US;
193                 hdq_state = HDQB_ADS_LOW;
194                 hdq_shifter >>= 1;
195                 hdq_bit--;
196                 s3c2410_gpio_setpin(fiq_ipc.hdq_gpio_pin, 0);
197                 break;
198
199         case HDQB_ADS_LOW:
200                 if (--hdq_ctr)
201                         break;
202                 s3c2410_gpio_setpin(fiq_ipc.hdq_gpio_pin, 1);
203                 hdq_state = HDQB_ADS_HIGH;
204                 break;
205
206         case HDQB_ADS_HIGH:
207                 if (--hdq_ctr2 > 1) /* account for HDQB_ADS_CALC */
208                         break;
209                 if (hdq_bit) { /* more bits to do */
210                         hdq_state = HDQB_ADS_CALC;
211                         break;
212                 }
213                 /* no more bits, wait it out until hdq_ctr2 exhausted */
214                 if (hdq_ctr2)
215                         break;
216                 /* ok no more bits and very last state */
217                 hdq_ctr = 60 / HDQ_SAMPLE_PERIOD_US;
218                 /* FIXME 0 = read */
219                 if (fiq_ipc.hdq_ads & 0x80) { /* write the byte out */
220                          /* set delay before payload */
221                         hdq_ctr = 300 / HDQ_SAMPLE_PERIOD_US;
222                         /* already high, no need to write */
223                         hdq_state = HDQB_WAIT_TX;
224                         break;
225                 }
226                 /* read the next byte */
227                 hdq_bit = 8; /* 8 bits of data */
228                 hdq_ctr = 3000 / HDQ_SAMPLE_PERIOD_US;
229                 hdq_state = HDQB_WAIT_RX;
230                 s3c2410_gpio_cfgpin(fiq_ipc.hdq_gpio_pin, S3C2410_GPIO_INPUT);
231                 break;
232
233         case HDQB_WAIT_TX: /* issue low for > 40us */
234                 if (--hdq_ctr)
235                         break;
236                 if (!hdq_tx_data_done) { /* was that the data sent? */
237                         hdq_tx_data_done++;
238                         hdq_shifter = fiq_ipc.hdq_tx_data;
239                         hdq_bit = 8; /* 8 bits of data */
240                         hdq_state = HDQB_ADS_CALC; /* start sending */
241                         break;
242                 }
243                 fiq_ipc.hdq_error = 0;
244                 fiq_ipc.hdq_transaction_ctr++;
245                 hdq_state = HDQB_IDLE; /* all tx is done */
246                 /* idle in input mode, it's pulled up by 10K */
247                 s3c2410_gpio_cfgpin(fiq_ipc.hdq_gpio_pin, S3C2410_GPIO_INPUT);
248                 break;
249
250         case HDQB_WAIT_RX: /* wait for battery to talk to us */
251                 if (s3c2410_gpio_getpin(fiq_ipc.hdq_gpio_pin) == 0) {
252                         /* it talks to us! */
253                         hdq_ctr2 = 1;
254                         hdq_bit = 8; /* 8 bits of data */
255                         /* timeout */
256                         hdq_ctr = 300 / HDQ_SAMPLE_PERIOD_US;
257                         hdq_state = HDQB_DATA_RX_LOW;
258                         break;
259                 }
260                 if (--hdq_ctr == 0) { /* timed out, error */
261                         fiq_ipc.hdq_error = 1;
262                         fiq_ipc.hdq_transaction_ctr++;
263                         hdq_state = HDQB_IDLE; /* abort */
264                 }
265                 break;
266
267         /*
268          * HDQ basically works by measuring the low time of the bit cell
269          * 32-50us --> '1', 80 - 145us --> '0'
270          */
271
272         case HDQB_DATA_RX_LOW:
273                 if (s3c2410_gpio_getpin(fiq_ipc.hdq_gpio_pin)) {
274                         fiq_ipc.hdq_rx_data >>= 1;
275                         if (hdq_ctr2 <= (65 / HDQ_SAMPLE_PERIOD_US))
276                                 fiq_ipc.hdq_rx_data |= 0x80;
277
278                         if (--hdq_bit == 0) {
279                                 fiq_ipc.hdq_error = 0;
280                                 fiq_ipc.hdq_transaction_ctr++; /* done */
281                                 hdq_state = HDQB_IDLE;
282                         } else
283                                 hdq_state = HDQB_DATA_RX_HIGH;
284                         /* timeout */
285                         hdq_ctr = 1000 / HDQ_SAMPLE_PERIOD_US;
286                         hdq_ctr2 = 1;
287                         break;
288                 }
289                 hdq_ctr2++;
290                 if (--hdq_ctr)
291                         break;
292                  /* timed out, error */
293                 fiq_ipc.hdq_error = 2;
294                 fiq_ipc.hdq_transaction_ctr++;
295                 hdq_state = HDQB_IDLE; /* abort */
296                 break;
297
298         case HDQB_DATA_RX_HIGH:
299                 if (!s3c2410_gpio_getpin(fiq_ipc.hdq_gpio_pin)) {
300                         /* it talks to us! */
301                         hdq_ctr2 = 1;
302                         /* timeout */
303                         hdq_ctr = 400 / HDQ_SAMPLE_PERIOD_US;
304                         hdq_state = HDQB_DATA_RX_LOW;
305                         break;
306                 }
307                 if (--hdq_ctr)
308                         break;
309                 /* timed out, error */
310                 fiq_ipc.hdq_error = 3;
311                 fiq_ipc.hdq_transaction_ctr++;
312                 /* we're in input mode already */
313                 hdq_state = HDQB_IDLE; /* abort */
314                 break;
315         }
316
317         if (hdq_state != HDQB_IDLE) /* ie, not idle */
318                 if (divisor > FIQ_DIVISOR_HDQ)
319                         divisor = FIQ_DIVISOR_HDQ; /* keep us going */
320 #endif
321
322         /* disable further timer interrupts if nobody has any work
323          * or adjust rate according to who still has work
324          *
325          * CAUTION: it means forground code must disable FIQ around
326          * its own non-atomic S3C2410_INTMSK changes... not common
327          * thankfully and taken care of by the fiq-basis patch
328          */
329         if (divisor == 0xffff) /* mask the fiq irq source */
330                 __raw_writel(__raw_readl(S3C2410_INTMSK) | _fiq_ack_mask,
331                              S3C2410_INTMSK);
332         else /* still working, maybe at a different rate */
333                 __raw_writel(divisor, S3C2410_TCNTB(_fiq_timer_index));
334         _fiq_timer_divisor = divisor;
335
336 FIQ_HANDLER_END()
337
338
339 /*
340  * this gets called every 1ms when we paniced.
341  */
342
343 static long gta02_panic_blink(long count)
344 {
345         long delay = 0;
346         static long last_blink;
347         static char led;
348
349         if (count - last_blink < 100) /* 200ms period, fast blink */
350                 return 0;
351
352         led ^= 1;
353         s3c2410_gpio_cfgpin(GTA02_GPIO_AUX_LED, S3C2410_GPIO_OUTPUT);
354         neo1973_gpb_setpin(GTA02_GPIO_AUX_LED, led);
355
356         last_blink = count;
357         return delay;
358 }
359
360
361 /**
362  * returns PCB revision information in b9,b8 and b2,b1,b0
363  * Pre-GTA02 A6 returns 0x000
364  *     GTA02 A6 returns 0x101
365  *     ...
366  */
367
368 int gta02_get_pcb_revision(void)
369 {
370         int n;
371         int u = 0;
372         static unsigned long pinlist[] = {
373                 GTA02_PCB_ID1_0,
374                 GTA02_PCB_ID1_1,
375                 GTA02_PCB_ID1_2,
376                 GTA02_PCB_ID2_0,
377                 GTA02_PCB_ID2_1,
378         };
379         static int pin_offset[] = {
380                 0, 1, 2, 8, 9
381         };
382
383         for (n = 0 ; n < ARRAY_SIZE(pinlist); n++) {
384                 /*
385                  * set the PCB version GPIO to be pulled-down input
386                  * force low briefly first
387                  */
388                 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_OUTPUT);
389                 s3c2410_gpio_setpin(pinlist[n], 0);
390                 /* misnomer: it is a pullDOWN in 2442 */
391                 s3c2410_gpio_pullup(pinlist[n], 1);
392                 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_INPUT);
393
394                 udelay(10);
395
396                 if (s3c2410_gpio_getpin(pinlist[n]))
397                         u |= 1 << pin_offset[n];
398
399                 /*
400                 * when not being interrogated, all of the revision GPIO
401                 * are set to output HIGH without pulldown so no current flows
402                 * if they are NC or pulled up.
403                 */
404                 s3c2410_gpio_setpin(pinlist[n], 1);
405                 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_OUTPUT);
406                 /* misnomer: it is a pullDOWN in 2442 */
407                 s3c2410_gpio_pullup(pinlist[n], 0);
408         }
409
410         return u;
411 }
412
413 struct platform_device gta02_version_device = {
414         .name           = "neo1973-version",
415         .num_resources  = 0,
416 };
417
418 struct platform_device gta02_resume_reason_device = {
419         .name           = "neo1973-resume",
420         .num_resources  = 0,
421 };
422
423 struct platform_device gta02_memconfig_device = {
424         .name           = "neo1973-memconfig",
425         .num_resources  = 0,
426 };
427
428 static struct map_desc gta02_iodesc[] __initdata = {
429         {
430                 .virtual        = 0xe0000000,
431                 .pfn            = __phys_to_pfn(S3C2410_CS3+0x01000000),
432                 .length         = SZ_1M,
433                 .type           = MT_DEVICE
434         },
435 };
436
437 #define UCON S3C2410_UCON_DEFAULT
438 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
439 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
440
441 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
442         [0] = {
443                 .hwport      = 0,
444                 .flags       = 0,
445                 .ucon        = UCON,
446                 .ulcon       = ULCON,
447                 .ufcon       = UFCON,
448         },
449         [1] = {
450                 .hwport      = 1,
451                 .flags       = 0,
452                 .ucon        = UCON,
453                 .ulcon       = ULCON,
454                 .ufcon       = UFCON,
455         },
456         [2] = {
457                 .hwport      = 2,
458                 .flags       = 0,
459                 .ucon        = UCON,
460                 .ulcon       = ULCON,
461                 .ufcon       = UFCON,
462         },
463
464 };
465
466 /* BQ27000 Battery */
467
468 static int gta02_get_charger_online_status(void)
469 {
470         return gta02_charger_online_status;
471 }
472
473 static int gta02_get_charger_active_status(void)
474 {
475         return gta02_charger_active_status;
476 }
477
478
479 struct bq27000_platform_data bq27000_pdata = {
480         .name = "bat",
481         .rsense_mohms = 20,
482         .hdq_read = gta02hdq_read,
483         .hdq_write = gta02hdq_write,
484         .hdq_initialized = gta02hdq_initialized,
485         .get_charger_online_status = gta02_get_charger_online_status,
486         .get_charger_active_status = gta02_get_charger_active_status
487 };
488
489 struct platform_device bq27000_battery_device = {
490         .name           = "bq27000-battery",
491         .dev = {
492                 .platform_data = &bq27000_pdata,
493         },
494 };
495
496
497 /* PMU driver info */
498
499 static int pmu_callback(struct device *dev, unsigned int feature,
500                         enum pmu_event event)
501 {
502         switch (feature) {
503         case PCF50633_FEAT_MBC:
504                 switch (event) {
505                 case PMU_EVT_CHARGER_IDLE:
506                         gta02_charger_active_status = 0;
507                         break;
508                 case PMU_EVT_CHARGER_ACTIVE:
509                         gta02_charger_active_status = 1;
510                         break;
511                 case PMU_EVT_USB_INSERT:
512                         gta02_charger_online_status = 1;
513                         break;
514                 case PMU_EVT_USB_REMOVE:
515                         gta02_charger_online_status = 0;
516                         break;
517                 case PMU_EVT_INSERT: /* adapter is unsused */
518                 case PMU_EVT_REMOVE: /* adapter is unused */
519                         break;
520                 default:
521                         break;
522                 }
523                 break;
524         default:
525                 break;
526         }
527
528         bq27000_charging_state_change(&bq27000_battery_device);
529         return 0;
530 }
531
532 static struct platform_device gta01_pm_gps_dev = {
533         .name           = "neo1973-pm-gps",
534 };
535
536 static struct platform_device gta01_pm_bt_dev = {
537         .name           = "neo1973-pm-bt",
538 };
539
540 /* this is called when pc50633 is probed, unfortunately quite late in the
541  * day since it is an I2C bus device.  Here we can belatedly define some
542  * platform devices with the advantage that we can mark the pcf50633 as the
543  * parent.  This makes them get suspended and resumed with their parent
544  * the pcf50633 still around.
545  */
546
547 static void gta02_pcf50633_attach_child_devices(struct device *parent_device)
548 {
549         gta01_pm_gps_dev.dev.parent = parent_device;
550         gta01_pm_bt_dev.dev.parent = parent_device;
551         platform_device_register(&gta01_pm_bt_dev);
552         platform_device_register(&gta01_pm_gps_dev);
553 }
554
555 static struct pcf50633_platform_data gta02_pcf_pdata = {
556         .used_features  = PCF50633_FEAT_MBC |
557                           PCF50633_FEAT_BBC |
558                           PCF50633_FEAT_RTC |
559                           PCF50633_FEAT_CHGCUR |
560                           PCF50633_FEAT_BATVOLT |
561                           PCF50633_FEAT_BATTEMP |
562                           PCF50633_FEAT_PWM_BL,
563         .onkey_seconds_sig_init = 4,
564         .onkey_seconds_shutdown = 8,
565         .cb             = &pmu_callback,
566         .r_fix_batt     = 10000,
567         .r_fix_batt_par = 10000,
568         .r_sense_milli  = 220,
569         .flag_use_apm_emulation = 0,
570         .resumers = {
571                 [0] = PCF50633_INT1_USBINS |
572                       PCF50633_INT1_USBREM |
573                       PCF50633_INT1_ALARM,
574                 [1] = PCF50633_INT2_ONKEYF,
575                 [2] = PCF50633_INT3_ONKEY1S
576         },
577         /* warning: these get rewritten during machine init below
578          * depending on pcb variant
579          */
580         .rails  = {
581                 [PCF50633_REGULATOR_AUTO] = {
582                         .name           = "io_3v3",
583                         .flags          = PMU_VRAIL_F_SUSPEND_ON,
584                         .voltage        = {
585                                 .init   = 3300,
586                                 .max    = 3300,
587                         },
588                 },
589                 [PCF50633_REGULATOR_DOWN1] = {
590                         .name           = "core_1v3",
591                         /* Wow, when we are going into suspend, after pcf50633
592                          * runs its suspend (which happens real early since it
593                          * is an i2c device) we are running out of the 22uF cap
594                          * on core_1v3 rail !!!!
595                          */
596                         .voltage        = {
597                                 .init   = 1300,
598                                 .max    = 1600,
599                         },
600                 },
601                 [PCF50633_REGULATOR_DOWN2] = {
602                         .name           = "core_1v8",
603                         .flags          = PMU_VRAIL_F_SUSPEND_ON,
604                         .voltage        = {
605                                 .init   = 1800,
606                                 .max    = 1800,
607                         },
608                 },
609                 [PCF50633_REGULATOR_HCLDO] = {
610                         .name           = "sd_3v3",
611                         .voltage        = {
612                                 .init   = 2000,
613                                 .max    = 3300,
614                         },
615                 },
616                 [PCF50633_REGULATOR_LDO1] = {
617                         .name           = "gsensor_3v3",
618                         .voltage        = {
619                                 .init   = 1300,
620                                 .max    = 1330,
621                         },
622                 },
623                 [PCF50633_REGULATOR_LDO2] = {
624                         .name           = "codec_3v3",
625                         .voltage        = {
626                                 .init   = 3300,
627                                 .max    = 3300,
628                         },
629                 },
630                 [PCF50633_REGULATOR_LDO3] = {
631                         .name           = "unused3",
632                         .voltage        = {
633                                 .init   = 3000,
634                                 .max    = 3000,
635                         },
636                 },
637                 [PCF50633_REGULATOR_LDO4] = {
638                         .name           = "bt_3v2",
639                         .voltage        = {
640                                 .init   = 2500,
641                                 .max    = 3300,
642                         },
643                 },
644                 [PCF50633_REGULATOR_LDO5] = {
645                         .name           = "rf3v",
646                         .voltage        = {
647                                 .init   = 1500,
648                                 .max    = 1500,
649                         },
650                 },
651                 [PCF50633_REGULATOR_LDO6] = {
652                         .name           = "lcm_3v",
653                         .flags = PMU_VRAIL_F_SUSPEND_ON,
654                         .voltage        = {
655                                 .init   = 0,
656                                 .max    = 3300,
657                         },
658                 },
659                 [PCF50633_REGULATOR_MEMLDO] = {
660                         .name           = "memldo",
661                         .flags = PMU_VRAIL_F_SUSPEND_ON,
662                         .voltage        = {
663                                 .init   = 1800,
664                                 .max    = 1800,
665                         },
666                 },
667         },
668         .defer_resume_backlight = 1,
669         .resume_backlight_ramp_speed = 5,
670         .attach_child_devices = gta02_pcf50633_attach_child_devices
671
672 };
673
674 #if 0 /* currently unused */
675 static void cfg_pmu_vrail(struct pmu_voltage_rail *vrail, char *name,
676                           unsigned int flags, unsigned int init,
677                           unsigned int max)
678 {
679         vrail->name = name;
680         vrail->flags = flags;
681         vrail->voltage.init = init;
682         vrail->voltage.max = max;
683 }
684 #endif
685
686 static void mangle_pmu_pdata_by_system_rev(void)
687 {
688         switch (system_rev) {
689         case GTA02v1_SYSTEM_REV:
690                 /* FIXME: this is only in v1 due to wrong PMU variant */
691                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_DOWN2].flags =
692                                                         PMU_VRAIL_F_SUSPEND_ON;
693                 break;
694         case GTA02v2_SYSTEM_REV:
695         case GTA02v3_SYSTEM_REV:
696         case GTA02v4_SYSTEM_REV:
697         case GTA02v5_SYSTEM_REV:
698         case GTA02v6_SYSTEM_REV:
699                 /* we need to keep the 1.8V going since this is the SDRAM
700                  * self-refresh voltage */
701                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_DOWN2].flags =
702                                                         PMU_VRAIL_F_SUSPEND_ON;
703                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_DOWN2].name =
704                                                         "io_1v8",
705                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_LDO1].name =
706                                                         "gsensor_3v3",
707                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_LDO1].voltage.init =
708                                                         3300;
709                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_LDO1].voltage.max =
710                                                         3300;
711                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_LDO1].flags &=
712                                                         ~PMU_VRAIL_F_SUSPEND_ON;
713                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_LDO3].flags =
714                                                         PMU_VRAIL_F_UNUSED;
715                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_LDO5] = ((struct pmu_voltage_rail) {
716                                                         .name = "rf_3v",
717                                                         .voltage = {
718                                                                 .init = 0,
719                                                                 .max = 3000,
720                                                         }
721                                                 });
722                 gta02_pcf_pdata.rails[PCF50633_REGULATOR_LDO6] =
723                                         ((struct pmu_voltage_rail) {
724                                                 .name = "lcm_3v",
725                                                 .flags = PMU_VRAIL_F_SUSPEND_ON,
726                                                 .voltage = {
727                                                         .init = 3000,
728                                                         .max = 3000,
729                                                 }
730                                         });
731                 break;
732         default:
733                 break;
734         }
735 }
736
737 static struct resource gta02_pmu_resources[] = {
738         [0] = {
739                 .flags  = IORESOURCE_IRQ,
740                 .start  = GTA02_IRQ_PCF50633,
741                 .end    = GTA02_IRQ_PCF50633,
742         },
743 };
744
745 struct platform_device gta02_pmu_dev = {
746         .name           = "pcf50633",
747         .num_resources  = ARRAY_SIZE(gta02_pmu_resources),
748         .resource       = gta02_pmu_resources,
749         .dev            = {
750                 .platform_data = &gta02_pcf_pdata,
751         },
752 };
753
754 /* FIQ */
755
756 static struct resource sc32440_fiq_resources[] = {
757         [0] = {
758                 .flags  = IORESOURCE_IRQ,
759                 .start  = IRQ_TIMER3,
760                 .end    = IRQ_TIMER3,
761         },
762 };
763
764 struct platform_device sc32440_fiq_device = {
765         .name           = "sc32440_fiq",
766         .num_resources  = 1,
767         .resource       = sc32440_fiq_resources,
768 };
769
770 #ifdef CONFIG_GTA02_HDQ
771 /* HDQ */
772
773 static struct resource gta02_hdq_resources[] = {
774         [0] = {
775                 .start  = GTA02v5_GPIO_HDQ,
776                 .end    = GTA02v5_GPIO_HDQ,
777         },
778 };
779
780 struct platform_device gta02_hdq_device = {
781         .name           = "gta02-hdq",
782         .num_resources  = 1,
783         .resource       = gta02_hdq_resources,
784 };
785 #endif
786
787
788 /* NOR Flash */
789
790 #define GTA02_FLASH_BASE        0x18000000 /* GCS3 */
791 #define GTA02_FLASH_SIZE        0x200000 /* 2MBytes */
792
793 static struct physmap_flash_data gta02_nor_flash_data = {
794         .width          = 2,
795 };
796
797 static struct resource gta02_nor_flash_resource = {
798         .start          = GTA02_FLASH_BASE,
799         .end            = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
800         .flags          = IORESOURCE_MEM,
801 };
802
803 static struct platform_device gta02_nor_flash = {
804         .name           = "physmap-flash",
805         .id             = 0,
806         .dev            = {
807                                 .platform_data  = &gta02_nor_flash_data,
808                         },
809         .resource       = &gta02_nor_flash_resource,
810         .num_resources  = 1,
811 };
812
813
814
815 static struct resource gta02_sdio_resources[] = {
816         [0] = {
817                 .flags  = IORESOURCE_IRQ,
818                 .start  = IRQ_SDI,
819                 .end    = IRQ_SDI,
820         },
821         [1] = {
822                 .flags = IORESOURCE_MEM,
823                 .start = S3C2410_PA_SDI,
824                 .end   = S3C2410_PA_SDI + S3C24XX_SZ_SDI - 1,
825         },
826         [2] = {
827                 .flags = IORESOURCE_DMA,
828                 .start = 0, /* Channel 0 for SDI */
829                 .end = 0,
830         },
831 };
832
833
834 static struct platform_device gta02_sdio_dev = {
835         .name           = "s3c24xx-sdio",
836         .id             = -1,
837         .dev            = {
838                                 .coherent_dma_mask      = 0xffffffff,
839         },
840         .resource       = gta02_sdio_resources,
841         .num_resources  = ARRAY_SIZE(gta02_sdio_resources),
842 };
843
844 struct platform_device s3c24xx_pwm_device = {
845         .name           = "s3c24xx_pwm",
846         .num_resources  = 0,
847 };
848
849
850 static struct platform_device *gta02_devices[] __initdata = {
851         &s3c_device_usb,
852         &s3c_device_wdt,
853         &s3c_device_i2c,
854         &s3c_device_iis,
855         // &s3c_device_sdi, /* FIXME: temporary disable to avoid s3cmci bind */
856         &s3c_device_usbgadget,
857         &s3c_device_nand,
858         &s3c_device_ts,
859         &gta02_nor_flash,
860         &sc32440_fiq_device,
861         &gta02_version_device,
862         &gta02_memconfig_device,
863         &gta02_resume_reason_device,
864         &s3c24xx_pwm_device,
865
866 };
867
868 static struct s3c2410_nand_set gta02_nand_sets[] = {
869         [0] = {
870                 .name           = "neo1973-nand",
871                 .nr_chips       = 1,
872                 .flags          = S3C2410_NAND_BBT,
873         },
874 };
875
876 /* choose a set of timings which should suit most 512Mbit
877  * chips and beyond.
878  */
879
880 static struct s3c2410_platform_nand gta02_nand_info = {
881         .tacls          = 20,
882         .twrph0         = 60,
883         .twrph1         = 20,
884         .nr_sets        = ARRAY_SIZE(gta02_nand_sets),
885         .sets           = gta02_nand_sets,
886         .software_ecc   = 1,
887 };
888
889 static struct s3c24xx_mci_pdata gta02_mmc_cfg = {
890         .gpio_detect    = GTA02v1_GPIO_nSD_DETECT,
891         .set_power      = NULL,
892         .ocr_avail      = MMC_VDD_32_33,
893 };
894
895 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
896 {
897         printk(KERN_DEBUG "%s(%d)\n", __func__, cmd);
898
899         switch (cmd) {
900         case S3C2410_UDC_P_ENABLE:
901                 neo1973_gpb_setpin(GTA02_GPIO_USB_PULLUP, 1);
902                 break;
903         case S3C2410_UDC_P_DISABLE:
904                 neo1973_gpb_setpin(GTA02_GPIO_USB_PULLUP, 0);
905                 break;
906         case S3C2410_UDC_P_RESET:
907                 /* FIXME! */
908                 break;
909         default:
910                 break;
911         }
912 }
913
914 /* get PMU to set USB current limit accordingly */
915
916 static void gta02_udc_vbus_draw(unsigned int ma)
917 {
918         if (!pcf50633_global)
919                 return;
920
921         pcf50633_notify_usb_current_limit_change(pcf50633_global, ma);
922 }
923
924 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
925         .vbus_draw      = gta02_udc_vbus_draw,
926         .udc_command    = gta02_udc_command,
927
928 };
929
930 static struct s3c2410_ts_mach_info gta02_ts_cfg = {
931         .delay = 10000,
932         .presc = 50000000 / 1000000, /* 50 MHz PCLK / 1MHz */
933         /* simple averaging, 2^n samples */
934         .oversampling_shift = 5,
935          /* averaging filter length, 2^n */
936         .excursion_filter_len_bits = 5,
937         /* flagged for beauty contest on next sample if differs from
938          * average more than this
939          */
940         .reject_threshold_vs_avg = 2,
941 };
942
943
944 /* SPI: LCM control interface attached to Glamo3362 */
945
946 static void gta02_jbt6k74_reset(int devidx, int level)
947 {
948         glamo_lcm_reset(level);
949 }
950
951 /* finally bring up deferred backlight resume now LCM is resumed itself */
952
953 static void gta02_jbt6k74_resuming(int devidx)
954 {
955         pcf50633_backlight_resume(pcf50633_global);
956 }
957
958 static int gta02_jbt6k74_all_dependencies_resumed(int devidx)
959 {
960         if (!resume_dep_jbt_pcf.called_flag)
961                 return 0;
962
963         if (!resume_dep_jbt_glamo.called_flag)
964                 return 0;
965
966         return 1;
967 }
968
969 /* register jbt resume action to be dependent on pcf50633 and glamo resume */
970
971 static void gta02_jbt6k74_suspending(int devindex, struct spi_device *spi)
972 {
973         void jbt6k74_resume(void *spi); /* little white lies about types */
974
975         resume_dep_jbt_pcf.callback = jbt6k74_resume;
976         resume_dep_jbt_pcf.context = (void *)spi;
977         pcf50633_register_resume_dependency(pcf50633_global,
978                                                            &resume_dep_jbt_pcf);
979         resume_dep_jbt_glamo.callback = jbt6k74_resume;
980         resume_dep_jbt_glamo.context = (void *)spi;
981         glamo_register_resume_dependency(&resume_dep_jbt_glamo);
982 }
983
984
985 const struct jbt6k74_platform_data jbt6k74_pdata = {
986         .reset          = gta02_jbt6k74_reset,
987         .resuming       = gta02_jbt6k74_resuming,
988         .suspending     = gta02_jbt6k74_suspending,
989         .all_dependencies_resumed = gta02_jbt6k74_all_dependencies_resumed,
990 };
991
992 static struct spi_board_info gta02_spi_board_info[] = {
993         {
994                 .modalias       = "jbt6k74",
995                 /* platform_data */
996                 .platform_data  = &jbt6k74_pdata,
997                 /* controller_data */
998                 /* irq */
999                 .max_speed_hz   = 10 * 1000 * 1000,
1000                 .bus_num        = 2,
1001                 /* chip_select */
1002         },
1003 };
1004
1005 #if 0 /* currently this is not used and we use gpio spi */
1006 static struct glamo_spi_info glamo_spi_cfg = {
1007         .board_size     = ARRAY_SIZE(gta02_spi_board_info),
1008         .board_info     = gta02_spi_board_info,
1009 };
1010 #endif /* 0 */
1011
1012 static struct glamo_spigpio_info glamo_spigpio_cfg = {
1013         .pin_clk        = GLAMO_GPIO10_OUTPUT,
1014         .pin_mosi       = GLAMO_GPIO11_OUTPUT,
1015         .pin_cs         = GLAMO_GPIO12_OUTPUT,
1016         .pin_miso       = 0,
1017         .board_size     = ARRAY_SIZE(gta02_spi_board_info),
1018         .board_info     = gta02_spi_board_info,
1019 };
1020
1021 static struct resource gta02_vibrator_resources[] = {
1022         [0] = {
1023                 .start  = GTA02_GPIO_VIBRATOR_ON,
1024                 .end    = GTA02_GPIO_VIBRATOR_ON,
1025         },
1026 };
1027
1028 static struct platform_device gta02_vibrator_dev = {
1029         .name           = "neo1973-vibrator",
1030         .num_resources  = ARRAY_SIZE(gta02_vibrator_resources),
1031         .resource       = gta02_vibrator_resources,
1032 };
1033
1034 /* SPI: Accelerometers attached to SPI of s3c244x */
1035
1036 /*
1037  * Situation is that Linux SPI can't work in an interrupt context, so we
1038  * implement our own bitbang here.  Arbitration is needed because not only
1039  * can this interrupt happen at any time even if foreground wants to use
1040  * the bitbang API from Linux, but multiple motion sensors can be on the
1041  * same SPI bus, and multiple interrupts can happen.
1042  *
1043  * Foreground / interrupt arbitration is okay because the interrupts are
1044  * disabled around all the foreground SPI code.
1045  *
1046  * Interrupt / Interrupt arbitration is evidently needed, otherwise we
1047  * lose edge-triggered service after a while due to the two sensors sharing
1048  * the SPI bus having irqs at the same time eventually.
1049  *
1050  * Servicing is typ 75 - 100us at 400MHz.
1051  */
1052
1053 /* #define DEBUG_SPEW_MS */
1054 #define MG_PER_SAMPLE 18
1055
1056 struct lis302dl_platform_data lis302_pdata[];
1057
1058 void gta02_lis302dl_bitbang_read(struct lis302dl_info *lis)
1059 {
1060         struct lis302dl_platform_data *pdata = lis->pdata;
1061         u8 shifter = 0xc0 | LIS302DL_REG_OUT_X; /* read, autoincrement */
1062         int n, n1;
1063         unsigned long other_cs;
1064         unsigned long flags;
1065 #ifdef DEBUG_SPEW_MS
1066         s8 x, y, z;
1067 #endif
1068
1069         local_irq_save(flags);
1070
1071         /*
1072          * Huh.. "quirk"... CS on this device is not really "CS" like you can
1073          * expect.  Instead when 1 it selects I2C interface mode.  Because we
1074          * have 2 devices on one interface, the "disabled" device when we talk
1075          * to an "enabled" device sees the clocks as I2C clocks, creating
1076          * havoc.
1077          * I2C sees MOSI going LOW while CLK HIGH as a START action, we must
1078          * ensure this is never issued.
1079          */
1080
1081         if (&lis302_pdata[0] == pdata)
1082                 other_cs = lis302_pdata[1].pin_chip_select;
1083         else
1084                 other_cs = lis302_pdata[0].pin_chip_select;
1085
1086         s3c2410_gpio_setpin(other_cs, 1);
1087         s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1088         s3c2410_gpio_setpin(pdata->pin_clk, 1);
1089         s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
1090         for (n = 0; n < 8; n++) { /* write the r/w, inc and address */
1091                 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1092                 s3c2410_gpio_setpin(pdata->pin_mosi, (shifter >> 7) & 1);
1093                 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1094                 s3c2410_gpio_setpin(pdata->pin_clk, 1);
1095                 s3c2410_gpio_setpin(pdata->pin_clk, 1);
1096                 shifter <<= 1;
1097         }
1098
1099         for (n = 0; n < 5; n++) { /* 5 consequetive registers */
1100                 for (n1 = 0; n1 < 8; n1++) { /* 8 bits each */
1101                         s3c2410_gpio_setpin(pdata->pin_clk, 0);
1102                         s3c2410_gpio_setpin(pdata->pin_clk, 0);
1103                         shifter <<= 1;
1104                         if (s3c2410_gpio_getpin(pdata->pin_miso))
1105                                 shifter |= 1;
1106                         s3c2410_gpio_setpin(pdata->pin_clk, 1);
1107                         s3c2410_gpio_setpin(pdata->pin_clk, 1);
1108                 }
1109                 switch (n) {
1110                 case 0:
1111 #ifdef DEBUG_SPEW_MS
1112                         x = shifter;
1113 #endif
1114                         input_report_rel(lis->input_dev, REL_X, MG_PER_SAMPLE * (s8)shifter);
1115                         break;
1116                 case 2:
1117 #ifdef DEBUG_SPEW_MS
1118                         y = shifter;
1119 #endif
1120                         input_report_rel(lis->input_dev, REL_Y, MG_PER_SAMPLE * (s8)shifter);
1121                         break;
1122                 case 4:
1123 #ifdef DEBUG_SPEW_MS
1124                         z = shifter;
1125 #endif
1126                         input_report_rel(lis->input_dev, REL_Z, MG_PER_SAMPLE * (s8)shifter);
1127                         break;
1128                 }
1129         }
1130         s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1131         s3c2410_gpio_setpin(other_cs, 1);
1132         local_irq_restore(flags);
1133
1134         input_sync(lis->input_dev);
1135 #ifdef DEBUG_SPEW_MS
1136         printk("%s: %d %d %d\n", pdata->name, x, y, z);
1137 #endif
1138 }
1139
1140
1141 void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
1142 {
1143         struct lis302dl_platform_data *pdata = lis->pdata;
1144
1145         if (!resume) {
1146                  /*
1147                  * we don't want to power them with a high level
1148                  * because GSENSOR_3V3 is not up during suspend
1149                  */
1150                 s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
1151                 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1152                 s3c2410_gpio_setpin(pdata->pin_mosi, 0);
1153                 /* misnomer: it is a pullDOWN in 2442 */
1154                 s3c2410_gpio_pullup(pdata->pin_miso, 1);
1155                 return;
1156         }
1157
1158         /* back to normal */
1159         s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1160         s3c2410_gpio_setpin(pdata->pin_clk, 1);
1161         /* misnomer: it is a pullDOWN in 2442 */
1162         s3c2410_gpio_pullup(pdata->pin_miso, 0);
1163 }
1164
1165 struct lis302dl_platform_data lis302_pdata[] = {
1166         {
1167                 .name           = "lis302-1 (top)",
1168                 .pin_chip_select= S3C2410_GPD12,
1169                 .pin_clk        = S3C2410_GPG7,
1170                 .pin_mosi       = S3C2410_GPG6,
1171                 .pin_miso       = S3C2410_GPG5,
1172                 .open_drain     = 1, /* altered at runtime by PCB rev */
1173                 .lis302dl_bitbang_read = gta02_lis302dl_bitbang_read,
1174                 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1175         }, {
1176                 .name           = "lis302-2 (bottom)",
1177                 .pin_chip_select= S3C2410_GPD13,
1178                 .pin_clk        = S3C2410_GPG7,
1179                 .pin_mosi       = S3C2410_GPG6,
1180                 .pin_miso       = S3C2410_GPG5,
1181                 .open_drain     = 1, /* altered at runtime by PCB rev */
1182                 .lis302dl_bitbang_read = gta02_lis302dl_bitbang_read,
1183                 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1184         },
1185 };
1186
1187 static struct spi_board_info gta02_spi_acc_bdinfo[] = {
1188         {
1189                 .modalias       = "lis302dl",
1190                 .platform_data  = &lis302_pdata[0],
1191                 .irq            = GTA02_IRQ_GSENSOR_1,
1192                 .max_speed_hz   = 10 * 1000 * 1000,
1193                 .bus_num        = 1,
1194                 .chip_select    = 0,
1195                 .mode           = SPI_MODE_3,
1196         },
1197         {
1198                 .modalias       = "lis302dl",
1199                 .platform_data  = &lis302_pdata[1],
1200                 .irq            = GTA02_IRQ_GSENSOR_2,
1201                 .max_speed_hz   = 10 * 1000 * 1000,
1202                 .bus_num        = 1,
1203                 .chip_select    = 1,
1204                 .mode           = SPI_MODE_3,
1205         },
1206 };
1207
1208 static void spi_acc_cs(struct s3c2410_spigpio_info *spigpio_info,
1209                        int csid, int cs)
1210 {
1211         struct lis302dl_platform_data * plat_data =
1212                                 (struct lis302dl_platform_data *)spigpio_info->
1213                                                      board_info->platform_data;
1214         switch (cs) {
1215         case BITBANG_CS_ACTIVE:
1216                 s3c2410_gpio_setpin(plat_data[csid].pin_chip_select, 0);
1217                 break;
1218         case BITBANG_CS_INACTIVE:
1219                 s3c2410_gpio_setpin(plat_data[csid].pin_chip_select, 1);
1220                 break;
1221         }
1222 }
1223
1224 static struct s3c2410_spigpio_info spi_gpio_cfg = {
1225         .pin_clk        = S3C2410_GPG7,
1226         .pin_mosi       = S3C2410_GPG6,
1227         .pin_miso       = S3C2410_GPG5,
1228         .board_size     = ARRAY_SIZE(gta02_spi_acc_bdinfo),
1229         .board_info     = gta02_spi_acc_bdinfo,
1230         .chip_select    = &spi_acc_cs,
1231         .num_chipselect = 2,
1232 };
1233
1234 static struct resource s3c_spi_acc_resource[] = {
1235         [0] = {
1236                 .start = S3C2410_GPG3,
1237                 .end   = S3C2410_GPG3,
1238         },
1239         [1] = {
1240                 .start = S3C2410_GPG5,
1241                 .end   = S3C2410_GPG5,
1242         },
1243         [2] = {
1244                 .start = S3C2410_GPG6,
1245                 .end   = S3C2410_GPG6,
1246         },
1247         [3] = {
1248                 .start = S3C2410_GPG7,
1249                 .end   = S3C2410_GPG7,
1250         },
1251 };
1252
1253 static struct platform_device s3c_device_spi_acc = {
1254         .name             = "spi_s3c24xx_gpio",
1255         .id               = 1,
1256         .num_resources    = ARRAY_SIZE(s3c_spi_acc_resource),
1257         .resource         = s3c_spi_acc_resource,
1258         .dev = {
1259                 .platform_data = &spi_gpio_cfg,
1260         },
1261 };
1262
1263 static struct resource gta02_led_resources[] = {
1264         {
1265                 .name   = "gta02-power:orange",
1266                 .start  = GTA02_GPIO_PWR_LED1,
1267                 .end    = GTA02_GPIO_PWR_LED1,
1268         }, {
1269                 .name   = "gta02-power:blue",
1270                 .start  = GTA02_GPIO_PWR_LED2,
1271                 .end    = GTA02_GPIO_PWR_LED2,
1272         }, {
1273                 .name   = "gta02-aux:red",
1274                 .start  = GTA02_GPIO_AUX_LED,
1275                 .end    = GTA02_GPIO_AUX_LED,
1276         },
1277 };
1278
1279 struct platform_device gta02_led_dev = {
1280         .name           = "gta02-led",
1281         .num_resources  = ARRAY_SIZE(gta02_led_resources),
1282         .resource       = gta02_led_resources,
1283 };
1284
1285 static struct resource gta02_button_resources[] = {
1286         [0] = {
1287                 .start = GTA02_GPIO_AUX_KEY,
1288                 .end   = GTA02_GPIO_AUX_KEY,
1289         },
1290         [1] = {
1291                 .start = GTA02_GPIO_HOLD_KEY,
1292                 .end   = GTA02_GPIO_HOLD_KEY,
1293         },
1294         [2] = {
1295                 .start = GTA02_GPIO_JACK_INSERT,
1296                 .end   = GTA02_GPIO_JACK_INSERT,
1297         },
1298 };
1299
1300 static struct platform_device gta02_button_dev = {
1301         .name           = "neo1973-button",
1302         .num_resources  = ARRAY_SIZE(gta02_button_resources),
1303         .resource       = gta02_button_resources,
1304 };
1305
1306 static struct platform_device gta02_pm_gsm_dev = {
1307         .name           = "neo1973-pm-gsm",
1308 };
1309
1310 static struct platform_device gta02_pm_usbhost_dev = {
1311         .name           = "neo1973-pm-host",
1312 };
1313
1314
1315 /* USB */
1316 static struct s3c2410_hcd_info gta02_usb_info = {
1317         .port[0]        = {
1318                 .flags  = S3C_HCDFLG_USED,
1319         },
1320         .port[1]        = {
1321                 .flags  = 0,
1322         },
1323 };
1324
1325 static int glamo_irq_is_wired(void)
1326 {
1327         int rc;
1328         int count = 0;
1329
1330         /*
1331         * GTA02 S-Media IRQs prior to A5 are broken due to a lack of
1332         * a pullup on the INT# line.  Check for the bad behaviour.
1333         */
1334         s3c2410_gpio_setpin(S3C2410_GPG4, 0);
1335         s3c2410_gpio_cfgpin(S3C2410_GPG4, S3C2410_GPG4_OUTP);
1336         s3c2410_gpio_cfgpin(S3C2410_GPG4, S3C2410_GPG4_INP);
1337         /*
1338         * we force it low ourselves for a moment and resume being input.
1339         * If there is a pullup, it won't stay low for long.  But if the
1340         * level converter is there as on < A5 revision, the weak keeper
1341         * on the input of the LC will hold the line low indefinitiely
1342         */
1343         do
1344                 rc = s3c2410_gpio_getpin(S3C2410_GPG4);
1345         while ((!rc) && ((count++) < 10));
1346         if (rc) { /* it got pulled back up, it's good */
1347                 printk(KERN_INFO "Detected S-Media IRQ# pullup, "
1348                 "enabling interrupt\n");
1349                 return 0;
1350         } else  /* Gah we can't work with this level converter */
1351                 printk(KERN_WARNING "** Detected bad IRQ# circuit found"
1352                 " on pre-A5 GTA02: S-Media interrupt disabled **\n");
1353         return -ENODEV;
1354 }
1355
1356
1357 static void
1358 gta02_glamo_mmc_set_power(unsigned char power_mode, unsigned short vdd)
1359 {
1360         int mv = 1650;
1361         int timeout = 100;
1362
1363         printk(KERN_DEBUG "mmc_set_power(power_mode=%u, vdd=%u\n",
1364                power_mode, vdd);
1365
1366         switch (system_rev) {
1367         case GTA02v1_SYSTEM_REV:
1368         case GTA02v2_SYSTEM_REV:
1369                 break;
1370         case GTA02v3_SYSTEM_REV:
1371         case GTA02v4_SYSTEM_REV:
1372         case GTA02v5_SYSTEM_REV:
1373         case GTA02v6_SYSTEM_REV:
1374                 switch (power_mode) {
1375                 case MMC_POWER_ON:
1376                 case MMC_POWER_UP:
1377                         /* depend on pcf50633 driver init + not suspended */
1378                         while (pcf50633_ready(pcf50633_global) && (timeout--))
1379                                 msleep(5);
1380
1381                         if (!timeout) {
1382                                 printk(KERN_ERR"gta02_glamo_mmc_set_power "
1383                                              "BAILING on timeout\n");
1384                                 return;
1385                         }
1386                         /* select and set the voltage */
1387                         if (vdd > 7)
1388                                 mv += 350 + 100 * (vdd - 8);
1389                         printk(KERN_INFO "SD power -> %dmV\n", mv);
1390                         pcf50633_voltage_set(pcf50633_global,
1391                                              PCF50633_REGULATOR_HCLDO, mv);
1392                         pcf50633_onoff_set(pcf50633_global,
1393                                            PCF50633_REGULATOR_HCLDO, 1);
1394                         break;
1395                 case MMC_POWER_OFF:
1396                         /* power off happens during suspend, when pcf50633 can
1397                          * be already gone and not coming back... just forget
1398                          * the action then because pcf50633 suspend already
1399                          * dealt with it, otherwise we spin forever
1400                          */
1401                         if (pcf50633_ready(pcf50633_global))
1402                                 return;
1403                         pcf50633_onoff_set(pcf50633_global,
1404                                            PCF50633_REGULATOR_HCLDO, 0);
1405                         break;
1406                 }
1407                 break;
1408         }
1409 }
1410
1411
1412 static int gta02_glamo_mci_all_dependencies_resumed(struct platform_device *dev)
1413 {
1414         return resume_dep_glamo_mci_pcf.called_flag;
1415 }
1416
1417 /* register jbt resume action to be dependent on pcf50633 and glamo resume */
1418
1419 static void gta02_glamo_mci_suspending(struct platform_device *dev)
1420 {
1421         void glamo_mci_resume(void *dev); /* little white lies about types */
1422
1423         resume_dep_glamo_mci_pcf.callback = glamo_mci_resume;
1424         resume_dep_glamo_mci_pcf.context = (void *)dev;
1425         pcf50633_register_resume_dependency(pcf50633_global,
1426                                                      &resume_dep_glamo_mci_pcf);
1427 }
1428
1429
1430
1431 /* Smedia Glamo 3362 */
1432
1433 /*
1434  * we crank down SD Card clock dynamically when GPS is powered
1435  */
1436
1437 static int gta02_glamo_mci_use_slow(void)
1438 {
1439         return neo1973_pm_gps_is_on();
1440 }
1441
1442 static struct glamofb_platform_data gta02_glamo_pdata = {
1443         .width          = 43,
1444         .height         = 58,
1445          /* 24.5MHz --> 40.816ns */
1446         .pixclock       = 40816,
1447         .left_margin    = 8,
1448         .right_margin   = 16,
1449         .upper_margin   = 2,
1450         .lower_margin   = 16,
1451         .hsync_len      = 8,
1452         .vsync_len      = 2,
1453         .fb_mem_size    = 0x400000, /* glamo has 8 megs of SRAM. we use 4 */
1454         .xres           = {
1455                 .min    = 240,
1456                 .max    = 640,
1457                 .defval = 480,
1458         },
1459         .yres           = {
1460                 .min    = 320,
1461                 .max    = 640,
1462                 .defval = 640,
1463         },
1464         .bpp            = {
1465                 .min    = 16,
1466                 .max    = 16,
1467                 .defval = 16,
1468         },
1469         //.spi_info     = &glamo_spi_cfg,
1470         .spigpio_info   = &glamo_spigpio_cfg,
1471
1472         /* glamo MMC function platform data */
1473         .glamo_set_mci_power = gta02_glamo_mmc_set_power,
1474         .glamo_mci_use_slow = gta02_glamo_mci_use_slow,
1475         .glamo_irq_is_wired = glamo_irq_is_wired,
1476         .mci_suspending = gta02_glamo_mci_suspending,
1477         .mci_all_dependencies_resumed =
1478                                       gta02_glamo_mci_all_dependencies_resumed,
1479 };
1480
1481 static struct resource gta02_glamo_resources[] = {
1482         [0] = {
1483                 .start  = S3C2410_CS1,
1484                 .end    = S3C2410_CS1 + 0x1000000 - 1,
1485                 .flags  = IORESOURCE_MEM,
1486         },
1487         [1] = {
1488                 .start  = GTA02_IRQ_3D,
1489                 .end    = GTA02_IRQ_3D,
1490                 .flags  = IORESOURCE_IRQ,
1491         },
1492         [2] = {
1493                 .start = GTA02v1_GPIO_3D_RESET,
1494                 .end   = GTA02v1_GPIO_3D_RESET,
1495         },
1496 };
1497
1498 static struct platform_device gta02_glamo_dev = {
1499         .name           = "glamo3362",
1500         .num_resources  = ARRAY_SIZE(gta02_glamo_resources),
1501         .resource       = gta02_glamo_resources,
1502         .dev            = {
1503                 .platform_data  = &gta02_glamo_pdata,
1504         },
1505 };
1506
1507 static void mangle_glamo_res_by_system_rev(void)
1508 {
1509         switch (system_rev) {
1510         case GTA02v1_SYSTEM_REV:
1511                 break;
1512         default:
1513                 gta02_glamo_resources[2].start = GTA02_GPIO_3D_RESET;
1514                 gta02_glamo_resources[2].end = GTA02_GPIO_3D_RESET;
1515                 break;
1516         }
1517
1518         switch (system_rev) {
1519         case GTA02v1_SYSTEM_REV:
1520         case GTA02v2_SYSTEM_REV:
1521         case GTA02v3_SYSTEM_REV:
1522         /* case GTA02v4_SYSTEM_REV: - FIXME: handle this later */
1523                 /* The hardware is missing a pull-up resistor and thus can't
1524                  * support the Smedia Glamo IRQ */
1525                 gta02_glamo_resources[1].start = 0;
1526                 gta02_glamo_resources[1].end = 0;
1527                 break;
1528         }
1529 }
1530
1531 static void __init gta02_map_io(void)
1532 {
1533         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
1534         s3c24xx_init_clocks(12000000);
1535         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
1536 }
1537
1538 static irqreturn_t gta02_modem_irq(int irq, void *param)
1539 {
1540         printk(KERN_DEBUG "modem wakeup interrupt\n");
1541         gta_gsm_interrupts++;
1542         return IRQ_HANDLED;
1543 }
1544
1545 static irqreturn_t ar6000_wow_irq(int irq, void *param)
1546 {
1547         printk(KERN_DEBUG "ar6000_wow interrupt\n");
1548         return IRQ_HANDLED;
1549 }
1550
1551 /*
1552  * hardware_ecc=1|0
1553  */
1554 static char hardware_ecc_str[4] __initdata = "";
1555
1556 static int __init hardware_ecc_setup(char *str)
1557 {
1558         if (str)
1559                 strlcpy(hardware_ecc_str, str, sizeof(hardware_ecc_str));
1560         return 1;
1561 }
1562
1563 __setup("hardware_ecc=", hardware_ecc_setup);
1564
1565 static void __init gta02_machine_init(void)
1566 {
1567         int rc;
1568
1569         /* set the panic callback to make AUX blink fast */
1570         panic_blink = gta02_panic_blink;
1571
1572         switch (system_rev) {
1573         case GTA02v6_SYSTEM_REV:
1574                 /* we need push-pull interrupt from motion sensors */
1575                 lis302_pdata[0].open_drain = 0;
1576                 lis302_pdata[1].open_drain = 0;
1577                 break;
1578         default:
1579                 break;
1580         }
1581
1582         spin_lock_init(&motion_irq_lock);
1583
1584         /* Glamo chip select optimization */
1585 /*       *((u32 *)(S3C2410_MEMREG(((1 + 1) << 2)))) = 0x1280; */
1586
1587         /* do not force soft ecc if we are asked to use hardware_ecc */
1588         if (hardware_ecc_str[0] == '1')
1589                 gta02_nand_info.software_ecc = 0;
1590
1591         s3c_device_usb.dev.platform_data = &gta02_usb_info;
1592         s3c_device_nand.dev.platform_data = &gta02_nand_info;
1593         s3c_device_sdi.dev.platform_data = &gta02_mmc_cfg;
1594
1595         /* Only GTA02v1 has a SD_DETECT GPIO.  Since the slot is not
1596          * hot-pluggable, this is not required anyway */
1597         switch (system_rev) {
1598         case GTA02v1_SYSTEM_REV:
1599                 break;
1600         default:
1601                 gta02_mmc_cfg.gpio_detect = 0;
1602                 break;
1603         }
1604
1605         /* acc sensor chip selects */
1606         s3c2410_gpio_setpin(S3C2410_GPD12, 1);
1607         s3c2410_gpio_cfgpin(S3C2410_GPD12, S3C2410_GPIO_OUTPUT);
1608         s3c2410_gpio_setpin(S3C2410_GPD13, 1);
1609         s3c2410_gpio_cfgpin(S3C2410_GPD13, S3C2410_GPIO_OUTPUT);
1610
1611         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
1612         set_s3c2410ts_info(&gta02_ts_cfg);
1613
1614         /* FIXME: hardcoded WLAN module power-up */
1615         s3c2410_gpio_cfgpin(GTA02_CHIP_PWD, S3C2410_GPIO_OUTPUT);
1616
1617         /* Power is down */
1618         s3c2410_gpio_setpin(GTA02_CHIP_PWD, 1);
1619         mdelay(100);
1620
1621         switch (system_rev) {
1622         case GTA02v1_SYSTEM_REV:
1623                 s3c2410_gpio_setpin(GTA02_CHIP_PWD, 0);
1624                 break;
1625         default:
1626                 /* Chip is in reset state */
1627                 s3c2410_gpio_setpin(GTA02_GPIO_nWLAN_RESET, 0);
1628                 s3c2410_gpio_cfgpin(GTA02_GPIO_nWLAN_RESET, S3C2410_GPIO_OUTPUT);
1629                 mdelay(100);
1630                 /* Power is up */
1631                 s3c2410_gpio_setpin(GTA02_CHIP_PWD, 0);
1632                 mdelay(100);
1633                 /* Chip is out of reset */
1634                 s3c2410_gpio_setpin(GTA02_GPIO_nWLAN_RESET, 1);
1635                 break;
1636         }
1637         mangle_glamo_res_by_system_rev();
1638         platform_device_register(&gta02_glamo_dev);
1639
1640         platform_device_register(&s3c_device_spi_acc);
1641         platform_device_register(&gta02_button_dev);
1642         platform_device_register(&gta02_pm_gsm_dev);
1643         platform_device_register(&gta02_pm_usbhost_dev);
1644
1645         mangle_pmu_pdata_by_system_rev();
1646         platform_device_register(&gta02_pmu_dev);
1647         platform_device_register(&gta02_vibrator_dev);
1648         platform_device_register(&gta02_led_dev);
1649
1650
1651         platform_device_register(&gta02_sdio_dev);
1652
1653         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
1654
1655 #ifdef CONFIG_GTA02_HDQ
1656         switch (system_rev) {
1657         case GTA02v5_SYSTEM_REV:
1658         case GTA02v6_SYSTEM_REV:
1659                 platform_device_register(&gta02_hdq_device);
1660                 platform_device_register(&bq27000_battery_device);
1661                 break;
1662         default:
1663                 break;
1664         }
1665 #endif
1666         s3c2410_pm_init();
1667
1668         /* Make sure the modem can wake us up */
1669         set_irq_type(GTA02_IRQ_MODEM, IRQ_TYPE_EDGE_RISING);
1670         rc = request_irq(GTA02_IRQ_MODEM, gta02_modem_irq, IRQF_DISABLED,
1671                          "modem", NULL);
1672         if (rc < 0)
1673                 printk(KERN_ERR "GTA02: can't request GSM modem wakeup IRQ\n");
1674         enable_irq_wake(GTA02_IRQ_MODEM);
1675
1676         /* Make sure the wifi module can wake us up*/
1677         set_irq_type(GTA02_IRQ_WLAN_GPIO1, IRQ_TYPE_EDGE_RISING);
1678         rc = request_irq(GTA02_IRQ_WLAN_GPIO1, ar6000_wow_irq, IRQF_DISABLED,
1679                         "ar6000", NULL);
1680
1681         if (rc < 0)
1682                 printk(KERN_ERR "GTA02: can't request ar6k wakeup IRQ\n");
1683         enable_irq_wake(GTA02_IRQ_WLAN_GPIO1);
1684 }
1685
1686 MACHINE_START(NEO1973_GTA02, "GTA02")
1687         .phys_io        = S3C2410_PA_UART,
1688         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
1689         .boot_params    = S3C2410_SDRAM_PA + 0x100,
1690         .map_io         = gta02_map_io,
1691         .init_irq       = s3c24xx_init_irq,
1692         .init_machine   = gta02_machine_init,
1693         .timer          = &s3c24xx_timer,
1694 MACHINE_END