From: Eddie James <eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
jk-mnsaURCQ41sdnm+yROfE0A@public.gmane.org,
joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org,
andrew-zrmu5oMJ5Fs@public.gmane.org,
eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
"Edward A. James"
<eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 4/6] drivers/i2c: Add I2C master locking to FSI algorithm
Date: Mon, 26 Jun 2017 14:29:33 -0500 [thread overview]
Message-ID: <1498505375-1454-5-git-send-email-eajames@linux.vnet.ibm.com> (raw)
In-Reply-To: <1498505375-1454-1-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
From: "Edward A. James" <eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
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: Edward A. James <eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
drivers/i2c/busses/i2c-fsi.c | 41 +++++++++++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
index 007f104..41193be 100644
--- a/drivers/i2c/busses/i2c-fsi.c
+++ b/drivers/i2c/busses/i2c-fsi.c
@@ -136,6 +136,8 @@ struct fsi_i2c_master {
u8 fifo_size;
struct list_head ports;
struct ida ida;
+ wait_queue_head_t wait;
+ struct semaphore lock;
};
struct fsi_i2c_port {
@@ -171,6 +173,29 @@ static int fsi_i2c_write_reg(struct fsi_device *fsi, unsigned int reg,
return fsi_device_write(fsi, reg, &data_be, sizeof(data_be));
}
+static int fsi_i2c_lock_master(struct fsi_i2c_master *i2c, int timeout)
+{
+ int rc;
+
+ rc = down_trylock(&i2c->lock);
+ if (!rc)
+ return 0;
+
+ rc = wait_event_interruptible_timeout(i2c->wait,
+ !down_trylock(&i2c->lock),
+ timeout);
+ if (rc > 0)
+ return 0;
+
+ return -EBUSY;
+}
+
+static void fsi_i2c_unlock_master(struct fsi_i2c_master *i2c)
+{
+ up(&i2c->lock);
+ wake_up(&i2c->wait);
+}
+
static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c)
{
int rc;
@@ -412,25 +437,31 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
struct fsi_i2c_port *port = adap->algo_data;
struct i2c_msg *msg;
- rc = fsi_i2c_set_port(port);
+ rc = fsi_i2c_lock_master(port->master, adap->timeout);
if (rc)
return rc;
+ rc = fsi_i2c_set_port(port);
+ if (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 0;
+unlock:
+ fsi_i2c_unlock_master(port->master);
+ return rc;
}
static u32 fsi_i2c_functionality(struct i2c_adapter *adap)
@@ -455,6 +486,8 @@ static int fsi_i2c_probe(struct device *dev)
if (!i2c)
return -ENOMEM;
+ init_waitqueue_head(&i2c->wait);
+ sema_init(&i2c->lock, 1);
i2c->fsi = to_fsi_dev(dev);
i2c->idx = ida_simple_get(&fsi_i2c_ida, 1, INT_MAX, GFP_KERNEL);
ida_init(&i2c->ida);
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-06-26 19:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-26 19:29 [PATCH 0/6] drivers/i2c: Add FSI-attached I2C master algorithm Eddie James
[not found] ` <1498505375-1454-1-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-06-26 19:29 ` [PATCH 1/6] " Eddie James
2017-06-26 19:29 ` Eddie James [this message]
2017-06-26 19:29 ` [PATCH 2/6] drivers/i2c: Add port structure to FSI algorithm Eddie James
2017-06-26 19:29 ` [PATCH 3/6] drivers/i2c: Add transfer implementation for " Eddie James
2017-06-26 19:29 ` [PATCH 5/6] drivers/i2c: Add bus recovery " Eddie James
2017-06-26 19:29 ` [PATCH 6/6] Documentation/devicetree: Add FSI-attached I2C master dt bindings Eddie James
[not found] ` <1498505375-1454-7-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-06-27 1:06 ` Jeremy Kerr
[not found] ` <ec4a5fec-fea0-09a7-8559-99d8eb071093-mnsaURCQ41sdnm+yROfE0A@public.gmane.org>
2017-06-27 17:28 ` Eddie James
2017-06-28 3:08 ` Jeremy Kerr
2017-06-28 23:21 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1498505375-1454-5-git-send-email-eajames@linux.vnet.ibm.com \
--to=eajames-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=andrew-zrmu5oMJ5Fs@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=jk-mnsaURCQ41sdnm+yROfE0A@public.gmane.org \
--cc=joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).