* 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++ ) {
i2c_stop ( basher );
DBGC ( basher, "I2CBIT %p reset after %d attempts\n",
basher, ( i + 1 ) );
+ close_bit ( basher );
return 0;
}
setscl ( basher, 0 );
DBGC ( basher, "I2CBIT %p could not reset after %d attempts\n",
basher, i );
+ close_bit ( basher );
return -ETIMEDOUT;
}
DBGC ( basher, "I2CBIT %p reading from device %x: ",
basher, i2cdev->dev_addr );
+ open_bit ( basher );
+
for ( ; ; data++, offset++ ) {
/* Select device for writing */
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
i2c_stop ( basher );
+ close_bit ( basher );
return rc;
}
DBGC ( basher, "I2CBIT %p writing to device %x: ",
basher, i2cdev->dev_addr );
+ open_bit ( basher );
+
for ( ; ; data++, offset++ ) {
/* Select device for writing */
if ( ( rc = i2c_send_byte ( basher, *data ) ) != 0 )
break;
}
-
+
DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) );
i2c_stop ( basher );
+ close_bit ( basher );
return rc;
}
uint32_t tmp_address;
uint32_t tmp_address_detect;
+ /* Open bit-bashing interface */
+ open_bit ( &spibit->basher );
+
/* Deassert chip select to reset specified slave */
spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
/* Deassert chip select on specified slave */
spi_bit_set_slave_select ( spibit, device->slave, DESELECT_SLAVE );
+ /* Close bit-bashing interface */
+ close_bit ( &spibit->basher );
+
return 0;
}
/** Bit-bashing 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
*
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,
unsigned long data );
extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );