All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: <alsa-devel@alsa-project.org>, <patches@opensource.cirrus.com>,
	<linux-kernel@vger.kernel.org>,
	Stefan Binding <sbinding@opensource.cirrus.com>
Subject: [PATCH 1/2] ALSA: hda/cs8409: Ensure Type Detection is only run on startup when necessary
Date: Fri, 27 Aug 2021 12:02:51 +0100	[thread overview]
Message-ID: <20210827110252.5361-1-vitalyr@opensource.cirrus.com> (raw)

From: Stefan Binding <sbinding@opensource.cirrus.com>

Type Detection should only be run after init and when the controls have been
built. There is no need to run it multiple times.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
---
 sound/pci/hda/patch_cs8409.c | 34 ++++++++++++++++++++++++++++------
 sound/pci/hda/patch_cs8409.h |  2 ++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/sound/pci/hda/patch_cs8409.c b/sound/pci/hda/patch_cs8409.c
index 9db16b6292f4..805441b7bf86 100644
--- a/sound/pci/hda/patch_cs8409.c
+++ b/sound/pci/hda/patch_cs8409.c
@@ -784,6 +784,8 @@ static void cs42l42_suspend(struct sub_codec *cs42l42)
 	cs8409_i2c_write(cs42l42, 0x1102, 0x9C);
 	cs42l42->suspended = 1;
 	cs42l42->last_page = 0;
+	cs42l42->hp_jack_in = 0;
+	cs42l42->mic_jack_in = 0;
 
 	/* Put CS42L42 into Reset */
 	gpio_data = snd_hda_codec_read(codec, CS8409_PIN_AFG, 0, AC_VERB_GET_GPIO_DATA, 0);
@@ -852,6 +854,8 @@ static int cs8409_cs42l42_suspend(struct hda_codec *codec)
 	struct cs8409_spec *spec = codec->spec;
 	int i;
 
+	spec->init_done = 0;
+
 	cs8409_enable_ur(codec, 0);
 
 	for (i = 0; i < spec->num_scodecs; i++)
@@ -1025,14 +1029,21 @@ void cs8409_cs42l42_fixups(struct hda_codec *codec, const struct hda_fixup *fix,
 		break;
 	case HDA_FIXUP_ACT_INIT:
 		cs8409_cs42l42_hw_init(codec);
-		fallthrough;
+		spec->init_done = 1;
+		if (spec->init_done && spec->build_ctrl_done
+			&& !spec->scodecs[CS8409_CODEC0]->hp_jack_in)
+			cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
+		break;
 	case HDA_FIXUP_ACT_BUILD:
+		spec->build_ctrl_done = 1;
 		/* Run jack auto detect first time on boot
 		 * after controls have been added, to check if jack has
 		 * been already plugged in.
 		 * Run immediately after init.
 		 */
-		cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
+		if (spec->init_done && spec->build_ctrl_done
+			&& !spec->scodecs[CS8409_CODEC0]->hp_jack_in)
+			cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
 		break;
 	default:
 		break;
@@ -1223,16 +1234,27 @@ void dolphin_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int ac
 		break;
 	case HDA_FIXUP_ACT_INIT:
 		dolphin_hw_init(codec);
-		fallthrough;
+		spec->init_done = 1;
+		if (spec->init_done && spec->build_ctrl_done) {
+			for (i = 0; i < spec->num_scodecs; i++) {
+				if (!spec->scodecs[i]->hp_jack_in)
+					cs42l42_run_jack_detect(spec->scodecs[i]);
+			}
+		}
+		break;
 	case HDA_FIXUP_ACT_BUILD:
+		spec->build_ctrl_done = 1;
 		/* Run jack auto detect first time on boot
 		 * after controls have been added, to check if jack has
 		 * been already plugged in.
 		 * Run immediately after init.
 		 */
-		for (i = 0; i < spec->num_scodecs; i++)
-			cs42l42_run_jack_detect(spec->scodecs[i]);
-
+		if (spec->init_done && spec->build_ctrl_done) {
+			for (i = 0; i < spec->num_scodecs; i++) {
+				if (!spec->scodecs[i]->hp_jack_in)
+					cs42l42_run_jack_detect(spec->scodecs[i]);
+			}
+		}
 		break;
 	default:
 		break;
diff --git a/sound/pci/hda/patch_cs8409.h b/sound/pci/hda/patch_cs8409.h
index 207315ad5bf6..ade2b838590c 100644
--- a/sound/pci/hda/patch_cs8409.h
+++ b/sound/pci/hda/patch_cs8409.h
@@ -333,6 +333,8 @@ struct cs8409_spec {
 
 	unsigned int playback_started:1;
 	unsigned int capture_started:1;
+	unsigned int init_done:1;
+	unsigned int build_ctrl_done:1;
 
 	/* verb exec op override */
 	int (*exec_verb)(struct hdac_device *dev, unsigned int cmd, unsigned int flags,
-- 
2.25.1


WARNING: multiple messages have this Message-ID (diff)
From: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org,
	Stefan Binding <sbinding@opensource.cirrus.com>
Subject: [PATCH 1/2] ALSA: hda/cs8409: Ensure Type Detection is only run on startup when necessary
Date: Fri, 27 Aug 2021 12:02:51 +0100	[thread overview]
Message-ID: <20210827110252.5361-1-vitalyr@opensource.cirrus.com> (raw)

From: Stefan Binding <sbinding@opensource.cirrus.com>

Type Detection should only be run after init and when the controls have been
built. There is no need to run it multiple times.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
---
 sound/pci/hda/patch_cs8409.c | 34 ++++++++++++++++++++++++++++------
 sound/pci/hda/patch_cs8409.h |  2 ++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/sound/pci/hda/patch_cs8409.c b/sound/pci/hda/patch_cs8409.c
index 9db16b6292f4..805441b7bf86 100644
--- a/sound/pci/hda/patch_cs8409.c
+++ b/sound/pci/hda/patch_cs8409.c
@@ -784,6 +784,8 @@ static void cs42l42_suspend(struct sub_codec *cs42l42)
 	cs8409_i2c_write(cs42l42, 0x1102, 0x9C);
 	cs42l42->suspended = 1;
 	cs42l42->last_page = 0;
+	cs42l42->hp_jack_in = 0;
+	cs42l42->mic_jack_in = 0;
 
 	/* Put CS42L42 into Reset */
 	gpio_data = snd_hda_codec_read(codec, CS8409_PIN_AFG, 0, AC_VERB_GET_GPIO_DATA, 0);
@@ -852,6 +854,8 @@ static int cs8409_cs42l42_suspend(struct hda_codec *codec)
 	struct cs8409_spec *spec = codec->spec;
 	int i;
 
+	spec->init_done = 0;
+
 	cs8409_enable_ur(codec, 0);
 
 	for (i = 0; i < spec->num_scodecs; i++)
@@ -1025,14 +1029,21 @@ void cs8409_cs42l42_fixups(struct hda_codec *codec, const struct hda_fixup *fix,
 		break;
 	case HDA_FIXUP_ACT_INIT:
 		cs8409_cs42l42_hw_init(codec);
-		fallthrough;
+		spec->init_done = 1;
+		if (spec->init_done && spec->build_ctrl_done
+			&& !spec->scodecs[CS8409_CODEC0]->hp_jack_in)
+			cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
+		break;
 	case HDA_FIXUP_ACT_BUILD:
+		spec->build_ctrl_done = 1;
 		/* Run jack auto detect first time on boot
 		 * after controls have been added, to check if jack has
 		 * been already plugged in.
 		 * Run immediately after init.
 		 */
-		cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
+		if (spec->init_done && spec->build_ctrl_done
+			&& !spec->scodecs[CS8409_CODEC0]->hp_jack_in)
+			cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
 		break;
 	default:
 		break;
@@ -1223,16 +1234,27 @@ void dolphin_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int ac
 		break;
 	case HDA_FIXUP_ACT_INIT:
 		dolphin_hw_init(codec);
-		fallthrough;
+		spec->init_done = 1;
+		if (spec->init_done && spec->build_ctrl_done) {
+			for (i = 0; i < spec->num_scodecs; i++) {
+				if (!spec->scodecs[i]->hp_jack_in)
+					cs42l42_run_jack_detect(spec->scodecs[i]);
+			}
+		}
+		break;
 	case HDA_FIXUP_ACT_BUILD:
+		spec->build_ctrl_done = 1;
 		/* Run jack auto detect first time on boot
 		 * after controls have been added, to check if jack has
 		 * been already plugged in.
 		 * Run immediately after init.
 		 */
-		for (i = 0; i < spec->num_scodecs; i++)
-			cs42l42_run_jack_detect(spec->scodecs[i]);
-
+		if (spec->init_done && spec->build_ctrl_done) {
+			for (i = 0; i < spec->num_scodecs; i++) {
+				if (!spec->scodecs[i]->hp_jack_in)
+					cs42l42_run_jack_detect(spec->scodecs[i]);
+			}
+		}
 		break;
 	default:
 		break;
diff --git a/sound/pci/hda/patch_cs8409.h b/sound/pci/hda/patch_cs8409.h
index 207315ad5bf6..ade2b838590c 100644
--- a/sound/pci/hda/patch_cs8409.h
+++ b/sound/pci/hda/patch_cs8409.h
@@ -333,6 +333,8 @@ struct cs8409_spec {
 
 	unsigned int playback_started:1;
 	unsigned int capture_started:1;
+	unsigned int init_done:1;
+	unsigned int build_ctrl_done:1;
 
 	/* verb exec op override */
 	int (*exec_verb)(struct hdac_device *dev, unsigned int cmd, unsigned int flags,
-- 
2.25.1


             reply	other threads:[~2021-08-27 11:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 11:02 Vitaly Rodionov [this message]
2021-08-27 11:02 ` [PATCH 1/2] ALSA: hda/cs8409: Ensure Type Detection is only run on startup when necessary Vitaly Rodionov
2021-08-27 11:02 ` [PATCH 2/2] ALSA: hda/cs8409: Initialize Codec only in init fixup Vitaly Rodionov
2021-08-27 11:02   ` Vitaly Rodionov
2021-08-27 20:37   ` Takashi Iwai
2021-08-27 20:37     ` Takashi Iwai
2021-08-27 20:37 ` [PATCH 1/2] ALSA: hda/cs8409: Ensure Type Detection is only run on startup when necessary Takashi Iwai
2021-08-27 20:37   ` Takashi Iwai

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=20210827110252.5361-1-vitalyr@opensource.cirrus.com \
    --to=vitalyr@opensource.cirrus.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=sbinding@opensource.cirrus.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.