i2c-c2k: Handle i2c transfers like a standard driver
The i2c-c2k driver doesn't implement read and write transfers as raw
transfers, instead it behaves like i2c_read/write_reg() and messes
with the message buffer. Remove this weird handling and make it behave
like a standard driver.
Change-Id: Id16f5a9fbc9d514c5801feb528237af4b9866136
diff --git a/drivers/i2c/busses/i2c-c2k.c b/drivers/i2c/busses/i2c-c2k.c
index d321a35..942bc10 100644
--- a/drivers/i2c/busses/i2c-c2k.c
+++ b/drivers/i2c/busses/i2c-c2k.c
@@ -283,52 +283,7 @@
return (0);
}
-static uchar i2c_set_dev_offset (struct device_d *pdev, uchar dev_addr, struct i2c_msg *msgs, int ten_bit, int alen)
-{
- uchar status;
- unsigned int table[2];
-
-/* initialize the table of address offset bytes */
-/* utilized for 2 byte address offsets */
-/* NOTE: the order is high byte first! */
- if (alen == 2) {
- table[1] = msgs->buf[1]; /* low byte */
- }
- table[0] = msgs->buf[0]; /* single byte */
-
-
- status = i2c_select_device (pdev, dev_addr, 0, ten_bit);
- if (status) {
- dev_dbg(pdev, "Failed to select device setting offset: 0x%02x\n", status);
- return status;
- }
-/* check the address offset length */
- if (alen == 0)
- /* no address offset */
- return (0);
- else if (alen == 1) {
- /* 1 byte address offset */
- status = i2c_write_data (pdev, table, 1);
- if (status) {
- dev_dbg(pdev, "Failed to write data: 0x%02x\n", status);
- return status;
- }
- } else if (alen == 2) {
- /* 2 bytes address offset */
- status = i2c_write_data (pdev, table, 2);
- if (status) {
- dev_dbg(pdev, "Failed to write data: 0x%02x\n", status);
- return status;
- }
- } else {
- /* address offset unknown or not supported */
- dev_dbg(pdev, "Address length offset %d is not supported\n", alen);
- return 1;
- }
- return 0; /* sucessful completion */
-}
-
-uchar i2c_read (struct device_d *pdev, uchar dev_addr, struct i2c_msg *msgs, int alen, uchar * data, int len)
+uchar i2c_read (struct device_d *pdev, uchar dev_addr, uchar * data, int len)
{
uchar status = 0;
struct i2c_platform_data *pdata;
@@ -347,20 +302,6 @@
return status;
}
- status = i2c_set_dev_offset (pdev, dev_addr, msgs, 0, alen); /* send the slave address + offset */
- if (status) {
- dev_dbg(pdev, "Failed to set slave address & offset: 0x%02x\n", status);
- return status;
- }
-
- i2c_init (pdev, i2cFreq, 0); /* set the i2c frequency again */
-
- status = i2c_start (pdev);
- if (status) {
- dev_dbg(pdev, "Transaction restart failed: 0x%02x\n", status);
- return status;
- }
-
status = i2c_select_device (pdev, dev_addr, 1, 0); /* send the slave address */
if (status) {
dev_dbg(pdev, "Address not acknowledged: 0x%02x\n", status);
@@ -384,14 +325,12 @@
/* I2C write function */
/* dev_addr = device address */
-/* offset = address offset */
-/* alen = length in bytes of the address offset */
-/* data = pointer to buffer to read data into */
-/* len = # of bytes to read */
+/* data = pointer to the data to send */
+/* len = # of bytes to send */
/* */
/* returns 0 = succesful */
/* anything but zero is failure */
-uchar i2c_write (struct device_d *pdev, uchar dev_addr, struct i2c_msg *msgs, int alen, uchar * data, int len)
+uchar i2c_write (struct device_d *pdev, uchar dev_addr, uchar * data, int len)
{
uchar status = 0;
struct i2c_platform_data *pdata;
@@ -410,15 +349,13 @@
return status;
}
- status = i2c_set_dev_offset (pdev, dev_addr, msgs, 0, alen); /* send the slave address + offset */
+ status = i2c_select_device (pdev, dev_addr, 0, 0);
if (status) {
- dev_dbg(pdev, "Failed to set slave address & offset: 0x%02x\n", status);
+ dev_dbg(pdev, "Failed to set slave address: 0x%02x\n", status);
return status;
}
- data += alen;
-
- status = i2c_write_byte (pdev, data, len - alen); /* write the data */
+ status = i2c_write_byte (pdev, data, len); /* write the data */
if (status) {
dev_dbg(pdev, "Data not written: 0x%02x\n", status);
return status;
@@ -441,9 +378,9 @@
/* read/write data */
i = num-1;
if (msgs[i].flags & I2C_M_RD)
- result = i2c_read(adapter->dev, msgs[i].addr, msgs, 2, msgs[i].buf, msgs[i].len);
+ result = i2c_read(adapter->dev, msgs[i].addr, msgs[i].buf, msgs[i].len);
else
- result = i2c_write(adapter->dev, msgs->addr, msgs, 2, msgs->buf, msgs->len);
+ result = i2c_write(adapter->dev, msgs->addr, msgs->buf, msgs->len);
if (result)
goto fail0;
@@ -496,4 +433,3 @@
}
device_initcall(c2k_i2c_driverinit);
-