mirror of https://github.com/ipxe/ipxe.git
[bitbash] Add optional open() and close() methods for bit-bashing interfaces
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/598/head
parent
5676abead2
commit
d1949f2737
|
@ -239,6 +239,7 @@ static int i2c_reset ( struct bit_basher *basher ) {
|
||||||
* pull SDA low while SCL is high (which creates a start
|
* pull SDA low while SCL is high (which creates a start
|
||||||
* condition).
|
* condition).
|
||||||
*/
|
*/
|
||||||
|
open_bit ( basher );
|
||||||
setscl ( basher, 0 );
|
setscl ( basher, 0 );
|
||||||
setsda ( basher, 1 );
|
setsda ( basher, 1 );
|
||||||
for ( i = 0 ; i < I2C_RESET_MAX_CYCLES ; i++ ) {
|
for ( i = 0 ; i < I2C_RESET_MAX_CYCLES ; i++ ) {
|
||||||
|
@ -251,6 +252,7 @@ static int i2c_reset ( struct bit_basher *basher ) {
|
||||||
i2c_stop ( basher );
|
i2c_stop ( basher );
|
||||||
DBGC ( basher, "I2CBIT %p reset after %d attempts\n",
|
DBGC ( basher, "I2CBIT %p reset after %d attempts\n",
|
||||||
basher, ( i + 1 ) );
|
basher, ( i + 1 ) );
|
||||||
|
close_bit ( basher );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
setscl ( basher, 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",
|
DBGC ( basher, "I2CBIT %p could not reset after %d attempts\n",
|
||||||
basher, i );
|
basher, i );
|
||||||
|
close_bit ( basher );
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,6 +288,8 @@ static int i2c_bit_read ( struct i2c_interface *i2c,
|
||||||
DBGC ( basher, "I2CBIT %p reading from device %x: ",
|
DBGC ( basher, "I2CBIT %p reading from device %x: ",
|
||||||
basher, i2cdev->dev_addr );
|
basher, i2cdev->dev_addr );
|
||||||
|
|
||||||
|
open_bit ( basher );
|
||||||
|
|
||||||
for ( ; ; data++, offset++ ) {
|
for ( ; ; data++, offset++ ) {
|
||||||
|
|
||||||
/* Select device for writing */
|
/* Select device for writing */
|
||||||
|
@ -312,6 +317,7 @@ static int i2c_bit_read ( struct i2c_interface *i2c,
|
||||||
|
|
||||||
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
|
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
|
||||||
i2c_stop ( basher );
|
i2c_stop ( basher );
|
||||||
|
close_bit ( basher );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,6 +345,8 @@ static int i2c_bit_write ( struct i2c_interface *i2c,
|
||||||
DBGC ( basher, "I2CBIT %p writing to device %x: ",
|
DBGC ( basher, "I2CBIT %p writing to device %x: ",
|
||||||
basher, i2cdev->dev_addr );
|
basher, i2cdev->dev_addr );
|
||||||
|
|
||||||
|
open_bit ( basher );
|
||||||
|
|
||||||
for ( ; ; data++, offset++ ) {
|
for ( ; ; data++, offset++ ) {
|
||||||
|
|
||||||
/* Select device for writing */
|
/* Select device for writing */
|
||||||
|
@ -362,6 +370,7 @@ static int i2c_bit_write ( struct i2c_interface *i2c,
|
||||||
|
|
||||||
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
|
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
|
||||||
i2c_stop ( basher );
|
i2c_stop ( basher );
|
||||||
|
close_bit ( basher );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,9 @@ static int spi_bit_rw ( struct spi_bus *bus, struct spi_device *device,
|
||||||
uint32_t tmp_address;
|
uint32_t tmp_address;
|
||||||
uint32_t tmp_address_detect;
|
uint32_t tmp_address_detect;
|
||||||
|
|
||||||
|
/* Open bit-bashing interface */
|
||||||
|
open_bit ( &spibit->basher );
|
||||||
|
|
||||||
/* Deassert chip select to reset specified slave */
|
/* Deassert chip select to reset specified slave */
|
||||||
spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
|
spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
|
||||||
|
|
||||||
|
@ -214,6 +217,9 @@ static int spi_bit_rw ( struct spi_bus *bus, struct spi_device *device,
|
||||||
/* Deassert chip select on specified slave */
|
/* Deassert chip select on specified slave */
|
||||||
spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
|
spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
|
||||||
|
|
||||||
|
/* Close bit-bashing interface */
|
||||||
|
close_bit ( &spibit->basher );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,18 @@ struct bit_basher;
|
||||||
|
|
||||||
/** Bit-bashing operations */
|
/** Bit-bashing operations */
|
||||||
struct bit_basher_operations {
|
struct bit_basher_operations {
|
||||||
|
/**
|
||||||
|
* Open bit-bashing interface (optional)
|
||||||
|
*
|
||||||
|
* @v basher Bit-bashing interface
|
||||||
|
*/
|
||||||
|
void ( * open ) ( struct bit_basher *basher );
|
||||||
|
/**
|
||||||
|
* Close bit-bashing interface (optional)
|
||||||
|
*
|
||||||
|
* @v basher Bit-bashing interface
|
||||||
|
*/
|
||||||
|
void ( * close ) ( struct bit_basher *basher );
|
||||||
/**
|
/**
|
||||||
* Set/clear output bit
|
* Set/clear output bit
|
||||||
*
|
*
|
||||||
|
@ -45,6 +57,26 @@ struct bit_basher {
|
||||||
struct bit_basher_operations *op;
|
struct bit_basher_operations *op;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open bit-bashing interface
|
||||||
|
*
|
||||||
|
* @v basher Bit-bashing interface
|
||||||
|
*/
|
||||||
|
static inline void open_bit ( struct bit_basher *basher ) {
|
||||||
|
if ( basher->op->open )
|
||||||
|
basher->op->open ( basher );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close bit-bashing interface
|
||||||
|
*
|
||||||
|
* @v basher Bit-bashing interface
|
||||||
|
*/
|
||||||
|
static inline void close_bit ( struct bit_basher *basher ) {
|
||||||
|
if ( basher->op->close )
|
||||||
|
basher->op->close ( basher );
|
||||||
|
}
|
||||||
|
|
||||||
extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
|
extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
|
||||||
unsigned long data );
|
unsigned long data );
|
||||||
extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );
|
extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );
|
||||||
|
|
Loading…
Reference in New Issue