public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
	linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org,
	Aditya Garg <gargaditya08@live.com>
Subject: Re: [PATCH] ACPI: video: Fix Apple GMUX backlight detection
Date: Thu, 15 Dec 2022 11:50:14 +0100	[thread overview]
Message-ID: <86820d40-cb99-76c7-c0c9-d1b6e1c8f053@redhat.com> (raw)
In-Reply-To: <20221215102211.GA5147@wunner.de>

Hi Lukas,

On 12/15/22 11:22, Lukas Wunner wrote:
> On Thu, Dec 15, 2022 at 10:41:38AM +0100, Hans de Goede wrote:
>> The apple-gmux driver only binds to old GMUX devices which have an
>> IORESOURCE_IO resource (using inb()/outb()) rather then memory-mapped
>> IO (IORESOURCE_MEM).
>>
>> T2 MacBooks use the new style GMUX devices (with IORESOURCE_MEM access),
>> so these are not supported by the apple-gmux driver. This is not a problem
>> since they have working ACPI video backlight support.
> 
> Interesting.
> 
> 
>> +static bool apple_gmux_backlight_present(void)
>> +{
>> +	struct acpi_device *adev;
>> +	struct device *dev;
>> +
>> +	adev = acpi_dev_get_first_match_dev(GMUX_ACPI_HID, NULL, -1);
>> +	if (!adev)
>> +		return false;
>> +
>> +	dev = acpi_get_first_physical_node(adev);
>> +	if (!dev)
>> +		return false;
>> +
>> +	/*
>> +	 * drivers/platform/x86/apple-gmux.c only supports old style
>> +	 * Apple GMUX with an IO-resource.
>> +	 */
>> +	return pnp_get_resource(to_pnp_dev(dev), IORESOURCE_IO, 0) != NULL;
>> +}
> 
> The T2 is represented by a PCI device with ID 106B:1802.
> 
> Instead of the above, how about amending apple_gmux_present()
> with a simple check like this:
> 
> 	/* T2 Macs drive GMUX via MMIO, which is unsupported for now */
> 	if (pci_dev_present({{PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x1802)}, {}}))
> 		return false;

Where ever possible I prefer to have the same checks in video_detect.c
as the actual backlight driver uses and:

drivers/platform/x86/apple-gmux.c

refuses to bind because the pnp_get_resource(to_pnp_dev(dev), IORESOURCE_IO, 0)
call fails. So IMHO it is better to do the same thing in video_detect.c .

Specifically likely more then 1 model of MacBook is affected and doing
the same check as apple-gmux.c does will catch them all, while an
(PCI) id based approach often turns into a game of whack-a-mole.

Also changing apple_gmux_present() itself impacts more callers then
just the drivers/acpi_video_detect.c code.

Specifically drivers/gpu/drm/nouveau/nouveau_backlight.c and
drivers/gpu/vga/vga_switcheroo.c also call this function.

And at least in the nouveau case where the check looks like this:

        if (apple_gmux_present()) {
                NV_INFO_ONCE(drm, "Apple GMUX detected: not registering Nouveau backlight interface\n");
                return 0;
        }

Not registering the GPU/native backlight device is the right thing to
do on the models with the new GMUX too, since native backlight control
won't work there either.

And I don't know about the check in vga_switcheroo.c. The goal of this
patch is to fix the 6.1 regression introduced by adding
a apple_gmux_present() to video_acpi.c and in its current form it
fixes that regression without introducing any behavioral changes
elsewhere, which seems best for a regressions fix which is intended
to be backported to 6.1 .

Regards,

Hans


p.s.

The nouveau driver not registering its native backlight is actually something
which the amdgpu driver gets wrong, it registers a non working amdgpu_bl0 on
the laptop Aditya ran their tests on. Starting with 6.2 however amdgpu will
honor the return value of acpi_video_get_backlight_type()
(on x86/ACPI platforms).

So the non working amdgpu_bl0 should disappear with 6.2, as long as we get
acpi_video_get_backlight_type() to return the right type, which it does after
this patch (it returns acpi_backlight_video after this patch).


  reply	other threads:[~2022-12-15 10:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15  9:41 [PATCH] ACPI: video: Fix Apple GMUX backlight detection Hans de Goede
2022-12-15 10:22 ` Lukas Wunner
2022-12-15 10:50   ` Hans de Goede [this message]
2022-12-22 16:44 ` Rafael J. Wysocki

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=86820d40-cb99-76c7-c0c9-d1b6e1c8f053@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=gargaditya08@live.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox