All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Hans de Goede <hdegoede@redhat.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>, Aditya Garg <gargaditya08@live.com>,
	Mark Gross <mgross@linux.intel.com>,
	linux-acpi@vger.kernel.org, Andy Shevchenko <andy@infradead.org>,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH 2/3] platform/x86: apple-gmux: Add apple_gmux_detect() helper
Date: Mon, 23 Jan 2023 14:49:07 +0100	[thread overview]
Message-ID: <20230123134907.GA2649@wunner.de> (raw)
In-Reply-To: <20230123113750.462144-3-hdegoede@redhat.com>

On Mon, Jan 23, 2023 at 12:37:49PM +0100, Hans de Goede wrote:
> --- a/include/linux/apple-gmux.h
> +++ b/include/linux/apple-gmux.h
[...]
> +static inline bool apple_gmux_is_indexed(unsigned long iostart)
> +{
> +	u16 val;
> +
> +	outb(0xaa, iostart + 0xcc);
> +	outb(0x55, iostart + 0xcd);
> +	outb(0x00, iostart + 0xce);
> +
> +	val = inb(iostart + 0xcc) | (inb(iostart + 0xcd) << 8);
> +	if (val == 0x55aa)
> +		return true;
> +
> +	return false;
> +}

Something like this, and especially the large apple_gmux_detect() below,
should not live in a header file.

Why can't apple_gmux.ko just export a detection function which is used
both internally and as a helper by the backlight detection?

Thanks,

Lukas

>  
>  /**
> - * apple_gmux_present() - detect if gmux is built into the machine
> + * apple_gmux_detect() - detect if gmux is built into the machine
> + *
> + * @pnp_dev:     Device to probe or NULL to use the first matching device
> + * @indexed_ret: Returns (by reference) if the gmux is indexed or not
> + *
> + * Detect if a supported gmux device is present by actually probing it.
> + * This avoids the false positives returned on some models by
> + * apple_gmux_present().
> + *
> + * Return: %true if a supported gmux ACPI device is detected and the kernel
> + * was configured with CONFIG_APPLE_GMUX, %false otherwise.
> + */
> +static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret)
> +{
> +	u8 ver_major, ver_minor, ver_release;
> +	struct resource *res;
> +	bool indexed = false;
> +
> +	if (!pnp_dev) {
> +		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;
> +
> +		pnp_dev = to_pnp_dev(dev);
> +	}
> +
> +	res = pnp_get_resource(pnp_dev, IORESOURCE_IO, 0);
> +	if (!res)
> +		return false;
> +
> +	if (resource_size(res) < GMUX_MIN_IO_LEN)
> +		return false;
> +
> +	/*
> +	 * Invalid version information may indicate either that the gmux
> +	 * device isn't present or that it's a new one that uses indexed io.
> +	 */
> +	ver_major = inb(res->start + GMUX_PORT_VERSION_MAJOR);
> +	ver_minor = inb(res->start + GMUX_PORT_VERSION_MINOR);
> +	ver_release = inb(res->start + GMUX_PORT_VERSION_RELEASE);
> +	if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) {
> +		indexed = apple_gmux_is_indexed(res->start);
> +		if (!indexed)
> +			return false;
> +	}
> +
> +	if (indexed_ret)
> +		*indexed_ret = indexed;
> +
> +	return true;
> +}
> +
> +/**
> + * apple_gmux_present() - check if gmux ACPI device is present
>   *
>   * Drivers may use this to activate quirks specific to dual GPU MacBook Pros
>   * and Mac Pros, e.g. for deferred probing, runtime pm and backlight.
>   *
> - * Return: %true if gmux is present and the kernel was configured
> + * Return: %true if gmux ACPI device is present and the kernel was configured
>   * with CONFIG_APPLE_GMUX, %false otherwise.
>   */
>  static inline bool apple_gmux_present(void)
> @@ -57,6 +133,11 @@ static inline bool apple_gmux_present(void)
>  	return false;
>  }
>  
> +static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret)
> +{
> +	return false;
> +}
> +
>  #endif /* !CONFIG_APPLE_GMUX */
>  
>  #endif /* LINUX_APPLE_GMUX_H */
> -- 
> 2.39.0

  reply	other threads:[~2023-01-23 14:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 11:37 [PATCH 0/3] ACPI: video/apple-gmux: Improve apple-gmux backlight detection Hans de Goede
2023-01-23 11:37 ` [PATCH 1/3] platform/x86: apple-gmux: Move port defines to apple-gmux.h Hans de Goede
2023-01-23 11:37 ` [PATCH 2/3] platform/x86: apple-gmux: Add apple_gmux_detect() helper Hans de Goede
2023-01-23 13:49   ` Lukas Wunner [this message]
2023-01-23 14:13     ` Hans de Goede
2023-01-23 14:23       ` Lukas Wunner
2023-01-23 15:05         ` Hans de Goede
2023-01-23 15:10           ` Hans de Goede
2023-01-23 16:35   ` Andy Shevchenko
2023-01-23 11:37 ` [PATCH 3/3] ACPI: video: Fix apple gmux detection Hans de Goede
2023-01-23 16:37   ` Andy Shevchenko
2023-01-23 17:25     ` Hans de Goede
2023-01-23 19:20   ` Rafael J. Wysocki
2023-01-23 12:09 ` [PATCH 0/3] ACPI: video/apple-gmux: Improve apple-gmux backlight detection Lukas Wunner
2023-01-23 12:38   ` Hans de Goede
2023-01-23 13:58     ` Lukas Wunner
2023-01-23 15:05       ` Hans de Goede
2023-01-23 14:53 ` Aditya Garg
2023-01-24  8:21   ` Orlando Chamberlain
2023-01-24 10:26     ` Aditya Garg

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=20230123134907.GA2649@wunner.de \
    --to=lukas@wunner.de \
    --cc=andy@infradead.org \
    --cc=gargaditya08@live.com \
    --cc=hdegoede@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=mgross@linux.intel.com \
    --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 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.