Lines Matching refs:basher
54 static void setscl ( struct bit_basher *basher, int state ) { in setscl() argument
56 write_bit ( basher, I2C_BIT_SCL, state ); in setscl()
66 static void setsda ( struct bit_basher *basher, int state ) { in setsda() argument
68 write_bit ( basher, I2C_BIT_SDA, state ); in setsda()
78 static int getsda ( struct bit_basher *basher ) { in getsda() argument
80 state = read_bit ( basher, I2C_BIT_SDA ); in getsda()
90 static void i2c_start ( struct bit_basher *basher ) { in i2c_start() argument
91 setscl ( basher, 1 ); in i2c_start()
92 setsda ( basher, 0 ); in i2c_start()
93 setscl ( basher, 0 ); in i2c_start()
94 setsda ( basher, 1 ); in i2c_start()
103 static void i2c_send_bit ( struct bit_basher *basher, int bit ) { in i2c_send_bit() argument
104 setsda ( basher, bit ); in i2c_send_bit()
105 setscl ( basher, 1 ); in i2c_send_bit()
106 setscl ( basher, 0 ); in i2c_send_bit()
107 setsda ( basher, 1 ); in i2c_send_bit()
116 static int i2c_recv_bit ( struct bit_basher *basher ) { in i2c_recv_bit() argument
119 setscl ( basher, 1 ); in i2c_recv_bit()
120 bit = getsda ( basher ); in i2c_recv_bit()
121 setscl ( basher, 0 ); in i2c_recv_bit()
130 static void i2c_stop ( struct bit_basher *basher ) { in i2c_stop() argument
131 setsda ( basher, 0 ); in i2c_stop()
132 setscl ( basher, 1 ); in i2c_stop()
133 setsda ( basher, 1 ); in i2c_stop()
146 static int i2c_send_byte ( struct bit_basher *basher, uint8_t byte ) { in i2c_send_byte() argument
153 i2c_send_bit ( basher, byte & 0x80 ); in i2c_send_byte()
158 ack = ( i2c_recv_bit ( basher ) == 0 ); in i2c_send_byte()
172 static uint8_t i2c_recv_byte ( struct bit_basher *basher ) { in i2c_recv_byte() argument
179 byte |= ( i2c_recv_bit ( basher ) & 0x1 ); in i2c_recv_byte()
183 i2c_send_bit ( basher, 1 ); in i2c_recv_byte()
198 static int i2c_select ( struct bit_basher *basher, struct i2c_device *i2cdev, in i2c_select() argument
205 i2c_start ( basher ); in i2c_select()
216 if ( ( rc = i2c_send_byte ( basher, byte ) ) != 0 ) in i2c_select()
233 static int i2c_reset ( struct bit_basher *basher ) { in i2c_reset() argument
241 setscl ( basher, 0 ); in i2c_reset()
242 setsda ( basher, 1 ); in i2c_reset()
244 setscl ( basher, 1 ); in i2c_reset()
245 sda = getsda ( basher ); in i2c_reset()
248 i2c_start ( basher ); in i2c_reset()
250 i2c_stop ( basher ); in i2c_reset()
251 DBGC ( basher, "I2CBIT %p reset after %d attempts\n", in i2c_reset()
252 basher, ( i + 1 ) ); in i2c_reset()
255 setscl ( basher, 0 ); in i2c_reset()
258 DBGC ( basher, "I2CBIT %p could not reset after %d attempts\n", in i2c_reset()
259 basher, i ); in i2c_reset()
281 struct bit_basher *basher = &i2cbit->basher; in i2c_bit_read() local
284 DBGC ( basher, "I2CBIT %p reading from device %x: ", in i2c_bit_read()
285 basher, i2cdev->dev_addr ); in i2c_bit_read()
290 if ( ( rc = i2c_select ( basher, i2cdev, offset, in i2c_bit_read()
299 if ( ( rc = i2c_send_byte ( basher, offset ) ) != 0 ) in i2c_bit_read()
303 if ( ( rc = i2c_select ( basher, i2cdev, offset, in i2c_bit_read()
308 *data = i2c_recv_byte ( basher ); in i2c_bit_read()
309 DBGC ( basher, "%02x ", *data ); in i2c_bit_read()
312 DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) ); in i2c_bit_read()
313 i2c_stop ( basher ); in i2c_bit_read()
335 struct bit_basher *basher = &i2cbit->basher; in i2c_bit_write() local
338 DBGC ( basher, "I2CBIT %p writing to device %x: ", in i2c_bit_write()
339 basher, i2cdev->dev_addr ); in i2c_bit_write()
344 if ( ( rc = i2c_select ( basher, i2cdev, offset, in i2c_bit_write()
353 if ( ( rc = i2c_send_byte ( basher, offset ) ) != 0 ) in i2c_bit_write()
357 DBGC ( basher, "%02x ", *data ); in i2c_bit_write()
358 if ( ( rc = i2c_send_byte ( basher, *data ) ) != 0 ) in i2c_bit_write()
362 DBGC ( basher, "%s\n", ( rc ? "failed" : "" ) ); in i2c_bit_write()
363 i2c_stop ( basher ); in i2c_bit_write()
375 struct bit_basher *basher = &i2cbit->basher; in init_i2c_bit_basher() local
379 basher->op = bash_op; in init_i2c_bit_basher()
380 assert ( basher->op->read != NULL ); in init_i2c_bit_basher()
381 assert ( basher->op->write != NULL ); in init_i2c_bit_basher()
386 if ( ( rc = i2c_reset ( basher ) ) != 0 ) { in init_i2c_bit_basher()
387 DBGC ( basher, "I2CBIT %p could not reset I2C bus: %s\n", in init_i2c_bit_basher()
388 basher, strerror ( rc ) ); in init_i2c_bit_basher()