From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Linus Walleij <linusw@kernel.org>
Cc: "Kalle Valo" <kvalo@kernel.org>, "Arnd Bergmann" <arnd@arndb.de>,
"Alban Bedel" <albeu@free.fr>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Toke Høiland-Jørgensen" <toke@toke.dk>,
"Michał Kępień" <kernel@kempniu.pl>,
linux-wireless@vger.kernel.org,
brcm80211-dev-list.pdl@broadcom.com, linux-gpio@vger.kernel.org
Subject: Re: [PATCH v3] wifi: ath9k: Obtain system GPIOS from descriptors
Date: Thu, 12 Mar 2026 18:23:54 +0200 [thread overview]
Message-ID: <abLomhQ4faipjIQu@ashevche-desk.local> (raw)
In-Reply-To: <20260312-descriptors-wireless-v3-1-5230e0870c31@kernel.org>
On Thu, Mar 12, 2026 at 04:09:53PM +0100, Linus Walleij wrote:
> The ath9k has an odd use of system-wide GPIOs: if the chip
> does not have internal GPIO capability, it will try to obtain a
> GPIO line from the system GPIO controller:
>
> if (BIT(gpio) & ah->caps.gpio_mask)
> ath9k_hw_gpio_cfg_wmac(...);
> else if (AR_SREV_SOC(ah))
> ath9k_hw_gpio_cfg_soc(ah, gpio, out, label);
>
> Where ath9k_hw_gpio_cfg_soc() will attempt to issue
> gpio_request_one() passing the local GPIO number of the controller
> (0..31) to gpio_request_one().
>
> This is somewhat peculiar and possibly even dangerous: there is
> nowadays no guarantee of the numbering of these system-wide
> GPIOs, and assuming that GPIO 0..31 as used by ath9k would
> correspond to GPIOs 0..31 on the system as a whole seems a bit
> wild.
>
> Register all 32 GPIOs at index 0..31 directly in the ATH79K
> GPIO driver and associate with the NULL device (making them
> widely available) if and only if we are probing ATH79K wifi
> from the AHB bus (used for SoCs). We obtain these offsets from
> the NULL device if necessary.
>
> These GPIOs should ideally be defined in the device tree
> instead, but we have no control over that for the legacy
> code path.
>
> Testcompiled with the ath79 defconfig.
...
> +#define ATH79K_WIFI_DESCS 32
> +static int ath79_gpio_register_wifi_descriptors(struct device *dev,
> + const char *label)
> +{
> + struct gpiod_lookup_table *lookup;
> + int i;
> +
> + /* Create a gpiod lookup using gpiochip-local offsets + 1 for NULL */
> + lookup = devm_kzalloc(dev,
> + struct_size(lookup, table, ATH79K_WIFI_DESCS + 1),
> + GFP_KERNEL);
> +
Redundant blank line.
> + if (!lookup)
> + return -ENOMEM;
> +
> + /*
> + * Ugly system-wide lookup for the NULL device: we know this
> + * is already NULL but explicitly assign it here for people to
> + * know what is going on. (Yes this is an ugly legacy hack, live
> + * with it.)
> + */
> + lookup->dev_id = NULL;
> +
> + for (i = 0; i < ATH79K_WIFI_DESCS; i++) {
> + lookup->table[i] = (struct gpiod_lookup)
The macro below is already compound literal, the '(struct gpiod_lookup)'
is redundant.
> + /*
> + * Set the HW offset on the chip and the lookup
> + * index to the same value, so looking up index 0
> + * will get HW offset 0, index 1 HW offset 1 etc.
> + */
> + GPIO_LOOKUP_IDX(label, i, "ath9k", i, GPIO_ACTIVE_HIGH);
> + }
> +
> + gpiod_add_lookup_table(lookup);
> +
> + return 0;
> +}
...
> + /*
> + * Obtains a system specific GPIO descriptor from another GPIO controller.
> + * Ideally this should come from the device tree, this is a legacy code
> + * path.
> + */
> + gpiod = gpiod_get_index(NULL, "ath9k", gpio, flags);
> +
Redundant blank line.
> + if (IS_ERR(gpiod)) {
> + err = PTR_ERR(gpiod);
What about
err = PTR_ERR_OR_ZERO(...);
if (err) {
...
?
> ath_err(ath9k_hw_common(ah), "request GPIO%d failed:%d\n",
> gpio, err);
> return;
> }
...
Have you considered using software nodes instead?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-03-12 16:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 15:09 [PATCH v3] wifi: ath9k: Obtain system GPIOS from descriptors Linus Walleij
2026-03-12 16:23 ` Andy Shevchenko [this message]
2026-03-12 21:26 ` Linus Walleij
2026-03-13 8:19 ` Andy Shevchenko
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=abLomhQ4faipjIQu@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=albeu@free.fr \
--cc=arnd@arndb.de \
--cc=brcm80211-dev-list.pdl@broadcom.com \
--cc=brgl@bgdev.pl \
--cc=kernel@kempniu.pl \
--cc=kvalo@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=toke@toke.dk \
/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