8189724c02dd772a0be47fbca559fc2ba006809e
[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         u8 shifter = 0;
1053         int n;
1054         unsigned long flags;
1055         unsigned long other_cs;
1056
1057         local_irq_save(flags);
1058
1059         /*
1060          * Huh.. "quirk"... CS on this device is not really "CS" like you can
1061          * expect.  Instead when 1 it selects I2C interface mode.  Because we
1062          * have 2 devices on one interface, the "disabled" device when we talk
1063          * to an "enabled" device sees the clocks as I2C clocks, creating
1064          * havoc.
1065          *
1066          * I2C sees MOSI going LOW while CLK HIGH as a START action, we must
1067          * ensure this is never issued.
1068          */
1069
1070         if (&lis302_pdata_top == pdata)
1071                 other_cs = lis302_pdata_bottom.pin_chip_select;
1072         else
1073                 other_cs = lis302_pdata_top.pin_chip_select;
1074
1075         s3c2410_gpio_setpin(other_cs, 1);
1076         s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1077         s3c2410_gpio_setpin(pdata->pin_clk, 1);
1078         s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
1079
1080         /* send the register index, r/w and autoinc bits */
1081         for (n = 0; n < (tx_bytes << 3); n++) {
1082                 if (!(n & 7))
1083                         shifter = tx[n >> 3];
1084                 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1085                 s3c2410_gpio_setpin(pdata->pin_mosi, (shifter >> (7 - n)) & 1);
1086                 s3c2410_gpio_setpin(pdata->pin_clk, 1);
1087                 shifter <<= 1;
1088         }
1089
1090         for (n = 0; n < (rx_bytes << 3); n++) { /* 8 bits each */
1091                 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1092                 shifter <<= 1;
1093                 if (s3c2410_gpio_getpin(pdata->pin_miso))
1094                         shifter |= 1;
1095                 if ((n & 7) == 7)
1096                         rx[n >> 3] = shifter;
1097                 s3c2410_gpio_setpin(pdata->pin_clk, 1);
1098         }
1099         s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1100         s3c2410_gpio_setpin(other_cs, 1);
1101
1102         local_irq_restore(flags);
1103 }
1104
1105
1106 static int gta02_lis302dl_bitbang_read_reg(struct lis302dl_info *lis, u8 reg)
1107 {
1108         u8 data = 0xc0 | reg; /* read, autoincrement */
1109         unsigned long flags;
1110
1111         local_irq_save(flags);
1112
1113         __gta02_lis302dl_bitbang(lis, &data, 1, &data, 1);
1114
1115         local_irq_restore(flags);
1116
1117         return data;
1118 }
1119
1120 static void gta02_lis302dl_bitbang_write_reg(struct lis302dl_info *lis, u8 reg,
1121                                                                          u8 val)
1122 {
1123         u8 data[2] = { 0x00 | reg, val }; /* write, no autoincrement */
1124         unsigned long flags;
1125
1126         local_irq_save(flags);
1127
1128         __gta02_lis302dl_bitbang(lis, &data[0], 2, NULL, 0);
1129
1130         local_irq_restore(flags);
1131
1132 }
1133
1134
1135 static void gta02_lis302dl_bitbang_sample(struct lis302dl_info *lis)
1136 {
1137         u8 data = 0xc0 | LIS302DL_REG_OUT_X; /* read, autoincrement */
1138         u8 read[5];
1139         unsigned long flags;
1140
1141         local_irq_save(flags);
1142
1143         __gta02_lis302dl_bitbang(lis, &data, 1, &read[0], 5);
1144
1145         local_irq_restore(flags);
1146
1147         input_report_rel(lis->input_dev, REL_X, MG_PER_SAMPLE * (s8)read[0]);
1148         input_report_rel(lis->input_dev, REL_Y, MG_PER_SAMPLE * (s8)read[2]);
1149         input_report_rel(lis->input_dev, REL_Z, MG_PER_SAMPLE * (s8)read[4]);
1150
1151         input_sync(lis->input_dev);
1152 #ifdef DEBUG_SPEW_MS
1153         printk(KERN_INFO "%s: %d %d %d\n", pdata->name, read[0], read[2],
1154                                                                        read[4]);
1155 #endif
1156 }
1157
1158
1159 void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
1160 {
1161         struct lis302dl_platform_data *pdata = lis->pdata;
1162
1163         if (!resume) {
1164                  /*
1165                  * we don't want to power them with a high level
1166                  * because GSENSOR_3V3 is not up during suspend
1167                  */
1168                 s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
1169                 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1170                 s3c2410_gpio_setpin(pdata->pin_mosi, 0);
1171                 /* misnomer: it is a pullDOWN in 2442 */
1172                 s3c2410_gpio_pullup(pdata->pin_miso, 1);
1173                 return;
1174         }
1175
1176         /* back to normal */
1177         s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1178         s3c2410_gpio_setpin(pdata->pin_clk, 1);
1179         /* misnomer: it is a pullDOWN in 2442 */
1180         s3c2410_gpio_pullup(pdata->pin_miso, 0);
1181
1182         s3c2410_gpio_cfgpin(pdata->pin_chip_select, S3C2410_GPIO_OUTPUT);
1183         s3c2410_gpio_cfgpin(pdata->pin_clk, S3C2410_GPIO_OUTPUT);
1184         s3c2410_gpio_cfgpin(pdata->pin_mosi, S3C2410_GPIO_OUTPUT);
1185         s3c2410_gpio_cfgpin(pdata->pin_miso, S3C2410_GPIO_INPUT);
1186
1187 }
1188
1189
1190
1191 struct lis302dl_platform_data lis302_pdata_top = {
1192                 .name           = "lis302-1 (top)",
1193                 .pin_chip_select= S3C2410_GPD12,
1194                 .pin_clk        = S3C2410_GPG7,
1195                 .pin_mosi       = S3C2410_GPG6,
1196                 .pin_miso       = S3C2410_GPG5,
1197                 .interrupt      = GTA02_IRQ_GSENSOR_1,
1198                 .open_drain     = 1, /* altered at runtime by PCB rev */
1199                 .lis302dl_bitbang_read_sample = gta02_lis302dl_bitbang_sample,
1200                 .lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
1201                 .lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
1202                 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1203 };
1204
1205 struct lis302dl_platform_data lis302_pdata_bottom = {
1206                 .name           = "lis302-2 (bottom)",
1207                 .pin_chip_select= S3C2410_GPD13,
1208                 .pin_clk        = S3C2410_GPG7,
1209                 .pin_mosi       = S3C2410_GPG6,
1210                 .pin_miso       = S3C2410_GPG5,
1211                 .interrupt      = GTA02_IRQ_GSENSOR_2,
1212                 .open_drain     = 1, /* altered at runtime by PCB rev */
1213                 .lis302dl_bitbang_read_sample = gta02_lis302dl_bitbang_sample,
1214                 .lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
1215                 .lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
1216                 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1217 };
1218
1219
1220 static struct platform_device s3c_device_spi_acc1 = {
1221         .name             = "lis302dl",
1222         .id               = 1,
1223         .dev = {
1224                 .platform_data = &lis302_pdata_top,
1225         },
1226 };
1227
1228 static struct platform_device s3c_device_spi_acc2 = {
1229         .name             = "lis302dl",
1230         .id               = 2,
1231         .dev = {
1232                 .platform_data = &lis302_pdata_bottom,
1233         },
1234 };
1235
1236 static struct resource gta02_led_resources[] = {
1237         {
1238                 .name   = "gta02-power:orange",
1239                 .start  = GTA02_GPIO_PWR_LED1,
1240                 .end    = GTA02_GPIO_PWR_LED1,
1241         }, {
1242                 .name   = "gta02-power:blue",
1243                 .start  = GTA02_GPIO_PWR_LED2,
1244                 .end    = GTA02_GPIO_PWR_LED2,
1245         }, {
1246                 .name   = "gta02-aux:red",
1247                 .start  = GTA02_GPIO_AUX_LED,
1248                 .end    = GTA02_GPIO_AUX_LED,
1249         },
1250 };
1251
1252 struct platform_device gta02_led_dev = {
1253         .name           = "gta02-led",
1254         .num_resources  = ARRAY_SIZE(gta02_led_resources),
1255         .resource       = gta02_led_resources,
1256 };
1257
1258 static struct resource gta02_button_resources[] = {
1259         [0] = {
1260                 .start = GTA02_GPIO_AUX_KEY,
1261                 .end   = GTA02_GPIO_AUX_KEY,
1262         },
1263         [1] = {
1264                 .start = GTA02_GPIO_HOLD_KEY,
1265                 .end   = GTA02_GPIO_HOLD_KEY,
1266         },
1267         [2] = {
1268                 .start = GTA02_GPIO_JACK_INSERT,
1269                 .end   = GTA02_GPIO_JACK_INSERT,
1270         },
1271 };
1272
1273 static struct platform_device gta02_button_dev = {
1274         .name           = "neo1973-button",
1275         .num_resources  = ARRAY_SIZE(gta02_button_resources),
1276         .resource       = gta02_button_resources,
1277 };
1278
1279
1280 static struct platform_device gta02_pm_usbhost_dev = {
1281         .name           = "neo1973-pm-host",
1282 };
1283
1284
1285 /* USB */
1286 static struct s3c2410_hcd_info gta02_usb_info = {
1287         .port[0]        = {
1288                 .flags  = S3C_HCDFLG_USED,
1289         },
1290         .port[1]        = {
1291                 .flags  = 0,
1292         },
1293 };
1294
1295 static int glamo_irq_is_wired(void)
1296 {
1297         int rc;
1298         int count = 0;
1299
1300         /*
1301         * GTA02 S-Media IRQs prior to A5 are broken due to a lack of
1302         * a pullup on the INT# line.  Check for the bad behaviour.
1303         */
1304         s3c2410_gpio_setpin(S3C2410_GPG4, 0);
1305         s3c2410_gpio_cfgpin(S3C2410_GPG4, S3C2410_GPG4_OUTP);
1306         s3c2410_gpio_cfgpin(S3C2410_GPG4, S3C2410_GPG4_INP);
1307         /*
1308         * we force it low ourselves for a moment and resume being input.
1309         * If there is a pullup, it won't stay low for long.  But if the
1310         * level converter is there as on < A5 revision, the weak keeper
1311         * on the input of the LC will hold the line low indefinitiely
1312         */
1313         do
1314                 rc = s3c2410_gpio_getpin(S3C2410_GPG4);
1315         while ((!rc) && ((count++) < 10));
1316         if (rc) { /* it got pulled back up, it's good */
1317                 printk(KERN_INFO "Detected S-Media IRQ# pullup, "
1318                 "enabling interrupt\n");
1319                 return 0;
1320         } else  /* Gah we can't work with this level converter */
1321                 printk(KERN_WARNING "** Detected bad IRQ# circuit found"
1322                 " on pre-A5 GTA02: S-Media interrupt disabled **\n");
1323         return -ENODEV;
1324 }
1325
1326
1327 static void
1328 gta02_glamo_mmc_set_power(unsigned char power_mode, unsigned short vdd)
1329 {
1330         int mv = 1650;
1331         int timeout = 500;
1332
1333         printk(KERN_DEBUG "mmc_set_power(power_mode=%u, vdd=%u)\n",
1334                power_mode, vdd);
1335
1336         switch (system_rev) {
1337         case GTA02v1_SYSTEM_REV:
1338         case GTA02v2_SYSTEM_REV:
1339                 break;
1340         case GTA02v3_SYSTEM_REV:
1341         case GTA02v4_SYSTEM_REV:
1342         case GTA02v5_SYSTEM_REV:
1343         case GTA02v6_SYSTEM_REV:
1344                 switch (power_mode) {
1345                 case MMC_POWER_ON:
1346                 case MMC_POWER_UP:
1347                         /* depend on pcf50633 driver init + not suspended */
1348                         while (pcf50633_ready(pcf50633_global) && (timeout--))
1349                                 msleep(5);
1350
1351                         if (timeout < 0) {
1352                                 printk(KERN_ERR"gta02_glamo_mmc_set_power "
1353                                              "BAILING on timeout\n");
1354                                 return;
1355                         }
1356                         /* select and set the voltage */
1357                         if (vdd > 7)
1358                                 mv += 350 + 100 * (vdd - 8);
1359                         printk(KERN_INFO "SD power -> %dmV\n", mv);
1360                         pcf50633_voltage_set(pcf50633_global,
1361                                              PCF50633_REGULATOR_HCLDO, mv);
1362                         pcf50633_onoff_set(pcf50633_global,
1363                                            PCF50633_REGULATOR_HCLDO, 1);
1364                         break;
1365                 case MMC_POWER_OFF:
1366                         /* power off happens during suspend, when pcf50633 can
1367                          * be already gone and not coming back... just forget
1368                          * the action then because pcf50633 suspend already
1369                          * dealt with it, otherwise we spin forever
1370                          */
1371                         if (pcf50633_ready(pcf50633_global))
1372                                 return;
1373                         pcf50633_onoff_set(pcf50633_global,
1374                                            PCF50633_REGULATOR_HCLDO, 0);
1375                         break;
1376                 }
1377                 break;
1378         }
1379 }
1380
1381
1382 /* Smedia Glamo 3362 */
1383
1384 /*
1385  * we crank down SD Card clock dynamically when GPS is powered
1386  */
1387
1388 static int gta02_glamo_mci_use_slow(void)
1389 {
1390         return neo1973_pm_gps_is_on();
1391 }
1392
1393 static void gta02_glamo_external_reset(int level)
1394 {
1395         s3c2410_gpio_setpin(GTA02_GPIO_3D_RESET, level);
1396         s3c2410_gpio_cfgpin(GTA02_GPIO_3D_RESET, S3C2410_GPIO_OUTPUT);
1397 }
1398
1399 static struct glamofb_platform_data gta02_glamo_pdata = {
1400         .width          = 43,
1401         .height         = 58,
1402          /* 24.5MHz --> 40.816ns */
1403         .pixclock       = 40816,
1404         .left_margin    = 8,
1405         .right_margin   = 16,
1406         .upper_margin   = 2,
1407         .lower_margin   = 16,
1408         .hsync_len      = 8,
1409         .vsync_len      = 2,
1410         .fb_mem_size    = 0x400000, /* glamo has 8 megs of SRAM. we use 4 */
1411         .xres           = {
1412                 .min    = 240,
1413                 .max    = 640,
1414                 .defval = 480,
1415         },
1416         .yres           = {
1417                 .min    = 320,
1418                 .max    = 640,
1419                 .defval = 640,
1420         },
1421         .bpp            = {
1422                 .min    = 16,
1423                 .max    = 16,
1424                 .defval = 16,
1425         },
1426         //.spi_info     = &glamo_spi_cfg,
1427         .spigpio_info   = &glamo_spigpio_cfg,
1428
1429         /* glamo MMC function platform data */
1430         .glamo_set_mci_power = gta02_glamo_mmc_set_power,
1431         .glamo_mci_use_slow = gta02_glamo_mci_use_slow,
1432         .glamo_irq_is_wired = glamo_irq_is_wired,
1433         .glamo_external_reset = gta02_glamo_external_reset
1434 };
1435
1436 static struct resource gta02_glamo_resources[] = {
1437         [0] = {
1438                 .start  = S3C2410_CS1,
1439                 .end    = S3C2410_CS1 + 0x1000000 - 1,
1440                 .flags  = IORESOURCE_MEM,
1441         },
1442         [1] = {
1443                 .start  = GTA02_IRQ_3D,
1444                 .end    = GTA02_IRQ_3D,
1445                 .flags  = IORESOURCE_IRQ,
1446         },
1447         [2] = {
1448                 .start = GTA02v1_GPIO_3D_RESET,
1449                 .end   = GTA02v1_GPIO_3D_RESET,
1450         },
1451 };
1452
1453 static struct platform_device gta02_glamo_dev = {
1454         .name           = "glamo3362",
1455         .num_resources  = ARRAY_SIZE(gta02_glamo_resources),
1456         .resource       = gta02_glamo_resources,
1457         .dev            = {
1458                 .platform_data  = &gta02_glamo_pdata,
1459         },
1460 };
1461
1462 static void mangle_glamo_res_by_system_rev(void)
1463 {
1464         switch (system_rev) {
1465         case GTA02v1_SYSTEM_REV:
1466                 break;
1467         default:
1468                 gta02_glamo_resources[2].start = GTA02_GPIO_3D_RESET;
1469                 gta02_glamo_resources[2].end = GTA02_GPIO_3D_RESET;
1470                 break;
1471         }
1472
1473         switch (system_rev) {
1474         case GTA02v1_SYSTEM_REV:
1475         case GTA02v2_SYSTEM_REV:
1476         case GTA02v3_SYSTEM_REV:
1477         /* case GTA02v4_SYSTEM_REV: - FIXME: handle this later */
1478                 /* The hardware is missing a pull-up resistor and thus can't
1479                  * support the Smedia Glamo IRQ */
1480                 gta02_glamo_resources[1].start = 0;
1481                 gta02_glamo_resources[1].end = 0;
1482                 break;
1483         }
1484 }
1485
1486 static void __init gta02_map_io(void)
1487 {
1488         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
1489         s3c24xx_init_clocks(12000000);
1490         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
1491 }
1492
1493 static irqreturn_t gta02_modem_irq(int irq, void *param)
1494 {
1495         printk(KERN_DEBUG "modem wakeup interrupt\n");
1496         gta_gsm_interrupts++;
1497         return IRQ_HANDLED;
1498 }
1499
1500 static irqreturn_t ar6000_wow_irq(int irq, void *param)
1501 {
1502         printk(KERN_DEBUG "ar6000_wow interrupt\n");
1503         return IRQ_HANDLED;
1504 }
1505
1506 /*
1507  * hardware_ecc=1|0
1508  */
1509 static char hardware_ecc_str[4] __initdata = "";
1510
1511 static int __init hardware_ecc_setup(char *str)
1512 {
1513         if (str)
1514                 strlcpy(hardware_ecc_str, str, sizeof(hardware_ecc_str));
1515         return 1;
1516 }
1517
1518 __setup("hardware_ecc=", hardware_ecc_setup);
1519
1520 /* these are the guys that don't need to be children of PMU */
1521
1522 static struct platform_device *gta02_devices[] __initdata = {
1523         &gta02_version_device,
1524         &s3c_device_usb,
1525         &s3c_device_wdt,
1526         &gta02_memconfig_device,
1527         &s3c_device_sdi,
1528         &s3c_device_usbgadget,
1529         &s3c_device_nand,
1530         &gta02_nor_flash,
1531
1532         &sc32440_fiq_device,
1533         &s3c24xx_pwm_device,
1534         &gta02_led_dev,
1535         &gta02_pm_wlan_dev, /* not dependent on PMU */
1536         &gta02_pmu_dev,
1537
1538         &s3c_device_iis,
1539         &s3c_device_i2c0,
1540 };
1541
1542 /* these guys DO need to be children of PMU */
1543
1544 static struct platform_device *gta02_devices_pmu_children[] = {
1545         &gta02_glamo_dev, /* glamo-mci power handling depends on PMU */
1546         &s3c_device_ts, /* input 1 */
1547         &gta01_pm_gps_dev,
1548         &gta01_pm_bt_dev,
1549         &gta02_pm_gsm_dev,
1550         &gta02_pm_usbhost_dev,
1551         &s3c_device_spi_acc1, /* input 2 */
1552         &s3c_device_spi_acc2, /* input 3 */
1553         &gta02_button_dev, /* input 4 */
1554         &gta02_resume_reason_device,
1555 };
1556
1557 /* this is called when pc50633 is probed, unfortunately quite late in the
1558  * day since it is an I2C bus device.  Here we can belatedly define some
1559  * platform devices with the advantage that we can mark the pcf50633 as the
1560  * parent.  This makes them get suspended and resumed with their parent
1561  * the pcf50633 still around.
1562  */
1563
1564 static void gta02_pcf50633_attach_child_devices(struct device *parent_device)
1565 {
1566         int n;
1567
1568         for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
1569                 gta02_devices_pmu_children[n]->dev.parent = parent_device;
1570
1571         mangle_glamo_res_by_system_rev();
1572         platform_add_devices(gta02_devices_pmu_children,
1573                                         ARRAY_SIZE(gta02_devices_pmu_children));
1574 }
1575
1576
1577 static void __init gta02_machine_init(void)
1578 {
1579         int rc;
1580
1581         /* set the panic callback to make AUX blink fast */
1582         panic_blink = gta02_panic_blink;
1583
1584         switch (system_rev) {
1585         case GTA02v6_SYSTEM_REV:
1586                 /* we need push-pull interrupt from motion sensors */
1587                 lis302_pdata_top.open_drain = 0;
1588                 lis302_pdata_bottom.open_drain = 0;
1589                 break;
1590         default:
1591                 break;
1592         }
1593
1594         spin_lock_init(&motion_irq_lock);
1595
1596         /* Glamo chip select optimization */
1597 /*       *((u32 *)(S3C2410_MEMREG(((1 + 1) << 2)))) = 0x1280; */
1598
1599         /* do not force soft ecc if we are asked to use hardware_ecc */
1600         if (hardware_ecc_str[0] == '1')
1601                 gta02_nand_info.software_ecc = 0;
1602
1603         s3c_device_usb.dev.platform_data = &gta02_usb_info;
1604         s3c_device_nand.dev.platform_data = &gta02_nand_info;
1605
1606         /* acc sensor chip selects */
1607         s3c2410_gpio_setpin(S3C2410_GPD12, 1);
1608         s3c2410_gpio_cfgpin(S3C2410_GPD12, S3C2410_GPIO_OUTPUT);
1609         s3c2410_gpio_setpin(S3C2410_GPD13, 1);
1610         s3c2410_gpio_cfgpin(S3C2410_GPD13, S3C2410_GPIO_OUTPUT);
1611
1612         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
1613         s3c_i2c0_set_platdata(NULL);
1614         set_s3c2410ts_info(&gta02_ts_cfg);
1615         
1616         mangle_glamo_res_by_system_rev();
1617
1618         mangle_pmu_pdata_by_system_rev();
1619
1620         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
1621
1622         s3c2410_pm_init();
1623
1624         /* Make sure the modem can wake us up */
1625         set_irq_type(GTA02_IRQ_MODEM, IRQ_TYPE_EDGE_RISING);
1626         rc = request_irq(GTA02_IRQ_MODEM, gta02_modem_irq, IRQF_DISABLED,
1627                          "modem", NULL);
1628         if (rc < 0)
1629                 printk(KERN_ERR "GTA02: can't request GSM modem wakeup IRQ\n");
1630         enable_irq_wake(GTA02_IRQ_MODEM);
1631
1632         /* Make sure the wifi module can wake us up*/
1633         set_irq_type(GTA02_IRQ_WLAN_GPIO1, IRQ_TYPE_EDGE_RISING);
1634         rc = request_irq(GTA02_IRQ_WLAN_GPIO1, ar6000_wow_irq, IRQF_DISABLED,
1635                         "ar6000", NULL);
1636
1637         if (rc < 0)
1638                 printk(KERN_ERR "GTA02: can't request ar6k wakeup IRQ\n");
1639         enable_irq_wake(GTA02_IRQ_WLAN_GPIO1);
1640 }
1641
1642 void DEBUG_LED(int n)
1643 {
1644 //      int *p = NULL;
1645         switch (n) {
1646         case 0:
1647                 neo1973_gpb_setpin(GTA02_GPIO_PWR_LED1, 1);
1648                 break;
1649         case 1:
1650                 neo1973_gpb_setpin(GTA02_GPIO_PWR_LED2, 1);
1651                 break;
1652         default:
1653                 neo1973_gpb_setpin(GTA02_GPIO_AUX_LED, 1);
1654                 break;
1655         }
1656 //      printk(KERN_ERR"die %d\n", *p);
1657 }
1658 EXPORT_SYMBOL_GPL(DEBUG_LED);
1659
1660 MACHINE_START(NEO1973_GTA02, "GTA02")
1661         .phys_io        = S3C2410_PA_UART,
1662         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
1663         .boot_params    = S3C2410_SDRAM_PA + 0x100,
1664         .map_io         = gta02_map_io,
1665         .init_irq       = s3c24xx_init_irq,
1666         .init_machine   = gta02_machine_init,
1667         .timer          = &s3c24xx_timer,
1668 MACHINE_END