blob: 45fe66a7eeb3fb9a2f2ffb2c6f715bc6a8f844fb [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2001
3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24/*
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020025 * AMCC 4XX DCR Functions
wdenk38635852002-08-27 05:55:31 +000026 */
27
28#include <common.h>
29#include <config.h>
30#include <command.h>
wdenk38635852002-08-27 05:55:31 +000031
Stefan Roeseaf9e1f52006-10-17 06:14:31 +020032unsigned long get_dcr (unsigned short);
33unsigned long set_dcr (unsigned short, unsigned long);
34
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020035/* =======================================================================
36 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
37 * =======================================================================
wdenk38635852002-08-27 05:55:31 +000038 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020039int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
wdenk38635852002-08-27 05:55:31 +000040{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020041 unsigned short dcrn; /* Device Control Register Num */
42 unsigned long value; /* DCR's value */
wdenk38635852002-08-27 05:55:31 +000043
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020044 unsigned long get_dcr (unsigned short);
wdenk8bde7f72003-06-27 21:31:46 +000045
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020046 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +020047 if (argc < 2)
48 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +000049
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020050 /* Get a DCR */
51 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
52 value = get_dcr (dcrn);
wdenk38635852002-08-27 05:55:31 +000053
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020054 printf ("%04x: %08lx\n", dcrn, value);
wdenk38635852002-08-27 05:55:31 +000055
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020056 return 0;
57}
wdenk38635852002-08-27 05:55:31 +000058
59
60/* ======================================================================
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020061 * Interpreter command to set an AMCC PPC 4xx Device Control Register
wdenk38635852002-08-27 05:55:31 +000062 * ======================================================================
63*/
Wolfgang Denk54841ab2010-06-28 22:00:46 +020064int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000065{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020066 unsigned short dcrn; /* Device Control Register Num */
67 unsigned long value;
wdenk38635852002-08-27 05:55:31 +000068
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020069 /* DCR's value */
70 int nbytes;
71 extern char console_buffer[];
wdenk38635852002-08-27 05:55:31 +000072
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020073 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +020074 if (argc < 2)
75 return cmd_usage(cmdtp);
wdenk38635852002-08-27 05:55:31 +000076
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020077 /* Set a DCR */
78 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
79 do {
80 value = get_dcr (dcrn);
81 printf ("%04x: %08lx", dcrn, value);
82 nbytes = readline (" ? ");
83 if (nbytes == 0) {
84 /*
85 * <CR> pressed as only input, don't modify current
86 * location and exit command.
87 */
88 nbytes = 1;
89 return 0;
90 } else {
91 unsigned long i;
92 char *endp;
93
94 i = simple_strtoul (console_buffer, &endp, 16);
95 nbytes = endp - console_buffer;
96 if (nbytes)
97 set_dcr (dcrn, i);
98 }
99 } while (nbytes);
100
101 return 0;
102}
wdenk38635852002-08-27 05:55:31 +0000103
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200104/* =======================================================================
105 * Interpreter command to retrieve an register value through AMCC PPC 4xx
106 * Device Control Register inderect addressing.
107 * =======================================================================
108 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200109int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200110{
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 */
115 char *ptr = NULL;
116 char buf[80];
117
118 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200119 if (argc < 3)
120 return cmd_usage(cmdtp);
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200121
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, '.');
126
127 if (ptr != NULL) {
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);
132 } else {
133 /*
134 * First parameter has format adr_dcrn; dat_dcrn will be
135 * calculated as adr_dcrn+1.
136 */
137 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
138 dat_dcrn = adr_dcrn+1;
139 }
140
141 /* Register's offset */
142 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
143
144 /* Disable interrupts */
145 disable_interrupts ();
146 /* Set offset */
147 set_dcr (adr_dcrn, offset);
148 /* get data */
149 value = get_dcr (dat_dcrn);
150 /* Enable interrupts */
151 enable_interrupts ();
152
153 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
154
155 return 0;
156}
157
158/* =======================================================================
159 * Interpreter command to update an register value through AMCC PPC 4xx
160 * Device Control Register inderect addressing.
161 * =======================================================================
162 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200163int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200164{
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 */
169 char *ptr = NULL;
170 char buf[80];
171
172 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200173 if (argc < 4)
174 return cmd_usage(cmdtp);
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200175
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, '.');
180
181 if (ptr != NULL) {
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);
186 } else {
187 /*
188 * First parameter has format adr_dcrn; dat_dcrn will be
189 * calculated as adr_dcrn+1.
190 */
Wolfgang Denk2b2a40b2006-10-26 16:24:31 +0200191 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
192 dat_dcrn = adr_dcrn+1;
193 }
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200194
195 /* Register's offset */
196 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
197 /* New value */
198 value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
199
200 /* Disable interrupts */
201 disable_interrupts ();
202 /* Set offset */
203 set_dcr (adr_dcrn, offset);
204 /* set data */
205 set_dcr (dat_dcrn, value);
206 /* Enable interrupts */
207 enable_interrupts ();
208
209 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
210
211 return 0;
212}
213
wdenk8bde7f72003-06-27 21:31:46 +0000214/***************************************************/
215
wdenk0d498392003-07-01 21:06:45 +0000216U_BOOT_CMD(
217 getdcr, 2, 1, do_getdcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600218 "Get an AMCC PPC 4xx DCR's value",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200219 "dcrn - return a DCR's value."
wdenk8bde7f72003-06-27 21:31:46 +0000220);
wdenk0d498392003-07-01 21:06:45 +0000221U_BOOT_CMD(
222 setdcr, 2, 1, do_setdcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600223 "Set an AMCC PPC 4xx DCR's value",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200224 "dcrn - set a DCR's value."
wdenk8bde7f72003-06-27 21:31:46 +0000225);
226
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200227U_BOOT_CMD(
228 getidcr, 3, 1, do_getidcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600229 "Get a register value via indirect DCR addressing",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200230 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200231);
232
233U_BOOT_CMD(
234 setidcr, 4, 1, do_setidcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600235 "Set a register value via indirect DCR addressing",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200236 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200237);