Re: [PATCH 3/3] pinctrl: amd: Add a quirk for Lenovo Ideapad 5

From: Mario Limonciello
Date: Thu Aug 31 2023 - 13:53:53 EST


On 8/30/2023 11:18, Hans de Goede wrote:
Hi,

On 8/30/23 17:47, Mario Limonciello wrote:
On 8/30/2023 10:37, Hans de Goede wrote:
Hi,

On 8/29/23 23:37, Mario Limonciello wrote:
On 8/29/2023 14:54, Hans de Goede wrote:
Hi Mario,

On 8/29/23 18:56, Mario Limonciello wrote:
Lenovo ideapad 5 doesn't use interrupts for GPIO 0, and so internally
debouncing with WinBlue debounce behavior means that the GPIO doesn't
clear until a separate GPIO is used (such as touchpad).

Prefer to use legacy debouncing to avoid problems.

Reported-by: Luca Pigliacampo <lucapgl2001@xxxxxxxxx>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217833
Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx>

I'm not happy to see yet another DMI quirk solution here.

and I guess you're not happy with this either...

Yeah I was really hoping the first patch was enough for the issue.

If we can't come up with anything else we can potentially drop patches 2 and 3. Even patch 1 alone will "significantly" improve the situation.

The other option I considered is to hardcode WinBlue debounce behavior "off" in Linux.

I don't think this is a good idea though though because we will likely trade bugs because the debounce values in the AML for systems using _AEI aren't actually used in Windows and might not have good values.

What if we turn off the WinBlue debounce behavior for GPIO0 and then just hardcode some sane debounce values for it, overriding whatever the DSDT _AEI entries contain ?


I don't think this is a good idea.

Some vendors GPIO0 doesn't connect to the power button but instead to the EC.  If it's connected to the EC, the EC might instead trigger GPIO0 for lid or power button or whatever they decided for a design specific way.

I'd worry that we're going to end up with inconsistent results if they have their own debouncing put in place in the EC *because* they were relying upon the Winblue debounce behavior.

After all - this was fixed because of https://bugzilla.kernel.org/show_bug.cgi?id=217315

Ok, that is fair.


Are we sure there is no other way? Did you check an acpidump
for the laptop and specifically for its ACPI powerbutton handling?

I'm not sure there is another way or not, but yes there is an acpidump attached to the bug in case you or anyone else has some ideas.


I would expect the ACPI powerbutton handler to somehow clear
the bit, like how patch 1/3 clears it from the GPIO chip's
own IRQ handler.

I see that drivers/acpi/button.c does:

static u32 acpi_button_event(void *data)
{
          acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_button_notify_run, data);
          return ACPI_INTERRUPT_HANDLED;
}

So unless I'm misreading something here, there is some AML being
executed on power-button events. So maybe there is something wrong
with how Linux interprets that AML ?

The relevant ACPI spec section is here:

https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/04_ACPI_Hardware_Specification/ACPI_Hardware_Specification.html#control-method-power-button

I did look at the acpidump.  GPE 08 notifies \_SB.PWRB (a PNP0C0C device) with 0x2.  According to the spec this is specifically for letting the system know the power button is waking up the system from G1.

Sorry, the acpi_os_execute() function name gave me the impression that this would actually call some ACPI defined function, since normally in acpi speak execute refers to an ACPI table defined method.

But that is not the case here it is just a wrapper to deferred-exec the passed in function pointer.

To be clear I was hoping that there was an ACPI defined (AML code) function which would maybe clear the GPIO for us and that that was maybe not working due to e.g. some opregion not being implemented by Linux. But no AML code is being executed at all, so this is all a red herring.

Regards,

Hans



Something we could do is add an extra callback for ACPI button driver to call the GPIO controller IRQ handler.  Worst case the IRQ handler does nothing, best case it fixes this issue.
I'm not sure how we'd tie it to something spec compliant.

I was actually thinking the same thing. I think we should discuss going this route
(ACPI button driver to call the GPIO controller IRQ handler) with Rafael.

We can use the existing acpi_notifier_call_chain() mechanism and:

1. Have the button code call acpi_notifier_call_chain() on the PNP0C0C
event on button presses.

2. Have the AMD pinctrl driver register a notifier_block with
register_acpi_notifier() and then check if the source is a PNP0C0C
device based on the device_class of the acpi_bus_event struct
passed to the notifier and if it is check if GPIO0 needs
clearing.

I think this is preferable over the DMI quirk route, because this should
fix the same issue also on other affected models which we don't know
about.


Linus - please disregard version 1.

I provided Luca a new series that implements this approach that Hans and I discussed and they confirmed it works.

I have some minor modifications to it to narrow where it's applied so we don't have needless notifications and will send it for review after the new modifications are tested as well.