blob: 7d11b29b59ab714775953d7a092f424d0b17400c [file] [log] [blame]
Wolfgang Denk7521af12005-10-09 01:04:33 +02001/*
2 * amirix.c: ppcboot platform support for AMIRIX board
3 *
4 * Copyright 2002 Mind NV
5 * Copyright 2003 AMIRIX Systems Inc.
6 *
7 * http://www.mind.be/
8 * http://www.amirix.com/
9 *
10 * Author : Peter De Schrijver (p2@mind.be)
11 * Frank Smith (smith@amirix.com)
12 *
13 * Derived from : Other platform support files in this tree, ml2
14 *
15 * This software may be used and distributed according to the terms of
16 * the GNU General Public License (GPL) version 2, incorporated herein by
17 * reference. Drivers based on or derived from this code fall under the GPL
18 * and must retain the authorship, copyright and this license notice. This
19 * file is not a complete program and may only be used when the entire
20 * program is licensed under the GPL.
21 *
22 */
23
24#include <common.h>
25#include <command.h>
26#include <asm/processor.h>
27
28#include "powerspan.h"
29#include "ap1000.h"
30
31int board_pre_init (void)
32{
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020033 return 0;
Wolfgang Denk7521af12005-10-09 01:04:33 +020034}
35
36/** serial number and platform display at startup */
37int checkboard (void)
38{
Stefan Roese18c5e642006-01-18 20:06:44 +010039 char *s = getenv ("serial#");
40 char *e;
Wolfgang Denk7521af12005-10-09 01:04:33 +020041
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020042 /* After a loadace command, the SystemAce control register is left in a wonky state. */
43 /* this code did not work in board_pre_init */
44 unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE;
Wolfgang Denk7521af12005-10-09 01:04:33 +020045
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020046 p[SYSACE_CTRLREG0] = 0x0;
Wolfgang Denk7521af12005-10-09 01:04:33 +020047
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020048 /* add platform and device to banner */
49 switch (get_device ()) {
50 case AP1xx_AP107_TARGET:
51 puts (AP1xx_AP107_TARGET_STR);
52 break;
53 case AP1xx_AP120_TARGET:
54 puts (AP1xx_AP120_TARGET_STR);
55 break;
56 case AP1xx_AP130_TARGET:
57 puts (AP1xx_AP130_TARGET_STR);
58 break;
59 case AP1xx_AP1070_TARGET:
60 puts (AP1xx_AP1070_TARGET_STR);
61 break;
62 case AP1xx_AP1100_TARGET:
63 puts (AP1xx_AP1100_TARGET_STR);
64 break;
65 default:
66 puts (AP1xx_UNKNOWN_STR);
67 break;
68 }
69 puts (AP1xx_TARGET_STR);
70 puts (" with ");
Wolfgang Denk7521af12005-10-09 01:04:33 +020071
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020072 switch (get_platform ()) {
73 case AP100_BASELINE_PLATFORM:
74 case AP1000_BASELINE_PLATFORM:
75 puts (AP1xx_BASELINE_PLATFORM_STR);
76 break;
77 case AP1xx_QUADGE_PLATFORM:
78 puts (AP1xx_QUADGE_PLATFORM_STR);
79 break;
80 case AP1xx_MGT_REF_PLATFORM:
81 puts (AP1xx_MGT_REF_PLATFORM_STR);
82 break;
83 case AP1xx_STANDARD_PLATFORM:
84 puts (AP1xx_STANDARD_PLATFORM_STR);
85 break;
86 case AP1xx_DUAL_PLATFORM:
87 puts (AP1xx_DUAL_PLATFORM_STR);
88 break;
89 case AP1xx_BASE_SRAM_PLATFORM:
90 puts (AP1xx_BASE_SRAM_PLATFORM_STR);
91 break;
92 case AP1xx_PCI_PCB_TESTPLATFORM:
93 case AP1000_PCI_PCB_TESTPLATFORM:
94 puts (AP1xx_PCI_PCB_TESTPLATFORM_STR);
95 break;
96 case AP1xx_DUAL_GE_MEZZ_TESTPLATFORM:
97 puts (AP1xx_DUAL_GE_MEZZ_TESTPLATFORM_STR);
98 break;
99 case AP1xx_SFP_MEZZ_TESTPLATFORM:
100 puts (AP1xx_SFP_MEZZ_TESTPLATFORM_STR);
101 break;
102 default:
103 puts (AP1xx_UNKNOWN_STR);
104 break;
105 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200106
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200107 if ((get_platform () & AP1xx_TESTPLATFORM_MASK) != 0) {
108 puts (AP1xx_TESTPLATFORM_STR);
109 } else {
110 puts (AP1xx_PLATFORM_STR);
111 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200112
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200113 putc ('\n');
Wolfgang Denk7521af12005-10-09 01:04:33 +0200114
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200115 puts ("Serial#: ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200116
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200117 if (!s) {
118 printf ("### No HW ID - assuming AMIRIX");
119 } else {
120 for (e = s; *e; ++e) {
121 if (*e == ' ')
122 break;
123 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200124
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200125 for (; s < e; ++s) {
126 putc (*s);
127 }
128 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200129
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200130 putc ('\n');
131
132 return (0);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200133}
134
135
136long int initdram (int board_type)
137{
Stefan Roese18c5e642006-01-18 20:06:44 +0100138 char *s = getenv ("dramsize");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200139
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200140 if (s != NULL) {
141 if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
142 s += 2;
143 }
Stefan Roese18c5e642006-01-18 20:06:44 +0100144 return (long int)simple_strtoul (s, NULL, 16);
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200145 } else {
146 /* give all 64 MB */
Wolfgang Denk7521af12005-10-09 01:04:33 +0200147 return 64 * 1024 * 1024;
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200148 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200149}
150
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200151unsigned int get_platform (void)
152{
153 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
154
155 return (*revision_reg_ptr & AP1xx_PLATFORM_MASK);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200156}
157
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200158unsigned int get_device (void)
159{
160 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200161
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200162 return (*revision_reg_ptr & AP1xx_TARGET_MASK);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200163}
164
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200165#if 0 /* loadace is not working; it appears to be a hardware issue with the system ace. */
Wolfgang Denk7521af12005-10-09 01:04:33 +0200166/*
167 This function loads FPGA configurations from the SystemACE CompactFlash
168*/
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200169int do_loadace (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
Wolfgang Denk7521af12005-10-09 01:04:33 +0200170{
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200171 unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE;
172 int cfg;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200173
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200174 if ((p[SYSACE_STATREG0] & 0x10) == 0) {
175 p[SYSACE_CTRLREG0] = 0x80;
176 printf ("\nNo CompactFlash Detected\n\n");
177 p[SYSACE_CTRLREG0] = 0x00;
178 return 1;
179 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200180
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200181 /* reset configuration controller: | 0x80 */
182 /* select cpflash & ~0x40 */
183 /* cfg start | 0x20 */
184 /* wait for cfgstart & ~0x10 */
185 /* force cfgmode: | 0x08 */
186 /* do no force cfgaddr: & ~0x04 */
187 /* clear mpulock: & ~0x02 */
188 /* do not force lock request & ~0x01 */
Wolfgang Denk7521af12005-10-09 01:04:33 +0200189
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200190 p[SYSACE_CTRLREG0] = 0x80 | 0x20 | 0x08;
191 p[SYSACE_CTRLREG1] = 0x00;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200192
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200193 /* force config address if arg2 exists */
194 if (argc == 2) {
195 cfg = simple_strtoul (argv[1], NULL, 10);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200196
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200197 if (cfg > 7) {
198 printf ("\nInvalid Configuration\n\n");
199 p[SYSACE_CTRLREG0] = 0x00;
200 return 1;
201 }
202 /* Set config address */
203 p[SYSACE_CTRLREG1] = (cfg << 5);
204 /* force cfgaddr */
205 p[SYSACE_CTRLREG0] |= 0x04;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200206
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200207 } else {
208 cfg = (p[SYSACE_STATREG1] & 0xE0) >> 5;
209 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200210
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200211 /* release configuration controller */
212 printf ("\nLoading V2PRO with config %d...\n", cfg);
213 p[SYSACE_CTRLREG0] &= ~0x80;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200214
215
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200216 while ((p[SYSACE_STATREG1] & 0x01) == 0) {
Wolfgang Denk7521af12005-10-09 01:04:33 +0200217
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200218 if (p[SYSACE_ERRREG0] & 0x80) {
219 /* attempting to load an invalid configuration makes the cpflash */
220 /* appear to be removed. Reset here to avoid that problem */
221 p[SYSACE_CTRLREG0] = 0x80;
222 printf ("\nConfiguration %d Read Error\n\n", cfg);
223 p[SYSACE_CTRLREG0] = 0x00;
224 return 1;
225 }
226 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200227
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200228 p[SYSACE_CTRLREG0] |= 0x20;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200229
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200230 return 0;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200231}
232#endif
233
234/** Console command to display and set the software reconfigure byte
235 * <pre>
236 * swconfig - display the current value of the software reconfigure byte
237 * swconfig [#] - change the software reconfigure byte to #
238 * </pre>
239 * @param *cmdtp [IN] as passed by run_command (ignored)
240 * @param flag [IN] as passed by run_command (ignored)
241 * @param argc [IN] as passed by run_command if 1, display, if 2 change
242 * @param *argv[] [IN] contains the parameters to use
243 * @return
244 * <pre>
245 * 0 if passed
246 * -1 if failed
247 * </pre>
248 */
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200249int do_swconfigbyte (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
250{
251 unsigned char *sector_buffer = NULL;
252 unsigned char input_char;
253 int write_result;
254 unsigned int input_uint;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200255
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200256 /* display value if no argument */
257 if (argc < 2) {
258 printf ("Software configuration byte is currently: 0x%02x\n",
259 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
260 SW_BYTE_SECTOR_OFFSET)));
261 return 0;
262 } else if (argc > 3) {
263 printf ("Too many arguments\n");
264 return -1;
265 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200266
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200267 /* if 3 arguments, 3rd argument is the address to use */
268 if (argc == 3) {
269 input_uint = simple_strtoul (argv[1], NULL, 16);
270 sector_buffer = (unsigned char *) input_uint;
271 } else {
272 sector_buffer = (unsigned char *) DEFAULT_TEMP_ADDR;
273 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200274
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200275 input_char = simple_strtoul (argv[1], NULL, 0);
276 if ((input_char & ~SW_BYTE_MASK) != 0) {
277 printf ("Input of 0x%02x will be masked to 0x%02x\n",
278 input_char, (input_char & SW_BYTE_MASK));
279 input_char = input_char & SW_BYTE_MASK;
280 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200281
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200282 memcpy (sector_buffer, (void *) SW_BYTE_SECTOR_ADDR,
283 SW_BYTE_SECTOR_SIZE);
284 sector_buffer[SW_BYTE_SECTOR_OFFSET] = input_char;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200285
286
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200287 printf ("Erasing Flash...");
288 if (flash_sect_erase
289 (SW_BYTE_SECTOR_ADDR,
290 (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET))) {
291 return -1;
292 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200293
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200294 printf ("Writing to Flash... ");
295 write_result =
Stefan Roese18c5e642006-01-18 20:06:44 +0100296 flash_write ((char *)sector_buffer, SW_BYTE_SECTOR_ADDR,
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200297 SW_BYTE_SECTOR_SIZE);
298 if (write_result != 0) {
299 flash_perror (write_result);
300 return -1;
301 } else {
302 printf ("done\n");
303 printf ("Software configuration byte is now: 0x%02x\n",
304 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
305 SW_BYTE_SECTOR_OFFSET)));
306 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200307
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200308 return 0;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200309}
310
311#define ONE_SECOND 1000000
312
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200313int do_pause (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
314{
315 int pause_time;
316 unsigned int delay_time;
317 int break_loop = 0;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200318
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200319 /* display value if no argument */
320 if (argc < 2) {
321 pause_time = 1;
322 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200323
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200324 else if (argc > 2) {
325 printf ("Too many arguments\n");
326 return -1;
327 } else {
328 pause_time = simple_strtoul (argv[1], NULL, 0);
329 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200330
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200331 printf ("Pausing with a poll time of %d, press any key to reactivate\n", pause_time);
332 delay_time = pause_time * ONE_SECOND;
333 while (break_loop == 0) {
334 udelay (delay_time);
335 if (serial_tstc () != 0) {
336 break_loop = 1;
337 /* eat user key presses */
338 while (serial_tstc () != 0) {
339 serial_getc ();
340 }
341 }
342 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200343
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200344 return 0;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200345}
346
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200347int do_swreconfig (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
348{
349 printf ("Triggering software reconfigure (software config byte is 0x%02x)...\n",
350 *((unsigned char *) (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET)));
351 udelay (1000);
352 *((unsigned char *) AP1000_CPLD_BASE) = 1;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200353
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200354 return 0;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200355}
356
357#define GET_DECIMAL(low_byte) ((low_byte >> 5) * 125)
358#define TEMP_BUSY_BIT 0x80
359#define TEMP_LHIGH_BIT 0x40
360#define TEMP_LLOW_BIT 0x20
361#define TEMP_EHIGH_BIT 0x10
362#define TEMP_ELOW_BIT 0x08
363#define TEMP_OPEN_BIT 0x04
364#define TEMP_ETHERM_BIT 0x02
365#define TEMP_LTHERM_BIT 0x01
366
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200367int do_temp_sensor (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
368{
369 char cmd;
370 int ret_val = 0;
371 unsigned char temp_byte;
372 int temp;
373 int temp_low;
374 int low;
375 int low_low;
376 int high;
377 int high_low;
378 int therm;
379 unsigned char user_data[4] = { 0 };
380 int user_data_count = 0;
381 int ii;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200382
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200383 if (argc > 1) {
384 cmd = argv[1][0];
385 } else {
386 cmd = 's'; /* default to status */
387 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200388
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200389 user_data_count = argc - 2;
390 for (ii = 0; ii < user_data_count; ii++) {
391 user_data[ii] = simple_strtoul (argv[2 + ii], NULL, 0);
392 }
393 switch (cmd) {
394 case 's':
395 if (I2CAccess
396 (0x2, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
397 &temp_byte, I2C_READ) != 0) {
398 goto fail;
399 }
400 printf ("Status : 0x%02x ", temp_byte);
401 if (temp_byte & TEMP_BUSY_BIT)
402 printf ("BUSY ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200403
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200404 if (temp_byte & TEMP_LHIGH_BIT)
405 printf ("LHIGH ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200406
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200407 if (temp_byte & TEMP_LLOW_BIT)
408 printf ("LLOW ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200409
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200410 if (temp_byte & TEMP_EHIGH_BIT)
411 printf ("EHIGH ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200412
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200413 if (temp_byte & TEMP_ELOW_BIT)
414 printf ("ELOW ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200415
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200416 if (temp_byte & TEMP_OPEN_BIT)
417 printf ("OPEN ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200418
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200419 if (temp_byte & TEMP_ETHERM_BIT)
420 printf ("ETHERM ");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200421
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200422 if (temp_byte & TEMP_LTHERM_BIT)
423 printf ("LTHERM");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200424
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200425 printf ("\n");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200426
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200427 if (I2CAccess
428 (0x3, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
429 &temp_byte, I2C_READ) != 0) {
430 goto fail;
431 }
432 printf ("Config : 0x%02x ", temp_byte);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200433
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200434 if (I2CAccess
435 (0x4, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
436 &temp_byte, I2C_READ) != 0) {
437 printf ("\n");
438 goto fail;
439 }
440 printf ("Conversion: 0x%02x\n", temp_byte);
441 if (I2CAccess
442 (0x22, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
443 &temp_byte, I2C_READ) != 0) {
444 goto fail;
445 }
446 printf ("Cons Alert: 0x%02x ", temp_byte);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200447
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200448 if (I2CAccess
449 (0x21, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
450 &temp_byte, I2C_READ) != 0) {
451 printf ("\n");
452 goto fail;
453 }
454 printf ("Therm Hyst: %d\n", temp_byte);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200455
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200456 if (I2CAccess
457 (0x0, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
458 &temp_byte, I2C_READ) != 0) {
459 goto fail;
460 }
461 temp = temp_byte;
462 if (I2CAccess
463 (0x6, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
464 &temp_byte, I2C_READ) != 0) {
465 goto fail;
466 }
467 low = temp_byte;
468 if (I2CAccess
469 (0x5, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
470 &temp_byte, I2C_READ) != 0) {
471 goto fail;
472 }
473 high = temp_byte;
474 if (I2CAccess
475 (0x20, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
476 &temp_byte, I2C_READ) != 0) {
477 goto fail;
478 }
479 therm = temp_byte;
480 printf ("Local Temp: %2d Low: %2d High: %2d THERM: %2d\n", temp, low, high, therm);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200481
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200482 if (I2CAccess
483 (0x1, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
484 &temp_byte, I2C_READ) != 0) {
485 goto fail;
486 }
487 temp = temp_byte;
488 if (I2CAccess
489 (0x10, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
490 &temp_byte, I2C_READ) != 0) {
491 goto fail;
492 }
493 temp_low = temp_byte;
494 if (I2CAccess
495 (0x8, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
496 &temp_byte, I2C_READ) != 0) {
497 goto fail;
498 }
499 low = temp_byte;
500 if (I2CAccess
501 (0x14, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
502 &temp_byte, I2C_READ) != 0) {
503 goto fail;
504 }
505 low_low = temp_byte;
506 if (I2CAccess
507 (0x7, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
508 &temp_byte, I2C_READ) != 0) {
509 goto fail;
510 }
511 high = temp_byte;
512 if (I2CAccess
513 (0x13, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
514 &temp_byte, I2C_READ) != 0) {
515 goto fail;
516 }
517 high_low = temp_byte;
518 if (I2CAccess
519 (0x19, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
520 &temp_byte, I2C_READ) != 0) {
521 goto fail;
522 }
523 therm = temp_byte;
524 if (I2CAccess
525 (0x11, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
526 &temp_byte, I2C_READ) != 0) {
527 goto fail;
528 }
529 printf ("Ext Temp : %2d.%03d Low: %2d.%03d High: %2d.%03d THERM: %2d Offset: %2d\n", temp, GET_DECIMAL (temp_low), low, GET_DECIMAL (low_low), high, GET_DECIMAL (high_low), therm, temp_byte);
530 break;
531 case 'l': /* alter local limits : low, high, therm */
532 if (argc < 3) {
533 goto usage;
534 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200535
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200536 /* low */
537 if (I2CAccess
538 (0xC, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
539 &user_data[0], I2C_WRITE) != 0) {
540 goto fail;
541 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200542
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200543 if (user_data_count > 1) {
544 /* high */
545 if (I2CAccess
546 (0xB, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
547 &user_data[1], I2C_WRITE) != 0) {
548 goto fail;
549 }
550 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200551
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200552 if (user_data_count > 2) {
553 /* therm */
554 if (I2CAccess
555 (0x20, I2C_SENSOR_DEV,
556 I2C_SENSOR_CHIP_SEL, &user_data[2],
557 I2C_WRITE) != 0) {
558 goto fail;
559 }
560 }
561 break;
562 case 'e': /* alter external limits: low, high, therm, offset */
563 if (argc < 3) {
564 goto usage;
565 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200566
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200567 /* low */
568 if (I2CAccess
569 (0xE, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
570 &user_data[0], I2C_WRITE) != 0) {
571 goto fail;
572 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200573
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200574 if (user_data_count > 1) {
575 /* high */
576 if (I2CAccess
577 (0xD, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
578 &user_data[1], I2C_WRITE) != 0) {
579 goto fail;
580 }
581 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200582
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200583 if (user_data_count > 2) {
584 /* therm */
585 if (I2CAccess
586 (0x19, I2C_SENSOR_DEV,
587 I2C_SENSOR_CHIP_SEL, &user_data[2],
588 I2C_WRITE) != 0) {
589 goto fail;
590 }
591 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200592
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200593 if (user_data_count > 3) {
594 /* offset */
595 if (I2CAccess
596 (0x11, I2C_SENSOR_DEV,
597 I2C_SENSOR_CHIP_SEL, &user_data[3],
598 I2C_WRITE) != 0) {
599 goto fail;
600 }
601 }
602 break;
603 case 'c': /* alter config settings: config, conv, cons alert, therm hyst */
604 if (argc < 3) {
605 goto usage;
606 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200607
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200608 /* config */
609 if (I2CAccess
610 (0x9, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
611 &user_data[0], I2C_WRITE) != 0) {
612 goto fail;
613 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200614
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200615 if (user_data_count > 1) {
616 /* conversion */
617 if (I2CAccess
618 (0xA, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
619 &user_data[1], I2C_WRITE) != 0) {
620 goto fail;
621 }
622 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200623
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200624 if (user_data_count > 2) {
625 /* cons alert */
626 if (I2CAccess
627 (0x22, I2C_SENSOR_DEV,
628 I2C_SENSOR_CHIP_SEL, &user_data[2],
629 I2C_WRITE) != 0) {
630 goto fail;
631 }
632 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200633
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200634 if (user_data_count > 3) {
635 /* therm hyst */
636 if (I2CAccess
637 (0x21, I2C_SENSOR_DEV,
638 I2C_SENSOR_CHIP_SEL, &user_data[3],
639 I2C_WRITE) != 0) {
640 goto fail;
641 }
642 }
643 break;
644 default:
645 goto usage;
646 }
Wolfgang Denk7521af12005-10-09 01:04:33 +0200647
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200648 goto done;
649fail:
650 printf ("Access to sensor failed\n");
651 ret_val = -1;
652 goto done;
653usage:
654 printf ("Usage:\n%s\n", cmdtp->help);
Wolfgang Denk7521af12005-10-09 01:04:33 +0200655
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200656done:
657 return ret_val;
Wolfgang Denk7521af12005-10-09 01:04:33 +0200658}
659
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200660U_BOOT_CMD (temp, 6, 0, do_temp_sensor,
661 "temp - interact with the temperature sensor\n",
662 "temp [s]\n"
663 " - Show status.\n"
664 "temp l LOW [HIGH] [THERM]\n"
665 " - Set local limits.\n"
666 "temp e LOW [HIGH] [THERM] [OFFSET]\n"
667 " - Set external limits.\n"
668 "temp c CONFIG [CONVERSION] [CONS. ALERT] [THERM HYST]\n"
669 " - Set config options.\n"
670 "\n"
671 "All values can be decimal or hex (hex preceded with 0x).\n"
672 "Only whole numbers are supported for external limits.\n");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200673
674#if 0
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200675U_BOOT_CMD (loadace, 2, 0, do_loadace,
676 "loadace - load fpga configuration from System ACE compact flash\n",
677 "N\n"
678 " - Load configuration N (0-7) from System ACE compact flash\n"
679 "loadace\n" " - loads default configuration\n");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200680#endif
681
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200682U_BOOT_CMD (swconfig, 2, 0, do_swconfigbyte,
683 "swconfig- display or modify the software configuration byte\n",
684 "N [ADDRESS]\n"
685 " - set software configuration byte to N, optionally use ADDRESS as\n"
686 " location of buffer for flash copy\n"
687 "swconfig\n" " - display software configuration byte\n");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200688
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200689U_BOOT_CMD (pause, 2, 0, do_pause,
690 "pause - sleep processor until any key is pressed with poll time of N seconds\n",
691 "N\n"
692 " - sleep processor until any key is pressed with poll time of N seconds\n"
693 "pause\n"
694 " - sleep processor until any key is pressed with poll time of 1 second\n");
Wolfgang Denk7521af12005-10-09 01:04:33 +0200695
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200696U_BOOT_CMD (swrecon, 1, 0, do_swreconfig,
697 "swrecon - trigger a board reconfigure to the software selected configuration\n",
698 "\n"
699 " - trigger a board reconfigure to the software selected configuration\n");