From e3364fbb3b5ba6a031cc3518fc4ee32f31c4c045 Mon Sep 17 00:00:00 2001
From: Valentin Raevsky <valentin@compulab.co.il>
Date: Mon, 13 Jun 2016 11:29:05 +0300
Subject: ARM: i.MX6: audio: add analog audio support

Add analog audio support by means of the simple-audio-card.
This instance provides a simple glue interface between cpu:ssi and codec:wm8731.

Signed-off-by: Valentin Raevsky <valentin@compulab.co.il>
---
 arch/arm/boot/dts/imx6qdl-cm-fx6.dtsi | 85 +++++++++++++++++++++++++++++------
 sound/soc/fsl/Kconfig                 | 13 ++++++
 2 files changed, 84 insertions(+), 14 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl-cm-fx6.dtsi b/arch/arm/boot/dts/imx6qdl-cm-fx6.dtsi
index 2f8ba05..52bca49 100644
--- a/arch/arm/boot/dts/imx6qdl-cm-fx6.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-cm-fx6.dtsi
@@ -10,6 +10,7 @@
  * http://www.opensource.org/licenses/gpl-license.html
  * http://www.gnu.org/copyleft/gpl.html
  */
+#include <dt-bindings/sound/fsl-imx-audmux.h>
 
 #define MX6QDL_GPR1	0x04 0x04 0x000 0x0 0x0
 #define MX6QDL_GPR6	0x18 0x18 0x000 0x0 0x0
@@ -105,13 +106,36 @@
 	};
 
 	sound {
-		compatible = "fsl,imx-audio-wm8731";
-		model = "wm8731-audio";
-		ssi-controller = <&ssi2>;
-		src-port = <2>;
-		ext-port = <4>;
-		audio-codec = <&codec>;
-		audio-routing = "LOUT", "ROUT", "LLINEIN", "RLINEIN";
+		compatible = "simple-audio-card";
+		simple-audio-card,name = "cm-fx6";
+		simple-audio-card,widgets =
+			"Headphone", "Headphone Jack",
+			"Line", "Line Out",
+			"Microphone", "Mic Jack",
+			"Line", "Line In";
+		simple-audio-card,routing =
+			"Headphone Jack", "RHPOUT",
+			"Headphone Jack", "LHPOUT",
+			"LLINEIN", "Line Jack",
+			"RLINEIN", "Line Jack",
+			"MICIN", "Mic Bias",
+			"Mic Bias", "Mic Jack";
+		simple-audio-card,format = "i2s";
+		simple-audio-card,bitclock-master = <&sound_master>;
+		simple-audio-card,frame-master = <&sound_master>;
+		simple-audio-card,bitclock-inversion;
+
+		sound_master: simple-audio-card,cpu {
+			sound-dai = <&ssi2>;
+			system-clock-frequency = <0>;
+			system-clock-direction = "out";
+		};
+
+		simple-audio-card,codec {
+			sound-dai = <&wm8731>;
+			system-clock-direction = "in";
+		};
+
 	};
 
 	sound-hdmi {
@@ -580,15 +604,11 @@
 		pagesize = <16>;
 	};
 
-	codec: wm8731@1a {
+	wm8731: wm8731@1a {
+		#sound-dai-cells = <0>;
 		compatible = "wlf,wm8731";
 		reg = <0x1a>;
-		clocks = <&clks 173>, <&clks 158>, <&clks 201>, <&clks 200>;
-		clock-names = "pll4", "imx-ssi.1", "cko", "cko2";
-		AVDD-supply = <&pu_dummy>;
-		HPVDD-supply = <&pu_dummy>;
-		DCVDD-supply = <&pu_dummy>;
-		DBVDD-supply = <&pu_dummy>;
+		status = "okay";
 	};
 };
 
@@ -634,9 +654,20 @@
 	status = "okay";
 };
 
+&clks {
+	assigned-clocks = <&clks IMX6QDL_CLK_PLL4_AUDIO_DIV>;
+	assigned-clock-rates = <786432000>;
+};
+
 &ssi2 {
+	#sound-dai-cells = <0>;
 	fsl,mode = "i2s-master";
 	status = "okay";
+
+	assigned-clocks = <&clks IMX6QDL_CLK_SSI2_SEL>,
+			<&clks IMX6QDL_CLK_SSI2>;
+	assigned-clock-parents = <&clks IMX6QDL_CLK_PLL4_AUDIO_DIV>;
+	assigned-clock-rates = <0>;
 };
 
 &hdmi_core {
@@ -662,8 +693,34 @@
 	status = "okay";
 };
 
+#define SRC_PORT (1)
+#define EXT_PORT (3)
 &audmux {
 	pinctrl-names = "default";
 	pinctrl-0 = <&pinctrl_audmux>;
 	status = "okay";
+
+	ssi2 {
+		fsl,audmux-port = <SRC_PORT>;
+		fsl,port-config = <
+			(IMX_AUDMUX_V2_PTCR_RCLKDIR |
+			IMX_AUDMUX_V2_PTCR_RCSEL(EXT_PORT | 0x8) |
+			IMX_AUDMUX_V2_PTCR_TCLKDIR |
+			IMX_AUDMUX_V2_PTCR_TCSEL(EXT_PORT))
+			IMX_AUDMUX_V2_PDCR_RXDSEL(EXT_PORT)
+		>;
+	};
+
+	pins5 {
+		fsl,audmux-port = <EXT_PORT>;
+		fsl,port-config = <
+			(IMX_AUDMUX_V2_PTCR_TFSDIR |
+			IMX_AUDMUX_V2_PTCR_TFSEL(SRC_PORT) |
+			IMX_AUDMUX_V2_PTCR_RCLKDIR |
+			IMX_AUDMUX_V2_PTCR_RCSEL(SRC_PORT | 0x8) |
+			IMX_AUDMUX_V2_PTCR_TCLKDIR |
+			IMX_AUDMUX_V2_PTCR_TCSEL(SRC_PORT))
+			IMX_AUDMUX_V2_PDCR_RXDSEL(SRC_PORT)
+		>;
+	};
 };
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index a4054f3..8a56912 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -392,6 +392,19 @@ config SND_SOC_IMX_HDMI
 	  Say Y if you want to add support for SoC audio on an i.MX board with
 	  IMX HDMI.
 
+config SND_SOC_IMX_WM8731
+	tristate "SoC Audio support for i.MX boards with WM8731"
+	select SND_SOC_IMX_PCM_DMA
+	select SND_SOC_IMX_AUDMUX
+	select SND_SOC_FSL_SSI
+	select SND_SOC_FSL_UTILS
+	select SND_SOC_WM8731
+	select SND_SIMPLE_CARD
+	help
+	  SoC Audio support for i.MX boards with WM8731
+	  Say Y if you want to add support for Soc audio for the WM8731 chip
+	  CM-FX6 module.
+
 endif # SND_IMX_SOC
 
 endmenu
-- 
1.9.1

