gta02: Add notify handler to probe device children
[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
42 #include <linux/mmc/host.h>
43
44 #include <linux/mtd/mtd.h>
45 #include <linux/mtd/nand.h>
46 #include <linux/mtd/nand_ecc.h>
47 #include <linux/mtd/partitions.h>
48 #include <linux/mtd/physmap.h>
49 #include <linux/io.h>
50
51 #include <linux/i2c.h>
52 #include <linux/backlight.h>
53 #include <linux/regulator/machine.h>
54
55 #include <linux/mfd/pcf50633/core.h>
56 #include <linux/mfd/pcf50633/mbc.h>
57 #include <linux/mfd/pcf50633/adc.h>
58 #include <linux/mfd/pcf50633/gpio.h>
59 #include <linux/mfd/pcf50633/pmic.h>
60
61 #include <linux/input.h>
62 #include <linux/gpio_keys.h>
63
64 #include <linux/leds.h>
65 #include <linux/leds_pwm.h>
66
67 #include <asm/mach/arch.h>
68 #include <asm/mach/map.h>
69 #include <asm/mach/irq.h>
70
71 #include <asm/irq.h>
72 #include <asm/mach-types.h>
73
74 #include <mach/regs-irq.h>
75 #include <mach/regs-gpio.h>
76 #include <mach/regs-gpioj.h>
77 #include <mach/fb.h>
78
79 #include <mach/spi.h>
80 #include <mach/spi-gpio.h>
81 #include <plat/usb-control.h>
82 #include <mach/regs-mem.h>
83 #include <mach/hardware.h>
84
85 #include <mach/gta02.h>
86
87 #include <plat/regs-serial.h>
88 #include <plat/nand.h>
89 #include <plat/devs.h>
90 #include <plat/cpu.h>
91 #include <plat/pm.h>
92 #include <plat/udc.h>
93 #include <plat/gpio-cfg.h>
94 #include <plat/gpio-core.h>
95 #include <plat/iic.h>
96
97 static struct pcf50633 *gta02_pcf;
98
99 /*
100  * This gets called every 1ms when we paniced.
101  */
102
103 static long gta02_panic_blink(long count)
104 {
105         long delay = 0;
106         static long last_blink;
107         static char led;
108
109         /* Fast blink: 200ms period. */
110         if (count - last_blink < 100)
111                 return 0;
112
113         led ^= 1;
114         gpio_direction_output(GTA02_GPIO_AUX_LED, led);
115
116         last_blink = count;
117
118         return delay;
119 }
120
121
122 static struct map_desc gta02_iodesc[] __initdata = {
123         {
124                 .virtual        = 0xe0000000,
125                 .pfn            = __phys_to_pfn(S3C2410_CS3 + 0x01000000),
126                 .length         = SZ_1M,
127                 .type           = MT_DEVICE
128         },
129 };
130
131 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
132 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
133 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
134
135 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
136         [0] = {
137                 .hwport         = 0,
138                 .flags          = 0,
139                 .ucon           = UCON,
140                 .ulcon          = ULCON,
141                 .ufcon          = UFCON,
142         },
143         [1] = {
144                 .hwport         = 1,
145                 .flags          = 0,
146                 .ucon           = UCON,
147                 .ulcon          = ULCON,
148                 .ufcon          = UFCON,
149         },
150         [2] = {
151                 .hwport         = 2,
152                 .flags          = 0,
153                 .ucon           = UCON,
154                 .ulcon          = ULCON,
155                 .ufcon          = UFCON,
156         },
157 };
158
159 #ifdef CONFIG_CHARGER_PCF50633
160 /*
161  * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
162  * We use this to recognize that we can pull 1A from the USB socket.
163  *
164  * These constants are the measured pcf50633 ADC levels with the 1A
165  * charger / 48K resistor, and with no pulldown resistor.
166  */
167
168 #define ADC_NOM_CHG_DETECT_1A 6
169 #define ADC_NOM_CHG_DETECT_USB 43
170
171 static void
172 gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
173 {
174         int  ma;
175
176         /* Interpret charger type */
177         if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
178
179                 /*
180                  * Sanity - stop GPO driving out now that we have a 1A charger
181                  * GPO controls USB Host power generation on GTA02
182                  */
183                 pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
184
185                 ma = 1000;
186         } else
187                 ma = 100;
188
189         pcf50633_mbc_usb_curlim_set(pcf, ma);
190 }
191
192 static struct delayed_work gta02_charger_work;
193 static int gta02_usb_vbus_draw;
194
195 static void gta02_charger_worker(struct work_struct *work)
196 {
197         if (gta02_usb_vbus_draw) {
198                 pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
199                 return;
200         }
201
202 #ifdef CONFIG_PCF50633_ADC
203         pcf50633_adc_async_read(gta02_pcf,
204                                 PCF50633_ADCC1_MUX_ADCIN1,
205                                 PCF50633_ADCC1_AVERAGE_16,
206                                 gta02_configure_pmu_for_charger,
207                                 NULL);
208 #else
209         /*
210          * If the PCF50633 ADC is disabled we fallback to a
211          * 100mA limit for safety.
212          */
213         pcf50633_mbc_usb_curlim_set(pcf, 100);
214 #endif
215 }
216
217 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
218
219 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
220 {
221         if (irq == PCF50633_IRQ_USBINS) {
222                 schedule_delayed_work(&gta02_charger_work,
223                                       GTA02_CHARGER_CONFIGURE_TIMEOUT);
224
225                 return;
226         }
227
228         if (irq == PCF50633_IRQ_USBREM) {
229                 cancel_delayed_work_sync(&gta02_charger_work);
230                 gta02_usb_vbus_draw = 0;
231         }
232 }
233
234 static void gta02_udc_vbus_draw(unsigned int ma)
235 {
236         if (!gta02_pcf)
237                 return;
238
239         gta02_usb_vbus_draw = ma;
240
241         schedule_delayed_work(&gta02_charger_work,
242                               GTA02_CHARGER_CONFIGURE_TIMEOUT);
243 }
244 #else /* !CONFIG_CHARGER_PCF50633 */
245 #define gta02_pmu_event_callback        NULL
246 #define gta02_udc_vbus_draw             NULL
247 #endif
248
249 /*
250  * This is called when pc50633 is probed, unfortunately quite late in the
251  * day since it is an I2C bus device. Here we can belatedly define some
252  * platform devices with the advantage that we can mark the pcf50633 as the
253  * parent. This makes them get suspended and resumed with their parent
254  * the pcf50633 still around.
255  */
256
257 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf);
258
259
260 static char *gta02_batteries[] = {
261         "battery",
262 };
263
264 struct pcf50633_platform_data gta02_pcf_pdata = {
265         .resumers = {
266                 [0] =   PCF50633_INT1_USBINS |
267                         PCF50633_INT1_USBREM |
268                         PCF50633_INT1_ALARM,
269                 [1] =   PCF50633_INT2_ONKEYF,
270                 [2] =   PCF50633_INT3_ONKEY1S,
271                 [3] =   PCF50633_INT4_LOWSYS |
272                         PCF50633_INT4_LOWBAT |
273                         PCF50633_INT4_HIGHTMP,
274         },
275
276         .batteries = gta02_batteries,
277         .num_batteries = ARRAY_SIZE(gta02_batteries),
278
279         .charger_reference_current_ma = 1000,
280
281         .gpio_base = GTA02_GPIO_PCF_BASE,
282
283         .reg_init_data = {
284                 [PCF50633_REGULATOR_AUTO] = {
285                         .constraints = {
286                                 .min_uV = 3300000,
287                                 .max_uV = 3300000,
288                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
289                                 .always_on = 1,
290                                 .apply_uV = 1,
291                                 .state_mem = {
292                                         .enabled = 1,
293                                 },
294                         },
295                 },
296                 [PCF50633_REGULATOR_DOWN1] = {
297                         .constraints = {
298                                 .min_uV = 1300000,
299                                 .max_uV = 1600000,
300                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
301                                 .always_on = 1,
302                                 .apply_uV = 1,
303                         },
304                 },
305                 [PCF50633_REGULATOR_DOWN2] = {
306                         .constraints = {
307                                 .min_uV = 1800000,
308                                 .max_uV = 1800000,
309                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
310                                 .apply_uV = 1,
311                                 .always_on = 1,
312                                 .state_mem = {
313                                         .enabled = 1,
314                                 },
315                         },
316                 },
317                 [PCF50633_REGULATOR_HCLDO] = {
318                         .constraints = {
319                                 .min_uV = 2000000,
320                                 .max_uV = 3300000,
321                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
322                                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | 
323                                                 REGULATOR_CHANGE_STATUS,
324                         },
325                 },
326                 [PCF50633_REGULATOR_LDO1] = {
327                         .constraints = {
328                                 .min_uV = 3300000,
329                                 .max_uV = 3300000,
330                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
331                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
332                                 .apply_uV = 1,
333                                 .state_mem = {
334                                         .enabled = 0,
335                                 },
336                         },
337                 },
338                 [PCF50633_REGULATOR_LDO2] = {
339                         .constraints = {
340                                 .min_uV = 3300000,
341                                 .max_uV = 3300000,
342                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
343                                 .apply_uV = 1,
344                         },
345                 },
346                 [PCF50633_REGULATOR_LDO3] = {
347                         .constraints = {
348                                 .min_uV = 3000000,
349                                 .max_uV = 3000000,
350                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
351                                 .apply_uV = 1,
352                         },
353                 },
354                 [PCF50633_REGULATOR_LDO4] = {
355                         .constraints = {
356                                 .min_uV = 3200000,
357                                 .max_uV = 3200000,
358                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
359                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
360                                 .apply_uV = 1,
361                         },
362                 },
363                 [PCF50633_REGULATOR_LDO5] = {
364                         .constraints = {
365                                 .min_uV = 3000000,
366                                 .max_uV = 3000000,
367                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
368                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
369                                 .apply_uV = 1,
370                                 .state_mem = {
371                                         .enabled = 1,
372                                 },
373                         },
374                 },
375                 [PCF50633_REGULATOR_LDO6] = {
376                         .constraints = {
377                                 .min_uV = 3000000,
378                                 .max_uV = 3000000,
379                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
380                         },
381                 },
382                 [PCF50633_REGULATOR_MEMLDO] = {
383                         .constraints = {
384                                 .min_uV = 1800000,
385                                 .max_uV = 1800000,
386                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
387                                 .state_mem = {
388                                         .enabled = 1,
389                                 },
390                         },
391                 },
392
393         },
394         .probe_done = gta02_pmu_attach_child_devices,
395         .mbc_event_callback = gta02_pmu_event_callback,
396 };
397
398
399 /* NOR Flash. */
400
401 #define GTA02_FLASH_BASE        0x18000000 /* GCS3 */
402 #define GTA02_FLASH_SIZE        0x200000 /* 2MBytes */
403
404 static struct physmap_flash_data gta02_nor_flash_data = {
405         .width          = 2,
406 };
407
408 static struct resource gta02_nor_flash_resource = {
409         .start          = GTA02_FLASH_BASE,
410         .end            = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
411         .flags          = IORESOURCE_MEM,
412 };
413
414 static struct platform_device gta02_nor_flash = {
415         .name           = "physmap-flash",
416         .id             = 0,
417         .dev            = {
418                 .platform_data  = &gta02_nor_flash_data,
419         },
420         .resource       = &gta02_nor_flash_resource,
421         .num_resources  = 1,
422 };
423
424 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
425         {
426                 I2C_BOARD_INFO("pcf50633", 0x73),
427                 .irq = GTA02_IRQ_PCF50633,
428                 .platform_data = &gta02_pcf_pdata,
429         },
430         {
431                 I2C_BOARD_INFO("wm8753", 0x1a),
432         },
433 };
434
435 static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
436         [0] = {
437                 /*
438                  * This name is also hard-coded in the boot loaders, so
439                  * changing it would would require all users to upgrade
440                  * their boot loaders, some of which are stored in a NOR
441                  * that is considered to be immutable.
442                  */
443                 .name           = "neo1973-nand",
444                 .nr_chips       = 1,
445                 .flash_bbt      = 1,
446         },
447 };
448
449 /*
450  * Choose a set of timings derived from S3C@2442B MCP54
451  * data sheet (K5D2G13ACM-D075 MCP Memory).
452  */
453
454 static struct s3c2410_platform_nand __initdata gta02_nand_info = {
455         .tacls          = 0,
456         .twrph0         = 25,
457         .twrph1         = 15,
458         .nr_sets        = ARRAY_SIZE(gta02_nand_sets),
459         .sets           = gta02_nand_sets,
460         .software_ecc   = 1,
461 };
462
463
464 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
465 {
466         switch (cmd) {
467         case S3C2410_UDC_P_ENABLE:
468                 pr_debug("%s S3C2410_UDC_P_ENABLE\n", __func__);
469                 gpio_set_value(GTA02_GPIO_USB_PULLUP, 1);
470                 break;
471         case S3C2410_UDC_P_DISABLE:
472                 pr_debug("%s S3C2410_UDC_P_DISABLE\n", __func__);
473                 gpio_set_value(GTA02_GPIO_USB_PULLUP, 0);
474                 break;
475         case S3C2410_UDC_P_RESET:
476                 pr_debug("%s S3C2410_UDC_P_RESET\n", __func__);
477                 /* FIXME: Do something here. */
478         }
479 }
480
481 /* Get PMU to set USB current limit accordingly. */
482 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
483         .vbus_draw      = gta02_udc_vbus_draw,
484         .udc_command    = gta02_udc_command,
485
486 };
487
488
489
490 static void gta02_bl_set_intensity(int intensity)
491 {
492         struct pcf50633 *pcf = gta02_pcf;
493         int old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
494
495         /* We map 8-bit intensity to 6-bit intensity in hardware. */
496         intensity >>= 2;
497
498         /*
499          * This can happen during, eg, print of panic on blanked console,
500          * but we can't service i2c without interrupts active, so abort.
501          */
502         if (in_atomic()) {
503                 printk(KERN_ERR "gta02_bl_set_intensity called while atomic\n");
504                 return;
505         }
506
507         old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
508         if (intensity == old_intensity)
509                 return;
510
511         /* We can't do this anywhere else. */
512         pcf50633_reg_write(pcf, PCF50633_REG_LEDDIM, 5);
513
514         if (!(pcf50633_reg_read(pcf, PCF50633_REG_LEDENA) & 3))
515                 old_intensity = 0;
516
517         /*
518          * The PCF50633 cannot handle LEDOUT = 0 (datasheet p60)
519          * if seen, you have to re-enable the LED unit.
520          */
521         if (!intensity || !old_intensity)
522                 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0);
523
524         /* Illegal to set LEDOUT to 0. */
525         if (!intensity)
526                 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f, 2);
527         else
528                 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f,
529                                           intensity);
530
531         if (intensity)
532                 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 2);
533
534 }
535
536 static struct generic_bl_info gta02_bl_info = {
537         .name                   = "gta02-bl",
538         .max_intensity          = 0xff,
539         .default_intensity      = 0xff,
540         .set_bl_intensity       = gta02_bl_set_intensity,
541 };
542
543 static struct platform_device gta02_bl_dev = {
544         .name                   = "generic-bl",
545         .id                     = 1,
546         .dev = {
547                 .platform_data = &gta02_bl_info,
548         },
549 };
550
551
552
553 /* USB */
554 static struct s3c2410_hcd_info gta02_usb_info __initdata = {
555         .port[0]        = {
556                 .flags  = S3C_HCDFLG_USED,
557         },
558         .port[1]        = {
559                 .flags  = 0,
560         },
561 };
562
563 /* Buttons */
564 static struct gpio_keys_button gta02_buttons[] = {
565         {
566                 .gpio = GTA02_GPIO_AUX_KEY,
567                 .code = KEY_PHONE,
568                 .desc = "Aux",
569                 .type = EV_KEY,
570                 .debounce_interval = 100,
571         },
572         {
573                 .gpio = GTA02_GPIO_HOLD_KEY,
574                 .code = KEY_PAUSE,
575                 .desc = "Hold",
576                 .type = EV_KEY,
577                 .debounce_interval = 100,
578         },
579 };
580
581 static struct gpio_keys_platform_data gta02_buttons_pdata = {
582         .buttons = gta02_buttons,
583         .nbuttons = ARRAY_SIZE(gta02_buttons),
584 };
585
586 static struct platform_device gta02_buttons_device = {
587         .name = "gpio-keys",
588         .id = -1,
589         .dev = {
590                 .platform_data = &gta02_buttons_pdata,
591         },
592 };
593
594 /* LEDs */
595 static struct gpio_led gta02_gpio_leds[] = {
596         {
597                 .name   = "gta02:red:aux",
598                 .gpio   = GTA02_GPIO_AUX_LED,
599         },
600 };
601
602 static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
603         .leds = gta02_gpio_leds,
604         .num_leds = ARRAY_SIZE(gta02_gpio_leds),
605 };
606
607 static struct platform_device gta02_leds_device = {
608         .name   = "leds-gpio",
609         .id             = -1,
610         .dev = {
611                 .platform_data = &gta02_gpio_leds_pdata,
612         },
613 };
614
615 static inline int gta02_pwm_to_gpio(int pwm_id)
616 {
617         return S3C2410_GPB(pwm_id);
618 }
619
620 static int gta02_pwm_led_init(struct device *dev, struct led_pwm *led)
621 {
622         int ret;
623         int gpio = gta02_pwm_to_gpio(led->pwm_id);
624
625         ret = gpio_request(gpio, dev_name(dev));
626         if (ret)
627                 return ret;
628
629         gpio_direction_output(gpio, 0);
630
631         return 0;
632 }
633
634 static enum led_brightness gta02_pwm_led_notify(struct device *dev,
635         struct led_pwm *led, enum led_brightness brightness)
636 {
637         int gpio = gta02_pwm_to_gpio(led->pwm_id);
638
639         if (brightness == led->max_brightness || brightness == 0) {
640                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_OUTPUT);
641                 gpio_set_value(gpio, brightness ? 1 : 0);
642
643                 brightness = 0;
644         } else {
645                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_SFN2);
646         }
647
648         return brightness;
649 }
650
651 static void gta02_pwm_led_exit(struct device *dev, struct led_pwm *led)
652 {
653         gpio_free(gta02_pwm_to_gpio(led->pwm_id));
654 }
655
656 static struct led_pwm gta02_pwm_leds[] = {
657         {
658                 .name = "gta02:orange:power",
659                 .max_brightness = 0xff,
660                 .pwm_period_ns = 1000000,
661                 .pwm_id = 0,
662         },
663         {
664                 .name = "gta02:blue:power",
665                 .max_brightness = 0xff,
666                 .pwm_period_ns = 1000000,
667                 .pwm_id = 1,
668         },
669         {
670                 .name = "gta02::vibrator",
671                 .max_brightness = 0x3f,
672                 .pwm_period_ns = 60000000,
673                 .pwm_id = 3,
674         }
675 };
676
677 static struct led_pwm_platform_data gta02_pwm_leds_pdata = {
678         .num_leds = ARRAY_SIZE(gta02_pwm_leds),
679         .leds = gta02_pwm_leds,
680
681         .init = gta02_pwm_led_init,
682         .notify = gta02_pwm_led_notify,
683         .exit = gta02_pwm_led_exit,
684 };
685
686 static struct platform_device gta02_pwm_leds_device = {
687         .name   = "leds_pwm",
688         .id     = -1,
689         .dev = {
690                 .platform_data = &gta02_pwm_leds_pdata,
691         }
692 };
693
694 static void __init gta02_map_io(void)
695 {
696         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
697         s3c24xx_init_clocks(12000000);
698         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
699 }
700
701
702 /* These are the guys that don't need to be children of PMU. */
703
704 static struct platform_device *gta02_devices[] __initdata = {
705         &s3c_device_ohci,
706         &s3c_device_wdt,
707         &s3c_device_sdi,
708         &s3c_device_usbgadget,
709         &s3c_device_nand,
710         &gta02_nor_flash,
711         &s3c_device_timer[0],
712         &s3c_device_timer[1],
713         &s3c_device_timer[3],
714         &s3c_device_iis,
715         &s3c_device_i2c0,
716         &gta02_buttons_device,
717         &gta02_leds_device,
718         &gta02_pwm_leds_device,
719 };
720
721 /* These guys DO need to be children of PMU. */
722
723 static struct platform_device *gta02_devices_pmu_children[] = {
724         &gta02_bl_dev,
725 };
726
727
728 /*
729  * This is called when pc50633 is probed, quite late in the day since it is an
730  * I2C bus device.  Here we can define platform devices with the advantage that
731  * we can mark the pcf50633 as the parent.  This makes them get suspended and
732  * resumed with their parent the pcf50633 still around.  All devices whose
733  * operation depends on something from pcf50633 must have this relationship
734  * made explicit like this, or suspend and resume will become an unreliable
735  * hellworld.
736  */
737
738 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
739 {
740         int n;
741
742         /* Grab a copy of the now probed PMU pointer. */
743         gta02_pcf = pcf;
744
745         for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
746                 gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
747
748         platform_add_devices(gta02_devices_pmu_children,
749                              ARRAY_SIZE(gta02_devices_pmu_children));
750 }
751
752 static void gta02_poweroff(void)
753 {
754         pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
755 }
756
757 struct gta02_device_children {
758         const char *dev_name;
759         size_t num_children;
760         struct platform_device **children;
761         void (*probed_callback)(struct device *dev);
762 };
763
764 static struct gta02_device_children gta02_device_children[] = {
765 };
766
767 static int gta02_add_child_devices(struct device *parent,
768                                    struct platform_device **children,
769                                                                    size_t num_children)
770 {
771         size_t i;
772
773         for (i = 0; i < num_children; ++i)
774                 children[i]->dev.parent = parent;
775
776         return platform_add_devices(children, num_children);
777 }
778
779 static int gta02_device_registered(struct notifier_block *block,
780                                    unsigned long action, void *data)
781 {
782         struct device *dev = data;
783         const char *devname = dev_name(dev);
784         size_t i;
785
786         if (action != BUS_NOTIFY_BOUND_DRIVER)
787                 return 0;
788
789         for (i = 0; i < ARRAY_SIZE(gta02_device_children); ++i) {
790                 if (strcmp(devname, gta02_device_children[i].dev_name) == 0) {
791                         gta02_add_child_devices(dev, gta02_device_children[i].children,
792                         gta02_device_children[i].num_children);
793
794                         if (gta02_device_children[i].probed_callback)
795                                 gta02_device_children[i].probed_callback(dev);
796                         break;
797                 }
798         }
799
800         return 0;
801 }
802
803 static struct notifier_block gta02_device_register_notifier = {
804         .notifier_call = gta02_device_registered,
805         .priority = INT_MAX,
806 };
807
808
809 /* On hardware rev 5 and earlier the leds are missing a resistor and reading
810  * from their gpio pins will always return 0, so we have to shadow the
811  * led states software */
812 static unsigned long gpb_shadow;
813 extern struct s3c_gpio_chip s3c24xx_gpios[];
814
815 static void gta02_gpb_set(struct gpio_chip *chip,
816                                 unsigned offset, int value)
817 {
818         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
819         unsigned long flags;
820         unsigned long dat;
821
822         local_irq_save(flags);
823
824         dat = __raw_readl(base + 0x04) | gpb_shadow;
825         dat &= ~(1 << offset);
826         gpb_shadow &= ~(1 << offset);
827         if (value) {
828                 dat |= 1 << offset;
829                 switch (offset) {
830                 case 0 ... 2:
831                         gpb_shadow |= 1 << offset;
832                         break;
833                 default:
834                         break;
835                 }
836         }
837         __raw_writel(dat, base + 0x04);
838
839         local_irq_restore(flags);
840 }
841
842 static int gta02_gpb_get(struct gpio_chip *chip, unsigned offset)
843 {
844         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
845         unsigned long val;
846
847         val = __raw_readl(base + 0x04) | gpb_shadow;
848         val >>= offset;
849         val &= 1;
850
851         return val;
852 }
853
854 static void gta02_hijack_gpb(void)
855 {
856 /* Uncomment this, once support for S3C_SYSTEM_REV_ATAG has been merged
857  * upstream.
858         if (S3C_SYSTEM_REV_ATAG > GTA02v5_SYSTEM_REV)
859                 return;
860 */
861
862         s3c24xx_gpios[1].chip.set = gta02_gpb_set;
863         s3c24xx_gpios[1].chip.get = gta02_gpb_get;
864 }
865
866 /*
867  * Allow the bootloader to enable hw ecc
868  * hardware_ecc=1|0
869  */
870 static int __init hardware_ecc_setup(char *str)
871 {
872         if (str && str[0] == '1')
873                 gta02_nand_info.software_ecc = 0;
874         return 1;
875 }
876 __setup("hardware_ecc=", hardware_ecc_setup);
877
878 static void gta02_request_gpios(void)
879 {
880         int ret;
881         ret = gpio_request(GTA02_GPIO_USB_PULLUP, "USB pullup");
882         if (ret) {
883                 printk(KERN_ERR "Failed to request USB pullup gpio pin: %d\n", ret);
884         } else {
885                 ret = gpio_direction_output(GTA02_GPIO_USB_PULLUP, 0);
886                 if (ret)
887                         printk(KERN_ERR "Failed to set USB pullup gpio direction: %d\n", ret);
888     }
889 }
890
891 static void __init gta02_machine_init(void)
892 {
893         /* Set the panic callback to make AUX LED blink at ~5Hz. */
894         panic_blink = gta02_panic_blink;
895
896         bus_register_notifier(&platform_bus_type, &gta02_device_register_notifier);
897         bus_register_notifier(&spi_bus_type, &gta02_device_register_notifier);
898
899         gta02_hijack_gpb();
900
901         gta02_request_gpios();
902
903         s3c_pm_init();
904
905 #ifdef CONFIG_CHARGER_PCF50633
906         INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
907 #endif
908
909         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
910         s3c_ohci_set_platdata(&gta02_usb_info);
911         s3c_nand_set_platdata(&gta02_nand_info);
912         s3c_i2c0_set_platdata(NULL);
913
914         i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
915
916         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
917
918         pm_power_off = gta02_poweroff;
919 }
920
921
922 MACHINE_START(NEO1973_GTA02, "GTA02")
923         /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
924         .phys_io        = S3C2410_PA_UART,
925         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
926         .boot_params    = S3C2410_SDRAM_PA + 0x100,
927         .map_io         = gta02_map_io,
928         .init_irq       = s3c24xx_init_irq,
929         .init_machine   = gta02_machine_init,
930         .timer          = &s3c24xx_timer,
931 MACHINE_END