Skip to content

Commit

Permalink
i2c: fsi: Add I2C master locking
Browse files Browse the repository at this point in the history
Since there are many ports per master, each with it's own adapter and
chardev, we need some locking to prevent transfers from changing the
master state while other transfers are in progress.

Signed-off-by: Eddie James <eajames@linux.vnet.ibm.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Tested-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
  • Loading branch information
Eddie James authored and Wolfram Sang committed Jul 20, 2018
1 parent 504b827 commit f4cdc31
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drivers/i2c/busses/i2c-fsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/slab.h>

Expand Down Expand Up @@ -148,6 +149,7 @@ struct fsi_i2c_master {
struct fsi_device *fsi;
u8 fifo_size;
struct list_head ports;
struct mutex lock;
};

struct fsi_i2c_port {
Expand Down Expand Up @@ -486,27 +488,32 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
int i, rc;
unsigned long start_time;
struct fsi_i2c_port *port = adap->algo_data;
struct fsi_i2c_master *master = port->master;
struct i2c_msg *msg;

mutex_lock(&master->lock);

rc = fsi_i2c_set_port(port);
if (rc)
return rc;
goto unlock;

for (i = 0; i < num; i++) {
msg = msgs + i;
start_time = jiffies;

rc = fsi_i2c_start(port, msg, i == num - 1);
if (rc)
return rc;
goto unlock;

rc = fsi_i2c_wait(port, msg,
adap->timeout - (jiffies - start_time));
if (rc)
return rc;
goto unlock;
}

return num;
unlock:
mutex_unlock(&master->lock);
return rc ? : num;
}

static u32 fsi_i2c_functionality(struct i2c_adapter *adap)
Expand All @@ -532,6 +539,7 @@ static int fsi_i2c_probe(struct device *dev)
if (!i2c)
return -ENOMEM;

mutex_init(&i2c->lock);
i2c->fsi = to_fsi_dev(dev);
INIT_LIST_HEAD(&i2c->ports);

Expand Down

0 comments on commit f4cdc31

Please sign in to comment.