Permalink
Browse files

fix i2c transfer

  • Loading branch information...
1 parent b14c58e commit 11b82cb9d4ba163095ab2afbfdab526b34241eba @mlankhorst mlankhorst committed Apr 10, 2012
Showing with 23 additions and 5 deletions.
  1. +1 −5 pscnv/nouveau_bios.c
  2. +22 −0 pscnv/nouveau_i2c.h
View
@@ -1608,7 +1608,6 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
uint8_t count = bios->data[offset + 3];
int len = 4 + count;
struct nouveau_i2c_chan *chan;
- struct i2c_msg msg;
uint8_t data[256];
int ret, i;
@@ -1632,10 +1631,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
}
if (bios->execute) {
- msg.addr = i2c_address;
- msg.flags = 0;
- msg.len = count;
- msg.buf = data;
+ struct i2c_msg msg = { i2c_address, 0, count, data };
ret = i2c_transfer(&chan->adapter, &msg, 1);
if (ret != 1) {
NV_ERROR(dev, "0x%04X: i2c wr fail: %d\n", offset, ret);
View
@@ -57,6 +57,28 @@ static inline int i2c_transfer(device_t *dev, struct iic_msg *msg, int n) {
return ret ? -ret : n;
}
+enum i2c_smbus_op { I2C_SMBUS_WRITE, I2C_SMBUS_READ };
+enum i2c_smbus_data_type { I2C_SMBUS_BYTE_DATA };
+union i2c_smbus_data { u8 byte; };
+
+static inline int i2c_smbus_xfer(device_t *dev, uint16_t addr, uint16_t flags,
+ enum i2c_smbus_op op, uint8_t command,
+ enum i2c_smbus_data_type type,
+ union i2c_smbus_data *val)
+{
+ if (op == I2C_SMBUS_WRITE) {
+ uint8_t wrbuf[2] = { command, val->byte };
+ struct iic_msg msg = { addr, flags, 2, wrbuf };
+ return i2c_transfer(dev, &msg, 1);
+ } else {
+ struct iic_msg msg[2] = {
+ { addr, flags, 1, &command },
+ { addr, flags | IIC_M_RD, 1, &val->byte }
+ };
+ return i2c_transfer(dev, msg, 2);
+ }
+}
+
#endif
struct nouveau_i2c_chan {

0 comments on commit 11b82cb

Please sign in to comment.