blob: 896f79f416c3a10128525cb91576fc285945dfd1 [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>
13#include <config.h>
14#include <command.h>
wdenk38635852002-08-27 05:55:31 +000015
Stefan Roeseaf9e1f52006-10-17 06:14:31 +020016unsigned long get_dcr (unsigned short);
17unsigned long set_dcr (unsigned short, unsigned long);
18
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020019/* =======================================================================
20 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
21 * =======================================================================
wdenk38635852002-08-27 05:55:31 +000022 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020023int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
wdenk38635852002-08-27 05:55:31 +000024{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020025 unsigned short dcrn; /* Device Control Register Num */
26 unsigned long value; /* DCR's value */
wdenk38635852002-08-27 05:55:31 +000027
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020028 unsigned long get_dcr (unsigned short);
wdenk8bde7f72003-06-27 21:31:46 +000029
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020030 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +020031 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000032 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000033
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020034 /* Get a DCR */
35 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
36 value = get_dcr (dcrn);
wdenk38635852002-08-27 05:55:31 +000037
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020038 printf ("%04x: %08lx\n", dcrn, value);
wdenk38635852002-08-27 05:55:31 +000039
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020040 return 0;
41}
wdenk38635852002-08-27 05:55:31 +000042
43
44/* ======================================================================
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020045 * Interpreter command to set an AMCC PPC 4xx Device Control Register
wdenk38635852002-08-27 05:55:31 +000046 * ======================================================================
47*/
Wolfgang Denk54841ab2010-06-28 22:00:46 +020048int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000049{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020050 unsigned short dcrn; /* Device Control Register Num */
51 unsigned long value;
wdenk38635852002-08-27 05:55:31 +000052
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020053 /* DCR's value */
54 int nbytes;
wdenk38635852002-08-27 05:55:31 +000055
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020056 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +020057 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000058 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000059
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020060 /* Set a DCR */
61 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
62 do {
63 value = get_dcr (dcrn);
64 printf ("%04x: %08lx", dcrn, value);
65 nbytes = readline (" ? ");
66 if (nbytes == 0) {
67 /*
68 * <CR> pressed as only input, don't modify current
69 * location and exit command.
70 */
71 nbytes = 1;
72 return 0;
73 } else {
74 unsigned long i;
75 char *endp;
76
77 i = simple_strtoul (console_buffer, &endp, 16);
78 nbytes = endp - console_buffer;
79 if (nbytes)
80 set_dcr (dcrn, i);
81 }
82 } while (nbytes);
83
84 return 0;
85}
wdenk38635852002-08-27 05:55:31 +000086
Stefan Roeseaf9e1f52006-10-17 06:14:31 +020087/* =======================================================================
88 * Interpreter command to retrieve an register value through AMCC PPC 4xx
89 * Device Control Register inderect addressing.
90 * =======================================================================
91 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020092int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roeseaf9e1f52006-10-17 06:14:31 +020093{
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 */
98 char *ptr = NULL;
99 char buf[80];
100
101 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200102 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000103 return CMD_RET_USAGE;
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200104
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, '.');
109
110 if (ptr != NULL) {
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);
115 } else {
116 /*
117 * First parameter has format adr_dcrn; dat_dcrn will be
118 * calculated as adr_dcrn+1.
119 */
120 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
121 dat_dcrn = adr_dcrn+1;
122 }
123
124 /* Register's offset */
125 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
126
127 /* Disable interrupts */
128 disable_interrupts ();
129 /* Set offset */
130 set_dcr (adr_dcrn, offset);
131 /* get data */
132 value = get_dcr (dat_dcrn);
133 /* Enable interrupts */
134 enable_interrupts ();
135
136 printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
137
138 return 0;
139}
140
141/* =======================================================================
142 * Interpreter command to update an register value through AMCC PPC 4xx
143 * Device Control Register inderect addressing.
144 * =======================================================================
145 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200146int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200147{
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 */
152 char *ptr = NULL;
153 char buf[80];
154
155 /* Validate arguments */
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200156 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000157 return CMD_RET_USAGE;
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200158
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, '.');
163
164 if (ptr != NULL) {
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);
169 } else {
170 /*
171 * First parameter has format adr_dcrn; dat_dcrn will be
172 * calculated as adr_dcrn+1.
173 */
Wolfgang Denk2b2a40b2006-10-26 16:24:31 +0200174 adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
175 dat_dcrn = adr_dcrn+1;
176 }
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200177
178 /* Register's offset */
179 offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
180 /* New value */
181 value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
182
183 /* Disable interrupts */
184 disable_interrupts ();
185 /* Set offset */
186 set_dcr (adr_dcrn, offset);
187 /* set data */
188 set_dcr (dat_dcrn, value);
189 /* Enable interrupts */
190 enable_interrupts ();
191
192 printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
193
194 return 0;
195}
196
wdenk8bde7f72003-06-27 21:31:46 +0000197/***************************************************/
198
wdenk0d498392003-07-01 21:06:45 +0000199U_BOOT_CMD(
200 getdcr, 2, 1, do_getdcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600201 "Get an AMCC PPC 4xx DCR's value",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200202 "dcrn - return a DCR's value."
wdenk8bde7f72003-06-27 21:31:46 +0000203);
wdenk0d498392003-07-01 21:06:45 +0000204U_BOOT_CMD(
205 setdcr, 2, 1, do_setdcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600206 "Set an AMCC PPC 4xx DCR's value",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200207 "dcrn - set a DCR's value."
wdenk8bde7f72003-06-27 21:31:46 +0000208);
209
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200210U_BOOT_CMD(
211 getidcr, 3, 1, do_getidcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600212 "Get a register value via indirect DCR addressing",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200213 "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200214);
215
216U_BOOT_CMD(
217 setidcr, 4, 1, do_setidcr,
Peter Tyser2fb26042009-01-27 18:03:12 -0600218 "Set a register value via indirect DCR addressing",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200219 "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."
Stefan Roeseaf9e1f52006-10-17 06:14:31 +0200220);