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