3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
5 * SPDX-License-Identifier: GPL-2.0+
9 * AMCC 4XX DCR Functions
17 unsigned long get_dcr (unsigned short);
18 unsigned long set_dcr (unsigned short, unsigned long);
20 /* =======================================================================
21 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
22 * =======================================================================
24 int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
26 unsigned short dcrn; /* Device Control Register Num */
27 unsigned long value; /* DCR's value */
29 unsigned long get_dcr (unsigned short);
31 /* Validate arguments */
36 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
37 value = get_dcr (dcrn);
39 printf ("%04x: %08lx\n", dcrn, value);
45 /* ======================================================================
46 * Interpreter command to set an AMCC PPC 4xx Device Control Register
47 * ======================================================================
49 int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
51 unsigned short dcrn; /* Device Control Register Num */
57 /* Validate arguments */
62 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
64 value = get_dcr (dcrn);
65 printf ("%04x: %08lx", dcrn, value);
66 nbytes = cli_readline(" ? ");
69 * <CR> pressed as only input, don't modify current
70 * location and exit command.
78 i = simple_strtoul (console_buffer, &endp, 16);
79 nbytes = endp - console_buffer;
88 /* =======================================================================
89 * Interpreter command to retrieve an register value through AMCC PPC 4xx
90 * Device Control Register inderect addressing.
91 * =======================================================================
93 int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
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 */
102 /* Validate arguments */
104 return CMD_RET_USAGE;
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, '.');
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);
118 * First parameter has format adr_dcrn; dat_dcrn will be
119 * calculated as adr_dcrn+1.
121 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
122 dat_dcrn = adr_dcrn+1;
125 /* Register's offset */
126 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
128 /* Disable interrupts */
129 disable_interrupts ();
131 set_dcr (adr_dcrn, offset);
133 value = get_dcr (dat_dcrn);
134 /* Enable interrupts */
135 enable_interrupts ();
137 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
142 /* =======================================================================
143 * Interpreter command to update an register value through AMCC PPC 4xx
144 * Device Control Register inderect addressing.
145 * =======================================================================
147 int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
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 */
156 /* Validate arguments */
158 return CMD_RET_USAGE;
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, '.');
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);
172 * First parameter has format adr_dcrn; dat_dcrn will be
173 * calculated as adr_dcrn+1.
175 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
176 dat_dcrn = adr_dcrn+1;
179 /* Register's offset */
180 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
182 value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
184 /* Disable interrupts */
185 disable_interrupts ();
187 set_dcr (adr_dcrn, offset);
189 set_dcr (dat_dcrn, value);
190 /* Enable interrupts */
191 enable_interrupts ();
193 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
198 /***************************************************/
201 getdcr, 2, 1, do_getdcr,
202 "Get an AMCC PPC 4xx DCR's value",
203 "dcrn - return a DCR's value."
206 setdcr, 2, 1, do_setdcr,
207 "Set an AMCC PPC 4xx DCR's value",
208 "dcrn - set a DCR's value."
212 getidcr, 3, 1, do_getidcr,
213 "Get a register value via indirect DCR addressing",
214 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
218 setidcr, 4, 1, do_setidcr,
219 "Set a register value via indirect DCR addressing",
220 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."