Re: [PATCH 1/9] platform/x86: asus-wmi: add support for 2024 ROG Mini-LED

From: Luke Jones
Date: Tue Mar 26 2024 - 23:01:52 EST


On Wed, 27 Mar 2024, at 12:49 AM, Ilpo Järvinen wrote:
> On Tue, 26 Mar 2024, Luke Jones wrote:
> > On Tue, 26 Mar 2024, at 2:47 AM, Ilpo Järvinen wrote:
> > > On Mon, 25 Mar 2024, Luke D. Jones wrote:
> > >
> > > > Support the 2024 mini-led backlight and adjust the related functions
> > > > to select the relevant dev-id. Also add `available_mini_led_mode` to the
> > > > platform sysfs since the available mini-led levels can be different.
> > > >
> > > > Signed-off-by: Luke D. Jones <luke@xxxxxxxxxx>
> > > > ---
>
> > > > @@ -2109,10 +2110,27 @@ static ssize_t mini_led_mode_show(struct device *dev,
> > > > struct asus_wmi *asus = dev_get_drvdata(dev);
> > > > int result;
> > > >
> > > > - result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_MINI_LED_MODE);
> > > > - if (result < 0)
> > > > - return result;
> > > > + result = asus_wmi_get_devstate_simple(asus, asus->mini_led_dev_id);
> > > >
> > > > + /* Remap the mode values to match previous generation mini-led.
> > > > + * Some BIOSes return -19 instead of 2, which is "mini-LED off", this
> > > > + * appears to be a BIOS bug.
> > > > + */
> > > > + if (asus->mini_led_dev_id == ASUS_WMI_DEVID_MINI_LED_MODE2) {
> > > > + switch (result) {
> > > > + case 0:
> > > > + result = 1;
> > > > + break;
> > > > + case 1:
> > > > + result = 2;
> > > > + break;
> > > > + case 2:
> > > > + case -19:
> > >
> > > Can you confirm this -19 really does come from BIOS? Because I suspect
> > > it's -ENODEV error code from from one of the functions on the driver side
> > > (which is why I asked you to change it into -ENODEV).
> >
> > Yes it does. It is rather annoying. What happens in this case is that
> > `2` is written to the WMI endpoint to turn off the MINI-Led feature,
> > this works fine and it is turned off, there are no errors from the write
> > at all - verifying the accepted limits in dsdt also shows it is correct.
> >
> > However, after that, the read fails once.
>
> Hi,
>
> I'm left a bit unsure how to interpret your response. If "read fails", it
> would indicate that -ENODEV originates from asus_wmi_evaluate_method3(),
> asus_wmi_get_devstate() or asus_wmi_get_devstate_bits(), not from BIOS? So
> which way it is?
>
> After reading some more code, I think I figured out the answer myself.
> However, that raises another question... So lets now take a step back and
> walk through the code:
>
> Your patch does:
> result = asus_wmi_get_devstate_simple(asus, asus->mini_led_dev_id);
>
> asus_wmi_get_devstate_simple() calls asus_wmi_get_devstate_bits() with
> ASUS_WMI_DSTS_STATUS_BIT mask that is 0x00000001.
>
> If there's no error, retval is masked with that ASUS_WMI_DSTS_STATUS_BIT
> forcing the return value to 0-1 range so:
>
> a) I don't think -19 can originate from BIOS but comes from kernel side.
> b) How can it ever return 2 (mini-LED off) ?????

You're right. *facepalm* *grumble*. Honestly if I were getting paid for this work I'd invest a bit more time in it and catch these silly little things myself.

I'll update the code with all feedback, including using a more appropriate WMI function whcih I really should have seen on my own.

Thank you for your time so far.