3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
6 * Holger Brunck, Keymile GmbH Hannover, holger.brunck@keymile.com
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 #include <linux/ctype.h>
37 #if defined(CONFIG_POST)
43 #if !defined(CONFIG_MPC83xx)
44 static void i2c_write_start_seq(void);
47 DECLARE_GLOBAL_DATA_PTR;
50 * Set Keymile specific environment variables
51 * Currently only some memory layout variables are calculated here
52 * ... ------------------------------------------------
53 * ... |@rootfsaddr |@pnvramaddr |@varaddr |@reserved |@END_OF_RAM
54 * ... |<------------------- pram ------------------->|
55 * ... ------------------------------------------------
56 * @END_OF_RAM: denotes the RAM size
57 * @pnvramaddr: Startadress of pseudo non volatile RAM in hex
58 * @pram : preserved ram size in k
59 * @varaddr : startadress for /var mounted into RAM
64 unsigned int pnvramaddr;
67 unsigned int kernelmem;
69 unsigned long rootfssize = 0;
71 pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM
73 sprintf((char *)buf, "0x%x", pnvramaddr);
74 setenv("pnvramaddr", (char *)buf);
76 /* try to read rootfssize (ram image) from envrionment */
77 p = getenv("rootfssize");
79 strict_strtoul(p, 16, &rootfssize);
80 pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
81 CONFIG_KM_PNVRAM) / 0x400;
82 sprintf((char *)buf, "0x%x", pram);
83 setenv("pram", (char *)buf);
85 varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
86 sprintf((char *)buf, "0x%x", varaddr);
87 setenv("varaddr", (char *)buf);
89 kernelmem = gd->ram_size - 0x400 * pram;
90 sprintf((char *)buf, "0x%x", kernelmem);
91 setenv("kernelmem", (char *)buf);
96 #if defined(CONFIG_SYS_I2C_INIT_BOARD)
97 #if !defined(CONFIG_MPC83xx)
98 static void i2c_write_start_seq(void)
101 udelay(DELAY_HALF_PERIOD);
103 udelay(DELAY_HALF_PERIOD);
105 udelay(DELAY_HALF_PERIOD);
107 udelay(DELAY_HALF_PERIOD);
111 * I2C is a synchronous protocol and resets of the processor in the middle
112 * of an access can block the I2C Bus until a powerdown of the full unit is
113 * done. This function toggles the SCL until the SCL and SCA line are
114 * released, but max. 16 times, after this a I2C start-sequence is sent.
115 * This I2C Deblocking mechanism was developed by Keymile in association
116 * with Anatech and Atmel in 1998.
118 int i2c_make_abort(void)
121 #if defined(CONFIG_HARD_I2C) && !defined(MACH_TYPE_KM_KIRKWOOD)
122 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
123 i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c;
126 * disable I2C controller first, otherwhise it thinks we want to
127 * talk to the slave port...
129 clrbits_8(&i2c->i2c_i2mod, 0x01);
131 /* Set the PortPins to GPIO */
145 udelay(DELAY_ABORT_SEQ);
147 udelay(DELAY_ABORT_SEQ);
148 scl_state = get_scl();
149 sda_state = get_sda();
150 if (scl_state && sda_state) {
157 for (i = 0; i < 5; i++)
158 i2c_write_start_seq();
160 /* respect stop setup time */
161 udelay(DELAY_ABORT_SEQ);
163 udelay(DELAY_ABORT_SEQ);
167 #if defined(CONFIG_HARD_I2C)
168 /* Set the PortPins back to use for I2C */
176 * i2c_init_board - reset i2c bus. When the board is powercycled during a
177 * bus transfer it might hang; for details see doc/I2C_Edge_Conditions.
179 void i2c_init_board(void)
181 /* Now run the AbortSequence() */
186 int board_eth_init(bd_t *bis)
188 if (ethernet_present())
189 return cpu_eth_init(bis);
195 * do_setboardid command
196 * read out the board id and the hw key from the intventory EEPROM and set
197 * this values as environment variables.
199 static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
202 unsigned char buf[32];
205 p = get_local_var("IVM_BoardId");
207 printf("can't get the IVM_Boardid\n");
210 sprintf((char *)buf, "%s", p);
211 setenv("boardid", (char *)buf);
212 printf("set boardid=%s\n", buf);
214 p = get_local_var("IVM_HWKey");
216 printf("can't get the IVM_HWKey\n");
219 sprintf((char *)buf, "%s", p);
220 setenv("hwkey", (char *)buf);
221 printf("set hwkey=%s\n", buf);
222 printf("Execute manually saveenv for persistent storage.\n");
227 U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and "
228 "hwkey from IVM and set in environment");
231 * command km_checkbidhwk
232 * if "boardid" and "hwkey" are not already set in the environment, do:
233 * if a "boardIdListHex" exists in the environment:
234 * - read ivm data for boardid and hwkey
235 * - compare each entry of the boardIdListHex with the
238 * set environment variables boardid, boardId,
239 * hwkey, hwKey to the found values
240 * both (boardid and boardId) are set because
241 * they might be used differently in the
242 * application and in the init scripts (?)
243 * return 0 in case of match, 1 if not match or error
245 int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
248 unsigned long ivmbid = 0, ivmhwkey = 0;
249 unsigned long envbid = 0, envhwkey = 0;
251 int verbose = argc > 1 && *argv[1] == 'v';
255 * first read out the real inventory values, these values are
256 * already stored in the local hush variables
258 p = get_local_var("IVM_BoardId");
260 printf("can't get the IVM_Boardid\n");
263 rc = strict_strtoul(p, 16, &ivmbid);
265 p = get_local_var("IVM_HWKey");
267 printf("can't get the IVM_HWKey\n");
270 rc = strict_strtoul(p, 16, &ivmhwkey);
272 if (!ivmbid || !ivmhwkey) {
273 printf("Error: IVM_BoardId and/or IVM_HWKey not set!\n");
277 /* now try to read values from environment if available */
278 p = getenv("boardid");
280 rc = strict_strtoul(p, 16, &envbid);
283 rc = strict_strtoul(p, 16, &envhwkey);
286 printf("strict_strtoul returns error: %d", rc);
290 if (!envbid || !envhwkey) {
292 * BoardId/HWkey not available in the environment, so try the
293 * environment variable for BoardId/HWkey list
295 char *bidhwklist = getenv("boardIdListHex");
299 char *rest = bidhwklist;
303 printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n",
305 printf("boardIdHwKeyList: %s\n",
309 /* loop over each bid/hwkey pair in the list */
310 unsigned long bid = 0;
311 unsigned long hwkey = 0;
313 while (*rest && !isxdigit(*rest))
316 * use simple_strtoul because we need &end and
317 * we know we got non numeric char at the end
319 bid = simple_strtoul(rest, &endp, 16);
320 /* BoardId and HWkey are separated with a "_" */
324 * use simple_strtoul because we need
327 hwkey = simple_strtoul(rest, &endp, 16);
329 while (*rest && !isxdigit(*rest))
332 if ((!bid) || (!hwkey)) {
337 printf("trying bid=0x%lX, hwkey=%ld\n",
341 * Compare the values of the found entry in the
342 * list with the valid values which are stored
343 * in the inventory eeprom. If they are equal
344 * set the values in environment variables.
346 if ((bid == ivmbid) && (hwkey == ivmhwkey)) {
352 sprintf(buf, "%lx", bid);
353 setenv("boardid", buf);
354 sprintf(buf, "%lx", hwkey);
355 setenv("hwkey", buf);
357 } /* end while( ! found ) */
361 /* compare now the values */
362 if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) {
363 printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey);
366 printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid,
368 printf(" IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey);
369 rc = 1; /* don't match */
374 U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk,
375 "check boardid and hwkey",
376 "[v]\n - check environment parameter "\
377 "\"boardIdListHex\" against stored boardid and hwkey "\
378 "from the IVM\n v: verbose output"
382 * command km_checktestboot
383 * if the testpin of the board is asserted, return 1
386 int do_checktestboot(cmd_tbl_t *cmdtp, int flag, int argc,
392 int verbose = argc > 1 && *argv[1] == 'v';
394 #if defined(CONFIG_POST)
395 testpin = post_hotkeys_pressed();
396 s = getenv("test_bank");
398 /* when test_bank is not set, act as if testpin is not asserted */
399 testboot = (testpin != 0) && (s);
401 printf("testpin = %d\n", testpin);
402 printf("test_bank = %s\n", s ? s : "not set");
403 printf("boot test app : %s\n", (testboot) ? "yes" : "no");
405 /* return 0 means: testboot, therefore we need the inversion */
409 U_BOOT_CMD(km_checktestboot, 2, 0, do_checktestboot,
410 "check if testpin is asserted",
411 "[v]\n v - verbose output"