gta02: Add touchscreen device
[kernel.git] / arch / arm / mach-s3c2440 / mach-gta02.c
1 /*
2  * linux/arch/arm/mach-s3c2442/mach-gta02.c
3  *
4  * S3C2442 Machine Support for Openmoko GTA02 / FreeRunner.
5  *
6  * Copyright (C) 2006-2009 by Openmoko, Inc.
7  * Authors: Harald Welte <laforge@openmoko.org>
8  *          Andy Green <andy@openmoko.org>
9  *          Werner Almesberger <werner@openmoko.org>
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  *
27  */
28
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/interrupt.h>
32 #include <linux/list.h>
33 #include <linux/delay.h>
34 #include <linux/timer.h>
35 #include <linux/init.h>
36 #include <linux/gpio.h>
37 #include <linux/workqueue.h>
38 #include <linux/platform_device.h>
39 #include <linux/serial_core.h>
40 #include <linux/spi/spi.h>
41 #include <linux/spi/spi_gpio.h>
42
43 #include <linux/mmc/host.h>
44
45 #include <linux/mtd/mtd.h>
46 #include <linux/mtd/nand.h>
47 #include <linux/mtd/nand_ecc.h>
48 #include <linux/mtd/partitions.h>
49 #include <linux/mtd/physmap.h>
50 #include <linux/io.h>
51
52 #include <linux/i2c.h>
53 #include <linux/regulator/machine.h>
54 #include <linux/regulator/fixed.h>
55
56 #include <linux/mfd/pcf50633/core.h>
57 #include <linux/mfd/pcf50633/mbc.h>
58 #include <linux/mfd/pcf50633/adc.h>
59 #include <linux/mfd/pcf50633/gpio.h>
60 #include <linux/mfd/pcf50633/pmic.h>
61 #include <linux/mfd/pcf50633/backlight.h>
62
63 #include <linux/input.h>
64 #include <linux/gpio_keys.h>
65
66 #include <linux/leds.h>
67 #include <linux/leds_pwm.h>
68
69 #include <asm/mach/arch.h>
70 #include <asm/mach/map.h>
71 #include <asm/mach/irq.h>
72
73 #include <asm/irq.h>
74 #include <asm/mach-types.h>
75
76 #include <mach/regs-irq.h>
77 #include <mach/regs-gpio.h>
78 #include <mach/regs-gpioj.h>
79 #include <mach/fb.h>
80
81 #include <mach/spi.h>
82 #include <mach/spi-gpio.h>
83 #include <plat/usb-control.h>
84 #include <mach/regs-mem.h>
85 #include <mach/hardware.h>
86
87 #include <mach/ts.h>
88
89 #include <mach/gta02.h>
90
91 #include <plat/regs-serial.h>
92 #include <plat/nand.h>
93 #include <plat/devs.h>
94 #include <plat/cpu.h>
95 #include <plat/pm.h>
96 #include <plat/udc.h>
97 #include <plat/gpio-cfg.h>
98 #include <plat/gpio-core.h>
99 #include <plat/iic.h>
100
101 #include <mach/gta02-pm-gps.h>
102 #include <mach/gta02-pm-wlan.h>
103
104 #include <linux/jbt6k74.h>
105 #include <linux/glamofb.h>
106 #include <linux/mfd/glamo.h>
107
108 static struct pcf50633 *gta02_pcf;
109
110 /*
111  * This gets called every 1ms when we paniced.
112  */
113
114 static long gta02_panic_blink(long count)
115 {
116         long delay = 0;
117         static long last_blink;
118         static char led;
119
120         /* Fast blink: 200ms period. */
121         if (count - last_blink < 100)
122                 return 0;
123
124         led ^= 1;
125         gpio_direction_output(GTA02_GPIO_AUX_LED, led);
126
127         last_blink = count;
128
129         return delay;
130 }
131
132
133 static struct map_desc gta02_iodesc[] __initdata = {
134         {
135                 .virtual        = 0xe0000000,
136                 .pfn            = __phys_to_pfn(S3C2410_CS3 + 0x01000000),
137                 .length         = SZ_1M,
138                 .type           = MT_DEVICE
139         },
140 };
141
142 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
143 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
144 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
145
146 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
147         [0] = {
148                 .hwport         = 0,
149                 .flags          = 0,
150                 .ucon           = UCON,
151                 .ulcon          = ULCON,
152                 .ufcon          = UFCON,
153         },
154         [1] = {
155                 .hwport         = 1,
156                 .flags          = 0,
157                 .ucon           = UCON,
158                 .ulcon          = ULCON,
159                 .ufcon          = UFCON,
160         },
161         [2] = {
162                 .hwport         = 2,
163                 .flags          = 0,
164                 .ucon           = UCON,
165                 .ulcon          = ULCON,
166                 .ufcon          = UFCON,
167         },
168 };
169
170 static struct platform_device gta02_pm_bt_dev = {
171         .name = "gta02-pm-bt",
172 };
173
174 static struct platform_device gta02_pm_gps_dev = {
175         .name = "gta02-pm-gps",
176 };
177
178 static struct platform_device gta02_pm_gsm_dev = {
179         .name = "gta02-pm-gsm",
180 };
181
182 static struct platform_device gta02_pm_wlan_dev = {
183         .name = "gta02-pm-wlan",
184 };
185
186 static struct regulator_consumer_supply gsm_supply_consumer = {
187         .dev = &gta02_pm_gsm_dev.dev,
188         .supply = "GSM",
189 };
190
191 static struct regulator_init_data gsm_supply_init_data = {
192         .constraints = {
193                 .min_uV = 3700000,
194                 .max_uV = 3700000,
195                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
196                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
197         },
198         .num_consumer_supplies = 1,
199         .consumer_supplies = &gsm_supply_consumer,
200 };
201
202 static struct fixed_voltage_config gsm_supply_config = {
203         .supply_name = "GSM",
204         .microvolts = 3700000,
205         .gpio = GTA02_GPIO_PCF(PCF50633_GPIO2),
206         .enable_high = 1,
207         .init_data = &gsm_supply_init_data,
208 };
209
210 static struct platform_device gta02_gsm_supply_device = {
211         .name = "reg-fixed-voltage",
212         .id = 1,
213         .dev = {
214                 .platform_data = &gsm_supply_config,
215         },
216 };
217
218 /*
219  * we crank down SD Card clock dynamically when GPS is powered
220  */
221
222 static int gta02_glamo_mci_use_slow(void)
223 {
224         return gta02_pm_gps_is_on();
225 }
226
227 static void gta02_glamo_external_reset(int level)
228 {
229         s3c2410_gpio_setpin(GTA02_GPIO_3D_RESET, level);
230         s3c2410_gpio_cfgpin(GTA02_GPIO_3D_RESET, S3C2410_GPIO_OUTPUT);
231 }
232
233 struct spi_gpio_platform_data spigpio_platform_data = {
234         .sck = GTA02_GPIO_GLAMO(10),
235         .mosi = GTA02_GPIO_GLAMO(11),
236         .miso = GTA02_GPIO_GLAMO(5),
237         .num_chipselect = 1,
238 };
239
240 static struct platform_device spigpio_device = {
241         .name = "spi_gpio",
242         .id   = 2,
243         .dev = {
244                 .platform_data = &spigpio_platform_data,
245         },
246 };
247
248 static void gta02_glamo_registered(struct device *dev)
249 {
250         spigpio_device.dev.parent = dev;
251         platform_device_register(&spigpio_device);
252 }
253
254 static struct fb_videomode gta02_glamo_modes[] = {
255         {
256                 .name = "480x640",
257                 .xres = 480,
258                 .yres = 640,
259                 .pixclock       = 40816,
260                 .left_margin    = 8,
261                 .right_margin   = 16,
262                 .upper_margin   = 2,
263                 .lower_margin   = 16,
264                 .hsync_len      = 8,
265                 .vsync_len      = 2,
266                 .vmode = FB_VMODE_NONINTERLACED,
267         }, {
268                 .name = "240x320",
269                 .xres = 240,
270                 .yres = 320,
271                 .pixclock       = 40816,
272                 .left_margin    = 8,
273                 .right_margin   = 16,
274                 .upper_margin   = 2,
275                 .lower_margin   = 16,
276                 .hsync_len      = 8,
277                 .vsync_len      = 2,
278                 .vmode = FB_VMODE_NONINTERLACED,
279         }
280 };
281
282 static struct glamo_fb_platform_data gta02_glamo_fb_pdata = {
283         .width  = 43,
284         .height = 58,
285
286         .num_modes = ARRAY_SIZE(gta02_glamo_modes),
287         .modes = gta02_glamo_modes,
288 };
289
290 static struct glamo_mmc_platform_data gta02_glamo_mmc_pdata = {
291         .glamo_mmc_use_slow = gta02_glamo_mci_use_slow,
292 };
293
294 static struct glamo_gpio_platform_data gta02_glamo_gpio_pdata = {
295         .base = GTA02_GPIO_GLAMO_BASE,
296         .registered = gta02_glamo_registered,
297 };
298
299 static struct glamo_platform_data gta02_glamo_pdata = {
300         .fb_data    = &gta02_glamo_fb_pdata,
301         .mmc_data   = &gta02_glamo_mmc_pdata,
302         .gpio_data  = &gta02_glamo_gpio_pdata,
303
304         .osci_clock_rate = 32768,
305
306         .glamo_external_reset = gta02_glamo_external_reset,
307 };
308
309 /* JBT6k74 display controller */
310 static void gta02_jbt6k74_probe_completed(struct device *dev)
311  {
312         pcf50633_bl_set_brightness_limit(gta02_pcf, 0x3f);
313 }
314  
315 const static struct jbt6k74_platform_data jbt6k74_pdata = {
316         .gpio_reset = GTA02_GPIO_GLAMO(4),
317 };
318
319 static struct spi_board_info gta02_spi_board_info[] = {
320         {
321                 .modalias       = "jbt6k74",
322                 .platform_data  = &jbt6k74_pdata,
323                 .controller_data = (void*)GTA02_GPIO_GLAMO(12),
324                 /* irq */
325                 .max_speed_hz   = 100 * 1000,
326                 .bus_num        = 2,
327                 .chip_select = 0
328         },
329 };
330  
331 static struct resource gta02_glamo_resources[] = {
332         [0] = {
333                 .start  = S3C2410_CS1,
334                 .end    = S3C2410_CS1 + 0x1000000 - 1,
335                 .flags  = IORESOURCE_MEM,
336         },
337         [1] = {
338                 .start  = GTA02_IRQ_3D,
339                 .end    = GTA02_IRQ_3D,
340                 .flags  = IORESOURCE_IRQ,
341         },
342         [2] = {
343                 .start  = IRQ_BOARD_START,
344                 .flags  = IORESOURCE_IRQ,
345         },
346 };
347
348 static struct platform_device gta02_glamo_dev = {
349         .name           = "glamo3362",
350         .num_resources  = ARRAY_SIZE(gta02_glamo_resources),
351         .resource       = gta02_glamo_resources,
352         .dev            = {
353                 .platform_data  = &gta02_glamo_pdata,
354         },
355 };
356
357
358 #ifdef CONFIG_CHARGER_PCF50633
359 /*
360  * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
361  * We use this to recognize that we can pull 1A from the USB socket.
362  *
363  * These constants are the measured pcf50633 ADC levels with the 1A
364  * charger / 48K resistor, and with no pulldown resistor.
365  */
366
367 #define ADC_NOM_CHG_DETECT_1A 6
368 #define ADC_NOM_CHG_DETECT_USB 43
369
370 static void
371 gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
372 {
373         int ma;
374
375         if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2))
376                 ma = 1000;
377         else
378                 ma = 100;
379
380         pcf50633_mbc_usb_curlim_set(pcf, ma);
381 }
382
383 static struct delayed_work gta02_charger_work;
384 static int gta02_usb_vbus_draw;
385
386 static void gta02_charger_worker(struct work_struct *work)
387 {
388         if (gta02_usb_vbus_draw) {
389                 pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
390                 return;
391         }
392
393 #ifdef CONFIG_PCF50633_ADC
394         pcf50633_adc_async_read(gta02_pcf,
395                                 PCF50633_ADCC1_MUX_ADCIN1,
396                                 PCF50633_ADCC1_AVERAGE_16,
397                                 gta02_configure_pmu_for_charger,
398                                 NULL);
399 #else
400         /*
401          * If the PCF50633 ADC is disabled we fallback to a
402          * 100mA limit for safety.
403          */
404         pcf50633_mbc_usb_curlim_set(pcf, 100);
405 #endif
406 }
407
408 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
409
410 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
411 {
412         if (irq == PCF50633_IRQ_USBINS) {
413                 schedule_delayed_work(&gta02_charger_work,
414                                       GTA02_CHARGER_CONFIGURE_TIMEOUT);
415
416                 return;
417         }
418
419         if (irq == PCF50633_IRQ_USBREM) {
420                 cancel_delayed_work_sync(&gta02_charger_work);
421                 gta02_usb_vbus_draw = 0;
422         }
423 }
424
425 static void gta02_udc_vbus_draw(unsigned int ma)
426 {
427         if (!gta02_pcf)
428                 return;
429
430         gta02_usb_vbus_draw = ma;
431
432         schedule_delayed_work(&gta02_charger_work,
433                               GTA02_CHARGER_CONFIGURE_TIMEOUT);
434 }
435 #else /* !CONFIG_CHARGER_PCF50633 */
436 #define gta02_pmu_event_callback        NULL
437 #define gta02_udc_vbus_draw             NULL
438 #endif
439
440 /*
441  * This is called when pc50633 is probed, unfortunately quite late in the
442  * day since it is an I2C bus device. Here we can belatedly define some
443  * platform devices with the advantage that we can mark the pcf50633 as the
444  * parent. This makes them get suspended and resumed with their parent
445  * the pcf50633 still around.
446  */
447
448 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf);
449
450
451 static char *gta02_batteries[] = {
452         "battery",
453 };
454
455 static struct regulator_consumer_supply ldo4_consumers[] = {
456         {
457                 .dev = &gta02_pm_bt_dev.dev,
458                 .supply = "BT_3V2",
459         },
460 };
461
462 static struct regulator_consumer_supply ldo5_consumers[] = {
463         {
464                 .dev = &gta02_pm_gps_dev.dev,
465                 .supply = "RF_3V",
466         },
467 };
468
469 static struct regulator_consumer_supply ldo6_consumers[] = {
470         REGULATOR_SUPPLY("VDC", "spi2.0"),
471         REGULATOR_SUPPLY("VDDIO", "spi2.0"),
472 };
473
474 static struct regulator_consumer_supply hcldo_consumers[] = {
475         {
476                 .dev = &gta02_glamo_dev.dev,
477                 .supply = "SD_3V3",
478         },
479 };
480
481 static struct pcf50633_bl_platform_data gta02_backlight_data = {
482         .default_brightness = 0x3f,
483         .default_brightness_limit = 0,
484         .ramp_time = 3,
485 };
486
487 struct pcf50633_platform_data gta02_pcf_pdata = {
488         .resumers = {
489                 [0] =   PCF50633_INT1_USBINS |
490                         PCF50633_INT1_USBREM |
491                         PCF50633_INT1_ALARM,
492                 [1] =   PCF50633_INT2_ONKEYF,
493                 [2] =   PCF50633_INT3_ONKEY1S,
494                 [3] =   PCF50633_INT4_LOWSYS |
495                         PCF50633_INT4_LOWBAT |
496                         PCF50633_INT4_HIGHTMP,
497         },
498
499         .batteries = gta02_batteries,
500         .num_batteries = ARRAY_SIZE(gta02_batteries),
501
502         .charger_reference_current_ma = 1000,
503
504         .backlight_data = &gta02_backlight_data,
505
506         .gpio_base = GTA02_GPIO_PCF_BASE,
507
508         .reg_init_data = {
509                 [PCF50633_REGULATOR_AUTO] = {
510                         .constraints = {
511                                 .min_uV = 3300000,
512                                 .max_uV = 3300000,
513                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
514                                 .always_on = 1,
515                                 .apply_uV = 1,
516                                 .state_mem = {
517                                         .enabled = 1,
518                                 },
519                         },
520                 },
521                 [PCF50633_REGULATOR_DOWN1] = {
522                         .constraints = {
523                                 .min_uV = 1300000,
524                                 .max_uV = 1600000,
525                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
526                                 .always_on = 1,
527                                 .apply_uV = 1,
528                         },
529                 },
530                 [PCF50633_REGULATOR_DOWN2] = {
531                         .constraints = {
532                                 .min_uV = 1800000,
533                                 .max_uV = 1800000,
534                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
535                                 .apply_uV = 1,
536                                 .always_on = 1,
537                                 .state_mem = {
538                                         .enabled = 1,
539                                 },
540                         },
541                 },
542                 [PCF50633_REGULATOR_HCLDO] = {
543                         .constraints = {
544                                 .min_uV = 2000000,
545                                 .max_uV = 3300000,
546                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
547                                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | 
548                                                 REGULATOR_CHANGE_STATUS,
549                         },
550                         .num_consumer_supplies = ARRAY_SIZE(hcldo_consumers),
551                         .consumer_supplies = hcldo_consumers,
552                 },
553                 [PCF50633_REGULATOR_LDO1] = {
554                         .constraints = {
555                                 .min_uV = 3300000,
556                                 .max_uV = 3300000,
557                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
558                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
559                                 .apply_uV = 1,
560                                 .state_mem = {
561                                         .enabled = 0,
562                                 },
563                         },
564                 },
565                 [PCF50633_REGULATOR_LDO2] = {
566                         .constraints = {
567                                 .min_uV = 3300000,
568                                 .max_uV = 3300000,
569                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
570                                 .apply_uV = 1,
571                         },
572                 },
573                 [PCF50633_REGULATOR_LDO3] = {
574                         .constraints = {
575                                 .min_uV = 3000000,
576                                 .max_uV = 3000000,
577                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
578                                 .apply_uV = 1,
579                         },
580                 },
581                 [PCF50633_REGULATOR_LDO4] = {
582                         .constraints = {
583                                 .min_uV = 3200000,
584                                 .max_uV = 3200000,
585                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
586                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
587                                 .apply_uV = 1,
588                         },
589                         .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers),
590                         .consumer_supplies = ldo4_consumers,
591                 },
592                 [PCF50633_REGULATOR_LDO5] = {
593                         .constraints = {
594                                 .min_uV = 3000000,
595                                 .max_uV = 3000000,
596                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
597                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
598                                 .apply_uV = 1,
599                                 .state_mem = {
600                                         .enabled = 1,
601                                 },
602                         },
603                         .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers),
604                         .consumer_supplies = ldo5_consumers,
605                 },
606                 [PCF50633_REGULATOR_LDO6] = {
607                         .constraints = {
608                                 .min_uV = 3000000,
609                                 .max_uV = 3000000,
610                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
611                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
612                         },
613                         .num_consumer_supplies = ARRAY_SIZE(ldo6_consumers),
614                         .consumer_supplies = ldo6_consumers,
615                 },
616                 [PCF50633_REGULATOR_MEMLDO] = {
617                         .constraints = {
618                                 .min_uV = 1800000,
619                                 .max_uV = 1800000,
620                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
621                                 .state_mem = {
622                                         .enabled = 1,
623                                 },
624                         },
625                 },
626
627         },
628         .probe_done = gta02_pmu_attach_child_devices,
629         .mbc_event_callback = gta02_pmu_event_callback,
630 };
631
632
633 /* NOR Flash. */
634
635 #define GTA02_FLASH_BASE        0x18000000 /* GCS3 */
636 #define GTA02_FLASH_SIZE        0x200000 /* 2MBytes */
637
638 static struct physmap_flash_data gta02_nor_flash_data = {
639         .width          = 2,
640 };
641
642 static struct resource gta02_nor_flash_resource = {
643         .start          = GTA02_FLASH_BASE,
644         .end            = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
645         .flags          = IORESOURCE_MEM,
646 };
647
648 static struct platform_device gta02_nor_flash = {
649         .name           = "physmap-flash",
650         .id             = 0,
651         .dev            = {
652                 .platform_data  = &gta02_nor_flash_data,
653         },
654         .resource       = &gta02_nor_flash_resource,
655         .num_resources  = 1,
656 };
657
658 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
659         {
660                 I2C_BOARD_INFO("pcf50633", 0x73),
661                 .irq = GTA02_IRQ_PCF50633,
662                 .platform_data = &gta02_pcf_pdata,
663         },
664         {
665                 I2C_BOARD_INFO("wm8753", 0x1a),
666         },
667 };
668
669 static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
670         [0] = {
671                 /*
672                  * This name is also hard-coded in the boot loaders, so
673                  * changing it would would require all users to upgrade
674                  * their boot loaders, some of which are stored in a NOR
675                  * that is considered to be immutable.
676                  */
677                 .name           = "neo1973-nand",
678                 .nr_chips       = 1,
679                 .flash_bbt      = 1,
680         },
681 };
682
683 /*
684  * Choose a set of timings derived from S3C@2442B MCP54
685  * data sheet (K5D2G13ACM-D075 MCP Memory).
686  */
687
688 static struct s3c2410_platform_nand __initdata gta02_nand_info = {
689         .tacls          = 0,
690         .twrph0         = 25,
691         .twrph1         = 15,
692         .nr_sets        = ARRAY_SIZE(gta02_nand_sets),
693         .sets           = gta02_nand_sets,
694         .software_ecc   = 1,
695 };
696
697
698 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
699 {
700         switch (cmd) {
701         case S3C2410_UDC_P_ENABLE:
702                 pr_debug("%s S3C2410_UDC_P_ENABLE\n", __func__);
703                 gpio_set_value(GTA02_GPIO_USB_PULLUP, 1);
704                 break;
705         case S3C2410_UDC_P_DISABLE:
706                 pr_debug("%s S3C2410_UDC_P_DISABLE\n", __func__);
707                 gpio_set_value(GTA02_GPIO_USB_PULLUP, 0);
708                 break;
709         case S3C2410_UDC_P_RESET:
710                 pr_debug("%s S3C2410_UDC_P_RESET\n", __func__);
711                 /* FIXME: Do something here. */
712         }
713 }
714
715 /* Get PMU to set USB current limit accordingly. */
716 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
717         .vbus_draw      = gta02_udc_vbus_draw,
718         .udc_command    = gta02_udc_command,
719
720 };
721
722 /* USB */
723 static struct s3c2410_hcd_info gta02_usb_info __initdata = {
724         .port[0]        = {
725                 .flags  = S3C_HCDFLG_USED,
726         },
727         .port[1]        = {
728                 .flags  = 0,
729         },
730 };
731
732 /* Touchscreen */
733 static struct s3c2410_ts_mach_info gta02_ts_info = {
734        .delay = 10000,
735        .presc = 0xff, /* slow as we can go */
736            .oversampling_shift = 2,
737 };
738
739 /* Buttons */
740 static struct gpio_keys_button gta02_buttons[] = {
741         {
742                 .gpio = GTA02_GPIO_AUX_KEY,
743                 .code = KEY_PHONE,
744                 .desc = "Aux",
745                 .type = EV_KEY,
746                 .debounce_interval = 100,
747         },
748         {
749                 .gpio = GTA02_GPIO_HOLD_KEY,
750                 .code = KEY_PAUSE,
751                 .desc = "Hold",
752                 .type = EV_KEY,
753                 .debounce_interval = 100,
754         },
755 };
756
757 static struct gpio_keys_platform_data gta02_buttons_pdata = {
758         .buttons = gta02_buttons,
759         .nbuttons = ARRAY_SIZE(gta02_buttons),
760 };
761
762 static struct platform_device gta02_buttons_device = {
763         .name = "gpio-keys",
764         .id = -1,
765         .dev = {
766                 .platform_data = &gta02_buttons_pdata,
767         },
768 };
769
770 /* LEDs */
771 static struct gpio_led gta02_gpio_leds[] = {
772         {
773                 .name   = "gta02:red:aux",
774                 .gpio   = GTA02_GPIO_AUX_LED,
775         },
776 };
777
778 static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
779         .leds = gta02_gpio_leds,
780         .num_leds = ARRAY_SIZE(gta02_gpio_leds),
781 };
782
783 static struct platform_device gta02_leds_device = {
784         .name   = "leds-gpio",
785         .id             = -1,
786         .dev = {
787                 .platform_data = &gta02_gpio_leds_pdata,
788         },
789 };
790
791 static inline int gta02_pwm_to_gpio(int pwm_id)
792 {
793         return S3C2410_GPB(pwm_id);
794 }
795
796 static int gta02_pwm_led_init(struct device *dev, struct led_pwm *led)
797 {
798         int ret;
799         int gpio = gta02_pwm_to_gpio(led->pwm_id);
800
801         ret = gpio_request(gpio, dev_name(dev));
802         if (ret)
803                 return ret;
804
805         gpio_direction_output(gpio, 0);
806
807         return 0;
808 }
809
810 static enum led_brightness gta02_pwm_led_notify(struct device *dev,
811         struct led_pwm *led, enum led_brightness brightness)
812 {
813         int gpio = gta02_pwm_to_gpio(led->pwm_id);
814
815         if (brightness == led->max_brightness || brightness == 0) {
816                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_OUTPUT);
817                 gpio_set_value(gpio, brightness ? 1 : 0);
818
819                 brightness = 0;
820         } else {
821                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_SFN2);
822         }
823
824         return brightness;
825 }
826
827 static void gta02_pwm_led_exit(struct device *dev, struct led_pwm *led)
828 {
829         gpio_free(gta02_pwm_to_gpio(led->pwm_id));
830 }
831
832 static struct led_pwm gta02_pwm_leds[] = {
833         {
834                 .name = "gta02:orange:power",
835                 .max_brightness = 0xff,
836                 .pwm_period_ns = 1000000,
837                 .pwm_id = 0,
838         },
839         {
840                 .name = "gta02:blue:power",
841                 .max_brightness = 0xff,
842                 .pwm_period_ns = 1000000,
843                 .pwm_id = 1,
844         },
845         {
846                 .name = "gta02::vibrator",
847                 .max_brightness = 0x3f,
848                 .pwm_period_ns = 60000000,
849                 .pwm_id = 3,
850         }
851 };
852
853 static struct led_pwm_platform_data gta02_pwm_leds_pdata = {
854         .num_leds = ARRAY_SIZE(gta02_pwm_leds),
855         .leds = gta02_pwm_leds,
856
857         .init = gta02_pwm_led_init,
858         .notify = gta02_pwm_led_notify,
859         .exit = gta02_pwm_led_exit,
860 };
861
862 static struct platform_device gta02_pwm_leds_device = {
863         .name   = "leds_pwm",
864         .id     = -1,
865         .dev = {
866                 .platform_data = &gta02_pwm_leds_pdata,
867         }
868 };
869
870 static void __init gta02_map_io(void)
871 {
872         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
873         s3c24xx_init_clocks(12000000);
874         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
875 }
876
877
878 /* These are the guys that don't need to be children of PMU. */
879
880 static struct platform_device *gta02_devices[] __initdata = {
881         &s3c_device_ohci,
882         &s3c_device_wdt,
883         &s3c_device_sdi,
884         &s3c_device_usbgadget,
885         &s3c_device_nand,
886         &gta02_nor_flash,
887         &s3c_device_timer[0],
888         &s3c_device_timer[1],
889         &s3c_device_timer[3],
890         &s3c_device_iis,
891         &s3c_device_i2c0,
892         &gta02_buttons_device,
893         &gta02_leds_device,
894         &gta02_pwm_leds_device,
895         &gta02_pm_gps_dev,
896         &gta02_pm_bt_dev,
897         &gta02_pm_wlan_dev,
898         &gta02_glamo_dev,
899         &s3c_device_adc,
900         &s3c_device_ts,
901 };
902
903 /* These guys DO need to be children of PMU. */
904
905 static struct platform_device *gta02_devices_pmu_children[] = {
906 };
907
908 /*
909  * This is called when pc50633 is probed, quite late in the day since it is an
910  * I2C bus device.  Here we can define platform devices with the advantage that
911  * we can mark the pcf50633 as the parent.  This makes them get suspended and
912  * resumed with their parent the pcf50633 still around.  All devices whose
913  * operation depends on something from pcf50633 must have this relationship
914  * made explicit like this, or suspend and resume will become an unreliable
915  * hellworld.
916  */
917
918 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
919 {
920         int n;
921
922         /* Grab a copy of the now probed PMU pointer. */
923         gta02_pcf = pcf;
924
925         for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
926                 gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
927
928         platform_add_devices(gta02_devices_pmu_children,
929                              ARRAY_SIZE(gta02_devices_pmu_children));
930 }
931
932 static void gta02_poweroff(void)
933 {
934         pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
935 }
936
937 struct gta02_device_children {
938         const char *dev_name;
939         size_t num_children;
940         struct platform_device **children;
941         void (*probed_callback)(struct device *dev);
942 };
943
944 static struct platform_device* gta02_pcf50633_gpio_children[] = {
945         &gta02_gsm_supply_device,
946 };
947
948 static struct platform_device* gta02_gsm_supply_children[] = {
949         &gta02_pm_gsm_dev,
950 };
951
952 static struct gta02_device_children gta02_device_children[] = {
953         {
954                 .dev_name = "pcf50633-gpio",
955                 .num_children = 1,
956                 .children = gta02_pcf50633_gpio_children,
957         },
958         {
959                 .dev_name = "reg-fixed-voltage.1",
960                 .num_children = 1,
961                 .children = gta02_gsm_supply_children,
962         },
963         {
964                 .dev_name = "spi2.0",
965                 .probed_callback = gta02_jbt6k74_probe_completed,
966         },
967 };
968
969 static int gta02_add_child_devices(struct device *parent,
970                                    struct platform_device **children,
971                                                                    size_t num_children)
972 {
973         size_t i;
974
975         for (i = 0; i < num_children; ++i)
976                 children[i]->dev.parent = parent;
977
978         return platform_add_devices(children, num_children);
979 }
980
981 static int gta02_device_registered(struct notifier_block *block,
982                                    unsigned long action, void *data)
983 {
984         struct device *dev = data;
985         const char *devname = dev_name(dev);
986         size_t i;
987
988         if (action != BUS_NOTIFY_BOUND_DRIVER)
989                 return 0;
990
991         for (i = 0; i < ARRAY_SIZE(gta02_device_children); ++i) {
992                 if (strcmp(devname, gta02_device_children[i].dev_name) == 0) {
993                         gta02_add_child_devices(dev, gta02_device_children[i].children,
994                         gta02_device_children[i].num_children);
995
996                         if (gta02_device_children[i].probed_callback)
997                                 gta02_device_children[i].probed_callback(dev);
998                         break;
999                 }
1000         }
1001
1002         return 0;
1003 }
1004
1005 static struct notifier_block gta02_device_register_notifier = {
1006         .notifier_call = gta02_device_registered,
1007         .priority = INT_MAX,
1008 };
1009
1010
1011 /* On hardware rev 5 and earlier the leds are missing a resistor and reading
1012  * from their gpio pins will always return 0, so we have to shadow the
1013  * led states software */
1014 static unsigned long gpb_shadow;
1015 extern struct s3c_gpio_chip s3c24xx_gpios[];
1016
1017 static void gta02_gpb_set(struct gpio_chip *chip,
1018                                 unsigned offset, int value)
1019 {
1020         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
1021         unsigned long flags;
1022         unsigned long dat;
1023
1024         local_irq_save(flags);
1025
1026         dat = __raw_readl(base + 0x04) | gpb_shadow;
1027         dat &= ~(1 << offset);
1028         gpb_shadow &= ~(1 << offset);
1029         if (value) {
1030                 dat |= 1 << offset;
1031                 switch (offset) {
1032                 case 0 ... 2:
1033                         gpb_shadow |= 1 << offset;
1034                         break;
1035                 default:
1036                         break;
1037                 }
1038         }
1039         __raw_writel(dat, base + 0x04);
1040
1041         local_irq_restore(flags);
1042 }
1043
1044 static int gta02_gpb_get(struct gpio_chip *chip, unsigned offset)
1045 {
1046         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
1047         unsigned long val;
1048
1049         val = __raw_readl(base + 0x04) | gpb_shadow;
1050         val >>= offset;
1051         val &= 1;
1052
1053         return val;
1054 }
1055
1056 static void gta02_hijack_gpb(void)
1057 {
1058 /* Uncomment this, once support for S3C_SYSTEM_REV_ATAG has been merged
1059  * upstream.
1060         if (S3C_SYSTEM_REV_ATAG > GTA02v5_SYSTEM_REV)
1061                 return;
1062 */
1063
1064         s3c24xx_gpios[1].chip.set = gta02_gpb_set;
1065         s3c24xx_gpios[1].chip.get = gta02_gpb_get;
1066 }
1067
1068 /*
1069  * Allow the bootloader to enable hw ecc
1070  * hardware_ecc=1|0
1071  */
1072 static int __init hardware_ecc_setup(char *str)
1073 {
1074         if (str && str[0] == '1')
1075                 gta02_nand_info.software_ecc = 0;
1076         return 1;
1077 }
1078 __setup("hardware_ecc=", hardware_ecc_setup);
1079
1080 static void gta02_request_gpios(void)
1081 {
1082         int ret;
1083         ret = gpio_request(GTA02_GPIO_USB_PULLUP, "USB pullup");
1084         if (ret) {
1085                 printk(KERN_ERR "Failed to request USB pullup gpio pin: %d\n", ret);
1086         } else {
1087                 ret = gpio_direction_output(GTA02_GPIO_USB_PULLUP, 0);
1088                 if (ret)
1089                         printk(KERN_ERR "Failed to set USB pullup gpio direction: %d\n", ret);
1090     }
1091 }
1092
1093 static void __init gta02_machine_init(void)
1094 {
1095         /* Set the panic callback to make AUX LED blink at ~5Hz. */
1096         panic_blink = gta02_panic_blink;
1097
1098         bus_register_notifier(&platform_bus_type, &gta02_device_register_notifier);
1099         bus_register_notifier(&spi_bus_type, &gta02_device_register_notifier);
1100
1101         gta02_hijack_gpb();
1102
1103         gta02_request_gpios();
1104
1105         s3c_pm_init();
1106
1107 #ifdef CONFIG_CHARGER_PCF50633
1108         INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
1109 #endif
1110
1111         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
1112         s3c24xx_ts_set_platdata(&gta02_ts_info);
1113         s3c_ohci_set_platdata(&gta02_usb_info);
1114         s3c_nand_set_platdata(&gta02_nand_info);
1115         s3c_i2c0_set_platdata(NULL);
1116         spi_register_board_info(gta02_spi_board_info,
1117                                 ARRAY_SIZE(gta02_spi_board_info));
1118
1119         i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
1120
1121         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
1122
1123         pm_power_off = gta02_poweroff;
1124 }
1125
1126
1127 MACHINE_START(NEO1973_GTA02, "GTA02")
1128         /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
1129         .phys_io        = S3C2410_PA_UART,
1130         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
1131         .boot_params    = S3C2410_SDRAM_PA + 0x100,
1132         .map_io         = gta02_map_io,
1133         .init_irq       = s3c24xx_init_irq,
1134         .init_machine   = gta02_machine_init,
1135         .timer          = &s3c24xx_timer,
1136 MACHINE_END