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.
26 #include <asm/processor.h>
28 #include "powerspan.h"
31 int board_pre_init (void)
36 /** serial number and platform display at startup */
39 char *s = getenv ("serial#");
42 /* 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;
46 p[SYSACE_CTRLREG0] = 0x0;
48 /* add platform and device to banner */
49 switch (get_device ()) {
50 case AP1xx_AP107_TARGET:
51 puts (AP1xx_AP107_TARGET_STR);
53 case AP1xx_AP120_TARGET:
54 puts (AP1xx_AP120_TARGET_STR);
56 case AP1xx_AP130_TARGET:
57 puts (AP1xx_AP130_TARGET_STR);
59 case AP1xx_AP1070_TARGET:
60 puts (AP1xx_AP1070_TARGET_STR);
62 case AP1xx_AP1100_TARGET:
63 puts (AP1xx_AP1100_TARGET_STR);
66 puts (AP1xx_UNKNOWN_STR);
69 puts (AP1xx_TARGET_STR);
72 switch (get_platform ()) {
73 case AP100_BASELINE_PLATFORM:
74 case AP1000_BASELINE_PLATFORM:
75 puts (AP1xx_BASELINE_PLATFORM_STR);
77 case AP1xx_QUADGE_PLATFORM:
78 puts (AP1xx_QUADGE_PLATFORM_STR);
80 case AP1xx_MGT_REF_PLATFORM:
81 puts (AP1xx_MGT_REF_PLATFORM_STR);
83 case AP1xx_STANDARD_PLATFORM:
84 puts (AP1xx_STANDARD_PLATFORM_STR);
86 case AP1xx_DUAL_PLATFORM:
87 puts (AP1xx_DUAL_PLATFORM_STR);
89 case AP1xx_BASE_SRAM_PLATFORM:
90 puts (AP1xx_BASE_SRAM_PLATFORM_STR);
92 case AP1xx_PCI_PCB_TESTPLATFORM:
93 case AP1000_PCI_PCB_TESTPLATFORM:
94 puts (AP1xx_PCI_PCB_TESTPLATFORM_STR);
96 case AP1xx_DUAL_GE_MEZZ_TESTPLATFORM:
97 puts (AP1xx_DUAL_GE_MEZZ_TESTPLATFORM_STR);
99 case AP1xx_SFP_MEZZ_TESTPLATFORM:
100 puts (AP1xx_SFP_MEZZ_TESTPLATFORM_STR);
103 puts (AP1xx_UNKNOWN_STR);
107 if ((get_platform () & AP1xx_TESTPLATFORM_MASK) != 0) {
108 puts (AP1xx_TESTPLATFORM_STR);
110 puts (AP1xx_PLATFORM_STR);
118 printf ("### No HW ID - assuming AMIRIX");
120 for (e = s; *e; ++e) {
136 long int initdram (int board_type)
138 char *s = getenv ("dramsize");
141 if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
144 return (long int)simple_strtoul (s, NULL, 16);
147 return 64 * 1024 * 1024;
151 unsigned int get_platform (void)
153 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
155 return (*revision_reg_ptr & AP1xx_PLATFORM_MASK);
158 unsigned int get_device (void)
160 unsigned int *revision_reg_ptr = (unsigned int *) AP1xx_FPGA_REV_ADDR;
162 return (*revision_reg_ptr & AP1xx_TARGET_MASK);
165 #if 0 /* loadace is not working; it appears to be a hardware issue with the system ace. */
167 This function loads FPGA configurations from the SystemACE CompactFlash
169 int do_loadace (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
171 unsigned char *p = (unsigned char *) AP1000_SYSACE_REGBASE;
174 if ((p[SYSACE_STATREG0] & 0x10) == 0) {
175 p[SYSACE_CTRLREG0] = 0x80;
176 printf ("\nNo CompactFlash Detected\n\n");
177 p[SYSACE_CTRLREG0] = 0x00;
181 /* 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 */
190 p[SYSACE_CTRLREG0] = 0x80 | 0x20 | 0x08;
191 p[SYSACE_CTRLREG1] = 0x00;
193 /* force config address if arg2 exists */
195 cfg = simple_strtoul (argv[1], NULL, 10);
198 printf ("\nInvalid Configuration\n\n");
199 p[SYSACE_CTRLREG0] = 0x00;
202 /* Set config address */
203 p[SYSACE_CTRLREG1] = (cfg << 5);
205 p[SYSACE_CTRLREG0] |= 0x04;
208 cfg = (p[SYSACE_STATREG1] & 0xE0) >> 5;
211 /* release configuration controller */
212 printf ("\nLoading V2PRO with config %d...\n", cfg);
213 p[SYSACE_CTRLREG0] &= ~0x80;
216 while ((p[SYSACE_STATREG1] & 0x01) == 0) {
218 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;
228 p[SYSACE_CTRLREG0] |= 0x20;
234 /** Console command to display and set the software reconfigure byte
236 * swconfig - display the current value of the software reconfigure byte
237 * swconfig [#] - change the software reconfigure byte to #
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
249 int do_swconfigbyte (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
251 unsigned char *sector_buffer = NULL;
252 unsigned char input_char;
254 unsigned int input_uint;
256 /* display value if no argument */
258 printf ("Software configuration byte is currently: 0x%02x\n",
259 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
260 SW_BYTE_SECTOR_OFFSET)));
262 } else if (argc > 3) {
263 printf ("Too many arguments\n");
267 /* if 3 arguments, 3rd argument is the address to use */
269 input_uint = simple_strtoul (argv[1], NULL, 16);
270 sector_buffer = (unsigned char *) input_uint;
272 sector_buffer = (unsigned char *) DEFAULT_TEMP_ADDR;
275 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;
282 memcpy (sector_buffer, (void *) SW_BYTE_SECTOR_ADDR,
283 SW_BYTE_SECTOR_SIZE);
284 sector_buffer[SW_BYTE_SECTOR_OFFSET] = input_char;
287 printf ("Erasing Flash...");
289 (SW_BYTE_SECTOR_ADDR,
290 (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET))) {
294 printf ("Writing to Flash... ");
296 flash_write ((char *)sector_buffer, SW_BYTE_SECTOR_ADDR,
297 SW_BYTE_SECTOR_SIZE);
298 if (write_result != 0) {
299 flash_perror (write_result);
303 printf ("Software configuration byte is now: 0x%02x\n",
304 *((unsigned char *) (SW_BYTE_SECTOR_ADDR +
305 SW_BYTE_SECTOR_OFFSET)));
311 #define ONE_SECOND 1000000
313 int do_pause (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
316 unsigned int delay_time;
319 /* display value if no argument */
325 printf ("Too many arguments\n");
328 pause_time = simple_strtoul (argv[1], NULL, 0);
331 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) {
335 if (serial_tstc () != 0) {
337 /* eat user key presses */
338 while (serial_tstc () != 0) {
347 int do_swreconfig (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
349 printf ("Triggering software reconfigure (software config byte is 0x%02x)...\n",
350 *((unsigned char *) (SW_BYTE_SECTOR_ADDR + SW_BYTE_SECTOR_OFFSET)));
352 *((unsigned char *) AP1000_CPLD_BASE) = 1;
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
367 int do_temp_sensor (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
371 unsigned char temp_byte;
379 unsigned char user_data[4] = { 0 };
380 int user_data_count = 0;
386 cmd = 's'; /* default to status */
389 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);
396 (0x2, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
397 &temp_byte, I2C_READ) != 0) {
400 printf ("Status : 0x%02x ", temp_byte);
401 if (temp_byte & TEMP_BUSY_BIT)
404 if (temp_byte & TEMP_LHIGH_BIT)
407 if (temp_byte & TEMP_LLOW_BIT)
410 if (temp_byte & TEMP_EHIGH_BIT)
413 if (temp_byte & TEMP_ELOW_BIT)
416 if (temp_byte & TEMP_OPEN_BIT)
419 if (temp_byte & TEMP_ETHERM_BIT)
422 if (temp_byte & TEMP_LTHERM_BIT)
428 (0x3, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
429 &temp_byte, I2C_READ) != 0) {
432 printf ("Config : 0x%02x ", temp_byte);
435 (0x4, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
436 &temp_byte, I2C_READ) != 0) {
440 printf ("Conversion: 0x%02x\n", temp_byte);
442 (0x22, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
443 &temp_byte, I2C_READ) != 0) {
446 printf ("Cons Alert: 0x%02x ", temp_byte);
449 (0x21, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
450 &temp_byte, I2C_READ) != 0) {
454 printf ("Therm Hyst: %d\n", temp_byte);
457 (0x0, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
458 &temp_byte, I2C_READ) != 0) {
463 (0x6, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
464 &temp_byte, I2C_READ) != 0) {
469 (0x5, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
470 &temp_byte, I2C_READ) != 0) {
475 (0x20, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
476 &temp_byte, I2C_READ) != 0) {
480 printf ("Local Temp: %2d Low: %2d High: %2d THERM: %2d\n", temp, low, high, therm);
483 (0x1, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
484 &temp_byte, I2C_READ) != 0) {
489 (0x10, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
490 &temp_byte, I2C_READ) != 0) {
493 temp_low = temp_byte;
495 (0x8, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
496 &temp_byte, I2C_READ) != 0) {
501 (0x14, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
502 &temp_byte, I2C_READ) != 0) {
507 (0x7, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
508 &temp_byte, I2C_READ) != 0) {
513 (0x13, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
514 &temp_byte, I2C_READ) != 0) {
517 high_low = temp_byte;
519 (0x19, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
520 &temp_byte, I2C_READ) != 0) {
525 (0x11, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
526 &temp_byte, I2C_READ) != 0) {
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);
531 case 'l': /* alter local limits : low, high, therm */
538 (0xC, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
539 &user_data[0], I2C_WRITE) != 0) {
543 if (user_data_count > 1) {
546 (0xB, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
547 &user_data[1], I2C_WRITE) != 0) {
552 if (user_data_count > 2) {
555 (0x20, I2C_SENSOR_DEV,
556 I2C_SENSOR_CHIP_SEL, &user_data[2],
562 case 'e': /* alter external limits: low, high, therm, offset */
569 (0xE, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
570 &user_data[0], I2C_WRITE) != 0) {
574 if (user_data_count > 1) {
577 (0xD, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
578 &user_data[1], I2C_WRITE) != 0) {
583 if (user_data_count > 2) {
586 (0x19, I2C_SENSOR_DEV,
587 I2C_SENSOR_CHIP_SEL, &user_data[2],
593 if (user_data_count > 3) {
596 (0x11, I2C_SENSOR_DEV,
597 I2C_SENSOR_CHIP_SEL, &user_data[3],
603 case 'c': /* alter config settings: config, conv, cons alert, therm hyst */
610 (0x9, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
611 &user_data[0], I2C_WRITE) != 0) {
615 if (user_data_count > 1) {
618 (0xA, I2C_SENSOR_DEV, I2C_SENSOR_CHIP_SEL,
619 &user_data[1], I2C_WRITE) != 0) {
624 if (user_data_count > 2) {
627 (0x22, I2C_SENSOR_DEV,
628 I2C_SENSOR_CHIP_SEL, &user_data[2],
634 if (user_data_count > 3) {
637 (0x21, I2C_SENSOR_DEV,
638 I2C_SENSOR_CHIP_SEL, &user_data[3],
650 printf ("Access to sensor failed\n");
654 printf ("Usage:\n%s\n", cmdtp->help);
660 U_BOOT_CMD (temp, 6, 0, do_temp_sensor,
661 "temp - interact with the temperature sensor\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"
671 "All values can be decimal or hex (hex preceded with 0x).\n"
672 "Only whole numbers are supported for external limits.\n");
675 U_BOOT_CMD (loadace, 2, 0, do_loadace,
676 "loadace - load fpga configuration from System ACE compact flash\n",
678 " - Load configuration N (0-7) from System ACE compact flash\n"
679 "loadace\n" " - loads default configuration\n");
682 U_BOOT_CMD (swconfig, 2, 0, do_swconfigbyte,
683 "swconfig- display or modify the software configuration byte\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");
689 U_BOOT_CMD (pause, 2, 0, do_pause,
690 "pause - sleep processor until any key is pressed with poll time of N seconds\n",
692 " - sleep processor until any key is pressed with poll time of N seconds\n"
694 " - sleep processor until any key is pressed with poll time of 1 second\n");
696 U_BOOT_CMD (swrecon, 1, 0, do_swreconfig,
697 "swrecon - trigger a board reconfigure to the software selected configuration\n",
699 " - trigger a board reconfigure to the software selected configuration\n");