wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 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> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 31 | |
| 32 | #if defined(CONFIG_4xx) && defined(CFG_CMD_SETGETDCR) |
| 33 | |
| 34 | /* ====================================================================== |
| 35 | * Interpreter command to retrieve an IBM PPC 4xx Device Control Register |
| 36 | * ====================================================================== |
| 37 | */ |
| 38 | int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ) |
| 39 | { |
| 40 | unsigned short dcrn; /* Device Control Register Num */ |
| 41 | unsigned long value; /* DCR's value */ |
| 42 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 43 | unsigned long get_dcr(unsigned short); |
| 44 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 45 | /* Validate arguments */ |
| 46 | if (argc < 2) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | printf("Usage:\n%s\n", cmdtp->usage); |
| 48 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /* Get a DCR */ |
| 52 | dcrn = (unsigned short)simple_strtoul(argv[ 1 ], NULL, 16); |
| 53 | value = get_dcr(dcrn); |
| 54 | |
| 55 | printf("%04x: %08lx\n", dcrn, value); |
| 56 | |
| 57 | return 0; |
| 58 | } /* do_getdcr */ |
| 59 | |
| 60 | |
| 61 | /* ====================================================================== |
| 62 | * Interpreter command to set an IBM PPC 4xx Device Control Register |
| 63 | * ====================================================================== |
| 64 | */ |
| 65 | int do_setdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 66 | { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | unsigned long get_dcr(unsigned short ); |
| 68 | unsigned long set_dcr(unsigned short , unsigned long ); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 69 | unsigned short dcrn; /* Device Control Register Num */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 70 | unsigned long value; |
| 71 | /* DCR's value */ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 72 | int nbytes; |
| 73 | extern char console_buffer[]; |
| 74 | |
| 75 | /* Validate arguments */ |
| 76 | if (argc < 2) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 77 | printf("Usage:\n%s\n", cmdtp->usage); |
| 78 | return 1; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* Set a DCR */ |
| 82 | dcrn = (unsigned short)simple_strtoul(argv[1], NULL, 16); |
| 83 | do { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 84 | value = get_dcr(dcrn); |
| 85 | printf("%04x: %08lx", dcrn, value); |
| 86 | nbytes = readline(" ? "); |
| 87 | if (nbytes == 0) { |
| 88 | /* |
| 89 | * <CR> pressed as only input, don't modify current |
| 90 | * location and exit command. |
| 91 | */ |
| 92 | nbytes = 1; |
| 93 | return 0; |
| 94 | } else { |
| 95 | unsigned long i; |
| 96 | char *endp; |
| 97 | i = simple_strtoul(console_buffer, &endp, 16); |
| 98 | nbytes = endp - console_buffer; |
| 99 | if (nbytes) |
| 100 | set_dcr(dcrn, i); |
| 101 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 102 | } while (nbytes); |
| 103 | |
| 104 | return 0; |
| 105 | } /* do_setdcr */ |
| 106 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 107 | /***************************************************/ |
| 108 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame^] | 109 | U_BOOT_CMD( |
| 110 | getdcr, 2, 1, do_getdcr, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 111 | "getdcr - Get an IBM PPC 4xx DCR's value\n", |
| 112 | "dcrn - return a DCR's value.\n" |
| 113 | ); |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame^] | 114 | U_BOOT_CMD( |
| 115 | setdcr, 2, 1, do_setdcr, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 116 | "setdcr - Set an IBM PPC 4xx DCR's value\n", |
| 117 | "dcrn - set a DCR's value.\n" |
| 118 | ); |
| 119 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 120 | #endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */ |