mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mizuno Miotsuki <founder@crepuse.com>
To: Luca Ceresoli <luca.ceresoli@bootlin.com>,
	Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Heiko Stuebner <heiko@sntech.de>,
	"linux-sound@vger.kernel.org" <linux-sound@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-rockchip@lists.infradead.org"
	<linux-rockchip@lists.infradead.org>
Subject: [RFC PATCH 1/1] ASoC: codecs: rk3308: add support for codec revision B
Date: Fri, 18 Sep 2026 12:57:19 +0000	[thread overview]
Message-ID: <20260918125711.94361-2-founder@crepuse.com> (raw)
In-Reply-To: <20260918125711.94361-1-founder@crepuse.com>

The RK3308 codec driver detects codec revision B (chip ID 0x3308),
but currently rejects it during probe. Revision B needs an additional
DAC output VCM charge and depop sequence using DAC_ANA_CON14 and
DAC_ANA_CON15.

Model the shared revision-B DAC output VCM as a playback-only DAPM
supply used by both HPOUT and LINEOUT. Charge the reference while both
CON15 channels are connected to VCM, then establish DC_FROM_INTERNAL as
the playback baseline. LINEOUT events switch each enabled channel to
LINEOUT_FROM_INTERNAL after its output driver is enabled and return it
to DC_FROM_INTERNAL after disable. When the last analogue output powers
down, return both channels to VCM and disable the shared reference.

All new register writes are conditional on codec revision B.
Capture-only streams do not traverse the new supply, so they do not
touch DAC_ANA_CON14 or DAC_ANA_CON15. Revisions A and C gain no
additional MMIO writes.

For HPOUT-only playback, keep CON15 at DC_FROM_INTERNAL, matching the
newer Rockchip 6.1 downstream driver. Physical HPOUT validation is still
needed.

Tested on a DFRobot UNIHIKER M10 V1.2 with codec revision B.
Revision-B probe, the board MICBIAS1 route, and physical onboard
microphone capture passed. A short capture-startup transient is also
present with the Rockchip vendor driver unless a longer wait is added,
so it is not treated as a regression and no generic 250 ms mute delay is
added here. Capture-only isolation from DAC_ANA_CON14/15 and playback
PCM, DAPM, and LINEOUT register endpoints were verified with the
preceding clean LINEOUT-only candidate. The shared-output revision is
compile-tested only. Physical LINEOUT and HPOUT audio were not tested
because suitable hardware endpoints were unavailable.

Signed-off-by: Mizuno Miotsuki <founder@crepuse.com>
---
 sound/soc/codecs/rk3308_codec.c | 102 +++++++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/rk3308_codec.c b/sound/soc/codecs/rk3308_codec.c
index 60befe9d37f0..8514d94d4051 100644
--- a/sound/soc/codecs/rk3308_codec.c
+++ b/sound/soc/codecs/rk3308_codec.c
@@ -192,6 +192,90 @@ static int rk3308_codec_pop_sound_set(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int rk3308_codec_dac_output_vcm_event(struct snd_soc_dapm_widget *w,
+					     struct snd_kcontrol *kcontrol,
+					     int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+	struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component);
+	unsigned int val;
+
+	if (rk3308->codec_ver != ACODEC_VERSION_B)
+		return 0;
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		/* Keep the DAC outputs at VCM while their reference is charged. */
+		regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15,
+				   RK3308_DAC_LINEOUT_POP_SOUND_L_MSK |
+				   RK3308_DAC_LINEOUT_POP_SOUND_R_MSK,
+				   RK3308_DAC_L_SEL_DC_FROM_VCM |
+				   RK3308_DAC_R_SEL_DC_FROM_VCM);
+		regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14,
+				   RK3308_DAC_CURRENT_CHARGE_MSK, 1);
+		regmap_set_bits(rk3308->regmap, RK3308_DAC_ANA_CON14,
+				RK3308_DAC_VCM_LINEOUT_EN);
+		for (val = 1; val <= 0xf; val++) {
+			regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14,
+					   RK3308_DAC_CURRENT_CHARGE_MSK, val);
+			usleep_range(200, 400);
+		}
+		msleep(20);
+		break;
+	case SND_SOC_DAPM_POST_PMU:
+		regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15,
+				   RK3308_DAC_LINEOUT_POP_SOUND_L_MSK |
+				   RK3308_DAC_LINEOUT_POP_SOUND_R_MSK,
+				   RK3308_DAC_L_SEL_DC_FROM_INTERNAL |
+				   RK3308_DAC_R_SEL_DC_FROM_INTERNAL);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15,
+				   RK3308_DAC_LINEOUT_POP_SOUND_L_MSK |
+				   RK3308_DAC_LINEOUT_POP_SOUND_R_MSK,
+				   RK3308_DAC_L_SEL_DC_FROM_VCM |
+				   RK3308_DAC_R_SEL_DC_FROM_VCM);
+		regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON14,
+				   RK3308_DAC_CURRENT_CHARGE_MSK, 1);
+		regmap_clear_bits(rk3308->regmap, RK3308_DAC_ANA_CON14,
+				  RK3308_DAC_VCM_LINEOUT_EN);
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+static int rk3308_codec_lineout_event(struct snd_soc_dapm_widget *w,
+				      struct snd_kcontrol *kcontrol,
+				      int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+	struct rk3308_codec_priv *rk3308 = snd_soc_component_get_drvdata(component);
+	unsigned int mask = RK3308_DAC_LINEOUT_POP_SOUND_L_MSK << w->shift;
+	unsigned int val;
+
+	if (rk3308->codec_ver != ACODEC_VERSION_B)
+		return 0;
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		val = RK3308_DAC_L_SEL_LINEOUT_FROM_INTERNAL << w->shift;
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		val = RK3308_DAC_L_SEL_DC_FROM_INTERNAL << w->shift;
+		break;
+	default:
+		return 0;
+	}
+
+	regmap_update_bits(rk3308->regmap, RK3308_DAC_ANA_CON15, mask, val);
+	usleep_range(20, 40);
+
+	return 0;
+}
+
 static const struct snd_soc_dapm_widget rk3308_codec_dapm_widgets[] = {
 	SND_SOC_DAPM_INPUT("MIC1"),
 	SND_SOC_DAPM_INPUT("MIC2"),
@@ -322,6 +406,10 @@ static const struct snd_soc_dapm_widget rk3308_codec_dapm_widgets[] = {
 	SND_SOC_DAPM_OUT_DRV_E("HPOUT_POP_SOUND_R", SND_SOC_NOPM, 4, 0, NULL, 0,
 			       rk3308_codec_pop_sound_set,
 			       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
+	SND_SOC_DAPM_SUPPLY("DAC_OUTPUT_VCM", SND_SOC_NOPM, 0, 0,
+			    rk3308_codec_dac_output_vcm_event,
+			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+			    SND_SOC_DAPM_POST_PMD),
 	SND_SOC_DAPM_OUT_DRV("L_HPOUT_EN", RK3308_DAC_ANA_CON03, 1, 0, NULL, 0),
 	SND_SOC_DAPM_OUT_DRV("R_HPOUT_EN", RK3308_DAC_ANA_CON03, 5, 0, NULL, 0),
 	SND_SOC_DAPM_OUT_DRV("L_HPOUT_WORK", RK3308_DAC_ANA_CON03, 2, 0, NULL, 0),
@@ -329,8 +417,12 @@ static const struct snd_soc_dapm_widget rk3308_codec_dapm_widgets[] = {
 	SND_SOC_DAPM_OUTPUT("HPOUT_L"),
 	SND_SOC_DAPM_OUTPUT("HPOUT_R"),
 
-	SND_SOC_DAPM_OUT_DRV("L_LINEOUT_EN", RK3308_DAC_ANA_CON04, 0, 0, NULL, 0),
-	SND_SOC_DAPM_OUT_DRV("R_LINEOUT_EN", RK3308_DAC_ANA_CON04, 4, 0, NULL, 0),
+	SND_SOC_DAPM_OUT_DRV_E("L_LINEOUT_EN", RK3308_DAC_ANA_CON04, 0, 0,
+			       NULL, 0, rk3308_codec_lineout_event,
+			       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+	SND_SOC_DAPM_OUT_DRV_E("R_LINEOUT_EN", RK3308_DAC_ANA_CON04, 4, 0,
+			       NULL, 0, rk3308_codec_lineout_event,
+			       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
 	SND_SOC_DAPM_OUTPUT("LINEOUT_L"),
 	SND_SOC_DAPM_OUTPUT("LINEOUT_R"),
 };
@@ -466,6 +558,8 @@ static const struct snd_soc_dapm_route rk3308_codec_dapm_routes[] = {
 	{ "HPOUT_R", NULL, "DAC_BUF_REF_R" },
 	{ "L_HPOUT_EN", NULL, "DAC_L_HPMIX_SEL" },
 	{ "R_HPOUT_EN", NULL, "DAC_R_HPMIX_SEL" },
+	{ "L_HPOUT_EN", NULL, "DAC_OUTPUT_VCM" },
+	{ "R_HPOUT_EN", NULL, "DAC_OUTPUT_VCM" },
 	{ "L_HPOUT_WORK", NULL, "L_HPOUT_EN" },
 	{ "R_HPOUT_WORK", NULL, "R_HPOUT_EN" },
 	{ "HPOUT_POP_SOUND_L", NULL, "L_HPOUT_WORK" },
@@ -475,6 +569,8 @@ static const struct snd_soc_dapm_route rk3308_codec_dapm_routes[] = {
 
 	{ "L_LINEOUT_EN", NULL, "DAC_L_HPMIX_SEL" },
 	{ "R_LINEOUT_EN", NULL, "DAC_R_HPMIX_SEL" },
+	{ "L_LINEOUT_EN", NULL, "DAC_OUTPUT_VCM" },
+	{ "R_LINEOUT_EN", NULL, "DAC_OUTPUT_VCM" },
 	{ "LINEOUT_L", NULL, "L_LINEOUT_EN" },
 	{ "LINEOUT_R", NULL, "R_LINEOUT_EN" },
 };
@@ -855,7 +951,7 @@ static int rk3308_codec_get_version(struct rk3308_codec_priv *rk3308)
 		break;
 	case 0x3308:
 		rk3308->codec_ver = ACODEC_VERSION_B;
-		return dev_err_probe(rk3308->dev, -EINVAL, "Chip version B not supported\n");
+		break;
 	case 0x3308c:
 		rk3308->codec_ver = ACODEC_VERSION_C;
 		break;
-- 
2.55.0


  reply	other threads:[~2026-09-18 12:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 12:57 [RFC PATCH 0/1] " Mizuno Miotsuki
2026-09-18 12:57 ` Mizuno Miotsuki [this message]
2026-09-18 12:58 ` 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=20260918125711.94361-2-founder@crepuse.com \
    --to=founder@crepuse.com \
    --cc=broonie@kernel.org \
    --cc=heiko@sntech.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=perex@perex.cz \
    --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 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®