Skip to contentSkip to conversation

Add freescale S/PDIF CPU DAI and machine drivers

PATCH Superseded Nicolin Chen 4 participants 16 messages Aug 19, 2013 – Aug 21, 2013

Subsystems (5)

v8 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v8 cover Add freescale S/PDIF CPU DAI and machine drivers

Changelog:
v7->v8:
* Revised DT binding doc.
* Revised dev_err() error msg.
* Check return value of clk_set_rate().
v6->v7:
* Removed extra comma in array.
* Revised some comments.
* Added some dev_err().
* Check the return value of soft reset.
* Use bitrev8() instead of extra reverse_bits().
* Use cache_bypass as default for regmap.
v5->v6:
* Sorted out rxtx clk source in DT binding.
* Use devm_xxxx() functions.
* Use platform_get_resource() instead.
v4->v5:
* Dropped rx/tx-clksrc-names DT bindings.
* Use standard clock binding instead to pass the clock source list.
* Update the compatible list by using "imx35", the first SoC that has spdif.
v3->v4:
* Use regmap for CPU DAI driver.
* Use individual clock source for 32KHz, 44KHz, 48KHz playback.
* Determine clock source configuration from 'clocks' entry.
* Added imx53 to compatible list, merged imx6q and imx6dl in the list.
* Improve the algorism of reverse_bits().
* Dropped the unneeded clk_put().
v2->v3:
* Removed a wrong tag from the commit of patch-1.
v1->v2:
* Dropped one applied patch for spdif dummy codec drivers.
* Use generic DMA DT binding.
* Let spdif controller driver calculate the clock div.
* Added one optional clock source for spdif tx.
* Reivsed documentation accordingly.

Nicolin Chen (2):
ASoC: fsl: Add S/PDIF CPU DAI driver
ASoC: fsl: Add S/PDIF machine driver

 .../devicetree/bindings/sound/fsl,spdif.txt        |   54 +
 .../devicetree/bindings/sound/imx-audio-spdif.txt  |   29 +
 sound/soc/fsl/Kconfig                              |   14 +
 sound/soc/fsl/Makefile                             |    4 +
 sound/soc/fsl/fsl_spdif.c                          | 1281 ++++++++++++++++++++
 sound/soc/fsl/fsl_spdif.h                          |  224 ++++
 sound/soc/fsl/imx-spdif.c                          |  134 ++
 7 files changed, 1740 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/fsl,spdif.txt
 create mode 100644 Documentation/devicetree/bindings/sound/imx-audio-spdif.txt
 create mode 100644 sound/soc/fsl/fsl_spdif.c
 create mode 100644 sound/soc/fsl/fsl_spdif.h
 create mode 100644 sound/soc/fsl/imx-spdif.c
#1 lore raw

PATCH v8 1/2 ASoC: fsl: Add S/PDIF CPU DAI driver

This patch implements a device-tree-only CPU DAI driver for Freescale S/PDIF controller that supports stereo playback and record feature.

---
 .../devicetree/bindings/sound/fsl,spdif.txt        |   54 +
 sound/soc/fsl/Kconfig                              |    3 +
 sound/soc/fsl/Makefile                             |    2 +
 sound/soc/fsl/fsl_spdif.c                          | 1281 ++++++++++++++++++++
 sound/soc/fsl/fsl_spdif.h                          |  224 ++++
 5 files changed, 1564 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/fsl,spdif.txt
 create mode 100644 sound/soc/fsl/fsl_spdif.c
 create mode 100644 sound/soc/fsl/fsl_spdif.h
Documentation/devicetree/bindings/sound/fsl,spdif.txt new file +54 -0
new file mode 100644
index 0000000..f2ae335
@@ -0,0 +1,54 @@
+Freescale Sony/Philips Digital Interface Format (S/PDIF) Controller
+
+The Freescale S/PDIF audio block is a stereo transceiver that allows the
+processor to receive and transmit digital audio via an coaxial cable or
+a fibre cable.
+
+Required properties:
+
+  - compatible : Compatible list, must contain "fsl,imx35-spdif".
+
+  - reg : Offset and length of the register set for the device.
+
+  - interrupts : Contains the spdif interrupt.
+
+  - dmas : Generic dma devicetree binding as described in
+  Documentation/devicetree/bindings/dma/dma.txt.
+
+  - dma-names : Two dmas have to be defined, "tx" and "rx".
+
+  - clocks : Contains an entry for each entry in clock-names.
+
+  - clock-names : Includes the following entries:
+	"core"		The core clock of spdif controller
+	"rxtx<0-7>"	Clock source list for tx and rx clock.
+			This clock list should be identical to
+			the source list connecting to the spdif
+			clock mux in "SPDIF Transceiver Clock
+			Diagram" of SoC reference manual. It
+			can also be referred to TxClk_Source
+			bit of register SPDIF_STC.
+
+Example:
+
+spdif: spdif@02004000 {
+	compatible = "fsl,imx35-spdif";
+	reg = <0x02004000 0x4000>;
+	interrupts = <0 52 0x04>;
+	dmas = <&sdma 14 18 0>,
+	       <&sdma 15 18 0>;
+	dma-names = "rx", "tx";
+
+	clocks = <&clks 197>, <&clks 3>,
+	       <&clks 197>, <&clks 107>,
+	       <&clks 0>, <&clks 118>,
+	       <&clks 62>, <&clks 139>,
+	       <&clks 0>;
+	clock-names = "core", "rxtx0",
+		"rxtx1", "rxtx2",
+		"rxtx3", "rxtx4",
+		"rxtx5", "rxtx6",
+		"rxtx7";
+
+	status = "okay";
+};
sound/soc/fsl/Kconfig +3 -0
index 3a4808d..cd088cc 100644
@@ -1,6 +1,9 @@
 config SND_SOC_FSL_SSI
 	tristate
 
