Fix wrong commit
[kernel.git] / arch / arm / mach-s3c2410 / mach-gta01.c
1 /*
2  * linux/arch/arm/mach-s3c2410/mach-gta01.c
3  *
4  * S3C2410 Machine Support for the FIC Neo1973 GTA01
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/timer.h>
32 #include <linux/init.h>
33 #include <linux/workqueue.h>
34 #include <linux/platform_device.h>
35 #include <linux/i2c.h>
36 #include <linux/serial_core.h>
37 #include <mach/ts.h>
38 #include <linux/spi/spi.h>
39 #include <linux/spi/spi_bitbang.h>
40 #include <linux/mmc/mmc.h>
41 #include <linux/mmc/host.h>
42
43 #include <linux/mtd/mtd.h>
44 #include <linux/mtd/nand.h>
45 #include <linux/mtd/nand_ecc.h>
46 #include <linux/mtd/partitions.h>
47
48 #include <linux/mmc/host.h>
49
50 #include <linux/mfd/pcf50606/core.h>
51 #include <linux/mfd/pcf50606/pmic.h>
52 #include <linux/mfd/pcf50606/mbc.h>
53 #include <linux/mfd/pcf50606/adc.h>
54
55 #include <linux/gta01_battery.h>
56
57 #include <linux/regulator/machine.h>
58 #include <linux/regulator/consumer.h>
59
60
61 #include <asm/mach/arch.h>
62 #include <asm/mach/map.h>
63 #include <asm/mach/irq.h>
64
65 #include <mach/hardware.h>
66 #include <mach/io.h>
67 #include <asm/irq.h>
68 #include <asm/mach-types.h>
69
70 #include <mach/regs-gpio.h>
71 #include <mach/fb.h>
72 #include <mach/spi.h>
73 #include <mach/spi-gpio.h>
74 #include <mach/cpu.h>
75
76 #include <mach/gta01.h>
77
78 #include <plat/regs-serial.h>
79 #include <plat/nand.h>
80 #include <plat/devs.h>
81 #include <plat/cpu.h>
82 #include <plat/pm.h>
83 #include <plat/udc.h>
84 #include <plat/iic.h>
85 #include <plat/mci.h>
86 #include <asm/plat-s3c24xx/neo1973.h>
87 #include <plat/usb-control.h>
88 #include <mach/neo1973-pm-gsm.h>
89
90 #include <linux/jbt6k74.h>
91
92 #include <../drivers/input/touchscreen/ts_filter_chain.h>
93 #ifdef CONFIG_TOUCHSCREEN_FILTER
94 #include <../drivers/input/touchscreen/ts_filter_linear.h>
95 #include <../drivers/input/touchscreen/ts_filter_mean.h>
96 #include <../drivers/input/touchscreen/ts_filter_median.h>
97 #include <../drivers/input/touchscreen/ts_filter_group.h>
98 #endif
99
100
101 static struct map_desc gta01_iodesc[] __initdata = {
102         {
103                 .virtual        = 0xe0000000,
104                 .pfn            = __phys_to_pfn(S3C2410_CS3+0x01000000),
105                 .length         = SZ_1M,
106                 .type           = MT_DEVICE
107         },
108 };
109
110 #define UCON S3C2410_UCON_DEFAULT
111 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
112 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
113 /* UFCON for the gta01 sets the FIFO trigger level at 4, not 8 */
114 #define UFCON_GTA01_PORT0 S3C2410_UFCON_FIFOMODE
115
116 static struct s3c2410_uartcfg gta01_uartcfgs[] = {
117         [0] = {
118                 .hwport      = 0,
119                 .flags       = 0,
120                 .ucon        = UCON,
121                 .ulcon       = ULCON,
122                 .ufcon       = UFCON_GTA01_PORT0,
123         },
124         [1] = {
125                 .hwport      = 1,
126                 .flags       = 0,
127                 .ucon        = UCON,
128                 .ulcon       = ULCON,
129                 .ufcon       = UFCON,
130         },
131 };
132
133 /* TODO */
134 static void gta01_pmu_event_callback(struct pcf50606 *pcf, int irq)
135 {
136         /*TODO : Handle ACD here */
137 }
138
139 /* FIXME : Goes away when ACD is handled above */
140 #if 0 
141 static int pmu_callback(struct device *dev, unsigned int feature,
142                         enum pmu_event event)
143 {
144         switch (feature) {
145         case PCF50606_FEAT_ACD:
146                 switch (event) {
147                 case PMU_EVT_INSERT:
148                         pcf50606_charge_fast(pcf50606_global, 1);
149                         break;
150                 case PMU_EVT_REMOVE:
151                         pcf50606_charge_fast(pcf50606_global, 0);
152                         break;
153                 default:
154                         break;
155                 }
156                 break;
157         default:
158                 break;
159         }
160
161         return 0;
162 }
163 #endif
164
165 struct pcf50606 *gta01_pcf;
166
167 static struct platform_device gta01_pm_gsm_dev = {
168         .name           = "neo1973-pm-gsm",
169 };
170
171 static struct platform_device gta01_pm_bt_dev = {
172         .name           = "neo1973-pm-bt",
173 };
174 static struct platform_device gta01_pm_gps_dev = {
175         .name           = "neo1973-pm-gps",
176 };
177
178 static struct regulator_consumer_supply ioreg_consumers[] = {
179         {
180                 .dev = &gta01_pm_gps_dev.dev,
181                 .supply = "GPS_2V8",
182         },
183 };
184
185 static struct regulator_consumer_supply d1reg_consumers[] = {
186         {
187                 .dev = &gta01_pm_gps_dev.dev,
188                 .supply = "GPS_3V",
189         },
190         {
191                 .dev = &gta01_pm_bt_dev.dev,
192                 .supply = "BT_3V1",
193         },
194 };
195
196 static struct regulator_consumer_supply dcd_consumers[] = {
197         {
198                 .dev = &gta01_pm_gps_dev.dev,
199                 .supply = "GPS_3V3",
200         },
201         {
202                 .dev = &gta01_pm_gps_dev.dev,
203                 .supply = "GPS_1V5",
204         },
205 };
206
207 static struct regulator_consumer_supply d2reg_consumers[] = {
208         {
209                 .dev = &gta01_pm_gps_dev.dev,
210                 .supply = "GPS_2V5",
211         },
212         {
213                 .dev = &s3c_device_sdi.dev,
214                 .supply = "SD_3V3",
215         },
216 };
217
218 static int gta01_bat_get_charging_status(void)
219 {
220         struct pcf50606 *pcf = gta01_pcf;
221         u8 mbcc1, chgmod;
222
223         mbcc1 = pcf50606_reg_read(pcf, PCF50606_REG_MBCC1);
224         chgmod = mbcc1 & PCF50606_MBCC1_CHGMOD_MASK;
225
226         if (chgmod == PCF50606_MBCC1_CHGMOD_IDLE)
227                 return 0;
228         else
229                 return 1;
230 }
231
232 static int gta01_bat_get_voltage(void)
233 {
234         struct pcf50606 *pcf = gta01_pcf;
235         u16 adc, mv = 0;
236
237         adc = pcf50606_adc_sync_read(pcf, PCF50606_ADCMUX_BATVOLT_RES);
238         mv = (adc * 6000) / 1024;
239         
240         return mv * 1000;
241 }
242
243 static int gta01_bat_get_current(void)
244 {
245         struct pcf50606 *pcf = gta01_pcf;
246         u16 adc_battvolt, adc_adcin1;
247         s32 res;
248         
249         adc_battvolt = pcf50606_adc_sync_read(pcf, PCF50606_ADCMUX_BATVOLT_SUBTR);
250         adc_adcin1 = pcf50606_adc_sync_read(pcf, PCF50606_ADCMUX_ADCIN1_SUBTR);
251         res = (adc_battvolt - adc_adcin1) * 2400;
252
253         /*rsense is 220 milli */
254         return (res * 1000) / (220 * 1024) * 1000;
255 }
256
257 static struct gta01_bat_platform_data gta01_bat_pdata = {
258         .get_charging_status = gta01_bat_get_charging_status,
259         .get_voltage = gta01_bat_get_voltage,
260         .get_current = gta01_bat_get_current,
261 };
262
263 struct platform_device gta01_bat = {
264         .name = "gta01_battery",
265         .id = -1,
266         .dev = {
267                 .platform_data = &gta01_bat_pdata,
268         }
269 };
270
271 static void gta01_pcf_probe_done(struct pcf50606 *pcf)
272 {
273         gta01_pcf = pcf;
274         gta01_bat.dev.parent = pcf->dev;
275         platform_device_register(&gta01_bat);
276 }
277
278 static int gps_registered_regulators = 0;
279
280 static void gta01_pmu_regulator_registered(struct pcf50606 *pcf, int id)
281 {
282         switch(id) {
283                 case PCF50606_REGULATOR_D1REG:
284                         platform_device_register(&gta01_pm_bt_dev);
285                         gps_registered_regulators++;
286                         break;
287                 case PCF50606_REGULATOR_D2REG:
288                         gps_registered_regulators++;
289                         break;
290                 case PCF50606_REGULATOR_IOREG:
291                 case PCF50606_REGULATOR_DCD:
292                         gps_registered_regulators++;
293                         break;
294         }
295
296         /* All GPS related regulators registered ? */
297         if (gps_registered_regulators == 4)
298                 platform_device_register(&gta01_pm_gps_dev);
299                         
300 }
301
302 static struct pcf50606_platform_data gta01_pcf_pdata = {
303         .resumers = {
304                         [0] =   PCF50606_INT1_ALARM |
305                                 PCF50606_INT1_ONKEYF |
306                                 PCF50606_INT1_EXTONR,
307                         [1] =   PCF50606_INT2_CHGWD10S |
308                                 PCF50606_INT2_CHGPROT |
309                                 PCF50606_INT2_CHGERR,
310                         [2] =   PCF50606_INT3_LOWBAT |
311                                 PCF50606_INT3_HIGHTMP |
312                                 PCF50606_INT3_ACDINS,
313         },
314         .mbc_event_callback = gta01_pmu_event_callback,
315         .reg_init_data = {
316                 [PCF50606_REGULATOR_D1REG] = {
317                         .constraints = {
318                                 .min_uV = 3000000,
319                                 .max_uV = 3150000,
320                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
321                                 .apply_uV = 1,
322                         },
323                         .num_consumer_supplies = ARRAY_SIZE(d1reg_consumers),
324                         .consumer_supplies = d1reg_consumers,
325                 },
326                 
327                 [PCF50606_REGULATOR_D2REG] = {
328                         .constraints = {
329                                 .min_uV = 1650000,
330                                 .max_uV = 3300000,
331                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
332                                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
333                                 .apply_uV = 1,
334                         },
335                         .num_consumer_supplies = ARRAY_SIZE(d2reg_consumers),
336                         .consumer_supplies = d2reg_consumers,
337
338                 },
339
340                 [PCF50606_REGULATOR_D3REG] = {
341                         .constraints = {
342                                 .min_uV = 1800000,
343                                 .max_uV = 2100000,
344                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
345                                 .state_mem = {
346                                         .enabled = 1,
347                                 },
348                         },
349                         .num_consumer_supplies = 0,
350                 },
351
352                 [PCF50606_REGULATOR_DCD] = {
353                         .constraints = {
354                                 .min_uV = 1500000,
355                                 .max_uV = 1500000,
356                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
357                                 .apply_uV = 1,
358                         },
359                         .num_consumer_supplies = ARRAY_SIZE(dcd_consumers),
360                         .consumer_supplies = dcd_consumers,
361                 },
362
363                 [PCF50606_REGULATOR_DCDE] = {
364                         .constraints = {
365                                 .min_uV = 3300000,
366                                 .max_uV = 3300000,
367                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
368                                 .apply_uV = 1,
369                                 .state_mem = {
370                                         .enabled = 1,
371                                 },
372                         },
373                         .num_consumer_supplies = 0,
374                 },
375
376                 [PCF50606_REGULATOR_DCUD] = {
377                         .constraints = {
378                                 .min_uV = 2100000,
379                                 .max_uV = 2100000,
380                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
381                                 .apply_uV = 1,
382                                 .state_mem = {
383                                         .enabled = 1,
384                                 },
385                         },
386                         .num_consumer_supplies = 0,
387                 },
388                 
389                 [PCF50606_REGULATOR_IOREG] = {
390                         .constraints = {
391                                 .min_uV = 3300000,
392                                 .max_uV = 3300000,
393                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
394                                 .apply_uV = 1,
395                         },
396                         .num_consumer_supplies = ARRAY_SIZE(ioreg_consumers),
397                         .consumer_supplies = ioreg_consumers,
398
399                 },
400                 
401                 [PCF50606_REGULATOR_LPREG] = {
402                         .constraints = {
403                                 .min_uV = 3300000,
404                                 .max_uV = 3300000,
405                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
406                                 .apply_uV = 1,
407                         },
408                         .num_consumer_supplies = 0,
409                 },
410         },
411         .probe_done = gta01_pcf_probe_done,
412         .regulator_registered = gta01_pmu_regulator_registered,
413 };
414
415 static void cfg_pmu_vrail(struct regulator_init_data *vrail,
416                           unsigned int suspend_on, unsigned int min,
417                           unsigned int max)
418 {
419         vrail->constraints.state_mem.enabled = suspend_on;
420         vrail->constraints.min_uV = min;
421         vrail->constraints.max_uV = min;
422         vrail->constraints.apply_uV = 1;
423 }
424
425 static void mangle_pmu_pdata_by_system_rev(void)
426 {
427         struct regulator_init_data *reg_init_data;
428
429         reg_init_data = gta01_pcf_pdata.reg_init_data;
430
431         switch (S3C_SYSTEM_REV_ATAG) {
432         case GTA01Bv4_SYSTEM_REV:
433
434                 /* FIXME : gta01_pcf_pdata.used_features |= PCF50606_FEAT_ACD; */
435                 break;
436         case GTA01Bv3_SYSTEM_REV:
437         case GTA01Bv2_SYSTEM_REV:
438                 reg_init_data[PCF50606_REGULATOR_D3REG].constraints.state_mem.enabled = 1;
439                 break;
440         case GTA01v4_SYSTEM_REV:
441                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCUD],
442                               1, 18000000, 1800000);
443                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D1REG],
444                               0, 3000000, 3000000);
445                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D3REG],
446                               0, 2800000, 2800000);
447                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCD],
448                               0, 3500000, 3500000);
449                 break;
450         case GTA01v3_SYSTEM_REV:
451                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D1REG],
452                               0, 3000000, 3000000);
453                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D2REG],
454                               0, 3300000, 3300000);
455                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D3REG],
456                               0, 3300000, 3300000);
457                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCD],
458                               0, 3300000, 3300000);
459                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCUD],
460                               1, 1800000, 1800000);
461                 cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_IOREG],
462                               0, 2800000, 2800000);
463                 break;
464         }
465 }
466
467 static void gta01_power_off(void)
468 {
469         pcf50606_reg_write(gta01_pcf, PCF50606_REG_OOCC1,
470                         PCF50606_OOCC1_GOSTDBY);
471 }
472
473 /* LCD driver info */
474
475 /* Configuration for 480x640 toppoly TD028TTEC1.
476  * Do not mark this as __initdata or it will break! */
477 static struct s3c2410fb_display gta01_displays[] =  {
478         {
479                 .type           = S3C2410_LCDCON1_TFT,
480                 .width          = 43,
481                 .height         = 58,
482                 .xres           = 480,
483                 .yres           = 640,
484                 .bpp            = 16,
485
486                 .pixclock       = 40000,        /* HCLK/4 */
487                 .left_margin    = 104,
488                 .right_margin   = 8,
489                 .hsync_len      = 8,
490                 .upper_margin   = 2,
491                 .lower_margin   = 16,
492                 .vsync_len      = 2,
493                 .lcdcon5        = S3C2410_LCDCON5_FRM565 |
494                                   S3C2410_LCDCON5_INVVCLK |
495                                   S3C2410_LCDCON5_INVVLINE |
496                                   S3C2410_LCDCON5_INVVFRAME |
497                                   S3C2410_LCDCON5_PWREN |
498                                   S3C2410_LCDCON5_HWSWP,
499         },
500         {
501                 .type           = S3C2410_LCDCON1_TFT,
502                 .width          = 43,
503                 .height         = 58,
504                 .xres           = 480,
505                 .yres           = 640,
506                 .bpp            = 32,
507
508                 .pixclock       = 40000,        /* HCLK/4 */
509                 .left_margin    = 104,
510                 .right_margin   = 8,
511                 .hsync_len      = 8,
512                 .upper_margin   = 2,
513                 .lower_margin   = 16,
514                 .vsync_len      = 2,
515                 .lcdcon5        = S3C2410_LCDCON5_FRM565 |
516                                   S3C2410_LCDCON5_INVVCLK |
517                                   S3C2410_LCDCON5_INVVLINE |
518                                   S3C2410_LCDCON5_INVVFRAME |
519                                   S3C2410_LCDCON5_PWREN |
520                                   S3C2410_LCDCON5_HWSWP,
521         },
522         {
523                 .type           = S3C2410_LCDCON1_TFT,
524                 .width          = 43,
525                 .height         = 58,
526                 .xres           = 240,
527                 .yres           = 320,
528                 .bpp            = 16,
529
530                 .pixclock       = 40000,        /* HCLK/4 */
531                 .left_margin    = 104,
532                 .right_margin   = 8,
533                 .hsync_len      = 8,
534                 .upper_margin   = 2,
535                 .lower_margin   = 16,
536                 .vsync_len      = 2,
537                 .lcdcon5        = S3C2410_LCDCON5_FRM565 |
538                                   S3C2410_LCDCON5_INVVCLK |
539                                   S3C2410_LCDCON5_INVVLINE |
540                                   S3C2410_LCDCON5_INVVFRAME |
541                                   S3C2410_LCDCON5_PWREN |
542                                   S3C2410_LCDCON5_HWSWP,
543         },
544 };
545
546 static struct s3c2410fb_mach_info gta01_lcd_cfg __initdata = {
547         .displays       = gta01_displays,
548         .num_displays   = ARRAY_SIZE(gta01_displays),
549         .default_display = 0,
550
551         .lpcsel         = ((0xCE6) & ~7) | 1<<4,
552 };
553
554 static struct platform_device *gta01_devices[] __initdata = {
555         &s3c_device_usb,
556         &s3c_device_lcd,
557         &s3c_device_wdt,
558         &s3c_device_i2c0,
559         &s3c_device_iis,
560         &s3c_device_sdi,
561         &s3c_device_usbgadget,
562         &s3c_device_nand,
563         &s3c_device_adc,
564         &s3c_device_ts,
565 };
566
567 static struct s3c2410_nand_set gta01_nand_sets[] = {
568         [0] = {
569                 .name           = "neo1973-nand",
570                 .nr_chips       = 1,
571                 .flags          = S3C2410_NAND_BBT,
572         },
573 };
574
575 static struct s3c2410_platform_nand gta01_nand_info = {
576         .tacls          = 20,
577         .twrph0         = 60,
578         .twrph1         = 20,
579         .nr_sets        = ARRAY_SIZE(gta01_nand_sets),
580         .sets           = gta01_nand_sets,
581 };
582
583 static struct regulator *s3c_sdi_regulator;
584
585 static void gta01_mmc_set_power(unsigned char power_mode, unsigned short vdd)
586 {
587         int bit;
588         int mv = 1700; /* 1.7V for MMC_VDD_165_195 */
589         struct regulator *regulator;
590
591         printk(KERN_DEBUG "mmc_set_power(power_mode=%u, vdd=%u)\n",
592                power_mode, vdd);
593
594         if (!s3c_sdi_regulator) {
595                 s3c_sdi_regulator =
596                         regulator_get(&s3c_device_sdi.dev, "SD_3V3");
597                 if (!s3c_sdi_regulator) {
598                         printk(KERN_ERR "gta01_mmc_set_power : Cannot get regulator");
599                         return;
600                 }
601         }
602
603         regulator = s3c_sdi_regulator;
604
605                 return;
606         switch (S3C_SYSTEM_REV_ATAG) {
607         case GTA01v3_SYSTEM_REV:
608                 switch (power_mode) {
609                 case MMC_POWER_OFF:
610                         regulator_disable(regulator);
611                         break;
612                 case MMC_POWER_ON:
613                         /* translate MMC_VDD_* VDD bit to mv */
614                         for (bit = 8; bit != 24; bit++)
615                                 if (vdd == (1 << bit))
616                                         mv += 100 * (bit - 4);
617                         regulator_set_voltage(regulator, mv * 1000, mv * 10000);
618                         break;
619                 case MMC_POWER_UP:
620                         regulator_enable(regulator);
621                         break;
622                 }
623                 break;
624         case GTA01v4_SYSTEM_REV:
625         case GTA01Bv2_SYSTEM_REV:
626         case GTA01Bv3_SYSTEM_REV:
627         case GTA01Bv4_SYSTEM_REV:
628                 switch (power_mode) {
629                 case MMC_POWER_OFF:
630                         neo1973_gpb_setpin(GTA01_GPIO_SDMMC_ON, 1);
631                         break;
632                 case MMC_POWER_ON:
633                         neo1973_gpb_setpin(GTA01_GPIO_SDMMC_ON, 0);
634                         break;
635                 }
636                 break;
637         }
638         
639         if (regulator)
640                 regulator_put(regulator);
641 }
642
643 static struct s3c24xx_mci_pdata gta01_mmc_cfg = {
644         .gpio_detect    = GTA01_GPIO_nSD_DETECT,
645         .set_power      = &gta01_mmc_set_power, 
646         .ocr_avail      = MMC_VDD_165_195|MMC_VDD_20_21|
647                           MMC_VDD_21_22|MMC_VDD_22_23|MMC_VDD_23_24|
648                           MMC_VDD_24_25|MMC_VDD_25_26|MMC_VDD_26_27|
649                           MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
650                           MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33,
651 };
652
653 static void gta01_udc_command(enum s3c2410_udc_cmd_e cmd)
654 {
655         printk(KERN_DEBUG "%s(%d)\n", __func__, cmd);
656
657         switch (cmd) {
658         case S3C2410_UDC_P_ENABLE:
659                 neo1973_gpb_setpin(GTA01_GPIO_USB_PULLUP, 1);
660                 break;
661         case S3C2410_UDC_P_DISABLE:
662                 neo1973_gpb_setpin(GTA01_GPIO_USB_PULLUP, 0);
663                 break;
664         default:
665                 break;
666         }
667 }
668
669 /* use a work queue, since I2C API inherently schedules
670  * and we get called in hardirq context from UDC driver */
671
672 struct vbus_draw {
673         struct work_struct work;
674         int ma;
675 };
676 static struct vbus_draw gta01_udc_vbus_drawer;
677
678 static void __gta01_udc_vbus_draw(struct work_struct *work)
679 {
680         /*
681          * This is a fix to work around boot-time ordering problems if the
682          * s3c2410_udc is initialized before the pcf50606 driver has defined
683          * pcf50606_global
684          */
685         if (!gta01_pcf)
686                 return;
687
688         if (gta01_udc_vbus_drawer.ma >= 500) {
689                 /* enable fast charge */
690                 printk(KERN_DEBUG "udc: enabling fast charge\n");
691                 pcf50606_charge_fast(gta01_pcf, 1);
692         } else {
693                 /* disable fast charge */
694                 printk(KERN_DEBUG "udc: disabling fast charge\n");
695                 pcf50606_charge_fast(gta01_pcf, 0);
696         }
697 }
698
699 static void gta01_udc_vbus_draw(unsigned int ma)
700 {
701         gta01_udc_vbus_drawer.ma = ma;
702         schedule_work(&gta01_udc_vbus_drawer.work);
703 }
704
705 static struct s3c2410_udc_mach_info gta01_udc_cfg = {
706         .vbus_draw      = gta01_udc_vbus_draw,
707 };
708
709 /* Touchscreen configuration. */
710
711 #ifdef CONFIG_TOUCHSCREEN_FILTER
712 const static struct ts_filter_group_configuration gta01_ts_group = {
713         .length = 12,
714         .close_enough = 10,
715         .threshold = 6,         /* At least half of the points in a group. */
716         .attempts = 10,
717 };
718
719 const static struct ts_filter_median_configuration gta01_ts_median = {
720         .extent = 20,
721         .decimation_below = 3,
722         .decimation_threshold = 8 * 3,
723         .decimation_above = 4,
724 };
725
726 const static struct ts_filter_mean_configuration gta01_ts_mean = {
727         .length = 4,
728 };
729
730 const static struct ts_filter_linear_configuration gta01_ts_linear = {
731         .constants = {1, 0, 0, 0, 1, 0, 1},     /* Don't modify coords. */
732         .coord0 = 0,
733         .coord1 = 1,
734 };
735 #endif
736
737 const static struct ts_filter_chain_configuration gta01_filter_configuration[] =
738 {
739 #ifdef CONFIG_TOUCHSCREEN_FILTER
740         {&ts_filter_group_api,          &gta01_ts_group.config},
741         {&ts_filter_median_api,         &gta01_ts_median.config},
742         {&ts_filter_mean_api,           &gta01_ts_mean.config},
743         {&ts_filter_linear_api,         &gta01_ts_linear.config},
744 #endif
745         {NULL, NULL},
746 };
747
748 const static struct s3c2410_ts_mach_info gta01_ts_cfg = {
749         .delay = 10000,
750         .presc = 0xff, /* slow as we can go */
751         .filter_config = gta01_filter_configuration,
752 };
753
754 /* SPI */
755
756 static void gta01_jbt6k74_reset(int devidx, int level)
757 {
758         /* empty place holder; gta01 does not yet use this */
759         printk(KERN_DEBUG "gta01_jbt6k74_reset\n");
760 }
761
762 static void gta01_jbt6k74_resuming(int devidx)
763 {
764         gta01bl_deferred_resume();
765 }
766
767 const struct jbt6k74_platform_data gta01_jbt6k74_pdata = {
768         .reset          = gta01_jbt6k74_reset,
769         .resuming       = gta01_jbt6k74_resuming,
770 };
771
772 static struct spi_board_info gta01_spi_board_info[] = {
773         {
774                 .modalias       = "jbt6k74",
775                 .platform_data  = &gta01_jbt6k74_pdata,
776                 /* controller_data */
777                 /* irq */
778                 .max_speed_hz   = 10 * 1000 * 1000,
779                 /* chip_select */
780         },
781 };
782
783 static void spi_gpio_cs(struct s3c2410_spigpio_info *spi, int csidx, int cs)
784 {
785         switch (cs) {
786         case BITBANG_CS_ACTIVE:
787                 s3c2410_gpio_setpin(S3C2410_GPG3, 0);
788                 break;
789         case BITBANG_CS_INACTIVE:
790                 s3c2410_gpio_setpin(S3C2410_GPG3, 1);
791                 break;
792         }
793 }
794
795 static struct s3c2410_spigpio_info spi_gpio_cfg = {
796         .pin_clk        = S3C2410_GPG7,
797         .pin_mosi       = S3C2410_GPG6,
798         .pin_miso       = S3C2410_GPG5,
799         .chip_select    = &spi_gpio_cs,
800         .num_chipselect = 2,   /*** Should be 1 or 2 for gta01? ***/
801 };
802
803 static struct resource s3c_spi_lcm_resource[] = {
804         [0] = {
805                 .start = S3C2410_GPG3,
806                 .end   = S3C2410_GPG3,
807         },
808         [1] = {
809                 .start = S3C2410_GPG5,
810                 .end   = S3C2410_GPG5,
811         },
812         [2] = {
813                 .start = S3C2410_GPG6,
814                 .end   = S3C2410_GPG6,
815         },
816         [3] = {
817                 .start = S3C2410_GPG7,
818                 .end   = S3C2410_GPG7,
819         },
820 };
821
822 struct platform_device s3c_device_spi_lcm = {
823         .name             = "spi_s3c24xx_gpio",
824         .id               = 1,
825         .num_resources    = ARRAY_SIZE(s3c_spi_lcm_resource),
826         .resource         = s3c_spi_lcm_resource,
827         .dev = {
828                 .platform_data = &spi_gpio_cfg,
829         },
830 };
831
832 static struct gta01bl_machinfo backlight_machinfo = {
833         .default_intensity      = 1,
834         .max_intensity          = 1,
835         .limit_mask             = 1,
836         .defer_resume_backlight = 1,
837 };
838
839 static struct resource gta01_bl_resources[] = {
840         [0] = {
841                 .start  = GTA01_GPIO_BACKLIGHT,
842                 .end    = GTA01_GPIO_BACKLIGHT,
843         },
844 };
845
846 struct platform_device gta01_bl_dev = {
847         .name           = "gta01-bl",
848         .num_resources  = ARRAY_SIZE(gta01_bl_resources),
849         .resource       = gta01_bl_resources,
850         .dev            = {
851                 .platform_data = &backlight_machinfo,
852         },
853 };
854
855 static struct resource gta01_led_resources[] = {
856         [0] = {
857                 .start  = GTA01_GPIO_VIBRATOR_ON,
858                 .end    = GTA01_GPIO_VIBRATOR_ON,
859         },
860 };
861
862 struct platform_device gta01_led_dev = {
863         .name           = "neo1973-vibrator",
864         .num_resources  = ARRAY_SIZE(gta01_led_resources),
865         .resource       = gta01_led_resources,
866 };
867
868 static struct resource gta01_button_resources[] = {
869         [0] = {
870                 .start = GTA01_GPIO_AUX_KEY,
871                 .end   = GTA01_GPIO_AUX_KEY,
872         },
873         [1] = {
874                 .start = GTA01_GPIO_HOLD_KEY,
875                 .end   = GTA01_GPIO_HOLD_KEY,
876         },
877         [2] = {
878                 .start = GTA01_GPIO_JACK_INSERT,
879                 .end   = GTA01_GPIO_JACK_INSERT,
880         },
881 };
882
883 struct platform_device gta01_button_dev = {
884         .name           = "neo1973-button",
885         .num_resources  = ARRAY_SIZE(gta01_button_resources),
886         .resource       = gta01_button_resources,
887 };
888
889 /* USB */
890 static struct s3c2410_hcd_info gta01_usb_info = {
891         .port[0]        = {
892                 .flags  = S3C_HCDFLG_USED,
893         },
894         .port[1]        = {
895                 .flags  = 0,
896         },
897 };
898
899 static void __init gta01_map_io(void)
900 {
901         s3c24xx_init_io(gta01_iodesc, ARRAY_SIZE(gta01_iodesc));
902         s3c24xx_init_clocks(12*1000*1000);
903         s3c24xx_init_uarts(gta01_uartcfgs, ARRAY_SIZE(gta01_uartcfgs));
904 }
905
906 static irqreturn_t gta01_modem_irq(int irq, void *param)
907 {
908         printk(KERN_DEBUG "GSM wakeup interrupt (IRQ %d)\n", irq);
909         gta_gsm_interrupts++;
910         return IRQ_HANDLED;
911 }
912
913 static struct i2c_board_info gta01_i2c_devs[] __initdata = {
914         {
915                 I2C_BOARD_INFO("pcf50606", 0x08),
916                 .irq = GTA01_IRQ_PCF50606,
917                 .platform_data = &gta01_pcf_pdata,
918         },
919         {
920                 I2C_BOARD_INFO("lm4857", 0x7c),
921         },
922         {
923                 I2C_BOARD_INFO("wm8753", 0x1a),
924         },
925 };
926
927 static void __init gta01_machine_init(void)
928 {
929         int rc;
930
931         if (S3C_SYSTEM_REV_ATAG == GTA01v4_SYSTEM_REV ||
932             S3C_SYSTEM_REV_ATAG == GTA01Bv2_SYSTEM_REV ||
933             S3C_SYSTEM_REV_ATAG == GTA01Bv3_SYSTEM_REV ||
934             S3C_SYSTEM_REV_ATAG == GTA01Bv4_SYSTEM_REV) {
935                 gta01_udc_cfg.udc_command = gta01_udc_command;
936                 gta01_mmc_cfg.ocr_avail = MMC_VDD_32_33;
937         }
938
939         s3c_device_usb.dev.platform_data = &gta01_usb_info;
940         s3c_device_nand.dev.platform_data = &gta01_nand_info;
941         s3c_device_sdi.dev.platform_data = &gta01_mmc_cfg;
942
943         s3c24xx_fb_set_platdata(&gta01_lcd_cfg);
944
945         INIT_WORK(&gta01_udc_vbus_drawer.work, __gta01_udc_vbus_draw);
946         s3c24xx_udc_set_platdata(&gta01_udc_cfg);
947         s3c_i2c0_set_platdata(NULL);
948         set_s3c2410ts_info(&gta01_ts_cfg);
949
950         /* Set LCD_RESET / XRES to high */
951         s3c2410_gpio_cfgpin(S3C2410_GPC6, S3C2410_GPIO_OUTPUT);
952         s3c2410_gpio_setpin(S3C2410_GPC6, 1);
953
954         /* SPI chip select is gpio output */
955         s3c2410_gpio_cfgpin(S3C2410_GPG3, S3C2410_GPIO_OUTPUT);
956         s3c2410_gpio_setpin(S3C2410_GPG3, 1);
957         platform_device_register(&s3c_device_spi_lcm);
958
959         platform_device_register(&gta01_bl_dev);
960         platform_device_register(&gta01_button_dev);
961         platform_device_register(&gta01_pm_gsm_dev);
962
963         switch (S3C_SYSTEM_REV_ATAG) {
964         case GTA01v3_SYSTEM_REV:
965         case GTA01v4_SYSTEM_REV:
966                 /* just use the default (GTA01_IRQ_PCF50606) */
967                 break;
968         case GTA01Bv2_SYSTEM_REV:
969         case GTA01Bv3_SYSTEM_REV:
970                 /* just use the default (GTA01_IRQ_PCF50606) */
971                 gta01_led_resources[0].start =
972                         gta01_led_resources[0].end = GTA01Bv2_GPIO_VIBRATOR_ON;
973                 break;
974         case GTA01Bv4_SYSTEM_REV:
975                 gta01_i2c_devs[0].irq =  GTA01Bv4_IRQ_PCF50606;
976                 gta01_led_resources[0].start =
977                         gta01_led_resources[0].end = GTA01Bv4_GPIO_VIBRATOR_ON;
978                 break;
979         }
980         mangle_pmu_pdata_by_system_rev();
981         i2c_register_board_info(0, gta01_i2c_devs, ARRAY_SIZE(gta01_i2c_devs));
982         spi_register_board_info(gta01_spi_board_info, ARRAY_SIZE(gta01_spi_board_info));
983         
984         platform_device_register(&gta01_led_dev);
985
986         platform_add_devices(gta01_devices, ARRAY_SIZE(gta01_devices));
987
988         s3c_pm_init();
989
990         set_irq_type(GTA01_IRQ_MODEM, IRQ_TYPE_EDGE_RISING);
991         rc = request_irq(GTA01_IRQ_MODEM, gta01_modem_irq, IRQF_DISABLED,
992                          "modem", NULL);
993         enable_irq_wake(GTA01_IRQ_MODEM);
994         printk(KERN_DEBUG  "Enabled GSM wakeup IRQ %d (rc=%d)\n",
995                GTA01_IRQ_MODEM, rc);
996
997         pm_power_off = &gta01_power_off;
998 }
999
1000 MACHINE_START(NEO1973_GTA01, "GTA01")
1001         .phys_io        = S3C2410_PA_UART,
1002         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
1003         .boot_params    = S3C2410_SDRAM_PA + 0x100,
1004         .map_io         = gta01_map_io,
1005         .init_irq       = s3c24xx_init_irq,
1006         .init_machine   = gta01_machine_init,
1007         .timer          = &s3c24xx_timer,
1008 MACHINE_END