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() */
187 #if !defined(MACH_TYPE_KM_KIRKWOOD)
188 int ethernet_present(void)
190 struct km_bec_fpga *base =
191 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
193 return in_8(&base->bprth) & PIGGY_PRESENT;
197 int board_eth_init(bd_t *bis)
199 if (ethernet_present())
200 return cpu_eth_init(bis);
206 * do_setboardid command
207 * read out the board id and the hw key from the intventory EEPROM and set
208 * this values as environment variables.
210 static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
213 unsigned char buf[32];
216 p = get_local_var("IVM_BoardId");
218 printf("can't get the IVM_Boardid\n");
221 sprintf((char *)buf, "%s", p);
222 setenv("boardid", (char *)buf);
223 printf("set boardid=%s\n", buf);
225 p = get_local_var("IVM_HWKey");
227 printf("can't get the IVM_HWKey\n");
230 sprintf((char *)buf, "%s", p);
231 setenv("hwkey", (char *)buf);
232 printf("set hwkey=%s\n", buf);
233 printf("Execute manually saveenv for persistent storage.\n");
238 U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and "
239 "hwkey from IVM and set in environment");
242 * command km_checkbidhwk
243 * if "boardid" and "hwkey" are not already set in the environment, do:
244 * if a "boardIdListHex" exists in the environment:
245 * - read ivm data for boardid and hwkey
246 * - compare each entry of the boardIdListHex with the
249 * set environment variables boardid, boardId,
250 * hwkey, hwKey to the found values
251 * both (boardid and boardId) are set because
252 * they might be used differently in the
253 * application and in the init scripts (?)
254 * return 0 in case of match, 1 if not match or error
256 int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
259 unsigned long ivmbid = 0, ivmhwkey = 0;
260 unsigned long envbid = 0, envhwkey = 0;
262 int verbose = argc > 1 && *argv[1] == 'v';
266 * first read out the real inventory values, these values are
267 * already stored in the local hush variables
269 p = get_local_var("IVM_BoardId");
271 printf("can't get the IVM_Boardid\n");
274 rc = strict_strtoul(p, 16, &ivmbid);
276 p = get_local_var("IVM_HWKey");
278 printf("can't get the IVM_HWKey\n");
281 rc = strict_strtoul(p, 16, &ivmhwkey);
283 if (!ivmbid || !ivmhwkey) {
284 printf("Error: IVM_BoardId and/or IVM_HWKey not set!\n");
288 /* now try to read values from environment if available */
289 p = getenv("boardid");
291 rc = strict_strtoul(p, 16, &envbid);
294 rc = strict_strtoul(p, 16, &envhwkey);
297 printf("strict_strtoul returns error: %d", rc);
301 if (!envbid || !envhwkey) {
303 * BoardId/HWkey not available in the environment, so try the
304 * environment variable for BoardId/HWkey list
306 char *bidhwklist = getenv("boardIdListHex");
310 char *rest = bidhwklist;
314 printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n",
316 printf("boardIdHwKeyList: %s\n",
320 /* loop over each bid/hwkey pair in the list */
321 unsigned long bid = 0;
322 unsigned long hwkey = 0;
324 while (*rest && !isxdigit(*rest))
327 * use simple_strtoul because we need &end and
328 * we know we got non numeric char at the end
330 bid = simple_strtoul(rest, &endp, 16);
331 /* BoardId and HWkey are separated with a "_" */
335 * use simple_strtoul because we need
338 hwkey = simple_strtoul(rest, &endp, 16);
340 while (*rest && !isxdigit(*rest))
343 if ((!bid) || (!hwkey)) {
348 printf("trying bid=0x%lX, hwkey=%ld\n",
352 * Compare the values of the found entry in the
353 * list with the valid values which are stored
354 * in the inventory eeprom. If they are equal
355 * set the values in environment variables.
357 if ((bid == ivmbid) && (hwkey == ivmhwkey)) {
363 sprintf(buf, "%lx", bid);
364 setenv("boardid", buf);
365 sprintf(buf, "%lx", hwkey);
366 setenv("hwkey", buf);
368 } /* end while( ! found ) */
372 /* compare now the values */
373 if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) {
374 printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey);
377 printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid,
379 printf(" IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey);
380 rc = 1; /* don't match */
385 U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk,
386 "check boardid and hwkey",
387 "[v]\n - check environment parameter "\
388 "\"boardIdListHex\" against stored boardid and hwkey "\
389 "from the IVM\n v: verbose output"
393 * command km_checktestboot
394 * if the testpin of the board is asserted, return 1
397 int do_checktestboot(cmd_tbl_t *cmdtp, int flag, int argc,
403 int verbose = argc > 1 && *argv[1] == 'v';
405 #if defined(CONFIG_POST)
406 testpin = post_hotkeys_pressed();
407 s = getenv("test_bank");
409 /* when test_bank is not set, act as if testpin is not asserted */
410 testboot = (testpin != 0) && (s);
412 printf("testpin = %d\n", testpin);
413 printf("test_bank = %s\n", s ? s : "not set");
414 printf("boot test app : %s\n", (testboot) ? "yes" : "no");
416 /* return 0 means: testboot, therefore we need the inversion */
420 U_BOOT_CMD(km_checktestboot, 2, 0, do_checktestboot,
421 "check if testpin is asserted",
422 "[v]\n v - verbose output"