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