3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
5 * SPDX-License-Identifier: GPL-2.0+
9 * AMCC 4XX DCR Functions
16 unsigned long get_dcr (unsigned short);
17 unsigned long set_dcr (unsigned short, unsigned long);
19 /* =======================================================================
20 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
21 * =======================================================================
23 int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
25 unsigned short dcrn; /* Device Control Register Num */
26 unsigned long value; /* DCR's value */
28 unsigned long get_dcr (unsigned short);
30 /* Validate arguments */
35 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
36 value = get_dcr (dcrn);
38 printf ("%04x: %08lx\n", dcrn, value);
44 /* ======================================================================
45 * Interpreter command to set an AMCC PPC 4xx Device Control Register
46 * ======================================================================
48 int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
50 unsigned short dcrn; /* Device Control Register Num */
56 /* Validate arguments */
61 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
63 value = get_dcr (dcrn);
64 printf ("%04x: %08lx", dcrn, value);
65 nbytes = readline (" ? ");
68 * <CR> pressed as only input, don't modify current
69 * location and exit command.
77 i = simple_strtoul (console_buffer, &endp, 16);
78 nbytes = endp - console_buffer;
87 /* =======================================================================
88 * Interpreter command to retrieve an register value through AMCC PPC 4xx
89 * Device Control Register inderect addressing.
90 * =======================================================================
92 int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
94 unsigned short adr_dcrn; /* Device Control Register Num for Address */
95 unsigned short dat_dcrn; /* Device Control Register Num for Data */
96 unsigned short offset; /* Register's offset */
97 unsigned long value; /* Register's value */
101 /* Validate arguments */
103 return CMD_RET_USAGE;
105 /* Find out whether ther is '.' (dot) symbol in the first parameter. */
106 strncpy (buf, argv[1], sizeof(buf)-1);
107 buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
108 ptr = strchr (buf, '.');
111 /* First parameter has format adr_dcrn.dat_dcrn */
112 *ptr++ = 0; /* erase '.', create zero-end string */
113 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
114 dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
117 * First parameter has format adr_dcrn; dat_dcrn will be
118 * calculated as adr_dcrn+1.
120 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
121 dat_dcrn = adr_dcrn+1;
124 /* Register's offset */
125 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
127 /* Disable interrupts */
128 disable_interrupts ();
130 set_dcr (adr_dcrn, offset);
132 value = get_dcr (dat_dcrn);
133 /* Enable interrupts */
134 enable_interrupts ();
136 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
141 /* =======================================================================
142 * Interpreter command to update an register value through AMCC PPC 4xx
143 * Device Control Register inderect addressing.
144 * =======================================================================
146 int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
148 unsigned short adr_dcrn; /* Device Control Register Num for Address */
149 unsigned short dat_dcrn; /* Device Control Register Num for Data */
150 unsigned short offset; /* Register's offset */
151 unsigned long value; /* Register's value */
155 /* Validate arguments */
157 return CMD_RET_USAGE;
159 /* Find out whether ther is '.' (dot) symbol in the first parameter. */
160 strncpy (buf, argv[1], sizeof(buf)-1);
161 buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
162 ptr = strchr (buf, '.');
165 /* First parameter has format adr_dcrn.dat_dcrn */
166 *ptr++ = 0; /* erase '.', create zero-end string */
167 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
168 dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
171 * First parameter has format adr_dcrn; dat_dcrn will be
172 * calculated as adr_dcrn+1.
174 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
175 dat_dcrn = adr_dcrn+1;
178 /* Register's offset */
179 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
181 value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
183 /* Disable interrupts */
184 disable_interrupts ();
186 set_dcr (adr_dcrn, offset);
188 set_dcr (dat_dcrn, value);
189 /* Enable interrupts */
190 enable_interrupts ();
192 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
197 /***************************************************/
200 getdcr, 2, 1, do_getdcr,
201 "Get an AMCC PPC 4xx DCR's value",
202 "dcrn - return a DCR's value."
205 setdcr, 2, 1, do_setdcr,
206 "Set an AMCC PPC 4xx DCR's value",
207 "dcrn - set a DCR's value."
211 getidcr, 3, 1, do_getidcr,
212 "Get a register value via indirect DCR addressing",
213 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
217 setidcr, 4, 1, do_setidcr,
218 "Set a register value via indirect DCR addressing",
219 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."