Merge branch 'master' of git://git.denx.de/u-boot
authorMinkyu Kang <mk7.kang@samsung.com>
Wed, 26 May 2010 01:11:33 +0000 (10:11 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Wed, 26 May 2010 01:11:33 +0000 (10:11 +0900)
Conflicts:
common/cmd_onenand.c
cpu/arm1176/cpu.c
cpu/arm1176/start.S
cpu/arm_cortexa8/s5pc1xx/Makefile
cpu/arm_cortexa8/s5pc1xx/clock.c
drivers/serial/Makefile
drivers/serial/serial_s5pc1xx.c
drivers/video/Makefile
include/asm-arm/arch-s5pc1xx/clk.h
include/asm-arm/arch-s5pc1xx/gpio.h
include/common.h
include/configs/smdkc100.h
include/serial.h
lib_arm/eabi_compat.c

Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
87 files changed:
1  2 
Makefile
arch/arm/cpu/arm1176/s5p64xx/Makefile
arch/arm/cpu/arm1176/s5p64xx/clock.c
arch/arm/cpu/arm1176/s5p64xx/cpu_info.c
arch/arm/cpu/arm1176/s5p64xx/gpio.c
arch/arm/cpu/arm1176/s5p64xx/i2c-gpio.c
arch/arm/cpu/arm1176/s5p64xx/reset.S
arch/arm/cpu/arm1176/s5p64xx/sleep.c
arch/arm/cpu/arm1176/s5p64xx/sleep.h
arch/arm/cpu/arm1176/s5p64xx/sleep_asm.S
arch/arm/cpu/arm1176/s5p64xx/timer.c
arch/arm/cpu/arm1176/s5p64xx/usb-hs-otg.c
arch/arm/cpu/arm1176/s5p64xx/usb-hs-otg.h
arch/arm/cpu/arm1176/s5p64xx/usb_downloader.c
arch/arm/cpu/arm1176/start.S
arch/arm/cpu/arm_cortexa8/config.mk
arch/arm/cpu/arm_cortexa8/cpu.c
arch/arm/cpu/arm_cortexa8/s5pc1xx/Makefile
arch/arm/cpu/arm_cortexa8/s5pc1xx/clock.c
arch/arm/cpu/arm_cortexa8/s5pc1xx/cpu_info.c
arch/arm/cpu/arm_cortexa8/s5pc1xx/i2c-gpio.c
arch/arm/cpu/arm_cortexa8/s5pc1xx/sleep.c
arch/arm/cpu/arm_cortexa8/s5pc1xx/sleep.h
arch/arm/cpu/arm_cortexa8/s5pc1xx/sleep_asm.S
arch/arm/cpu/arm_cortexa8/s5pc1xx/timer.c
arch/arm/cpu/arm_cortexa8/s5pc1xx/usb-hs-otg.c
arch/arm/cpu/arm_cortexa8/s5pc1xx/usb-hs-otg.h
arch/arm/cpu/arm_cortexa8/s5pc1xx/usb_downloader.c
arch/arm/cpu/arm_cortexa8/start.S
arch/arm/include/asm/arch-omap3/sys_proto.h
arch/arm/include/asm/arch-s5p64xx/clk.h
arch/arm/include/asm/arch-s5p64xx/clock.h
arch/arm/include/asm/arch-s5p64xx/cpu.h
arch/arm/include/asm/arch-s5p64xx/gpio.h
arch/arm/include/asm/arch-s5p64xx/i2c.h
arch/arm/include/asm/arch-s5p64xx/keypad.h
arch/arm/include/asm/arch-s5p64xx/mem.h
arch/arm/include/asm/arch-s5p64xx/mmc.h
arch/arm/include/asm/arch-s5p64xx/power.h
arch/arm/include/asm/arch-s5p64xx/pwm.h
arch/arm/include/asm/arch-s5p64xx/regs-fb.h
arch/arm/include/asm/arch-s5p64xx/sys_proto.h
arch/arm/include/asm/arch-s5p64xx/uart.h
arch/arm/include/asm/arch-s5p64xx/usb-hs-otg.h
arch/arm/include/asm/arch-s5pc1xx/adc.h
arch/arm/include/asm/arch-s5pc1xx/clock.h
arch/arm/include/asm/arch-s5pc1xx/cpu.h
arch/arm/include/asm/arch-s5pc1xx/hs_otg.h
arch/arm/include/asm/arch-s5pc1xx/i2c.h
arch/arm/include/asm/arch-s5pc1xx/keypad.h
arch/arm/include/asm/arch-s5pc1xx/mem.h
arch/arm/include/asm/arch-s5pc1xx/mmc.h
arch/arm/include/asm/arch-s5pc1xx/power.h
arch/arm/include/asm/arch-s5pc1xx/regs-fb.h
arch/arm/include/asm/arch-s5pc1xx/regs-otg.h
arch/arm/include/asm/arch-s5pc1xx/rtc.h
arch/arm/include/asm/arch-s5pc1xx/usb-hs-otg.h
arch/arm/include/asm/assembler.h
arch/arm/lib/Makefile
arch/arm/lib/_memcpy32.S
board/samsung/p1p2/p1p2.c
board/samsung/universal/gpio_setting.h
board/samsung/universal/universal.c
common/cmd_mtdparts.c
common/cmd_onenand.c
common/cmd_ubi.c
common/cmd_usbd.c
common/serial.c
drivers/i2c/Makefile
drivers/net/smc911x.c
drivers/serial/Makefile
drivers/serial/serial_s5p.c
drivers/video/Makefile
drivers/video/s5p-spi.h
include/configs/smdkc100.h
include/net.h
include/serial.h
lib/Makefile
onenand_ipl/board/samsung/smdk6442/Makefile
onenand_ipl/board/samsung/smdkc100/Makefile
onenand_ipl/board/samsung/universal/Makefile
recovery/board/samsung/universal/Makefile
recovery/board/samsung/universal/gpio.c
recovery/board/samsung/universal/universal.c
recovery/config.mk
recovery/drivers/serial/serial_s5pc1xx.c
recovery/serial.c

diff --cc Makefile
Simple merge
index 326fa94,0000000..326fa94
mode 100644,000000..100644
--- /dev/null
index c289b1e,0000000..c289b1e
mode 100644,000000..100644
--- /dev/null
index f9d0fcc,0000000..f9d0fcc
mode 100644,000000..100644
--- /dev/null
index b2b034e,0000000..b2b034e
mode 100644,000000..100644
--- /dev/null
index cbe7155,0000000..cbe7155
mode 100644,000000..100644
--- /dev/null
index 002286f,0000000..002286f
mode 100644,000000..100644
--- /dev/null
index 47ec48b,0000000..47ec48b
mode 100644,000000..100644
--- /dev/null
index ce8cb1a,0000000..ce8cb1a
mode 100644,000000..100644
--- /dev/null
index 5a619a1,0000000..5a619a1
mode 100644,000000..100644
--- /dev/null
Simple merge
Simple merge
Simple merge
index 0000000,3785593..6ce30b8
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,54 +1,58 @@@
 -COBJS += clock.o
 -COBJS += cpu_info.o
 -COBJS += sromc.o
 -COBJS += timer.o
+ #
+ # (C) Copyright 2000-2003
+ # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ #
+ # (C) Copyright 2008
+ # Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
+ #
+ # See file CREDITS for list of people who contributed to this
+ # project.
+ #
+ # This program is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU General Public License as
+ # published by the Free Software Foundation; either version 2 of
+ # the License, or (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ include $(TOPDIR)/config.mk
+ LIB   = $(obj)lib$(SOC).a
+ SOBJS = cache.o
+ SOBJS += reset.o
 -OBJS  := $(addprefix $(obj),$(COBJS) $(SOBJS))
++COBJS-y               += clock.o
++COBJS-y               += cpu_info.o
++COBJS-y               += sromc.o
++COBJS-y               += timer.o
++COBJS-$(CONFIG_CMD_SLEEP)     += sleep.o
++COBJS-$(CONFIG_CMD_SLEEP)     += sleep_asm.o
++COBJS-$(CONFIG_SOFT_I2C)      += i2c-gpio.o
++COBJS-$(CONFIG_CMD_USBDOWN)   += usb-hs-otg.o usb_downloader.o
+ SRCS  := $(SOBJS:.o=.S) $(COBJS:.o=.c)
++OBJS  := $(addprefix $(obj),$(COBJS-y) $(SOBJS))
+ all:   $(obj).depend $(LIB)
+ $(LIB):       $(OBJS)
+       $(AR) $(ARFLAGS) $@ $(OBJS)
+ #########################################################################
+ # defines $(obj).depend target
+ include $(SRCTREE)/rules.mk
+ sinclude $(obj).depend
+ #########################################################################
index 0000000,0000000..7998d82
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,110 @@@
++/*
++ * Copyright (C) 2009 Samsung Electronics
++ * Minkyu Kang <mk7.kang@samsung.com>
++ *
++ * See file CREDITS for list of people who contributed to this
++ * project.
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation; either version 2 of
++ * the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ * MA 02111-1307 USA
++ */
++
++#include <common.h>
++#include <asm/io.h>
++#include <asm/arch/gpio.h>
++#include <i2c-gpio.h>
++#include <i2c.h>
++
++static struct i2c_gpio_bus *i2c_gpio;
++
++void i2c_gpio_init(struct i2c_gpio_bus *bus, int len, int index)
++{
++      int i;
++      struct s5p_gpio_bank *bank;
++
++      i2c_gpio = bus;
++
++      /* init all i2c gpio buses */
++      for (i = 0; i < len; i++) {
++              bank = (struct s5p_gpio_bank *)i2c_gpio[i].bus->gpio_base;
++
++              if (!bank)
++                      continue;
++
++              /* SDA */
++              gpio_direction_output(bank,
++                              i2c_gpio[i].bus->sda_pin, 1);
++
++              /* SCL */
++              gpio_direction_output(bank,
++                              i2c_gpio[i].bus->scl_pin, 1);
++      }
++
++      /* set default bus */
++      i2c_set_bus_num(index);
++}
++
++void i2c_gpio_set(int line, int value)
++{
++      struct s5p_gpio_bank *bank;
++      unsigned int bus_index;
++
++      bus_index = i2c_get_bus_num();
++
++      bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base;
++      if (!bank)
++              return;
++
++      if (line)
++              line = i2c_gpio[bus_index].bus->sda_pin;
++      else
++              line = i2c_gpio[bus_index].bus->scl_pin;
++
++      gpio_set_value(bank, line, value);
++}
++
++int i2c_gpio_get(void)
++{
++      struct s5p_gpio_bank *bank;
++      unsigned int bus_index;
++
++      bus_index = i2c_get_bus_num();
++
++      bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base;
++      if (!bank)
++              return 0;
++
++      return gpio_get_value(bank, i2c_gpio[bus_index].bus->sda_pin);
++}
++
++void i2c_gpio_dir(int dir)
++{
++      struct s5p_gpio_bank *bank;
++      unsigned int bus_index;
++
++      bus_index = i2c_get_bus_num();
++
++      bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base;
++      if (!bank)
++              return;
++
++      if (dir) {
++              gpio_direction_output(bank,
++                              i2c_gpio[bus_index].bus->sda_pin, 0);
++      } else {
++              gpio_direction_input(bank,
++                              i2c_gpio[bus_index].bus->sda_pin);
++      }
++}
index ce8cb1a,0000000..ce8cb1a
mode 100644,000000..100644
--- /dev/null
Simple merge
index 0000000,0000000..8e69c4f
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,46 @@@
++/*
++ * (C) Copyright 2009 Samsung Electronics
++ * Minkyu Kang <mk7.kang@samsung.com>
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License as
++ * published by the Free Software Foundation; either version 2 of
++ * the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ * MA 02111-1307 USA
++ *
++ */
++
++#ifndef __ASM_ARCH_UART_H_
++#define __ASM_ARCH_UART_H_
++
++#ifndef __ASSEMBLY__
++struct s5p_uart {
++      unsigned int    ulcon;
++      unsigned int    ucon;
++      unsigned int    ufcon;
++      unsigned int    umcon;
++      unsigned int    utrstat;
++      unsigned int    uerstat;
++      unsigned int    ufstat;
++      unsigned int    umstat;
++      unsigned char   utxh;
++      unsigned char   res1[3];
++      unsigned char   urxh;
++      unsigned char   res2[3];
++      unsigned int    ubrdiv;
++      unsigned short  udivslot;
++      unsigned char   res3[2];
++      unsigned char   res4[0x3d0];
++};
++#endif        /* __ASSEMBLY__ */
++
++#endif
index 6116e48,0000000..6116e48
mode 100644,000000..100644
--- /dev/null
index 0000000,0293348..47ab982
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,82 +1,84 @@@
 -$(LIB):       $(obj).depend $(OBJS)
 -      $(AR) $(ARFLAGS) $@ $(OBJS)
+ #
+ # (C) Copyright 2002-2006
+ # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ #
+ # See file CREDITS for list of people who contributed to this
+ # project.
+ #
+ # This program is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU General Public License as
+ # published by the Free Software Foundation; either version 2 of
+ # the License, or (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ include $(TOPDIR)/config.mk
+ LIB   = $(obj)lib$(ARCH).a
+ LIBGCC        = $(obj)libgcc.a
+ GLSOBJS       += _ashldi3.o
+ GLSOBJS       += _ashrdi3.o
+ GLSOBJS       += _divsi3.o
+ GLSOBJS       += _lshrdi3.o
+ GLSOBJS       += _modsi3.o
+ GLSOBJS       += _udivsi3.o
+ GLSOBJS       += _umodsi3.o
+ GLCOBJS       += div0.o
++SOBJS-y       += _memcpy32.o
++
+ COBJS-y       += board.o
+ COBJS-y       += bootm.o
+ COBJS-y       += cache.o
+ ifndef CONFIG_SYS_NO_CP15_CACHE
+ COBJS-y       += cache-cp15.o
+ endif
+ COBJS-y       += interrupts.o
+ COBJS-y       += reset.o
+ SRCS  := $(GLSOBJS:.o=.S) $(GLCOBJS:.o=.c) \
+          $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c)
+ OBJS  := $(addprefix $(obj),$(SOBJS-y) $(COBJS-y))
+ LGOBJS        := $(addprefix $(obj),$(GLSOBJS)) \
+          $(addprefix $(obj),$(GLCOBJS))
+ # Always build libarm.a
+ TARGETS       := $(LIB)
+ # Build private libgcc only when asked for
+ ifdef USE_PRIVATE_LIBGCC
+ TARGETS       += $(LIBGCC)
+ endif
+ # For EABI conformant tool chains, provide eabi_compat()
+ ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))
+ TARGETS       += $(obj)eabi_compat.o
+ endif
+ all:  $(TARGETS)
++$(LIB):       $(obj).depend $(OBJS) $(SOBJS)
++      $(AR) $(ARFLAGS) $@ $(OBJS) $(SOBJS)
+ $(LIBGCC): $(obj).depend $(LGOBJS)
+       $(AR) $(ARFLAGS) $@ $(LGOBJS)
+ #########################################################################
+ # defines $(obj).depend target
+ include $(SRCTREE)/rules.mk
+ sinclude $(obj).depend
+ #########################################################################
index 4ce2536,0000000..4ce2536
mode 100644,000000..100644
--- /dev/null
index 9b010b5,0000000..5cf19d4
mode 100644,000000..100644
--- /dev/null
@@@ -1,2532 -1,0 +1,2532 @@@
- static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank)
 +/*
 + * Copyright (C) 2009 Samsung Electronics
 + * Kyungmin Park <kyungmin.park@samsung.com>
 + * Minkyu Kang <mk7.kang@samsung.com>
 + *
 + * See file CREDITS for list of people who contributed to this
 + * project.
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License as
 + * published by the Free Software Foundation; either version 2 of
 + * the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software
 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 + * MA 02111-1307 USA
 + */
 +
 +#include <common.h>
 +#include <i2c.h>
 +#include <asm/io.h>
 +#include <asm/arch/clk.h>
 +#include <asm/arch/clock.h>
 +#include <asm/arch/gpio.h>
 +#include <asm/arch/keypad.h>
 +#include <asm/arch/mmc.h>
 +#include <asm/arch/power.h>
 +#include <asm/arch/mem.h>
 +#include <asm/errno.h>
 +#include <fbutils.h>
 +#include <lcd.h>
 +
 +DECLARE_GLOBAL_DATA_PTR;
 +
 +#define C100_MACH_START                       3000
 +#define C110_MACH_START                       3100
 +
 +static unsigned int board_rev;
 +static unsigned int battery_soc;
 +static struct s5pc110_gpio *s5pc110_gpio;
 +
 +enum {
 +      I2C_2,
 +      I2C_GPIO3,
 +      I2C_PMIC,
 +      I2C_GPIO5,
 +      I2C_GPIO6,
 +      I2C_GPIO7,
 +};
 +
 +/*
 + * i2c 2
 + * SDA: GPD1[4]
 + * SCL: GPD1[5]
 + */
 +static struct i2c_gpio_bus_data i2c_2 = {
 +      .sda_pin        = 4,
 +      .scl_pin        = 5,
 +};
 +
 +/*
 + * i2c gpio3
 + * SDA: GPJ3[6]
 + * SCL: GPJ3[7]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio3 = {
 +      .sda_pin        = 6,
 +      .scl_pin        = 7,
 +};
 +
 +/*
 + * i2c pmic
 + * SDA: GPJ4[0]
 + * SCL: GPJ4[3]
 + */
 +static struct i2c_gpio_bus_data i2c_pmic = {
 +      .sda_pin        = 0,
 +      .scl_pin        = 3,
 +};
 +
 +/*
 + * i2c gpio5
 + * SDA: MP05[3]
 + * SCL: MP05[2]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio5 = {
 +      .sda_pin        = 3,
 +      .scl_pin        = 2,
 +};
 +
 +/*
 + * i2c gpio6
 + * SDA: GPJ3[0]
 + * SCL: GPJ3[1]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio6 = {
 +      .sda_pin        = 0,
 +      .scl_pin        = 1,
 +};
 +
 +/*
 + * i2c gpio6 - cypress
 + * SDA: GPJ3[4]
 + * SCL: GPJ3[5]
 + */
 +static struct i2c_gpio_bus_data i2c_cypress_gpio6 = {
 +      .sda_pin        = 4,
 +      .scl_pin        = 5,
 +};
 +
 +/*
 + * i2c gpio7 - cypress
 + * SDA: MP05[6]
 + * SCL: MP05[4]
 + */
 +static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
 +      .sda_pin        = 6,
 +      .scl_pin        = 4,
 +};
 +
 +static struct i2c_gpio_bus i2c_gpio[] = {
 +      {
 +              .bus    = &i2c_2,
 +      }, {
 +              .bus    = &i2c_gpio3,
 +      }, {
 +              .bus    = &i2c_pmic,
 +      }, {
 +              .bus    = &i2c_gpio5,
 +      }, {
 +              .bus    = &i2c_gpio6,
 +      }, {
 +              .bus    = NULL,
 +      }
 +};
 +
 +u32 get_board_rev(void)
 +{
 +      return board_rev;
 +}
 +
 +static int hwrevision(int rev)
 +{
 +      return (board_rev & 0xf) == rev;
 +}
 +
 +enum {
 +      MACH_UNIVERSAL,
 +      MACH_TICKERTAPE,
 +      MACH_AQUILA,
 +      MACH_P1P2,
 +      MACH_GEMINUS,
 +      MACH_CYPRESS,
 +};
 +#ifdef CONFIG_LCD
 +typedef enum {
 +      LCD_NONE,
 +      LCD_AMOLED,
 +      LCD_TFT,
 +} lcd_type_t;
 +
 +static lcd_type_t lcd_type;
 +#endif
 +
 +#define SPLIT_SCREEN_FEATURE  0x100
 +
 +/* board is MACH_AQUILA and board is like below. */
 +#define J1_B2_BOARD           0x200
 +#define LIMO_UNIVERSAL_BOARD  0x400
 +#define LIMO_REAL_BOARD               0x800
 +#define MEDIA_BOARD           0x1000
 +#define BAMBOO_BOARD          0x2000
 +/* board is MACH_P1P2 and board is like below. */
 +#define P1_REAL_BOARD         0x200
 +#define P2_REAL_BOARD         0x400
 +#define HAYDN_BOARD           0x800
 +
 +#define BOARD_MASK            0xF00
 +
 +static int c110_machine_id(void)
 +{
 +      return gd->bd->bi_arch_number - C110_MACH_START;
 +}
 +
 +static int machine_is_p1p2(void)
 +{
 +      return c110_machine_id() == MACH_P1P2;
 +}
 +
 +static int machine_is_tickertape(void)
 +{
 +      return c110_machine_id() == MACH_TICKERTAPE;
 +}
 +
 +static int machine_is_geminus(void)
 +{
 +      return c110_machine_id() == MACH_GEMINUS;
 +}
 +
 +static int machine_is_cypress(void)
 +{
 +      return c110_machine_id() == MACH_CYPRESS;
 +}
 +
 +static int board_is_limo_universal(void)
 +{
 +      return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
 +}
 +
 +static int board_is_limo_real(void)
 +{
 +      return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
 +}
 +
 +static int board_is_media(void)
 +{
 +      return machine_is_aquila() && (board_rev & MEDIA_BOARD);
 +}
 +
 +static int board_is_bamboo(void)
 +{
 +      return machine_is_aquila() && (board_rev & BAMBOO_BOARD);
 +}
 +
 +static int board_is_j1b2(void)
 +{
 +      return machine_is_aquila() && (board_rev & J1_B2_BOARD);
 +}
 +
 +static int board_is_p2_real(void)
 +{
 +      return machine_is_p1p2() && (board_rev & P2_REAL_BOARD);
 +}
 +
 +#ifdef CONFIG_LCD
 +static int lcd_is_amoled(void)
 +{
 +      return lcd_type == LCD_AMOLED;
 +}
 +
 +static int lcd_is_tft(void)
 +{
 +      return lcd_type == LCD_TFT;
 +}
 +#endif
 +static void enable_battery(void);
 +
 +void i2c_init_board(void)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
 +      int num_bus;
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      num_bus = ARRAY_SIZE(i2c_gpio);
 +
 +      if (machine_is_cypress()) {
 +              i2c_gpio[I2C_GPIO6].bus = &i2c_cypress_gpio6;
 +              i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
 +              i2c_gpio[I2C_GPIO7].bus->gpio_base =
 +                      (unsigned int)&gpio->gpio_mp0_5;
 +      } else {
 +              num_bus--;
 +      }
 +
 +      i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
 +      i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
 +      i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
 +      i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
 +      i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
 +
 +      i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
 +
 +      /* Reset on max17040 early */
 +      if (battery_soc == 0)
 +              enable_battery();
 +}
 +
 +#ifdef CONFIG_MISC_INIT_R
 +#define DEV_INFO_LEN          512
 +static char device_info[DEV_INFO_LEN];
 +static int display_info;
 +
 +static void dprintf(const char *fmt, ...)
 +{
 +      va_list args;
 +      uint i;
 +      char buf[128];
 +
 +      va_start(args, fmt);
 +      i = vsprintf(buf, fmt, args);
 +      va_end(args);
 +
 +      buf[127] = 0;
 +
 +      if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
 +              puts("Flushing device info...\n");
 +              puts(device_info);
 +              device_info[0] = 0;
 +      }
 +      strcat(device_info, buf);
 +      puts(buf);
 +}
 +
 +#ifdef CONFIG_S5PC1XXFB
 +static void display_device_info(void)
 +{
 +      if (!display_info)
 +              return;
 +
 +      init_font();
 +      set_font_xy(0, 450);
 +      set_font_color(FONT_WHITE);
 +      fb_printf(device_info);
 +      exit_font();
 +
 +      memset(device_info, 0x0, DEV_INFO_LEN);
 +
 +      udelay(5 * 1000 * 1000);
 +}
 +#endif
 +
 +static const char *board_name[] = {
 +      "Universal",
 +      "TickerTape",
 +      "Aquila",
 +      "P1P2",
 +      "Geminus",
 +      "Cypress",
 +};
 +
 +enum {
 +      MEM_4G1G1G,
 +      MEM_4G2G1G,
 +      MEM_4G3G1G,
 +      MEM_4G4G1G,
 +};
 +
 +static char feature_buffer[32];
 +
 +static char *display_features(int board, int board_rev)
 +{
 +      int count = 0;
 +      char *buf = feature_buffer;
 +
 +      if (board == MACH_AQUILA) {
 +              if (board_rev & SPLIT_SCREEN_FEATURE)
 +                      count += sprintf(buf + count, " - SplitScreen");
 +              if (board_rev & J1_B2_BOARD)
 +                      count += sprintf(buf + count, " - J1 B2 board");
 +              /* Limo Real or Universal */
 +              if (board_rev & LIMO_REAL_BOARD)
 +                      count += sprintf(buf + count, " - Limo Real");
 +              else if (board_rev & LIMO_UNIVERSAL_BOARD)
 +                      count += sprintf(buf + count, " - Limo Universal");
 +              if (board_rev & MEDIA_BOARD)
 +                      count += sprintf(buf + count, " - Media");
 +              if (board_rev & BAMBOO_BOARD)
 +                      count += sprintf(buf + count, " - Bamboo");
 +      } else if (board == MACH_P1P2) {
 +              /* P1P2 */
 +              if (board_rev & P1_REAL_BOARD)
 +                      count += sprintf(buf + count, " - P1 Real");
 +              else if (board_rev & P2_REAL_BOARD)
 +                      count += sprintf(buf + count, " - P2 Real");
 +              else if (board_rev & HAYDN_BOARD)
 +                      count += sprintf(buf + count, " - Haydn");
 +              else
 +                      count += sprintf(buf + count, " - Universal");
 +      }
 +
 +      return buf;
 +}
 +
 +static void check_board_revision(int board, int rev)
 +{
 +      switch (board) {
 +      case MACH_AQUILA:
 +              /* Limo Real or Universal */
 +              if (rev & LIMO_UNIVERSAL_BOARD)
 +                      board_rev &= ~J1_B2_BOARD;
 +              if (rev & LIMO_REAL_BOARD) {
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              }
 +              if (rev & MEDIA_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & BAMBOO_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD |
 +                                      LIMO_REAL_BOARD |
 +                                      MEDIA_BOARD);
 +              break;
 +      case MACH_P1P2:
 +              break;
 +      case MACH_CYPRESS:
 +              /* There's no HWREV_MODE3 */
 +              board_rev &= ~(1 << 3);
 +              /* Fall through */
 +      case MACH_TICKERTAPE:
 +      case MACH_GEMINUS:
 +              board_rev &= ~BOARD_MASK;
 +              break;
 +      default:
 +              break;
 +      }
 +}
 +
-       struct s5pc1xx_gpio_bank *bank;
++static unsigned int get_hw_revision(struct s5p_gpio_bank *bank)
 +{
 +      unsigned int rev;
 +
 +      gpio_direction_input(bank, 1);
 +      gpio_direction_input(bank, 2);
 +      gpio_direction_input(bank, 3);
 +      gpio_direction_input(bank, 4);
 +
 +      gpio_set_pull(bank, 1, GPIO_PULL_NONE);         /* HWREV_MODE3 */
 +      gpio_set_pull(bank, 2, GPIO_PULL_NONE);         /* HWREV_MODE0 */
 +      gpio_set_pull(bank, 3, GPIO_PULL_NONE);         /* HWREV_MODE1 */
 +      gpio_set_pull(bank, 4, GPIO_PULL_NONE);         /* HWREV_MODE2 */
 +
 +      rev = gpio_get_value(bank, 2);
 +      rev |= (gpio_get_value(bank, 3) << 1);
 +      rev |= (gpio_get_value(bank, 4) << 2);
 +      rev |= (gpio_get_value(bank, 1) << 3);
 +
 +      return rev;
 +}
 +
 +static void check_hw_revision(void)
 +{
 +      unsigned int board = MACH_UNIVERSAL;    /* Default is Universal */
 +              
 +      if (cpu_is_s5pc100()) {
 +              struct s5pc100_gpio *gpio =
 +                      (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
 +
 +              board_rev = get_hw_revision(&gpio->gpio_j0);
 +
 +              /* C100 TickerTape */
 +              if (board_rev == 3)
 +                      board = MACH_TICKERTAPE;
 +      } else {
 +              struct s5pc110_gpio *gpio =
 +                      (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
 +
 +              board_rev = get_hw_revision(&gpio->gpio_j0);
 +
 +              /*
 +               * Note Check 'Aquila' board first
 +               *
 +               * TT: TickerTape
 +               * SS: SplitScreen
 +               * LRA: Limo Real Aquila
 +               * LUA: Limo Universal Aquila
 +               * OA: Old Aquila
 +               * P1P2: Smart Book
 +               * CYP: Cypress
 +               * BB: Bamboo
 +               *
 +               * ADDR = 0xE0200000 + OFF
 +               *
 +               *       OFF    Universal BB   LRA  LUA  OA   TT   SS       P1P2 CYP
 +               *   J1: 0x0264 0x10      0x10 0x00 0x00 0x00 0x00 0x00     0x00
 +               *   J2: 0x0284           0x01 0x10 0x00 
 +               *   H1: 0x0C24    W           0x28 0xA8 0x1C               0x18 0x0F
 +               *   H3: 0x0C64                0x03 0x07 0x0F               0xff
 +               *   D1: 0x00C4 0x0F           0x3F 0x3F 0x0F 0xXC 0x3F
 +               *    I: 0x0224                          0x02 0x00 0x08
 +               * MP03: 0x0324                          0x9x      0xbx 0x9x
 +               * MP05: 0x0364                          0x80      0x88
 +               */
 +#if 0
 +              /* C110 Aquila */
 +              if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
 +                      board = MACH_AQUILA;
 +                      board_rev |= J1_B2_BOARD;
 +
 +                      gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
 +                      gpio_direction_input(&gpio->gpio_j2, 6);
 +
 +                      /* Check board */
 +                      if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
 +                              board_rev |= LIMO_UNIVERSAL_BOARD;
 +
 +                      if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
 +                              board_rev |= LIMO_REAL_BOARD;
 +
 +                      if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
 +                              board_rev |= MEDIA_BOARD;
 +
 +                      /* set gpio to default value. */
 +                      gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
 +                      gpio_direction_output(&gpio->gpio_j2, 6, 0);
 +              }
 +              /* Workaround: C110 Aquila Rev0.6 */
 +              if (board_rev == 6) {
 +                      board = MACH_AQUILA;
 +                      board_rev |= LIMO_REAL_BOARD;
 +              }
 +              /* C110 Aquila Bamboo */
 +              if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
 +                      board = MACH_AQUILA;
 +                      board_rev |= BAMBOO_BOARD;
 +              }
 +
 +              /* C110 TickerTape */
 +              if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
 +                              gpio_get_value(&gpio->gpio_d1, 1) == 0)
 +                      board = MACH_TICKERTAPE;
 +
 +              /* C110 Cypress: Do first this than P1P2 */
 +              gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
 +              gpio_direction_input(&gpio->gpio_j2, 2);
 +              if (gpio_get_value(&gpio->gpio_j2, 2) == 1)
 +                      board = MACH_CYPRESS;
 +              gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
 +
 +              /* C110 P1P2 */
 +              if (gpio_get_value(&gpio->gpio_h3, 7) == 1) {
 +                      board = MACH_P1P2;
 +                      board_rev &= ~BOARD_MASK;
 +              }
 +#endif
 +
 +              /* set gpio configuration for P1P2. */
 +              gpio_direction_input(&gpio->gpio_j0, 6);
 +              gpio_direction_input(&gpio->gpio_j0, 7);
 +
 +              /*
 +               * do not change order below
 +               * because it needs delay to get gpio value.
 +               */
 +              /* HWREV_MODE4 */
 +              gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_NONE);
 +              /* HWREV_MODE5 */
 +              gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
 +
 +/*
 + * GPJ0[7:6] 00 : P1_real - EVT1 _ AMOLED
 + *                     11 : P1_real - EVT0 _ TFT
 + * */
 +
 +              if (gpio_get_value(&gpio->gpio_j0, 7) == 1) {
 +                      board = MACH_P1P2;
 +                      board_rev &= ~BOARD_MASK;
 +                      if (gpio_get_value(&gpio->gpio_j0, 6) == 1)     {
 +                              board_rev |= P1_REAL_BOARD;
 +              #ifdef CONFIG_LCD
 +                              lcd_type = LCD_TFT;
 +              #endif
 +                      }
 +                      if (gpio_get_value(&gpio->gpio_j0, 6) == 0)
 +                              board_rev |= P2_REAL_BOARD;
 +              } else {
 +                      board = MACH_P1P2;
 +                      board_rev &= ~BOARD_MASK;
 +
 +                      if (gpio_get_value(&gpio->gpio_h1, 2) == 1)
 +                              board_rev |= HAYDN_BOARD;
 +                      else
 +                              board_rev |= P1_REAL_BOARD;
 +
 +              #ifdef CONFIG_LCD
 +                      if (gpio_get_value(&gpio->gpio_j0, 6) == 0)     {
 +                              lcd_type = LCD_AMOLED;
 +                      }
 +              #endif
 +              }
 +
 +              /* set gpio to default value. */
 +              /* HWREV_MODE4 */
 +              gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
 +              /* HWREV_MODE5 */
 +              gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_DOWN);
 +
 +              if(board != MACH_P1P2)
 +              {
 +                      /* C110 Geminus for rev0.0 */
 +                      gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
 +                      gpio_direction_input(&gpio->gpio_j1, 2);
 +                      if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
 +                              board = MACH_GEMINUS;
 +                              if ((board_rev & ~BOARD_MASK) == 3)
 +                                      board_rev &= ~0xff;
 +                      }
 +                      gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
 +                      gpio_direction_output(&gpio->gpio_j1, 2, 0);
 +
 +                      /* C110 Geminus for rev0.1 ~ */
 +                      gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
 +                      gpio_direction_input(&gpio->gpio_j0, 6);
 +                      if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
 +                              board = MACH_GEMINUS;
 +                      gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
 +              #ifdef CONFIG_LCD
 +                      lcd_type = LCD_NONE;    /* TODO: if the board is not p1p2, this code should be modified */
 +              #endif
 +              }
 +      }
 +
 +      /* Set machine id */
 +      if (cpu_is_s5pc110())
 +              gd->bd->bi_arch_number = C110_MACH_START + board;
 +      else
 +              gd->bd->bi_arch_number = C100_MACH_START + board;
 +
 +      /* Architecture Common settings */
 +      if (cpu_is_s5pc110()) {
 +              setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
 +      } else {
 +              setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
 +                              "bootm 0x30007FC0");
 +              setenv("updatek", "onenand erase 0x60000 0x300000; "
 +                                "onenand write 0x31008000 0x60000 0x300000");
 +      }
 +}
 +
 +static void show_hw_revision(void)
 +{
 +      int board;
 +
 +      /*
 +       * Workaround for Rev 0.3 + CP Ver ES 3.1
 +       * it's Rev 0.4
 +       */
 +      if (board_is_limo_real()) {
 +              if (hwrevision(0)) {
 +                      /* default is Rev 0.4 */
 +                      board_rev &= ~0xf;
 +                      board_rev |= 0x4;
 +              }
 +      }
 +
 +      if (cpu_is_s5pc110())
 +              board = gd->bd->bi_arch_number - C110_MACH_START;
 +      else
 +              board = gd->bd->bi_arch_number - C100_MACH_START;
 +
 +      check_board_revision(board, board_rev);
 +
 +      /* Set CPU Revision */
 +      if ((board_rev & 0xf) > 2) {
 +              s5pc1xx_set_cpu_rev(0);
 +      }
 +
 +      dprintf("HW Revision:\t%x (%s%s)\n", board_rev, board_name[board],
 +              display_features(board, board_rev));
 +}
 +
 +static void check_auto_burn(void)
 +{
 +      unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
 +      unsigned int count = 0;
 +      char buf[64];
 +
 +      if (readl(magic_base) == 0x426f6f74) {  /* ASICC: Boot */
 +              printf("Auto burning bootloader\n");
 +              count += sprintf(buf + count, "run updateb; ");
 +      }
 +      if (readl(magic_base + 0x04) == 0x4b65726e) {   /* ASICC: Kern */
 +              printf("Auto burning kernel\n");
 +              count += sprintf(buf + count, "run updatek; ");
 +      }
 +
 +      if (count) {
 +              count += sprintf(buf + count, "reset");
 +              setenv("bootcmd", buf);
 +      }
 +
 +      /* Clear the magic value */
 +      writel(0xa5a55a5a, magic_base);
 +      writel(0xa5a55a5a, magic_base + 0x4);
 +}
 +
 +static void pmic_pin_init(void)
 +{
 +      unsigned int reg, value;
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      /* AP_PS_HOLD: XEINT_0: GPH0[0]
 +       * Note: Don't use GPIO PS_HOLD it doesn't work
 +       */
 +      reg = S5PC110_PS_HOLD_CONTROL;
 +      value = readl(reg);
 +      value |= S5PC110_PS_HOLD_DIR_OUTPUT |
 +              S5PC110_PS_HOLD_DATA_HIGH |
 +              S5PC110_PS_HOLD_OUT_EN;
 +      writel(value, reg);
 +
 +      /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
 +}
 +
 +static void enable_ldos(void)
 +{
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      if (machine_is_p1p2())
 +              return;
 +
 +      /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
 +}
 +
 +static void enable_t_flash(void)
 +{
 +      if (!(board_is_limo_universal() || board_is_limo_real()))
 +              return;
 +
 +      /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
 +}
 +
 +static void setup_limo_real_gpios(void)
 +{
 +      if (!board_is_limo_real())
 +              return;
 +
 +      /*
 +       * Note: Please write GPIO alphabet order
 +       */
 +      /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
 +
 +      if (hwrevision(0))
 +              /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
 +              gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
 +      else
 +              /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
 +              gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
 +
 +      /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
 +}
 +
 +static void setup_media_gpios(void)
 +{
 +      if (!board_is_media())
 +              return;
 +
 +      /*
 +       * Note: Please write GPIO alphabet order
 +       */
 +      /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
 +
 +      /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
 +}
 +
 +static void setup_p1p2_gpios(void)
 +{
 +      if (!machine_is_p1p2())
 +              return;
 +
 +      /*
 +       * Note: Please write GPIO alphabet order
 +       */
 +      /* RESET_REQ_N: XM0FRnB[1]: MP0_3[5] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 5, 1);
 +      /* CODEC_LDO_EN: XM0FRnB[2]: MP0_3[6] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 6, 1);
 +}
 +
 +#define KBR3          (1 << 3)
 +#define KBR2          (1 << 2)
 +#define KBR1          (1 << 1)
 +#define KBR0          (1 << 0)
 +
 +static void check_p2_keypad(void)
 +{
 +      unsigned int auto_download = 0;
 +      unsigned char addr = 0x34, val[2];      /* adp5587 key controller */
 +      int i, ret;
 +      i2c_set_bus_num(I2C_2);
 +
 +      if (i2c_probe(addr)) {
 +              printf("Can't found adp5587 key controller\n");
 +              return;
 +      }
 +      /* Row 8, Column 10 */
 +      val[0] = 0xf;
 +      ret = i2c_write(addr, 0x1D, 1, val, 1);         /* Set KP_GPIO1 */
 +      val[0] = 0xf;
 +      ret |= i2c_write(addr, 0x1E, 1, val, 1);        /* Set KP_GPIO2 */
 +      val[0] = 0x3;
 +      ret |= i2c_write(addr, 0x1F, 1, val, 1);        /* Set KP_GPIO3 */
 +      val[0] = 0x3f;          /* CMP2_INT | CMP1_INT | OVR_FLOW_INT |
 +                                 K_LCK_INT | GPI_INT | KE_INT */
 +      ret |= i2c_write(addr, 0x02, 1, val, 1);        /* Status is W1C */
 +      val[0] = 0x19;          /* INT_CFG | OVR_FLOW_IEN | KE_IEN */
 +      ret |= i2c_write(addr, 0x01, 1, val, 1);
 +      for (i = 0; i < 10; i++) {
 +              udelay(1000);           /* FIXME */
 +              i2c_read(addr, 0x04 + i, 1, val, 1);
 +              if (val[0] == 0x94)
 +                      auto_download = 1;
 +      }
 +
 +      if (auto_download == 1)
 +              setenv("bootcmd", "usbdown");
 +}
 +
 +static void check_keypad(void)
 +{
 +      unsigned int reg, value;
 +      unsigned int col_num, row_num;
 +      unsigned int col_mask;
 +      unsigned int col_mask_shift;
 +      unsigned int row_state[4];
 +      unsigned int i;
 +      unsigned int auto_download = 0;
 +
 +      writel((readl(0xE010046C) | (0x1 << 21)), 0xE010046C);
 +
 +      if (cpu_is_s5pc100()) {
 +              struct s5pc100_gpio *gpio =
 +                              (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
 +              row_num = 3;
 +              col_num = 3;
 +      /* Set GPH2[2:0] to KP_COL[2:0] */
 +      gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
 +      gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
 +      gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
 +      
 +      /* Set GPH3[2:0] to KP_ROW[2:0] */
 +      gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
 +      gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
 +      gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
 +      reg = S5PC110_KEYPAD_BASE;
 +      col_mask = S5PC1XX_KEYIFCOL_MASK;
 +      col_mask_shift = 0;
 +} else {
 +      if (board_is_limo_real() || board_is_limo_universal()) {
 +      row_num = 2;
 +      col_num = 3;
 +      } else if (machine_is_p1p2()){
 +      row_num = 2;
 +      col_num = 3;
 +      }
 +      else {
 +              row_num = 4;
 +              col_num = 4;
 +      }
 +      for (i = 0; i < row_num; i++) {
 +      /* Set GPH3[3:0] to KP_ROW[3:0] */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
 +      }
 +                                                                                                                                              
 +      for (i = 0; i < col_num; i++){
 +      /* Set GPH2[3:0] to KP_COL[3:0] */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h2,i, GPIO_PULL_DOWN);
 +      }
 +      reg = S5PC110_KEYPAD_BASE;
 +      col_mask = S5PC110_KEYIFCOLEN_MASK;
 +      col_mask_shift = 8;
 +      }
 +
 +      /* KEYIFCOL reg clear */
 +      writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +      /* key_scan */
 +      for (i = 0; i < col_num; i++) {
 +      value = col_mask;
 +      value &= ~(1 << i) << col_mask_shift;
 +      writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +      udelay(1000);
 +      value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
 +      row_state[i] = ~value & ((1 << row_num) - 1);
 +      printf("[%d col] row_state: 0x%x :value = 0x%x\n", i, row_state[i], value);
 +      }
 +      if(row_state[2] & 0x2)
 +      setenv("bootcmd","usbdown");
 +}
 +#if 0
 +static void check_keypad(void)
 +{
 +      unsigned int reg, value;
 +      unsigned int col_mask, row_mask;
 +      unsigned int auto_download = 0;
 +      unsigned int col_value[4], i;
 +
 +      if (cpu_is_s5pc100()) {
 +              struct s5pc100_gpio *gpio =
 +                      (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
 +
 +              /* Set GPH2[2:0] to KP_COL[2:0] */
 +              gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
 +
 +              /* Set GPH3[2:0] to KP_ROW[2:0] */
 +              gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
 +
 +              reg = S5PC100_KEYPAD_BASE;
 +      } else {
 +              if (board_is_limo_real() || board_is_limo_universal()) {
 +                      row_mask = 0x00FF;
 +                      col_mask = 0x0FFF;
 +              } else {
 +                      row_mask = 0xFFFF;
 +                      col_mask = 0xFFFF;
 +              }
 +
 +              for (i = 0; i < 4; i++) {
 +                      /* Set GPH3[3:0] to KP_ROW[3:0] */
 +                      if (row_mask & (0xF << (i << 2))) {
 +                              gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
 +                              if (!machine_is_p1p2())
 +                                      gpio_set_pull(&s5pc110_gpio->gpio_h3,
 +                                                      i, GPIO_PULL_UP);
 +                      }
 +
 +                      /* Set GPH2[3:0] to KP_COL[3:0] */
 +                      if (col_mask & (0xF << (i << 2)))
 +                              gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
 +                      if (machine_is_p1p2())
 +                              gpio_set_pull(&s5pc110_gpio->gpio_h2, i, GPIO_PULL_UP);
 +              }
 +
 +              reg = S5PC110_KEYPAD_BASE;
 +      }
 +      /* init col */
 +      value = 0x00;
 +      writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +      value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
 +      /* VOLUMEDOWN and CAM(Half shot) Button */
 +      if ((value & KBR1) == 0) {
 +              i = 0;
 +              while (i < 4) {
 +                      value = readl(reg + S5PC1XX_KEYIFCOL_OFFSET);
 +                      value |= 0xff;
 +                      value &= ~(1 << i);
 +                      writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +                      udelay(10*1000);
 +                      col_value[i++] = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
 +              }
 +              writel(0x00, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +
 +              /* expected value is row_value[0] = 0x00 row_value[1] = 0x01 */
 +              /* workaround */
 +              if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) == 0x3)
 +                      auto_download = 1;
 +
 +              if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) != 0x3)
 +                      display_info = 1;
 +              if (machine_is_p1p2()) {
 +                      if ((col_value[0] & 0xd) == 0xd)
 +                              auto_download = 1;
 +              }
 +      }
 +
 +      if (auto_download)
 +              setenv("bootcmd", "usbdown");
 +}
 +#endif
 +
 +static void enable_battery(void)
 +{
 +      unsigned char val[2];
 +      unsigned char addr = 0x36;      /* max17040 fuel gauge */
 +
 +      if (machine_is_aquila()) {
 +              if (board_is_j1b2())
 +                      return;
 +      }
 +
 +      if (machine_is_tickertape())
 +              return;
 +
 +      if (machine_is_cypress())
 +              i2c_set_bus_num(I2C_GPIO7);
 +      else
 +              i2c_set_bus_num(I2C_GPIO3);
 +
 +      if(machine_is_p1p2())
 +      {
 +              return;
 +      }
 +
 +      if (i2c_probe(addr)) {
 +              printf("Can't found max17040 fuel gauge\n");
 +              return;
 +      }
 +
 +      val[0] = 0x54;
 +      val[1] = 0x00;
 +      i2c_write(addr, 0xfe, 1, val, 2);
 +}
 +
 +static void check_battery(void)
 +{
 +      unsigned char val[2];
 +      unsigned char addr = 0x36;      /* max17040 fuel gauge */
 +
 +      if(machine_is_p1p2())
 +      {
 +              return;
 +      }
 +
 +      if (machine_is_aquila()) {
 +              if (board_is_j1b2())
 +                      return;
 +      }
 +
 +      if (machine_is_tickertape())
 +              return;
 +
 +      if (machine_is_cypress())
 +              i2c_set_bus_num(I2C_GPIO7);
 +      else
 +              i2c_set_bus_num(I2C_GPIO3);
 +
 +      if (i2c_probe(addr)) {
 +              printf("Can't found max17040 fuel gauge\n");
 +              return;
 +      }
 +
 +      i2c_read(addr, 0x04, 1, val, 1);
 +
 +      dprintf("battery:\t%d%%\n", val[0]);
 +
 +      battery_soc = val[0];
 +}
 +
 +static void check_mhl(void)
 +{
 +      unsigned char val[2];
 +      unsigned char addr = 0x39;      /* SIL9230 */
 +
 +      /* MHL Power enable */
 +      /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
 +
 +      /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
 +
 +      /* 10ms required after reset */
 +      udelay(10000);
 +
 +      /* output enable */
 +      gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
 +
 +      i2c_set_bus_num(I2C_GPIO5);
 +
 +      /* set usb path */
 +      if (i2c_probe(addr)) {
 +              printf("Can't found MHL Chip\n");
 +              return;
 +      }
 +
 +      /*
 +       * System Control #1
 +       * set to Normal operation
 +       */
 +      val[0] = 0x35;
 +      i2c_write((0x72 >> 1), 0x08, 1, val, 1);
 +      i2c_read((0x72 >> 1), 0x08, 1, val, 1);
 +
 +      /*
 +       * MHL TX Control #1
 +       * TERM_MODE [7:6]
 +       * 00 = MHL termination ON
 +       * 11 = MHL termination OFF
 +       */
 +      val[0] = 0xd0;
 +      i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
 +      i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
 +}
 +
 +static void into_charge_mode(void)
 +{
 +      unsigned char addr = 0xCC >> 1; /* max8998 */;
 +      unsigned char val[2];
 +      unsigned int level;
 +      int i, j;
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +
 +      if (i2c_probe(addr)) {
 +              printf("Can't found max8998\n");
 +              return;
 +      }
 +
 +      printf("Charge Mode\n");
 +
 +      i2c_read(addr, 0x0C, 1, val, 1);
 +      val[0] &= ~(0x7 << 0);
 +      val[0] |= 5;            /* 600mA */
 +      i2c_write(addr, 0x0C, 1, val, 1);
 +
 +#ifdef CONFIG_S5PC1XXFB
 +      /* TODO: change to Image animation */
 +      init_font();
 +      set_font_xy(0, 0);
 +      set_font_color(FONT_WHITE);
 +      fb_printf("charging");
 +
 +      level = battery_soc / 25;
 +
 +      for (i = 0; i < 3; i++) {
 +              if (level == 0)
 +                      udelay(1 * 1000 * 1000);
 +
 +              for (j = 0; j < 4; j++) {
 +                      fb_printf("..");
 +
 +                      if (j >= level)
 +                              udelay(1 * 1000 * 1000);
 +              }
 +
 +              if (level <= 4)
 +                      udelay(1 * 1000 * 1000);
 +
 +              set_font_xy(0, 0);
 +              set_font_color(FONT_XOR);
 +              fb_printf("charging........");
 +
 +              set_font_xy(0, 0);
 +              set_font_color(FONT_WHITE);
 +              fb_printf("charging");
 +      }
 +
 +      exit_font();
 +#endif
 +
 +      /* EVT0: sleep 1, EVT1: sleep */
 +      if (s5pc1xx_get_cpu_rev() == 0) {
 +              run_command("sleep 1", 0);
 +              return;
 +      }
 +
 +      run_command("sleep", 0);
 +}
 +
 +static void check_micro_usb(int intr)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      if (board_is_limo_real()) {
 +              if (hwrevision(0) || hwrevision(1))
 +                      return;
 +      }
 +
 +      if (machine_is_cypress())
 +              i2c_set_bus_num(I2C_GPIO6);
 +      else
 +              i2c_set_bus_num(I2C_PMIC);
 +
 +      addr = 0x25;            /* fsa9480 */
 +      if (i2c_probe(addr)) {
 +              printf("Can't found fsa9480\n");
 +              return;
 +      }
 +
 +      /* Clear Interrupt */
 +      if (intr) {
 +              i2c_read(addr, 0x03, 1, val, 2);
 +              udelay(500 * 1000);
 +      }
 +
 +      /* Read Device Type 1 */
 +      i2c_read(addr, 0x0a, 1, val, 1);
 +
 +#define FSA_DEDICATED_CHARGER (1 << 6)
 +#define FSA_UART              (1 << 3)
 +#define FSA_USB                       (1 << 2)
 +
 +      /*
 +       * If USB, use default 475mA
 +       * If Charger, use 600mA and go to charge mode
 +       */
 +      if (val[0] & FSA_DEDICATED_CHARGER)
 +              into_charge_mode();
 +
 +      /* If Factory Mode is Boot ON-USB, go to download mode */
 +      i2c_read(addr, 0x07, 1, val, 1);
 +
 +#define FSA_ADC_FAC_USB               0x19
 +#define FSA_ADC_FAC_UART      0x1d
 +
 +      if (val[0] == FSA_ADC_FAC_USB)
 +              setenv("bootcmd", "usbdown");
 +}
 +
 +#define MAX8998_REG_ONOFF1    0x11
 +#define MAX8998_REG_ONOFF2    0x12
 +#define MAX8998_REG_ONOFF3    0x13
 +#define MAX8998_LDO3          (1 << 2)
 +#define MAX8998_LDO10         (1 << 3)
 +#define MAX8998_LDO11         (1 << 2)
 +#define MAX8998_LDO12         (1 << 1)
 +#define MAX8998_LDO13         (1 << 0)
 +#define MAX8998_LDO14         (1 << 7)
 +#define MAX8998_LDO15         (1 << 6)
 +#define MAX8998_LDO16         (1 << 5)
 +#define MAX8998_LDO17         (1 << 4)
 +
 +static void init_pmic(void)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +
 +      addr = 0xCC >> 1;       /* max8998 */
 +      if (i2c_probe(addr)) {
 +              printf("Can't found max8998\n");
 +              return;
 +      }
 +
 +      /* ONOFF1 */
 +      i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +      val[0] &= ~MAX8998_LDO3;
 +      i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +
 +      /* ONOFF2 */
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      /*
 +       * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
 +       * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
 +       */
 +      val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
 +                      MAX8998_LDO12 | MAX8998_LDO13);
 +      val[0] |= (1 << 7);
 +      i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      /* ONOFF3 */
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      /*
 +       * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
 +       * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
 +       */
 +      val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
 +                      MAX8998_LDO16 | MAX8998_LDO17);
 +      i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +}
 +
 +#define PDN_MASK(x)           (0x3 << ((x) << 1))
 +
 +#define CON_INPUT(x)          (0x0 << ((x) << 2))
 +#define CON_OUTPUT(x)         (0x1 << ((x) << 2))
 +#define CON_IRQ(x)            (0xf << ((x) << 2))
 +
 +#define DAT_SET(x)            (0x1 << (x))
 +#define DAT_CLEAR(x)          (0x0 << (x))
 +
 +#define OUTPUT0(x)            (0x0 << ((x) << 1))
 +#define OUTPUT1(x)            (0x1 << ((x) << 1))
 +#define INPUT(x)              (0x2 << ((x) << 1))
 +
 +#define PULL_DIS(x)           (0x0 << ((x) << 1))
 +#define PULL_DOWN(x)          (0x1 << ((x) << 1))
 +#define PULL_UP(x)            (0x2 << ((x) << 1))
 +
 +#define PREVIOUS(x)           (0x3 << ((x) << 1))
 +
 +struct gpio_powermode {
 +      unsigned int    conpdn;
 +      unsigned int    pudpdn;
 +};
 +
 +struct gpio_external {
 +      unsigned int    con;
 +      unsigned int    dat;
 +      unsigned int    pud;
 +};
 +
 +static struct gpio_powermode powerdown_modes[] = {
 +      {       /* S5PC110_GPIO_A0_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_A1_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
 +      }, {    /* S5PC110_GPIO_B_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_C0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_GPIO_C1_OFFSET */
 +              /* OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4), */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_GPIO_D0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
 +      }, {    /* S5PC110_GPIO_D1_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110_GPIO_E0_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
 +              PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
 +      }, {    /* S5PC110_GPIO_E1_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
 +              OUTPUT0(4),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_GPIO_F0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_F1_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_F2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_F3_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110_GPIO_G0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_G1_OFFSET */
 +              OUTPUT0(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5) | INPUT(6),
 +              PULL_DIS(0) | PULL_UP(1) | PULL_DIS(2) | PULL_UP(3) |
 +              PULL_UP(4) | PULL_UP(5) | PULL_UP(6),
 +      }, {    /* S5PC110_GPIO_G2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_G3_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | INPUT(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_I_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_J0_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_J1_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_J2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DOWN(7),
 +      }, {    /* S5PC110_GPIO_J3_OFFSET */
 +              INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT1(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_J4_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_MP0_1_OFFSET */
 +              /* XM0CSN[4]: MP0_1[4] -> output high */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
 +              OUTPUT1(4) | OUTPUT0(5) | OUTPUT1(6) | OUTPUT1(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
 +      }, {    /* S5PC110_MP0_3_OFFSET */
 +              /* XM0FWEN: MP0_3[2] -> output high */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_4_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
 +              PULL_DOWN(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_5_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_6_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_7_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      },
 +};
 +
 +static struct gpio_external external_powerdown_modes[] = {
 +      {       /* S5PC110_GPIO_H0_OFFSET */
 +              CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
 +              CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_INPUT(7),
 +              DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
 +              DAT_CLEAR(4) | DAT_CLEAR(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110_GPIO_H1_OFFSET */
 +              /* CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
 +              CON_IRQ(4) | CON_INPUT(5) | CON_INPUT(6) | CON_INPUT(7),
 +              DAT_CLEAR(2),
 +              PULL_DOWN(0) | PULL_DOWN(1) |
 +              PULL_DOWN(6),           */
 +              CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
 +              CON_INPUT(4) | CON_INPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
 +              DAT_SET(0),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DOWN(4),
 +      }, {    /* S5PC110_GPIO_H2_OFFSET */
 +              CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
 +              CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
 +              DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
 +              0,
 +      }, {    /* S5PC110_GPIO_H3_OFFSET */
 +              CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
 +              CON_IRQ(4) | CON_INPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
 +              DAT_CLEAR(3) | DAT_CLEAR(7),
 +              0,
 +      },
 +};
 +
 +static void setup_power_down_mode_registers(void)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
-       struct s5pc1xx_gpio_bank *bank;
++      struct s5p_gpio_bank *bank;
 +      struct gpio_powermode *p;
 +      struct gpio_external *ge;
 +      int i;
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      if (!(machine_is_aquila() && board_is_limo_real()))
 +              return;
 +
 +      bank = &gpio->gpio_a0;
 +      p = powerdown_modes;
 +
 +      for (i = 0; i < ARRAY_SIZE(powerdown_modes); i++, p++, bank++) {
 +              writel(p->conpdn, &bank->pdn_con);
 +              writel(p->pudpdn, &bank->pdn_pull);
 +      }
 +      /* M299 */
 +      writel(0xff0022b0, (unsigned int *)0xF0000000);
 +      writel(0xff0022b0, (unsigned int *)0xF1400000);
 +
 +
 +      bank = &gpio->gpio_h0;
 +      ge = external_powerdown_modes;
 +
 +      for (i = 0; i < ARRAY_SIZE(external_powerdown_modes); i++) {
 +              writel(ge->con, &bank->con);
 +              writel(ge->dat, &bank->dat);
 +              writel(ge->pud, &bank->pull);
 +
 +              bank++;
 +              ge++;
 +      }
 +}
 +
 +#ifdef CONFIG_LCD
 +struct s6e63m0_platform_data {
++      struct s5p_gpio_bank *bank;
 +      unsigned int num;
 +};
 +
 +extern void s6e63m0_set_spi_interface(struct s6e63m0_platform_data *cs,
 +      struct s6e63m0_platform_data *clk, struct s6e63m0_platform_data *si,
 +      struct s6e63m0_platform_data *so);
 +
 +struct s6e63m0_platform_data pd_cs, pd_clk, pd_si, pd_so;
 +struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +int s5p_no_lcd_support(void)
 +{
 +      return 0;
 +}
 +
 +
 +void lcd_cfg_gpio(void)
 +{
 +      unsigned int i, f3_end = 4;
 +
 +      for (i = 0; i < 8; i++) {
 +              /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
 +              gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
 +              gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
 +              gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
 +              /* pull-up/down disable */
 +              gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
 +              gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
 +              gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
 +
 +              /* drive strength to max (24bit) */
 +              gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
 +              gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
 +              gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
 +      }
 +
 +      /* set DISPLAY_DE_B pin for dual rgb mode. */
 +      if (board_is_media())
 +              f3_end = 5;
 +
 +      for (i = 0; i < f3_end; i++) {
 +              /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
 +              gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
 +              /* pull-up/down disable */
 +              gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
 +              /* drive strength to max (24bit) */
 +              gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
 +      }
 +      /* display output path selection (only [1:0] valid) */
 +      writel(0x2, 0xE0107008);
 +
 +      /* gpio pad configuration for LCD reset. */
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
 +
 +      /* gpio pad configuration for LCD ON. */
 +      gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
 +
 +      /* MLCD_ON2 */
 +      
 +      if (board_is_p2_real())
 +           gpio_cfg_pin(&gpio_base->gpio_j1, 4, GPIO_OUTPUT);
 +      else
 +           gpio_cfg_pin(&gpio_base->gpio_j2, 6, GPIO_OUTPUT);
 +
 +      /* LCD_BACKLIGHT_EN */
 +      if (machine_is_geminus())
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
 +
 +      /*
 +       * gpio pad configuration for
 +       * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
 +       */
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
 +
 +      if (machine_is_aquila()) {
 +              pd_cs.bank = &gpio_base->gpio_mp0_1;
 +              pd_cs.num = 1;
 +              pd_clk.bank = &gpio_base->gpio_mp0_4;
 +              pd_clk.num = 1;
 +              pd_si.bank = &gpio_base->gpio_mp0_4;
 +              pd_si.num = 3;
 +              pd_so.bank = &gpio_base->gpio_mp0_4;
 +              pd_so.num = 2;
 +
 +              /* these data would be sent to s6e63m0 lcd panel driver. */
 +              //s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, &pd_so);
 +      }
 +
 +      if (machine_is_cypress()) {
 +              /* FLCD_CS */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
 +              /* FLCD_CLK */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
 +              /* FLCD_SDI */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
 +              /* FLCD_RST_S */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
 +              /* FLCD_ON_S */
 +              gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
 +
 +              pd_cs.bank = &gpio_base->gpio_mp0_1;
 +              pd_cs.num = 0;
 +              pd_clk.bank = &gpio_base->gpio_mp0_4;
 +              pd_clk.num = 0;
 +              pd_si.bank = &gpio_base->gpio_mp0_4;
 +              pd_si.num = 2;
 +
 +              /* these data would be sent to s6e63m0 lcd panel driver. */
 +              //s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, NULL);
 +      }
 +
 +      return;
 +}
 +
 +void backlight_on(unsigned int onoff)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      if (onoff) {
 +              if (machine_is_geminus())
 +                      gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
 +      } else {
 +              if (machine_is_geminus())
 +                      gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
 +      }
 +}
 +
 +void reset_lcd(void)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      if (machine_is_aquila() || machine_is_geminus())
 +              gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
 +      if (machine_is_cypress())
 +              gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
 +      if (machine_is_p1p2())
 +      {
 +              /* set gpio pin for DISPLAY_CS to HIGH */
 +              gpio_set_value(&gpio->gpio_mp0_1, 1, 1);
 +              /* set gpio pin for DISPLAY_CLK to HIGH */
 +              gpio_set_value(&gpio->gpio_mp0_4, 1, 1);
 +              /* set gpio pin for DISPLAY_SI to HIGH */
 +              gpio_set_value(&gpio->gpio_mp0_4, 3, 1);
 +      }
 +}
 +void lcd_set_RST(void)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
 +      udelay(1400000);
 +      gpio_set_value(&gpio->gpio_mp0_5, 5, 0);
 +      udelay(500000);
 +      gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
 +      udelay(1000000);
 +}
 +
 +void lcd_power_on(unsigned int onoff)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      if (onoff) {
 +              if (machine_is_aquila() || machine_is_geminus() || machine_is_p1p2())
 +              {
 +                      gpio_set_value(&gpio->gpio_j1, 3, 1);
 +                      udelay(5000);
 +              }
 +
 +              if (machine_is_cypress())
 +                      gpio_set_value(&gpio->gpio_g2, 2, 1);
 +
 +              if (board_is_p2_real())
 +                      gpio_set_value(&gpio->gpio_j1, 4, 1);
 +              else if (machine_is_p1p2())
 +              {
 +                      gpio_set_value(&gpio->gpio_j2, 6, 1);
 +                      udelay(5000);
 +                      lcd_set_RST();
 +              }
 +              else
 +                      gpio_set_value(&gpio->gpio_j2, 6, 1);
 +
 +      } else {
 +              if (machine_is_aquila() || machine_is_geminus() || machine_is_p1p2())
 +                      gpio_set_value(&gpio->gpio_j1, 3, 0);
 +
 +              if (machine_is_cypress())
 +                      gpio_set_value(&gpio->gpio_g2, 2, 0);
 +
 +              if (board_is_p2_real())
 +                      gpio_set_value(&gpio->gpio_j1, 4, 0);
 +              else if (machine_is_p1p2())
 +                      gpio_set_value(&gpio->gpio_j2, 6, 0);
 +      }
 +}
 +
 +extern void ams701ka_cfg_ldo(void);
 +extern void ams701ka_enable_ldo(unsigned int onoff);
 +
 +void init_panel_info(vidinfo_t *vid)
 +{
 +      vid->cfg_gpio = NULL;
 +      vid->reset_lcd = NULL;
 +      vid->backlight_on = NULL;
 +      vid->lcd_power_on = NULL;
 +
 +      vid->cfg_ldo = NULL;
 +      vid->enable_ldo = NULL;
 +
 +      vid->init_delay = 0;
 +      vid->reset_delay = 0;
 +      vid->power_on_delay = 0;
 +
 +      vid->dual_lcd_enabled = 0;
 +
 +      vid->vl_freq    = 40;
 +      vid->vl_col     = 1024,
 +      vid->vl_row     = 600,
 +      vid->vl_width   = 1024,
 +      vid->vl_height  = 600,
 +      vid->vl_clkp    = CONFIG_SYS_HIGH,
 +      vid->vl_hsp     = CONFIG_SYS_HIGH,
 +      vid->vl_vsp     = CONFIG_SYS_HIGH,
 +      vid->vl_dp      = CONFIG_SYS_LOW,
 +      vid->vl_bpix    = 32,
 +
 +      /* AMS701KA AMOLED Panel. */
 +      vid->vl_hspw    = 30,
 +      vid->vl_hbpd    = 114,
 +      vid->vl_hfpd    = 48,
 +
 +      vid->vl_vspw    = 2,
 +      vid->vl_vbpd    = 6,
 +      vid->vl_vfpd    = 8,
 +
 +      vid->cfg_gpio = lcd_cfg_gpio;
 +      vid->reset_lcd = reset_lcd;
 +      vid->backlight_on = backlight_on;
 +      vid->lcd_power_on = lcd_power_on;
 +
 +      vid->cfg_ldo = ams701ka_cfg_ldo;
 +      vid->enable_ldo = ams701ka_enable_ldo;
 +
 +      vid->init_delay = 25000;
 +      vid->reset_delay = 120000;
 +
 +#if 0
 +      vid->vl_freq    = 60;
 +      vid->vl_col     = 480,
 +      vid->vl_row     = 800,
 +      vid->vl_width   = 480,
 +      vid->vl_height  = 800,
 +      vid->vl_clkp    = CONFIG_SYS_HIGH,
 +      vid->vl_hsp     = CONFIG_SYS_LOW,
 +      vid->vl_vsp     = CONFIG_SYS_LOW,
 +      vid->vl_dp      = CONFIG_SYS_HIGH,
 +      vid->vl_bpix    = 32,
 +
 +      /* tl2796 panel. */
 +      vid->vl_hpw     = 4,
 +      vid->vl_blw     = 8,
 +      vid->vl_elw     = 8,
 +
 +      vid->vl_vpw     = 4,
 +      vid->vl_bfw     = 8,
 +      vid->vl_efw     = 8,
 +#endif
 +#if 0
 +      vid->vl_freq    = 60;
 +      vid->vl_col     = 1024,
 +      vid->vl_row     = 600,
 +      vid->vl_width   = 1024,
 +      vid->vl_height  = 600,
 +      vid->vl_clkp    = CONFIG_SYS_HIGH,
 +      vid->vl_hsp     = CONFIG_SYS_HIGH,
 +      vid->vl_vsp     = CONFIG_SYS_HIGH,
 +      vid->vl_dp      = CONFIG_SYS_LOW,
 +      vid->vl_bpix    = 32,
 +
 +      /* AMS701KA AMOLED Panel. */
 +      vid->vl_hpw     = 30,
 +      vid->vl_blw     = 114,
 +      vid->vl_elw     = 48,
 +
 +      vid->vl_vpw     = 2,
 +      vid->vl_bfw     = 6,
 +      vid->vl_efw     = 8,
 +#endif
 +}
 +#endif
 +
 +static void setup_meminfo(void)
 +{
 +      char meminfo[64] = {0, };
 +      int count = 0, size, real;
 +
 +      size = gd->bd->bi_dram[0].size >> 20;
 +      count += sprintf(meminfo + count, "mem=%dM", size);
 +
 +      /* Each Chip Select can't exceed the 256MiB */
 +      size = gd->bd->bi_dram[1].size >> 20;
 +      real = min(size, 256);
 +      count += sprintf(meminfo + count, " mem=%dM@0x%x",
 +              real, (unsigned int)gd->bd->bi_dram[1].start);
 +
 +      size -= real;
 +      if (size > 0) {
 +              count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
 +                      (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
 +      }
 +
 +      setenv("meminfo", meminfo);
 +}
 +
 +int misc_init_r(void)
 +{
 +#ifdef CONFIG_LCD
 +      /* It should be located at first */
 +      lcd_is_enabled = 0;
 +
 +      if (board_is_limo_real() ||
 +              board_is_limo_universal() ||
 +              board_is_j1b2())
 +              setenv("lcdinfo", "lcd=s6e63m0");
 +      /* it can't classify tl2796 with single-lcd and dual-lcd.
 +      else
 +              setenv("lcdinfo", "lcd=tl2796-dual");
 +      */
 +
 +      /*
 +       * env values below should be added in case that lcd panel of geminus,
 +       * p1 and p2 are enabled at u-boot.
 +       * setenv means that lcd panel has been turned on at u-boot.
 +       */
 +      if (machine_is_geminus())
 +              setenv("lcdinfo", "lcd=lms480jc01");
 +
 +      if (board_is_p2_real()) {
 +              setenv("lcdinfo", "lcd=ams701");
 +      }       else if(lcd_is_amoled())        {
 +              setenv("lcdinfo", "lcd=ams701");
 +      }
 +
 +#endif
 +      setup_meminfo();
 +
 +      show_hw_revision();
 +
 +      /* Set proper PMIC pins */
 +      pmic_pin_init();
 +
 +      /* Check auto burning */
 +      check_auto_burn();
 +
 +      /* To power up I2C2 */
 +      enable_ldos();
 +
 +      /* Enable T-Flash at Limo Real or Limo Universal */
 +      enable_t_flash();
 +
 +      /* Setup Limo Real board GPIOs */
 +      setup_limo_real_gpios();
 +
 +      /* Setup Media board GPIOs */
 +      setup_media_gpios();
 +
 +      /* Setup P1P2 board GPIOS */
 +      setup_p1p2_gpios();
 +
 +      /* To usbdown automatically */
 +      if (board_is_p2_real())
 +              check_p2_keypad();
 +      else
 +              check_keypad();
 +
 +      /* check max8998 */
 +      init_pmic();
 +
 +#ifdef CONFIG_S5PC1XXFB
 +      display_device_info();
 +#endif
 +
 +      setup_power_down_mode_registers();
 +
 +      /* check max17040 */
 +      check_battery();
 +
 +      /* check fsa9480 */
 +      check_micro_usb(0);
 +
 +      return 0;
 +}
 +#endif
 +
 +int board_init(void)
 +{
 +      /* Set Initial global variables */
 +      s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      gd->bd->bi_arch_number = MACH_TYPE;
 +      gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
 +
 +      /* Check H/W Revision */
 +      check_hw_revision();
 +
 +      return 0;
 +}
 +
 +int dram_init(void)
 +{
 +      unsigned int base, memconfig0, size;
 +      unsigned int memconfig1, sz = 0;
 +
 +      if (cpu_is_s5pc100()) {
 +              /* In mem setup, we swap the bank. So below size is correct */
 +              gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
 +              gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
 +              gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
 +              size = 128;
 +      } else {
 +              /* In S5PC110, we can't swap the DMC0/1 */
 +              gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
 +              gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
 +
 +              base = S5PC110_DMC1_BASE;
 +              /* DMC configuration */
 +              memconfig0 = readl(base + MEMCONFIG0_OFFSET);
 +              gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
 +
 +              size = (memconfig0 >> 16) & 0xFF;
 +              size = ((unsigned char) ~size) + 1;
 +
 +              /*
 +               * (0x07 + 1) * 16 = 128 MiB
 +               * (0x0f + 1) * 16 = 256 MiB
 +               */
 +              size = size << 4;
 +
 +              /*
 +               * Aquila Rev0.5 4G3G1G
 +               * Aquila Rev0.8 4G3G1G
 +               */
 +              if (machine_is_aquila() && (hwrevision(5) || hwrevision(8))) {
 +                      memconfig1 = readl(base + MEMCONFIG1_OFFSET);
 +
 +                      sz = (memconfig1 >> 16) & 0xFF;
 +                      sz = ((unsigned char) ~sz) + 1;
 +                      sz = sz << 4;
 +              }
 +
 +      }
 +      /*
 +       * bi_dram[1].size contains all DMC1 memory size
 +       */
 +      gd->bd->bi_dram[1].size = (size + sz) << 20;
 +
 +      return 0;
 +}
 +
 +/* Used for sleep test */
 +static unsigned char saved_val[4][2];
 +void board_sleep_init_late(void)
 +{
 +      /* CODEC_LDO_EN: GPF3[4] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
 +      /* CODEC_XTAL_EN: GPH3[2] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
 +
 +      /* MMC T_FLASH off */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
 +      /* MHL off */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
 +
 +
 +}
 +void board_sleep_init(void)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +      addr = 0xCC >> 1;
 +      if (i2c_probe(addr)) {
 +              printf("Can't find max8998\n");
 +              return;
 +      }
 +
 +      /* Set ONOFF1 */
 +      i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +      saved_val[0][0] = val[0];
 +      saved_val[0][1] = val[1];
 +      val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
 +                      (1 << 1) | (1 << 0));
 +      i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +      /* Set ONOFF2 */
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      saved_val[1][0] = val[0];
 +      saved_val[1][1] = val[1];
 +      val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
 +                      (1 << 2) | (1 << 1) | (1 << 0));
 +      val[0] |= (1 << 7);
 +      i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      /* Set ONOFF3 */
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      saved_val[2][0] = val[0];
 +      saved_val[2][1] = val[1];
 +      val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
 +      i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      /* Set ONOFF4 */
 +      i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +      saved_val[3][0] = val[0];
 +      saved_val[3][1] = val[1];
 +      val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
 +      i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +      printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
 +                      __FILE__, __LINE__);
 +}
 +
 +void board_sleep_resume(void)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      show_hw_revision();
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +      addr = 0xCC >> 1;
 +      if (i2c_probe(addr)) {
 +              printf("Can't find max8998\n");
 +              return;
 +      }
 +
 +      /* Set ONOFF1 */
 +      i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +      /* Set ONOFF2 */
 +      i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      /* Set ONOFF3 */
 +      i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      /* Set ONOFF4 */
 +      i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +      printf("Waked up.\n");
 +
 +      /* check max17040 */
 +      check_battery();
 +
 +      /* check fsa9480 */
 +      check_micro_usb(1);
 +}
 +
 +#ifdef CONFIG_CMD_USBDOWN
 +int usb_board_init(void)
 +{
 +#ifdef CONFIG_CMD_PMIC
 +      run_command("pmic ldo 3 on", 0);
 +#endif
 +
 +      if (cpu_is_s5pc100()) {
 +#ifdef CONFIG_HARD_I2C
 +              uchar val[2] = {0,};
 +
 +              /* PMIC */
 +              if (i2c_read(0x66, 0, 1, val, 2)) {
 +                      printf("i2c_read error\n");
 +                      return 1;
 +              }
 +
 +              val[0] |= (1 << 3);
 +              val[1] |= (1 << 5);
 +
 +              if (i2c_write(0x66, 0, 1, val, 2)) {
 +                      printf("i2c_write error\n");
 +                      return 1;
 +              }
 +              i2c_read(0x66, 0, 1, val, 2);
 +#endif
 +              return 0;
 +      }
 +
 +      /* S5PC110 */
 +      if (board_is_limo_universal() ||
 +              board_is_limo_real() ||
 +              board_is_media()) {
 +              /* check usb path */
 +              if (board_is_limo_real() && !hwrevision(6))
 +                      check_mhl();
 +      }
 +
 +      if (machine_is_tickertape())
 +              /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
 +              gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
 +
 +      return 0;
 +}
 +#endif
 +
 +#ifdef CONFIG_GENERIC_MMC
 +int s5p_no_mmc_support(void)
 +{
 +      return 0;
 +}
 +
 +
 +int board_mmc_init(bd_t *bis)
 +{
 +      unsigned int reg;
 +      unsigned int clock;
 +      struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
 +      int i;
 +
 +      /* MMC0 Clock source = SCLKMPLL */
 +      reg = readl(&clk->src4);
 +      reg &= ~0xf;
 +      reg |= 0x6;
 +      writel(reg, &clk->src4);
 +
 +      reg = readl(&clk->div4);
 +      reg &= ~0xf;
 +
 +      /* set div value near 50MHz */
 +      clock = get_pll_clk(MPLL) / 1000000;
 +      for (i = 0; i < 0xf; i++) {
 +              if ((clock / (i + 1)) <= 50) {
 +                      reg |= i << 0;
 +                      break;
 +              }
 +      }
 +
 +      writel(reg, &clk->div4);
 +
 +      /*
 +       * MMC0 GPIO
 +       * GPG0[0]      SD_0_CLK
 +       * GPG0[1]      SD_0_CMD
 +       * GPG0[2]      SD_0_CDn        -> Not used
 +       * GPG0[3:6]    SD_0_DATA[0:3]
 +       */
 +      for (i = 0; i < 7; i++) {
 +              if (i == 2)
 +                      continue;
 +              /* GPG0[0:6] special function 2 */
 +              gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
 +              /* GPG0[0:6] pull disable */
 +              gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
 +              /* GPG0[0:6] drv 4x */
 +              gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
 +      }
 +
 +      return s5pc1xx_mmc_init(0);
 +}
 +#endif
 +
 +#ifdef CONFIG_CMD_PMIC
 +static int pmic_status(void)
 +{
 +      unsigned char addr, val[2];
 +      int reg, i;
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +      addr = 0xCC >> 1;
 +      if (i2c_probe(addr)) {
 +              printf("Can't found max8998\n");
 +              return -1;
 +      }
 +
 +      reg = 0x11;
 +      i2c_read(addr, reg, 1, val, 1);
 +      for (i = 7; i >= 4; i--)
 +              printf("BUCK%d %s\n", 7 - i + 1,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      for (; i >= 0; i--)
 +              printf("LDO%d %s\n", 5 - i,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      reg = 0x12;
 +      i2c_read(addr, reg, 1, val, 1);
 +      for (i = 7; i >= 0; i--)
 +              printf("LDO%d %s\n", 7 - i + 6,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      reg = 0x13;
 +      i2c_read(addr, reg, 1, val, 1);
 +      for (i = 7; i >= 4; i--)
 +              printf("LDO%d %s\n", 7 - i + 14,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      return 0;
 +}
 +
 +static int pmic_ldo_control(int buck, int ldo, int on)
 +{
 +      unsigned char addr, val[2];
 +      unsigned int reg, shift;
 +
 +      if (ldo) {
 +              if (ldo < 2)
 +                      return -1;
 +              if (ldo <= 5) {
 +                      reg = 0x11;
 +                      shift = 5 - ldo;
 +              } else if (ldo <= 13) {
 +                      reg = 0x12;
 +                      shift = 13 - ldo;
 +              } else if (ldo <= 17) {
 +                      reg = 0x13;
 +                      shift = 17 - ldo + 4;
 +              } else
 +                      return -1;
 +      } else if (buck) {
 +              if (buck > 4)
 +                      return -1;
 +              reg = 0x11;
 +              shift = 4 - buck + 4;
 +      } else
 +              return -1;
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +      addr = 0xCC >> 1;
 +      if (i2c_probe(addr)) {
 +              printf("Can't found max8998\n");
 +              return -1;
 +      }
 +
 +      i2c_read(addr, reg, 1, val, 1);
 +      if (on)
 +              val[0] |= (1 << shift);
 +      else
 +              val[0] &= ~(1 << shift);
 +      i2c_write(addr, reg, 1, val, 1);
 +      i2c_read(addr, reg, 1, val, 1);
 +      printf("%s %d value 0x%x, %s\n", buck ? "buck" : "ldo", buck ? : ldo,
 +              val[0], val[0] & (1 << shift) ? "on" : "off");
 +
 +      return 0;
 +}
 +
 +static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 +{
 +      int buck = 0, ldo = 0, on = -1;
 +
 +      switch (argc) {
 +      case 2:
 +              if (strncmp(argv[1], "status", 6) == 0)
 +                      return pmic_status();
 +              break;
 +      case 4:
 +              if (strncmp(argv[1], "ldo", 3) == 0) {
 +                      ldo = simple_strtoul(argv[2], NULL, 10);
 +                      if (strncmp(argv[3], "on", 2) == 0)
 +                              on = 1;
 +                      else if (strncmp(argv[3], "off", 3) == 0)
 +                              on = 0;
 +                      else
 +                              break;
 +                      return pmic_ldo_control(buck, ldo, on);
 +              }
 +              if (strncmp(argv[1], "buck", 4) == 0) {
 +                      buck = simple_strtoul(argv[2], NULL, 10);
 +                      if (strncmp(argv[3], "on", 2) == 0)
 +                              on = 1;
 +                      else if (strncmp(argv[3], "off", 3) == 0)
 +                              on = 0;
 +                      else
 +                              break;
 +                      return pmic_ldo_control(buck, ldo, on);
 +              }
 +
 +      default:
 +              break;
 +      }
 +
 +      cmd_usage(cmdtp);
 +      return 1;
 +}
 +
 +U_BOOT_CMD(
 +      pmic,           CONFIG_SYS_MAXARGS,     1, do_pmic,
 +      "PMIC LDO & BUCK control",
 +      "status - Display PMIC LDO & BUCK status\n"
 +      "pmic ldo num on/off - Turn on/off the LDO\n"
 +      "pmic buck num on/off - Turn on/off the BUCK\n"
 +);
 +#endif
 +
 +#ifdef CONFIG_CMD_DEVICE_POWER
 +
 +enum {
 +      POWER_NONE,
 +      POWER_TOUCH,
 +      POWER_3_TOUCHKEY,
 +      POWER_LCD,
 +      POWER_HAPTIC,
 +      POWER_AUDIO_CODEC,
 +      POWER_FM_RADIO,
 +      POWER_BT_WIFI,
 +      POWER_HDMI,
 +};
 +
 +static void power_display_devices(void)
 +{
 +      printf("devices:\n");
 +      printf("\t%d - touch\n", POWER_TOUCH);
 +      printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
 +      printf("\t%d - LCD\n", POWER_LCD);
 +      printf("\t%d - Haptic\n", POWER_HAPTIC);
 +      printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
 +      printf("\t%d - FM Radio\n", POWER_FM_RADIO);
 +      printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
 +      printf("\t%d - HDMI\n", POWER_HDMI);
 +}
 +
 +static int power_hdmi(int on)
 +{
 +      /* HDMI_EN1: GPJ2[2] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
 +      /* MHL_ON: GPJ2[3] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
 +      return 0;
 +}
 +
 +static int power_bt_wifi(int on)
 +{
 +      /* WLAN_BT_EN: GPB[5] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
 +      return 0;
 +}
 +
 +static int power_fm_radio(int on)
 +{
 +      /* FM_BUS_nRST: GPJ2[5] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
 +      return 0;
 +}
 +
 +static int power_audio_codec(int on)
 +{
 +      /* CODEC_LDO_EN: GPF3[4] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
 +      /* CODEC_XTAL_EN: GPH3[2] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
 +      return 0;
 +}
 +
 +static int power_haptic(int on)
 +{
 +      /* HAPTIC_ON: GPJ1[1] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
 +      return 0;
 +}
 +
 +static int power_lcd(int on)
 +{
 +      /* MLCD_ON: GPJ1[3] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
 +      return 0;
 +}
 +
 +static int power_touch(int on)
 +{
 +      /* TOUCH_EN: GPG3[6] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
 +      return 0;
 +}
 +
 +static int power_3_touchkey(int on)
 +{
 +      if (on) {
 +              /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
 +              /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
 +              if (board_rev & J1_B2_BOARD)
 +                      gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
 +              else
 +                      gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
 +
 +              /* 3_TOUCH_CE - GPJ2[6] */
 +              gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on);   /* TOUCH_CE */
 +      } else {
 +              /* 3_TOUCH_CE - GPJ2[6] */
 +              gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on);   /* TOUCH_CE */
 +      }
 +
 +      if (on) {
 +              unsigned int reg;
 +              unsigned char val[2];
 +              unsigned char addr = 0x20;              /* mcs5000 3-touchkey */
 +
 +              /* Require 100ms */
 +              udelay(80 * 1000);
 +
 +              /* 3 touchkey */
 +              i2c_set_bus_num(I2C_GPIO6);
 +
 +              /* Workaround to probe */
 +              if (i2c_probe(addr)) {
 +                      if (i2c_probe(addr)) {
 +                              printf("Can't found 3 touchkey\n");
 +                              return -ENODEV;
 +                      }
 +              }
 +
 +#define MCS5000_TK_HW_VERSION  0x06
 +#define MCS5000_TK_FW_VERSION  0x0A
 +#define MCS5000_TK_MI_VERSION  0x0B
 +
 +              reg = MCS5000_TK_MI_VERSION;
 +              i2c_read(addr, reg, 1, val, 1);
 +              printf("3-touchkey:\tM/I 0x%x, ", val[0]);
 +              reg = MCS5000_TK_HW_VERSION;
 +              i2c_read(addr, reg, 1, val, 1);
 +              printf("H/W 0x%x, ", val[0]);
 +              reg = MCS5000_TK_FW_VERSION;
 +              i2c_read(addr, reg, 1, val, 1);
 +              printf("F/W 0x%x\n", val[0]);
 +      }
 +      return 0;
 +}
 +
 +static int power_control(int device, int on)
 +{
 +      switch (device) {
 +      case POWER_TOUCH:
 +              return power_touch(on);
 +      case POWER_3_TOUCHKEY:
 +              return power_3_touchkey(on);
 +      case POWER_LCD:
 +              return power_lcd(on);
 +      case POWER_HAPTIC:
 +              return power_haptic(on);
 +      case POWER_AUDIO_CODEC:
 +              return power_audio_codec(on);
 +      case POWER_FM_RADIO:
 +              return power_fm_radio(on);
 +      case POWER_BT_WIFI:
 +              return power_bt_wifi(on);
 +      case POWER_HDMI:
 +              return power_hdmi(on);
 +      default:
 +              printf("I don't know device %d\n", device);
 +              break;
 +      }
 +      return 0;
 +}
 +
 +static int power_on(int on)
 +{
 +      power_touch(on);
 +      power_3_touchkey(on);
 +      power_lcd(on);
 +      power_haptic(on);
 +      power_audio_codec(on);
 +      power_fm_radio(on);
 +      power_bt_wifi(on);
 +      power_hdmi(on);
 +
 +      return 0;
 +}
 +
 +static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 +{
 +      int device, on;
 +
 +      if (!machine_is_aquila())
 +              goto out;
 +
 +      switch (argc) {
 +      case 2:
 +              if (strncmp(argv[1], "on", 2) == 0)
 +                      return power_on(1);
 +              if (strncmp(argv[1], "off", 3) == 0)
 +                      return power_on(0);
 +              break;
 +      case 3:
 +              device = simple_strtoul(argv[1], NULL, 10);
 +              if (device < 0)
 +                      break;
 +
 +              if (strncmp(argv[2], "on", 2) == 0)
 +                      on = 1;
 +              else if (strncmp(argv[2], "off", 3) == 0)
 +                      on = 0;
 +              else
 +                      break;
 +              return power_control(device, on);
 +      default:
 +              break;
 +      }
 +out:
 +      cmd_usage(cmdtp);
 +      power_display_devices();
 +      return 1;
 +}
 +
 +U_BOOT_CMD(
 +      power,          CONFIG_SYS_MAXARGS,     1, do_power,
 +      "Device Power Management control",
 +      "device on/off - Turn on/off the device\n"
 +);
 +#endif
index 9a5f109,0000000..615be55
mode 100644,000000..100644
--- /dev/null
@@@ -1,442 -1,0 +1,442 @@@
-       struct s5pc1xx_gpio_bank *bank;
 +#ifndef __GPIO_SETTING_H
 +#define __GPIO_SETTING_H
 +
 +#include <asm/arch/gpio.h>
 +#include <asm/arch/cpu.h>
 +
 +#define PDN_MASK(x)           (0x3 << ((x) << 1))
 +
 +#define CON_INPUT(x)          (0x0 << ((x) << 2))
 +#define CON_OUTPUT(x)         (0x1 << ((x) << 2))
 +#define CON_IRQ(x)            (0xf << ((x) << 2))
 +
 +#define DAT_SET(x)            (0x1 << (x))
 +#define DAT_CLEAR(x)          (0x0 << (x))
 +
 +#define OUTPUT0(x)            (0x0 << ((x) << 1))
 +#define OUTPUT1(x)            (0x1 << ((x) << 1))
 +#define INPUT(x)              (0x2 << ((x) << 1))
 +#define KEEP_STATE(x)         (0x3 << ((x) << 1))
 +
 +#define PULL_DIS(x)           (0x0 << ((x) << 1))
 +#define PULL_DOWN(x)          (0x1 << ((x) << 1))
 +#define PULL_UP(x)            (0x2 << ((x) << 1))
 +
 +#define PREVIOUS(x)           (0x3 << ((x) << 1))
 +
 +#define HWSUGGEST
 +#ifdef HWSUGGEST
 +#define PDNCON_NC(x)          INPUT(x)
 +#define PDNPUD_NC(x)          PULL_DOWN(x)
 +#else
 +#define PDNCON_NC(x)          OUTPUT0(x)
 +#define PDNPUD_NC(x)          PULL_DIS(x)
 +#endif
 +
 +/* #define OPTMIZED_SLEEP_CURRENT_BCM4329 */
 +
 +struct gpio_powermode {
 +      unsigned int    conpdn;
 +      unsigned int    pudpdn;
 +};
 +
 +struct gpio_external {
 +      unsigned int    con;
 +      unsigned int    dat;
 +      unsigned int    pud;
 +};
 +
 +#define       __GPIO(x)       \
 +      &((struct s5pc110_gpio *)S5PC110_GPIO_BASE)->gpio_##x
 +/* In mirror mode, it sets "I(PD/PU)" according to the
 + * output at the u-boot time. */
 +struct s5pc1xx_gpio_item {
++      struct s5p_gpio_bank *bank;
 +      unsigned int number;
 +};
 +
 +static struct s5pc1xx_gpio_item aquila_mirror_powerdown_mode[] = {
 +};
 +
 +static struct s5pc1xx_gpio_item kessler_mirror_powerdown_mode[] = {
 +      { .bank = __GPIO(j0), .number = 2},
 +      { .bank = __GPIO(j0), .number = 3},
 +      { .bank = __GPIO(j0), .number = 4},
 +      { .bank = __GPIO(j0), .number = 7},
 +};
 +
 +#undef __GPIO
 +
 +static struct gpio_powermode aquila_powerdown_modes[] = {
 +      {       /* S5PC110_GPIO_A0_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_A1_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
 +      }, {    /* S5PC110_GPIO_B_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_C0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_GPIO_C1_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_GPIO_D0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
 +      }, {    /* S5PC110_GPIO_D1_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110_GPIO_E0_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
 +              PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
 +      }, {    /* S5PC110_GPIO_E1_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
 +              OUTPUT0(4),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_GPIO_F0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_F1_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_F2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_F3_OFFSET */
 +              /*
 +               * GPF3[4]: CODEC_LDO_EN can be enabled at suspend
 +               */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110_GPIO_G0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_G1_OFFSET */
 +
 +              /*
 +               * Chip Status:                 Off     On      
 +               * GPG1[2]: WLAN_nRST           low     high (need to verify)
 +               */
 +#ifdef OPTMIZED_SLEEP_CURRENT_BCM4329
 +              OUTPUT0(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
 +#else
 +              OUTPUT0(0) | INPUT(1) | KEEP_STATE(2) | INPUT(3) |
 +#endif
 +              INPUT(4) | INPUT(5) | INPUT(6),
 +              PULL_DIS(0) | PULL_UP(1) | PULL_DIS(2) | PULL_UP(3) |
 +              PULL_UP(4) | PULL_UP(5) | PULL_UP(6),
 +      }, {    /* S5PC110_GPIO_G2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_G3_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | INPUT(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_I_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110_GPIO_J0_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_J1_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_J2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DOWN(7),
 +      }, {    /* S5PC110_GPIO_J3_OFFSET */
 +              INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT1(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_GPIO_J4_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110_MP0_1_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
 +              OUTPUT1(4) | OUTPUT0(5) | OUTPUT1(6) | OUTPUT1(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
 +      }, {    /* S5PC110_MP0_3_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_4_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
 +              PULL_DOWN(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_5_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_6_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110_MP0_7_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      },
 +};
 +
 +static struct gpio_external aquila_external_powerdown_modes[] = {
 +      {       /* S5PC110_GPIO_H0_OFFSET */
 +              CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
 +              CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_IRQ(7),
 +              DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
 +              DAT_CLEAR(4) | DAT_CLEAR(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110_GPIO_H1_OFFSET */
 +              CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
 +              CON_INPUT(4) | CON_INPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
 +              DAT_SET(0),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DOWN(4),
 +      }, {    /* S5PC110_GPIO_H2_OFFSET */
 +              CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
 +              CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
 +              DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
 +              0,
 +      }, {    /* S5PC110_GPIO_H3_OFFSET */
 +              CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
 +              CON_IRQ(4) | CON_INPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
 +              DAT_CLEAR(3) | DAT_CLEAR(7),
 +              0,
 +      },
 +};
 +
 +static struct gpio_powermode kessler_powerdown_modes[] = {
 +      {       /* S5PC110(ARIES)_GPIO_A0_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_A1_OFFSET */
 +              INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
 +      }, {    /* S5PC110(ARIES)_GPIO_B_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | PDNCON_NC(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PDNPUD_NC(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_C0_OFFSET */
 +              OUTPUT0(0) | PDNCON_NC(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PDNPUD_NC(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110(ARIES)_GPIO_C1_OFFSET */
 +              OUTPUT0(0) | PDNCON_NC(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PDNPUD_NC(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110(ARIES)_GPIO_D0_OFFSET */
 +              PDNCON_NC(0) | OUTPUT0(1) | PDNCON_NC(2) | PDNCON_NC(3),
 +              PDNPUD_NC(0) | PULL_DIS(1) | PDNPUD_NC(2) | PDNPUD_NC(3),
 +      }, {    /* S5PC110(ARIES)_GPIO_D1_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110(ARIES)_GPIO_E0_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
 +              PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_E1_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
 +              PDNCON_NC(4),
 +              PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
 +              PDNPUD_NC(4),
 +      }, {    /* S5PC110(ARIES)_GPIO_F0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_F1_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_F2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_F3_OFFSET */
 +              /*
 +               * GPF3[4]: CODEC_LDO_EN can be enabled at suspend
 +               */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | PDNCON_NC(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DOWN(4) | PDNPUD_NC(5),
 +      }, {    /* S5PC110(ARIES)_GPIO_G0_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110(ARIES)_GPIO_G1_OFFSET */
 +#ifdef OPTMIZED_SLEEP_CURRENT_BCM4329
 +              OUTPUT0(0) | OUTPUT1(1) | OUTPUT0(2) | OUTPUT1(3) |
 +              OUTPUT1(4) | OUTPUT1(5) | OUTPUT1(6),
 +#else
 +              OUTPUT0(0) | OUTPUT1(1) | KEEP_STATE(2) | OUTPUT1(3) |
 +              OUTPUT1(4) | OUTPUT1(5) | OUTPUT1(6),
 +#endif
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110(ARIES)_GPIO_G2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110(ARIES)_GPIO_G3_OFFSET */
 +              OUTPUT1(0) | OUTPUT0(1) | PDNCON_NC(2) | INPUT(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PDNPUD_NC(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110(ARIES)_GPIO_I_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
 +      }, {    /* S5PC110(ARIES)_GPIO_J0_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | INPUT(5) | OUTPUT0(6) | INPUT(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_J1_OFFSET */
 +              OUTPUT1(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_J2_OFFSET */
 +              OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_J3_OFFSET */
 +              INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
 +              INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_GPIO_J4_OFFSET */
 +              INPUT(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
 +              OUTPUT0(4),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110(ARIES)_MP0_1_OFFSET */
 +              /* XM0CSN[4]: MP0_1[4] -> output high */
 +              PDNCON_NC(0) | OUTPUT0(1) | PDNCON_NC(2) | INPUT(3) |
 +              OUTPUT1(4) | INPUT(5) | PDNCON_NC(6) | PDNCON_NC(7),
 +              PDNPUD_NC(0) | PULL_DIS(1) | PDNPUD_NC(2) | PULL_DOWN(3) |
 +              PULL_DIS(4) | PULL_DOWN(5) | PDNPUD_NC(6) | PDNPUD_NC(7),
 +      }, {    /* S5PC110(ARIES)_MP0_2_OFFSET */
 +              PDNCON_NC(0) | PDNCON_NC(1) | INPUT(2) | PDNCON_NC(3),
 +              PDNPUD_NC(0) | PDNPUD_NC(1) | PULL_DIS(2) | PDNPUD_NC(3),
 +      }, {    /* S5PC110(ARIES)_MP0_3_OFFSET */
 +              /* XM0FWEN: MP0_3[2] -> output high */
 +              PDNCON_NC(0) | PDNCON_NC(1) | OUTPUT1(2) | INPUT(3) |
 +              INPUT(4) | OUTPUT1(5) | PDNCON_NC(6) | PDNCON_NC(7),
 +              PDNPUD_NC(0) | PDNPUD_NC(1) | PULL_DIS(2) | PULL_DOWN(3) |
 +              PULL_DIS(4) | PULL_DIS(5) | PDNPUD_NC(6) | PDNPUD_NC(7),
 +      }, {    /* S5PC110(ARIES)_MP0_4_OFFSET */
 +              PDNCON_NC(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
 +              PDNCON_NC(4) | PDNCON_NC(5) | OUTPUT0(6) | PDNCON_NC(7),
 +              PDNPUD_NC(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
 +              PDNPUD_NC(4) | PDNPUD_NC(5) | PULL_DIS(6) | PDNPUD_NC(7),
 +      }, {    /* S5PC110(ARIES)_MP0_5_OFFSET */
 +              INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
 +              INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DOWN(4) | PULL_DIS(5) | PULL_UP(6) | PULL_DIS(7),
 +      }, {    /* S5PC110(ARIES)_MP0_6_OFFSET */
 +              PDNCON_NC(0) | PDNCON_NC(1) | PDNCON_NC(2) | PDNCON_NC(3) |
 +              PDNCON_NC(4) | PDNCON_NC(5) | PDNCON_NC(6) | PDNCON_NC(7),
 +              PDNPUD_NC(0) | PDNPUD_NC(1) | PDNPUD_NC(2) | PDNPUD_NC(3) |
 +              PDNPUD_NC(4) | PDNPUD_NC(5) | PDNPUD_NC(6) | PDNPUD_NC(7),
 +      }, {    /* S5PC110(ARIES)_MP0_7_OFFSET */
 +              PDNCON_NC(0) | PDNCON_NC(1) | PDNCON_NC(2) | PDNCON_NC(3) |
 +              PDNCON_NC(4) | PDNCON_NC(5) | PDNCON_NC(6) | PDNCON_NC(7),
 +              PDNPUD_NC(0) | PDNPUD_NC(1) | PDNPUD_NC(2) | PDNPUD_NC(3) |
 +              PDNPUD_NC(4) | PDNPUD_NC(5) | PDNPUD_NC(6) | PDNPUD_NC(7),
 +      },
 +};
 +
 +static struct gpio_external kessler_external_powerdown_modes[] = {
 +      {       /* S5PC110(ARIES)_GPIO_H0_OFFSET */
 +              CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
 +              CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_IRQ(7),
 +              DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
 +              DAT_CLEAR(4) | DAT_CLEAR(5),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4) | PULL_DIS(5),
 +      }, {    /* S5PC110(ARIES)_GPIO_H1_OFFSET */
 +              CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
 +              CON_OUTPUT(4) | CON_OUTPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
 +              DAT_CLEAR(0),
 +              PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
 +              PULL_DIS(4),
 +      }, {    /* S5PC110(ARIES)_GPIO_H2_OFFSET */
 +              CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
 +              CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
 +              DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
 +              0,
 +      }, {    /* S5PC110(ARIES)_GPIO_H3_OFFSET */
 +              CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
 +              CON_IRQ(4) | CON_OUTPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
 +              DAT_CLEAR(3) | DAT_CLEAR(5) | DAT_CLEAR(7),
 +              0,
 +      },
 +};
 +
 +#endif /* __GPIO_SETTING_H */
index a5d7349,0000000..07e1486
mode 100644,000000..100644
--- /dev/null
@@@ -1,2914 -1,0 +1,2914 @@@
- static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
 +/*
 + * Copyright (C) 2009 Samsung Electronics
 + * Kyungmin Park <kyungmin.park@samsung.com>
 + * Minkyu Kang <mk7.kang@samsung.com>
 + *
 + * See file CREDITS for list of people who contributed to this
 + * project.
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License as
 + * published by the Free Software Foundation; either version 2 of
 + * the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software
 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 + * MA 02111-1307 USA
 + */
 +
 +#include <common.h>
 +#include <i2c.h>
 +#include <malloc.h>
 +#include <asm/io.h>
 +#include <asm/arch/clk.h>
 +#include <asm/arch/clock.h>
 +#include <asm/arch/gpio.h>
 +#include <asm/arch/keypad.h>
 +#include <asm/arch/mmc.h>
 +#include <asm/arch/power.h>
 +#include <asm/arch/mem.h>
 +#include <asm/arch/hs_otg.h>
 +#include <asm/arch/regs-otg.h>
 +#include <asm/arch/rtc.h>
 +#include <asm/arch/adc.h>
 +#include <asm/errno.h>
 +#include <fbutils.h>
 +#include <lcd.h>
 +#include <bmp_layout.h>
 +
 +#include "animation_frames.h"
 +#include "gpio_setting.h"
 +
 +DECLARE_GLOBAL_DATA_PTR;
 +
 +#define C100_MACH_START                       3000
 +#define C110_MACH_START                       3100
 +
 +static unsigned int board_rev;
 +static unsigned int battery_soc;
 +static struct s5pc110_gpio *s5pc110_gpio;
 +
 +enum {
 +      I2C_2,
 +      I2C_GPIO3,
 +      I2C_PMIC,
 +      I2C_GPIO5,
 +      I2C_GPIO6,
 +      I2C_GPIO7,
 +      I2C_GPIO10,
 +};
 +
 +/*
 + * i2c 2
 + * SDA: GPD1[4]
 + * SCL: GPD1[5]
 + */
 +static struct i2c_gpio_bus_data i2c_2 = {
 +      .sda_pin        = 4,
 +      .scl_pin        = 5,
 +};
 +
 +/*
 + * i2c gpio3
 + * SDA: GPJ3[6]
 + * SCL: GPJ3[7]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio3 = {
 +      .sda_pin        = 6,
 +      .scl_pin        = 7,
 +};
 +
 +/*
 + * i2c pmic
 + * SDA: GPJ4[0]
 + * SCL: GPJ4[3]
 + */
 +static struct i2c_gpio_bus_data i2c_pmic = {
 +      .sda_pin        = 0,
 +      .scl_pin        = 3,
 +};
 +
 +/*
 + * i2c gpio5
 + * SDA: MP05[3]
 + * SCL: MP05[2]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio5 = {
 +      .sda_pin        = 3,
 +      .scl_pin        = 2,
 +};
 +
 +/*
 + * i2c gpio6
 + * SDA: GPJ3[4]
 + * SCL: GPJ3[5]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio6 = {
 +      .sda_pin        = 4,
 +      .scl_pin        = 5,
 +};
 +
 +/*
 + * i2c gpio7 - goni
 + * SDA: MP05[1]
 + * SCL: MP05[0]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio7 = {
 +      .sda_pin        = 1,
 +      .scl_pin        = 0,
 +};
 +
 +/*
 + * i2c gpio7 - cypress
 + * SDA: MP05[6]
 + * SCL: MP05[4]
 + */
 +static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
 +      .sda_pin        = 6,
 +      .scl_pin        = 4,
 +};
 +
 +/*
 + * i2c gpio10
 + * SDA: GPJ3[0]
 + * SCL: GPJ3[1]
 + */
 +static struct i2c_gpio_bus_data i2c_gpio10 = {
 +      .sda_pin        = 0,
 +      .scl_pin        = 1,
 +};
 +
 +
 +static struct i2c_gpio_bus i2c_gpio[] = {
 +      {
 +              .bus    = &i2c_2,
 +      }, {
 +              .bus    = &i2c_gpio3,
 +      }, {
 +              .bus    = &i2c_pmic,
 +      }, {
 +              .bus    = &i2c_gpio5,
 +      }, {
 +              .bus    = &i2c_gpio6,
 +      }, {
 +              .bus    = &i2c_gpio7,
 +      }, {
 +              .bus    = &i2c_gpio10,
 +      },
 +};
 +
 +u32 get_board_rev(void)
 +{
 +      return board_rev;
 +}
 +
 +static int hwrevision(int rev)
 +{
 +      return (board_rev & 0xf) == rev;
 +}
 +
 +enum {
 +      MACH_UNIVERSAL,
 +      MACH_TICKERTAPE,
 +      MACH_CHANGED,
 +      MACH_P1P2,      /* Don't remove it */
 +      MACH_GEMINUS,
 +      MACH_CYPRESS,
 +
 +      MACH_WMG160 = 160,
 +
 +      MACH_PSEUDO_END,
 +
 +      MACH_GONI = 2862,
 +};
 +
 +#define SPLIT_SCREEN_FEATURE  0x100
 +
 +/* board is MACH_AQUILA and board is like below. */
 +#define J1_B2_BOARD           0x0200
 +#define LIMO_UNIVERSAL_BOARD  0x0400
 +#define LIMO_REAL_BOARD               0x0800
 +#define MEDIA_BOARD           0x1000
 +#define BAMBOO_BOARD          0x2000
 +
 +/* board is MACH_GONI and board is like below */
 +#define S1_BOARD              0x1000
 +#define KESSLER_BOARD         0x4000
 +#define SDK_BOARD             0x8000
 +
 +#define BOARD_MASK            0xFF00
 +
 +static int c110_machine_id(void)
 +{
 +      return gd->bd->bi_arch_number - C110_MACH_START;
 +}
 +
 +static int mach_is_aquila(void)
 +{
 +      return gd->bd->bi_arch_number == MACH_TYPE_AQUILA;
 +}
 +
 +static int mach_is_tickertape(void)
 +{
 +      return c110_machine_id() == MACH_TICKERTAPE;
 +}
 +
 +static int mach_is_geminus(void)
 +{
 +      return c110_machine_id() == MACH_GEMINUS;
 +}
 +
 +static int mach_is_cypress(void)
 +{
 +      return c110_machine_id() == MACH_CYPRESS;
 +}
 +
 +static int board_is_limo_universal(void)
 +{
 +      return mach_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
 +}
 +
 +static int board_is_limo_real(void)
 +{
 +      return mach_is_aquila() && (board_rev & LIMO_REAL_BOARD);
 +}
 +
 +static int board_is_bamboo(void)
 +{
 +      return mach_is_aquila() && (board_rev & BAMBOO_BOARD);
 +}
 +
 +static int board_is_media(void)
 +{
 +      return mach_is_aquila() && (board_rev & MEDIA_BOARD);
 +}
 +
 +static int board_is_j1b2(void)
 +{
 +      return mach_is_aquila() && (board_rev & J1_B2_BOARD);
 +}
 +
 +/* Kessler */
 +static int mach_is_goni(void)
 +{
 +      return gd->bd->bi_arch_number == MACH_GONI;
 +}
 +
 +static int board_is_sdk(void)
 +{
 +      return mach_is_goni() && (board_rev & SDK_BOARD);
 +}
 +
 +static int board_is_s1(void)
 +{
 +      return mach_is_goni() && (board_rev & S1_BOARD);
 +}
 +
 +/* DLNA Dongle */
 +static int mach_is_wmg160(void)
 +{
 +      return c110_machine_id() == MACH_WMG160;
 +}
 +
 +static void check_battery(int mode);
 +static void check_micro_usb(int intr);
 +
 +void i2c_init_board(void)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
 +      int num_bus;
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      num_bus = ARRAY_SIZE(i2c_gpio);
 +
 +      if (mach_is_aquila()) {
 +              i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
 +              i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
 +      } else if (mach_is_goni()) {
 +              i2c_gpio[I2C_GPIO7].bus->gpio_base =
 +                      (unsigned int)&gpio->gpio_mp0_5;
 +      } else if (mach_is_cypress()) {
 +              i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
 +              i2c_gpio[I2C_GPIO7].bus->gpio_base =
 +                      (unsigned int)&gpio->gpio_mp0_5;
 +      } else {
 +              i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
 +      }
 +
 +      i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
 +      i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
 +      i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
 +      i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
 +      i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
 +
 +      i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
 +
 +      /* Reset on fsa9480 early */
 +      check_micro_usb(1);
 +      /* Reset on max17040 early */
 +      if (battery_soc == 0)
 +              check_battery(1);
 +}
 +
 +#ifdef CONFIG_MISC_INIT_R
 +#define DEV_INFO_LEN          256
 +static char device_info[DEV_INFO_LEN];
 +static int display_info;
 +
 +static void empty_device_info_buffer(void)
 +{
 +      memset(device_info, 0x0, DEV_INFO_LEN);
 +}
 +
 +static void dprintf(const char *fmt, ...)
 +{
 +      va_list args;
 +      uint i;
 +      char buf[128];
 +
 +      va_start(args, fmt);
 +      i = vsprintf(buf, fmt, args);
 +      va_end(args);
 +
 +      buf[127] = 0;
 +
 +      if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
 +              puts("Flushing device info...\n");
 +              puts(device_info);
 +              empty_device_info_buffer();
 +      }
 +      strncat(device_info, buf, 127);
 +      puts(buf);
 +}
 +
 +#ifdef CONFIG_S5PC1XXFB
 +static void display_device_info(void)
 +{
 +      if (!display_info)
 +              return;
 +
 +      init_font();
 +      set_font_xy(0, 450);
 +      set_font_color(FONT_WHITE);
 +      fb_printf(device_info);
 +      exit_font();
 +
 +      memset(device_info, 0x0, DEV_INFO_LEN);
 +
 +      udelay(5 * 1000 * 1000);
 +}
 +#endif
 +
 +static const char *board_name[] = {
 +      "Universal",
 +      "TickerTape",
 +      "Goni",
 +      "P1P2",         /* Don't remove it */
 +      "Geminus",
 +      "Cypress",
 +      "Limo SDK",
 +};
 +
 +enum {
 +      MEM_4G1G1G,
 +      MEM_4G2G1G,
 +      MEM_4G3G1G,
 +      MEM_4G4G1G,
 +};
 +
 +static char feature_buffer[32];
 +
 +static char *display_features(int board, int board_rev)
 +{
 +      int count = 0;
 +      char *buf = feature_buffer;
 +      char *name = NULL;
 +
 +      if (board == MACH_TYPE_AQUILA) {
 +              if (board_rev & SPLIT_SCREEN_FEATURE)
 +                      name = "SplitScreen";
 +              if (board_rev & J1_B2_BOARD)
 +                      name = "J1 B2";
 +              /* Limo Real or Universal */
 +              if (board_rev & LIMO_REAL_BOARD)
 +                      name = "Limo Real";
 +              else if (board_rev & LIMO_UNIVERSAL_BOARD)
 +                      name = "Limo Universal";
 +              if (board_rev & MEDIA_BOARD)
 +                      name = "Media";
 +              if (board_rev & BAMBOO_BOARD)
 +                      name = "Bamboo";
 +      } else if (board == MACH_GONI) {
 +              if (board_rev & SDK_BOARD)
 +                      name = "Limo SDK";
 +              if (board_rev & S1_BOARD)
 +                      name = "S1";
 +      }
 +      if (name)
 +              count += sprintf(buf + count, " - %s", name);
 +
 +      return buf;
 +}
 +
 +static char *get_board_name(int board)
 +{
 +      if (board == MACH_TYPE_AQUILA)
 +              return "Aquila";
 +      else if (board == MACH_GONI)
 +              return "Goni";
 +      else if (board == MACH_WMG160)
 +              return "WMG160";
 +      return (char *) board_name[board];
 +}
 +
 +static void check_board_revision(int board, int rev)
 +{
 +      if (board == MACH_TYPE_AQUILA) {
 +              /* Limo Real or Universal */
 +              if (rev & LIMO_UNIVERSAL_BOARD)
 +                      board_rev &= ~J1_B2_BOARD;
 +              if (rev & LIMO_REAL_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & MEDIA_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & BAMBOO_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD |
 +                                      LIMO_REAL_BOARD |
 +                                      MEDIA_BOARD);
 +      } else if (board == MACH_GONI) {
 +              if (rev & KESSLER_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & SDK_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & S1_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
 +                                      LIMO_REAL_BOARD);
 +      } else {
 +              board_rev &= ~BOARD_MASK;
 +      }
 +}
 +
-       struct s5pc1xx_gpio_bank *bank;
++static unsigned int get_hw_revision(struct s5p_gpio_bank *bank, int hwrev3)
 +{
 +      unsigned int rev;
 +
 +      gpio_direction_input(bank, 2);
 +      gpio_direction_input(bank, 3);
 +      gpio_direction_input(bank, 4);
 +      gpio_direction_input(bank, hwrev3);
 +
 +      gpio_set_pull(bank, 2, GPIO_PULL_NONE);         /* HWREV_MODE0 */
 +      gpio_set_pull(bank, 3, GPIO_PULL_NONE);         /* HWREV_MODE1 */
 +      gpio_set_pull(bank, 4, GPIO_PULL_NONE);         /* HWREV_MODE2 */
 +      gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE);    /* HWREV_MODE3 */
 +
 +      rev = gpio_get_value(bank, 2);
 +      rev |= (gpio_get_value(bank, 3) << 1);
 +      rev |= (gpio_get_value(bank, 4) << 2);
 +      rev |= (gpio_get_value(bank, hwrev3) << 3);
 +
 +      return rev;
 +}
 +
 +static void check_hw_revision(void)
 +{
 +      unsigned int board = MACH_UNIVERSAL;    /* Default is Universal */
 +
 +      if (cpu_is_s5pc100()) {
 +              struct s5pc100_gpio *gpio =
 +                      (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
 +
 +              board_rev = get_hw_revision(&gpio->gpio_j0, 0);
 +
 +              /* C100 TickerTape */
 +              if (board_rev == 3)
 +                      board = MACH_TICKERTAPE;
 +      } else {
 +              struct s5pc110_gpio *gpio =
 +                      (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
 +              int hwrev3 = 1;
 +
 +              board_rev = 0;
 +
 +              /*
 +               * Note Check 'Aquila' board first
 +               *
 +               * TT: TickerTape
 +               * SS: SplitScreen
 +               * LRA: Limo Real Aquila
 +               * LUA: Limo Universal Aquila
 +               * OA: Old Aquila
 +               * CYP: Cypress
 +               * BB: Bamboo
 +               *
 +               * ADDR = 0xE0200000 + OFF
 +               *
 +               *       OFF    Universal BB   LRA  LUA  OA   TT   SS        CYP
 +               *   J1: 0x0264 0x10      0x10 0x00 0x00 0x00 0x00 0x00
 +               *   J2: 0x0284           0x01 0x10 0x00
 +               *   H1: 0x0C24    W           0x28 0xA8 0x1C                0x0F
 +               *   H3: 0x0C64                0x03 0x07 0x0F
 +               *   D1: 0x00C4 0x0F           0x3F 0x3F 0x0F 0xXC 0x3F
 +               *    I: 0x0224                          0x02 0x00 0x08
 +               * MP03: 0x0324                          0x9x      0xbx 0x9x
 +               * MP05: 0x0364                          0x80      0x88
 +               */
 +
 +              /* C110 Aquila */
 +              if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
 +                      board = MACH_TYPE_AQUILA;
 +                      board_rev |= J1_B2_BOARD;
 +
 +                      gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
 +                      gpio_direction_input(&gpio->gpio_j2, 6);
 +
 +                      /* Check board */
 +                      if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
 +                              board_rev |= LIMO_UNIVERSAL_BOARD;
 +
 +                      if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
 +                              board_rev |= LIMO_REAL_BOARD;
 +
 +                      if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
 +                              board_rev |= MEDIA_BOARD;
 +
 +                      /* set gpio to default value. */
 +                      gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
 +                      gpio_direction_output(&gpio->gpio_j2, 6, 0);
 +              }
 +
 +              /* Workaround: C110 Aquila Rev0.6 */
 +              if (board_rev == 6) {
 +                      board = MACH_TYPE_AQUILA;
 +                      board_rev |= LIMO_REAL_BOARD;
 +              }
 +
 +              /* C110 Aquila Bamboo */
 +              if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
 +                      board = MACH_TYPE_AQUILA;
 +                      board_rev |= BAMBOO_BOARD;
 +              }
 +
 +              /* C110 TickerTape */
 +              if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
 +                              gpio_get_value(&gpio->gpio_d1, 1) == 0)
 +                      board = MACH_TICKERTAPE;
 +
 +              /* WMG160 - GPH3[0:4] = 0x00 */
 +              if (board == MACH_TICKERTAPE) {
 +                      int i, wmg160 = 1;
 +
 +                      for (i = 0; i < 4; i++) {
 +                              if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
 +                                      wmg160 = 0;
 +                                      break;
 +                              }
 +                      }
 +                      if (wmg160) {
 +                              board = MACH_WMG160;
 +                              hwrev3 = 7;
 +                      }
 +              }
 +
 +              /* C110 Geminus for rev0.0 */
 +              gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
 +              gpio_direction_input(&gpio->gpio_j1, 2);
 +              if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
 +                      board = MACH_GEMINUS;
 +                      if ((board_rev & ~BOARD_MASK) == 3)
 +                              board_rev &= ~0xff;
 +              }
 +              gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
 +              gpio_direction_output(&gpio->gpio_j1, 2, 0);
 +
 +              /* C110 Geminus for rev0.1 ~ */
 +              gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
 +              gpio_direction_input(&gpio->gpio_j0, 6);
 +              if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
 +                      board = MACH_GEMINUS;
 +                      hwrev3 = 7;
 +              }
 +              gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
 +
 +              /* Kessler MP0_5[6] == 1 */
 +              gpio_direction_input(&gpio->gpio_mp0_5, 6);
 +              if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
 +                      /* Cypress: Do this for cypress */
 +                      gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
 +                      gpio_direction_input(&gpio->gpio_j2, 2);
 +                      if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
 +                              board = MACH_CYPRESS;
 +                              gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
 +                      } else {
 +                              board = MACH_GONI;
 +                              board_rev |= KESSLER_BOARD;
 +
 +                              /* Limo SDK MP0_5[4] == 1 */
 +                              gpio_direction_input(&gpio->gpio_mp0_5, 4);
 +                              if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
 +                                      board_rev &= ~KESSLER_BOARD;
 +                                      board_rev |= SDK_BOARD;
 +                              }
 +                      }
 +                      gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
 +                      hwrev3 = 7;
 +              } else {
 +                      gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
 +                      /* Goni S1 board detection */
 +                      if (board == MACH_TICKERTAPE) {
 +                              board = MACH_GONI;
 +                              board_rev |= S1_BOARD;
 +                              hwrev3 = 7;
 +                      }
 +              }
 +
 +              board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
 +      }
 +
 +      /* Set machine id */
 +      if (board < MACH_PSEUDO_END) {
 +              if (cpu_is_s5pc110())
 +                      gd->bd->bi_arch_number = C110_MACH_START + board;
 +              else
 +                      gd->bd->bi_arch_number = C100_MACH_START + board;
 +      } else {
 +              gd->bd->bi_arch_number = board;
 +      }
 +
 +      /* Architecture Common settings */
 +      if (cpu_is_s5pc110()) {
 +              setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
 +      } else {
 +              setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
 +                              "bootm 0x30007FC0");
 +              setenv("updatek", "onenand erase 0x60000 0x300000; "
 +                                "onenand write 0x31008000 0x60000 0x300000");
 +      }
 +}
 +
 +static void show_hw_revision(void)
 +{
 +      int board;
 +
 +      /*
 +       * Workaround for Rev 0.3 + CP Ver ES 3.1
 +       * it's Rev 0.4
 +       */
 +      if (board_is_limo_real()) {
 +              if (hwrevision(0)) {
 +                      /* default is Rev 0.4 */
 +                      board_rev &= ~0xf;
 +                      board_rev |= 0x4;
 +              }
 +      }
 +
 +      if (mach_is_goni() || mach_is_aquila())
 +              board = gd->bd->bi_arch_number;
 +      else if (cpu_is_s5pc110())
 +              board = gd->bd->bi_arch_number - C110_MACH_START;
 +      else
 +              board = gd->bd->bi_arch_number - C100_MACH_START;
 +
 +      check_board_revision(board, board_rev);
 +
 +      /* Set CPU Revision */
 +      if (mach_is_aquila()) {
 +              if (board_is_limo_real()) {
 +                      if ((board_rev & 0xf) < 8)
 +                              s5pc1xx_set_cpu_rev(0);
 +              }
 +              else if (board_is_bamboo())
 +                      s5pc1xx_set_cpu_rev(0);
 +      } else if (mach_is_goni()) {
 +              if (board_is_sdk() && (hwrevision(2) || hwrevision(4)))
 +                      s5pc1xx_set_cpu_rev(2); /* EVT1-Fused */
 +              else
 +                      s5pc1xx_set_cpu_rev(1);
 +      } else if (mach_is_geminus()) {
 +              if ((board_rev & 0xf) < 1)
 +                      s5pc1xx_set_cpu_rev(0);
 +      } else if (mach_is_cypress()) {
 +              s5pc1xx_set_cpu_rev(1);
 +      } else {
 +              s5pc1xx_set_cpu_rev(0);
 +      }
 +
 +      if (cpu_is_s5pc110())
 +              writel(0xc1100000 | (0xffff & (s5pc1xx_get_cpu_rev() ? 1 : 0)),
 +                              S5PC110_INFORM3);
 +
 +      empty_device_info_buffer();
 +      dprintf("HW Revision:\t%x (%s%s) %s\n",
 +              board_rev, get_board_name(board),
 +              display_features(board, board_rev),
 +              s5pc1xx_get_cpu_rev() ? "" : "EVT0");
 +}
 +
 +static void check_auto_burn(void)
 +{
 +      unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
 +      unsigned int count = 0;
 +      char buf[64];
 +
 +      if (readl(magic_base) == 0x426f6f74) {  /* ASICC: Boot */
 +              puts("Auto burning bootloader\n");
 +              count += sprintf(buf + count, "run updateb; ");
 +      }
 +      if (readl(magic_base + 0x04) == 0x4b65726e) {   /* ASICC: Kern */
 +              puts("Auto burning kernel\n");
 +              count += sprintf(buf + count, "run updatek; ");
 +      }
 +
 +      if (count) {
 +              count += sprintf(buf + count, "reset");
 +              setenv("bootcmd", buf);
 +      }
 +
 +      /* Clear the magic value */
 +      writel(0xa5a55a5a, magic_base);
 +      writel(0xa5a55a5a, magic_base + 0x4);
 +}
 +
 +static void pmic_pin_init(void)
 +{
 +      unsigned int reg, value;
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      /* AP_PS_HOLD: XEINT_0: GPH0[0]
 +       * Note: Don't use GPIO PS_HOLD it doesn't work
 +       */
 +      reg = S5PC110_PS_HOLD_CONTROL;
 +      value = readl(reg);
 +      value |= S5PC110_PS_HOLD_DIR_OUTPUT |
 +              S5PC110_PS_HOLD_DATA_HIGH |
 +              S5PC110_PS_HOLD_OUT_EN;
 +      writel(value, reg);
 +
 +      /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
 +}
 +
 +static void enable_ldos(void)
 +{
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
 +}
 +
 +static void enable_t_flash(void)
 +{
 +      if (!(board_is_limo_universal() || board_is_limo_real()))
 +              return;
 +
 +      /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
 +}
 +
 +static void setup_limo_real_gpios(void)
 +{
 +      if (!board_is_limo_real())
 +              return;
 +
 +      /*
 +       * Note: Please write GPIO alphabet order
 +       */
 +      /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
 +
 +      if (hwrevision(0))
 +              /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
 +              gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
 +      else
 +              /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
 +              gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
 +
 +      /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
 +}
 +
 +static void setup_media_gpios(void)
 +{
 +      if (!board_is_media())
 +              return;
 +
 +      /*
 +       * Note: Please write GPIO alphabet order
 +       */
 +      /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
 +
 +      /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
 +      gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
 +      gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
 +}
 +
 +#define KBR3          (1 << 3)
 +#define KBR2          (1 << 2)
 +#define KBR1          (1 << 1)
 +#define KBR0          (1 << 0)
 +
 +static void check_keypad(void)
 +{
 +      unsigned int reg, value;
 +      unsigned int col_num, row_num;
 +      unsigned int col_mask;
 +      unsigned int col_mask_shift;
 +      unsigned int row_state[4];
 +      unsigned int i;
 +      unsigned int auto_download = 0;
 +
 +      if (mach_is_wmg160())
 +              return;
 +
 +      if (cpu_is_s5pc100()) {
 +              struct s5pc100_gpio *gpio =
 +                      (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
 +
 +              row_num = 3;
 +              col_num = 3;
 +
 +              /* Set GPH2[2:0] to KP_COL[2:0] */
 +              gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
 +
 +              /* Set GPH3[2:0] to KP_ROW[2:0] */
 +              gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
 +
 +              reg = S5PC100_KEYPAD_BASE;
 +              col_mask = S5PC1XX_KEYIFCOL_MASK;
 +              col_mask_shift = 0;
 +      } else {
 +              if (board_is_limo_real() || board_is_limo_universal()) {
 +                      row_num = 2;
 +                      col_num = 3;
 +              } else {
 +                      row_num = 4;
 +                      col_num = 4;
 +              }
 +
 +              for (i = 0; i < row_num; i++) {
 +                      if (board_is_sdk() && (hwrevision(3) || hwrevision(4)) && i == 0) {
 +                              continue;
 +                      }
 +                      /* Set GPH3[3:0] to KP_ROW[3:0] */
 +                      gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
 +                      gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
 +              }
 +
 +              for (i = 0; i < col_num; i++)
 +                      /* Set GPH2[3:0] to KP_COL[3:0] */
 +                      gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
 +
 +              reg = S5PC110_KEYPAD_BASE;
 +              col_mask = S5PC110_KEYIFCOLEN_MASK;
 +              col_mask_shift = 8;
 +      }
 +
 +      /* KEYIFCOL reg clear */
 +      writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +
 +      /* key_scan */
 +      for (i = 0; i < col_num; i++) {
 +              value = col_mask;
 +              value &= ~(1 << i) << col_mask_shift;
 +
 +              writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +              udelay(1000);
 +
 +              value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
 +              row_state[i] = ~value & ((1 << row_num) - 1);
 +              if (row_state[i])
 +                      printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
 +      }
 +
 +      /* KEYIFCOL reg clear */
 +      writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +
 +      if (mach_is_aquila() || mach_is_goni()) {
 +              /* volume down */
 +              if (row_state[1] & 0x2)
 +                      display_info = 1;
 +              if (board_is_sdk() && hwrevision(0)) {
 +                      /* home & volume down */
 +                      if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
 +                              auto_download = 1;
 +              } else if (board_is_sdk() && hwrevision(2)) {
 +                      /* cam full shot & volume down */
 +                      if ((row_state[1] & 0x6) && (row_state[2] & 0x4))
 +                              auto_download = 1;
 +              } else if (board_is_sdk() && (hwrevision(3) || hwrevision(4))) {
 +                      /* cam full shot & volume down */
 +                      if ((row_state[1] & 0x6) && (row_state[2] & 0x4))
 +                              auto_download = 1;
 +              } else {
 +                      /* cam full shot & volume down */
 +                      if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
 +                              auto_download = 1;
 +              }
 +      } else if (mach_is_geminus())
 +              /* volume down & home */
 +              if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
 +                      auto_download = 1;
 +
 +      if (auto_download)
 +              setenv("bootcmd", "usbdown");
 +}
 +
 +static void check_battery(int mode)
 +{
 +      unsigned char val[2];
 +      unsigned char addr = 0x36;      /* max17040 fuel gauge */
 +
 +      i2c_set_bus_num(I2C_GPIO3);
 +
 +      if (mach_is_aquila()) {
 +              if (board_is_j1b2())
 +                      return;
 +      } else if (mach_is_goni()) {
 +              i2c_set_bus_num(I2C_GPIO7);
 +      } else if (mach_is_cypress()) {
 +              i2c_set_bus_num(I2C_GPIO7);
 +      } else if (mach_is_geminus()) {
 +              if (hwrevision(1))
 +                      i2c_set_bus_num(I2C_GPIO7);
 +      } else
 +              return;
 +
 +      if (i2c_probe(addr)) {
 +              puts("Can't found max17040 fuel gauge\n");
 +              return;
 +      }
 +
 +      /* mode 0: check mode / 1: enable mode */
 +      if (mode) {
 +              val[0] = 0x54;
 +              val[1] = 0x00;
 +              i2c_write(addr, 0xfe, 1, val, 2);
 +      } else {
 +              i2c_read(addr, 0x04, 1, val, 1);
 +              dprintf("battery:\t%d%%\n", val[0]);
 +              battery_soc = val[0];
 +      }
 +}
 +
 +static void check_mhl(void)
 +{
 +      unsigned char val[2];
 +      unsigned char addr = 0x39;      /* SIL9230 */
 +
 +      /* MHL Power enable */
 +      /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
 +
 +      /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
 +
 +      /* 10ms required after reset */
 +      udelay(10000);
 +
 +      /* output enable */
 +      gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
 +
 +      i2c_set_bus_num(I2C_GPIO5);
 +
 +      /* set usb path */
 +      if (i2c_probe(addr)) {
 +              puts("Can't found MHL Chip\n");
 +              return;
 +      }
 +
 +      /*
 +       * System Control #1
 +       * set to Normal operation
 +       */
 +      val[0] = 0x35;
 +      i2c_write((0x72 >> 1), 0x08, 1, val, 1);
 +      i2c_read((0x72 >> 1), 0x08, 1, val, 1);
 +
 +      /*
 +       * MHL TX Control #1
 +       * TERM_MODE [7:6]
 +       * 00 = MHL termination ON
 +       * 11 = MHL termination OFF
 +       */
 +      val[0] = 0xd0;
 +      i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
 +      i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
 +}
 +
 +static int max8998_probe(void)
 +{
 +      unsigned char addr = 0xCC >> 1;
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +
 +      if (i2c_probe(addr)) {
 +              puts("Can't found max8998\n");
 +              return 1;
 +      }
 +
 +      return 0;
 +}
 +
 +#define CHARGER_ANIMATION_FRAME               6
 +static void max8998_clear_interrupt(void)
 +{
 +      unsigned char addr, val[2];
 +      addr = 0xCC >> 1;
 +
 +      if (max8998_probe())
 +              return;
 +
 +      i2c_read(addr, 0x00, 1, val, 1);
 +      i2c_read(addr, 0x01, 1, val, 1);
 +      i2c_read(addr, 0x02, 1, val, 1);
 +      i2c_read(addr, 0x03, 1, val, 1);
 +}
 +
 +static int max8998_power_key(void)
 +{
 +      unsigned char addr, val[2];
 +      addr = 0xCC >> 1;
 +
 +      if (max8998_probe())
 +              return 0;
 +
 +      /* Accessing IRQ1 register */
 +      i2c_read(addr, 0x00, 1, val, 1);
 +      if (val[0] & (1 << 6))
 +              return 1;
 +
 +      return 0;
 +}
 +
 +static int max8998_has_ext_power_source(void)
 +{
 +      unsigned char addr, val[2];
 +      addr = 0xCC >> 1;
 +
 +      if (max8998_probe())
 +              return 0;
 +
 +      /* Accessing STATUS2 register */
 +      i2c_read(addr, 0x09, 1, val, 1);
 +      if (val[0] & (1 << 5))
 +              return 1;
 +
 +      return 0;
 +}
 +
 +struct thermister_stat {
 +      short centigrade;
 +      unsigned short adc;
 +};
 +
 +static struct thermister_stat adc_to_temperature_data[] = {
 +      { .centigrade = -20,    .adc = 1856, },
 +      { .centigrade = -15,    .adc = 1799, },
 +      { .centigrade = -10,    .adc = 1730, },
 +      { .centigrade = -5,     .adc = 1649, },
 +      { .centigrade = 0,      .adc = 1556, },
 +      { .centigrade = 5,      .adc = 1454, },
 +      { .centigrade = 10,     .adc = 1343, },
 +      { .centigrade = 15,     .adc = 1227, },
 +      { .centigrade = 20,     .adc = 1109, },
 +      { .centigrade = 25,     .adc = 992, },
 +      { .centigrade = 30,     .adc = 880, },
 +      { .centigrade = 35,     .adc = 773, },
 +      { .centigrade = 40,     .adc = 675, },
 +      { .centigrade = 45,     .adc = 586, },
 +      { .centigrade = 50,     .adc = 507, },
 +      { .centigrade = 55,     .adc = 436, },
 +      { .centigrade = 58,     .adc = 399, },
 +      { .centigrade = 63,     .adc = 343, },
 +      { .centigrade = 65,     .adc = 322, },
 +};
 +
 +#ifndef USHRT_MAX
 +#define USHRT_MAX     0xFFFFU
 +#endif
 +static int adc_to_temperature_centigrade(unsigned short adc)
 +{
 +      int i;
 +      int approximation;
 +      /* low_*: Greatest Lower Bound,
 +       *          *          *          * high_*: Smallest Upper Bound */
 +      int low_temp = 0, high_temp = 0;
 +      unsigned short low_adc = 0, high_adc = USHRT_MAX;
 +      for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
 +              if (adc_to_temperature_data[i].adc <= adc &&
 +                              adc_to_temperature_data[i].adc >= low_adc) {
 +                      low_temp = adc_to_temperature_data[i].centigrade;
 +                      low_adc = adc_to_temperature_data[i].adc;
 +              }
 +              if (adc_to_temperature_data[i].adc >= adc &&
 +                              adc_to_temperature_data[i].adc <= high_adc) {
 +                      high_temp = adc_to_temperature_data[i].centigrade;
 +                      high_adc = adc_to_temperature_data[i].adc;
 +              }
 +      }
 +
 +      /* Linear approximation between cloest low and high,
 +       * which is the weighted average of the two. */
 +
 +      /* The following equation is correct only when the two are different */
 +      if (low_adc == high_adc)
 +              return low_temp;
 +      if (ARRAY_SIZE(adc_to_temperature_data) < 2)
 +              return 20; /* The room temperature */
 +      if (low_adc == 0)
 +              return high_temp;
 +      if (high_adc == USHRT_MAX)
 +              return low_temp;
 +
 +      approximation = low_temp * (adc - low_adc) +
 +              high_temp * (high_adc - adc);
 +      approximation /= high_adc - low_adc;
 +
 +      return approximation;
 +}
 +
 +static unsigned short get_adc_value(int channel)
 +{
 +      struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
 +      unsigned short ret = 0;
 +      unsigned int reg;
 +      int ldonum = 8;
 +      char buf[64];
 +      unsigned int loop = 0;
 +
 +      if (mach_is_goni())
 +              ldonum = 4;
 +      else if (mach_is_geminus())
 +              ldonum = 4;
 +      else if (mach_is_wmg160())
 +              ldonum = 4;
 +      else if (mach_is_cypress())
 +              ldonum = 8;
 +      else if (mach_is_tickertape())
 +              ldonum = 8;
 +      else if (mach_is_aquila())
 +              ldonum = 8;
 +      /*
 +      else if (mach_is_p1p2())
 +              ldonum = 4;
 +      */
 +
 +      sprintf(buf, "pmic ldo %d on", ldonum);
 +      run_command(buf, 0);
 +
 +      writel(channel & 0xF, &adc->adcmux);
 +      writel((1 << 14) | (49 << 6), &adc->adccon);
 +      writel(1000 & 0xffff, &adc->adcdly);
 +      writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
 +      udelay(10);
 +      writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
 +      udelay(10);
 +
 +      do {
 +              udelay(1);
 +              reg = readl(&adc->adccon);
 +      } while (!(reg & (1 << 15)) && (loop++ < 1000));
 +
 +      ret = readl(&adc->adcdat0) & 0xFFF;
 +      sprintf(buf, "pmic ldo %d off", ldonum);
 +      run_command(buf, 0);
 +
 +      return ret;
 +}
 +
 +static int adc_get_average_ambient_temperature(void)
 +{
 +      if (mach_is_goni()) {
 +              unsigned short min = USHRT_MAX;
 +              unsigned short max = 0;
 +              unsigned int sum = 0;
 +              unsigned int measured = 0;
 +              int i;
 +
 +              for (i = 0; i < 7; i++) {
 +                      unsigned short measurement = get_adc_value(6);
 +                      sum += measurement;
 +                      measured++;
 +                      if (min > measurement)
 +                              min = measurement;
 +                      if (max < measurement)
 +                              max = measurement;
 +              }
 +              if (measured >= 3) {
 +                      measured -= 2;
 +                      sum -= min;
 +                      sum -= max;
 +              }
 +              sum /= measured;
 +              printf("Average Ambient Temperature = %d(ADC=%d)\n",
 +                              adc_to_temperature_centigrade(sum), sum);
 +              return adc_to_temperature_centigrade(sum);
 +      }
 +
 +      return 20; /* 20 Centigrade */
 +}
 +
 +enum temperature_level {
 +      _TEMP_OK,
 +      _TEMP_OK_HIGH,
 +      _TEMP_OK_LOW,
 +      _TEMP_TOO_HIGH,
 +      _TEMP_TOO_LOW,
 +};
 +
 +static enum temperature_level temperature_check(void)
 +{
 +      int temp = adc_get_average_ambient_temperature();
 +      if (temp < -5)
 +              return _TEMP_TOO_LOW;
 +      if (temp < 0)
 +              return _TEMP_OK_LOW;
 +      if (temp > 63)
 +              return _TEMP_TOO_HIGH;
 +      if (temp > 58)
 +              return _TEMP_OK_HIGH;
 +      return _TEMP_OK;
 +}
 +
 +extern void lcd_display_clear(void);
 +extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
 +
 +static void charger_en(int enable)
 +{
 +      /* 0: disable
 +       * 600: 600mA
 +       * 475: 475mA
 +       */
 +      unsigned char addr = 0xCC >> 1; /* max8998 */
 +      unsigned char val[2];
 +
 +      if (max8998_probe())
 +              return;
 +
 +      if (!enable) {
 +              puts("Disable the charger.\n");
 +              i2c_read(addr, 0x0D, 1, val, 1);
 +              val[0] &= ~(0x1);
 +              val[0] |= 0x1;
 +              i2c_write(addr, 0x0D, 1, val, 1);
 +      } else {
 +              i2c_read(addr, 0x0C, 1, val, 1);
 +              val[0] &= ~(0x7 << 0);
 +              val[0] &= ~(0x7 << 5);
 +              if (enable == 600) {
 +                      val[0] |= 5; /* 600mA */
 +                      val[0] |= (3 << 5); /* Stop at 150mA (25%) */
 +              } else { /* Assume 475 mA */
 +                      enable = 475;
 +                      val[0] |= 2; /* 475mA */
 +                      val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
 +              }
 +              i2c_write(addr, 0x0C, 1, val, 1);
 +
 +              i2c_read(addr, 0x0D, 1, val, 1);
 +              val[0] &= ~(0x1);
 +              i2c_write(addr, 0x0D, 1, val, 1);
 +              printf("Enable the charger @ %dmA\n", enable);
 +      }
 +}
 +
 +void lcd_power_on(unsigned int onoff);
 +extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 +extern int drv_lcd_init_resume (void);
 +
 +static void into_charge_mode(void)
 +{
 +      unsigned int level;
 +      int i, j;
 +      bmp_image_t *bmp;
 +      unsigned long len;
 +      ulong bmp_addr[CHARGER_ANIMATION_FRAME];
 +      unsigned int reg, wakeup_stat;
 +      int charger_speed = 600;
 +
 +      max8998_clear_interrupt();
 +
 +      puts("Charge Mode\n");
 +      charger_en(charger_speed);
 +
 +#ifdef CONFIG_S5PC1XXFB
 +      init_font();
 +
 +      /* TODO: write the image-text for the charger */
 +
 +      level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
 +      if (level >= CHARGER_ANIMATION_FRAME)
 +              level = CHARGER_ANIMATION_FRAME - 1;
 +
 +      for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
 +              bmp_addr[i] = (ulong)battery_charging_animation[i];
 +
 +      lcd_display_clear();
 +      for (i = 0; i < 3; i++) {
 +              for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
 +                      int k;
 +
 +                      bmp = gunzip_bmp(bmp_addr[j], &len);
 +                      lcd_display_bitmap((ulong)bmp, 140, 202);
 +                      free(bmp);
 +
 +                      for (k = 0; k < 10; k++) {
 +                              if (max8998_power_key()) {
 +                                      lcd_display_clear();
 +                                      goto restore_screen;
 +                              } else if (!max8998_has_ext_power_source()) {
 +                                      lcd_display_clear();
 +                                      goto restore_screen;
 +                              } else {
 +                                      udelay(100 * 1000);
 +                              }
 +                      }
 +              }
 +      }
 +      exit_font();
 +
 +      /* Disable the display to prevent flickering */
 +      /* TODO: how to reenable the display later? */
 +      lcd_power_on(0);
 +#endif
 +
 +      do {
 +              struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
 +              unsigned int org, org_ip3;
 +              enum temperature_level  previous_state = _TEMP_OK;
 +
 +              empty_device_info_buffer();
 +              if (max8998_power_key())
 +                      break;
 +              else if (!max8998_has_ext_power_source())
 +                      break;
 +
 +              /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
 +              org_ip3 = readl(0xE010046C);
 +              writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
 +
 +              reg = org = readl(&rtc->rtccon);
 +              reg |= (1 << 0);
 +              writel(reg, &rtc->rtccon);
 +
 +              reg = readl(&rtc->rtccon);
 +              writel(reg | (1 << 3), &rtc->rtccon);
 +              udelay(10);
 +              writel(reg & ~(1 << 3), &rtc->rtccon);
 +              udelay(10);
 +
 +              reg = readl(&rtc->rtccon);
 +              reg &= ~((1 << 8) | (0xF << 4));
 +              reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
 +              writel(reg, &rtc->rtccon);
 +
 +              reg = 15 * 4 - 1; /* 15 sec */
 +              writel(reg, &rtc->ticcnt);
 +
 +              /* EVT0: sleep 1, EVT1: sleep */
 +              if (cpu_is_s5pc110()) {
 +                      char *name = "dummy";
 +                      char *usage = "N/A";
 +                      char *help = NULL;
 +                      cmd_tbl_t ctt;
 +                      ctt.name = name;
 +                      ctt.usage = usage;
 +                      ctt.help = help;
 +
 +                      if (s5pc1xx_get_cpu_rev() == 0) {
 +                              char *argv[] = {"1", "1"};
 +                              wakeup_stat = do_sleep(&ctt, 0, 2, argv);
 +                      } else {
 +                              char *argv[] = {"0", "0"};
 +                              wakeup_stat = do_sleep(&ctt, 0, 1, argv);
 +                      }
 +              } else {
 +                      puts("\n\n\nERROR: this is not S5PC110.\n\n\n");
 +                      return;
 +              }
 +
 +              /* Check TEMP HIGH/LOW */
 +              switch (temperature_check()) {
 +              case _TEMP_OK:
 +                      charger_en(charger_speed);
 +                      previous_state = _TEMP_OK;
 +                      break;
 +              case _TEMP_TOO_LOW:
 +                      charger_en(0);
 +                      previous_state = _TEMP_TOO_LOW;
 +                      break;
 +              case _TEMP_TOO_HIGH:
 +                      charger_en(0);
 +                      previous_state = _TEMP_TOO_HIGH;
 +                      break;
 +              case _TEMP_OK_LOW:
 +                      if (previous_state == _TEMP_TOO_LOW) {
 +                              charger_en(0);
 +                      } else {
 +                              charger_en(charger_speed);
 +                              previous_state = _TEMP_OK;
 +                      }
 +                      break;
 +              case _TEMP_OK_HIGH:
 +                      if (previous_state == _TEMP_TOO_HIGH) {
 +                              charger_en(0);
 +                      } else {
 +                              charger_en(charger_speed);
 +                              previous_state = _TEMP_OK;
 +                      }
 +                      break;
 +              }
 +
 +              writel(org, &rtc->rtccon);
 +              writel(org_ip3, 0xE010046C);
 +
 +      } while (wakeup_stat == 0x04); /* RTC TICK */
 +
 +#ifdef CONFIG_S5PC1XXFB
 +restore_screen:
 +      /* TODO: Reenable logo display (not working yet) */
 +      lcd_power_on(1);
 +      drv_lcd_init_resume();
 +#endif
 +}
 +
 +#define S5PC110_RST_STAT      0xE010A000
 +
 +#define SWRESET                       (1 << 3)
 +#define WDTRESET              (1 << 2)
 +#define WARMRESET             (1 << 1)
 +#define EXTRESET              (1 << 0)
 +
 +static int get_reset_status(void)
 +{
 +      return readl(S5PC110_RST_STAT) & 0xf;
 +}
 +
 +static int fsa9480_probe(void)
 +{
 +      unsigned char addr = 0x25;
 +
 +      if (cpu_is_s5pc100())
 +              return 1;
 +
 +      if (board_is_limo_real()) {
 +              if (hwrevision(0) || hwrevision(1))
 +                      return 1;
 +      }
 +
 +      i2c_set_bus_num(I2C_PMIC);
 +
 +      if (mach_is_goni()) {
 +              i2c_set_bus_num(I2C_GPIO6);
 +      } else if (mach_is_cypress()) {
 +              i2c_set_bus_num(I2C_GPIO6);
 +      } else if (mach_is_geminus()) {
 +              if (hwrevision(1))
 +                      i2c_set_bus_num(I2C_GPIO6);
 +      } else if (mach_is_wmg160()) {
 +              i2c_set_bus_num(I2C_GPIO6);
 +      }
 +
 +      if (i2c_probe(addr)) {
 +              puts("Can't found fsa9480\n");
 +              return 1;
 +      }
 +
 +      return 0;
 +}
 +
 +static void check_micro_usb(int intr)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +      static int started_charging_once = 0;
 +      char *path;
 +
 +      if (fsa9480_probe())
 +              return;
 +
 +      addr = 0x25;            /* fsa9480 */
 +
 +      /* Clear Interrupt */
 +      if (intr) {
 +              i2c_read(addr, 0x03, 1, val, 2);
 +              return;
 +      }
 +
 +      /* Read Device Type 1 */
 +      i2c_read(addr, 0x0a, 1, val, 1);
 +
 +#define FSA_DEV1_CHARGER      (1 << 6)
 +#define FSA_DEV1_UART         (1 << 3)
 +#define FSA_DEV1_USB          (1 << 2)
 +#define FSA_DEV2_JIG_USB_OFF  (1 << 1)
 +#define FSA_DEV2_JIG_USB_ON   (1 << 0)
 +
 +      /*
 +       * If USB, use default 475mA
 +       * If Charger, use 600mA and go to charge mode
 +       */
 +      if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
 +              started_charging_once = 1;
 +
 +              /* If it's full, do not charge. */
 +              if (battery_soc < 100)
 +                      into_charge_mode();
 +              else
 +                      charger_en(0);
 +      } else if (val[0] & FSA_DEV1_USB) {
 +              if (battery_soc < 100)
 +                      charger_en(475); /* enable charger and keep booting */
 +              else
 +                      charger_en(0);
 +      }
 +
 +      /* If reset status is watchdog reset then skip it */
 +      if (!(get_reset_status() & WDTRESET)) {
 +              /* If Factory Mode is Boot ON-USB, go to download mode */
 +              i2c_read(addr, 0x07, 1, val, 1);
 +
 +#define FSA_ADC_FAC_USB_OFF   0x18
 +#define FSA_ADC_FAC_USB_ON    0x19
 +#define FSA_ADC_FAC_UART      0x1d
 +
 +              if (val[0] == FSA_ADC_FAC_USB_ON ||
 +                      val[0] == FSA_ADC_FAC_USB_OFF)
 +                      setenv("bootcmd", "usbdown");
 +      }
 +
 +      path = getenv("usb");
 +
 +      if (!strncmp(path, "cp", 2))
 +              run_command("microusb cp", 0);
 +}
 +
 +static void micro_usb_switch(int path)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      if (fsa9480_probe())
 +              return;
 +
 +      addr = 0x25;            /* fsa9480 */
 +
 +      if (path)
 +              val[0] = 0x90;  /* VAUDIO */
 +      else
 +              val[0] = (1 << 5) | (1 << 2);   /* DHOST */
 +
 +      i2c_write(addr, 0x13, 1, val, 1);       /* MANSW1 */
 +
 +      i2c_read(addr, 0x2, 1, val, 1);
 +      val[0] &= ~(1 << 2);                    /* Manual switching */
 +      i2c_write(addr, 0x2, 1, val, 1);
 +}
 +
 +#define MAX8998_REG_ONOFF1    0x11
 +#define MAX8998_REG_ONOFF2    0x12
 +#define MAX8998_REG_ONOFF3    0x13
 +#define MAX8998_REG_LDO7      0x21
 +#define MAX8998_REG_LDO17     0x29
 +/* ONOFF1 */
 +#define MAX8998_LDO3          (1 << 2)
 +/* ONOFF2 */
 +#define MAX8998_LDO6          (1 << 7)
 +#define MAX8998_LDO7          (1 << 6)
 +#define MAX8998_LDO8          (1 << 5)
 +#define MAX8998_LDO9          (1 << 4)
 +#define MAX8998_LDO10         (1 << 3)
 +#define MAX8998_LDO11         (1 << 2)
 +#define MAX8998_LDO12         (1 << 1)
 +#define MAX8998_LDO13         (1 << 0)
 +/* ONOFF3 */
 +#define MAX8998_LDO14         (1 << 7)
 +#define MAX8998_LDO15         (1 << 6)
 +#define MAX8998_LDO16         (1 << 5)
 +#define MAX8998_LDO17         (1 << 4)
 +
 +
 +static void init_pmic(void)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      addr = 0xCC >> 1;       /* max8998 */
 +      if (max8998_probe())
 +              return;
 +
 +      /* ONOFF1 */
 +      i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +      val[0] &= ~MAX8998_LDO3;
 +      i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +
 +      /* ONOFF2 */
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      /*
 +       * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
 +       * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
 +       */
 +      val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
 +                      MAX8998_LDO12 | MAX8998_LDO13);
 +
 +      if (mach_is_goni())
 +              val[0] |= MAX8998_LDO7;         /* LDO7: VLCD_1.8V */
 +
 +      i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      /* ONOFF3 */
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      /*
 +       * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
 +       * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
 +       */
 +      val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
 +                      MAX8998_LDO16 | MAX8998_LDO17);
 +
 +      if (mach_is_goni())
 +              val[0] |= MAX8998_LDO17;        /* LDO17: VCC_3.0V_LCD */
 +
 +      i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +}
 +
 +static void setup_power_down_mode_registers(void)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
++      struct s5p_gpio_bank *bank;
 +      struct gpio_powermode *p;
 +      int n_p;
 +      struct gpio_external *ge;
 +      int n_ge;
 +      struct s5pc1xx_gpio_item *mr;
 +      int n_mr;
 +      int i;
 +
 +      if (cpu_is_s5pc100())
 +              return;
 +
 +      /* Only Limo real and kessler supports worked for sleep currnet */
 +      if (mach_is_aquila()) {
 +              if (board_is_limo_real())
 +                      /* Support */;
 +              else
 +                      return;
 +      } else if (mach_is_goni()) {
 +              /* Support */;
 +      } else if (mach_is_geminus()) {
 +              /* Support */;
 +      } else {
 +              return;
 +      }
 +
 +      if (mach_is_aquila()) {
 +              /* Aquila rev 0.8 or lower */
 +              p = aquila_powerdown_modes;
 +              ge = aquila_external_powerdown_modes;
 +              mr = aquila_mirror_powerdown_mode;
 +              n_p = ARRAY_SIZE(aquila_powerdown_modes);
 +              n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
 +              n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
 +      } else if (mach_is_goni()) {
 +              /* Aquila rev 0.9 */
 +              p = kessler_powerdown_modes;
 +              ge = kessler_external_powerdown_modes;
 +              mr = kessler_mirror_powerdown_mode;
 +              n_p = ARRAY_SIZE(kessler_powerdown_modes);
 +              n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
 +              n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
 +      } else if (mach_is_geminus()) {
 +              if (hwrevision(1)) {
 +                      /* Same as Aquila rev 0.9 */
 +#if 0
 +                      p = kessler_powerdown_modes;
 +                      ge = kessler_external_powerdown_modes;
 +                      mr = kessler_mirror_powerdown_mode;
 +                      n_p = ARRAY_SIZE(kessler_powerdown_modes);
 +                      n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
 +                      n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
 +#else
 +                      p = aquila_powerdown_modes;
 +                      ge = aquila_external_powerdown_modes;
 +                      mr = aquila_mirror_powerdown_mode;
 +                      n_p = ARRAY_SIZE(aquila_powerdown_modes);
 +                      n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
 +                      n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
 +#endif
 +              } else if (hwrevision(0)) {
 +                      /* Same as Aquila rev 0.8 or lower */
 +                      p = aquila_powerdown_modes;
 +                      ge = aquila_external_powerdown_modes;
 +                      mr = aquila_mirror_powerdown_mode;
 +                      n_p = ARRAY_SIZE(aquila_powerdown_modes);
 +                      n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
 +                      n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
 +              } else {
 +                      return; /* Not supported */
 +              }
 +      }
 +
 +      bank = &gpio->gpio_a0;
 +
 +      for (i = 0; i < n_p; i++, p++, bank++) {
 +              writel(p->conpdn, &bank->pdn_con);
 +              writel(p->pudpdn, &bank->pdn_pull);
 +      }
 +      /* M299 */
 +      writel(0xff0022b0, (unsigned int *)0xF0000000);
 +      writel(0xff0022b0, (unsigned int *)0xF1400000);
 +
 +      bank = &gpio->gpio_h0;
 +
 +      for (i = 0; i < n_ge; i++) {
 +              writel(ge->con, &bank->con);
 +              writel(ge->dat, &bank->dat);
 +              writel(ge->pud, &bank->pull);
 +
 +              bank++;
 +              ge++;
 +      }
 +
 +      for (i = 0; i < n_mr; i++) {
 +              unsigned int reg = readl(&mr->bank->pdn_con);
 +              reg &= ~(0x3 << (mr->number << 1));
 +              if (readl(&mr->bank->dat) & (1 << mr->number))
 +                      reg |= 0x1 << (mr->number << 1);
 +              writel(reg, &mr->bank->pdn_con);
 +              mr++;
 +      }
 +}
 +
 +#ifdef CONFIG_LCD
 +#include "../../../drivers/video/s5p-spi.h"
 +
 +extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
 +extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
 +extern void ld9040_set_platform_data(struct spi_platform_data *pd);
 +
 +struct spi_platform_data spi_pd;
 +
 +struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +void lcd_cfg_gpio(void)
 +{
 +      unsigned int i, f3_end = 4;
 +
 +      for (i = 0; i < 8; i++) {
 +              /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
 +              gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
 +              gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
 +              gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
 +              /* pull-up/down disable */
 +              gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
 +              gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
 +              gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
 +
 +              /* drive strength to max (24bit) */
 +              gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
 +              gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
 +              gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
 +      }
 +
 +      /* set DISPLAY_DE_B pin for dual rgb mode. */
 +      if (board_is_media())
 +              f3_end = 5;
 +
 +      for (i = 0; i < f3_end; i++) {
 +              /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
 +              gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
 +              /* pull-up/down disable */
 +              gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
 +              /* drive strength to max (24bit) */
 +              gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
 +              gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
 +      }
 +      /* display output path selection (only [1:0] valid) */
 +      writel(0x2, 0xE0107008);
 +
 +      /* gpio pad configuration for LCD reset. */
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
 +
 +      /* gpio pad configuration for LCD ON. */
 +      gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
 +
 +      /* LCD_BACKLIGHT_EN */
 +      if (mach_is_geminus())
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
 +      if (board_is_sdk() && hwrevision(0)) {
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
 +              gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
 +      }
 +
 +      /*
 +       * gpio pad configuration for
 +       * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
 +       */
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
 +      gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
 +
 +      if (mach_is_aquila() || mach_is_goni()) {
 +              spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
 +              spi_pd.cs_num = 1;
 +              spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
 +              spi_pd.clk_num = 1;
 +              spi_pd.si_bank = &gpio_base->gpio_mp0_4;
 +              spi_pd.si_num = 3;
 +              spi_pd.so_bank = &gpio_base->gpio_mp0_4;
 +              spi_pd.so_num = 2;
 +
 +              if (board_is_sdk() && hwrevision(0))
 +                      s6d16a0x_set_platform_data(&spi_pd);
 +              else if (board_is_sdk() && hwrevision(3))
 +                      ld9040_set_platform_data(&spi_pd);
 +              else {
 +                      s6e63m0_set_platform_data(&spi_pd);
 +                      if (board_is_media())
 +                              spi_pd.set_rev = 1;
 +              }
 +      }
 +
 +      if (mach_is_cypress()) {
 +#if 0         /* universal cypress */
 +              /* FLCD_CS */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
 +#endif
 +              /* FLCD_CS_S */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
 +              /* FLCD_CLK */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
 +              /* FLCD_SDI */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
 +              /* FLCD_RST_S */
 +              gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
 +              /* FLCD_ON_S */
 +              gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
 +#if 0         /* universal cypress */
 +              pd_cs.bank = &gpio_base->gpio_mp0_1;
 +              pd_cs.num = 0;
 +#endif
 +              spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
 +              spi_pd.cs_num = 1;
 +              spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
 +              spi_pd.clk_num = 0;
 +              spi_pd.si_bank = &gpio_base->gpio_mp0_4;
 +              spi_pd.si_num = 2;
 +
 +              spi_pd.set_rev = 1;
 +
 +              /* these data would be sent to s6e63m0 lcd panel driver. */
 +              s6e63m0_set_platform_data(&spi_pd);
 +      }
 +
 +      return;
 +}
 +
 +#define SWRST_REG             0x00
 +#define LEDCON_REG            0x01
 +#define LED_CUR_SET_REG               0x03
 +#define LED_CUR_TR_REG                0x08
 +
 +#define SWRST                 0x01
 +#define NORMAL_MODE           0x09
 +#define CUR_SET                       0x63
 +#define TR_SET                        0x00
 +void backlight_on(unsigned int onoff)
 +{
 +
 +      unsigned char addr;
 +      unsigned char val[2];
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +      printf("%s\n", __func__);
 +
 +      if (onoff) {
 +              if (mach_is_geminus())
 +                      gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
 +      } else {
 +              if (mach_is_geminus())
 +                      gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
 +      }
 +
 +      if (mach_is_goni() && board_is_sdk() && hwrevision(0)) {
 +              gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
 +              udelay(6);
 +
 +              i2c_set_bus_num(I2C_GPIO5);
 +
 +              addr = 0x76;
 +              if (i2c_probe(addr)) {
 +                      if (i2c_probe(addr)) {
 +                              puts("Can't found s6d16a0x backlight i2c\n");
 +                              return;
 +                      }
 +              }
 +              val[0] = SWRST;
 +              i2c_write(addr, SWRST_REG, 1, val, 1);
 +              /* NORMAL MODE */
 +              val[0] = CUR_SET;
 +              i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
 +              val[0] = TR_SET;
 +              i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
 +              val[0] = NORMAL_MODE;
 +              i2c_write(addr, LEDCON_REG, 1, val, 1);
 +              udelay(5000);
 +      }
 +}
 +
 +void reset_lcd(void)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      if (mach_is_aquila() || mach_is_goni() || mach_is_geminus()) {
 +              gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
 +              if (board_is_sdk() && (hwrevision(3))) {
 +                      udelay(10000);
 +                      gpio_set_value(&gpio->gpio_mp0_5, 5, 0);
 +                      udelay(10000);
 +                      gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
 +                      udelay(100);
 +              }
 +      }
 +      if (mach_is_cypress())
 +              gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
 +}
 +
 +void lcd_power_on(unsigned int onoff)
 +{
 +      struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +      if (onoff) {
 +              /* TSP_LDO_ON */
 +              if (mach_is_aquila() || mach_is_geminus())
 +                      gpio_set_value(&gpio->gpio_j1, 3, 1);
 +
 +              if (mach_is_cypress())
 +                      gpio_set_value(&gpio->gpio_g2, 2, 1);
 +
 +              if (mach_is_goni()) {
 +                      unsigned char addr;
 +                      unsigned char val[2];
 +                      unsigned char val2[2];
 +
 +                      gpio_set_value(&gpio->gpio_j1, 3, 1);
 +
 +                      addr = 0xCC >> 1;       /* max8998 */
 +                      if (max8998_probe())
 +                              return;
 +
 +                      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +                      val[0] &= ~(MAX8998_LDO17);
 +                      val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
 +                      i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +
 +                      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +                      val[0] |= MAX8998_LDO17;
 +                      val2[0] = 0xE;
 +                      i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
 +                      i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +
 +                      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +                      val[0] |= MAX8998_LDO7;
 +                      val2[0] = 0x2;
 +                      i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
 +                      i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +              }
 +      } else {
 +              if (mach_is_aquila() || mach_is_geminus())
 +                      gpio_set_value(&gpio->gpio_j1, 3, 0);
 +
 +              if (mach_is_cypress())
 +                      gpio_set_value(&gpio->gpio_g2, 2, 0);
 +
 +              if (mach_is_goni()) {
 +                      unsigned char addr;
 +                      unsigned char val[2];
 +
 +                      gpio_set_value(&gpio->gpio_j1, 3, 0);
 +
 +                      addr = 0xCC >> 1;       /* max8998 */
 +                      if (max8998_probe())
 +                              return;
 +
 +                      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +                      val[0] &= ~(MAX8998_LDO7);
 +                      i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +                      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +
 +                      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +                      val[0] &= ~(MAX8998_LDO17);
 +                      i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +                      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +              }
 +      }
 +}
 +
 +extern void s6e63m0_cfg_ldo(void);
 +extern void s6e63m0_enable_ldo(unsigned int onoff);
 +extern void s6d16a0x_cfg_ldo(void);
 +extern void s6d16a0x_enable_ldo(unsigned int onoff);
 +extern void ld9040_cfg_ldo(void);
 +extern void ld9040_enable_ldo(unsigned int onoff);
 +
 +int s5p_no_lcd_support(void)
 +{
 +      if (mach_is_wmg160())
 +              return 1;
 +      return 0;
 +}
 +
 +void init_panel_info(vidinfo_t *vid)
 +{
 +      vid->cfg_gpio = NULL;
 +      vid->reset_lcd = NULL;
 +      vid->backlight_on = NULL;
 +      vid->lcd_power_on = NULL;
 +
 +      vid->cfg_ldo = NULL;
 +      vid->enable_ldo = NULL;
 +
 +      vid->init_delay = 0;
 +      vid->reset_delay = 0;
 +      vid->power_on_delay = 0;
 +
 +      vid->vl_freq    = 60;
 +      vid->vl_col     = 480;
 +      vid->vl_row     = 800;
 +      vid->vl_width   = 480;
 +      vid->vl_height  = 800;
 +
 +      vid->dual_lcd_enabled = 0;
 +
 +      if (board_is_media()) {
 +              vid->vl_col     = 960;
 +              vid->vl_row     = 800;
 +              vid->vl_width   = 960;
 +              vid->vl_height  = 800;
 +
 +              /* enable dual lcd mode. */
 +              vid->dual_lcd_enabled = 1;
 +      }
 +
 +      vid->vl_clkp    = CONFIG_SYS_HIGH;
 +      vid->vl_hsp     = CONFIG_SYS_LOW;
 +      vid->vl_vsp     = CONFIG_SYS_LOW;
 +      vid->vl_dp      = CONFIG_SYS_HIGH;
 +      vid->vl_bpix    = 32;
 +
 +      /* S6E63M0 LCD Panel */
 +      vid->vl_hspw    = 2;
 +      vid->vl_hbpd    = 16;
 +      vid->vl_hfpd    = 16;
 +
 +      vid->vl_vspw    = 2;
 +      vid->vl_vbpd    = 3;
 +      vid->vl_vfpd    = 28;
 +
 +      if (mach_is_aquila() || mach_is_goni()
 +                      || mach_is_cypress()) {
 +              vid->cfg_gpio = lcd_cfg_gpio;
 +              vid->reset_lcd = reset_lcd;
 +              vid->backlight_on = backlight_on;
 +              vid->lcd_power_on = lcd_power_on;
 +              vid->cfg_ldo = s6e63m0_cfg_ldo;
 +              vid->enable_ldo = s6e63m0_enable_ldo;
 +
 +              vid->init_delay = 25000;
 +              vid->reset_delay = 120000;
 +      }
 +
 +      if (board_is_sdk() && hwrevision(0)) {
 +              vid->vl_freq    = 100;
 +              vid->vl_col     = 320;
 +              vid->vl_row     = 480;
 +              vid->vl_width   = 320;
 +              vid->vl_height  = 480;
 +
 +              vid->vl_clkp    = CONFIG_SYS_HIGH;
 +              vid->vl_hsp     = CONFIG_SYS_HIGH;
 +              vid->vl_vsp     = CONFIG_SYS_HIGH;
 +              vid->vl_dp      = CONFIG_SYS_LOW;
 +              vid->vl_bpix    = 32;
 +
 +              /* disable dual lcd mode. */
 +              vid->dual_lcd_enabled = 0;
 +
 +              /* S6D16A0X LCD Panel */
 +              vid->vl_hspw    = 16;
 +              vid->vl_hbpd    = 24;
 +              vid->vl_hfpd    = 16;
 +
 +              vid->vl_vspw    = 2;
 +              vid->vl_vbpd    = 2;
 +              vid->vl_vfpd    = 4;
 +
 +              vid->cfg_gpio = lcd_cfg_gpio;
 +              vid->backlight_on = backlight_on;
 +              vid->lcd_power_on = lcd_power_on;
 +              vid->reset_lcd = reset_lcd;
 +              vid->cfg_ldo = s6d16a0x_cfg_ldo;
 +              vid->enable_ldo = s6d16a0x_enable_ldo;
 +
 +              vid->init_delay = 10000;
 +              vid->power_on_delay = 10000;
 +              vid->reset_delay = 1000;
 +
 +      }
 +      if (board_is_sdk() && hwrevision(3)) {
 +              vid->vl_freq    = 60;
 +              vid->vl_col     = 480;
 +              vid->vl_row     = 800;
 +              vid->vl_width   = 480;
 +              vid->vl_height  = 800;
 +              vid->vl_clkp    = CONFIG_SYS_HIGH;
 +              vid->vl_hsp     = CONFIG_SYS_HIGH;
 +              vid->vl_vsp     = CONFIG_SYS_HIGH;
 +              vid->vl_dp      = CONFIG_SYS_HIGH;
 +
 +              vid->vl_bpix    = 32;
 +              /* disable dual lcd mode. */
 +              vid->dual_lcd_enabled = 0;
 +
 +              /* LD9040 LCD Panel */
 +              vid->vl_hspw    = 2;
 +              vid->vl_hbpd    = 16;
 +              vid->vl_hfpd    = 16;
 +
 +              vid->vl_vspw    = 2;
 +              vid->vl_vbpd    = 3;
 +              vid->vl_vfpd    = 28;
 +
 +              vid->cfg_gpio = lcd_cfg_gpio;
 +              vid->backlight_on = NULL;
 +              vid->lcd_power_on = lcd_power_on;
 +              vid->reset_lcd = reset_lcd;
 +              vid->cfg_ldo = ld9040_cfg_ldo;
 +              vid->enable_ldo = ld9040_enable_ldo;
 +
 +              vid->init_delay = 0;
 +              vid->power_on_delay = 30000;
 +              vid->reset_delay = 20000;
 +      }
 +      if (mach_is_geminus()) {
 +              vid->vl_freq    = 60;
 +              vid->vl_col     = 1024,
 +              vid->vl_row     = 600,
 +              vid->vl_width   = 1024,
 +              vid->vl_height  = 600,
 +              vid->vl_clkp    = CONFIG_SYS_LOW,
 +              vid->vl_hsp     = CONFIG_SYS_HIGH,
 +              vid->vl_vsp     = CONFIG_SYS_HIGH,
 +              vid->vl_dp      = CONFIG_SYS_LOW,
 +              vid->vl_bpix    = 32,
 +
 +              vid->vl_hspw    = 32,
 +              vid->vl_hfpd    = 48,
 +              vid->vl_hbpd    = 80,
 +
 +              vid->vl_vspw    = 1,
 +              vid->vl_vfpd    = 3,
 +              vid->vl_vbpd    = 4,
 +
 +              vid->cfg_gpio = lcd_cfg_gpio;
 +              vid->reset_lcd = reset_lcd;
 +              vid->backlight_on = backlight_on;
 +              vid->lcd_power_on = lcd_power_on;
 +      }
 +#if 0
 +      vid->vl_freq    = 60;
 +      vid->vl_col     = 480,
 +      vid->vl_row     = 800,
 +      vid->vl_width   = 480,
 +      vid->vl_height  = 800,
 +      vid->vl_clkp    = CONFIG_SYS_HIGH,
 +      vid->vl_hsp     = CONFIG_SYS_LOW,
 +      vid->vl_vsp     = CONFIG_SYS_LOW,
 +      vid->vl_dp      = CONFIG_SYS_HIGH,
 +      vid->vl_bpix    = 32,
 +
 +      /* tl2796 panel. */
 +      vid->vl_hpw     = 4,
 +      vid->vl_blw     = 8,
 +      vid->vl_elw     = 8,
 +
 +      vid->vl_vpw     = 4,
 +      vid->vl_bfw     = 8,
 +      vid->vl_efw     = 8,
 +#endif
 +#if 0
 +      vid->vl_freq    = 60;
 +      vid->vl_col     = 1024,
 +      vid->vl_row     = 600,
 +      vid->vl_width   = 1024,
 +      vid->vl_height  = 600,
 +      vid->vl_clkp    = CONFIG_SYS_HIGH,
 +      vid->vl_hsp     = CONFIG_SYS_HIGH,
 +      vid->vl_vsp     = CONFIG_SYS_HIGH,
 +      vid->vl_dp      = CONFIG_SYS_LOW,
 +      vid->vl_bpix    = 32,
 +
 +      /* AMS701KA AMOLED Panel. */
 +      vid->vl_hpw     = 30,
 +      vid->vl_blw     = 114,
 +      vid->vl_elw     = 48,
 +
 +      vid->vl_vpw     = 2,
 +      vid->vl_bfw     = 6,
 +      vid->vl_efw     = 8,
 +#endif
 +}
 +#endif
 +
 +static void setup_meminfo(void)
 +{
 +      char meminfo[64] = {0, };
 +      int count = 0, size, real;
 +
 +      size = gd->bd->bi_dram[0].size >> 20;
 +      count += sprintf(meminfo + count, "mem=%dM", size);
 +
 +      /* Each Chip Select can't exceed the 256MiB */
 +      size = gd->bd->bi_dram[1].size >> 20;
 +      real = min(size, 256);
 +      count += sprintf(meminfo + count, " mem=%dM@0x%x",
 +              real, (unsigned int)gd->bd->bi_dram[1].start);
 +
 +      size -= real;
 +      if (size > 0) {
 +              count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
 +                      (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
 +      }
 +
 +      setenv("meminfo", meminfo);
 +}
 +
 +int misc_init_r(void)
 +{
 +#ifdef CONFIG_LCD
 +      /* It should be located at first */
 +      lcd_is_enabled = 0;
 +
 +      if (mach_is_aquila() || mach_is_goni()) {
 +              if (board_is_sdk() && hwrevision(0))
 +                      setenv("lcdinfo", "lcd=s6d16a0x");
 +              else if (board_is_sdk() && hwrevision(3))
 +                      setenv("lcdinfo", "lcd=ld9040");
 +              else if (board_is_media())
 +                      setenv("lcdinfo", "lcd=s6e63m0");
 +              else
 +                      setenv("lcdinfo", "lcd=s6e63m0");
 +      }
 +      if (mach_is_geminus())
 +              setenv("lcdinfo", "lcd=lms480jc01");
 +      if (mach_is_cypress())
 +              setenv("lcdinfo", "lcd=s6e63m0");
 +#endif
 +      setup_meminfo();
 +
 +      show_hw_revision();
 +
 +      /* Set proper PMIC pins */
 +      pmic_pin_init();
 +
 +      /* Check auto burning */
 +      check_auto_burn();
 +
 +      /* To power up I2C2 */
 +      enable_ldos();
 +
 +      /* Enable T-Flash at Limo Real or Limo Universal */
 +      enable_t_flash();
 +
 +      /* Setup Limo Real board GPIOs */
 +      setup_limo_real_gpios();
 +
 +      /* Setup Media board GPIOs */
 +      setup_media_gpios();
 +
 +      /* To usbdown automatically */
 +      check_keypad();
 +
 +      /* check max8998 */
 +      init_pmic();
 +
 +#ifdef CONFIG_S5PC1XXFB
 +      display_device_info();
 +#endif
 +
 +      setup_power_down_mode_registers();
 +
 +      /* check max17040 */
 +      check_battery(0);
 +
 +      /* check fsa9480 */
 +      check_micro_usb(0);
 +
 +      return 0;
 +}
 +#endif
 +
 +int board_init(void)
 +{
 +      /* Set Initial global variables */
 +      s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
 +      gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
 +
 +#ifdef CONFIG_LCD
 +      /* 
 +       * set reserved memory region for framebuffer.
 +       *
 +       * this region wouldn't be rewrited by kernel so
 +       * could avoid nosie screen filled by garbages
 +       * after hibernation resume has been completed.
 +       */
 +      gd->fb_base = CONFIG_FB_RESERVED_MEM;
 +#endif
 +
 +      /* Check H/W Revision */
 +      check_hw_revision();
 +
 +      return 0;
 +}
 +
 +int dram_init(void)
 +{
 +      unsigned int base, memconfig0, size;
 +      unsigned int memconfig1, sz = 0;
 +
 +      if (cpu_is_s5pc100()) {
 +              /* In mem setup, we swap the bank. So below size is correct */
 +              gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
 +              gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
 +              gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
 +              size = 128;
 +      } else {
 +              /* In S5PC110, we can't swap the DMC0/1 */
 +              gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
 +              gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
 +
 +              base = S5PC110_DMC1_BASE;
 +              /* DMC configuration */
 +              memconfig0 = readl(base + MEMCONFIG0_OFFSET);
 +              gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
 +
 +              size = (memconfig0 >> 16) & 0xFF;
 +              size = ((unsigned char) ~size) + 1;
 +
 +              /*
 +               * (0x07 + 1) * 16 = 128 MiB
 +               * (0x0f + 1) * 16 = 256 MiB
 +               */
 +              size = size << 4;
 +
 +              /*
 +               * Aquila Rev0.5 4G3G1G
 +               * Aquila Rev0.8 4G3G1G
 +               * Aquila Rev0.9 4G3G1G
 +               * Limo SDK Rev 0.2 4G3G1G
 +               * Limo SDK Rev 0.3 4G3G1G
 +               * Limo SDK Rev 0.4 4G3G1G
 +               */
 +              if (mach_is_aquila() || mach_is_goni()) {
 +                      if ((!board_is_sdk() && (hwrevision(5) ||
 +                              hwrevision(8) || hwrevision(9))) ||
 +                              (board_is_sdk() && !hwrevision(1))) {
 +                              memconfig1 = readl(base + MEMCONFIG1_OFFSET);
 +
 +                              sz = (memconfig1 >> 16) & 0xFF;
 +                              sz = ((unsigned char) ~sz) + 1;
 +                              sz = sz << 4;
 +                      }
 +                      if (mach_is_goni () && board_is_s1())
 +                              sz = 0;
 +              }
 +      }
 +      /*
 +       * bi_dram[1].size contains all DMC1 memory size
 +       */
 +      gd->bd->bi_dram[1].size = (size + sz) << 20;
 +
 +      return 0;
 +}
 +
 +/* Used for sleep test */
 +static unsigned char saved_val[4][2];
 +void board_sleep_init_late(void)
 +{
 +      /* CODEC_LDO_EN: GPF3[4] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
 +      /* CODEC_XTAL_EN: GPH3[2] */
 +      gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
 +
 +      /* MMC T_FLASH off */
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
 +      /* MHL off */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
 +      gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
 +      /* MHL_ON for REV02 or higher */
 +      gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
 +}
 +
 +void board_sleep_init(void)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      addr = 0xCC >> 1;
 +      if (max8998_probe())
 +              return;
 +
 +      if (mach_is_goni()) {
 +              /* Set ONOFF1 */
 +              i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +              saved_val[0][0] = val[0];
 +              saved_val[0][1] = val[1];
 +              val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
 +                              (1 << 1) | (1 << 0));
 +              i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +
 +              /* Set ONOFF2 */
 +              i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +              saved_val[1][0] = val[0];
 +              saved_val[1][1] = val[1];
 +              val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
 +                              (1 << 2) | (1 << 1) | (1 << 0));
 +              val[0] |= (1 << 7);
 +              i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +
 +              /* Set ONOFF3 */
 +              i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +              saved_val[2][0] = val[0];
 +              saved_val[2][1] = val[1];
 +              val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
 +              i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +
 +              /* Set ONOFF4 */
 +              i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +              saved_val[3][0] = val[0];
 +              saved_val[3][1] = val[1];
 +              val[0] &= ~((1 << 6) | (1 << 4));
 +              i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +
 +              printf("Turned off regulators with Kessler setting."
 +                             " Preparing to sleep. [%s:%d]\n",
 +                              __FILE__, __LINE__);
 +      } else { /* Default */
 +              /* Set ONOFF1 */
 +              i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +              saved_val[0][0] = val[0];
 +              saved_val[0][1] = val[1];
 +              val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
 +                              (1 << 1) | (1 << 0));
 +              i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +
 +              /* Set ONOFF2 */
 +              i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +              saved_val[1][0] = val[0];
 +              saved_val[1][1] = val[1];
 +              val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
 +                              (1 << 2) | (1 << 1) | (1 << 0));
 +              val[0] |= (1 << 7);
 +              i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +
 +              /* Set ONOFF3 */
 +              i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +              saved_val[2][0] = val[0];
 +              saved_val[2][1] = val[1];
 +              val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
 +              i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +
 +              /* Set ONOFF4 */
 +              i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +              saved_val[3][0] = val[0];
 +              saved_val[3][1] = val[1];
 +              val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
 +              i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +              i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +
 +              printf("Turned off regulators with default(Aquila) setting."
 +                             " Preparing to sleep. [%s:%d]\n",
 +                              __FILE__, __LINE__);
 +      }
 +}
 +
 +void board_sleep_resume(void)
 +{
 +      unsigned char addr;
 +      unsigned char val[2];
 +
 +      show_hw_revision();
 +
 +      addr = 0xCC >> 1;
 +      if (max8998_probe())
 +              return;
 +
 +      /* Set ONOFF1 */
 +      i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
 +      /* Set ONOFF2 */
 +      i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
 +      /* Set ONOFF3 */
 +      i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
 +      /* Set ONOFF4 */
 +      i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
 +      i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
 +      puts("Waked up.\n");
 +
 +      /* check max17040 */
 +      check_battery(0);
 +
 +      /* check fsa9480 */
 +      check_micro_usb(0);
 +}
 +
 +#if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
 +
 +static int s5pc1xx_phy_control(int on)
 +{
 +      static int status;
 +
 +      if (on && !status) {
 +#ifdef CONFIG_CMD_PMIC
 +              run_command("pmic ldo 3 on", 0);
 +#endif
 +              /* S5PC110 */
 +              if (board_is_limo_universal() ||
 +                      board_is_limo_real() ||
 +                      board_is_media()) {
 +                      /* check usb path */
 +                      if (board_is_limo_real() && !hwrevision(6))
 +                              check_mhl();
 +              }
 +
 +              if (mach_is_tickertape())
 +                      /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
 +                      gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
 +
 +              /* USB Path to AP */
 +              micro_usb_switch(0);
 +              status = 1;
 +      } else if (!on && status) {
 +#ifdef CONFIG_CMD_PMIC
 +              run_command("pmic ldo 3 off", 0);
 +#endif
 +              status = 0;
 +      }
 +      udelay(10000);
 +
 +      return 0;
 +}
 +
 +struct s3c_plat_otg_data s5pc110_otg_data = {
 +      .phy_control = s5pc1xx_phy_control,
 +      .regs_phy = S5PC110_PHY_BASE,
 +      .regs_otg = S5PC110_OTG_BASE,
 +};
 +
 +int board_eth_init(bd_t *bis)
 +{
 +      int res = -1;
 +
 +      if (cpu_is_s5pc100())
 +              return -1;
 +
 +      s3c_udc_probe(&s5pc110_otg_data);
 +      if (usb_eth_initialize(bis) >= 0)
 +              res = 0;
 +      return res;
 +}
 +#endif
 +
 +#ifdef CONFIG_CMD_USBDOWN
 +int usb_board_init(void)
 +{
 +#ifdef CONFIG_CMD_PMIC
 +      run_command("pmic ldo 3 on", 0);
 +#endif
 +
 +      if (cpu_is_s5pc100()) {
 +#ifdef CONFIG_HARD_I2C
 +              uchar val[2] = {0,};
 +
 +              /* PMIC */
 +              if (i2c_read(0x66, 0, 1, val, 2)) {
 +                      puts("i2c_read error\n");
 +                      return 1;
 +              }
 +
 +              val[0] |= (1 << 3);
 +              val[1] |= (1 << 5);
 +
 +              if (i2c_write(0x66, 0, 1, val, 2)) {
 +                      puts("i2c_write error\n");
 +                      return 1;
 +              }
 +              i2c_read(0x66, 0, 1, val, 2);
 +#endif
 +              return 0;
 +      }
 +
 +      /* S5PC110 */
 +      if (board_is_limo_universal() ||
 +              board_is_limo_real() ||
 +              board_is_media()) {
 +              /* check usb path */
 +              if (board_is_limo_real() && !hwrevision(6))
 +                      check_mhl();
 +      }
 +
 +      if (mach_is_tickertape())
 +              /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
 +              gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
 +
 +      /* USB Path to AP */
 +      micro_usb_switch(0);
 +
 +      return 0;
 +}
 +#endif
 +
 +#ifdef CONFIG_GENERIC_MMC
 +int s5p_no_mmc_support(void)
 +{
 +      if (mach_is_wmg160())
 +              return 1;
 +      return 0;
 +}
 +
 +int board_mmc_init(bd_t *bis)
 +{
 +      unsigned int reg;
 +      unsigned int clock;
 +      struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
 +      int i;
 +
 +      /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
 +      if (mach_is_goni())
 +              gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
 +
 +      if (mach_is_wmg160())
 +              return -1;
 +
 +      /* MMC0 Clock source = SCLKMPLL */
 +      reg = readl(&clk->src4);
 +      reg &= ~0xf;
 +      reg |= 0x6;
 +      writel(reg, &clk->src4);
 +
 +      reg = readl(&clk->div4);
 +      reg &= ~0xf;
 +
 +      /* set div value near 50MHz */
 +      clock = get_pll_clk(MPLL) / 1000000;
 +      for (i = 0; i < 0xf; i++) {
 +              if ((clock / (i + 1)) <= 50) {
 +                      reg |= i << 0;
 +                      break;
 +              }
 +      }
 +
 +      writel(reg, &clk->div4);
 +
 +      /*
 +       * MMC0 GPIO
 +       * GPG0[0]      SD_0_CLK
 +       * GPG0[1]      SD_0_CMD
 +       * GPG0[2]      SD_0_CDn        -> Not used
 +       * GPG0[3:6]    SD_0_DATA[0:3]
 +       */
 +      for (i = 0; i < 7; i++) {
 +              if (i == 2)
 +                      continue;
 +              /* GPG0[0:6] special function 2 */
 +              gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
 +              /* GPG0[0:6] pull disable */
 +              gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
 +              /* GPG0[0:6] drv 4x */
 +              gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
 +      }
 +
 +      if (mach_is_geminus()) {
 +              gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
 +              gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
 +      }
 +
 +      return s5pc1xx_mmc_init(0);
 +}
 +#endif
 +
 +#ifdef CONFIG_CMD_PMIC
 +static int pmic_status(void)
 +{
 +      unsigned char addr, val[2];
 +      int reg, i;
 +
 +      addr = 0xCC >> 1;
 +
 +      if (max8998_probe())
 +              return -1;
 +
 +      reg = 0x11;
 +      i2c_read(addr, reg, 1, val, 1);
 +      for (i = 7; i >= 4; i--)
 +              printf("BUCK%d %s\n", 7 - i + 1,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      for (; i >= 0; i--)
 +              printf("LDO%d %s\n", 5 - i,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      reg = 0x12;
 +      i2c_read(addr, reg, 1, val, 1);
 +      for (i = 7; i >= 0; i--)
 +              printf("LDO%d %s\n", 7 - i + 6,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      reg = 0x13;
 +      i2c_read(addr, reg, 1, val, 1);
 +      for (i = 7; i >= 4; i--)
 +              printf("LDO%d %s\n", 7 - i + 14,
 +                      val[0] & (1 << i) ? "on" : "off");
 +
 +      reg = 0xd;
 +      i2c_read(addr, reg, 1, val, 1);
 +      for (i = 7; i >= 6; i--)
 +              printf("SAFEOUT%d %s\n", 7 - i + 1,
 +                      val[0] & (1 << i) ? "on" : "off");
 +      return 0;
 +}
 +
 +static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
 +{
 +      unsigned char addr, val[2];
 +      unsigned int reg, shift;
 +
 +      if (ldo) {
 +              if (ldo < 2)
 +                      return -1;
 +              if (ldo <= 5) {
 +                      reg = 0x11;
 +                      shift = 5 - ldo;
 +              } else if (ldo <= 13) {
 +                      reg = 0x12;
 +                      shift = 13 - ldo;
 +              } else if (ldo <= 17) {
 +                      reg = 0x13;
 +                      shift = 17 - ldo + 4;
 +              } else
 +                      return -1;
 +      } else if (buck) {
 +              if (buck > 4)
 +                      return -1;
 +              reg = 0x11;
 +              shift = 4 - buck + 4;
 +      } else if (safeout) {
 +              if (safeout > 3)
 +                      return -1;
 +              reg = 0xd;
 +              shift = 8 - safeout;
 +      } else
 +              return -1;
 +
 +      addr = 0xCC >> 1;
 +
 +      if (max8998_probe())
 +              return -1;
 +
 +      i2c_read(addr, reg, 1, val, 1);
 +      if (on)
 +              val[0] |= (1 << shift);
 +      else
 +              val[0] &= ~(1 << shift);
 +      i2c_write(addr, reg, 1, val, 1);
 +      i2c_read(addr, reg, 1, val, 1);
 +
 +      if (ldo)
 +              printf("ldo %d value 0x%x, %s\n", ldo, val[0],
 +                      val[0] & (1 << shift) ? "on" : "off");
 +      else if (buck)
 +              printf("buck %d value 0x%x, %s\n", buck, val[0],
 +                      val[0] & (1 << shift) ? "on" : "off");
 +      else if (safeout)
 +              printf("safeout %d value 0x%x, %s\n", safeout, val[0],
 +                      val[0] & (1 << shift) ? "on" : "off");
 +
 +      return 0;
 +}
 +
 +static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 +{
 +      int buck = 0, ldo = 0, safeout = 0, on = -1;
 +
 +      switch (argc) {
 +      case 2:
 +              if (strncmp(argv[1], "status", 6) == 0)
 +                      return pmic_status();
 +              break;
 +      case 4:
 +              if (strncmp(argv[1], "ldo", 3) == 0)
 +                      ldo = simple_strtoul(argv[2], NULL, 10);
 +              else if (strncmp(argv[1], "buck", 4) == 0)
 +                      buck = simple_strtoul(argv[2], NULL, 10);
 +              else if (strncmp(argv[1], "safeout", 7) == 0)
 +                      safeout = simple_strtoul(argv[2], NULL, 10);
 +              else
 +                      break;
 +
 +              if (strncmp(argv[3], "on", 2) == 0)
 +                      on = 1;
 +              else if (strncmp(argv[3], "off", 3) == 0)
 +                      on = 0;
 +              else
 +                      break;
 +
 +              return pmic_ldo_control(buck, ldo, safeout, on);
 +
 +      default:
 +              break;
 +      }
 +
 +      cmd_usage(cmdtp);
 +      return 1;
 +}
 +
 +U_BOOT_CMD(
 +      pmic,           CONFIG_SYS_MAXARGS,     1, do_pmic,
 +      "PMIC LDO & BUCK control",
 +      "status - Display PMIC LDO & BUCK status\n"
 +      "pmic ldo num on/off - Turn on/off the LDO\n"
 +      "pmic buck num on/off - Turn on/off the BUCK\n"
 +      "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
 +);
 +#endif
 +
 +#ifdef CONFIG_CMD_DEVICE_POWER
 +static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 +{
 +      switch (argc) {
 +      case 2:
 +              if (strncmp(argv[1], "cp", 2) == 0) {
 +                      micro_usb_switch(1);
 +                      pmic_ldo_control(0, 0, 2, 1);
 +                      setenv("usb", "cp");
 +              } else if (strncmp(argv[1], "ap", 2) == 0) {
 +                      micro_usb_switch(0);
 +                      pmic_ldo_control(0, 0, 2, 0);
 +                      setenv("usb", "ap");
 +              }
 +              break;
 +      default:
 +              cmd_usage(cmdtp);
 +              return 1;
 +      }
 +
 +      saveenv();
 +
 +      printf("USB Path is set to %s\n", getenv("usb"));
 +
 +      return 0;
 +}
 +
 +U_BOOT_CMD(
 +      microusb,               CONFIG_SYS_MAXARGS,     1, do_microusb,
 +      "Micro USB Switch",
 +      "cp - switch to CP\n"
 +      "microusb ap - switch to AP\n"
 +);
 +#endif
@@@ -1553,9 -1534,9 +1548,9 @@@ int mtdparts_init(void
        const char *ids, *parts;
        const char *current_partition;
        int ids_changed;
 -      char tmp_ep[PARTITION_MAXLEN];
 +      char tmp_ep[PARTITION_MAXLEN+1];
  
-       DEBUGF("\n---mtdparts_init---\n");
+       debug("\n---mtdparts_init---\n");
        if (!initialized) {
                INIT_LIST_HEAD(&mtdids);
                INIT_LIST_HEAD(&devices);
@@@ -364,170 -330,231 +344,262 @@@ static int onenand_dump(struct mtd_inf
        return 0;
  }
  
- int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ static int do_onenand_info(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       printf("%s\n", mtd->name);
+       return 0;
+ }
+ static int do_onenand_bad(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       ulong ofs;
+       mtd = &onenand_mtd;
+       /* Currently only one OneNAND device is supported */
+       printf("\nDevice %d bad blocks:\n", 0);
+       for (ofs = 0; ofs < mtd->size; ofs += mtd->erasesize) {
+               if (mtd->block_isbad(mtd, ofs))
+                       printf("  %08x\n", (u32)ofs);
+       }
+       return 0;
+ }
+ static int do_onenand_read(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  {
-       struct onenand_chip *this;
-       int blocksize;
+       char *s;
+       int oob = 0;
        ulong addr, ofs;
-       ssize_t len, retlen = 0;
 -      size_t len;
++      ssize_t len;
        int ret = 0;
-       char *cmd, *s;
 -      size_t retlen = 0;
++      ssize_t retlen = 0;
  
-       mtd = &onenand_mtd;
-       this = mtd->priv;
-       blocksize = (1 << this->erase_shift);
+       if (argc < 3)
+       {
+               cmd_usage(cmdtp);
+               return 1;
+       }
  
-       cmd = argv[1];
+       s = strchr(argv[0], '.');
+       if ((s != NULL) && (!strcmp(s, ".oob")))
+               oob = 1;
  
-       switch (argc) {
-       case 0:
-       case 1:
-               goto usage;
+       addr = (ulong)simple_strtoul(argv[1], NULL, 16);
  
-       case 2:
-               if (strcmp(cmd, "info") == 0) {
-                       printf("%s\n", mtd->name);
-                       return 0;
-               }
+       printf("\nOneNAND read: ");
+       if (arg_off_size(argc - 2, argv + 2, &ofs, &len) != 0)
+               return 1;
  
-               if (strcmp(cmd, "bad") == 0) {
-                       /* Currently only one OneNAND device is supported */
-                       printf("\nDevice %d bad blocks:\n", 0);
-                       for (ofs = 0; ofs < mtd->size; ofs += mtd->erasesize) {
-                               if (mtd->block_isbad(mtd, ofs))
-                                       printf("  %08x\n", (u32)ofs);
-                       }
+       ret = onenand_block_read(ofs, len, &retlen, (u8 *)addr, oob);
  
-                       return 0;
-               }
+       printf(" %d bytes read: %s\n", retlen, ret ? "ERROR" : "OK");
  
-       default:
-               /* At least 4 args */
+       return ret == 0 ? 0 : 1;
+ }
  
-               /*
-                * Syntax is:
-                *   0       1     2       3    4
-                *   onenand erase [force] [off size]
-                */
-               if ((strcmp(cmd, "erase") == 0) || (strcmp(cmd, "test") == 0)) {
-                       int force = argc > 2 && !strcmp("force", argv[2]);
-                       int o = force ? 3 : 2;
-                       int erase;
+ static int do_onenand_write(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       ulong addr, ofs;
 -      size_t len;
++      ssize_t len;
+       int ret = 0;
 -      size_t retlen = 0;
++      ssize_t retlen = 0;
  
-                       erase = strcmp(cmd, "erase") == 0; /* 1 = erase, 0 = test */
-                       printf("\nOneNAND %s %s: ", erase ? "erase" : "test",
-                               force ? "force" : "");
+       if (argc < 3)
+       {
+               cmd_usage(cmdtp);
+               return 1;
+       }
  
-                       /* skip first two or three arguments, look for offset and size */
-                       if (arg_off_size(argc - o, argv + o, &ofs, &len) != 0)
-                               return 1;
+       addr = (ulong)simple_strtoul(argv[1], NULL, 16);
  
-                       if (erase)
-                               ret = onenand_block_erase(ofs, len, force);
-                       else
-                               ret = onenand_block_test(ofs, len);
+       printf("\nOneNAND write: ");
+       if (arg_off_size(argc - 2, argv + 2, &ofs, &len) != 0)
+               return 1;
  
-                       printf("%s\n", ret ? "ERROR" : "OK");
+       ret = onenand_block_write(ofs, len, &retlen, (u8 *)addr);
+       printf(" %d bytes written: %s\n", retlen, ret ? "ERROR" : "OK");
+       return ret == 0 ? 0 : 1;
+ }
  
-                       return ret == 0 ? 0 : 1;
+ static int do_onenand_erase(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       ulong ofs;
+       int ret = 0;
 -      size_t len;
++      ssize_t len;
+       int force;
+       /*
+        * Syntax is:
+        *   0       1     2       3    4
+        *   onenand erase [force] [off size]
+        */
+       argc--;
+       argv++;
+       if (argc)
+       {
+               if (!strcmp("force", argv[0]))
+               {
+                       force = 1;
+                       argc--;
+                       argv++;
                }
+       }
+       printf("\nOneNAND erase: ");
  
-               if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
-                       int read;
-                       int oob = 0;
+       /* skip first two or three arguments, look for offset and size */
+       if (arg_off_size(argc, argv, &ofs, &len) != 0)
+               return 1;
  
-                       if (argc < 4)
-                               goto usage;
+       ret = onenand_block_erase(ofs, len, force);
  
-                       addr = (ulong)simple_strtoul(argv[2], NULL, 16);
+       printf("%s\n", ret ? "ERROR" : "OK");
  
-                       read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
-                       printf("\nOneNAND %s: ", read ? "read" : "write");
-                       if (arg_off_size(argc - 3, argv + 3, &ofs, &len) != 0)
-                               return 1;
+       return ret == 0 ? 0 : 1;
+ }
  
-                       s = strchr(cmd, '.');
-                       if ((s != NULL) && (!strcmp(s, ".oob")))
-                               oob = 1;
+ static int do_onenand_test(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       ulong ofs;
+       int ret = 0;
 -      size_t len;
++      ssize_t len;
  
-                       if (read) {
-                               ret = onenand_block_read(ofs, len, &retlen,
-                                                        (u8 *)addr, oob);
-                       } else {
-                               ret = onenand_block_write(ofs, len, &retlen,
-                                                         (u8 *)addr);
-                       }
+       /*
+        * Syntax is:
+        *   0       1     2       3    4
+        *   onenand test [force] [off size]
+        */
  
-                       printf(" %d bytes %s: %s\n", retlen,
-                              read ? "read" : "written", ret ? "ERROR" : "OK");
+       printf("\nOneNAND test: ");
  
-                       return ret == 0 ? 0 : 1;
-               }
+       /* skip first two or three arguments, look for offset and size */
+       if (arg_off_size(argc - 1, argv + 1, &ofs, &len) != 0)
+               return 1;
  
-               if (strcmp(cmd, "markbad") == 0) {
-                       argc -= 2;
-                       argv += 2;
-                       if (argc <= 0)
-                               goto usage;
-                       while (argc > 0) {
-                               addr = simple_strtoul(*argv, NULL, 16);
-                               if (mtd->block_markbad(mtd, addr)) {
-                                       printf("block 0x%08lx NOT marked "
-                                               "as bad! ERROR %d\n",
-                                               addr, ret);
-                                       ret = 1;
-                               } else {
-                                       printf("block 0x%08lx successfully "
-                                               "marked as bad\n",
-                                               addr);
-                               }
-                               --argc;
-                               ++argv;
-                       }
-                       return ret;
-               }
+       ret = onenand_block_test(ofs, len);
  
-               if (strncmp(cmd, "dump", 4) == 0) {
-                       if (argc < 3)
-                               goto usage;
+       printf("%s\n", ret ? "ERROR" : "OK");
  
-                       s = strchr(cmd, '.');
-                       ofs = (int)simple_strtoul(argv[2], NULL, 16);
+       return ret == 0 ? 0 : 1;
+ }
+ static int do_onenand_dump(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       ulong ofs;
+       int ret = 0;
+       char *s;
  
-                       if (s != NULL && strcmp(s, ".oob") == 0)
-                               ret = onenand_dump(mtd, ofs, 1);
-                       else
-                               ret = onenand_dump(mtd, ofs, 0);
+       if (argc < 2)
+       {
+               cmd_usage(cmdtp);
+               return 1;
+       }
  
-                       return ret == 0 ? 1 : 0;
-               }
+       s = strchr(argv[0], '.');
+       ofs = (int)simple_strtoul(argv[1], NULL, 16);
  
-               if (strncmp(cmd, "lock", 4) == 0) {
-                       printf("OneNAND lock: ");
-                       if (argc < 4) {
-                               ofs = 0x0;
-                               len = mtd->size;
-                       } else {
-                               if (arg_off_size(argc-2, argv+2, &ofs, &len))
-                                       return 1;
-                       }
+       if (s != NULL && strcmp(s, ".oob") == 0)
+               ret = onenand_dump(mtd, ofs, 1);
+       else
+               ret = onenand_dump(mtd, ofs, 0);
  
-                       ret = onenand_block_islock(ofs, len);
+       return ret == 0 ? 1 : 0;
+ }
  
-                       return ret;
+ static int do_onenand_markbad(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       int ret = 0;
+       ulong addr;
+       argc -= 2;
+       argv += 2;
+       if (argc <= 0)
+       {
+               cmd_usage(cmdtp);
+               return 1;
+       }
+       while (argc > 0) {
+               addr = simple_strtoul(*argv, NULL, 16);
+               if (mtd->block_markbad(mtd, addr)) {
+                       printf("block 0x%08lx NOT marked "
+                               "as bad! ERROR %d\n",
+                               addr, ret);
+                       ret = 1;
+               } else {
+                       printf("block 0x%08lx successfully "
+                               "marked as bad\n",
+                               addr);
                }
+               --argc;
+               ++argv;
+       }
+       return ret;
+ }
  
-               break;
++static int do_onenand_lock(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
++{
++      ulong start;
++      ssize_t size;
++      struct onenand_chip *this = mtd->priv;
++      loff_t ofs;
++      int status;
++      int status_mask = ONENAND_WP_LS|ONENAND_WP_LTS;
++
++      if (argc < 4) {
++              start = 0x0;
++              size = mtd->size;
++      } else {
++              if (arg_off_size(argc - 2, argv + 2, &start, &size))
++                      return 1;
++      }
++
++      for (ofs = start; ofs < (start + size); ofs += mtd->erasesize) {
++              if (this->block_islock != NULL)
++                      status = this->block_islock(mtd, ofs);
++              else
++                      status = 0;
++
++              if (status & status_mask)
++                      return (status & status_mask);
 +      }
 +
 +      return 0;
++}
 +
- usage:
-       cmd_usage(cmdtp);
-       return 1;
+ static cmd_tbl_t cmd_onenand_sub[] = {
+       U_BOOT_CMD_MKENT(info, 1, 0, do_onenand_info, "", ""),
+       U_BOOT_CMD_MKENT(bad, 1, 0, do_onenand_bad, "", ""),
+       U_BOOT_CMD_MKENT(read, 4, 0, do_onenand_read, "", ""),
+       U_BOOT_CMD_MKENT(write, 4, 0, do_onenand_write, "", ""),
+       U_BOOT_CMD_MKENT(erase, 3, 0, do_onenand_erase, "", ""),
+       U_BOOT_CMD_MKENT(test, 3, 0, do_onenand_test, "", ""),
+       U_BOOT_CMD_MKENT(dump, 2, 0, do_onenand_dump, "", ""),
+       U_BOOT_CMD_MKENT(markbad, CONFIG_SYS_MAXARGS, 0, do_onenand_markbad, "", ""),
++      U_BOOT_CMD_MKENT(lock, 3, 0, do_onenand_lock, "", ""),
+ };
 -static int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
++int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+ {
+       cmd_tbl_t *c;
+       mtd = &onenand_mtd;
+       /* Strip off leading 'onenand' command argument */
+       argc--;
+       argv++;
+       c = find_cmd_tbl(argv[0], &cmd_onenand_sub[0], ARRAY_SIZE(cmd_onenand_sub));
+       if (c) {
+               return  c->cmd(cmdtp, flag, argc, argv);
+       } else {
+               cmd_usage(cmdtp);
+               return 1;
+       }
  }
  
  U_BOOT_CMD(
Simple merge
index 76565e3,0000000..d2dff0c
mode 100644,000000..100644
--- /dev/null
@@@ -1,1087 -1,0 +1,1089 @@@
 +/*
 + * USB Downloader for SAMSUNG Platform
 + *
 + * Copyright (C) 2007-2008 Samsung Electronics
 + * Minkyu Kang <mk7.kang@samsung.com>
 + *
 + */
 +
 +#include <common.h>
 +#include <usbd.h>
 +#include <asm/errno.h>
 +#include <malloc.h>
 +
 +/* version of USB Downloader Application */
 +#define APP_VERSION   "1.5.3"
 +
 +#define OPS_READ      0
 +#define OPS_WRITE     1
 +
 +#ifdef CONFIG_CMD_MTDPARTS
 +#include <jffs2/load_kernel.h>
 +static struct part_info *parts[16];
 +#endif
 +
 +static const char pszMe[] = "usbd: ";
 +
 +static struct usbd_ops usbd_ops;
 +
 +static unsigned int part_id;
 +static unsigned int write_part = 0;
 +static unsigned long fs_offset = 0x0;
 +
 +#ifdef CONFIG_USE_YAFFS
 +static unsigned int yaffs_len = 0;
 +static unsigned char yaffs_data[2112];
 +#define YAFFS_PAGE 2112
 +#endif
 +
 +#define NAND_PAGE_SIZE 2048
 +
 +static unsigned long down_ram_addr;
 +
 +static int down_mode;
 +
 +/* cpu/${CPU} dependent */
 +extern void do_reset(void);
 +
 +/* common commands */
 +extern int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 +extern int do_run(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
 +
 +int mtdparts_init(void);
 +int find_dev_and_part(const char*, struct mtd_device**, u8*, struct part_info**);
 +
 +/* common/cmd_jffs2.c */
 +extern struct list_head devices;
 +
 +static u8 count_mtdparts(void)
 +{
 +      struct list_head *dentry, *pentry;
 +      struct mtd_device *dev;
 +      u8 part_num = 0;
 +
 +      list_for_each(dentry, &devices) {
 +              dev = list_entry(dentry, struct mtd_device, link);
 +
 +              /* list partitions for given device */
 +              list_for_each(pentry, &dev->parts)
 +                      part_num++;
 +      }
 +
 +      return part_num;
 +}
 +
 +#ifdef CONFIG_CMD_UBI
 +static int check_ubi_mode(void)
 +{
 +      char *env_ubifs;
 +      int ubi_mode;
 +
 +      env_ubifs = getenv("ubi");
 +      ubi_mode = !strcmp(env_ubifs, "enabled");
 +
 +      return ubi_mode;
 +}
 +#else
 +#define check_ubi_mode()              0
 +#endif
 +
 +#ifdef CONFIG_MTD_PARTITIONS
 +static int get_part_info(void)
 +{
 +      struct mtd_device *dev;
 +      u8 out_partnum;
 +      char part_name[12];
 +      char nand_name[12];
 +      int i;
 +      int part_num;
 +      int ubi_mode = 0;
 +
 +#if defined(CONFIG_CMD_NAND)
 +      sprintf(nand_name, "nand0");
 +#elif defined(CONFIG_CMD_ONENAND)
 +      sprintf(nand_name, "onenand0");
 +#else
 +      printf("Configure your NAND sub-system\n");
 +      return 0;
 +#endif
 +
 +      if (mtdparts_init())
 +              return 0;
 +
 +      ubi_mode = check_ubi_mode();
 +
 +      part_num = count_mtdparts();
 +      for (i = 0; i < part_num; i++) {
 +              sprintf(part_name, "%s,%d", nand_name, i);
 +
 +              if (find_dev_and_part(part_name, &dev, &out_partnum, &parts[i]))
 +                      return -EINVAL;
 +      }
 +
 +      return 0;
 +}
 +
 +static int get_part_id(char *name)
 +{
 +      int nparts = count_mtdparts();
 +      int i;
 +
 +      for (i = 0; i < nparts; i++) {
 +              if (strcmp(parts[i]->name, name) == 0)
 +                      return i;
 +      }
 +
 +      printf("Error: Unknown partition -> %s\n", name);
 +      return -1;
 +}
 +#else
 +static int get_part_info(void)
 +{
 +      printf("Error: Can't get patition information\n");
 +      return -EINVAL;
 +}
 +
 +static int get_part_id(char *name)
 +{
 +      return 0;
 +}
 +#endif
 +
 +static void boot_cmd(char *addr)
 +{
 +      char *argv[] = { "bootm", addr };
 +      do_bootm(NULL, 0, 2, argv);
 +}
 +
 +static void run_cmd(char *cmd)
 +{
 +      char *argv[] = { "run", cmd };
 +      do_run(NULL, 0, 2, argv);
 +}
 +
 +#if defined(CONFIG_CMD_NAND)
 +extern int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 +#elif defined(CONFIG_CMD_ONENAND)
 +extern int do_onenand(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 +#endif
 +
 +/* NAND erase and write using nand command */
 +static int nand_cmd(int type, char *p1, char *p2, char *p3)
 +{
 +      int ret = 1;
 +      char nand_name[12];
 +      int (*nand_func) (cmd_tbl_t *, int, int, char **);
 +
 +#if defined(CONFIG_CMD_NAND)
 +      sprintf(nand_name, "nand");
 +      nand_func = do_nand;
 +#elif defined(CONFIG_CMD_ONENAND)
 +      sprintf(nand_name, "onenand");
 +      nand_func = do_onenand;
 +#else
 +      printf("Configure your NAND sub-system\n");
 +      return 0;
 +#endif
 +
 +      if (type == 0) {
 +              char *argv[] = {nand_name, "erase", p1, p2};
 +              printf("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
 +              ret = nand_func(NULL, 0, 4, argv);
 +      } else if (type == 1) {
 +              char *argv[] = {nand_name, "write", p1, p2, p3};
 +              printf("%s %s %s %s %s\n", argv[0], argv[1], argv[2],
 +                              argv[3], argv[4]);
 +              ret = nand_func(NULL, 0, 5, argv);
 +      } else if (type == 2) {
 +              char *argv[] = {nand_name, "write.yaffs", p1, p2, p3};
 +              printf("%s %s %s %s %s\n", argv[0], argv[1], argv[2],
 +                              argv[3], argv[4]);
 +              ret = nand_func(NULL, 0, 5, argv);
 +      } else if (type == 3) {
 +              char *argv[] = {nand_name, "lock", p1, p2};
 +              printf("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
 +              ret = nand_func(NULL, 0, 4, argv);
 +      }
 +
 +      if (ret)
 +              printf("Error: NAND Command\n");
 +
 +      return ret;
 +}
 +
 +#ifdef CONFIG_CMD_UBI
 +int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 +
 +int ubi_cmd(int part, char *p1, char *p2, char *p3)
 +{
 +      int ret = 1;
 +
 +      if (part == RAMDISK_PART_ID) {
 +              char *argv[] = {"ubi", "write", p1, "rootfs.cramfs", p2, p3};
 +              printf("%s %s %s %s %s %s\n", argv[0], argv[1], argv[2],
 +                              argv[3], argv[4], argv[5]);
 +              ret = do_ubi(NULL, 0, 6, argv);
 +      } else if (part == FILESYSTEM_PART_ID) {
 +              char *argv[] = {"ubi", "write", p1, "factoryfs.cramfs", p2, p3};
 +              printf("%s %s %s %s %s %s\n", argv[0], argv[1], argv[2],
 +                              argv[3], argv[4], argv[5]);
 +              ret = do_ubi(NULL, 0, 6, argv);
 +      } else if (part == FILESYSTEM2_PART_ID) {
 +              char *argv[] = {"ubi", "write", p1, "datafs.ubifs", p2, p3};
 +              printf("%s %s %s %s %s %s\n", argv[0], argv[1], argv[2],
 +                              argv[3], argv[4], argv[5]);
 +              ret = do_ubi(NULL, 0, 6, argv);
 +      }
 +
 +      return ret;
 +}
 +#endif
 +
 +#ifdef CONFIG_CMD_MMC
 +#include <fat.h>
 +
 +extern int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 +
 +static int mmc_cmd(int ops, char *p1, char *p2, char *p3)
 +{
 +      int ret;
 +
 +      if (ops) {
 +              char *argv[] = {"mmc", "write", "0", p1, p2, p3};
 +              ret = do_mmcops(NULL, 0, 6, argv);
 +      } else {
 +              char *argv[] = {"mmc", "read", "0", p1, p2, p3};
 +              ret = do_mmcops(NULL, 0, 6, argv);
 +      }
 +
 +      return ret;
 +}
 +
 +static unsigned int cur_blk_offset;
 +static unsigned int cur_part_size;
 +static unsigned int cur_partition;
 +
 +static unsigned int mmc_parts;
 +static unsigned int mmc_part_write;
 +
 +struct partition_info {
 +      u32 size;
 +      u32 checksum;
 +      u32 res;
 +} __attribute__((packed));
 +
 +struct partition_header {
 +      u8                      fat32head[16];  /* RFSHEAD identifier */
 +      struct partition_info   partition[4];
 +      u8                      res[448];       /* reserved */
 +} __attribute__((packed));
 +
 +struct partition_table {
 +      u8      boot_flag;
 +      u8      chs_begin[3];
 +      u8      type_code;
 +      u8      chs_end[3];
 +      u32     lba_begin;
 +      u32     num_sectors;
 +} __attribute__((packed));
 +
 +struct mbr_table {
 +      u8                      boot_code[446];
 +      struct partition_table  partition[4];
 +      u16                     signature;
 +} __attribute__((packed));
 +
 +#define MBR_OFFSET    0x10
 +
 +struct partition_header part_info;
 +struct mbr_table mbr_info;
 +
 +static int write_mmc_partition(struct usbd_ops *usbd, u32 *ram_addr, u32 len)
 +{
 +      unsigned int blocks;
 +      char offset[12], length[12], ramaddr[12];
 +      int i;
 +      int loop;
 +      u32 cnt;
 +      int ret;
 +
 +      if (cur_part_size > len) {
 +              blocks = len / usbd->mmc_blk;
 +              ret = -1;
 +      } else {
 +              blocks = cur_part_size / usbd->mmc_blk;
 +              ret = len - cur_part_size;
 +      }
 +
 +      if (len % usbd->mmc_blk)
 +              blocks++;
 +
 +      loop = blocks / usbd->mmc_max;
 +      if (blocks % usbd->mmc_max)
 +              loop++;
 +
 +      for (i = 0; i < loop; i++) {
 +              if (i == 0) {
 +                      cnt = blocks % usbd->mmc_max;
 +                      if (cnt == 0)
 +                              cnt = usbd->mmc_max;
 +              } else {
 +                      cnt = usbd->mmc_max;
 +              }
 +
 +              sprintf(length, "%x", cnt);
 +              sprintf(offset, "%x", cur_blk_offset);
 +              sprintf(ramaddr, "0x%x", *ram_addr);
 +              mmc_cmd(OPS_WRITE, ramaddr, offset, length);
 +
 +              cur_blk_offset += cnt;
 +
 +              *ram_addr += (cnt * usbd->mmc_blk);
 +      }
 +
 +      return ret;
 +}
 +
 +static int write_file_mmc(struct usbd_ops *usbd, char *ramaddr, u32 len,
 +              char *offset, char *length)
 +{
 +      u32 ram_addr;
 +      int i;
 +      int ret;
 +
 +      if (!usbd->mmc_total) {
 +              printf("MMC is not supported!\n");
 +              return 0;
 +      }
 +
 +      ram_addr = (u32)down_ram_addr;
 +
 +      if (cur_blk_offset == 0) {
 +              boot_sector *bs;
 +              struct mbr_table *mbr;
 +
 +              memcpy(&part_info, (void *)ram_addr,
 +                              sizeof(struct partition_header));
 +
 +              ram_addr += sizeof(struct partition_header);
 +              len -= sizeof(struct partition_header);
 +              mbr = (struct mbr_table*)ram_addr;
 +
 +              /* modify sectors of p1 */
 +              mbr->partition[0].num_sectors = usbd->mmc_total -
 +                              (MBR_OFFSET +
 +                              mbr->partition[1].num_sectors +
 +                              mbr->partition[2].num_sectors +
 +                              mbr->partition[3].num_sectors);
 +
 +              mmc_parts++;
 +
 +              /* modify lba_begin of p2 and p3 and p4 */
 +              for (i = 1; i < 4; i++) {
 +                      if (part_info.partition[i].size == 0)
 +                              break;
 +
 +                      mmc_parts++;
 +                      mbr->partition[i].lba_begin =
 +                              mbr->partition[i - 1].lba_begin +
 +                              mbr->partition[i - 1].num_sectors;
 +              }
 +
 +              /* copy MBR */
 +              memcpy(&mbr_info, mbr, sizeof(struct mbr_table));
 +
 +              printf("Total Size: 0x%08x #parts %d\n",
 +                              (unsigned int)usbd->mmc_total, mmc_parts);
 +              for (i = 0; i < mmc_parts; i++) {
 +                      printf("p%d\t0x%08x\t0x%08x\n", i + 1,
 +                              mbr_info.partition[i].lba_begin,
 +                              mbr_info.partition[i].num_sectors);
 +              }
 +
 +              /* write MBR */
 +              sprintf(length, "%x", MBR_OFFSET);
 +              sprintf(offset, "%x", 0);
 +              sprintf(ramaddr, "0x%x", (u32)ram_addr);
 +              ret = mmc_cmd(OPS_WRITE, ramaddr, offset, length);
 +
 +              ram_addr += (MBR_OFFSET * usbd->mmc_blk);
 +              len -= (MBR_OFFSET * usbd->mmc_blk);
 +
 +              cur_blk_offset = MBR_OFFSET;
 +              cur_partition = 0;
 +              cur_part_size = part_info.partition[0].size;
 +
 +              /* modify p1's total sector */
 +              bs = (boot_sector *)ram_addr;
 +              bs->total_sect = mbr_info.partition[0].num_sectors;
 +
 +              printf("\nWrite Partition %d.. %d blocks\n",
 +                      cur_partition + 1,
 +                      part_info.partition[cur_partition].size /
 +                      (int)usbd->mmc_blk);
 +      }
 +
 +      for (i = cur_partition; i < mmc_parts; i++) {
 +              ret = write_mmc_partition(usbd, &ram_addr, len);
 +
 +              if (ret < 0) {
 +                      cur_part_size -= len;
 +                      break;
 +              } else {
 +                      cur_partition++;
 +                      cur_part_size =
 +                              part_info.partition[cur_partition].size;
 +                      cur_blk_offset =
 +                              mbr_info.partition[cur_partition].lba_begin;
 +
 +                      if (ret == 0)
 +                              break;
 +                      else
 +                              len = ret;
 +
 +                      printf("\nWrite Partition %d.. %d blocks\n",
 +                              cur_partition + 1,
 +                              part_info.partition[cur_partition].size /
 +                              (int)usbd->mmc_blk);
 +              }
 +      }
 +
 +      return 0;
 +}
 +
 +static int write_file_mmc_part(struct usbd_ops *usbd, char *ramaddr, u32 len,
 +              char *offset, char *length)
 +{
 +      u32 ram_addr;
 +      int ret;
 +      int i;
 +
 +      ram_addr = (u32)down_ram_addr;
 +
 +      if (cur_blk_offset == 0) {
 +              /* read MBR */
 +              sprintf(length, "%x", MBR_OFFSET);
 +              sprintf(offset, "%x", 0);
 +              sprintf(ramaddr, "0x%x", (u32)&mbr_info);
 +              ret = mmc_cmd(OPS_READ, ramaddr, offset, length);
 +
 +              for (i = 0; i < 4; i++) {
 +                      printf("p%d\t0x%08x\t0x%08x\n", i + 1,
 +                              mbr_info.partition[i].lba_begin,
 +                              mbr_info.partition[i].num_sectors);
 +              }
 +
 +              cur_blk_offset = (unsigned int)
 +                      mbr_info.partition[mmc_part_write - 1].lba_begin;
 +              cur_partition = mmc_part_write - 1;
 +              cur_part_size = (unsigned int)len;
 +
 +              if (mmc_part_write == 1) {
 +                      ram_addr += sizeof(boot_sector);
 +                      cur_blk_offset += sizeof(boot_sector) / usbd->mmc_blk;
 +                      len -= sizeof(boot_sector);
 +              }
 +      }
 +
 +      printf("\nWrite Partition %d.. %d blocks\n",
 +              cur_partition + 1,
 +              len / (int)usbd->mmc_blk);
 +
 +      write_mmc_partition(usbd, &ram_addr, len);
 +
 +      return 0;
 +}
 +#endif
 +
 +static int write_file_system(char *ramaddr, ulong len, char *offset,
 +              char *length, int part_num, int ubi_update)
 +{
 +#ifdef CONFIG_USE_YAFFS
 +      int actual_len = 0;
 +      int yaffs_write = 0;
 +#endif
 +      int ret = 0;
 +
 +#ifdef CONFIG_CMD_UBI
 +      /* UBI Update */
 +      if (ubi_update) {
 +              sprintf(length, "0x%x", (uint)len);
 +              ret = ubi_cmd(part_id, ramaddr, length, "cont");
 +              return ret;
 +      }
 +#endif
 +
 +      /* Erase entire partition at the first writing */
 +      if (write_part == 0 && ubi_update == 0) {
 +              sprintf(offset, "0x%x", (uint)parts[part_num]->offset);
 +              sprintf(length, "0x%x", (uint)parts[part_num]->size);
 +              nand_cmd(0, offset, length, NULL);
 +      }
 +
 +#ifdef CONFIG_USE_YAFFS
 +      /* if using yaffs, wirte size must be 2112*X
 +       * so, must have to realloc, and writing */
 +      if (!strcmp("yaffs", getenv(parts[part_num]->name))) {
 +              yaffs_write = 1;
 +
 +              memcpy((void *)down_ram_addr, yaffs_data, yaffs_len);
 +
 +              actual_len = len + yaffs_len;
 +              yaffs_len = actual_len % YAFFS_PAGE;
 +              len = actual_len - yaffs_len;
 +
 +              memset(yaffs_data, 0x00, YAFFS_PAGE);
 +              memcpy(yaffs_data, (char *)down_ram_addr + len, yaffs_len);
 +      }
 +#endif
 +
 +      sprintf(offset, "0x%x", (uint)(parts[part_num]->offset + fs_offset));
 +      sprintf(length, "0x%x", (uint)len);
 +
 +#ifdef CONFIG_USE_YAFFS
 +      if (yaffs_write)
 +              ret = nand_cmd(2, ramaddr, offset, length);
 +      else
 +              ret = nand_cmd(1, ramaddr, offset, length);
 +
 +      if (!strcmp("yaffs", getenv(parts[part_num]->name)))
 +              fs_offset += len / YAFFS_PAGE * NAND_PAGE_SIZE;
 +      else
 +              fs_offset += len;
 +
 +#else
 +      fs_offset += len;
 +      ret = nand_cmd(1, ramaddr, offset, length);
 +#endif
 +
 +      return ret;
 +}
 +
 +/* Parsing received data packet and Process data */
 +static int process_data(struct usbd_ops *usbd)
 +{
 +      ulong cmd = 0, arg = 0, ofs = 0, len = 0, flag = 0;
 +      char offset[12], length[12], ramaddr[12];
 +      int recvlen = 0;
 +      unsigned int blocks = 0;
 +      int ret = 0;
 +      int ubi_update = 0;
 +      int ubi_mode = 0;
 +      int img_type;
 +
 +      sprintf(ramaddr, "0x%x", (uint) down_ram_addr);
 +
 +      /* Parse command */
 +      cmd  = *((ulong *) usbd->rx_data + 0);
 +      arg  = *((ulong *) usbd->rx_data + 1);
 +      len  = *((ulong *) usbd->rx_data + 2);
 +      flag = *((ulong *) usbd->rx_data + 3);
 +
 +      /* Reset tx buffer */
 +      memset(usbd->tx_data, 0, sizeof(usbd->tx_data));
 +
 +      ubi_mode = check_ubi_mode();
 +
 +      switch (cmd) {
 +      case COMMAND_DOWNLOAD_IMAGE:
 +              printf("\nCOMMAND_DOWNLOAD_IMAGE\n");
 +
 +#ifdef CONFIG_USE_YAFFS
 +              usbd->recv_setup((char *)down_ram_addr + yaffs_len, (int)len);
 +              printf("Download to 0x%08x, %d bytes\n",
 +                              (uint)down_ram_addr + yaffs_len, (int)len);
 +#else
 +              usbd->recv_setup((char *)down_ram_addr, (int)len);
 +              printf("Download to 0x%08x, %d bytes\n",
 +                              (uint)down_ram_addr, (int)len);
 +#endif
 +              /* response */
 +              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +
 +              /* Receive image by using dma */
 +              recvlen = usbd->recv_data();
 +              if (recvlen < len) {
 +                      printf("Error: wrong image size -> %d/%d\n",
 +                                      (int)recvlen, (int)len);
 +
 +                      /* Retry this commad */
 +                      *((ulong *) usbd->tx_data) = STATUS_RETRY;
 +              } else
 +                      *((ulong *) usbd->tx_data) = STATUS_DONE;
 +
 +              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +              return 1;
 +
 +      /* Report partition info */
 +      case COMMAND_PARTITION_SYNC:
 +              part_id = arg;
 +
 +#ifdef CONFIG_CMD_UBI
 +              if (ubi_mode) {
 +                      if (part_id == RAMDISK_PART_ID ||
 +                          part_id == FILESYSTEM_PART_ID ||
 +                          part_id == FILESYSTEM2_PART_ID) {
 +                              /* change to yaffs style */
 +                              get_part_info();
 +                      }
 +              } else {
 +                      if (part_id == FILESYSTEM3_PART_ID) {
 +                              /* change ubi style */
 +                              get_part_info();
 +                      }
 +              }
 +#endif
 +
 +              if (part_id == FILESYSTEM3_PART_ID)
 +                      part_id = get_part_id("UBI");
 +              else if (part_id == MODEM_PART_ID)
 +                      part_id = get_part_id("modem");
 +              else if (part_id == KERNEL_PART_ID)
 +                      part_id = get_part_id("kernel");
 +#ifdef CONFIG_MIRAGE
 +              if (part_id)
 +                      part_id--;
 +#endif
 +              printf("COMMAND_PARTITION_SYNC - Part%d\n", part_id);
 +
 +              blocks = parts[part_id]->size / 1024 / 128;
 +              printf("COMMAND_PARTITION_SYNC - Part%d, %d blocks\n",
 +                              part_id, blocks);
 +
 +              *((ulong *) usbd->tx_data) = blocks;
 +              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +              return 1;
 +
 +      case COMMAND_WRITE_PART_0:
 +              /* Do nothing */
 +              printf("COMMAND_WRITE_PART_0\n");
 +              return 1;
 +
 +      case COMMAND_WRITE_PART_1:
 +              printf("COMMAND_WRITE_PART_BOOT\n");
 +              part_id = get_part_id("bootloader");
 +              img_type = IMG_BOOT;
 +              break;
 +
 +      case COMMAND_WRITE_PART_2:
 +      case COMMAND_ERASE_PARAMETER:
 +              printf("COMMAND_PARAMETER - not support!\n");
 +              break;
 +
 +      case COMMAND_WRITE_PART_3:
 +              printf("COMMAND_WRITE_KERNEL\n");
 +              part_id = get_part_id("kernel");
 +              img_type = IMG_KERNEL;
 +              break;
 +
 +      case COMMAND_WRITE_PART_4:
 +              printf("COMMAND_WRITE_ROOTFS\n");
 +              part_id = get_part_id("Root");
 +              img_type = IMG_FILESYSTEM;
 +              ubi_update = arg;
 +              break;
 +
 +      case COMMAND_WRITE_PART_5:
 +              printf("COMMAND_WRITE_FACTORYFS\n");
 +              part_id = get_part_id("Fact");
 +              img_type = IMG_FILESYSTEM;
 +              ubi_update = arg;
 +              break;
 +
 +      case COMMAND_WRITE_PART_6:
 +              printf("COMMAND_WRITE_DATAFS\n");
 +              part_id = get_part_id("Data");
 +              img_type = IMG_FILESYSTEM;
 +              ubi_update = arg;
 +              break;
 +
 +      case COMMAND_WRITE_PART_7:
 +              printf("COMMAND_WRITE_UBI\n");
 +              part_id = get_part_id("UBI");
 +              img_type = IMG_FILESYSTEM;
 +              ubi_update = 0;
 +              /* someday, it will be deleted */
 +              get_part_info();
 +              break;
 +
 +      case COMMAND_WRITE_PART_8:
 +              printf("COMMAND_WRITE_MODEM\n");
 +              part_id = get_part_id("modem");
 +              img_type = IMG_MODEM;
 +              break;
 +
++#ifdef CONFIG_CMD_MMC
 +      case COMMAND_WRITE_PART_9:
 +              printf("COMMAND_WRITE_MMC\n");
 +              img_type = IMG_MMC;
 +              mmc_part_write = arg;
 +              break;
++#endif
 +
 +      case COMMAND_WRITE_UBI_INFO:
 +              printf("COMMAND_WRITE_UBI_INFO\n");
 +
 +              if (ubi_mode) {
 +#ifdef CONFIG_CMD_UBI
 +                      part_id = arg-1;
 +                      sprintf(length, "0x%x", (uint)len);
 +                      ret = ubi_cmd(part_id, ramaddr, length, "begin");
 +              } else {
 +#endif
 +                      printf("Error: Not UBI mode\n");
 +                      ret = 1;
 +              }
 +
 +              *((ulong *) usbd->tx_data) = ret;
 +              /* Write image success -> Report status */
 +              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +
 +              return !ret;
 +      /* Download complete -> reset */
 +      case COMMAND_RESET_PDA:
 +              printf("\nDownload finished and Auto reset!\nWait........\n");
 +
 +              /* Stop USB */
 +              usbd->usb_stop();
 +
 +              if (usbd->cpu_reset)
 +                      usbd->cpu_reset();
 +              else
 +                      do_reset();
 +
 +              return 0;
 +
 +      /* Error */
 +      case COMMAND_RESET_USB:
 +              printf("\nError is occured!(maybe previous step)->\
 +                              Turn off and restart!\n");
 +
 +              /* Stop USB */
 +              usbd->usb_stop();
 +              return 0;
 +
 +      case COMMAND_RAM_BOOT:
 +              usbd->usb_stop();
 +              boot_cmd(ramaddr);
 +              return 0;
 +
 +      case COMMAND_RAMDISK_MODE:
 +              printf("COMMAND_RAMDISK_MODE\n");
 +#ifdef CONFIG_RAMDISK_ADDR
 +              if (arg) {
 +                      down_ram_addr = usbd->ram_addr;
 +              } else {
 +                      down_ram_addr = CONFIG_RAMDISK_ADDR;
 +                      run_cmd("ramboot");
 +              }
 +#endif
 +              return 1;
 +
 +#ifdef CONFIG_DOWN_PHONE
 +      case COMMAND_DOWN_PHONE:
 +              printf("COMMAND_RESET_PHONE\n");
 +
 +              usbd_phone_down();
 +
 +              *((ulong *) usbd->tx_data) = STATUS_DONE;
 +              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +              return 1;
 +
 +      case COMMAND_CHANGE_USB:
 +              printf("COMMAND_CHANGE_USB\n");
 +
 +              /* Stop USB */
 +              usbd->usb_stop();
 +
 +              usbd_path_change();
 +
 +              do_reset();
 +              return 0;
 +#endif
 +      case COMMAND_CSA_CLEAR:
 +              printf("COMMAND_CSA_CLEAR\n");
 +              part_id = get_part_id("csa");
 +              img_type = IMG_MODEM;
 +              break;
 +
 +      case COMMAND_PROGRESS:
 +              if (usbd->set_progress)
 +                      usbd->set_progress(arg);
 +              return 1;
 +
 +      default:
 +              printf("Error: Unknown command -> (%d)\n", (int)cmd);
 +              return 1;
 +      }
 +
 +      /* Erase and Write to NAND */
 +      switch (img_type) {
 +      case IMG_BOOT:
 +              ofs = parts[part_id]->offset;
 +#ifdef CONFIG_RECOVERY
 +      {
 +              /* block is fixed:
 +                      1m = ipl(16k)+recovery(240k)+bootloader(768k)*/
 +              long *buf = (long *)down_ram_addr;
 +              u32 ofst;
 +              u32 bootloader_edge = parts[part_id]->size;
 +              u32 bootloader_addr = bootloader_edge >> 2;
 +              u32 recovery_edge = bootloader_addr;
 +              u32 recovery_addr = recovery_edge >> 4;
 +              u32 ipl_addr = 0;
 +
 +              if (len > bootloader_addr) {
 +                      ofst = bootloader_addr / sizeof(buf);
 +                      if (*(buf + ofst) == 0xea000012) {
 +                              /* case: ipl + recovery + bootloader */
 +                              printf("target: ipl + recovery + loader\n");
 +                              ofs = ipl_addr;
 +                      } else {
 +                              /* case: unknown format */
 +                              printf("target: unknown\n");
 +                              *((ulong *) usbd->tx_data) = STATUS_ERROR;
 +                              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +                              return 0;
 +                      }
 +              } else {
 +                      ofst = recovery_addr/sizeof(buf);
 +                      if (*(buf + ofst) == 0xea000012 &&
 +                              *(buf + ofst - 1) == 0x00000000) {
 +                              /* case: ipl + bootloader (old type) */
 +                              printf("target: ipl + bootloader\n");
 +                              ofs = ipl_addr;
 +                      } else {
 +                              /* case: bootloader only */
 +                              printf("target: bootloader\n");
 +                              ofs = bootloader_addr;
 +
 +                              /* skip revision check */
 +                              down_mode = MODE_FORCE;
 +                      }
 +              }
 +
 +              sprintf(offset, "%x", (uint)ofs);
 +              sprintf(length, "%x", parts[part_id]->size);
 +
 +              /* check block is locked/locked-tight */
 +              ret = nand_cmd(3, offset, length, NULL);
 +              if (ret) {
 +                      printf("target is locked%s\n",
 +                              (ret == 1) ? "-tight" : "");
 +                      printf("-> try at recovery mode "
 +                              "to update 'system'.\n");
 +                      printf("   how-to: reset "
 +                              "while pressing volume up and down.\n");
 +                      *((ulong *) usbd->tx_data) = STATUS_ERROR;
 +                      usbd->send_data(usbd->tx_data, usbd->tx_len);
 +                      return 0;
 +              }
 +      }
 +#endif
 +#ifdef CONFIG_S5PC1XX
 +              /* Workaround: for prevent revision mismatch */
 +              if (cpu_is_s5pc110() && (down_mode != MODE_FORCE)) {
 +                      int img_rev = 1;
 +                      long *img_header = (long *)down_ram_addr;
 +
 +                      if (*img_header == 0xea000012)
 +                              img_rev = 0;
 +                      else if (*(img_header + 0x400) == 0xea000012)
 +                              img_rev = 2;
 +
 +                      if (img_rev != s5pc1xx_get_cpu_rev()) {
 +                              printf("CPU revision mismatch!\n"
 +                                      "bootloader is %s%s\n"
 +                                      "download image is %s%s\n",
 +                                      s5pc1xx_get_cpu_rev() ? "EVT1" : "EVT0",
 +                                      s5pc1xx_get_cpu_rev() == 2 ? "-Fused" : "",
 +                                      img_rev ? "EVT1" : "EVT0",
 +                                      img_rev == 2 ? "-Fused" : "");
 +                              *((ulong *) usbd->tx_data) = STATUS_ERROR;
 +                              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +                              return 0;
 +                      }
 +              }
 +#endif
 +#if defined(CONFIG_ENV_IS_IN_NAND) || defined(CONFIG_ENV_IS_IN_ONENAND)
 +              /* Erase the environment also when write bootloader */
 +              {
 +                      int param_id;
 +                      param_id = get_part_id("params");
 +
 +                      if (param_id == -1) {
 +                              sprintf(offset, "%x", CONFIG_ENV_ADDR);
 +                              sprintf(length, "%x", CONFIG_ENV_SIZE);
 +                      } else {
 +                              sprintf(offset, "%x", parts[param_id]->offset);
 +                              sprintf(length, "%x", parts[param_id]->size);
 +                      }
 +                      nand_cmd(0, offset, length, NULL);
 +              }
 +#endif
 +              sprintf(offset, "%x", (uint)ofs);
 +              if (ofs != 0)
 +                      sprintf(length, "%x", parts[part_id]->size - (uint)ofs);
 +              else
 +                      sprintf(length, "%x", parts[part_id]->size);
 +
 +              /* Erase */
 +              nand_cmd(0, offset, length, NULL);
 +              /* Write */
 +              sprintf(length, "%x", (unsigned int) len);
 +              ret = nand_cmd(1, ramaddr, offset, length);
 +              break;
 +
 +      case IMG_KERNEL:
 +              sprintf(offset, "%x", parts[part_id]->offset);
 +              sprintf(length, "%x", parts[part_id]->size);
 +
 +              /* Erase */
 +              nand_cmd(0, offset, length, NULL);
 +              /* Write */
 +              sprintf(length, "%x", (unsigned int) len);
 +              ret = nand_cmd(1, ramaddr, offset, length);
 +              break;
 +
 +      /* File Systems */
 +      case IMG_FILESYSTEM:
 +              /* Erase the qboot also when write ubi image */
 +              {
 +                      int qboot_id;
 +                      qboot_id = get_part_id("qboot");
 +
 +                      if (qboot_id != -1) {
 +                              sprintf(offset, "%x", parts[qboot_id]->offset);
 +                              sprintf(length, "%x", parts[qboot_id]->size);
 +                              nand_cmd(0, offset, length, NULL);
 +                      }
 +              }
 +              ret = write_file_system(ramaddr, len, offset, length,
 +                              part_id, ubi_update);
 +              break;
 +
 +      case IMG_MODEM:
 +              sprintf(offset, "%x", parts[part_id]->offset);
 +              sprintf(length, "%x", parts[part_id]->size);
 +
 +              /* Erase */
 +              if (!arg)
 +                      nand_cmd(0, offset, length, NULL);
 +              else
 +                      printf("CSA Clear will be skipped temporary\n");
 +
 +              /* Write : arg (0 Modem) / (1 CSA) */
 +              if (!arg) {
 +                      sprintf(length, "%x", (unsigned int) len);
 +                      ret = nand_cmd(1, ramaddr, offset, length);
 +              }
 +              break;
 +
 +#ifdef CONFIG_CMD_MMC
 +      case IMG_MMC:
 +              if (mmc_part_write)
 +                      ret = write_file_mmc_part(usbd, ramaddr,
 +                                              len, offset, length);
 +              else
 +                      ret = write_file_mmc(usbd, ramaddr,
 +                                              len, offset, length);
 +              break;
 +#endif
 +
 +      default:
 +              /* Retry? */
 +              write_part--;
 +      }
 +
 +      if (ret) {
 +              /* Retry this commad */
 +              *((ulong *) usbd->tx_data) = STATUS_RETRY;
 +              usbd->send_data(usbd->tx_data, usbd->tx_len);
 +              return 1;
 +      } else
 +              *((ulong *) usbd->tx_data) = STATUS_DONE;
 +
 +      /* Write image success -> Report status */
 +      usbd->send_data(usbd->tx_data, usbd->tx_len);
 +
 +      write_part++;
 +
 +      /* Reset write count for another image */
 +      if (flag) {
 +              write_part = 0;
 +              fs_offset = 0;
 +#ifdef CONFIG_USE_YAFFS
 +              yaffs_len = 0;
 +#endif
 +      }
 +
 +      return 1;
 +}
 +
 +static const char *recv_key = "SAMSUNG";
 +static const char *tx_key = "MPL";
 +
 +int do_usbd_down(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 +{
 +      struct usbd_ops *usbd;
 +      int err;
 +
 +      if (argc > 1)
 +              down_mode = simple_strtoul(argv[1], NULL, 10);
 +      else
 +              down_mode = MODE_NORMAL;
 +
 +      printf("USB Downloader v%s\n", APP_VERSION);
 +
 +      /* get partition info */
 +      err = get_part_info();
 +      if (err)
 +              return err;
 +
 +      /* interface setting */
 +      usbd = usbd_set_interface(&usbd_ops);
 +      down_ram_addr = usbd->ram_addr;
 +
 +      /* init the usb controller */
 +      usbd->usb_init();
 +
 +      /* receive setting */
 +      usbd->recv_setup(usbd->rx_data, usbd->rx_len);
 +
 +      /* detect the download request from Host PC */
 +      if (usbd->recv_data()) {
 +              if (strncmp(usbd->rx_data, recv_key, strlen(recv_key)) == 0) {
 +                      printf("Download request from the Host PC\n");
 +                      msleep(30);
 +
 +                      strcpy(usbd->tx_data, tx_key);
 +                      usbd->send_data(usbd->tx_data, usbd->tx_len);
 +              } else {
 +                      printf("No download request from the Host PC!! 1\n");
 +                      return 0;
 +              }
 +      } else {
 +              printf("No download request from the Host PC!!\n");
 +              return 0;
 +      }
 +
 +      printf("Receive the packet\n");
 +
 +      /* receive the data from Host PC */
 +      while (1) {
 +              usbd->recv_setup(usbd->rx_data, usbd->rx_len);
 +
 +              if (usbd->recv_data()) {
 +                      if (process_data(usbd) == 0)
 +                              return 0;
 +              }
 +      }
 +
 +      return 0;
 +}
 +
 +U_BOOT_CMD(usbdown, CONFIG_SYS_MAXARGS, 1, do_usbd_down,
 +      "Initialize USB device and Run USB Downloader (specific)",
 +      "- normal mode\n"
 +      "usbdown mode - specific mode (0: NORAML, 1: FORCE)\n"
 +);
diff --cc common/serial.c
@@@ -69,15 -78,15 +78,15 @@@ struct serial_device *__default_serial_
  #else
  #error "CONFIG_SERIAL? missing."
  #endif
 -#elif defined(CONFIG_S5PC1XX)
 +#elif defined(CONFIG_S5PC1XX) || defined(CONFIG_S5P64XX)
  #if defined(CONFIG_SERIAL0)
-       return &s5pc1xx_serial0_device;
+       return &s5p_serial0_device;
  #elif defined(CONFIG_SERIAL1)
-       return &s5pc1xx_serial1_device;
+       return &s5p_serial1_device;
  #elif defined(CONFIG_SERIAL2)
-       return &s5pc1xx_serial2_device;
+       return &s5p_serial2_device;
  #elif defined(CONFIG_SERIAL3)
-       return &s5pc1xx_serial3_device;
+       return &s5p_serial3_device;
  #else
  #error "CONFIG_SERIAL? missing."
  #endif
Simple merge
Simple merge
@@@ -33,8 -36,7 +36,8 @@@ COBJS-$(CONFIG_OPENCORES_YANU) += openc
  COBJS-$(CONFIG_SYS_NS16550) += ns16550.o
  COBJS-$(CONFIG_DRIVER_S3C4510_UART) += s3c4510b_uart.o
  COBJS-$(CONFIG_S3C64XX) += s3c64xx.o
- COBJS-$(CONFIG_S5PC1XX) += serial_s5pc1xx.o
- COBJS-$(CONFIG_S5P64XX) += serial_s5pc1xx.o
+ COBJS-$(CONFIG_S5PC1XX) += serial_s5p.o
++COBJS-$(CONFIG_S5P64XX) += serial_s5p.o
  COBJS-$(CONFIG_SYS_NS16550_SERIAL) += serial.o
  COBJS-$(CONFIG_CLPS7111_SERIAL) += serial_clps7111.o
  COBJS-$(CONFIG_IMX_SERIAL) += serial_imx.o
index 0000000,9747db3..60e0df3
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,206 +1,213 @@@
+ /*
+  * (C) Copyright 2009 SAMSUNG Electronics
+  * Minkyu Kang <mk7.kang@samsung.com>
+  * Heungjun Kim <riverful.kim@samsung.com>
+  *
+  * based on drivers/serial/s3c64xx.c
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License as published by
+  * the Free Software Foundation; either version 2 of the License, or
+  * (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  *
+  */
+ #include <common.h>
+ #include <asm/io.h>
+ #include <asm/arch/uart.h>
+ #include <asm/arch/clk.h>
+ #include <serial.h>
+ static inline struct s5p_uart *s5p_get_base_uart(int dev_index)
+ {
+       u32 offset = dev_index * sizeof(struct s5p_uart);
++#ifdef CONFIG_S5PC1XX
+       if (cpu_is_s5pc100())
+               return (struct s5p_uart *)(S5PC100_UART_BASE + offset);
+       else
+               return (struct s5p_uart *)(S5PC110_UART_BASE + offset);
++#elif CONFIG_S5P64XX
++      if (cpu_is_s5p6442())
++              return (struct s5pc1xx_uart *)(S5P6442_UART_BASE + offset);
++      else
++              return NULL;
++#endif
+ }
+ /*
+  * The coefficient, used to calculate the baudrate on S5P UARTs is
+  * calculated as
+  * C = UBRDIV * 16 + number_of_set_bits_in_UDIVSLOT
+  * however, section 31.6.11 of the datasheet doesn't recomment using 1 for 1,
+  * 3 for 2, ... (2^n - 1) for n, instead, they suggest using these constants:
+  */
+ static const int udivslot[] = {
+       0,
+       0x0080,
+       0x0808,
+       0x0888,
+       0x2222,
+       0x4924,
+       0x4a52,
+       0x54aa,
+       0x5555,
+       0xd555,
+       0xd5d5,
+       0xddd5,
+       0xdddd,
+       0xdfdd,
+       0xdfdf,
+       0xffdf,
+ };
+ void serial_setbrg_dev(const int dev_index)
+ {
+       DECLARE_GLOBAL_DATA_PTR;
+       struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
+       u32 pclk = get_pclk();
+       u32 baudrate = gd->baudrate;
+       u32 val;
+       val = pclk / baudrate;
+       writel(val / 16 - 1, &uart->ubrdiv);
+       writew(udivslot[val % 16], &uart->udivslot);
+ }
+ /*
+  * Initialise the serial port with the given baudrate. The settings
+  * are always 8 data bits, no parity, 1 stop bit, no start bits.
+  */
+ int serial_init_dev(const int dev_index)
+ {
+       struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
+       /* reset and enable FIFOs, set triggers to the maximum */
+       writel(0, &uart->ufcon);
+       writel(0, &uart->umcon);
+       /* 8N1 */
+       writel(0x3, &uart->ulcon);
+       /* No interrupts, no DMA, pure polling */
+       writel(0x245, &uart->ucon);
+       serial_setbrg_dev(dev_index);
+       return 0;
+ }
+ static int serial_err_check(const int dev_index, int op)
+ {
+       struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
+       unsigned int mask;
+       /*
+        * UERSTAT
+        * Break Detect [3]
+        * Frame Err    [2] : receive operation
+        * Parity Err   [1] : receive operation
+        * Overrun Err  [0] : receive operation
+        */
+       if (op)
+               mask = 0x8;
+       else
+               mask = 0xf;
+       return readl(&uart->uerstat) & mask;
+ }
+ /*
+  * Read a single byte from the serial port. Returns 1 on success, 0
+  * otherwise. When the function is succesfull, the character read is
+  * written into its argument c.
+  */
+ int serial_getc_dev(const int dev_index)
+ {
+       struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
+       /* wait for character to arrive */
+       while (!(readl(&uart->utrstat) & 0x1)) {
+               if (serial_err_check(dev_index, 0))
+                       return 0;
+       }
+       return (int)(readl(&uart->urxh) & 0xff);
+ }
+ /*
+  * Output a single byte to the serial port.
+  */
+ void serial_putc_dev(const char c, const int dev_index)
+ {
+       struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
+       /* wait for room in the tx FIFO */
+       while (!(readl(&uart->utrstat) & 0x2)) {
+               if (serial_err_check(dev_index, 1))
+                       return;
+       }
+       writel(c, &uart->utxh);
+       /* If \n, also do \r */
+       if (c == '\n')
+               serial_putc('\r');
+ }
+ /*
+  * Test whether a character is in the RX buffer
+  */
+ int serial_tstc_dev(const int dev_index)
+ {
+       struct s5p_uart *const uart = s5p_get_base_uart(dev_index);
+       return (int)(readl(&uart->utrstat) & 0x1);
+ }
+ void serial_puts_dev(const char *s, const int dev_index)
+ {
+       while (*s)
+               serial_putc_dev(*s++, dev_index);
+ }
+ /* Multi serial device functions */
+ #define DECLARE_S5P_SERIAL_FUNCTIONS(port) \
+ int s5p_serial##port##_init(void) { return serial_init_dev(port); } \
+ void s5p_serial##port##_setbrg(void) { serial_setbrg_dev(port); } \
+ int s5p_serial##port##_getc(void) { return serial_getc_dev(port); } \
+ int s5p_serial##port##_tstc(void) { return serial_tstc_dev(port); } \
+ void s5p_serial##port##_putc(const char c) { serial_putc_dev(c, port); } \
+ void s5p_serial##port##_puts(const char *s) { serial_puts_dev(s, port); }
+ #define INIT_S5P_SERIAL_STRUCTURE(port, name, bus) { \
+       name, \
+       bus, \
+       s5p_serial##port##_init, \
+       NULL, \
+       s5p_serial##port##_setbrg, \
+       s5p_serial##port##_getc, \
+       s5p_serial##port##_tstc, \
+       s5p_serial##port##_putc, \
+       s5p_serial##port##_puts, }
+ DECLARE_S5P_SERIAL_FUNCTIONS(0);
+ struct serial_device s5p_serial0_device =
+       INIT_S5P_SERIAL_STRUCTURE(0, "s5pser0", "S5PUART0");
+ DECLARE_S5P_SERIAL_FUNCTIONS(1);
+ struct serial_device s5p_serial1_device =
+       INIT_S5P_SERIAL_STRUCTURE(1, "s5pser1", "S5PUART1");
+ DECLARE_S5P_SERIAL_FUNCTIONS(2);
+ struct serial_device s5p_serial2_device =
+       INIT_S5P_SERIAL_STRUCTURE(2, "s5pser2", "S5PUART2");
+ DECLARE_S5P_SERIAL_FUNCTIONS(3);
+ struct serial_device s5p_serial3_device =
+       INIT_S5P_SERIAL_STRUCTURE(3, "s5pser3", "S5PUART3");
@@@ -36,19 -36,8 +36,19 @@@ COBJS-$(CONFIG_VIDEO_MX3) += mx3fb.
  COBJS-$(CONFIG_VIDEO_SED13806) += sed13806.o
  COBJS-$(CONFIG_SED156X) += sed156x.o
  COBJS-$(CONFIG_VIDEO_SM501) += sm501.o
- COBJS-$(CONFIG_VIDEO_SMI_LYNXEM) += smiLynxEM.o
+ COBJS-$(CONFIG_VIDEO_SMI_LYNXEM) += smiLynxEM.o videomodes.o
  COBJS-$(CONFIG_VIDEO_VCXK) += bus_vcxk.o
- COBJS-y += videomodes.o
 +COBJS-$(CONFIG_S5PC1XXFB) += s5p-fb.o s5p-fimd.o s5p-spi.o
 +COBJS-$(CONFIG_S6E63M0) += s6e63m0.o
 +COBJS-$(CONFIG_S6D16A0X) += s6d16a0x.o
 +COBJS-$(CONFIG_AMS701KA) += ams701ka.o
 +COBJS-$(CONFIG_LD9040) += ld9040.o
 +#COBJS-$(CONFIG_S5PC1XXFB) += s5p-fb.o s5p_fimd_aquila.o tl2796_aquila.o
 +#COBJS-$(CONFIG_S5PC1XXFB) += s5p-dualfb.o s5p-dualfimd.o tl2796_dual.o
 +#COBJS-$(CONFIG_S5PC1XXFB) += s5p-dualfb.o s5p_dualfimd_aquila.o tl2796_dual_aquila.o
 +#COBJS-$(CONFIG_SUBLCD) += eltz_lcd.o
++#COBJS-y += videomodes.o
 +COBJS-$(CONFIG_S5PC1XXFB) += font_8x16.o fbutils.o
  
  COBJS := $(COBJS-y)
  SRCS  := $(COBJS:.o=.c)
index 63a92e3,0000000..36c8871
mode 100644,000000..100644
--- /dev/null
@@@ -1,22 -1,0 +1,22 @@@
-       struct s5pc1xx_gpio_bank *cs_bank;
-       struct s5pc1xx_gpio_bank *clk_bank;
-       struct s5pc1xx_gpio_bank *si_bank;
-       struct s5pc1xx_gpio_bank *so_bank;
 +#define COMMAND_ONLY          0xFE
 +#define DATA_ONLY             0xFF
 +#define PACKET_LEN            8
 +
 +struct spi_platform_data {
++      struct s5p_gpio_bank *cs_bank;
++      struct s5p_gpio_bank *clk_bank;
++      struct s5p_gpio_bank *si_bank;
++      struct s5p_gpio_bank *so_bank;
 +
 +      unsigned int cs_num;
 +      unsigned int clk_num;
 +      unsigned int si_num;
 +      unsigned int so_num;
 +
 +      unsigned int set_rev;
 +};
 +
 +void spi_write_byte(struct spi_platform_data *spi,
 +                              unsigned char address, unsigned char command);
 +void spi_read_byte(struct spi_platform_data *spi,
 +                              unsigned char address, unsigned char command);
  
  #define CONFIG_DOS_PARTITION          1
  
+ /*
+  * Ethernet Contoller driver
+  */
+ #ifdef CONFIG_CMD_NET
+ #define CONFIG_NET_MULTI
+ #define CONFIG_SMC911X         1       /* we have a SMC9115 on-board   */
+ #define CONFIG_SMC911X_16_BIT  1       /* SMC911X_16_BIT Mode          */
+ #define CONFIG_SMC911X_BASE    0x98800300      /* SMC911X Drive Base   */
+ #define CONFIG_ENV_SROM_BANK   3       /* Select SROM Bank-3 for Ethernet*/
+ #endif /* CONFIG_CMD_NET */
 +/* USB Downloader */
 +#define CONFIG_CMD_USBDOWN
 +#define CONFIG_SAMSUNG_USB
 +#define CONFIG_OTG_CLK_OSCC
 +#define CONFIG_SYS_DOWN_ADDR  CONFIG_SYS_SDRAM_BASE
 +#define CONFIG_RAMDISK_ADDR   0x33000000
 +
  #endif        /* __CONFIG_H */
diff --cc include/net.h
@@@ -137,9 -105,9 +137,10 @@@ struct eth_device 
  #ifdef CONFIG_MCAST_TFTP
        int (*mcast) (struct eth_device*, u32 ip, u8 set);
  #endif
+       int  (*write_hwaddr) (struct eth_device*);
        struct eth_device *next;
        void *priv;
 +      int mtu;
  };
  
  extern int eth_initialize(bd_t *bis); /* Initialize network subsystem */
@@@ -43,11 -52,11 +52,11 @@@ extern struct serial_device s3c24xx_ser
  extern struct serial_device s3c24xx_serial2_device;
  #endif
  
 -#if defined(CONFIG_S5PC1XX)
 +#if defined(CONFIG_S5PC1XX) || defined(CONFIG_S5P64XX)
- extern struct serial_device s5pc1xx_serial0_device;
- extern struct serial_device s5pc1xx_serial1_device;
- extern struct serial_device s5pc1xx_serial2_device;
- extern struct serial_device s5pc1xx_serial3_device;
+ extern struct serial_device s5p_serial0_device;
+ extern struct serial_device s5p_serial1_device;
+ extern struct serial_device s5p_serial2_device;
+ extern struct serial_device s5p_serial3_device;
  #endif
  
  #if defined(CONFIG_OMAP3_ZOOM2)
diff --cc lib/Makefile
Simple merge
index 6f5cc79,0000000..860787a
mode 100644,000000..100644
--- /dev/null
@@@ -1,103 -1,0 +1,103 @@@
-       ln -s $(SRCTREE)/cpu/$(CPU)/start.S $@
 +#
 +#  Samsung SMDK6442(S5P6442) board OneNAND IPL
 +#
 +#  Copyright (C) 2009 Samsung Electronics
 +#  Minkyu Kang <mk7.kang@samsung.com>
 +#
 +# This program is free software; you can redistribute it and/or
 +# modify it under the terms of the GNU General Public License as
 +# published by the Free Software Foundation; either version 2 of
 +# the License, or (at your option) any later version.
 +#
 +
 +include $(TOPDIR)/config.mk
 +TEXT_BASE = 0xD0021800
 +TEXT_BASE8K = 0xD0023800
 +
 +LDSCRIPT= $(TOPDIR)/onenand_ipl/board/$(BOARDDIR)/u-boot-onenand.lds
 +LDFLAGS       = -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 +AFLAGS        += -DCONFIG_ONENAND_IPL -g
 +CFLAGS        += -DCONFIG_ONENAND_IPL -g -D__HAVE_ARCH_MEMCPY32
 +OBJCFLAGS += --gap-fill=0x00
 +
 +SOBJS := lowlevel_init.o mem_setup.o
 +SOBJS += start.o _memcpy32.o
 +COBJS += onenand_read.o
 +COBJS += onenand_boot.o
 +
 +SRCS  := $(addprefix $(obj),$(SOBJS:.o=.S) $(COBJS:.o=.c))
 +OBJS  := $(addprefix $(obj),$(SOBJS) $(COBJS))
 +__OBJS        := $(SOBJS) $(COBJS)
 +LNDIR := $(OBJTREE)/onenand_ipl/board/$(BOARDDIR)
 +
 +onenandobj    := $(OBJTREE)/onenand_ipl/
 +
 +ALL   = $(onenandobj)onenand-ipl $(onenandobj)onenand-ipl.bin $(onenandobj)onenand-ipl-8k.bin
 +
 +all:  $(obj).depend $(ALL)
 +
 +$(onenandobj)onenand-ipl-8k.bin:      $(onenandobj)onenand-ipl checksum
 +      $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(TEXT_BASE8K) -O binary $< $@
 +      $(onenandobj)/board/$(BOARDDIR)/checksum $@
 +
 +$(onenandobj)onenand-ipl.bin: $(onenandobj)onenand-ipl
 +      $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 +
 +$(onenandobj)onenand-ipl:     $(OBJS)
 +      cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
 +              -Map $@.map -o $@
 +
 +checksum: checksum.c
 +      $(HOSTCC) -o $@ $<
 +
 +# create symbolic links from common files
 +
 +# from cpu directory
 +$(obj)start.S:
 +      @rm -f $@
-       ln -sf $(SRCTREE)/lib_arm/_memcpy32.S $@
++      ln -s $(SRCTREE)/$(CPUDIR)/start.S $@
 +
 +$(obj)mem_setup.S:
 +      ln -sf $(SRCTREE)/board/$(BOARDDIR)/mem_setup.S $@
 +
 +$(obj)lowlevel_init.S:
 +      ln -sf $(SRCTREE)/board/$(BOARDDIR)/lowlevel_init.S $@
 +
 +# from lib_arm
 +$(obj)_memcpy32.S:
++      ln -sf $(SRCTREE)/arch/$(ARCH)/lib/_memcpy32.S $@
 +
 +# from onenand_ipl directory
 +$(obj)onenand_ipl.h:
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_ipl.h $@
 +
 +$(obj)onenand_boot.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_boot.c $@
 +
 +$(obj)onenand_read.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_read.c $@
 +
 +$(obj)samsung_read.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/samsung_read.c $@
 +
 +#########################################################################
 +
 +$(obj)%.o:    $(obj)%.S
 +      $(CC) $(AFLAGS) -c -o $@ $<
 +
 +$(obj)%.o:    $(obj)$.c
 +      $(CC) $(CFLAGS) -c -o $@ $<
 +
 +# defines $(obj).depend target
 +include $(SRCTREE)/rules.mk
 +
 +sinclude $(obj).depend
 +
 +clean:
 +      rm onenand_boot.c onenand_read.c
 +
 +#########################################################################
index 768505d,0000000..8d86ec3
mode 100644,000000..100644
--- /dev/null
@@@ -1,103 -1,0 +1,103 @@@
-       ln -s $(SRCTREE)/cpu/$(CPU)/start.S $@
 +#
 +#  Samsung SMDKC100(S5PC100) board OneNAND IPL
 +#
 +#  Copyright (C) 2009 Samsung Electronics
 +#  Minkyu Kang <mk7.kang@samsung.com>
 +#
 +# This program is free software; you can redistribute it and/or
 +# modify it under the terms of the GNU General Public License as
 +# published by the Free Software Foundation; either version 2 of
 +# the License, or (at your option) any later version.
 +#
 +
 +include $(TOPDIR)/config.mk
 +TEXT_BASE = 0xD0034000
 +TEXT_BASE2K = 0xD0034800
 +TEXT_BASE4K = 0xD0035000
 +TEXT_BASE16K = 0xD0038000
 +
 +LDSCRIPT= $(TOPDIR)/onenand_ipl/board/$(BOARDDIR)/u-boot-onenand.lds
 +LDFLAGS       = -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 +AFLAGS        += -DCONFIG_ONENAND_IPL -g
 +CFLAGS        += -DCONFIG_ONENAND_IPL -g
 +OBJCFLAGS += --gap-fill=0x00
 +
 +SOBJS := lowlevel_init.o mem_setup.o
 +SOBJS += start.o
 +COBJS += onenand_read.o samsung_read.o
 +COBJS += onenand_boot.o
 +
 +SRCS  := $(addprefix $(obj),$(SOBJS:.o=.S) $(COBJS:.o=.c))
 +OBJS  := $(addprefix $(obj),$(SOBJS) $(COBJS))
 +__OBJS        := $(SOBJS) $(COBJS)
 +LNDIR := $(OBJTREE)/onenand_ipl/board/$(BOARDDIR)
 +
 +onenandobj    := $(OBJTREE)/onenand_ipl/
 +
 +ALL   = $(onenandobj)onenand-ipl $(onenandobj)onenand-ipl.bin $(onenandobj)onenand-ipl-2k.bin $(onenandobj)onenand-ipl-4k.bin $(onenandobj)onenand-ipl-16k.bin
 +
 +all:  $(obj).depend $(ALL)
 +
 +$(onenandobj)onenand-ipl-2k.bin:      $(onenandobj)onenand-ipl
 +      $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(TEXT_BASE2K) -O binary $< $@
 +
 +$(onenandobj)onenand-ipl-4k.bin:      $(onenandobj)onenand-ipl
 +      $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(TEXT_BASE4K) -O binary $< $@
 +
 +$(onenandobj)onenand-ipl-16k.bin:     $(onenandobj)onenand-ipl
 +      $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(TEXT_BASE16K) -O binary $< $@
 +
 +$(onenandobj)onenand-ipl.bin: $(onenandobj)onenand-ipl
 +      $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 +
 +$(onenandobj)onenand-ipl:     $(OBJS)
 +      cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
 +              -Map $@.map -o $@
 +
 +# create symbolic links from common files
 +
 +# from cpu directory
 +$(obj)start.S:
 +      @rm -f $@
++      ln -s $(SRCTREE)/$(CPUDIR)/start.S $@
 +
 +$(obj)mem_setup.S:
 +      ln -sf $(SRCTREE)/board/$(BOARDDIR)/mem_setup.S $@
 +
 +$(obj)lowlevel_init.S:
 +      ln -sf $(SRCTREE)/board/$(BOARDDIR)/lowlevel_init.S $@
 +
 +# from onenand_ipl directory
 +$(obj)onenand_ipl.h:
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_ipl.h $@
 +
 +$(obj)onenand_boot.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_boot.c $@
 +
 +$(obj)onenand_read.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_read.c $@
 +
 +$(obj)samsung_read.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/samsung_read.c $@
 +
 +#########################################################################
 +
 +$(obj)%.o:    $(obj)%.S
 +      $(CC) $(AFLAGS) -c -o $@ $<
 +
 +$(obj)%.o:    $(obj)$.c
 +      $(CC) $(CFLAGS) -c -o $@ $<
 +
 +# defines $(obj).depend target
 +include $(SRCTREE)/rules.mk
 +
 +sinclude $(obj).depend
 +
 +clean:
 +      rm onenand_boot.c onenand_read.c
 +
 +#########################################################################
index 49ee837,0000000..eca96e5
mode 100644,000000..100644
--- /dev/null
@@@ -1,128 -1,0 +1,128 @@@
-       ln -s $(SRCTREE)/cpu/$(CPU)/start.S $@
 +#
 +#  Samsung Universal(S5PC100/S5PC110) board OneNAND IPL
 +#
 +#  Copyright (C) 2009 Samsung Electronics
 +#  Minkyu Kang <mk7.kang@samsung.com>
 +#  Kyungmin Park <kyungmin.park@samsung.com>
 +#
 +# This program is free software; you can redistribute it and/or
 +# modify it under the terms of the GNU General Public License as
 +# published by the Free Software Foundation; either version 2 of
 +# the License, or (at your option) any later version.
 +#
 +
 +include $(TOPDIR)/config.mk
 +# S5PC100 loads at 0x34000
 +# S5PC110 loads at 0x30000 (EVT0)
 +# S5PC110 loads at 0x20010 (EVT1)
 +# Now it uses the S5PC100 as default
 +# If you use the S5PC110, the load address is relocated at start.S
 +# XXX Never set it S5PC110 it don't relocate it
 +# FIXME BL1 header uses 16 bytes at S5PC110 EVT1
 +TEXT_BASE             = 0xD0034000
 +TEXT_BASE16K_EVT0     = 0xD0038000
 +TEXT_BASE16K_EVT1     = 0xD0037ff0
 +TEXT_BASE16K_EVT1_SEC = 0xD0037000
 +
 +LDSCRIPT= $(TOPDIR)/onenand_ipl/board/$(BOARDDIR)/u-boot-onenand.lds
 +LDFLAGS       = -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 +AFLAGS        += -DCONFIG_ONENAND_IPL -g -UTEXT_BASE -DTEXT_BASE=$(TEXT_BASE)
 +CFLAGS        += -DCONFIG_ONENAND_IPL -g -D__HAVE_ARCH_MEMCPY32
 +OBJCFLAGS += --gap-fill=0x00
 +
 +SOBJS := lowlevel_init.o mem_setup.o
 +SOBJS += start.o _memcpy32.o
 +SOBJS += cache.o
 +COBJS += onenand_read.o samsung_read.o
 +COBJS += onenand_boot.o
 +
 +SRCS  := $(addprefix $(obj),$(SOBJS:.o=.S) $(COBJS:.o=.c))
 +OBJS  := $(addprefix $(obj),$(SOBJS) $(COBJS))
 +__OBJS        := $(SOBJS) $(COBJS)
 +LNDIR := $(OBJTREE)/onenand_ipl/board/$(BOARDDIR)
 +
 +onenandobj    := $(OBJTREE)/onenand_ipl/
 +
 +ALL   = $(onenandobj)onenand-ipl $(onenandobj)onenand-ipl.bin $(onenandobj)onenand-ipl-16k-evt0.bin $(onenandobj)onenand-ipl-16k-evt1.bin $(onenandobj)onenand-ipl-fused.bin
 +
 +all:  $(obj).depend $(ALL)
 +
 +$(onenandobj)onenand-ipl-16k-evt0.bin:        $(onenandobj)onenand-ipl checksum
 +      $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(TEXT_BASE16K_EVT0) -O binary $< $@
 +      $(onenandobj)/board/$(BOARDDIR)/checksum $@ 0
 +
 +$(onenandobj)onenand-ipl-16k-evt1.bin:        $(onenandobj)onenand-ipl checksum
 +      $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(TEXT_BASE16K_EVT1) -O binary $< $@
 +      $(onenandobj)/board/$(BOARDDIR)/checksum $@ 1
 +      cat $(onenandobj)/board/$(BOARDDIR)/header.bin $@ > $(onenandobj)onenand-ipl-16k.bin
 +
 +$(onenandobj)onenand-ipl-fused.bin:   $(onenandobj)onenand-ipl checksum
 +      $(OBJCOPY) ${OBJCFLAGS} --pad-to=$(TEXT_BASE16K_EVT1_SEC) -O binary $< $@
 +      cat $(onenandobj)/board/$(BOARDDIR)/bl1.img $@ > $(onenandobj)onenand-ipl-16k-fused.bin
 +
 +$(onenandobj)onenand-ipl.bin: $(onenandobj)onenand-ipl
 +      $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 +
 +$(onenandobj)onenand-ipl:     $(OBJS)
 +      cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
 +              -Map $@.map -o $@
 +
 +checksum: checksum.c
 +      $(HOSTCC) -o $@ $<
 +
 +# create symbolic links from common files
 +
 +# from cpu directory
 +$(obj)start.S:
 +      @rm -f $@
-       ln -s $(SRCTREE)/cpu/$(CPU)/$(SOC)/cache.S $@
++      ln -s $(SRCTREE)/$(CPUDIR)/start.S $@
 +
 +# from SoC directory
 +$(obj)cache.S:
 +      @rm -f $@
-       ln -sf $(SRCTREE)/lib_arm/_memcpy32.S $@
++      ln -s $(SRCTREE)/$(CPUDIR)/$(SOC)/cache.S $@
 +
 +$(obj)mem_setup.S:
 +      ln -sf $(SRCTREE)/board/$(BOARDDIR)/mem_setup.S $@
 +
 +$(obj)lowlevel_init.S:
 +      ln -sf $(SRCTREE)/board/$(BOARDDIR)/lowlevel_init.S $@
 +
 +# from lib_arm
 +$(obj)_memcpy32.S:
++      ln -sf $(SRCTREE)/arch/$(ARCH)/lib/_memcpy32.S $@
 +
 +# from onenand_ipl directory
 +$(obj)onenand_ipl.h:
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_ipl.h $@
 +
 +$(obj)onenand_boot.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_boot.c $@
 +
 +$(obj)onenand_read.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/onenand_read.c $@
 +
 +$(obj)samsung_read.c: $(obj)onenand_ipl.h
 +      @rm -f $@
 +      ln -s $(SRCTREE)/onenand_ipl/samsung_read.c $@
 +
 +#########################################################################
 +
 +$(obj)%.o:    $(obj)%.S
 +      $(CC) $(AFLAGS) -c -o $@ $<
 +
 +$(obj)%.o:    $(obj)$.c
 +      $(CC) $(CFLAGS) -c -o $@ $<
 +
 +# defines $(obj).depend target
 +include $(SRCTREE)/rules.mk
 +
 +sinclude $(obj).depend
 +
 +clean:
 +      rm onenand_boot.c onenand_read.c samsung_read.c
 +
 +#########################################################################
index 2c9ae0f,0000000..06aa7b9
mode 100644,000000..100644
--- /dev/null
@@@ -1,57 -1,0 +1,57 @@@
-       ln -s $(SRCTREE)/cpu/$(CPU)/$@ $@
 +#
 +#  Samsung Universal(S5PC110) board Recovery block
 +#
 +#  Copyright (C) 2010 Samsung Electronics
 +#  Minkyu Kang <mk7.kang@samsung.com>
 +#  Kyungmin Park <kyungmin.park@samsung.com>
 +#
 +
 +include $(TOPDIR)/$(RECOVERY_BLOCK)/config.mk
 +
 +LIB   := $(obj)lib$(BOARD).a
 +
 +SOBJS = start.o reset.o _memcpy32.o
 +COBJS = string.o dlmalloc.o cpu_info.o
 +COBJS += gpio.o
 +COBJS += universal.o
 +
 +SRCS := $(COBJS:.o=.c)
 +OBJS := $(addprefix $(obj),$(COBJS))
 +
 +all:  $(LIB)
 +
 +$(LIB):       $(obj).depend $(SOBJS) $(OBJS)
 +      $(AR) $(ARFLAGS) $@ $(SOBJS) $(OBJS)
 +
 +# create symbolic links from common files
 +
 +$(obj)start.S:
 +      @rm -f $@
-       ln -s $(SRCTREE)/cpu/$(CPU)/$(SOC)/$@ $@
++      ln -s $(SRCTREE)/$(CPUDIR)/$@ $@
 +
 +$(obj)reset.S:
 +      @rm -f $@
-       ln -s $(SRCTREE)/cpu/$(CPU)/$(SOC)/$@ $@
++      ln -s $(SRCTREE)/$(CPUDIR)/$(SOC)/$@ $@
 +
 +$(obj)cpu_info.c:
 +      @rm -f $@
-       ln -sf $(SRCTREE)/lib_arm/$@ $@
++      ln -s $(SRCTREE)/$(CPUDIR)/$(SOC)/$@ $@
 +
 +$(obj)_memcpy32.S:
-       ln -s $(SRCTREE)/lib_generic/$@ $@
++      ln -sf $(SRCTREE)/arch/$(ARCH)/lib/$@ $@
 +
 +$(obj)string.c:
 +      @rm -f $@
++      ln -s $(SRCTREE)/lib/$@ $@
 +
 +$(obj)dlmalloc.c:
 +      @rm -f $@
 +      ln -s $(SRCTREE)/common/$@ $@
 +
 +#########################################################################
 +
 +include $(SRCTREE)/rules.mk
 +
 +sinclude $(obj).depend
 +
 +#########################################################################
index 0be942d,0000000..18e9713
mode 100644,000000..100644
--- /dev/null
@@@ -1,153 -1,0 +1,153 @@@
- void gpio_cfg_pin(struct s5pc1xx_gpio_bank *bank, int gpio, int cfg)
 +/*
 + * Copyright (C) 2009-2010 Samsung Electronics
 + * Minkyu Kang <mk7.kang@samsung.com>
 + */
 +
 +#include <common.h>
 +#include <asm/io.h>
 +#include <asm/arch/gpio.h>
 +
 +#define CON_MASK(x)           (0xf << ((x) << 2))
 +#define CON_SFR(x, v)         ((v) << ((x) << 2))
 +
 +#define DAT_MASK(x)           (0x1 << (x))
 +#define DAT_SET(x)            (0x1 << (x))
 +
 +#define PULL_MASK(x)          (0x3 << ((x) << 1))
 +#define PULL_MODE(x, v)               ((v) << ((x) << 1))
 +
 +#define DRV_MASK(x)           (0x3 << ((x) << 1))
 +#define DRV_SET(x, m)         ((m) << ((x) << 1))
 +#define RATE_MASK(x)          (0x1 << (x + 16))
 +#define RATE_SET(x)           (0x1 << (x + 16))
 +
- void gpio_direction_output(struct s5pc1xx_gpio_bank *bank, int gpio, int en)
++void gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg)
 +{
 +      unsigned int value;
 +
 +      value = readl(&bank->con);
 +      value &= ~CON_MASK(gpio);
 +      value |= CON_SFR(gpio, cfg);
 +      writel(value, &bank->con);
 +#if 0
 +      if (s5pc1xx_get_cpu_rev() == 0)
 +#endif
 +              value = readl(&bank->con);
 +}
 +
- void gpio_direction_input(struct s5pc1xx_gpio_bank *bank, int gpio)
++void gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en)
 +{
 +      unsigned int value;
 +
 +      gpio_cfg_pin(bank, gpio, GPIO_OUTPUT);
 +
 +      value = readl(&bank->dat);
 +      value &= ~DAT_MASK(gpio);
 +      if (en)
 +              value |= DAT_SET(gpio);
 +      writel(value, &bank->dat);
 +#if 0
 +      if (s5pc1xx_get_cpu_rev() == 0)
 +#endif
 +              value = readl(&bank->dat);
 +}
 +
- void gpio_set_value(struct s5pc1xx_gpio_bank *bank, int gpio, int en)
++void gpio_direction_input(struct s5p_gpio_bank *bank, int gpio)
 +{
 +      gpio_cfg_pin(bank, gpio, GPIO_INPUT);
 +}
 +
- unsigned int gpio_get_value(struct s5pc1xx_gpio_bank *bank, int gpio)
++void gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en)
 +{
 +      unsigned int value;
 +
 +      value = readl(&bank->dat);
 +      value &= ~DAT_MASK(gpio);
 +      if (en)
 +              value |= DAT_SET(gpio);
 +      writel(value, &bank->dat);
 +#if 0
 +      if (s5pc1xx_get_cpu_rev() == 0)
 +#endif
 +              value = readl(&bank->dat);
 +}
 +
- void gpio_set_pull(struct s5pc1xx_gpio_bank *bank, int gpio, int mode)
++unsigned int gpio_get_value(struct s5p_gpio_bank *bank, int gpio)
 +{
 +      unsigned int value;
 +
 +      value = readl(&bank->dat);
 +      return !!(value & DAT_MASK(gpio));
 +}
 +
- void gpio_set_drv(struct s5pc1xx_gpio_bank *bank, int gpio, int mode)
++void gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode)
 +{
 +      unsigned int value;
 +
 +      value = readl(&bank->pull);
 +      value &= ~PULL_MASK(gpio);
 +
 +      switch (mode) {
 +      case GPIO_PULL_DOWN:
 +      case GPIO_PULL_UP:
 +              value |= PULL_MODE(gpio, mode);
 +              break;
 +      default:
 +              break;
 +      }
 +
 +      writel(value, &bank->pull);
 +#if 0
 +      if (s5pc1xx_get_cpu_rev() == 0)
 +#endif
 +              value = readl(&bank->pull);
 +}
 +
- void gpio_set_rate(struct s5pc1xx_gpio_bank *bank, int gpio, int mode)
++void gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode)
 +{
 +      unsigned int value;
 +
 +      value = readl(&bank->drv);
 +      value &= ~DRV_MASK(gpio);
 +
 +      switch (mode) {
 +      case GPIO_DRV_1X:
 +      case GPIO_DRV_2X:
 +      case GPIO_DRV_3X:
 +      case GPIO_DRV_4X:
 +              value |= DRV_SET(gpio, mode);
 +              break;
 +      default:
 +              return;
 +      }
 +
 +      writel(value, &bank->drv);
 +#if 0
 +      if (s5pc1xx_get_cpu_rev() == 0)
 +#endif
 +              value = readl(&bank->drv);
 +}
 +
++void gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode)
 +{
 +      unsigned int value;
 +
 +      value = readl(&bank->drv);
 +      value &= ~RATE_MASK(gpio);
 +
 +      switch (mode) {
 +      case GPIO_DRV_FAST:
 +      case GPIO_DRV_SLOW:
 +              value |= RATE_SET(gpio);
 +              break;
 +      default:
 +              return;
 +      }
 +
 +      writel(value, &bank->drv);
 +#if 0
 +      if (s5pc1xx_get_cpu_rev() == 0)
 +#endif
 +              value = readl(&bank->drv);
 +}
 +
index 4dab615,0000000..3c25ffb
mode 100644,000000..100644
--- /dev/null
@@@ -1,657 -1,0 +1,657 @@@
- static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
 +/*
 + * Copyright (C) 2009-2010 Samsung Electronics
 + */
 +
 +#include <common.h>
 +#include <linux/mtd/mtd.h>
 +#include <linux/mtd/onenand.h>
 +#include <asm/io.h>
 +#include <asm/arch/cpu.h>
 +#include <asm/arch/gpio.h>
 +#include <asm/arch/keypad.h>
 +#include <asm/arch/power.h>
 +#include "recovery.h"
 +#include "onenand.h"
 +
 +#ifdef RECOVERY_DEBUG
 +#define       PUTS(s) serial_puts(DEBUG_MARK""s)
 +#else
 +#define PUTS(s)
 +#endif
 +
 +#define C110_MACH_START               3100
 +#define C100_MACH_START               3000
 +
 +/* board is MACH_AQUILA and board is like below. */
 +#define J1_B2_BOARD           0x0200
 +#define LIMO_UNIVERSAL_BOARD  0x0400
 +#define LIMO_REAL_BOARD               0x0800
 +#define MEDIA_BOARD           0x1000
 +#define BAMBOO_BOARD          0x2000
 +
 +/* board is MACH_GONI and board is like below */
 +#define S1_BOARD              0x1000
 +#define KESSLER_BOARD         0x4000
 +#define SDK_BOARD             0x8000
 +
 +#define BOARD_MASK            0xFF00
 +
 +enum {
 +      MACH_UNIVERSAL,
 +      MACH_TICKERTAPE,
 +      MACH_CHANGED,
 +      MACH_P1P2,      /* Don't remove it */
 +      MACH_GEMINUS,
 +      MACH_CYPRESS,
 +
 +      MACH_WMG160 = 160,
 +
 +      MACH_PSEUDO_END,
 +
 +      MACH_GONI = 3102,
 +};
 +
 +typedef int (init_fnc_t) (void);
 +
 +static bd_t bd;
 +
 +static unsigned int board_rev;
 +
 +static void sdelay(unsigned long usec)
 +{
 +      ulong kv;
 +
 +      do {
 +              kv = 0x100000;
 +              while (kv)
 +                      kv--;
 +              usec--;
 +      } while (usec);
 +}
 +
 +static int hwrevision(int rev)
 +{
 +      return (board_rev & 0xf) == rev;
 +}
 +
 +static int c110_machine_id(void)
 +{
 +      return bd.bi_arch_number - C110_MACH_START;
 +}
 +
 +static int mach_is_aquila(void)
 +{
 +      return bd.bi_arch_number == MACH_TYPE_AQUILA;
 +}
 +
 +static int mach_is_geminus(void)
 +{
 +      return c110_machine_id() == MACH_GEMINUS;
 +}
 +
 +static int board_is_limo_universal(void)
 +{
 +      return mach_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
 +}
 +
 +static int board_is_limo_real(void)
 +{
 +      return mach_is_aquila() && (board_rev & LIMO_REAL_BOARD);
 +}
 +
 +/* Kessler */
 +static int mach_is_goni(void)
 +{
 +      return bd.bi_arch_number == MACH_GONI;
 +}
 +
 +static int board_is_sdk(void)
 +{
 +      return mach_is_goni() && (board_rev & SDK_BOARD);
 +}
 +
 +static void check_board_revision(int board, int rev)
 +{
 +      if (board == MACH_TYPE_AQUILA) {
 +              /* Limo Real or Universal */
 +              if (rev & LIMO_UNIVERSAL_BOARD)
 +                      board_rev &= ~J1_B2_BOARD;
 +              if (rev & LIMO_REAL_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & MEDIA_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & BAMBOO_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD |
 +                                      LIMO_REAL_BOARD |
 +                                      MEDIA_BOARD);
 +      } else if (board == MACH_GONI) {
 +              if (rev & KESSLER_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & SDK_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD |
 +                                      LIMO_UNIVERSAL_BOARD);
 +              if (rev & S1_BOARD)
 +                      board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
 +                                      LIMO_REAL_BOARD);
 +      } else {
 +              board_rev &= ~BOARD_MASK;
 +      }
 +}
 +
++static unsigned int get_hw_revision(struct s5p_gpio_bank *bank, int hwrev3)
 +{
 +      unsigned int rev;
 +
 +      gpio_direction_input(bank, 2);
 +      gpio_direction_input(bank, 3);
 +      gpio_direction_input(bank, 4);
 +      gpio_direction_input(bank, hwrev3);
 +
 +      gpio_set_pull(bank, 2, GPIO_PULL_NONE);         /* HWREV_MODE0 */
 +      gpio_set_pull(bank, 3, GPIO_PULL_NONE);         /* HWREV_MODE1 */
 +      gpio_set_pull(bank, 4, GPIO_PULL_NONE);         /* HWREV_MODE2 */
 +      gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE);    /* HWREV_MODE3 */
 +
 +      rev = gpio_get_value(bank, 2);
 +      rev |= (gpio_get_value(bank, 3) << 1);
 +      rev |= (gpio_get_value(bank, 4) << 2);
 +      rev |= (gpio_get_value(bank, hwrev3) << 3);
 +
 +      return rev;
 +}
 +
 +static void check_hw_revision(void)
 +{
 +      unsigned int board = MACH_UNIVERSAL;    /* Default is Universal */
 +
 +      if (cpu_is_s5pc100()) {
 +              struct s5pc100_gpio *gpio =
 +                      (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
 +
 +              board_rev = get_hw_revision(&gpio->gpio_j0, 0);
 +
 +              /* C100 TickerTape */
 +              if (board_rev == 3)
 +                      board = MACH_TICKERTAPE;
 +      } else {
 +              struct s5pc110_gpio *gpio =
 +                      (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
 +              int hwrev3 = 1;
 +
 +              board_rev = 0;
 +
 +              /*
 +               * Note Check 'Aquila' board first
 +               *
 +               * TT: TickerTape
 +               * SS: SplitScreen
 +               * LRA: Limo Real Aquila
 +               * LUA: Limo Universal Aquila
 +               * OA: Old Aquila
 +               * CYP: Cypress
 +               * BB: Bamboo
 +               *
 +               * ADDR = 0xE0200000 + OFF
 +               *
 +               *       OFF    Universal BB   LRA  LUA  OA   TT   SS       CYP
 +               *   J1: 0x0264 0x10      0x10 0x00 0x00 0x00 0x00 0x00
 +               *   J2: 0x0284           0x01 0x10 0x00
 +               *   H1: 0x0C24    W           0x28 0xA8 0x1C               0x0F
 +               *   H3: 0x0C64                0x03 0x07 0x0F
 +               *   D1: 0x00C4 0x0F           0x3F 0x3F 0x0F 0xXC 0x3F
 +               *    I: 0x0224                          0x02 0x00 0x08
 +               * MP03: 0x0324                          0x9x      0xbx 0x9x
 +               * MP05: 0x0364                          0x80      0x88
 +               */
 +
 +              /* C110 Aquila */
 +              if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
 +                      board = MACH_TYPE_AQUILA;
 +                      board_rev |= J1_B2_BOARD;
 +
 +                      gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
 +                      gpio_direction_input(&gpio->gpio_j2, 6);
 +
 +                      /* Check board */
 +                      if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
 +                              board_rev |= LIMO_UNIVERSAL_BOARD;
 +
 +                      if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
 +                              board_rev |= LIMO_REAL_BOARD;
 +
 +                      if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
 +                              board_rev |= MEDIA_BOARD;
 +
 +                      /* set gpio to default value. */
 +                      gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
 +                      gpio_direction_output(&gpio->gpio_j2, 6, 0);
 +              }
 +
 +              /* Workaround: C110 Aquila Rev0.6 */
 +              if (board_rev == 6) {
 +                      board = MACH_TYPE_AQUILA;
 +                      board_rev |= LIMO_REAL_BOARD;
 +              }
 +
 +              /* C110 Aquila Bamboo */
 +              if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
 +                      board = MACH_TYPE_AQUILA;
 +                      board_rev |= BAMBOO_BOARD;
 +              }
 +
 +              /* C110 TickerTape */
 +              if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
 +                              gpio_get_value(&gpio->gpio_d1, 1) == 0)
 +                      board = MACH_TICKERTAPE;
 +
 +              /* WMG160 - GPH3[0:4] = 0x00 */
 +              if (board == MACH_TICKERTAPE) {
 +                      int i, wmg160 = 1;
 +
 +                      for (i = 0; i < 4; i++) {
 +                              if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
 +                                      wmg160 = 0;
 +                                      break;
 +                              }
 +                      }
 +                      if (wmg160) {
 +                              board = MACH_WMG160;
 +                              hwrev3 = 7;
 +                      }
 +              }
 +
 +              /* C110 Geminus for rev0.0 */
 +              gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
 +              gpio_direction_input(&gpio->gpio_j1, 2);
 +              if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
 +                      board = MACH_GEMINUS;
 +                      if ((board_rev & ~BOARD_MASK) == 3)
 +                              board_rev &= ~0xff;
 +              }
 +              gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
 +              gpio_direction_output(&gpio->gpio_j1, 2, 0);
 +
 +              /* C110 Geminus for rev0.1 ~ */
 +              gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
 +              gpio_direction_input(&gpio->gpio_j0, 6);
 +              if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
 +                      board = MACH_GEMINUS;
 +                      hwrev3 = 7;
 +              }
 +              gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
 +
 +              /* Kessler MP0_5[6] == 1 */
 +              gpio_direction_input(&gpio->gpio_mp0_5, 6);
 +              if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
 +                      /* Cypress: Do this for cypress */
 +                      gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
 +                      gpio_direction_input(&gpio->gpio_j2, 2);
 +                      if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
 +                              board = MACH_CYPRESS;
 +                              gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
 +                      } else {
 +                              board = MACH_GONI;
 +                              board_rev |= KESSLER_BOARD;
 +
 +                              /* Limo SDK MP0_5[4] == 1 */
 +                              gpio_direction_input(&gpio->gpio_mp0_5, 4);
 +                              if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
 +                                      board_rev &= ~KESSLER_BOARD;
 +                                      board_rev |= SDK_BOARD;
 +                              }
 +                      }
 +                      gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
 +                      hwrev3 = 7;
 +              } else {
 +                      gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
 +                      /* Goni S1 board detection */
 +                      if (board == MACH_TICKERTAPE) {
 +                              board = MACH_GONI;
 +                              board_rev |= S1_BOARD;
 +                              hwrev3 = 7;
 +                      }
 +              }
 +
 +              board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
 +      }
 +
 +      /* Set machine id */
 +      if (board < MACH_PSEUDO_END) {
 +              if (cpu_is_s5pc110())
 +                      bd.bi_arch_number = C110_MACH_START + board;
 +              else
 +                      bd.bi_arch_number = C100_MACH_START + board;
 +      } else {
 +              bd.bi_arch_number = board;
 +      }
 +}
 +
 +static void show_hw_revision(void)
 +{
 +      int board;
 +
 +      /*
 +       * Workaround for Rev 0.3 + CP Ver ES 3.1
 +       * it's Rev 0.4
 +       */
 +      if (board_is_limo_real()) {
 +              if (hwrevision(0)) {
 +                      /* default is Rev 0.4 */
 +                      board_rev &= ~0xf;
 +                      board_rev |= 0x4;
 +              }
 +      }
 +
 +      if (mach_is_goni() || mach_is_aquila())
 +              board = bd.bi_arch_number;
 +      else if (cpu_is_s5pc110())
 +              board = bd.bi_arch_number - C110_MACH_START;
 +      else
 +              board = bd.bi_arch_number - C100_MACH_START;
 +
 +      check_board_revision(board, board_rev);
 +
 +      /* Set CPU Revision */
 +      if (mach_is_aquila()) {
 +              if (board_is_limo_real()) {
 +                      if ((board_rev & 0xf) < 8)
 +                              s5pc1xx_set_cpu_rev(0);
 +              }
 +      } else if (mach_is_goni()) {
 +              if (board_is_sdk() && hwrevision(2))
 +                      s5pc1xx_set_cpu_rev(2); /* EVT1-Fused */
 +              else
 +                      s5pc1xx_set_cpu_rev(1);
 +      } else if (mach_is_geminus()) {
 +              if ((board_rev & 0xf) < 1)
 +                      s5pc1xx_set_cpu_rev(0);
 +      } else {
 +              s5pc1xx_set_cpu_rev(0);
 +      }
 +
 +      if (cpu_is_s5pc110())
 +              writel(0xc1100000 | (0xffff & (s5pc1xx_get_cpu_rev() ? 1 : 0)),
 +                              S5PC110_INFORM3);
 +}
 +
 +static int check_keypad(void)
 +{
 +      uint condition = 0;
 +      uint reg, value;
 +      uint col_num, row_num;
 +      uint col_mask;
 +      uint col_mask_shift;
 +      uint row_state[4] = {0, 0, 0, 0};
 +      uint i;
 +      int cpu_rev;
 +
 +      if (cpu_is_s5pc100()) {
 +              struct s5pc100_gpio *gpio =
 +                      (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
 +
 +              row_num = 3;
 +              col_num = 3;
 +
 +              /* Set GPH2[2:0] to KP_COL[2:0] */
 +              gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
 +
 +              /* Set GPH3[2:0] to KP_ROW[2:0] */
 +              gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
 +              gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
 +
 +              reg = S5PC100_KEYPAD_BASE;
 +              col_mask = S5PC1XX_KEYIFCOL_MASK;
 +              col_mask_shift = 0;
 +      } else {
 +              struct s5pc110_gpio *gpio =
 +                      (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +              if (board_is_limo_real() || board_is_limo_universal()) {
 +                      row_num = 2;
 +                      col_num = 3;
 +              } else {
 +                      row_num = 4;
 +                      col_num = 4;
 +              }
 +
 +              for (i = 0; i < row_num; i++) {
 +                      /* Set GPH3[3:0] to KP_ROW[3:0] */
 +                      gpio_cfg_pin(&gpio->gpio_h3, i, 0x3);
 +                      gpio_set_pull(&gpio->gpio_h3, i, GPIO_PULL_UP);
 +              }
 +
 +              for (i = 0; i < col_num; i++)
 +                      /* Set GPH2[3:0] to KP_COL[3:0] */
 +                      gpio_cfg_pin(&gpio->gpio_h2, i, 0x3);
 +
 +              reg = S5PC110_KEYPAD_BASE;
 +              col_mask = S5PC110_KEYIFCOLEN_MASK;
 +              col_mask_shift = 8;
 +      }
 +
 +      /* KEYIFCOL reg clear */
 +      writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +
 +      /* key_scan */
 +      for (i = 0; i < col_num; i++) {
 +              value = col_mask;
 +              value &= ~(1 << i) << col_mask_shift;
 +
 +              writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +              sdelay(1000);
 +
 +              value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
 +              row_state[i] = ~value & ((1 << row_num) - 1);
 +      }
 +
 +      /* KEYIFCOL reg clear */
 +      writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
 +
 +      cpu_rev = s5pc1xx_get_cpu_rev();
 +      if (cpu_rev == 1) {
 +              if ((row_state[1] & 0x6) == 0x6)
 +                      condition = 1;
 +      } else if (cpu_rev == 2) {
 +              if ((row_state[2] & 0x6) == 0x6)
 +                      condition = 1;
 +      } else {
 +              if ((row_state[1] & 0x3) == 0x3)
 +                      condition = 1;
 +      }
 +
 +      return condition;
 +}
 +
 +static int check_block(void)
 +{
 +      struct onenand_op *onenand_ops = onenand_get_interface();
 +      struct mtd_info *mtd = onenand_ops->mtd;
 +      struct onenand_chip *this = mtd->priv;
 +      int i;
 +      int retlen = 0;
 +      u32 from = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift;
 +      u32 len = 1 << this->erase_shift;
 +      u32 *buf = (u32 *)CONFIG_SYS_DOWN_ADDR;
 +
 +      /* check first page of bootloader*/
 +      onenand_ops->read(from, len, (ssize_t *)&retlen, (u_char *)buf, 0);
 +      if (retlen != len)
 +              return 1;
 +
 +      for (i = 0; i < (this->writesize / sizeof(this->writesize)); i++)
 +              if (*(buf + i) != 0xffffffff)
 +                      return 0;
 +
 +      return 1;
 +}
 +
 +int board_check_condition(void)
 +{
 +      if (check_keypad()) {
 +              PUTS("check: manual\n");
 +              return 1;
 +      }
 +
 +      if (check_block()) {
 +              PUTS("check: bootloader broken\n");
 +              return 2;
 +      }
 +
 +      return 0;
 +}
 +
 +int board_load_bootloader(unsigned char *buf)
 +{
 +      struct mtd_info *mtd = &onenand_mtd;
 +      struct onenand_chip *this = mtd->priv;
 +      u32 ofs, len, retlen;
 +
 +      ofs = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift;
 +      len = CONFIG_SYS_MONITOR_LEN;
 +
 +      mtd->read(mtd, ofs, len, &retlen, buf);
 +
 +      if (len != retlen)
 +              return -1;
 +
 +      return 0;
 +}
 +
 +int board_lock_recoveryblock(void)
 +{
 +      struct mtd_info *mtd = &onenand_mtd;
 +      struct onenand_chip *this = mtd->priv;
 +      u32 ofs = 0;
 +      u32 len = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift;
 +      int ret = 0;
 +
 +      /* lock-tight the recovery block */
 +      if (this->lock_tight != NULL)
 +              ret = this->lock_tight(mtd, ofs, len);
 +
 +      return ret;
 +}
 +
 +void board_update_init(void)
 +{
 +      struct mtd_info *mtd = &onenand_mtd;
 +      struct onenand_chip *this = mtd->priv;
 +
 +      /* Unlock whole block */
 +      this->unlock_all(mtd);
 +}
 +
 +int board_update_image(u32 *buf, u32 len)
 +{
 +      struct onenand_op *onenand_ops = onenand_get_interface();
 +      struct mtd_info *mtd = &onenand_mtd;
 +      struct onenand_chip *this = mtd->priv;
 +      u32 ofs;
 +      u32 ipl_addr = 0;
 +      u32 ipl_edge = CONFIG_ONENAND_START_PAGE << this->page_shift;
 +      u32 recovery_addr = ipl_edge;
 +      u32 recovery_edge = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift;
 +      u32 bootloader_addr = recovery_edge;
 +      int ret, retlen;
 +
 +      if (len > bootloader_addr) {
 +              if (*(buf + bootloader_addr/sizeof(buf)) == 0xea000012) {
 +                      /* case: IPL + Recovery + bootloader */
 +                      PUTS("target: ipl + recovery + bootloader\n");
 +                      ofs = ipl_addr;
 +                      /* len = bootloader_edge; */
 +              } else {
 +                      /* case: unknown format */
 +                      PUTS("target: unknown\n");
 +                      return 1;
 +              }
 +      } else {
 +              if (*(buf + recovery_addr/sizeof(buf)) == 0xea000012 &&
 +                      *(buf + recovery_addr/sizeof(buf) - 1) == 0x00000000) {
 +                      /* case: old image (IPL + bootloader) */
 +                      PUTS("target: ipl + bootloader (old type)\n");
 +                      ofs = ipl_addr;
 +                      /* len = recovery_edge; */
 +              } else {
 +                      /* case: bootloader only */
 +                      PUTS("target: bootloader\n");
 +                      ofs = bootloader_addr;
 +                      /* len = bootloader_edge - recovery_edge; */
 +              }
 +      }
 +
 +#ifdef CONFIG_S5PC1XX
 +      /* Workaround: for prevent revision mismatch */
 +      if (cpu_is_s5pc110() && (ofs == 0)) {
 +              int img_rev;
 +
 +              if (*buf == 0xea000012)
 +                      img_rev = 0;
 +              else if (*(buf + 0x400) == 0xea000012)
 +                      img_rev = 2;
 +              else
 +                      img_rev = 1;
 +
 +              if (img_rev != s5pc1xx_get_cpu_rev()) {
 +                      PUTS("target check: CPU revision mismatch!\n");
 +                      PUTS("target check: system is ");
 +                      if (s5pc1xx_get_cpu_rev() == 1)
 +                              serial_puts("EVT1\n");
 +                      else if (s5pc1xx_get_cpu_rev() == 2)
 +                              serial_puts("EVT1-Fused\n");
 +                      else
 +                              serial_puts("EVT0\n");
 +                      PUTS("target check: download image is ");
 +                      if (img_rev == 1)
 +                              serial_puts("EVT1\n");
 +                      else if (img_rev == 2)
 +                              serial_puts("EVT1-Fused\n");
 +                      else
 +                              serial_puts("EVT0\n");
 +                      PUTS("try again.");
 +                      return 1;
 +              }
 +      }
 +#endif
 +
 +      /* Erase */
 +      ret = onenand_ops->erase(ofs, len, 0);
 +      if (ret)
 +              return ret;
 +
 +      /* Write */
 +      onenand_ops->write(ofs, len, (ssize_t *)&retlen, (u_char *)buf);
 +      if (ret)
 +              return ret;
 +
 +      return 0;
 +}
 +
 +void board_recovery_init(void)
 +{
 +      struct s5pc110_gpio *gpio_base =
 +              (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
 +
 +      /* basic arch cpu dependent setup */
 +      arch_cpu_init();
 +
 +      /* Check H/W Revision */
 +      check_hw_revision();
 +
 +      show_hw_revision();
 +
 +      /* set GPIO to enable UART2 */
 +      gpio_cfg_pin(&gpio_base->gpio_a1, 0, 0x2);
 +      gpio_cfg_pin(&gpio_base->gpio_a1, 1, 0x2);
 +
 +      /* UART_SEL MP0_5[7] at S5PC110 */
 +      gpio_direction_output(&gpio_base->gpio_mp0_5, 7, 0x1);
 +      gpio_set_pull(&gpio_base->gpio_mp0_5, 7, GPIO_PULL_DOWN);
 +}
index 76be7a8,0000000..5743ee1
mode 100644,000000..100644
--- /dev/null
@@@ -1,249 -1,0 +1,264 @@@
 +#
 +# Copyright (C) 2010 Samsung Electronics
 +#
 +
 +#########################################################################
 +
 +ifneq ($(OBJTREE),$(SRCTREE))
 +ifeq ($(CURDIR),$(SRCTREE))
 +dir :=
 +else
 +dir := $(subst $(SRCTREE)/,,$(CURDIR))
 +endif
 +
 +obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
 +src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
 +
 +$(shell mkdir -p $(obj))
 +else
 +obj :=
 +src :=
 +endif
 +
 +# clean the slate ...
 +PLATFORM_RELFLAGS =
 +PLATFORM_CPPFLAGS =
 +PLATFORM_LDFLAGS =
 +
 +#########################################################################
 +
 +HOSTCFLAGS    = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
 +                $(HOSTCPPFLAGS)
 +HOSTSTRIP     = strip
 +
 +#
 +# Mac OS X / Darwin's C preprocessor is Apple specific.  It
 +# generates numerous errors and warnings.  We want to bypass it
 +# and use GNU C's cpp.  To do this we pass the -traditional-cpp
 +# option to the compiler.  Note that the -traditional-cpp flag
 +# DOES NOT have the same semantics as GNU C's flag, all it does
 +# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
 +#
 +# Apple's linker is similar, thanks to the new 2 stage linking
 +# multiple symbol definitions are treated as errors, hence the
 +# -multiply_defined suppress option to turn off this error.
 +#
 +
 +ifeq ($(HOSTOS),darwin)
 +HOSTCC                = cc
 +HOSTCFLAGS    += -traditional-cpp
 +HOSTLDFLAGS   += -multiply_defined suppress
 +else
 +HOSTCC                = gcc
 +endif
 +
 +ifeq ($(HOSTOS),cygwin)
 +HOSTCFLAGS    += -ansi
 +endif
 +
 +# We build some files with extra pedantic flags to try to minimize things
 +# that won't build on some weird host compiler -- though there are lots of
 +# exceptions for files that aren't complaint.
 +
 +HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
 +HOSTCFLAGS    += -pedantic
 +
 +#########################################################################
 +#
 +# Option checker (courtesy linux kernel) to ensure
 +# only supported compiler options are used
 +#
 +cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
 +              > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 +
 +#
 +# Include the make variables (CC, etc...)
 +#
 +AS    = $(CROSS_COMPILE)as
 +LD    = $(CROSS_COMPILE)ld
 +CC    = $(CROSS_COMPILE)gcc
 +CPP   = $(CC) -E
 +AR    = $(CROSS_COMPILE)ar
 +NM    = $(CROSS_COMPILE)nm
 +LDR   = $(CROSS_COMPILE)ldr
 +STRIP = $(CROSS_COMPILE)strip
 +OBJCOPY = $(CROSS_COMPILE)objcopy
 +OBJDUMP = $(CROSS_COMPILE)objdump
 +RANLIB        = $(CROSS_COMPILE)RANLIB
 +
 +#########################################################################
 +
 +# Load generated board configuration
 +sinclude $(OBJTREE)/include/autoconf.mk
 +
++# Some architecture config.mk files need to know what CPUDIR is set to,
++# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
++# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
++# CPU-specific code.
++CPUDIR=arch/$(ARCH)/cpu/$(CPU)
++ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
++CPUDIR=arch/$(ARCH)/cpu
++endif
++
++sinclude $(TOPDIR)/arch/$(ARCH)/config.mk     # include architecture dependend rules
++sinclude $(TOPDIR)/$(CPUDIR)/config.mk                # include  CPU  specific rules
++
++ifdef SOC
++sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include  SoC  specific rules
++endif
 +ifdef VENDOR
 +BOARDDIR = $(VENDOR)/$(BOARD)
 +else
 +BOARDDIR = $(BOARD)
 +endif
 +ifdef BOARD
 +sinclude $(TOPDIR)/$(RECOVERY_BLOCK)/board/$(BOARDDIR)/config.mk
 +endif
 +
 +#########################################################################
 +
 +# sinclude $(TOPDIR)/lib_$(ARCH)/config.mk
 +
 +CROSS_COMPILE ?= arm-linux-
 +
 +PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM__
 +
 +# Explicitly specifiy 32-bit ARM ISA since toolchain default can be -mthumb:
 +PLATFORM_CPPFLAGS += $(call cc-option,-marm,)
 +
 +# Try if EABI is supported, else fall back to old API,
 +# i. e. for example:
 +# - with ELDK 4.2 (EABI supported), use:
 +#     -mabi=aapcs-linux -mno-thumb-interwork
 +# - with ELDK 4.1 (gcc 4.x, no EABI), use:
 +#     -mabi=apcs-gnu -mno-thumb-interwork
 +# - with ELDK 3.1 (gcc 3.x), use:
 +#     -mapcs-32 -mno-thumb-interwork
 +PLATFORM_CPPFLAGS += $(call cc-option,\
 +                              -mabi=aapcs-linux -mno-thumb-interwork,\
 +                              $(call cc-option,\
 +                                      -mapcs-32,\
 +                                      $(call cc-option,\
 +                                              -mabi=apcs-gnu,\
 +                                      )\
 +                              ) $(call cc-option,-mno-thumb-interwork,)\
 +                      )
 +
 +# For EABI, make sure to provide raise()
 +ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))
 +# This file is parsed several times; make sure to add only once.
 +ifeq (,$(findstring lib_arm/eabi_compat.o,$(PLATFORM_LIBS)))
 +PLATFORM_LIBS += $(OBJTREE)/lib_arm/eabi_compat.o
 +endif
 +endif
 +LDSCRIPT := $(SRCTREE)/$(RECOVERY_BLOCK)/board/$(BOARDDIR)/recovery.lds
 +
 +#########################################################################
 +
 +# sinclude $(TOPDIR)/cpu/$(CPU)/config.mk
 +PLATFORM_RELFLAGS += -fno-strict-aliasing -fno-common -ffixed-r8 \
 +                   -msoft-float
 +
 +# Make ARMv5 to allow more compilers to work, even though its v7a.
 +PLATFORM_CPPFLAGS += -march=armv5
 +# =========================================================================
 +#
 +# Supply options according to compiler version
 +#
 +# =========================================================================
 +PLATFORM_RELFLAGS +=$(call cc-option,-mshort-load-bytes,\
 +                  $(call cc-option,-malignment-traps,))
 +
 +#########################################################################
 +
 +ifneq (,$(findstring s,$(MAKEFLAGS)))
 +ARFLAGS = cr
 +else
 +ARFLAGS = crv
 +endif
 +RELFLAGS= $(PLATFORM_RELFLAGS)
 +DBGFLAGS= -g # -DDEBUG
 +OPTFLAGS= -Os #-fomit-frame-pointer
 +OBJCFLAGS += --gap-fill=0x00
 +
 +gccincdir := $(shell $(CC) -print-file-name=include)
 +
 +CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS)               \
 +      -D__KERNEL__
 +ifneq ($(TEXT_BASE),)
 +CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
 +endif
 +
 +ifneq ($(RESET_VECTOR_ADDRESS),)
 +CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
 +endif
 +
 +ifneq ($(OBJTREE),$(SRCTREE))
 +CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
 +endif
 +
 +CPPFLAGS += -I$(TOPDIR)/include
 +CPPFLAGS += -fno-builtin -ffreestanding -nostdinc     \
 +      -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
 +
 +CPPFLAGS += -I$(TOPDIR)/$(RECOVERY_BLOCK)
 +CPPFLAGS += -DCONFIG_RECOVERY_BLOCK -D__HAVE_ARCH_MEMCPY32
 +CPPFLAGS += -DRECOVERY_DEBUG
 +
 +ifdef BUILD_TAG
 +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
 +      -DBUILD_TAG='"$(BUILD_TAG)"'
 +else
 +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
 +endif
 +
 +CFLAGS += $(call cc-option,-fno-stack-protector)
 +
 +# avoid trigraph warnings while parsing pci.h (produced by NIOS gcc-2.9)
 +# this option have to be placed behind -Wall -- that's why it is here
 +ifeq ($(ARCH),nios)
 +ifeq ($(findstring 2.9,$(shell $(CC) --version)),2.9)
 +CFLAGS := $(CPPFLAGS) -Wall -Wno-trigraphs
 +endif
 +endif
 +
 +# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
 +# option to the assembler.
 +AFLAGS_DEBUG :=
 +
 +# turn jbsr into jsr for m68k
 +ifeq ($(ARCH),m68k)
 +ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
 +AFLAGS_DEBUG := -Wa,-gstabs,-S
 +endif
 +endif
 +
 +AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
 +
 +LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS)
 +ifneq ($(TEXT_BASE),)
 +LDFLAGS += -Ttext $(TEXT_BASE)
 +endif
 +
 +#########################################################################
 +
 +export        HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
 +      AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
 +export        TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
 +
 +#########################################################################
 +
 +# Allow boards to use custom optimize flags on a per dir/file basis
 +BCURDIR := $(notdir $(CURDIR))
 +$(obj)%.s:    %.S
 +      $(CPP) $(AFLAGS) $(AFLAGS_$(@F)) $(AFLAGS_$(BCURDIR)) -o $@ $<
 +$(obj)%.o:    %.S
 +      $(CC)  $(AFLAGS) $(AFLAGS_$(@F)) $(AFLAGS_$(BCURDIR)) -o $@ $< -c
 +$(obj)%.o:    %.c
 +      $(CC)  $(CFLAGS) $(CFLAGS_$(@F)) $(CFLAGS_$(BCURDIR)) -o $@ $< -c
 +$(obj)%.i:    %.c
 +      $(CPP) $(CFLAGS) $(CFLAGS_$(@F)) $(CFLAGS_$(BCURDIR)) -o $@ $< -c
 +$(obj)%.s:    %.c
 +      $(CC)  $(CFLAGS) $(CFLAGS_$(@F)) $(CFLAGS_$(BCURDIR)) -o $@ $< -c -S
 +
 +#########################################################################
index 18207ff,0000000..1bf5508
mode 100644,000000..100644
--- /dev/null
@@@ -1,180 -1,0 +1,181 @@@
- static inline struct s5pc1xx_uart *s5pc1xx_get_base_uart(int dev_index)
 +/*
 + * Copyright (C) 2009 Samsung Electronics
 + * Minkyu Kang <mk7.kang@samsung.com>
 + * Heungjun Kim <riverful.kim@samsung.com>
 + */
 +
 +#include <common.h>
 +#include <asm/io.h>
 +#include <asm/arch/uart.h>
 +#include <asm/arch/clk.h>
 +#include <serial.h>
 +
-       u32 offset = dev_index * sizeof(struct s5pc1xx_uart);
++static inline struct s5p_uart *s5pc1xx_get_base_uart(int dev_index)
 +{
-       return (struct s5pc1xx_uart *)(S5PC110_UART_BASE + offset);
++      u32 offset = dev_index * sizeof(struct s5p_uart);
 +
-       struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index);
++      return (struct s5p_uart *)(S5PC110_UART_BASE + offset);
 +}
 +
 +/*
 + * The coefficient, used to calculate the baudrate on S3C6400 UARTs is
 + * calculated as
 + * C = UBRDIV * 16 + number_of_set_bits_in_UDIVSLOT
 + * however, section 31.6.11 of the datasheet doesn't recomment using 1 for 1,
 + * 3 for 2, ... (2^n - 1) for n, instead, they suggest using these constants:
 + */
 +static const int udivslot[] = {
 +      0,
 +      0x0080,
 +      0x0808,
 +      0x0888,
 +      0x2222,
 +      0x4924,
 +      0x4a52,
 +      0x54aa,
 +      0x5555,
 +      0xd555,
 +      0xd5d5,
 +      0xddd5,
 +      0xdddd,
 +      0xdfdd,
 +      0xdfdf,
 +      0xffdf,
 +};
 +
 +void serial_setbrg_dev(const int dev_index)
 +{
-       struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index);
++      struct s5p_uart *const uart = s5pc1xx_get_base_uart(dev_index);
 +
 +      /* baudrate: 115200*/
 +      writel(0x23, &uart->ubrdiv);
 +      writew(udivslot[2], &uart->udivslot);
 +}
 +
 +/*
 + * Initialise the serial port with the given baudrate. The settings
 + * are always 8 data bits, no parity, 1 stop bit, no start bits.
 + */
 +int serial_init_dev(const int dev_index)
 +{
-       struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index);
++      struct s5p_uart *const uart = s5pc1xx_get_base_uart(dev_index);
 +
 +      /* reset and enable FIFOs, set triggers to the maximum */
 +      writel(0, &uart->ufcon);
 +      writel(0, &uart->umcon);
 +      /* 8N1 */
 +      writel(0x3, &uart->ulcon);
 +      /* No interrupts, no DMA, pure polling */
 +      writel(0x245, &uart->ucon);
 +
 +      serial_setbrg_dev(dev_index);
 +
 +      return 0;
 +}
 +
 +static int serial_err_check(const int dev_index, int op)
 +{
-       struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index);
++      struct s5p_uart *const uart = s5pc1xx_get_base_uart(dev_index);
 +      unsigned int mask;
 +
 +      /*
 +       * UERSTAT
 +       * Break Detect [3]
 +       * Frame Err    [2] : receive operation
 +       * Parity Err   [1] : receive operation
 +       * Overrun Err  [0] : receive operation
 +       */
 +      if (op)
 +              mask = 0x8;
 +      else
 +              mask = 0xf;
 +
 +      return readl(&uart->uerstat) & mask;
 +}
 +
 +/*
 + * Read a single byte from the serial port. Returns 1 on success, 0
 + * otherwise. When the function is succesfull, the character read is
 + * written into its argument c.
 + */
 +int serial_getc_dev(const int dev_index)
 +{
-       struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index);
++      struct s5p_uart *const uart = s5pc1xx_get_base_uart(dev_index);
 +
 +      /* wait for character to arrive */
 +      while (!(readl(&uart->utrstat) & 0x1)) {
 +              if (serial_err_check(dev_index, 0))
 +                      return 0;
 +      }
 +
 +      return (int)(readl(&uart->urxh) & 0xff);
 +}
 +
 +/*
 + * Output a single byte to the serial port.
 + */
 +void serial_putc_dev(const char c, const int dev_index)
 +{
-       struct s5pc1xx_uart *const uart = s5pc1xx_get_base_uart(dev_index);
++      struct s5p_uart *const uart = s5pc1xx_get_base_uart(dev_index);
 +
 +      /* wait for room in the tx FIFO */
 +      while (!(readl(&uart->utrstat) & 0x2)) {
 +              if (serial_err_check(dev_index, 1))
 +                      return;
 +      }
 +
 +      writel(c, &uart->utxh);
 +
 +      /* If \n, also do \r */
 +      if (c == '\n')
 +              serial_putc_dev('\r', dev_index);
 +}
 +
 +/*
 + * Test whether a character is in the RX buffer
 + */
 +int serial_tstc_dev(const int dev_index)
 +{
- struct serial_device s5pc1xx_serial0_device =
++      struct s5p_uart *const uart = s5pc1xx_get_base_uart(dev_index);
 +
 +      return (int)(readl(&uart->utrstat) & 0x1);
 +}
 +
 +void serial_puts_dev(const char *s, const int dev_index)
 +{
 +      while (*s)
 +              serial_putc_dev(*s++, dev_index);
 +}
 +
 +/* Multi serial device functions */
 +#define DECLARE_S5P_SERIAL_FUNCTIONS(port) \
 +int s5p_serial##port##_init(void) { return serial_init_dev(port); } \
 +void s5p_serial##port##_setbrg(void) { serial_setbrg_dev(port); } \
 +int s5p_serial##port##_getc(void) { return serial_getc_dev(port); } \
 +int s5p_serial##port##_tstc(void) { return serial_tstc_dev(port); } \
 +void s5p_serial##port##_putc(const char c) { serial_putc_dev(c, port); } \
 +void s5p_serial##port##_puts(const char *s) { serial_puts_dev(s, port); }
 +
 +#define INIT_S5P_SERIAL_STRUCTURE(port, name, bus) { \
 +      name, \
 +      bus, \
 +      s5p_serial##port##_init, \
++      NULL, \
 +      s5p_serial##port##_setbrg, \
 +      s5p_serial##port##_getc, \
 +      s5p_serial##port##_tstc, \
 +      s5p_serial##port##_putc, \
 +      s5p_serial##port##_puts, }
 +
 +DECLARE_S5P_SERIAL_FUNCTIONS(0);
- struct serial_device s5pc1xx_serial1_device =
++struct serial_device s5p_serial0_device =
 +      INIT_S5P_SERIAL_STRUCTURE(0, "s5pser0", "S5PUART0");
 +DECLARE_S5P_SERIAL_FUNCTIONS(1);
- struct serial_device s5pc1xx_serial2_device =
++struct serial_device s5p_serial1_device =
 +      INIT_S5P_SERIAL_STRUCTURE(1, "s5pser1", "S5PUART1");
 +DECLARE_S5P_SERIAL_FUNCTIONS(2);
- struct serial_device s5pc1xx_serial3_device =
++struct serial_device s5p_serial2_device =
 +      INIT_S5P_SERIAL_STRUCTURE(2, "s5pser2", "S5PUART2");
 +DECLARE_S5P_SERIAL_FUNCTIONS(3);
++struct serial_device s5p_serial3_device =
 +      INIT_S5P_SERIAL_STRUCTURE(3, "s5pser3", "S5PUART3");
index c7b029b,0000000..69343c2
mode 100644,000000..100644
--- /dev/null
@@@ -1,52 -1,0 +1,52 @@@
- static struct serial_device *serial_current = &s5pc1xx_serial2_device;
 +/*
 + * Copyright (C) 2010 Samsung Electronics
 + * Sanghee Kim <sh0130.kim@samsung.com>
 + */
 +
 +#include <common.h>
 +#include <serial.h>
 +
-       return &s5pc1xx_serial2_device;
++static struct serial_device *serial_current = &s5p_serial2_device;
 +
 +struct serial_device *__default_serial_console(void)
 +{
++      return &s5p_serial2_device;
 +}
 +
 +struct serial_device *default_serial_console(void)
 +      __attribute__((weak, alias("__default_serial_console")));
 +
 +void serial_putc(const char c)
 +{
 +      if (!serial_current) {
 +              struct serial_device *dev = default_serial_console();
 +
 +              dev->putc(c);
 +              return;
 +      }
 +
 +      serial_current->putc(c);
 +}
 +
 +void serial_puts(const char *s)
 +{
 +      if (!serial_current) {
 +              struct serial_device *dev = default_serial_console();
 +
 +              dev->puts(s);
 +              return;
 +      }
 +
 +      serial_current->puts(s);
 +}
 +
 +int serial_init(void)
 +{
 +      if (!serial_current) {
 +              struct serial_device *dev = default_serial_console();
 +
 +              return dev->init();
 +      }
 +
 +      return serial_current->init();
 +}