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