+config SND_SOC_FSL_SPDIF
+	tristate
+
 config SND_SOC_FSL_UTILS
 	tristate
 
sound/soc/fsl/Makefile +2 -0
index d4b4aa8..4b5970e 100644
@@ -12,9 +12,11 @@ obj-$(CONFIG_SND_SOC_P1022_RDK) += snd-soc-p1022-rdk.o
 
 # Freescale PowerPC SSI/DMA Platform Support
 snd-soc-fsl-ssi-objs := fsl_ssi.o
+snd-soc-fsl-spdif-objs := fsl_spdif.o
 snd-soc-fsl-utils-objs := fsl_utils.o
 snd-soc-fsl-dma-objs := fsl_dma.o
 obj-$(CONFIG_SND_SOC_FSL_SSI) += snd-soc-fsl-ssi.o
+obj-$(CONFIG_SND_SOC_FSL_SPDIF) += snd-soc-fsl-spdif.o
 obj-$(CONFIG_SND_SOC_FSL_UTILS) += snd-soc-fsl-utils.o
 obj-$(CONFIG_SND_SOC_POWERPC_DMA) += snd-soc-fsl-dma.o
 
sound/soc/fsl/fsl_spdif.c new file +1281 -0

1,281 lines not on this page · raw message

sound/soc/fsl/fsl_spdif.h new file +224 -0

224 lines not on this page · raw message

Signature · 1 line
1.7.1
#7 lore raw

PATCH v8 2/2 ASoC: fsl: Add S/PDIF machine driver

In reply to Nicolin Chen

This patch implements a device-tree-only machine driver for Freescale i.MX series Soc. It works with spdif_transmitter/spdif_receiver and fsl_spdif.c drivers.

---
 .../devicetree/bindings/sound/imx-audio-spdif.txt  |   29 +++++
 sound/soc/fsl/Kconfig                              |   11 ++
 sound/soc/fsl/Makefile                             |    2 +
 sound/soc/fsl/imx-spdif.c                          |  134 ++++++++++++++++++++
 4 files changed, 176 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/imx-audio-spdif.txt
 create mode 100644 sound/soc/fsl/imx-spdif.c
Documentation/devicetree/bindings/sound/imx-audio-spdif.txt new file +29 -0
new file mode 100644
index 0000000..9a3fa26
@@ -0,0 +1,29 @@
+Freescale i.MX audio complex with S/PDIF transceiver
+
+Required properties:
+
+  - compatible : "fsl,imx-audio-spdif"
+
+  - model : The user-visible name of this sound complex
+
+  - spdif-controller : The phandle of the i.MX S/PDIF controller
+
+
+Optional properties:
+
+  - spdif-transmitter : The phandle of the spdif-transmitter dummy codec
+
+  - spdif-receiver : The phandle of the spdif-receiver dummy codec
+
+* Note: At least one of these two properties should be set in the DT binding.
+
+
+Example:
+
+sound-spdif {
+	compatible = "fsl,imx-audio-spdif";
+	model = "imx-spdif";
+	spdif-controller = <&spdif>;
+	spdif-transmitter = <&spdif_tx_codec>;
+	spdif-receiver = <&spdif_rx_codec>;
+};
sound/soc/fsl/Kconfig +11 -0
index cd088cc..a708380 100644
@@ -193,6 +193,17 @@ config SND_SOC_IMX_SGTL5000
 	  Say Y if you want to add support for SoC audio on an i.MX board with
 	  a sgtl5000 codec.
 
+config SND_SOC_IMX_SPDIF
+	tristate "SoC Audio support for i.MX boards with S/PDIF"
+	select SND_SOC_IMX_PCM_DMA
+	select SND_SOC_FSL_SPDIF
+	select SND_SOC_FSL_UTILS
+	select SND_SOC_SPDIF
+	help
+	  SoC Audio support for i.MX boards with S/PDIF
+	  Say Y if you want to add support for SoC audio on an i.MX board with
+	  a S/DPDIF.
+
 config SND_SOC_IMX_MC13783
 	tristate "SoC Audio support for I.MX boards with mc13783"
 	depends on MFD_MC13783 && ARM
sound/soc/fsl/Makefile +2 -0
index 4b5970e..e2aaff7 100644
@@ -45,6 +45,7 @@ snd-soc-mx27vis-aic32x4-objs := mx27vis-aic32x4.o
 snd-soc-wm1133-ev1-objs := wm1133-ev1.o
 snd-soc-imx-sgtl5000-objs := imx-sgtl5000.o
 snd-soc-imx-wm8962-objs := imx-wm8962.o
+snd-soc-imx-spdif-objs :=imx-spdif.o
 snd-soc-imx-mc13783-objs := imx-mc13783.o
 
 obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
@@ -53,4 +54,5 @@ obj-$(CONFIG_SND_SOC_MX27VIS_AIC32X4) += snd-soc-mx27vis-aic32x4.o
 obj-$(CONFIG_SND_MXC_SOC_WM1133_EV1) += snd-soc-wm1133-ev1.o
 obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o
 obj-$(CONFIG_SND_SOC_IMX_WM8962) += snd-soc-imx-wm8962.o
+obj-$(CONFIG_SND_SOC_IMX_SPDIF) += snd-soc-imx-spdif.o
 obj-$(CONFIG_SND_SOC_IMX_MC13783) += snd-soc-imx-mc13783.o
sound/soc/fsl/imx-spdif.c new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
1.7.1
maintainer
#2 lore raw

Re: [PATCH v8 1/2] ASoC: fsl: Add S/PDIF CPU DAI driver

In reply to Nicolin Chen

Hi Nicolas,

Some misc other comments inline.

sound/soc/fsl/fsl_spdif.c line 75

Quoted 8 lines · Nicolin Chen

This patch implements a device-tree-only CPU DAI driver for Freescale

sound/soc/fsl/fsl_spdif.c new file +7 -0
+
+struct fsl_spdif_priv {
+	struct spdif_mixer_control fsl_spdif_control;
+	struct snd_soc_dai_driver cpu_dai_drv;
+	struct platform_device *pdev;
+	struct regmap *regmap;
+	atomic_t dpll_locked;

You don't need an atomic_t to track a bool variable. Use a plain bool or int instead.

Quoted 21 lines
sound/soc/fsl/fsl_spdif.c new file +21 -0
+	u8 txclk_div[SPDIF_TXRATE_MAX];
+	u8 txclk_src[SPDIF_TXRATE_MAX];
+	u8 rxclk_src;
+	struct clk *txclk[SPDIF_TXRATE_MAX];
+	struct clk *rxclk;
+	struct snd_dmaengine_dai_dma_data dma_params_tx;
+	struct snd_dmaengine_dai_dma_data dma_params_rx;
+
+	/* The name space will be allocated dynamically */
+	char name[0];
+};
+
+
+#ifdef DEBUG
+static void dumpregs(struct fsl_spdif_priv *spdif_priv)
+{
+	struct regmap *regmap = spdif_priv->regmap;
+	struct platform_device *pdev = spdif_priv->pdev;
+	u32 val, i;
+	int ret;
+

sound/soc/fsl/fsl_spdif.c line 106

Quoted 10 lines
sound/soc/fsl/fsl_spdif.c new file +10 -0
+	/* Valid address set of SPDIF is {[0x0-0x38], 0x44, 0x50} */
+	for (i = 0 ; i <= REG_SPDIF_STC; i += 4) {
+		ret = regmap_read(regmap, REG_SPDIF_SCR + i, &val);
+		if (!ret)
+			dev_dbg(&pdev->dev, "REG 0x%02x = 0x%06x\n", i, val);
+	}
+}
+#else
+static void dumpregs(struct fsl_spdif_priv *spdif_priv) {}
+#endif

Is this needed? regmap provides a register dump in debugfs.

sound/soc/fsl/fsl_spdif.c line 366

Quoted 8 lines
sound/soc/fsl/fsl_spdif.c new file +8 -0
+
+static int spdif_clk_set_rate(struct clk *clk, unsigned long rate)
+{
+	unsigned long rate_actual;
+
+	rate_actual = clk_round_rate(clk, rate);
+	return clk_set_rate(clk, rate_actual);
+}

clk_round_rate returns the rate which clk_set_rate would set if called with the same rate. The clk_round_rate() is unnecessary.

sound/soc/fsl/fsl_spdif.c line 426

Quoted 5 lines
sound/soc/fsl/fsl_spdif.c new file +5 -0
+
+	dev_dbg(&pdev->dev, "expected clock rate = %d\n",
+			(int)(64 * sample_rate * div));
+	dev_dbg(&pdev->dev, "acutal clock rate = %d\n",
+			(int)clk_get_rate(spdif_priv->txclk[rate]));

s/acutal/actual/

Also please use %ld instead of casting the unsigned long to int.

sound/soc/fsl/fsl_spdif.c line 797

Quoted 4 lines
sound/soc/fsl/fsl_spdif.c new file +4 -0
+
+	dev_dbg(&pdev->dev, "FreqMeas: %d\n", (int)freqmeas);
+	dev_dbg(&pdev->dev, "BusclkFreq: %d\n", (int)busclk_freq);
+	dev_dbg(&pdev->dev, "RxRate: %d\n", (int)tmpval64);

Get rid of the casts

sound/soc/fsl/fsl_spdif.c line 1131

Quoted 5 lines
sound/soc/fsl/fsl_spdif.c new file +5 -0
+
+	spdif_priv = devm_kzalloc(&pdev->dev,
+			sizeof(struct fsl_spdif_priv) + strlen(np->name) + 1, GFP_KERNEL);
+	if (!spdif_priv) {
+		dev_err(&pdev->dev, "could not allocate DAI object\n");

Please drop this message. You'll never see it.

sound/soc/fsl/fsl_spdif.c line 1193

Quoted 11 lines
sound/soc/fsl/fsl_spdif.c new file +11 -0
+
+	for (i = 0; i < SPDIF_TXRATE_MAX; i++) {
+		ret = fsl_spdif_probe_txclk(spdif_priv, i);
+		if (ret)
+			return ret;
+	}
+
+	/* Prepare rx/tx clock */
+	clk_prepare(spdif_priv->rxclk);
+	for (i = 0; i < SPDIF_TXRATE_MAX; i++)
+		clk_prepare(spdif_priv->txclk[i]);

Why do you prepare all clocks instead of the one you actually use? Also, no need to do this here. You can use clk_prepare_enable instead where you have clk_enable now.

Quoted 10 lines
sound/soc/fsl/fsl_spdif.h new file +10 -0
+
+/* SPDIF rx clock source */
+enum spdif_rxclk_src {
+	SRPC_CLKSRC_0 = 0,
+	SRPC_CLKSRC_1,
+	SRPC_CLKSRC_2,
+	SRPC_CLKSRC_3,
+	SRPC_CLKSRC_4,
+	SRPC_CLKSRC_5,
+	SRPC_CLKSRC_6,

sound/soc/fsl/fsl_spdif.h line 129

Quoted 10 lines
sound/soc/fsl/fsl_spdif.h new file +10 -0
+	SRPC_CLKSRC_7,
+	SRPC_CLKSRC_8,
+	SRPC_CLKSRC_9,
+	SRPC_CLKSRC_10,
+	SRPC_CLKSRC_11,
+	SRPC_CLKSRC_12,
+	SRPC_CLKSRC_13,
+	SRPC_CLKSRC_14,
+	SRPC_CLKSRC_15,
+};

These are unused and look unnecessary.

sound/soc/fsl/fsl_spdif.h line 189

Quoted 12 lines
sound/soc/fsl/fsl_spdif.h new file +12 -0
+
+/* SPDIF tx clksrc */
+enum spdif_txclk_src {
+	STC_TXCLK_SRC_0 = 0,
+	STC_TXCLK_SRC_1,
+	STC_TXCLK_SRC_2,
+	STC_TXCLK_SRC_3,
+	STC_TXCLK_SRC_4,
+	STC_TXCLK_SRC_5,
+	STC_TXCLK_SRC_6,
+	STC_TXCLK_SRC_7,
+};

Also unused.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#4 lore raw

Re: [PATCH v8 1/2] ASoC: fsl: Add S/PDIF CPU DAI driver

In reply to Nicolin Chen

Documentation/devicetree/bindings/sound/fsl,spdif.txt line 5

Quoted 10 lines · Nicolin Chen

This patch implements a device-tree-only CPU DAI driver for Freescale S/PDIF controller that supports stereo playback and record feature.

Documentation/devicetree/bindings/sound/fsl,spdif.txt +5 -0
 
+Freescale Sony/Philips Digital Interface Format (S/PDIF) Controller
+
+The Freescale S/PDIF audio block is a stereo transceiver that allows the
+processor to receive and transmit digital audio via an coaxial cable or
+a fibre cable.

Well, the cable type is more a property of the components that are hooked to the SoC signals that this module drives, so are somewhat out of scope of this binding document. However, this is nit-picky comment, and I'm not too worried about it.

Documentation/devicetree/bindings/sound/fsl,spdif.txt line 30

Quoted 9 lines
Documentation/devicetree/bindings/sound/fsl,spdif.txt +9 -0
+  - clock-names : Includes the following entries:
+	"core"		The core clock of spdif controller
+	"rxtx<0-7>"	Clock source list for tx and rx clock.
+			This clock list should be identical to
+			the source list connecting to the spdif
+			clock mux in "SPDIF Transceiver Clock
+			Diagram" of SoC reference manual. It
+			can also be referred to TxClk_Source
+			bit of register SPDIF_STC.

So, the HW block has 1 clock input, yet there's a mux somewhere else in the SoC which has 8 inputs?

If so, I'm not completely sure it's correct to reference anything other than the "core" clock in this binding. I think the other clocks would be more suitably represented in the system-level "sound card" binding that I guess patch 2/2 (which I haven't read yet) adds, since I assume those clock are more to do with system-level clock tree setup decisions, and might not even exist in some other SoC that included this IP block.

What do others think, assuming I'm correct about my HW design assumptions?

#8 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

In reply to Nicolin Chen

Documentation/devicetree/bindings/sound/imx-audio-spdif.txt line 18

Quoted 13 lines · Nicolin Chen

This patch implements a device-tree-only machine driver for Freescale i.MX series Soc. It works with spdif_transmitter/spdif_receiver and fsl_spdif.c drivers.

Documentation/devicetree/bindings/sound/imx-audio-spdif.txt +7 -0
 
+Optional properties:
+
+  - spdif-transmitter : The phandle of the spdif-transmitter dummy codec
+
+  - spdif-receiver : The phandle of the spdif-receiver dummy codec
+
+* Note: At least one of these two properties should be set in the DT binding.

Those object truly don't exist in HW and only exist due to internal details of Linux's ASoC subsystem.

Instead, you should register any SPDIF rx/tx dummy CODEC internally to the machine driver.

Perhaps you'll still need properties to indicate which of the RX and TX paths of the HW block are actually connected to anything on the board. Perhaps a Boolean property "spdif-tx" to indicate TX support, otherwise RX support is assumed?

Or, to map the properties more directly to HW, perhaps name the property "spdif-tx-jack-exists", or even "spdif-tx-jack" and make it a phandle to a node that represents the actual S/PDIF connector?

maintainer
#9 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

Quoted 9 lines · Stephen Warren
Quoted 7 lines · Nicolin Chen

This patch implements a device-tree-only machine driver for Freescale i.MX series Soc. It works with spdif_transmitter/spdif_receiver and fsl_spdif.c drivers.

Documentation/devicetree/bindings/sound/imx-audio-spdif.txt +1 -0
 
+Optional properties:
Quoted 7 lines

Documentation/devicetree/bindings/sound/imx-audio-spdif.txt line 18

Quoted 4 lines
Documentation/devicetree/bindings/sound/imx-audio-spdif.txt +3 -0
+  - spdif-transmitter : The phandle of the spdif-transmitter dummy codec
+  - spdif-receiver : The phandle of the spdif-receiver dummy codec
 
+* Note: At least one of these two properties should be set in the DT binding.

Those object truly don't exist in HW and only exist due to internal details of Linux's ASoC subsystem.

They will physically exist if they're usefully present on the board (in the sense that they're there and can be pointed at) - there will be either a TOSLINK optical connector or (less commonly) an electrical connector breaking the signal out to go elsewhere though they don't have any interaction with software usually which is more what you mean here.

Quoted 3 lines

Or, to map the properties more directly to HW, perhaps name the property "spdif-tx-jack-exists", or even "spdif-tx-jack" and make it a phandle to a node that represents the actual S/PDIF connector?

S/PDIF is also sometimes used as an interconnect between devices - some CODECs have S/PDIF I/O (more normally used as an external connector on the box). This is most frequently seen as a way to plumb HDMI in since some HDMI devices seem to provide this as a legacy interconnect, though it can get used just for regular CODECs as well. Using this machine driver would probably be a bit of an abuse for some applications, though with things like the HDMI one the goal of the hardware is to be dropped into a driver like this so perhaps it makes sense and is useful anyway.

Equally well it'd be good to get this stuff actually merged, it seems to have been surprisingly time consuming thus far...

#3 lore raw

Re: [PATCH v8 1/2] ASoC: fsl: Add S/PDIF CPU DAI driver

In reply to Sascha Hauer

Thank you Sascha, I'll revise them all in v9

Quoted 150 lines · Sascha Hauer

Hi Nicolas,

Some misc other comments inline.

sound/soc/fsl/fsl_spdif.c line 75

Quoted 8 lines · Nicolin Chen

This patch implements a device-tree-only CPU DAI driver for Freescale

sound/soc/fsl/fsl_spdif.c new file +7 -0
+
+struct fsl_spdif_priv {
+	struct spdif_mixer_control fsl_spdif_control;
+	struct snd_soc_dai_driver cpu_dai_drv;
+	struct platform_device *pdev;
+	struct regmap *regmap;
+	atomic_t dpll_locked;

You don't need an atomic_t to track a bool variable. Use a plain bool or int instead.

Quoted 21 lines
sound/soc/fsl/fsl_spdif.c new file +21 -0
+	u8 txclk_div[SPDIF_TXRATE_MAX];
+	u8 txclk_src[SPDIF_TXRATE_MAX];
+	u8 rxclk_src;
+	struct clk *txclk[SPDIF_TXRATE_MAX];
+	struct clk *rxclk;
+	struct snd_dmaengine_dai_dma_data dma_params_tx;
+	struct snd_dmaengine_dai_dma_data dma_params_rx;
+
+	/* The name space will be allocated dynamically */
+	char name[0];
+};
+
+
+#ifdef DEBUG
+static void dumpregs(struct fsl_spdif_priv *spdif_priv)
+{
+	struct regmap *regmap = spdif_priv->regmap;
+	struct platform_device *pdev = spdif_priv->pdev;
+	u32 val, i;
+	int ret;
+

sound/soc/fsl/fsl_spdif.c line 106

Quoted 10 lines
sound/soc/fsl/fsl_spdif.c new file +10 -0
+	/* Valid address set of SPDIF is {[0x0-0x38], 0x44, 0x50} */
+	for (i = 0 ; i <= REG_SPDIF_STC; i += 4) {
+		ret = regmap_read(regmap, REG_SPDIF_SCR + i, &val);
+		if (!ret)
+			dev_dbg(&pdev->dev, "REG 0x%02x = 0x%06x\n", i, val);
+	}
+}
+#else
+static void dumpregs(struct fsl_spdif_priv *spdif_priv) {}
+#endif

Is this needed? regmap provides a register dump in debugfs.

sound/soc/fsl/fsl_spdif.c line 366

Quoted 8 lines
sound/soc/fsl/fsl_spdif.c new file +8 -0
+
+static int spdif_clk_set_rate(struct clk *clk, unsigned long rate)
+{
+	unsigned long rate_actual;
+
+	rate_actual = clk_round_rate(clk, rate);
+	return clk_set_rate(clk, rate_actual);
+}

clk_round_rate returns the rate which clk_set_rate would set if called with the same rate. The clk_round_rate() is unnecessary.

sound/soc/fsl/fsl_spdif.c line 426

Quoted 5 lines
sound/soc/fsl/fsl_spdif.c new file +5 -0
+
+	dev_dbg(&pdev->dev, "expected clock rate = %d\n",
+			(int)(64 * sample_rate * div));
+	dev_dbg(&pdev->dev, "acutal clock rate = %d\n",
+			(int)clk_get_rate(spdif_priv->txclk[rate]));

s/acutal/actual/

Also please use %ld instead of casting the unsigned long to int.

sound/soc/fsl/fsl_spdif.c line 797

Quoted 4 lines
sound/soc/fsl/fsl_spdif.c new file +4 -0
+
+	dev_dbg(&pdev->dev, "FreqMeas: %d\n", (int)freqmeas);
+	dev_dbg(&pdev->dev, "BusclkFreq: %d\n", (int)busclk_freq);
+	dev_dbg(&pdev->dev, "RxRate: %d\n", (int)tmpval64);

Get rid of the casts

sound/soc/fsl/fsl_spdif.c line 1131

Quoted 5 lines
sound/soc/fsl/fsl_spdif.c new file +5 -0
+
+	spdif_priv = devm_kzalloc(&pdev->dev,
+			sizeof(struct fsl_spdif_priv) + strlen(np->name) + 1, GFP_KERNEL);
+	if (!spdif_priv) {
+		dev_err(&pdev->dev, "could not allocate DAI object\n");

Please drop this message. You'll never see it.

sound/soc/fsl/fsl_spdif.c line 1193

Quoted 11 lines
sound/soc/fsl/fsl_spdif.c new file +11 -0
+
+	for (i = 0; i < SPDIF_TXRATE_MAX; i++) {
+		ret = fsl_spdif_probe_txclk(spdif_priv, i);
+		if (ret)
+			return ret;
+	}
+
+	/* Prepare rx/tx clock */
+	clk_prepare(spdif_priv->rxclk);
+	for (i = 0; i < SPDIF_TXRATE_MAX; i++)
+		clk_prepare(spdif_priv->txclk[i]);

Why do you prepare all clocks instead of the one you actually use? Also, no need to do this here. You can use clk_prepare_enable instead where you have clk_enable now.

Quoted 10 lines
sound/soc/fsl/fsl_spdif.h new file +10 -0
+
+/* SPDIF rx clock source */
+enum spdif_rxclk_src {
+	SRPC_CLKSRC_0 = 0,
+	SRPC_CLKSRC_1,
+	SRPC_CLKSRC_2,
+	SRPC_CLKSRC_3,
+	SRPC_CLKSRC_4,
+	SRPC_CLKSRC_5,
+	SRPC_CLKSRC_6,

sound/soc/fsl/fsl_spdif.h line 129

Quoted 10 lines
sound/soc/fsl/fsl_spdif.h new file +10 -0
+	SRPC_CLKSRC_7,
+	SRPC_CLKSRC_8,
+	SRPC_CLKSRC_9,
+	SRPC_CLKSRC_10,
+	SRPC_CLKSRC_11,
+	SRPC_CLKSRC_12,
+	SRPC_CLKSRC_13,
+	SRPC_CLKSRC_14,
+	SRPC_CLKSRC_15,
+};

These are unused and look unnecessary.

sound/soc/fsl/fsl_spdif.h line 189

Quoted 12 lines
sound/soc/fsl/fsl_spdif.h new file +12 -0
+
+/* SPDIF tx clksrc */
+enum spdif_txclk_src {
+	STC_TXCLK_SRC_0 = 0,
+	STC_TXCLK_SRC_1,
+	STC_TXCLK_SRC_2,
+	STC_TXCLK_SRC_3,
+	STC_TXCLK_SRC_4,
+	STC_TXCLK_SRC_5,
+	STC_TXCLK_SRC_6,
+	STC_TXCLK_SRC_7,
+};

Also unused.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw

Re: [PATCH v8 1/2] ASoC: fsl: Add S/PDIF CPU DAI driver

In reply to Stephen Warren
Quoted 12 lines · Stephen Warren

Documentation/devicetree/bindings/sound/fsl,spdif.txt line 30

Quoted 8 lines
Documentation/devicetree/bindings/sound/fsl,spdif.txt new file +8 -0
+	"core"		The core clock of spdif controller
+	"rxtx<0-7>"	Clock source list for tx and rx clock.
+			This clock list should be identical to
+			the source list connecting to the spdif
+			clock mux in "SPDIF Transceiver Clock
+			Diagram" of SoC reference manual. It
+			can also be referred to TxClk_Source
+			bit of register SPDIF_STC.

So, the HW block has 1 clock input, yet there's a mux somewhere else in the SoC which has 8 inputs?

Quoted 8 lines

If so, I'm not completely sure it's correct to reference anything other than the "core" clock in this binding. I think the other clocks would be more suitably represented in the system-level "sound card" binding that I guess patch 2/2 (which I haven't read yet) adds, since I assume those clock are more to do with system-level clock tree setup decisions, and might not even exist in some other SoC that included this IP block.

What do others think, assuming I'm correct about my HW design assumptions?

The core clock is being only needed when accessing registers of this IP. Thus, in the driver, I let regmap handle it.

While the other 8 clocks are actual reference clocks for Tx. Tx clock needs to select one of them that can easily derive a child clock matching the tx sample rate. This is essential for the IP, so I don't think it's nicer to put into machine driver.

Thank you
Nicolin

#10 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

In reply to Mark Brown
Quoted 22 lines · Mark Brown
Quoted 15 lines · Stephen Warren
Quoted 13 lines · Nicolin Chen

This patch implements a device-tree-only machine driver for Freescale i.MX series Soc. It works with spdif_transmitter/spdif_receiver and fsl_spdif.c drivers.

diff --git a/Documentation/devicetree/bindings/sound/imx-audio-spdif.txt b/Documentation/devicetree/bindings/sound/imx-audio-spdif.txt

(quoted diff) +2 -0
+Optional properties:
 
+  - spdif-transmitter : The phandle of the spdif-transmitter

dummy codec + - spdif-receiver : The phandle of the spdif-receiver dummy codec

Quoted 5 lines
Quoted 2 lines

+* Note: At least one of these two properties should be set in the DT binding.

Those object truly don't exist in HW and only exist due to internal details of Linux's ASoC subsystem.

Quoted 6 lines

They will physically exist if they're usefully present on the board (in the sense that they're there and can be pointed at) - there will be either a TOSLINK optical connector or (less commonly) an electrical connector breaking the signal out to go elsewhere though they don't have any interaction with software usually which is more what you mean here.

Sure, the S/PDIF signal is connected to something, but it is not a "dummy CODEC"; a "dummy CODEC" is purely something internal to ASoC and absolutely nothing to do with HW.

Quoted 15 lines
Quoted 4 lines

Or, to map the properties more directly to HW, perhaps name the property "spdif-tx-jack-exists", or even "spdif-tx-jack" and make it a phandle to a node that represents the actual S/PDIF connector?

S/PDIF is also sometimes used as an interconnect between devices - some CODECs have S/PDIF I/O (more normally used as an external connector on the box). This is most frequently seen as a way to plumb HDMI in since some HDMI devices seem to provide this as a legacy interconnect, though it can get used just for regular CODECs as well. Using this machine driver would probably be a bit of an abuse for some applications, though with things like the HDMI one the goal of the hardware is to be dropped into a driver like this so perhaps it makes sense and is useful anyway.

Quoted 2 lines

Equally well it'd be good to get this stuff actually merged, it seems to have been surprisingly time consuming thus far...

That's not a good argument for an incorrect binding.

#6 lore raw

Re: [PATCH v8 1/2] ASoC: fsl: Add S/PDIF CPU DAI driver

In reply to Nicolin Chen
Quoted 22 lines · Nicolin Chen
Quoted 12 lines · Stephen Warren

Documentation/devicetree/bindings/sound/fsl,spdif.txt line 30

Quoted 8 lines
Documentation/devicetree/bindings/sound/fsl,spdif.txt new file +8 -0
+	"core"		The core clock of spdif controller
+	"rxtx<0-7>"	Clock source list for tx and rx clock.
+			This clock list should be identical to
+			the source list connecting to the spdif
+			clock mux in "SPDIF Transceiver Clock
+			Diagram" of SoC reference manual. It
+			can also be referred to TxClk_Source
+			bit of register SPDIF_STC.

So, the HW block has 1 clock input, yet there's a mux somewhere else in the SoC which has 8 inputs?

Quoted 8 lines

If so, I'm not completely sure it's correct to reference anything other than the "core" clock in this binding. I think the other clocks would be more suitably represented in the system-level "sound card" binding that I guess patch 2/2 (which I haven't read yet) adds, since I assume those clock are more to do with system-level clock tree setup decisions, and might not even exist in some other SoC that included this IP block.

What do others think, assuming I'm correct about my HW design assumptions?

Quoted 7 lines

The core clock is being only needed when accessing registers of this IP. Thus, in the driver, I let regmap handle it.

While the other 8 clocks are actual reference clocks for Tx. Tx clock needs to select one of them that can easily derive a child clock matching the tx sample rate. This is essential for the IP, so I don't think it's nicer to put into machine driver.

So just to be clear, the S/PDIF IP block truly has 8 rxtx clock input signals, and the mux between them is internal to the S/PDIF block? If so, then this aspect of the binding is fine.

maintainer
#11 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

In reply to Stephen Warren
Quoted 7 lines · Stephen Warren
Quoted 3 lines · Mark Brown

S/PDIF is also sometimes used as an interconnect between devices - some CODECs have S/PDIF I/O (more normally used as an external connector on the box). This is most frequently seen as a way to

That's not a good argument for an incorrect binding.

The point is that it might turn into a more correct binding depending on what the S/PDIF device actually is.

#12 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

Quoted 8 lines · Mark Brown
Quoted 6 lines · Stephen Warren
Quoted 4 lines · Mark Brown

S/PDIF is also sometimes used as an interconnect between devices - some CODECs have S/PDIF I/O (more normally used as an external connector on the box). This is most frequently seen as a way to

Quoted 4 lines
Quoted 1 line

That's not a good argument for an incorrect binding.

The point is that it might turn into a more correct binding depending on what the S/PDIF device actually is.

There's *never* an object on the board called a "dummy codec".

maintainer
#13 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

Quoted 6 lines · Stephen Warren
Quoted 2 lines · Mark Brown

The point is that it might turn into a more correct binding depending on what the S/PDIF device actually is.

There's *never* an object on the board called a "dummy codec".

Oh, is that what you're talking about? Yes, that makes sense. I had been responding to the comments about the transceivers.

#14 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

Quoted 10 lines · Mark Brown
Quoted 6 lines · Stephen Warren
Quoted 2 lines · Mark Brown

The point is that it might turn into a more correct binding depending on what the S/PDIF device actually is.

There's *never* an object on the board called a "dummy codec".

Oh, is that what you're talking about? Yes, that makes sense. I had been responding to the comments about the transceivers.

I'll remove the 'dummy' words in the next version from the binding doc.

Thank you
Nicolin

#15 lore raw

Re: [PATCH v8 2/2] ASoC: fsl: Add S/PDIF machine driver

Quoted 7 lines · Nicolin Chen
Quoted 6 lines · Mark Brown
Quoted 4 lines · Stephen Warren
Quoted 2 lines · Mark Brown

The point is that it might turn into a more correct binding depending on what the S/PDIF device actually is.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

There's *never* an object on the board called a "dummy codec".

Oh, is that what you're talking about? Yes, that makes sense. I had been responding to the comments about the transceivers.

I'll remove the 'dummy' words in the next version from the binding doc.

I think the word "CODEC" is also problematic in this context, since whatever is connector to the S/PDIF output path may not be a CODEC. That's why I suggested some more generic property names that IIRC concentrated on enabling rx/tx rather than indicating what was actually connected to the S/PDIF controller.