2 * amirix.c: ppcboot platform support for AMIRIX board
4 * Copyright 2002 Mind NV
5 * Copyright 2003 AMIRIX Systems Inc.
8 * http://www.amirix.com/
10 * Author : Peter De Schrijver (p2@mind.be)
11 * Frank Smith (smith@amirix.com)
13 * Derived from : Other platform support files in this tree, ml2
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.
27 #include <asm/processor.h>
29 #include "powerspan.h"
32 int board_pre_init (void)
37 /** serial number and platform display at startup */
41 int l = getenv_f("serial#", buf, sizeof(buf));
43 /* After a loadace command, the SystemAce control register is left in a wonky state. */
44 /* this code did not work in board_pre_init */
45 unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE;
47 p[SYSACE_CTRLREG0] = 0x0;
49 /* add platform and device to banner */
50 switch (get_device ()) {
51 case AP1xx_AP107_TARGET:
52 puts (AP1xx_AP107_TARGET_STR);
54 case AP1xx_AP120_TARGET:
55 puts (AP1xx_AP120_TARGET_STR);
57 case AP1xx_AP130_TARGET:
58 puts (AP1xx_AP130_TARGET_STR);
60 case AP1xx_AP1070_TARGET:
61 puts (AP1xx_AP1070_TARGET_STR);
63 case AP1xx_AP1100_TARGET:
64 puts (AP1xx_AP1100_TARGET_STR);
67 puts (AP1xx_UNKNOWN_STR);
70 puts (AP1xx_TARGET_STR);
73 switch (get_platform ()) {
74 case AP100_BASELINE_PLATFORM:
75 case AP1000_BASELINE_PLATFORM:
76 puts (AP1xx_BASELINE_PLATFORM_STR);
78 case AP1xx_QUADGE_PLATFORM:
79 puts (AP1xx_QUADGE_PLATFORM_STR);
81 case AP1xx_MGT_REF_PLATFORM:
82 puts (AP1xx_MGT_REF_PLATFORM_STR);
84 case AP1xx_STANDARD_PLATFORM:
85 puts (AP1xx_STANDARD_PLATFORM_STR);
87 case AP1xx_DUAL_PLATFORM:
88 puts (AP1xx_DUAL_PLATFORM_STR);
90 case AP1xx_BASE_SRAM_PLATFORM:
91 puts (AP1xx_BASE_SRAM_PLATFORM_STR);
93 case AP1xx_PCI_PCB_TESTPLATFORM:
94 case AP1000_PCI_PCB_TESTPLATFORM:
95 puts (AP1xx_PCI_PCB_TESTPLATFORM_STR);
97 case AP1xx_DUAL_GE_MEZZ_TESTPLATFORM:
98 puts (AP1xx_DUAL_GE_MEZZ_TESTPLATFORM_STR);
100 case AP1xx_SFP_MEZZ_TESTPLATFORM:
101 puts (AP1xx_SFP_MEZZ_TESTPLATFORM_STR);
104 puts (AP1xx_UNKNOWN_STR);
108 if ((get_platform () & AP1xx_TESTPLATFORM_MASK) != 0) {
109 puts (AP1xx_TESTPLATFORM_STR);
111 puts (AP1xx_PLATFORM_STR);
119 printf ("### No HW ID - assuming AMIRIX");
123 for (i = 0; i < l; ++i) {
139 phys_size_t initdram (int board_type)
142 int i = getenv_f("dramsize", buf, sizeof(buf));
146 if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
149 return (long int)simple_strtoul (s, NULL, 16);
152 return 64 * 1024 * 1024;
156 unsigned int get_platform (void)
158 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
160 return (*revision_reg_ptr & AP1xx_PLATFORM_MASK);
163 unsigned int get_device (void)
165 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
167 return (*revision_reg_ptr & AP1xx_TARGET_MASK);
170 #if 0 /* loadace is not working; it appears to be a hardware issue with the system ace. */
172 This function loads FPGA configurations from the SystemACE CompactFlash
174 int do_loadace (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
176 unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE;
179 if ((p[SYSACE_STATREG0] & 0x10) == 0) {
180 p[SYSACE_CTRLREG0] = 0x80;
181 printf ("\nNo CompactFlash Detected\n\n");
182 p[SYSACE_CTRLREG0] = 0x00;
186 /* reset configuration controller: | 0x80 */
187 /* select cpflash & ~0x40 */
188 /* cfg start | 0x20 */
189 /* wait for cfgstart & ~0x10 */
190 /* force cfgmode: | 0x08 */
191 /* do no force cfgaddr: & ~0x04 */
192 /* clear mpulock: & ~0x02 */
193 /* do not force lock request & ~0x01 */
195 p[SYSACE_CTRLREG0] = 0x80 | 0x20 | 0x08;
196 p[SYSACE_CTRLREG1] = 0x00;
198 /* force config address if arg2 exists */
200 cfg = simple_strtoul (argv[1], NULL, 10);
203 printf ("\nInvalid Configuration\n\n");
204 p[SYSACE_CTRLREG0] = 0x00;
207 /* Set config address */
208 p[SYSACE_CTRLREG1] = (cfg << 5);
210 p[SYSACE_CTRLREG0] |= 0x04;
213 cfg = (p[SYSACE_STATREG1] & 0xE0) >> 5;
216 /* release configuration controller */
217 printf ("\nLoading V2PRO with config %d...\n", cfg);
218 p[SYSACE_CTRLREG0] &= ~0x80;
221 while ((p[SYSACE_STATREG1] & 0x01) == 0) {
223 if (p[SYSACE_ERRREG0] & 0x80) {
224 /* attempting to load an invalid configuration makes the cpflash */
225 /* appear to be removed. Reset here to avoid that problem */
226 p[SYSACE_CTRLREG0] = 0x80;
227 printf ("\nConfiguration %d Read Error\n\n", cfg);
228 p[SYSACE_CTRLREG0] = 0x00;
233 p[SYSACE_CTRLREG0] |= 0x20;
239 /** Console command to display and set the software reconfigure byte
241 * swconfig - display the current value of the software reconfigure byte
242 * swconfig [#] - change the software reconfigure byte to #
244 * @param *cmdtp [IN] as passed by run_command (ignored)
245 * @param flag [IN] as passed by run_command (ignored)
246 * @param argc [IN] as passed by run_command if 1, display, if 2 change
247 * @param *argv[] [IN] contains the parameters to use
254 int do_swconfigbyte (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
256 unsigned char *sector_buffer = NULL;
257 unsigned char input_char;
259 unsigned int input_uint;
261 /* display value if no argument */
263 printf ("Software configuration byte is currently: 0x%02x\n",
264 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
265 SW_BYTE_SECTOR_OFFSET)));
267 } else if (argc > 3) {
268 printf ("Too many arguments\n");
272 /* if 3 arguments, 3rd argument is the address to use */
274 input_uint = simple_strtoul (argv[1], NULL, 16);
275 sector_buffer = (unsigned char *) input_uint;
277 sector_buffer = (unsigned char *) DEFAULT_TEMP_ADDR;
280 input_char = simple_strtoul (argv[1], NULL, 0);
281 if ((input_char & ~SW_BYTE_MASK) != 0) {
282 printf ("Input of 0x%02x will be masked to 0x%02x\n",
283 input_char, (input_char & SW_BYTE_MASK));
284 input_char = input_char & SW_BYTE_MASK;
287 memcpy (sector_buffer, (void *) SW_BYTE_SECTOR_ADDR,
288 SW_BYTE_SECTOR_SIZE);
289 sector_buffer[SW_BYTE_SECTOR_OFFSET] = input_char;
292 printf ("Erasing Flash...");
294 (SW_BYTE_SECTOR_ADDR,
295 (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET))) {
299 printf ("Writing to Flash... ");
301 flash_write ((char *)sector_buffer, SW_BYTE_SECTOR_ADDR,
302 SW_BYTE_SECTOR_SIZE);
303 if (write_result != 0) {
304 flash_perror (write_result);
308 printf ("Software configuration byte is now: 0x%02x\n",
309 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
310 SW_BYTE_SECTOR_OFFSET)));
316 #define ONE_SECOND 1000000
318 int do_pause (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
321 unsigned int delay_time;
324 /* display value if no argument */
330 printf ("Too many arguments\n");
333 pause_time = simple_strtoul (argv[1], NULL, 0);
336 printf ("Pausing with a poll time of %d, press any key to reactivate\n", pause_time);
337 delay_time = pause_time * ONE_SECOND;
338 while (break_loop == 0) {
340 if (serial_tstc () != 0) {
342 /* eat user key presses */
343 while (serial_tstc () != 0) {
352 int do_swreconfig (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
354 printf ("Triggering software reconfigure (software config byte is 0x%02x)...\n",
355 *((unsigned char *) (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET)));
357 *((unsigned char *) AP1000_CPLD_BASE) = 1;
362 #define GET_DECIMAL(low_byte) ((low_byte >> 5) * 125)
363 #define TEMP_BUSY_BIT 0x80
364 #define TEMP_LHIGH_BIT 0x40
365 #define TEMP_LLOW_BIT 0x20
366 #define TEMP_EHIGH_BIT 0x10
367 #define TEMP_ELOW_BIT 0x08
368 #define TEMP_OPEN_BIT 0x04
369 #define TEMP_ETHERM_BIT 0x02
370 #define TEMP_LTHERM_BIT 0x01
372 int do_temp_sensor (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
376 unsigned char temp_byte;
384 unsigned char user_data[4] = { 0 };
385 int user_data_count = 0;
391 cmd = 's'; /* default to status */
394 user_data_count = argc - 2;
395 for (ii = 0; ii < user_data_count; ii++) {
396 user_data[ii] = simple_strtoul (argv[2 + ii], NULL, 0);
401 (0x2, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
402 &temp_byte, I2C_READ) != 0) {
405 printf ("Status : 0x%02x ", temp_byte);
406 if (temp_byte & TEMP_BUSY_BIT)
409 if (temp_byte & TEMP_LHIGH_BIT)
412 if (temp_byte & TEMP_LLOW_BIT)
415 if (temp_byte & TEMP_EHIGH_BIT)
418 if (temp_byte & TEMP_ELOW_BIT)
421 if (temp_byte & TEMP_OPEN_BIT)
424 if (temp_byte & TEMP_ETHERM_BIT)
427 if (temp_byte & TEMP_LTHERM_BIT)
433 (0x3, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
434 &temp_byte, I2C_READ) != 0) {
437 printf ("Config : 0x%02x ", temp_byte);
440 (0x4, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
441 &temp_byte, I2C_READ) != 0) {
445 printf ("Conversion: 0x%02x\n", temp_byte);
447 (0x22, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
448 &temp_byte, I2C_READ) != 0) {
451 printf ("Cons Alert: 0x%02x ", temp_byte);
454 (0x21, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
455 &temp_byte, I2C_READ) != 0) {
459 printf ("Therm Hyst: %d\n", temp_byte);
462 (0x0, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
463 &temp_byte, I2C_READ) != 0) {
468 (0x6, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
469 &temp_byte, I2C_READ) != 0) {
474 (0x5, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
475 &temp_byte, I2C_READ) != 0) {
480 (0x20, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
481 &temp_byte, I2C_READ) != 0) {
485 printf ("Local Temp: %2d Low: %2d High: %2d THERM: %2d\n", temp, low, high, therm);
488 (0x1, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
489 &temp_byte, I2C_READ) != 0) {
494 (0x10, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
495 &temp_byte, I2C_READ) != 0) {
498 temp_low = temp_byte;
500 (0x8, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
501 &temp_byte, I2C_READ) != 0) {
506 (0x14, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
507 &temp_byte, I2C_READ) != 0) {
512 (0x7, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
513 &temp_byte, I2C_READ) != 0) {
518 (0x13, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
519 &temp_byte, I2C_READ) != 0) {
522 high_low = temp_byte;
524 (0x19, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
525 &temp_byte, I2C_READ) != 0) {
530 (0x11, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
531 &temp_byte, I2C_READ) != 0) {
534 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);
536 case 'l': /* alter local limits : low, high, therm */
543 (0xC, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
544 &user_data[0], I2C_WRITE) != 0) {
548 if (user_data_count > 1) {
551 (0xB, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
552 &user_data[1], I2C_WRITE) != 0) {
557 if (user_data_count > 2) {
560 (0x20, I2C_SENSOR_DEV,
561 I2C_SENSOR_CHIP_SEL, &user_data[2],
567 case 'e': /* alter external limits: low, high, therm, offset */
574 (0xE, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
575 &user_data[0], I2C_WRITE) != 0) {
579 if (user_data_count > 1) {
582 (0xD, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
583 &user_data[1], I2C_WRITE) != 0) {
588 if (user_data_count > 2) {
591 (0x19, I2C_SENSOR_DEV,
592 I2C_SENSOR_CHIP_SEL, &user_data[2],
598 if (user_data_count > 3) {
601 (0x11, I2C_SENSOR_DEV,
602 I2C_SENSOR_CHIP_SEL, &user_data[3],
608 case 'c': /* alter config settings: config, conv, cons alert, therm hyst */
615 (0x9, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
616 &user_data[0], I2C_WRITE) != 0) {
620 if (user_data_count > 1) {
623 (0xA, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
624 &user_data[1], I2C_WRITE) != 0) {
629 if (user_data_count > 2) {
632 (0x22, I2C_SENSOR_DEV,
633 I2C_SENSOR_CHIP_SEL, &user_data[2],
639 if (user_data_count > 3) {
642 (0x21, I2C_SENSOR_DEV,
643 I2C_SENSOR_CHIP_SEL, &user_data[3],
655 printf ("Access to sensor failed\n");
659 printf ("Usage:\n%s\n", cmdtp->help);
665 U_BOOT_CMD (temp, 6, 0, do_temp_sensor,
666 "interact with the temperature sensor",
669 "temp l LOW [HIGH] [THERM]\n"
670 " - Set local limits.\n"
671 "temp e LOW [HIGH] [THERM] [OFFSET]\n"
672 " - Set external limits.\n"
673 "temp c CONFIG [CONVERSION] [CONS. ALERT] [THERM HYST]\n"
674 " - Set config options.\n"
676 "All values can be decimal or hex (hex preceded with 0x).\n"
677 "Only whole numbers are supported for external limits.");
680 U_BOOT_CMD (loadace, 2, 0, do_loadace,
681 "load fpga configuration from System ACE compact flash",
683 " - Load configuration N (0-7) from System ACE compact flash\n"
684 "loadace\n" " - loads default configuration");
687 U_BOOT_CMD (swconfig, 2, 0, do_swconfigbyte,
688 "display or modify the software configuration byte",
690 " - set software configuration byte to N, optionally use ADDRESS as\n"
691 " location of buffer for flash copy\n"
692 "swconfig\n" " - display software configuration byte");
694 U_BOOT_CMD (pause, 2, 0, do_pause,
695 "sleep processor until any key is pressed with poll time of N seconds",
697 " - sleep processor until any key is pressed with poll time of N seconds\n"
699 " - sleep processor until any key is pressed with poll time of 1 second");
701 U_BOOT_CMD (swrecon, 1, 0, do_swreconfig,
702 "trigger a board reconfigure to the software selected configuration",
704 " - trigger a board reconfigure to the software selected configuration");
706 int board_eth_init(bd_t *bis)
708 return pci_eth_init(bis);