Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Laurentiu Mihalcea" <laurentiumihalcea111@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 1/3] ASoC: wm8962: implement GPIO .get callback
Date: Fri, 27 Nov 2026 17:22:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-237987@kernel.org> (raw)
In-Reply-To: <20261127170039.663-2-laurentiumihalcea111@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ASoC: wm8962: missing direction_input callback on
  wm8962_template_chip
- [Medium] ASoC: wm8962: wm8962_gpio_get() rejects valid output pins
  GPIO2 and GPIO3
--

commit b87e152ac0d0fb816585617c6713e1d54f3b94a7
Author: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>

ASoC: wm8962: implement GPIO .get callback

This commit implements the .get callback for the WM8962 gpio_chip to support
reading the logic level of GPIO5 and GPIO6.

> diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
> index 1832685aca40d..7122d93a742c5 100644
> --- a/sound/soc/codecs/wm8962.c
> +++ b/sound/soc/codecs/wm8962.c
> @@ -3505,12 +3505,63 @@ static int wm8962_gpio_direction_out(struct gpio_chip *chip,
>  	return 0;
>  }
>  
> +/*
> + * If your input pins have debouncing enabled, then make sure DBCLK is enabled
> + * before using this function! Otherwise, the value returned by this function
> + * may not be correct!
> + *
> + * TODO: can we work around this limitation by force enabling SYSCLK before
> + * attempting to read the pin's state? Is SYSCLK's source clock guaranteed
> + * to be configured by the time this function is called?
> + */
> +static int wm8962_gpio_get(struct gpio_chip *chip, unsigned int offset)
> +{
> +	struct wm8962_priv *wm8962 = gpiochip_get_data(chip);
> +	struct snd_soc_component *component = wm8962->component;
> +	unsigned int val;
> +	int ret;
> +
> +	/*
> +	 * only GPIO5/GPIO6 can be used as inputs! Note the difference between the GPIO
> +	 * index and the register offset.
> +	 */
> +	if (offset != 4 && offset != 5) {
> +		dev_err(component->dev, "Only GPIO5/GPIO6 can be used as inputs!\n");
> +		return -EINVAL;
> +	}

[Severity: Medium]
Should wm8962_gpio_get() also accept output pins GPIO2 (offset 1) and GPIO3
(offset 2)?

gpiolib calls .get() on requested output lines too, such as from
gpiolib_dbg_show() when reading /sys/kernel/debug/gpio or when querying an
output's state via gpiod_get_value_cansleep().  WM8962_GPIO_2 and
WM8962_GPIO_3 are readable registers and expose WM8962_GP2_LVL and
WM8962_GP3_LVL at bit 6 just like GPIO5 and GPIO6, so rejecting offsets 1
and 2 here breaks output value readback and logs a dev_err() whenever
/sys/kernel/debug/gpio is read while GPIO2 or GPIO3 is requested.

> +
> +	/*
> +	 * we are forced to resume the device and bypass the regmap cache for the
> +	 * read operation. This is because the GPIO level could change at any time.
> +	 * Remember that the GPIO registers are still marked as cacheable. This is
> +	 * because the configuration bits and the GPIO LVL bits share the same registers.
> +	 */
> +	ret = pm_runtime_resume_and_get(component->dev);
> +	if (ret < 0) {
> +		dev_err(component->dev, "Failed to resume device: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = regmap_read_bypassed(component->regmap, WM8962_GPIO_BASE + offset, &val);
> +	if (ret < 0) {
> +		dev_err(component->dev, "Failed to read GP%d_LVL: %d\n", offset + 1, ret);
> +		pm_runtime_put(component->dev);
> +		return ret;
> +	}
> +
> +	pm_runtime_put(component->dev);
> +
> +	/* mask is intentional! We (ab)use the fact that GPn_LVL fields share the same mask */
> +	return (val & WM8962_GP5_LVL) >> WM8962_GP5_LVL_SHIFT;
> +}
> +
>  static const struct gpio_chip wm8962_template_chip = {
>  	.label			= "wm8962",
>  	.owner			= THIS_MODULE,
>  	.request		= wm8962_gpio_request,
>  	.direction_output	= wm8962_gpio_direction_out,
>  	.set			= wm8962_gpio_set,
> +	.get			= wm8962_gpio_get,
>  	.can_sleep		= 1,
>  };

[Severity: Medium]
Does wm8962_template_chip also need a .direction_input (and .get_direction)
callback to support GPIO5 and GPIO6 as inputs?

When both .get_direction and .direction_input are NULL,
gpiochip_add_data_with_key() marks every line with GPIOD_FLAG_IS_OUT at
registration time, even though GPIO5 and GPIO6 default to inputs in hardware,
causing consumers that request them with GPIOD_ASIS or lock them as IRQs via
gpiochip_lock_as_irq() to fail with -EIO.  In addition,
gpiod_direction_input_nonotify() becomes a software-only flag clear when both
callbacks are absent:

drivers/gpio/gpiolib.c:gpiod_direction_input_nonotify() {
    ...
	if (guard.gc->direction_input) {
		ret = gpiochip_direction_input(guard.gc,
					       gpiod_hwgpio(desc));
	} else if (guard.gc->get_direction) {
		dir = gpiochip_get_direction(guard.gc, gpiod_hwgpio(desc));
    ...
	}
	if (ret == 0) {
		clear_bit(GPIOD_FLAG_IS_OUT, &desc->flags);
		ret = gpio_set_bias(desc);
	}
}

As a result, calling gpiod_direction_input() on GPIO5 or GPIO6 never sets
WM8962_GP5_DIR or WM8962_GP6_DIR in hardware if the pin was previously driven
as an output, and requesting output-only pins GPIO2 or GPIO3 with GPIOD_IN
silently succeeds instead of returning -EINVAL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127170039.663-1-laurentiumihalcea111@gmail.com?part=1

  reply	other threads:[~2026-11-27 17:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 17:00 [PATCH 0/3] ASoC: wm8962: make GPIO-based HP detection work Laurentiu Mihalcea
2026-11-27 17:00 ` [PATCH 1/3] ASoC: wm8962: implement GPIO .get callback Laurentiu Mihalcea
2026-11-27 17:22   ` sashiko-bot [this message]
2026-11-27 17:00 ` [PATCH 2/3] ASoC: wm8962: add GPIO interrupt controller support Laurentiu Mihalcea
2026-11-27 17:36   ` sashiko-bot
2026-11-27 17:00 ` [PATCH 3/3] ASoC: wm8962: fix interrupt mis-firing during runtime_resume() Laurentiu Mihalcea
2026-11-27 17:30   ` sashiko-bot

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=sashiko-outbox-237987@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=laurentiumihalcea111@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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