summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
authorNico Huber <nico.huber@secunet.com>2017-07-12 17:59:16 +0200
committerMartin Roth <martinroth@google.com>2017-08-14 18:07:30 +0000
commit029dfff30cc468b3e21c2004a135d3380a8c20e6 (patch)
treee4650cddc8c7fbe6c31608ba35235474cff8cf9e /src/device
parent673e014fab7b6640942c141a4d2d2dc23e93d7a0 (diff)
i2c: Move to Linux like `struct i2c_msg`
Our current struct for I2C segments `i2c_seg` was close to being compa- tible to the Linux version `i2c_msg`, close to being compatible to SMBus and close to being readable (e.g. what was `chip` supposed to mean?) but turned out to be hard to fix. Instead of extending it in a backwards compatible way (and not touching current controller drivers), replace it with a Linux source compatible `struct i2c_msg` and patch all the drivers and users with Coccinelle. The new `struct i2c_msg` should ease porting drivers from Linux and help to write SMBus compatible controller drivers. Beside integer type changes, the field `read` is replaced with a generic field `flags` and `chip` is renamed to `slave`. Patched with Coccinelle using the clumsy spatch below and some manual changes: * Nested struct initializers and one field access skipped by Coccinelle. * Removed assumption in the code that I2C_M_RD is 1. * In `i2c.h`, changed all occurences of `chip` to `slave`. @@ @@ -struct i2c_seg +struct i2c_msg @@ identifier msg; expression e; @@ ( struct i2c_msg msg = { - .read = 0, + .flags = 0, }; | struct i2c_msg msg = { - .read = 1, + .flags = I2C_M_RD, }; | struct i2c_msg msg = { - .chip = e, + .slave = e, }; ) @@ struct i2c_msg msg; statement S1, S2; @@ ( -if (msg.read) +if (msg.flags & I2C_M_RD) S1 else S2 | -if (msg.read) +if (msg.flags & I2C_M_RD) S1 ) @@ struct i2c_msg *msg; statement S1, S2; @@ ( -if (msg->read) +if (msg->flags & I2C_M_RD) S1 else S2 | -if (msg->read) +if (msg->flags & I2C_M_RD) S1 ) @@ struct i2c_msg msg; expression e; @@ ( -msg.read = 0; +msg.flags = 0; | -msg.read = 1; +msg.flags = I2C_M_RD; | -msg.read = e; +msg.flags = e ? I2C_M_RD : 0; | -!!(msg.read) +(msg.flags & I2C_M_RD) | -(msg.read) +(msg.flags & I2C_M_RD) ) @@ struct i2c_msg *msg; expression e; @@ ( -msg->read = 0; +msg->flags = 0; | -msg->read = 1; +msg->flags = I2C_M_RD; | -msg->read = e; +msg->flags = e ? I2C_M_RD : 0; | -!!(msg->read) +(msg->flags & I2C_M_RD) | -(msg->read) +(msg->flags & I2C_M_RD) ) @@ struct i2c_msg msg; @@ -msg.chip +msg.slave @@ struct i2c_msg *msg; expression e; @@ -msg[e].chip +msg[e].slave @ slave disable ptr_to_array @ struct i2c_msg *msg; @@ -msg->chip +msg->slave Change-Id: Ifd7cabf0a18ffd7a1def25d1d7059b713d0b7ea9 Signed-off-by: Nico Huber <nico.huber@secunet.com> Reviewed-on: https://review.coreboot.org/20542 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Werner Zeh <werner.zeh@siemens.com> Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Diffstat (limited to 'src/device')
-rw-r--r--src/device/i2c.c2
-rw-r--r--src/device/software_i2c.c9
2 files changed, 6 insertions, 5 deletions
diff --git a/src/device/i2c.c b/src/device/i2c.c
index d4670a013c..67470d4921 100644
--- a/src/device/i2c.c
+++ b/src/device/i2c.c
@@ -49,7 +49,7 @@ int i2c_dev_find_bus(struct device *dev)
return ops->dev_to_bus(pbus->dev);
}
-int i2c_dev_transfer(struct device *dev, struct i2c_seg *segments, int count)
+int i2c_dev_transfer(struct device *dev, struct i2c_msg *segments, int count)
{
int bus = i2c_dev_find_bus(dev);
if (bus < 0)
diff --git a/src/device/software_i2c.c b/src/device/software_i2c.c
index be7aebecd0..368d145b3e 100644
--- a/src/device/software_i2c.c
+++ b/src/device/software_i2c.c
@@ -238,19 +238,20 @@ static int in_byte(unsigned bus, int ack)
return byte;
}
-int software_i2c_transfer(unsigned bus, struct i2c_seg *segments, int count)
+int software_i2c_transfer(unsigned bus, struct i2c_msg *segments, int count)
{
int i;
- struct i2c_seg *seg;
+ struct i2c_msg *seg;
for (seg = segments; seg - segments < count; seg++) {
if (start_cond(bus) < 0)
return -1;
- if (out_byte(bus, seg->chip << 1 | !!seg->read) < 0)
+ const u8 addr_dir = seg->slave << 1 | !!(seg->flags & I2C_M_RD);
+ if (out_byte(bus, addr_dir) < 0)
return -1;
for (i = 0; i < seg->len; i++) {
int ret;
- if (seg->read) {
+ if (seg->flags & I2C_M_RD) {
ret = in_byte(bus, i < seg->len - 1);
seg->buf[i] = (u8)ret;
} else {