]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_dcr.c
* Patch by Arun Dharankar, 24 Mar 2003:
[people/ms/u-boot.git] / common / cmd_dcr.c
CommitLineData
3863585b
WD
1/*
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/*
25 * IBM 4XX DCR Functions
26 */
27
28#include <common.h>
29#include <config.h>
30#include <command.h>
31#include <cmd_dcr.h>
32
33#if defined(CONFIG_4xx) && defined(CFG_CMD_SETGETDCR)
34
35/* ======================================================================
36 * Interpreter command to retrieve an IBM PPC 4xx Device Control Register
37 * ======================================================================
38 */
39int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
40{
41 unsigned short dcrn; /* Device Control Register Num */
42 unsigned long value; /* DCR's value */
43
44 /* Validate arguments */
45 if (argc < 2) {
46 printf("Usage:\n%s\n", cmdtp->usage);
47 return 1;
48 }
49
50 /* Get a DCR */
51 dcrn = (unsigned short)simple_strtoul(argv[ 1 ], NULL, 16);
52 value = get_dcr(dcrn);
53
54 printf("%04x: %08lx\n", dcrn, value);
55
56 return 0;
57} /* do_getdcr */
58
59
60/* ======================================================================
61 * Interpreter command to set an IBM PPC 4xx Device Control Register
62 * ======================================================================
63*/
64int do_setdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
65{
66 unsigned short dcrn; /* Device Control Register Num */
67 unsigned long value; /* DCR's value */
68 int nbytes;
69 extern char console_buffer[];
70
71 /* Validate arguments */
72 if (argc < 2) {
73 printf("Usage:\n%s\n", cmdtp->usage);
74 return 1;
75 }
76
77 /* 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 i = simple_strtoul(console_buffer, &endp, 16);
94 nbytes = endp - console_buffer;
95 if (nbytes)
96 set_dcr(dcrn, i);
97 }
98 } while (nbytes);
99
100 return 0;
101} /* do_setdcr */
102
103#endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */