linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bastian Hecht <hechtb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux-SH <linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Tomoya MORINAGA
	<tomoya.rohm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Naveen Krishna Chatradhi
	<ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Taekgyun Ko <taeggyun.ko-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Ben Dooks <ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org>,
	Magnus Damm <magnus.damm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 1/5] i2c: Don't start transfers when suspended
Date: Thu, 17 Jul 2014 16:34:39 +0200	[thread overview]
Message-ID: <CABYn4swzWs3MvADjJChO701Mao3biFemcSm-3FuB-syt91ng+A@mail.gmail.com> (raw)
In-Reply-To: <20140717130047.GF2740@katana>

Hi Wolfram,

thanks for the review.

2014-07-17 15:00 GMT+02:00 Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>:
> Hi Bastian,
>
> On Sat, Jul 12, 2014 at 01:49:27PM +0200, Bastian Hecht wrote:
>> i2c transfer requests come in very uncontrolled, like from interrupt routines.
>> We might be suspended when this happens. To avoid i2c timeouts caused by
>> powered down busses we check for suspension.
>>
>> Signed-off-by: Bastian Hecht <hechtb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
> Thanks for doing this! I add linux-pm to CC because of two questions.
>
> And in case of resending, please add at least alkml to the CC list. Or
> better: use 'get_maintainer.pl' as cc-cmd with git-send-email.

Wow these scripts! So useful - thanks for the hint. I looked up the
few people I added manually in the drivers.

>> ---
>> I ended up getting i2c timeouts when suspending and provoking touchscreen
>> IRQs on an Armadillo board with an sh_mobile i2c bus. Instead of copying
>> again the protection mechanism from other bus drivers, we can clean things
>> up and move this into the core.
>
> This could be part of the commit message IMO.

Ok I added it partly. I didn't include the Armadillo specific part,
but added the general
idea to move existing protection schemes to the core.

>>
>> I assume that all bus drivers use kzalloc or equivalent for the
>> struct i2c_adapter. So adap->suspended can't end up uninitialized,
>> right?
>
> Better safe than sorry, I'd say. Please add the initialization.

Ok done.

>> We could consider using this scheme for freeze/restore too.
>
> linux-pm: opinions?
>
>>
>>
>>  drivers/i2c/i2c-core.c | 24 +++++++++++++++++++++++-
>>  include/linux/i2c.h    |  1 +
>>  2 files changed, 24 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
>> index 7c7f4b8..9fe9581 100644
>> --- a/drivers/i2c/i2c-core.c
>> +++ b/drivers/i2c/i2c-core.c
>> @@ -343,6 +343,13 @@ static int i2c_legacy_resume(struct device *dev)
>>  static int i2c_device_pm_suspend(struct device *dev)
>>  {
>>       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
>> +     struct i2c_adapter *adap = i2c_verify_adapter(dev);
>> +
>> +     if (adap) {
>> +             i2c_lock_adapter(adap);
>> +             adap->suspended = true;
>> +             i2c_unlock_adapter(adap);
>> +     }
>>
>>       if (pm)
>>               return pm_generic_suspend(dev);
>> @@ -353,6 +360,13 @@ static int i2c_device_pm_suspend(struct device *dev)
>>  static int i2c_device_pm_resume(struct device *dev)
>>  {
>>       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
>> +     struct i2c_adapter *adap = i2c_verify_adapter(dev);
>> +
>> +     if (adap) {
>> +             i2c_lock_adapter(adap);
>> +             adap->suspended = false;
>> +             i2c_unlock_adapter(adap);
>> +     }
>>
>>       if (pm)
>>               return pm_generic_resume(dev);
>> @@ -1819,7 +1833,10 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
>>                       i2c_lock_adapter(adap);
>>               }
>>
>> -             ret = __i2c_transfer(adap, msgs, num);
>> +             if (adap->suspended)
>> +                     ret = -EIO;
>> +             else
>> +                     ret = __i2c_transfer(adap, msgs, num);
>
> a) Minor: I'd swap the branches and invert the condition, so that the
> more expected code path comes first

Oh yes, well seen. I swapped it.

> b) linux-pm: I wonder about the return code. Currently, some drivers
> return -EIO, some -EBUSY. Do you care which? Since we try to have
> designated fault codes in the i2c subsystem, I wonder about -ESHUTDOWN?
> Or is this too much of hijacking fault codes?

I looked up Documentation/i2c/fault-codes and -EIO currently is the
closest blurrily defined fault code to our problem. I agree that
-ESHUTDOWN would look clearer, but as well agree that I'm unsure about
getting too pedantic. I left -EIO for the v2 series for now. If we opt
for -ESHUTDOWN we shouldn't forget to update the docs too.

I will post v2 now but be on the road for probably a month and can't
participate further here. If needed feel free to completely modify
these patches - it's a very basic patchset anyway.

Cheers,

 Bastian


>>               i2c_unlock_adapter(adap);
>>
>>               return ret;
>> @@ -2577,6 +2594,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
>>
>>       if (adapter->algo->smbus_xfer) {
>>               i2c_lock_adapter(adapter);
>> +             if (adapter->suspended) {
>> +                     res = -EIO;
>> +                     goto unlock;
>> +             }
>>
>>               /* Retry automatically on arbitration loss */
>>               orig_jiffies = jiffies;
>> @@ -2590,6 +2611,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
>>                                      orig_jiffies + adapter->timeout))
>>                               break;
>>               }
>> +unlock:
>>               i2c_unlock_adapter(adapter);
>>
>>               if (res != -EOPNOTSUPP || !adapter->algo->master_xfer)
>> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
>> index b556e0a..af08c75 100644
>> --- a/include/linux/i2c.h
>> +++ b/include/linux/i2c.h
>> @@ -434,6 +434,7 @@ struct i2c_adapter {
>>       int timeout;                    /* in jiffies */
>>       int retries;
>>       struct device dev;              /* the adapter device */
>> +     unsigned int suspended:1;
>>
>>       int nr;
>>       char name[48];
>> --
>> 1.9.1
>>

      parent reply	other threads:[~2014-07-17 14:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-12 11:49 [PATCH 1/5] i2c: Don't start transfers when suspended Bastian Hecht
2014-07-12 11:49 ` [PATCH 4/5] i2c: sc3c2410: Remove suspension check Bastian Hecht
     [not found] ` <1405165771-8732-1-git-send-email-hechtb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-07-12 11:49   ` [PATCH 2/5] i2c: eg20t: " Bastian Hecht
2014-07-12 11:49   ` [PATCH 3/5] i2c: exynos5: " Bastian Hecht
2014-07-12 11:49   ` [PATCH 5/5] i2c: tegra: " Bastian Hecht
2014-07-17 13:00 ` [PATCH 1/5] i2c: Don't start transfers when suspended Wolfram Sang
2014-07-17 13:04   ` Wolfram Sang
2014-07-17 14:34   ` Bastian Hecht [this message]

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=CABYn4swzWs3MvADjJChO701Mao3biFemcSm-3FuB-syt91ng+A@mail.gmail.com \
    --to=hechtb-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org \
    --cc=ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=magnus.damm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=taeggyun.ko-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=tomoya.rohm-Re5JQEeQqe8AvxtiuMwx3w@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).