summaryrefslogtreecommitdiff
path: root/src/soc/intel/common/block
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/soc/intel/common/block
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/soc/intel/common/block')
-rw-r--r--src/soc/intel/common/block/i2c/lpss_i2c.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/soc/intel/common/block/i2c/lpss_i2c.c b/src/soc/intel/common/block/i2c/lpss_i2c.c
index 5b188f8c22..711517f6d3 100644
--- a/src/soc/intel/common/block/i2c/lpss_i2c.c
+++ b/src/soc/intel/common/block/i2c/lpss_i2c.c
@@ -258,7 +258,7 @@ static int lpss_i2c_wait_for_bus_idle(struct lpss_i2c_regs *regs)
/* Transfer one byte of one segment, sending stop bit if requested */
static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
- struct i2c_seg *segment,
+ struct i2c_msg *segment,
size_t byte, int send_stop)
{
struct stopwatch sw;
@@ -266,7 +266,7 @@ static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
stopwatch_init_usecs_expire(&sw, LPSS_I2C_TIMEOUT_US);
- if (!segment->read) {
+ if (!(segment->flags & I2C_M_RD)) {
/* Write op only: Wait for FIFO not full */
while (!(read32(&regs->status) & STATUS_TX_FIFO_NOT_FULL)) {
if (stopwatch_expired(&sw)) {
@@ -283,7 +283,7 @@ static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
write32(&regs->cmd_data, cmd);
- if (segment->read) {
+ if (segment->flags & I2C_M_RD) {
/* Read op only: Wait for FIFO data and store it */
while (!(read32(&regs->status) & STATUS_RX_FIFO_NOT_EMPTY)) {
if (stopwatch_expired(&sw)) {
@@ -298,7 +298,8 @@ static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
}
/* Global I2C bus handler, defined in include/i2c.h */
-int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segments, int count)
+int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments,
+ int count)
{
struct stopwatch sw;
struct lpss_i2c_regs *regs;
@@ -325,11 +326,12 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segments, int count)
while (count--) {
if (CONFIG_SOC_INTEL_COMMON_LPSS_I2C_DEBUG)
printk(BIOS_DEBUG, "i2c %u:%02x %s %d bytes : ",
- bus, segments->chip, segments->read ? "R" : "W",
+ bus, segments->slave,
+ (segments->flags & I2C_M_RD) ? "R" : "W",
segments->len);
/* Set target slave address */
- write32(&regs->target_addr, segments->chip);
+ write32(&regs->target_addr, segments->slave);
/* Read or write each byte in segment */
for (byte = 0; byte < segments->len; byte++) {
@@ -341,8 +343,9 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segments, int count)
if (lpss_i2c_transfer_byte(regs, segments, byte,
count == 0) < 0) {
printk(BIOS_ERR, "I2C %s failed: bus %u "
- "addr 0x%02x\n", segments->read ?
- "read" : "write", bus, segments->chip);
+ "addr 0x%02x\n",
+ (segments->flags & I2C_M_RD) ?
+ "read" : "write", bus, segments->slave);
goto out;
}
}