gta02: Add pcf50633 backlight platform data
[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         /* Interpret charger type */
374         if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
375
376                 /*
377                  * Sanity - stop GPO driving out now that we have a 1A charger
378                  * GPO controls USB Host power generation on GTA02
379                  */
380                 pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
381
382                 ma = 1000;
383         } else
384                 ma = 100;
385
386         pcf50633_mbc_usb_curlim_set(pcf, ma);
387 }
388
389 static struct delayed_work gta02_charger_work;
390 static int gta02_usb_vbus_draw;
391
392 static void gta02_charger_worker(struct work_struct *work)
393 {
394         if (gta02_usb_vbus_draw) {
395                 pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
396                 return;
397         }
398
399 #ifdef CONFIG_PCF50633_ADC
400         pcf50633_adc_async_read(gta02_pcf,
401                                 PCF50633_ADCC1_MUX_ADCIN1,
402                                 PCF50633_ADCC1_AVERAGE_16,
403                                 gta02_configure_pmu_for_charger,
404                                 NULL);
405 #else
406         /*
407          * If the PCF50633 ADC is disabled we fallback to a
408          * 100mA limit for safety.
409          */
410         pcf50633_mbc_usb_curlim_set(pcf, 100);
411 #endif
412 }
413
414 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
415
416 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
417 {
418         if (irq == PCF50633_IRQ_USBINS) {
419                 schedule_delayed_work(&gta02_charger_work,
420                                       GTA02_CHARGER_CONFIGURE_TIMEOUT);
421
422                 return;
423         }
424
425         if (irq == PCF50633_IRQ_USBREM) {
426                 cancel_delayed_work_sync(&gta02_charger_work);
427                 gta02_usb_vbus_draw = 0;
428         }
429 }
430
431 static void gta02_udc_vbus_draw(unsigned int ma)
432 {
433         if (!gta02_pcf)
434                 return;
435
436         gta02_usb_vbus_draw = ma;
437
438         schedule_delayed_work(&gta02_charger_work,
439                               GTA02_CHARGER_CONFIGURE_TIMEOUT);
440 }
441 #else /* !CONFIG_CHARGER_PCF50633 */
442 #define gta02_pmu_event_callback        NULL
443 #define gta02_udc_vbus_draw             NULL
444 #endif
445
446 /*
447  * This is called when pc50633 is probed, unfortunately quite late in the
448  * day since it is an I2C bus device. Here we can belatedly define some
449  * platform devices with the advantage that we can mark the pcf50633 as the
450  * parent. This makes them get suspended and resumed with their parent
451  * the pcf50633 still around.
452  */
453
454 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf);
455
456
457 static char *gta02_batteries[] = {
458         "battery",
459 };
460
461 static struct regulator_consumer_supply ldo4_consumers[] = {
462         {
463                 .dev = &gta02_pm_bt_dev.dev,
464                 .supply = "BT_3V2",
465         },
466 };
467
468 static struct regulator_consumer_supply ldo5_consumers[] = {
469         {
470                 .dev = &gta02_pm_gps_dev.dev,
471                 .supply = "RF_3V",
472         },
473 };
474
475 static struct regulator_consumer_supply ldo6_consumers[] = {
476         REGULATOR_SUPPLY("VDC", "spi2.0"),
477         REGULATOR_SUPPLY("VDDIO", "spi2.0"),
478 };
479
480 static struct regulator_consumer_supply hcldo_consumers[] = {
481         {
482                 .dev = &gta02_glamo_dev.dev,
483                 .supply = "SD_3V3",
484         },
485 };
486
487 static struct pcf50633_bl_platform_data gta02_backlight_data = {
488         .default_brightness = 0x3f,
489         .default_brightness_limit = 0,
490         .ramp_time = 3,
491 };
492
493 struct pcf50633_platform_data gta02_pcf_pdata = {
494         .resumers = {
495                 [0] =   PCF50633_INT1_USBINS |
496                         PCF50633_INT1_USBREM |
497                         PCF50633_INT1_ALARM,
498                 [1] =   PCF50633_INT2_ONKEYF,
499                 [2] =   PCF50633_INT3_ONKEY1S,
500                 [3] =   PCF50633_INT4_LOWSYS |
501                         PCF50633_INT4_LOWBAT |
502                         PCF50633_INT4_HIGHTMP,
503         },
504
505         .batteries = gta02_batteries,
506         .num_batteries = ARRAY_SIZE(gta02_batteries),
507
508         .charger_reference_current_ma = 1000,
509
510         .backlight_data = &gta02_backlight_data,
511
512         .gpio_base = GTA02_GPIO_PCF_BASE,
513
514         .reg_init_data = {
515                 [PCF50633_REGULATOR_AUTO] = {
516                         .constraints = {
517                                 .min_uV = 3300000,
518                                 .max_uV = 3300000,
519                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
520                                 .always_on = 1,
521                                 .apply_uV = 1,
522                                 .state_mem = {
523                                         .enabled = 1,
524                                 },
525                         },
526                 },
527                 [PCF50633_REGULATOR_DOWN1] = {
528                         .constraints = {
529                                 .min_uV = 1300000,
530                                 .max_uV = 1600000,
531                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
532                                 .always_on = 1,
533                                 .apply_uV = 1,
534                         },
535                 },
536                 [PCF50633_REGULATOR_DOWN2] = {
537                         .constraints = {
538                                 .min_uV = 1800000,
539                                 .max_uV = 1800000,
540                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
541                                 .apply_uV = 1,
542                                 .always_on = 1,
543                                 .state_mem = {
544                                         .enabled = 1,
545                                 },
546                         },
547                 },
548                 [PCF50633_REGULATOR_HCLDO] = {
549                         .constraints = {
550                                 .min_uV = 2000000,
551                                 .max_uV = 3300000,
552                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
553                                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | 
554                                                 REGULATOR_CHANGE_STATUS,
555                         },
556                         .num_consumer_supplies = ARRAY_SIZE(hcldo_consumers),
557                         .consumer_supplies = hcldo_consumers,
558                 },
559                 [PCF50633_REGULATOR_LDO1] = {
560                         .constraints = {
561                                 .min_uV = 3300000,
562                                 .max_uV = 3300000,
563                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
564                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
565                                 .apply_uV = 1,
566                                 .state_mem = {
567                                         .enabled = 0,
568                                 },
569                         },
570                 },
571                 [PCF50633_REGULATOR_LDO2] = {
572                         .constraints = {
573                                 .min_uV = 3300000,
574                                 .max_uV = 3300000,
575                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
576                                 .apply_uV = 1,
577                         },
578                 },
579                 [PCF50633_REGULATOR_LDO3] = {
580                         .constraints = {
581                                 .min_uV = 3000000,
582                                 .max_uV = 3000000,
583                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
584                                 .apply_uV = 1,
585                         },
586                 },
587                 [PCF50633_REGULATOR_LDO4] = {
588                         .constraints = {
589                                 .min_uV = 3200000,
590                                 .max_uV = 3200000,
591                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
592                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
593                                 .apply_uV = 1,
594                         },
595                         .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers),
596                         .consumer_supplies = ldo4_consumers,
597                 },
598                 [PCF50633_REGULATOR_LDO5] = {
599                         .constraints = {
600                                 .min_uV = 3000000,
601                                 .max_uV = 3000000,
602                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
603                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
604                                 .apply_uV = 1,
605                                 .state_mem = {
606                                         .enabled = 1,
607                                 },
608                         },
609                         .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers),
610                         .consumer_supplies = ldo5_consumers,
611                 },
612                 [PCF50633_REGULATOR_LDO6] = {
613                         .constraints = {
614                                 .min_uV = 3000000,
615                                 .max_uV = 3000000,
616                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
617                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
618                         },
619                         .num_consumer_supplies = ARRAY_SIZE(ldo6_consumers),
620                         .consumer_supplies = ldo6_consumers,
621                 },
622                 [PCF50633_REGULATOR_MEMLDO] = {
623                         .constraints = {
624                                 .min_uV = 1800000,
625                                 .max_uV = 1800000,
626                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
627                                 .state_mem = {
628                                         .enabled = 1,
629                                 },
630                         },
631                 },
632
633         },
634         .probe_done = gta02_pmu_attach_child_devices,
635         .mbc_event_callback = gta02_pmu_event_callback,
636 };
637
638
639 /* NOR Flash. */
640
641 #define GTA02_FLASH_BASE        0x18000000 /* GCS3 */
642 #define GTA02_FLASH_SIZE        0x200000 /* 2MBytes */
643
644 static struct physmap_flash_data gta02_nor_flash_data = {
645         .width          = 2,
646 };
647
648 static struct resource gta02_nor_flash_resource = {
649         .start          = GTA02_FLASH_BASE,
650         .end            = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
651         .flags          = IORESOURCE_MEM,
652 };
653
654 static struct platform_device gta02_nor_flash = {
655         .name           = "physmap-flash",
656         .id             = 0,
657         .dev            = {
658                 .platform_data  = &gta02_nor_flash_data,
659         },
660         .resource       = &gta02_nor_flash_resource,
661         .num_resources  = 1,
662 };
663
664 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
665         {
666                 I2C_BOARD_INFO("pcf50633", 0x73),
667                 .irq = GTA02_IRQ_PCF50633,
668                 .platform_data = &gta02_pcf_pdata,
669         },
670         {
671                 I2C_BOARD_INFO("wm8753", 0x1a),
672         },
673 };
674
675 static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
676         [0] = {
677                 /*
678                  * This name is also hard-coded in the boot loaders, so
679                  * changing it would would require all users to upgrade
680                  * their boot loaders, some of which are stored in a NOR
681                  * that is considered to be immutable.
682                  */
683                 .name           = "neo1973-nand",
684                 .nr_chips       = 1,
685                 .flash_bbt      = 1,
686         },
687 };
688
689 /*
690  * Choose a set of timings derived from S3C@2442B MCP54
691  * data sheet (K5D2G13ACM-D075 MCP Memory).
692  */
693
694 static struct s3c2410_platform_nand __initdata gta02_nand_info = {
695         .tacls          = 0,
696         .twrph0         = 25,
697         .twrph1         = 15,
698         .nr_sets        = ARRAY_SIZE(gta02_nand_sets),
699         .sets           = gta02_nand_sets,
700         .software_ecc   = 1,
701 };
702
703
704 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
705 {
706         switch (cmd) {
707         case S3C2410_UDC_P_ENABLE:
708                 pr_debug("%s S3C2410_UDC_P_ENABLE\n", __func__);
709                 gpio_set_value(GTA02_GPIO_USB_PULLUP, 1);
710                 break;
711         case S3C2410_UDC_P_DISABLE:
712                 pr_debug("%s S3C2410_UDC_P_DISABLE\n", __func__);
713                 gpio_set_value(GTA02_GPIO_USB_PULLUP, 0);
714                 break;
715         case S3C2410_UDC_P_RESET:
716                 pr_debug("%s S3C2410_UDC_P_RESET\n", __func__);
717                 /* FIXME: Do something here. */
718         }
719 }
720
721 /* Get PMU to set USB current limit accordingly. */
722 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
723         .vbus_draw      = gta02_udc_vbus_draw,
724         .udc_command    = gta02_udc_command,
725
726 };
727
728 /* USB */
729 static struct s3c2410_hcd_info gta02_usb_info __initdata = {
730         .port[0]        = {
731                 .flags  = S3C_HCDFLG_USED,
732         },
733         .port[1]        = {
734                 .flags  = 0,
735         },
736 };
737
738 /* Buttons */
739 static struct gpio_keys_button gta02_buttons[] = {
740         {
741                 .gpio = GTA02_GPIO_AUX_KEY,
742                 .code = KEY_PHONE,
743                 .desc = "Aux",
744                 .type = EV_KEY,
745                 .debounce_interval = 100,
746         },
747         {
748                 .gpio = GTA02_GPIO_HOLD_KEY,
749                 .code = KEY_PAUSE,
750                 .desc = "Hold",
751                 .type = EV_KEY,
752                 .debounce_interval = 100,
753         },
754 };
755
756 static struct gpio_keys_platform_data gta02_buttons_pdata = {
757         .buttons = gta02_buttons,
758         .nbuttons = ARRAY_SIZE(gta02_buttons),
759 };
760
761 static struct platform_device gta02_buttons_device = {
762         .name = "gpio-keys",
763         .id = -1,
764         .dev = {
765                 .platform_data = &gta02_buttons_pdata,
766         },
767 };
768
769 /* LEDs */
770 static struct gpio_led gta02_gpio_leds[] = {
771         {
772                 .name   = "gta02:red:aux",
773                 .gpio   = GTA02_GPIO_AUX_LED,
774         },
775 };
776
777 static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
778         .leds = gta02_gpio_leds,
779         .num_leds = ARRAY_SIZE(gta02_gpio_leds),
780 };
781
782 static struct platform_device gta02_leds_device = {
783         .name   = "leds-gpio",
784         .id             = -1,
785         .dev = {
786                 .platform_data = &gta02_gpio_leds_pdata,
787         },
788 };
789
790 static inline int gta02_pwm_to_gpio(int pwm_id)
791 {
792         return S3C2410_GPB(pwm_id);
793 }
794
795 static int gta02_pwm_led_init(struct device *dev, struct led_pwm *led)
796 {
797         int ret;
798         int gpio = gta02_pwm_to_gpio(led->pwm_id);
799
800         ret = gpio_request(gpio, dev_name(dev));
801         if (ret)
802                 return ret;
803
804         gpio_direction_output(gpio, 0);
805
806         return 0;
807 }
808
809 static enum led_brightness gta02_pwm_led_notify(struct device *dev,
810         struct led_pwm *led, enum led_brightness brightness)
811 {
812         int gpio = gta02_pwm_to_gpio(led->pwm_id);
813
814         if (brightness == led->max_brightness || brightness == 0) {
815                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_OUTPUT);
816                 gpio_set_value(gpio, brightness ? 1 : 0);
817
818                 brightness = 0;
819         } else {
820                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_SFN2);
821         }
822
823         return brightness;
824 }
825
826 static void gta02_pwm_led_exit(struct device *dev, struct led_pwm *led)
827 {
828         gpio_free(gta02_pwm_to_gpio(led->pwm_id));
829 }
830
831 static struct led_pwm gta02_pwm_leds[] = {
832         {
833                 .name = "gta02:orange:power",
834                 .max_brightness = 0xff,
835                 .pwm_period_ns = 1000000,
836                 .pwm_id = 0,
837         },
838         {
839                 .name = "gta02:blue:power",
840                 .max_brightness = 0xff,
841                 .pwm_period_ns = 1000000,
842                 .pwm_id = 1,
843         },
844         {
845                 .name = "gta02::vibrator",
846                 .max_brightness = 0x3f,
847                 .pwm_period_ns = 60000000,
848                 .pwm_id = 3,
849         }
850 };
851
852 static struct led_pwm_platform_data gta02_pwm_leds_pdata = {
853         .num_leds = ARRAY_SIZE(gta02_pwm_leds),
854         .leds = gta02_pwm_leds,
855
856         .init = gta02_pwm_led_init,
857         .notify = gta02_pwm_led_notify,
858         .exit = gta02_pwm_led_exit,
859 };
860
861 static struct platform_device gta02_pwm_leds_device = {
862         .name   = "leds_pwm",
863         .id     = -1,
864         .dev = {
865                 .platform_data = &gta02_pwm_leds_pdata,
866         }
867 };
868
869 static void __init gta02_map_io(void)
870 {
871         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
872         s3c24xx_init_clocks(12000000);
873         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
874 }
875
876
877 /* These are the guys that don't need to be children of PMU. */
878
879 static struct platform_device *gta02_devices[] __initdata = {
880         &s3c_device_ohci,
881         &s3c_device_wdt,
882         &s3c_device_sdi,
883         &s3c_device_usbgadget,
884         &s3c_device_nand,
885         &gta02_nor_flash,
886         &s3c_device_timer[0],
887         &s3c_device_timer[1],
888         &s3c_device_timer[3],
889         &s3c_device_iis,
890         &s3c_device_i2c0,
891         &gta02_buttons_device,
892         &gta02_leds_device,
893         &gta02_pwm_leds_device,
894         &gta02_pm_gps_dev,
895         &gta02_pm_bt_dev,
896         &gta02_pm_wlan_dev,
897         &gta02_glamo_dev,
898 };
899
900 /* These guys DO need to be children of PMU. */
901
902 static struct platform_device *gta02_devices_pmu_children[] = {
903 };
904
905 /*
906  * This is called when pc50633 is probed, quite late in the day since it is an
907  * I2C bus device.  Here we can define platform devices with the advantage that
908  * we can mark the pcf50633 as the parent.  This makes them get suspended and
909  * resumed with their parent the pcf50633 still around.  All devices whose
910  * operation depends on something from pcf50633 must have this relationship
911  * made explicit like this, or suspend and resume will become an unreliable
912  * hellworld.
913  */
914
915 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
916 {
917         int n;
918
919         /* Grab a copy of the now probed PMU pointer. */
920         gta02_pcf = pcf;
921
922         for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
923                 gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
924
925         platform_add_devices(gta02_devices_pmu_children,
926                              ARRAY_SIZE(gta02_devices_pmu_children));
927 }
928
929 static void gta02_poweroff(void)
930 {
931         pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
932 }
933
934 struct gta02_device_children {
935         const char *dev_name;
936         size_t num_children;
937         struct platform_device **children;
938         void (*probed_callback)(struct device *dev);
939 };
940
941 static struct platform_device* gta02_pcf50633_gpio_children[] = {
942         &gta02_gsm_supply_device,
943 };
944
945 static struct platform_device* gta02_gsm_supply_children[] = {
946         &gta02_pm_gsm_dev,
947 };
948
949 static struct gta02_device_children gta02_device_children[] = {
950         {
951                 .dev_name = "pcf50633-gpio",
952                 .num_children = 1,
953                 .children = gta02_pcf50633_gpio_children,
954         },
955         {
956                 .dev_name = "reg-fixed-voltage.1",
957                 .num_children = 1,
958                 .children = gta02_gsm_supply_children,
959         },
960         {
961                 .dev_name = "spi2.0",
962                 .probed_callback = gta02_jbt6k74_probe_completed,
963         },
964 };
965
966 static int gta02_add_child_devices(struct device *parent,
967                                    struct platform_device **children,
968                                                                    size_t num_children)
969 {
970         size_t i;
971
972         for (i = 0; i < num_children; ++i)
973                 children[i]->dev.parent = parent;
974
975         return platform_add_devices(children, num_children);
976 }
977
978 static int gta02_device_registered(struct notifier_block *block,
979                                    unsigned long action, void *data)
980 {
981         struct device *dev = data;
982         const char *devname = dev_name(dev);
983         size_t i;
984
985         if (action != BUS_NOTIFY_BOUND_DRIVER)
986                 return 0;
987
988         for (i = 0; i < ARRAY_SIZE(gta02_device_children); ++i) {
989                 if (strcmp(devname, gta02_device_children[i].dev_name) == 0) {
990                         gta02_add_child_devices(dev, gta02_device_children[i].children,
991                         gta02_device_children[i].num_children);
992
993                         if (gta02_device_children[i].probed_callback)
994                                 gta02_device_children[i].probed_callback(dev);
995                         break;
996                 }
997         }
998
999         return 0;
1000 }
1001
1002 static struct notifier_block gta02_device_register_notifier = {
1003         .notifier_call = gta02_device_registered,
1004         .priority = INT_MAX,
1005 };
1006
1007
1008 /* On hardware rev 5 and earlier the leds are missing a resistor and reading
1009  * from their gpio pins will always return 0, so we have to shadow the
1010  * led states software */
1011 static unsigned long gpb_shadow;
1012 extern struct s3c_gpio_chip s3c24xx_gpios[];
1013
1014 static void gta02_gpb_set(struct gpio_chip *chip,
1015                                 unsigned offset, int value)
1016 {
1017         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
1018         unsigned long flags;
1019         unsigned long dat;
1020
1021         local_irq_save(flags);
1022
1023         dat = __raw_readl(base + 0x04) | gpb_shadow;
1024         dat &= ~(1 << offset);
1025         gpb_shadow &= ~(1 << offset);
1026         if (value) {
1027                 dat |= 1 << offset;
1028                 switch (offset) {
1029                 case 0 ... 2:
1030                         gpb_shadow |= 1 << offset;
1031                         break;
1032                 default:
1033                         break;
1034                 }
1035         }
1036         __raw_writel(dat, base + 0x04);
1037
1038         local_irq_restore(flags);
1039 }
1040
1041 static int gta02_gpb_get(struct gpio_chip *chip, unsigned offset)
1042 {
1043         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
1044         unsigned long val;
1045
1046         val = __raw_readl(base + 0x04) | gpb_shadow;
1047         val >>= offset;
1048         val &= 1;
1049
1050         return val;
1051 }
1052
1053 static void gta02_hijack_gpb(void)
1054 {
1055 /* Uncomment this, once support for S3C_SYSTEM_REV_ATAG has been merged
1056  * upstream.
1057         if (S3C_SYSTEM_REV_ATAG > GTA02v5_SYSTEM_REV)
1058                 return;
1059 */
1060
1061         s3c24xx_gpios[1].chip.set = gta02_gpb_set;
1062         s3c24xx_gpios[1].chip.get = gta02_gpb_get;
1063 }
1064
1065 /*
1066  * Allow the bootloader to enable hw ecc
1067  * hardware_ecc=1|0
1068  */
1069 static int __init hardware_ecc_setup(char *str)
1070 {
1071         if (str && str[0] == '1')
1072                 gta02_nand_info.software_ecc = 0;
1073         return 1;
1074 }
1075 __setup("hardware_ecc=", hardware_ecc_setup);
1076
1077 static void gta02_request_gpios(void)
1078 {
1079         int ret;
1080         ret = gpio_request(GTA02_GPIO_USB_PULLUP, "USB pullup");
1081         if (ret) {
1082                 printk(KERN_ERR "Failed to request USB pullup gpio pin: %d\n", ret);
1083         } else {
1084                 ret = gpio_direction_output(GTA02_GPIO_USB_PULLUP, 0);
1085                 if (ret)
1086                         printk(KERN_ERR "Failed to set USB pullup gpio direction: %d\n", ret);
1087     }
1088 }
1089
1090 static void __init gta02_machine_init(void)
1091 {
1092         /* Set the panic callback to make AUX LED blink at ~5Hz. */
1093         panic_blink = gta02_panic_blink;
1094
1095         bus_register_notifier(&platform_bus_type, &gta02_device_register_notifier);
1096         bus_register_notifier(&spi_bus_type, &gta02_device_register_notifier);
1097
1098         gta02_hijack_gpb();
1099
1100         gta02_request_gpios();
1101
1102         s3c_pm_init();
1103
1104 #ifdef CONFIG_CHARGER_PCF50633
1105         INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
1106 #endif
1107
1108         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
1109         s3c_ohci_set_platdata(&gta02_usb_info);
1110         s3c_nand_set_platdata(&gta02_nand_info);
1111         s3c_i2c0_set_platdata(NULL);
1112         spi_register_board_info(gta02_spi_board_info,
1113                                 ARRAY_SIZE(gta02_spi_board_info));
1114
1115         i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
1116  
1117         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
1118
1119         pm_power_off = gta02_poweroff;
1120 }
1121
1122
1123 MACHINE_START(NEO1973_GTA02, "GTA02")
1124         /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
1125         .phys_io        = S3C2410_PA_UART,
1126         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
1127         .boot_params    = S3C2410_SDRAM_PA + 0x100,
1128         .map_io         = gta02_map_io,
1129         .init_irq       = s3c24xx_init_irq,
1130         .init_machine   = gta02_machine_init,
1131         .timer          = &s3c24xx_timer,
1132 MACHINE_END