1 /***********************************************************************
5 M* Content: LWMON specific U-Boot commands.
7 * (C) Copyright 2001, 2002
8 * DENX Software Engineering
9 * Wolfgang Denk, wd@denx.de
13 V* Verification: dzu@denx.de
15 * SPDX-License-Identifier: GPL-2.0+
16 ***********************************************************************/
18 /*---------------------------- Headerfiles ----------------------------*/
28 #include <linux/types.h>
29 #include <linux/string.h> /* for strdup */
31 DECLARE_GLOBAL_DATA_PTR
;
33 /*------------------------ Local prototypes ---------------------------*/
34 static long int dram_size (long int, long int *, long int);
35 static void kbd_init (void);
36 static int compare_magic (uchar
*kbd_data
, uchar
*str
);
39 /*--------------------- Local macros and constants --------------------*/
40 #define _NOT_USED_ 0xFFFFFFFF
42 #ifdef CONFIG_MODEM_SUPPORT
43 static int key_pressed(void);
44 extern void disable_putc(void);
45 #endif /* CONFIG_MODEM_SUPPORT */
48 * 66 MHz SDRAM access using UPM A
50 const uint sdram_table
[] =
52 #if defined(CONFIG_SYS_MEMORY_75) || defined(CONFIG_SYS_MEMORY_8E)
54 * Single Read. (Offset 0 in UPM RAM)
56 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
57 0x1FF5FC47, /* last */
59 * SDRAM Initialization (offset 5 in UPM RAM)
61 * This is no UPM entry point. The following definition uses
62 * the remaining space to establish an initialization
63 * sequence, which is executed by a RUN command.
66 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
68 * Burst Read. (Offset 8 in UPM RAM)
70 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
71 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
72 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
73 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
75 * Single Write. (Offset 18 in UPM RAM)
77 0x1F2DFC04, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */
78 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
80 * Burst Write. (Offset 20 in UPM RAM)
82 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
83 0xF0AFFC00, 0xE1BAFC04, 0x01FF5FC47, /* last */
85 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
86 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
88 * Refresh (Offset 30 in UPM RAM)
90 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
91 0xFFFFFC84, 0xFFFFFC07, /* last */
92 _NOT_USED_
, _NOT_USED_
,
93 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
95 * Exception. (Offset 3c in UPM RAM)
97 0x7FFFFC07, /* last */
98 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
100 #ifdef CONFIG_SYS_MEMORY_7E
102 * Single Read. (Offset 0 in UPM RAM)
104 0x0E2DBC04, 0x11AF7C04, 0xEFBAFC00, 0x1FF5FC47, /* last */
107 * SDRAM Initialization (offset 5 in UPM RAM)
109 * This is no UPM entry point. The following definition uses
110 * the remaining space to establish an initialization
111 * sequence, which is executed by a RUN command.
114 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
116 * Burst Read. (Offset 8 in UPM RAM)
118 0x0E2DBC04, 0x10AF7C04, 0xF0AFFC00, 0xF0AFFC00,
119 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
121 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
122 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
124 * Single Write. (Offset 18 in UPM RAM)
126 0x0E29BC04, 0x01B27C04, 0x1FF5FC47, /* last */
128 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
130 * Burst Write. (Offset 20 in UPM RAM)
132 0x0E29BC04, 0x10A77C00, 0xF0AFFC00, 0xF0AFFC00,
133 0xE1BAFC04, 0x1FF5FC47, /* last */
134 _NOT_USED_
, _NOT_USED_
,
135 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
136 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
138 * Refresh (Offset 30 in UPM RAM)
140 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
141 0xFFFFFC84, 0xFFFFFC07, /* last */
142 _NOT_USED_
, _NOT_USED_
,
143 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
145 * Exception. (Offset 3c in UPM RAM)
147 0x7FFFFC07, /* last */
148 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
153 * Check Board Identity:
157 /***********************************************************************
158 F* Function: int checkboard (void) P*A*Z*
162 P* Returnvalue: int - 0 is always returned
164 Z* Intention: This function is the checkboard() method implementation
165 Z* for the lwmon board. Only a standard message is printed.
167 D* Design: wd@denx.de
168 C* Coding: wd@denx.de
169 V* Verification: dzu@denx.de
170 ***********************************************************************/
171 int checkboard (void)
173 puts ("Board: LICCON Konsole LCD3\n");
177 /***********************************************************************
178 F* Function: phys_size_t initdram (int board_type) P*A*Z*
180 P* Parameters: int board_type
181 P* - Usually type of the board - ignored here.
183 P* Returnvalue: long int
184 P* - Size of initialized memory
186 Z* Intention: This function is the initdram() method implementation
187 Z* for the lwmon board.
188 Z* The memory controller is initialized to access the
191 D* Design: wd@denx.de
192 C* Coding: wd@denx.de
193 V* Verification: dzu@denx.de
194 ***********************************************************************/
195 phys_size_t
initdram (int board_type
)
197 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
198 volatile memctl8xx_t
*memctl
= &immr
->im_memctl
;
200 long int size8
, size9
;
204 * Configure UPMA for SDRAM
206 upmconfig (UPMA
, (uint
*)sdram_table
, sizeof(sdram_table
)/sizeof(uint
));
208 memctl
->memc_mptpr
= CONFIG_SYS_MPTPR
;
210 /* burst length=4, burst type=sequential, CAS latency=2 */
211 memctl
->memc_mar
= CONFIG_SYS_MAR
;
214 * Map controller bank 3 to the SDRAM bank at preliminary address.
216 memctl
->memc_or3
= CONFIG_SYS_OR3_PRELIM
;
217 memctl
->memc_br3
= CONFIG_SYS_BR3_PRELIM
;
219 /* initialize memory address register */
220 memctl
->memc_mamr
= CONFIG_SYS_MAMR_8COL
; /* refresh not enabled yet */
222 /* mode initialization (offset 5) */
223 udelay (200); /* 0x80006105 */
224 memctl
->memc_mcr
= MCR_OP_RUN
| MCR_MB_CS3
| MCR_MLCF (1) | MCR_MAD (0x05);
226 /* run 2 refresh sequence with 4-beat refresh burst (offset 0x30) */
227 udelay (1); /* 0x80006130 */
228 memctl
->memc_mcr
= MCR_OP_RUN
| MCR_MB_CS3
| MCR_MLCF (1) | MCR_MAD (0x30);
229 udelay (1); /* 0x80006130 */
230 memctl
->memc_mcr
= MCR_OP_RUN
| MCR_MB_CS3
| MCR_MLCF (1) | MCR_MAD (0x30);
232 udelay (1); /* 0x80006106 */
233 memctl
->memc_mcr
= MCR_OP_RUN
| MCR_MB_CS3
| MCR_MLCF (1) | MCR_MAD (0x06);
235 memctl
->memc_mamr
|= MAMR_PTAE
; /* refresh enabled */
239 /* Need at least 10 DRAM accesses to stabilize */
240 for (i
= 0; i
< 10; ++i
) {
241 volatile unsigned long *addr
=
242 (volatile unsigned long *) SDRAM_BASE3_PRELIM
;
250 * Check Bank 0 Memory Size for re-configuration
254 size8
= dram_size (CONFIG_SYS_MAMR_8COL
, (long *)SDRAM_BASE3_PRELIM
, SDRAM_MAX_SIZE
);
261 size9
= dram_size (CONFIG_SYS_MAMR_9COL
, (long *)SDRAM_BASE3_PRELIM
, SDRAM_MAX_SIZE
);
263 if (size8
< size9
) { /* leave configuration at 9 columns */
265 memctl
->memc_mamr
= CONFIG_SYS_MAMR_9COL
| MAMR_PTAE
;
267 } else { /* back to 8 columns */
269 memctl
->memc_mamr
= CONFIG_SYS_MAMR_8COL
| MAMR_PTAE
;
277 memctl
->memc_or3
= ((-size_b0
) & 0xFFFF0000) |
278 OR_CSNT_SAM
| OR_G5LS
| SDRAM_TIMING
;
279 memctl
->memc_br3
= (CONFIG_SYS_SDRAM_BASE
& BR_BA_MSK
) | BR_MS_UPMA
| BR_V
;
285 /***********************************************************************
286 F* Function: static long int dram_size (long int mamr_value,
288 F* long int maxsize) P*A*Z*
290 P* Parameters: long int mamr_value
291 P* - Value for MAMR for the test
293 P* - Base address for the test
295 P* - Maximum size to test for
297 P* Returnvalue: long int
298 P* - Size of probed memory
300 Z* Intention: Check memory range for valid RAM. A simple memory test
301 Z* determines the actually available RAM size between
302 Z* addresses `base' and `base + maxsize'. Some (not all)
303 Z* hardware errors are detected:
304 Z* - short between address lines
305 Z* - short between data lines
307 D* Design: wd@denx.de
308 C* Coding: wd@denx.de
309 V* Verification: dzu@denx.de
310 ***********************************************************************/
311 static long int dram_size (long int mamr_value
, long int *base
, long int maxsize
)
313 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
314 volatile memctl8xx_t
*memctl
= &immr
->im_memctl
;
316 memctl
->memc_mamr
= mamr_value
;
318 return (get_ram_size(base
, maxsize
));
321 /* ------------------------------------------------------------------------- */
324 # define PB_ENET_TENA ((uint)0x00002000) /* PB 18 */
327 /***********************************************************************
328 F* Function: int board_early_init_f (void) P*A*Z*
333 P* - 0 is always returned.
335 Z* Intention: This function is the board_early_init_f() method implementation
336 Z* for the lwmon board.
337 Z* Disable Ethernet TENA on Port B.
339 D* Design: wd@denx.de
340 C* Coding: wd@denx.de
341 V* Verification: dzu@denx.de
342 ***********************************************************************/
343 int board_early_init_f (void)
345 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
347 /* Disable Ethernet TENA on Port B
348 * Necessary because of pull up in COM3 port.
350 * This is just a preliminary fix, intended to turn off TENA
351 * as soon as possible to avoid noise on the network. Once
352 * I2C is running we will make sure the interface is
353 * correctly initialized.
355 immr
->im_cpm
.cp_pbpar
&= ~PB_ENET_TENA
;
356 immr
->im_cpm
.cp_pbodr
&= ~PB_ENET_TENA
;
357 immr
->im_cpm
.cp_pbdat
&= ~PB_ENET_TENA
; /* set to 0 = disabled */
358 immr
->im_cpm
.cp_pbdir
|= PB_ENET_TENA
;
363 /* ------------------------------------------------------------------------- */
365 /***********************************************************************
366 F* Function: void reset_phy (void) P*A*Z*
372 Z* Intention: Reset the PHY. In the lwmon case we do this by the
373 Z* signaling the PIC I/O expander.
375 D* Design: wd@denx.de
376 C* Coding: wd@denx.de
377 V* Verification: dzu@denx.de
378 ***********************************************************************/
379 void reset_phy (void)
384 printf ("### Switch on Ethernet for SCC2 ###\n");
388 printf ("Old PIC read: reg_61 = 0x%02x\n", c
);
390 c
|= 0x40; /* disable COM3 */
391 c
&= ~0x80; /* enable Ethernet */
395 printf ("New PIC read: reg_61 = 0x%02x\n", c
);
401 /*------------------------- Keyboard controller -----------------------*/
403 #define KEYBD_CMD_READ_KEYS 0x01
404 #define KEYBD_CMD_READ_VERSION 0x02
405 #define KEYBD_CMD_READ_STATUS 0x03
406 #define KEYBD_CMD_RESET_ERRORS 0x10
409 #define KEYBD_STATUS_MASK 0x3F
410 #define KEYBD_STATUS_H_RESET 0x20
411 #define KEYBD_STATUS_BROWNOUT 0x10
412 #define KEYBD_STATUS_WD_RESET 0x08
413 #define KEYBD_STATUS_OVERLOAD 0x04
414 #define KEYBD_STATUS_ILLEGAL_WR 0x02
415 #define KEYBD_STATUS_ILLEGAL_RD 0x01
417 /* Number of bytes returned from Keyboard Controller */
418 #define KEYBD_VERSIONLEN 2 /* version information */
419 #define KEYBD_DATALEN 9 /* normal key scan data */
421 /* maximum number of "magic" key codes that can be assigned */
423 static uchar kbd_addr
= CONFIG_SYS_I2C_KEYBD_ADDR
;
425 static uchar
*key_match (uchar
*);
427 #define KEYBD_SET_DEBUGMODE '#' /* Magic key to enable debug output */
429 /***********************************************************************
430 F* Function: int board_postclk_init (void) P*A*Z*
435 P* - 0 is always returned.
437 Z* Intention: This function is the board_postclk_init() method implementation
438 Z* for the lwmon board.
440 ***********************************************************************/
441 int board_postclk_init (void)
445 #ifdef CONFIG_MODEM_SUPPORT
447 disable_putc(); /* modem doesn't understand banner etc */
455 struct serial_device
* default_serial_console (void)
457 return gd
->do_mdm_init
? &serial_scc_device
: &serial_smc_device
;
460 static void kbd_init (void)
462 uchar kbd_data
[KEYBD_DATALEN
];
463 uchar tmp_data
[KEYBD_DATALEN
];
469 gd
->arch
.kbd_status
= 0;
471 /* Forced by PIC. Delays <= 175us loose */
474 /* Read initial keyboard error code */
475 val
= KEYBD_CMD_READ_STATUS
;
476 i2c_write (kbd_addr
, 0, 0, &val
, 1);
477 i2c_read (kbd_addr
, 0, 0, &errcd
, 1);
478 /* clear unused bits */
479 errcd
&= KEYBD_STATUS_MASK
;
480 /* clear "irrelevant" bits. Recommended by Martin Rajek, LWN */
481 errcd
&= ~(KEYBD_STATUS_H_RESET
|KEYBD_STATUS_BROWNOUT
);
483 gd
->arch
.kbd_status
|= errcd
<< 8;
485 /* Reset error code and verify */
486 val
= KEYBD_CMD_RESET_ERRORS
;
487 i2c_write (kbd_addr
, 0, 0, &val
, 1);
488 udelay(1000); /* delay NEEDED by keyboard PIC !!! */
490 val
= KEYBD_CMD_READ_STATUS
;
491 i2c_write (kbd_addr
, 0, 0, &val
, 1);
492 i2c_read (kbd_addr
, 0, 0, &val
, 1);
494 val
&= KEYBD_STATUS_MASK
; /* clear unused bits */
495 if (val
) { /* permanent error, report it */
496 gd
->arch
.kbd_status
|= val
;
501 * Read current keyboard state.
503 * After the error reset it may take some time before the
504 * keyboard PIC picks up a valid keyboard scan - the total
505 * scan time is approx. 1.6 ms (information by Martin Rajek,
506 * 28 Sep 2002). We read a couple of times for the keyboard
507 * to stabilize, using a big enough delay.
508 * 10 times should be enough. If the data is still changing,
509 * we use what we get :-(
512 memset (tmp_data
, 0xFF, KEYBD_DATALEN
); /* impossible value */
513 for (i
=0; i
<10; ++i
) {
514 val
= KEYBD_CMD_READ_KEYS
;
515 i2c_write (kbd_addr
, 0, 0, &val
, 1);
516 i2c_read (kbd_addr
, 0, 0, kbd_data
, KEYBD_DATALEN
);
518 if (memcmp(kbd_data
, tmp_data
, KEYBD_DATALEN
) == 0) {
519 /* consistent state, done */
522 /* remeber last state, delay, and retry */
523 memcpy (tmp_data
, kbd_data
, KEYBD_DATALEN
);
528 /***********************************************************************
529 F* Function: int misc_init_r (void) P*A*Z*
534 P* - 0 is always returned, even in the case of a keyboard
537 Z* Intention: This function is the misc_init_r() method implementation
538 Z* for the lwmon board.
539 Z* The keyboard controller is initialized and the result
540 Z* of a read copied to the environment variable "keybd".
541 Z* If KEYBD_SET_DEBUGMODE is defined, a check is made for
542 Z* this key, and if found display to the LCD will be enabled.
543 Z* The keys in "keybd" are checked against the magic
544 Z* keycommands defined in the environment.
545 Z* See also key_match().
547 D* Design: wd@denx.de
548 C* Coding: wd@denx.de
549 V* Verification: dzu@denx.de
550 ***********************************************************************/
551 int misc_init_r (void)
553 uchar kbd_data
[KEYBD_DATALEN
];
554 char keybd_env
[2 * KEYBD_DATALEN
+ 1];
555 uchar kbd_init_status
= gd
->arch
.kbd_status
>> 8;
556 uchar kbd_status
= gd
->arch
.kbd_status
;
561 if (kbd_init_status
) {
562 printf ("KEYBD: Error %02X\n", kbd_init_status
);
564 if (kbd_status
) { /* permanent error, report it */
565 printf ("*** Keyboard error code %02X ***\n", kbd_status
);
566 sprintf (keybd_env
, "%02X", kbd_status
);
567 setenv ("keybd", keybd_env
);
572 * Now we know that we have a working keyboard, so disable
573 * all output to the LCD except when a key press is detected.
576 if ((console_assign (stdout
, "serial") < 0) ||
577 (console_assign (stderr
, "serial") < 0)) {
578 printf ("Can't assign serial port as output device\n");
582 val
= KEYBD_CMD_READ_VERSION
;
583 i2c_write (kbd_addr
, 0, 0, &val
, 1);
584 i2c_read (kbd_addr
, 0, 0, kbd_data
, KEYBD_VERSIONLEN
);
585 printf ("KEYBD: Version %d.%d\n", kbd_data
[0], kbd_data
[1]);
587 /* Read current keyboard state */
588 val
= KEYBD_CMD_READ_KEYS
;
589 i2c_write (kbd_addr
, 0, 0, &val
, 1);
590 i2c_read (kbd_addr
, 0, 0, kbd_data
, KEYBD_DATALEN
);
592 for (i
= 0; i
< KEYBD_DATALEN
; ++i
) {
593 sprintf (keybd_env
+ i
+ i
, "%02X", kbd_data
[i
]);
595 setenv ("keybd", keybd_env
);
597 str
= strdup ((char *)key_match (kbd_data
)); /* decode keys */
598 #ifdef KEYBD_SET_DEBUGMODE
599 if (kbd_data
[0] == KEYBD_SET_DEBUGMODE
) { /* set debug mode */
600 if ((console_assign (stdout
, "lcd") < 0) ||
601 (console_assign (stderr
, "lcd") < 0)) {
602 printf ("Can't assign LCD display as output device\n");
605 #endif /* KEYBD_SET_DEBUGMODE */
606 #ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */
607 setenv ("preboot", str
); /* set or delete definition */
608 #endif /* CONFIG_PREBOOT */
615 #ifdef CONFIG_PREBOOT
617 static uchar kbd_magic_prefix
[] = "key_magic";
618 static uchar kbd_command_prefix
[] = "key_cmd";
620 static int compare_magic (uchar
*kbd_data
, uchar
*str
)
622 uchar compare
[KEYBD_DATALEN
-1];
626 /* Don't include modifier byte */
627 memcpy (compare
, kbd_data
+1, KEYBD_DATALEN
-1);
629 for (; str
!= NULL
; str
= (*nxt
) ? (uchar
*)(nxt
+1) : (uchar
*)nxt
) {
633 c
= (uchar
) simple_strtoul ((char *)str
, (char **) (&nxt
), 16);
635 if (str
== (uchar
*)nxt
) { /* invalid character */
640 * Check if this key matches the input.
641 * Set matches to zero, so they match only once
642 * and we can find duplicates or extra keys
644 for (k
= 0; k
< sizeof(compare
); ++k
) {
645 if (compare
[k
] == '\0') /* only non-zero entries */
647 if (c
== compare
[k
]) { /* found matching key */
652 if (k
== sizeof(compare
)) {
653 return -1; /* unmatched key */
658 * A full match leaves no keys in the `compare' array,
660 for (i
= 0; i
< sizeof(compare
); ++i
) {
670 /***********************************************************************
671 F* Function: static uchar *key_match (uchar *kbd_data) P*A*Z*
673 P* Parameters: uchar *kbd_data
674 P* - The keys to match against our magic definitions
676 P* Returnvalue: uchar *
677 P* - != NULL: Pointer to the corresponding command(s)
678 P* NULL: No magic is about to happen
680 Z* Intention: Check if pressed key(s) match magic sequence,
681 Z* and return the command string associated with that key(s).
683 Z* If no key press was decoded, NULL is returned.
685 Z* Note: the first character of the argument will be
686 Z* overwritten with the "magic charcter code" of the
687 Z* decoded key(s), or '\0'.
689 Z* Note: the string points to static environment data
690 Z* and must be saved before you call any function that
691 Z* modifies the environment.
693 D* Design: wd@denx.de
694 C* Coding: wd@denx.de
695 V* Verification: dzu@denx.de
696 ***********************************************************************/
697 static uchar
*key_match (uchar
*kbd_data
)
699 char magic
[sizeof (kbd_magic_prefix
) + 1];
701 char *kbd_magic_keys
;
704 * The following string defines the characters that can pe appended
705 * to "key_magic" to form the names of environment variables that
706 * hold "magic" key codes, i. e. such key codes that can cause
707 * pre-boot actions. If the string is empty (""), then only
708 * "key_magic" is checked (old behaviour); the string "125" causes
709 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
711 if ((kbd_magic_keys
= getenv ("magic_keys")) == NULL
)
714 /* loop over all magic keys;
715 * use '\0' suffix in case of empty string
717 for (suffix
=(uchar
*)kbd_magic_keys
; *suffix
|| suffix
==(uchar
*)kbd_magic_keys
; ++suffix
) {
718 sprintf (magic
, "%s%c", kbd_magic_prefix
, *suffix
);
720 printf ("### Check magic \"%s\"\n", magic
);
722 if (compare_magic(kbd_data
, (uchar
*)getenv(magic
)) == 0) {
723 char cmd_name
[sizeof (kbd_command_prefix
) + 1];
726 sprintf (cmd_name
, "%s%c", kbd_command_prefix
, *suffix
);
728 cmd
= getenv (cmd_name
);
730 printf ("### Set PREBOOT to $(%s): \"%s\"\n",
731 cmd_name
, cmd
? cmd
: "<<NULL>>");
734 return ((uchar
*)cmd
);
738 printf ("### Delete PREBOOT\n");
743 #endif /* CONFIG_PREBOOT */
745 #ifdef CONFIG_LCD_INFO
748 #include <timestamp.h>
750 void lcd_show_board_info(void)
754 lcd_printf ("%s (%s - %s)\n", U_BOOT_VERSION
, U_BOOT_DATE
, U_BOOT_TIME
);
755 lcd_printf ("(C) 2008 DENX Software Engineering GmbH\n");
756 lcd_printf (" Wolfgang DENK, wd@denx.de\n");
757 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
758 lcd_printf ("MPC823 CPU at %s MHz\n",
759 strmhz(temp
, gd
->cpu_clk
));
760 lcd_printf (" %ld MB RAM, %ld MB Flash\n",
762 gd
->bd
->bi_flashsize
>> 20 );
764 /* leave one blank line */
765 lcd_printf ("\nMPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash\n",
766 strmhz(temp
, gd
->cpu_clk
),
768 gd
->bd
->bi_flashsize
>> 20 );
769 #endif /* CONFIG_LCD_INFO_BELOW_LOGO */
771 #endif /* CONFIG_LCD_INFO */
773 /*---------------Board Special Commands: PIC read/write ---------------*/
775 #if defined(CONFIG_CMD_BSP)
776 /***********************************************************************
777 F* Function: int do_pic (cmd_tbl_t *cmdtp, int flag,
778 F* int argc, char * const argv[]) P*A*Z*
780 P* Parameters: cmd_tbl_t *cmdtp
781 P* - Pointer to our command table entry
783 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
787 P* char * const argv[]
788 P* - Array of the actual arguments
791 P* - 0 The command was handled successfully
792 P* 1 An error occurred
794 Z* Intention: Implement the "pic [read|write]" commands.
795 Z* The read subcommand takes one argument, the register,
796 Z* whereas the write command takes two, the register and
799 D* Design: wd@denx.de
800 C* Coding: wd@denx.de
801 V* Verification: dzu@denx.de
802 ***********************************************************************/
803 int do_pic (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
808 case 3: /* PIC read reg */
809 if (strcmp (argv
[1], "read") != 0)
812 reg
= simple_strtoul (argv
[2], NULL
, 16);
814 printf ("PIC read: reg %02x: %02x\n\n", reg
, pic_read (reg
));
817 case 4: /* PIC write reg val */
818 if (strcmp (argv
[1], "write") != 0)
821 reg
= simple_strtoul (argv
[2], NULL
, 16);
822 val
= simple_strtoul (argv
[3], NULL
, 16);
824 printf ("PIC write: reg %02x val 0x%02x: %02x => ",
825 reg
, val
, pic_read (reg
));
826 pic_write (reg
, val
);
827 printf ("%02x\n\n", pic_read (reg
));
832 return cmd_usage(cmdtp
);
836 "read and write PIC registers",
837 "read reg - read PIC register `reg'\n"
838 "pic write reg val - write value `val' to PIC register `reg'"
841 /***********************************************************************
842 F* Function: int do_kbd (cmd_tbl_t *cmdtp, int flag,
843 F* int argc, char * const argv[]) P*A*Z*
845 P* Parameters: cmd_tbl_t *cmdtp
846 P* - Pointer to our command table entry
848 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
852 P* char * const argv[]
853 P* - Array of the actual arguments
856 P* - 0 is always returned.
858 Z* Intention: Implement the "kbd" command.
859 Z* The keyboard status is read. The result is printed on
860 Z* the console and written into the "keybd" environment
863 D* Design: wd@denx.de
864 C* Coding: wd@denx.de
865 V* Verification: dzu@denx.de
866 ***********************************************************************/
867 int do_kbd (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
869 uchar kbd_data
[KEYBD_DATALEN
];
870 char keybd_env
[2 * KEYBD_DATALEN
+ 1];
874 #if 0 /* Done in kbd_init */
875 i2c_init (CONFIG_SYS_I2C_SPEED
, CONFIG_SYS_I2C_SLAVE
);
879 val
= KEYBD_CMD_READ_KEYS
;
880 i2c_write (kbd_addr
, 0, 0, &val
, 1);
881 i2c_read (kbd_addr
, 0, 0, kbd_data
, KEYBD_DATALEN
);
884 for (i
= 0; i
< KEYBD_DATALEN
; ++i
) {
885 sprintf (keybd_env
+ i
+ i
, "%02X", kbd_data
[i
]);
886 printf (" %02x", kbd_data
[i
]);
889 setenv ("keybd", keybd_env
);
895 "read keyboard status",
899 /* Read and set LSB switch */
900 #define CONFIG_SYS_PC_TXD1_ENA 0x0008 /* PC.12 */
902 /***********************************************************************
903 F* Function: int do_lsb (cmd_tbl_t *cmdtp, int flag,
904 F* int argc, char * const argv[]) P*A*Z*
906 P* Parameters: cmd_tbl_t *cmdtp
907 P* - Pointer to our command table entry
909 P* - If the CMD_FLAG_REPEAT bit is set, then this call is
913 P* char * const argv[]
914 P* - Array of the actual arguments
917 P* - 0 The command was handled successfully
918 P* 1 An error occurred
920 Z* Intention: Implement the "lsb [on|off]" commands.
921 Z* The lsb is switched according to the first parameter by
922 Z* by signaling the PIC I/O expander.
923 Z* Called with no arguments, the current setting is
926 D* Design: wd@denx.de
927 C* Coding: wd@denx.de
928 V* Verification: dzu@denx.de
929 ***********************************************************************/
930 int do_lsb (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
933 immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
936 case 1: /* lsb - print setting */
937 val
= pic_read (0x60);
938 printf ("LSB is o%s\n", (val
& 0x20) ? "n" : "ff");
940 case 2: /* lsb on or lsb off - set switch */
941 val
= pic_read (0x60);
943 if (strcmp (argv
[1], "on") == 0) {
945 immr
->im_ioport
.iop_pcpar
&= ~(CONFIG_SYS_PC_TXD1_ENA
);
946 immr
->im_ioport
.iop_pcdat
|= CONFIG_SYS_PC_TXD1_ENA
;
947 immr
->im_ioport
.iop_pcdir
|= CONFIG_SYS_PC_TXD1_ENA
;
948 } else if (strcmp (argv
[1], "off") == 0) {
950 immr
->im_ioport
.iop_pcpar
&= ~(CONFIG_SYS_PC_TXD1_ENA
);
951 immr
->im_ioport
.iop_pcdat
&= ~(CONFIG_SYS_PC_TXD1_ENA
);
952 immr
->im_ioport
.iop_pcdir
|= CONFIG_SYS_PC_TXD1_ENA
;
956 pic_write (0x60, val
);
961 return cmd_usage(cmdtp
);
966 "check and set LSB switch",
967 "on - switch LSB on\n"
968 "lsb off - switch LSB off\n"
969 "lsb - print current setting"
974 /*----------------------------- Utilities -----------------------------*/
975 /***********************************************************************
976 F* Function: uchar pic_read (uchar reg) P*A*Z*
978 P* Parameters: uchar reg
979 P* - Register to read
981 P* Returnvalue: uchar
982 P* - Value read from register
984 Z* Intention: Read a register from the PIC I/O expander.
986 D* Design: wd@denx.de
987 C* Coding: wd@denx.de
988 V* Verification: dzu@denx.de
989 ***********************************************************************/
990 uchar
pic_read (uchar reg
)
992 return (i2c_reg_read (CONFIG_SYS_I2C_PICIO_ADDR
, reg
));
995 /***********************************************************************
996 F* Function: void pic_write (uchar reg, uchar val) P*A*Z*
998 P* Parameters: uchar reg
999 P* - Register to read
1003 P* Returnvalue: none
1005 Z* Intention: Write to a register on the PIC I/O expander.
1007 D* Design: wd@denx.de
1008 C* Coding: wd@denx.de
1009 V* Verification: dzu@denx.de
1010 ***********************************************************************/
1011 void pic_write (uchar reg
, uchar val
)
1013 i2c_reg_write (CONFIG_SYS_I2C_PICIO_ADDR
, reg
, val
);
1016 /*---------------------- Board Control Functions ----------------------*/
1017 /***********************************************************************
1018 F* Function: void board_poweroff (void) P*A*Z*
1022 P* Returnvalue: none
1024 Z* Intention: Turn off the battery power and loop endless, so this
1025 Z* should better be the last function you call...
1027 D* Design: wd@denx.de
1028 C* Coding: wd@denx.de
1029 V* Verification: dzu@denx.de
1030 ***********************************************************************/
1031 void board_poweroff (void)
1033 /* Turn battery off */
1034 ((volatile immap_t
*)CONFIG_SYS_IMMR
)->im_ioport
.iop_pcdat
&= ~(1 << (31 - 13));
1039 #ifdef CONFIG_MODEM_SUPPORT
1040 static int key_pressed(void)
1042 uchar kbd_data
[KEYBD_DATALEN
];
1046 val
= KEYBD_CMD_READ_KEYS
;
1047 i2c_write (kbd_addr
, 0, 0, &val
, 1);
1048 i2c_read (kbd_addr
, 0, 0, kbd_data
, KEYBD_DATALEN
);
1050 return (compare_magic(kbd_data
, (uchar
*)CONFIG_MODEM_KEY_MAGIC
) == 0);
1052 #endif /* CONFIG_MODEM_SUPPORT */
1056 * Returns 1 if keys pressed to start the power-on long-running tests
1057 * Called from board_init_f().
1059 int post_hotkeys_pressed(void)
1061 uchar kbd_data
[KEYBD_DATALEN
];
1065 val
= KEYBD_CMD_READ_KEYS
;
1066 i2c_write (kbd_addr
, 0, 0, &val
, 1);
1067 i2c_read (kbd_addr
, 0, 0, kbd_data
, KEYBD_DATALEN
);
1069 return (compare_magic(kbd_data
, (uchar
*)CONFIG_POST_KEY_MAGIC
) == 0);