blob: 4fddd804abd9bbad5b3c682dbe5211151a47b3a0 [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2001
3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00006 */
7
8/*
Wolfgang Denk0c8721a2005-09-23 11:05:55 +02009 * AMCC 4XX DCR Functions
wdenk38635852002-08-27 05:55:31 +000010 */
11
12#include <common.h>
Simon Glass18d66532014-04-10 20:01:25 -060013#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000014#include <config.h>
15#include <command.h>
wdenk38635852002-08-27 05:55:31 +000016
Stefan Roeseaf9e1f52006-10-17 06:14:31 +020017unsigned long get_dcr (unsigned short);
18unsigned long set_dcr (unsigned short, unsigned long);
19
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020020/* =======================================================================
21 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
22 * =======================================================================
wdenk38635852002-08-27 05:55:31 +000023 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020024int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
wdenk38635852002-08-27 05:55:31 +000025{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020026 unsigned short dcrn; /* Device Control Register Num */
27 unsigned long value; /* DCR's value */
wdenk38635852002-08-27 05:55:31 +000028
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020029 unsigned long get_dcr (unsigned short);
wdenk8bde7f72003-06-27 21:31:46 +000030
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020031 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +020032 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000033 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000034
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020035 /* Get a DCR */
36 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
37 value = get_dcr (dcrn);
wdenk38635852002-08-27 05:55:31 +000038
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020039 printf ("%04x: %08lx\n", dcrn, value);
wdenk38635852002-08-27 05:55:31 +000040
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020041 return 0;
42}
wdenk38635852002-08-27 05:55:31 +000043
44
45/* ======================================================================
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020046 * Interpreter command to set an AMCC PPC 4xx Device Control Register
wdenk38635852002-08-27 05:55:31 +000047 * ======================================================================
48*/
Wolfgang Denk54841ab2010-06-28 22:00:46 +020049int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000050{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020051 unsigned short dcrn; /* Device Control Register Num */
52 unsigned long value;
wdenk38635852002-08-27 05:55:31 +000053
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020054 /* DCR's value */
55 int nbytes;
wdenk38635852002-08-27 05:55:31 +000056
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020057 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +020058 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000059 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000060
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020061 /* Set a DCR */
62 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
63 do {
64 value = get_dcr (dcrn);
65 printf ("%04x: %08lx", dcrn, value);
Simon Glasse1bf8242014-04-10 20:01:27 -060066 nbytes = cli_readline(" ? ");
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020067 if (nbytes == 0) {
68 /*
69 * <CR> pressed as only input, don't modify current
70 * location and exit command.
71 */
72 nbytes = 1;
73 return 0;
74 } else {
75 unsigned long i;
76 char *endp;
77
78 i = simple_strtoul (console_buffer, &endp, 16);
79 nbytes = endp - console_buffer;
80 if (nbytes)
81 set_dcr (dcrn, i);
82 }
83 } while (nbytes);
84
85 return 0;
86}
wdenk38635852002-08-27 05:55:31 +000087
Stefan Roeseaf9e1f52006-10-17 06:14:31 +020088/* =======================================================================
89 * Interpreter command to retrieve an register value through AMCC PPC 4xx
90 * Device Control Register inderect addressing.
91 * =======================================================================
92 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020093int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roeseaf9e1f52006-10-17 06:14:31 +020094{
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 */
99 char *ptr = NULL;
100 char buf[80];
101
102 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200103 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000104 return CMD_RET_USAGE;
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200105
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, '.');
110
111 if (ptr != NULL) {
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);
116 } else {
117 /*
118 * First parameter has format adr_dcrn; dat_dcrn will be
119 * calculated as adr_dcrn+1.
120 */
121 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
122 dat_dcrn = adr_dcrn+1;
123 }
124
125 /* Register's offset */
126 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
127
128 /* Disable interrupts */
129 disable_interrupts ();
130 /* Set offset */
131 set_dcr (adr_dcrn, offset);
132 /* get data */
133 value = get_dcr (dat_dcrn);
134 /* Enable interrupts */
135 enable_interrupts ();
136
137 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
138
139 return 0;
140}
141
142/* =======================================================================
143 * Interpreter command to update an register value through AMCC PPC 4xx
144 * Device Control Register inderect addressing.
145 * =======================================================================
146 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200147int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200148{
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 */
153 char *ptr = NULL;
154 char buf[80];
155
156 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200157 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000158 return CMD_RET_USAGE;
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200159
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, '.');
164
165 if (ptr != NULL) {
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);
170 } else {
171 /*
172 * First parameter has format adr_dcrn; dat_dcrn will be
173 * calculated as adr_dcrn+1.
174 */
Wolfgang Denk2b2a40b2006-10-26 16:24:31 +0200175 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
176 dat_dcrn = adr_dcrn+1;
177 }
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200178
179 /* Register's offset */
180 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
181 /* New value */
182 value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
183
184 /* Disable interrupts */
185 disable_interrupts ();
186 /* Set offset */
187 set_dcr (adr_dcrn, offset);
188 /* set data */
189 set_dcr (dat_dcrn, value);
190 /* Enable interrupts */
191 enable_interrupts ();
192
193 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
194
195 return 0;
196}
197
wdenk8bde7f72003-06-27 21:31:46 +0000198/***************************************************/
199
wdenk0d498392003-07-01 21:06:45 +0000200U_BOOT_CMD(
201 getdcr, 2, 1, do_getdcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600202 "Get an AMCC PPC 4xx DCR's value",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200203 "dcrn - return a DCR's value."
wdenk8bde7f72003-06-27 21:31:46 +0000204);
wdenk0d498392003-07-01 21:06:45 +0000205U_BOOT_CMD(
206 setdcr, 2, 1, do_setdcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600207 "Set an AMCC PPC 4xx DCR's value",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200208 "dcrn - set a DCR's value."
wdenk8bde7f72003-06-27 21:31:46 +0000209);
210
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200211U_BOOT_CMD(
212 getidcr, 3, 1, do_getidcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600213 "Get a register value via indirect DCR addressing",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200214 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200215);
216
217U_BOOT_CMD(
218 setidcr, 4, 1, do_setidcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600219 "Set a register value via indirect DCR addressing",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200220 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200221);