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 */
40 char *s = getenv ("serial#");
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");
121 for (e = s; *e; ++e) {
137 phys_size_t initdram (int board_type)
139 char *s = getenv ("dramsize");
142 if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
145 return (long int)simple_strtoul (s, NULL, 16);
148 return 64 * 1024 * 1024;
152 unsigned int get_platform (void)
154 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
156 return (*revision_reg_ptr & AP1xx_PLATFORM_MASK);
159 unsigned int get_device (void)
161 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
163 return (*revision_reg_ptr & AP1xx_TARGET_MASK);
166 #if 0 /* loadace is not working; it appears to be a hardware issue with the system ace. */
168 This function loads FPGA configurations from the SystemACE CompactFlash
170 int do_loadace (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
172 unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE;
175 if ((p[SYSACE_STATREG0] & 0x10) == 0) {
176 p[SYSACE_CTRLREG0] = 0x80;
177 printf ("\nNo CompactFlash Detected\n\n");
178 p[SYSACE_CTRLREG0] = 0x00;
182 /* reset configuration controller: | 0x80 */
183 /* select cpflash & ~0x40 */
184 /* cfg start | 0x20 */
185 /* wait for cfgstart & ~0x10 */
186 /* force cfgmode: | 0x08 */
187 /* do no force cfgaddr: & ~0x04 */
188 /* clear mpulock: & ~0x02 */
189 /* do not force lock request & ~0x01 */
191 p[SYSACE_CTRLREG0] = 0x80 | 0x20 | 0x08;
192 p[SYSACE_CTRLREG1] = 0x00;
194 /* force config address if arg2 exists */
196 cfg = simple_strtoul (argv[1], NULL, 10);
199 printf ("\nInvalid Configuration\n\n");
200 p[SYSACE_CTRLREG0] = 0x00;
203 /* Set config address */
204 p[SYSACE_CTRLREG1] = (cfg << 5);
206 p[SYSACE_CTRLREG0] |= 0x04;
209 cfg = (p[SYSACE_STATREG1] & 0xE0) >> 5;
212 /* release configuration controller */
213 printf ("\nLoading V2PRO with config %d...\n", cfg);
214 p[SYSACE_CTRLREG0] &= ~0x80;
217 while ((p[SYSACE_STATREG1] & 0x01) == 0) {
219 if (p[SYSACE_ERRREG0] & 0x80) {
220 /* attempting to load an invalid configuration makes the cpflash */
221 /* appear to be removed. Reset here to avoid that problem */
222 p[SYSACE_CTRLREG0] = 0x80;
223 printf ("\nConfiguration %d Read Error\n\n", cfg);
224 p[SYSACE_CTRLREG0] = 0x00;
229 p[SYSACE_CTRLREG0] |= 0x20;
235 /** Console command to display and set the software reconfigure byte
237 * swconfig - display the current value of the software reconfigure byte
238 * swconfig [#] - change the software reconfigure byte to #
240 * @param *cmdtp [IN] as passed by run_command (ignored)
241 * @param flag [IN] as passed by run_command (ignored)
242 * @param argc [IN] as passed by run_command if 1, display, if 2 change
243 * @param *argv[] [IN] contains the parameters to use
250 int do_swconfigbyte (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
252 unsigned char *sector_buffer = NULL;
253 unsigned char input_char;
255 unsigned int input_uint;
257 /* display value if no argument */
259 printf ("Software configuration byte is currently: 0x%02x\n",
260 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
261 SW_BYTE_SECTOR_OFFSET)));
263 } else if (argc > 3) {
264 printf ("Too many arguments\n");
268 /* if 3 arguments, 3rd argument is the address to use */
270 input_uint = simple_strtoul (argv[1], NULL, 16);
271 sector_buffer = (unsigned char *) input_uint;
273 sector_buffer = (unsigned char *) DEFAULT_TEMP_ADDR;
276 input_char = simple_strtoul (argv[1], NULL, 0);
277 if ((input_char & ~SW_BYTE_MASK) != 0) {
278 printf ("Input of 0x%02x will be masked to 0x%02x\n",
279 input_char, (input_char & SW_BYTE_MASK));
280 input_char = input_char & SW_BYTE_MASK;
283 memcpy (sector_buffer, (void *) SW_BYTE_SECTOR_ADDR,
284 SW_BYTE_SECTOR_SIZE);
285 sector_buffer[SW_BYTE_SECTOR_OFFSET] = input_char;
288 printf ("Erasing Flash...");
290 (SW_BYTE_SECTOR_ADDR,
291 (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET))) {
295 printf ("Writing to Flash... ");
297 flash_write ((char *)sector_buffer, SW_BYTE_SECTOR_ADDR,
298 SW_BYTE_SECTOR_SIZE);
299 if (write_result != 0) {
300 flash_perror (write_result);
304 printf ("Software configuration byte is now: 0x%02x\n",
305 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
306 SW_BYTE_SECTOR_OFFSET)));
312 #define ONE_SECOND 1000000
314 int do_pause (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
317 unsigned int delay_time;
320 /* display value if no argument */
326 printf ("Too many arguments\n");
329 pause_time = simple_strtoul (argv[1], NULL, 0);
332 printf ("Pausing with a poll time of %d, press any key to reactivate\n", pause_time);
333 delay_time = pause_time * ONE_SECOND;
334 while (break_loop == 0) {
336 if (serial_tstc () != 0) {
338 /* eat user key presses */
339 while (serial_tstc () != 0) {
348 int do_swreconfig (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
350 printf ("Triggering software reconfigure (software config byte is 0x%02x)...\n",
351 *((unsigned char *) (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET)));
353 *((unsigned char *) AP1000_CPLD_BASE) = 1;
358 #define GET_DECIMAL(low_byte) ((low_byte >> 5) * 125)
359 #define TEMP_BUSY_BIT 0x80
360 #define TEMP_LHIGH_BIT 0x40
361 #define TEMP_LLOW_BIT 0x20
362 #define TEMP_EHIGH_BIT 0x10
363 #define TEMP_ELOW_BIT 0x08
364 #define TEMP_OPEN_BIT 0x04
365 #define TEMP_ETHERM_BIT 0x02
366 #define TEMP_LTHERM_BIT 0x01
368 int do_temp_sensor (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
372 unsigned char temp_byte;
380 unsigned char user_data[4] = { 0 };
381 int user_data_count = 0;
387 cmd = 's'; /* default to status */
390 user_data_count = argc - 2;
391 for (ii = 0; ii < user_data_count; ii++) {
392 user_data[ii] = simple_strtoul (argv[2 + ii], NULL, 0);
397 (0x2, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
398 &temp_byte, I2C_READ) != 0) {
401 printf ("Status : 0x%02x ", temp_byte);
402 if (temp_byte & TEMP_BUSY_BIT)
405 if (temp_byte & TEMP_LHIGH_BIT)
408 if (temp_byte & TEMP_LLOW_BIT)
411 if (temp_byte & TEMP_EHIGH_BIT)
414 if (temp_byte & TEMP_ELOW_BIT)
417 if (temp_byte & TEMP_OPEN_BIT)
420 if (temp_byte & TEMP_ETHERM_BIT)
423 if (temp_byte & TEMP_LTHERM_BIT)
429 (0x3, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
430 &temp_byte, I2C_READ) != 0) {
433 printf ("Config : 0x%02x ", temp_byte);
436 (0x4, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
437 &temp_byte, I2C_READ) != 0) {
441 printf ("Conversion: 0x%02x\n", temp_byte);
443 (0x22, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
444 &temp_byte, I2C_READ) != 0) {
447 printf ("Cons Alert: 0x%02x ", temp_byte);
450 (0x21, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
451 &temp_byte, I2C_READ) != 0) {
455 printf ("Therm Hyst: %d\n", temp_byte);
458 (0x0, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
459 &temp_byte, I2C_READ) != 0) {
464 (0x6, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
465 &temp_byte, I2C_READ) != 0) {
470 (0x5, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
471 &temp_byte, I2C_READ) != 0) {
476 (0x20, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
477 &temp_byte, I2C_READ) != 0) {
481 printf ("Local Temp: %2d Low: %2d High: %2d THERM: %2d\n", temp, low, high, therm);
484 (0x1, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
485 &temp_byte, I2C_READ) != 0) {
490 (0x10, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
491 &temp_byte, I2C_READ) != 0) {
494 temp_low = temp_byte;
496 (0x8, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
497 &temp_byte, I2C_READ) != 0) {
502 (0x14, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
503 &temp_byte, I2C_READ) != 0) {
508 (0x7, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
509 &temp_byte, I2C_READ) != 0) {
514 (0x13, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
515 &temp_byte, I2C_READ) != 0) {
518 high_low = temp_byte;
520 (0x19, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
521 &temp_byte, I2C_READ) != 0) {
526 (0x11, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
527 &temp_byte, I2C_READ) != 0) {
530 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);
532 case 'l': /* alter local limits : low, high, therm */
539 (0xC, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
540 &user_data[0], I2C_WRITE) != 0) {
544 if (user_data_count > 1) {
547 (0xB, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
548 &user_data[1], I2C_WRITE) != 0) {
553 if (user_data_count > 2) {
556 (0x20, I2C_SENSOR_DEV,
557 I2C_SENSOR_CHIP_SEL, &user_data[2],
563 case 'e': /* alter external limits: low, high, therm, offset */
570 (0xE, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
571 &user_data[0], I2C_WRITE) != 0) {
575 if (user_data_count > 1) {
578 (0xD, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
579 &user_data[1], I2C_WRITE) != 0) {
584 if (user_data_count > 2) {
587 (0x19, I2C_SENSOR_DEV,
588 I2C_SENSOR_CHIP_SEL, &user_data[2],
594 if (user_data_count > 3) {
597 (0x11, I2C_SENSOR_DEV,
598 I2C_SENSOR_CHIP_SEL, &user_data[3],
604 case 'c': /* alter config settings: config, conv, cons alert, therm hyst */
611 (0x9, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
612 &user_data[0], I2C_WRITE) != 0) {
616 if (user_data_count > 1) {
619 (0xA, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
620 &user_data[1], I2C_WRITE) != 0) {
625 if (user_data_count > 2) {
628 (0x22, I2C_SENSOR_DEV,
629 I2C_SENSOR_CHIP_SEL, &user_data[2],
635 if (user_data_count > 3) {
638 (0x21, I2C_SENSOR_DEV,
639 I2C_SENSOR_CHIP_SEL, &user_data[3],
651 printf ("Access to sensor failed\n");
655 printf ("Usage:\n%s\n", cmdtp->help);
661 U_BOOT_CMD (temp, 6, 0, do_temp_sensor,
662 "interact with the temperature sensor",
665 "temp l LOW [HIGH] [THERM]\n"
666 " - Set local limits.\n"
667 "temp e LOW [HIGH] [THERM] [OFFSET]\n"
668 " - Set external limits.\n"
669 "temp c CONFIG [CONVERSION] [CONS. ALERT] [THERM HYST]\n"
670 " - Set config options.\n"
672 "All values can be decimal or hex (hex preceded with 0x).\n"
673 "Only whole numbers are supported for external limits.\n");
676 U_BOOT_CMD (loadace, 2, 0, do_loadace,
677 "load fpga configuration from System ACE compact flash",
679 " - Load configuration N (0-7) from System ACE compact flash\n"
680 "loadace\n" " - loads default configuration\n");
683 U_BOOT_CMD (swconfig, 2, 0, do_swconfigbyte,
684 "display or modify the software configuration byte",
686 " - set software configuration byte to N, optionally use ADDRESS as\n"
687 " location of buffer for flash copy\n"
688 "swconfig\n" " - display software configuration byte\n");
690 U_BOOT_CMD (pause, 2, 0, do_pause,
691 "sleep processor until any key is pressed with poll time of N seconds",
693 " - sleep processor until any key is pressed with poll time of N seconds\n"
695 " - sleep processor until any key is pressed with poll time of 1 second\n");
697 U_BOOT_CMD (swrecon, 1, 0, do_swreconfig,
698 "trigger a board reconfigure to the software selected configuration",
700 " - trigger a board reconfigure to the software selected configuration\n");
702 int board_eth_init(bd_t *bis)
704 return pci_eth_init(bis);