linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] Use native gpiolib inversion for jack gpios
@ 2020-03-08  3:13 Tobias Schramm
  2020-03-08  3:13 ` [RFC PATCH 1/1] ASoC: jack: use gpiolib inversion flag for inverted gpios Tobias Schramm
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Schramm @ 2020-03-08  3:13 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai
  Cc: Liam Girdwood, alsa-devel, linux-kernel, Tobias Schramm

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(-)

-- 
2.24.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [RFC PATCH 1/1] ASoC: jack: use gpiolib inversion flag for inverted gpios
  2020-03-08  3:13 [RFC PATCH 0/1] Use native gpiolib inversion for jack gpios Tobias Schramm
@ 2020-03-08  3:13 ` Tobias Schramm
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Schramm @ 2020-03-08  3:13 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai
  Cc: Liam Girdwood, alsa-devel, linux-kernel, Tobias Schramm

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;
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-08  3:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-08  3:13 [RFC PATCH 0/1] Use native gpiolib inversion for jack gpios Tobias Schramm
2020-03-08  3:13 ` [RFC PATCH 1/1] ASoC: jack: use gpiolib inversion flag for inverted gpios Tobias Schramm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).