2 * (C) Copyright 2010 Samsung Electronics
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <linux/mtd/compat.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/onenand.h>
28 #include <asm/arch/gpio.h>
29 #include <asm/arch/keypad.h>
30 #include "../../../onenand.h"
32 typedef int (init_fnc_t) (void);
34 DECLARE_GLOBAL_DATA_PTR;
36 static struct s5pc110_gpio *s5pc110_gpio;
38 static void sdelay(unsigned long usec)
50 static int check_keypad(void)
52 unsigned int condition = 0;
53 unsigned int reg, value;
54 unsigned int col_num, row_num;
55 unsigned int col_mask;
56 unsigned int col_mask_shift;
57 unsigned int row_state[4] = {0, 0, 0, 0};
60 /* board is limo universal */
65 for (i = 0; i < sizeof(row_state)/sizeof(int); i++)
68 for (i = 0; i < row_num; i++) {
69 /* Set GPH3[3:0] to KP_ROW[3:0] */
70 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
71 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
74 for (i = 0; i < col_num; i++)
75 /* Set GPH2[3:0] to KP_COL[3:0] */
76 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
78 reg = S5PC110_KEYPAD_BASE;
79 col_mask = S5PC110_KEYIFCOLEN_MASK;
82 /* KEYIFCOL reg clear */
83 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
86 for (i = 0; i < col_num; i++) {
88 value &= ~(1 << i) << col_mask_shift;
90 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
93 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
94 row_state[i] = ~value & ((1 << row_num) - 1);
97 /* KEYIFCOL reg clear */
98 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
100 /* check volume up/down */
101 if ((row_state[1] & 0x3) == 0x3)
107 static int check_block(void)
109 struct onenand_op *onenand_ops = onenand_get_interface();
110 struct mtd_info *mtd = onenand_ops->mtd;
111 struct onenand_chip *this = mtd->priv;
113 int page_to_check = 4;
115 ulong blocksize = 1 << this->erase_shift;
116 ulong pagesize = 1 << this->page_shift;
117 u_char *down_ram_addr;
119 u_char verify_buf[0x10];
121 down_ram_addr = (unsigned char *)CONFIG_SYS_DOWN_ADDR;
122 uboot_addr = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift;
124 onenand_ops->read(uboot_addr, blocksize, &retlen, down_ram_addr, 0);
125 if (retlen != blocksize)
128 memset(verify_buf, 0xFF, sizeof(verify_buf));
130 for (i = 0; i < page_to_check; i++) {
131 ret = memcmp(down_ram_addr + pagesize*i, verify_buf,
137 if (i == page_to_check)
143 int board_check_condition(void)
154 int board_load_uboot(unsigned char *buf)
156 struct mtd_info *mtd = &onenand_mtd;
157 struct onenand_chip *this = mtd->priv;
162 offset = CONFIG_RECOVERY_UBOOT_BLOCK << this->erase_shift;
163 size = CONFIG_SYS_MONITOR_LEN;
165 mtd->read(mtd, offset, size, &ret, buf);
173 void board_recovery_init(void)
175 /* Set Initial global variables */
176 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;