mirror of
https://github.com/ipxe/ipxe
synced 2026-01-10 06:48:47 +03:00
[bitbash] Add optional open() and close() methods for bit-bashing interfaces
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -239,6 +239,7 @@ static int i2c_reset ( struct bit_basher *basher ) {
|
||||
* pull SDA low while SCL is high (which creates a start
|
||||
* condition).
|
||||
*/
|
||||
open_bit ( basher );
|
||||
setscl ( basher, 0 );
|
||||
setsda ( basher, 1 );
|
||||
for ( i = 0 ; i < I2C_RESET_MAX_CYCLES ; i++ ) {
|
||||
@@ -251,6 +252,7 @@ static int i2c_reset ( struct bit_basher *basher ) {
|
||||
i2c_stop ( basher );
|
||||
DBGC ( basher, "I2CBIT %p reset after %d attempts\n",
|
||||
basher, ( i + 1 ) );
|
||||
close_bit ( basher );
|
||||
return 0;
|
||||
}
|
||||
setscl ( basher, 0 );
|
||||
@@ -258,6 +260,7 @@ static int i2c_reset ( struct bit_basher *basher ) {
|
||||
|
||||
DBGC ( basher, "I2CBIT %p could not reset after %d attempts\n",
|
||||
basher, i );
|
||||
close_bit ( basher );
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
@@ -285,6 +288,8 @@ static int i2c_bit_read ( struct i2c_interface *i2c,
|
||||
DBGC ( basher, "I2CBIT %p reading from device %x: ",
|
||||
basher, i2cdev->dev_addr );
|
||||
|
||||
open_bit ( basher );
|
||||
|
||||
for ( ; ; data++, offset++ ) {
|
||||
|
||||
/* Select device for writing */
|
||||
@@ -312,6 +317,7 @@ static int i2c_bit_read ( struct i2c_interface *i2c,
|
||||
|
||||
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
|
||||
i2c_stop ( basher );
|
||||
close_bit ( basher );
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -339,6 +345,8 @@ static int i2c_bit_write ( struct i2c_interface *i2c,
|
||||
DBGC ( basher, "I2CBIT %p writing to device %x: ",
|
||||
basher, i2cdev->dev_addr );
|
||||
|
||||
open_bit ( basher );
|
||||
|
||||
for ( ; ; data++, offset++ ) {
|
||||
|
||||
/* Select device for writing */
|
||||
@@ -359,9 +367,10 @@ static int i2c_bit_write ( struct i2c_interface *i2c,
|
||||
if ( ( rc = i2c_send_byte ( basher, *data ) ) != 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
|
||||
i2c_stop ( basher );
|
||||
close_bit ( basher );
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user