wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 1 | /*********************************************************************** |
| 2 | * |
| 3 | M* Modul: lwmon.c |
| 4 | M* |
| 5 | M* Content: LWMON specific U-Boot commands. |
| 6 | * |
| 7 | * (C) Copyright 2001, 2002 |
| 8 | * DENX Software Engineering |
| 9 | * Wolfgang Denk, wd@denx.de |
| 10 | * All rights reserved. |
| 11 | * |
| 12 | D* Design: wd@denx.de |
| 13 | C* Coding: wd@denx.de |
| 14 | V* Verification: dzu@denx.de |
| 15 | * |
| 16 | * See file CREDITS for list of people who contributed to this |
| 17 | * project. |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or |
| 20 | * modify it under the terms of the GNU General Public License as |
| 21 | * published by the Free Software Foundation; either version 2 of |
| 22 | * the License, or (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 32 | * MA 02111-1307 USA |
| 33 | ***********************************************************************/ |
| 34 | |
| 35 | /*---------------------------- Headerfiles ----------------------------*/ |
| 36 | #include <common.h> |
| 37 | #include <mpc8xx.h> |
| 38 | #include <commproc.h> |
| 39 | #include <i2c.h> |
| 40 | #include <command.h> |
| 41 | #include <cmd_bsp.h> |
| 42 | #include <malloc.h> |
| 43 | #include <post.h> |
| 44 | |
| 45 | #include <linux/types.h> |
| 46 | #include <linux/string.h> /* for strdup */ |
| 47 | |
| 48 | /*------------------------ Local prototypes ---------------------------*/ |
| 49 | static long int dram_size (long int, long int *, long int); |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 50 | static void kbd_init (void); |
| 51 | static int compare_magic (uchar *kbd_data, uchar *str); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | /*--------------------- Local macros and constants --------------------*/ |
| 55 | #define _NOT_USED_ 0xFFFFFFFF |
| 56 | |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 57 | #ifdef CONFIG_MODEM_SUPPORT |
| 58 | static int key_pressed(void); |
| 59 | extern void disable_putc(void); |
| 60 | #endif /* CONFIG_MODEM_SUPPORT */ |
| 61 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 62 | /* |
| 63 | * 66 MHz SDRAM access using UPM A |
| 64 | */ |
| 65 | const uint sdram_table[] = |
| 66 | { |
| 67 | #if defined(CFG_MEMORY_75) || defined(CFG_MEMORY_8E) |
| 68 | /* |
| 69 | * Single Read. (Offset 0 in UPM RAM) |
| 70 | */ |
| 71 | 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00, |
| 72 | 0x1FF5FC47, /* last */ |
| 73 | /* |
| 74 | * SDRAM Initialization (offset 5 in UPM RAM) |
| 75 | * |
| 76 | * This is no UPM entry point. The following definition uses |
| 77 | * the remaining space to establish an initialization |
| 78 | * sequence, which is executed by a RUN command. |
| 79 | * |
| 80 | */ |
| 81 | 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */ |
| 82 | /* |
| 83 | * Burst Read. (Offset 8 in UPM RAM) |
| 84 | */ |
| 85 | 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00, |
| 86 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */ |
| 87 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 88 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 89 | /* |
| 90 | * Single Write. (Offset 18 in UPM RAM) |
| 91 | */ |
| 92 | 0x1F2DFC04, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */ |
| 93 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 94 | /* |
| 95 | * Burst Write. (Offset 20 in UPM RAM) |
| 96 | */ |
| 97 | 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00, |
| 98 | 0xF0AFFC00, 0xE1BAFC04, 0x01FF5FC47, /* last */ |
| 99 | _NOT_USED_, |
| 100 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 101 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 102 | /* |
| 103 | * Refresh (Offset 30 in UPM RAM) |
| 104 | */ |
| 105 | 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 106 | 0xFFFFFC84, 0xFFFFFC07, /* last */ |
| 107 | _NOT_USED_, _NOT_USED_, |
| 108 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 109 | /* |
| 110 | * Exception. (Offset 3c in UPM RAM) |
| 111 | */ |
| 112 | 0x7FFFFC07, /* last */ |
| 113 | 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF, |
| 114 | #endif |
| 115 | #ifdef CFG_MEMORY_7E |
| 116 | /* |
| 117 | * Single Read. (Offset 0 in UPM RAM) |
| 118 | */ |
| 119 | 0x0E2DBC04, 0x11AF7C04, 0xEFBAFC00, 0x1FF5FC47, /* last */ |
| 120 | _NOT_USED_, |
| 121 | /* |
| 122 | * SDRAM Initialization (offset 5 in UPM RAM) |
| 123 | * |
| 124 | * This is no UPM entry point. The following definition uses |
| 125 | * the remaining space to establish an initialization |
| 126 | * sequence, which is executed by a RUN command. |
| 127 | * |
| 128 | */ |
| 129 | 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */ |
| 130 | /* |
| 131 | * Burst Read. (Offset 8 in UPM RAM) |
| 132 | */ |
| 133 | 0x0E2DBC04, 0x10AF7C04, 0xF0AFFC00, 0xF0AFFC00, |
| 134 | 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */ |
| 135 | _NOT_USED_, |
| 136 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 137 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 138 | /* |
| 139 | * Single Write. (Offset 18 in UPM RAM) |
| 140 | */ |
| 141 | 0x0E29BC04, 0x01B27C04, 0x1FF5FC47, /* last */ |
| 142 | _NOT_USED_, |
| 143 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 144 | /* |
| 145 | * Burst Write. (Offset 20 in UPM RAM) |
| 146 | */ |
| 147 | 0x0E29BC04, 0x10A77C00, 0xF0AFFC00, 0xF0AFFC00, |
| 148 | 0xE1BAFC04, 0x1FF5FC47, /* last */ |
| 149 | _NOT_USED_, _NOT_USED_, |
| 150 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 151 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 152 | /* |
| 153 | * Refresh (Offset 30 in UPM RAM) |
| 154 | */ |
| 155 | 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 156 | 0xFFFFFC84, 0xFFFFFC07, /* last */ |
| 157 | _NOT_USED_, _NOT_USED_, |
| 158 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 159 | /* |
| 160 | * Exception. (Offset 3c in UPM RAM) |
| 161 | */ |
| 162 | 0x7FFFFC07, /* last */ |
| 163 | 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF, |
| 164 | #endif |
| 165 | }; |
| 166 | |
| 167 | /* |
| 168 | * Check Board Identity: |
| 169 | * |
| 170 | */ |
| 171 | |
| 172 | /*********************************************************************** |
| 173 | F* Function: int checkboard (void) P*A*Z* |
| 174 | * |
| 175 | P* Parameters: none |
| 176 | P* |
| 177 | P* Returnvalue: int - 0 is always returned |
| 178 | * |
| 179 | Z* Intention: This function is the checkboard() method implementation |
| 180 | Z* for the lwmon board. Only a standard message is printed. |
| 181 | * |
| 182 | D* Design: wd@denx.de |
| 183 | C* Coding: wd@denx.de |
| 184 | V* Verification: dzu@denx.de |
| 185 | ***********************************************************************/ |
| 186 | int checkboard (void) |
| 187 | { |
| 188 | puts ("Board: Litronic Monitor IV\n"); |
| 189 | return (0); |
| 190 | } |
| 191 | |
| 192 | /*********************************************************************** |
| 193 | F* Function: long int initdram (int board_type) P*A*Z* |
| 194 | * |
| 195 | P* Parameters: int board_type |
| 196 | P* - Usually type of the board - ignored here. |
| 197 | P* |
| 198 | P* Returnvalue: long int |
| 199 | P* - Size of initialized memory |
| 200 | * |
| 201 | Z* Intention: This function is the initdram() method implementation |
| 202 | Z* for the lwmon board. |
| 203 | Z* The memory controller is initialized to access the |
| 204 | Z* DRAM. |
| 205 | * |
| 206 | D* Design: wd@denx.de |
| 207 | C* Coding: wd@denx.de |
| 208 | V* Verification: dzu@denx.de |
| 209 | ***********************************************************************/ |
| 210 | long int initdram (int board_type) |
| 211 | { |
| 212 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 213 | volatile memctl8xx_t *memctl = &immr->im_memctl; |
| 214 | long int size_b0; |
| 215 | long int size8, size9; |
| 216 | int i; |
| 217 | |
| 218 | /* |
| 219 | * Configure UPMA for SDRAM |
| 220 | */ |
| 221 | upmconfig (UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint)); |
| 222 | |
| 223 | memctl->memc_mptpr = CFG_MPTPR; |
| 224 | |
| 225 | /* burst length=4, burst type=sequential, CAS latency=2 */ |
| 226 | memctl->memc_mar = CFG_MAR; |
| 227 | |
| 228 | /* |
| 229 | * Map controller bank 3 to the SDRAM bank at preliminary address. |
| 230 | */ |
| 231 | memctl->memc_or3 = CFG_OR3_PRELIM; |
| 232 | memctl->memc_br3 = CFG_BR3_PRELIM; |
| 233 | |
| 234 | /* initialize memory address register */ |
| 235 | memctl->memc_mamr = CFG_MAMR_8COL; /* refresh not enabled yet */ |
| 236 | |
| 237 | /* mode initialization (offset 5) */ |
| 238 | udelay (200); /* 0x80006105 */ |
| 239 | memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x05); |
| 240 | |
| 241 | /* run 2 refresh sequence with 4-beat refresh burst (offset 0x30) */ |
| 242 | udelay (1); /* 0x80006130 */ |
| 243 | memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x30); |
| 244 | udelay (1); /* 0x80006130 */ |
| 245 | memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x30); |
| 246 | |
| 247 | udelay (1); /* 0x80006106 */ |
| 248 | memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x06); |
| 249 | |
| 250 | memctl->memc_mamr |= MAMR_PTBE; /* refresh enabled */ |
| 251 | |
| 252 | udelay (200); |
| 253 | |
| 254 | /* Need at least 10 DRAM accesses to stabilize */ |
| 255 | for (i = 0; i < 10; ++i) { |
| 256 | volatile unsigned long *addr = |
| 257 | (volatile unsigned long *) SDRAM_BASE3_PRELIM; |
| 258 | unsigned long val; |
| 259 | |
| 260 | val = *(addr + i); |
| 261 | *(addr + i) = val; |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * Check Bank 0 Memory Size for re-configuration |
| 266 | * |
| 267 | * try 8 column mode |
| 268 | */ |
| 269 | size8 = dram_size (CFG_MAMR_8COL, (ulong *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE); |
| 270 | |
| 271 | udelay (1000); |
| 272 | |
| 273 | /* |
| 274 | * try 9 column mode |
| 275 | */ |
| 276 | size9 = dram_size (CFG_MAMR_9COL, (ulong *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE); |
| 277 | |
| 278 | if (size8 < size9) { /* leave configuration at 9 columns */ |
| 279 | size_b0 = size9; |
| 280 | memctl->memc_mamr = CFG_MAMR_9COL | MAMR_PTBE; |
| 281 | udelay (500); |
| 282 | } else { /* back to 8 columns */ |
| 283 | size_b0 = size8; |
| 284 | memctl->memc_mamr = CFG_MAMR_8COL | MAMR_PTBE; |
| 285 | udelay (500); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Final mapping: |
| 290 | */ |
| 291 | |
| 292 | memctl->memc_or3 = ((-size_b0) & 0xFFFF0000) | |
| 293 | OR_CSNT_SAM | OR_G5LS | SDRAM_TIMING; |
| 294 | memctl->memc_br3 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
| 295 | udelay (1000); |
| 296 | |
| 297 | return (size_b0); |
| 298 | } |
| 299 | |
| 300 | /*********************************************************************** |
| 301 | F* Function: static long int dram_size (long int mamr_value, |
| 302 | F* long int *base, |
| 303 | F* long int maxsize) P*A*Z* |
| 304 | * |
| 305 | P* Parameters: long int mamr_value |
| 306 | P* - Value for MAMR for the test |
| 307 | P* long int *base |
| 308 | P* - Base address for the test |
| 309 | P* long int maxsize |
| 310 | P* - Maximum size to test for |
| 311 | P* |
| 312 | P* Returnvalue: long int |
| 313 | P* - Size of probed memory |
| 314 | * |
| 315 | Z* Intention: Check memory range for valid RAM. A simple memory test |
| 316 | Z* determines the actually available RAM size between |
| 317 | Z* addresses `base' and `base + maxsize'. Some (not all) |
| 318 | Z* hardware errors are detected: |
| 319 | Z* - short between address lines |
| 320 | Z* - short between data lines |
| 321 | * |
| 322 | D* Design: wd@denx.de |
| 323 | C* Coding: wd@denx.de |
| 324 | V* Verification: dzu@denx.de |
| 325 | ***********************************************************************/ |
| 326 | static long int dram_size (long int mamr_value, long int *base, long int maxsize) |
| 327 | { |
| 328 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 329 | volatile memctl8xx_t *memctl = &immr->im_memctl; |
| 330 | volatile long int *addr; |
| 331 | ulong cnt, val; |
| 332 | ulong save[32]; /* to make test non-destructive */ |
| 333 | unsigned char i = 0; |
| 334 | |
| 335 | memctl->memc_mamr = mamr_value; |
| 336 | |
| 337 | for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) { |
| 338 | addr = base + cnt; /* pointer arith! */ |
| 339 | |
| 340 | save[i++] = *addr; |
| 341 | *addr = ~cnt; |
| 342 | } |
| 343 | |
| 344 | /* write 0 to base address */ |
| 345 | addr = base; |
| 346 | save[i] = *addr; |
| 347 | *addr = 0; |
| 348 | |
| 349 | /* check at base address */ |
| 350 | if ((val = *addr) != 0) { |
| 351 | *addr = save[i]; |
| 352 | return (0); |
| 353 | } |
| 354 | |
| 355 | for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) { |
| 356 | addr = base + cnt; /* pointer arith! */ |
| 357 | |
| 358 | val = *addr; |
| 359 | *addr = save[--i]; |
| 360 | |
| 361 | if (val != (~cnt)) { |
| 362 | return (cnt * sizeof (long)); |
| 363 | } |
| 364 | } |
| 365 | return (maxsize); |
| 366 | } |
| 367 | |
| 368 | /* ------------------------------------------------------------------------- */ |
| 369 | |
| 370 | #ifndef PB_ENET_TENA |
| 371 | # define PB_ENET_TENA ((uint)0x00002000) /* PB 18 */ |
| 372 | #endif |
| 373 | |
| 374 | /*********************************************************************** |
| 375 | F* Function: int board_pre_init (void) P*A*Z* |
| 376 | * |
| 377 | P* Parameters: none |
| 378 | P* |
| 379 | P* Returnvalue: int |
| 380 | P* - 0 is always returned. |
| 381 | * |
| 382 | Z* Intention: This function is the board_pre_init() method implementation |
| 383 | Z* for the lwmon board. |
| 384 | Z* Disable Ethernet TENA on Port B. |
| 385 | * |
| 386 | D* Design: wd@denx.de |
| 387 | C* Coding: wd@denx.de |
| 388 | V* Verification: dzu@denx.de |
| 389 | ***********************************************************************/ |
| 390 | int board_pre_init (void) |
| 391 | { |
| 392 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 393 | |
| 394 | /* Disable Ethernet TENA on Port B |
| 395 | * Necessary because of pull up in COM3 port. |
| 396 | * |
| 397 | * This is just a preliminary fix, intended to turn off TENA |
| 398 | * as soon as possible to avoid noise on the network. Once |
| 399 | * I²C is running we will make sure the interface is |
| 400 | * correctly initialized. |
| 401 | */ |
| 402 | immr->im_cpm.cp_pbpar &= ~PB_ENET_TENA; |
| 403 | immr->im_cpm.cp_pbodr &= ~PB_ENET_TENA; |
| 404 | immr->im_cpm.cp_pbdat &= ~PB_ENET_TENA; /* set to 0 = disabled */ |
| 405 | immr->im_cpm.cp_pbdir |= PB_ENET_TENA; |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 406 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 407 | return (0); |
| 408 | } |
| 409 | |
| 410 | /* ------------------------------------------------------------------------- */ |
| 411 | |
| 412 | /*********************************************************************** |
| 413 | F* Function: void reset_phy (void) P*A*Z* |
| 414 | * |
| 415 | P* Parameters: none |
| 416 | P* |
| 417 | P* Returnvalue: none |
| 418 | * |
| 419 | Z* Intention: Reset the PHY. In the lwmon case we do this by the |
| 420 | Z* signaling the PIC I/O expander. |
| 421 | * |
| 422 | D* Design: wd@denx.de |
| 423 | C* Coding: wd@denx.de |
| 424 | V* Verification: dzu@denx.de |
| 425 | ***********************************************************************/ |
| 426 | void reset_phy (void) |
| 427 | { |
| 428 | uchar c; |
| 429 | |
| 430 | #ifdef DEBUG |
| 431 | printf ("### Switch on Ethernet for SCC2 ###\n"); |
| 432 | #endif |
| 433 | c = pic_read (0x61); |
| 434 | #ifdef DEBUG |
| 435 | printf ("Old PIC read: reg_61 = 0x%02x\n", c); |
| 436 | #endif |
| 437 | c |= 0x40; /* disable COM3 */ |
| 438 | c &= ~0x80; /* enable Ethernet */ |
| 439 | pic_write (0x61, c); |
| 440 | #ifdef DEBUG |
| 441 | c = pic_read (0x61); |
| 442 | printf ("New PIC read: reg_61 = 0x%02x\n", c); |
| 443 | #endif |
| 444 | udelay (1000); |
| 445 | } |
| 446 | |
| 447 | |
| 448 | /*------------------------- Keyboard controller -----------------------*/ |
| 449 | /* command codes */ |
| 450 | #define KEYBD_CMD_READ_KEYS 0x01 |
| 451 | #define KEYBD_CMD_READ_VERSION 0x02 |
| 452 | #define KEYBD_CMD_READ_STATUS 0x03 |
| 453 | #define KEYBD_CMD_RESET_ERRORS 0x10 |
| 454 | |
| 455 | /* status codes */ |
| 456 | #define KEYBD_STATUS_MASK 0x3F |
| 457 | #define KEYBD_STATUS_H_RESET 0x20 |
| 458 | #define KEYBD_STATUS_BROWNOUT 0x10 |
| 459 | #define KEYBD_STATUS_WD_RESET 0x08 |
| 460 | #define KEYBD_STATUS_OVERLOAD 0x04 |
| 461 | #define KEYBD_STATUS_ILLEGAL_WR 0x02 |
| 462 | #define KEYBD_STATUS_ILLEGAL_RD 0x01 |
| 463 | |
| 464 | /* Number of bytes returned from Keyboard Controller */ |
| 465 | #define KEYBD_VERSIONLEN 2 /* version information */ |
| 466 | #define KEYBD_DATALEN 9 /* normal key scan data */ |
| 467 | |
| 468 | /* maximum number of "magic" key codes that can be assigned */ |
| 469 | |
| 470 | static uchar kbd_addr = CFG_I2C_KEYBD_ADDR; |
| 471 | |
| 472 | static uchar *key_match (uchar *); |
| 473 | |
| 474 | #define KEYBD_SET_DEBUGMODE '#' /* Magic key to enable debug output */ |
| 475 | |
| 476 | /*********************************************************************** |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 477 | F* Function: int board_postclk_init (void) P*A*Z* |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 478 | * |
| 479 | P* Parameters: none |
| 480 | P* |
| 481 | P* Returnvalue: int |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 482 | P* - 0 is always returned. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 483 | * |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 484 | Z* Intention: This function is the board_postclk_init() method implementation |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 485 | Z* for the lwmon board. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 486 | * |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 487 | ***********************************************************************/ |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 488 | int board_postclk_init (void) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 489 | { |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 490 | DECLARE_GLOBAL_DATA_PTR; |
| 491 | |
| 492 | kbd_init(); |
| 493 | |
| 494 | #ifdef CONFIG_MODEM_SUPPORT |
| 495 | if (key_pressed()) { |
| 496 | disable_putc(); /* modem doesn't understand banner etc */ |
| 497 | gd->do_mdm_init = 1; |
| 498 | } |
| 499 | #endif |
| 500 | |
| 501 | return (0); |
| 502 | } |
| 503 | |
| 504 | static void kbd_init (void) |
| 505 | { |
| 506 | DECLARE_GLOBAL_DATA_PTR; |
| 507 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 508 | uchar kbd_data[KEYBD_DATALEN]; |
| 509 | uchar tmp_data[KEYBD_DATALEN]; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 510 | uchar val, errcd; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 511 | int i; |
| 512 | |
| 513 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 514 | |
| 515 | gd->kbd_status = 0; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 516 | |
| 517 | /* Read initial keyboard error code */ |
| 518 | val = KEYBD_CMD_READ_STATUS; |
| 519 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 520 | i2c_read (kbd_addr, 0, 0, &errcd, 1); |
| 521 | /* clear unused bits */ |
| 522 | errcd &= KEYBD_STATUS_MASK; |
| 523 | /* clear "irrelevant" bits. Recommended by Martin Rajek, LWN */ |
| 524 | errcd &= ~(KEYBD_STATUS_H_RESET|KEYBD_STATUS_BROWNOUT); |
| 525 | if (errcd) { |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 526 | gd->kbd_status |= errcd << 8; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 527 | } |
| 528 | /* Reset error code and verify */ |
| 529 | val = KEYBD_CMD_RESET_ERRORS; |
| 530 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 531 | udelay(1000); /* delay NEEDED by keyboard PIC !!! */ |
| 532 | |
| 533 | val = KEYBD_CMD_READ_STATUS; |
| 534 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 535 | i2c_read (kbd_addr, 0, 0, &val, 1); |
| 536 | |
| 537 | val &= KEYBD_STATUS_MASK; /* clear unused bits */ |
| 538 | if (val) { /* permanent error, report it */ |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 539 | gd->kbd_status |= val; |
| 540 | return; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 541 | } |
| 542 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 543 | /* |
| 544 | * Read current keyboard state. |
| 545 | * |
| 546 | * After the error reset it may take some time before the |
| 547 | * keyboard PIC picks up a valid keyboard scan - the total |
| 548 | * scan time is approx. 1.6 ms (information by Martin Rajek, |
| 549 | * 28 Sep 2002). We read a couple of times for the keyboard |
| 550 | * to stabilize, using a big enough delay. |
| 551 | * 10 times should be enough. If the data is still changing, |
| 552 | * we use what we get :-( |
| 553 | */ |
| 554 | |
| 555 | memset (tmp_data, 0xFF, KEYBD_DATALEN); /* impossible value */ |
| 556 | for (i=0; i<10; ++i) { |
| 557 | val = KEYBD_CMD_READ_KEYS; |
| 558 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 559 | i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); |
| 560 | |
| 561 | if (memcmp(kbd_data, tmp_data, KEYBD_DATALEN) == 0) { |
| 562 | /* consistent state, done */ |
| 563 | break; |
| 564 | } |
| 565 | /* remeber last state, delay, and retry */ |
| 566 | memcpy (tmp_data, kbd_data, KEYBD_DATALEN); |
| 567 | udelay (5000); |
| 568 | } |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 569 | } |
| 570 | |
| 571 | /*********************************************************************** |
| 572 | F* Function: int misc_init_r (void) P*A*Z* |
| 573 | * |
| 574 | P* Parameters: none |
| 575 | P* |
| 576 | P* Returnvalue: int |
| 577 | P* - 0 is always returned, even in the case of a keyboard |
| 578 | P* error. |
| 579 | * |
| 580 | Z* Intention: This function is the misc_init_r() method implementation |
| 581 | Z* for the lwmon board. |
| 582 | Z* The keyboard controller is initialized and the result |
| 583 | Z* of a read copied to the environment variable "keybd". |
| 584 | Z* If KEYBD_SET_DEBUGMODE is defined, a check is made for |
| 585 | Z* this key, and if found display to the LCD will be enabled. |
| 586 | Z* The keys in "keybd" are checked against the magic |
| 587 | Z* keycommands defined in the environment. |
| 588 | Z* See also key_match(). |
| 589 | * |
| 590 | D* Design: wd@denx.de |
| 591 | C* Coding: wd@denx.de |
| 592 | V* Verification: dzu@denx.de |
| 593 | ***********************************************************************/ |
| 594 | int misc_init_r (void) |
| 595 | { |
| 596 | DECLARE_GLOBAL_DATA_PTR; |
| 597 | |
| 598 | uchar kbd_data[KEYBD_DATALEN]; |
| 599 | uchar keybd_env[2 * KEYBD_DATALEN + 1]; |
| 600 | uchar kbd_init_status = gd->kbd_status >> 8; |
| 601 | uchar kbd_status = gd->kbd_status; |
| 602 | uchar val; |
| 603 | uchar *str; |
| 604 | int i; |
| 605 | |
| 606 | if (kbd_init_status) { |
| 607 | printf ("KEYBD: Error %02X\n", kbd_init_status); |
| 608 | } |
| 609 | if (kbd_status) { /* permanent error, report it */ |
| 610 | printf ("*** Keyboard error code %02X ***\n", kbd_status); |
| 611 | sprintf (keybd_env, "%02X", kbd_status); |
| 612 | setenv ("keybd", keybd_env); |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * Now we know that we have a working keyboard, so disable |
| 618 | * all output to the LCD except when a key press is detected. |
| 619 | */ |
| 620 | |
| 621 | if ((console_assign (stdout, "serial") < 0) || |
| 622 | (console_assign (stderr, "serial") < 0)) { |
| 623 | printf ("Can't assign serial port as output device\n"); |
| 624 | } |
| 625 | |
| 626 | /* Read Version */ |
| 627 | val = KEYBD_CMD_READ_VERSION; |
| 628 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 629 | i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_VERSIONLEN); |
| 630 | printf ("KEYBD: Version %d.%d\n", kbd_data[0], kbd_data[1]); |
| 631 | |
| 632 | /* Read current keyboard state */ |
| 633 | val = KEYBD_CMD_READ_KEYS; |
| 634 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 635 | i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 636 | |
| 637 | for (i = 0; i < KEYBD_DATALEN; ++i) { |
| 638 | sprintf (keybd_env + i + i, "%02X", kbd_data[i]); |
| 639 | } |
| 640 | setenv ("keybd", keybd_env); |
| 641 | |
| 642 | str = strdup (key_match (kbd_data)); /* decode keys */ |
| 643 | #ifdef KEYBD_SET_DEBUGMODE |
| 644 | if (kbd_data[0] == KEYBD_SET_DEBUGMODE) { /* set debug mode */ |
| 645 | if ((console_assign (stdout, "lcd") < 0) || |
| 646 | (console_assign (stderr, "lcd") < 0)) { |
| 647 | printf ("Can't assign LCD display as output device\n"); |
| 648 | } |
| 649 | } |
| 650 | #endif /* KEYBD_SET_DEBUGMODE */ |
| 651 | #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */ |
| 652 | setenv ("preboot", str); /* set or delete definition */ |
| 653 | #endif /* CONFIG_PREBOOT */ |
| 654 | if (str != NULL) { |
| 655 | free (str); |
| 656 | } |
| 657 | return (0); |
| 658 | } |
| 659 | |
| 660 | #ifdef CONFIG_PREBOOT |
| 661 | |
| 662 | static uchar kbd_magic_prefix[] = "key_magic"; |
| 663 | static uchar kbd_command_prefix[] = "key_cmd"; |
| 664 | |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 665 | static int compare_magic (uchar *kbd_data, uchar *str) |
| 666 | { |
| 667 | uchar compare[KEYBD_DATALEN-1]; |
| 668 | uchar *nxt; |
| 669 | int i; |
| 670 | |
| 671 | /* Don't include modifier byte */ |
| 672 | memcpy (compare, kbd_data+1, KEYBD_DATALEN-1); |
| 673 | |
| 674 | for (; str != NULL; str = (*nxt) ? nxt+1 : nxt) { |
| 675 | uchar c; |
| 676 | int k; |
| 677 | |
| 678 | c = (uchar) simple_strtoul (str, (char **) (&nxt), 16); |
| 679 | |
| 680 | if (str == nxt) { /* invalid character */ |
| 681 | break; |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | * Check if this key matches the input. |
| 686 | * Set matches to zero, so they match only once |
| 687 | * and we can find duplicates or extra keys |
| 688 | */ |
| 689 | for (k = 0; k < sizeof(compare); ++k) { |
| 690 | if (compare[k] == '\0') /* only non-zero entries */ |
| 691 | continue; |
| 692 | if (c == compare[k]) { /* found matching key */ |
| 693 | compare[k] = '\0'; |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | if (k == sizeof(compare)) { |
| 698 | return -1; /* unmatched key */ |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * A full match leaves no keys in the `compare' array, |
| 704 | */ |
| 705 | for (i = 0; i < sizeof(compare); ++i) { |
| 706 | if (compare[i]) |
| 707 | { |
| 708 | return -1; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 715 | /*********************************************************************** |
| 716 | F* Function: static uchar *key_match (uchar *kbd_data) P*A*Z* |
| 717 | * |
| 718 | P* Parameters: uchar *kbd_data |
| 719 | P* - The keys to match against our magic definitions |
| 720 | P* |
| 721 | P* Returnvalue: uchar * |
| 722 | P* - != NULL: Pointer to the corresponding command(s) |
| 723 | P* NULL: No magic is about to happen |
| 724 | * |
| 725 | Z* Intention: Check if pressed key(s) match magic sequence, |
| 726 | Z* and return the command string associated with that key(s). |
| 727 | Z* |
| 728 | Z* If no key press was decoded, NULL is returned. |
| 729 | Z* |
| 730 | Z* Note: the first character of the argument will be |
| 731 | Z* overwritten with the "magic charcter code" of the |
| 732 | Z* decoded key(s), or '\0'. |
| 733 | Z* |
| 734 | Z* Note: the string points to static environment data |
| 735 | Z* and must be saved before you call any function that |
| 736 | Z* modifies the environment. |
| 737 | * |
| 738 | D* Design: wd@denx.de |
| 739 | C* Coding: wd@denx.de |
| 740 | V* Verification: dzu@denx.de |
| 741 | ***********************************************************************/ |
| 742 | static uchar *key_match (uchar *kbd_data) |
| 743 | { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 744 | uchar magic[sizeof (kbd_magic_prefix) + 1]; |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 745 | uchar *suffix; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 746 | uchar *kbd_magic_keys; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 747 | |
| 748 | /* |
| 749 | * The following string defines the characters that can pe appended |
| 750 | * to "key_magic" to form the names of environment variables that |
| 751 | * hold "magic" key codes, i. e. such key codes that can cause |
| 752 | * pre-boot actions. If the string is empty (""), then only |
| 753 | * "key_magic" is checked (old behaviour); the string "125" causes |
| 754 | * checks for "key_magic1", "key_magic2" and "key_magic5", etc. |
| 755 | */ |
| 756 | if ((kbd_magic_keys = getenv ("magic_keys")) == NULL) |
| 757 | kbd_magic_keys = ""; |
| 758 | |
| 759 | /* loop over all magic keys; |
| 760 | * use '\0' suffix in case of empty string |
| 761 | */ |
| 762 | for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix) { |
| 763 | sprintf (magic, "%s%c", kbd_magic_prefix, *suffix); |
| 764 | #if 0 |
| 765 | printf ("### Check magic \"%s\"\n", magic); |
| 766 | #endif |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 767 | if (compare_magic(kbd_data, getenv(magic)) == 0) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 768 | uchar cmd_name[sizeof (kbd_command_prefix) + 1]; |
| 769 | char *cmd; |
| 770 | |
| 771 | sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix); |
| 772 | |
| 773 | cmd = getenv (cmd_name); |
| 774 | #if 0 |
| 775 | printf ("### Set PREBOOT to $(%s): \"%s\"\n", |
| 776 | cmd_name, cmd ? cmd : "<<NULL>>"); |
| 777 | #endif |
| 778 | *kbd_data = *suffix; |
| 779 | return (cmd); |
| 780 | } |
| 781 | } |
| 782 | #if 0 |
| 783 | printf ("### Delete PREBOOT\n"); |
| 784 | #endif |
| 785 | *kbd_data = '\0'; |
| 786 | return (NULL); |
| 787 | } |
| 788 | #endif /* CONFIG_PREBOOT */ |
| 789 | |
| 790 | /*---------------Board Special Commands: PIC read/write ---------------*/ |
| 791 | |
| 792 | #if (CONFIG_COMMANDS & CFG_CMD_BSP) |
| 793 | /*********************************************************************** |
| 794 | F* Function: int do_pic (cmd_tbl_t *cmdtp, int flag, |
| 795 | F* int argc, char *argv[]) P*A*Z* |
| 796 | * |
| 797 | P* Parameters: cmd_tbl_t *cmdtp |
| 798 | P* - Pointer to our command table entry |
| 799 | P* int flag |
| 800 | P* - If the CMD_FLAG_REPEAT bit is set, then this call is |
| 801 | P* a repetition |
| 802 | P* int argc |
| 803 | P* - Argument count |
| 804 | P* char *argv[] |
| 805 | P* - Array of the actual arguments |
| 806 | P* |
| 807 | P* Returnvalue: int |
| 808 | P* - 0 The command was handled successfully |
| 809 | P* 1 An error occurred |
| 810 | * |
| 811 | Z* Intention: Implement the "pic [read|write]" commands. |
| 812 | Z* The read subcommand takes one argument, the register, |
| 813 | Z* whereas the write command takes two, the register and |
| 814 | Z* the new value. |
| 815 | * |
| 816 | D* Design: wd@denx.de |
| 817 | C* Coding: wd@denx.de |
| 818 | V* Verification: dzu@denx.de |
| 819 | ***********************************************************************/ |
| 820 | int do_pic (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 821 | { |
| 822 | uchar reg, val; |
| 823 | |
| 824 | switch (argc) { |
| 825 | case 3: /* PIC read reg */ |
| 826 | if (strcmp (argv[1], "read") != 0) |
| 827 | break; |
| 828 | |
| 829 | reg = simple_strtoul (argv[2], NULL, 16); |
| 830 | |
| 831 | printf ("PIC read: reg %02x: %02x\n\n", reg, pic_read (reg)); |
| 832 | |
| 833 | return 0; |
| 834 | case 4: /* PIC write reg val */ |
| 835 | if (strcmp (argv[1], "write") != 0) |
| 836 | break; |
| 837 | |
| 838 | reg = simple_strtoul (argv[2], NULL, 16); |
| 839 | val = simple_strtoul (argv[3], NULL, 16); |
| 840 | |
| 841 | printf ("PIC write: reg %02x val 0x%02x: %02x => ", |
| 842 | reg, val, pic_read (reg)); |
| 843 | pic_write (reg, val); |
| 844 | printf ("%02x\n\n", pic_read (reg)); |
| 845 | return 0; |
| 846 | default: |
| 847 | break; |
| 848 | } |
| 849 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 850 | return 1; |
| 851 | } |
| 852 | |
| 853 | /*********************************************************************** |
| 854 | F* Function: int do_kbd (cmd_tbl_t *cmdtp, int flag, |
| 855 | F* int argc, char *argv[]) P*A*Z* |
| 856 | * |
| 857 | P* Parameters: cmd_tbl_t *cmdtp |
| 858 | P* - Pointer to our command table entry |
| 859 | P* int flag |
| 860 | P* - If the CMD_FLAG_REPEAT bit is set, then this call is |
| 861 | P* a repetition |
| 862 | P* int argc |
| 863 | P* - Argument count |
| 864 | P* char *argv[] |
| 865 | P* - Array of the actual arguments |
| 866 | P* |
| 867 | P* Returnvalue: int |
| 868 | P* - 0 is always returned. |
| 869 | * |
| 870 | Z* Intention: Implement the "kbd" command. |
| 871 | Z* The keyboard status is read. The result is printed on |
| 872 | Z* the console and written into the "keybd" environment |
| 873 | Z* variable. |
| 874 | * |
| 875 | D* Design: wd@denx.de |
| 876 | C* Coding: wd@denx.de |
| 877 | V* Verification: dzu@denx.de |
| 878 | ***********************************************************************/ |
| 879 | int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 880 | { |
| 881 | uchar kbd_data[KEYBD_DATALEN]; |
| 882 | uchar keybd_env[2 * KEYBD_DATALEN + 1]; |
| 883 | uchar val; |
| 884 | int i; |
| 885 | |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 886 | #if 0 /* Done in kbd_init */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 887 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 888 | #endif |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 889 | |
| 890 | /* Read keys */ |
| 891 | val = KEYBD_CMD_READ_KEYS; |
| 892 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 893 | i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); |
| 894 | |
| 895 | puts ("Keys:"); |
| 896 | for (i = 0; i < KEYBD_DATALEN; ++i) { |
| 897 | sprintf (keybd_env + i + i, "%02X", kbd_data[i]); |
| 898 | printf (" %02x", kbd_data[i]); |
| 899 | } |
| 900 | putc ('\n'); |
| 901 | setenv ("keybd", keybd_env); |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | /* Read and set LSB switch */ |
wdenk | e7f34c6 | 2003-01-11 09:48:40 +0000 | [diff] [blame] | 906 | #define CFG_PC_TXD1_ENA 0x0008 /* PC.12 */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 907 | |
| 908 | /*********************************************************************** |
| 909 | F* Function: int do_lsb (cmd_tbl_t *cmdtp, int flag, |
| 910 | F* int argc, char *argv[]) P*A*Z* |
| 911 | * |
| 912 | P* Parameters: cmd_tbl_t *cmdtp |
| 913 | P* - Pointer to our command table entry |
| 914 | P* int flag |
| 915 | P* - If the CMD_FLAG_REPEAT bit is set, then this call is |
| 916 | P* a repetition |
| 917 | P* int argc |
| 918 | P* - Argument count |
| 919 | P* char *argv[] |
| 920 | P* - Array of the actual arguments |
| 921 | P* |
| 922 | P* Returnvalue: int |
| 923 | P* - 0 The command was handled successfully |
| 924 | P* 1 An error occurred |
| 925 | * |
| 926 | Z* Intention: Implement the "lsb [on|off]" commands. |
| 927 | Z* The lsb is switched according to the first parameter by |
| 928 | Z* by signaling the PIC I/O expander. |
| 929 | Z* Called with no arguments, the current setting is |
| 930 | Z* printed. |
| 931 | * |
| 932 | D* Design: wd@denx.de |
| 933 | C* Coding: wd@denx.de |
| 934 | V* Verification: dzu@denx.de |
| 935 | ***********************************************************************/ |
| 936 | int do_lsb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 937 | { |
| 938 | uchar val; |
| 939 | immap_t *immr = (immap_t *) CFG_IMMR; |
| 940 | |
| 941 | switch (argc) { |
| 942 | case 1: /* lsb - print setting */ |
| 943 | val = pic_read (0x60); |
| 944 | printf ("LSB is o%s\n", (val & 0x20) ? "n" : "ff"); |
| 945 | return 0; |
| 946 | case 2: /* lsb on or lsb off - set switch */ |
| 947 | val = pic_read (0x60); |
| 948 | |
| 949 | if (strcmp (argv[1], "on") == 0) { |
| 950 | val |= 0x20; |
| 951 | immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA); |
| 952 | immr->im_ioport.iop_pcdat |= CFG_PC_TXD1_ENA; |
| 953 | immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA; |
| 954 | } else if (strcmp (argv[1], "off") == 0) { |
| 955 | val &= ~0x20; |
| 956 | immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA); |
| 957 | immr->im_ioport.iop_pcdat &= ~(CFG_PC_TXD1_ENA); |
| 958 | immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA; |
| 959 | } else { |
| 960 | break; |
| 961 | } |
| 962 | pic_write (0x60, val); |
| 963 | return 0; |
| 964 | default: |
| 965 | break; |
| 966 | } |
| 967 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 968 | return 1; |
| 969 | } |
| 970 | |
| 971 | #endif /* CFG_CMD_BSP */ |
| 972 | |
| 973 | /*----------------------------- Utilities -----------------------------*/ |
| 974 | /*********************************************************************** |
| 975 | F* Function: uchar pic_read (uchar reg) P*A*Z* |
| 976 | * |
| 977 | P* Parameters: uchar reg |
| 978 | P* - Register to read |
| 979 | P* |
| 980 | P* Returnvalue: uchar |
| 981 | P* - Value read from register |
| 982 | * |
| 983 | Z* Intention: Read a register from the PIC I/O expander. |
| 984 | * |
| 985 | D* Design: wd@denx.de |
| 986 | C* Coding: wd@denx.de |
| 987 | V* Verification: dzu@denx.de |
| 988 | ***********************************************************************/ |
| 989 | uchar pic_read (uchar reg) |
| 990 | { |
| 991 | return (i2c_reg_read (CFG_I2C_PICIO_ADDR, reg)); |
| 992 | } |
| 993 | |
| 994 | /*********************************************************************** |
| 995 | F* Function: void pic_write (uchar reg, uchar val) P*A*Z* |
| 996 | * |
| 997 | P* Parameters: uchar reg |
| 998 | P* - Register to read |
| 999 | P* uchar val |
| 1000 | P* - Value to write |
| 1001 | P* |
| 1002 | P* Returnvalue: none |
| 1003 | * |
| 1004 | Z* Intention: Write to a register on the PIC I/O expander. |
| 1005 | * |
| 1006 | D* Design: wd@denx.de |
| 1007 | C* Coding: wd@denx.de |
| 1008 | V* Verification: dzu@denx.de |
| 1009 | ***********************************************************************/ |
| 1010 | void pic_write (uchar reg, uchar val) |
| 1011 | { |
| 1012 | i2c_reg_write (CFG_I2C_PICIO_ADDR, reg, val); |
| 1013 | } |
| 1014 | |
| 1015 | /*---------------------- Board Control Functions ----------------------*/ |
| 1016 | /*********************************************************************** |
| 1017 | F* Function: void board_poweroff (void) P*A*Z* |
| 1018 | * |
| 1019 | P* Parameters: none |
| 1020 | P* |
| 1021 | P* Returnvalue: none |
| 1022 | * |
| 1023 | Z* Intention: Turn off the battery power and loop endless, so this |
| 1024 | Z* should better be the last function you call... |
| 1025 | * |
| 1026 | D* Design: wd@denx.de |
| 1027 | C* Coding: wd@denx.de |
| 1028 | V* Verification: dzu@denx.de |
| 1029 | ***********************************************************************/ |
| 1030 | void board_poweroff (void) |
| 1031 | { |
| 1032 | /* Turn battery off */ |
| 1033 | ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat &= ~(1 << (31 - 13)); |
| 1034 | |
| 1035 | while (1); |
| 1036 | } |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame^] | 1037 | |
| 1038 | #ifdef CONFIG_MODEM_SUPPORT |
| 1039 | static int key_pressed(void) |
| 1040 | { |
| 1041 | uchar kbd_data[KEYBD_DATALEN]; |
| 1042 | uchar val; |
| 1043 | |
| 1044 | /* Read keys */ |
| 1045 | val = KEYBD_CMD_READ_KEYS; |
| 1046 | i2c_write (kbd_addr, 0, 0, &val, 1); |
| 1047 | i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); |
| 1048 | |
| 1049 | return (compare_magic(kbd_data, CONFIG_MODEM_KEY_MAGIC) == 0); |
| 1050 | } |
| 1051 | #endif /* CONFIG_MODEM_SUPPORT */ |