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 */
71 extern char console_buffer[];
73 /* Validate arguments */
75 return cmd_usage(cmdtp);
78 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
80 value = get_dcr (dcrn);
81 printf ("%04x: %08lx", dcrn, value);
82 nbytes = readline (" ? ");
85 * <CR> pressed as only input, don't modify current
86 * location and exit command.
94 i = simple_strtoul (console_buffer, &endp, 16);
95 nbytes = endp - console_buffer;
104 /* =======================================================================
105 * Interpreter command to retrieve an register value through AMCC PPC 4xx
106 * Device Control Register inderect addressing.
107 * =======================================================================
109 int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
111 unsigned short adr_dcrn; /* Device Control Register Num for Address */
112 unsigned short dat_dcrn; /* Device Control Register Num for Data */
113 unsigned short offset; /* Register's offset */
114 unsigned long value; /* Register's value */
118 /* Validate arguments */
120 return cmd_usage(cmdtp);
122 /* Find out whether ther is '.' (dot) symbol in the first parameter. */
123 strncpy (buf, argv[1], sizeof(buf)-1);
124 buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
125 ptr = strchr (buf, '.');
128 /* First parameter has format adr_dcrn.dat_dcrn */
129 *ptr++ = 0; /* erase '.', create zero-end string */
130 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
131 dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
134 * First parameter has format adr_dcrn; dat_dcrn will be
135 * calculated as adr_dcrn+1.
137 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
138 dat_dcrn = adr_dcrn+1;
141 /* Register's offset */
142 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
144 /* Disable interrupts */
145 disable_interrupts ();
147 set_dcr (adr_dcrn, offset);
149 value = get_dcr (dat_dcrn);
150 /* Enable interrupts */
151 enable_interrupts ();
153 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
158 /* =======================================================================
159 * Interpreter command to update an register value through AMCC PPC 4xx
160 * Device Control Register inderect addressing.
161 * =======================================================================
163 int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
165 unsigned short adr_dcrn; /* Device Control Register Num for Address */
166 unsigned short dat_dcrn; /* Device Control Register Num for Data */
167 unsigned short offset; /* Register's offset */
168 unsigned long value; /* Register's value */
172 /* Validate arguments */
174 return cmd_usage(cmdtp);
176 /* Find out whether ther is '.' (dot) symbol in the first parameter. */
177 strncpy (buf, argv[1], sizeof(buf)-1);
178 buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
179 ptr = strchr (buf, '.');
182 /* First parameter has format adr_dcrn.dat_dcrn */
183 *ptr++ = 0; /* erase '.', create zero-end string */
184 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
185 dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
188 * First parameter has format adr_dcrn; dat_dcrn will be
189 * calculated as adr_dcrn+1.
191 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
192 dat_dcrn = adr_dcrn+1;
195 /* Register's offset */
196 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
198 value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
200 /* Disable interrupts */
201 disable_interrupts ();
203 set_dcr (adr_dcrn, offset);
205 set_dcr (dat_dcrn, value);
206 /* Enable interrupts */
207 enable_interrupts ();
209 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
214 /***************************************************/
217 getdcr, 2, 1, do_getdcr,
218 "Get an AMCC PPC 4xx DCR's value",
219 "dcrn - return a DCR's value."
222 setdcr, 2, 1, do_setdcr,
223 "Set an AMCC PPC 4xx DCR's value",
224 "dcrn - set a DCR's value."
228 getidcr, 3, 1, do_getidcr,
229 "Get a register value via indirect DCR addressing",
230 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
234 setidcr, 4, 1, do_setidcr,
235 "Set a register value via indirect DCR addressing",
236 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."