Skip to contentSkip to conversation

add ASoC components for AHUB

PATCH Superseded Sameer Pujar 3 participants 43 messages Jan 20, 2020 – Feb 19, 2020

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover add ASoC components for AHUB

Overview
========
The Audio Hub (AHUB) is part of the Audio Processing Engine (APE) which comprises a collection of hardware accelerators for audio pre-processing and post-processing. It also includes a programmable full crossbar for routing audio data across these accelerators.

This series exposes some of these below mentioned HW devices as ASoC components for Tegra platforms from Tegra210 onwards.
* ADMAIF : The interface between ADMA and AHUB

 * XBAR   : Crossbar for routing audio samples across various modules
 * I2S    : Inter-IC Sound Controller
 * DMIC   : Digital Microphone
 * DSPK   : Digital Speaker

Following is the summary of current series.
1. Add YAML DT binding documentation for above mentioned modules.
2. ACIF programming is same for Tegra generations and hence it is moved to a common file.
3. Add ASoC driver components for each of the above modules.
4. Add DT entries for above components for Tegra210, Tegra186 and

    Tegra194.

5. Enable these components for Jetson-Tx1, Jetson-Tx2 and Jetson-Xavier.

Machine driver series will be sent separately.

Sameer Pujar (9):
dt-bindings: sound: tegra: add DT binding for AHUB
ASoC: tegra: add support for CIF programming
ASoC: tegra: add Tegra210 based DMIC driver
ASoC: tegra: add Tegra210 based I2S driver
ASoC: tegra: add Tegra210 based AHUB driver
ASoC: tegra: add Tegra186 based DSPK driver
ASoC: tegra: add Tegra210 based ADMAIF driver
arm64: tegra: add AHUB components for few Tegra chips
arm64: tegra: enable AHUB modules for few Tegra chips

 .../bindings/sound/nvidia,tegra186-dspk.yaml       | 105 +++
 .../bindings/sound/nvidia,tegra210-admaif.yaml     | 165 ++++
 .../bindings/sound/nvidia,tegra210-ahub.yaml       | 130 +++
 .../bindings/sound/nvidia,tegra210-dmic.yaml       | 105 +++
 .../bindings/sound/nvidia,tegra210-i2s.yaml        | 112 +++
 arch/arm64/boot/dts/nvidia/tegra186-p2771-0000.dts |  48 ++
 arch/arm64/boot/dts/nvidia/tegra186.dtsi           | 231 ++++-
 arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts |  36 +
 arch/arm64/boot/dts/nvidia/tegra194.dtsi           | 239 +++++-
 arch/arm64/boot/dts/nvidia/tegra210-p2371-2180.dts |  40 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi           | 145 ++++
 sound/soc/tegra/Kconfig                            |  56 ++
 sound/soc/tegra/Makefile                           |  12 +
 sound/soc/tegra/tegra186_dspk.c                    | 516 +++++++++++
 sound/soc/tegra/tegra186_dspk.h                    |  73 ++
 sound/soc/tegra/tegra210_admaif.c                  | 896 ++++++++++++++++++++
 sound/soc/tegra/tegra210_admaif.h                  | 164 ++++
 sound/soc/tegra/tegra210_ahub.c                    | 667 +++++++++++++++
 sound/soc/tegra/tegra210_ahub.h                    | 125 +++
 sound/soc/tegra/tegra210_dmic.c                    | 522 ++++++++++++
 sound/soc/tegra/tegra210_dmic.h                    |  85 ++
 sound/soc/tegra/tegra210_i2s.c                     | 941 +++++++++++++++++++++
 sound/soc/tegra/tegra210_i2s.h                     | 132 +++
 sound/soc/tegra/tegra30_ahub.c                     |  94 +-
 sound/soc/tegra/tegra30_ahub.h                     | 129 ---
 sound/soc/tegra/tegra30_i2s.c                      |  35 +-
 sound/soc/tegra/tegra30_i2s.h                      |   7 -
 sound/soc/tegra/tegra_cif.c                        |  34 +
 sound/soc/tegra/tegra_cif.h                        |  50 ++
 sound/soc/tegra/tegra_pcm.c                        | 224 ++++-
 sound/soc/tegra/tegra_pcm.h                        |  23 +-
 31 files changed, 5897 insertions(+), 244 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra186-dspk.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-admaif.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-dmic.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-i2s.yaml
 create mode 100644 sound/soc/tegra/tegra186_dspk.c
 create mode 100644 sound/soc/tegra/tegra186_dspk.h
 create mode 100644 sound/soc/tegra/tegra210_admaif.c
 create mode 100644 sound/soc/tegra/tegra210_admaif.h
 create mode 100644 sound/soc/tegra/tegra210_ahub.c
 create mode 100644 sound/soc/tegra/tegra210_ahub.h
 create mode 100644 sound/soc/tegra/tegra210_dmic.c
 create mode 100644 sound/soc/tegra/tegra210_dmic.h
 create mode 100644 sound/soc/tegra/tegra210_i2s.c
 create mode 100644 sound/soc/tegra/tegra210_i2s.h
 create mode 100644 sound/soc/tegra/tegra_cif.c
 create mode 100644 sound/soc/tegra/tegra_cif.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/9 dt-bindings: sound: tegra: add DT binding for AHUB

Audio Hub (AHUB) comprises a collection of hardware accelerators for audio pre-processing and post-processing and a programmable full crossbar for audio routing across these accelerators. This patch adds YAML schema for DT binding of AHUB and few of its following components. These devices will be registered as ASoC components.
* ADMAIF
* I2S
* DMIC
* DSPK

---
 .../bindings/sound/nvidia,tegra186-dspk.yaml       | 105 +++++++++++++
 .../bindings/sound/nvidia,tegra210-admaif.yaml     | 165 +++++++++++++++++++++
 .../bindings/sound/nvidia,tegra210-ahub.yaml       | 130 ++++++++++++++++
 .../bindings/sound/nvidia,tegra210-dmic.yaml       | 105 +++++++++++++
 .../bindings/sound/nvidia,tegra210-i2s.yaml        | 112 ++++++++++++++
 5 files changed, 617 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra186-dspk.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-admaif.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-dmic.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-i2s.yaml
Documentation/devicetree/bindings/sound/nvidia,tegra186-dspk.yaml new file +105 -0
new file mode 100644
index 0000000..dc9fef3
@@ -0,0 +1,105 @@
+# SPDX-License-Identifier: (GPL-2.0)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/nvidia,tegra186-dspk.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Tegra186 DSPK Controller Device Tree Bindings
+
+description: |
+  The Digital Speaker Controller (DSPK) can be viewed as a Pulse
+  Density Modulation (PDM) transmitter that up-samples the input to
+  the desired sampling rate by interpolation and then converts the
+  over sampled Pulse Code Modulation (PCM) input to the desired 1-bit
+  output via Delta Sigma Modulation (DSM).
+
+maintainers:
+  - Jon Hunter <[email protected]>
+  - Sameer Pujar <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          const: nvidia,tegra186-dspk
+      - items:
+          - enum:
+              - nvidia,tegra194-dspk
+          - enum:
+              - nvidia,tegra186-dspk
+
+  reg:
+    description: offset and length of the register set for the device.
+    maxItems: 1
+
+  clocks:
+    description: must contain an entry for each entry in clock-names.
+      See ../clocks/clocks-bindings.txt for details.
+    minItems: 1
+    items:
+      - description: Module clock
+
+  clock-names:
+    description: must contain clock names for each corresponding entry in clocks.
+      See ../clocks/clocks-bindings.txt for details.
+    minItems: 1
+    items:
+      - const: dspk
+
+  assigned-clocks:
+    description: list of input clocks and dividers for the audio system.
+      See ../clocks/clock-bindings.txt for details.
+    minItems: 1
+    items:
+      - description: Module clock
+
+  assigned-clock-parents:
+    description: parent clock for each entry in assigned-clocks
+      See ../clocks/clock-bindings.txt for details.
+    minItems: 1
+    items:
+      - description: Parent for module clock
+
+  assigned-clock-rates:
+    description: clock rate for each entry in assigned-clocks
+      See ../clocks/clock-bindings.txt for details.
+    items:
+      - description: initial module clock rate
+
+  "#sound-dai-cells":
+    const: 1
+
+  sound-name-prefix:
+    $ref: /schemas/types.yaml#/definitions/string
+    description:
+      Used as prefix for sink/source names of the component. Must be a
+      unique string among multiple instances of the same component.
+      The name can be "DSPK1" or "DSPKx", where x depends on the maximum
+      available instances on a Tegra SoC.
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - assigned-clocks
+  - assigned-clock-parents
+  - "#sound-dai-cells"
+
+examples:
+  - |
+    #include<dt-bindings/clock/tegra186-clock.h>
+
+    tegra_dspk1: dspk@2905000 {
+        compatible = "nvidia,tegra186-dspk";
+        reg = <0x2905000 0x100>;
+        clocks = <&bpmp TEGRA186_CLK_DSPK1>;
+        clock-names = "dspk";
+        assigned-clocks = <&bpmp TEGRA186_CLK_DSPK1>;
+        assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+        assigned-clock-rates = <12288000>;
+        #sound-dai-cells = <1>;
+        sound-name-prefix = "DSPK1";
+    };
+
+...
Documentation/devicetree/bindings/sound/nvidia,tegra210-admaif.yaml new file +165 -0

165 lines not on this page · raw message

Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml new file +130 -0

130 lines not on this page · raw message

Documentation/devicetree/bindings/sound/nvidia,tegra210-dmic.yaml new file +105 -0

105 lines not on this page · raw message

Documentation/devicetree/bindings/sound/nvidia,tegra210-i2s.yaml new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/9 ASoC: tegra: add support for CIF programming

In reply to Sameer Pujar

Audio Client Interface (CIF) is a proprietary interface employed to route audio samples through Audio Hub (AHUB) components by inter connecting the various modules. This patch exposes a helper function to program CIF instance present in various modules. Update Makefile to build tegra_cif.c and build dependency is added over config CONFIG_SND_SOC_TEGRA.

Tegra30 and Tegra124 have an identical CIF programming helper function. Remove tegra30_ahub_set_cif(), tegra124_ahub_set_cif() and instead we can rely on common exposed function tegra_set_cif(). Tegra30 and Tegra124 I2S driver uses soc_data to reference different versions of set_audio_cif function via callback function pointer. This is no more required with current patch and hence remove soc_data from i2s driver.

Also update variable names for audio and client channels. This is required to avoid wrapping in function tegra_set_cif().

---
 sound/soc/tegra/Makefile       |   2 +
 sound/soc/tegra/tegra30_ahub.c |  94 +++++-------------------------
 sound/soc/tegra/tegra30_ahub.h | 129 -----------------------------------------
 sound/soc/tegra/tegra30_i2s.c  |  35 ++++-------
 sound/soc/tegra/tegra30_i2s.h  |   7 ---
 sound/soc/tegra/tegra_cif.c    |  34 +++++++++++
 sound/soc/tegra/tegra_cif.h    |  50 ++++++++++++++++
 7 files changed, 111 insertions(+), 240 deletions(-)
 create mode 100644 sound/soc/tegra/tegra_cif.c
 create mode 100644 sound/soc/tegra/tegra_cif.h
sound/soc/tegra/Makefile +2 -0
index c84f183..261aa21 100644
@@ -8,9 +8,11 @@ snd-soc-tegra20-i2s-objs := tegra20_i2s.o
 snd-soc-tegra20-spdif-objs := tegra20_spdif.o
 snd-soc-tegra30-ahub-objs := tegra30_ahub.o
 snd-soc-tegra30-i2s-objs := tegra30_i2s.o
+snd-soc-tegra-cif-objs := tegra_cif.o
 
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
+obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-cif.o
 obj-$(CONFIG_SND_SOC_TEGRA20_AC97) += snd-soc-tegra20-ac97.o
 obj-$(CONFIG_SND_SOC_TEGRA20_DAS) += snd-soc-tegra20-das.o
 obj-$(CONFIG_SND_SOC_TEGRA20_I2S) += snd-soc-tegra20-i2s.o
sound/soc/tegra/tegra30_ahub.c +13 -81

160 lines not on this page · raw message

sound/soc/tegra/tegra30_ahub.h +0 -129

143 lines not on this page · raw message

sound/soc/tegra/tegra30_i2s.c +12 -23
index dbed3c5..36d7f4f 100644
@@ -32,6 +32,7 @@
 
 #include "tegra30_ahub.h"
 #include "tegra30_i2s.h"
+#include "tegra_cif.h"
 
 #define DRV_NAME "tegra30-i2s"
 
@@ -128,7 +129,7 @@ static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
 	struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
 	unsigned int mask, val, reg;
 	int ret, sample_size, srate, i2sclock, bitcnt, audio_bits;
-	struct tegra30_ahub_cif_conf cif_conf;
+	struct tegra_cif_conf cif_conf;
 
 	if (params_channels(params) != 2)
 		return -EINVAL;
@@ -137,17 +138,17 @@ static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S16_LE:
 		val = TEGRA30_I2S_CTRL_BIT_SIZE_16;
-		audio_bits = TEGRA30_AUDIOCIF_BITS_16;
+		audio_bits = TEGRA_ACIF_BITS_16;
 		sample_size = 16;
 		break;
 	case SNDRV_PCM_FORMAT_S24_LE:
 		val = TEGRA30_I2S_CTRL_BIT_SIZE_24;
-		audio_bits = TEGRA30_AUDIOCIF_BITS_24;
+		audio_bits = TEGRA_ACIF_BITS_24;
 		sample_size = 24;
 		break;
 	case SNDRV_PCM_FORMAT_S32_LE:
 		val = TEGRA30_I2S_CTRL_BIT_SIZE_32;
-		audio_bits = TEGRA30_AUDIOCIF_BITS_32;
+		audio_bits = TEGRA_ACIF_BITS_32;
 		sample_size = 32;
 		break;
 	default:
@@ -179,8 +180,8 @@ static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
 	regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val);
 
 	cif_conf.threshold = 0;
-	cif_conf.audio_channels = 2;
-	cif_conf.client_channels = 2;
+	cif_conf.audio_ch = 2;
+	cif_conf.client_ch = 2;
 	cif_conf.audio_bits = audio_bits;
 	cif_conf.client_bits = audio_bits;
 	cif_conf.expand = 0;
@@ -189,15 +190,12 @@ static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
 	cif_conf.truncate = 0;
 	cif_conf.mono_conv = 0;
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		reg = TEGRA30_I2S_CIF_RX_CTRL;
-	} else {
-		cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
+	else
 		reg = TEGRA30_I2S_CIF_TX_CTRL;
-	}
 
-	i2s->soc_data->set_audio_cif(i2s->regmap, reg, &cif_conf);
+	tegra_set_cif(i2s->regmap, reg, &cif_conf);
 
 	val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) |
 	      (1 << TEGRA30_I2S_OFFSET_TX_DATA_OFFSET_SHIFT);
@@ -393,17 +391,9 @@ static const struct regmap_config tegra30_i2s_regmap_config = {
 	.cache_type = REGCACHE_FLAT,
 };
 
-static const struct tegra30_i2s_soc_data tegra30_i2s_config = {
-	.set_audio_cif = tegra30_ahub_set_cif,
-};
-
-static const struct tegra30_i2s_soc_data tegra124_i2s_config = {
-	.set_audio_cif = tegra124_ahub_set_cif,
-};
-
 static const struct of_device_id tegra30_i2s_of_match[] = {
-	{ .compatible = "nvidia,tegra124-i2s", .data = &tegra124_i2s_config },
-	{ .compatible = "nvidia,tegra30-i2s", .data = &tegra30_i2s_config },
+	{ .compatible = "nvidia,tegra124-i2s", },
+	{ .compatible = "nvidia,tegra30-i2s", },
 	{},
 };
 
@@ -428,7 +418,6 @@ static int tegra30_i2s_platform_probe(struct platform_device *pdev)
 		ret = -ENODEV;
 		goto err;
 	}
-	i2s->soc_data = (struct tegra30_i2s_soc_data *)match->data;
 
 	i2s->dai = tegra30_i2s_dai_template;
 	i2s->dai.name = dev_name(&pdev->dev);
sound/soc/tegra/tegra30_i2s.h +0 -7
index 0b1f312..e2f0d3f 100644
@@ -214,14 +214,7 @@
 #define TEGRA30_I2S_LCOEF_COEF_MASK_US			0xffff
 #define TEGRA30_I2S_LCOEF_COEF_MASK			(TEGRA30_I2S_LCOEF_COEF_MASK_US << TEGRA30_I2S_LCOEF_COEF_SHIFT)
 
-struct tegra30_i2s_soc_data {
-	void (*set_audio_cif)(struct regmap *regmap,
-			      unsigned int reg,
-			      struct tegra30_ahub_cif_conf *conf);
-};
-
 struct tegra30_i2s {
-	const struct tegra30_i2s_soc_data *soc_data;
 	struct snd_soc_dai_driver dai;
 	int cif_id;
 	struct clk *clk_i2s;
sound/soc/tegra/tegra_cif.c new file +34 -0
new file mode 100644
index 0000000..d9f288c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * tegra_cif.c - Tegra Audio CIF Programming for AHUB modules
+ *
+ * Copyright (c) 2020 NVIDIA CORPORATION.  All rights reserved.
+ *
+ */
+
+#include <linux/regmap.h>
+#include <linux/module.h>
+#include "tegra_cif.h"
+
+void tegra_set_cif(struct regmap *regmap, unsigned int reg,
+		   struct tegra_cif_conf *conf)
+{
+	unsigned int value;
+
+	value = (conf->threshold << TEGRA_ACIF_CTRL_FIFO_THRESHOLD_SHIFT) |
+		((conf->audio_ch - 1) << TEGRA_ACIF_CTRL_AUDIO_CH_SHIFT) |
+		((conf->client_ch - 1) << TEGRA_ACIF_CTRL_CLIENT_CH_SHIFT) |
+		(conf->audio_bits << TEGRA_ACIF_CTRL_AUDIO_BITS_SHIFT) |
+		(conf->client_bits << TEGRA_ACIF_CTRL_CLIENT_BITS_SHIFT) |
+		(conf->expand << TEGRA_ACIF_CTRL_EXPAND_SHIFT) |
+		(conf->stereo_conv << TEGRA_ACIF_CTRL_STEREO_CONV_SHIFT) |
+		(conf->replicate << TEGRA_ACIF_CTRL_REPLICATE_SHIFT) |
+		(conf->truncate << TEGRA_ACIF_CTRL_TRUNCATE_SHIFT) |
+		(conf->mono_conv << TEGRA_ACIF_CTRL_MONO_CONV_SHIFT);
+
+	regmap_update_bits(regmap, reg, TEGRA_ACIF_UPDATE_MASK, value);
+}
+EXPORT_SYMBOL_GPL(tegra_set_cif);
+
+MODULE_DESCRIPTION("Tegra Audio Client Interface (ACIF) driver");
+MODULE_LICENSE("GPL v2");
sound/soc/tegra/tegra_cif.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

Re: [alsa-devel] [PATCH 2/9] ASoC: tegra: add support for CIF programming

Hello Sameer,

20.01.2020 17:23, Sameer Pujar пишет:

[snip]

Quoted 1 line

Tegra30 and Tegra124 have an identical CIF programming helper function.

[snip]

sound/soc/tegra/tegra30_ahub.h line 24

Quoted 8 lines
sound/soc/tegra/tegra30_ahub.h +0 -8
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT	24
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US	0x3f
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK	(TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US << TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT)
-
-/* Channel count minus 1 */
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT	24
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US	7
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK	(TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT)

The AUDIOCIF_CTRL bitfields are not the same on T30 and T124, why are you claiming that programming is identical? Have you actually tried to test these patches on T30?

#4 lore raw

Re: [alsa-devel] [PATCH 2/9] ASoC: tegra: add support for CIF programming

Quoted 12 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

Hello Sameer,

20.01.2020 17:23, Sameer Pujar пишет:

[snip]

Quoted 1 line

Tegra30 and Tegra124 have an identical CIF programming helper function.

[snip]

Quoted 11 lines

sound/soc/tegra/tegra30_ahub.h line 24

Quoted 8 lines
sound/soc/tegra/tegra30_ahub.h +0 -8
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT  24
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US        0x3f
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK   (TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US << TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT)
-
-/* Channel count minus 1 */
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT   24
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 7
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK    (TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US << TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT)

The AUDIOCIF_CTRL bitfields are not the same on T30 and T124, why are you claiming that programming is identical? Have you actually tried to test these patches on T30?

Oh yes! seems like I overlooked the macro values. Thanks for pointing this. I will retain separate CIF function for Tegra30. I do not have a Tegra30 board with me and hence could not test anything specific to it apart from build sanity. If someone can help me test I would really appreciate.

#5 lore raw

Re: [alsa-devel] [PATCH 2/9] ASoC: tegra: add support for CIF programming

21.01.2020 07:41, Sameer Pujar пишет:

Quoted 30 lines · Dmitry Osipenko
Quoted 12 lines

External email: Use caution opening links or attachments

Hello Sameer,

20.01.2020 17:23, Sameer Pujar пишет:

[snip]

Quoted 1 line

Tegra30 and Tegra124 have an identical CIF programming helper function.

[snip]

Quoted 15 lines
Quoted 10 lines
sound/soc/tegra/tegra30_ahub.h +0 -3
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT  24
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US        0x3f
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK  

(TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US <<
TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT)

sound/soc/tegra/tegra30_ahub.h +0 -5
-
-/* Channel count minus 1 */
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT   24
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 7
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK   
Quoted 2 lines

(TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US <<
TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT)

The AUDIOCIF_CTRL bitfields are not the same on T30 and T124, why are you claiming that programming is identical? Have you actually tried to test these patches on T30?

Quoted 6 lines

Oh yes! seems like I overlooked the macro values. Thanks for pointing this. I will retain separate CIF function for Tegra30.
I do not have a Tegra30 board with me and hence could not test anything specific to it apart from build sanity.
If someone can help me test I would really appreciate.

I'll help with the testing once all obvious problems will be fixed.

#6 lore raw

Re: [alsa-devel] [PATCH 2/9] ASoC: tegra: add support for CIF programming

Quoted 32 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

21.01.2020 07:41, Sameer Pujar пишет:

Quoted 28 lines · Dmitry Osipenko
Quoted 27 lines

External email: Use caution opening links or attachments

Hello Sameer,

20.01.2020 17:23, Sameer Pujar пишет:

[snip]

Quoted 1 line

Tegra30 and Tegra124 have an identical CIF programming helper function.

[snip]

Quoted 10 lines
sound/soc/tegra/tegra30_ahub.h +0 -3
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT  24
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US        0x3f
-#define TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK

(TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_MASK_US <<
TEGRA124_AUDIOCIF_CTRL_FIFO_THRESHOLD_SHIFT)

sound/soc/tegra/tegra30_ahub.h +0 -5
-
-/* Channel count minus 1 */
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT   24
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US 7
-#define TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK
Quoted 2 lines

(TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_MASK_US <<
TEGRA30_AUDIOCIF_CTRL_AUDIO_CHANNELS_SHIFT)

The AUDIOCIF_CTRL bitfields are not the same on T30 and T124, why are you claiming that programming is identical? Have you actually tried to test these patches on T30?

Quoted 7 lines
Quoted 6 lines

Oh yes! seems like I overlooked the macro values. Thanks for pointing this. I will retain separate CIF function for Tegra30.
I do not have a Tegra30 board with me and hence could not test anything specific to it apart from build sanity.
If someone can help me test I would really appreciate.

I'll help with the testing once all obvious problems will be fixed.

Thanks Dmitry. However I plan to send Tegra30 related patch separately. In this series I will focus on Tegra210 and later.

#7 lore raw

Re: [alsa-devel] [PATCH 2/9] ASoC: tegra: add support for CIF programming

27.01.2020 08:11, Sameer Pujar пишет:

Quoted 1 line

Thanks Dmitry. However I plan to send Tegra30 related patch separately.

Feel free to add me to the email's CC if you'll need to test or review anything related to the T20/30.

Quoted 1 line

In this series I will focus on Tegra210 and later.

Please be more careful next time and try not to break the existing functionality, looking forward to v2 :)

#8 lore raw

PATCH 3/9 ASoC: tegra: add Tegra210 based DMIC driver

In reply to Sameer Pujar

The Digital MIC (DMIC) Controller is used to interface with Pulse Density Modulation (PDM) input devices. The DMIC controller implements a converter to convert PDM signals to Pulse Code Modulation (PCM) signals. From signal flow perspective, the DMIC can be viewed as a PDM receiver.

This patch registers DMIC component with ASoC framework. The component driver exposes DAPM widgets, routes and kcontrols for the device. The DAI driver exposes DMIC interfaces, which can be used to connect different components in the ASoC layer. Makefile and Kconfig support is added to allow to build the driver. The DMIC devices can be enabled in the DT via "nvidia,tegra210-dmic" compatible string. This driver can be used for Tegra186 and Tegra194 chips as well.

---
 sound/soc/tegra/Kconfig         |  11 +
 sound/soc/tegra/Makefile        |   2 +
 sound/soc/tegra/tegra210_dmic.c | 522 ++++++++++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra210_dmic.h |  85 +++++++
 4 files changed, 620 insertions(+)
 create mode 100644 sound/soc/tegra/tegra210_dmic.c
 create mode 100644 sound/soc/tegra/tegra210_dmic.h
sound/soc/tegra/Kconfig +11 -0
index addadc8..2bde1e6 100644
@@ -62,6 +62,17 @@ config SND_SOC_TEGRA30_I2S
 	  Tegra30 I2S interface. You will also need to select the individual
 	  machine drivers to support below.
 
+config SND_SOC_TEGRA210_DMIC
+        tristate "Tegra210 DMIC module"
+        depends on SND_SOC_TEGRA
+        help
+          Config to enable the Digital MIC (DMIC) controller which is used
+          to interface with Pulse Density Modulation (PDM) input devices.
+          The DMIC controller implements a converter to convert PDM signals
+          to Pulse Code Modulation (PCM) signals. This can be viewed as a
+          PDM receiver.
+          Say Y or M if you want to add support for Tegra210 DMIC module.
+
 config SND_SOC_TEGRA_RT5640
 	tristate "SoC Audio support for Tegra boards using an RT5640 codec"
 	depends on SND_SOC_TEGRA && I2C && GPIOLIB
sound/soc/tegra/Makefile +2 -0
index 261aa21..9e78fe4 100644
@@ -9,6 +9,7 @@ snd-soc-tegra20-spdif-objs := tegra20_spdif.o
 snd-soc-tegra30-ahub-objs := tegra30_ahub.o
 snd-soc-tegra30-i2s-objs := tegra30_i2s.o
 snd-soc-tegra-cif-objs := tegra_cif.o
+snd-soc-tegra210-dmic-objs := tegra210_dmic.o
 
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
@@ -19,6 +20,7 @@ obj-$(CONFIG_SND_SOC_TEGRA20_I2S) += snd-soc-tegra20-i2s.o
 obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o
 obj-$(CONFIG_SND_SOC_TEGRA30_AHUB) += snd-soc-tegra30-ahub.o
 obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
