X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=board%2Fkeymile%2Fcommon%2Fcommon.c;h=9adfefaf6aac9c89cfec7e86429da150aabace33;hb=a9417ce74a8b79b1a3ab879d05f4f54138422c6e;hp=1338950814426e5dd2d5ca4350e996dbd3c0fa13;hpb=833d94bcdc89cf88928be21587240950afdc33c8;p=u-boot diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c index 1338950814..9adfefaf6a 100644 --- a/board/keymile/common/common.c +++ b/board/keymile/common/common.c @@ -22,25 +22,30 @@ */ #include -#if defined(CONFIG_MGCOGE) +#if defined(CONFIG_KM82XX) #include #endif #include +#include #include #include #include +#include #include #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) #include #endif +#include "../common/common.h" #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) #include -extern int i2c_soft_read_pin (void); +static void i2c_write_start_seq(void); +static int i2c_make_abort(void); +DECLARE_GLOBAL_DATA_PTR; -int ivm_calc_crc (unsigned char *buf, int len) +int ivm_calc_crc(unsigned char *buf, int len) { const unsigned short crc_tab[16] = { 0x0000, 0xCC01, 0xD801, 0x1400, @@ -70,20 +75,55 @@ int ivm_calc_crc (unsigned char *buf, int len) return crc; } -static int ivm_set_value (char *name, char *value) +/* + * Set Keymile specific environment variables + * Currently only some memory layout variables are calculated here + * ... ------------------------------------------------ + * ... |@rootfsaddr |@pnvramaddr |@varaddr |@reserved |@END_OF_RAM + * ... |<------------------- pram ------------------->| + * ... ------------------------------------------------ + * @END_OF_RAM: denotes the RAM size + * @pnvramaddr: Startadress of pseudo non volatile RAM in hex + * @pram : preserved ram size in k + * @varaddr : startadress for /var mounted into RAM + */ +int set_km_env(void) +{ + uchar buf[32]; + unsigned int pnvramaddr; + unsigned int pram; + unsigned int varaddr; + + pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM + - CONFIG_KM_PNVRAM; + sprintf((char *)buf, "0x%x", pnvramaddr); + setenv("pnvramaddr", (char *)buf); + + pram = (CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM + CONFIG_KM_PNVRAM) / + 0x400; + sprintf((char *)buf, "0x%x", pram); + setenv("pram", (char *)buf); + + varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM; + sprintf((char *)buf, "0x%x", varaddr); + setenv("varaddr", (char *)buf); + return 0; +} + +static int ivm_set_value(char *name, char *value) { char tempbuf[256]; if (value != NULL) { - sprintf (tempbuf, "%s=%s", name, value); - return set_local_var (tempbuf, 0); + sprintf(tempbuf, "%s=%s", name, value); + return set_local_var(tempbuf, 0); } else { - unset_local_var (name); + unset_local_var(name); } return 0; } -static int ivm_get_value (unsigned char *buf, int len, char *name, int off, +static int ivm_get_value(unsigned char *buf, int len, char *name, int off, int check) { unsigned short val; @@ -91,21 +131,21 @@ static int ivm_get_value (unsigned char *buf, int len, char *name, int off, if ((buf[off + 0] != buf[off + 2]) && (buf[off + 2] != buf[off + 4])) { - printf ("%s Error corrupted %s\n", __FUNCTION__, name); + printf("%s Error corrupted %s\n", __func__, name); val = -1; } else { val = buf[off + 0] + (buf[off + 1] << 8); if ((val == 0) && (check == 1)) val = -1; } - sprintf ((char *)valbuf, "%x", val); - ivm_set_value (name, (char *)valbuf); + sprintf((char *)valbuf, "%x", val); + ivm_set_value(name, (char *)valbuf); return val; } -#define INVENTORYBLOCKSIZE 0x100 -#define INVENTORYDATAADDRESS 0x21 -#define INVENTORYDATASIZE (INVENTORYBLOCKSIZE - INVENTORYDATAADDRESS - 3) +#define INV_BLOCKSIZE 0x100 +#define INV_DATAADDRESS 0x21 +#define INVENTORYDATASIZE (INV_BLOCKSIZE - INV_DATAADDRESS - 3) #define IVM_POS_SHORT_TEXT 0 #define IVM_POS_MANU_ID 1 @@ -120,19 +160,19 @@ static int ivm_get_value (unsigned char *buf, int len, char *name, int off, #define IVM_POS_HISTORY 10 #define IVM_POS_SYMBOL_ONLY 11 -static char convert_char (char c) +static char convert_char(char c) { return (c < ' ' || c > '~') ? '.' : c; } -static int ivm_findinventorystring (int type, +static int ivm_findinventorystring(int type, unsigned char* const string, unsigned long maxlen, unsigned char *buf) { int xcode = 0; unsigned long cr = 0; - unsigned long addr = INVENTORYDATAADDRESS; + unsigned long addr = INV_DATAADDRESS; unsigned long size = 0; unsigned long nr = type; int stop = 0; /* stop on semicolon */ @@ -156,8 +196,10 @@ static int ivm_findinventorystring (int type, addr++; } - /* the expected number of CR was found until the end of the IVM - * content --> fill string */ + /* + * the expected number of CR was found until the end of the IVM + * content --> fill string + */ if (addr < INVENTORYDATASIZE) { /* Copy the IVM string in the corresponding string */ for (; (buf[addr] != '\r') && @@ -169,63 +211,75 @@ static int ivm_findinventorystring (int type, convert_char (buf[addr])); } - /* copy phase is done: check if everything is ok. If not, + /* + * copy phase is done: check if everything is ok. If not, * the inventory data is most probably corrupted: tell - * the world there is a problem! */ + * the world there is a problem! + */ if (addr == INVENTORYDATASIZE) { xcode = -1; - printf ("Error end of string not found\n"); + printf("Error end of string not found\n"); } else if ((size >= (maxlen - 1)) && (buf[addr] != '\r')) { xcode = -1; - printf ("string too long till next CR\n"); + printf("string too long till next CR\n"); } } else { - /* some CR are missing... - * the inventory data is most probably corrupted */ + /* + * some CR are missing... + * the inventory data is most probably corrupted + */ xcode = -1; - printf ("not enough cr found\n"); + printf("not enough cr found\n"); } return xcode; } #define GET_STRING(name, which, len) \ - if (ivm_findinventorystring (which, valbuf, len, buf) == 0) { \ - ivm_set_value (name, (char *)valbuf); \ + if (ivm_findinventorystring(which, valbuf, len, buf) == 0) { \ + ivm_set_value(name, (char *)valbuf); \ } -static int ivm_check_crc (unsigned char *buf, int block) +static int ivm_check_crc(unsigned char *buf, int block) { unsigned long crc; unsigned long crceeprom; - crc = ivm_calc_crc (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2); + crc = ivm_calc_crc(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2); crceeprom = (buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 1] + \ buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2] * 256); if (crc != crceeprom) { - printf ("Error CRC Block: %d EEprom: calculated: %lx EEprom: %lx\n", - block, crc, crceeprom); + if (block == 0) + printf("Error CRC Block: %d EEprom: calculated: \ + %lx EEprom: %lx\n", block, crc, crceeprom); return -1; } return 0; } -static int ivm_analyze_block2 (unsigned char *buf, int len) +static int ivm_analyze_block2(unsigned char *buf, int len) { unsigned char valbuf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN]; unsigned long count; /* IVM_MacAddress */ - sprintf ((char *)valbuf, "%02X:%02X:%02X:%02X:%02X:%02X", - buf[1], - buf[2], - buf[3], - buf[4], - buf[5], - buf[6]); - ivm_set_value ("IVM_MacAddress", (char *)valbuf); - if (getenv ("ethaddr") == NULL) - setenv ((char *)"ethaddr", (char *)valbuf); + sprintf((char *)valbuf, "%pM", buf); + ivm_set_value("IVM_MacAddress", (char *)valbuf); + /* if an offset is defined, add it */ +#if defined(CONFIG_PIGGY_MAC_ADRESS_OFFSET) + if (CONFIG_PIGGY_MAC_ADRESS_OFFSET > 0) { + unsigned long val = (buf[4] << 16) + (buf[5] << 8) + buf[6]; + + val += CONFIG_PIGGY_MAC_ADRESS_OFFSET; + buf[4] = (val >> 16) & 0xff; + buf[5] = (val >> 8) & 0xff; + buf[6] = val & 0xff; + sprintf((char *)valbuf, "%pM", buf); + } +#endif + if (getenv("ethaddr") == NULL) + setenv((char *)"ethaddr", (char *)valbuf); + /* IVM_MacCount */ count = (buf[10] << 24) + (buf[11] << 16) + @@ -233,48 +287,52 @@ static int ivm_analyze_block2 (unsigned char *buf, int len) buf[13]; if (count == 0xffffffff) count = 1; - sprintf ((char *)valbuf, "%lx", count); - ivm_set_value ("IVM_MacCount", (char *)valbuf); + sprintf((char *)valbuf, "%lx", count); + ivm_set_value("IVM_MacCount", (char *)valbuf); return 0; } -int ivm_analyze_eeprom (unsigned char *buf, int len) +int ivm_analyze_eeprom(unsigned char *buf, int len) { unsigned short val; unsigned char valbuf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN]; unsigned char *tmp; - if (ivm_check_crc (buf, 0) != 0) + if (ivm_check_crc(buf, 0) != 0) return -1; - ivm_get_value (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, "IVM_BoardId", 0, 1); - val = ivm_get_value (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, "IVM_HWKey", 6, 1); + ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, + "IVM_BoardId", 0, 1); + val = ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, + "IVM_HWKey", 6, 1); if (val != 0xffff) { - sprintf ((char *)valbuf, "%x", ((val /100) % 10)); - ivm_set_value ("IVM_HWVariant", (char *)valbuf); - sprintf ((char *)valbuf, "%x", (val % 100)); - ivm_set_value ("IVM_HWVersion", (char *)valbuf); + sprintf((char *)valbuf, "%x", ((val / 100) % 10)); + ivm_set_value("IVM_HWVariant", (char *)valbuf); + sprintf((char *)valbuf, "%x", (val % 100)); + ivm_set_value("IVM_HWVersion", (char *)valbuf); } - ivm_get_value (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, "IVM_Functions", 12, 0); + ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, + "IVM_Functions", 12, 0); GET_STRING("IVM_Symbol", IVM_POS_SYMBOL_ONLY, 8) GET_STRING("IVM_DeviceName", IVM_POS_SHORT_TEXT, 64) tmp = (unsigned char *) getenv("IVM_DeviceName"); if (tmp) { - int len = strlen ((char *)tmp); + int len = strlen((char *)tmp); int i = 0; while (i < len) { if (tmp[i] == ';') { - ivm_set_value ("IVM_ShortText", (char *)&tmp[i + 1]); + ivm_set_value("IVM_ShortText", + (char *)&tmp[i + 1]); break; } i++; } if (i >= len) - ivm_set_value ("IVM_ShortText", NULL); + ivm_set_value("IVM_ShortText", NULL); } else { - ivm_set_value ("IVM_ShortText", NULL); + ivm_set_value("IVM_ShortText", NULL); } GET_STRING("IVM_ManufacturerID", IVM_POS_MANU_ID, 32) GET_STRING("IVM_ManufacturerSerialNumber", IVM_POS_MANU_SERIAL, 20) @@ -286,189 +344,260 @@ int ivm_analyze_eeprom (unsigned char *buf, int len) GET_STRING("IVM_CustomerID", IVM_POS_CUSTOMER_ID, 32) GET_STRING("IVM_CustomerProductID", IVM_POS_CUSTOMER_PROD_ID, 32) - if (ivm_check_crc (&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], 2) != 0) - return -2; - ivm_analyze_block2 (&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], CONFIG_SYS_IVM_EEPROM_PAGE_LEN); + if (ivm_check_crc(&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], 2) != 0) + return 0; + ivm_analyze_block2(&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], + CONFIG_SYS_IVM_EEPROM_PAGE_LEN); return 0; } -int ivm_read_eeprom (void) +int ivm_read_eeprom(void) { +#if defined(CONFIG_I2C_MUX) I2C_MUX_DEVICE *dev = NULL; +#endif uchar i2c_buffer[CONFIG_SYS_IVM_EEPROM_MAX_LEN]; uchar *buf; unsigned dev_addr = CONFIG_SYS_IVM_EEPROM_ADR; + int ret; +#if defined(CONFIG_I2C_MUX) /* First init the Bus, select the Bus */ #if defined(CONFIG_SYS_I2C_IVM_BUS) - dev = i2c_mux_ident_muxstring ((uchar *)CONFIG_SYS_I2C_IVM_BUS); + dev = i2c_mux_ident_muxstring((uchar *)CONFIG_SYS_I2C_IVM_BUS); #else - buf = (unsigned char *) getenv ("EEprom_ivm"); + buf = (unsigned char *) getenv("EEprom_ivm"); if (buf != NULL) - dev = i2c_mux_ident_muxstring (buf); + dev = i2c_mux_ident_muxstring(buf); #endif if (dev == NULL) { - printf ("Error couldnt add Bus for IVM\n"); + printf("Error couldnt add Bus for IVM\n"); return -1; } - i2c_set_bus_num (dev->busid); + i2c_set_bus_num(dev->busid); +#endif - buf = (unsigned char *) getenv ("EEprom_ivm_addr"); + buf = (unsigned char *) getenv("EEprom_ivm_addr"); if (buf != NULL) - dev_addr = simple_strtoul ((char *)buf, NULL, 16); + dev_addr = simple_strtoul((char *)buf, NULL, 16); + + /* add deblocking here */ + i2c_make_abort(); - if (eeprom_read (dev_addr, 0, i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN) != 0) { + ret = i2c_read(dev_addr, 0, 1, i2c_buffer, + CONFIG_SYS_IVM_EEPROM_MAX_LEN); + if (ret != 0) { printf ("Error reading EEprom\n"); return -2; } - return ivm_analyze_eeprom (i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN); + return ivm_analyze_eeprom(i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN); } #if defined(CONFIG_SYS_I2C_INIT_BOARD) -#define DELAY_ABORT_SEQ 62 +#define DELAY_ABORT_SEQ 62 /* @200kHz 9 clocks = 44us, 62us is ok */ #define DELAY_HALF_PERIOD (500 / (CONFIG_SYS_I2C_SPEED / 1000)) -#if defined(CONFIG_MGCOGE) +#if defined(CONFIG_KM_82XX) #define SDA_MASK 0x00010000 #define SCL_MASK 0x00020000 -static void set_pin (int state, unsigned long mask) +void set_pin(int state, unsigned long mask) { - volatile ioport_t *iop = ioport_addr ((immap_t *)CONFIG_SYS_IMMR, 3); + ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); if (state) - iop->pdat |= (mask); + setbits_be32(&iop->pdat, mask); else - iop->pdat &= ~(mask); + clrbits_be32(&iop->pdat, mask); - iop->pdir |= (mask); + setbits_be32(&iop->pdir, mask); } -static int get_pin (unsigned long mask) +static int get_pin(unsigned long mask) { - volatile ioport_t *iop = ioport_addr ((immap_t *)CONFIG_SYS_IMMR, 3); + ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); - iop->pdir &= ~(mask); - return (0 != (iop->pdat & (mask))); + clrbits_be32(&iop->pdir, mask); + return 0 != (in_be32(&iop->pdat) & mask); } -static void set_sda (int state) +static void set_sda(int state) { - set_pin (state, SDA_MASK); + set_pin(state, SDA_MASK); } -static void set_scl (int state) +static void set_scl(int state) { - set_pin (state, SCL_MASK); + set_pin(state, SCL_MASK); } -static int get_sda (void) +static int get_sda(void) { - return get_pin (SDA_MASK); + return get_pin(SDA_MASK); } -static int get_scl (void) +static int get_scl(void) { - return get_pin (SCL_MASK); + return get_pin(SCL_MASK); } #if defined(CONFIG_HARD_I2C) -static void setports (int gpio) +static void setports(int gpio) { - volatile ioport_t *iop = ioport_addr ((immap_t *)CONFIG_SYS_IMMR, 3); + ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); if (gpio) { - iop->ppar &= ~(SDA_MASK | SCL_MASK); - iop->podr &= ~(SDA_MASK | SCL_MASK); + clrbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK)); + clrbits_be32(&iop->podr, (SDA_MASK | SCL_MASK)); } else { - iop->ppar |= (SDA_MASK | SCL_MASK); - iop->pdir &= ~(SDA_MASK | SCL_MASK); - iop->podr |= (SDA_MASK | SCL_MASK); + setbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK)); + clrbits_be32(&iop->pdir, (SDA_MASK | SCL_MASK)); + setbits_be32(&iop->podr, (SDA_MASK | SCL_MASK)); } } #endif #endif -#if defined(CONFIG_MGSUVD) -static void set_sda (int state) -{ - I2C_SDA(state); -} - -static void set_scl (int state) +#if !defined(CONFIG_MPC83xx) +static void i2c_write_start_seq(void) { - I2C_SCL(state); + set_sda(1); + udelay(DELAY_HALF_PERIOD); + set_scl(1); + udelay(DELAY_HALF_PERIOD); + set_sda(0); + udelay(DELAY_HALF_PERIOD); + set_scl(0); + udelay(DELAY_HALF_PERIOD); } -static int get_sda (void) -{ - return I2C_READ; -} - -static int get_scl (void) +/* + * I2C is a synchronous protocol and resets of the processor in the middle + * of an access can block the I2C Bus until a powerdown of the full unit is + * done. This function toggles the SCL until the SCL and SCA line are + * released, but max. 16 times, after this a I2C start-sequence is sent. + * This I2C Deblocking mechanism was developed by Keymile in association + * with Anatech and Atmel in 1998. + */ +static int i2c_make_abort(void) { - int val; - *(unsigned short *)(I2C_BASE_DIR) &= ~SCL_CONF; - udelay (1); - val = *(unsigned char *)(I2C_BASE_PORT); +#if defined(CONFIG_HARD_I2C) && !defined(MACH_TYPE_KM_KIRKWOOD) + immap_t *immap = (immap_t *)CONFIG_SYS_IMMR ; + i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c; - return ((val & SCL_BIT) == SCL_BIT); -} + /* + * disable I2C controller first, otherwhise it thinks we want to + * talk to the slave port... + */ + clrbits_8(&i2c->i2c_i2mod, 0x01); + /* Set the PortPins to GPIO */ + setports(1); #endif -static void writeStartSeq (void) -{ - set_sda (1); - udelay (DELAY_HALF_PERIOD); - set_scl (1); - udelay (DELAY_HALF_PERIOD); - set_sda (0); - udelay (DELAY_HALF_PERIOD); - set_scl (0); - udelay (DELAY_HALF_PERIOD); -} - -/* I2C is a synchronous protocol and resets of the processor in the middle - of an access can block the I2C Bus until a powerdown of the full unit is - done. This function toggles the SCL until the SCL and SCA line are - released, but max. 16 times, after this a I2C start-sequence is sent. - This I2C Deblocking mechanism was developed by Keymile in association - with Anatech and Atmel in 1998. - */ -static int i2c_make_abort (void) -{ int scl_state = 0; int sda_state = 0; int i = 0; int ret = 0; - if (!get_sda ()) { + if (!get_sda()) { ret = -1; while (i < 16) { i++; - set_scl (0); - udelay (DELAY_ABORT_SEQ); - set_scl (1); - udelay (DELAY_ABORT_SEQ); - scl_state = get_scl (); - sda_state = get_sda (); + set_scl(0); + udelay(DELAY_ABORT_SEQ); + set_scl(1); + udelay(DELAY_ABORT_SEQ); + scl_state = get_scl(); + sda_state = get_sda(); if (scl_state && sda_state) { ret = 0; break; } } } - if (ret == 0) { - for (i =0; i < 5; i++) { - writeStartSeq (); - } + if (ret == 0) + for (i = 0; i < 5; i++) + i2c_write_start_seq(); + + /* respect stop setup time */ + udelay(DELAY_ABORT_SEQ); + set_scl(1); + udelay(DELAY_ABORT_SEQ); + set_sda(1); + get_sda(); + +#if defined(CONFIG_HARD_I2C) + /* Set the PortPins back to use for I2C */ + setports(0); +#endif + return ret; +} +#endif + +#if defined(CONFIG_MPC83xx) +static void i2c_write_start_seq(void) +{ + struct fsl_i2c *dev; + dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET); + udelay(DELAY_ABORT_SEQ); + out_8(&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA)); + udelay(DELAY_ABORT_SEQ); + out_8(&dev->cr, (I2C_CR_MEN)); +} + +static int i2c_make_abort(void) +{ + struct fsl_i2c *dev; + dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET); + uchar dummy; + uchar last; + int nbr_read = 0; + int i = 0; + int ret = 0; + + /* wait after each operation to finsh with a delay */ + out_8(&dev->cr, (I2C_CR_MSTA)); + udelay(DELAY_ABORT_SEQ); + out_8(&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA)); + udelay(DELAY_ABORT_SEQ); + dummy = in_8(&dev->dr); + udelay(DELAY_ABORT_SEQ); + last = in_8(&dev->dr); + nbr_read++; + + /* + * do read until the last bit is 1, but stop if the full eeprom is + * read. + */ + while (((last & 0x01) != 0x01) && + (nbr_read < CONFIG_SYS_IVM_EEPROM_MAX_LEN)) { + udelay(DELAY_ABORT_SEQ); + last = in_8(&dev->dr); + nbr_read++; } - get_sda (); + if ((last & 0x01) != 0x01) + ret = -2; + if ((last != 0xff) || (nbr_read > 1)) + printf("[INFO] i2c abort after %d bytes (0x%02x)\n", + nbr_read, last); + udelay(DELAY_ABORT_SEQ); + out_8(&dev->cr, (I2C_CR_MEN)); + udelay(DELAY_ABORT_SEQ); + /* clear status reg */ + out_8(&dev->sr, 0); + + for (i = 0; i < 5; i++) + i2c_write_start_seq(); + if (ret != 0) + printf("[ERROR] i2c abort failed after %d bytes (0x%02x)\n", + nbr_read, last); + return ret; } +#endif /** * i2c_init_board - reset i2c bus. When the board is powercycled during a @@ -476,31 +605,14 @@ static int i2c_make_abort (void) */ void i2c_init_board(void) { -#if defined(CONFIG_HARD_I2C) - volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR ; - volatile i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c; - - /* disable I2C controller first, otherwhise it thinks we want to */ - /* talk to the slave port... */ - i2c->i2c_i2mod &= ~0x01; - - /* Set the PortPins to GPIO */ - setports (1); -#endif - /* Now run the AbortSequence() */ - i2c_make_abort (); - -#if defined(CONFIG_HARD_I2C) - /* Set the PortPins back to use for I2C */ - setports (0); -#endif + i2c_make_abort(); } #endif #endif #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) -int fdt_set_node_and_value (void *blob, +int fdt_set_node_and_value(void *blob, char *nodename, char *regname, void *var, @@ -509,34 +621,98 @@ int fdt_set_node_and_value (void *blob, int ret = 0; int nodeoffset = 0; - nodeoffset = fdt_path_offset (blob, nodename); + nodeoffset = fdt_path_offset(blob, nodename); if (nodeoffset >= 0) { - ret = fdt_setprop (blob, nodeoffset, regname, var, + ret = fdt_setprop(blob, nodeoffset, regname, var, size); if (ret < 0) printf("ft_blob_update(): cannot set %s/%s " "property err:%s\n", nodename, regname, - fdt_strerror (ret)); + fdt_strerror(ret)); } else { printf("ft_blob_update(): cannot find %s node " - "err:%s\n", nodename, fdt_strerror (nodeoffset)); + "err:%s\n", nodename, fdt_strerror(nodeoffset)); } return ret; } -#endif -int ethernet_present (void) +int fdt_get_node_and_value(void *blob, + char *nodename, + char *propname, + void **var) { - return (in_8((u8 *)CONFIG_SYS_PIGGY_BASE + CONFIG_SYS_SLOT_ID_OFF) & 0x80); + int len; + int nodeoffset = 0; + + nodeoffset = fdt_path_offset(blob, nodename); + if (nodeoffset >= 0) { + *var = (void *)fdt_getprop(blob, nodeoffset, propname, &len); + if (len == 0) { + /* no value */ + printf("%s no value\n", __func__); + return -1; + } else if (len > 0) { + return len; + } else { + printf("libfdt fdt_getprop(): %s\n", + fdt_strerror(len)); + return -2; + } + } else { + printf("%s: cannot find %s node err:%s\n", __func__, + nodename, fdt_strerror(nodeoffset)); + return -3; + } } +#endif -int board_eth_init (bd_t *bis) +#if !defined(MACH_TYPE_KM_KIRKWOOD) +int ethernet_present(void) { -#ifdef CONFIG_KEYMILE_HDLC_ENET - (void)keymile_hdlc_enet_initialize (bis); + struct km_bec_fpga *base = + (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE; + + return in_8(&base->bprth) & PIGGY_PRESENT; +} #endif - if (ethernet_present ()) { - return -1; + +int board_eth_init(bd_t *bis) +{ + if (ethernet_present()) + return cpu_eth_init(bis); + + return -1; +} + +/* + * do_setboardid command + * read out the board id and the hw key from the intventory EEPROM and set + * this values as environment variables. + */ +static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + unsigned char buf[32]; + char *p; + + p = get_local_var("IVM_BoardId"); + if (p == NULL) { + printf("can't get the IVM_Boardid\n"); + return 1; } + sprintf((char *)buf, "%s", p); + setenv("boardid", (char *)buf); + + p = get_local_var("IVM_HWKey"); + if (p == NULL) { + printf("can't get the IVM_HWKey\n"); + return 1; + } + sprintf((char *)buf, "%s", p); + setenv("hwkey", (char *)buf); + return 0; } + +U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and " + "hwkey from IVM and set in environment");