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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 25 | * AMCC 4XX DCR Functions |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <config.h> |
| 30 | #include <command.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 31 | |
Wolfgang Denk | 9419a4f | 2005-07-28 01:50:14 +0200 | [diff] [blame] | 32 | #if defined(CONFIG_4xx) && (CONFIG_COMMANDS & CFG_CMD_SETGETDCR) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 33 | |
Stefan Roese | 84cf624 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 34 | unsigned long get_dcr (unsigned short); |
| 35 | unsigned long set_dcr (unsigned short, unsigned long); |
| 36 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 37 | /* ======================================================================= |
| 38 | * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register |
| 39 | * ======================================================================= |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 40 | */ |
| 41 | int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ) |
| 42 | { |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 43 | unsigned short dcrn; /* Device Control Register Num */ |
| 44 | unsigned long value; /* DCR's value */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 45 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 46 | unsigned long get_dcr (unsigned short); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 48 | /* Validate arguments */ |
| 49 | if (argc < 2) { |
| 50 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 51 | return 1; |
| 52 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 53 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 54 | /* Get a DCR */ |
| 55 | dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16); |
| 56 | value = get_dcr (dcrn); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 57 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 58 | printf ("%04x: %08lx\n", dcrn, value); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 59 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 60 | return 0; |
| 61 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 62 | |
| 63 | |
| 64 | /* ====================================================================== |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 65 | * Interpreter command to set an AMCC PPC 4xx Device Control Register |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 66 | * ====================================================================== |
| 67 | */ |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 68 | int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 69 | { |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 70 | unsigned short dcrn; /* Device Control Register Num */ |
| 71 | unsigned long value; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 72 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 73 | /* DCR's value */ |
| 74 | int nbytes; |
| 75 | extern char console_buffer[]; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 76 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 77 | /* Validate arguments */ |
| 78 | if (argc < 2) { |
| 79 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 80 | return 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 81 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 82 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 83 | /* Set a DCR */ |
| 84 | dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16); |
| 85 | do { |
| 86 | value = get_dcr (dcrn); |
| 87 | printf ("%04x: %08lx", dcrn, value); |
| 88 | nbytes = readline (" ? "); |
| 89 | if (nbytes == 0) { |
| 90 | /* |
| 91 | * <CR> pressed as only input, don't modify current |
| 92 | * location and exit command. |
| 93 | */ |
| 94 | nbytes = 1; |
| 95 | return 0; |
| 96 | } else { |
| 97 | unsigned long i; |
| 98 | char *endp; |
| 99 | |
| 100 | i = simple_strtoul (console_buffer, &endp, 16); |
| 101 | nbytes = endp - console_buffer; |
| 102 | if (nbytes) |
| 103 | set_dcr (dcrn, i); |
| 104 | } |
| 105 | } while (nbytes); |
| 106 | |
| 107 | return 0; |
| 108 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 109 | |
Stefan Roese | 84cf624 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 110 | /* ======================================================================= |
| 111 | * Interpreter command to retrieve an register value through AMCC PPC 4xx |
| 112 | * Device Control Register inderect addressing. |
| 113 | * ======================================================================= |
| 114 | */ |
| 115 | int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 116 | { |
| 117 | unsigned short adr_dcrn; /* Device Control Register Num for Address */ |
| 118 | unsigned short dat_dcrn; /* Device Control Register Num for Data */ |
| 119 | unsigned short offset; /* Register's offset */ |
| 120 | unsigned long value; /* Register's value */ |
| 121 | char *ptr = NULL; |
| 122 | char buf[80]; |
| 123 | |
| 124 | /* Validate arguments */ |
| 125 | if (argc < 3) { |
| 126 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 127 | return 1; |
| 128 | } |
| 129 | |
| 130 | /* Find out whether ther is '.' (dot) symbol in the first parameter. */ |
| 131 | strncpy (buf, argv[1], sizeof(buf)-1); |
| 132 | buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */ |
| 133 | ptr = strchr (buf, '.'); |
| 134 | |
| 135 | if (ptr != NULL) { |
| 136 | /* First parameter has format adr_dcrn.dat_dcrn */ |
| 137 | *ptr++ = 0; /* erase '.', create zero-end string */ |
| 138 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 139 | dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16); |
| 140 | } else { |
| 141 | /* |
| 142 | * First parameter has format adr_dcrn; dat_dcrn will be |
| 143 | * calculated as adr_dcrn+1. |
| 144 | */ |
| 145 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 146 | dat_dcrn = adr_dcrn+1; |
| 147 | } |
| 148 | |
| 149 | /* Register's offset */ |
| 150 | offset = (unsigned short) simple_strtoul (argv[2], NULL, 16); |
| 151 | |
| 152 | /* Disable interrupts */ |
| 153 | disable_interrupts (); |
| 154 | /* Set offset */ |
| 155 | set_dcr (adr_dcrn, offset); |
| 156 | /* get data */ |
| 157 | value = get_dcr (dat_dcrn); |
| 158 | /* Enable interrupts */ |
| 159 | enable_interrupts (); |
| 160 | |
| 161 | printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | /* ======================================================================= |
| 167 | * Interpreter command to update an register value through AMCC PPC 4xx |
| 168 | * Device Control Register inderect addressing. |
| 169 | * ======================================================================= |
| 170 | */ |
| 171 | int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 172 | { |
| 173 | unsigned short adr_dcrn; /* Device Control Register Num for Address */ |
| 174 | unsigned short dat_dcrn; /* Device Control Register Num for Data */ |
| 175 | unsigned short offset; /* Register's offset */ |
| 176 | unsigned long value; /* Register's value */ |
| 177 | char *ptr = NULL; |
| 178 | char buf[80]; |
| 179 | |
| 180 | /* Validate arguments */ |
| 181 | if (argc < 4) { |
| 182 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 183 | return 1; |
Wolfgang Denk | 9ba223b | 2006-10-26 16:24:31 +0200 | [diff] [blame] | 184 | } |
Stefan Roese | 84cf624 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 185 | |
| 186 | /* Find out whether ther is '.' (dot) symbol in the first parameter. */ |
| 187 | strncpy (buf, argv[1], sizeof(buf)-1); |
| 188 | buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */ |
| 189 | ptr = strchr (buf, '.'); |
| 190 | |
| 191 | if (ptr != NULL) { |
| 192 | /* First parameter has format adr_dcrn.dat_dcrn */ |
| 193 | *ptr++ = 0; /* erase '.', create zero-end string */ |
| 194 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 195 | dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16); |
| 196 | } else { |
| 197 | /* |
| 198 | * First parameter has format adr_dcrn; dat_dcrn will be |
| 199 | * calculated as adr_dcrn+1. |
| 200 | */ |
Wolfgang Denk | 9ba223b | 2006-10-26 16:24:31 +0200 | [diff] [blame] | 201 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
| 202 | dat_dcrn = adr_dcrn+1; |
| 203 | } |
Stefan Roese | 84cf624 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 204 | |
| 205 | /* Register's offset */ |
| 206 | offset = (unsigned short) simple_strtoul (argv[2], NULL, 16); |
| 207 | /* New value */ |
| 208 | value = (unsigned long) simple_strtoul (argv[3], NULL, 16); |
| 209 | |
| 210 | /* Disable interrupts */ |
| 211 | disable_interrupts (); |
| 212 | /* Set offset */ |
| 213 | set_dcr (adr_dcrn, offset); |
| 214 | /* set data */ |
| 215 | set_dcr (dat_dcrn, value); |
| 216 | /* Enable interrupts */ |
| 217 | enable_interrupts (); |
| 218 | |
| 219 | printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value); |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 224 | /***************************************************/ |
| 225 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 226 | U_BOOT_CMD( |
| 227 | getdcr, 2, 1, do_getdcr, |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 228 | "getdcr - Get an AMCC PPC 4xx DCR's value\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 229 | "dcrn - return a DCR's value.\n" |
| 230 | ); |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 231 | U_BOOT_CMD( |
| 232 | setdcr, 2, 1, do_setdcr, |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 233 | "setdcr - Set an AMCC PPC 4xx DCR's value\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 234 | "dcrn - set a DCR's value.\n" |
| 235 | ); |
| 236 | |
Stefan Roese | 84cf624 | 2006-10-17 06:14:31 +0200 | [diff] [blame] | 237 | U_BOOT_CMD( |
| 238 | getidcr, 3, 1, do_getidcr, |
| 239 | "getidcr - Get a register value via indirect DCR addressing\n", |
| 240 | "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn.\n" |
| 241 | ); |
| 242 | |
| 243 | U_BOOT_CMD( |
| 244 | setidcr, 4, 1, do_setidcr, |
| 245 | "setidcr - Set a register value via indirect DCR addressing\n", |
| 246 | "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn.\n" |
| 247 | ); |
| 248 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 249 | #endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */ |