[RFC PATCH 0/1] Use native gpiolib inversion for jack gpios
This patch changes the logic used for jack gpio state inversion to utilize gpiolib inversion.
Previously the gpio active state would not correspond to the plugged-in state of the jack. Since the active state of a gpio is usually defined by its purpose in a specific application I'd expect the active state to represent the jacks plug status.
However, judging by the users [1], [2] of snd_soc_jack_add_gpiods the ACPI tables of some devices seem to indicate the "wrong" polarity for their jack detect gpios. I'm not entirely sure how to deal with those devices. At the moment I'd vote for inverting the gpio active level again (via gpiod_toggle_active_low) inside snd_soc_jack_add_gpios if gpio->gpiod_dev != NULL and gpio->invert is set.
I'm not entirely sure about [3] either. In my opinion removing invert = 1 from ams_delta_hook_switch_gpios and adding GPIO_ACTIVE_LOW to the flags of hook_switch in [4] would be the right move here.
What are your thoughts on this?
Best regards,
Tobias
[1] /sound/soc/intel/boards/byt-max98090.c [2] /sound/soc/intel/boards/cht_bsw_max98090_ti.c [3] /sound/soc/ti/ams-delta.c [4] /arch/arm/mach-omap1/board-ams-delta.c
Tobias Schramm (1): ASoC: jack: use gpiolib inversion flag for inverted gpios
sound/soc/soc-jack.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
This commit changes the handling of jack gpios with ACTIVE_LOW logic. The inversion flag is now passed down and transparently handled by the legacy gpiolib.
Previously the level of a gpio was inverted manually inside snd_soc_jack_gpio_detect and gpiolib ACTIVE_LOW flag was not set on the gpio. This resulted in erroneous output in /dev/class/gpio/gpio*/active_low and debug interfaces like /sys/kernel/debug/gpio where the gpio was still listed as active high while jack status for that gpio actually followed an active low logic.
Signed-off-by: Tobias Schramm t.schramm@manjaro.org --- sound/soc/soc-jack.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index b5748dcd490f..8c17cfdbb883 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -254,8 +254,6 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio) int report;
enable = gpiod_get_value_cansleep(gpio->desc); - if (gpio->invert) - enable = !enable;
if (enable) report = gpio->report; @@ -385,6 +383,10 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, } } else { /* legacy GPIO number */ + int flags = GPIOF_IN; + + if (gpios[i].invert) + flags |= GPIOF_ACTIVE_LOW; if (!gpio_is_valid(gpios[i].gpio)) { dev_err(jack->card->dev, "ASoC: Invalid gpio %d\n", @@ -393,7 +395,7 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, goto undo; }
- ret = gpio_request_one(gpios[i].gpio, GPIOF_IN, + ret = gpio_request_one(gpios[i].gpio, flags, gpios[i].name); if (ret) goto undo;
participants (1)
-
Tobias Schramm