1 /***********************************************************************
5 M* Content: LWMON specific U-Boot commands.
7 * (C) Copyright 2001, 2002
8 * DENX Software Engineering
9 * Wolfgang Denk, wd@denx.de
10 * All rights reserved.
14 V* Verification: dzu@denx.de
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 ----------------------------*/
45 #include <linux/types.h>
46 #include <linux/string.h> /* for strdup */
48 /*------------------------ Local prototypes ---------------------------*/
49 static long int dram_size (long int, long int *, long int);
50 static void kbd_init (void);
51 static int compare_magic (uchar *kbd_data, uchar *str);
54 /*--------------------- Local macros and constants --------------------*/
55 #define _NOT_USED_ 0xFFFFFFFF
57 #ifdef CONFIG_MODEM_SUPPORT
58 static int key_pressed(void);
59 extern void disable_putc(void);
60 #endif /* CONFIG_MODEM_SUPPORT */
63 * 66 MHz SDRAM access using UPM A
65 const uint sdram_table[] =
67 #if defined(CFG_MEMORY_75) || defined(CFG_MEMORY_8E)
69 * Single Read. (Offset 0 in UPM RAM)
71 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
72 0x1FF5FC47, /* last */
74 * SDRAM Initialization (offset 5 in UPM RAM)
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.
81 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
83 * Burst Read. (Offset 8 in UPM RAM)
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_,
90 * Single Write. (Offset 18 in UPM RAM)
92 0x1F2DFC04, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */
93 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
95 * Burst Write. (Offset 20 in UPM RAM)
97 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
98 0xF0AFFC00, 0xE1BAFC04, 0x01FF5FC47, /* last */
100 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
101 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
103 * Refresh (Offset 30 in UPM RAM)
105 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
106 0xFFFFFC84, 0xFFFFFC07, /* last */
107 _NOT_USED_, _NOT_USED_,
108 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
110 * Exception. (Offset 3c in UPM RAM)
112 0x7FFFFC07, /* last */
113 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
117 * Single Read. (Offset 0 in UPM RAM)
119 0x0E2DBC04, 0x11AF7C04, 0xEFBAFC00, 0x1FF5FC47, /* last */
122 * SDRAM Initialization (offset 5 in UPM RAM)
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.
129 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
131 * Burst Read. (Offset 8 in UPM RAM)
133 0x0E2DBC04, 0x10AF7C04, 0xF0AFFC00, 0xF0AFFC00,
134 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
136 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
137 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
139 * Single Write. (Offset 18 in UPM RAM)
141 0x0E29BC04, 0x01B27C04, 0x1FF5FC47, /* last */
143 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
145 * Burst Write. (Offset 20 in UPM RAM)
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_,
153 * Refresh (Offset 30 in UPM RAM)
155 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
156 0xFFFFFC84, 0xFFFFFC07, /* last */
157 _NOT_USED_, _NOT_USED_,
158 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
160 * Exception. (Offset 3c in UPM RAM)
162 0x7FFFFC07, /* last */
163 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
168 * Check Board Identity:
172 /***********************************************************************
173 F* Function: int checkboard (void) P*A*Z*
177 P* Returnvalue: int - 0 is always returned
179 Z* Intention: This function is the checkboard() method implementation
180 Z* for the lwmon board. Only a standard message is printed.
182 D* Design: wd@denx.de
183 C* Coding: wd@denx.de
184 V* Verification: dzu@denx.de
185 ***********************************************************************/
186 int checkboard (void)
188 puts ("Board: LICCON Konsole LCD3\n");
192 /***********************************************************************
193 F* Function: long int initdram (int board_type) P*A*Z*
195 P* Parameters: int board_type
196 P* - Usually type of the board - ignored here.
198 P* Returnvalue: long int
199 P* - Size of initialized memory
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
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)
212 volatile immap_t *immr = (immap_t *) CFG_IMMR;
213 volatile memctl8xx_t *memctl = &immr->im_memctl;
215 long int size8, size9;
219 * Configure UPMA for SDRAM
221 upmconfig (UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
223 memctl->memc_mptpr = CFG_MPTPR;
225 /* burst length=4, burst type=sequential, CAS latency=2 */
226 memctl->memc_mar = CFG_MAR;
229 * Map controller bank 3 to the SDRAM bank at preliminary address.
231 memctl->memc_or3 = CFG_OR3_PRELIM;
232 memctl->memc_br3 = CFG_BR3_PRELIM;
234 /* initialize memory address register */
235 memctl->memc_mamr = CFG_MAMR_8COL; /* refresh not enabled yet */
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);
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);
247 udelay (1); /* 0x80006106 */
248 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x06);
250 memctl->memc_mamr |= MAMR_PTAE; /* refresh enabled */
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;
265 * Check Bank 0 Memory Size for re-configuration
269 size8 = dram_size (CFG_MAMR_8COL, (long *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
276 size9 = dram_size (CFG_MAMR_9COL, (long *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
278 if (size8 < size9) { /* leave configuration at 9 columns */
280 memctl->memc_mamr = CFG_MAMR_9COL | MAMR_PTAE;
282 } else { /* back to 8 columns */
284 memctl->memc_mamr = CFG_MAMR_8COL | MAMR_PTAE;
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;
300 /***********************************************************************
301 F* Function: static long int dram_size (long int mamr_value,
303 F* long int maxsize) P*A*Z*
305 P* Parameters: long int mamr_value
306 P* - Value for MAMR for the test
308 P* - Base address for the test
310 P* - Maximum size to test for
312 P* Returnvalue: long int
313 P* - Size of probed memory
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
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)
328 volatile immap_t *immr = (immap_t *) CFG_IMMR;
329 volatile memctl8xx_t *memctl = &immr->im_memctl;
331 memctl->memc_mamr = mamr_value;
333 return (get_ram_size(base, maxsize));
336 /* ------------------------------------------------------------------------- */
339 # define PB_ENET_TENA ((uint)0x00002000) /* PB 18 */
342 /***********************************************************************
343 F* Function: int board_early_init_f (void) P*A*Z*
348 P* - 0 is always returned.
350 Z* Intention: This function is the board_early_init_f() method implementation
351 Z* for the lwmon board.
352 Z* Disable Ethernet TENA on Port B.
354 D* Design: wd@denx.de
355 C* Coding: wd@denx.de
356 V* Verification: dzu@denx.de
357 ***********************************************************************/
358 int board_early_init_f (void)
360 volatile immap_t *immr = (immap_t *) CFG_IMMR;
362 /* Disable Ethernet TENA on Port B
363 * Necessary because of pull up in COM3 port.
365 * This is just a preliminary fix, intended to turn off TENA
366 * as soon as possible to avoid noise on the network. Once
367 * I²C is running we will make sure the interface is
368 * correctly initialized.
370 immr->im_cpm.cp_pbpar &= ~PB_ENET_TENA;
371 immr->im_cpm.cp_pbodr &= ~PB_ENET_TENA;
372 immr->im_cpm.cp_pbdat &= ~PB_ENET_TENA; /* set to 0 = disabled */
373 immr->im_cpm.cp_pbdir |= PB_ENET_TENA;
378 /* ------------------------------------------------------------------------- */
380 /***********************************************************************
381 F* Function: void reset_phy (void) P*A*Z*
387 Z* Intention: Reset the PHY. In the lwmon case we do this by the
388 Z* signaling the PIC I/O expander.
390 D* Design: wd@denx.de
391 C* Coding: wd@denx.de
392 V* Verification: dzu@denx.de
393 ***********************************************************************/
394 void reset_phy (void)
399 printf ("### Switch on Ethernet for SCC2 ###\n");
403 printf ("Old PIC read: reg_61 = 0x%02x\n", c);
405 c |= 0x40; /* disable COM3 */
406 c &= ~0x80; /* enable Ethernet */
410 printf ("New PIC read: reg_61 = 0x%02x\n", c);
416 /*------------------------- Keyboard controller -----------------------*/
418 #define KEYBD_CMD_READ_KEYS 0x01
419 #define KEYBD_CMD_READ_VERSION 0x02
420 #define KEYBD_CMD_READ_STATUS 0x03
421 #define KEYBD_CMD_RESET_ERRORS 0x10
424 #define KEYBD_STATUS_MASK 0x3F
425 #define KEYBD_STATUS_H_RESET 0x20
426 #define KEYBD_STATUS_BROWNOUT 0x10
427 #define KEYBD_STATUS_WD_RESET 0x08
428 #define KEYBD_STATUS_OVERLOAD 0x04
429 #define KEYBD_STATUS_ILLEGAL_WR 0x02
430 #define KEYBD_STATUS_ILLEGAL_RD 0x01
432 /* Number of bytes returned from Keyboard Controller */
433 #define KEYBD_VERSIONLEN 2 /* version information */
434 #define KEYBD_DATALEN 9 /* normal key scan data */
436 /* maximum number of "magic" key codes that can be assigned */
438 static uchar kbd_addr = CFG_I2C_KEYBD_ADDR;
440 static uchar *key_match (uchar *);
442 #define KEYBD_SET_DEBUGMODE '#' /* Magic key to enable debug output */
444 /***********************************************************************
445 F* Function: int board_postclk_init (void) P*A*Z*
450 P* - 0 is always returned.
452 Z* Intention: This function is the board_postclk_init() method implementation
453 Z* for the lwmon board.
455 ***********************************************************************/
456 int board_postclk_init (void)
458 DECLARE_GLOBAL_DATA_PTR;
462 #ifdef CONFIG_MODEM_SUPPORT
464 disable_putc(); /* modem doesn't understand banner etc */
472 struct serial_device * default_serial_console (void)
474 DECLARE_GLOBAL_DATA_PTR;
476 return gd->do_mdm_init ? &serial_scc_device : &serial_smc_device;
479 static void kbd_init (void)
481 DECLARE_GLOBAL_DATA_PTR;
483 uchar kbd_data[KEYBD_DATALEN];
484 uchar tmp_data[KEYBD_DATALEN];
488 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
492 /* Forced by PIC. Delays <= 175us loose */
495 /* Read initial keyboard error code */
496 val = KEYBD_CMD_READ_STATUS;
497 i2c_write (kbd_addr, 0, 0, &val, 1);
498 i2c_read (kbd_addr, 0, 0, &errcd, 1);
499 /* clear unused bits */
500 errcd &= KEYBD_STATUS_MASK;
501 /* clear "irrelevant" bits. Recommended by Martin Rajek, LWN */
502 errcd &= ~(KEYBD_STATUS_H_RESET|KEYBD_STATUS_BROWNOUT);
504 gd->kbd_status |= errcd << 8;
506 /* Reset error code and verify */
507 val = KEYBD_CMD_RESET_ERRORS;
508 i2c_write (kbd_addr, 0, 0, &val, 1);
509 udelay(1000); /* delay NEEDED by keyboard PIC !!! */
511 val = KEYBD_CMD_READ_STATUS;
512 i2c_write (kbd_addr, 0, 0, &val, 1);
513 i2c_read (kbd_addr, 0, 0, &val, 1);
515 val &= KEYBD_STATUS_MASK; /* clear unused bits */
516 if (val) { /* permanent error, report it */
517 gd->kbd_status |= val;
522 * Read current keyboard state.
524 * After the error reset it may take some time before the
525 * keyboard PIC picks up a valid keyboard scan - the total
526 * scan time is approx. 1.6 ms (information by Martin Rajek,
527 * 28 Sep 2002). We read a couple of times for the keyboard
528 * to stabilize, using a big enough delay.
529 * 10 times should be enough. If the data is still changing,
530 * we use what we get :-(
533 memset (tmp_data, 0xFF, KEYBD_DATALEN); /* impossible value */
534 for (i=0; i<10; ++i) {
535 val = KEYBD_CMD_READ_KEYS;
536 i2c_write (kbd_addr, 0, 0, &val, 1);
537 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
539 if (memcmp(kbd_data, tmp_data, KEYBD_DATALEN) == 0) {
540 /* consistent state, done */
543 /* remeber last state, delay, and retry */
544 memcpy (tmp_data, kbd_data, KEYBD_DATALEN);
549 /***********************************************************************
550 F* Function: int misc_init_r (void) P*A*Z*
555 P* - 0 is always returned, even in the case of a keyboard
558 Z* Intention: This function is the misc_init_r() method implementation
559 Z* for the lwmon board.
560 Z* The keyboard controller is initialized and the result
561 Z* of a read copied to the environment variable "keybd".
562 Z* If KEYBD_SET_DEBUGMODE is defined, a check is made for
563 Z* this key, and if found display to the LCD will be enabled.
564 Z* The keys in "keybd" are checked against the magic
565 Z* keycommands defined in the environment.
566 Z* See also key_match().
568 D* Design: wd@denx.de
569 C* Coding: wd@denx.de
570 V* Verification: dzu@denx.de
571 ***********************************************************************/
572 int misc_init_r (void)
574 DECLARE_GLOBAL_DATA_PTR;
576 uchar kbd_data[KEYBD_DATALEN];
577 char keybd_env[2 * KEYBD_DATALEN + 1];
578 uchar kbd_init_status = gd->kbd_status >> 8;
579 uchar kbd_status = gd->kbd_status;
584 if (kbd_init_status) {
585 printf ("KEYBD: Error %02X\n", kbd_init_status);
587 if (kbd_status) { /* permanent error, report it */
588 printf ("*** Keyboard error code %02X ***\n", kbd_status);
589 sprintf (keybd_env, "%02X", kbd_status);
590 setenv ("keybd", keybd_env);
595 * Now we know that we have a working keyboard, so disable
596 * all output to the LCD except when a key press is detected.
599 if ((console_assign (stdout, "serial") < 0) ||
600 (console_assign (stderr, "serial") < 0)) {
601 printf ("Can't assign serial port as output device\n");
605 val = KEYBD_CMD_READ_VERSION;
606 i2c_write (kbd_addr, 0, 0, &val, 1);
607 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_VERSIONLEN);
608 printf ("KEYBD: Version %d.%d\n", kbd_data[0], kbd_data[1]);
610 /* Read current keyboard state */
611 val = KEYBD_CMD_READ_KEYS;
612 i2c_write (kbd_addr, 0, 0, &val, 1);
613 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
615 for (i = 0; i < KEYBD_DATALEN; ++i) {
616 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
618 setenv ("keybd", keybd_env);
620 str = strdup ((char *)key_match (kbd_data)); /* decode keys */
621 #ifdef KEYBD_SET_DEBUGMODE
622 if (kbd_data[0] == KEYBD_SET_DEBUGMODE) { /* set debug mode */
623 if ((console_assign (stdout, "lcd") < 0) ||
624 (console_assign (stderr, "lcd") < 0)) {
625 printf ("Can't assign LCD display as output device\n");
628 #endif /* KEYBD_SET_DEBUGMODE */
629 #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
630 setenv ("preboot", str); /* set or delete definition */
631 #endif /* CONFIG_PREBOOT */
638 #ifdef CONFIG_PREBOOT
640 static uchar kbd_magic_prefix[] = "key_magic";
641 static uchar kbd_command_prefix[] = "key_cmd";
643 static int compare_magic (uchar *kbd_data, uchar *str)
645 uchar compare[KEYBD_DATALEN-1];
649 /* Don't include modifier byte */
650 memcpy (compare, kbd_data+1, KEYBD_DATALEN-1);
652 for (; str != NULL; str = (*nxt) ? (uchar *)(nxt+1) : (uchar *)nxt) {
656 c = (uchar) simple_strtoul ((char *)str, (char **) (&nxt), 16);
658 if (str == (uchar *)nxt) { /* invalid character */
663 * Check if this key matches the input.
664 * Set matches to zero, so they match only once
665 * and we can find duplicates or extra keys
667 for (k = 0; k < sizeof(compare); ++k) {
668 if (compare[k] == '\0') /* only non-zero entries */
670 if (c == compare[k]) { /* found matching key */
675 if (k == sizeof(compare)) {
676 return -1; /* unmatched key */
681 * A full match leaves no keys in the `compare' array,
683 for (i = 0; i < sizeof(compare); ++i) {
693 /***********************************************************************
694 F* Function: static uchar *key_match (uchar *kbd_data) P*A*Z*
696 P* Parameters: uchar *kbd_data
697 P* - The keys to match against our magic definitions
699 P* Returnvalue: uchar *
700 P* - != NULL: Pointer to the corresponding command(s)
701 P* NULL: No magic is about to happen
703 Z* Intention: Check if pressed key(s) match magic sequence,
704 Z* and return the command string associated with that key(s).
706 Z* If no key press was decoded, NULL is returned.
708 Z* Note: the first character of the argument will be
709 Z* overwritten with the "magic charcter code" of the
710 Z* decoded key(s), or '\0'.
712 Z* Note: the string points to static environment data
713 Z* and must be saved before you call any function that
714 Z* modifies the environment.
716 D* Design: wd@denx.de
717 C* Coding: wd@denx.de
718 V* Verification: dzu@denx.de
719 ***********************************************************************/
720 static uchar *key_match (uchar *kbd_data)
722 char magic[sizeof (kbd_magic_prefix) + 1];
724 char *kbd_magic_keys;
727 * The following string defines the characters that can pe appended
728 * to "key_magic" to form the names of environment variables that
729 * hold "magic" key codes, i. e. such key codes that can cause
730 * pre-boot actions. If the string is empty (""), then only
731 * "key_magic" is checked (old behaviour); the string "125" causes
732 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
734 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
737 /* loop over all magic keys;
738 * use '\0' suffix in case of empty string
740 for (suffix=(uchar *)kbd_magic_keys; *suffix || suffix==(uchar *)kbd_magic_keys; ++suffix) {
741 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
743 printf ("### Check magic \"%s\"\n", magic);
745 if (compare_magic(kbd_data, (uchar *)getenv(magic)) == 0) {
746 char cmd_name[sizeof (kbd_command_prefix) + 1];
749 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
751 cmd = getenv (cmd_name);
753 printf ("### Set PREBOOT to $(%s): \"%s\"\n",
754 cmd_name, cmd ? cmd : "<<NULL>>");
757 return ((uchar *)cmd);
761 printf ("### Delete PREBOOT\n");
766 #endif /* CONFIG_PREBOOT */
768 /*---------------Board Special Commands: PIC read/write ---------------*/
770 #if (CONFIG_COMMANDS & CFG_CMD_BSP)
771 /***********************************************************************
772 F* Function: int do_pic (cmd_tbl_t *cmdtp, int flag,
773 F* int argc, char *argv[]) P*A*Z*
775 P* Parameters: cmd_tbl_t *cmdtp
776 P* - Pointer to our command table entry
778 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
783 P* - Array of the actual arguments
786 P* - 0 The command was handled successfully
787 P* 1 An error occurred
789 Z* Intention: Implement the "pic [read|write]" commands.
790 Z* The read subcommand takes one argument, the register,
791 Z* whereas the write command takes two, the register and
794 D* Design: wd@denx.de
795 C* Coding: wd@denx.de
796 V* Verification: dzu@denx.de
797 ***********************************************************************/
798 int do_pic (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
803 case 3: /* PIC read reg */
804 if (strcmp (argv[1], "read") != 0)
807 reg = simple_strtoul (argv[2], NULL, 16);
809 printf ("PIC read: reg %02x: %02x\n\n", reg, pic_read (reg));
812 case 4: /* PIC write reg val */
813 if (strcmp (argv[1], "write") != 0)
816 reg = simple_strtoul (argv[2], NULL, 16);
817 val = simple_strtoul (argv[3], NULL, 16);
819 printf ("PIC write: reg %02x val 0x%02x: %02x => ",
820 reg, val, pic_read (reg));
821 pic_write (reg, val);
822 printf ("%02x\n\n", pic_read (reg));
827 printf ("Usage:\n%s\n", cmdtp->usage);
832 "pic - read and write PIC registers\n",
833 "read reg - read PIC register `reg'\n"
834 "pic write reg val - write value `val' to PIC register `reg'\n"
837 /***********************************************************************
838 F* Function: int do_kbd (cmd_tbl_t *cmdtp, int flag,
839 F* int argc, char *argv[]) P*A*Z*
841 P* Parameters: cmd_tbl_t *cmdtp
842 P* - Pointer to our command table entry
844 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
849 P* - Array of the actual arguments
852 P* - 0 is always returned.
854 Z* Intention: Implement the "kbd" command.
855 Z* The keyboard status is read. The result is printed on
856 Z* the console and written into the "keybd" environment
859 D* Design: wd@denx.de
860 C* Coding: wd@denx.de
861 V* Verification: dzu@denx.de
862 ***********************************************************************/
863 int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
865 uchar kbd_data[KEYBD_DATALEN];
866 char keybd_env[2 * KEYBD_DATALEN + 1];
870 #if 0 /* Done in kbd_init */
871 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
875 val = KEYBD_CMD_READ_KEYS;
876 i2c_write (kbd_addr, 0, 0, &val, 1);
877 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
880 for (i = 0; i < KEYBD_DATALEN; ++i) {
881 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
882 printf (" %02x", kbd_data[i]);
885 setenv ("keybd", keybd_env);
891 "kbd - read keyboard status\n",
895 /* Read and set LSB switch */
896 #define CFG_PC_TXD1_ENA 0x0008 /* PC.12 */
898 /***********************************************************************
899 F* Function: int do_lsb (cmd_tbl_t *cmdtp, int flag,
900 F* int argc, char *argv[]) P*A*Z*
902 P* Parameters: cmd_tbl_t *cmdtp
903 P* - Pointer to our command table entry
905 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
910 P* - Array of the actual arguments
913 P* - 0 The command was handled successfully
914 P* 1 An error occurred
916 Z* Intention: Implement the "lsb [on|off]" commands.
917 Z* The lsb is switched according to the first parameter by
918 Z* by signaling the PIC I/O expander.
919 Z* Called with no arguments, the current setting is
922 D* Design: wd@denx.de
923 C* Coding: wd@denx.de
924 V* Verification: dzu@denx.de
925 ***********************************************************************/
926 int do_lsb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
929 immap_t *immr = (immap_t *) CFG_IMMR;
932 case 1: /* lsb - print setting */
933 val = pic_read (0x60);
934 printf ("LSB is o%s\n", (val & 0x20) ? "n" : "ff");
936 case 2: /* lsb on or lsb off - set switch */
937 val = pic_read (0x60);
939 if (strcmp (argv[1], "on") == 0) {
941 immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA);
942 immr->im_ioport.iop_pcdat |= CFG_PC_TXD1_ENA;
943 immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA;
944 } else if (strcmp (argv[1], "off") == 0) {
946 immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA);
947 immr->im_ioport.iop_pcdat &= ~(CFG_PC_TXD1_ENA);
948 immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA;
952 pic_write (0x60, val);
957 printf ("Usage:\n%s\n", cmdtp->usage);
963 "lsb - check and set LSB switch\n",
964 "on - switch LSB on\n"
965 "lsb off - switch LSB off\n"
966 "lsb - print current setting\n"
969 #endif /* CFG_CMD_BSP */
971 /*----------------------------- Utilities -----------------------------*/
972 /***********************************************************************
973 F* Function: uchar pic_read (uchar reg) P*A*Z*
975 P* Parameters: uchar reg
976 P* - Register to read
978 P* Returnvalue: uchar
979 P* - Value read from register
981 Z* Intention: Read a register from the PIC I/O expander.
983 D* Design: wd@denx.de
984 C* Coding: wd@denx.de
985 V* Verification: dzu@denx.de
986 ***********************************************************************/
987 uchar pic_read (uchar reg)
989 return (i2c_reg_read (CFG_I2C_PICIO_ADDR, reg));
992 /***********************************************************************
993 F* Function: void pic_write (uchar reg, uchar val) P*A*Z*
995 P* Parameters: uchar reg
996 P* - Register to read
1000 P* Returnvalue: none
1002 Z* Intention: Write to a register on the PIC I/O expander.
1004 D* Design: wd@denx.de
1005 C* Coding: wd@denx.de
1006 V* Verification: dzu@denx.de
1007 ***********************************************************************/
1008 void pic_write (uchar reg, uchar val)
1010 i2c_reg_write (CFG_I2C_PICIO_ADDR, reg, val);
1013 /*---------------------- Board Control Functions ----------------------*/
1014 /***********************************************************************
1015 F* Function: void board_poweroff (void) P*A*Z*
1019 P* Returnvalue: none
1021 Z* Intention: Turn off the battery power and loop endless, so this
1022 Z* should better be the last function you call...
1024 D* Design: wd@denx.de
1025 C* Coding: wd@denx.de
1026 V* Verification: dzu@denx.de
1027 ***********************************************************************/
1028 void board_poweroff (void)
1030 /* Turn battery off */
1031 ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat &= ~(1 << (31 - 13));
1036 #ifdef CONFIG_MODEM_SUPPORT
1037 static int key_pressed(void)
1039 uchar kbd_data[KEYBD_DATALEN];
1043 val = KEYBD_CMD_READ_KEYS;
1044 i2c_write (kbd_addr, 0, 0, &val, 1);
1045 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
1047 return (compare_magic(kbd_data, (uchar *)CONFIG_MODEM_KEY_MAGIC) == 0);
1049 #endif /* CONFIG_MODEM_SUPPORT */
1053 * Returns 1 if keys pressed to start the power-on long-running tests
1054 * Called from board_init_f().
1056 int post_hotkeys_pressed(void)
1058 uchar kbd_data[KEYBD_DATALEN];
1062 val = KEYBD_CMD_READ_KEYS;
1063 i2c_write (kbd_addr, 0, 0, &val, 1);
1064 i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN);
1066 return (compare_magic(kbd_data, (uchar *)CONFIG_POST_KEY_MAGIC) == 0);