?? lwmon.c
字號:
int board_early_init_f (void){ volatile immap_t *immr = (immap_t *) CFG_IMMR; /* Disable Ethernet TENA on Port B * Necessary because of pull up in COM3 port. * * This is just a preliminary fix, intended to turn off TENA * as soon as possible to avoid noise on the network. Once * I睠 is running we will make sure the interface is * correctly initialized. */ immr->im_cpm.cp_pbpar &= ~PB_ENET_TENA; immr->im_cpm.cp_pbodr &= ~PB_ENET_TENA; immr->im_cpm.cp_pbdat &= ~PB_ENET_TENA; /* set to 0 = disabled */ immr->im_cpm.cp_pbdir |= PB_ENET_TENA; return (0);}/* ------------------------------------------------------------------------- *//***********************************************************************F* Function: void reset_phy (void) P*A*Z* *P* Parameters: noneP*P* Returnvalue: none *Z* Intention: Reset the PHY. In the lwmon case we do this by theZ* signaling the PIC I/O expander. *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/void reset_phy (void){ uchar c;#ifdef DEBUG printf ("### Switch on Ethernet for SCC2 ###\n");#endif c = pic_read (0x61);#ifdef DEBUG printf ("Old PIC read: reg_61 = 0x%02x\n", c);#endif c |= 0x40; /* disable COM3 */ c &= ~0x80; /* enable Ethernet */ pic_write (0x61, c);#ifdef DEBUG c = pic_read (0x61); printf ("New PIC read: reg_61 = 0x%02x\n", c);#endif udelay (1000);}/*------------------------- Keyboard controller -----------------------*//* command codes */#define KEYBD_CMD_READ_KEYS 0x01#define KEYBD_CMD_READ_VERSION 0x02#define KEYBD_CMD_READ_STATUS 0x03#define KEYBD_CMD_RESET_ERRORS 0x10/* status codes */#define KEYBD_STATUS_MASK 0x3F#define KEYBD_STATUS_H_RESET 0x20#define KEYBD_STATUS_BROWNOUT 0x10#define KEYBD_STATUS_WD_RESET 0x08#define KEYBD_STATUS_OVERLOAD 0x04#define KEYBD_STATUS_ILLEGAL_WR 0x02#define KEYBD_STATUS_ILLEGAL_RD 0x01/* Number of bytes returned from Keyboard Controller */#define KEYBD_VERSIONLEN 2 /* version information */#define KEYBD_DATALEN 9 /* normal key scan data *//* maximum number of "magic" key codes that can be assigned */static uchar kbd_addr = CFG_I2C_KEYBD_ADDR;static uchar *key_match (uchar *);#define KEYBD_SET_DEBUGMODE '#' /* Magic key to enable debug output *//***********************************************************************F* Function: int board_postclk_init (void) P*A*Z* *P* Parameters: noneP*P* Returnvalue: intP* - 0 is always returned. *Z* Intention: This function is the board_postclk_init() method implementationZ* for the lwmon board. * ***********************************************************************/int board_postclk_init (void){ DECLARE_GLOBAL_DATA_PTR; kbd_init();#ifdef CONFIG_MODEM_SUPPORT if (key_pressed()) { disable_putc(); /* modem doesn't understand banner etc */ gd->do_mdm_init = 1; }#endif return (0);}struct serial_device * default_serial_console (void){ DECLARE_GLOBAL_DATA_PTR; return gd->do_mdm_init ? &serial_scc_device : &serial_smc_device;}static void kbd_init (void){ DECLARE_GLOBAL_DATA_PTR; uchar kbd_data[KEYBD_DATALEN]; uchar tmp_data[KEYBD_DATALEN]; uchar val, errcd; int i; i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); gd->kbd_status = 0; /* Forced by PIC. Delays <= 175us loose */ udelay(1000); /* Read initial keyboard error code */ val = KEYBD_CMD_READ_STATUS; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, &errcd, 1); /* clear unused bits */ errcd &= KEYBD_STATUS_MASK; /* clear "irrelevant" bits. Recommended by Martin Rajek, LWN */ errcd &= ~(KEYBD_STATUS_H_RESET|KEYBD_STATUS_BROWNOUT); if (errcd) { gd->kbd_status |= errcd << 8; } /* Reset error code and verify */ val = KEYBD_CMD_RESET_ERRORS; i2c_write (kbd_addr, 0, 0, &val, 1); udelay(1000); /* delay NEEDED by keyboard PIC !!! */ val = KEYBD_CMD_READ_STATUS; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, &val, 1); val &= KEYBD_STATUS_MASK; /* clear unused bits */ if (val) { /* permanent error, report it */ gd->kbd_status |= val; return; } /* * Read current keyboard state. * * After the error reset it may take some time before the * keyboard PIC picks up a valid keyboard scan - the total * scan time is approx. 1.6 ms (information by Martin Rajek, * 28 Sep 2002). We read a couple of times for the keyboard * to stabilize, using a big enough delay. * 10 times should be enough. If the data is still changing, * we use what we get :-( */ memset (tmp_data, 0xFF, KEYBD_DATALEN); /* impossible value */ for (i=0; i<10; ++i) { val = KEYBD_CMD_READ_KEYS; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); if (memcmp(kbd_data, tmp_data, KEYBD_DATALEN) == 0) { /* consistent state, done */ break; } /* remeber last state, delay, and retry */ memcpy (tmp_data, kbd_data, KEYBD_DATALEN); udelay (5000); }}/***********************************************************************F* Function: int misc_init_r (void) P*A*Z* *P* Parameters: noneP*P* Returnvalue: intP* - 0 is always returned, even in the case of a keyboardP* error. *Z* Intention: This function is the misc_init_r() method implementationZ* for the lwmon board.Z* The keyboard controller is initialized and the resultZ* of a read copied to the environment variable "keybd".Z* If KEYBD_SET_DEBUGMODE is defined, a check is made forZ* this key, and if found display to the LCD will be enabled.Z* The keys in "keybd" are checked against the magicZ* keycommands defined in the environment.Z* See also key_match(). *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/int misc_init_r (void){ DECLARE_GLOBAL_DATA_PTR; uchar kbd_data[KEYBD_DATALEN]; uchar keybd_env[2 * KEYBD_DATALEN + 1]; uchar kbd_init_status = gd->kbd_status >> 8; uchar kbd_status = gd->kbd_status; uchar val; uchar *str; int i; if (kbd_init_status) { printf ("KEYBD: Error %02X\n", kbd_init_status); } if (kbd_status) { /* permanent error, report it */ printf ("*** Keyboard error code %02X ***\n", kbd_status); sprintf (keybd_env, "%02X", kbd_status); setenv ("keybd", keybd_env); return 0; } /* * Now we know that we have a working keyboard, so disable * all output to the LCD except when a key press is detected. */ if ((console_assign (stdout, "serial") < 0) || (console_assign (stderr, "serial") < 0)) { printf ("Can't assign serial port as output device\n"); } /* Read Version */ val = KEYBD_CMD_READ_VERSION; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_VERSIONLEN); printf ("KEYBD: Version %d.%d\n", kbd_data[0], kbd_data[1]); /* Read current keyboard state */ val = KEYBD_CMD_READ_KEYS; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); for (i = 0; i < KEYBD_DATALEN; ++i) { sprintf (keybd_env + i + i, "%02X", kbd_data[i]); } setenv ("keybd", keybd_env); str = strdup (key_match (kbd_data)); /* decode keys */#ifdef KEYBD_SET_DEBUGMODE if (kbd_data[0] == KEYBD_SET_DEBUGMODE) { /* set debug mode */ if ((console_assign (stdout, "lcd") < 0) || (console_assign (stderr, "lcd") < 0)) { printf ("Can't assign LCD display as output device\n"); } }#endif /* KEYBD_SET_DEBUGMODE */#ifdef CONFIG_PREBOOT /* automatically configure "preboot" command on key match */ setenv ("preboot", str); /* set or delete definition */#endif /* CONFIG_PREBOOT */ if (str != NULL) { free (str); } return (0);}#ifdef CONFIG_PREBOOTstatic uchar kbd_magic_prefix[] = "key_magic";static uchar kbd_command_prefix[] = "key_cmd";static int compare_magic (uchar *kbd_data, uchar *str){ uchar compare[KEYBD_DATALEN-1]; char *nxt; int i; /* Don't include modifier byte */ memcpy (compare, kbd_data+1, KEYBD_DATALEN-1); for (; str != NULL; str = (*nxt) ? nxt+1 : nxt) { uchar c; int k; c = (uchar) simple_strtoul (str, (char **) (&nxt), 16); if (str == (uchar *)nxt) { /* invalid character */ break; } /* * Check if this key matches the input. * Set matches to zero, so they match only once * and we can find duplicates or extra keys */ for (k = 0; k < sizeof(compare); ++k) { if (compare[k] == '\0') /* only non-zero entries */ continue; if (c == compare[k]) { /* found matching key */ compare[k] = '\0'; break; } } if (k == sizeof(compare)) { return -1; /* unmatched key */ } } /* * A full match leaves no keys in the `compare' array, */ for (i = 0; i < sizeof(compare); ++i) { if (compare[i]) { return -1; } } return 0;}/***********************************************************************F* Function: static uchar *key_match (uchar *kbd_data) P*A*Z* *P* Parameters: uchar *kbd_dataP* - The keys to match against our magic definitionsP*P* Returnvalue: uchar *P* - != NULL: Pointer to the corresponding command(s)P* NULL: No magic is about to happen *Z* Intention: Check if pressed key(s) match magic sequence,Z* and return the command string associated with that key(s).Z*Z* If no key press was decoded, NULL is returned.Z*Z* Note: the first character of the argument will beZ* overwritten with the "magic charcter code" of theZ* decoded key(s), or '\0'.Z*Z* Note: the string points to static environment dataZ* and must be saved before you call any function thatZ* modifies the environment.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -