Skip to contentSkip to conversation

Add mediatek codec mt6359 driver

PATCH Superseded Jiaxin Yu 3 participants 10 messages Aug 10, 2020 – Aug 14, 2020

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jiaxin Yu

author
#0 lore raw

v2 cover Add mediatek codec mt6359 driver

Add mediatek codec (MT6359) driver

MT6359 support playback and capture feature.

On downlink path, it includes three DACs for handset, headset, and lineout path. On unlink path, it includeds three ADCs for main mic, second mic, 3rd mic, and headset mic.

By scenario, select *_MUX widget to create damp path. And by select mic_type_mux to choose DMIC/AMIC/....

For example, select these MUX widget to create headset path
(1) DAC In Mux --> "Normal Path"
(2) HPL Mux --> "Audio Playback"
(3) HPR Mux --> "Audio Playback"

v2 changes:
1. Move playback_gpio/capture_gpio to the machine driver.
2. Fix mic_type(ACC/DMIC/DCC/DCC_*) at init stage.
3. Move devm_regulor_get to mt6359_platform_driver_probe.
4. Add relulator_disable in remove function.
5. Use stereo controls to the volume control.
6. Use SOC_ENUM_SINGLE_DECL instead of SOC_VALUE_ENUM_SINGLE_DECL.
7. Cleanup unused code.

v1 changes:

	1.lkml link:
		https://lkml.org/lkml/2020/3/5/1257

Jiaxin Yu (2):
ASoC: mediatek: mt6359: add codec driver
dt-bindings: mediatek: mt6359: add codec document

 .../devicetree/bindings/sound/mt6359.yaml          |   68 +
 sound/soc/codecs/Kconfig                           |    8 +
 sound/soc/codecs/Makefile                          |    2 +
 sound/soc/codecs/mt6359.c                          | 2966 ++++++++++++++++++++
 sound/soc/codecs/mt6359.h                          | 2653 +++++++++++++++++
 5 files changed, 5697 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt6359.yaml
 create mode 100644 sound/soc/codecs/mt6359.c
 create mode 100644 sound/soc/codecs/mt6359.h
Signature · 1 line
1.8.1.1.dirty
author
#9 lore raw

PATCH v2 2/2 dt-bindings: mediatek: mt6359: add codec document

This patch adds MediaTek MT6359 codec document.

---
 .../devicetree/bindings/sound/mt6359.yaml          | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt6359.yaml
Documentation/devicetree/bindings/sound/mt6359.yaml new file +68 -0
new file mode 100644
index 0000000..cd59dbe
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/mt6359.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek MT6359 Codec Device Tree Bindings
+
+maintainers:
+  - Eason Yen <[email protected]>
+  - Jiaxin Yu <[email protected]>
+  - Shane Chien <[email protected]>
+
+description: |
+  The communication between MT6359 and SoC is through Mediatek PMIC wrapper.
+  For more detail, please visit Mediatek PMIC wrapper documentation.
+  Must be a child node of PMIC wrapper.
+
+properties:
+  compatible:
+    const: mediatek,mt6359-sound
+
+  mediatek,dmic-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Indicates how many data pins are used to transmit two channels of PDM
+      signal. 0 means two wires, 1 means one wire. Default value is 0.
+    enum:
+      - 0 # one wire
+      - 1 # two wires
+
+  mediatek,mic-type-0:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Specifies the type of mic type connected to adc0
+
+    enum:
+      - 0 # IDLE - mic in turn-off status
+      - 1 # ACC - analog mic with alternating coupling
+      - 2 # DMIC - digital mic
+      - 3 # DCC - analog mic with direct couping
+      - 4 # DCC_ECM_DIFF - analog electret condenser mic with differential mode
+      - 5 # DCC_ECM_SINGLE - analog electret condenser mic with single mode
+
+  mediatek,mic-type-1:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Specifies the type of mic type connected to adc1
+
+  mediatek,mic-type-2:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Specifies the type of mic type connected to adc2
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+    mt6359codec: mt6359codec {
+      compatible = "mediatek,mt6359-sound";
+      mediatek,dmic-mode = <0>;
+      mediatek,mic-type-0 = <2>;
+    };
+
+...
Signature · 1 line
1.8.1.1.dirty
author
#1 lore raw

PATCH v2 1/2 ASoC: mediatek: mt6359: add codec driver

In reply to Jiaxin Yu

Add the mt6359 codec driver.

---
 sound/soc/codecs/Kconfig  |    8 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/mt6359.c | 2966 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/mt6359.h | 2653 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 5629 insertions(+)
 create mode 100644 sound/soc/codecs/mt6359.c
 create mode 100644 sound/soc/codecs/mt6359.h
sound/soc/codecs/Kconfig +8 -0
index 946a702..e6c71ca 100644
@@ -127,6 +127,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_ML26124
 	imply SND_SOC_MT6351
 	imply SND_SOC_MT6358
+	imply SND_SOC_MT6359
 	imply SND_SOC_MT6660
 	imply SND_SOC_NAU8540
 	imply SND_SOC_NAU8810
@@ -1724,6 +1725,13 @@ config SND_SOC_MT6358
 	  Enable support for the platform which uses MT6358 as
 	  external codec device.
 
+config SND_SOC_MT6359
+	tristate "MediaTek MT6359 Codec"
+	depends on MTK_PMIC_WRAP
+	help
+	  Enable support for the platform which uses MT6359 as
+	  external codec device.
+
 config SND_SOC_MT6660
 	tristate "Mediatek MT6660 Speaker Amplifier"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 0140c60..9a3f58c 100644
@@ -126,6 +126,7 @@ snd-soc-msm8916-analog-objs := msm8916-wcd-analog.o
 snd-soc-msm8916-digital-objs := msm8916-wcd-digital.o
 snd-soc-mt6351-objs := mt6351.o
 snd-soc-mt6358-objs := mt6358.o
+snd-soc-mt6359-objs := mt6359.o
 snd-soc-mt6660-objs := mt6660.o
 snd-soc-nau8540-objs := nau8540.o
 snd-soc-nau8810-objs := nau8810.o
@@ -431,6 +432,7 @@ obj-$(CONFIG_SND_SOC_MSM8916_WCD_ANALOG) +=snd-soc-msm8916-analog.o
 obj-$(CONFIG_SND_SOC_MSM8916_WCD_DIGITAL) +=snd-soc-msm8916-digital.o
 obj-$(CONFIG_SND_SOC_MT6351)	+= snd-soc-mt6351.o
 obj-$(CONFIG_SND_SOC_MT6358)	+= snd-soc-mt6358.o
+obj-$(CONFIG_SND_SOC_MT6359)	+= snd-soc-mt6359.o
 obj-$(CONFIG_SND_SOC_MT6660)	+= snd-soc-mt6660.o
 obj-$(CONFIG_SND_SOC_NAU8540)   += snd-soc-nau8540.o
 obj-$(CONFIG_SND_SOC_NAU8810)   += snd-soc-nau8810.o
sound/soc/codecs/mt6359.c new file +2966 -0

2,966 lines not on this page · raw message

sound/soc/codecs/mt6359.h new file +2653 -0

2,653 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 5 lines
1.8.1.1.dirty
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

Part of the diff is not shown here. View the raw message.

maintainer
#3 lore raw

Re: [PATCH v2 1/2] ASoC: mediatek: mt6359: add codec driver

In reply to Jiaxin Yu

sound/soc/codecs/mt6359.c line 76

Quoted 13 lines · Jiaxin Yu
sound/soc/codecs/mt6359.c new file +10 -0
+void mt6359_set_playback_gpio(struct snd_soc_component *cmpnt)
+{
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
 
+void mt6359_reset_playback_gpio(struct snd_soc_component *cmpnt)
+{
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
 
+void mt6359_set_capture_gpio(struct snd_soc_component *cmpnt)
+{
 
+void mt6359_reset_capture_gpio(struct snd_soc_component *cmpnt)
+{

What are these, should they not be managed through gpiolib and/or pinctrl?

sound/soc/codecs/mt6359.c line 102

Quoted 7 lines
sound/soc/codecs/mt6359.c new file +7 -0
+/* use only when doing mtkaif calibraiton at the boot time */
+static int mt6359_set_dcxo(struct mt6359_priv *priv, bool enable)
+{
+	regmap_update_bits(priv->regmap, MT6359_DCXO_CW12,
+			   0x1 << RG_XO_AUDIO_EN_M_SFT,
+			   (enable ? 1 : 0) << RG_XO_AUDIO_EN_M_SFT);
+	return 0;

Either don't have a return value or use the result of regmap_update_bits(). There's similar issues with some other functions in here.

sound/soc/codecs/mt6359.c line 221

Quoted 4 lines
sound/soc/codecs/mt6359.c new file +3 -0
+int mt6359_mtkaif_calibration_enable(struct snd_soc_pcm_runtime *rtd)
+{
 
+EXPORT_SYMBOL_GPL(mt6359_mtkaif_calibration_enable);

Why is this exported?

sound/soc/codecs/mt6359.c line 301

Quoted 7 lines
sound/soc/codecs/mt6359.c new file +7 -0
+static void hp_aux_feedback_loop_gain_ramp(struct mt6359_priv *priv, bool up)
+{
+	int i = 0, stage = 0;
+
+	/* Reduce HP aux feedback loop gain step by step */
+	for (i = 0; i <= 0xf; i++) {
+		stage = up ? i : 0xf - i;

Please write normal conditional statements, it helps legibility.

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+static int mt6359_put_volsw(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+			snd_soc_kcontrol_component(kcontrol);

sound/soc/codecs/mt6359.c line 423

Quoted 10 lines
sound/soc/codecs/mt6359.c new file +10 -0
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(component);
+	struct soc_mixer_control *mc =
+			(struct soc_mixer_control *)kcontrol->private_value;
+	unsigned int reg;
+	int index = ucontrol->value.integer.value[0];
+	int ret;
+
+	ret = snd_soc_put_volsw(kcontrol, ucontrol);
+	if (ret < 0)
+		return ret;

So we make the volume change actually take effect...

sound/soc/codecs/mt6359.c line 432

Quoted 8 lines
sound/soc/codecs/mt6359.c new file +8 -0
+	switch (mc->reg) {
+	case MT6359_ZCD_CON2:
+		regmap_read(priv->regmap, MT6359_ZCD_CON2, &reg);
+		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] =
+			(reg >> RG_AUDHPLGAIN_SFT) & RG_AUDHPLGAIN_MASK;
+		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] =
+			(reg >> RG_AUDHPRGAIN_SFT) & RG_AUDHPRGAIN_MASK;
+		break;

...then read the value that was set and store it elsewhere. What's going on here?

sound/soc/codecs/mt6359.c line 490

Quoted 11 lines
sound/soc/codecs/mt6359.c new file +11 -0
+/*HP MUX */
+static const char * const hp_in_mux_map[] = {
+	"Open",
+	"LoudSPK Playback",
+	"Audio Playback",
+	"Test Mode",
+	"HP Impedance",
+	"undefined1",
+	"undefined2",
+	"undefined3",
+};

Why expose undefined (and presumably out of spec) values to userspace?

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+static int mt_clksq_event(struct snd_soc_dapm_widget *w,
+			  struct snd_kcontrol *kcontrol,
+			  int event)
+{
+	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);

sound/soc/codecs/mt6359.c line 808

Quoted 10 lines
sound/soc/codecs/mt6359.c new file +10 -0
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
+
+	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		/* audio clk source from internal dcxo */
+		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON23,
+				   RG_CLKSQ_IN_SEL_TEST_MASK_SFT,
+				   0x0);

This also appeared to be controlled in _set_clkseq() - are we sure that things couldn't get confused about the state?

sound/soc/codecs/mt6359.c line 887

Quoted 2 lines
sound/soc/codecs/mt6359.c new file +2 -0
+	/* HP damp circuit enable */
+	/*Enable HPRN/HPLN output 4K to VCM */

Spaces around the /* */

Quoted 8 lines
sound/soc/codecs/mt6359.c new file +8 -0
+static int mt_hp_event(struct snd_soc_dapm_widget *w,
+		       struct snd_kcontrol *kcontrol,
+		       int event)
+{
+	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
+	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
+	int device = DEVICE_HP;

sound/soc/codecs/mt6359.c line 1063

Quoted 10 lines
sound/soc/codecs/mt6359.c new file +10 -0
+
+	dev_dbg(priv->dev, "%s(), event 0x%x, dev_counter[DEV_HP] %d, mux %u\n",
+		__func__, event, priv->dev_counter[device], mux);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		priv->dev_counter[device]++;
+		if (priv->dev_counter[device] > 1)
+			break;	/* already enabled, do nothing */
+		else if (priv->dev_counter[device] <= 0)

Why are we doing additional refcounting on top of what DAPM is doing? This seems like there should be at least one widget representing the shared bits of the audio path.

sound/soc/codecs/mt6359.c line 2675

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+#define MT6359_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\
+			SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |\
+			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\
+			SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |\
+			SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\
+			SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE)

The driver doesn't appear to configure anything except the sample rate - how are all these formats supported?

sound/soc/codecs/mt6359.c line 2768

Quoted 3 lines
sound/soc/codecs/mt6359.c new file +3 -0
+	/* hp gain ctl default choose ZCD */
+	priv->hp_gain_ctl = HP_GAIN_CTL_ZCD;
+	hp_gain_ctl_select(priv, priv->hp_gain_ctl);

Why not use the hardware default?

sound/soc/codecs/mt6359.c line 2796

Quoted 7 lines
sound/soc/codecs/mt6359.c new file +7 -0
+	mt6359_codec_init_reg(cmpnt);
+
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = 8;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = 8;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1] = 3;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2] = 3;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3] = 3;

Same here.

sound/soc/codecs/mt6359.c line 2803

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+	ret = regulator_enable(priv->avdd_reg);
+	if (ret) {
+		dev_err(priv->dev, "%s(), failed to enable regulator!\n",
+			__func__);
+		return ret;
+	}

Perhaps make this a DAPM widget?

sound/soc/codecs/mt6359.c line 2932

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+	priv->avdd_reg = devm_regulator_get(&pdev->dev, "vaud18");
+	if (IS_ERR(priv->avdd_reg)) {
+		dev_err(&pdev->dev, "%s(), have no vaud18 supply", __func__);
+		return PTR_ERR(priv->avdd_reg);
+	}

It's better to print error codes to help people debugging problems.

sound/soc/codecs/mt6359.c line 2950

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+static const struct of_device_id mt6359_of_match[] = {
+	{.compatible = "mediatek,mt6359-sound",},
+	{}
+};
+MODULE_DEVICE_TABLE(of, mt6359_of_match);

We don't need a compatible here, we know that this device is here since it's part of the parent device and isn't something that might appear in another device. This is reflecting the Linux driver model, not the hardware.

author
#4 lore raw

Re: [PATCH v2 1/2] ASoC: mediatek: mt6359: add codec driver

Quoted 10 lines · Mark Brown
Quoted 7 lines · Jiaxin Yu
sound/soc/codecs/mt6359.c new file +6 -0
+void mt6359_set_playback_gpio(struct snd_soc_component *cmpnt)
+{
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
 
+void mt6359_reset_playback_gpio(struct snd_soc_component *cmpnt)
+{
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
Quoted 8 lines

sound/soc/codecs/mt6359.c line 76

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +4 -0
+void mt6359_set_capture_gpio(struct snd_soc_component *cmpnt)
+{
 
+void mt6359_reset_capture_gpio(struct snd_soc_component *cmpnt)
+{

What are these, should they not be managed through gpiolib and/or pinctrl?

These are the functions that control the mux of input or output signal. I refer to the other codec drivers, most of them are manipulate the regs in their codec drivers also. Maybe it's easier to control?

Quoted 12 lines

sound/soc/codecs/mt6359.c line 102

Quoted 7 lines
sound/soc/codecs/mt6359.c new file +7 -0
+/* use only when doing mtkaif calibraiton at the boot time */
+static int mt6359_set_dcxo(struct mt6359_priv *priv, bool enable)
+{
+	regmap_update_bits(priv->regmap, MT6359_DCXO_CW12,
+			   0x1 << RG_XO_AUDIO_EN_M_SFT,
+			   (enable ? 1 : 0) << RG_XO_AUDIO_EN_M_SFT);
+	return 0;

Either don't have a return value or use the result of regmap_update_bits(). There's similar issues with some other functions in here.

Yes, I will refine them.

Quoted 7 lines

sound/soc/codecs/mt6359.c line 221

Quoted 4 lines
sound/soc/codecs/mt6359.c new file +3 -0
+int mt6359_mtkaif_calibration_enable(struct snd_soc_pcm_runtime *rtd)
+{
 
+EXPORT_SYMBOL_GPL(mt6359_mtkaif_calibration_enable);

Why is this exported?

This function is exported to machine driver to do calibration when registering. The interface between MT6359 and MTK SoC is a special interface that named MTKAIF. Therefore, if MT6359 is to be used normally, it needs to rely on the platform for calibration when registering.

Quoted 10 lines

sound/soc/codecs/mt6359.c line 301

Quoted 7 lines
sound/soc/codecs/mt6359.c new file +7 -0
+static void hp_aux_feedback_loop_gain_ramp(struct mt6359_priv *priv, bool up)
+{
+	int i = 0, stage = 0;
+
+	/* Reduce HP aux feedback loop gain step by step */
+	for (i = 0; i <= 0xf; i++) {
+		stage = up ? i : 0xf - i;

Please write normal conditional statements, it helps legibility.

/* Increase/Reduce HP aux feedback loop gain step by step */ This is to prevent sudden changes in volume.

Quoted 18 lines
Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+static int mt6359_put_volsw(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+			snd_soc_kcontrol_component(kcontrol);

sound/soc/codecs/mt6359.c line 423

Quoted 10 lines
sound/soc/codecs/mt6359.c new file +10 -0
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(component);
+	struct soc_mixer_control *mc =
+			(struct soc_mixer_control *)kcontrol->private_value;
+	unsigned int reg;
+	int index = ucontrol->value.integer.value[0];
+	int ret;
+
+	ret = snd_soc_put_volsw(kcontrol, ucontrol);
+	if (ret < 0)
+		return ret;

So we make the volume change actually take effect...

Quoted 12 lines

sound/soc/codecs/mt6359.c line 432

Quoted 8 lines
sound/soc/codecs/mt6359.c new file +8 -0
+	switch (mc->reg) {
+	case MT6359_ZCD_CON2:
+		regmap_read(priv->regmap, MT6359_ZCD_CON2, &reg);
+		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] =
+			(reg >> RG_AUDHPLGAIN_SFT) & RG_AUDHPLGAIN_MASK;
+		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] =
+			(reg >> RG_AUDHPRGAIN_SFT) & RG_AUDHPRGAIN_MASK;
+		break;

..then read the value that was set and store it elsewhere. What's going on here?

Because we can adjust the volume at two points, before and during the playback or capture. In addition, we will do volume ramp when opening the driver. If we set the volume before opening the driver, we need get the value to do volume ramp during opening the driver.

Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+/*HP MUX */
+static const char * const hp_in_mux_map[] = {
+	"Open",
+	"LoudSPK Playback",
+	"Audio Playback",
Quoted 9 lines

sound/soc/codecs/mt6359.c line 490

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+	"Test Mode",
+	"HP Impedance",
+	"undefined1",
+	"undefined2",
+	"undefined3",
+};

Why expose undefined (and presumably out of spec) values to userspace?

Removed them.

Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/mt6359.c new file +10 -0
+static int mt_clksq_event(struct snd_soc_dapm_widget *w,
+			  struct snd_kcontrol *kcontrol,
+			  int event)
+{
+	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
+
+	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
+
+	switch (event) {
Quoted 9 lines

sound/soc/codecs/mt6359.c line 808

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+	case SND_SOC_DAPM_PRE_PMU:
+		/* audio clk source from internal dcxo */
+		regmap_update_bits(priv->regmap, MT6359_AUDENC_ANA_CON23,
+				   RG_CLKSQ_IN_SEL_TEST_MASK_SFT,
+				   0x0);

This also appeared to be controlled in _set_clkseq() - are we sure that things couldn't get confused about the state?

_set_clkseq() will only be run at the time of mtkaif calibraiton, and the calibration only run once when the codec driver probe. So it won't get confused about the state. But it really only needs to be set up once at mt6359_codec_init_reg(). I will remove the unnecesary settings.

Quoted 5 lines

sound/soc/codecs/mt6359.c line 887

Quoted 2 lines
sound/soc/codecs/mt6359.c new file +2 -0
+	/* HP damp circuit enable */
+	/*Enable HPRN/HPLN output 4K to VCM */

Spaces around the /* */

Sorry, fixed it.

Quoted 14 lines
Quoted 14 lines
sound/soc/codecs/mt6359.c new file +14 -0
+static int mt_hp_event(struct snd_soc_dapm_widget *w,
+		       struct snd_kcontrol *kcontrol,
+		       int event)
+{
+	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);
+	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
+	int device = DEVICE_HP;
+
+	dev_dbg(priv->dev, "%s(), event 0x%x, dev_counter[DEV_HP] %d, mux %u\n",
+		__func__, event, priv->dev_counter[device], mux);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
Quoted 9 lines

sound/soc/codecs/mt6359.c line 1063

Quoted 4 lines
sound/soc/codecs/mt6359.c new file +4 -0
+		priv->dev_counter[device]++;
+		if (priv->dev_counter[device] > 1)
+			break;	/* already enabled, do nothing */
+		else if (priv->dev_counter[device] <= 0)

Why are we doing additional refcounting on top of what DAPM is doing? This seems like there should be at least one widget representing the shared bits of the audio path.

We have "HPL Mux" and "HPR Mux", there will be two paths enabled when playback throuh HP. But actually they share the same control sequences. So in order to prevent setting it one more time we do additional refcouting.

Quoted 10 lines

sound/soc/codecs/mt6359.c line 2675

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+#define MT6359_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\
+			SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |\
+			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\
+			SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |\
+			SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\
+			SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE)

The driver doesn't appear to configure anything except the sample rate - how are all these formats supported?

The interface between MT6359 and MTK SoC is a special interface that named MTKAIF. Because of its unique hardware settings, it really doesn't to set format argument. The capability of pcm driver mainly depends on cpu-dai driver to limit.

Quoted 6 lines

sound/soc/codecs/mt6359.c line 2768

Quoted 3 lines
sound/soc/codecs/mt6359.c new file +3 -0
+	/* hp gain ctl default choose ZCD */
+	priv->hp_gain_ctl = HP_GAIN_CTL_ZCD;
+	hp_gain_ctl_select(priv, priv->hp_gain_ctl);

Why not use the hardware default?

We have two ways to control the volume, there is to select ZCD. Because the other one it not often used, ZCD is used by default.

Quoted 10 lines

sound/soc/codecs/mt6359.c line 2796

Quoted 7 lines
sound/soc/codecs/mt6359.c new file +7 -0
+	mt6359_codec_init_reg(cmpnt);
+
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = 8;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = 8;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1] = 3;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2] = 3;
+	priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP3] = 3;

Same here.

Removed them.

Quoted 9 lines

sound/soc/codecs/mt6359.c line 2803

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+	ret = regulator_enable(priv->avdd_reg);
+	if (ret) {
+		dev_err(priv->dev, "%s(), failed to enable regulator!\n",
+			__func__);
+		return ret;
+	}

Perhaps make this a DAPM widget?

"vaud18" needs to be always on so we enable it when codec probe.

Quoted 8 lines

sound/soc/codecs/mt6359.c line 2932

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+	priv->avdd_reg = devm_regulator_get(&pdev->dev, "vaud18");
+	if (IS_ERR(priv->avdd_reg)) {
+		dev_err(&pdev->dev, "%s(), have no vaud18 supply", __func__);
+		return PTR_ERR(priv->avdd_reg);
+	}

It's better to print error codes to help people debugging problems.

Yes, I will print the error codes.

Quoted 10 lines

sound/soc/codecs/mt6359.c line 2950

Quoted 5 lines
sound/soc/codecs/mt6359.c new file +5 -0
+static const struct of_device_id mt6359_of_match[] = {
+	{.compatible = "mediatek,mt6359-sound",},
+	{}
+};
+MODULE_DEVICE_TABLE(of, mt6359_of_match);

We don't need a compatible here, we know that this device is here since it's part of the parent device and isn't something that might appear in another device. This is reflecting the Linux driver model, not the hardware.

Removed them.

maintainer
#5 lore raw

Re: [PATCH v2 1/2] ASoC: mediatek: mt6359: add codec driver

Quoted 10 lines · Jiaxin Yu
Quoted 8 lines · Mark Brown

sound/soc/codecs/mt6359.c line 36

Quoted 3 lines · Jiaxin Yu
sound/soc/codecs/mt6359.c new file +3 -0
+void mt6359_set_playback_gpio(struct snd_soc_component *cmpnt)
+{
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);

What are these, should they not be managed through gpiolib and/or pinctrl?

Quoted 3 lines

These are the functions that control the mux of input or output signal. I refer to the other codec drivers, most of them are manipulate the regs in their codec drivers also. Maybe it's easier to control?

These functions are exported for other drivers to use rather than something done internally by the driver - if this were internal to the driver it'd not be a big deal but when it's for use by another driver it'd be better to go through standard interfaces.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/mt6359.c new file +3 -0
+int mt6359_mtkaif_calibration_enable(struct snd_soc_pcm_runtime *rtd)
+{
 
+EXPORT_SYMBOL_GPL(mt6359_mtkaif_calibration_enable);
Quoted 7 lines
Quoted 1 line

Why is this exported?

This function is exported to machine driver to do calibration when registering. The interface between MT6359 and MTK SoC is a special interface that named MTKAIF. Therefore, if MT6359 is to be used normally, it needs to rely on the platform for calibration when registering.

So this needs the SoC to do something as part of callibration?

Quoted 11 lines
Quoted 10 lines

sound/soc/codecs/mt6359.c line 1063

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		priv->dev_counter[device]++;
+		if (priv->dev_counter[device] > 1)
+			break;	/* already enabled, do nothing */
+		else if (priv->dev_counter[device] <= 0)

Why are we doing additional refcounting on top of what DAPM is doing? This seems like there should be at least one widget representing the shared bits of the audio path.

Quoted 4 lines

We have "HPL Mux" and "HPR Mux", there will be two paths enabled when playback throuh HP. But actually they share the same control sequences. So in order to prevent setting it one more time we do additional refcouting.

That sounds like you should just have one output path defined in DAPM and merge the left and right signals together rather than maintaining them separately.

Quoted 8 lines
Quoted 5 lines

sound/soc/codecs/mt6359.c line 2768

Quoted 3 lines
sound/soc/codecs/mt6359.c new file +3 -0
+	/* hp gain ctl default choose ZCD */
+	priv->hp_gain_ctl = HP_GAIN_CTL_ZCD;
+	hp_gain_ctl_select(priv, priv->hp_gain_ctl);

Why not use the hardware default?

We have two ways to control the volume, there is to select ZCD. Because the other one it not often used, ZCD is used by default.

Why not just let the user pick at runtime?

Quoted 10 lines
Quoted 8 lines

sound/soc/codecs/mt6359.c line 2803

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+	ret = regulator_enable(priv->avdd_reg);
+	if (ret) {
+		dev_err(priv->dev, "%s(), failed to enable regulator!\n",
+			__func__);
+		return ret;
+	}

Perhaps make this a DAPM widget?

"vaud18" needs to be always on so we enable it when codec probe.

If it is just supposed to be left on all the time it's better to do this in the main device model probe rather than the component probe. The component probe should usually only be used for things that need the rest of the card to be there.

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

author
#6 lore raw

Re: [PATCH v2 1/2] ASoC: mediatek: mt6359: add codec driver

Quoted 11 lines · Mark Brown
Quoted 9 lines · Jiaxin Yu
Quoted 8 lines · Mark Brown

sound/soc/codecs/mt6359.c line 36

Quoted 3 lines · Jiaxin Yu
sound/soc/codecs/mt6359.c new file +3 -0
+void mt6359_set_playback_gpio(struct snd_soc_component *cmpnt)
+{
+	struct mt6359_priv *priv = snd_soc_component_get_drvdata(cmpnt);

What are these, should they not be managed through gpiolib and/or pinctrl?

Quoted 9 lines
Quoted 3 lines

These are the functions that control the mux of input or output signal. I refer to the other codec drivers, most of them are manipulate the regs in their codec drivers also. Maybe it's easier to control?

These functions are exported for other drivers to use rather than something done internally by the driver - if this were internal to the driver it'd not be a big deal but when it's for use by another driver it'd be better to go through standard interfaces.

Can we move this part of the operation to the codec dai driver ops, such as .startup and .shutdown? Because originally these functions are exported to machine driver's dai_link .startup and .shutdown ops.

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

sound/soc/codecs/mt6359.c line 221

Quoted 4 lines
sound/soc/codecs/mt6359.c new file +3 -0
+int mt6359_mtkaif_calibration_enable(struct snd_soc_pcm_runtime *rtd)
+{
 
+EXPORT_SYMBOL_GPL(mt6359_mtkaif_calibration_enable);

Why is this exported?

Quoted 8 lines
Quoted 5 lines

This function is exported to machine driver to do calibration when registering. The interface between MT6359 and MTK SoC is a special interface that named MTKAIF. Therefore, if MT6359 is to be used normally, it needs to rely on the platform for calibration when registering.

So this needs the SoC to do something as part of callibration?

Yes, the side of MTKAIF in SoC part named adda, we need config it before calibration. We will also upstream machine/platform driver that use this codec driver later.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

sound/soc/codecs/mt6359.c line 1063

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		priv->dev_counter[device]++;
+		if (priv->dev_counter[device] > 1)
+			break;	/* already enabled, do nothing */
+		else if (priv->dev_counter[device] <= 0)

Why are we doing additional refcounting on top of what DAPM is doing? This seems like there should be at least one widget representing the shared bits of the audio path.

Quoted 9 lines
Quoted 4 lines

We have "HPL Mux" and "HPR Mux", there will be two paths enabled when playback throuh HP. But actually they share the same control sequences. So in order to prevent setting it one more time we do additional refcouting.

That sounds like you should just have one output path defined in DAPM and merge the left and right signals together rather than maintaining them separately.

Yes, it's would better if they are combined into one mixer control that named "HP Mux".

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

sound/soc/codecs/mt6359.c line 2768

Quoted 3 lines
sound/soc/codecs/mt6359.c new file +3 -0
+	/* hp gain ctl default choose ZCD */
+	priv->hp_gain_ctl = HP_GAIN_CTL_ZCD;
+	hp_gain_ctl_select(priv, priv->hp_gain_ctl);

Why not use the hardware default?

We have two ways to control the volume, there is to select ZCD. Because the other one it not often used, ZCD is used by default.

Why not just let the user pick at runtime?

For another adjustment method, we didn't upstream it, so only ZCD reserved. And the hardware default setting is ZCD, so we can removed these lines.

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

sound/soc/codecs/mt6359.c line 2803

Quoted 6 lines
sound/soc/codecs/mt6359.c new file +6 -0
+	ret = regulator_enable(priv->avdd_reg);
+	if (ret) {
+		dev_err(priv->dev, "%s(), failed to enable regulator!\n",
+			__func__);
+		return ret;
+	}

Perhaps make this a DAPM widget?

Quoted 6 lines
Quoted 1 line

"vaud18" needs to be always on so we enable it when codec probe.

If it is just supposed to be left on all the time it's better to do this in the main device model probe rather than the component probe. The component probe should usually only be used for things that need the rest of the card to be there.

Ok, I will correct it.

maintainer
#7 lore raw

Re: [PATCH v2 1/2] ASoC: mediatek: mt6359: add codec driver

Quoted 10 lines · Jiaxin Yu
Quoted 4 lines · Mark Brown

These functions are exported for other drivers to use rather than something done internally by the driver - if this were internal to the driver it'd not be a big deal but when it's for use by another driver it'd be better to go through standard interfaces.

Can we move this part of the operation to the codec dai driver ops, such as .startup and .shutdown? Because originally these functions are exported to machine driver's dai_link .startup and .shutdown ops.

If it's internal to the driver sure.

Quoted 5 lines
Quoted 1 line

So this needs the SoC to do something as part of callibration?

Yes, the side of MTKAIF in SoC part named adda, we need config it before calibration. We will also upstream machine/platform driver that use this codec driver later.

It would probably be better to just leave this out for now then add the required bits to the CODEC driver as part of a patch series that also adds the machine driver that uses it so it's clear how it all fits together. It sounds like it should be fine but this'd be easier to review.

author
#8 lore raw

Re: [PATCH v2 1/2] ASoC: mediatek: mt6359: add codec driver

Quoted 20 lines · Mark Brown
Quoted 10 lines · Jiaxin Yu
Quoted 4 lines · Mark Brown

These functions are exported for other drivers to use rather than something done internally by the driver - if this were internal to the driver it'd not be a big deal but when it's for use by another driver it'd be better to go through standard interfaces.

Can we move this part of the operation to the codec dai driver ops, such as .startup and .shutdown? Because originally these functions are exported to machine driver's dai_link .startup and .shutdown ops.

If it's internal to the driver sure.

Quoted 5 lines
Quoted 1 line

So this needs the SoC to do something as part of callibration?

Yes, the side of MTKAIF in SoC part named adda, we need config it before calibration. We will also upstream machine/platform driver that use this codec driver later.

Quoted 5 lines

It would probably be better to just leave this out for now then add the required bits to the CODEC driver as part of a patch series that also adds the machine driver that uses it so it's clear how it all fits together. It sounds like it should be fine but this'd be easier to review.

Ok, I'll remove the functions that related to the calibration, and upstream them again as part of a patch series that adds the machine driver later.