blob: 225b1ef25827d16a834a34724a783a43e565da43 [file] [log] [blame]
wdenke2211742002-11-02 23:30:20 +00001/***********************************************************************
2 *
3M* Modul: lwmon.c
4M*
5M* Content: LWMON specific U-Boot commands.
6 *
7 * (C) Copyright 2001, 2002
8 * DENX Software Engineering
9 * Wolfgang Denk, wd@denx.de
wdenke2211742002-11-02 23:30:20 +000010 *
11D* Design: wd@denx.de
12C* Coding: wd@denx.de
13V* Verification: dzu@denx.de
14 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020015 * SPDX-License-Identifier: GPL-2.0+
wdenke2211742002-11-02 23:30:20 +000016 ***********************************************************************/
17
18/*---------------------------- Headerfiles ----------------------------*/
19#include <common.h>
20#include <mpc8xx.h>
21#include <commproc.h>
22#include <i2c.h>
23#include <command.h>
wdenke2211742002-11-02 23:30:20 +000024#include <malloc.h>
25#include <post.h>
wdenk281e00a2004-08-01 22:48:16 +000026#include <serial.h>
wdenke2211742002-11-02 23:30:20 +000027
28#include <linux/types.h>
29#include <linux/string.h> /* for strdup */
30
Wolfgang Denkd87080b2006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
wdenke2211742002-11-02 23:30:20 +000033/*------------------------ Local prototypes ---------------------------*/
34static long int dram_size (long int, long int *, long int);
wdenk4532cb62003-04-27 22:52:51 +000035static void kbd_init (void);
36static int compare_magic (uchar *kbd_data, uchar *str);
wdenke2211742002-11-02 23:30:20 +000037
38
39/*--------------------- Local macros and constants --------------------*/
40#define _NOT_USED_ 0xFFFFFFFF
41
wdenk4532cb62003-04-27 22:52:51 +000042#ifdef CONFIG_MODEM_SUPPORT
43static int key_pressed(void);
44extern void disable_putc(void);
45#endif /* CONFIG_MODEM_SUPPORT */
46
wdenke2211742002-11-02 23:30:20 +000047/*
48 * 66 MHz SDRAM access using UPM A
49 */
50const uint sdram_table[] =
51{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020052#if defined(CONFIG_SYS_MEMORY_75) || defined(CONFIG_SYS_MEMORY_8E)
wdenke2211742002-11-02 23:30:20 +000053 /*
54 * Single Read. (Offset 0 in UPM RAM)
55 */
56 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
57 0x1FF5FC47, /* last */
58 /*
59 * SDRAM Initialization (offset 5 in UPM RAM)
60 *
wdenk8bde7f72003-06-27 21:31:46 +000061 * 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.
wdenke2211742002-11-02 23:30:20 +000064 *
65 */
66 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
67 /*
68 * Burst Read. (Offset 8 in UPM RAM)
69 */
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_,
74 /*
75 * Single Write. (Offset 18 in UPM RAM)
76 */
77 0x1F2DFC04, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */
78 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
79 /*
80 * Burst Write. (Offset 20 in UPM RAM)
81 */
82 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
83 0xF0AFFC00, 0xE1BAFC04, 0x01FF5FC47, /* last */
84 _NOT_USED_,
85 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
86 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
87 /*
88 * Refresh (Offset 30 in UPM RAM)
89 */
90 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
91 0xFFFFFC84, 0xFFFFFC07, /* last */
92 _NOT_USED_, _NOT_USED_,
93 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
94 /*
95 * Exception. (Offset 3c in UPM RAM)
96 */
97 0x7FFFFC07, /* last */
98 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
99#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100#ifdef CONFIG_SYS_MEMORY_7E
wdenke2211742002-11-02 23:30:20 +0000101 /*
102 * Single Read. (Offset 0 in UPM RAM)
103 */
104 0x0E2DBC04, 0x11AF7C04, 0xEFBAFC00, 0x1FF5FC47, /* last */
105 _NOT_USED_,
106 /*
107 * SDRAM Initialization (offset 5 in UPM RAM)
108 *
wdenk8bde7f72003-06-27 21:31:46 +0000109 * 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.
wdenke2211742002-11-02 23:30:20 +0000112 *
113 */
114 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
115 /*
116 * Burst Read. (Offset 8 in UPM RAM)
117 */
118 0x0E2DBC04, 0x10AF7C04, 0xF0AFFC00, 0xF0AFFC00,
119 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* last */
wdenk8bde7f72003-06-27 21:31:46 +0000120 _NOT_USED_,
wdenke2211742002-11-02 23:30:20 +0000121 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
122 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
123 /*
124 * Single Write. (Offset 18 in UPM RAM)
125 */
126 0x0E29BC04, 0x01B27C04, 0x1FF5FC47, /* last */
127 _NOT_USED_,
128 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
129 /*
130 * Burst Write. (Offset 20 in UPM RAM)
131 */
132 0x0E29BC04, 0x10A77C00, 0xF0AFFC00, 0xF0AFFC00,
133 0xE1BAFC04, 0x1FF5FC47, /* last */
wdenk8bde7f72003-06-27 21:31:46 +0000134 _NOT_USED_, _NOT_USED_,
wdenke2211742002-11-02 23:30:20 +0000135 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
136 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
137 /*
138 * Refresh (Offset 30 in UPM RAM)
139 */
140 0x1FFD7C84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
141 0xFFFFFC84, 0xFFFFFC07, /* last */
142 _NOT_USED_, _NOT_USED_,
143 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
144 /*
145 * Exception. (Offset 3c in UPM RAM)
146 */
147 0x7FFFFC07, /* last */
148 0xFFFFFCFF, 0xFFFFFCFF, 0xFFFFFCFF,
149#endif
150};
151
152/*
153 * Check Board Identity:
154 *
155 */
156
157/***********************************************************************
158F* Function: int checkboard (void) P*A*Z*
159 *
160P* Parameters: none
161P*
162P* Returnvalue: int - 0 is always returned
163 *
164Z* Intention: This function is the checkboard() method implementation
165Z* for the lwmon board. Only a standard message is printed.
166 *
167D* Design: wd@denx.de
168C* Coding: wd@denx.de
169V* Verification: dzu@denx.de
170 ***********************************************************************/
171int checkboard (void)
172{
Wolfgang Denkee073a52005-07-21 13:53:44 +0200173 puts ("Board: LICCON Konsole LCD3\n");
wdenke2211742002-11-02 23:30:20 +0000174 return (0);
175}
176
177/***********************************************************************
Becky Bruce9973e3c2008-06-09 16:03:40 -0500178F* Function: phys_size_t initdram (int board_type) P*A*Z*
wdenke2211742002-11-02 23:30:20 +0000179 *
180P* Parameters: int board_type
181P* - Usually type of the board - ignored here.
182P*
183P* Returnvalue: long int
184P* - Size of initialized memory
185 *
186Z* Intention: This function is the initdram() method implementation
187Z* for the lwmon board.
188Z* The memory controller is initialized to access the
189Z* DRAM.
190 *
191D* Design: wd@denx.de
192C* Coding: wd@denx.de
193V* Verification: dzu@denx.de
194 ***********************************************************************/
Becky Bruce9973e3c2008-06-09 16:03:40 -0500195phys_size_t initdram (int board_type)
wdenke2211742002-11-02 23:30:20 +0000196{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200197 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenke2211742002-11-02 23:30:20 +0000198 volatile memctl8xx_t *memctl = &immr->im_memctl;
199 long int size_b0;
200 long int size8, size9;
201 int i;
202
203 /*
204 * Configure UPMA for SDRAM
205 */
206 upmconfig (UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
207
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200208 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
wdenke2211742002-11-02 23:30:20 +0000209
210 /* burst length=4, burst type=sequential, CAS latency=2 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200211 memctl->memc_mar = CONFIG_SYS_MAR;
wdenke2211742002-11-02 23:30:20 +0000212
213 /*
214 * Map controller bank 3 to the SDRAM bank at preliminary address.
215 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200216 memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
217 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
wdenke2211742002-11-02 23:30:20 +0000218
219 /* initialize memory address register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200220 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL; /* refresh not enabled yet */
wdenke2211742002-11-02 23:30:20 +0000221
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);
225
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);
231
232 udelay (1); /* 0x80006106 */
233 memctl->memc_mcr = MCR_OP_RUN | MCR_MB_CS3 | MCR_MLCF (1) | MCR_MAD (0x06);
234
wdenk2535d602003-07-17 23:16:40 +0000235 memctl->memc_mamr |= MAMR_PTAE; /* refresh enabled */
wdenke2211742002-11-02 23:30:20 +0000236
237 udelay (200);
238
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;
243 unsigned long val;
244
245 val = *(addr + i);
246 *(addr + i) = val;
247 }
248
249 /*
250 * Check Bank 0 Memory Size for re-configuration
251 *
252 * try 8 column mode
253 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200254 size8 = dram_size (CONFIG_SYS_MAMR_8COL, (long *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
wdenke2211742002-11-02 23:30:20 +0000255
256 udelay (1000);
257
258 /*
259 * try 9 column mode
260 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200261 size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
wdenke2211742002-11-02 23:30:20 +0000262
263 if (size8 < size9) { /* leave configuration at 9 columns */
264 size_b0 = size9;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200265 memctl->memc_mamr = CONFIG_SYS_MAMR_9COL | MAMR_PTAE;
wdenke2211742002-11-02 23:30:20 +0000266 udelay (500);
267 } else { /* back to 8 columns */
268 size_b0 = size8;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200269 memctl->memc_mamr = CONFIG_SYS_MAMR_8COL | MAMR_PTAE;
wdenke2211742002-11-02 23:30:20 +0000270 udelay (500);
271 }
272
273 /*
274 * Final mapping:
275 */
276
277 memctl->memc_or3 = ((-size_b0) & 0xFFFF0000) |
278 OR_CSNT_SAM | OR_G5LS | SDRAM_TIMING;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200279 memctl->memc_br3 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
wdenke2211742002-11-02 23:30:20 +0000280 udelay (1000);
281
282 return (size_b0);
283}
284
285/***********************************************************************
286F* Function: static long int dram_size (long int mamr_value,
287F* long int *base,
288F* long int maxsize) P*A*Z*
289 *
290P* Parameters: long int mamr_value
291P* - Value for MAMR for the test
292P* long int *base
293P* - Base address for the test
294P* long int maxsize
295P* - Maximum size to test for
296P*
297P* Returnvalue: long int
298P* - Size of probed memory
299 *
300Z* Intention: Check memory range for valid RAM. A simple memory test
301Z* determines the actually available RAM size between
302Z* addresses `base' and `base + maxsize'. Some (not all)
303Z* hardware errors are detected:
304Z* - short between address lines
305Z* - short between data lines
306 *
307D* Design: wd@denx.de
308C* Coding: wd@denx.de
309V* Verification: dzu@denx.de
310 ***********************************************************************/
311static long int dram_size (long int mamr_value, long int *base, long int maxsize)
312{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200313 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenke2211742002-11-02 23:30:20 +0000314 volatile memctl8xx_t *memctl = &immr->im_memctl;
wdenke2211742002-11-02 23:30:20 +0000315
316 memctl->memc_mamr = mamr_value;
317
wdenkc83bf6a2004-01-06 22:38:14 +0000318 return (get_ram_size(base, maxsize));
wdenke2211742002-11-02 23:30:20 +0000319}
320
321/* ------------------------------------------------------------------------- */
322
323#ifndef PB_ENET_TENA
324# define PB_ENET_TENA ((uint)0x00002000) /* PB 18 */
325#endif
326
327/***********************************************************************
wdenkc837dcb2004-01-20 23:12:12 +0000328F* Function: int board_early_init_f (void) P*A*Z*
wdenke2211742002-11-02 23:30:20 +0000329 *
330P* Parameters: none
331P*
332P* Returnvalue: int
333P* - 0 is always returned.
334 *
wdenkc837dcb2004-01-20 23:12:12 +0000335Z* Intention: This function is the board_early_init_f() method implementation
wdenke2211742002-11-02 23:30:20 +0000336Z* for the lwmon board.
337Z* Disable Ethernet TENA on Port B.
338 *
339D* Design: wd@denx.de
340C* Coding: wd@denx.de
341V* Verification: dzu@denx.de
342 ***********************************************************************/
wdenkc837dcb2004-01-20 23:12:12 +0000343int board_early_init_f (void)
wdenke2211742002-11-02 23:30:20 +0000344{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200345 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenke2211742002-11-02 23:30:20 +0000346
347 /* Disable Ethernet TENA on Port B
348 * Necessary because of pull up in COM3 port.
349 *
350 * This is just a preliminary fix, intended to turn off TENA
351 * as soon as possible to avoid noise on the network. Once
Albert ARIBAUDfa82f872011-08-04 18:45:45 +0200352 * I2C is running we will make sure the interface is
wdenke2211742002-11-02 23:30:20 +0000353 * correctly initialized.
354 */
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;
wdenk4532cb62003-04-27 22:52:51 +0000359
wdenke2211742002-11-02 23:30:20 +0000360 return (0);
361}
362
363/* ------------------------------------------------------------------------- */
364
365/***********************************************************************
366F* Function: void reset_phy (void) P*A*Z*
367 *
368P* Parameters: none
369P*
370P* Returnvalue: none
371 *
372Z* Intention: Reset the PHY. In the lwmon case we do this by the
373Z* signaling the PIC I/O expander.
374 *
375D* Design: wd@denx.de
376C* Coding: wd@denx.de
377V* Verification: dzu@denx.de
378 ***********************************************************************/
379void reset_phy (void)
380{
381 uchar c;
382
383#ifdef DEBUG
384 printf ("### Switch on Ethernet for SCC2 ###\n");
385#endif
386 c = pic_read (0x61);
387#ifdef DEBUG
388 printf ("Old PIC read: reg_61 = 0x%02x\n", c);
389#endif
390 c |= 0x40; /* disable COM3 */
391 c &= ~0x80; /* enable Ethernet */
392 pic_write (0x61, c);
393#ifdef DEBUG
394 c = pic_read (0x61);
395 printf ("New PIC read: reg_61 = 0x%02x\n", c);
396#endif
397 udelay (1000);
398}
399
400
401/*------------------------- Keyboard controller -----------------------*/
402/* command codes */
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
407
408/* status codes */
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
416
417/* Number of bytes returned from Keyboard Controller */
418#define KEYBD_VERSIONLEN 2 /* version information */
419#define KEYBD_DATALEN 9 /* normal key scan data */
420
421/* maximum number of "magic" key codes that can be assigned */
422
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200423static uchar kbd_addr = CONFIG_SYS_I2C_KEYBD_ADDR;
wdenke2211742002-11-02 23:30:20 +0000424
425static uchar *key_match (uchar *);
426
427#define KEYBD_SET_DEBUGMODE '#' /* Magic key to enable debug output */
428
429/***********************************************************************
wdenk4532cb62003-04-27 22:52:51 +0000430F* Function: int board_postclk_init (void) P*A*Z*
wdenke2211742002-11-02 23:30:20 +0000431 *
432P* Parameters: none
433P*
434P* Returnvalue: int
wdenk4532cb62003-04-27 22:52:51 +0000435P* - 0 is always returned.
wdenke2211742002-11-02 23:30:20 +0000436 *
wdenk4532cb62003-04-27 22:52:51 +0000437Z* Intention: This function is the board_postclk_init() method implementation
wdenke2211742002-11-02 23:30:20 +0000438Z* for the lwmon board.
wdenke2211742002-11-02 23:30:20 +0000439 *
wdenke2211742002-11-02 23:30:20 +0000440 ***********************************************************************/
wdenk4532cb62003-04-27 22:52:51 +0000441int board_postclk_init (void)
wdenke2211742002-11-02 23:30:20 +0000442{
wdenk4532cb62003-04-27 22:52:51 +0000443 kbd_init();
444
445#ifdef CONFIG_MODEM_SUPPORT
446 if (key_pressed()) {
447 disable_putc(); /* modem doesn't understand banner etc */
448 gd->do_mdm_init = 1;
449 }
450#endif
451
452 return (0);
453}
454
wdenk281e00a2004-08-01 22:48:16 +0000455struct serial_device * default_serial_console (void)
456{
wdenk281e00a2004-08-01 22:48:16 +0000457 return gd->do_mdm_init ? &serial_scc_device : &serial_smc_device;
458}
459
wdenk4532cb62003-04-27 22:52:51 +0000460static void kbd_init (void)
461{
wdenke2211742002-11-02 23:30:20 +0000462 uchar kbd_data[KEYBD_DATALEN];
463 uchar tmp_data[KEYBD_DATALEN];
wdenke2211742002-11-02 23:30:20 +0000464 uchar val, errcd;
wdenke2211742002-11-02 23:30:20 +0000465 int i;
466
Heiko Schocherea818db2013-01-29 08:53:15 +0100467 i2c_set_bus_num(0);
wdenk8bde7f72003-06-27 21:31:46 +0000468
Simon Glass225ca832012-12-13 20:49:04 +0000469 gd->arch.kbd_status = 0;
wdenke2211742002-11-02 23:30:20 +0000470
wdenkd1cbe852003-06-28 17:24:46 +0000471 /* Forced by PIC. Delays <= 175us loose */
472 udelay(1000);
473
wdenke2211742002-11-02 23:30:20 +0000474 /* 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);
482 if (errcd) {
Simon Glass225ca832012-12-13 20:49:04 +0000483 gd->arch.kbd_status |= errcd << 8;
wdenke2211742002-11-02 23:30:20 +0000484 }
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 !!! */
489
490 val = KEYBD_CMD_READ_STATUS;
491 i2c_write (kbd_addr, 0, 0, &val, 1);
492 i2c_read (kbd_addr, 0, 0, &val, 1);
493
494 val &= KEYBD_STATUS_MASK; /* clear unused bits */
495 if (val) { /* permanent error, report it */
Simon Glass225ca832012-12-13 20:49:04 +0000496 gd->arch.kbd_status |= val;
wdenk4532cb62003-04-27 22:52:51 +0000497 return;
wdenke2211742002-11-02 23:30:20 +0000498 }
499
500 /*
wdenke2211742002-11-02 23:30:20 +0000501 * Read current keyboard state.
502 *
wdenk8bde7f72003-06-27 21:31:46 +0000503 * 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 :-(
wdenke2211742002-11-02 23:30:20 +0000510 */
511
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);
517
518 if (memcmp(kbd_data, tmp_data, KEYBD_DATALEN) == 0) {
519 /* consistent state, done */
520 break;
521 }
522 /* remeber last state, delay, and retry */
523 memcpy (tmp_data, kbd_data, KEYBD_DATALEN);
524 udelay (5000);
525 }
wdenk4532cb62003-04-27 22:52:51 +0000526}
527
528/***********************************************************************
529F* Function: int misc_init_r (void) P*A*Z*
530 *
531P* Parameters: none
532P*
533P* Returnvalue: int
534P* - 0 is always returned, even in the case of a keyboard
535P* error.
536 *
537Z* Intention: This function is the misc_init_r() method implementation
538Z* for the lwmon board.
539Z* The keyboard controller is initialized and the result
540Z* of a read copied to the environment variable "keybd".
541Z* If KEYBD_SET_DEBUGMODE is defined, a check is made for
542Z* this key, and if found display to the LCD will be enabled.
543Z* The keys in "keybd" are checked against the magic
544Z* keycommands defined in the environment.
545Z* See also key_match().
546 *
547D* Design: wd@denx.de
548C* Coding: wd@denx.de
549V* Verification: dzu@denx.de
550 ***********************************************************************/
551int misc_init_r (void)
552{
wdenk4532cb62003-04-27 22:52:51 +0000553 uchar kbd_data[KEYBD_DATALEN];
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200554 char keybd_env[2 * KEYBD_DATALEN + 1];
Simon Glass225ca832012-12-13 20:49:04 +0000555 uchar kbd_init_status = gd->arch.kbd_status >> 8;
556 uchar kbd_status = gd->arch.kbd_status;
wdenk4532cb62003-04-27 22:52:51 +0000557 uchar val;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200558 char *str;
wdenk4532cb62003-04-27 22:52:51 +0000559 int i;
560
561 if (kbd_init_status) {
562 printf ("KEYBD: Error %02X\n", kbd_init_status);
563 }
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);
568 return 0;
569 }
570
571 /*
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.
574 */
575
576 if ((console_assign (stdout, "serial") < 0) ||
577 (console_assign (stderr, "serial") < 0)) {
578 printf ("Can't assign serial port as output device\n");
579 }
580
581 /* Read Version */
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]);
586
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);
wdenke2211742002-11-02 23:30:20 +0000591
592 for (i = 0; i < KEYBD_DATALEN; ++i) {
593 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
594 }
595 setenv ("keybd", keybd_env);
596
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200597 str = strdup ((char *)key_match (kbd_data)); /* decode keys */
wdenke2211742002-11-02 23:30:20 +0000598#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");
603 }
604 }
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 */
609 if (str != NULL) {
610 free (str);
611 }
612 return (0);
613}
614
615#ifdef CONFIG_PREBOOT
616
617static uchar kbd_magic_prefix[] = "key_magic";
618static uchar kbd_command_prefix[] = "key_cmd";
619
wdenk4532cb62003-04-27 22:52:51 +0000620static int compare_magic (uchar *kbd_data, uchar *str)
621{
622 uchar compare[KEYBD_DATALEN-1];
wdenkeedcd072004-09-08 22:03:11 +0000623 char *nxt;
wdenk4532cb62003-04-27 22:52:51 +0000624 int i;
625
626 /* Don't include modifier byte */
627 memcpy (compare, kbd_data+1, KEYBD_DATALEN-1);
628
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200629 for (; str != NULL; str = (*nxt) ? (uchar *)(nxt+1) : (uchar *)nxt) {
wdenk4532cb62003-04-27 22:52:51 +0000630 uchar c;
631 int k;
632
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200633 c = (uchar) simple_strtoul ((char *)str, (char **) (&nxt), 16);
wdenk4532cb62003-04-27 22:52:51 +0000634
wdenkeedcd072004-09-08 22:03:11 +0000635 if (str == (uchar *)nxt) { /* invalid character */
wdenk4532cb62003-04-27 22:52:51 +0000636 break;
637 }
638
639 /*
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
643 */
644 for (k = 0; k < sizeof(compare); ++k) {
645 if (compare[k] == '\0') /* only non-zero entries */
646 continue;
647 if (c == compare[k]) { /* found matching key */
648 compare[k] = '\0';
649 break;
650 }
651 }
652 if (k == sizeof(compare)) {
653 return -1; /* unmatched key */
654 }
655 }
656
657 /*
658 * A full match leaves no keys in the `compare' array,
659 */
660 for (i = 0; i < sizeof(compare); ++i) {
661 if (compare[i])
662 {
663 return -1;
664 }
665 }
666
667 return 0;
668}
669
wdenke2211742002-11-02 23:30:20 +0000670/***********************************************************************
671F* Function: static uchar *key_match (uchar *kbd_data) P*A*Z*
672 *
673P* Parameters: uchar *kbd_data
674P* - The keys to match against our magic definitions
675P*
676P* Returnvalue: uchar *
677P* - != NULL: Pointer to the corresponding command(s)
678P* NULL: No magic is about to happen
679 *
680Z* Intention: Check if pressed key(s) match magic sequence,
681Z* and return the command string associated with that key(s).
682Z*
683Z* If no key press was decoded, NULL is returned.
684Z*
685Z* Note: the first character of the argument will be
686Z* overwritten with the "magic charcter code" of the
687Z* decoded key(s), or '\0'.
688Z*
689Z* Note: the string points to static environment data
690Z* and must be saved before you call any function that
691Z* modifies the environment.
692 *
693D* Design: wd@denx.de
694C* Coding: wd@denx.de
695V* Verification: dzu@denx.de
696 ***********************************************************************/
697static uchar *key_match (uchar *kbd_data)
698{
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200699 char magic[sizeof (kbd_magic_prefix) + 1];
wdenk4532cb62003-04-27 22:52:51 +0000700 uchar *suffix;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200701 char *kbd_magic_keys;
wdenke2211742002-11-02 23:30:20 +0000702
703 /*
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.
710 */
711 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
712 kbd_magic_keys = "";
713
714 /* loop over all magic keys;
715 * use '\0' suffix in case of empty string
716 */
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200717 for (suffix=(uchar *)kbd_magic_keys; *suffix || suffix==(uchar *)kbd_magic_keys; ++suffix) {
wdenke2211742002-11-02 23:30:20 +0000718 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
719#if 0
720 printf ("### Check magic \"%s\"\n", magic);
721#endif
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200722 if (compare_magic(kbd_data, (uchar *)getenv(magic)) == 0) {
723 char cmd_name[sizeof (kbd_command_prefix) + 1];
wdenke2211742002-11-02 23:30:20 +0000724 char *cmd;
725
726 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
727
728 cmd = getenv (cmd_name);
729#if 0
730 printf ("### Set PREBOOT to $(%s): \"%s\"\n",
731 cmd_name, cmd ? cmd : "<<NULL>>");
732#endif
733 *kbd_data = *suffix;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200734 return ((uchar *)cmd);
wdenke2211742002-11-02 23:30:20 +0000735 }
736 }
737#if 0
738 printf ("### Delete PREBOOT\n");
739#endif
740 *kbd_data = '\0';
741 return (NULL);
742}
743#endif /* CONFIG_PREBOOT */
744
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200745#ifdef CONFIG_LCD_INFO
746#include <lcd.h>
747#include <version.h>
Peter Tyser561858e2008-11-03 09:30:59 -0600748#include <timestamp.h>
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200749
750void lcd_show_board_info(void)
751{
752 char temp[32];
753
Peter Tyser561858e2008-11-03 09:30:59 -0600754 lcd_printf ("%s (%s - %s)\n", U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200755 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));
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200760 lcd_printf (" %ld MB RAM, %ld MB Flash\n",
761 gd->ram_size >> 20,
762 gd->bd->bi_flashsize >> 20 );
763#else
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),
767 gd->ram_size >> 20,
768 gd->bd->bi_flashsize >> 20 );
769#endif /* CONFIG_LCD_INFO_BELOW_LOGO */
770}
771#endif /* CONFIG_LCD_INFO */
772
wdenke2211742002-11-02 23:30:20 +0000773/*---------------Board Special Commands: PIC read/write ---------------*/
774
Jon Loeligerc508a4c2007-07-09 18:31:28 -0500775#if defined(CONFIG_CMD_BSP)
wdenke2211742002-11-02 23:30:20 +0000776/***********************************************************************
777F* Function: int do_pic (cmd_tbl_t *cmdtp, int flag,
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200778F* int argc, char * const argv[]) P*A*Z*
wdenke2211742002-11-02 23:30:20 +0000779 *
780P* Parameters: cmd_tbl_t *cmdtp
781P* - Pointer to our command table entry
782P* int flag
783P* - If the CMD_FLAG_REPEAT bit is set, then this call is
784P* a repetition
785P* int argc
786P* - Argument count
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200787P* char * const argv[]
wdenke2211742002-11-02 23:30:20 +0000788P* - Array of the actual arguments
789P*
790P* Returnvalue: int
791P* - 0 The command was handled successfully
792P* 1 An error occurred
793 *
794Z* Intention: Implement the "pic [read|write]" commands.
795Z* The read subcommand takes one argument, the register,
796Z* whereas the write command takes two, the register and
797Z* the new value.
798 *
799D* Design: wd@denx.de
800C* Coding: wd@denx.de
801V* Verification: dzu@denx.de
802 ***********************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200803int do_pic (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenke2211742002-11-02 23:30:20 +0000804{
805 uchar reg, val;
806
807 switch (argc) {
808 case 3: /* PIC read reg */
809 if (strcmp (argv[1], "read") != 0)
810 break;
811
812 reg = simple_strtoul (argv[2], NULL, 16);
813
814 printf ("PIC read: reg %02x: %02x\n\n", reg, pic_read (reg));
815
816 return 0;
817 case 4: /* PIC write reg val */
818 if (strcmp (argv[1], "write") != 0)
819 break;
820
821 reg = simple_strtoul (argv[2], NULL, 16);
822 val = simple_strtoul (argv[3], NULL, 16);
823
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));
828 return 0;
829 default:
830 break;
831 }
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200832 return cmd_usage(cmdtp);
wdenke2211742002-11-02 23:30:20 +0000833}
wdenk0d498392003-07-01 21:06:45 +0000834U_BOOT_CMD(
835 pic, 4, 1, do_pic,
Peter Tyser2fb26042009-01-27 18:03:12 -0600836 "read and write PIC registers",
wdenk8bde7f72003-06-27 21:31:46 +0000837 "read reg - read PIC register `reg'\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200838 "pic write reg val - write value `val' to PIC register `reg'"
wdenk8bde7f72003-06-27 21:31:46 +0000839);
wdenke2211742002-11-02 23:30:20 +0000840
841/***********************************************************************
842F* Function: int do_kbd (cmd_tbl_t *cmdtp, int flag,
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200843F* int argc, char * const argv[]) P*A*Z*
wdenke2211742002-11-02 23:30:20 +0000844 *
845P* Parameters: cmd_tbl_t *cmdtp
846P* - Pointer to our command table entry
847P* int flag
848P* - If the CMD_FLAG_REPEAT bit is set, then this call is
849P* a repetition
850P* int argc
851P* - Argument count
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200852P* char * const argv[]
wdenke2211742002-11-02 23:30:20 +0000853P* - Array of the actual arguments
854P*
855P* Returnvalue: int
856P* - 0 is always returned.
857 *
858Z* Intention: Implement the "kbd" command.
859Z* The keyboard status is read. The result is printed on
860Z* the console and written into the "keybd" environment
861Z* variable.
862 *
863D* Design: wd@denx.de
864C* Coding: wd@denx.de
865V* Verification: dzu@denx.de
866 ***********************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200867int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenke2211742002-11-02 23:30:20 +0000868{
869 uchar kbd_data[KEYBD_DATALEN];
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200870 char keybd_env[2 * KEYBD_DATALEN + 1];
wdenke2211742002-11-02 23:30:20 +0000871 uchar val;
872 int i;
873
wdenk4532cb62003-04-27 22:52:51 +0000874#if 0 /* Done in kbd_init */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200875 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenk4532cb62003-04-27 22:52:51 +0000876#endif
wdenke2211742002-11-02 23:30:20 +0000877
878 /* Read keys */
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);
882
883 puts ("Keys:");
884 for (i = 0; i < KEYBD_DATALEN; ++i) {
885 sprintf (keybd_env + i + i, "%02X", kbd_data[i]);
886 printf (" %02x", kbd_data[i]);
887 }
888 putc ('\n');
889 setenv ("keybd", keybd_env);
890 return 0;
891}
892
wdenk0d498392003-07-01 21:06:45 +0000893U_BOOT_CMD(
894 kbd, 1, 1, do_kbd,
Peter Tyser2fb26042009-01-27 18:03:12 -0600895 "read keyboard status",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200896 ""
wdenk8bde7f72003-06-27 21:31:46 +0000897);
898
wdenke2211742002-11-02 23:30:20 +0000899/* Read and set LSB switch */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200900#define CONFIG_SYS_PC_TXD1_ENA 0x0008 /* PC.12 */
wdenke2211742002-11-02 23:30:20 +0000901
902/***********************************************************************
903F* Function: int do_lsb (cmd_tbl_t *cmdtp, int flag,
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200904F* int argc, char * const argv[]) P*A*Z*
wdenke2211742002-11-02 23:30:20 +0000905 *
906P* Parameters: cmd_tbl_t *cmdtp
907P* - Pointer to our command table entry
908P* int flag
909P* - If the CMD_FLAG_REPEAT bit is set, then this call is
910P* a repetition
911P* int argc
912P* - Argument count
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200913P* char * const argv[]
wdenke2211742002-11-02 23:30:20 +0000914P* - Array of the actual arguments
915P*
916P* Returnvalue: int
917P* - 0 The command was handled successfully
918P* 1 An error occurred
919 *
920Z* Intention: Implement the "lsb [on|off]" commands.
921Z* The lsb is switched according to the first parameter by
922Z* by signaling the PIC I/O expander.
923Z* Called with no arguments, the current setting is
924Z* printed.
925 *
926D* Design: wd@denx.de
927C* Coding: wd@denx.de
928V* Verification: dzu@denx.de
929 ***********************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200930int do_lsb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenke2211742002-11-02 23:30:20 +0000931{
932 uchar val;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200933 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenke2211742002-11-02 23:30:20 +0000934
935 switch (argc) {
936 case 1: /* lsb - print setting */
937 val = pic_read (0x60);
938 printf ("LSB is o%s\n", (val & 0x20) ? "n" : "ff");
939 return 0;
940 case 2: /* lsb on or lsb off - set switch */
941 val = pic_read (0x60);
942
943 if (strcmp (argv[1], "on") == 0) {
944 val |= 0x20;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200945 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;
wdenke2211742002-11-02 23:30:20 +0000948 } else if (strcmp (argv[1], "off") == 0) {
949 val &= ~0x20;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200950 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;
wdenke2211742002-11-02 23:30:20 +0000953 } else {
954 break;
955 }
956 pic_write (0x60, val);
957 return 0;
958 default:
959 break;
960 }
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200961 return cmd_usage(cmdtp);
wdenke2211742002-11-02 23:30:20 +0000962}
963
wdenk0d498392003-07-01 21:06:45 +0000964U_BOOT_CMD(
965 lsb, 2, 1, do_lsb,
Peter Tyser2fb26042009-01-27 18:03:12 -0600966 "check and set LSB switch",
wdenk8bde7f72003-06-27 21:31:46 +0000967 "on - switch LSB on\n"
968 "lsb off - switch LSB off\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200969 "lsb - print current setting"
wdenk8bde7f72003-06-27 21:31:46 +0000970);
971
Jon Loeligerd39b5742007-07-10 10:48:22 -0500972#endif
wdenke2211742002-11-02 23:30:20 +0000973
974/*----------------------------- Utilities -----------------------------*/
975/***********************************************************************
976F* Function: uchar pic_read (uchar reg) P*A*Z*
977 *
978P* Parameters: uchar reg
979P* - Register to read
980P*
981P* Returnvalue: uchar
982P* - Value read from register
983 *
984Z* Intention: Read a register from the PIC I/O expander.
985 *
986D* Design: wd@denx.de
987C* Coding: wd@denx.de
988V* Verification: dzu@denx.de
989 ***********************************************************************/
990uchar pic_read (uchar reg)
991{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200992 return (i2c_reg_read (CONFIG_SYS_I2C_PICIO_ADDR, reg));
wdenke2211742002-11-02 23:30:20 +0000993}
994
995/***********************************************************************
996F* Function: void pic_write (uchar reg, uchar val) P*A*Z*
997 *
998P* Parameters: uchar reg
999P* - Register to read
1000P* uchar val
1001P* - Value to write
1002P*
1003P* Returnvalue: none
1004 *
1005Z* Intention: Write to a register on the PIC I/O expander.
1006 *
1007D* Design: wd@denx.de
1008C* Coding: wd@denx.de
1009V* Verification: dzu@denx.de
1010 ***********************************************************************/
1011void pic_write (uchar reg, uchar val)
1012{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001013 i2c_reg_write (CONFIG_SYS_I2C_PICIO_ADDR, reg, val);
wdenke2211742002-11-02 23:30:20 +00001014}
1015
1016/*---------------------- Board Control Functions ----------------------*/
1017/***********************************************************************
1018F* Function: void board_poweroff (void) P*A*Z*
1019 *
1020P* Parameters: none
1021P*
1022P* Returnvalue: none
1023 *
1024Z* Intention: Turn off the battery power and loop endless, so this
1025Z* should better be the last function you call...
1026 *
1027D* Design: wd@denx.de
1028C* Coding: wd@denx.de
1029V* Verification: dzu@denx.de
1030 ***********************************************************************/
1031void board_poweroff (void)
1032{
1033 /* Turn battery off */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001034 ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat &= ~(1 << (31 - 13));
wdenke2211742002-11-02 23:30:20 +00001035
1036 while (1);
1037}
wdenk4532cb62003-04-27 22:52:51 +00001038
1039#ifdef CONFIG_MODEM_SUPPORT
1040static int key_pressed(void)
1041{
1042 uchar kbd_data[KEYBD_DATALEN];
1043 uchar val;
1044
1045 /* Read keys */
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);
1049
Wolfgang Denk77ddac92005-10-13 16:45:02 +02001050 return (compare_magic(kbd_data, (uchar *)CONFIG_MODEM_KEY_MAGIC) == 0);
wdenk4532cb62003-04-27 22:52:51 +00001051}
1052#endif /* CONFIG_MODEM_SUPPORT */
wdenk8564acf2003-07-14 22:13:32 +00001053
1054#ifdef CONFIG_POST
wdenk945af8d2003-07-16 21:53:01 +00001055/*
wdenk8564acf2003-07-14 22:13:32 +00001056 * Returns 1 if keys pressed to start the power-on long-running tests
1057 * Called from board_init_f().
1058 */
wdenk27b207f2003-07-24 23:38:38 +00001059int post_hotkeys_pressed(void)
wdenk8564acf2003-07-14 22:13:32 +00001060{
1061 uchar kbd_data[KEYBD_DATALEN];
1062 uchar val;
1063
1064 /* Read keys */
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);
1068
Wolfgang Denk77ddac92005-10-13 16:45:02 +02001069 return (compare_magic(kbd_data, (uchar *)CONFIG_POST_KEY_MAGIC) == 0);
wdenk8564acf2003-07-14 22:13:32 +00001070}
1071#endif