Skip to contentSkip to conversation

ASoC: codecs: rk3308: add support for codec revision B

RFC PATCH In review Mizuno Miotsuki 2 participants 4 messages Sep 18 – Oct 5

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ASoC: codecs: rk3308: add support for codec revision B

Hi,

The current RK3308 internal codec driver detects codec revision B (chip ID 0x3308) but explicitly rejects it. The initial 2022 driver supported revision B with a monolithic power sequence; the later DAPM rewrite left it unsupported.

This RFC restores the revision-specific DAC output VCM/current sequence as a playback-only DAPM supply shared by HPOUT and LINEOUT. Per-channel LINEOUT events override the shared DC baseline only while LINEOUT is enabled. It does not restore the old codec-global power-on/off functions, and capture-only streams do not touch DAC_ANA_CON14/15.

The original 2022 upstream v1 selected LINEOUT_FROM_INTERNAL for revision B even for HPOUT-only playback. A newer Rockchip 6.1 downstream driver instead keeps CON15 at DC_FROM_INTERNAL for HPOUT-only and selects LINEOUT_FROM_INTERNAL only for LINEOUT or LINEOUT+HPOUT. This RFC follows the newer behaviour. Is that a hardware sequencing fix that should be preserved?

On a DFRobot UNIHIKER M10 V1.2, revision-B probe, the board MICBIAS1 route, capture/playback PCM operation, capture isolation from CON14/15, and the LINEOUT DAPM/register states were verified with the preceding clean candidate. Physical onboard microphone capture was also confirmed. A short transient at capture startup is also present with the Rockchip vendor driver unless a longer wait is added, so it is not treated as a regression and this RFC does not add a generic 250 ms mute delay.

The shared-output revision is compile-tested but was not deployed. Physical LINEOUT and HPOUT audio remain untested because suitable hardware endpoints were unavailable. In particular, the HPOUT-only CON15=0x22 choice still needs maintainer guidance or real-hardware confirmation.

The M10 microphone route, its overly broad output topology, microphone PGA controls, and capture-startup transient are deliberately kept outside this codec RFC.

Regards,
Mizuno Miotsuki

Mizuno Miotsuki (1):
ASoC: codecs: rk3308: add support for codec revision B

 sound/soc/codecs/rk3308_codec.c | 102 +++++++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 3 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

RFC PATCH 1/1 ASoC: codecs: rk3308: add support for codec revision B

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.

---
 sound/soc/codecs/rk3308_codec.c | 102 +++++++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 3 deletions(-)
sound/soc/codecs/rk3308_codec.c +99 -3
index 60befe9d37f0..8514d94d4051 100644
@@ -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;
Signature · 1 line
2.55.0
maintainer
#2 lore raw
In reply to Mizuno Miotsuki
Quoted 5 lines · Mizuno Miotsuki

Hi,

The current RK3308 internal codec driver detects codec revision B (chip ID 0x3308) but explicitly rejects it. The initial 2022 driver supported revision B with a monolithic power sequence; the later DAPM

Please don't send cover letters for single patches, if there is anything that needs saying put it in the changelog of the patch or after the --- if it's administrative stuff. This reduces mail volume and ensures that any important information is recorded in the changelog rather than being lost.

maintainer
#3 lore raw
In reply to Mizuno Miotsuki
Quoted 10 lines · Mizuno Miotsuki

ASoC: codecs: rk3308: add support for codec revision B

Hi,

The current RK3308 internal codec driver detects codec revision B (chip ID 0x3308) but explicitly rejects it. The initial 2022 driver supported revision B with a monolithic power sequence; the later DAPM rewrite left it unsupported.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/1] ASoC: codecs: rk3308: add support for codec revision B

      https://git.kernel.org/broonie/sound/c/157f7cba77a9

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark