All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>
To: Oder Chiou <oder_chiou@realtek.com>, Mark Brown <broonie@kernel.org>
Cc: "Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
	"Cezary Rojewski" <cezary.rojewski@intel.com>,
	alsa-devel@alsa-project.org, "Takashi Iwai" <tiwai@suse.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>
Subject: [PATCH 07/11] ASoC: codecs: rt274: Enable irq only when needed
Date: Thu,  9 Jun 2022 15:35:37 +0200	[thread overview]
Message-ID: <20220609133541.3984886-8-amadeuszx.slawinski@linux.intel.com> (raw)
In-Reply-To: <20220609133541.3984886-1-amadeuszx.slawinski@linux.intel.com>

Interrupt is only needed when jack detection is enabled, so enable it
then, similarly disable it when jack detection is being disabled.

Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
---
 sound/soc/codecs/rt274.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/rt274.c b/sound/soc/codecs/rt274.c
index 144a6f775c21..730de9452333 100644
--- a/sound/soc/codecs/rt274.c
+++ b/sound/soc/codecs/rt274.c
@@ -16,6 +16,7 @@
 #include <linux/spi/spi.h>
 #include <linux/dmi.h>
 #include <linux/acpi.h>
+#include <linux/irq.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -395,28 +396,42 @@ static void rt274_jack_detect_work(struct work_struct *work)
 		SND_JACK_MICROPHONE | SND_JACK_HEADPHONE);
 }
 
-static irqreturn_t rt274_irq(int irq, void *data);
-
 static int rt274_mic_detect(struct snd_soc_component *component,
 	struct snd_soc_jack *jack,  void *data)
 {
 	struct rt274_priv *rt274 = snd_soc_component_get_drvdata(component);
+	bool mic = false;
+	bool hp = false;
+	int status = 0;
+	int ret;
 
 	rt274->jack = jack;
 
 	if (jack == NULL) {
 		/* Disable jack detection */
+		disable_irq(rt274->i2c->irq);
 		regmap_update_bits(rt274->regmap, RT274_EAPD_GPIO_IRQ_CTRL,
 					RT274_IRQ_EN, RT274_IRQ_DIS);
 
 		return 0;
 	}
 
+	/* Enable jack detection */
 	regmap_update_bits(rt274->regmap, RT274_EAPD_GPIO_IRQ_CTRL,
 				RT274_IRQ_EN, RT274_IRQ_EN);
+	enable_irq(rt274->i2c->irq);
 
 	/* Send an initial report */
-	rt274_irq(0, rt274);
+	ret = rt274_jack_detect(rt274, &hp, &mic);
+	if (!ret) {
+		if (hp)
+			status |= SND_JACK_HEADPHONE;
+
+		if (mic)
+			status |= SND_JACK_MICROPHONE;
+
+		snd_soc_jack_report(rt274->jack, status, SND_JACK_MICROPHONE | SND_JACK_HEADPHONE);
+	}
 
 	return 0;
 }
@@ -984,6 +999,9 @@ static int rt274_probe(struct snd_soc_component *component)
 	INIT_DELAYED_WORK(&rt274->jack_detect_work, rt274_jack_detect_work);
 
 	if (rt274->i2c->irq) {
+		/* irq will be enabled in rt274_mic_detect */
+		irq_set_status_flags(rt274->i2c->irq, IRQ_NOAUTOEN);
+
 		ret = request_threaded_irq(rt274->i2c->irq, NULL, rt274_irq,
 					   IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "rt274", rt274);
 		if (ret) {
-- 
2.25.1


  parent reply	other threads:[~2022-06-09 13:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09 13:35 [PATCH 00/11] ASoC: codecs: Series of fixes for realtek codecs used on RVPs Amadeusz Sławiński
2022-06-09 13:35 ` [PATCH 01/11] ASoC: codecs: rt274: Always init jack_detect_work Amadeusz Sławiński
2022-06-09 13:35 ` [PATCH 02/11] ASoC: codecs: rt286: Reorganize jack detect handling Amadeusz Sławiński
2022-06-09 13:35 ` [PATCH 03/11] ASoC: codecs: rt298: " Amadeusz Sławiński
2022-06-09 13:35 ` [PATCH 04/11] ASoC: codecs: rt274: Move irq registration and cleanup Amadeusz Sławiński
2022-06-09 14:17   ` Mark Brown
2022-06-09 13:35 ` [PATCH 05/11] ASoC: codecs: rt286: " Amadeusz Sławiński
2022-06-09 13:35 ` [PATCH 06/11] ASoC: codecs: rt298: " Amadeusz Sławiński
2022-06-09 13:35 ` Amadeusz Sławiński [this message]
2022-06-09 14:18   ` [PATCH 07/11] ASoC: codecs: rt274: Enable irq only when needed Mark Brown
2022-06-10  9:33     ` Amadeusz Sławiński
2022-06-10 10:38       ` Mark Brown
2022-06-23 13:53     ` Amadeusz Sławiński
2022-06-23 14:23       ` Mark Brown
2022-06-09 13:35 ` [PATCH 08/11] ASoC: codecs: rt286: " Amadeusz Sławiński
2022-06-09 13:35 ` [PATCH 09/11] ASoC: codecs: rt298: " Amadeusz Sławiński
2022-06-09 13:35 ` [PATCH 10/11] ASoC: codecs: rt298: Fix NULL jack in interrupt Amadeusz Sławiński
2022-06-09 14:19   ` Mark Brown
2022-06-09 13:35 ` [PATCH 11/11] ASoC: codecs: rt298: Fix jack detection Amadeusz Sławiński
2022-06-09 14:55   ` Mark Brown
2022-06-10  9:46     ` Amadeusz Sławiński
2022-06-10 12:25       ` Mark Brown
2022-06-10 15:58 ` (subset) [PATCH 00/11] ASoC: codecs: Series of fixes for realtek codecs used on RVPs Mark Brown

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=20220609133541.3984886-8-amadeuszx.slawinski@linux.intel.com \
    --to=amadeuszx.slawinski@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=oder_chiou@realtek.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=tiwai@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.