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