1 /***********************************************************************
5 M* Content: LWMON specific U-Boot commands.
7 * (C) Copyright 2001, 2002
8 * DENX Software Engineering
10 * All rights reserved.
16 * See file CREDITS for list of people who contributed to this
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.
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.
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,
33 ***********************************************************************/
35 /*---------------------------- Headerfiles ----------------------------*/
44 #include <linux/types.h>
45 #include <linux/string.h> /* for strdup */
47 /*------------------------ Local prototypes ---------------------------*/
48 static long int dram_size (long int, long int *, long int);
49 static void kbd_init (void);
50 static int compare_magic (uchar *kbd_data, uchar *str);
53 /*--------------------- Local macros and constants --------------------*/
54 #define _NOT_USED_ 0xFFFFFFFF
56 #ifdef CONFIG_MODEM_SUPPORT
57 static int key_pressed(void);
58 extern void disable_putc(void);
59 #endif /* CONFIG_MODEM_SUPPORT */
62 * 66 MHz SDRAM access using UPM A
64 const uint sdram_table[] =
66 #if defined(CFG_MEMORY_75) || defined(CFG_MEMORY_8E)
68 * Single Read. (Offset 0 in UPM RAM)
70 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
71 0x1FF5FC47, /* last */
73 * SDRAM Initialization (offset 5 in UPM RAM)
75 * This is no UPM entry point. The following definition uses
76 * the remaining space to establish an initialization
77 * sequence, which is executed by a RUN command.
80 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
82 * Burst Read. (Offset 8 in UPM RAM)
84 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
85 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
86 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
87 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
89 * Single Write. (Offset 18 in UPM RAM)
91 0x1F2DFC04, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */
92 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
94 * Burst Write. (Offset 20 in UPM RAM)
96 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
97 0xF0AFFC00, 0xE1BAFC04, 0x01FF5FC47, /* last */
99 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
100 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
102 * Refresh (Offset 30 in UPM RAM)
104 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
105 0xFFFFFC84, 0xFFFFFC07, /* last */
106 _NOT_USED_, _NOT_USED_,
107 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
109 * Exception. (Offset 3c in UPM RAM)
111 0x7FFFFC07, /* last */
112 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
116 * Single Read. (Offset 0 in UPM RAM)
118 0x0E2DBC04, 0x11AF7C04, 0xEFBAFC00, 0x1FF5FC47, /* last */
121 * SDRAM Initialization (offset 5 in UPM RAM)
123 * This is no UPM entry point. The following definition uses
124 * the remaining space to establish an initialization
125 * sequence, which is executed by a RUN command.
128 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
130 * Burst Read. (Offset 8 in UPM RAM)
132 0x0E2DBC04, 0x10AF7C04, 0xF0AFFC00, 0xF0AFFC00,
133 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
135 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
136 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
138 * Single Write. (Offset 18 in UPM RAM)
140 0x0E29BC04, 0x01B27C04, 0x1FF5FC47, /* last */
142 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
144 * Burst Write. (Offset 20 in UPM RAM)
146 0x0E29BC04, 0x10A77C00, 0xF0AFFC00, 0xF0AFFC00,
147 0xE1BAFC04, 0x1FF5FC47, /* last */
148 _NOT_USED_, _NOT_USED_,
149 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
150 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
152 * Refresh (Offset 30 in UPM RAM)
154 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
155 0xFFFFFC84, 0xFFFFFC07, /* last */
156 _NOT_USED_, _NOT_USED_,
157 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
159 * Exception. (Offset 3c in UPM RAM)
161 0x7FFFFC07, /* last */
162 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
167 * Check Board Identity:
171 /***********************************************************************
172 F* Function: int checkboard (void) P*A*Z*
176 P* Returnvalue: int - 0 is always returned
178 Z* Intention: This function is the checkboard() method implementation
179 Z* for the lwmon board. Only a standard message is printed.
184 ***********************************************************************/
185 int checkboard (void)
187 puts ("Board: Litronic Monitor IV\n");
191 /***********************************************************************
192 F* Function: long int initdram (int board_type) P*A*Z*
194 P* Parameters: int board_type
195 P* - Usually type of the board - ignored here.
197 P* Returnvalue: long int
198 P* - Size of initialized memory
200 Z* Intention: This function is the initdram() method implementation
201 Z* for the lwmon board.
202 Z* The memory controller is initialized to access the
208 ***********************************************************************/
209 long int initdram (int board_type)
211 volatile immap_t *immr = (immap_t *) CFG_IMMR;
212 volatile memctl8xx_t *memctl = &immr->im_memctl;
214 long int size8, size9;
218 * Configure UPMA for SDRAM
220 upmconfig (UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
222 memctl->memc_mptpr = CFG_MPTPR;
224 /* burst length=4, burst type=sequential, CAS latency=2 */
225 memctl->memc_mar = CFG_MAR;
228 * Map controller bank 3 to the SDRAM bank at preliminary address.
230 memctl->memc_or3 = CFG_OR3_PRELIM;
231 memctl->memc_br3 = CFG_BR3_PRELIM;
233 /* initialize memory address register */
234 memctl->memc_mamr = CFG_MAMR_8COL; /* refresh not enabled yet */
236 /* mode initialization (offset 5) */
237 udelay (200); /* 0x80006105 */
238 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x05);
240 /* run 2 refresh sequence with 4-beat refresh burst (offset 0x30) */
241 udelay (1); /* 0x80006130 */
242 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x30);
243 udelay (1); /* 0x80006130 */
244 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x30);
246 udelay (1); /* 0x80006106 */
247 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x06);
249 memctl->memc_mamr |= MAMR_PTBE; /* refresh enabled */
253 /* Need at least 10 DRAM accesses to stabilize */
254 for (i = 0; i < 10; ++i) {
255 volatile unsigned long *addr =
256 (volatile unsigned long *) SDRAM_BASE3_PRELIM;
264 * Check Bank 0 Memory Size for re-configuration
268 size8 = dram_size (CFG_MAMR_8COL, (ulong *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
275 size9 = dram_size (CFG_MAMR_9COL, (ulong *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
277 if (size8 < size9) { /* leave configuration at 9 columns */
279 memctl->memc_mamr = CFG_MAMR_9COL | MAMR_PTBE;
281 } else { /* back to 8 columns */
283 memctl->memc_mamr = CFG_MAMR_8COL | MAMR_PTBE;
291 memctl->memc_or3 = ((-size_b0) & 0xFFFF0000) |
292 OR_CSNT_SAM | OR_G5LS | SDRAM_TIMING;
293 memctl->memc_br3 = (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
299 /***********************************************************************
300 F* Function: static long int dram_size (long int mamr_value,
302 F* long int maxsize) P*A*Z*
304 P* Parameters: long int mamr_value
305 P* - Value for MAMR for the test
307 P* - Base address for the test
309 P* - Maximum size to test for
311 P* Returnvalue: long int
312 P* - Size of probed memory
314 Z* Intention: Check memory range for valid RAM. A simple memory test
315 Z* determines the actually available RAM size between
316 Z* addresses `base' and `base + maxsize'. Some (not all)
317 Z* hardware errors are detected:
318 Z* - short between address lines
319 Z* - short between data lines
324 ***********************************************************************/
325 static long int dram_size (long int mamr_value, long int *base, long int maxsize)
327 volatile immap_t *immr = (immap_t *) CFG_IMMR;
328 volatile memctl8xx_t *memctl = &immr->im_memctl;
329 volatile long int *addr;
331 ulong save[32]; /* to make test non-destructive */
334 memctl->memc_mamr = mamr_value;
336 for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
337 addr = base + cnt; /* pointer arith! */
343 /* write 0 to base address */
348 /* check at base address */
349 if ((val = *addr) != 0) {
354 for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
355 addr = base + cnt; /* pointer arith! */
361 return (cnt * sizeof (long));
367 /* ------------------------------------------------------------------------- */
370 # define PB_ENET_TENA ((uint)0x00002000) /* PB 18 */
373 /***********************************************************************
374 F* Function: int board_pre_init (void) P*A*Z*
379 P* - 0 is always returned.
381 Z* Intention: This function is the board_pre_init() method implementation
382 Z* for the lwmon board.
383 Z* Disable Ethernet TENA on Port B.
388 ***********************************************************************/
389 int board_pre_init (void)
391 volatile immap_t *immr = (immap_t *) CFG_IMMR;
393 /* Disable Ethernet TENA on Port B
394 * Necessary because of pull up in COM3 port.
396 * This is just a preliminary fix, intended to turn off TENA
397 * as soon as possible to avoid noise on the network. Once
398 * I²C is running we will make sure the interface is
399 * correctly initialized.
401 immr->im_cpm.cp_pbpar &= ~PB_ENET_TENA;
402 immr->im_cpm.cp_pbodr &= ~PB_ENET_TENA;
403 immr->im_cpm.cp_pbdat &= ~PB_ENET_TENA; /* set to 0 = disabled */
404 immr->im_cpm.cp_pbdir |= PB_ENET_TENA;
409 /* ------------------------------------------------------------------------- */
411 /***********************************************************************
412 F* Function: void reset_phy (void) P*A*Z*
418 Z* Intention: Reset the PHY. In the lwmon case we do this by the
419 Z* signaling the PIC I/O expander.
424 ***********************************************************************/
425 void reset_phy (void)
430 printf ("### Switch on Ethernet for SCC2 ###\n");
434 printf ("Old PIC read: reg_61 = 0x%02x\n", c);
436 c |= 0x40; /* disable COM3 */
437 c &= ~0x80; /* enable Ethernet */
441 printf ("New PIC read: reg_61 = 0x%02x\n", c);
447 /*------------------------- Keyboard controller -----------------------*/
449 #define KEYBD_CMD_READ_KEYS 0x01
450 #define KEYBD_CMD_READ_VERSION 0x02
451 #define KEYBD_CMD_READ_STATUS 0x03
452 #define KEYBD_CMD_RESET_ERRORS 0x10
455 #define KEYBD_STATUS_MASK 0x3F
456 #define KEYBD_STATUS_H_RESET 0x20
457 #define KEYBD_STATUS_BROWNOUT 0x10
458 #define KEYBD_STATUS_WD_RESET 0x08
459 #define KEYBD_STATUS_OVERLOAD 0x04
460 #define KEYBD_STATUS_ILLEGAL_WR 0x02
461 #define KEYBD_STATUS_ILLEGAL_RD 0x01
463 /* Number of bytes returned from Keyboard Controller */
464 #define KEYBD_VERSIONLEN 2 /* version information */
465 #define KEYBD_DATALEN 9 /* normal key scan data */
467 /* maximum number of "magic" key codes that can be assigned */
469 static uchar kbd_addr = CFG_I2C_KEYBD_ADDR;
471 static uchar *key_match (uchar *);
473 #define KEYBD_SET_DEBUGMODE '#' /* Magic key to enable debug output */
475 /***********************************************************************
476 F* Function: int board_postclk_init (void) P*A*Z*
481 P* - 0 is always returned.
483 Z* Intention: This function is the board_postclk_init() method implementation
484 Z* for the lwmon board.
486 ***********************************************************************/
487 int board_postclk_init (void)
489 DECLARE_GLOBAL_DATA_PTR;
493 #ifdef CONFIG_MODEM_SUPPORT
495 disable_putc(); /* modem doesn't understand banner etc */
503 static void kbd_init (void)
505 DECLARE_GLOBAL_DATA_PTR;
507 uchar kbd_data[KEYBD_DATALEN];
508 uchar tmp_data[KEYBD_DATALEN];
512 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
516 /* Read initial keyboard error code */
517 val = KEYBD_CMD_READ_STATUS;
518 i2c_write (kbd_addr, 0, 0, &val, 1);
519 i2c_read (kbd_addr, 0, 0, &errcd, 1);
520 /* clear unused bits */
521 errcd &= KEYBD_STATUS_MASK;
522 /* clear "irrelevant" bits. Recommended by Martin Rajek, LWN */
523 errcd &= ~(KEYBD_STATUS_H_RESET|KEYBD_STATUS_BROWNOUT);
525 gd->kbd_status |= errcd << 8;
527 /* Reset error code and verify */
528 val = KEYBD_CMD_RESET_ERRORS;
529 i2c_write (kbd_addr, 0, 0, &val, 1);
530 udelay(1000); /* delay NEEDED by keyboard PIC !!! */
532 val = KEYBD_CMD_READ_STATUS;
533 i2c_write (kbd_addr, 0, 0, &val, 1);
534 i2c_read (kbd_addr, 0, 0, &val, 1);
536 val &= KEYBD_STATUS_MASK; /* clear unused bits */
537 if (val) { /* permanent error, report it */
538 gd->kbd_status |= val;
543 * Read current keyboard state.
545 * After the error reset it may take some time before the
546 * keyboard PIC picks up a valid keyboard scan - the total
547 * scan time is approx. 1.6 ms (information by Martin Rajek,
548 * 28 Sep 2002). We read a couple of times for the keyboard
549 * to stabilize, using a big enough delay.
550 * 10 times should be enough. If the data is still changing,
551 * we use what we get :-(
554 memset (tmp_data, 0xFF, KEYBD_DATALEN); /* impossible value */
555 for (i=0; i<10; ++i) {
556 val = KEYBD_CMD_READ_KEYS;
557 i2c_write (kbd_addr, 0, 0, &val, 1);
558 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
560 if (memcmp(kbd_data, tmp_data, KEYBD_DATALEN) == 0) {
561 /* consistent state, done */
564 /* remeber last state, delay, and retry */
565 memcpy (tmp_data, kbd_data, KEYBD_DATALEN);
570 /***********************************************************************
571 F* Function: int misc_init_r (void) P*A*Z*
576 P* - 0 is always returned, even in the case of a keyboard
579 Z* Intention: This function is the misc_init_r() method implementation
580 Z* for the lwmon board.
581 Z* The keyboard controller is initialized and the result
582 Z* of a read copied to the environment variable "keybd".
583 Z* If KEYBD_SET_DEBUGMODE is defined, a check is made for
584 Z* this key, and if found display to the LCD will be enabled.
585 Z* The keys in "keybd" are checked against the magic
586 Z* keycommands defined in the environment.
587 Z* See also key_match().
592 ***********************************************************************/
593 int misc_init_r (void)
595 DECLARE_GLOBAL_DATA_PTR;
597 uchar kbd_data[KEYBD_DATALEN];
598 uchar keybd_env[2 * KEYBD_DATALEN + 1];
599 uchar kbd_init_status = gd->kbd_status >> 8;
600 uchar kbd_status = gd->kbd_status;
605 if (kbd_init_status) {
606 printf ("KEYBD: Error %02X\n", kbd_init_status);
608 if (kbd_status) { /* permanent error, report it */
609 printf ("*** Keyboard error code %02X ***\n", kbd_status);
610 sprintf (keybd_env, "%02X", kbd_status);
611 setenv ("keybd", keybd_env);
616 * Now we know that we have a working keyboard, so disable
617 * all output to the LCD except when a key press is detected.
620 if ((console_assign (stdout, "serial") < 0) ||
621 (console_assign (stderr, "serial") < 0)) {
622 printf ("Can't assign serial port as output device\n");
626 val = KEYBD_CMD_READ_VERSION;
627 i2c_write (kbd_addr, 0, 0, &val, 1);
628 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_VERSIONLEN);
629 printf ("KEYBD: Version %d.%d\n", kbd_data[0], kbd_data[1]);
631 /* Read current keyboard state */
632 val = KEYBD_CMD_READ_KEYS;
633 i2c_write (kbd_addr, 0, 0, &val, 1);
634 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
636 for (i = 0; i < KEYBD_DATALEN; ++i) {
637 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
639 setenv ("keybd", keybd_env);
641 str = strdup (key_match (kbd_data)); /* decode keys */
642 #ifdef KEYBD_SET_DEBUGMODE
643 if (kbd_data[0] == KEYBD_SET_DEBUGMODE) { /* set debug mode */
644 if ((console_assign (stdout, "lcd") < 0) ||
645 (console_assign (stderr, "lcd") < 0)) {
646 printf ("Can't assign LCD display as output device\n");
649 #endif /* KEYBD_SET_DEBUGMODE */
650 #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
651 setenv ("preboot", str); /* set or delete definition */
652 #endif /* CONFIG_PREBOOT */
659 #ifdef CONFIG_PREBOOT
661 static uchar kbd_magic_prefix[] = "key_magic";
662 static uchar kbd_command_prefix[] = "key_cmd";
664 static int compare_magic (uchar *kbd_data, uchar *str)
666 uchar compare[KEYBD_DATALEN-1];
670 /* Don't include modifier byte */
671 memcpy (compare, kbd_data+1, KEYBD_DATALEN-1);
673 for (; str != NULL; str = (*nxt) ? nxt+1 : nxt) {
677 c = (uchar) simple_strtoul (str, (char **) (&nxt), 16);
679 if (str == nxt) { /* invalid character */
684 * Check if this key matches the input.
685 * Set matches to zero, so they match only once
686 * and we can find duplicates or extra keys
688 for (k = 0; k < sizeof(compare); ++k) {
689 if (compare[k] == '\0') /* only non-zero entries */
691 if (c == compare[k]) { /* found matching key */
696 if (k == sizeof(compare)) {
697 return -1; /* unmatched key */
702 * A full match leaves no keys in the `compare' array,
704 for (i = 0; i < sizeof(compare); ++i) {
714 /***********************************************************************
715 F* Function: static uchar *key_match (uchar *kbd_data) P*A*Z*
717 P* Parameters: uchar *kbd_data
718 P* - The keys to match against our magic definitions
720 P* Returnvalue: uchar *
721 P* - != NULL: Pointer to the corresponding command(s)
722 P* NULL: No magic is about to happen
724 Z* Intention: Check if pressed key(s) match magic sequence,
725 Z* and return the command string associated with that key(s).
727 Z* If no key press was decoded, NULL is returned.
729 Z* Note: the first character of the argument will be
730 Z* overwritten with the "magic charcter code" of the
731 Z* decoded key(s), or '\0'.
733 Z* Note: the string points to static environment data
734 Z* and must be saved before you call any function that
735 Z* modifies the environment.
740 ***********************************************************************/
741 static uchar *key_match (uchar *kbd_data)
743 uchar magic[sizeof (kbd_magic_prefix) + 1];
745 uchar *kbd_magic_keys;
748 * The following string defines the characters that can pe appended
749 * to "key_magic" to form the names of environment variables that
750 * hold "magic" key codes, i. e. such key codes that can cause
751 * pre-boot actions. If the string is empty (""), then only
752 * "key_magic" is checked (old behaviour); the string "125" causes
753 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
755 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
758 /* loop over all magic keys;
759 * use '\0' suffix in case of empty string
761 for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix) {
762 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
764 printf ("### Check magic \"%s\"\n", magic);
766 if (compare_magic(kbd_data, getenv(magic)) == 0) {
767 uchar cmd_name[sizeof (kbd_command_prefix) + 1];
770 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
772 cmd = getenv (cmd_name);
774 printf ("### Set PREBOOT to $(%s): \"%s\"\n",
775 cmd_name, cmd ? cmd : "<<NULL>>");
782 printf ("### Delete PREBOOT\n");
787 #endif /* CONFIG_PREBOOT */
789 /*---------------Board Special Commands: PIC read/write ---------------*/
791 #if (CONFIG_COMMANDS & CFG_CMD_BSP)
792 /***********************************************************************
793 F* Function: int do_pic (cmd_tbl_t *cmdtp, int flag,
794 F* int argc, char *argv[]) P*A*Z*
796 P* Parameters: cmd_tbl_t *cmdtp
797 P* - Pointer to our command table entry
799 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
804 P* - Array of the actual arguments
807 P* - 0 The command was handled successfully
808 P* 1 An error occurred
810 Z* Intention: Implement the "pic [read|write]" commands.
811 Z* The read subcommand takes one argument, the register,
812 Z* whereas the write command takes two, the register and
818 ***********************************************************************/
819 int do_pic (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
824 case 3: /* PIC read reg */
825 if (strcmp (argv[1], "read") != 0)
828 reg = simple_strtoul (argv[2], NULL, 16);
830 printf ("PIC read: reg %02x: %02x\n\n", reg, pic_read (reg));
833 case 4: /* PIC write reg val */
834 if (strcmp (argv[1], "write") != 0)
837 reg = simple_strtoul (argv[2], NULL, 16);
838 val = simple_strtoul (argv[3], NULL, 16);
840 printf ("PIC write: reg %02x val 0x%02x: %02x => ",
841 reg, val, pic_read (reg));
842 pic_write (reg, val);
843 printf ("%02x\n\n", pic_read (reg));
848 printf ("Usage:\n%s\n", cmdtp->usage);
851 cmd_tbl_t U_BOOT_CMD(pic) = MK_CMD_ENTRY(
853 "pic - read and write PIC registers\n",
854 "read reg - read PIC register `reg'\n"
855 "pic write reg val - write value `val' to PIC register `reg'\n"
858 /***********************************************************************
859 F* Function: int do_kbd (cmd_tbl_t *cmdtp, int flag,
860 F* int argc, char *argv[]) P*A*Z*
862 P* Parameters: cmd_tbl_t *cmdtp
863 P* - Pointer to our command table entry
865 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
870 P* - Array of the actual arguments
873 P* - 0 is always returned.
875 Z* Intention: Implement the "kbd" command.
876 Z* The keyboard status is read. The result is printed on
877 Z* the console and written into the "keybd" environment
883 ***********************************************************************/
884 int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
886 uchar kbd_data[KEYBD_DATALEN];
887 uchar keybd_env[2 * KEYBD_DATALEN + 1];
891 #if 0 /* Done in kbd_init */
892 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
896 val = KEYBD_CMD_READ_KEYS;
897 i2c_write (kbd_addr, 0, 0, &val, 1);
898 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
901 for (i = 0; i < KEYBD_DATALEN; ++i) {
902 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
903 printf (" %02x", kbd_data[i]);
906 setenv ("keybd", keybd_env);
910 cmd_tbl_t U_BOOT_CMD(kdb) = MK_CMD_ENTRY(
912 "kbd - read keyboard status\n",
916 /* Read and set LSB switch */
917 #define CFG_PC_TXD1_ENA 0x0008 /* PC.12 */
919 /***********************************************************************
920 F* Function: int do_lsb (cmd_tbl_t *cmdtp, int flag,
921 F* int argc, char *argv[]) P*A*Z*
923 P* Parameters: cmd_tbl_t *cmdtp
924 P* - Pointer to our command table entry
926 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
931 P* - Array of the actual arguments
934 P* - 0 The command was handled successfully
935 P* 1 An error occurred
937 Z* Intention: Implement the "lsb [on|off]" commands.
938 Z* The lsb is switched according to the first parameter by
939 Z* by signaling the PIC I/O expander.
940 Z* Called with no arguments, the current setting is
946 ***********************************************************************/
947 int do_lsb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
950 immap_t *immr = (immap_t *) CFG_IMMR;
953 case 1: /* lsb - print setting */
954 val = pic_read (0x60);
955 printf ("LSB is o%s\n", (val & 0x20) ? "n" : "ff");
957 case 2: /* lsb on or lsb off - set switch */
958 val = pic_read (0x60);
960 if (strcmp (argv[1], "on") == 0) {
962 immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA);
963 immr->im_ioport.iop_pcdat |= CFG_PC_TXD1_ENA;
964 immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA;
965 } else if (strcmp (argv[1], "off") == 0) {
967 immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA);
968 immr->im_ioport.iop_pcdat &= ~(CFG_PC_TXD1_ENA);
969 immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA;
973 pic_write (0x60, val);
978 printf ("Usage:\n%s\n", cmdtp->usage);
982 cmd_tbl_t U_BOOT_CMD(lsb) = MK_CMD_ENTRY(
984 "lsb - check and set LSB switch\n",
985 "on - switch LSB on\n"
986 "lsb off - switch LSB off\n"
987 "lsb - print current setting\n"
990 #endif /* CFG_CMD_BSP */
992 /*----------------------------- Utilities -----------------------------*/
993 /***********************************************************************
994 F* Function: uchar pic_read (uchar reg) P*A*Z*
996 P* Parameters: uchar reg
997 P* - Register to read
999 P* Returnvalue: uchar
1000 P* - Value read from register
1002 Z* Intention: Read a register from the PIC I/O expander.
1007 ***********************************************************************/
1008 uchar pic_read (uchar reg)
1010 return (i2c_reg_read (CFG_I2C_PICIO_ADDR, reg));
1013 /***********************************************************************
1014 F* Function: void pic_write (uchar reg, uchar val) P*A*Z*
1016 P* Parameters: uchar reg
1017 P* - Register to read
1021 P* Returnvalue: none
1023 Z* Intention: Write to a register on the PIC I/O expander.
1028 ***********************************************************************/
1029 void pic_write (uchar reg, uchar val)
1031 i2c_reg_write (CFG_I2C_PICIO_ADDR, reg, val);
1034 /*---------------------- Board Control Functions ----------------------*/
1035 /***********************************************************************
1036 F* Function: void board_poweroff (void) P*A*Z*
1040 P* Returnvalue: none
1042 Z* Intention: Turn off the battery power and loop endless, so this
1043 Z* should better be the last function you call...
1048 ***********************************************************************/
1049 void board_poweroff (void)
1051 /* Turn battery off */
1052 ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat &= ~(1 << (31 - 13));
1057 #ifdef CONFIG_MODEM_SUPPORT
1058 static int key_pressed(void)
1060 uchar kbd_data[KEYBD_DATALEN];
1064 val = KEYBD_CMD_READ_KEYS;
1065 i2c_write (kbd_addr, 0, 0, &val, 1);
1066 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
1068 return (compare_magic(kbd_data, CONFIG_MODEM_KEY_MAGIC) == 0);
1070 #endif /* CONFIG_MODEM_SUPPORT */