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>
This commit is contained in:
@@ -186,8 +186,8 @@ static int platform_i2c_read(uint32_t restart, uint8_t *rx_buffer, int length,
|
||||
return bytes_transferred;
|
||||
}
|
||||
|
||||
int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
|
||||
int seg_count)
|
||||
int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segment,
|
||||
int seg_count)
|
||||
{
|
||||
int bytes_transferred;
|
||||
uint8_t chip;
|
||||
@@ -212,9 +212,9 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
|
||||
printk(BIOS_ERR,
|
||||
"I2C segment[%d]: %s 0x%02x %s 0x%p, 0x%08x bytes\n",
|
||||
index,
|
||||
segment[index].read ? "Read from" : "Write to",
|
||||
segment[index].chip,
|
||||
segment[index].read ? "to " : "from",
|
||||
(segment[index].flags & I2C_M_RD) ? "Read from" : "Write to",
|
||||
segment[index].slave,
|
||||
(segment[index].flags & I2C_M_RD) ? "to " : "from",
|
||||
segment[index].buf,
|
||||
segment[index].len);
|
||||
printk(BIOS_ERR, "I2C %s\n",
|
||||
@@ -243,7 +243,7 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
|
||||
regs->ic_con = cmd;
|
||||
|
||||
/* Set the target chip address */
|
||||
chip = segment->chip;
|
||||
chip = segment->slave;
|
||||
regs->ic_tar = chip;
|
||||
|
||||
/* Enable the I2C controller */
|
||||
@@ -270,13 +270,13 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
|
||||
total_bytes += length;
|
||||
ASSERT(segment->buf != NULL);
|
||||
ASSERT(length >= 1);
|
||||
ASSERT(segment->chip == chip);
|
||||
ASSERT(segment->slave == chip);
|
||||
|
||||
/* Determine if this is the last segment of the transaction */
|
||||
stop = (index == seg_count) ? IC_DATA_CMD_STOP : 0;
|
||||
|
||||
/* Fill the FIFO with the necessary command bytes */
|
||||
if (segment->read) {
|
||||
if (segment->flags & I2C_M_RD) {
|
||||
/* Place read commands into the FIFO */
|
||||
rx_buffer = segment->buf;
|
||||
data_bytes = platform_i2c_read(restart, rx_buffer,
|
||||
|
Reference in New Issue
Block a user