wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 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 | #include <common.h> |
| 25 | #include <config.h> |
| 26 | #include <mpc8xx.h> |
| 27 | #include <i2c.h> |
| 28 | |
| 29 | #include <commproc.h> |
| 30 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 31 | #include <malloc.h> |
| 32 | |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/string.h> /* for strdup */ |
| 35 | |
| 36 | |
| 37 | /* |
| 38 | * Memory Controller Using |
| 39 | * |
| 40 | * CS0 - Flash memory (0x40000000) |
| 41 | * CS1 - SDRAM (0x00000000} |
| 42 | * CS2 - |
| 43 | * CS3 - |
| 44 | * CS4 - |
| 45 | * CS5 - |
| 46 | * CS6 - PCMCIA device |
| 47 | * CS7 - PCMCIA device |
| 48 | */ |
| 49 | |
| 50 | /* ------------------------------------------------------------------------- */ |
| 51 | |
| 52 | #define _not_used_ 0xffffffff |
| 53 | |
| 54 | const uint sdram_table[]= |
| 55 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | /* single read. (offset 0 in upm RAM) */ |
| 57 | 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00, |
| 58 | 0x1ff77c47, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 59 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 60 | /* MRS initialization (offset 5) */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 61 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 62 | 0x1ff77c34, 0xefeabc34, 0x1fb57c35, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 63 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 64 | /* burst read. (offset 8 in upm RAM) */ |
| 65 | 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00, |
| 66 | 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47, |
| 67 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 68 | _not_used_, _not_used_, _not_used_, _not_used_, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 70 | /* single write. (offset 18 in upm RAM) */ |
| 71 | 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47, |
| 72 | _not_used_, _not_used_, _not_used_, _not_used_, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 73 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 74 | /* burst write. (offset 20 in upm RAM) */ |
| 75 | 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00, |
| 76 | 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, _not_used_, |
| 77 | _not_used_, _not_used_, _not_used_, _not_used_, |
| 78 | _not_used_, _not_used_, _not_used_, _not_used_, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 79 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 80 | /* refresh. (offset 30 in upm RAM) */ |
| 81 | 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 82 | 0xfffffc84, 0xfffffc07, _not_used_, _not_used_, |
| 83 | _not_used_, _not_used_, _not_used_, _not_used_, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 84 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 85 | /* exception. (offset 3c in upm RAM) */ |
| 86 | 0x7ffffc07, _not_used_, _not_used_, _not_used_ }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 87 | |
| 88 | /* ------------------------------------------------------------------------- */ |
| 89 | |
| 90 | /* |
| 91 | * Check Board Identity: |
| 92 | */ |
| 93 | |
| 94 | int checkboard (void) |
| 95 | { |
| 96 | puts ("Board: R360 MPI Board\n"); |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | /* ------------------------------------------------------------------------- */ |
| 101 | |
| 102 | static long int dram_size (long int, long int *, long int); |
| 103 | |
| 104 | /* ------------------------------------------------------------------------- */ |
| 105 | |
| 106 | long int initdram (int board_type) |
| 107 | { |
| 108 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 109 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 110 | long int size8, size9; |
| 111 | long int size_b0 = 0; |
| 112 | unsigned long reg; |
| 113 | |
| 114 | upmconfig (UPMA, (uint *) sdram_table, |
| 115 | sizeof (sdram_table) / sizeof (uint)); |
| 116 | |
| 117 | /* |
| 118 | * Preliminary prescaler for refresh (depends on number of |
| 119 | * banks): This value is selected for four cycles every 62.4 us |
| 120 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 121 | * bank. It will be adjusted after memory sizing. |
| 122 | */ |
| 123 | memctl->memc_mptpr = CFG_MPTPR_2BK_8K; |
| 124 | |
| 125 | memctl->memc_mar = 0x00000088; |
| 126 | |
| 127 | /* |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 128 | * Map controller bank 2 to the SDRAM bank at |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 129 | * preliminary address - these have to be modified after the |
| 130 | * SDRAM size has been determined. |
| 131 | */ |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 132 | memctl->memc_or2 = CFG_OR2_PRELIM; |
| 133 | memctl->memc_br2 = CFG_BR2_PRELIM; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 134 | |
| 135 | memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */ |
| 136 | |
| 137 | udelay (200); |
| 138 | |
| 139 | /* perform SDRAM initializsation sequence */ |
| 140 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 141 | memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 142 | udelay (200); |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 143 | memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 144 | udelay (200); |
| 145 | |
| 146 | memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */ |
| 147 | |
| 148 | udelay (1000); |
| 149 | |
| 150 | /* |
| 151 | * Check Bank 0 Memory Size for re-configuration |
| 152 | * |
| 153 | * try 8 column mode |
| 154 | */ |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 155 | size8 = dram_size (CFG_MAMR_8COL, (ulong *) SDRAM_BASE2_PRELIM, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 156 | SDRAM_MAX_SIZE); |
| 157 | |
| 158 | udelay (1000); |
| 159 | |
| 160 | /* |
| 161 | * try 9 column mode |
| 162 | */ |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 163 | size9 = dram_size (CFG_MAMR_9COL, (ulong *) SDRAM_BASE2_PRELIM, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | SDRAM_MAX_SIZE); |
| 165 | |
| 166 | if (size8 < size9) { /* leave configuration at 9 columns */ |
| 167 | size_b0 = size9; |
| 168 | /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */ |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 169 | } else { /* back to 8 columns */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | size_b0 = size8; |
| 171 | memctl->memc_mamr = CFG_MAMR_8COL; |
| 172 | udelay (500); |
| 173 | /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */ |
| 174 | } |
| 175 | |
| 176 | udelay (1000); |
| 177 | |
| 178 | /* |
| 179 | * Adjust refresh rate depending on SDRAM type, both banks |
| 180 | * For types > 128 MBit leave it at the current (fast) rate |
| 181 | */ |
| 182 | if ((size_b0 < 0x02000000)) { |
| 183 | /* reduce to 15.6 us (62.4 us / quad) */ |
| 184 | memctl->memc_mptpr = CFG_MPTPR_2BK_4K; |
| 185 | udelay (1000); |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * Final mapping |
| 190 | */ |
| 191 | |
| 192 | memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM; |
| 193 | memctl->memc_br1 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
| 194 | |
| 195 | /* adjust refresh rate depending on SDRAM type, one bank */ |
| 196 | reg = memctl->memc_mptpr; |
| 197 | reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */ |
| 198 | memctl->memc_mptpr = reg; |
| 199 | |
| 200 | udelay (10000); |
| 201 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 202 | #ifdef CONFIG_CAN_DRIVER |
| 203 | /* Initialize OR3 / BR3 */ |
| 204 | memctl->memc_or3 = CFG_OR3_CAN; /* switch GPLB_5 to GPLA_5 */ |
| 205 | memctl->memc_br3 = CFG_BR3_CAN; |
| 206 | |
| 207 | /* Initialize MBMR */ |
| 208 | memctl->memc_mbmr = MAMR_GPL_B4DIS; /* GPL_B4 works as UPWAITB */ |
| 209 | |
| 210 | /* Initialize UPMB for CAN: single read */ |
| 211 | memctl->memc_mdr = 0xFFFFC004; |
| 212 | memctl->memc_mcr = 0x0100 | UPMB; |
| 213 | |
| 214 | memctl->memc_mdr = 0x0FFFD004; |
| 215 | memctl->memc_mcr = 0x0101 | UPMB; |
| 216 | |
| 217 | memctl->memc_mdr = 0x0FFFC000; |
| 218 | memctl->memc_mcr = 0x0102 | UPMB; |
| 219 | |
| 220 | memctl->memc_mdr = 0x3FFFC004; |
| 221 | memctl->memc_mcr = 0x0103 | UPMB; |
| 222 | |
| 223 | memctl->memc_mdr = 0xFFFFDC05; |
| 224 | memctl->memc_mcr = 0x0104 | UPMB; |
| 225 | |
| 226 | /* Initialize UPMB for CAN: single write */ |
| 227 | memctl->memc_mdr = 0xFFFCC004; |
| 228 | memctl->memc_mcr = 0x0118 | UPMB; |
| 229 | |
| 230 | memctl->memc_mdr = 0xCFFCD004; |
| 231 | memctl->memc_mcr = 0x0119 | UPMB; |
| 232 | |
| 233 | memctl->memc_mdr = 0x0FFCC000; |
| 234 | memctl->memc_mcr = 0x011A | UPMB; |
| 235 | |
| 236 | memctl->memc_mdr = 0x7FFCC004; |
| 237 | memctl->memc_mcr = 0x011B | UPMB; |
| 238 | |
| 239 | memctl->memc_mdr = 0xFFFDCC05; |
| 240 | memctl->memc_mcr = 0x011C | UPMB; |
| 241 | #endif |
| 242 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 243 | return (size_b0); |
| 244 | } |
| 245 | |
| 246 | /* ------------------------------------------------------------------------- */ |
| 247 | |
| 248 | /* |
| 249 | * Check memory range for valid RAM. A simple memory test determines |
| 250 | * the actually available RAM size between addresses `base' and |
| 251 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 252 | * - short between address lines |
| 253 | * - short between data lines |
| 254 | */ |
| 255 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 256 | static long int dram_size (long int mamr_value, |
| 257 | long int *base, long int maxsize) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 258 | { |
| 259 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 260 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 261 | volatile long int *addr; |
| 262 | ulong cnt, val; |
| 263 | ulong save[32]; /* to make test non-destructive */ |
| 264 | unsigned char i = 0; |
| 265 | |
| 266 | memctl->memc_mamr = mamr_value; |
| 267 | |
| 268 | for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) { |
| 269 | addr = base + cnt; /* pointer arith! */ |
| 270 | |
| 271 | save[i++] = *addr; |
| 272 | *addr = ~cnt; |
| 273 | } |
| 274 | |
| 275 | /* write 0 to base address */ |
| 276 | addr = base; |
| 277 | save[i] = *addr; |
| 278 | *addr = 0; |
| 279 | |
| 280 | /* check at base address */ |
| 281 | if ((val = *addr) != 0) { |
| 282 | *addr = save[i]; |
| 283 | return (0); |
| 284 | } |
| 285 | |
| 286 | for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) { |
| 287 | addr = base + cnt; /* pointer arith! */ |
| 288 | val = *addr; |
| 289 | *addr = save[--i]; |
| 290 | |
| 291 | if (val != (~cnt)) { |
| 292 | return (cnt * sizeof (long)); |
| 293 | } |
| 294 | } |
| 295 | return (maxsize); |
| 296 | } |
| 297 | |
| 298 | /* ------------------------------------------------------------------------- */ |
| 299 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 300 | void r360_i2c_lcd_write (uchar data0, uchar data1) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 301 | { |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 302 | if (i2c_write (CFG_I2C_LCD_ADDR, data0, 1, &data1, 1)) { |
| 303 | printf("Can't write lcd data 0x%02X 0x%02X.\n", data0, data1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | /* ------------------------------------------------------------------------- */ |
| 308 | |
| 309 | /*----------------------------------------------------------------------- |
| 310 | * Keyboard Controller |
| 311 | */ |
| 312 | |
| 313 | /* Number of bytes returned from Keyboard Controller */ |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 314 | #define KEYBD_KEY_MAX 16 /* maximum key number */ |
| 315 | #define KEYBD_DATALEN ((KEYBD_KEY_MAX + 7) / 8) /* normal key scan data */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 316 | |
| 317 | static uchar *key_match (uchar *); |
| 318 | |
| 319 | int misc_init_r (void) |
| 320 | { |
| 321 | uchar kbd_data[KEYBD_DATALEN]; |
| 322 | uchar keybd_env[2 * KEYBD_DATALEN + 1]; |
| 323 | uchar *str; |
| 324 | int i; |
| 325 | |
| 326 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 327 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 328 | i2c_read (CFG_I2C_KEY_ADDR, 0, 0, kbd_data, KEYBD_DATALEN); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 329 | |
| 330 | for (i = 0; i < KEYBD_DATALEN; ++i) { |
| 331 | sprintf (keybd_env + i + i, "%02X", kbd_data[i]); |
| 332 | } |
| 333 | setenv ("keybd", keybd_env); |
| 334 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 335 | str = strdup (key_match (keybd_env)); /* decode keys */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 336 | |
| 337 | #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */ |
| 338 | setenv ("preboot", str); /* set or delete definition */ |
| 339 | #endif /* CONFIG_PREBOOT */ |
| 340 | if (str != NULL) { |
| 341 | free (str); |
| 342 | } |
| 343 | |
| 344 | return (0); |
| 345 | } |
| 346 | |
| 347 | /*----------------------------------------------------------------------- |
| 348 | * Check if pressed key(s) match magic sequence, |
| 349 | * and return the command string associated with that key(s). |
| 350 | * |
| 351 | * If no key press was decoded, NULL is returned. |
| 352 | * |
| 353 | * Note: the first character of the argument will be overwritten with |
| 354 | * the "magic charcter code" of the decoded key(s), or '\0'. |
| 355 | * |
| 356 | * |
| 357 | * Note: the string points to static environment data and must be |
| 358 | * saved before you call any function that modifies the environment. |
| 359 | */ |
| 360 | #ifdef CONFIG_PREBOOT |
| 361 | |
| 362 | static uchar kbd_magic_prefix[] = "key_magic"; |
| 363 | static uchar kbd_command_prefix[] = "key_cmd"; |
| 364 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 365 | static uchar *key_match (uchar * kbd_str) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 366 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 367 | uchar magic[sizeof (kbd_magic_prefix) + 1]; |
| 368 | uchar cmd_name[sizeof (kbd_command_prefix) + 1]; |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 369 | uchar *str, *suffix; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 370 | uchar *kbd_magic_keys; |
| 371 | char *cmd; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 372 | |
| 373 | /* |
| 374 | * The following string defines the characters that can pe appended |
| 375 | * to "key_magic" to form the names of environment variables that |
| 376 | * hold "magic" key codes, i. e. such key codes that can cause |
| 377 | * pre-boot actions. If the string is empty (""), then only |
| 378 | * "key_magic" is checked (old behaviour); the string "125" causes |
| 379 | * checks for "key_magic1", "key_magic2" and "key_magic5", etc. |
| 380 | */ |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 381 | if ((kbd_magic_keys = getenv ("magic_keys")) != NULL) { |
| 382 | /* loop over all magic keys; |
| 383 | * use '\0' suffix in case of empty string |
| 384 | */ |
| 385 | for (suffix = kbd_magic_keys; |
| 386 | *suffix || suffix == kbd_magic_keys; |
| 387 | ++suffix) { |
| 388 | sprintf (magic, "%s%c", kbd_magic_prefix, *suffix); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 389 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 390 | #if 0 |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 391 | printf ("### Check magic \"%s\"\n", magic); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 392 | #endif |
| 393 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 394 | if ((str = getenv (magic)) != 0) { |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 395 | |
wdenk | 3f9ab98 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 396 | #if 0 |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 397 | printf ("### Compare \"%s\" \"%s\"\n", |
| 398 | kbd_str, str); |
wdenk | 3f9ab98 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 399 | #endif |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 400 | if (strcmp (kbd_str, str) == 0) { |
| 401 | sprintf (cmd_name, "%s%c", |
| 402 | kbd_command_prefix, |
| 403 | *suffix); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 404 | |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 405 | if ((cmd = getenv (cmd_name)) != 0) { |
| 406 | #if 0 |
| 407 | printf ("### Set PREBOOT to $(%s): \"%s\"\n", |
| 408 | cmd_name, cmd); |
| 409 | #endif |
| 410 | return (cmd); |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | } |
| 416 | #if 0 |
| 417 | printf ("### Delete PREBOOT\n"); |
| 418 | #endif |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 419 | *kbd_str = '\0'; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | return (NULL); |
| 421 | } |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 422 | #endif /* CONFIG_PREBOOT */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 423 | |
| 424 | /* Read Keyboard status */ |
| 425 | int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 426 | { |
| 427 | uchar kbd_data[KEYBD_DATALEN]; |
| 428 | uchar keybd_env[2 * KEYBD_DATALEN + 1]; |
| 429 | int i; |
| 430 | |
| 431 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 432 | |
| 433 | /* Read keys */ |
wdenk | d2d1a98 | 2003-04-20 16:49:37 +0000 | [diff] [blame] | 434 | i2c_read (CFG_I2C_KEY_ADDR, 0, 0, kbd_data, KEYBD_DATALEN); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 435 | |
| 436 | puts ("Keys:"); |
| 437 | for (i = 0; i < KEYBD_DATALEN; ++i) { |
| 438 | sprintf (keybd_env + i + i, "%02X", kbd_data[i]); |
| 439 | printf (" %02x", kbd_data[i]); |
| 440 | } |
| 441 | putc ('\n'); |
| 442 | setenv ("keybd", keybd_env); |
| 443 | return 0; |
| 444 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 445 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 446 | U_BOOT_CMD( |
| 447 | kbd, 1, 1, do_kbd, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 448 | "kbd - read keyboard status\n", |
| 449 | NULL |
| 450 | ); |