From: Philby John <pjohn-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
To: Pablo Bitton <pablo.bitton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Philby John <pjohn-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>,
Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Kevin Hilman
<khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
Subject: Re: [PATCH 6/6] i2c: davinci: bus recovery procedure to clear the bus
Date: Mon, 27 Sep 2010 18:10:05 +0530 [thread overview]
Message-ID: <1285591205.3643.63.camel@localhost.localdomain> (raw)
In-Reply-To: <AANLkTimqT=xgoxycjFAwEr6LPTeK21-FB1F-7kP5baPE-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Hello Pablo,
On Mon, 2010-09-13 at 16:23 +0200, Pablo Bitton wrote:
> Hi Philby,
> i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
> char allow_sleep)
> {
> unsigned long timeout;
> + static u16 to_cnt;
>
> timeout = jiffies + dev->adapter.timeout;
> while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
> & DAVINCI_I2C_STR_BB) {
> - if (time_after(jiffies, timeout)) {
> - dev_warn(dev->dev,
> - "timeout waiting for bus
> ready\n");
> - return -ETIMEDOUT;
> + if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
> + if (time_after(jiffies, timeout)) {
> + dev_warn(dev->dev,
> + "timeout waiting for bus ready
> \n");
> + to_cnt++;
> + return -ETIMEDOUT;
> + } else {
> + to_cnt = 0;
> + i2c_recover_bus(dev);
> + i2c_davinci_init(dev);
> + }
> }
> if (allow_sleep)
> schedule_timeout(1);
>
> The resulting loop has the following drawbacks:
> 1) If to_cnt reaches DAVINCI_I2C_MAX_TRIES+1 (which it currently
> can't, see 2) and the i2c bus collapses,
> the kernel will be stuck in the loop forever, especially if
> allow_sleep is false.
I do not understand how to_cnt can reach DAVINCI_I2C_MAX_TRIES+1. You
seem to be contradicting your own statement, you also say that this
cannot happen!!
> 2) The to_cnt static var never increments beyond 1.
Precisely.
> It's initialized to zero and then kept at zero until the timeout
> expires.
> When the timeout expires, to_cnt is incremented once, until the
> next call to the function, where it will be zeroed again.
How then can your 1st assumption hold good?
> 3) Do we really want to retry recovering the bus thousands of times,
> until the timeout arrives?
> It seems to me that if the bus recovery procedure didn't help
> after one or two tries, it probably never will.
Once a bus recovery is initiated, we are in the last phase of a recovery
and if that fails the user is left with no other choice but to reset the
target. From the very beginning the idea was to try until timeout.
Wouldn't you have a working system rather than to have to reset the
target?
>
>
> I also have the following nitpicks:
> a) The timeout variable actually holds the finish time.
Well, that's just aesthetic makeover. I could say the timeout is 10
seconds and the finish time is 10 seconds, it sounds the same to me.
> b) The i2c_recover_bus function uses dev_err to report a bus recovery
> process,
> but if all recovery attempts failed and the timeout was reached,
> only dev_warn is used to report the timeout.
Agreed. But your patch does not reflect this change.
>
>
> Other than that the patch is very helpful, thanks a lot.
>
>
> Below is my suggestion for the wait_bus_not_busy function. My patch
> has been tested on a DM6446.
All in all, your patch gives multiple checkpatch errors/warnings (spaces
instead of tabs etc). You have missed out parts of the code present in
the pristine kernel and so will not cleanly apply. To me, there are two
things that are of interest in your patch. First is you got rid of the
static variable definition and the other is usage of dev_err. I fail to
understand your assumption that the "kernel will be stuck in the loop
forever", hence I cannot tell how useful this patch really is.
>
>
> Signed-off-by: Pablo Bitton <pablo.bitton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> --
> diff --git a/drivers/i2c/busses/i2c-davinci.c
> b/drivers/i2c/busses/i2c-davinci.c
> --- a/drivers/i2c/busses/i2c-davinci.c
> +++ b/drivers/i2c/busses/i2c-davinci.c
>
>
>
>
>
> @@ -220,16 +261,24 @@ static int i2c_davinci_init(struct
> davinci_i2c_dev *dev)
> static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
> char allow_sleep)
> {
> - unsigned long timeout;
> + unsigned long finish_time;
You have missed out on this line static u16 to_cnt;
> + unsigned long to_cnt = 0;
>
> - timeout = jiffies + dev->adapter.timeout;
> + finish_time = jiffies + dev->adapter.timeout;
> + /* While bus busy */
> while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
> & DAVINCI_I2C_STR_BB) {
Your patch misses out on this line.
if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
Shouldn't you show removing it in the patch?
> - if (time_after(jiffies, timeout)) {
> + if (time_after(jiffies, finish_time)) {
> dev_warn(dev->dev,
> "timeout waiting for bus ready\n");
This is the part where the bus recover procedure would have failed. In
this case we could use dev_err here instead of in the function
i2c_recover_bus().
Also this line..
to_cnt++;
is missing from your patch.
You should show that you are removing it.
> return -ETIMEDOUT;
> }
> + else if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
> + dev_warn(dev->dev, "bus busy, performing bus
> recovery\n");
There is already a warning in the function i2c_recover_bus(). This can
be removed?
> + ++to_cnt;
Can we stick to to_cnt++; ?
> + i2c_recover_bus(dev);
> + i2c_davinci_init(dev);
> + }
> if (allow_sleep)
> schedule_timeout(1);
> }
Regards,
Philby
next prev parent reply other threads:[~2010-09-27 12:40 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-26 23:41 [PATCH 0/6] davinci i2c updates for 2.6.34 Kevin Hilman
[not found] ` <1264549293-25556-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-01-26 23:41 ` [PATCH 1/6] i2c: davinci: Fix smbus Oops with AIC33 usage Kevin Hilman
[not found] ` <026601ca9f54$17a18110$46e48330$@raj@ti.com>
[not found] ` <026601ca9f54$17a18110$46e48330$@raj-l0cyMroinI0@public.gmane.org>
2010-01-27 14:50 ` Kevin Hilman
[not found] ` <87k4v3y53z.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-01-28 4:05 ` Sudhakar Rajashekhara
2010-01-28 8:46 ` Sudhakar Rajashekhara
[not found] ` <02ee01ca9ff6$53cf0d90$fb6d28b0$@raj@ti.com>
[not found] ` <02ee01ca9ff6$53cf0d90$fb6d28b0$@raj-l0cyMroinI0@public.gmane.org>
2010-01-28 14:45 ` Kevin Hilman
[not found] ` <1264549293-25556-2-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-01-27 13:24 ` Sudhakar Rajashekhara
2010-01-27 15:03 ` Ben Dooks
2010-01-26 23:41 ` [PATCH 2/6] i2c: davinci: Remove MOD_REG_BIT and IO_ADDRESS usage Kevin Hilman
[not found] ` <1264549293-25556-3-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-01-27 15:05 ` Ben Dooks
[not found] ` <20100127150518.GB6090-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
2010-01-29 19:46 ` Kevin Hilman
2010-01-26 23:41 ` [PATCH 3/6] i2c: davinci: Add helper functions Kevin Hilman
2010-01-26 23:41 ` [PATCH 4/6] i2c: davinci: Add suspend/resume support Kevin Hilman
2010-01-26 23:41 ` [PATCH 5/6] i2c: davinci: Add cpufreq support Kevin Hilman
2010-01-26 23:41 ` [PATCH 6/6] i2c: davinci: bus recovery procedure to clear the bus Kevin Hilman
[not found] ` <1264549293-25556-7-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-02-01 5:57 ` Nori, Sekhar
[not found] ` <B85A65D85D7EB246BE421B3FB0FBB59301E235A3C2-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-02-01 19:40 ` Kevin Hilman
2010-02-05 13:53 ` Philby John
[not found] ` <225d086e1002050553tc1a696avce827cc115f56b1c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-08 10:35 ` Nori, Sekhar
[not found] ` <B85A65D85D7EB246BE421B3FB0FBB59301E2639AD8-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-02-08 10:50 ` Philby John
2010-02-08 15:13 ` Philby John
[not found] ` <4B702A17.3070104-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
2010-02-08 16:03 ` Nori, Sekhar
[not found] ` <B85A65D85D7EB246BE421B3FB0FBB59301E2639D67-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-02-09 10:15 ` Philby John
[not found] ` <4B7135B3.9080104-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
2010-02-09 10:52 ` Nori, Sekhar
[not found] ` <B85A65D85D7EB246BE421B3FB0FBB59301E263A447-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-03-05 15:20 ` Griffis, Brad
[not found] ` <F8C55F6A02E92D48BDDFC6048552C6F14E6D9F3F-lTKHBJngVwKIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-03-08 13:37 ` Philby John
[not found] ` <4B94FD84.3060100-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
2010-03-11 16:28 ` Griffis, Brad
2010-03-08 13:36 ` Philby John
[not found] ` <4B94FD6F.7050603-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
2010-03-16 20:50 ` Kevin Hilman
[not found] ` <87d3z4xa7m.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-03-17 11:28 ` Philby John
[not found] ` <4BA0BCEC.8040209-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
2010-03-17 13:18 ` Nori, Sekhar
[not found] ` <B85A65D85D7EB246BE421B3FB0FBB59301E6328944-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-03-17 13:46 ` Philby John
2010-09-13 14:23 ` Pablo Bitton
[not found] ` <AANLkTimqT=xgoxycjFAwEr6LPTeK21-FB1F-7kP5baPE-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-27 12:40 ` Philby John [this message]
-- strict thread matches above, loose matches on Subject: below --
2010-04-06 17:42 [PATCH 0/6] i2c: davinci updates for 2.6.35 Kevin Hilman
[not found] ` <1270575738-22388-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-04-06 17:42 ` [PATCH 6/6] i2c: davinci: bus recovery procedure to clear the bus Kevin Hilman
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=1285591205.3643.63.camel@localhost.localdomain \
--to=pjohn-igf4poytycdqt0dzr+alfa@public.gmane.org \
--cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
--cc=davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org \
--cc=khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=pablo.bitton-Re5JQEeQqe8AvxtiuMwx3w@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).