All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Jiri Kosina <jikos@kernel.org>,
	"open list:HID CORE LAYER" <linux-input@vger.kernel.org>
Subject: Re: [PATCH 3/3] HID: multitouch: Disable event reporting on suspend when our parent is not a wakeup-source
Date: Wed, 5 May 2021 15:59:58 +0200	[thread overview]
Message-ID: <2c62d70f-4878-a286-cc78-7f6360378253@redhat.com> (raw)
In-Reply-To: <CAO-hwJLdNiKG-+YZVSZ1hPztjgCTYrmeh2qdVvropkeeRxpYAg@mail.gmail.com>

Hi,

On 5/5/21 3:40 PM, Benjamin Tissoires wrote:
> Hi Hans,
> 
> On Sat, Mar 6, 2021 at 2:37 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Disable event reporting on suspend when our parent is not
>> a wakeup-source. This should help save some extra power in
>> this case.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/hid/Kconfig          |  2 +-
>>  drivers/hid/hid-multitouch.c | 23 ++++++++++++++++++++++-
>>  2 files changed, 23 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
>> index 786b71ef7738..5cbe4adfd816 100644
>> --- a/drivers/hid/Kconfig
>> +++ b/drivers/hid/Kconfig
>> @@ -675,7 +675,7 @@ config HID_MONTEREY
>>
>>  config HID_MULTITOUCH
>>         tristate "HID Multitouch panels"
>> -       depends on HID
>> +       depends on USB_HID
> 
> I tried really hard during the past 8 years to not have a usbhid
> dependency on hid-multitouch.
> 
> The code below should not break the test suite, but still I am not
> that happy about the Kconfig change.
> 
> I don't see an immediate and better way of doing what you are
> achieving here, but maybe you have some magic I did not think about
> that would help to no pull USB_HID with HID_MULTITOUCH.
> 
> FTR, I think the use case of hid-multitouch *without* USB is rather
> non-existent, but there might be some weird systems with I2C only
> (edge computing?).

Interesting how you often manage to pick out the bits of patches
which I'm not 100% happy with myself either. I was thinking the
same thing myself.

We have this: "hid_is_using_ll_driver(hdev, &usb_hid_driver)" check
in various drivers under drivers/hid and so far the dependency fix
of adding a "depends on USB_HID" was not pretty but ok, because it
would be weird to enable those HID drivers on a system without
USB_HID being enabled. But I agree with you that hid-multitouch
is different. So I did try to come up with something better and
failed.

But now that I look at this with fresh eyes I think I see a
nice solution for this.

I propose to add a hid_is_usb_device() helper which is defined
in hid-core.c (1) and this helper would look like this:

bool hid_is_usb_device(struct hid_device *hid)
{
#if IS_ENABLED(CONFIG_USB_HID)
	return hid_is_using_ll_driver(hid, &usb_hid_driver);
#else
	return false;
#endif
}

And then I can use this helper function instead of directly doing
the hid_is_using_ll_driver() check in hid-multitouch.c fixing
this dependency ugliness.

1) hid-core.c is controlled by CONFIG_HID which gets selected at
the Kconfig level by CONFIG_USB_HID so there is no chance of
builtin vs module issues.

As an added bonus I can then also do a follow-up patch-set to
remove more depends on USB_HID stuff by switching to the helper
in other places too.

###

Unrelated but something else which I was wondering about while
working on this patch. 

I think that it might also be useful to change the
mt_parent_may_wake() helper introduced here into a generic
hid_parent_may_wakeup() helper in case we need a similar thing
in other places. I decided it may be best to do that once we
have a second driver needing such a check, but since we're
discussing this anyways, what is your opinion on this ?

Regards,

Hans



>>         help
>>           Generic support for HID multitouch panels.
>>
>> diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
>> index cfb68e443ddd..7926295bab81 100644
>> --- a/drivers/hid/hid-multitouch.c
>> +++ b/drivers/hid/hid-multitouch.c
>> @@ -1759,12 +1759,33 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
>>  }
>>
>>  #ifdef CONFIG_PM
>> +
>> +/* Check if the parent which has the power/wakeup* sysfs attributes may wake the hdev */
>> +static bool mt_parent_may_wake(struct hid_device *hdev)
>> +{
>> +       struct device *parent = hdev->dev.parent;
>> +
>> +       /*
>> +        * USB-HID is attached to the usb_interface (our parent), the
>> +        * power/wakeup* attr are part of the usb-device which is its parent.
>> +        */
>> +       if (hid_is_using_ll_driver(hdev, &usb_hid_driver) && parent)
>> +               parent = parent->parent;
>> +
>> +       if (parent)
>> +               return device_may_wakeup(parent);
>> +
>> +       /* Huh? Play it safe and keep reporting events. */
>> +       return true;
>> +}
>> +
>>  static int mt_suspend(struct hid_device *hdev, pm_message_t state)
>>  {
>>         struct mt_device *td = hid_get_drvdata(hdev);
>>
>>         /* High latency is desirable for power savings during S3/S0ix */
>> -       if (td->mtclass.quirks & MT_QUIRK_DISABLE_WAKEUP)
>> +       if ((td->mtclass.quirks & MT_QUIRK_DISABLE_WAKEUP) ||
>> +           !mt_parent_may_wake(hdev))
>>                 mt_set_modes(hdev, HID_LATENCY_HIGH, false, false);
>>         else
>>                 mt_set_modes(hdev, HID_LATENCY_HIGH, true, true);
>> --
>> 2.30.1
>>
> 


  reply	other threads:[~2021-05-05 14:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-06 13:37 [PATCH 1/3] HID: asus: Cleanup Asus T101HA keyboard-dock handling Hans de Goede
2021-03-06 13:37 ` [PATCH 2/3] HID: multitouch: Disable event reporting on suspend on the Asus T101HA touchpad Hans de Goede
2021-05-13 10:34   ` Jiri Kosina
2021-03-06 13:37 ` [PATCH 3/3] HID: multitouch: Disable event reporting on suspend when our parent is not a wakeup-source Hans de Goede
2021-05-05 13:40   ` Benjamin Tissoires
2021-05-05 13:59     ` Hans de Goede [this message]
2021-05-05 14:09       ` Benjamin Tissoires
2021-03-31  9:41 ` [PATCH 1/3] HID: asus: Cleanup Asus T101HA keyboard-dock handling Jiri Kosina
2021-05-05 12:24   ` Jiri Kosina
2021-05-05 13:36     ` Benjamin Tissoires
2021-05-13 10:33 ` Jiri Kosina

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=2c62d70f-4878-a286-cc78-7f6360378253@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.