Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-12 Thread Mika Westerberg
On Thu, Mar 12, 2015 at 08:24:53AM -0700, Doug Anderson wrote:
> Mika,
> 
> On Thu, Mar 12, 2015 at 2:10 AM, Mika Westerberg
>  wrote:
> > That's interesting. So you have an ARM device with i2c-hid compatible
> > device connected to it? Out of curiousity, do you use DT or some
> > platform board file to configure the thing?
> 
> Using DT.  That's allowed, right?  (3d7d248 HID: i2c-hid: add DT bindings)

Of course.

I was just curious because I have only seen i2c-hid devices that are
ACPI enumerated.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-12 Thread Doug Anderson
Mika,

On Thu, Mar 12, 2015 at 2:10 AM, Mika Westerberg
 wrote:
> That's interesting. So you have an ARM device with i2c-hid compatible
> device connected to it? Out of curiousity, do you use DT or some
> platform board file to configure the thing?

Using DT.  That's allowed, right?  (3d7d248 HID: i2c-hid: add DT bindings)

-Doug
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-12 Thread Mika Westerberg
On Thu, Mar 12, 2015 at 11:10:14AM +0200, Mika Westerberg wrote:
> On Wed, Mar 11, 2015 at 08:06:47AM -0700, Doug Anderson wrote:
> > Mika,
> > 
> > On Wed, Mar 11, 2015 at 4:20 AM, Mika Westerberg
> >  wrote:
> > > On Tue, Mar 10, 2015 at 09:12:36AM -0700, Doug Anderson wrote:
> > >> Thanks for testing!  Can you do a "dump_stack()" here?  I'm curious
> > >> why it's deciding to runtime resume.  Maybe something changed between
> > >> 3.14 and ToT?
> > >
> > > Here you go:
> > >
> > > [   26.711737] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime resume
> > > [   26.711754] CPU: 3 PID: 123 Comm: sh Not tainted 4.0.0-rc3+ #6
> > > [   26.711775]  88007604c600 88007ba77ae8 8183966e 
> > > 8000
> > > [   26.711791]  88017a83a020 88007ba77b08 816a0759 
> > > 88017a83a020
> > > [   26.711804]  88017a83a0ce 88007ba77b18 814ba3ee 
> > > 88007ba77b38
> > > [   26.711807] Call Trace:
> > > [   26.711835]  [] dump_stack+0x4f/0x7b
> > > [   26.711852]  [] i2c_hid_runtime_resume+0x29/0x50
> > > [   26.711866]  [] pm_generic_runtime_resume+0x2e/0x40
> > > [   26.711880]  [] acpi_subsys_runtime_resume+0x1f/0x23
> > > [   26.711892]  [] __rpm_callback+0x36/0x90
> > > [   26.711902]  [] rpm_callback+0x26/0xa0
> > > [   26.711914]  [] rpm_resume+0x496/0x670
> > > [   26.711928]  [] __pm_runtime_resume+0x40/0x60
> > > [   26.711940]  [] ? acpi_subsys_complete+0x1e/0x1e
> > > [   26.711951]  [] acpi_subsys_suspend+0x15/0x21
> > >
> > > It's the ACPI power domain that runtime resumes the device before it
> > > suspends it for system sleep.
> > 
> > OK, that explains the difference in behavior for me.  I'm on an ARM
> > board that has no ACPI, so there's no ACPI layer to runtime resume the
> > device.
> 
> That's interesting. So you have an ARM device with i2c-hid compatible
> device connected to it? Out of curiousity, do you use DT or some
> platform board file to configure the thing?
> 
> > At least it sounds like you confirmed that my patch doesn't break your
> > use case, which is good.
> 
> I actually didn't have your patch applied yet. I just wanted to verify
> that the existing code works.
> 
> Let me know and I'll run the same test with your patch applied.

I did try with the patch applied and suspend/resume worked just fine.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-12 Thread Mika Westerberg
On Wed, Mar 11, 2015 at 08:06:47AM -0700, Doug Anderson wrote:
> Mika,
> 
> On Wed, Mar 11, 2015 at 4:20 AM, Mika Westerberg
>  wrote:
> > On Tue, Mar 10, 2015 at 09:12:36AM -0700, Doug Anderson wrote:
> >> Thanks for testing!  Can you do a "dump_stack()" here?  I'm curious
> >> why it's deciding to runtime resume.  Maybe something changed between
> >> 3.14 and ToT?
> >
> > Here you go:
> >
> > [   26.711737] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime resume
> > [   26.711754] CPU: 3 PID: 123 Comm: sh Not tainted 4.0.0-rc3+ #6
> > [   26.711775]  88007604c600 88007ba77ae8 8183966e 
> > 8000
> > [   26.711791]  88017a83a020 88007ba77b08 816a0759 
> > 88017a83a020
> > [   26.711804]  88017a83a0ce 88007ba77b18 814ba3ee 
> > 88007ba77b38
> > [   26.711807] Call Trace:
> > [   26.711835]  [] dump_stack+0x4f/0x7b
> > [   26.711852]  [] i2c_hid_runtime_resume+0x29/0x50
> > [   26.711866]  [] pm_generic_runtime_resume+0x2e/0x40
> > [   26.711880]  [] acpi_subsys_runtime_resume+0x1f/0x23
> > [   26.711892]  [] __rpm_callback+0x36/0x90
> > [   26.711902]  [] rpm_callback+0x26/0xa0
> > [   26.711914]  [] rpm_resume+0x496/0x670
> > [   26.711928]  [] __pm_runtime_resume+0x40/0x60
> > [   26.711940]  [] ? acpi_subsys_complete+0x1e/0x1e
> > [   26.711951]  [] acpi_subsys_suspend+0x15/0x21
> >
> > It's the ACPI power domain that runtime resumes the device before it
> > suspends it for system sleep.
> 
> OK, that explains the difference in behavior for me.  I'm on an ARM
> board that has no ACPI, so there's no ACPI layer to runtime resume the
> device.

That's interesting. So you have an ARM device with i2c-hid compatible
device connected to it? Out of curiousity, do you use DT or some
platform board file to configure the thing?

> At least it sounds like you confirmed that my patch doesn't break your
> use case, which is good.

I actually didn't have your patch applied yet. I just wanted to verify
that the existing code works.

Let me know and I'll run the same test with your patch applied.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-11 Thread Doug Anderson
Mika,

On Wed, Mar 11, 2015 at 4:20 AM, Mika Westerberg
 wrote:
> On Tue, Mar 10, 2015 at 09:12:36AM -0700, Doug Anderson wrote:
>> Thanks for testing!  Can you do a "dump_stack()" here?  I'm curious
>> why it's deciding to runtime resume.  Maybe something changed between
>> 3.14 and ToT?
>
> Here you go:
>
> [   26.711737] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime resume
> [   26.711754] CPU: 3 PID: 123 Comm: sh Not tainted 4.0.0-rc3+ #6
> [   26.711775]  88007604c600 88007ba77ae8 8183966e 
> 8000
> [   26.711791]  88017a83a020 88007ba77b08 816a0759 
> 88017a83a020
> [   26.711804]  88017a83a0ce 88007ba77b18 814ba3ee 
> 88007ba77b38
> [   26.711807] Call Trace:
> [   26.711835]  [] dump_stack+0x4f/0x7b
> [   26.711852]  [] i2c_hid_runtime_resume+0x29/0x50
> [   26.711866]  [] pm_generic_runtime_resume+0x2e/0x40
> [   26.711880]  [] acpi_subsys_runtime_resume+0x1f/0x23
> [   26.711892]  [] __rpm_callback+0x36/0x90
> [   26.711902]  [] rpm_callback+0x26/0xa0
> [   26.711914]  [] rpm_resume+0x496/0x670
> [   26.711928]  [] __pm_runtime_resume+0x40/0x60
> [   26.711940]  [] ? acpi_subsys_complete+0x1e/0x1e
> [   26.711951]  [] acpi_subsys_suspend+0x15/0x21
>
> It's the ACPI power domain that runtime resumes the device before it
> suspends it for system sleep.

