]>
Commit | Line | Data |
---|---|---|
3863585b WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Erik Theisen, Wave 7 Optics, [email protected]. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
3863585b WD |
6 | */ |
7 | ||
8 | /* | |
0c8721a4 | 9 | * AMCC 4XX DCR Functions |
3863585b WD |
10 | */ |
11 | ||
12 | #include <common.h> | |
18d66533 | 13 | #include <cli.h> |
3863585b WD |
14 | #include <config.h> |
15 | #include <command.h> | |
3863585b | 16 | |
af9e1f5b SR |
17 | unsigned long get_dcr (unsigned short); |
18 | unsigned long set_dcr (unsigned short, unsigned long); | |
19 | ||
0c8721a4 WD |
20 | /* ======================================================================= |
21 | * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register | |
22 | * ======================================================================= | |
3863585b | 23 | */ |
54841ab5 | 24 | int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] ) |
3863585b | 25 | { |
0c8721a4 WD |
26 | unsigned short dcrn; /* Device Control Register Num */ |
27 | unsigned long value; /* DCR's value */ | |
3863585b | 28 | |
0c8721a4 | 29 | unsigned long get_dcr (unsigned short); |
8bde7f77 | 30 | |
0c8721a4 | 31 | /* Validate arguments */ |
47e26b1b | 32 | if (argc < 2) |
4c12eeb8 | 33 | return CMD_RET_USAGE; |
3863585b | 34 | |
0c8721a4 WD |
35 | /* Get a DCR */ |
36 | dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16); | |
37 | value = get_dcr (dcrn); | |
3863585b | 38 | |
0c8721a4 | 39 | printf ("%04x: %08lx\n", dcrn, value); |
3863585b | 40 | |
0c8721a4 WD |
41 | return 0; |
42 | } | |
3863585b WD |
43 | |
44 | ||
45 | /* ====================================================================== | |
0c8721a4 | 46 | * Interpreter command to set an AMCC PPC 4xx Device Control Register |
3863585b WD |
47 | * ====================================================================== |
48 | */ | |
54841ab5 | 49 | int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
3863585b | 50 | { |
0c8721a4 WD |
51 | unsigned short dcrn; /* Device Control Register Num */ |
52 | unsigned long value; | |
53 | ||
54 | /* DCR's value */ | |
55 | int nbytes; | |
0c8721a4 WD |
56 | |
57 | /* Validate arguments */ | |
47e26b1b | 58 | if (argc < 2) |
4c12eeb8 | 59 | return CMD_RET_USAGE; |
3863585b | 60 | |
0c8721a4 WD |
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); | |
e1bf824d | 66 | nbytes = cli_readline(" ? "); |
0c8721a4 WD |
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 | } | |
3863585b | 87 | |
af9e1f5b SR |
88 | /* ======================================================================= |
89 | * Interpreter command to retrieve an register value through AMCC PPC 4xx | |
90 | * Device Control Register inderect addressing. | |
91 | * ======================================================================= | |
92 | */ | |
54841ab5 | 93 | int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
af9e1f5b SR |
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 */ | |
47e26b1b | 103 | if (argc < 3) |
4c12eeb8 | 104 | return CMD_RET_USAGE; |
af9e1f5b SR |
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 | */ | |
54841ab5 | 147 | int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
af9e1f5b SR |
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 */ | |
47e26b1b | 157 | if (argc < 4) |
4c12eeb8 | 158 | return CMD_RET_USAGE; |
af9e1f5b SR |
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 | */ | |
2b2a40be WD |
175 | adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16); |
176 | dat_dcrn = adr_dcrn+1; | |
177 | } | |
af9e1f5b SR |
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 | ||
8bde7f77 WD |
198 | /***************************************************/ |
199 | ||
0d498393 WD |
200 | U_BOOT_CMD( |
201 | getdcr, 2, 1, do_getdcr, | |
2fb2604d | 202 | "Get an AMCC PPC 4xx DCR's value", |
a89c33db | 203 | "dcrn - return a DCR's value." |
8bde7f77 | 204 | ); |
0d498393 WD |
205 | U_BOOT_CMD( |
206 | setdcr, 2, 1, do_setdcr, | |
2fb2604d | 207 | "Set an AMCC PPC 4xx DCR's value", |
a89c33db | 208 | "dcrn - set a DCR's value." |
8bde7f77 WD |
209 | ); |
210 | ||
af9e1f5b SR |
211 | U_BOOT_CMD( |
212 | getidcr, 3, 1, do_getidcr, | |
2fb2604d | 213 | "Get a register value via indirect DCR addressing", |
a89c33db | 214 | "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn." |
af9e1f5b SR |
215 | ); |
216 | ||
217 | U_BOOT_CMD( | |
218 | setidcr, 4, 1, do_setidcr, | |
2fb2604d | 219 | "Set a register value via indirect DCR addressing", |
a89c33db | 220 | "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn." |
af9e1f5b | 221 | ); |