uns8 i2c_tx_reg( uns8 addr, uns8 reg, uns8 data ) { i2c_start(); // send START if( i2c_put_byte( addr ) ) // a slave did not acknowledge { i2c_stop(); return( I2C_NO_ACK_ADDR ); } if( i2c_put_byte( reg ) ) // a slave did not acknowledge { i2c_stop(); return( I2C_NO_ACK_ADDR ); } if( i2c_put_byte( data ) ) // a slave did not acknowledge { i2c_stop(); return( I2C_NO_ACK_DATA ); } i2c_stop(); // send STOP return( I2C_NORMAL ); }
static int i2c_bit_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { struct nouveau_i2c_port *port = adap->algo_data; struct i2c_msg *msg = msgs; int ret = 0, mcnt = num; if (port->func->acquire) port->func->acquire(port); while (!ret && mcnt--) { u8 remaining = msg->len; u8 *ptr = msg->buf; ret = i2c_start(port); if (ret == 0) ret = i2c_addr(port, msg); if (msg->flags & I2C_M_RD) { while (!ret && remaining--) ret = i2c_get_byte(port, ptr++, !remaining); } else { while (!ret && remaining--) ret = i2c_put_byte(port, *ptr++); } msg++; } i2c_stop(port); return (ret < 0) ? ret : num; }
// not debugged uns8 i2c_rx_multi( uns8 addr, uns8 *data_ptr, uns8 length ) { uns8 dt; i2c_start(); // send START if( i2c_put_byte( addr ) ) // slave did not acknowledge { i2c_stop(); return( I2C_NO_ACK_ADDR ); } while( length ) { length--; dt = i2c_get_byte(); // get a data byte *data_ptr++ = dt; if( length ) i2c_send_ack(); // this is not the last byte } i2c_send_noack(); // this was the last byte i2c_stop(); // send STOP return( I2C_NORMAL ); }
static int i2c_addr(struct nouveau_i2c_port *port, struct i2c_msg *msg) { u32 addr = msg->addr << 1; if (msg->flags & I2C_M_RD) addr |= 1; return i2c_put_byte(port, addr); }
// not debugged uns8 i2c_tx_multi( uns8 addr, uns8 *data_ptr, uns8 length ) { i2c_start(); // send START if( i2c_put_byte( addr ) ) // a slave did not acknowledge { i2c_stop(); return( I2C_NO_ACK_ADDR ); } while( length ) { length--; if( i2c_put_byte( *data_ptr++ ) ) // a slave did not acknowledge { i2c_stop(); return( I2C_NO_ACK_DATA ); } } i2c_stop(); // send STOP return( I2C_NORMAL ); }
uns8 i2c_rx( uns8 addr, uns8 *data ) { uns8 dt; i2c_start(); // send START if( i2c_put_byte( addr ) ) // slave did not acknowledge { i2c_stop(); return( I2C_NO_ACK_ADDR ); } dt = i2c_get_byte(); // get a data byte *data = dt; i2c_send_noack(); // this is the last byte i2c_stop(); // send STOP return( I2C_NORMAL ); }