@ -96,10 +96,10 @@ static int WaitForXfer(void)
S3C24X0_I2C * const i2c = S3C24X0_GetBase_I2C ( ) ;
int i , status ;
i = I2C_TIMEOUT * 1000 ;
i = I2C_TIMEOUT * 10 000 ;
status = i2c - > IICCON ;
while ( ( i > 0 ) & & ! ( status & I2CCON_IRPND ) ) {
udelay ( 10 00 ) ;
udelay ( 100 ) ;
status = i2c - > IICCON ;
i - - ;
}
@ -157,14 +157,18 @@ void i2c_init (int speed, int slaveadd)
# endif
/* toggle I2CSCL until bus idle */
SetI2CSCL ( 0 ) ; udelay ( 1000 ) ;
SetI2CSCL ( 0 ) ;
udelay ( 1000 ) ;
i = 10 ;
while ( ( i > 0 ) & & ( GetI2CSDA ( ) ! = 1 ) ) {
SetI2CSCL ( 1 ) ; udelay ( 1000 ) ;
SetI2CSCL ( 0 ) ; udelay ( 1000 ) ;
SetI2CSCL ( 1 ) ;
udelay ( 1000 ) ;
SetI2CSCL ( 0 ) ;
udelay ( 1000 ) ;
i - - ;
}
SetI2CSCL ( 1 ) ; udelay ( 1000 ) ;
SetI2CSCL ( 1 ) ;
udelay ( 1000 ) ;
/* restore pin functions */
# ifdef CONFIG_S3C2410
@ -186,7 +190,7 @@ void i2c_init (int speed, int slaveadd)
div + + ;
/* set prescaler, divisor according to freq, also set
ACKGEN , IRQ */
* ACKGEN , IRQ */
i2c - > IICCON = ( div & 0x0F ) | 0xA0 | ( ( pres = = 512 ) ? 0x40 : 0 ) ;
/* init to SLAVE REVEIVE and set slaveaddr */
@ -198,20 +202,18 @@ void i2c_init (int speed, int slaveadd)
}
/*
cmd_type is 0 for write 1 for read .
addr_len can take any value from 0 - 255 , it is only limited
by the char , we could make it larger if needed . If it is
0 we skip the address write cycle .
* cmd_type is 0 for write , 1 for read .
*
* addr_len can take any value from 0 - 255 , it is only limited
* by the char , we could make it larger if needed . If it is
* 0 we skip the address write cycle .
*/
static
int i2c_transfer ( unsigned char cmd_type ,
unsigned char chip ,
unsigned char addr [ ] ,
unsigned char addr_len ,
unsigned char data [ ] ,
unsigned short data_len )
unsigned char data [ ] , unsigned short data_len )
{
S3C24X0_I2C * const i2c = S3C24X0_GetBase_I2C ( ) ;
int i , status , result ;
@ -222,8 +224,6 @@ int i2c_transfer(unsigned char cmd_type,
return I2C_NOK ;
}
/*CheckDelay(); */
/* Check I2C bus idle */
i = I2C_TIMEOUT * 1000 ;
status = i2c - > IICSTAT ;
@ -233,14 +233,10 @@ int i2c_transfer(unsigned char cmd_type,
i - - ;
}
if ( status & I2CSTAT_BSY ) {
result = I2C_NOK_TOUT ;
return ( result ) ;
}
if ( status & I2CSTAT_BSY )
return I2C_NOK_TOUT ;
i2c - > IICCON | = 0x80 ;
result = I2C_OK ;
switch ( cmd_type ) {
@ -302,7 +298,8 @@ int i2c_transfer(unsigned char cmd_type,
i2c - > IICDS = chip ;
/* resend START */
i2c - > IICSTAT = I2C_MODE_MR | I2C_TXRX_ENA | I2C_START_STOP ;
i2c - > IICSTAT = I2C_MODE_MR | I2C_TXRX_ENA |
I2C_START_STOP ;
ReadWriteByte ( ) ;
result = WaitForXfer ( ) ;
i = 0 ;
@ -387,7 +384,6 @@ int i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
xaddr [ 3 ] = addr & 0xFF ;
}
# ifdef CFG_I2C_EEPROM_ADDR_OVERFLOW
/*
* EEPROM chips that implement " address overflow " are ones
@ -403,7 +399,9 @@ int i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
if ( alen > 0 )
chip | = ( ( addr > > ( alen * 8 ) ) & CFG_I2C_EEPROM_ADDR_OVERFLOW ) ;
# endif
if ( ( ret = i2c_transfer ( I2C_READ , chip < < 1 , & xaddr [ 4 - alen ] , alen , buffer , len ) ) ! = 0 ) {
if ( ( ret =
i2c_transfer ( I2C_READ , chip < < 1 , & xaddr [ 4 - alen ] , alen ,
buffer , len ) ) ! = 0 ) {
printf ( " I2c read: failed %d \n " , ret ) ;
return 1 ;
}
@ -425,7 +423,6 @@ int i2c_write (uchar chip, uint addr, int alen, uchar * buffer, int len)
xaddr [ 2 ] = ( addr > > 8 ) & 0xFF ;
xaddr [ 3 ] = addr & 0xFF ;
}
# ifdef CFG_I2C_EEPROM_ADDR_OVERFLOW
/*
* EEPROM chips that implement " address overflow " are ones
@ -441,9 +438,10 @@ int i2c_write (uchar chip, uint addr, int alen, uchar * buffer, int len)
if ( alen > 0 )
chip | = ( ( addr > > ( alen * 8 ) ) & CFG_I2C_EEPROM_ADDR_OVERFLOW ) ;
# endif
return ( i2c_transfer ( I2C_WRITE , chip < < 1 , & xaddr [ 4 - alen ] , alen , buffer , len ) ! = 0 ) ;
return ( i2c_transfer
( I2C_WRITE , chip < < 1 , & xaddr [ 4 - alen ] , alen , buffer ,
len ) ! = 0 ) ;
}
# endif /* CONFIG_HARD_I2C */
# endif /* CONFIG_DRIVER_S3C24X0_I2C */