+obj-$(CONFIG_SND_SOC_TEGRA210_DMIC) += snd-soc-tegra210-dmic.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
sound/soc/tegra/tegra210_dmic.c new file +522 -0

522 lines not on this page · raw message

sound/soc/tegra/tegra210_dmic.h new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.7.4
#9 lore raw

PATCH 4/9 ASoC: tegra: add Tegra210 based I2S driver

In reply to Sameer Pujar

The Inter-IC Sound (I2S) controller implements full-duplex, bi-directional and single direction point to point serial interface. It can interface with I2S compatible devices. Tegra I2S controller can operate as both master and slave.

This patch registers I2S controller with ASoC framework. The component driver exposes DAPM widgets, routes and kcontrols for the device. The DAI driver exposes I2S interfaces, which can be used to connect different components in the ASoC layer. Makefile and Kconfig support is added to allow to build the driver. The I2S devices can be enabled in the DT via "nvidia,tegra210-i2s" compatible binding.

---
 sound/soc/tegra/Kconfig        |  10 +
 sound/soc/tegra/Makefile       |   2 +
 sound/soc/tegra/tegra210_i2s.c | 941 +++++++++++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra210_i2s.h | 132 ++++++
 4 files changed, 1085 insertions(+)
 create mode 100644 sound/soc/tegra/tegra210_i2s.c
 create mode 100644 sound/soc/tegra/tegra210_i2s.h
sound/soc/tegra/Kconfig +10 -0
index 2bde1e6..157fa7a 100644
@@ -73,6 +73,16 @@ config SND_SOC_TEGRA210_DMIC
           PDM receiver.
           Say Y or M if you want to add support for Tegra210 DMIC module.
 
+config SND_SOC_TEGRA210_I2S
+        tristate "Tegra210 I2S module"
+        depends on SND_SOC_TEGRA
+        help
+          Config to enable the Inter-IC Sound (I2S) Controller which
+          implements full-duplex and bidirectional and single direction
+          point-to-point serial interfaces. It can interface with I2S
+          compatible devices.
+          Say Y or M if you want to add support for Tegra210 I2S module.
+
 config SND_SOC_TEGRA_RT5640
 	tristate "SoC Audio support for Tegra boards using an RT5640 codec"
 	depends on SND_SOC_TEGRA && I2C && GPIOLIB
sound/soc/tegra/Makefile +2 -0
index 9e78fe4..1c4457d 100644
@@ -10,6 +10,7 @@ snd-soc-tegra30-ahub-objs := tegra30_ahub.o
 snd-soc-tegra30-i2s-objs := tegra30_i2s.o
 snd-soc-tegra-cif-objs := tegra_cif.o
 snd-soc-tegra210-dmic-objs := tegra210_dmic.o
+snd-soc-tegra210-i2s-objs := tegra210_i2s.o
 
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
@@ -21,6 +22,7 @@ obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o
 obj-$(CONFIG_SND_SOC_TEGRA30_AHUB) += snd-soc-tegra30-ahub.o
 obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 obj-$(CONFIG_SND_SOC_TEGRA210_DMIC) += snd-soc-tegra210-dmic.o
+obj-$(CONFIG_SND_SOC_TEGRA210_I2S) += snd-soc-tegra210-i2s.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
sound/soc/tegra/tegra210_i2s.c new file +941 -0

941 lines not on this page · raw message

sound/soc/tegra/tegra210_i2s.h new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.7.4
#10 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

20.01.2020 17:23, Sameer Pujar пишет:

Quoted 79 lines

The Inter-IC Sound (I2S) controller implements full-duplex, bi-directional and single direction point to point serial interface. It can interface with I2S compatible devices. Tegra I2S controller can operate as both master and slave.

This patch registers I2S controller with ASoC framework. The component driver exposes DAPM widgets, routes and kcontrols for the device. The DAI driver exposes I2S interfaces, which can be used to connect different components in the ASoC layer. Makefile and Kconfig support is added to allow to build the driver. The I2S devices can be enabled in the DT via "nvidia,tegra210-i2s" compatible binding.

---
 sound/soc/tegra/Kconfig        |  10 +
 sound/soc/tegra/Makefile       |   2 +
 sound/soc/tegra/tegra210_i2s.c | 941 +++++++++++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra210_i2s.h | 132 ++++++
 4 files changed, 1085 insertions(+)
 create mode 100644 sound/soc/tegra/tegra210_i2s.c
 create mode 100644 sound/soc/tegra/tegra210_i2s.h
sound/soc/tegra/Kconfig +10 -0
index 2bde1e6..157fa7a 100644
@@ -73,6 +73,16 @@ config SND_SOC_TEGRA210_DMIC
           PDM receiver.
           Say Y or M if you want to add support for Tegra210 DMIC module.
 
+config SND_SOC_TEGRA210_I2S
+        tristate "Tegra210 I2S module"
+        depends on SND_SOC_TEGRA
+        help
+          Config to enable the Inter-IC Sound (I2S) Controller which
+          implements full-duplex and bidirectional and single direction
+          point-to-point serial interfaces. It can interface with I2S
+          compatible devices.
+          Say Y or M if you want to add support for Tegra210 I2S module.
+
 config SND_SOC_TEGRA_RT5640
 	tristate "SoC Audio support for Tegra boards using an RT5640 codec"
 	depends on SND_SOC_TEGRA && I2C && GPIOLIB
sound/soc/tegra/Makefile +2 -0
index 9e78fe4..1c4457d 100644
@@ -10,6 +10,7 @@ snd-soc-tegra30-ahub-objs := tegra30_ahub.o
 snd-soc-tegra30-i2s-objs := tegra30_i2s.o
 snd-soc-tegra-cif-objs := tegra_cif.o
 snd-soc-tegra210-dmic-objs := tegra210_dmic.o
+snd-soc-tegra210-i2s-objs := tegra210_i2s.o
 
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
@@ -21,6 +22,7 @@ obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o
 obj-$(CONFIG_SND_SOC_TEGRA30_AHUB) += snd-soc-tegra30-ahub.o
 obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 obj-$(CONFIG_SND_SOC_TEGRA210_DMIC) += snd-soc-tegra210-dmic.o
+obj-$(CONFIG_SND_SOC_TEGRA210_I2S) += snd-soc-tegra210-i2s.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
sound/soc/tegra/tegra210_i2s.c new file +10 -0
new file mode 100644
index 0000000..36e8a7c
@@ -0,0 +1,941 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * tegra210_i2s.c - Tegra210 I2S driver
+ *
+ * Copyright (c) 2020 NVIDIA CORPORATION.  All rights reserved.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>

sound/soc/tegra/tegra210_i2s.c line 20

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+#include <linux/of_device.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/clk.h>
+#include <sound/pcm_params.h>
+#include <sound/core.h>
+#include <sound/soc.h>
+#include "tegra210_i2s.h"
+#include "tegra_cif.h"

Headers should be sorted in alphabet order to avoid confusion about how to insert a new header.

Quoted 137 lines
sound/soc/tegra/tegra210_i2s.c new file +137 -0
+#define DRV_NAME "tegra210-i2s"
+
+static const struct reg_default tegra210_i2s_reg_defaults[] = {
+	{ TEGRA210_I2S_RX_INT_MASK, 0x00000003},
+	{ TEGRA210_I2S_RX_CIF_CTRL, 0x00007700},
+	{ TEGRA210_I2S_TX_INT_MASK, 0x00000003},
+	{ TEGRA210_I2S_TX_CIF_CTRL, 0x00007700},
+	{ TEGRA210_I2S_CG, 0x1},
+	{ TEGRA210_I2S_TIMING, 0x0000001f},
+	{ TEGRA210_I2S_ENABLE, 0x1},
+	/*
+	 * Below update does not have any effect on Tegra186 and Tegra194.
+	 * On Tegra210, I2S4 has "i2s4a" and "i2s4b" pins and below update
+	 * is required to select i2s4b for it to be functional for I2S
+	 * operation.
+	 */
+	{ TEGRA210_I2S_CYA, 0x1},
+};
+
+static void tegra210_i2s_set_slot_ctrl(struct regmap *regmap,
+				       unsigned int total_slots,
+				       unsigned int tx_slot_mask,
+				       unsigned int rx_slot_mask)
+{
+	regmap_write(regmap, TEGRA210_I2S_SLOT_CTRL, total_slots - 1);
+	regmap_write(regmap, TEGRA210_I2S_TX_SLOT_CTRL, tx_slot_mask);
+	regmap_write(regmap, TEGRA210_I2S_RX_SLOT_CTRL, rx_slot_mask);
+}
+
+static int tegra210_i2s_set_clock_rate(struct device *dev,
+				       unsigned int clock_rate)
+{
+	struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+	unsigned int val;
+	int ret;
+
+	regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &val);
+
+	/* No need to set rates if I2S is being operated in slave */
+	if (!(val & I2S_CTRL_MASTER_EN))
+		return 0;
+
+	ret = clk_set_rate(i2s->clk_i2s, clock_rate);
+	if (ret) {
+		dev_err(dev, "failed to set I2S bit clock rate %u, err: %d\n",
+			clock_rate, ret);
+		return ret;
+	}
+
+	if (!IS_ERR(i2s->clk_sync_input)) {
+		/*
+		 * Other I/O modules in AHUB can use i2s bclk as reference
+		 * clock. Below sets sync input clock rate as per bclk,
+		 * which can be used as input to other I/O modules.
+		 */
+		ret = clk_set_rate(i2s->clk_sync_input, clock_rate);
+		if (ret) {
+			dev_err(dev,
+				"failed to set sync input rate %u, err = %d\n",
+				clock_rate, ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int tegra210_i2s_sw_reset(struct snd_soc_component *compnt,
+				 bool is_playback)
+{
+	struct device *dev = compnt->dev;
+	struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+	unsigned int reset_mask = I2S_SOFT_RESET_MASK;
+	unsigned int reset_en = I2S_SOFT_RESET_EN;
+	unsigned int reset_reg, cif_reg, stream_reg;
+	unsigned int cif_ctrl, stream_ctrl, i2s_ctrl, val;
+	int ret;
+
+	if (is_playback) {
+		reset_reg = TEGRA210_I2S_RX_SOFT_RESET;
+		cif_reg = TEGRA210_I2S_RX_CIF_CTRL;
+		stream_reg = TEGRA210_I2S_RX_CTRL;
+	} else {
+		reset_reg = TEGRA210_I2S_TX_SOFT_RESET;
+		cif_reg = TEGRA210_I2S_TX_CIF_CTRL;
+		stream_reg = TEGRA210_I2S_TX_CTRL;
+	}
+
+	/* Store */
+	regmap_read(i2s->regmap, cif_reg, &cif_ctrl);
+	regmap_read(i2s->regmap, stream_reg, &stream_ctrl);
+	regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &i2s_ctrl);
+
+	/* Reset */
+	regmap_update_bits(i2s->regmap, reset_reg, reset_mask, reset_en);
+
+	ret = regmap_read_poll_timeout(i2s->regmap, reset_reg, val,
+				       !(val & reset_mask & reset_en),
+				       10, 10000);
+	if (ret < 0) {
+		dev_err(dev, "timeout: failed to reset I2S for %s\n",
+			is_playback ? "playback" : "capture");
+		return ret;
+	}
+
+	/* Restore */
+	regmap_write(i2s->regmap, cif_reg, cif_ctrl);
+	regmap_write(i2s->regmap, stream_reg, stream_ctrl);
+	regmap_write(i2s->regmap, TEGRA210_I2S_CTRL, i2s_ctrl);
+
+	return 0;
+}
+
+static int tegra210_i2s_init(struct snd_soc_dapm_widget *w,
+			     struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *compnt = snd_soc_dapm_to_component(w->dapm);
+	struct device *dev = compnt->dev;
+	struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+	unsigned int val, status_reg;
+	bool is_playback;
+	int ret;
+
+	switch (w->reg) {
+	case TEGRA210_I2S_RX_ENABLE:
+		is_playback = true;
+		status_reg = TEGRA210_I2S_RX_STATUS;
+		break;
+	case TEGRA210_I2S_TX_ENABLE:
+		is_playback = false;
+		status_reg = TEGRA210_I2S_TX_STATUS;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Ensure I2S is in disabled state before new session */

sound/soc/tegra/tegra210_i2s.c line 168

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+	ret = regmap_read_poll_timeout(i2s->regmap, status_reg, val,
+				       !(val & I2S_EN_MASK & I2S_EN),
+				       10, 10000);
+	if (ret < 0) {
+		dev_err(dev, "timeout: previous I2S %s is still active\n",
+			is_playback ? "playback" : "capture");
+		return ret;
+	}
+
+	/* SW reset */

Comments should amend code with useful information.

Quoted 184 lines
sound/soc/tegra/tegra210_i2s.c new file +184 -0
+	return tegra210_i2s_sw_reset(compnt, is_playback);
+}
+
+static int tegra210_i2s_runtime_suspend(struct device *dev)
+{
+	struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+
+	regcache_cache_only(i2s->regmap, true);
+	regcache_mark_dirty(i2s->regmap);
+
+	clk_disable_unprepare(i2s->clk_i2s);
+
+	return 0;
+}
+
+static int tegra210_i2s_runtime_resume(struct device *dev)
+{
+	struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+	int ret;
+
+	ret = clk_prepare_enable(i2s->clk_i2s);
+	if (ret) {
+		dev_err(dev, "failed to enable I2S bit clock, err: %d\n", ret);
+		return ret;
+	}
+
+	regcache_cache_only(i2s->regmap, false);
+	regcache_sync(i2s->regmap);
+
+	return 0;
+}
+
+static void tegra210_i2s_set_data_offset(struct tegra210_i2s *i2s,
+					 unsigned int data_offset)
+{
+	unsigned int mask = I2S_CTRL_DATA_OFFSET_MASK;
+	unsigned int shift = I2S_DATA_SHIFT;
+	unsigned int reg;
+
+	reg = TEGRA210_I2S_TX_CTRL;
+	regmap_update_bits(i2s->regmap, reg, mask, data_offset << shift);
+
+	reg = TEGRA210_I2S_RX_CTRL;
+	regmap_update_bits(i2s->regmap, reg, mask, data_offset << shift);
+}
+
+static int tegra210_i2s_set_fmt(struct snd_soc_dai *dai,
+				unsigned int fmt)
+{
+	struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+	unsigned int mask, val;
+
+	mask = I2S_CTRL_MASTER_EN_MASK;
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBS_CFS:
+		val = 0;
+		break;
+	case SND_SOC_DAIFMT_CBM_CFM:
+		val = I2S_CTRL_MASTER_EN;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	mask |= I2S_CTRL_FRAME_FMT_MASK | I2S_CTRL_LRCK_POL_MASK;
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_DSP_A:
+		val |= I2S_CTRL_FRAME_FMT_FSYNC_MODE;
+		val |= I2S_CTRL_LRCK_POL_HIGH;
+		tegra210_i2s_set_data_offset(i2s, 1);
+		break;
+	case SND_SOC_DAIFMT_DSP_B:
+		val |= I2S_CTRL_FRAME_FMT_FSYNC_MODE;
+		val |= I2S_CTRL_LRCK_POL_HIGH;
+		tegra210_i2s_set_data_offset(i2s, 0);
+		break;
+	/* I2S mode has data offset of 1 */
+	case SND_SOC_DAIFMT_I2S:
+		val |= I2S_CTRL_FRAME_FMT_LRCK_MODE;
+		val |= I2S_CTRL_LRCK_POL_LOW;
+		tegra210_i2s_set_data_offset(i2s, 1);
+		break;
+	/*
+	 * For RJ mode data offset is dependent on the sample size
+	 * and the bclk ratio, and so is set when hw_params is called.
+	 */
+	case SND_SOC_DAIFMT_RIGHT_J:
+		val |= I2S_CTRL_FRAME_FMT_LRCK_MODE;
+		val |= I2S_CTRL_LRCK_POL_HIGH;
+		break;
+	case SND_SOC_DAIFMT_LEFT_J:
+		val |= I2S_CTRL_FRAME_FMT_LRCK_MODE;
+		val |= I2S_CTRL_LRCK_POL_HIGH;
+		tegra210_i2s_set_data_offset(i2s, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	mask |= I2S_CTRL_EDGE_CTRL_MASK;
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+		val |= I2S_CTRL_EDGE_CTRL_POS_EDGE;
+		break;
+	case SND_SOC_DAIFMT_NB_IF:
+		val |= I2S_CTRL_EDGE_CTRL_POS_EDGE;
+		val ^= I2S_CTRL_LRCK_POL_MASK;
+		break;
+	case SND_SOC_DAIFMT_IB_NF:
+		val |= I2S_CTRL_EDGE_CTRL_NEG_EDGE;
+		break;
+	case SND_SOC_DAIFMT_IB_IF:
+		val |= I2S_CTRL_EDGE_CTRL_NEG_EDGE;
+		val ^= I2S_CTRL_LRCK_POL_MASK;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, mask, val);
+
+	i2s->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
+
+	return 0;
+}
+
+static int tegra210_i2s_set_tdm_slot(struct snd_soc_dai *dai,
+				     unsigned int tx_mask, unsigned int rx_mask,
+				     int slots, int slot_width)
+{
+	struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+
+	/* Copy the required tx and rx mask */
+	i2s->tx_mask = (tx_mask > DEFAULT_I2S_SLOT_MASK) ?
+		       DEFAULT_I2S_SLOT_MASK : tx_mask;
+	i2s->rx_mask = (rx_mask > DEFAULT_I2S_SLOT_MASK) ?
+		       DEFAULT_I2S_SLOT_MASK : rx_mask;
+
+	return 0;
+}
+
+static int tegra210_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
+					   unsigned int ratio)
+{
+	struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+
+	i2s->bclk_ratio = ratio;
+
+	return 0;
+}
+
+static int tegra210_i2s_get_control(struct snd_kcontrol *kcontrol,
+				    struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol);
+	struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt);
+	long *uctl_val = &ucontrol->value.integer.value[0];
+
+	if (strstr(kcontrol->id.name, "Loopback"))
+		*uctl_val = i2s->loopback;
+	else if (strstr(kcontrol->id.name, "Sample Rate"))
+		*uctl_val = i2s->srate_override;
+	else if (strstr(kcontrol->id.name, "FSYNC Width"))
+		*uctl_val = i2s->fsync_width;
+	else if (strstr(kcontrol->id.name, "Playback Audio Bit Format"))
+		*uctl_val = i2s->audio_fmt_override[I2S_RX_PATH];
+	else if (strstr(kcontrol->id.name, "Capture Audio Bit Format"))
+		*uctl_val = i2s->audio_fmt_override[I2S_TX_PATH];
+	else if (strstr(kcontrol->id.name, "Client Bit Format"))
+		*uctl_val = i2s->client_fmt_override;
+	else if (strstr(kcontrol->id.name, "Playback Audio Channels"))
+		*uctl_val = i2s->audio_ch_override[I2S_RX_PATH];
+	else if (strstr(kcontrol->id.name, "Capture Audio Channels"))
+		*uctl_val = i2s->audio_ch_override[I2S_TX_PATH];
+	else if (strstr(kcontrol->id.name, "Client Channels"))
+		*uctl_val = i2s->client_ch_override;
+	else if (strstr(kcontrol->id.name, "Capture Stereo To Mono"))
+		*uctl_val = i2s->stereo_to_mono[I2S_TX_PATH];
+	else if (strstr(kcontrol->id.name, "Capture Mono To Stereo"))
+		*uctl_val = i2s->mono_to_stereo[I2S_TX_PATH];
+	else if (strstr(kcontrol->id.name, "Playback Stereo To Mono"))
+		*uctl_val = i2s->stereo_to_mono[I2S_RX_PATH];
+	else if (strstr(kcontrol->id.name, "Playback Mono To Stereo"))
+		*uctl_val = i2s->mono_to_stereo[I2S_RX_PATH];

sound/soc/tegra/tegra210_i2s.c line 362

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+	else if (strstr(kcontrol->id.name, "Playback FIFO Threshold"))
+		*uctl_val = i2s->rx_fifo_th;
+	else if (strstr(kcontrol->id.name, "BCLK Ratio"))
+		*uctl_val = i2s->bclk_ratio;
+
+	return 0;
+}
+
+static int tegra210_i2s_put_control(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol)

Checkpatch should complain about the wrong indentation here.

Quoted 43 lines
sound/soc/tegra/tegra210_i2s.c new file +43 -0
+{
+	struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol);
+	struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt);
+	int value = ucontrol->value.integer.value[0];
+
+	if (strstr(kcontrol->id.name, "Loopback")) {
+		i2s->loopback = value;
+
+		regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL,
+				   I2S_CTRL_LPBK_MASK,
+				   i2s->loopback << I2S_CTRL_LPBK_SHIFT);
+
+	} else if (strstr(kcontrol->id.name, "Sample Rate"))
+		i2s->srate_override = value;
+	else if (strstr(kcontrol->id.name, "FSYNC Width")) {
+		/*
+		 * Frame sync width is used only for FSYNC modes and not
+		 * applicable for LRCK modes. Reset value for this field is "0",
+		 * which means the width is one bit clock wide.
+		 * The width requirement may depend on the codec and in such
+		 * cases mixer control is used to update custom values. A value
+		 * of "N" here means, width is "N + 1" bit clock wide.
+		 */
+		i2s->fsync_width = value;
+
+		regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL,
+				   I2S_CTRL_FSYNC_WIDTH_MASK,
+				   i2s->fsync_width << I2S_FSYNC_WIDTH_SHIFT);
+
+	} else if (strstr(kcontrol->id.name, "Playback Audio Bit Format"))
+		i2s->audio_fmt_override[I2S_RX_PATH] = value;
+	else if (strstr(kcontrol->id.name, "Capture Audio Bit Format"))
+		i2s->audio_fmt_override[I2S_TX_PATH] = value;
+	else if (strstr(kcontrol->id.name, "Client Bit Format"))
+		i2s->client_fmt_override = value;
+	else if (strstr(kcontrol->id.name, "Playback Audio Channels"))
+		i2s->audio_ch_override[I2S_RX_PATH] = value;
+	else if (strstr(kcontrol->id.name, "Capture Audio Channels"))
+		i2s->audio_ch_override[I2S_TX_PATH] = value;
+	else if (strstr(kcontrol->id.name, "Client Channels"))
+		i2s->client_ch_override = value;
+	else if (strstr(kcontrol->id.name, "Capture Stereo To Mono"))
+		i2s->stereo_to_mono[I2S_TX_PATH] = value;

sound/soc/tegra/tegra210_i2s.c line 415

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+	else if (strstr(kcontrol->id.name, "Capture Mono To Stereo"))
+		i2s->mono_to_stereo[I2S_TX_PATH] = value;
+	else if (strstr(kcontrol->id.name, "Playback Stereo To Mono"))
+		i2s->stereo_to_mono[I2S_RX_PATH] = value;
+	else if (strstr(kcontrol->id.name, "Playback Mono To Stereo"))
+		i2s->mono_to_stereo[I2S_RX_PATH] = value;
+	else if (strstr(kcontrol->id.name, "Playback FIFO Threshold"))
+		i2s->rx_fifo_th = value;
+	else if (strstr(kcontrol->id.name, "BCLK Ratio"))
+		i2s->bclk_ratio = value;

I'm pretty sure that checkpatch should complain about the missing brackets, they should make code's indentation uniform and thus easier to read. Same for all other occurrences in the code.

Quoted 187 lines
sound/soc/tegra/tegra210_i2s.c new file +187 -0
+	return 0;
+}
+
+static const char * const tegra210_i2s_format_text[] = {
+	"None",
+	"16",
+	"32",
+};
+
+static const int tegra210_cif_fmt[] = {
+	0,
+	TEGRA_ACIF_BITS_16,
+	TEGRA_ACIF_BITS_32,
+};
+
+static const int tegra210_i2s_bit_fmt[] = {
+	0,
+	I2S_BITS_16,
+	I2S_BITS_32,
+};
+
+static const int tegra210_i2s_sample_size[] = {
+	0,
+	16,
+	32,
+};
+
+static const struct soc_enum tegra210_i2s_format_enum =
+	SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(tegra210_i2s_format_text),
+			tegra210_i2s_format_text);
+
+static int tegra210_i2s_set_timing_params(struct device *dev,
+					  unsigned int sample_size,
+					  unsigned int srate,
+					  unsigned int channels)
+{
+	struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+	unsigned int val, bit_count, bclk_rate, num_bclk = sample_size;
+	int ret;
+
+	if (i2s->bclk_ratio)
+		num_bclk *= i2s->bclk_ratio;
+
+	if (i2s->dai_fmt == SND_SOC_DAIFMT_RIGHT_J)
+		tegra210_i2s_set_data_offset(i2s, num_bclk - sample_size);
+
+	/* I2S bit clock rate */
+	bclk_rate = srate * channels * num_bclk;
+
+	ret = tegra210_i2s_set_clock_rate(dev, bclk_rate);
+	if (ret) {
+		dev_err(dev, "can't set I2S bit clock rate %u, err: %d\n",
+			bclk_rate, ret);
+		return ret;
+	}
+
+	regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &val);
+
+	/*
+	 * For LRCK mode, channel bit count depends on number of bit clocks
+	 * on the left channel, where as for FSYNC mode bit count depends on
+	 * the number of bit clocks in both left and right channels for DSP
+	 * mode or the number of bit clocks in one TDM frame.
+	 *
+	 */
+	switch (val & I2S_CTRL_FRAME_FMT_MASK) {
+	case I2S_CTRL_FRAME_FMT_LRCK_MODE:
+		bit_count = (bclk_rate / (srate * 2)) - 1;
+		break;
+	case I2S_CTRL_FRAME_FMT_FSYNC_MODE:
+		bit_count = (bclk_rate / srate) - 1;
+
+		tegra210_i2s_set_slot_ctrl(i2s->regmap, channels,
+					   i2s->tx_mask, i2s->rx_mask);
+		break;
+	default:
+		dev_err(dev, "invalid I2S mode\n");
+		return -EINVAL;
+	}
+
+	if (bit_count > I2S_TIMING_CH_BIT_CNT_MASK) {
+		dev_err(dev, "invalid channel bit count %u\n", bit_count);
+		return -EINVAL;
+	}
+
+	regmap_write(i2s->regmap, TEGRA210_I2S_TIMING,
+		     bit_count << I2S_TIMING_CH_BIT_CNT_SHIFT);
+
+	return 0;
+}
+
+static int tegra210_i2s_hw_params(struct snd_pcm_substream *substream,
+				  struct snd_pcm_hw_params *params,
+				  struct snd_soc_dai *dai)
+{
+	struct device *dev = dai->dev;
+	struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+	unsigned int sample_size, channels, srate, val, reg, path;
+	struct tegra_cif_conf cif_conf;
+	int max_th;
+
+	memset(&cif_conf, 0, sizeof(struct tegra_cif_conf));
+
+	channels = params_channels(params);
+	if (channels < 1) {
+		dev_err(dev, "invalid %d channel configuration\n", channels);
+		return -EINVAL;
+	}
+
+	cif_conf.audio_ch = channels;
+	cif_conf.client_ch = channels;
+
+	switch (params_format(params)) {
+	case SNDRV_PCM_FORMAT_S8:
+		val = I2S_BITS_8;
+		sample_size = 8;
+		cif_conf.audio_bits = TEGRA_ACIF_BITS_8;
+		cif_conf.client_bits = TEGRA_ACIF_BITS_8;
+		break;
+	case SNDRV_PCM_FORMAT_S16_LE:
+		val = I2S_BITS_16;
+		sample_size = 16;
+		cif_conf.audio_bits = TEGRA_ACIF_BITS_16;
+		cif_conf.client_bits = TEGRA_ACIF_BITS_16;
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		val = I2S_BITS_32;
+		sample_size = 32;
+		cif_conf.audio_bits = TEGRA_ACIF_BITS_32;
+		cif_conf.client_bits = TEGRA_ACIF_BITS_32;
+		break;
+	default:
+		dev_err(dev, "unsupported format!\n");
+		return -ENOTSUPP;
+	}
+
+	if (i2s->client_fmt_override) {
+		val = tegra210_i2s_bit_fmt[i2s->client_fmt_override];
+		sample_size =
+			tegra210_i2s_sample_size[i2s->client_fmt_override];
+		cif_conf.client_bits =
+			tegra210_cif_fmt[i2s->client_fmt_override];
+	}
+
+	/* Program sample size */
+	regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL,
+			   I2S_CTRL_BIT_SIZE_MASK, val);
+
+	srate = params_rate(params);
+
+	/* Override rate, channel and audio bit params as applicable */
+	if (i2s->srate_override)
+		srate = i2s->srate_override;
+
+	/*
+	 * For playback I2S RX-CIF and for capture TX-CIF is used.
+	 * With reference to AHUB, for I2S, SNDRV_PCM_STREAM_CAPTURE stream is
+	 * actually for playback.
+	 */
+	path = (substream->stream == SNDRV_PCM_STREAM_CAPTURE) ?
+	       I2S_RX_PATH : I2S_TX_PATH;
+
+	if (i2s->audio_ch_override[path])
+		cif_conf.audio_ch = i2s->audio_ch_override[path];
+
+	if (i2s->client_ch_override)
+		cif_conf.client_ch = i2s->client_ch_override;
+
+	if (i2s->audio_fmt_override[path])
+		cif_conf.audio_bits =
+			tegra210_cif_fmt[i2s->audio_fmt_override[path]];
+
+	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+		reg = TEGRA210_I2S_RX_CIF_CTRL;
+
+		/* FIFO threshold in terms of frames */
+		max_th = (I2S_RX_FIFO_DEPTH / cif_conf.audio_ch) - 1;
+		if (max_th < 0)
+			return -EINVAL;
+
+		if (i2s->rx_fifo_th > max_th)
+			i2s->rx_fifo_th = max_th;
+
+		cif_conf.threshold = i2s->rx_fifo_th;
+	} else
+		reg = TEGRA210_I2S_TX_CIF_CTRL;
+

sound/soc/tegra/tegra210_i2s.c line 613

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+	cif_conf.mono_conv = i2s->mono_to_stereo[path];
+	cif_conf.stereo_conv = i2s->stereo_to_mono[path];
+
+	tegra_set_cif(i2s->regmap, reg, &cif_conf);
+
+	return tegra210_i2s_set_timing_params(dev, sample_size, srate,
+					      cif_conf.client_ch);
+}
+
+static struct snd_soc_dai_ops tegra210_i2s_dai_ops = {

const?

Quoted 234 lines
sound/soc/tegra/tegra210_i2s.c new file +234 -0
+	.set_fmt	= tegra210_i2s_set_fmt,
+	.hw_params	= tegra210_i2s_hw_params,
+	.set_bclk_ratio	= tegra210_i2s_set_dai_bclk_ratio,
+	.set_tdm_slot	= tegra210_i2s_set_tdm_slot,
+};
+
+/*
+ * Three DAIs are exposed
+ * 1. "CIF" DAI for connecting with XBAR
+ * 2. "DAP" DAI for connecting with CODEC
+ * 3. "DUMMY" can be used when no external codec connection is
+ *    available. In such case "DAP" is connected with "DUMMY".
+ * Order of these DAIs should not be changed, since DAI links in DT refer
+ * to these DAIs depending on the index.
+ */
+static struct snd_soc_dai_driver tegra210_i2s_dais[] = {
+	{
+		.name = "CIF",
+		.playback = {
+			.stream_name = "CIF Receive",
+			.channels_min = 1,
+			.channels_max = 16,
+			.rates = SNDRV_PCM_RATE_8000_192000,
+			.formats = SNDRV_PCM_FMTBIT_S8 |
+				SNDRV_PCM_FMTBIT_S16_LE |
+				SNDRV_PCM_FMTBIT_S32_LE,
+		},
+		.capture = {
+			.stream_name = "CIF Transmit",
+			.channels_min = 1,
+			.channels_max = 16,
+			.rates = SNDRV_PCM_RATE_8000_192000,
+			.formats = SNDRV_PCM_FMTBIT_S8 |
+				SNDRV_PCM_FMTBIT_S16_LE |
+				SNDRV_PCM_FMTBIT_S32_LE,
+		},
+	},
+	{
+		.name = "DAP",
+		.playback = {
+			.stream_name = "DAP Receive",
+			.channels_min = 1,
+			.channels_max = 16,
+			.rates = SNDRV_PCM_RATE_8000_192000,
+			.formats = SNDRV_PCM_FMTBIT_S8 |
+				SNDRV_PCM_FMTBIT_S16_LE |
+				SNDRV_PCM_FMTBIT_S32_LE,
+		},
+		.capture = {
+			.stream_name = "DAP Transmit",
+			.channels_min = 1,
+			.channels_max = 16,
+			.rates = SNDRV_PCM_RATE_8000_192000,
+			.formats = SNDRV_PCM_FMTBIT_S8 |
+				SNDRV_PCM_FMTBIT_S16_LE |
+				SNDRV_PCM_FMTBIT_S32_LE,
+		},
+		.ops = &tegra210_i2s_dai_ops,
+		.symmetric_rates = 1,
+	},
+	{
+		.name = "DUMMY",
+		.playback = {
+			.stream_name = "Dummy Playback",
+			.channels_min = 1,
+			.channels_max = 16,
+			.rates = SNDRV_PCM_RATE_8000_192000,
+			.formats = SNDRV_PCM_FMTBIT_S8 |
+				SNDRV_PCM_FMTBIT_S16_LE |
+				SNDRV_PCM_FMTBIT_S32_LE,
+		},
+		.capture = {
+			.stream_name = "Dummy Capture",
+			.channels_min = 1,
+			.channels_max = 16,
+			.rates = SNDRV_PCM_RATE_8000_192000,
+			.formats = SNDRV_PCM_FMTBIT_S8 |
+				SNDRV_PCM_FMTBIT_S16_LE |
+				SNDRV_PCM_FMTBIT_S32_LE,
+		},
+	},
+};
+
+static const char * const tegra210_i2s_stereo_conv_text[] = {
+	"CH0", "CH1", "AVG",
+};
+
+static const char * const tegra210_i2s_mono_conv_text[] = {
+	"ZERO", "COPY",
+};
+
+static const struct soc_enum tegra210_i2s_mono_conv_enum =
+	SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(tegra210_i2s_mono_conv_text),
+			tegra210_i2s_mono_conv_text);
+
+static const struct soc_enum tegra210_i2s_stereo_conv_enum =
+	SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(tegra210_i2s_stereo_conv_text),
+			tegra210_i2s_stereo_conv_text);
+
+static const struct snd_kcontrol_new tegra210_i2s_controls[] = {
+	SOC_SINGLE_EXT("Loopback", 0, 0, 1, 0, tegra210_i2s_get_control,
+		       tegra210_i2s_put_control),
+	SOC_SINGLE_EXT("FSYNC Width", 0, 0, 255, 0, tegra210_i2s_get_control,
+		       tegra210_i2s_put_control),
+	SOC_SINGLE_EXT("Sample Rate", 0, 0, 192000, 0, tegra210_i2s_get_control,
+		       tegra210_i2s_put_control),
+	SOC_ENUM_EXT("Playback Audio Bit Format", tegra210_i2s_format_enum,
+		     tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_ENUM_EXT("Capture Audio Bit Format", tegra210_i2s_format_enum,
+		     tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_ENUM_EXT("Client Bit Format", tegra210_i2s_format_enum,
+		     tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_SINGLE_EXT("Playback Audio Channels", 0, 0, 16, 0,
+		       tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_SINGLE_EXT("Capture Audio Channels", 0, 0, 16, 0,
+		       tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_SINGLE_EXT("Client Channels", 0, 0, 16, 0,
+		       tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_ENUM_EXT("Capture Stereo To Mono", tegra210_i2s_stereo_conv_enum,
+		     tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_ENUM_EXT("Capture Mono To Stereo", tegra210_i2s_mono_conv_enum,
+		     tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_ENUM_EXT("Playback Stereo To Mono", tegra210_i2s_stereo_conv_enum,
+		     tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_ENUM_EXT("Playback Mono To Stereo", tegra210_i2s_mono_conv_enum,
+		     tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_SINGLE_EXT("Playback FIFO Threshold", 0, 0, I2S_RX_FIFO_DEPTH - 1,
+		       0, tegra210_i2s_get_control, tegra210_i2s_put_control),
+	SOC_SINGLE_EXT("BCLK Ratio", 0, 0, INT_MAX, 0, tegra210_i2s_get_control,
+		       tegra210_i2s_put_control),
+};
+
+static const struct snd_soc_dapm_widget tegra210_i2s_widgets[] = {
+	SND_SOC_DAPM_AIF_IN("CIF RX", NULL, 0, SND_SOC_NOPM, 0, 0),
+	SND_SOC_DAPM_AIF_OUT("CIF TX", NULL, 0, SND_SOC_NOPM, 0, 0),
+	SND_SOC_DAPM_AIF_IN_E("DAP RX", NULL, 0, TEGRA210_I2S_TX_ENABLE,
+			      0, 0, tegra210_i2s_init, SND_SOC_DAPM_PRE_PMU),
+	SND_SOC_DAPM_AIF_OUT_E("DAP TX", NULL, 0, TEGRA210_I2S_RX_ENABLE,
+			       0, 0, tegra210_i2s_init, SND_SOC_DAPM_PRE_PMU),
+	SND_SOC_DAPM_MIC("Dummy Input", NULL),
+	SND_SOC_DAPM_SPK("Dummy Output", NULL),
+};
+
+static const struct snd_soc_dapm_route tegra210_i2s_routes[] = {
+	{ "CIF RX",	  NULL, "CIF Receive" },
+	{ "DAP TX",	  NULL, "CIF RX" },
+	{ "DAP Transmit", NULL, "DAP TX" },
+
+	{ "DAP RX",	  NULL, "DAP Receive" },
+	{ "CIF TX",	  NULL, "DAP RX" },
+	{ "CIF Transmit", NULL, "CIF TX" },
+
+	{ "Dummy Capture", NULL, "Dummy Input" },
+	{ "Dummy Output", NULL, "Dummy Playback" },
+};
+
+static const struct snd_soc_component_driver tegra210_i2s_cmpnt = {
+	.dapm_widgets = tegra210_i2s_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(tegra210_i2s_widgets),
+	.dapm_routes = tegra210_i2s_routes,
+	.num_dapm_routes = ARRAY_SIZE(tegra210_i2s_routes),
+	.controls = tegra210_i2s_controls,
+	.num_controls = ARRAY_SIZE(tegra210_i2s_controls),
+	.non_legacy_dai_naming = 1,
+};
+
+static bool tegra210_i2s_wr_reg(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case TEGRA210_I2S_RX_ENABLE ... TEGRA210_I2S_RX_SOFT_RESET:
+	case TEGRA210_I2S_RX_INT_MASK ... TEGRA210_I2S_RX_CLK_TRIM:
+	case TEGRA210_I2S_TX_ENABLE ... TEGRA210_I2S_TX_SOFT_RESET:
+	case TEGRA210_I2S_TX_INT_MASK ... TEGRA210_I2S_TX_CLK_TRIM:
+	case TEGRA210_I2S_ENABLE ... TEGRA210_I2S_CG:
+	case TEGRA210_I2S_CTRL ... TEGRA210_I2S_CYA:
+		return true;
+	default:
+		return false;
+	};
+}
+
+static bool tegra210_i2s_rd_reg(struct device *dev, unsigned int reg)
+{
+	if (tegra210_i2s_wr_reg(dev, reg))
+		return true;
+
+	switch (reg) {
+	case TEGRA210_I2S_RX_STATUS:
+	case TEGRA210_I2S_RX_INT_STATUS:
+	case TEGRA210_I2S_RX_CIF_FIFO_STATUS:
+	case TEGRA210_I2S_TX_STATUS:
+	case TEGRA210_I2S_TX_INT_STATUS:
+	case TEGRA210_I2S_TX_CIF_FIFO_STATUS:
+	case TEGRA210_I2S_STATUS:
+	case TEGRA210_I2S_INT_STATUS:
+		return true;
+	default:
+		return false;
+	};
+}
+
+static bool tegra210_i2s_volatile_reg(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case TEGRA210_I2S_RX_STATUS:
+	case TEGRA210_I2S_RX_INT_STATUS:
+	case TEGRA210_I2S_RX_CIF_FIFO_STATUS:
+	case TEGRA210_I2S_TX_STATUS:
+	case TEGRA210_I2S_TX_INT_STATUS:
+	case TEGRA210_I2S_TX_CIF_FIFO_STATUS:
+	case TEGRA210_I2S_STATUS:
+	case TEGRA210_I2S_INT_STATUS:
+	case TEGRA210_I2S_RX_SOFT_RESET:
+	case TEGRA210_I2S_TX_SOFT_RESET:
+		return true;
+	default:
+		return false;
+	};
+}
+
+static const struct regmap_config tegra210_i2s_regmap_config = {
+	.reg_bits		= 32,
+	.reg_stride		= 4,
+	.val_bits		= 32,
+	.max_register		= TEGRA210_I2S_CYA,
+	.writeable_reg		= tegra210_i2s_wr_reg,
+	.readable_reg		= tegra210_i2s_rd_reg,
+	.volatile_reg		= tegra210_i2s_volatile_reg,
+	.reg_defaults		= tegra210_i2s_reg_defaults,
+	.num_reg_defaults	= ARRAY_SIZE(tegra210_i2s_reg_defaults),
+	.cache_type		= REGCACHE_FLAT,
+};
+
+static const struct of_device_id tegra210_i2s_of_match[] = {

sound/soc/tegra/tegra210_i2s.c line 857

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+	{ .compatible = "nvidia,tegra210-i2s" },
+	{},
+};
+
+static int tegra210_i2s_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct tegra210_i2s *i2s;
+	void __iomem *regs;
+	int ret = 0;

Please do not initialize variables if it's not really needed, to keep code cleaner. Same for all other occurrences in the code.

Quoted 37 lines
sound/soc/tegra/tegra210_i2s.c new file +37 -0
+	i2s = devm_kcalloc(dev, 1, sizeof(*i2s), GFP_KERNEL);
+	if (!i2s)
+		return -ENOMEM;
+
+	i2s->rx_fifo_th = DEFAULT_I2S_RX_FIFO_THRESHOLD;
+	i2s->tx_mask = i2s->rx_mask = DEFAULT_I2S_SLOT_MASK;
+	i2s->loopback = false;
+
+	dev_set_drvdata(dev, i2s);
+
+	i2s->clk_i2s = devm_clk_get(dev, "i2s");
+	if (IS_ERR(i2s->clk_i2s)) {
+		dev_err(dev, "can't retrieve I2S bit clock\n");
+		return PTR_ERR(i2s->clk_i2s);
+	}
+
+	/*
+	 * Not an error, as this clock is needed only when some other I/O
+	 * requires input clock from current I2S instance, which is
+	 * configurable from DT.
+	 */
+	i2s->clk_sync_input = devm_clk_get(dev, "sync_input");
+	if (IS_ERR(i2s->clk_sync_input))
+		dev_dbg(dev, "can't retrieve I2S sync input clock\n");
+
+	regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(regs))
+		return PTR_ERR(regs);
+
+	i2s->regmap = devm_regmap_init_mmio(dev, regs,
+					    &tegra210_i2s_regmap_config);
+	if (IS_ERR(i2s->regmap)) {
+		dev_err(dev, "regmap init failed\n");
+		return PTR_ERR(i2s->regmap);
+	}
+
+	regcache_cache_only(i2s->regmap, true);

sound/soc/tegra/tegra210_i2s.c line 905

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+
+	ret = devm_snd_soc_register_component(dev, &tegra210_i2s_cmpnt,
+					      tegra210_i2s_dais,
+					      ARRAY_SIZE(tegra210_i2s_dais));
+	if (ret != 0) {
+		dev_err(dev, "can't register I2S component, err: %d\n", ret);
+		return ret;
+	}
+
+	pm_runtime_enable(dev);

Error checking?

sound/soc/tegra/tegra210_i2s.c line 914

Quoted 9 lines
sound/soc/tegra/tegra210_i2s.c new file +8 -0
+	return 0;
+}
+
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+	pm_runtime_disable(&pdev->dev);
 
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

sound/soc/tegra/tegra210_i2s.c line 928

Quoted 13 lines
sound/soc/tegra/tegra210_i2s.c new file +13 -0
+	return 0;
+}
+
+static const struct dev_pm_ops tegra210_i2s_pm_ops = {
+	SET_RUNTIME_PM_OPS(tegra210_i2s_runtime_suspend,
+			   tegra210_i2s_runtime_resume, NULL)
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+				     pm_runtime_force_resume)
+};
+
+static struct platform_driver tegra210_i2s_driver = {
+	.driver = {
+		.name = DRV_NAME,

Will be nicer to set the name directly here, thus to remove the DRV_NAME macro.

sound/soc/tegra/tegra210_i2s.c line 929

Quoted 1 line
sound/soc/tegra/tegra210_i2s.c new file +1 -0
+		.owner = THIS_MODULE,

No need to explicitly set the owner, drivers core takes care about it.

sound/soc/tegra/tegra210_i2s.c line 941

Quoted 13 lines
sound/soc/tegra/tegra210_i2s.c new file +12 -0
+		.of_match_table = tegra210_i2s_of_match,
+		.pm = &tegra210_i2s_pm_ops,
+	},
+	.probe = tegra210_i2s_probe,
+	.remove = tegra210_i2s_remove,
+};
+module_platform_driver(tegra210_i2s_driver)
+
+MODULE_AUTHOR("Songhee Baek <[email protected]>");
+MODULE_DESCRIPTION("Tegra210 ASoC I2S driver");
+MODULE_LICENSE("GPL v2");
 
+MODULE_DEVICE_TABLE(of, tegra210_i2s_of_match);

What about to place MODULE_DEVICE_TABLE() right after the definition of tegra210_i2s_of_match like it's done by most of the drivers in kernel?

Quoted 124 lines
sound/soc/tegra/tegra210_i2s.h new file +118 -0
new file mode 100644
index 0000000..121dff7
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * tegra210_i2s.h - Definitions for Tegra210 I2S driver
+ *
+ * Copyright (c) 2020 NVIDIA CORPORATION. All rights reserved.
+ *
+ */
+
+#ifndef __TEGRA210_I2S_H__
+#define __TEGRA210_I2S_H__
+
+/* Register offsets from I2S*_BASE */
+#define TEGRA210_I2S_RX_ENABLE			0x0
+#define TEGRA210_I2S_RX_SOFT_RESET		0x4
+#define TEGRA210_I2S_RX_STATUS			0x0c
+#define TEGRA210_I2S_RX_INT_STATUS		0x10
+#define TEGRA210_I2S_RX_INT_MASK		0x14
+#define TEGRA210_I2S_RX_INT_SET			0x18
+#define TEGRA210_I2S_RX_INT_CLEAR		0x1c
+#define TEGRA210_I2S_RX_CIF_CTRL		0x20
+#define TEGRA210_I2S_RX_CTRL			0x24
+#define TEGRA210_I2S_RX_SLOT_CTRL		0x28
+#define TEGRA210_I2S_RX_CLK_TRIM		0x2c
+#define TEGRA210_I2S_RX_CYA			0x30
+#define TEGRA210_I2S_RX_CIF_FIFO_STATUS		0x34
+#define TEGRA210_I2S_TX_ENABLE			0x40
+#define TEGRA210_I2S_TX_SOFT_RESET		0x44
+#define TEGRA210_I2S_TX_STATUS			0x4c
+#define TEGRA210_I2S_TX_INT_STATUS		0x50
+#define TEGRA210_I2S_TX_INT_MASK		0x54
+#define TEGRA210_I2S_TX_INT_SET			0x58
+#define TEGRA210_I2S_TX_INT_CLEAR		0x5c
+#define TEGRA210_I2S_TX_CIF_CTRL		0x60
+#define TEGRA210_I2S_TX_CTRL			0x64
+#define TEGRA210_I2S_TX_SLOT_CTRL		0x68
+#define TEGRA210_I2S_TX_CLK_TRIM		0x6c
+#define TEGRA210_I2S_TX_CYA			0x70
+#define TEGRA210_I2S_TX_CIF_FIFO_STATUS		0x74
+#define TEGRA210_I2S_ENABLE			0x80
+#define TEGRA210_I2S_SOFT_RESET			0x84
+#define TEGRA210_I2S_CG				0x88
+#define TEGRA210_I2S_STATUS			0x8c
+#define TEGRA210_I2S_INT_STATUS			0x90
+#define TEGRA210_I2S_CTRL			0xa0
+#define TEGRA210_I2S_TIMING			0xa4
+#define TEGRA210_I2S_SLOT_CTRL			0xa8
+#define TEGRA210_I2S_CLK_TRIM			0xac
+#define TEGRA210_I2S_CYA			0xb0
+
+/* Bit fields, shifts and masks */
+#define I2S_DATA_SHIFT				8
+#define I2S_CTRL_DATA_OFFSET_MASK		(0x7ff << I2S_DATA_SHIFT)
+
+#define I2S_EN_SHIFT				0
+#define I2S_EN_MASK				(1 << I2S_EN_SHIFT)
+#define I2S_EN					(1 << I2S_EN_SHIFT)
+
+#define I2S_FSYNC_WIDTH_SHIFT			24
+#define I2S_CTRL_FSYNC_WIDTH_MASK		(0xff << I2S_FSYNC_WIDTH_SHIFT)
+
+#define I2S_POS_EDGE				0
+#define I2S_NEG_EDGE				1
+#define I2S_EDGE_SHIFT				20
+#define I2S_CTRL_EDGE_CTRL_MASK			(1 << I2S_EDGE_SHIFT)
+#define I2S_CTRL_EDGE_CTRL_POS_EDGE		(I2S_POS_EDGE << I2S_EDGE_SHIFT)
+#define I2S_CTRL_EDGE_CTRL_NEG_EDGE		(I2S_NEG_EDGE << I2S_EDGE_SHIFT)
+
+#define I2S_FMT_LRCK				0
+#define I2S_FMT_FSYNC				1
+#define I2S_FMT_SHIFT				12
+#define I2S_CTRL_FRAME_FMT_MASK			(7 << I2S_FMT_SHIFT)
+#define I2S_CTRL_FRAME_FMT_LRCK_MODE		(I2S_FMT_LRCK << I2S_FMT_SHIFT)
+#define I2S_CTRL_FRAME_FMT_FSYNC_MODE		(I2S_FMT_FSYNC << I2S_FMT_SHIFT)
+
+#define I2S_CTRL_MASTER_EN_SHIFT		10
+#define I2S_CTRL_MASTER_EN_MASK			(1 << I2S_CTRL_MASTER_EN_SHIFT)
+#define I2S_CTRL_MASTER_EN			(1 << I2S_CTRL_MASTER_EN_SHIFT)
+
+#define I2S_CTRL_LRCK_POL_SHIFT			9
+#define I2S_CTRL_LRCK_POL_MASK			(1 << I2S_CTRL_LRCK_POL_SHIFT)
+#define I2S_CTRL_LRCK_POL_LOW			(0 << I2S_CTRL_LRCK_POL_SHIFT)
+#define I2S_CTRL_LRCK_POL_HIGH			(1 << I2S_CTRL_LRCK_POL_SHIFT)
+
+#define I2S_CTRL_LPBK_SHIFT			8
+#define I2S_CTRL_LPBK_MASK			(1 << I2S_CTRL_LPBK_SHIFT)
+#define I2S_CTRL_LPBK_EN			(1 << I2S_CTRL_LPBK_SHIFT)
+
+#define I2S_BITS_8				1
+#define I2S_BITS_16				3
+#define I2S_BITS_32				7
+#define I2S_CTRL_BIT_SIZE_MASK			0x7
+
+#define I2S_TIMING_CH_BIT_CNT_MASK		0x7ff
+#define I2S_TIMING_CH_BIT_CNT_SHIFT		0
+
+#define I2S_SOFT_RESET_SHIFT			0
+#define I2S_SOFT_RESET_MASK			(1 << I2S_SOFT_RESET_SHIFT)
+#define I2S_SOFT_RESET_EN			(1 << I2S_SOFT_RESET_SHIFT)
+
+#define I2S_RX_FIFO_DEPTH			64
+#define DEFAULT_I2S_RX_FIFO_THRESHOLD		3
+
+#define DEFAULT_I2S_SLOT_MASK			0xffff
+
+enum tegra210_i2s_path {
+	I2S_RX_PATH,
+	I2S_TX_PATH,
+	I2S_PATHS,
+};
+
+struct tegra210_i2s {
+	struct clk *clk_i2s;
+	struct clk *clk_sync_input;
+	struct regmap *regmap;
+	unsigned int stereo_to_mono[I2S_PATHS];
+	unsigned int mono_to_stereo[I2S_PATHS];
+	unsigned int audio_ch_override[I2S_PATHS];
+	unsigned int audio_fmt_override[I2S_PATHS];

sound/soc/tegra/tegra210_i2s.h line 128

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.h new file +10 -0
+	/* Client overrides are common for TX and RX paths */
+	unsigned int client_ch_override;
+	unsigned int client_fmt_override;
+	unsigned int srate_override;
+	unsigned int dai_fmt;
+	unsigned int fsync_width;
+	unsigned int bclk_ratio;
+	unsigned int tx_mask;
+	unsigned int rx_mask;
+	int rx_fifo_th;

Could rx_fifo_th be negative?

Quoted 5 lines
sound/soc/tegra/tegra210_i2s.h new file +4 -0
+	bool loopback;
+};
+
+#endif
#11 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 87 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

20.01.2020 17:23, Sameer Pujar пишет:

Quoted 83 lines

The Inter-IC Sound (I2S) controller implements full-duplex, bi-directional and single direction point to point serial interface. It can interface with I2S compatible devices. Tegra I2S controller can operate as both master and slave.

This patch registers I2S controller with ASoC framework. The component driver exposes DAPM widgets, routes and kcontrols for the device. The DAI driver exposes I2S interfaces, which can be used to connect different components in the ASoC layer. Makefile and Kconfig support is added to allow to build the driver. The I2S devices can be enabled in the DT via "nvidia,tegra210-i2s" compatible binding.

---
  sound/soc/tegra/Kconfig        |  10 +
  sound/soc/tegra/Makefile       |   2 +
  sound/soc/tegra/tegra210_i2s.c | 941 +++++++++++++++++++++++++++++++++++++++++
  sound/soc/tegra/tegra210_i2s.h | 132 ++++++
  4 files changed, 1085 insertions(+)

create mode 100644 sound/soc/tegra/tegra210_i2s.c create mode 100644 sound/soc/tegra/tegra210_i2s.h

sound/soc/tegra/Kconfig +10 -0
index 2bde1e6..157fa7a 100644
@@ -73,6 +73,16 @@ config SND_SOC_TEGRA210_DMIC
            PDM receiver.
            Say Y or M if you want to add support for Tegra210 DMIC module.
 
+config SND_SOC_TEGRA210_I2S
+        tristate "Tegra210 I2S module"
+        depends on SND_SOC_TEGRA
+        help
+          Config to enable the Inter-IC Sound (I2S) Controller which
+          implements full-duplex and bidirectional and single direction
+          point-to-point serial interfaces. It can interface with I2S
+          compatible devices.
+          Say Y or M if you want to add support for Tegra210 I2S module.
+
  config SND_SOC_TEGRA_RT5640
       tristate "SoC Audio support for Tegra boards using an RT5640 codec"
       depends on SND_SOC_TEGRA && I2C && GPIOLIB
sound/soc/tegra/Makefile +2 -0
index 9e78fe4..1c4457d 100644
@@ -10,6 +10,7 @@ snd-soc-tegra30-ahub-objs := tegra30_ahub.o
  snd-soc-tegra30-i2s-objs := tegra30_i2s.o
  snd-soc-tegra-cif-objs := tegra_cif.o
  snd-soc-tegra210-dmic-objs := tegra210_dmic.o
+snd-soc-tegra210-i2s-objs := tegra210_i2s.o
 
  obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
  obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
@@ -21,6 +22,7 @@ obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o
  obj-$(CONFIG_SND_SOC_TEGRA30_AHUB) += snd-soc-tegra30-ahub.o
  obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
  obj-$(CONFIG_SND_SOC_TEGRA210_DMIC) += snd-soc-tegra210-dmic.o
+obj-$(CONFIG_SND_SOC_TEGRA210_I2S) += snd-soc-tegra210-i2s.o
 
  # Tegra machine Support
  snd-soc-tegra-rt5640-objs := tegra_rt5640.o
sound/soc/tegra/tegra210_i2s.c new file +14 -0
new file mode 100644
index 0000000..36e8a7c
@@ -0,0 +1,941 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * tegra210_i2s.c - Tegra210 I2S driver
+ *
+ * Copyright (c) 2020 NVIDIA CORPORATION.  All rights reserved.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/of_device.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 20

Quoted 6 lines
sound/soc/tegra/tegra210_i2s.c new file +6 -0
+#include <linux/clk.h>
+#include <sound/pcm_params.h>
+#include <sound/core.h>
+#include <sound/soc.h>
+#include "tegra210_i2s.h"
+#include "tegra_cif.h"

Headers should be sorted in alphabet order to avoid confusion about how to insert a new header.

I had tried using inverted-waterfall order to make it appear cleaner.
But I see that other Tegra source files are using alphabetical order, will follow the same here.

Quoted 140 lines
Quoted 140 lines
sound/soc/tegra/tegra210_i2s.c new file +140 -0
+#define DRV_NAME "tegra210-i2s"
+
+static const struct reg_default tegra210_i2s_reg_defaults[] = {
+     { TEGRA210_I2S_RX_INT_MASK, 0x00000003},
+     { TEGRA210_I2S_RX_CIF_CTRL, 0x00007700},
+     { TEGRA210_I2S_TX_INT_MASK, 0x00000003},
+     { TEGRA210_I2S_TX_CIF_CTRL, 0x00007700},
+     { TEGRA210_I2S_CG, 0x1},
+     { TEGRA210_I2S_TIMING, 0x0000001f},
+     { TEGRA210_I2S_ENABLE, 0x1},
+     /*
+      * Below update does not have any effect on Tegra186 and Tegra194.
+      * On Tegra210, I2S4 has "i2s4a" and "i2s4b" pins and below update
+      * is required to select i2s4b for it to be functional for I2S
+      * operation.
+      */
+     { TEGRA210_I2S_CYA, 0x1},
+};
+
+static void tegra210_i2s_set_slot_ctrl(struct regmap *regmap,
+                                    unsigned int total_slots,
+                                    unsigned int tx_slot_mask,
+                                    unsigned int rx_slot_mask)
+{
+     regmap_write(regmap, TEGRA210_I2S_SLOT_CTRL, total_slots - 1);
+     regmap_write(regmap, TEGRA210_I2S_TX_SLOT_CTRL, tx_slot_mask);
+     regmap_write(regmap, TEGRA210_I2S_RX_SLOT_CTRL, rx_slot_mask);
+}
+
+static int tegra210_i2s_set_clock_rate(struct device *dev,
+                                    unsigned int clock_rate)
+{
+     struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+     unsigned int val;
+     int ret;
+
+     regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &val);
+
+     /* No need to set rates if I2S is being operated in slave */
+     if (!(val & I2S_CTRL_MASTER_EN))
+             return 0;
+
+     ret = clk_set_rate(i2s->clk_i2s, clock_rate);
+     if (ret) {
+             dev_err(dev, "failed to set I2S bit clock rate %u, err: %d\n",
+                     clock_rate, ret);
+             return ret;
+     }
+
+     if (!IS_ERR(i2s->clk_sync_input)) {
+             /*
+              * Other I/O modules in AHUB can use i2s bclk as reference
+              * clock. Below sets sync input clock rate as per bclk,
+              * which can be used as input to other I/O modules.
+              */
+             ret = clk_set_rate(i2s->clk_sync_input, clock_rate);
+             if (ret) {
+                     dev_err(dev,
+                             "failed to set sync input rate %u, err = %d\n",
+                             clock_rate, ret);
+                     return ret;
+             }
+     }
+
+     return 0;
+}
+
+static int tegra210_i2s_sw_reset(struct snd_soc_component *compnt,
+                              bool is_playback)
+{
+     struct device *dev = compnt->dev;
+     struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+     unsigned int reset_mask = I2S_SOFT_RESET_MASK;
+     unsigned int reset_en = I2S_SOFT_RESET_EN;
+     unsigned int reset_reg, cif_reg, stream_reg;
+     unsigned int cif_ctrl, stream_ctrl, i2s_ctrl, val;
+     int ret;
+
+     if (is_playback) {
+             reset_reg = TEGRA210_I2S_RX_SOFT_RESET;
+             cif_reg = TEGRA210_I2S_RX_CIF_CTRL;
+             stream_reg = TEGRA210_I2S_RX_CTRL;
+     } else {
+             reset_reg = TEGRA210_I2S_TX_SOFT_RESET;
+             cif_reg = TEGRA210_I2S_TX_CIF_CTRL;
+             stream_reg = TEGRA210_I2S_TX_CTRL;
+     }
+
+     /* Store */
+     regmap_read(i2s->regmap, cif_reg, &cif_ctrl);
+     regmap_read(i2s->regmap, stream_reg, &stream_ctrl);
+     regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &i2s_ctrl);
+
+     /* Reset */
+     regmap_update_bits(i2s->regmap, reset_reg, reset_mask, reset_en);
+
+     ret = regmap_read_poll_timeout(i2s->regmap, reset_reg, val,
+                                    !(val & reset_mask & reset_en),
+                                    10, 10000);
+     if (ret < 0) {
+             dev_err(dev, "timeout: failed to reset I2S for %s\n",
+                     is_playback ? "playback" : "capture");
+             return ret;
+     }
+
+     /* Restore */
+     regmap_write(i2s->regmap, cif_reg, cif_ctrl);
+     regmap_write(i2s->regmap, stream_reg, stream_ctrl);
+     regmap_write(i2s->regmap, TEGRA210_I2S_CTRL, i2s_ctrl);
+
+     return 0;
+}
+
+static int tegra210_i2s_init(struct snd_soc_dapm_widget *w,
+                          struct snd_kcontrol *kcontrol, int event)
+{
+     struct snd_soc_component *compnt = snd_soc_dapm_to_component(w->dapm);
+     struct device *dev = compnt->dev;
+     struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+     unsigned int val, status_reg;
+     bool is_playback;
+     int ret;
+
+     switch (w->reg) {
+     case TEGRA210_I2S_RX_ENABLE:
+             is_playback = true;
+             status_reg = TEGRA210_I2S_RX_STATUS;
+             break;
+     case TEGRA210_I2S_TX_ENABLE:
+             is_playback = false;
+             status_reg = TEGRA210_I2S_TX_STATUS;
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     /* Ensure I2S is in disabled state before new session */
+     ret = regmap_read_poll_timeout(i2s->regmap, status_reg, val,
+                                    !(val & I2S_EN_MASK & I2S_EN),
+                                    10, 10000);
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 168

Quoted 7 lines
sound/soc/tegra/tegra210_i2s.c new file +7 -0
+     if (ret < 0) {
+             dev_err(dev, "timeout: previous I2S %s is still active\n",
+                     is_playback ? "playback" : "capture");
+             return ret;
+     }
+
+     /* SW reset */

Comments should amend code with useful information.

Will add more details if needed or will get rid of it.

Quoted 188 lines
Quoted 188 lines
sound/soc/tegra/tegra210_i2s.c new file +187 -0
+     return tegra210_i2s_sw_reset(compnt, is_playback);
+}
+
+static int tegra210_i2s_runtime_suspend(struct device *dev)
+{
+     struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+
+     regcache_cache_only(i2s->regmap, true);
+     regcache_mark_dirty(i2s->regmap);
+
+     clk_disable_unprepare(i2s->clk_i2s);
+
+     return 0;
+}
+
+static int tegra210_i2s_runtime_resume(struct device *dev)
+{
+     struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+     int ret;
+
+     ret = clk_prepare_enable(i2s->clk_i2s);
+     if (ret) {
+             dev_err(dev, "failed to enable I2S bit clock, err: %d\n", ret);
+             return ret;
+     }
+
+     regcache_cache_only(i2s->regmap, false);
+     regcache_sync(i2s->regmap);
+
+     return 0;
+}
+
+static void tegra210_i2s_set_data_offset(struct tegra210_i2s *i2s,
+                                      unsigned int data_offset)
+{
+     unsigned int mask = I2S_CTRL_DATA_OFFSET_MASK;
+     unsigned int shift = I2S_DATA_SHIFT;
+     unsigned int reg;
+
+     reg = TEGRA210_I2S_TX_CTRL;
+     regmap_update_bits(i2s->regmap, reg, mask, data_offset << shift);
+
+     reg = TEGRA210_I2S_RX_CTRL;
+     regmap_update_bits(i2s->regmap, reg, mask, data_offset << shift);
+}
+
+static int tegra210_i2s_set_fmt(struct snd_soc_dai *dai,
+                             unsigned int fmt)
+{
+     struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+     unsigned int mask, val;
+
+     mask = I2S_CTRL_MASTER_EN_MASK;
+     switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+     case SND_SOC_DAIFMT_CBS_CFS:
+             val = 0;
+             break;
+     case SND_SOC_DAIFMT_CBM_CFM:
+             val = I2S_CTRL_MASTER_EN;
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     mask |= I2S_CTRL_FRAME_FMT_MASK | I2S_CTRL_LRCK_POL_MASK;
+     switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+     case SND_SOC_DAIFMT_DSP_A:
+             val |= I2S_CTRL_FRAME_FMT_FSYNC_MODE;
+             val |= I2S_CTRL_LRCK_POL_HIGH;
+             tegra210_i2s_set_data_offset(i2s, 1);
+             break;
+     case SND_SOC_DAIFMT_DSP_B:
+             val |= I2S_CTRL_FRAME_FMT_FSYNC_MODE;
+             val |= I2S_CTRL_LRCK_POL_HIGH;
+             tegra210_i2s_set_data_offset(i2s, 0);
+             break;
+     /* I2S mode has data offset of 1 */
+     case SND_SOC_DAIFMT_I2S:
+             val |= I2S_CTRL_FRAME_FMT_LRCK_MODE;
+             val |= I2S_CTRL_LRCK_POL_LOW;
+             tegra210_i2s_set_data_offset(i2s, 1);
+             break;
+     /*
+      * For RJ mode data offset is dependent on the sample size
+      * and the bclk ratio, and so is set when hw_params is called.
+      */
+     case SND_SOC_DAIFMT_RIGHT_J:
+             val |= I2S_CTRL_FRAME_FMT_LRCK_MODE;
+             val |= I2S_CTRL_LRCK_POL_HIGH;
+             break;
+     case SND_SOC_DAIFMT_LEFT_J:
+             val |= I2S_CTRL_FRAME_FMT_LRCK_MODE;
+             val |= I2S_CTRL_LRCK_POL_HIGH;
+             tegra210_i2s_set_data_offset(i2s, 0);
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     mask |= I2S_CTRL_EDGE_CTRL_MASK;
+     switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+     case SND_SOC_DAIFMT_NB_NF:
+             val |= I2S_CTRL_EDGE_CTRL_POS_EDGE;
+             break;
+     case SND_SOC_DAIFMT_NB_IF:
+             val |= I2S_CTRL_EDGE_CTRL_POS_EDGE;
+             val ^= I2S_CTRL_LRCK_POL_MASK;
+             break;
+     case SND_SOC_DAIFMT_IB_NF:
+             val |= I2S_CTRL_EDGE_CTRL_NEG_EDGE;
+             break;
+     case SND_SOC_DAIFMT_IB_IF:
+             val |= I2S_CTRL_EDGE_CTRL_NEG_EDGE;
+             val ^= I2S_CTRL_LRCK_POL_MASK;
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, mask, val);
+
+     i2s->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
+
+     return 0;
+}
+
+static int tegra210_i2s_set_tdm_slot(struct snd_soc_dai *dai,
+                                  unsigned int tx_mask, unsigned int rx_mask,
+                                  int slots, int slot_width)
+{
+     struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+
+     /* Copy the required tx and rx mask */
+     i2s->tx_mask = (tx_mask > DEFAULT_I2S_SLOT_MASK) ?
+                    DEFAULT_I2S_SLOT_MASK : tx_mask;
+     i2s->rx_mask = (rx_mask > DEFAULT_I2S_SLOT_MASK) ?
+                    DEFAULT_I2S_SLOT_MASK : rx_mask;
+
+     return 0;
+}
+
+static int tegra210_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
+                                        unsigned int ratio)
+{
+     struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+
+     i2s->bclk_ratio = ratio;
+
+     return 0;
+}
+
+static int tegra210_i2s_get_control(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+     struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol);
+     struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt);
+     long *uctl_val = &ucontrol->value.integer.value[0];
+
+     if (strstr(kcontrol->id.name, "Loopback"))
+             *uctl_val = i2s->loopback;
+     else if (strstr(kcontrol->id.name, "Sample Rate"))
+             *uctl_val = i2s->srate_override;
+     else if (strstr(kcontrol->id.name, "FSYNC Width"))
+             *uctl_val = i2s->fsync_width;
+     else if (strstr(kcontrol->id.name, "Playback Audio Bit Format"))
+             *uctl_val = i2s->audio_fmt_override[I2S_RX_PATH];
+     else if (strstr(kcontrol->id.name, "Capture Audio Bit Format"))
+             *uctl_val = i2s->audio_fmt_override[I2S_TX_PATH];
+     else if (strstr(kcontrol->id.name, "Client Bit Format"))
+             *uctl_val = i2s->client_fmt_override;
+     else if (strstr(kcontrol->id.name, "Playback Audio Channels"))
+             *uctl_val = i2s->audio_ch_override[I2S_RX_PATH];
+     else if (strstr(kcontrol->id.name, "Capture Audio Channels"))
+             *uctl_val = i2s->audio_ch_override[I2S_TX_PATH];
+     else if (strstr(kcontrol->id.name, "Client Channels"))
+             *uctl_val = i2s->client_ch_override;
+     else if (strstr(kcontrol->id.name, "Capture Stereo To Mono"))
+             *uctl_val = i2s->stereo_to_mono[I2S_TX_PATH];
+     else if (strstr(kcontrol->id.name, "Capture Mono To Stereo"))
+             *uctl_val = i2s->mono_to_stereo[I2S_TX_PATH];
+     else if (strstr(kcontrol->id.name, "Playback Stereo To Mono"))
+             *uctl_val = i2s->stereo_to_mono[I2S_RX_PATH];
+     else if (strstr(kcontrol->id.name, "Playback Mono To Stereo"))
+             *uctl_val = i2s->mono_to_stereo[I2S_RX_PATH];
+     else if (strstr(kcontrol->id.name, "Playback FIFO Threshold"))
+             *uctl_val = i2s->rx_fifo_th;
+     else if (strstr(kcontrol->id.name, "BCLK Ratio"))
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 362

Quoted 7 lines
sound/soc/tegra/tegra210_i2s.c new file +7 -0
+             *uctl_val = i2s->bclk_ratio;
+
+     return 0;
+}
+
+static int tegra210_i2s_put_control(struct snd_kcontrol *kcontrol,
+     struct snd_ctl_elem_value *ucontrol)

Checkpatch should complain about the wrong indentation here.

I had run checkpatch before sending the patch, below is the result.
-----
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #70:
new file mode 100644

total: 0 errors, 1 warnings, 1103 lines checked

NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
-----

Quoted 49 lines
Quoted 49 lines
sound/soc/tegra/tegra210_i2s.c new file +48 -0
+{
+     struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol);
+     struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt);
+     int value = ucontrol->value.integer.value[0];
+
+     if (strstr(kcontrol->id.name, "Loopback")) {
+             i2s->loopback = value;
+
+             regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL,
+                                I2S_CTRL_LPBK_MASK,
+                                i2s->loopback << I2S_CTRL_LPBK_SHIFT);
+
+     } else if (strstr(kcontrol->id.name, "Sample Rate"))
+             i2s->srate_override = value;
+     else if (strstr(kcontrol->id.name, "FSYNC Width")) {
+             /*
+              * Frame sync width is used only for FSYNC modes and not
+              * applicable for LRCK modes. Reset value for this field is "0",
+              * which means the width is one bit clock wide.
+              * The width requirement may depend on the codec and in such
+              * cases mixer control is used to update custom values. A value
+              * of "N" here means, width is "N + 1" bit clock wide.
+              */
+             i2s->fsync_width = value;
+
+             regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL,
+                                I2S_CTRL_FSYNC_WIDTH_MASK,
+                                i2s->fsync_width << I2S_FSYNC_WIDTH_SHIFT);
+
+     } else if (strstr(kcontrol->id.name, "Playback Audio Bit Format"))
+             i2s->audio_fmt_override[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Audio Bit Format"))
+             i2s->audio_fmt_override[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Client Bit Format"))
+             i2s->client_fmt_override = value;
+     else if (strstr(kcontrol->id.name, "Playback Audio Channels"))
+             i2s->audio_ch_override[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Audio Channels"))
+             i2s->audio_ch_override[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Client Channels"))
+             i2s->client_ch_override = value;
+     else if (strstr(kcontrol->id.name, "Capture Stereo To Mono"))
+             i2s->stereo_to_mono[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Mono To Stereo"))
+             i2s->mono_to_stereo[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback Stereo To Mono"))
+             i2s->stereo_to_mono[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback Mono To Stereo"))
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 415

Quoted 5 lines
sound/soc/tegra/tegra210_i2s.c new file +5 -0
+             i2s->mono_to_stereo[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback FIFO Threshold"))
+             i2s->rx_fifo_th = value;
+     else if (strstr(kcontrol->id.name, "BCLK Ratio"))
+             i2s->bclk_ratio = value;

I'm pretty sure that checkpatch should complain about the missing brackets, they should make code's indentation uniform and thus easier to read. Same for all other occurrences in the code.

same as above

Quoted 190 lines
Quoted 190 lines
sound/soc/tegra/tegra210_i2s.c new file +190 -0
+     return 0;
+}
+
+static const char * const tegra210_i2s_format_text[] = {
+     "None",
+     "16",
+     "32",
+};
+
+static const int tegra210_cif_fmt[] = {
+     0,
+     TEGRA_ACIF_BITS_16,
+     TEGRA_ACIF_BITS_32,
+};
+
+static const int tegra210_i2s_bit_fmt[] = {
+     0,
+     I2S_BITS_16,
+     I2S_BITS_32,
+};
+
+static const int tegra210_i2s_sample_size[] = {
+     0,
+     16,
+     32,
+};
+
+static const struct soc_enum tegra210_i2s_format_enum =
+     SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(tegra210_i2s_format_text),
+                     tegra210_i2s_format_text);
+
+static int tegra210_i2s_set_timing_params(struct device *dev,
+                                       unsigned int sample_size,
+                                       unsigned int srate,
+                                       unsigned int channels)
+{
+     struct tegra210_i2s *i2s = dev_get_drvdata(dev);
+     unsigned int val, bit_count, bclk_rate, num_bclk = sample_size;
+     int ret;
+
+     if (i2s->bclk_ratio)
+             num_bclk *= i2s->bclk_ratio;
+
+     if (i2s->dai_fmt == SND_SOC_DAIFMT_RIGHT_J)
+             tegra210_i2s_set_data_offset(i2s, num_bclk - sample_size);
+
+     /* I2S bit clock rate */
+     bclk_rate = srate * channels * num_bclk;
+
+     ret = tegra210_i2s_set_clock_rate(dev, bclk_rate);
+     if (ret) {
+             dev_err(dev, "can't set I2S bit clock rate %u, err: %d\n",
+                     bclk_rate, ret);
+             return ret;
+     }
+
+     regmap_read(i2s->regmap, TEGRA210_I2S_CTRL, &val);
+
+     /*
+      * For LRCK mode, channel bit count depends on number of bit clocks
+      * on the left channel, where as for FSYNC mode bit count depends on
+      * the number of bit clocks in both left and right channels for DSP
+      * mode or the number of bit clocks in one TDM frame.
+      *
+      */
+     switch (val & I2S_CTRL_FRAME_FMT_MASK) {
+     case I2S_CTRL_FRAME_FMT_LRCK_MODE:
+             bit_count = (bclk_rate / (srate * 2)) - 1;
+             break;
+     case I2S_CTRL_FRAME_FMT_FSYNC_MODE:
+             bit_count = (bclk_rate / srate) - 1;
+
+             tegra210_i2s_set_slot_ctrl(i2s->regmap, channels,
+                                        i2s->tx_mask, i2s->rx_mask);
+             break;
+     default:
+             dev_err(dev, "invalid I2S mode\n");
+             return -EINVAL;
+     }
+
+     if (bit_count > I2S_TIMING_CH_BIT_CNT_MASK) {
+             dev_err(dev, "invalid channel bit count %u\n", bit_count);
+             return -EINVAL;
+     }
+
+     regmap_write(i2s->regmap, TEGRA210_I2S_TIMING,
+                  bit_count << I2S_TIMING_CH_BIT_CNT_SHIFT);
+
+     return 0;
+}
+
+static int tegra210_i2s_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params,
+                               struct snd_soc_dai *dai)
+{
+     struct device *dev = dai->dev;
+     struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+     unsigned int sample_size, channels, srate, val, reg, path;
+     struct tegra_cif_conf cif_conf;
+     int max_th;
+
+     memset(&cif_conf, 0, sizeof(struct tegra_cif_conf));
+
+     channels = params_channels(params);
+     if (channels < 1) {
+             dev_err(dev, "invalid %d channel configuration\n", channels);
+             return -EINVAL;
+     }
+
+     cif_conf.audio_ch = channels;
+     cif_conf.client_ch = channels;
+
+     switch (params_format(params)) {
+     case SNDRV_PCM_FORMAT_S8:
+             val = I2S_BITS_8;
+             sample_size = 8;
+             cif_conf.audio_bits = TEGRA_ACIF_BITS_8;
+             cif_conf.client_bits = TEGRA_ACIF_BITS_8;
+             break;
+     case SNDRV_PCM_FORMAT_S16_LE:
+             val = I2S_BITS_16;
+             sample_size = 16;
+             cif_conf.audio_bits = TEGRA_ACIF_BITS_16;
+             cif_conf.client_bits = TEGRA_ACIF_BITS_16;
+             break;
+     case SNDRV_PCM_FORMAT_S32_LE:
+             val = I2S_BITS_32;
+             sample_size = 32;
+             cif_conf.audio_bits = TEGRA_ACIF_BITS_32;
+             cif_conf.client_bits = TEGRA_ACIF_BITS_32;
+             break;
+     default:
+             dev_err(dev, "unsupported format!\n");
+             return -ENOTSUPP;
+     }
+
+     if (i2s->client_fmt_override) {
+             val = tegra210_i2s_bit_fmt[i2s->client_fmt_override];
+             sample_size =
+                     tegra210_i2s_sample_size[i2s->client_fmt_override];
+             cif_conf.client_bits =
+                     tegra210_cif_fmt[i2s->client_fmt_override];
+     }
+
+     /* Program sample size */
+     regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL,
+                        I2S_CTRL_BIT_SIZE_MASK, val);
+
+     srate = params_rate(params);
+
+     /* Override rate, channel and audio bit params as applicable */
+     if (i2s->srate_override)
+             srate = i2s->srate_override;
+
+     /*
+      * For playback I2S RX-CIF and for capture TX-CIF is used.
+      * With reference to AHUB, for I2S, SNDRV_PCM_STREAM_CAPTURE stream is
+      * actually for playback.
+      */
+     path = (substream->stream == SNDRV_PCM_STREAM_CAPTURE) ?
+            I2S_RX_PATH : I2S_TX_PATH;
+
+     if (i2s->audio_ch_override[path])
+             cif_conf.audio_ch = i2s->audio_ch_override[path];
+
+     if (i2s->client_ch_override)
+             cif_conf.client_ch = i2s->client_ch_override;
+
+     if (i2s->audio_fmt_override[path])
+             cif_conf.audio_bits =
+                     tegra210_cif_fmt[i2s->audio_fmt_override[path]];
+
+     if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+             reg = TEGRA210_I2S_RX_CIF_CTRL;
+
+             /* FIFO threshold in terms of frames */
+             max_th = (I2S_RX_FIFO_DEPTH / cif_conf.audio_ch) - 1;
+             if (max_th < 0)
+                     return -EINVAL;
+
+             if (i2s->rx_fifo_th > max_th)
+                     i2s->rx_fifo_th = max_th;
+
+             cif_conf.threshold = i2s->rx_fifo_th;
+     } else
+             reg = TEGRA210_I2S_TX_CIF_CTRL;
+
+     cif_conf.mono_conv = i2s->mono_to_stereo[path];
+     cif_conf.stereo_conv = i2s->stereo_to_mono[path];
+
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 613

Quoted 7 lines
sound/soc/tegra/tegra210_i2s.c new file +7 -0
+     tegra_set_cif(i2s->regmap, reg, &cif_conf);
+
+     return tegra210_i2s_set_timing_params(dev, sample_size, srate,
+                                           cif_conf.client_ch);
+}
+
+static struct snd_soc_dai_ops tegra210_i2s_dai_ops = {

const?

will add

Quoted 239 lines
Quoted 239 lines
sound/soc/tegra/tegra210_i2s.c new file +238 -0
+     .set_fmt        = tegra210_i2s_set_fmt,
+     .hw_params      = tegra210_i2s_hw_params,
+     .set_bclk_ratio = tegra210_i2s_set_dai_bclk_ratio,
+     .set_tdm_slot   = tegra210_i2s_set_tdm_slot,
+};
+
+/*
+ * Three DAIs are exposed
+ * 1. "CIF" DAI for connecting with XBAR
+ * 2. "DAP" DAI for connecting with CODEC
+ * 3. "DUMMY" can be used when no external codec connection is
+ *    available. In such case "DAP" is connected with "DUMMY".
+ * Order of these DAIs should not be changed, since DAI links in DT refer
+ * to these DAIs depending on the index.
+ */
+static struct snd_soc_dai_driver tegra210_i2s_dais[] = {
+     {
+             .name = "CIF",
+             .playback = {
+                     .stream_name = "CIF Receive",
+                     .channels_min = 1,
+                     .channels_max = 16,
+                     .rates = SNDRV_PCM_RATE_8000_192000,
+                     .formats = SNDRV_PCM_FMTBIT_S8 |
+                             SNDRV_PCM_FMTBIT_S16_LE |
+                             SNDRV_PCM_FMTBIT_S32_LE,
+             },
+             .capture = {
+                     .stream_name = "CIF Transmit",
+                     .channels_min = 1,
+                     .channels_max = 16,
+                     .rates = SNDRV_PCM_RATE_8000_192000,
+                     .formats = SNDRV_PCM_FMTBIT_S8 |
+                             SNDRV_PCM_FMTBIT_S16_LE |
+                             SNDRV_PCM_FMTBIT_S32_LE,
+             },
+     },
+     {
+             .name = "DAP",
+             .playback = {
+                     .stream_name = "DAP Receive",
+                     .channels_min = 1,
+                     .channels_max = 16,
+                     .rates = SNDRV_PCM_RATE_8000_192000,
+                     .formats = SNDRV_PCM_FMTBIT_S8 |
+                             SNDRV_PCM_FMTBIT_S16_LE |
+                             SNDRV_PCM_FMTBIT_S32_LE,
+             },
+             .capture = {
+                     .stream_name = "DAP Transmit",
+                     .channels_min = 1,
+                     .channels_max = 16,
+                     .rates = SNDRV_PCM_RATE_8000_192000,
+                     .formats = SNDRV_PCM_FMTBIT_S8 |
+                             SNDRV_PCM_FMTBIT_S16_LE |
+                             SNDRV_PCM_FMTBIT_S32_LE,
+             },
+             .ops = &tegra210_i2s_dai_ops,
+             .symmetric_rates = 1,
+     },
+     {
+             .name = "DUMMY",
+             .playback = {
+                     .stream_name = "Dummy Playback",
+                     .channels_min = 1,
+                     .channels_max = 16,
+                     .rates = SNDRV_PCM_RATE_8000_192000,
+                     .formats = SNDRV_PCM_FMTBIT_S8 |
+                             SNDRV_PCM_FMTBIT_S16_LE |
+                             SNDRV_PCM_FMTBIT_S32_LE,
+             },
+             .capture = {
+                     .stream_name = "Dummy Capture",
+                     .channels_min = 1,
+                     .channels_max = 16,
+                     .rates = SNDRV_PCM_RATE_8000_192000,
+                     .formats = SNDRV_PCM_FMTBIT_S8 |
+                             SNDRV_PCM_FMTBIT_S16_LE |
+                             SNDRV_PCM_FMTBIT_S32_LE,
+             },
+     },
+};
+
+static const char * const tegra210_i2s_stereo_conv_text[] = {
+     "CH0", "CH1", "AVG",
+};
+
+static const char * const tegra210_i2s_mono_conv_text[] = {
+     "ZERO", "COPY",
+};
+
+static const struct soc_enum tegra210_i2s_mono_conv_enum =
+     SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(tegra210_i2s_mono_conv_text),
+                     tegra210_i2s_mono_conv_text);
+
+static const struct soc_enum tegra210_i2s_stereo_conv_enum =
+     SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(tegra210_i2s_stereo_conv_text),
+                     tegra210_i2s_stereo_conv_text);
+
+static const struct snd_kcontrol_new tegra210_i2s_controls[] = {
+     SOC_SINGLE_EXT("Loopback", 0, 0, 1, 0, tegra210_i2s_get_control,
+                    tegra210_i2s_put_control),
+     SOC_SINGLE_EXT("FSYNC Width", 0, 0, 255, 0, tegra210_i2s_get_control,
+                    tegra210_i2s_put_control),
+     SOC_SINGLE_EXT("Sample Rate", 0, 0, 192000, 0, tegra210_i2s_get_control,
+                    tegra210_i2s_put_control),
+     SOC_ENUM_EXT("Playback Audio Bit Format", tegra210_i2s_format_enum,
+                  tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_ENUM_EXT("Capture Audio Bit Format", tegra210_i2s_format_enum,
+                  tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_ENUM_EXT("Client Bit Format", tegra210_i2s_format_enum,
+                  tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_SINGLE_EXT("Playback Audio Channels", 0, 0, 16, 0,
+                    tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_SINGLE_EXT("Capture Audio Channels", 0, 0, 16, 0,
+                    tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_SINGLE_EXT("Client Channels", 0, 0, 16, 0,
+                    tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_ENUM_EXT("Capture Stereo To Mono", tegra210_i2s_stereo_conv_enum,
+                  tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_ENUM_EXT("Capture Mono To Stereo", tegra210_i2s_mono_conv_enum,
+                  tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_ENUM_EXT("Playback Stereo To Mono", tegra210_i2s_stereo_conv_enum,
+                  tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_ENUM_EXT("Playback Mono To Stereo", tegra210_i2s_mono_conv_enum,
+                  tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_SINGLE_EXT("Playback FIFO Threshold", 0, 0, I2S_RX_FIFO_DEPTH - 1,
+                    0, tegra210_i2s_get_control, tegra210_i2s_put_control),
+     SOC_SINGLE_EXT("BCLK Ratio", 0, 0, INT_MAX, 0, tegra210_i2s_get_control,
+                    tegra210_i2s_put_control),
+};
+
+static const struct snd_soc_dapm_widget tegra210_i2s_widgets[] = {
+     SND_SOC_DAPM_AIF_IN("CIF RX", NULL, 0, SND_SOC_NOPM, 0, 0),
+     SND_SOC_DAPM_AIF_OUT("CIF TX", NULL, 0, SND_SOC_NOPM, 0, 0),
+     SND_SOC_DAPM_AIF_IN_E("DAP RX", NULL, 0, TEGRA210_I2S_TX_ENABLE,
+                           0, 0, tegra210_i2s_init, SND_SOC_DAPM_PRE_PMU),
+     SND_SOC_DAPM_AIF_OUT_E("DAP TX", NULL, 0, TEGRA210_I2S_RX_ENABLE,
+                            0, 0, tegra210_i2s_init, SND_SOC_DAPM_PRE_PMU),
+     SND_SOC_DAPM_MIC("Dummy Input", NULL),
+     SND_SOC_DAPM_SPK("Dummy Output", NULL),
+};
+
+static const struct snd_soc_dapm_route tegra210_i2s_routes[] = {
+     { "CIF RX",       NULL, "CIF Receive" },
+     { "DAP TX",       NULL, "CIF RX" },
+     { "DAP Transmit", NULL, "DAP TX" },
+
+     { "DAP RX",       NULL, "DAP Receive" },
+     { "CIF TX",       NULL, "DAP RX" },
+     { "CIF Transmit", NULL, "CIF TX" },
+
+     { "Dummy Capture", NULL, "Dummy Input" },
+     { "Dummy Output", NULL, "Dummy Playback" },
+};
+
+static const struct snd_soc_component_driver tegra210_i2s_cmpnt = {
+     .dapm_widgets = tegra210_i2s_widgets,
+     .num_dapm_widgets = ARRAY_SIZE(tegra210_i2s_widgets),
+     .dapm_routes = tegra210_i2s_routes,
+     .num_dapm_routes = ARRAY_SIZE(tegra210_i2s_routes),
+     .controls = tegra210_i2s_controls,
+     .num_controls = ARRAY_SIZE(tegra210_i2s_controls),
+     .non_legacy_dai_naming = 1,
+};
+
+static bool tegra210_i2s_wr_reg(struct device *dev, unsigned int reg)
+{
+     switch (reg) {
+     case TEGRA210_I2S_RX_ENABLE ... TEGRA210_I2S_RX_SOFT_RESET:
+     case TEGRA210_I2S_RX_INT_MASK ... TEGRA210_I2S_RX_CLK_TRIM:
+     case TEGRA210_I2S_TX_ENABLE ... TEGRA210_I2S_TX_SOFT_RESET:
+     case TEGRA210_I2S_TX_INT_MASK ... TEGRA210_I2S_TX_CLK_TRIM:
+     case TEGRA210_I2S_ENABLE ... TEGRA210_I2S_CG:
+     case TEGRA210_I2S_CTRL ... TEGRA210_I2S_CYA:
+             return true;
+     default:
+             return false;
+     };
+}
+
+static bool tegra210_i2s_rd_reg(struct device *dev, unsigned int reg)
+{
+     if (tegra210_i2s_wr_reg(dev, reg))
+             return true;
+
+     switch (reg) {
+     case TEGRA210_I2S_RX_STATUS:
+     case TEGRA210_I2S_RX_INT_STATUS:
+     case TEGRA210_I2S_RX_CIF_FIFO_STATUS:
+     case TEGRA210_I2S_TX_STATUS:
+     case TEGRA210_I2S_TX_INT_STATUS:
+     case TEGRA210_I2S_TX_CIF_FIFO_STATUS:
+     case TEGRA210_I2S_STATUS:
+     case TEGRA210_I2S_INT_STATUS:
+             return true;
+     default:
+             return false;
+     };
+}
+
+static bool tegra210_i2s_volatile_reg(struct device *dev, unsigned int reg)
+{
+     switch (reg) {
+     case TEGRA210_I2S_RX_STATUS:
+     case TEGRA210_I2S_RX_INT_STATUS:
+     case TEGRA210_I2S_RX_CIF_FIFO_STATUS:
+     case TEGRA210_I2S_TX_STATUS:
+     case TEGRA210_I2S_TX_INT_STATUS:
+     case TEGRA210_I2S_TX_CIF_FIFO_STATUS:
+     case TEGRA210_I2S_STATUS:
+     case TEGRA210_I2S_INT_STATUS:
+     case TEGRA210_I2S_RX_SOFT_RESET:
+     case TEGRA210_I2S_TX_SOFT_RESET:
+             return true;
+     default:
+             return false;
+     };
+}
+
+static const struct regmap_config tegra210_i2s_regmap_config = {
+     .reg_bits               = 32,
+     .reg_stride             = 4,
+     .val_bits               = 32,
+     .max_register           = TEGRA210_I2S_CYA,
+     .writeable_reg          = tegra210_i2s_wr_reg,
+     .readable_reg           = tegra210_i2s_rd_reg,
+     .volatile_reg           = tegra210_i2s_volatile_reg,
+     .reg_defaults           = tegra210_i2s_reg_defaults,
+     .num_reg_defaults       = ARRAY_SIZE(tegra210_i2s_reg_defaults),
+     .cache_type             = REGCACHE_FLAT,
+};
+
+static const struct of_device_id tegra210_i2s_of_match[] = {
+     { .compatible = "nvidia,tegra210-i2s" },
+     {},
+};
+
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 857

Quoted 6 lines
sound/soc/tegra/tegra210_i2s.c new file +6 -0
+static int tegra210_i2s_probe(struct platform_device *pdev)
+{
+     struct device *dev = &pdev->dev;
+     struct tegra210_i2s *i2s;
+     void __iomem *regs;
+     int ret = 0;

Please do not initialize variables if it's not really needed, to keep code cleaner. Same for all other occurrences in the code.

initialization can be avoided, will remove.

Quoted 41 lines
Quoted 41 lines
sound/soc/tegra/tegra210_i2s.c new file +40 -0
+     i2s = devm_kcalloc(dev, 1, sizeof(*i2s), GFP_KERNEL);
+     if (!i2s)
+             return -ENOMEM;
+
+     i2s->rx_fifo_th = DEFAULT_I2S_RX_FIFO_THRESHOLD;
+     i2s->tx_mask = i2s->rx_mask = DEFAULT_I2S_SLOT_MASK;
+     i2s->loopback = false;
+
+     dev_set_drvdata(dev, i2s);
+
+     i2s->clk_i2s = devm_clk_get(dev, "i2s");
+     if (IS_ERR(i2s->clk_i2s)) {
+             dev_err(dev, "can't retrieve I2S bit clock\n");
+             return PTR_ERR(i2s->clk_i2s);
+     }
+
+     /*
+      * Not an error, as this clock is needed only when some other I/O
+      * requires input clock from current I2S instance, which is
+      * configurable from DT.
+      */
+     i2s->clk_sync_input = devm_clk_get(dev, "sync_input");
+     if (IS_ERR(i2s->clk_sync_input))
+             dev_dbg(dev, "can't retrieve I2S sync input clock\n");
+
+     regs = devm_platform_ioremap_resource(pdev, 0);
+     if (IS_ERR(regs))
+             return PTR_ERR(regs);
+
+     i2s->regmap = devm_regmap_init_mmio(dev, regs,
+                                         &tegra210_i2s_regmap_config);
+     if (IS_ERR(i2s->regmap)) {
+             dev_err(dev, "regmap init failed\n");
+             return PTR_ERR(i2s->regmap);
+     }
+
+     regcache_cache_only(i2s->regmap, true);
+
+     ret = devm_snd_soc_register_component(dev, &tegra210_i2s_cmpnt,
+                                           tegra210_i2s_dais,
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 905

Quoted 7 lines
sound/soc/tegra/tegra210_i2s.c new file +7 -0
+                                           ARRAY_SIZE(tegra210_i2s_dais));
+     if (ret != 0) {
+             dev_err(dev, "can't register I2S component, err: %d\n", ret);
+             return ret;
+     }
+
+     pm_runtime_enable(dev);

Error checking?

return type for above is void()

Quoted 11 lines

sound/soc/tegra/tegra210_i2s.c line 914

Quoted 8 lines
sound/soc/tegra/tegra210_i2s.c new file +8 -0
+     return 0;
+}
+
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed. I see few drivers using this way.

Quoted 16 lines
Quoted 4 lines
sound/soc/tegra/tegra210_i2s.c new file +3 -0
+     return 0;
+}
+

sound/soc/tegra/tegra210_i2s.c line 928

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +10 -0
+static const struct dev_pm_ops tegra210_i2s_pm_ops = {
+     SET_RUNTIME_PM_OPS(tegra210_i2s_runtime_suspend,
+                        tegra210_i2s_runtime_resume, NULL)
+     SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+                                  pm_runtime_force_resume)
+};
+
+static struct platform_driver tegra210_i2s_driver = {
+     .driver = {
+             .name = DRV_NAME,

Will be nicer to set the name directly here, thus to remove the DRV_NAME macro.

can be done.

Quoted 3 lines

sound/soc/tegra/tegra210_i2s.c line 929

Quoted 2 lines
sound/soc/tegra/tegra210_i2s.c new file +1 -0
+             .owner = THIS_MODULE,

No need to explicitly set the owner, drivers core takes care about it.

OK, will remove.

Quoted 15 lines

sound/soc/tegra/tegra210_i2s.c line 941

Quoted 13 lines
sound/soc/tegra/tegra210_i2s.c new file +12 -0
+             .of_match_table = tegra210_i2s_of_match,
+             .pm = &tegra210_i2s_pm_ops,
+     },
+     .probe = tegra210_i2s_probe,
+     .remove = tegra210_i2s_remove,
+};
+module_platform_driver(tegra210_i2s_driver)
+
+MODULE_AUTHOR("Songhee Baek <[email protected]>");
+MODULE_DESCRIPTION("Tegra210 ASoC I2S driver");
+MODULE_LICENSE("GPL v2");
+MODULE_DEVICE_TABLE(of, tegra210_i2s_of_match);

What about to place MODULE_DEVICE_TABLE() right after the definition of tegra210_i2s_of_match like it's done by most of the drivers in kernel?

yes will move.

Quoted 128 lines
Quoted 128 lines
sound/soc/tegra/tegra210_i2s.h new file +121 -0
new file mode 100644
index 0000000..121dff7
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * tegra210_i2s.h - Definitions for Tegra210 I2S driver
+ *
+ * Copyright (c) 2020 NVIDIA CORPORATION. All rights reserved.
+ *
+ */
+
+#ifndef __TEGRA210_I2S_H__
+#define __TEGRA210_I2S_H__
+
+/* Register offsets from I2S*_BASE */
+#define TEGRA210_I2S_RX_ENABLE                       0x0
+#define TEGRA210_I2S_RX_SOFT_RESET           0x4
+#define TEGRA210_I2S_RX_STATUS                       0x0c
+#define TEGRA210_I2S_RX_INT_STATUS           0x10
+#define TEGRA210_I2S_RX_INT_MASK             0x14
+#define TEGRA210_I2S_RX_INT_SET                      0x18
+#define TEGRA210_I2S_RX_INT_CLEAR            0x1c
+#define TEGRA210_I2S_RX_CIF_CTRL             0x20
+#define TEGRA210_I2S_RX_CTRL                 0x24
+#define TEGRA210_I2S_RX_SLOT_CTRL            0x28
+#define TEGRA210_I2S_RX_CLK_TRIM             0x2c
+#define TEGRA210_I2S_RX_CYA                  0x30
+#define TEGRA210_I2S_RX_CIF_FIFO_STATUS              0x34
+#define TEGRA210_I2S_TX_ENABLE                       0x40
+#define TEGRA210_I2S_TX_SOFT_RESET           0x44
+#define TEGRA210_I2S_TX_STATUS                       0x4c
+#define TEGRA210_I2S_TX_INT_STATUS           0x50
+#define TEGRA210_I2S_TX_INT_MASK             0x54
+#define TEGRA210_I2S_TX_INT_SET                      0x58
+#define TEGRA210_I2S_TX_INT_CLEAR            0x5c
+#define TEGRA210_I2S_TX_CIF_CTRL             0x60
+#define TEGRA210_I2S_TX_CTRL                 0x64
+#define TEGRA210_I2S_TX_SLOT_CTRL            0x68
+#define TEGRA210_I2S_TX_CLK_TRIM             0x6c
+#define TEGRA210_I2S_TX_CYA                  0x70
+#define TEGRA210_I2S_TX_CIF_FIFO_STATUS              0x74
+#define TEGRA210_I2S_ENABLE                  0x80
+#define TEGRA210_I2S_SOFT_RESET                      0x84
+#define TEGRA210_I2S_CG                              0x88
+#define TEGRA210_I2S_STATUS                  0x8c
+#define TEGRA210_I2S_INT_STATUS                      0x90
+#define TEGRA210_I2S_CTRL                    0xa0
+#define TEGRA210_I2S_TIMING                  0xa4
+#define TEGRA210_I2S_SLOT_CTRL                       0xa8
+#define TEGRA210_I2S_CLK_TRIM                        0xac
+#define TEGRA210_I2S_CYA                     0xb0
+
+/* Bit fields, shifts and masks */
+#define I2S_DATA_SHIFT                               8
+#define I2S_CTRL_DATA_OFFSET_MASK            (0x7ff << I2S_DATA_SHIFT)
+
+#define I2S_EN_SHIFT                         0
+#define I2S_EN_MASK                          (1 << I2S_EN_SHIFT)
+#define I2S_EN                                       (1 << I2S_EN_SHIFT)
+
+#define I2S_FSYNC_WIDTH_SHIFT                        24
+#define I2S_CTRL_FSYNC_WIDTH_MASK            (0xff << I2S_FSYNC_WIDTH_SHIFT)
+
+#define I2S_POS_EDGE                         0
+#define I2S_NEG_EDGE                         1
+#define I2S_EDGE_SHIFT                               20
+#define I2S_CTRL_EDGE_CTRL_MASK                      (1 << I2S_EDGE_SHIFT)
+#define I2S_CTRL_EDGE_CTRL_POS_EDGE          (I2S_POS_EDGE << I2S_EDGE_SHIFT)
+#define I2S_CTRL_EDGE_CTRL_NEG_EDGE          (I2S_NEG_EDGE << I2S_EDGE_SHIFT)
+
+#define I2S_FMT_LRCK                         0
+#define I2S_FMT_FSYNC                                1
+#define I2S_FMT_SHIFT                                12
+#define I2S_CTRL_FRAME_FMT_MASK                      (7 << I2S_FMT_SHIFT)
+#define I2S_CTRL_FRAME_FMT_LRCK_MODE         (I2S_FMT_LRCK << I2S_FMT_SHIFT)
+#define I2S_CTRL_FRAME_FMT_FSYNC_MODE                (I2S_FMT_FSYNC << I2S_FMT_SHIFT)
+
+#define I2S_CTRL_MASTER_EN_SHIFT             10
+#define I2S_CTRL_MASTER_EN_MASK                      (1 << I2S_CTRL_MASTER_EN_SHIFT)
+#define I2S_CTRL_MASTER_EN                   (1 << I2S_CTRL_MASTER_EN_SHIFT)
+
+#define I2S_CTRL_LRCK_POL_SHIFT                      9
+#define I2S_CTRL_LRCK_POL_MASK                       (1 << I2S_CTRL_LRCK_POL_SHIFT)
+#define I2S_CTRL_LRCK_POL_LOW                        (0 << I2S_CTRL_LRCK_POL_SHIFT)
+#define I2S_CTRL_LRCK_POL_HIGH                       (1 << I2S_CTRL_LRCK_POL_SHIFT)
+
+#define I2S_CTRL_LPBK_SHIFT                  8
+#define I2S_CTRL_LPBK_MASK                   (1 << I2S_CTRL_LPBK_SHIFT)
+#define I2S_CTRL_LPBK_EN                     (1 << I2S_CTRL_LPBK_SHIFT)
+
+#define I2S_BITS_8                           1
+#define I2S_BITS_16                          3
+#define I2S_BITS_32                          7
+#define I2S_CTRL_BIT_SIZE_MASK                       0x7
+
+#define I2S_TIMING_CH_BIT_CNT_MASK           0x7ff
+#define I2S_TIMING_CH_BIT_CNT_SHIFT          0
+
+#define I2S_SOFT_RESET_SHIFT                 0
+#define I2S_SOFT_RESET_MASK                  (1 << I2S_SOFT_RESET_SHIFT)
+#define I2S_SOFT_RESET_EN                    (1 << I2S_SOFT_RESET_SHIFT)
+
+#define I2S_RX_FIFO_DEPTH                    64
+#define DEFAULT_I2S_RX_FIFO_THRESHOLD                3
+
+#define DEFAULT_I2S_SLOT_MASK                        0xffff
+
+enum tegra210_i2s_path {
+     I2S_RX_PATH,
+     I2S_TX_PATH,
+     I2S_PATHS,
+};
+
+struct tegra210_i2s {
+     struct clk *clk_i2s;
+     struct clk *clk_sync_input;
+     struct regmap *regmap;
+     unsigned int stereo_to_mono[I2S_PATHS];
+     unsigned int mono_to_stereo[I2S_PATHS];
+     unsigned int audio_ch_override[I2S_PATHS];
+     unsigned int audio_fmt_override[I2S_PATHS];
+     /* Client overrides are common for TX and RX paths */
+     unsigned int client_ch_override;
+     unsigned int client_fmt_override;
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.h line 128

Quoted 7 lines
sound/soc/tegra/tegra210_i2s.h new file +7 -0
+     unsigned int srate_override;
+     unsigned int dai_fmt;
+     unsigned int fsync_width;
+     unsigned int bclk_ratio;
+     unsigned int tx_mask;
+     unsigned int rx_mask;
+     int rx_fifo_th;

Could rx_fifo_th be negative?

rx_fifo_th itself does not take negative values, explicit typecasting is avoided in "if" condition by declaring this as "int"

Quoted 5 lines
Quoted 5 lines
sound/soc/tegra/tegra210_i2s.h new file +4 -0
+     bool loopback;
+};
+
+#endif
#12 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

21.01.2020 17:21, Sameer Pujar пишет:

[snip]

Quoted 10 lines
Quoted 3 lines
Quoted 2 lines

+static int tegra210_i2s_put_control(struct snd_kcontrol *kcontrol, +     struct snd_ctl_elem_value *ucontrol)

Checkpatch should complain about the wrong indentation here.

I had run checkpatch before sending the patch, below is the result.
-----
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #70:
new file mode 100644

Quoted 6 lines

total: 0 errors, 1 warnings, 1103 lines checked

NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
-----

Using 'checkpatch --strict':

CHECK: Alignment should match open parenthesis
#2693: FILE: sound/soc/tegra/tegra210_i2s.c:362:
+static int tegra210_i2s_put_control(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol

[snip]

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

+
+     } else if (strstr(kcontrol->id.name, "Playback Audio Bit Format")) +             i2s->audio_fmt_override[I2S_RX_PATH] = value; +     else if (strstr(kcontrol->id.name, "Capture Audio Bit Format")) +             i2s->audio_fmt_override[I2S_TX_PATH] = value; +     else if (strstr(kcontrol->id.name, "Client Bit Format")) +             i2s->client_fmt_override = value;
+     else if (strstr(kcontrol->id.name, "Playback Audio Channels")) +             i2s->audio_ch_override[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Audio Channels")) +             i2s->audio_ch_override[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Client Channels")) +             i2s->client_ch_override = value;
+     else if (strstr(kcontrol->id.name, "Capture Stereo To Mono")) +             i2s->stereo_to_mono[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Mono To Stereo")) +             i2s->mono_to_stereo[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback Stereo To Mono")) +             i2s->stereo_to_mono[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback Mono To Stereo")) +             i2s->mono_to_stereo[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback FIFO Threshold")) +             i2s->rx_fifo_th = value;
+     else if (strstr(kcontrol->id.name, "BCLK Ratio"))
+             i2s->bclk_ratio = value;

Quoted 5 lines
Quoted 3 lines

I'm pretty sure that checkpatch should complain about the missing brackets, they should make code's indentation uniform and thus easier to read. Same for all other occurrences in the code.

same as above

CHECK: braces {} should be used on all arms of this statement #2699: FILE: sound/soc/tegra/tegra210_i2s.c:368:
+ if (strstr(kcontrol->id.name, "Loopback")) {
[...]
+ } else if (strstr(kcontrol->id.name, "Sample Rate"))
[...]
+ else if (strstr(kcontrol->id.name, "FSYNC Width")) {
[...]
+ } else if (strstr(kcontrol->id.name, "Playback Audio Bit Format"))
[...]
+ else if (strstr(kcontrol->id.name, "Capture Audio Bit Format"))
[...]
+ else if (strstr(kcontrol->id.name, "Client Bit Format"))
[...]
+ else if (strstr(kcontrol->id.name, "Playback Audio Channels"))
[...]
+ else if (strstr(kcontrol->id.name, "Capture Audio Channels"))
[...]
+ else if (strstr(kcontrol->id.name, "Client Channels"))
[...]
+ else if (strstr(kcontrol->id.name, "Capture Stereo To Mono"))
[...]
+ else if (strstr(kcontrol->id.name, "Capture Mono To Stereo"))
[...]
+ else if (strstr(kcontrol->id.name, "Playback Stereo To Mono"))
[...]
+ else if (strstr(kcontrol->id.name, "Playback Mono To Stereo"))
[...]
+ else if (strstr(kcontrol->id.name, "Playback FIFO Threshold"))
[...]
+ else if (strstr(kcontrol->id.name, "BCLK Ratio"))
[...]

[snip]

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

+     pm_runtime_enable(dev);

Error checking?

return type for above is void()

Ok

Quoted 12 lines
Quoted 11 lines

sound/soc/tegra/tegra210_i2s.c line 914

Quoted 8 lines

+     return 0;

sound/soc/tegra/tegra210_i2s.c new file +7 -0
+}
+
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

It should matter (if I'm not missing something) because RPM should be in a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

+ int rx_fifo_th;

Could rx_fifo_th be negative?

rx_fifo_th itself does not take negative values, explicit typecasting> is avoided in "if" condition by declaring this as "int"

Explicit typecasting isn't needed for integers.

#13 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 26 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

21.01.2020 17:21, Sameer Pujar пишет:

[snip]

Quoted 9 lines
Quoted 3 lines

sound/soc/tegra/tegra210_i2s.c line 362

Quoted 2 lines
sound/soc/tegra/tegra210_i2s.c new file +2 -0
+static int tegra210_i2s_put_control(struct snd_kcontrol *kcontrol,
+     struct snd_ctl_elem_value *ucontrol)

Checkpatch should complain about the wrong indentation here.

I had run checkpatch before sending the patch, below is the result.
-----
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #70:
new file mode 100644

Quoted 6 lines

total: 0 errors, 1 warnings, 1103 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.
-----

Using 'checkpatch --strict':

CHECK: Alignment should match open parenthesis
#2693: FILE: sound/soc/tegra/tegra210_i2s.c:362:

Review

Quoted 4 lines
(quoted diff) +2 -0
+static int tegra210_i2s_put_control(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol
 
[snip]

will fix

Quoted 53 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
sound/soc/tegra/tegra210_i2s.c new file +25 -0
+
+     } else if (strstr(kcontrol->id.name, "Playback Audio Bit Format"))
+             i2s->audio_fmt_override[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Audio Bit Format"))
+             i2s->audio_fmt_override[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Client Bit Format"))
+             i2s->client_fmt_override = value;
+     else if (strstr(kcontrol->id.name, "Playback Audio Channels"))
+             i2s->audio_ch_override[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Audio Channels"))
+             i2s->audio_ch_override[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Client Channels"))
+             i2s->client_ch_override = value;
+     else if (strstr(kcontrol->id.name, "Capture Stereo To Mono"))
+             i2s->stereo_to_mono[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Capture Mono To Stereo"))
+             i2s->mono_to_stereo[I2S_TX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback Stereo To Mono"))
+             i2s->stereo_to_mono[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback Mono To Stereo"))
+             i2s->mono_to_stereo[I2S_RX_PATH] = value;
+     else if (strstr(kcontrol->id.name, "Playback FIFO Threshold"))
+             i2s->rx_fifo_th = value;
+     else if (strstr(kcontrol->id.name, "BCLK Ratio"))
+             i2s->bclk_ratio = value;
Quoted 4 lines
Quoted 3 lines

I'm pretty sure that checkpatch should complain about the missing brackets, they should make code's indentation uniform and thus easier to read. Same for all other occurrences in the code.

same as above

CHECK: braces {} should be used on all arms of this statement #2699: FILE: sound/soc/tegra/tegra210_i2s.c:368:

sound/soc/tegra/tegra210_i2s.c new file +11 -0
+       if (strstr(kcontrol->id.name, "Loopback")) {
[...]
+       } else if (strstr(kcontrol->id.name, "Sample Rate"))
[...]
+       else if (strstr(kcontrol->id.name, "FSYNC Width")) {
[...]
+       } else if (strstr(kcontrol->id.name, "Playback Audio Bit Format"))
[...]
+       else if (strstr(kcontrol->id.name, "Capture Audio Bit Format"))
[...]
+       else if (strstr(kcontrol->id.name, "Client Bit Format"))
[...]
+       else if (strstr(kcontrol->id.name, "Playback Audio Channels"))
[...]
+       else if (strstr(kcontrol->id.name, "Capture Audio Channels"))
[...]
+       else if (strstr(kcontrol->id.name, "Client Channels"))
[...]
+       else if (strstr(kcontrol->id.name, "Capture Stereo To Mono"))
[...]
+       else if (strstr(kcontrol->id.name, "Capture Mono To Stereo"))
[...]

sound/soc/tegra/tegra210_i2s.c

Quoted 10 lines
sound/soc/tegra/tegra210_i2s.c new file +4 -0
+       else if (strstr(kcontrol->id.name, "Playback Stereo To Mono"))
[...]
+       else if (strstr(kcontrol->id.name, "Playback Mono To Stereo"))
[...]
+       else if (strstr(kcontrol->id.name, "Playback FIFO Threshold"))
[...]
+       else if (strstr(kcontrol->id.name, "BCLK Ratio"))
[...]
 
[snip]

will fix

Quoted 21 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

+ pm_runtime_enable(dev);

Error checking?

return type for above is void()

Ok

Quoted 11 lines
Quoted 11 lines

sound/soc/tegra/tegra210_i2s.c line 914

Quoted 8 lines
sound/soc/tegra/tegra210_i2s.c new file +8 -0
+     return 0;
+}
+
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 5 lines

It should matter (if I'm not missing something) because RPM should be in a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use the same 'dev' and the corresponding ref count. Doesn't it use the new counters? If RPM is not working for some reason, most likely it would be the case for other devices. What best driver can do is probably do a force suspend during removal if already not done. I would prefer to keep, since multiple drivers still have it, unless there is a real harm in doing so.

Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

+ int rx_fifo_th;

Could rx_fifo_th be negative?

rx_fifo_th itself does not take negative values, explicit typecasting> is avoided in "if" condition by declaring this as "int"

Explicit typecasting isn't needed for integers.

What I meant was, rx_fifo_th is checked against a 'int' variable in an "if" condition.

#14 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

22.01.2020 07:32, Sameer Pujar пишет:
[snip]

Quoted 19 lines
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 914

Quoted 5 lines
sound/soc/tegra/tegra210_i2s.c new file +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 5 lines

It should matter (if I'm not missing something) because RPM should be in a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Quoted 10 lines

Once the driver is re-loaded and RPM is enabled, I don't think it would use the same 'dev' and the corresponding ref count. Doesn't it use the new counters?
If RPM is not working for some reason, most likely it would be the case for other
devices. What best driver can do is probably do a force suspend during removal if
already not done. I would prefer to keep, since multiple drivers still have it,
unless there is a real harm in doing so.

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

+     int rx_fifo_th;

Could rx_fifo_th be negative?

rx_fifo_th itself does not take negative values, explicit typecasting> is avoided in "if" condition by declaring this as "int"

Explicit typecasting isn't needed for integers.

What I meant was, rx_fifo_th is checked against a 'int' variable in an "if" condition.

What's the problem with comparing of unsigned with signed?

Besides, cif_conf.audio_ch > I2S_RX_FIFO_DEPTH can't be ever true, isn't it? I2S_RX_FIFO_DEPTH=64, channels_max=16

Lastly, nothing stops you to make max_th unsigned.

#15 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 33 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

22.01.2020 07:32, Sameer Pujar пишет:
[snip]

Quoted 18 lines
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

sound/soc/tegra/tegra210_i2s.c line 914

Quoted 5 lines
sound/soc/tegra/tegra210_i2s.c new file +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 5 lines

It should matter (if I'm not missing something) because RPM should be in a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Quoted 10 lines

Once the driver is re-loaded and RPM is enabled, I don't think it would use the same 'dev' and the corresponding ref count. Doesn't it use the new counters?
If RPM is not working for some reason, most likely it would be the case for other
devices. What best driver can do is probably do a force suspend during removal if
already not done. I would prefer to keep, since multiple drivers still have it,
unless there is a real harm in doing so.

Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage. I will remove explicit suspend here if no any concerns from other folks. Thanks.

Quoted 9 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

+ int rx_fifo_th;

Could rx_fifo_th be negative?

rx_fifo_th itself does not take negative values, explicit typecasting> is avoided in "if" condition by declaring this as "int"

Explicit typecasting isn't needed for integers.

What I meant was, rx_fifo_th is checked against a 'int' variable in an "if" condition.

What's the problem with comparing of unsigned with signed?

consider this example,
----
unsigned int x = 5;
int y = -1;

(x > y) is false.
----
Hence should be careful while using signed and unsigned comparisons.

Quoted 3 lines

Besides, cif_conf.audio_ch > I2S_RX_FIFO_DEPTH can't be ever true, isn't it? I2S_RX_FIFO_DEPTH=64, channels_max=16

Yes true.

Quoted 1 line

Lastly, nothing stops you to make max_th unsigned.

will update.

maintainer
#16 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

On 22/01/2020 07:16, Sameer Pujar wrote:

...

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 6 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new counters?
If RPM is not working for some reason, most likely it would be the case for other
devices. What best driver can do is probably do a force suspend during removal if
already not done. I would prefer to keep, since multiple drivers still have it,
unless there is a real harm in doing so.

Quoted 7 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage. I will remove explicit suspend here if no any concerns from other folks. Thanks.

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference. I believe that this is meant to ensure that the device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Now for Tegra210 (or actually 64-bit Tegra) RPM is always enabled and so we don't need to worry about the !RPM case. However, I still don't see the harm in this.

Jon

Signature · 1 line
nvpublic
#17 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

22.01.2020 14:52, Jon Hunter пишет:

Quoted 43 lines · Sameer Pujar

...

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 6 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new counters?
If RPM is not working for some reason, most likely it would be the case for other
devices. What best driver can do is probably do a force suspend during removal if
already not done. I would prefer to keep, since multiple drivers still have it,
unless there is a real harm in doing so.

Quoted 7 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage. I will remove explicit suspend here if no any concerns from other folks. Thanks.

Quoted 7 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference.

I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Yes, it was kinda actual for the case of unavailable RPM.

Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev))

	tegra210_i2s_runtime_suspend(&pdev->dev);
else
	pm_runtime_disable(&pdev->dev);
Quoted 3 lines

Now for Tegra210 (or actually 64-bit Tegra) RPM is always enabled and so we don't need to worry about the !RPM case. However, I still don't see the harm in this.

There is no real harm today, but:

1. I'd prefer to be very careful with RPM in general, based on previous experience.

2. It should be a bug if device isn't RPM-suspended during of driver's removal. Thus the real problem needs to be fixed rather than worked around.

#18 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 50 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

22.01.2020 14:52, Jon Hunter пишет:

Quoted 40 lines · Sameer Pujar

...

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 6 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new counters?
If RPM is not working for some reason, most likely it would be the case for other
devices. What best driver can do is probably do a force suspend during removal if
already not done. I would prefer to keep, since multiple drivers still have it,
unless there is a real harm in doing so.

Quoted 6 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage. I will remove explicit suspend here if no any concerns from other folks. Thanks.

Quoted 6 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference.
I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Quoted 8 lines

Yes, it was kinda actual for the case of unavailable RPM.

Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev))

         tegra210_i2s_runtime_suspend(&pdev->dev);
else
         pm_runtime_disable(&pdev->dev);

I think it looks to be similar to what is there already.

pm_runtime_disable(&pdev->dev); // it would turn out to be a dummy call if !RPM if (!pm_runtime_status_suspended(&pdev->dev)) // it is true always if !RPM tegra210_i2s_runtime_suspend(&pdev->dev);

Quoted 11 lines
Quoted 3 lines

Now for Tegra210 (or actually 64-bit Tegra) RPM is always enabled and so we don't need to worry about the !RPM case. However, I still don't see the harm in this.

There is no real harm today, but:

1. I'd prefer to be very careful with RPM in general, based on previous experience.

2. It should be a bug if device isn't RPM-suspended during of driver's removal. Thus the real problem needs to be fixed rather than worked around.

#19 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

23.01.2020 12:22, Sameer Pujar пишет:

Quoted 71 lines · Dmitry Osipenko
Quoted 59 lines

External email: Use caution opening links or attachments

22.01.2020 14:52, Jon Hunter пишет:

Quoted 49 lines · Sameer Pujar

...

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 15 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active
state. This code should be removed. At most you could warn about the
unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 7 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely
that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new
counters?
If RPM is not working for some reason, most likely it would be the case
for other
devices. What best driver can do is probably do a force suspend during
removal if
already not done. I would prefer to keep, since multiple drivers still
have it,
unless there is a real harm in doing so.

Quoted 8 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage.
I will remove explicit suspend here if no any concerns from other folks.
Thanks.

Quoted 6 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference.
I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Quoted 8 lines

Yes, it was kinda actual for the case of unavailable RPM.

Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev)) tegra210_i2s_runtime_suspend(&pdev->dev); else
         pm_runtime_disable(&pdev->dev);

Quoted 6 lines

I think it looks to be similar to what is there already.

pm_runtime_disable(&pdev->dev); // it would turn out to be a dummy call if !RPM
if (!pm_runtime_status_suspended(&pdev->dev)) // it is true always if !RPM tegra210_i2s_runtime_suspend(&pdev->dev);

Maybe this is fine for !RPM, but not really fine in a case of enabled RPM. Device could be in resumed state after pm_runtime_disable() if it wasn't suspended before the disabling.

maintainer
#20 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 74 lines · Dmitry Osipenko

23.01.2020 12:22, Sameer Pujar пишет:

Quoted 73 lines · Dmitry Osipenko
Quoted 59 lines

External email: Use caution opening links or attachments

22.01.2020 14:52, Jon Hunter пишет:

Quoted 49 lines · Sameer Pujar

...

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 15 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active
state. This code should be removed. At most you could warn about the
unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 7 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely
that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new
counters?
If RPM is not working for some reason, most likely it would be the case
for other
devices. What best driver can do is probably do a force suspend during
removal if
already not done. I would prefer to keep, since multiple drivers still
have it,
unless there is a real harm in doing so.

Quoted 8 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage.
I will remove explicit suspend here if no any concerns from other folks.
Thanks.

Quoted 6 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference.
I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Quoted 8 lines

Yes, it was kinda actual for the case of unavailable RPM.

Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev)) tegra210_i2s_runtime_suspend(&pdev->dev); else
         pm_runtime_disable(&pdev->dev);

I think it looks to be similar to what is there already.

Quoted 8 lines
Quoted 4 lines

pm_runtime_disable(&pdev->dev); // it would turn out to be a dummy call if !RPM
if (!pm_runtime_status_suspended(&pdev->dev)) // it is true always if !RPM tegra210_i2s_runtime_suspend(&pdev->dev);

Maybe this is fine for !RPM, but not really fine in a case of enabled RPM. Device could be in resumed state after pm_runtime_disable() if it wasn't suspended before the disabling.

I don't see any problem with this for the !RPM case.

Jon

Signature · 1 line
nvpublic
maintainer
#21 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 81 lines · Jon Hunter
Quoted 79 lines · Dmitry Osipenko

23.01.2020 12:22, Sameer Pujar пишет:

Quoted 77 lines · Dmitry Osipenko
Quoted 59 lines

External email: Use caution opening links or attachments

22.01.2020 14:52, Jon Hunter пишет:

Quoted 49 lines · Sameer Pujar

...

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 15 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active
state. This code should be removed. At most you could warn about the
unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 7 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely
that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new
counters?
If RPM is not working for some reason, most likely it would be the case
for other
devices. What best driver can do is probably do a force suspend during
removal if
already not done. I would prefer to keep, since multiple drivers still
have it,
unless there is a real harm in doing so.

Quoted 8 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage.
I will remove explicit suspend here if no any concerns from other folks.
Thanks.

Quoted 6 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference.
I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Quoted 8 lines

Yes, it was kinda actual for the case of unavailable RPM.

Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev)) tegra210_i2s_runtime_suspend(&pdev->dev); else
         pm_runtime_disable(&pdev->dev);

I think it looks to be similar to what is there already.

pm_runtime_disable(&pdev->dev); // it would turn out to be a dummy call if !RPM
if (!pm_runtime_status_suspended(&pdev->dev)) // it is true always if !RPM tegra210_i2s_runtime_suspend(&pdev->dev);

Quoted 5 lines
Quoted 3 lines

Maybe this is fine for !RPM, but not really fine in a case of enabled RPM. Device could be in resumed state after pm_runtime_disable() if it wasn't suspended before the disabling.

I don't see any problem with this for the !RPM case.

Sorry I meant the RPM case. In other words, I don't see a problem for neither the RPM case of the !RPM case.

Jon

Signature · 1 line
nvpublic
#22 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

24.01.2020 12:51, Jon Hunter пишет:

Quoted 83 lines · Jon Hunter
Quoted 81 lines · Dmitry Osipenko
Quoted 79 lines

23.01.2020 12:22, Sameer Pujar пишет:

Quoted 77 lines · Dmitry Osipenko
Quoted 59 lines

External email: Use caution opening links or attachments

22.01.2020 14:52, Jon Hunter пишет:

Quoted 49 lines · Sameer Pujar

...

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 15 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active
state. This code should be removed. At most you could warn about the
unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 7 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely
that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new
counters?
If RPM is not working for some reason, most likely it would be the case
for other
devices. What best driver can do is probably do a force suspend during
removal if
already not done. I would prefer to keep, since multiple drivers still
have it,
unless there is a real harm in doing so.

Quoted 8 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage.
I will remove explicit suspend here if no any concerns from other folks.
Thanks.

Quoted 6 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference.
I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Quoted 8 lines

Yes, it was kinda actual for the case of unavailable RPM.

Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev)) tegra210_i2s_runtime_suspend(&pdev->dev); else
         pm_runtime_disable(&pdev->dev);

I think it looks to be similar to what is there already.

pm_runtime_disable(&pdev->dev); // it would turn out to be a dummy call if !RPM
if (!pm_runtime_status_suspended(&pdev->dev)) // it is true always if !RPM tegra210_i2s_runtime_suspend(&pdev->dev);

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Maybe this is fine for !RPM, but not really fine in a case of enabled RPM. Device could be in resumed state after pm_runtime_disable() if it wasn't suspended before the disabling.

I don't see any problem with this for the !RPM case.

Sorry I meant the RPM case. In other words, I don't see a problem for neither the RPM case of the !RPM case.

1. Device shall be in RPM-suspended state at the time of driver's removal, unless there is a bug in the sound driver. Hence why do you need the dead code which doesn't bring any practical value?

2. Making changes underneath of RPM is simply error-prone. It may hit badly in the future once something will change in the RPM core.

#23 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 85 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

24.01.2020 12:51, Jon Hunter пишет:

Quoted 81 lines · Jon Hunter
Quoted 80 lines · Dmitry Osipenko
Quoted 71 lines

23.01.2020 12:22, Sameer Pujar пишет:

Quoted 70 lines · Dmitry Osipenko
Quoted 59 lines

External email: Use caution opening links or attachments

22.01.2020 14:52, Jon Hunter пишет:

Quoted 49 lines · Sameer Pujar

...

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 15 lines
Quoted 10 lines
Quoted 10 lines

+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+ pm_runtime_disable(&pdev->dev);
+ if (!pm_runtime_status_suspended(&pdev->dev))
+ tegra210_i2s_runtime_suspend(&pdev->dev);
This breaks device's RPM refcounting if it was disabled in the
active
state. This code should be removed. At most you could warn
about the
unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 7 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely
that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new
counters?
If RPM is not working for some reason, most likely it would be the case
for other
devices. What best driver can do is probably do a force suspend during
removal if
already not done. I would prefer to keep, since multiple drivers still
have it,
unless there is a real harm in doing so.

Quoted 8 lines
Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage.
I will remove explicit suspend here if no any concerns from other folks.
Thanks.

Quoted 6 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to this as a reference.
I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and what the current state is.

Quoted 7 lines

Yes, it was kinda actual for the case of unavailable RPM. Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev))

          tegra210_i2s_runtime_suspend(&pdev->dev);
else
          pm_runtime_disable(&pdev->dev);

I think it looks to be similar to what is there already.

Quoted 7 lines
Quoted 4 lines

pm_runtime_disable(&pdev->dev); // it would turn out to be a dummy call if !RPM
if (!pm_runtime_status_suspended(&pdev->dev)) // it is true always if !RPM

         tegra210_i2s_runtime_suspend(&pdev->dev);

Maybe this is fine for !RPM, but not really fine in a case of enabled RPM. Device could be in resumed state after pm_runtime_disable() if it wasn't suspended before the disabling.

I don't see any problem with this for the !RPM case.

Quoted 8 lines
Quoted 2 lines

Sorry I meant the RPM case. In other words, I don't see a problem for neither the RPM case of the !RPM case.

1. Device shall be in RPM-suspended state at the time of driver's removal, unless there is a bug in the sound driver. Hence why do you need the dead code which doesn't bring any practical value?

2. Making changes underneath of RPM is simply error-prone. It may hit badly in the future once something will change in the RPM core.

I think we are stretching a bit more here when there is no any real harm. Right now it works well for both RPM and !RPM case and if we really need to fix something in future we can fix. Since my initial inclination was keeping the code as it is and Jon also has similar thoughts, I would retain this code. Sorry Dmitry, we can fix if something comes up and many other drivers would need this at that time.

#24 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

27.01.2020 08:22, Sameer Pujar пишет:

Quoted 112 lines · Dmitry Osipenko
Quoted 100 lines

External email: Use caution opening links or attachments

24.01.2020 12:51, Jon Hunter пишет:

Quoted 96 lines · Jon Hunter
Quoted 95 lines · Dmitry Osipenko
Quoted 90 lines

23.01.2020 12:22, Sameer Pujar пишет:

Quoted 81 lines · Dmitry Osipenko
Quoted 71 lines

External email: Use caution opening links or attachments

22.01.2020 14:52, Jon Hunter пишет:

Quoted 59 lines · Sameer Pujar

...

Quoted 50 lines
Quoted 45 lines
Quoted 37 lines
Quoted 19 lines
Quoted 19 lines

+static int tegra210_i2s_remove(struct platform_device
*pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);
This breaks device's RPM refcounting if it was disabled in
the
active
state. This code should be removed. At most you could warn
about the
unxpected RPM state here, but it shouldn't be necessary.
I guess this was added for safety and explicit suspend
keeps clock
disabled.
Not sure if ref-counting of the device matters when runtime
PM is
disabled and device is removed.
I see few drivers using this way.

Quoted 8 lines

It should matter (if I'm not missing something) because RPM should
be in
a wrecked state once you'll try to re-load the driver's module. Likely
that those few other drivers are wrong.

[snip]

Once the driver is re-loaded and RPM is enabled, I don't think it
would use
the same 'dev' and the corresponding ref count. Doesn't it use the
new
counters?
If RPM is not working for some reason, most likely it would be the
case

Quoted 8 lines

for other
devices. What best driver can do is probably do a force suspend during
removal if
already not done. I would prefer to keep, since multiple drivers still
have it,
unless there is a real harm in doing so.

Quoted 5 lines

I took a closer look and looks like the counter actually should be
reset. Still I don't think that it's a good practice to make changes
underneath of RPM, it may strike back.

Quoted 5 lines

If RPM is broken, it probably would have been caught during device usage.
I will remove explicit suspend here if no any concerns from other folks.
Thanks.

Quoted 8 lines

I recall that this was the preferred way of doing this from the RPM folks. Tegra30 I2S driver does the same and Stephen had pointed me to
this as a reference.
I believe that this is meant to ensure that the
device is always powered-off regardless of it RPM is enabled or not and
what the current state is.

Quoted 8 lines

Yes, it was kinda actual for the case of unavailable RPM. Anyways, /I think/ variant like this should have been more preferred:

if (!pm_runtime_enabled(&pdev->dev)) tegra210_i2s_runtime_suspend(&pdev->dev); else
          pm_runtime_disable(&pdev->dev);

Quoted 8 lines

I think it looks to be similar to what is there already.

pm_runtime_disable(&pdev->dev); // it would turn out to be a dummy call
if !RPM
if (!pm_runtime_status_suspended(&pdev->dev)) // it is true always if !RPM
         tegra210_i2s_runtime_suspend(&pdev->dev);

Quoted 3 lines

Maybe this is fine for !RPM, but not really fine in a case of enabled RPM. Device could be in resumed state after pm_runtime_disable() if it wasn't suspended before the disabling.

I don't see any problem with this for the !RPM case.

Quoted 8 lines
Quoted 2 lines

Sorry I meant the RPM case. In other words, I don't see a problem for neither the RPM case of the !RPM case.

1. Device shall be in RPM-suspended state at the time of driver's removal, unless there is a bug in the sound driver. Hence why do you need the dead code which doesn't bring any practical value?

2. Making changes underneath of RPM is simply error-prone. It may hit badly in the future once something will change in the RPM core.

Quoted 8 lines

I think we are stretching a bit more here when there is no any real harm. Right now it works well for both RPM and !RPM case and if we really need to fix something in future we can fix. Since my initial inclination was keeping
the code as it is and Jon also has similar thoughts, I would retain this code.
Sorry Dmitry, we can fix if something comes up and many other drivers would need this at that time.

The !RPM case isn't supported by Tegra anymore in upstream kernel. I'm trying to help to make yours driver better and gave you reasons to remove the unneeded code, while you're keep saying that "there is no harm to retain it", which is not a reason to clutter up the code. I don't feel that it's worthwhile to continue arguing here.

maintainer
#25 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

On 29/01/2020 03:41, Dmitry Osipenko wrote:

...

Quoted 5 lines

The !RPM case isn't supported by Tegra anymore in upstream kernel. I'm trying to help to make yours driver better and gave you reasons to remove the unneeded code, while you're keep saying that "there is no harm to retain it", which is not a reason to clutter up the code. I don't feel that it's worthwhile to continue arguing here.

On further review, it does look like a reasonable argument to get rid of this now completely. Like you see less clutter and the soc-core should ensure that the card is shutdown before unloading. OK, so fine with me.

Jon

Signature · 1 line
nvpublic
#26 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

14.02.2020 17:05, Jon Hunter пишет:

Quoted 11 lines · Dmitry Osipenko

...

Quoted 5 lines

The !RPM case isn't supported by Tegra anymore in upstream kernel. I'm trying to help to make yours driver better and gave you reasons to remove the unneeded code, while you're keep saying that "there is no harm to retain it", which is not a reason to clutter up the code. I don't feel that it's worthwhile to continue arguing here.

Quoted 3 lines

On further review, it does look like a reasonable argument to get rid of this now completely. Like you see less clutter and the soc-core should ensure that the card is shutdown before unloading. OK, so fine with me.

And the RPM core ensures that state is synced on disable, sorry if I didn't make it clear before.

+1 for less clutter :)

#27 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

Quoted 13 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

14.02.2020 17:05, Jon Hunter пишет:

Quoted 9 lines · Dmitry Osipenko

...

Quoted 5 lines

The !RPM case isn't supported by Tegra anymore in upstream kernel. I'm trying to help to make yours driver better and gave you reasons to remove the unneeded code, while you're keep saying that "there is no harm to retain it", which is not a reason to clutter up the code. I don't feel that it's worthwhile to continue arguing here.

Quoted 7 lines
Quoted 3 lines

On further review, it does look like a reasonable argument to get rid of this now completely. Like you see less clutter and the soc-core should ensure that the card is shutdown before unloading. OK, so fine with me.

And the RPM core ensures that state is synced on disable, sorry if I didn't make it clear before.

+1 for less clutter :)

Done, I am removing explicit RPM suspend in the next revision. Thanks Dmitry and Jon.

#28 lore raw

Re: [alsa-devel] [PATCH 4/9] ASoC: tegra: add Tegra210 based I2S driver

In reply to Sameer Pujar

22.01.2020 10:16, Sameer Pujar пишет:

Quoted 53 lines · Dmitry Osipenko
Quoted 35 lines

External email: Use caution opening links or attachments

22.01.2020 07:32, Sameer Pujar пишет:
[snip]

Quoted 19 lines
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static int tegra210_i2s_remove(struct platform_device *pdev)
+{
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             tegra210_i2s_runtime_suspend(&pdev->dev);

This breaks device's RPM refcounting if it was disabled in the active state. This code should be removed. At most you could warn about the unxpected RPM state here, but it shouldn't be necessary.

Quoted 5 lines

I guess this was added for safety and explicit suspend keeps clock disabled.
Not sure if ref-counting of the device matters when runtime PM is disabled and device is removed.
I see few drivers using this way.

Quoted 6 lines

It should matter (if I'm not missing something) because RPM should be in
a wrecked state once you'll try to re-load the driver's module. Likely that those few other drivers are wrong.

[snip]

Quoted 11 lines

Once the driver is re-loaded and RPM is enabled, I don't think it would use
the same 'dev' and the corresponding ref count. Doesn't it use the new counters?
If RPM is not working for some reason, most likely it would be the case for other
devices. What best driver can do is probably do a force suspend during removal if
already not done. I would prefer to keep, since multiple drivers still have it,
unless there is a real harm in doing so.

Quoted 3 lines

I took a closer look and looks like the counter actually should be reset. Still I don't think that it's a good practice to make changes underneath of RPM, it may strike back.

If RPM is broken, it probably would have been caught during device usage. I will remove explicit suspend here if no any concerns from other folks. Thanks.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

+     int rx_fifo_th;

Could rx_fifo_th be negative?

rx_fifo_th itself does not take negative values, explicit typecasting> is avoided in "if" condition by declaring this as "int"

Explicit typecasting isn't needed for integers.

What I meant was, rx_fifo_th is checked against a 'int' variable in an "if" condition.

Quoted 8 lines
Quoted 1 line

What's the problem with comparing of unsigned with signed?

consider this example,
----
unsigned int x = 5;
int y = -1;

(x > y) is false.

Right

Quoted 11 lines

----
Hence should be careful while using signed and unsigned comparisons.

Quoted 3 lines

Besides, cif_conf.audio_ch > I2S_RX_FIFO_DEPTH can't be ever true, isn't it? I2S_RX_FIFO_DEPTH=64, channels_max=16

Yes true.

Quoted 1 line

Lastly, nothing stops you to make max_th unsigned.

will update.

Thanks

#29 lore raw

PATCH 5/9 ASoC: tegra: add Tegra210 based AHUB driver

In reply to Sameer Pujar

The Audio Hub (AHUB) comprises a collection of hardware accelerators for audio pre/post-processing and a programmable full crossbar (XBAR) for routing audio data across these accelerators in time and in parallel. AHUB supports multiple interfaces to I2S, DSPK, DMIC etc., XBAR is a switch used to configure or modify audio routing between HW accelerators present inside AHUB.

This patch registers AHUB component with ASoC framework. The component driver exposes DAPM widgets, routes and kcontrols for the device. The DAI driver exposes AHUB interfaces, which can be used to connect different components in the ASoC layer. Currently the driver takes care of XBAR programming to allow audio data flow through various clients of the AHUB. Makefile and Kconfig support is added to allow to build the driver. The AHUB component can be enabled in the DT via "nvidia,tegra210-ahub" compatible binding.

---
 sound/soc/tegra/Kconfig         |  10 +
 sound/soc/tegra/Makefile        |   2 +
 sound/soc/tegra/tegra210_ahub.c | 667 ++++++++++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra210_ahub.h | 125 ++++++++
 4 files changed, 804 insertions(+)
 create mode 100644 sound/soc/tegra/tegra210_ahub.c
 create mode 100644 sound/soc/tegra/tegra210_ahub.h
sound/soc/tegra/Kconfig +10 -0
index 157fa7a..0c07f63 100644
@@ -62,6 +62,16 @@ config SND_SOC_TEGRA30_I2S
 	  Tegra30 I2S interface. You will also need to select the individual
 	  machine drivers to support below.
 
+config SND_SOC_TEGRA210_AHUB
+        tristate "Tegra210 AHUB module"
+        depends on SND_SOC_TEGRA
+        help
+	  Config to enable Audio Hub (AHUB) module, which comprises of a
+	  switch called Audio Crossbar (AXBAR) used to configure or modify
+	  the audio routing path between various HW accelerators present in
+	  AHUB.
+          Say Y or M if you want to add support for Tegra210 AHUB module.
+
 config SND_SOC_TEGRA210_DMIC
         tristate "Tegra210 DMIC module"
         depends on SND_SOC_TEGRA
sound/soc/tegra/Makefile +2 -0
index 1c4457d..5283d47 100644
@@ -9,6 +9,7 @@ snd-soc-tegra20-spdif-objs := tegra20_spdif.o
 snd-soc-tegra30-ahub-objs := tegra30_ahub.o
 snd-soc-tegra30-i2s-objs := tegra30_i2s.o
 snd-soc-tegra-cif-objs := tegra_cif.o
+snd-soc-tegra210-ahub-objs := tegra210_ahub.o
 snd-soc-tegra210-dmic-objs := tegra210_dmic.o
 snd-soc-tegra210-i2s-objs := tegra210_i2s.o
 
@@ -22,6 +23,7 @@ obj-$(CONFIG_SND_SOC_TEGRA20_SPDIF) += snd-soc-tegra20-spdif.o
 obj-$(CONFIG_SND_SOC_TEGRA30_AHUB) += snd-soc-tegra30-ahub.o
 obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 obj-$(CONFIG_SND_SOC_TEGRA210_DMIC) += snd-soc-tegra210-dmic.o
+obj-$(CONFIG_SND_SOC_TEGRA210_AHUB) += snd-soc-tegra210-ahub.o
 obj-$(CONFIG_SND_SOC_TEGRA210_I2S) += snd-soc-tegra210-i2s.o
 
 # Tegra machine Support
sound/soc/tegra/tegra210_ahub.c new file +667 -0

667 lines not on this page · raw message

sound/soc/tegra/tegra210_ahub.h new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.7.4
#30 lore raw

Re: [alsa-devel] [PATCH 5/9] ASoC: tegra: add Tegra210 based AHUB driver

20.01.2020 17:23, Sameer Pujar пишет:
[snip]

Quoted 12 lines
sound/soc/tegra/tegra210_ahub.c new file +12 -0
+static int tegra_ahub_get_value_enum(struct snd_kcontrol *kctl,
+				     struct snd_ctl_elem_value *uctl)
+{
+	struct snd_soc_component *cmpnt = snd_soc_dapm_kcontrol_component(kctl);
+	struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt);
+	struct soc_enum *e = (struct soc_enum *)kctl->private_value;
+	unsigned int reg, i, bit_pos = 0;
+
+	/*
+	 * Find the bit position of current MUX input.
+	 * If nothing is set, position would be 0 and it corresponds to 'None'.
+	 */

sound/soc/tegra/tegra210_ahub.c line 42

Quoted 10 lines
sound/soc/tegra/tegra210_ahub.c new file +10 -0
+	for (i = 0; i < ahub->soc_data->reg_count; i++) {
+		unsigned int reg_val;
+
+		reg = e->reg + (TEGRA210_XBAR_PART1_RX * i);
+		snd_soc_component_read(cmpnt, reg, &reg_val);
+		reg_val &= ahub->soc_data->mask[i];
+
+		if (reg_val) {
+			bit_pos = ffs(reg_val) +
+				  (8 * cmpnt->val_bytes * i);

Multiplication takes precedence, braces are not needed. Same for all other occurrences in the code.

[snip]

Quoted 13 lines
sound/soc/tegra/tegra210_ahub.c new file +13 -0
+			break;
+		}
+	}
+
+	/* Find index related to the item in array *_ahub_mux_texts[] */
+	for (i = 0; i < e->items; i++) {
+		if (bit_pos == e->values[i]) {
+			uctl->value.enumerated.item[0] = i;
+			break;
+		}
+	}
+
+	return 0;

sound/soc/tegra/tegra210_ahub.c line 65

Quoted 10 lines
sound/soc/tegra/tegra210_ahub.c new file +10 -0
+}
+
+static int tegra_ahub_put_value_enum(struct snd_kcontrol *kctl,
+				     struct snd_ctl_elem_value *uctl)
+{
+	struct snd_soc_component *cmpnt = snd_soc_dapm_kcontrol_component(kctl);
+	struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt);
+	struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kctl);
+	struct soc_enum *e = (struct soc_enum *)kctl->private_value;
+	struct snd_soc_dapm_update update[TEGRA_XBAR_UPDATE_MAX_REG] = { };

Shouldn't this be {0} to make array zero'ed?

[snip]

Quoted 6 lines
sound/soc/tegra/tegra210_ahub.c new file +6 -0
+static int tegra_ahub_probe(struct platform_device *pdev)
+{
+	const struct of_device_id *match;
+	struct tegra_ahub *ahub;
+	struct tegra_ahub_soc_data *soc_data;
+	void __iomem *regs;

sound/soc/tegra/tegra210_ahub.c line 587

Quoted 10 lines
sound/soc/tegra/tegra210_ahub.c new file +10 -0
+	struct resource *res;
+	int ret;
+
+	match = of_match_device(tegra_ahub_of_match, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "error: no device match found\n");
+		return -ENODEV;
+	}
+
+	soc_data = (struct tegra_ahub_soc_data *)match->data;

soc_data = device_get_match_data(&pdev->dev);

Quoted 9 lines
sound/soc/tegra/tegra210_ahub.c new file +9 -0
+	ahub = devm_kcalloc(&pdev->dev, 1, sizeof(*ahub), GFP_KERNEL);
+	if (!ahub)
+		return -ENOMEM;
+
+	ahub->soc_data = soc_data;
+
+	platform_set_drvdata(pdev, ahub);
+
+	ahub->clk = devm_clk_get(&pdev->dev, "ahub");

sound/soc/tegra/tegra210_ahub.c line 607

Quoted 10 lines
sound/soc/tegra/tegra210_ahub.c new file +10 -0
+	if (IS_ERR(ahub->clk)) {
+		dev_err(&pdev->dev, "can't retrieve AHUB clock\n");
+		return PTR_ERR(ahub->clk);
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+	regs = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(regs))
+		return PTR_ERR(regs);

regs = devm_platform_ioremap_resource(pdev, 0);

#31 lore raw

Re: [alsa-devel] [PATCH 5/9] ASoC: tegra: add Tegra210 based AHUB driver

Quoted 47 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

20.01.2020 17:23, Sameer Pujar пишет:
[snip]

Quoted 12 lines
sound/soc/tegra/tegra210_ahub.c new file +12 -0
+static int tegra_ahub_get_value_enum(struct snd_kcontrol *kctl,
+                                  struct snd_ctl_elem_value *uctl)
+{
+     struct snd_soc_component *cmpnt = snd_soc_dapm_kcontrol_component(kctl);
+     struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt);
+     struct soc_enum *e = (struct soc_enum *)kctl->private_value;
+     unsigned int reg, i, bit_pos = 0;
+
+     /*
+      * Find the bit position of current MUX input.
+      * If nothing is set, position would be 0 and it corresponds to 'None'.
+      */

sound/soc/tegra/tegra210_ahub.c line 42

Quoted 10 lines
sound/soc/tegra/tegra210_ahub.c new file +10 -0
+     for (i = 0; i < ahub->soc_data->reg_count; i++) {
+             unsigned int reg_val;
+
+             reg = e->reg + (TEGRA210_XBAR_PART1_RX * i);
+             snd_soc_component_read(cmpnt, reg, &reg_val);
+             reg_val &= ahub->soc_data->mask[i];
+
+             if (reg_val) {
+                     bit_pos = ffs(reg_val) +
+                               (8 * cmpnt->val_bytes * i);

Multiplication takes precedence, braces are not needed. Same for all other occurrences in the code.

[snip]

Quoted 16 lines
sound/soc/tegra/tegra210_ahub.c new file +16 -0
+                     break;
+             }
+     }
+
+     /* Find index related to the item in array *_ahub_mux_texts[] */
+     for (i = 0; i < e->items; i++) {
+             if (bit_pos == e->values[i]) {
+                     uctl->value.enumerated.item[0] = i;
+                     break;
+             }
+     }
+
+     return 0;
+}
+
+static int tegra_ahub_put_value_enum(struct snd_kcontrol *kctl,
Quoted 8 lines

sound/soc/tegra/tegra210_ahub.c line 65

Quoted 7 lines
sound/soc/tegra/tegra210_ahub.c new file +7 -0
+                                  struct snd_ctl_elem_value *uctl)
+{
+     struct snd_soc_component *cmpnt = snd_soc_dapm_kcontrol_component(kctl);
+     struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt);
+     struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kctl);
+     struct soc_enum *e = (struct soc_enum *)kctl->private_value;
+     struct snd_soc_dapm_update update[TEGRA_XBAR_UPDATE_MAX_REG] = { };

Shouldn't this be {0} to make array zero'ed?

Isn't it the same with empty braces?

Quoted 11 lines

[snip]

Quoted 9 lines
sound/soc/tegra/tegra210_ahub.c new file +9 -0
+static int tegra_ahub_probe(struct platform_device *pdev)
+{
+     const struct of_device_id *match;
+     struct tegra_ahub *ahub;
+     struct tegra_ahub_soc_data *soc_data;
+     void __iomem *regs;
+     struct resource *res;
+     int ret;
+
Quoted 8 lines

sound/soc/tegra/tegra210_ahub.c line 587

Quoted 7 lines
sound/soc/tegra/tegra210_ahub.c new file +7 -0
+     match = of_match_device(tegra_ahub_of_match, &pdev->dev);
+     if (!match) {
+             dev_err(&pdev->dev, "error: no device match found\n");
+             return -ENODEV;
+     }
+
+     soc_data = (struct tegra_ahub_soc_data *)match->data;

soc_data = device_get_match_data(&pdev->dev);

will update

Quoted 12 lines
Quoted 12 lines
sound/soc/tegra/tegra210_ahub.c new file +12 -0
+     ahub = devm_kcalloc(&pdev->dev, 1, sizeof(*ahub), GFP_KERNEL);
+     if (!ahub)
+             return -ENOMEM;
+
+     ahub->soc_data = soc_data;
+
+     platform_set_drvdata(pdev, ahub);
+
+     ahub->clk = devm_clk_get(&pdev->dev, "ahub");
+     if (IS_ERR(ahub->clk)) {
+             dev_err(&pdev->dev, "can't retrieve AHUB clock\n");
+             return PTR_ERR(ahub->clk);
Quoted 8 lines

sound/soc/tegra/tegra210_ahub.c line 607

Quoted 7 lines
sound/soc/tegra/tegra210_ahub.c new file +7 -0
+     }
+
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+     regs = devm_ioremap_resource(&pdev->dev, res);
+     if (IS_ERR(regs))
+             return PTR_ERR(regs);

regs = devm_platform_ioremap_resource(pdev, 0);

will update

#32 lore raw

Re: [alsa-devel] [PATCH 5/9] ASoC: tegra: add Tegra210 based AHUB driver

24.01.2020 06:39, Sameer Pujar пишет:

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/tegra/tegra210_ahub.c new file +4 -0
+static int tegra_ahub_put_value_enum(struct snd_kcontrol *kctl,
+                                  struct snd_ctl_elem_value *uctl)
+{
+     struct snd_soc_component *cmpnt =
Quoted 8 lines
Quoted 7 lines

snd_soc_dapm_kcontrol_component(kctl);
+     struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt); +     struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kctl);
+     struct soc_enum *e = (struct soc_enum *)kctl->private_value; +     struct snd_soc_dapm_update update[TEGRA_XBAR_UPDATE_MAX_REG] = { };

Shouldn't this be {0} to make array zero'ed?

Quoted 1 line

Isn't it the same with empty braces?

Looks like is should be the same because turns out GCC has an extension for that.

maintainer
#33 lore raw

Re: [alsa-devel] [PATCH 5/9] ASoC: tegra: add Tegra210 based AHUB driver

In reply to Dmitry Osipenko
Quoted 19 lines · Dmitry Osipenko

20.01.2020 17:23, Sameer Pujar пишет:
[snip]

