Commit f4cdc319 authored by Eddie James's avatar Eddie James Committed by Wolfram Sang

i2c: fsi: Add I2C master locking

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: default avatarEddie James <eajames@linux.vnet.ibm.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Tested-by: default avatarJoel Stanley <joel@jms.id.au>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 504b8277
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -148,6 +149,7 @@ struct fsi_i2c_master { ...@@ -148,6 +149,7 @@ struct fsi_i2c_master {
struct fsi_device *fsi; struct fsi_device *fsi;
u8 fifo_size; u8 fifo_size;
struct list_head ports; struct list_head ports;
struct mutex lock;
}; };
struct fsi_i2c_port { struct fsi_i2c_port {
...@@ -486,11 +488,14 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, ...@@ -486,11 +488,14 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
int i, rc; int i, rc;
unsigned long start_time; unsigned long start_time;
struct fsi_i2c_port *port = adap->algo_data; struct fsi_i2c_port *port = adap->algo_data;
struct fsi_i2c_master *master = port->master;
struct i2c_msg *msg; struct i2c_msg *msg;
mutex_lock(&master->lock);
rc = fsi_i2c_set_port(port); rc = fsi_i2c_set_port(port);
if (rc) if (rc)
return rc; goto unlock;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
msg = msgs + i; msg = msgs + i;
...@@ -498,15 +503,17 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, ...@@ -498,15 +503,17 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
rc = fsi_i2c_start(port, msg, i == num - 1); rc = fsi_i2c_start(port, msg, i == num - 1);
if (rc) if (rc)
return rc; goto unlock;
rc = fsi_i2c_wait(port, msg, rc = fsi_i2c_wait(port, msg,
adap->timeout - (jiffies - start_time)); adap->timeout - (jiffies - start_time));
if (rc) 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) static u32 fsi_i2c_functionality(struct i2c_adapter *adap)
...@@ -532,6 +539,7 @@ static int fsi_i2c_probe(struct device *dev) ...@@ -532,6 +539,7 @@ static int fsi_i2c_probe(struct device *dev)
if (!i2c) if (!i2c)
return -ENOMEM; return -ENOMEM;
mutex_init(&i2c->lock);
i2c->fsi = to_fsi_dev(dev); i2c->fsi = to_fsi_dev(dev);
INIT_LIST_HEAD(&i2c->ports); INIT_LIST_HEAD(&i2c->ports);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment