wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 9 | * AMCC 4XX DCR Functions |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 18d6653 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 13 | #include <cli.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 14 | #include <config.h> |
| 15 | #include <command.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 16 | |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 17 | unsigned long get_dcr (unsigned short); |
| 18 | unsigned long set_dcr (unsigned short, unsigned long); |
| 19 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 20 | /* ======================================================================= |
| 21 | * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register |
| 22 | * ======================================================================= |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 23 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 24 | int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] ) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 25 | { |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 26 | unsigned short dcrn; /* Device Control Register Num */ |
| 27 | unsigned long value; /* DCR's value */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 28 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 29 | unsigned long get_dcr (unsigned short); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 30 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 31 | /* Validate arguments */ |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 32 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 33 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 34 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 35 | /* Get a DCR */ |
| 36 | dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16); |
| 37 | value = get_dcr (dcrn); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 38 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 39 | printf ("%04x: %08lx\n", dcrn, value); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 40 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 41 | return 0; |
| 42 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | /* ====================================================================== |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 46 | * Interpreter command to set an AMCC PPC 4xx Device Control Register |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 47 | * ====================================================================== |
| 48 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 49 | int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 50 | { |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 51 | unsigned short dcrn; /* Device Control Register Num */ |
| 52 | unsigned long value; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 53 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 54 | /* DCR's value */ |
| 55 | int nbytes; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 56 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 57 | /* Validate arguments */ |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 58 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 59 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 60 | |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 61 | /* Set a DCR */ |
| 62 | dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16); |
| 63 | do { |
| 64 | value = get_dcr (dcrn); |
| 65 | printf ("%04x: %08lx", dcrn, value); |
Simon Glass | e1bf824 | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 66 | nbytes = cli_readline(" ? "); |
Wolfgang Denk | 0c8721a | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 67 | if (nbytes == 0) { |
| 68 | /* |
| 69 | * <CR> pressed as only input, don't modify current |
| 70 | * location and exit command. |
| 71 | */ |
| 72 | nbytes = 1; |
| 73 | return 0; |
| 74 | } else { |
| 75 | unsigned long i; |
| 76 | char *endp; |
| 77 | |
| 78 | i = simple_strtoul (console_buffer, &endp, 16); |
| 79 | nbytes = endp - console_buffer; |
| 80 | if (nbytes) |
| 81 | set_dcr (dcrn, i); |
| 82 | } |
| 83 | } while (nbytes); |
| 84 | |
| 85 | return 0; |
| 86 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 87 | |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 88 | /* ======================================================================= |
| 89 | * Interpreter command to retrieve an register value through AMCC PPC 4xx |
| 90 | * Device Control Register inderect addressing. |
| 91 | * ======================================================================= |
| 92 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 93 | int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 94 | { |
| 95 | unsigned short adr_dcrn; /* Device Control Register Num for Address */ |
| 96 | unsigned short dat_dcrn; /* Device Control Register Num for Data */ |
| 97 | unsigned short offset; /* Register's offset */ |
| 98 | unsigned long value; /* Register's value */ |
| 99 | char *ptr = NULL; |
| 100 | char buf[80]; |
| 101 | |
| 102 | /* Validate arguments */ |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 103 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 104 | return CMD_RET_USAGE; |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 105 | |
| 106 | /* Find out whether ther is '.' (dot) symbol in the first parameter. */ |
| 107 | strncpy (buf, argv[1], sizeof(buf)-1); |
| 108 | buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */ |
| 109 | ptr = strchr (buf, '.'); |
| 110 | |
| 111 | if (ptr != NULL) { |
| 112 | /* First parameter has format adr_dcrn.dat_dcrn */ |
| 113 | *ptr++ = 0; /* erase '.', create zero-end string */ |
| 114 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 115 | dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16); |
| 116 | } else { |
| 117 | /* |
| 118 | * First parameter has format adr_dcrn; dat_dcrn will be |
| 119 | * calculated as adr_dcrn+1. |
| 120 | */ |
| 121 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 122 | dat_dcrn = adr_dcrn+1; |
| 123 | } |
| 124 | |
| 125 | /* Register's offset */ |
| 126 | offset = (unsigned short) simple_strtoul (argv[2], NULL, 16); |
| 127 | |
| 128 | /* Disable interrupts */ |
| 129 | disable_interrupts (); |
| 130 | /* Set offset */ |
| 131 | set_dcr (adr_dcrn, offset); |
| 132 | /* get data */ |
| 133 | value = get_dcr (dat_dcrn); |
| 134 | /* Enable interrupts */ |
| 135 | enable_interrupts (); |
| 136 | |
| 137 | printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | /* ======================================================================= |
| 143 | * Interpreter command to update an register value through AMCC PPC 4xx |
| 144 | * Device Control Register inderect addressing. |
| 145 | * ======================================================================= |
| 146 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 147 | int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 148 | { |
| 149 | unsigned short adr_dcrn; /* Device Control Register Num for Address */ |
| 150 | unsigned short dat_dcrn; /* Device Control Register Num for Data */ |
| 151 | unsigned short offset; /* Register's offset */ |
| 152 | unsigned long value; /* Register's value */ |
| 153 | char *ptr = NULL; |
| 154 | char buf[80]; |
| 155 | |
| 156 | /* Validate arguments */ |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 157 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 158 | return CMD_RET_USAGE; |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 159 | |
| 160 | /* Find out whether ther is '.' (dot) symbol in the first parameter. */ |
| 161 | strncpy (buf, argv[1], sizeof(buf)-1); |
| 162 | buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */ |
| 163 | ptr = strchr (buf, '.'); |
| 164 | |
| 165 | if (ptr != NULL) { |
| 166 | /* First parameter has format adr_dcrn.dat_dcrn */ |
| 167 | *ptr++ = 0; /* erase '.', create zero-end string */ |
| 168 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 169 | dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16); |
| 170 | } else { |
| 171 | /* |
| 172 | * First parameter has format adr_dcrn; dat_dcrn will be |
| 173 | * calculated as adr_dcrn+1. |
| 174 | */ |
Wolfgang Denk | 2b2a40b | 2006-10-26 16:24:31 +0200 | [diff] [blame] | 175 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 176 | dat_dcrn = adr_dcrn+1; |
| 177 | } |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 178 | |
| 179 | /* Register's offset */ |
| 180 | offset = (unsigned short) simple_strtoul (argv[2], NULL, 16); |
| 181 | /* New value */ |
| 182 | value = (unsigned long) simple_strtoul (argv[3], NULL, 16); |
| 183 | |
| 184 | /* Disable interrupts */ |
| 185 | disable_interrupts (); |
| 186 | /* Set offset */ |
| 187 | set_dcr (adr_dcrn, offset); |
| 188 | /* set data */ |
| 189 | set_dcr (dat_dcrn, value); |
| 190 | /* Enable interrupts */ |
| 191 | enable_interrupts (); |
| 192 | |
| 193 | printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 198 | /***************************************************/ |
| 199 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 200 | U_BOOT_CMD( |
| 201 | getdcr, 2, 1, do_getdcr, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 202 | "Get an AMCC PPC 4xx DCR's value", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 203 | "dcrn - return a DCR's value." |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 204 | ); |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 205 | U_BOOT_CMD( |
| 206 | setdcr, 2, 1, do_setdcr, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 207 | "Set an AMCC PPC 4xx DCR's value", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 208 | "dcrn - set a DCR's value." |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 209 | ); |
| 210 | |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 211 | U_BOOT_CMD( |
| 212 | getidcr, 3, 1, do_getidcr, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 213 | "Get a register value via indirect DCR addressing", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 214 | "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn." |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 215 | ); |
| 216 | |
| 217 | U_BOOT_CMD( |
| 218 | setidcr, 4, 1, do_setidcr, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 219 | "Set a register value via indirect DCR addressing", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 220 | "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn." |
Stefan Roese | af9e1f5 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 221 | ); |