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