@ -39,8 +39,6 @@
# if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
# if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
# include <i2c.h>
# include <i2c.h>
extern int i2c_soft_read_pin ( void ) ;
int ivm_calc_crc ( unsigned char * buf , int len )
int ivm_calc_crc ( unsigned char * buf , int len )
{
{
const unsigned short crc_tab [ 16 ] = {
const unsigned short crc_tab [ 16 ] = {
@ -92,7 +90,7 @@ static int ivm_get_value (unsigned char *buf, int len, char *name, int off,
if ( ( buf [ off + 0 ] ! = buf [ off + 2 ] ) & &
if ( ( buf [ off + 0 ] ! = buf [ off + 2 ] ) & &
( buf [ off + 2 ] ! = buf [ off + 4 ] ) ) {
( buf [ off + 2 ] ! = buf [ off + 4 ] ) ) {
printf ( " %s Error corrupted %s \n " , __FUNCTION __ , name ) ;
printf ( " %s Error corrupted %s \n " , __func __ , name ) ;
val = - 1 ;
val = - 1 ;
} else {
} else {
val = buf [ off + 0 ] + ( buf [ off + 1 ] < < 8 ) ;
val = buf [ off + 0 ] + ( buf [ off + 1 ] < < 8 ) ;
@ -104,9 +102,9 @@ static int ivm_get_value (unsigned char *buf, int len, char *name, int off,
return val ;
return val ;
}
}
# define INVENTORYBLOCKSIZE 0x100
# define INV_BLOCKSIZE 0x100
# define INVENTORYDATAADDRESS 0x21
# define INV_DATAADDRESS 0x21
# define INVENTORYDATASIZE (INVENTORYBLOCKSIZE - INVENTORY DATAADDRESS - 3)
# define INVENTORYDATASIZE (INV_BLOCKSIZE - INV_ DATAADDRESS - 3)
# define IVM_POS_SHORT_TEXT 0
# define IVM_POS_SHORT_TEXT 0
# define IVM_POS_MANU_ID 1
# define IVM_POS_MANU_ID 1
@ -133,7 +131,7 @@ static int ivm_findinventorystring (int type,
{
{
int xcode = 0 ;
int xcode = 0 ;
unsigned long cr = 0 ;
unsigned long cr = 0 ;
unsigned long addr = INVENTORY DATAADDRESS ;
unsigned long addr = INV_ DATAADDRESS ;
unsigned long size = 0 ;
unsigned long size = 0 ;
unsigned long nr = type ;
unsigned long nr = type ;
int stop = 0 ; /* stop on semicolon */
int stop = 0 ; /* stop on semicolon */
@ -157,8 +155,10 @@ static int ivm_findinventorystring (int type,
addr + + ;
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 ) {
if ( addr < INVENTORYDATASIZE ) {
/* Copy the IVM string in the corresponding string */
/* Copy the IVM string in the corresponding string */
for ( ; ( buf [ addr ] ! = ' \r ' ) & &
for ( ; ( buf [ addr ] ! = ' \r ' ) & &
@ -170,9 +170,11 @@ static int ivm_findinventorystring (int type,
convert_char ( buf [ addr ] ) ) ;
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 inventory data is most probably corrupted : tell
* the world there is a problem ! */
* the world there is a problem !
*/
if ( addr = = INVENTORYDATASIZE ) {
if ( addr = = INVENTORYDATASIZE ) {
xcode = - 1 ;
xcode = - 1 ;
printf ( " Error end of string not found \n " ) ;
printf ( " Error end of string not found \n " ) ;
@ -182,8 +184,10 @@ static int ivm_findinventorystring (int type,
printf ( " string too long till next CR \n " ) ;
printf ( " string too long till next CR \n " ) ;
}
}
} else {
} 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 ;
xcode = - 1 ;
printf ( " not enough cr found \n " ) ;
printf ( " not enough cr found \n " ) ;
}
}
@ -218,13 +222,7 @@ static int ivm_analyze_block2 (unsigned char *buf, int len)
unsigned long count ;
unsigned long count ;
/* IVM_MacAddress */
/* IVM_MacAddress */
sprintf ( ( char * ) valbuf , " %02X:%02X:%02X:%02X:%02X:%02X " ,
sprintf ( ( char * ) valbuf , " %pM " , buf ) ;
buf [ 1 ] ,
buf [ 2 ] ,
buf [ 3 ] ,
buf [ 4 ] ,
buf [ 5 ] ,
buf [ 6 ] ) ;
ivm_set_value ( " IVM_MacAddress " , ( char * ) valbuf ) ;
ivm_set_value ( " IVM_MacAddress " , ( char * ) valbuf ) ;
if ( getenv ( " ethaddr " ) = = NULL )
if ( getenv ( " ethaddr " ) = = NULL )
setenv ( ( char * ) " ethaddr " , ( char * ) valbuf ) ;
setenv ( ( char * ) " ethaddr " , ( char * ) valbuf ) ;
@ -249,15 +247,18 @@ int ivm_analyze_eeprom (unsigned char *buf, int len)
if ( ivm_check_crc ( buf , 0 ) ! = 0 )
if ( ivm_check_crc ( buf , 0 ) ! = 0 )
return - 1 ;
return - 1 ;
ivm_get_value ( buf , CONFIG_SYS_IVM_EEPROM_PAGE_LEN , " IVM_BoardId " , 0 , 1 ) ;
ivm_get_value ( buf , CONFIG_SYS_IVM_EEPROM_PAGE_LEN ,
val = ivm_get_value ( buf , CONFIG_SYS_IVM_EEPROM_PAGE_LEN , " IVM_HWKey " , 6 , 1 ) ;
" IVM_BoardId " , 0 , 1 ) ;
val = ivm_get_value ( buf , CONFIG_SYS_IVM_EEPROM_PAGE_LEN ,
" IVM_HWKey " , 6 , 1 ) ;
if ( val ! = 0xffff ) {
if ( val ! = 0xffff ) {
sprintf ( ( char * ) valbuf , " %x " , ( ( val / 100 ) % 10 ) ) ;
sprintf ( ( char * ) valbuf , " %x " , ( ( val / 100 ) % 10 ) ) ;
ivm_set_value ( " IVM_HWVariant " , ( char * ) valbuf ) ;
ivm_set_value ( " IVM_HWVariant " , ( char * ) valbuf ) ;
sprintf ( ( char * ) valbuf , " %x " , ( val % 100 ) ) ;
sprintf ( ( char * ) valbuf , " %x " , ( val % 100 ) ) ;
ivm_set_value ( " IVM_HWVersion " , ( char * ) valbuf ) ;
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_Symbol " , IVM_POS_SYMBOL_ONLY , 8 )
GET_STRING ( " IVM_DeviceName " , IVM_POS_SHORT_TEXT , 64 )
GET_STRING ( " IVM_DeviceName " , IVM_POS_SHORT_TEXT , 64 )
@ -268,7 +269,8 @@ int ivm_analyze_eeprom (unsigned char *buf, int len)
while ( i < len ) {
while ( i < len ) {
if ( tmp [ i ] = = ' ; ' ) {
if ( tmp [ i ] = = ' ; ' ) {
ivm_set_value ( " IVM_ShortText " , ( char * ) & tmp [ i + 1 ] ) ;
ivm_set_value ( " IVM_ShortText " ,
( char * ) & tmp [ i + 1 ] ) ;
break ;
break ;
}
}
i + + ;
i + + ;
@ -290,7 +292,8 @@ int ivm_analyze_eeprom (unsigned char *buf, int len)
if ( ivm_check_crc ( & buf [ CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2 ] , 2 ) ! = 0 )
if ( ivm_check_crc ( & buf [ CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2 ] , 2 ) ! = 0 )
return 0 ;
return 0 ;
ivm_analyze_block2 ( & buf [ CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2 ] , CONFIG_SYS_IVM_EEPROM_PAGE_LEN ) ;
ivm_analyze_block2 ( & buf [ CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2 ] ,
CONFIG_SYS_IVM_EEPROM_PAGE_LEN ) ;
return 0 ;
return 0 ;
}
}
@ -303,6 +306,7 @@ int ivm_read_eeprom (void)
uchar i2c_buffer [ CONFIG_SYS_IVM_EEPROM_MAX_LEN ] ;
uchar i2c_buffer [ CONFIG_SYS_IVM_EEPROM_MAX_LEN ] ;
uchar * buf ;
uchar * buf ;
unsigned dev_addr = CONFIG_SYS_IVM_EEPROM_ADR ;
unsigned dev_addr = CONFIG_SYS_IVM_EEPROM_ADR ;
int ret ;
# if defined(CONFIG_I2C_MUX)
# if defined(CONFIG_I2C_MUX)
/* First init the Bus, select the Bus */
/* First init the Bus, select the Bus */
@ -324,7 +328,9 @@ int ivm_read_eeprom (void)
if ( buf ! = NULL )
if ( buf ! = NULL )
dev_addr = simple_strtoul ( ( char * ) buf , NULL , 16 ) ;
dev_addr = simple_strtoul ( ( char * ) buf , NULL , 16 ) ;
if ( i2c_read ( dev_addr , 0 , 1 , 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 " ) ;
printf ( " Error reading EEprom \n " ) ;
return - 2 ;
return - 2 ;
}
}
@ -341,22 +347,22 @@ int ivm_read_eeprom (void)
# define SCL_MASK 0x00020000
# define SCL_MASK 0x00020000
static void set_pin ( int state , unsigned long mask )
static 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 )
if ( state )
iop - > pdat | = ( mask ) ;
setbits_be32 ( & iop - > pdat , mask ) ;
else
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 ) ;
clrbits_be32 ( & iop - > pdir , mask ) ;
return ( 0 ! = ( iop - > pdat & ( mask ) ) ) ;
return 0 ! = ( in_be32 ( & iop - > pdat ) & mask ) ;
}
}
static void set_sda ( int state )
static void set_sda ( int state )
@ -382,48 +388,20 @@ static int get_scl (void)
# if defined(CONFIG_HARD_I2C)
# 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 ) {
if ( gpio ) {
iop - > ppar & = ~ ( SDA_MASK | SCL_MASK ) ;
clrbits_be32 ( & iop - > ppar , ( SDA_MASK | SCL_MASK ) ) ;
iop - > podr & = ~ ( SDA_MASK | SCL_MASK ) ;
clrbits_be32 ( & iop - > podr , ( SDA_MASK | SCL_MASK ) ) ;
} else {
} else {
iop - > ppar | = ( SDA_MASK | SCL_MASK ) ;
setbits_be32 ( & iop - > ppar , ( SDA_MASK | SCL_MASK ) ) ;
iop - > pdir & = ~ ( SDA_MASK | SCL_MASK ) ;
clrbits_be32 ( & iop - > pdir , ( SDA_MASK | SCL_MASK ) ) ;
iop - > podr | = ( SDA_MASK | SCL_MASK ) ;
setbits_be32 ( & iop - > podr , ( SDA_MASK | SCL_MASK ) ) ;
}
}
}
}
# endif
# endif
# endif
# endif
# if defined(CONFIG_KM8XX)
static void set_sda ( int state )
{
I2C_SDA ( state ) ;
}
static void set_scl ( int state )
{
I2C_SCL ( state ) ;
}
static int get_sda ( void )
{
return I2C_READ ;
}
static int get_scl ( void )
{
int val ;
* ( unsigned short * ) ( I2C_BASE_DIR ) & = ~ SCL_CONF ;
udelay ( 1 ) ;
val = * ( unsigned char * ) ( I2C_BASE_PORT ) ;
return ( ( val & SCL_BIT ) = = SCL_BIT ) ;
}
# endif
# if !defined(CONFIG_KMETER1)
# if !defined(CONFIG_KMETER1)
static void writeStartSeq ( void )
static void writeStartSeq ( void )
{
{
@ -437,12 +415,13 @@ static void writeStartSeq (void)
udelay ( DELAY_HALF_PERIOD ) ;
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
* I2C is a synchronous protocol and resets of the processor in the middle
done . This function toggles the SCL until the SCL and SCA line are
* of an access can block the I2C Bus until a powerdown of the full unit is
released , but max . 16 times , after this a I2C start - sequence is sent .
* done . This function toggles the SCL until the SCL and SCA line are
This I2C Deblocking mechanism was developed by Keymile in association
* released , but max . 16 times , after this a I2C start - sequence is sent .
with Anatech and Atmel in 1998.
* This I2C Deblocking mechanism was developed by Keymile in association
* with Anatech and Atmel in 1998.
*/
*/
static int i2c_make_abort ( void )
static int i2c_make_abort ( void )
{
{
@ -467,17 +446,16 @@ static int i2c_make_abort (void)
}
}
}
}
}
}
if ( ret = = 0 ) {
if ( ret = = 0 )
for ( i = 0 ; i < 5 ; i + + ) {
for ( i = 0 ; i < 5 ; i + + )
writeStartSeq ( ) ;
writeStartSeq ( ) ;
}
}
get_sda ( ) ;
get_sda ( ) ;
return ret ;
return ret ;
}
}
# endif
# endif
/**
/*
* i2c_init_board - reset i2c bus . When the board is powercycled during a
* i2c_init_board - reset i2c bus . When the board is powercycled during a
* bus transfer it might hang ; for details see doc / I2C_Edge_Conditions .
* bus transfer it might hang ; for details see doc / I2C_Edge_Conditions .
*/
*/
@ -498,15 +476,16 @@ void i2c_init_board(void)
out_8 ( & dev - > cr , ( I2C_CR_MEN ) ) ;
out_8 ( & dev - > cr , ( I2C_CR_MEN ) ) ;
out_8 ( & dev - > cr , 0x00 ) ;
out_8 ( & dev - > cr , 0x00 ) ;
out_8 ( & dev - > cr , ( I2C_CR_MEN ) ) ;
out_8 ( & dev - > cr , ( I2C_CR_MEN ) ) ;
# else
# else
# if defined(CONFIG_HARD_I2C) && !defined(MACH_TYPE_KM_KIRKWOOD)
# if defined(CONFIG_HARD_I2C) && !defined(MACH_TYPE_KM_KIRKWOOD)
volatile immap_t * immap = ( immap_t * ) CONFIG_SYS_IMMR ;
immap_t * immap = ( immap_t * ) CONFIG_SYS_IMMR ;
volatile i2c8260_t * i2c = ( i2c8260_t * ) & immap - > im_i2c ;
i2c8260_t * i2c = ( i2c8260_t * ) & immap - > im_i2c ;
/* disable I2C controller first, otherwhise it thinks we want to */
/*
/* talk to the slave port... */
* disable I2C controller first , otherwhise it thinks we want to
i2c - > i2c_i2mod & = ~ 0x01 ;
* talk to the slave port . . .
*/
clrbits_8 ( & i2c - > i2c_i2mod , 0x01 ) ;
/* Set the PortPins to GPIO */
/* Set the PortPins to GPIO */
setports ( 1 ) ;
setports ( 1 ) ;
@ -548,6 +527,7 @@ int fdt_set_node_and_value (void *blob,
}
}
return ret ;
return ret ;
}
}
int fdt_get_node_and_value ( void * blob ,
int fdt_get_node_and_value ( void * blob ,
char * nodename ,
char * nodename ,
char * propname ,
char * propname ,
@ -561,7 +541,7 @@ int fdt_get_node_and_value (void *blob,
* var = ( void * ) fdt_getprop ( blob , nodeoffset , propname , & len ) ;
* var = ( void * ) fdt_getprop ( blob , nodeoffset , propname , & len ) ;
if ( len = = 0 ) {
if ( len = = 0 ) {
/* no value */
/* no value */
printf ( " %s no value \n " , __FUNCTION __ ) ;
printf ( " %s no value \n " , __func __ ) ;
return - 1 ;
return - 1 ;
} else if ( len > 0 ) {
} else if ( len > 0 ) {
return len ;
return len ;
@ -571,7 +551,7 @@ int fdt_get_node_and_value (void *blob,
return - 2 ;
return - 2 ;
}
}
} else {
} else {
printf ( " %s: cannot find %s node err:%s \n " , __FUNCTION __ ,
printf ( " %s: cannot find %s node err:%s \n " , __func __ ,
nodename , fdt_strerror ( nodeoffset ) ) ;
nodename , fdt_strerror ( nodeoffset ) ) ;
return - 3 ;
return - 3 ;
}
}
@ -581,7 +561,9 @@ int fdt_get_node_and_value (void *blob,
# if !defined(MACH_TYPE_KM_KIRKWOOD)
# if !defined(MACH_TYPE_KM_KIRKWOOD)
int ethernet_present ( void )
int ethernet_present ( void )
{
{
return ( in_8 ( ( u8 * ) CONFIG_SYS_PIGGY_BASE + CONFIG_SYS_SLOT_ID_OFF ) & 0x80 ) ;
struct km_bec_fpga * base = ( struct km_bec_fpga * ) CONFIG_SYS_PIGGY_BASE ;
return in_8 ( & base - > bprth ) & PIGGY_PRESENT ;
}
}
# endif
# endif
@ -590,8 +572,7 @@ int board_eth_init (bd_t *bis)
# ifdef CONFIG_KEYMILE_HDLC_ENET
# ifdef CONFIG_KEYMILE_HDLC_ENET
( void ) keymile_hdlc_enet_initialize ( bis ) ;
( void ) keymile_hdlc_enet_initialize ( bis ) ;
# endif
# endif
if ( ethernet_present ( ) ) {
if ( ethernet_present ( ) )
return - 1 ;
return - 1 ;
}
return 0 ;
return 0 ;
}
}