Quoted 17 lines
sound/soc/tegra/tegra210_ahub.c new file +17 -0
+static int tegra_ahub_get_value_enum(struct snd_kcontrol *kctl,
+				     struct snd_ctl_elem_value *uctl)
+{
+	struct snd_soc_component *cmpnt = snd_soc_dapm_kcontrol_component(kctl);
+	struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt);
+	struct soc_enum *e = (struct soc_enum *)kctl->private_value;
+	unsigned int reg, i, bit_pos = 0;
+
+	/*
+	 * Find the bit position of current MUX input.
+	 * If nothing is set, position would be 0 and it corresponds to 'None'.
+	 */
+	for (i = 0; i < ahub->soc_data->reg_count; i++) {
+		unsigned int reg_val;
+
+		reg = e->reg + (TEGRA210_XBAR_PART1_RX * i);
+		snd_soc_component_read(cmpnt, reg, &reg_val);
Quoted 8 lines

sound/soc/tegra/tegra210_ahub.c line 42

Quoted 5 lines
sound/soc/tegra/tegra210_ahub.c new file +5 -0
+		reg_val &= ahub->soc_data->mask[i];
+
+		if (reg_val) {
+			bit_pos = ffs(reg_val) +
+				  (8 * cmpnt->val_bytes * i);

Multiplication takes precedence, braces are not needed. Same for all other occurrences in the code.

Personally, I prefer the above as it is explicit and helps readability.

Jon

Signature · 1 line
nvpublic
#34 lore raw

PATCH 6/9 ASoC: tegra: add Tegra186 based DSPK driver

In reply to Sameer Pujar

The Digital Speaker Controller (DSPK) converts the multi-bit Pulse Code Modulation (PCM) audio input to oversampled 1-bit Pulse Density Modulation (PDM) output. From the signal flow perpsective, the DSPK can be viewed as a PDM transmitter that up-samples the input to the desired sampling rate by interpolation then converts the oversampled PCM input to the desired 1-bit output via Delta Sigma Modulation (DSM).

This patch registers DSPK component with ASoC framework. The component driver exposes DAPM widgets, routes and kcontrols for the device. The DAI driver exposes DSPK interfaces, which can be used to connect different components in the ASoC layer. Makefile and Kconfig support is added to allow to build the driver. The DSPK devices can be enabled in the DT via "nvidia,tegra186-dspk" compatible binding. This driver can be used on Tegra194 chip as well.

---
 sound/soc/tegra/Kconfig         |  13 +
 sound/soc/tegra/Makefile        |   2 +
 sound/soc/tegra/tegra186_dspk.c | 516 ++++++++++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra186_dspk.h |  73 ++++++
 4 files changed, 604 insertions(+)
 create mode 100644 sound/soc/tegra/tegra186_dspk.c
 create mode 100644 sound/soc/tegra/tegra186_dspk.h
sound/soc/tegra/Kconfig +13 -0
index 0c07f63..fb77df3 100644
@@ -93,6 +93,19 @@ config SND_SOC_TEGRA210_I2S
           compatible devices.
           Say Y or M if you want to add support for Tegra210 I2S module.
 
+config SND_SOC_TEGRA186_DSPK
+        tristate "Tegra186 DSPK module"
+        depends on SND_SOC_TEGRA
+        help
+          Config to enable the Digital Speaker Controller (DSPK) which
+          converts the multi-bit Pulse Code Modulation (PCM) audio input to
+          oversampled 1-bit Pulse Desnity Modulation (PDM) output. From the
+          signal flow perspective DSPK can be viewed as a PDM transmitter
+          that up-samples the input to the desired sampling rate by
+          interpolation and then converts the oversampled PCM input to
+          the desired 1-bit output via Delta Sigma Modulation (DSM).
+          Say Y or M if you want to add support for Tegra186 DSPK module.
+
 config SND_SOC_TEGRA_RT5640
 	tristate "SoC Audio support for Tegra boards using an RT5640 codec"
 	depends on SND_SOC_TEGRA && I2C && GPIOLIB
sound/soc/tegra/Makefile +2 -0
index 5283d47..7ad8169 100644
@@ -12,6 +12,7 @@ snd-soc-tegra-cif-objs := tegra_cif.o
 snd-soc-tegra210-ahub-objs := tegra210_ahub.o
 snd-soc-tegra210-dmic-objs := tegra210_dmic.o
 snd-soc-tegra210-i2s-objs := tegra210_i2s.o
+snd-soc-tegra186-dspk-objs := tegra186_dspk.o
 
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
@@ -25,6 +26,7 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
 obj-$(CONFIG_SND_SOC_TEGRA210_DMIC) += snd-soc-tegra210-dmic.o
 obj-$(CONFIG_SND_SOC_TEGRA210_AHUB) += snd-soc-tegra210-ahub.o
 obj-$(CONFIG_SND_SOC_TEGRA210_I2S) += snd-soc-tegra210-i2s.o
+obj-$(CONFIG_SND_SOC_TEGRA186_DSPK) += snd-soc-tegra186-dspk.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
sound/soc/tegra/tegra186_dspk.c new file +516 -0

516 lines not on this page · raw message

sound/soc/tegra/tegra186_dspk.h new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.7.4
#35 lore raw

PATCH 7/9 ASoC: tegra: add Tegra210 based ADMAIF driver

In reply to Sameer Pujar

ADMAIF is the interface between ADMA and AHUB. Each ADMA channel that sends/receives data to/from AHUB must intreface through an ADMAIF channel. ADMA channel sending data to AHUB pairs with an ADMAIF Tx channel and similarly ADMA channel receiving data from AHUB pairs with an ADMAIF Rx channel. Buffer size is configuranle for each ADMAIF channel, but currently SW uses default values.

This patch registers ADMAIF driver with ASoC framework. The component driver exposes DAPM widgets, routes and kcontrols for the device. The DAI driver exposes ADMAIF interfaces, which can be used to connect different components in the ASoC layer. Makefile and Kconfig support is added to allow to build the driver. The ADMAIF device can be enabled in the DT via "nvidia,tegra210-admaif" compatible binding.

Tegra PCM driver is updated to expose required PCM interfaces and snd_pcm_ops callbacks.

---
 sound/soc/tegra/Kconfig           |  12 +
 sound/soc/tegra/Makefile          |   2 +
 sound/soc/tegra/tegra210_admaif.c | 896 ++++++++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra210_admaif.h | 164 +++++++
 sound/soc/tegra/tegra_pcm.c       | 224 +++++++++-
 sound/soc/tegra/tegra_pcm.h       |  23 +-
 6 files changed, 1319 insertions(+), 2 deletions(-)
 create mode 100644 sound/soc/tegra/tegra210_admaif.c
 create mode 100644 sound/soc/tegra/tegra210_admaif.h
sound/soc/tegra/Kconfig +12 -0
index fb77df3..c0a5f0b 100644
@@ -106,6 +106,18 @@ config SND_SOC_TEGRA186_DSPK
           the desired 1-bit output via Delta Sigma Modulation (DSM).
           Say Y or M if you want to add support for Tegra186 DSPK module.
 
+config SND_SOC_TEGRA210_ADMAIF
+        tristate "Tegra210 ADMAIF module"
+        depends on SND_SOC_TEGRA
+        help
+          Config to enable ADMAIF which is the interface between ADMA and
+          Audio Hub (AHUB). Each ADMA channel that sends/receives data to/
+          from AHUB must interface through an ADMAIF channel. ADMA channel
+          sending data to AHUB pairs with an ADMAIF Tx channel, where as
+          ADMA channel receiving data from AHUB pairs with an ADMAIF Rx
+          channel. Buffer size is confiigurable for each ADMAIIF channel.
+          Say Y or M if you want to add support for Tegra210 ADMAIF module.
+
 config SND_SOC_TEGRA_RT5640
 	tristate "SoC Audio support for Tegra boards using an RT5640 codec"
 	depends on SND_SOC_TEGRA && I2C && GPIOLIB
sound/soc/tegra/Makefile +2 -0
index 7ad8169..1033464 100644
@@ -13,6 +13,7 @@ snd-soc-tegra210-ahub-objs := tegra210_ahub.o
 snd-soc-tegra210-dmic-objs := tegra210_dmic.o
 snd-soc-tegra210-i2s-objs := tegra210_i2s.o
 snd-soc-tegra186-dspk-objs := tegra186_dspk.o
+snd-soc-tegra210-admaif-objs := tegra210_admaif.o
 
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-pcm.o
 obj-$(CONFIG_SND_SOC_TEGRA) += snd-soc-tegra-utils.o
@@ -27,6 +28,7 @@ obj-$(CONFIG_SND_SOC_TEGRA210_DMIC) += snd-soc-tegra210-dmic.o
 obj-$(CONFIG_SND_SOC_TEGRA210_AHUB) += snd-soc-tegra210-ahub.o
 obj-$(CONFIG_SND_SOC_TEGRA210_I2S) += snd-soc-tegra210-i2s.o
 obj-$(CONFIG_SND_SOC_TEGRA186_DSPK) += snd-soc-tegra186-dspk.o
+obj-$(CONFIG_SND_SOC_TEGRA210_ADMAIF) += snd-soc-tegra210-admaif.o
 
 # Tegra machine Support
 snd-soc-tegra-rt5640-objs := tegra_rt5640.o
sound/soc/tegra/tegra210_admaif.c new file +896 -0

896 lines not on this page · raw message

sound/soc/tegra/tegra210_admaif.h new file +164 -0

164 lines not on this page · raw message

sound/soc/tegra/tegra_pcm.c +223 -1

241 lines not on this page · raw message

sound/soc/tegra/tegra_pcm.h +22 -1
index 0433372..fe138a4 100644
@@ -17,8 +17,29 @@
 #ifndef __TEGRA_PCM_H__
 #define __TEGRA_PCM_H__
 
-struct snd_dmaengine_pcm_config;
+#include <sound/dmaengine_pcm.h>
+#include <sound/asound.h>
 
+int tegra_pcm_construct(struct snd_soc_component *component,
+			struct snd_soc_pcm_runtime *rtd);
+void tegra_pcm_destruct(struct snd_soc_component *component,
+			struct snd_pcm *pcm);
+int tegra_pcm_open(struct snd_soc_component *component,
+		   struct snd_pcm_substream *substream);
+int tegra_pcm_close(struct snd_soc_component *component,
+		    struct snd_pcm_substream *substream);
+int tegra_pcm_hw_params(struct snd_soc_component *component,
+			struct snd_pcm_substream *substream,
+			struct snd_pcm_hw_params *params);
+int tegra_pcm_hw_free(struct snd_soc_component *component,
+		      struct snd_pcm_substream *substream);
+int tegra_pcm_mmap(struct snd_soc_component *component,
+		   struct snd_pcm_substream *substream,
+		   struct vm_area_struct *vma);
+int tegra_pcm_trigger(struct snd_soc_component *component,
+		      struct snd_pcm_substream *substream, int cmd);
+snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component,
+				    struct snd_pcm_substream *substream);
 int tegra_pcm_platform_register(struct device *dev);
 int tegra_pcm_platform_register_with_chan_names(struct device *dev,
 				struct snd_dmaengine_pcm_config *config,
Signature · 1 line
2.7.4
#36 lore raw

Re: [alsa-devel] [PATCH 7/9] ASoC: tegra: add Tegra210 based ADMAIF driver

20.01.2020 17:23, Sameer Pujar пишет:
[snip]

sound/soc/tegra/tegra210_admaif.c line 96

Quoted 13 lines
sound/soc/tegra/tegra210_admaif.c new file +13 -0
+static bool tegra_admaif_wr_reg(struct device *dev, unsigned int reg)
+{
+	struct tegra_admaif *admaif = dev_get_drvdata(dev);
+	unsigned int ch_stride = TEGRA_ADMAIF_CHANNEL_REG_STRIDE;
+	unsigned int num_ch = admaif->soc_data->num_ch;
+	unsigned int rx_base = admaif->soc_data->rx_base;
+	unsigned int tx_base = admaif->soc_data->tx_base;
+	unsigned int global_base = admaif->soc_data->global_base;
+	unsigned int reg_max = admaif->soc_data->regmap_conf->max_register;
+	unsigned int rx_max = rx_base + (num_ch * ch_stride);
+	unsigned int tx_max = tx_base + (num_ch * ch_stride);
+
+	if ((reg >= rx_base) && (reg < rx_max)) {

The braces are not needed around the comparisons because they precede the AND. Same for all other similar occurrences in the code.

#37 lore raw

Re: [alsa-devel] [PATCH 7/9] ASoC: tegra: add Tegra210 based ADMAIF driver

Quoted 5 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

20.01.2020 17:23, Sameer Pujar пишет:
[snip]

Quoted 15 lines

sound/soc/tegra/tegra210_admaif.c line 96

Quoted 13 lines
sound/soc/tegra/tegra210_admaif.c new file +13 -0
+static bool tegra_admaif_wr_reg(struct device *dev, unsigned int reg)
+{
+     struct tegra_admaif *admaif = dev_get_drvdata(dev);
+     unsigned int ch_stride = TEGRA_ADMAIF_CHANNEL_REG_STRIDE;
+     unsigned int num_ch = admaif->soc_data->num_ch;
+     unsigned int rx_base = admaif->soc_data->rx_base;
+     unsigned int tx_base = admaif->soc_data->tx_base;
+     unsigned int global_base = admaif->soc_data->global_base;
+     unsigned int reg_max = admaif->soc_data->regmap_conf->max_register;
+     unsigned int rx_max = rx_base + (num_ch * ch_stride);
+     unsigned int tx_max = tx_base + (num_ch * ch_stride);
+
+     if ((reg >= rx_base) && (reg < rx_max)) {

The braces are not needed around the comparisons because they precede the AND. Same for all other similar occurrences in the code.

While that is true, some prefer to use explicit braces to make it more readable. In the past I was told to use explicitly in such cases.

#38 lore raw

Re: [alsa-devel] [PATCH 7/9] ASoC: tegra: add Tegra210 based ADMAIF driver

24.01.2020 06:27, Sameer Pujar пишет:

Quoted 25 lines · Dmitry Osipenko
Quoted 5 lines

External email: Use caution opening links or attachments

20.01.2020 17:23, Sameer Pujar пишет:
[snip]

Quoted 16 lines
Quoted 9 lines
sound/soc/tegra/tegra210_admaif.c new file +9 -0
+static bool tegra_admaif_wr_reg(struct device *dev, unsigned int reg)
+{
+     struct tegra_admaif *admaif = dev_get_drvdata(dev);
+     unsigned int ch_stride = TEGRA_ADMAIF_CHANNEL_REG_STRIDE;
+     unsigned int num_ch = admaif->soc_data->num_ch;
+     unsigned int rx_base = admaif->soc_data->rx_base;
+     unsigned int tx_base = admaif->soc_data->tx_base;
+     unsigned int global_base = admaif->soc_data->global_base;
+     unsigned int reg_max =
Quoted 5 lines

admaif->soc_data->regmap_conf->max_register;
+     unsigned int rx_max = rx_base + (num_ch * ch_stride); +     unsigned int tx_max = tx_base + (num_ch * ch_stride); +
+     if ((reg >= rx_base) && (reg < rx_max)) {

The braces are not needed around the comparisons because they precede the AND. Same for all other similar occurrences in the code.

Quoted 3 lines

While that is true, some prefer to use explicit braces to make it more readable.
In the past I was told to use explicitly in such cases.

At least most of code in kernel (I've seen) doesn't have superfluous parens (the curvy thingies actually should be the braces). Readability is arguable in this case, I'm finding such code a bit more difficult to read, although in some cases parens and spacing may help to read more complex constructions.

#39 lore raw

Re: [alsa-devel] [PATCH 7/9] ASoC: tegra: add Tegra210 based ADMAIF driver

Quoted 27 lines · Dmitry Osipenko

External email: Use caution opening links or attachments

24.01.2020 06:27, Sameer Pujar пишет:

Quoted 23 lines · Dmitry Osipenko
Quoted 21 lines

External email: Use caution opening links or attachments

20.01.2020 17:23, Sameer Pujar пишет:
[snip]

Quoted 10 lines
sound/soc/tegra/tegra210_admaif.c new file +9 -0
+static bool tegra_admaif_wr_reg(struct device *dev, unsigned int reg)
+{
+     struct tegra_admaif *admaif = dev_get_drvdata(dev);
+     unsigned int ch_stride = TEGRA_ADMAIF_CHANNEL_REG_STRIDE;
+     unsigned int num_ch = admaif->soc_data->num_ch;
+     unsigned int rx_base = admaif->soc_data->rx_base;
+     unsigned int tx_base = admaif->soc_data->tx_base;
+     unsigned int global_base = admaif->soc_data->global_base;
+     unsigned int reg_max =

admaif->soc_data->regmap_conf->max_register;

sound/soc/tegra/tegra210_admaif.c line 96

Quoted 4 lines
sound/soc/tegra/tegra210_admaif.c new file +4 -0
+     unsigned int rx_max = rx_base + (num_ch * ch_stride);
+     unsigned int tx_max = tx_base + (num_ch * ch_stride);
+
+     if ((reg >= rx_base) && (reg < rx_max)) {

The braces are not needed around the comparisons because they precede the AND. Same for all other similar occurrences in the code.

Quoted 8 lines
Quoted 3 lines

While that is true, some prefer to use explicit braces to make it more readable.
In the past I was told to use explicitly in such cases.

At least most of code in kernel (I've seen) doesn't have superfluous parens (the curvy thingies actually should be the braces). Readability is arguable in this case, I'm finding such code a bit more difficult to read, although in some cases parens and spacing may help to read more complex constructions.

Yes this is subjective and depends on the individual reading the code. It is confusing every time, for the sender, about which guideline to follow. Resending the patch/series for only this reason may not be really necessary. Since I need to fix couple of issues in this series I may consider removing the explicit braces.

#40 lore raw

PATCH 8/9 arm64: tegra: add AHUB components for few Tegra chips

In reply to Sameer Pujar

This patch adds few AHUB modules for Tegra210, Tegra186 and Tegra194. Following modules are common to all above SoCs,
* AHUB added as a child node under ACONNECT
* AHUB includes many HW accelerators and below components are added as its children.
* ADMAIF
* I2S
* DMIC
* DSPK (added for Tegra186 and Tegra194 only, since Tegra210 does not have this module)

---
 arch/arm64/boot/dts/nvidia/tegra186.dtsi | 231 ++++++++++++++++++++++++++++-
 arch/arm64/boot/dts/nvidia/tegra194.dtsi | 239 ++++++++++++++++++++++++++++++-
 arch/arm64/boot/dts/nvidia/tegra210.dtsi | 145 +++++++++++++++++++
 3 files changed, 613 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/nvidia/tegra186.dtsi +230 -1
index c905527..04a1b4e 100644
@@ -82,7 +82,7 @@
 		ranges = <0x02900000 0x0 0x02900000 0x200000>;
 		status = "disabled";
 
-		dma-controller@2930000 {
+		adma: dma-controller@2930000 {
 			compatible = "nvidia,tegra186-adma";
 			reg = <0x02930000 0x20000>;
 			interrupt-parent = <&agic>;
@@ -137,6 +137,235 @@
 			clock-names = "clk";
 			status = "disabled";
 		};
+
+		tegra_ahub: ahub@2900800 {
+			compatible = "nvidia,tegra186-ahub";
+			reg = <0x02900800 0x800>;
+			clocks = <&bpmp TEGRA186_CLK_AHUB>;
+			clock-names = "ahub";
+			assigned-clocks = <&bpmp TEGRA186_CLK_AHUB>;
+			assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0x02900800 0x02900800 0x11800>;
+			#sound-dai-cells = <1>;
+			status = "disabled";
+
+			tegra_admaif: admaif@290f000 {
+				compatible = "nvidia,tegra186-admaif";
+				reg = <0x0290f000 0x1000>;
+				dmas = <&adma 1>, <&adma 1>,
+				       <&adma 2>, <&adma 2>,
+				       <&adma 3>, <&adma 3>,
+				       <&adma 4>, <&adma 4>,
+				       <&adma 5>, <&adma 5>,
+				       <&adma 6>, <&adma 6>,
+				       <&adma 7>, <&adma 7>,
+				       <&adma 8>, <&adma 8>,
+				       <&adma 9>, <&adma 9>,
+				       <&adma 10>, <&adma 10>,
+				       <&adma 11>, <&adma 11>,
+				       <&adma 12>, <&adma 12>,
+				       <&adma 13>, <&adma 13>,
+				       <&adma 14>, <&adma 14>,
+				       <&adma 15>, <&adma 15>,
+				       <&adma 16>, <&adma 16>,
+				       <&adma 17>, <&adma 17>,
+				       <&adma 18>, <&adma 18>,
+				       <&adma 19>, <&adma 19>,
+				       <&adma 20>, <&adma 20>;
+				dma-names = "rx1", "tx1",
+					    "rx2", "tx2",
+					    "rx3", "tx3",
+					    "rx4", "tx4",
+					    "rx5", "tx5",
+					    "rx6", "tx6",
+					    "rx7", "tx7",
+					    "rx8", "tx8",
+					    "rx9", "tx9",
+					    "rx10", "tx10",
+					    "rx11", "tx11",
+					    "rx12", "tx12",
+					    "rx13", "tx13",
+					    "rx14", "tx14",
+					    "rx15", "tx15",
+					    "rx16", "tx16",
+					    "rx17", "tx17",
+					    "rx18", "tx18",
+					    "rx19", "tx19",
+					    "rx20", "tx20";
+				#sound-dai-cells = <1>;
+				status = "disabled";
+			};
+
+			tegra_i2s1: i2s@2901000 {
+				compatible = "nvidia,tegra186-i2s",
+					     "nvidia,tegra210-i2s";
+				reg = <0x2901000 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_I2S1>,
+					 <&bpmp TEGRA186_CLK_I2S1_SYNC_INPUT>;
+				clock-names = "i2s", "sync_input";
+				assigned-clocks = <&bpmp TEGRA186_CLK_I2S1>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <1536000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "I2S1";
+				status = "disabled";
+			};
+
+			tegra_i2s2: i2s@2901100 {
+				compatible = "nvidia,tegra186-i2s",
+					     "nvidia,tegra210-i2s";
+				reg = <0x2901100 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_I2S2>,
+					 <&bpmp TEGRA186_CLK_I2S2_SYNC_INPUT>;
+				clock-names = "i2s", "sync_input";
+				assigned-clocks = <&bpmp TEGRA186_CLK_I2S2>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <1536000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "I2S2";
+				status = "disabled";
+			};
+
+			tegra_i2s3: i2s@2901200 {
+				compatible = "nvidia,tegra186-i2s",
+					     "nvidia,tegra210-i2s";
+				reg = <0x2901200 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_I2S3>,
+					 <&bpmp TEGRA186_CLK_I2S3_SYNC_INPUT>;
+				clock-names = "i2s", "sync_input";
+				assigned-clocks = <&bpmp TEGRA186_CLK_I2S3>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <1536000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "I2S3";
+				status = "disabled";
+			};
+
+			tegra_i2s4: i2s@2901300 {
+				compatible = "nvidia,tegra186-i2s",
+					     "nvidia,tegra210-i2s";
+				reg = <0x2901300 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_I2S4>,
+					 <&bpmp TEGRA186_CLK_I2S4_SYNC_INPUT>;
+				clock-names = "i2s", "sync_input";
+				assigned-clocks = <&bpmp TEGRA186_CLK_I2S4>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <1536000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "I2S4";
+				status = "disabled";
+			};
+
+			tegra_i2s5: i2s@2901400 {
+				compatible = "nvidia,tegra186-i2s",
+					     "nvidia,tegra210-i2s";
+				reg = <0x2901400 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_I2S5>,
+					 <&bpmp TEGRA186_CLK_I2S5_SYNC_INPUT>;
+				clock-names = "i2s", "sync_input";
+				assigned-clocks = <&bpmp TEGRA186_CLK_I2S5>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <1536000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "I2S5";
+				status = "disabled";
+			};
+
+			tegra_i2s6: i2s@2901500 {
+				compatible = "nvidia,tegra186-i2s",
+					     "nvidia,tegra210-i2s";
+				reg = <0x2901500 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_I2S6>,
+					 <&bpmp TEGRA186_CLK_I2S6_SYNC_INPUT>;
+				clock-names = "i2s", "sync_input";
+				assigned-clocks = <&bpmp TEGRA186_CLK_I2S6>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <1536000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "I2S6";
+				status = "disabled";
+			};
+
+			tegra_dmic1: dmic@2904000 {
+				compatible = "nvidia,tegra210-dmic";
+				reg = <0x2904000 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_DMIC1>;
+				clock-names = "dmic";
+				assigned-clocks = <&bpmp TEGRA186_CLK_DMIC1>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <3072000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "DMIC1";
+				status = "disabled";
+			};
+
+			tegra_dmic2: dmic@2904100 {
+				compatible = "nvidia,tegra210-dmic";
+				reg = <0x2904100 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_DMIC2>;
+				clock-names = "dmic";
+				assigned-clocks = <&bpmp TEGRA186_CLK_DMIC2>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <3072000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "DMIC2";
+				status = "disabled";
+			};
+
+			tegra_dmic3: dmic@2904200 {
+				compatible = "nvidia,tegra210-dmic";
+				reg = <0x2904200 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_DMIC3>;
+				clock-names = "dmic";
+				assigned-clocks = <&bpmp TEGRA186_CLK_DMIC3>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <3072000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "DMIC3";
+				status = "disabled";
+			};
+
+			tegra_dmic4: dmic@2904300 {
+				compatible = "nvidia,tegra210-dmic";
+				reg = <0x2904300 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_DMIC4>;
+				clock-names = "dmic";
+				assigned-clocks = <&bpmp TEGRA186_CLK_DMIC4>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <3072000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "DMIC4";
+				status = "disabled";
+			};
+
+			tegra_dspk1: dspk@2905000 {
+				compatible = "nvidia,tegra186-dspk";
+				reg = <0x2905000 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_DSPK1>;
+				clock-names = "dspk";
+				assigned-clocks = <&bpmp TEGRA186_CLK_DSPK1>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <12288000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "DSPK1";
+				status = "disabled";
+			};
+
+			tegra_dspk2: dspk@2905100 {
+				compatible = "nvidia,tegra186-dspk";
+				reg = <0x2905100 0x100>;
+				clocks = <&bpmp TEGRA186_CLK_DSPK2>;
+				clock-names = "dspk";
+				assigned-clocks = <&bpmp TEGRA186_CLK_DSPK2>;
+				assigned-clock-parents = <&bpmp TEGRA186_CLK_PLL_A_OUT0>;
+				assigned-clock-rates = <12288000>;
+				#sound-dai-cells = <1>;
+				sound-name-prefix = "DSPK2";
+				status = "disabled";
+			};
+		};
 	};
 
 	memory-controller@2c00000 {
arch/arm64/boot/dts/nvidia/tegra194.dtsi +238 -1

251 lines not on this page · raw message

arch/arm64/boot/dts/nvidia/tegra210.dtsi +145 -0

151 lines not on this page · raw message

Signature · 1 line
2.7.4
#41 lore raw

PATCH 9/9 arm64: tegra: enable AHUB modules for few Tegra chips

In reply to Sameer Pujar

This patch enables AHUB, ADMAIF modules for following Tegra platforms. Along with this specific instances of I/O modules are enabled as per the board design.

* Jetson TX1
- I2S1, I2S2, I2S3, I2S4 and I2S5
- DMIC1, DMIC2 and DMIC3

* Jetson TX2
- I2S1, I2S2, I2S3, I2S4, I2S5 and I2S6
- DMIC1, DMIC2 and DMIC3
- DSPK2

* Jetson AGX Xavier
- I2S1, I2S2, I2S4 and I2S6
- DMIC2 and DMIC3
- DSPK1

---
 arch/arm64/boot/dts/nvidia/tegra186-p2771-0000.dts | 48 ++++++++++++++++++++++
 arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts | 36 ++++++++++++++++
 arch/arm64/boot/dts/nvidia/tegra210-p2371-2180.dts | 40 ++++++++++++++++++
 3 files changed, 124 insertions(+)
arch/arm64/boot/dts/nvidia/tegra186-p2771-0000.dts +48 -0
index f1de4ff..717993c 100644
@@ -20,6 +20,54 @@
 		interrupt-controller@2a40000 {
 			status = "okay";
 		};
+
+		ahub@2900800 {
+			status = "okay";
+
+			admaif@290f000 {
+				status = "okay";
+			};
+
+			i2s@2901000 {
+				status = "okay";
+			};
+
+			i2s@2901100 {
+				status = "okay";
+			};
+
+			i2s@2901200 {
+				status = "okay";
+			};
+
+			i2s@2901300 {
+				status = "okay";
+			};
+
+			i2s@2901400 {
+				status = "okay";
+			};
+
+			i2s@2901500 {
+				status = "okay";
+			};
+
+			dmic@2904000 {
+				status = "okay";
+			};
+
+			dmic@2904100 {
+				status = "okay";
+			};
+
+			dmic@2904200 {
+				status = "okay";
+			};
+
+			dspk@2905100 {
+				status = "okay";
+			};
+		};
 	};
 
 	i2c@3160000 {
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +36 -0
index 985e7d8..f5d5832 100644
@@ -21,6 +21,42 @@
 			interrupt-controller@2a40000 {
 				status = "okay";
 			};
+
+			ahub@2900800 {
+				status = "okay";
+
+				admaif@290f000 {
+					status = "okay";
+				};
+
+				i2s@2901000 {
+					status = "okay";
+				};
+
+				i2s@2901100 {
+					status = "okay";
+				};
+
+				i2s@2901300 {
+					status = "okay";
+				};
+
+				i2s@2901500 {
+					status = "okay";
+				};
+
+				dmic@2904100 {
+					status = "okay";
+				};
+
+				dmic@2904200 {
+					status = "okay";
+				};
+
+				dspk@2905000 {
+					status = "okay";
+				};
+			};
 		};
 
 		ddc: i2c@31c0000 {
arch/arm64/boot/dts/nvidia/tegra210-p2371-2180.dts +40 -0
index a3cafe3..c8d2c21 100644
@@ -123,5 +123,45 @@
 		agic@702f9000 {
 			status = "okay";
 		};
+
+		ahub@702d0800 {
+			status = "okay";
+
+			admaif@702d0000 {
+				status = "okay";
+			};
+
+			i2s@702d1000 {
+				status = "okay";
+			};
+
+			i2s@702d1100 {
+				status = "okay";
+			};
+
+			i2s@702d1200 {
+				status = "okay";
+			};
+
+			i2s@702d1300 {
+				status = "okay";
+			};
+
+			i2s@702d1400 {
+				status = "okay";
+			};
+
+			dmic@702d4000 {
+				status = "okay";
+			};
+
+			dmic@702d4100 {
+				status = "okay";
+			};
+
+			dmic@702d4200 {
+				status = "okay";
+			};
+		};
 	};
 };
Signature · 1 line
2.7.4
#42 lore raw
In reply to Sameer Pujar
Quoted 27 lines · Sameer Pujar

Overview
========
The Audio Hub (AHUB) is part of the Audio Processing Engine (APE) which comprises a collection of hardware accelerators for audio pre-processing and post-processing. It also includes a programmable full crossbar for routing audio data across these accelerators.

This series exposes some of these below mentioned HW devices as ASoC components for Tegra platforms from Tegra210 onwards.
* ADMAIF : The interface between ADMA and AHUB

  * XBAR   : Crossbar for routing audio samples across various modules
  * I2S    : Inter-IC Sound Controller
  * DMIC   : Digital Microphone
  * DSPK   : Digital Speaker

Following is the summary of current series.
1. Add YAML DT binding documentation for above mentioned modules.
2. ACIF programming is same for Tegra generations and hence it is moved to a common file.
3. Add ASoC driver components for each of the above modules.
4. Add DT entries for above components for Tegra210, Tegra186 and

     Tegra194.

5. Enable these components for Jetson-Tx1, Jetson-Tx2 and Jetson-Xavier.

Machine driver series will be sent separately.

Quoted 10 lines

Sameer Pujar (9):
dt-bindings: sound: tegra: add DT binding for AHUB
ASoC: tegra: add support for CIF programming
ASoC: tegra: add Tegra210 based DMIC driver
ASoC: tegra: add Tegra210 based I2S driver
ASoC: tegra: add Tegra210 based AHUB driver
ASoC: tegra: add Tegra186 based DSPK driver
ASoC: tegra: add Tegra210 based ADMAIF driver
arm64: tegra: add AHUB components for few Tegra chips
arm64: tegra: enable AHUB modules for few Tegra chips

If any comments on the series, please let me know.
I am planning to publish v2 based on the discussion we had in v1.

Thanks,
Sameer.

Quoted 51 lines
  .../bindings/sound/nvidia,tegra186-dspk.yaml       | 105 +++
  .../bindings/sound/nvidia,tegra210-admaif.yaml     | 165 ++++
  .../bindings/sound/nvidia,tegra210-ahub.yaml       | 130 +++
  .../bindings/sound/nvidia,tegra210-dmic.yaml       | 105 +++
  .../bindings/sound/nvidia,tegra210-i2s.yaml        | 112 +++
  arch/arm64/boot/dts/nvidia/tegra186-p2771-0000.dts |  48 ++
  arch/arm64/boot/dts/nvidia/tegra186.dtsi           | 231 ++++-
  arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts |  36 +
  arch/arm64/boot/dts/nvidia/tegra194.dtsi           | 239 +++++-
  arch/arm64/boot/dts/nvidia/tegra210-p2371-2180.dts |  40 +
  arch/arm64/boot/dts/nvidia/tegra210.dtsi           | 145 ++++
  sound/soc/tegra/Kconfig                            |  56 ++
  sound/soc/tegra/Makefile                           |  12 +
  sound/soc/tegra/tegra186_dspk.c                    | 516 +++++++++++
  sound/soc/tegra/tegra186_dspk.h                    |  73 ++
  sound/soc/tegra/tegra210_admaif.c                  | 896 ++++++++++++++++++++
  sound/soc/tegra/tegra210_admaif.h                  | 164 ++++
  sound/soc/tegra/tegra210_ahub.c                    | 667 +++++++++++++++
  sound/soc/tegra/tegra210_ahub.h                    | 125 +++
  sound/soc/tegra/tegra210_dmic.c                    | 522 ++++++++++++
  sound/soc/tegra/tegra210_dmic.h                    |  85 ++
  sound/soc/tegra/tegra210_i2s.c                     | 941 +++++++++++++++++++++
  sound/soc/tegra/tegra210_i2s.h                     | 132 +++
  sound/soc/tegra/tegra30_ahub.c                     |  94 +-
  sound/soc/tegra/tegra30_ahub.h                     | 129 ---
  sound/soc/tegra/tegra30_i2s.c                      |  35 +-
  sound/soc/tegra/tegra30_i2s.h                      |   7 -
  sound/soc/tegra/tegra_cif.c                        |  34 +
  sound/soc/tegra/tegra_cif.h                        |  50 ++
  sound/soc/tegra/tegra_pcm.c                        | 224 ++++-
  sound/soc/tegra/tegra_pcm.h                        |  23 +-
  31 files changed, 5897 insertions(+), 244 deletions(-)

create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra186-dspk.yaml create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-admaif.yaml create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-ahub.yaml create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-dmic.yaml create mode 100644 Documentation/devicetree/bindings/sound/nvidia,tegra210-i2s.yaml create mode 100644 sound/soc/tegra/tegra186_dspk.c
create mode 100644 sound/soc/tegra/tegra186_dspk.h
create mode 100644 sound/soc/tegra/tegra210_admaif.c
create mode 100644 sound/soc/tegra/tegra210_admaif.h
create mode 100644 sound/soc/tegra/tegra210_ahub.c
create mode 100644 sound/soc/tegra/tegra210_ahub.h
create mode 100644 sound/soc/tegra/tegra210_dmic.c
create mode 100644 sound/soc/tegra/tegra210_dmic.h
create mode 100644 sound/soc/tegra/tegra210_i2s.c
create mode 100644 sound/soc/tegra/tegra210_i2s.h
create mode 100644 sound/soc/tegra/tegra_cif.c
create mode 100644 sound/soc/tegra/tegra_cif.h