2002-08-27 13:55:31 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-08-27 13:55:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2005-09-23 17:05:55 +08:00
|
|
|
* AMCC 4XX DCR Functions
|
2002-08-27 13:55:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2014-04-11 10:01:25 +08:00
|
|
|
#include <cli.h>
|
2002-08-27 13:55:31 +08:00
|
|
|
#include <config.h>
|
|
|
|
#include <command.h>
|
|
|
|
|
2006-10-17 12:14:31 +08:00
|
|
|
unsigned long get_dcr (unsigned short);
|
|
|
|
unsigned long set_dcr (unsigned short, unsigned long);
|
|
|
|
|
2005-09-23 17:05:55 +08:00
|
|
|
/* =======================================================================
|
|
|
|
* Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
|
|
|
|
* =======================================================================
|
2002-08-27 13:55:31 +08:00
|
|
|
*/
|
2010-06-29 04:00:46 +08:00
|
|
|
int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
2005-09-23 17:05:55 +08:00
|
|
|
unsigned short dcrn; /* Device Control Register Num */
|
|
|
|
unsigned long value; /* DCR's value */
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2005-09-23 17:05:55 +08:00
|
|
|
unsigned long get_dcr (unsigned short);
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2005-09-23 17:05:55 +08:00
|
|
|
/* Validate arguments */
|
2010-07-17 07:06:04 +08:00
|
|
|
if (argc < 2)
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2005-09-23 17:05:55 +08:00
|
|
|
/* Get a DCR */
|
|
|
|
dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
|
|
|
|
value = get_dcr (dcrn);
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2005-09-23 17:05:55 +08:00
|
|
|
printf ("%04x: %08lx\n", dcrn, value);
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2005-09-23 17:05:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2002-08-27 13:55:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* ======================================================================
|
2005-09-23 17:05:55 +08:00
|
|
|
* Interpreter command to set an AMCC PPC 4xx Device Control Register
|
2002-08-27 13:55:31 +08:00
|
|
|
* ======================================================================
|
|
|
|
*/
|
2010-06-29 04:00:46 +08:00
|
|
|
int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
2005-09-23 17:05:55 +08:00
|
|
|
unsigned short dcrn; /* Device Control Register Num */
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
/* DCR's value */
|
|
|
|
int nbytes;
|
|
|
|
|
|
|
|
/* Validate arguments */
|
2010-07-17 07:06:04 +08:00
|
|
|
if (argc < 2)
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2005-09-23 17:05:55 +08:00
|
|
|
/* Set a DCR */
|
|
|
|
dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
|
|
|
|
do {
|
|
|
|
value = get_dcr (dcrn);
|
|
|
|
printf ("%04x: %08lx", dcrn, value);
|
2014-04-11 10:01:27 +08:00
|
|
|
nbytes = cli_readline(" ? ");
|
2005-09-23 17:05:55 +08:00
|
|
|
if (nbytes == 0) {
|
|
|
|
/*
|
|
|
|
* <CR> pressed as only input, don't modify current
|
|
|
|
* location and exit command.
|
|
|
|
*/
|
|
|
|
nbytes = 1;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
unsigned long i;
|
|
|
|
char *endp;
|
|
|
|
|
|
|
|
i = simple_strtoul (console_buffer, &endp, 16);
|
|
|
|
nbytes = endp - console_buffer;
|
|
|
|
if (nbytes)
|
|
|
|
set_dcr (dcrn, i);
|
|
|
|
}
|
|
|
|
} while (nbytes);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2006-10-17 12:14:31 +08:00
|
|
|
/* =======================================================================
|
|
|
|
* Interpreter command to retrieve an register value through AMCC PPC 4xx
|
|
|
|
* Device Control Register inderect addressing.
|
|
|
|
* =======================================================================
|
|
|
|
*/
|
2010-06-29 04:00:46 +08:00
|
|
|
int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2006-10-17 12:14:31 +08:00
|
|
|
{
|
|
|
|
unsigned short adr_dcrn; /* Device Control Register Num for Address */
|
|
|
|
unsigned short dat_dcrn; /* Device Control Register Num for Data */
|
|
|
|
unsigned short offset; /* Register's offset */
|
|
|
|
unsigned long value; /* Register's value */
|
|
|
|
char *ptr = NULL;
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
/* Validate arguments */
|
2010-07-17 07:06:04 +08:00
|
|
|
if (argc < 3)
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2006-10-17 12:14:31 +08:00
|
|
|
|
|
|
|
/* Find out whether ther is '.' (dot) symbol in the first parameter. */
|
|
|
|
strncpy (buf, argv[1], sizeof(buf)-1);
|
|
|
|
buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
|
|
|
|
ptr = strchr (buf, '.');
|
|
|
|
|
|
|
|
if (ptr != NULL) {
|
|
|
|
/* First parameter has format adr_dcrn.dat_dcrn */
|
|
|
|
*ptr++ = 0; /* erase '.', create zero-end string */
|
|
|
|
adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
|
|
|
|
dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* First parameter has format adr_dcrn; dat_dcrn will be
|
|
|
|
* calculated as adr_dcrn+1.
|
|
|
|
*/
|
|
|
|
adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
|
|
|
|
dat_dcrn = adr_dcrn+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register's offset */
|
|
|
|
offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
|
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
disable_interrupts ();
|
|
|
|
/* Set offset */
|
|
|
|
set_dcr (adr_dcrn, offset);
|
|
|
|
/* get data */
|
|
|
|
value = get_dcr (dat_dcrn);
|
|
|
|
/* Enable interrupts */
|
|
|
|
enable_interrupts ();
|
|
|
|
|
|
|
|
printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* =======================================================================
|
|
|
|
* Interpreter command to update an register value through AMCC PPC 4xx
|
|
|
|
* Device Control Register inderect addressing.
|
|
|
|
* =======================================================================
|
|
|
|
*/
|
2010-06-29 04:00:46 +08:00
|
|
|
int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
|
2006-10-17 12:14:31 +08:00
|
|
|
{
|
|
|
|
unsigned short adr_dcrn; /* Device Control Register Num for Address */
|
|
|
|
unsigned short dat_dcrn; /* Device Control Register Num for Data */
|
|
|
|
unsigned short offset; /* Register's offset */
|
|
|
|
unsigned long value; /* Register's value */
|
|
|
|
char *ptr = NULL;
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
/* Validate arguments */
|
2010-07-17 07:06:04 +08:00
|
|
|
if (argc < 4)
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2006-10-17 12:14:31 +08:00
|
|
|
|
|
|
|
/* Find out whether ther is '.' (dot) symbol in the first parameter. */
|
|
|
|
strncpy (buf, argv[1], sizeof(buf)-1);
|
|
|
|
buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
|
|
|
|
ptr = strchr (buf, '.');
|
|
|
|
|
|
|
|
if (ptr != NULL) {
|
|
|
|
/* First parameter has format adr_dcrn.dat_dcrn */
|
|
|
|
*ptr++ = 0; /* erase '.', create zero-end string */
|
|
|
|
adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
|
|
|
|
dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* First parameter has format adr_dcrn; dat_dcrn will be
|
|
|
|
* calculated as adr_dcrn+1.
|
|
|
|
*/
|
2006-10-26 22:24:31 +08:00
|
|
|
adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
|
|
|
|
dat_dcrn = adr_dcrn+1;
|
|
|
|
}
|
2006-10-17 12:14:31 +08:00
|
|
|
|
|
|
|
/* Register's offset */
|
|
|
|
offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
|
|
|
|
/* New value */
|
|
|
|
value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
|
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
disable_interrupts ();
|
|
|
|
/* Set offset */
|
|
|
|
set_dcr (adr_dcrn, offset);
|
|
|
|
/* set data */
|
|
|
|
set_dcr (dat_dcrn, value);
|
|
|
|
/* Enable interrupts */
|
|
|
|
enable_interrupts ();
|
|
|
|
|
|
|
|
printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-28 05:31:46 +08:00
|
|
|
/***************************************************/
|
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
getdcr, 2, 1, do_getdcr,
|
2009-01-28 08:03:12 +08:00
|
|
|
"Get an AMCC PPC 4xx DCR's value",
|
2009-05-24 23:06:54 +08:00
|
|
|
"dcrn - return a DCR's value."
|
2003-06-28 05:31:46 +08:00
|
|
|
);
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
setdcr, 2, 1, do_setdcr,
|
2009-01-28 08:03:12 +08:00
|
|
|
"Set an AMCC PPC 4xx DCR's value",
|
2009-05-24 23:06:54 +08:00
|
|
|
"dcrn - set a DCR's value."
|
2003-06-28 05:31:46 +08:00
|
|
|
);
|
|
|
|
|
2006-10-17 12:14:31 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
getidcr, 3, 1, do_getidcr,
|
2009-01-28 08:03:12 +08:00
|
|
|
"Get a register value via indirect DCR addressing",
|
2009-05-24 23:06:54 +08:00
|
|
|
"adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
|
2006-10-17 12:14:31 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
setidcr, 4, 1, do_setidcr,
|
2009-01-28 08:03:12 +08:00
|
|
|
"Set a register value via indirect DCR addressing",
|
2009-05-24 23:06:54 +08:00
|
|
|
"adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."
|
2006-10-17 12:14:31 +08:00
|
|
|
);
|