1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <common.h>
28#include <ioports.h>
29#include <command.h>
30#include <malloc.h>
31#include <hush.h>
32#include <net.h>
33#include <netdev.h>
34#include <asm/io.h>
35#include <linux/ctype.h>
36
37#include "common.h"
38#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
39#include <i2c.h>
40#endif
41
42#if !defined(CONFIG_MPC83xx)
43static void i2c_write_start_seq(void);
44#endif
45
46DECLARE_GLOBAL_DATA_PTR;
47
48
49
50
51
52
53
54
55
56
57
58
59
60int set_km_env(void)
61{
62 uchar buf[32];
63 unsigned int pnvramaddr;
64 unsigned int pram;
65 unsigned int varaddr;
66 unsigned int kernelmem;
67 char *p;
68 unsigned long rootfssize = 0;
69
70 pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM
71 - CONFIG_KM_PNVRAM;
72 sprintf((char *)buf, "0x%x", pnvramaddr);
73 setenv("pnvramaddr", (char *)buf);
74
75
76 p = getenv("rootfssize");
77 if (p != NULL)
78 strict_strtoul(p, 16, &rootfssize);
79 pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
80 CONFIG_KM_PNVRAM) / 0x400;
81 sprintf((char *)buf, "0x%x", pram);
82 setenv("pram", (char *)buf);
83
84 varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
85 sprintf((char *)buf, "0x%x", varaddr);
86 setenv("varaddr", (char *)buf);
87
88 kernelmem = gd->ram_size - 0x400 * pram;
89 sprintf((char *)buf, "0x%x", kernelmem);
90 setenv("kernelmem", (char *)buf);
91
92 return 0;
93}
94
95#if defined(CONFIG_SYS_I2C_INIT_BOARD)
96#if !defined(CONFIG_MPC83xx)
97static void i2c_write_start_seq(void)
98{
99 set_sda(1);
100 udelay(DELAY_HALF_PERIOD);
101 set_scl(1);
102 udelay(DELAY_HALF_PERIOD);
103 set_sda(0);
104 udelay(DELAY_HALF_PERIOD);
105 set_scl(0);
106 udelay(DELAY_HALF_PERIOD);
107}
108
109
110
111
112
113
114
115
116
117int i2c_make_abort(void)
118{
119
120#if defined(CONFIG_HARD_I2C) && !defined(MACH_TYPE_KM_KIRKWOOD)
121 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR ;
122 i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c;
123
124
125
126
127
128 clrbits_8(&i2c->i2c_i2mod, 0x01);
129
130
131 setports(1);
132#endif
133
134 int scl_state = 0;
135 int sda_state = 0;
136 int i = 0;
137 int ret = 0;
138
139 if (!get_sda()) {
140 ret = -1;
141 while (i < 16) {
142 i++;
143 set_scl(0);
144 udelay(DELAY_ABORT_SEQ);
145 set_scl(1);
146 udelay(DELAY_ABORT_SEQ);
147 scl_state = get_scl();
148 sda_state = get_sda();
149 if (scl_state && sda_state) {
150 ret = 0;
151 printf("[INFO] i2c abort after %d clocks\n", i);
152 break;
153 }
154 }
155 }
156 if (ret == 0)
157 for (i = 0; i < 5; i++)
158 i2c_write_start_seq();
159 else
160 printf("[ERROR] i2c abort failed\n");
161
162
163 udelay(DELAY_ABORT_SEQ);
164 set_scl(1);
165 udelay(DELAY_ABORT_SEQ);
166 set_sda(1);
167 get_sda();
168
169#if defined(CONFIG_HARD_I2C)
170
171 setports(0);
172#endif
173 return ret;
174}
175#endif
176
177
178
179
180
181void i2c_init_board(void)
182{
183
184 i2c_make_abort();
185}
186#endif
187
188
189#if !defined(MACH_TYPE_KM_KIRKWOOD)
190int ethernet_present(void)
191{
192 struct km_bec_fpga *base =
193 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
194
195 return in_8(&base->bprth) & PIGGY_PRESENT;
196}
197#endif
198
199int board_eth_init(bd_t *bis)
200{
201 if (ethernet_present())
202 return cpu_eth_init(bis);
203
204 return -1;
205}
206
207
208
209
210
211
212static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
213 char *const argv[])
214{
215 unsigned char buf[32];
216 char *p;
217
218 p = get_local_var("IVM_BoardId");
219 if (p == NULL) {
220 printf("can't get the IVM_Boardid\n");
221 return 1;
222 }
223 sprintf((char *)buf, "%s", p);
224 setenv("boardid", (char *)buf);
225 printf("set boardid=%s\n", buf);
226
227 p = get_local_var("IVM_HWKey");
228 if (p == NULL) {
229 printf("can't get the IVM_HWKey\n");
230 return 1;
231 }
232 sprintf((char *)buf, "%s", p);
233 setenv("hwkey", (char *)buf);
234 printf("set hwkey=%s\n", buf);
235 printf("Execute manually saveenv for persistent storage.\n");
236
237 return 0;
238}
239
240U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and "
241 "hwkey from IVM and set in environment");
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
259 char *const argv[])
260{
261 unsigned long ivmbid = 0, ivmhwkey = 0;
262 unsigned long envbid = 0, envhwkey = 0;
263 char *p;
264 int verbose = argc > 1 && *argv[1] == 'v';
265 int rc = 0;
266
267
268
269
270
271 p = get_local_var("IVM_BoardId");
272 if (p == NULL) {
273 printf("can't get the IVM_Boardid\n");
274 return 1;
275 }
276 rc = strict_strtoul(p, 16, &ivmbid);
277
278 p = get_local_var("IVM_HWKey");
279 if (p == NULL) {
280 printf("can't get the IVM_HWKey\n");
281 return 1;
282 }
283 rc = strict_strtoul(p, 16, &ivmhwkey);
284
285 if (!ivmbid || !ivmhwkey) {
286 printf("Error: IVM_BoardId and/or IVM_HWKey not set!\n");
287 return rc;
288 }
289
290
291 p = getenv("boardid");
292 if (p != NULL)
293 rc = strict_strtoul(p, 16, &envbid);
294 p = getenv("hwkey");
295 if (p != NULL)
296 rc = strict_strtoul(p, 16, &envhwkey);
297
298 if (rc != 0) {
299 printf("strict_strtoul returns error: %d", rc);
300 return rc;
301 }
302
303 if (!envbid || !envhwkey) {
304
305
306
307
308 char *bidhwklist = getenv("boardIdListHex");
309
310 if (bidhwklist) {
311 int found = 0;
312 char *rest = bidhwklist;
313 char *endp;
314
315 if (verbose) {
316 printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n",
317 ivmbid, ivmhwkey);
318 printf("boardIdHwKeyList: %s\n",
319 bidhwklist);
320 }
321 while (!found) {
322
323 unsigned long bid = 0;
324 unsigned long hwkey = 0;
325
326 while (*rest && !isxdigit(*rest))
327 rest++;
328
329
330
331
332 bid = simple_strtoul(rest, &endp, 16);
333
334 if (*endp == '_') {
335 rest = endp + 1;
336
337
338
339
340 hwkey = simple_strtoul(rest, &endp, 16);
341 rest = endp;
342 while (*rest && !isxdigit(*rest))
343 rest++;
344 }
345 if ((!bid) || (!hwkey)) {
346
347 break;
348 }
349 if (verbose) {
350 printf("trying bid=0x%lX, hwkey=%ld\n",
351 bid, hwkey);
352 }
353
354
355
356
357
358
359 if ((bid == ivmbid) && (hwkey == ivmhwkey)) {
360 char buf[10];
361
362 found = 1;
363 envbid = bid;
364 envhwkey = hwkey;
365 sprintf(buf, "%lx", bid);
366 setenv("boardid", buf);
367 sprintf(buf, "%lx", hwkey);
368 setenv("hwkey", buf);
369 }
370 }
371 }
372 }
373
374
375 if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) {
376 printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey);
377 rc = 0;
378 } else {
379 printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid,
380 envhwkey);
381 printf(" IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey);
382 rc = 1;
383 }
384 return rc;
385}
386
387U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk,
388 "check boardid and hwkey",
389 "[v]\n - check environment parameter "\
390 "\"boardIdListHex\" against stored boardid and hwkey "\
391 "from the IVM\n v: verbose output"
392);
393