OK, that explains the difference in behavior for me.  I'm on an ARM
board that has no ACPI, so there's no ACPI layer to runtime resume the
device.

At least it sounds like you confirmed that my patch doesn't break your
use case, which is good.  If folks want to wait until I can reproduce
this problem on ToT Linux before merging then I guess we can let this
patch float until I can manage to get enough other bits of the system
happy with mainline.

Thanks for your tests!  :)

-Doug
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-11 Thread Mika Westerberg
On Tue, Mar 10, 2015 at 09:12:36AM -0700, Doug Anderson wrote:
> Thanks for testing!  Can you do a "dump_stack()" here?  I'm curious
> why it's deciding to runtime resume.  Maybe something changed between
> 3.14 and ToT?

Here you go:

[   26.711737] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime resume
[   26.711754] CPU: 3 PID: 123 Comm: sh Not tainted 4.0.0-rc3+ #6
[   26.711775]  88007604c600 88007ba77ae8 8183966e 
8000
[   26.711791]  88017a83a020 88007ba77b08 816a0759 
88017a83a020
[   26.711804]  88017a83a0ce 88007ba77b18 814ba3ee 
88007ba77b38
[   26.711807] Call Trace:
[   26.711835]  [] dump_stack+0x4f/0x7b
[   26.711852]  [] i2c_hid_runtime_resume+0x29/0x50
[   26.711866]  [] pm_generic_runtime_resume+0x2e/0x40
[   26.711880]  [] acpi_subsys_runtime_resume+0x1f/0x23
[   26.711892]  [] __rpm_callback+0x36/0x90
[   26.711902]  [] rpm_callback+0x26/0xa0
[   26.711914]  [] rpm_resume+0x496/0x670
[   26.711928]  [] __pm_runtime_resume+0x40/0x60
[   26.711940]  [] ? acpi_subsys_complete+0x1e/0x1e
[   26.711951]  [] acpi_subsys_suspend+0x15/0x21

It's the ACPI power domain that runtime resumes the device before it
suspends it for system sleep.

[   26.711964]  [] dpm_run_callback+0x4c/0x150
[   26.711978]  [] __device_suspend+0xee/0x320
[   26.711991]  [] dpm_suspend+0x68/0x300
[   26.712004]  [] dpm_suspend_start+0x5f/0x70
[   26.712019]  [] suspend_devices_and_enter+0xbf/0x7d0
[   26.712035]  [] ? vprintk_default+0x1f/0x30
[   26.712047]  [] pm_suspend+0x3b9/0x4e0
[   26.712059]  [] state_store+0x80/0x100
[   26.712074]  [] kobj_attr_store+0xf/0x20
[   26.712087]  [] sysfs_kf_write+0x3a/0x50
[   26.712098]  [] kernfs_fop_write+0x127/0x180
[   26.712112]  [] vfs_write+0xb7/0x200
[   26.712124]  [] SyS_write+0x46/0xc0
[   26.712140]  [] ia32_do_call+0x13/0x13
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-10 Thread Doug Anderson
Mika,

On Tue, Mar 10, 2015 at 5:23 AM, Mika Westerberg
 wrote:
