From: lucas.de.marchi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
Jarkko Nikula
<jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
Mika Westerberg
<mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
Fabio Mello <fabio.mello-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
Lucas De Marchi
<lucas.demarchi-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: [PATCH] i2c: designware: use enable on resume instead initialization
Date: Mon, 8 Jun 2015 14:50:28 -0300 [thread overview]
Message-ID: <1433785828-4100-1-git-send-email-lucas.de.marchi@gmail.com> (raw)
From: Fabio Mello <fabio.mello-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
According to documentation and tests, initialization is not
necessary on module resume, since the controller keeps its state
between disable/enable. Change the target address is also allowed.
So, this patch replaces the initialization on module resume with a
simple enable, and removes the (non required anymore) enables and
disables.
Signed-off-by: Fabio Mello <fabio.mello-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
These pictures explain a little more the consequence of letting the
enable+disable in the code:
http://pub.politreco.com/paste/TEK0011-before.jpg
http://pub.politreco.com/paste/TEK0007-after.jpg
The yellow line is a GPIO toggle in userspace to mark when we start and finish
the i2c transactions. The blue line is the SCL in that i2c bus. Take a look on
the huge pauses we have between any 2 transactions. These pauses are removed
with this patch and we are able to read our sensor's values in 950usec rather
than 5.24msec we had before. We are testing this using a Minnowboard Max that
has a designware i2c controller.
There's this comment in the code suggesting the designware controller might
have problems if we don't disable it after each transfer. We left a stress
code running for 3 days to check if anything bad would happen. This is the
test code using a PCA9685 (just because it was the easiest device we had
available to check read+write commands):
http://pub.politreco.com/paste/test-i2c.c
drivers/i2c/busses/i2c-designware-core.c | 19 ++++---------------
drivers/i2c/busses/i2c-designware-platdrv.c | 2 +-
2 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 6e25c01..b386c10 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -375,8 +375,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
/* configure the i2c master */
dw_writel(dev, dev->master_cfg , DW_IC_CON);
+ /* Enable the adapter */
+ __i2c_dw_enable(dev, true);
+
if (dev->release_lock)
dev->release_lock(dev);
+
return 0;
}
EXPORT_SYMBOL_GPL(i2c_dw_init);
@@ -405,9 +409,6 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
struct i2c_msg *msgs = dev->msgs;
u32 ic_con, ic_tar = 0;
- /* Disable the adapter */
- __i2c_dw_enable(dev, false);
-
/* if the slave address is ten bit address, enable 10BITADDR */
ic_con = dw_readl(dev, DW_IC_CON);
if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) {
@@ -434,9 +435,6 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
/* enforce disabled interrupts (due to HW issues) */
i2c_dw_disable_int(dev);
- /* Enable the adapter */
- __i2c_dw_enable(dev, true);
-
/* Clear and enable interrupts */
i2c_dw_clear_int(dev);
dw_writel(dev, DW_IC_INTR_DEFAULT_MASK, DW_IC_INTR_MASK);
@@ -665,15 +663,6 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
goto done;
}
- /*
- * We must disable the adapter before unlocking the &dev->lock mutex
- * below. Otherwise the hardware might continue generating interrupts
- * which in turn causes a race condition with the following transfer.
- * Needs some more investigation if the additional interrupts are
- * a hardware bug or this driver doesn't handle them correctly yet.
- */
- __i2c_dw_enable(dev, false);
-
if (dev->msg_err) {
ret = dev->msg_err;
goto done;
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index c270f5f..0598695 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -320,7 +320,7 @@ static int dw_i2c_resume(struct device *dev)
clk_prepare_enable(i_dev->clk);
if (!i_dev->pm_runtime_disabled)
- i2c_dw_init(i_dev);
+ i2c_dw_enable(i_dev);
return 0;
}
--
2.4.2
next reply other threads:[~2015-06-08 17:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-08 17:50 lucas.de.marchi-Re5JQEeQqe8AvxtiuMwx3w [this message]
[not found] ` <1433785828-4100-1-git-send-email-lucas.de.marchi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-09 8:51 ` [PATCH] i2c: designware: use enable on resume instead initialization Mika Westerberg
[not found] ` <20150609085146.GD1478-3PARRvDOhMZrdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2015-06-09 18:29 ` Lucas De Marchi
[not found] ` <CAKi4VAJwD45VbWuCHegfkB-tbgvgza52-cgVNF4AxF8NCuYyRQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-10 7:07 ` Mika Westerberg
[not found] ` <OF847FFF39.1FF5F96A-ONC1257E60.00506AFD-C1257E60.0052A8CE@alitech.com>
[not found] ` <OF847FFF39.1FF5F96A-ONC1257E60.00506AFD-C1257E60.0052A8CE-Yycd8EPnGM5BDgjK7y7TUQ@public.gmane.org>
2015-06-11 9:38 ` Mika Westerberg
2015-06-11 14:48 ` Lucas De Marchi
[not found] ` <OF847FFF39.1FF5F96A-ONC1257E60.00506AFD-C1257E60.0052A8CE@LocalDomain>
2015-06-23 16:45 ` christian.ruppert-Yycd8EPnGM5BDgjK7y7TUQ
[not found] ` <OFB47A681B.5488F019-ONC1257E6D.005A6CD2-C1257E6D.005BD52F-Yycd8EPnGM5BDgjK7y7TUQ@public.gmane.org>
2015-06-23 17:02 ` Lucas De Marchi
[not found] ` <CAKi4VA+t3d-XoqDiL9ez+9qDR_ndgGnAOhkpZsJyJ2tMjfCYLA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-24 7:36 ` christian.ruppert-Yycd8EPnGM5BDgjK7y7TUQ
[not found] ` <OFB918064C.F72245F4-ONC1257E6E.00287EC7-C1257E6E.00299EF2-Yycd8EPnGM5BDgjK7y7TUQ@public.gmane.org>
2015-06-24 11:27 ` Mika Westerberg
[not found] ` <20150624112723.GE827-3PARRvDOhMZrdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2015-06-24 12:56 ` De Marchi, Lucas
[not found] ` <1435150578.1075.5.camel-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-06-24 13:18 ` mika.westerberg-VuQAYsv1563Yd54FQh9/CA
2015-06-24 14:06 ` christian.ruppert-Yycd8EPnGM5BDgjK7y7TUQ
2015-06-10 7:55 ` Mika Westerberg
[not found] ` <20150610075555.GO1478-3PARRvDOhMZrdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2015-06-12 22:45 ` Lucas De Marchi
2015-06-15 9:29 ` Mika Westerberg
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=1433785828-4100-1-git-send-email-lucas.de.marchi@gmail.com \
--to=lucas.de.marchi-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=fabio.mello-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lucas.demarchi-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=mika.westerberg-VuQAYsv1563Yd54FQh9/CA@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).