3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
5 * SPDX-License-Identifier: GPL-2.0+
9 * AMCC 4XX DCR Functions
18 unsigned long get_dcr (unsigned short);
19 unsigned long set_dcr (unsigned short, unsigned long);
21 /* =======================================================================
22 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
23 * =======================================================================
25 int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
27 unsigned short dcrn; /* Device Control Register Num */
28 unsigned long value; /* DCR's value */
30 unsigned long get_dcr (unsigned short);
32 /* Validate arguments */
37 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
38 value = get_dcr (dcrn);
40 printf ("%04x: %08lx\n", dcrn, value);
46 /* ======================================================================
47 * Interpreter command to set an AMCC PPC 4xx Device Control Register
48 * ======================================================================
50 int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
52 unsigned short dcrn; /* Device Control Register Num */
58 /* Validate arguments */
63 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
65 value = get_dcr (dcrn);
66 printf ("%04x: %08lx", dcrn, value);
67 nbytes = cli_readline(" ? ");
70 * <CR> pressed as only input, don't modify current
71 * location and exit command.
79 i = simple_strtoul (console_buffer, &endp, 16);
80 nbytes = endp - console_buffer;
89 /* =======================================================================
90 * Interpreter command to retrieve an register value through AMCC PPC 4xx
91 * Device Control Register inderect addressing.
92 * =======================================================================
94 int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
96 unsigned short adr_dcrn; /* Device Control Register Num for Address */
97 unsigned short dat_dcrn; /* Device Control Register Num for Data */
98 unsigned short offset; /* Register's offset */
99 unsigned long value; /* Register's value */
103 /* Validate arguments */
105 return CMD_RET_USAGE;
107 /* Find out whether ther is '.' (dot) symbol in the first parameter. */
108 strncpy (buf, argv[1], sizeof(buf)-1);
109 buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
110 ptr = strchr (buf, '.');
113 /* First parameter has format adr_dcrn.dat_dcrn */
114 *ptr++ = 0; /* erase '.', create zero-end string */
115 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
116 dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
119 * First parameter has format adr_dcrn; dat_dcrn will be
120 * calculated as adr_dcrn+1.
122 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
123 dat_dcrn = adr_dcrn+1;
126 /* Register's offset */
127 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
129 /* Disable interrupts */
130 disable_interrupts ();
132 set_dcr (adr_dcrn, offset);
134 value = get_dcr (dat_dcrn);
135 /* Enable interrupts */
136 enable_interrupts ();
138 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
143 /* =======================================================================
144 * Interpreter command to update an register value through AMCC PPC 4xx
145 * Device Control Register inderect addressing.
146 * =======================================================================
148 int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
150 unsigned short adr_dcrn; /* Device Control Register Num for Address */
151 unsigned short dat_dcrn; /* Device Control Register Num for Data */
152 unsigned short offset; /* Register's offset */
153 unsigned long value; /* Register's value */
157 /* Validate arguments */
159 return CMD_RET_USAGE;
161 /* Find out whether ther is '.' (dot) symbol in the first parameter. */
162 strncpy (buf, argv[1], sizeof(buf)-1);
163 buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
164 ptr = strchr (buf, '.');
167 /* First parameter has format adr_dcrn.dat_dcrn */
168 *ptr++ = 0; /* erase '.', create zero-end string */
169 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
170 dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
173 * First parameter has format adr_dcrn; dat_dcrn will be
174 * calculated as adr_dcrn+1.
176 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
177 dat_dcrn = adr_dcrn+1;
180 /* Register's offset */
181 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
183 value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
185 /* Disable interrupts */
186 disable_interrupts ();
188 set_dcr (adr_dcrn, offset);
190 set_dcr (dat_dcrn, value);
191 /* Enable interrupts */
192 enable_interrupts ();
194 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
199 /***************************************************/
202 getdcr, 2, 1, do_getdcr,
203 "Get an AMCC PPC 4xx DCR's value",
204 "dcrn - return a DCR's value."
207 setdcr, 2, 1, do_setdcr,
208 "Set an AMCC PPC 4xx DCR's value",
209 "dcrn - set a DCR's value."
213 getidcr, 3, 1, do_getidcr,
214 "Get a register value via indirect DCR addressing",
215 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
219 setidcr, 4, 1, do_setidcr,
220 "Set a register value via indirect DCR addressing",
221 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."