> On Mon, Mar 09, 2015 at 12:44:47PM -0700, Doug Anderson wrote:
>> If the i2c-hid device was runtime suspended and then the system
>> suspended itself we'd end up disabling interrupts twice (in
>> i2c_hid_runtime_suspend and i2c_hid_suspend) and not reenabling them
>> until later when the i2c-hid device was runtime resumed.
>> Unfortunately the i2c_hid_resume() calls i2c_hid_hwreset() and that
>> only works properly if interrupts are enabled.
>>
>> We can fix this by taking the advice from "runtime_pm.txt".
>> Specifically we'll change i2c-hid to always resume to full power.
>> This only works if our parents are also resumed to full power, but
>> given the suggestion in "runtime_pm.txt" this seems a reasonable
>> assumption.
>>
>> Signed-off-by: Doug Anderson 
>> ---
>> Note that this was tested on a 3.14 kernel with backports.  Any
>> testing that folks can do on ToT is appreciated.
>>
>> Changes in v2:
>> - Move pm_runtime_enable() higher in resume
>
> Hmm, I tried on one machine with Atmel touch panel. I modified i2c-hid.c
> a bit to print out when it is running suspend/resume hooks. Here is what
> I got:
>
>   [7.506455] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime suspend
>
> This is the initialization and after that the device is runtime
> suspended.
>
> Now I put the machine to system sleep (using echo mem >
> /sys/power/state):
>
>   [   26.988867] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime resume

Thanks for testing!  Can you do a "dump_stack()" here?  I'm curious
why it's deciding to runtime resume.  Maybe something changed between
3.14 and ToT?

>   [   27.002957] i2c_hid i2c-ATML1000:00: PM: i2c-hid suspend
>
> So the PM core will kick the device out of runtime suspend before it
> suspends it again.
>
> Pressing power button will resume the device:
>
>   [   28.238934] i2c_hid i2c-ATML1000:00: PM: i2c-hid resume
>   [   29.941579] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime suspend
>
> and since the device is not being used, it will runtime suspend itself.
>
> In other words, I'm not sure if this patch is needed. It would be good
> if you could do similar testing using mainline kernel (if possible at
> all).

Unfortunately it's not so easy.  For my platform suspend/resume is
just barely functional as it is, but then I'm on a board that's
further not supported upstream.

If folks upstream can't reproduce the problems then there's no reason
to take my patch...

-Doug
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended

2015-03-10 Thread Mika Westerberg
On Mon, Mar 09, 2015 at 12:44:47PM -0700, Doug Anderson wrote:
> If the i2c-hid device was runtime suspended and then the system
> suspended itself we'd end up disabling interrupts twice (in
> i2c_hid_runtime_suspend and i2c_hid_suspend) and not reenabling them
> until later when the i2c-hid device was runtime resumed.
> Unfortunately the i2c_hid_resume() calls i2c_hid_hwreset() and that
> only works properly if interrupts are enabled.
> 
> We can fix this by taking the advice from "runtime_pm.txt".
> Specifically we'll change i2c-hid to always resume to full power.
> This only works if our parents are also resumed to full power, but
> given the suggestion in "runtime_pm.txt" this seems a reasonable
> assumption.
> 
> Signed-off-by: Doug Anderson 
> ---
> Note that this was tested on a 3.14 kernel with backports.  Any
> testing that folks can do on ToT is appreciated.
> 
> Changes in v2:
> - Move pm_runtime_enable() higher in resume

Hmm, I tried on one machine with Atmel touch panel. I modified i2c-hid.c
a bit to print out when it is running suspend/resume hooks. Here is what
I got:

  [7.506455] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime suspend

This is the initialization and after that the device is runtime
suspended.

Now I put the machine to system sleep (using echo mem >
/sys/power/state):

  [   26.988867] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime resume
  [   27.002957] i2c_hid i2c-ATML1000:00: PM: i2c-hid suspend

So the PM core will kick the device out of runtime suspend before it
suspends it again.

Pressing power button will resume the device:

  [   28.238934] i2c_hid i2c-ATML1000:00: PM: i2c-hid resume
  [   29.941579] i2c_hid i2c-ATML1000:00: PM: i2c-hid runtime suspend

and since the device is not being used, it will runtime suspend itself.

In other words, I'm not sure if this patch is needed. It would be good
if you could do similar testing using mainline kernel (if possible at
all).
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/