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