]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_dcr.c
3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 * AMCC 4XX DCR Functions
32 unsigned long get_dcr (unsigned short);
33 unsigned long set_dcr (unsigned short, unsigned long);
35 /* =======================================================================
36 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
37 * =======================================================================
39 int do_getdcr ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[] )
41 unsigned short dcrn
; /* Device Control Register Num */
42 unsigned long value
; /* DCR's value */
44 unsigned long get_dcr (unsigned short);
46 /* Validate arguments */
48 return cmd_usage(cmdtp
);
51 dcrn
= (unsigned short) simple_strtoul (argv
[1], NULL
, 16);
52 value
= get_dcr (dcrn
);
54 printf ("%04x: %08lx\n", dcrn
, value
);
60 /* ======================================================================
61 * Interpreter command to set an AMCC PPC 4xx Device Control Register
62 * ======================================================================
64 int do_setdcr (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
66 unsigned short dcrn
; /* Device Control Register Num */
72 /* Validate arguments */
74 return cmd_usage(cmdtp
);
77 dcrn
= (unsigned short) simple_strtoul (argv
[1], NULL
, 16);
79 value
= get_dcr (dcrn
);
80 printf ("%04x: %08lx", dcrn
, value
);
81 nbytes
= readline (" ? ");
84 * <CR> pressed as only input, don't modify current
85 * location and exit command.
93 i
= simple_strtoul (console_buffer
, &endp
, 16);
94 nbytes
= endp
- console_buffer
;
103 /* =======================================================================
104 * Interpreter command to retrieve an register value through AMCC PPC 4xx
105 * Device Control Register inderect addressing.
106 * =======================================================================
108 int do_getidcr (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
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 */
117 /* Validate arguments */
119 return cmd_usage(cmdtp
);
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
, '.');
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);
133 * First parameter has format adr_dcrn; dat_dcrn will be
134 * calculated as adr_dcrn+1.
136 adr_dcrn
= (unsigned short) simple_strtoul (buf
, NULL
, 16);
137 dat_dcrn
= adr_dcrn
+1;
140 /* Register's offset */
141 offset
= (unsigned short) simple_strtoul (argv
[2], NULL
, 16);
143 /* Disable interrupts */
144 disable_interrupts ();
146 set_dcr (adr_dcrn
, offset
);
148 value
= get_dcr (dat_dcrn
);
149 /* Enable interrupts */
150 enable_interrupts ();
152 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn
, dat_dcrn
, offset
, value
);
157 /* =======================================================================
158 * Interpreter command to update an register value through AMCC PPC 4xx
159 * Device Control Register inderect addressing.
160 * =======================================================================
162 int do_setidcr (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
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 */
171 /* Validate arguments */
173 return cmd_usage(cmdtp
);
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
, '.');
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);
187 * First parameter has format adr_dcrn; dat_dcrn will be
188 * calculated as adr_dcrn+1.
190 adr_dcrn
= (unsigned short) simple_strtoul (buf
, NULL
, 16);
191 dat_dcrn
= adr_dcrn
+1;
194 /* Register's offset */
195 offset
= (unsigned short) simple_strtoul (argv
[2], NULL
, 16);
197 value
= (unsigned long) simple_strtoul (argv
[3], NULL
, 16);
199 /* Disable interrupts */
200 disable_interrupts ();
202 set_dcr (adr_dcrn
, offset
);
204 set_dcr (dat_dcrn
, value
);
205 /* Enable interrupts */
206 enable_interrupts ();
208 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn
, dat_dcrn
, offset
, value
);
213 /***************************************************/
216 getdcr
, 2, 1, do_getdcr
,
217 "Get an AMCC PPC 4xx DCR's value",
218 "dcrn - return a DCR's value."
221 setdcr
, 2, 1, do_setdcr
,
222 "Set an AMCC PPC 4xx DCR's value",
223 "dcrn - set a DCR's value."
227 getidcr
, 3, 1, do_getidcr
,
228 "Get a register value via indirect DCR addressing",
229 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
233 setidcr
, 4, 1, do_setidcr
,
234 "Set a register value via indirect DCR addressing",
235 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."