From: Laurentiu Mihalcea <laurentiumihalcea111@gmail.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>,
elena.popa@nxp.com, cosmin.stoica@nxp.com
Cc: patches@opensource.cirrus.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] ASoC: wm8962: implement GPIO .get callback
Date: Fri, 27 Nov 2026 19:00:37 +0200 [thread overview]
Message-ID: <20261127170039.663-2-laurentiumihalcea111@gmail.com> (raw)
In-Reply-To: <20261127170039.663-1-laurentiumihalcea111@gmail.com>
From: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
The WM8962 codec provides two GPIO pins: GPIO5 and GPIO6, which can be
used as inputs. Implement the GPIO .get callback to allow consumers to
make use of them.
One important detail to remember is that the get() callback will not
function correctly if the input pins have debouncing enabled and DBCLK
is not enabled. In particular, for MR-NAVQ95 where GPIO5 is used for
headphone detection (LOW = unplugged, HIGH = plugged), what would happen
is the get() function would always return 0 even if the headphones were
plugged in. This would happen whenever DBCLK wasn't enabled (or, rather,
when SYSCLK wasn't enabled since DBCLK should be enabled automatically).
We might be able to get around the aforementioned limitation by force
enabling SYSCLK before reading the pin's state. See TODO from the code.
Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
---
sound/soc/codecs/wm8962.c | 51 +++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 1832685aca40..7122d93a742c 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;
+ }
+
+ /*
+ * 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,
};
--
2.53.0
next prev parent reply other threads:[~2026-11-27 17:06 UTC|newest]
Thread overview: 4+ 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 ` Laurentiu Mihalcea [this message]
2026-11-27 17:00 ` [PATCH 2/3] ASoC: wm8962: add GPIO interrupt controller support Laurentiu Mihalcea
2026-11-27 17:00 ` [PATCH 3/3] ASoC: wm8962: fix interrupt mis-firing during runtime_resume() Laurentiu Mihalcea
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=20261127170039.663-2-laurentiumihalcea111@gmail.com \
--to=laurentiumihalcea111@gmail.com \
--cc=broonie@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=cosmin.stoica@nxp.com \
--cc=elena.popa@nxp.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=sebastian.krzyszkowiak@puri.sm \
/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
all inboxes | Powered by JetHome®