ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
[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         .reg_init_data = {
282                 [PCF50633_REGULATOR_AUTO] = {
283                         .constraints = {
284                                 .min_uV = 3300000,
285                                 .max_uV = 3300000,
286                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
287                                 .always_on = 1,
288                                 .apply_uV = 1,
289                                 .state_mem = {
290                                         .enabled = 1,
291                                 },
292                         },
293                 },
294                 [PCF50633_REGULATOR_DOWN1] = {
295                         .constraints = {
296                                 .min_uV = 1300000,
297                                 .max_uV = 1600000,
298                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
299                                 .always_on = 1,
300                                 .apply_uV = 1,
301                         },
302                 },
303                 [PCF50633_REGULATOR_DOWN2] = {
304                         .constraints = {
305                                 .min_uV = 1800000,
306                                 .max_uV = 1800000,
307                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
308                                 .apply_uV = 1,
309                                 .always_on = 1,
310                                 .state_mem = {
311                                         .enabled = 1,
312                                 },
313                         },
314                 },
315                 [PCF50633_REGULATOR_HCLDO] = {
316                         .constraints = {
317                                 .min_uV = 2000000,
318                                 .max_uV = 3300000,
319                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
320                                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
321                                 .always_on = 1,
322                         },
323                 },
324                 [PCF50633_REGULATOR_LDO1] = {
325                         .constraints = {
326                                 .min_uV = 3300000,
327                                 .max_uV = 3300000,
328                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
329                                 .apply_uV = 1,
330                                 .state_mem = {
331                                         .enabled = 0,
332                                 },
333                         },
334                 },
335                 [PCF50633_REGULATOR_LDO2] = {
336                         .constraints = {
337                                 .min_uV = 3300000,
338                                 .max_uV = 3300000,
339                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
340                                 .apply_uV = 1,
341                         },
342                 },
343                 [PCF50633_REGULATOR_LDO3] = {
344                         .constraints = {
345                                 .min_uV = 3000000,
346                                 .max_uV = 3000000,
347                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
348                                 .apply_uV = 1,
349                         },
350                 },
351                 [PCF50633_REGULATOR_LDO4] = {
352                         .constraints = {
353                                 .min_uV = 3200000,
354                                 .max_uV = 3200000,
355                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
356                                 .apply_uV = 1,
357                         },
358                 },
359                 [PCF50633_REGULATOR_LDO5] = {
360                         .constraints = {
361                                 .min_uV = 3000000,
362                                 .max_uV = 3000000,
363                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
364                                 .apply_uV = 1,
365                                 .state_mem = {
366                                         .enabled = 1,
367                                 },
368                         },
369                 },
370                 [PCF50633_REGULATOR_LDO6] = {
371                         .constraints = {
372                                 .min_uV = 3000000,
373                                 .max_uV = 3000000,
374                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
375                         },
376                 },
377                 [PCF50633_REGULATOR_MEMLDO] = {
378                         .constraints = {
379                                 .min_uV = 1800000,
380                                 .max_uV = 1800000,
381                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
382                                 .state_mem = {
383                                         .enabled = 1,
384                                 },
385                         },
386                 },
387
388         },
389         .probe_done = gta02_pmu_attach_child_devices,
390         .mbc_event_callback = gta02_pmu_event_callback,
391 };
392
393
394 /* NOR Flash. */
395
396 #define GTA02_FLASH_BASE        0x18000000 /* GCS3 */
397 #define GTA02_FLASH_SIZE        0x200000 /* 2MBytes */
398
399 static struct physmap_flash_data gta02_nor_flash_data = {
400         .width          = 2,
401 };
402
403 static struct resource gta02_nor_flash_resource = {
404         .start          = GTA02_FLASH_BASE,
405         .end            = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
406         .flags          = IORESOURCE_MEM,
407 };
408
409 static struct platform_device gta02_nor_flash = {
410         .name           = "physmap-flash",
411         .id             = 0,
412         .dev            = {
413                 .platform_data  = &gta02_nor_flash_data,
414         },
415         .resource       = &gta02_nor_flash_resource,
416         .num_resources  = 1,
417 };
418
419 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
420         {
421                 I2C_BOARD_INFO("pcf50633", 0x73),
422                 .irq = GTA02_IRQ_PCF50633,
423                 .platform_data = &gta02_pcf_pdata,
424         },
425         {
426                 I2C_BOARD_INFO("wm8753", 0x1a),
427         },
428 };
429
430 static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
431         [0] = {
432                 /*
433                  * This name is also hard-coded in the boot loaders, so
434                  * changing it would would require all users to upgrade
435                  * their boot loaders, some of which are stored in a NOR
436                  * that is considered to be immutable.
437                  */
438                 .name           = "neo1973-nand",
439                 .nr_chips       = 1,
440                 .flash_bbt      = 1,
441         },
442 };
443
444 /*
445  * Choose a set of timings derived from S3C@2442B MCP54
446  * data sheet (K5D2G13ACM-D075 MCP Memory).
447  */
448
449 static struct s3c2410_platform_nand __initdata gta02_nand_info = {
450         .tacls          = 0,
451         .twrph0         = 25,
452         .twrph1         = 15,
453         .nr_sets        = ARRAY_SIZE(gta02_nand_sets),
454         .sets           = gta02_nand_sets,
455 };
456
457
458 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
459 {
460         switch (cmd) {
461         case S3C2410_UDC_P_ENABLE:
462                 pr_debug("%s S3C2410_UDC_P_ENABLE\n", __func__);
463                 gpio_direction_output(GTA02_GPIO_USB_PULLUP, 1);
464                 break;
465         case S3C2410_UDC_P_DISABLE:
466                 pr_debug("%s S3C2410_UDC_P_DISABLE\n", __func__);
467                 gpio_direction_output(GTA02_GPIO_USB_PULLUP, 0);
468                 break;
469         case S3C2410_UDC_P_RESET:
470                 pr_debug("%s S3C2410_UDC_P_RESET\n", __func__);
471                 /* FIXME: Do something here. */
472         }
473 }
474
475 /* Get PMU to set USB current limit accordingly. */
476 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
477         .vbus_draw      = gta02_udc_vbus_draw,
478         .udc_command    = gta02_udc_command,
479
480 };
481
482
483
484 static void gta02_bl_set_intensity(int intensity)
485 {
486         struct pcf50633 *pcf = gta02_pcf;
487         int old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
488
489         /* We map 8-bit intensity to 6-bit intensity in hardware. */
490         intensity >>= 2;
491
492         /*
493          * This can happen during, eg, print of panic on blanked console,
494          * but we can't service i2c without interrupts active, so abort.
495          */
496         if (in_atomic()) {
497                 printk(KERN_ERR "gta02_bl_set_intensity called while atomic\n");
498                 return;
499         }
500
501         old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
502         if (intensity == old_intensity)
503                 return;
504
505         /* We can't do this anywhere else. */
506         pcf50633_reg_write(pcf, PCF50633_REG_LEDDIM, 5);
507
508         if (!(pcf50633_reg_read(pcf, PCF50633_REG_LEDENA) & 3))
509                 old_intensity = 0;
510
511         /*
512          * The PCF50633 cannot handle LEDOUT = 0 (datasheet p60)
513          * if seen, you have to re-enable the LED unit.
514          */
515         if (!intensity || !old_intensity)
516                 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0);
517
518         /* Illegal to set LEDOUT to 0. */
519         if (!intensity)
520                 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f, 2);
521         else
522                 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f,
523                                           intensity);
524
525         if (intensity)
526                 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 2);
527
528 }
529
530 static struct generic_bl_info gta02_bl_info = {
531         .name                   = "gta02-bl",
532         .max_intensity          = 0xff,
533         .default_intensity      = 0xff,
534         .set_bl_intensity       = gta02_bl_set_intensity,
535 };
536
537 static struct platform_device gta02_bl_dev = {
538         .name                   = "generic-bl",
539         .id                     = 1,
540         .dev = {
541                 .platform_data = &gta02_bl_info,
542         },
543 };
544
545
546
547 /* USB */
548 static struct s3c2410_hcd_info gta02_usb_info __initdata = {
549         .port[0]        = {
550                 .flags  = S3C_HCDFLG_USED,
551         },
552         .port[1]        = {
553                 .flags  = 0,
554         },
555 };
556
557 /* Buttons */
558 static struct gpio_keys_button gta02_buttons[] = {
559         {
560                 .gpio = GTA02_GPIO_AUX_KEY,
561                 .code = KEY_PHONE,
562                 .desc = "Aux",
563                 .type = EV_KEY,
564                 .debounce_interval = 100,
565         },
566         {
567                 .gpio = GTA02_GPIO_HOLD_KEY,
568                 .code = KEY_PAUSE,
569                 .desc = "Hold",
570                 .type = EV_KEY,
571                 .debounce_interval = 100,
572         },
573 };
574
575 static struct gpio_keys_platform_data gta02_buttons_pdata = {
576         .buttons = gta02_buttons,
577         .nbuttons = ARRAY_SIZE(gta02_buttons),
578 };
579
580 static struct platform_device gta02_buttons_device = {
581         .name = "gpio-keys",
582         .id = -1,
583         .dev = {
584                 .platform_data = &gta02_buttons_pdata,
585         },
586 };
587
588 /* LEDs */
589 static struct gpio_led gta02_gpio_leds[] = {
590         {
591                 .name   = "gta02:red:aux",
592                 .gpio   = GTA02_GPIO_AUX_LED,
593         },
594 };
595
596 static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
597         .leds = gta02_gpio_leds,
598         .num_leds = ARRAY_SIZE(gta02_gpio_leds),
599 };
600
601 static struct platform_device gta02_leds_device = {
602         .name   = "leds-gpio",
603         .id             = -1,
604         .dev = {
605                 .platform_data = &gta02_gpio_leds_pdata,
606         },
607 };
608
609 static inline int gta02_pwm_to_gpio(int pwm_id)
610 {
611         return S3C2410_GPB(pwm_id);
612 }
613
614 static int gta02_pwm_led_init(struct device *dev, struct led_pwm *led)
615 {
616         int ret;
617         int gpio = gta02_pwm_to_gpio(led->pwm_id);
618
619         ret = gpio_request(gpio, dev_name(dev));
620         if (ret)
621                 return ret;
622
623         gpio_direction_output(gpio, 0);
624
625         return 0;
626 }
627
628 static enum led_brightness gta02_pwm_led_notify(struct device *dev,
629         struct led_pwm *led, enum led_brightness brightness)
630 {
631         int gpio = gta02_pwm_to_gpio(led->pwm_id);
632
633         if (brightness == led->max_brightness || brightness == 0) {
634                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_OUTPUT);
635                 gpio_set_value(gpio, brightness ? 1 : 0);
636
637                 brightness = 0;
638         } else {
639                 s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_SFN2);
640         }
641
642         return brightness;
643 }
644
645 static void gta02_pwm_led_exit(struct device *dev, struct led_pwm *led)
646 {
647         gpio_free(gta02_pwm_to_gpio(led->pwm_id));
648 }
649
650 static struct led_pwm gta02_pwm_leds[] = {
651         {
652                 .name = "gta02:orange:power",
653                 .max_brightness = 0xff,
654                 .pwm_period_ns = 1000000,
655                 .pwm_id = 0,
656         },
657         {
658                 .name = "gta02:blue:power",
659                 .max_brightness = 0xff,
660                 .pwm_period_ns = 1000000,
661                 .pwm_id = 1,
662         },
663         {
664                 .name = "gta02::vibrator",
665                 .max_brightness = 0x3f,
666                 .pwm_period_ns = 60000000,
667                 .pwm_id = 3,
668         }
669 };
670
671 static struct led_pwm_platform_data gta02_pwm_leds_pdata = {
672         .num_leds = ARRAY_SIZE(gta02_pwm_leds),
673         .leds = gta02_pwm_leds,
674
675         .init = gta02_pwm_led_init,
676         .notify = gta02_pwm_led_notify,
677         .exit = gta02_pwm_led_exit,
678 };
679
680 static struct platform_device gta02_pwm_leds_device = {
681         .name   = "leds_pwm",
682         .id     = -1,
683         .dev = {
684                 .platform_data = &gta02_pwm_leds_pdata,
685         }
686 };
687
688 static void __init gta02_map_io(void)
689 {
690         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
691         s3c24xx_init_clocks(12000000);
692         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
693 }
694
695
696 /* These are the guys that don't need to be children of PMU. */
697
698 static struct platform_device *gta02_devices[] __initdata = {
699         &s3c_device_ohci,
700         &s3c_device_wdt,
701         &s3c_device_sdi,
702         &s3c_device_usbgadget,
703         &s3c_device_nand,
704         &gta02_nor_flash,
705         &s3c_device_timer[0],
706         &s3c_device_timer[1],
707         &s3c_device_timer[3],
708         &s3c_device_iis,
709         &s3c_device_i2c0,
710         &gta02_buttons_device,
711         &gta02_leds_device,
712         &gta02_pwm_leds_device,
713 };
714
715 /* These guys DO need to be children of PMU. */
716
717 static struct platform_device *gta02_devices_pmu_children[] = {
718         &gta02_bl_dev,
719 };
720
721
722 /*
723  * This is called when pc50633 is probed, quite late in the day since it is an
724  * I2C bus device.  Here we can define platform devices with the advantage that
725  * we can mark the pcf50633 as the parent.  This makes them get suspended and
726  * resumed with their parent the pcf50633 still around.  All devices whose
727  * operation depends on something from pcf50633 must have this relationship
728  * made explicit like this, or suspend and resume will become an unreliable
729  * hellworld.
730  */
731
732 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
733 {
734         int n;
735
736         /* Grab a copy of the now probed PMU pointer. */
737         gta02_pcf = pcf;
738
739         for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
740                 gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
741
742         platform_add_devices(gta02_devices_pmu_children,
743                              ARRAY_SIZE(gta02_devices_pmu_children));
744 }
745
746 static void gta02_poweroff(void)
747 {
748         pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
749 }
750
751 /* On hardware rev 5 and earlier the leds are missing a resistor and reading
752  * from their gpio pins will always return 0, so we have to shadow the
753  * led states software */
754 static unsigned long gpb_shadow;
755 extern struct s3c_gpio_chip s3c24xx_gpios[];
756
757 static void gta02_gpb_set(struct gpio_chip *chip,
758                                 unsigned offset, int value)
759 {
760         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
761         unsigned long flags;
762         unsigned long dat;
763
764         local_irq_save(flags);
765
766         dat = __raw_readl(base + 0x04) | gpb_shadow;
767         dat &= ~(1 << offset);
768         gpb_shadow &= ~(1 << offset);
769         if (value) {
770                 dat |= 1 << offset;
771                 switch (offset) {
772                 case 0 ... 2:
773                         gpb_shadow |= 1 << offset;
774                         break;
775                 default:
776                         break;
777                 }
778         }
779         __raw_writel(dat, base + 0x04);
780
781         local_irq_restore(flags);
782 }
783
784 static int gta02_gpb_get(struct gpio_chip *chip, unsigned offset)
785 {
786         void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
787         unsigned long val;
788
789         val = __raw_readl(base + 0x04) | gpb_shadow;
790         val >>= offset;
791         val &= 1;
792
793         return val;
794 }
795
796 static void gta02_hijack_gpb(void)
797 {
798 /* Uncomment this, once support for S3C_SYSTEM_REV_ATAG has been merged
799  * upstream.
800         if (S3C_SYSTEM_REV_ATAG > GTA02v5_SYSTEM_REV)
801                 return;
802 */
803
804         s3c24xx_gpios[1].chip.set = gta02_gpb_set;
805         s3c24xx_gpios[1].chip.get = gta02_gpb_get;
806 }
807
808 static void __init gta02_machine_init(void)
809 {
810         /* Set the panic callback to make AUX LED blink at ~5Hz. */
811         panic_blink = gta02_panic_blink;
812
813         gta02_hijack_gpb();
814
815         s3c_pm_init();
816
817 #ifdef CONFIG_CHARGER_PCF50633
818         INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
819 #endif
820
821         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
822         s3c_ohci_set_platdata(&gta02_usb_info);
823         s3c_nand_set_platdata(&gta02_nand_info);
824         s3c_i2c0_set_platdata(NULL);
825
826         i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
827
828         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
829
830         pm_power_off = gta02_poweroff;
831 }
832
833
834 MACHINE_START(NEO1973_GTA02, "GTA02")
835         /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
836         .phys_io        = S3C2410_PA_UART,
837         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
838         .boot_params    = S3C2410_SDRAM_PA + 0x100,
839         .map_io         = gta02_map_io,
840         .init_irq       = s3c24xx_init_irq,
841         .init_machine   = gta02_machine_init,
842         .timer          = &s3c24xx_timer,
843 MACHINE_END