blob: 5842471df159b15ed929b5dd916e373078315941 [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
Wolfgang Denke82bc622005-07-28 01:50:14 +020032#if defined(CONFIG_4xx) && (CONFIG_COMMANDS & CFG_CMD_SETGETDCR)
wdenk38635852002-08-27 05:55:31 +000033
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020034/* =======================================================================
35 * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
36 * =======================================================================
wdenk38635852002-08-27 05:55:31 +000037 */
38int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
39{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020040 unsigned short dcrn; /* Device Control Register Num */
41 unsigned long value; /* DCR's value */
wdenk38635852002-08-27 05:55:31 +000042
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020043 unsigned long get_dcr (unsigned short);
wdenk8bde7f72003-06-27 21:31:46 +000044
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020045 /* Validate arguments */
46 if (argc < 2) {
47 printf ("Usage:\n%s\n", cmdtp->usage);
48 return 1;
49 }
wdenk38635852002-08-27 05:55:31 +000050
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020051 /* Get a DCR */
52 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
53 value = get_dcr (dcrn);
wdenk38635852002-08-27 05:55:31 +000054
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020055 printf ("%04x: %08lx\n", dcrn, value);
wdenk38635852002-08-27 05:55:31 +000056
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020057 return 0;
58}
wdenk38635852002-08-27 05:55:31 +000059
60
61/* ======================================================================
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020062 * Interpreter command to set an AMCC PPC 4xx Device Control Register
wdenk38635852002-08-27 05:55:31 +000063 * ======================================================================
64*/
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020065int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
wdenk38635852002-08-27 05:55:31 +000066{
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020067 unsigned long get_dcr (unsigned short);
68 unsigned long set_dcr (unsigned short, unsigned long);
69 unsigned short dcrn; /* Device Control Register Num */
70 unsigned long value;
wdenk38635852002-08-27 05:55:31 +000071
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020072 /* DCR's value */
73 int nbytes;
74 extern char console_buffer[];
wdenk38635852002-08-27 05:55:31 +000075
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020076 /* Validate arguments */
77 if (argc < 2) {
78 printf ("Usage:\n%s\n", cmdtp->usage);
79 return 1;
wdenk8bde7f72003-06-27 21:31:46 +000080 }
wdenk38635852002-08-27 05:55:31 +000081
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020082 /* Set a DCR */
83 dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
84 do {
85 value = get_dcr (dcrn);
86 printf ("%04x: %08lx", dcrn, value);
87 nbytes = readline (" ? ");
88 if (nbytes == 0) {
89 /*
90 * <CR> pressed as only input, don't modify current
91 * location and exit command.
92 */
93 nbytes = 1;
94 return 0;
95 } else {
96 unsigned long i;
97 char *endp;
98
99 i = simple_strtoul (console_buffer, &endp, 16);
100 nbytes = endp - console_buffer;
101 if (nbytes)
102 set_dcr (dcrn, i);
103 }
104 } while (nbytes);
105
106 return 0;
107}
wdenk38635852002-08-27 05:55:31 +0000108
wdenk8bde7f72003-06-27 21:31:46 +0000109/***************************************************/
110
wdenk0d498392003-07-01 21:06:45 +0000111U_BOOT_CMD(
112 getdcr, 2, 1, do_getdcr,
Wolfgang Denk0c8721a2005-09-23 11:05:55 +0200113 "getdcr - Get an AMCC PPC 4xx DCR's value\n",
wdenk8bde7f72003-06-27 21:31:46 +0000114 "dcrn - return a DCR's value.\n"
115);
wdenk0d498392003-07-01 21:06:45 +0000116U_BOOT_CMD(
117 setdcr, 2, 1, do_setdcr,
Wolfgang Denk0c8721a2005-09-23 11:05:55 +0200118 "setdcr - Set an AMCC PPC 4xx DCR's value\n",
wdenk8bde7f72003-06-27 21:31:46 +0000119 "dcrn - set a DCR's value.\n"
120);
121
wdenk38635852002-08-27 05:55:31 +0000122#endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */