Personal tools

VAR-SOM-MX6 DMic

From Variscite Wiki

Jump to: navigation, search

VAR-SOM-MX6 Digital Mic


Latest kernel 4.9 includes changes allowing to setup DMIC at runtime using alsamixer/amixer: to enable DMIC, simply set a valid oversampling rate ("128x", "64x", "32x"), or leave it "off" to use LINE_IN.

DMIC activation for older kernel versions

To get the digital microphone working, apply the following patch to the Linux kernel:

diff --git a/arch/arm/boot/dts/imx6qdl-var-dart.dtsi b/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
index 362be93..884c037 100644
--- a/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-var-dart.dtsi
@@ -279,14 +279,7 @@
 		AVDD-supply = <&reg_audio>;
 		DRVDD-supply = <&reg_audio>;
 		gpio-reset = <&gpio4 5 1>;
-		gpio-cfg = <
-			0x0000 /* 0:Default */
-			0x0000 /* 1:Default */
-			0x0013 /* 2:FN_DMICCLK */
-			0x0000 /* 3:Default */
-			0x8014 /* 4:FN_DMICCDAT */
-			0x0000 /* 5:Default */
-		>;
+               ai3x-gpio-func = <0xa 0x5 0x2 0x0 0x0>;
 	};
 };
 
diff --git a/arch/arm/boot/dts/imx6qdl-var-som.dtsi b/arch/arm/boot/dts/imx6qdl-var-som.dtsi
index f221360..48bc48d 100644
--- a/arch/arm/boot/dts/imx6qdl-var-som.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-var-som.dtsi
@@ -321,10 +321,7 @@
 		AVDD-supply = <&reg_audio>;
 		DRVDD-supply = <&reg_audio>;
 		gpio-reset = <&gpio4 5 1>;
-		ai3x-gpio-func = <
-			0 /* AIC3X_GPIO1_FUNC_DISABLED */
-			5 /* AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT */
-		>;
+               ai3x-gpio-func = <0xa 0x5 0x2 0x0 0x0>;
 	};
 };
 
diff --git a/include/sound/tlv320aic3x.h b/include/sound/tlv320aic3x.h
index 9407fd0..421ad03 100644
--- a/include/sound/tlv320aic3x.h
+++ b/include/sound/tlv320aic3x.h
@@ -54,7 +54,7 @@ enum aic3x_micbias_voltage {
 };
 
 struct aic3x_setup_data {
-	unsigned int gpio_func[2];
+	unsigned int gpio_func[5];
 };
 
 struct aic3x_pdata {
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 51c4713..8fc96d1 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -687,26 +687,6 @@ static const struct snd_soc_dapm_widget aic3x_extra_dapm_widgets[] = {
 	SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
 			 &aic3x_right_line2_mux_controls),
 
-	/*
-	 * Not a real mic bias widget but similar function. This is for dynamic
-	 * control of GPIO1 digital mic modulator clock output function when
-	 * using digital mic.
-	 */
-	SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
-			 AIC3X_GPIO1_REG, 4, 0xf,
-			 AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
-			 AIC3X_GPIO1_FUNC_DISABLED),
-
-	/*
-	 * Also similar function like mic bias. Selects digital mic with
-	 * configurable oversampling rate instead of ADC converter.
-	 */
-	SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
-			 AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
-	SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
-			 AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
-	SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
-			 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
 
 	/* Output mixers */
 	SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
@@ -1573,8 +1553,18 @@ static int aic3x_probe(struct snd_soc_codec *codec)
 			/* setup GPIO functions */
 			snd_soc_write(codec, AIC3X_GPIO1_REG,
 				      (aic3x->setup->gpio_func[0] & 0xf) << 4);
+
 			snd_soc_write(codec, AIC3X_GPIO2_REG,
 				      (aic3x->setup->gpio_func[1] & 0xf) << 4);
+
+                       snd_soc_update_bits(codec, AIC3X_ASD_INTF_CTRLA,
+                                     0x3 << 0, (aic3x->setup->gpio_func[2] & 0x3) << 0);
+
+                       snd_soc_update_bits(codec, MICBIAS_CTRL,
+                                     0x3 << 4, (aic3x->setup->gpio_func[3] & 0x3) << 4);
+
+                       snd_soc_update_bits(codec, NEW_ADC_DIGITALPATH,
+                                     0x3 << 4, (aic3x->setup->gpio_func[4] & 0x3) << 4);
 		} else {
 			dev_warn(codec->dev, "GPIO functionality is not supported on tlv320aic3104\n");
 		}
@@ -1722,7 +1712,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
 			aic3x->gpio_reset = -1;
 
 		if (of_property_read_u32_array(np, "ai3x-gpio-func",
-					ai3x_setup->gpio_func, 2) >= 0) {
+                                       ai3x_setup->gpio_func, 5) >= 0) {
 			aic3x->setup = ai3x_setup;
 		}


To test the digital mic. and record to a wav file, run the following command after applying the above patch:

# arecord –f cd test.wav