Skip to contentSkip to conversation

ASoC: Some issues about loongson i2s

PATCH Superseded Binbin Zhou 7 participants 40 messages Sep 5, 2024 – Sep 18, 2024

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Binbin Zhou

author maintainer
#0 lore raw

cover ASoC: Some issues about loongson i2s

Hi all:

This patch set is mainly about Loongson i2s related issues.

Please allow me to briefly explain this patch set:
Patch 1-2: Add ES8323 codec required on Loongson-2K2000 Patch 3-4: Add uda1342 codec required on Loongson-2K1000 Patch 5: Improve code readability
Patch 6: Fix the problem of unable to detect codec under FDT system. Patch 7-8: Add Loongson i2s platform device support
Patch 9-10: Related DTS support.

Thanks.

base-commit: 097a44db5747403b19d05a9664e8ec6adba27e3b

Binbin Zhou (10):
ASoC: dt-bindings: Add Everest ES8323 Codec
ASoC: codecs: Add support for ES8323
ASoC: dt-bindings: Add NXP uda1342 Codec
ASoC: codecs: Add uda1342 codec driver
ASoC: loongson: Improve code readability
ASoC: loongson: Fix codec detection failure on FDT systems
ASoC: dt-bindings: Add Loongson I2S controller
ASoC: loongson: Add I2S controller driver as platform device
LoongArch: dts: Add I2S support to Loongson-2K1000
LoongArch: dts: Add I2S support to Loongson-2K2000

 .../bindings/sound/everest,es8323.yaml        |  49 +
 .../bindings/sound/loongson,ls2k-i2s.yaml     |  66 ++
 .../bindings/sound/nxp,uda1342.yaml           |  42 +
 arch/loongarch/boot/dts/loongson-2k1000.dtsi  |  17 +-
 arch/loongarch/boot/dts/loongson-2k2000.dtsi  |  22 +-
 sound/soc/codecs/Kconfig                      |  13 +
 sound/soc/codecs/Makefile                     |   4 +
 sound/soc/codecs/es8323.c                     | 849 ++++++++++++++++++
 sound/soc/codecs/es8323.h                     |  77 ++
 sound/soc/codecs/uda1342.c                    | 397 ++++++++
 sound/soc/codecs/uda1342.h                    |  77 ++
 sound/soc/loongson/Kconfig                    |  12 +-
 sound/soc/loongson/Makefile                   |   3 +
 sound/soc/loongson/loongson_card.c            | 217 +++--
 sound/soc/loongson/loongson_dma.c             |  10 +-
 sound/soc/loongson/loongson_i2s.c             | 110 +--
 sound/soc/loongson/loongson_i2s.h             |  24 +-
 sound/soc/loongson/loongson_i2s_pci.c         |  51 +-
 sound/soc/loongson/loongson_i2s_plat.c        | 186 ++++
 19 files changed, 2030 insertions(+), 196 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/everest,es8323.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/nxp,uda1342.yaml
 create mode 100644 sound/soc/codecs/es8323.c
 create mode 100644 sound/soc/codecs/es8323.h
 create mode 100644 sound/soc/codecs/uda1342.c
 create mode 100644 sound/soc/codecs/uda1342.h
 create mode 100644 sound/soc/loongson/loongson_i2s_plat.c
Signature · 1 line
2.43.5
author maintainer
#1 lore raw

PATCH 1/10 ASoC: dt-bindings: Add Everest ES8323 Codec

Add Everest Semiconductor ES8316 low power audio CODEC binding with DT schema format using json-schema.

---
 .../bindings/sound/everest,es8323.yaml        | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/everest,es8323.yaml
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +49 -0
new file mode 100644
index 000000000000..0450d0f49d03
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/everest,es8323.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Everest ES8323 audio CODECs
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: everest,es8323
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    description: clock for master clock (MCLK)
+    maxItems: 1
+
+  clock-names:
+    const: mclk
+
+  '#sound-dai-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - '#sound-dai-cells'
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      codec@10 {
+        compatible = "everest,es8323";
+        reg = <0x10>;
+        #sound-dai-cells = <0>;
+      };
+    };
Signature · 1 line
2.43.5
author maintainer
#4 lore raw

PATCH 2/10 ASoC: codecs: Add support for ES8323

In reply to Binbin Zhou

Add a codec driver for the Everest ES8323. It supports two separate audio outputs and two separate audio inputs.

---
 sound/soc/codecs/Kconfig  |   5 +
 sound/soc/codecs/Makefile |   2 +
 sound/soc/codecs/es8323.c | 849 ++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/es8323.h |  77 ++++
 4 files changed, 933 insertions(+)
 create mode 100644 sound/soc/codecs/es8323.c
 create mode 100644 sound/soc/codecs/es8323.h
sound/soc/codecs/Kconfig +5 -0
index b5e6d0a986c8..85270aa43512 100644
@@ -112,6 +112,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_DA9055
 	imply SND_SOC_DMIC
 	imply SND_SOC_ES8316
+	imply SND_SOC_ES8323
 	imply SND_SOC_ES8326
 	imply SND_SOC_ES8328_SPI
 	imply SND_SOC_ES8328_I2C
@@ -1142,6 +1143,10 @@ config SND_SOC_ES8316
 	tristate "Everest Semi ES8316 CODEC"
 	depends on I2C
 
+config SND_SOC_ES8323
+	tristate "Everest Semi ES8323 CODEC"
+	depends on I2C
+
 config SND_SOC_ES8326
 	tristate "Everest Semi ES8326 CODEC"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 622e360f0086..00ff3fdf0133 100644
@@ -125,6 +125,7 @@ snd-soc-es7241-y := es7241.o
 snd-soc-es83xx-dsm-common-y := es83xx-dsm-common.o
 snd-soc-es8311-y := es8311.o
 snd-soc-es8316-y := es8316.o
+snd-soc-es8323-y := es8323.o
 snd-soc-es8326-y := es8326.o
 snd-soc-es8328-y := es8328.o
 snd-soc-es8328-i2c-y := es8328-i2c.o
@@ -531,6 +532,7 @@ obj-$(CONFIG_SND_SOC_ES7241)	+= snd-soc-es7241.o
 obj-$(CONFIG_SND_SOC_ES83XX_DSM_COMMON)    += snd-soc-es83xx-dsm-common.o
 obj-$(CONFIG_SND_SOC_ES8311)    += snd-soc-es8311.o
 obj-$(CONFIG_SND_SOC_ES8316)    += snd-soc-es8316.o
+obj-$(CONFIG_SND_SOC_ES8323)	+= snd-soc-es8323.o
 obj-$(CONFIG_SND_SOC_ES8326)    += snd-soc-es8326.o
 obj-$(CONFIG_SND_SOC_ES8328)	+= snd-soc-es8328.o
 obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
sound/soc/codecs/es8323.c new file +847 -0

847 lines not on this page · raw message

sound/soc/codecs/es8323.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.43.5
author maintainer
#11 lore raw

PATCH 3/10 ASoC: dt-bindings: Add NXP uda1342 Codec

In reply to Binbin Zhou

Add NXP uda1342 CODEC binding with DT schema format using json-schema.

---
 .../bindings/sound/nxp,uda1342.yaml           | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nxp,uda1342.yaml
Documentation/devicetree/bindings/sound/nxp,uda1342.yaml new file +42 -0
new file mode 100644
index 000000000000..71c6a5a2f5bc
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/nxp,uda1342.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP uda1342 audio CODECs
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: nxp,uda1342
+
+  reg:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - '#sound-dai-cells'
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      codec@1a {
+        compatible = "nxp,uda1342";
+        reg = <0x1a>;
+        #sound-dai-cells = <0>;
+      };
+    };
Signature · 1 line
2.43.5
author maintainer
#13 lore raw

PATCH 4/10 ASoC: codecs: Add uda1342 codec driver

In reply to Binbin Zhou

The UDA1342 is an NXP audio codec, support 2x Stereo audio ADC (4x PGA mic inputs), stereo audio DAC, with basic audio processing.

---
 sound/soc/codecs/Kconfig   |   8 +
 sound/soc/codecs/Makefile  |   2 +
 sound/soc/codecs/uda1342.c | 397 +++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/uda1342.h |  77 +++++++
 4 files changed, 484 insertions(+)
 create mode 100644 sound/soc/codecs/uda1342.c
 create mode 100644 sound/soc/codecs/uda1342.h
sound/soc/codecs/Kconfig +8 -0
index 85270aa43512..347ac5e8eca7 100644
@@ -281,6 +281,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_TWL4030
 	imply SND_SOC_TWL6040
 	imply SND_SOC_UDA1334
+	imply SND_SOC_UDA1342
 	imply SND_SOC_UDA1380
 	imply SND_SOC_WCD9335
 	imply SND_SOC_WCD934X
@@ -2118,6 +2119,13 @@ config SND_SOC_UDA1334
 	  and has basic features such as de-emphasis (at 44.1 kHz sampling
 	  rate) and mute.
 
+config SND_SOC_UDA1342
+	tristate "NXP UDA1342 CODEC"
+	depends on I2C
+	help
+	  The UDA1342 is an NXP audio codec, support 2x Stereo audio ADC (4x PGA mic inputs),
+	  stereo audio DAC, with basic audio processing.
+
 config SND_SOC_UDA1380
 	tristate
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 00ff3fdf0133..f5b1c8499d6c 100644
@@ -319,6 +319,7 @@ snd-soc-ts3a227e-y := ts3a227e.o
 snd-soc-twl4030-y := twl4030.o
 snd-soc-twl6040-y := twl6040.o
 snd-soc-uda1334-y := uda1334.o
+snd-soc-uda1342-y := uda1342.o
 snd-soc-uda1380-y := uda1380.o
 snd-soc-wcd-classh-y := wcd-clsh-v2.o
 snd-soc-wcd-mbhc-y := wcd-mbhc-v2.o
@@ -723,6 +724,7 @@ obj-$(CONFIG_SND_SOC_TS3A227E)	+= snd-soc-ts3a227e.o
 obj-$(CONFIG_SND_SOC_TWL4030)	+= snd-soc-twl4030.o
 obj-$(CONFIG_SND_SOC_TWL6040)	+= snd-soc-twl6040.o
 obj-$(CONFIG_SND_SOC_UDA1334)	+= snd-soc-uda1334.o
+obj-$(CONFIG_SND_SOC_UDA1342)	+= snd-soc-uda1342.o
 obj-$(CONFIG_SND_SOC_UDA1380)	+= snd-soc-uda1380.o
 obj-$(CONFIG_SND_SOC_WCD_CLASSH)	+= snd-soc-wcd-classh.o
 obj-$(CONFIG_SND_SOC_WCD_MBHC)	+= snd-soc-wcd-mbhc.o
sound/soc/codecs/uda1342.c new file +397 -0

397 lines not on this page · raw message

sound/soc/codecs/uda1342.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.43.5
author maintainer
#17 lore raw

PATCH 5/10 ASoC: loongson: Improve code readability

In reply to Binbin Zhou

This patch attempts to clean up driver code formatting issues. Mainly as follows:
1. Use the BIT macro;
2. Use dev_err_probe() in every error path in probe in loongson_card driver;
3. Introduce loongson_card_acpi_find_device() to streamlined code.

No functional change intended.

---
 sound/soc/loongson/loongson_card.c    | 144 +++++++++++++-------------
 sound/soc/loongson/loongson_dma.c     |  10 +-
 sound/soc/loongson/loongson_i2s.c     | 110 ++++++++++----------
 sound/soc/loongson/loongson_i2s.h     |  24 ++---
 sound/soc/loongson/loongson_i2s_pci.c |  51 ++++-----
 5 files changed, 166 insertions(+), 173 deletions(-)
sound/soc/loongson/loongson_card.c +71 -73
index 2c8dbdba27c5..a25287efdd5c 100644
@@ -24,27 +24,27 @@ static int loongson_card_hw_params(struct snd_pcm_substream *substream,
 				   struct snd_pcm_hw_params *params)
 {
 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
-	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
-	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
 	struct loongson_card_data *ls_card = snd_soc_card_get_drvdata(rtd->card);
+	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
+	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
 	int ret, mclk;
 
-	if (ls_card->mclk_fs) {
-		mclk = ls_card->mclk_fs * params_rate(params);
-		ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
-					     SND_SOC_CLOCK_OUT);
-		if (ret < 0) {
-			dev_err(codec_dai->dev, "cpu_dai clock not set\n");
-			return ret;
-		}
+	if (!ls_card->mclk_fs)
+		return 0;
 
-		ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
-					     SND_SOC_CLOCK_IN);
-		if (ret < 0) {
-			dev_err(codec_dai->dev, "codec_dai clock not set\n");
-			return ret;
-		}
+	mclk = ls_card->mclk_fs * params_rate(params);
+	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT);
+	if (ret < 0) {
+		dev_err(codec_dai->dev, "cpu_dai clock not set\n");
+		return ret;
 	}
+
+	ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
+	if (ret < 0) {
+		dev_err(codec_dai->dev, "codec_dai clock not set\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -68,54 +68,61 @@ static struct snd_soc_dai_link loongson_dai_links[] = {
 	},
 };
 
-static int loongson_card_parse_acpi(struct loongson_card_data *data)
+static struct acpi_device *
+loongson_card_acpi_find_device(struct snd_soc_card *card, const char *name)
 {
-	struct snd_soc_card *card = &data->snd_card;
 	struct fwnode_handle *fwnode = card->dev->fwnode;
 	struct fwnode_reference_args args;
+	int status;
+
+	memset(&args, 0, sizeof(args));
+	status = acpi_node_get_property_reference(fwnode, name, 0, &args);
+	if (ACPI_FAILURE(status) || !is_acpi_device_node(args.fwnode)) {
+		dev_err(card->dev, "No matching phy in ACPI table\n");
+		return NULL;
+	}
+
+	return to_acpi_device_node(args.fwnode);
+}
+
+static int loongson_card_parse_acpi(struct loongson_card_data *data)
+{
+	struct snd_soc_card *card = &data->snd_card;
 	const char *codec_dai_name;
 	struct acpi_device *adev;
 	struct device *phy_dev;
-	int ret, i;
+	int i;
 
 	/* fixup platform name based on reference node */
-	memset(&args, 0, sizeof(args));
-	ret = acpi_node_get_property_reference(fwnode, "cpu", 0, &args);
-	if (ret || !is_acpi_device_node(args.fwnode)) {
-		dev_err(card->dev, "No matching phy in ACPI table\n");
-		return ret ?: -ENOENT;
-	}
-	adev = to_acpi_device_node(args.fwnode);
+	adev = loongson_card_acpi_find_device(card, "cpu");
+	if (!adev)
+		return -ENOENT;
+
 	phy_dev = acpi_get_first_physical_node(adev);
 	if (!phy_dev)
 		return -EPROBE_DEFER;
-	for (i = 0; i < card->num_links; i++)
-		loongson_dai_links[i].platforms->name = dev_name(phy_dev);
 
 	/* fixup codec name based on reference node */
-	memset(&args, 0, sizeof(args));
-	ret = acpi_node_get_property_reference(fwnode, "codec", 0, &args);
-	if (ret || !is_acpi_device_node(args.fwnode)) {
-		dev_err(card->dev, "No matching phy in ACPI table\n");
-		return ret ?: -ENOENT;
-	}
-	adev = to_acpi_device_node(args.fwnode);
+	adev = loongson_card_acpi_find_device(card, "codec");
+	if (!adev)
+		return -ENOENT;
 	snprintf(codec_name, sizeof(codec_name), "i2c-%s", acpi_dev_name(adev));
-	for (i = 0; i < card->num_links; i++)
-		loongson_dai_links[i].codecs->name = codec_name;
 
-	device_property_read_string(card->dev, "codec-dai-name",
-				    &codec_dai_name);
-	for (i = 0; i < card->num_links; i++)
+	device_property_read_string(card->dev, "codec-dai-name", &codec_dai_name);
+
+	for (i = 0; i < card->num_links; i++) {
+		loongson_dai_links[i].platforms->name = dev_name(phy_dev);
+		loongson_dai_links[i].codecs->name = codec_name;
 		loongson_dai_links[i].codecs->dai_name = codec_dai_name;
+	}
 
 	return 0;
 }
 
 static int loongson_card_parse_of(struct loongson_card_data *data)
 {
-	struct device_node *cpu, *codec;
 	struct snd_soc_card *card = &data->snd_card;
+	struct device_node *cpu, *codec;
 	struct device *dev = card->dev;
 	int ret, i;
 
@@ -124,77 +131,68 @@ static int loongson_card_parse_of(struct loongson_card_data *data)
 		dev_err(dev, "platform property missing or invalid\n");
 		return -EINVAL;
 	}
+
 	codec = of_get_child_by_name(dev->of_node, "codec");
 	if (!codec) {
 		dev_err(dev, "audio-codec property missing or invalid\n");
-		of_node_put(cpu);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto free_cpu;
 	}
 
 	for (i = 0; i < card->num_links; i++) {
 		ret = snd_soc_of_get_dlc(cpu, NULL, loongson_dai_links[i].cpus, 0);
-		if (ret < 0) {
+		if (ret) {
 			dev_err(dev, "getting cpu dlc error (%d)\n", ret);
-			goto err;
+			goto free_codec;
 		}
 
 		ret = snd_soc_of_get_dlc(codec, NULL, loongson_dai_links[i].codecs, 0);
-		if (ret < 0) {
+		if (ret) {
 			dev_err(dev, "getting codec dlc error (%d)\n", ret);
-			goto err;
+			goto free_codec;
 		}
 	}
 
-	of_node_put(cpu);
+free_codec:
 	of_node_put(codec);
-
-	return 0;
-
-err:
+free_cpu:
 	of_node_put(cpu);
-	of_node_put(codec);
 	return ret;
 }
 
 static int loongson_asoc_card_probe(struct platform_device *pdev)
 {
 	struct loongson_card_data *ls_priv;
+	struct device *dev = &pdev->dev;
 	struct snd_soc_card *card;
 	int ret;
 
-	ls_priv = devm_kzalloc(&pdev->dev, sizeof(*ls_priv), GFP_KERNEL);
+	ls_priv = devm_kzalloc(dev, sizeof(*ls_priv), GFP_KERNEL);
 	if (!ls_priv)
 		return -ENOMEM;
 
 	card = &ls_priv->snd_card;
 
-	card->dev = &pdev->dev;
+	card->dev = dev;
 	card->owner = THIS_MODULE;
 	card->dai_link = loongson_dai_links;
 	card->num_links = ARRAY_SIZE(loongson_dai_links);
 	snd_soc_card_set_drvdata(card, ls_priv);
 
-	ret = device_property_read_string(&pdev->dev, "model", &card->name);
-	if (ret) {
-		dev_err(&pdev->dev, "Error parsing card name: %d\n", ret);
-		return ret;
-	}
-	ret = device_property_read_u32(&pdev->dev, "mclk-fs", &ls_priv->mclk_fs);
-	if (ret) {
-		dev_err(&pdev->dev, "Error parsing mclk-fs: %d\n", ret);
-		return ret;
-	}
+	ret = device_property_read_string(dev, "model", &card->name);
+	if (ret)
+		dev_err_probe(dev, ret, "Error parsing card name.\n");
 
-	if (has_acpi_companion(&pdev->dev))
-		ret = loongson_card_parse_acpi(ls_priv);
-	else
-		ret = loongson_card_parse_of(ls_priv);
-	if (ret < 0)
-		return ret;
+	ret = device_property_read_u32(dev, "mclk-fs", &ls_priv->mclk_fs);
+	if (ret)
+		dev_err_probe(dev, ret, "Error parsing mclk-fs.\n");
 
-	ret = devm_snd_soc_register_card(&pdev->dev, card);
+	ret = has_acpi_companion(dev) ? loongson_card_parse_acpi(ls_priv)
+				      : loongson_card_parse_of(ls_priv);
+	if (ret)
+		dev_err_probe(dev, ret, "Error parsing acpi/of properties.\n");
 
-	return ret;
+	return devm_snd_soc_register_card(dev, card);
 }
 
 static const struct of_device_id loongson_asoc_dt_ids[] = {
sound/soc/loongson/loongson_dma.c +5 -5
index 0238f88bc674..20e4a0641340 100644
@@ -17,11 +17,11 @@
 #include "loongson_i2s.h"
 
 /* DMA dma_order Register */
-#define DMA_ORDER_STOP          (1 << 4) /* DMA stop */
-#define DMA_ORDER_START         (1 << 3) /* DMA start */
-#define DMA_ORDER_ASK_VALID     (1 << 2) /* DMA ask valid flag */
-#define DMA_ORDER_AXI_UNCO      (1 << 1) /* Uncache access */
-#define DMA_ORDER_ADDR_64       (1 << 0) /* 64bits address support */
+#define DMA_ORDER_STOP          BIT(4) /* DMA stop */
+#define DMA_ORDER_START         BIT(3) /* DMA start */
+#define DMA_ORDER_ASK_VALID     BIT(2) /* DMA ask valid flag */
+#define DMA_ORDER_AXI_UNCO      BIT(1) /* Uncache access */
+#define DMA_ORDER_ADDR_64       BIT(0) /* 64bits address support */
 
 #define DMA_ORDER_ASK_MASK      (~0x1fUL) /* Ask addr mask */
 #define DMA_ORDER_CTRL_MASK     (0x0fUL)  /* Control mask  */
sound/soc/loongson/loongson_i2s.c +57 -53

155 lines not on this page · raw message

sound/soc/loongson/loongson_i2s.h +12 -12
index 89492eebf834..c8052a762c1b 100644
@@ -27,18 +27,18 @@
 #define LS_I2S_RX_ORDER 0x110 /* RX DMA Order */
 
 /* Loongson I2S Control Register */
-#define I2S_CTRL_MCLK_READY	(1 << 16) /* MCLK ready */
-#define I2S_CTRL_MASTER		(1 << 15) /* Master mode */
-#define I2S_CTRL_MSB		(1 << 14) /* MSB bit order */
-#define I2S_CTRL_RX_EN		(1 << 13) /* RX enable */
-#define I2S_CTRL_TX_EN		(1 << 12) /* TX enable */
-#define I2S_CTRL_RX_DMA_EN	(1 << 11) /* DMA RX enable */
-#define I2S_CTRL_CLK_READY	(1 << 8)  /* BCLK ready */
-#define I2S_CTRL_TX_DMA_EN	(1 << 7)  /* DMA TX enable */
-#define I2S_CTRL_RESET		(1 << 4)  /* Controller soft reset */
-#define I2S_CTRL_MCLK_EN	(1 << 3)  /* Enable MCLK */
-#define I2S_CTRL_RX_INT_EN	(1 << 1)  /* RX interrupt enable */
-#define I2S_CTRL_TX_INT_EN	(1 << 0)  /* TX interrupt enable */
+#define I2S_CTRL_MCLK_READY	BIT(16) /* MCLK ready */
+#define I2S_CTRL_MASTER		BIT(15) /* Master mode */
+#define I2S_CTRL_MSB		BIT(14) /* MSB bit order */
+#define I2S_CTRL_RX_EN		BIT(13) /* RX enable */
+#define I2S_CTRL_TX_EN		BIT(12) /* TX enable */
+#define I2S_CTRL_RX_DMA_EN	BIT(11) /* DMA RX enable */
+#define I2S_CTRL_CLK_READY	BIT(8)  /* BCLK ready */
+#define I2S_CTRL_TX_DMA_EN	BIT(7)  /* DMA TX enable */
+#define I2S_CTRL_RESET		BIT(4)  /* Controller soft reset */
+#define I2S_CTRL_MCLK_EN	BIT(3)  /* Enable MCLK */
+#define I2S_CTRL_RX_INT_EN	BIT(1)  /* RX interrupt enable */
+#define I2S_CTRL_TX_INT_EN	BIT(0)  /* TX interrupt enable */
 
 #define LS_I2S_DRVNAME		"loongson-i2s"
 
sound/soc/loongson/loongson_i2s_pci.c +21 -30

92 lines not on this page · raw message

Signature · 1 line
2.43.5
author maintainer
#20 lore raw

PATCH 6/10 ASoC: loongson: Fix codec detection failure on FDT systems

In reply to Binbin Zhou

When the Codec is compiled into a module, we can't use snd_soc_of_get_dlc() to get the codec dai_name, use snd_soc_get_dai_name() instead.

Also, for the cpu dailink, its dai_name is already defined as "loongson-i2s", so just get the corresponding of_node attribute here.

---
 sound/soc/loongson/loongson_card.c | 89 +++++++++++++++++++++---------
 1 file changed, 63 insertions(+), 26 deletions(-)
sound/soc/loongson/loongson_card.c +63 -26
index a25287efdd5c..d45a3e77cb90 100644
@@ -119,44 +119,81 @@ static int loongson_card_parse_acpi(struct loongson_card_data *data)
 	return 0;
 }
 
-static int loongson_card_parse_of(struct loongson_card_data *data)
+static int loongson_parse_cpu(struct device *dev, struct device_node **dai_node)
 {
-	struct snd_soc_card *card = &data->snd_card;
-	struct device_node *cpu, *codec;
-	struct device *dev = card->dev;
-	int ret, i;
+	struct device_node *cpu;
+	int ret = 0;
 
 	cpu = of_get_child_by_name(dev->of_node, "cpu");
-	if (!cpu) {
-		dev_err(dev, "platform property missing or invalid\n");
+	if (!cpu)
 		return -EINVAL;
-	}
+
+	*dai_node = of_parse_phandle(cpu, "sound-dai", 0);
+	if (!*dai_node)
+		ret = -EINVAL;
+
+	of_node_put(cpu);
+	return ret;
+}
+
+static int loongson_parse_codec(struct device *dev, struct device_node **dai_node,
+				const char **dai_name)
+{
+	struct of_phandle_args args;
+	struct device_node *codec;
+	int ret = 0;
 
 	codec = of_get_child_by_name(dev->of_node, "codec");
-	if (!codec) {
-		dev_err(dev, "audio-codec property missing or invalid\n");
+	if (!codec)
+		return -EINVAL;
+
+	ret = of_parse_phandle_with_args(codec, "sound-dai", "#sound-dai-cells", 0, &args);
+	if (ret)
+		goto free_codec;
+
+	ret = snd_soc_get_dai_name(&args, dai_name);
+	if (ret)
+		goto free_codec;
+
+	*dai_node = of_parse_phandle(codec, "sound-dai", 0);
+	if (!*dai_node)
 		ret = -EINVAL;
-		goto free_cpu;
+
+free_codec:
+	of_node_put(codec);
+	return ret;
+}
+
+static int loongson_card_parse_of(struct loongson_card_data *data)
+{
+	struct device_node *codec_dai_node, *cpu_dai_node;
+	struct snd_soc_card *card = &data->snd_card;
+	struct device *dev = card->dev;
+	const char *codec_dai_name;
+	int ret = 0, i;
+
+	ret = loongson_parse_cpu(dev, &cpu_dai_node);
+	if (ret) {
+		dev_err(dev, "cpu property missing or invalid.\n");
+		goto out;
+	}
+
+	ret = loongson_parse_codec(dev, &codec_dai_node, &codec_dai_name);
+	if (ret) {
+		dev_err(dev, "audio-codec property missing or invalid.\n");
+		goto out;
 	}
 
 	for (i = 0; i < card->num_links; i++) {
-		ret = snd_soc_of_get_dlc(cpu, NULL, loongson_dai_links[i].cpus, 0);
-		if (ret) {
-			dev_err(dev, "getting cpu dlc error (%d)\n", ret);
-			goto free_codec;
-		}
-
-		ret = snd_soc_of_get_dlc(codec, NULL, loongson_dai_links[i].codecs, 0);
-		if (ret) {
-			dev_err(dev, "getting codec dlc error (%d)\n", ret);
-			goto free_codec;
-		}
+		loongson_dai_links[i].platforms->of_node = cpu_dai_node;
+		loongson_dai_links[i].cpus->of_node = cpu_dai_node;
+		loongson_dai_links[i].codecs->of_node = codec_dai_node;
+		loongson_dai_links[i].codecs->dai_name = codec_dai_name;
 	}
 
-free_codec:
-	of_node_put(codec);
-free_cpu:
-	of_node_put(cpu);
+out:
+	of_node_put(codec_dai_node);
+	of_node_put(cpu_dai_node);
 	return ret;
 }
 
Signature · 1 line
2.43.5
author maintainer
#24 lore raw

PATCH 7/10 ASoC: dt-bindings: Add Loongson I2S controller

In reply to Binbin Zhou

Add Loongson I2S controller binding with DT schema format using json-schema.

---
 .../bindings/sound/loongson,ls2k-i2s.yaml     | 66 +++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +66 -0
new file mode 100644
index 000000000000..a2e3bbe00dab
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/loongson,ls2k-i2s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson-2K I2S controller
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: loongson,ls2k1000-i2s
+
+  reg:
+    maxItems: 2
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  dmas:
+    maxItems: 2
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  '#sound-dai-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - dmas
+  - dma-names
+  - '#sound-dai-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/loongson,ls2k-clk.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2s@1fe2d000 {
+        compatible = "loongson,ls2k1000-i2s";
+        reg = <0x1fe2d000 0x14>,
+              <0x1fe00438 0x8>;
+        interrupt-parent = <&liointc0>;
+        interrupts = <5 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clk LOONGSON2_APB_CLK>;
+        dmas = <&apbdma2 0>, <&apbdma3 0>;
+        dma-names = "tx", "rx";
+        #sound-dai-cells = <0>;
+    };
+...
Signature · 1 line
2.43.5
author maintainer
#27 lore raw

PATCH 8/10 ASoC: loongson: Add I2S controller driver as platform device

In reply to Binbin Zhou

The Loongson I2S controller exists not only in PCI form (LS7A bridge chip), but also in platform device form (Loongson-2K1000 SoC).

This patch adds support for platform device I2S controller.

---
 sound/soc/loongson/Kconfig             |  12 +-
 sound/soc/loongson/Makefile            |   3 +
 sound/soc/loongson/loongson_i2s_plat.c | 186 +++++++++++++++++++++++++
 3 files changed, 200 insertions(+), 1 deletion(-)
 create mode 100644 sound/soc/loongson/loongson_i2s_plat.c
sound/soc/loongson/Kconfig +11 -1
index b8d7e2bade24..cd298f8b54cd 100644
@@ -13,10 +13,20 @@ config SND_SOC_LOONGSON_I2S_PCI
 	  The controller is found in loongson bridge chips or SoCs,
 	  and work as a PCI device.
 
+config SND_SOC_LOONGSON_I2S_PLATFORM
+	tristate "Loongson I2S controller as platform device"
+	select SND_SOC_GENERIC_DMAENGINE_PCM
+	help
+	  Say Y or M if you want to add support for I2S driver for
+	  Loongson I2S controller.
+
+	  The controller work as a platform device, found in loongson
+	  SoCs.
+
 config SND_SOC_LOONGSON_CARD
 	tristate "Loongson Sound Card Driver"
 	select SND_SOC_LOONGSON_I2S_PCI
-	depends on PCI
+	select SND_SOC_LOONGSON_I2S_PLATFORM
 	help
 	  Say Y or M if you want to add support for SoC audio using
 	  loongson I2S controller.
sound/soc/loongson/Makefile +3 -0
index 578030ad6563..f396259244a3 100644
@@ -3,6 +3,9 @@
 snd-soc-loongson-i2s-pci-y := loongson_i2s_pci.o loongson_i2s.o loongson_dma.o
 obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PCI) += snd-soc-loongson-i2s-pci.o
 
+snd-soc-loongson-i2s-plat-y := loongson_i2s_plat.o loongson_i2s.o
+obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PLATFORM) += snd-soc-loongson-i2s-plat.o
+
 #Machine Support
 snd-soc-loongson-card-y := loongson_card.o
 obj-$(CONFIG_SND_SOC_LOONGSON_CARD) += snd-soc-loongson-card.o
sound/soc/loongson/loongson_i2s_plat.c new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
2.43.5
author maintainer
#35 lore raw

PATCH 9/10 LoongArch: dts: Add I2S support to Loongson-2K1000

In reply to Binbin Zhou

The module is supported, enable it.

Not all Loongson-2K1000 development boards have an i2s interface, here is an example of adding one:

sound {
	compatible = "loongson,ls-audio-card";
	model = "Loongson-ASoC";
	mclk-fs = <512>;

	cpu {
		sound-dai = <&i2s>;
	};

	codec {
		sound-dai = <&uda1342>;
	};
};
&apbdma2 {
	status = "okay";
};
&apbdma3 {
	status = "okay";
};
&i2c3 {
	status = "okay";

	pinctrl-0 = <&i2c1_pins_default>;
	pinctrl-names = "default";

	#address-cells = <1>;
	#size-cells = <0>;

	uda1342: codec@1a {
		compatible = "nxp,uda1342";
		reg = <0x1a>;
		#sound-dai-cells = <0>;
	};
};
&i2s {
	status = "okay";

	pinctrl-0 = <&hda_pins_default>;
	pinctrl-names = "default";
};
---
 arch/loongarch/boot/dts/loongson-2k1000.dtsi | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
arch/loongarch/boot/dts/loongson-2k1000.dtsi +15 -2
index 92180140eb56..8dff2aa52417 100644
@@ -266,7 +266,7 @@ dma-controller@1fe00c10 {
 			status = "disabled";
 		};
 
-		dma-controller@1fe00c20 {
+		apbdma2: dma-controller@1fe00c20 {
 			compatible = "loongson,ls2k1000-apbdma";
 			reg = <0x0 0x1fe00c20 0x0 0x8>;
 			interrupt-parent = <&liointc1>;
@@ -276,7 +276,7 @@ dma-controller@1fe00c20 {
 			status = "disabled";
 		};
 
-		dma-controller@1fe00c30 {
+		apbdma3: dma-controller@1fe00c30 {
 			compatible = "loongson,ls2k1000-apbdma";
 			reg = <0x0 0x1fe00c30 0x0 0x8>;
 			interrupt-parent = <&liointc1>;
@@ -352,6 +352,19 @@ rtc0: rtc@1fe27800 {
 			status = "disabled";
 		};
 
+		i2s: i2s@1fe2d000 {
+			compatible = "loongson,ls2k1000-i2s";
+			reg = <0 0x1fe2d000 0 0x14>,
+			      <0 0x1fe00438 0 0x8>;
+			interrupt-parent = <&liointc0>;
+			interrupts = <5 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk LOONGSON2_APB_CLK>;
+			dmas = <&apbdma2 0>, <&apbdma3 0>;
+			dma-names = "tx", "rx";
+			#sound-dai-cells = <0>;
+			status = "disabled";
+		};
+
 		spi0: spi@1fff0220 {
 			compatible = "loongson,ls2k1000-spi";
 			reg = <0x0 0x1fff0220 0x0 0x10>;
Signature · 1 line
2.43.5
author maintainer
#36 lore raw

PATCH 10/10 LoongArch: dts: Add I2S support to Loongson-2K2000

In reply to Binbin Zhou

The module is supported, enable it.

Not all Loongson-2K2000 development boards have an i2s interface, here is an example of adding one:

sound {
	compatible = "loongson,ls-audio-card";
	model = "Loongson-ASoC";
	mclk-fs = <512>;

	cpu {
		sound-dai = <&i2s>;
	};

	codec {
		sound-dai = <&es8323>;
	};
};
&i2c1 {
	status = "okay";
	#address-cells = <1>;
	#size-cells = <0>;

	es8323:es8323@10 {
		compatible = "everest,es8323";
		reg = <0x10>;
		#sound-dai-cells = <0>;
	};
};
&i2s {
	status = "okay";

	clock-frequency = <175000000>;
	#sound-dai-cells = <0>;

};

---
 arch/loongarch/boot/dts/loongson-2k2000.dtsi | 22 ++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
arch/loongarch/boot/dts/loongson-2k2000.dtsi +20 -2
index 0953c5707825..b4ff55a33e90 100644
@@ -173,6 +173,22 @@ rtc0: rtc@100d0100 {
 			status = "disabled";
 		};
 
+		i2c@1fe00120 {
+			compatible = "loongson,ls2k-i2c";
+			reg = <0x0 0x1fe00120 0x0 0x8>;
+			interrupt-parent = <&liointc>;
+			interrupts = <8 IRQ_TYPE_LEVEL_HIGH>;
+			status = "disabled";
+		};
+
+		i2c@1fe00130 {
+			compatible = "loongson,ls2k-i2c";
+			reg = <0x0 0x1fe00130 0x0 0x8>;
+			interrupt-parent = <&liointc>;
+			interrupts = <9 IRQ_TYPE_LEVEL_HIGH>;
+			status = "disabled";
+		};
+
 		uart0: serial@1fe001e0 {
 			compatible = "ns16550a";
 			reg = <0x0 0x1fe001e0 0x0 0x10>;
@@ -243,9 +259,11 @@ display@6,1 {
 				status = "disabled";
 			};
 
-			hda@7,0 {
+			i2s@7,0 {
 				reg = <0x3800 0x0 0x0 0x0 0x0>;
-				interrupts = <58 IRQ_TYPE_LEVEL_HIGH>;
+				interrupts = <78 IRQ_TYPE_LEVEL_HIGH>,
+					     <79 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-names = "tx", "rx";
 				interrupt-parent = <&pic>;
 				status = "disabled";
 			};
Signature · 1 line
2.43.5
#37 lore raw
In reply to Binbin Zhou
Quoted 11 lines · Binbin Zhou

Hi all:

This patch set is mainly about Loongson i2s related issues.

Please allow me to briefly explain this patch set:
Patch 1-2: Add ES8323 codec required on Loongson-2K2000 Patch 3-4: Add uda1342 codec required on Loongson-2K1000 Patch 5: Improve code readability
Patch 6: Fix the problem of unable to detect codec under FDT system. Patch 7-8: Add Loongson i2s platform device support
Patch 9-10: Related DTS support.

This was based on some old tree... or you do not use get_maintainers.pl.

Best regards,
Krzysztof

#38 lore raw
Quoted 14 lines · Krzysztof Kozlowski
Quoted 11 lines · Binbin Zhou

Hi all:

This patch set is mainly about Loongson i2s related issues.

Please allow me to briefly explain this patch set:
Patch 1-2: Add ES8323 codec required on Loongson-2K2000 Patch 3-4: Add uda1342 codec required on Loongson-2K1000 Patch 5: Improve code readability
Patch 6: Fix the problem of unable to detect codec under FDT system. Patch 7-8: Add Loongson i2s platform device support
Patch 9-10: Related DTS support.

Quoted 1 line

This was based on some old tree... or you do not use get_maintainers.pl.

Hi Krzysztof:

I used the following method to obtain the email address I need to copy:

scripts/get_maintainer.pl sound/soc/
Liam Girdwood <[email protected]> (supporter:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...)
Mark Brown <[email protected]> (supporter:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...)
Jaroslav Kysela <[email protected]> (maintainer:SOUND)
Takashi Iwai <[email protected]> (maintainer:SOUND) [email protected] (open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...)
[email protected] (open list)

The code repository from MAINTAINERS:

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git/log/?h=for-next
base commit: 097a44db5747403b19d05a9664e8ec6adba27e3b

Is there anything I'm missing, or where I'm going wrong?

Thanks.
Binbin

Quoted 4 lines

Best regards,
Krzysztof

#39 lore raw
Quoted 16 lines · Binbin Zhou
Quoted 14 lines · Krzysztof Kozlowski
Quoted 11 lines · Binbin Zhou

Hi all:

This patch set is mainly about Loongson i2s related issues.

Please allow me to briefly explain this patch set:
Patch 1-2: Add ES8323 codec required on Loongson-2K2000 Patch 3-4: Add uda1342 codec required on Loongson-2K1000 Patch 5: Improve code readability
Patch 6: Fix the problem of unable to detect codec under FDT system. Patch 7-8: Add Loongson i2s platform device support
Patch 9-10: Related DTS support.

Quoted 7 lines
Quoted 1 line

This was based on some old tree... or you do not use get_maintainers.pl.

Hi Krzysztof:

I used the following method to obtain the email address I need to copy:

scripts/get_maintainer.pl sound/soc/

That's not how you run get_maintainer.pl in typical process. You run it on the patches.

Quoted 10 lines

Liam Girdwood <[email protected]> (supporter:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...)
Mark Brown <[email protected]> (supporter:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...)
Jaroslav Kysela <[email protected]> (maintainer:SOUND)
Takashi Iwai <[email protected]> (maintainer:SOUND) [email protected] (open list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...)
[email protected] (open list)

Quoted 6 lines

The code repository from MAINTAINERS:

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git/log/?h=for-next
base commit: 097a44db5747403b19d05a9664e8ec6adba27e3b

Is there anything I'm missing, or where I'm going wrong?

Yeah, the list is incomplete and wrong emails are used.

Best regards,
Krzysztof

maintainer
#5 lore raw

Re: [PATCH v1 02/10] ASoC: codecs: Add support for ES8323

In reply to Binbin Zhou

On Thu, Sep 05, 2024 at 03:02:15PM +0800, Binbin Zhou wrote:

This looks like it was based on some *extremely* old code and needs quite a few updates to bring it up to modern standards.

Quoted 1 line

+ * Author: Mark Brown <[email protected]>

Oh?

sound/soc/codecs/es8323.c line 41

Quoted 8 lines
sound/soc/codecs/es8323.c new file +8 -0
+/*
+ * es8323 register cache
+ * We can't read the es8323 register space when we
+ * are using 2 wire for device control, so we cache them instead.
+ */
+static u16 es8323_reg[] = {
+	0x06, 0x1C, 0xC3, 0xFC,	/*  0 */
+	0xC0, 0x00, 0x00, 0x7C,	/*  4 */

There's a bunch of regmap reimplementation in the driver, the cache and I/O code all looks totally generic. Just use regmap.

sound/soc/codecs/es8323.c line 101

Quoted 5 lines
sound/soc/codecs/es8323.c new file +5 -0
+static const struct soc_enum es8323_enum[] = {
+	SOC_VALUE_ENUM_SINGLE(ES8323_DACCONTROL16, 3, 7, ARRAY_SIZE(es8323_line_texts),
+			      es8323_line_texts, es8323_line_values),	/* LLINE */
+	SOC_VALUE_ENUM_SINGLE(ES8323_DACCONTROL16, 0, 7, ARRAY_SIZE(es8323_line_texts),
+			      es8323_line_texts, es8323_line_values),	/* RLINE */

Use named variables for the enums rather than putting them into an array that's not otherwise used...

sound/soc/codecs/es8323.c line 123

Quoted 3 lines
sound/soc/codecs/es8323.c new file +3 -0
+static const struct snd_kcontrol_new es8323_snd_controls[] = {
+	SOC_ENUM("3D Mode", es8323_enum[4]),
+	SOC_ENUM("ALC Capture Function", es8323_enum[5]),

...it's *vastly* more readable and maintainable.

sound/soc/codecs/es8323.c line 133

Quoted 1 line
sound/soc/codecs/es8323.c new file +1 -0
+	SOC_SINGLE("Capture Mute", ES8323_ADC_MUTE, 2, 1, 0),

On/off switches should end in Switch, see control-names.rst.

sound/soc/codecs/es8323.c line 214

Quoted 2 lines
sound/soc/codecs/es8323.c new file +2 -0
+	/* gModify.Cmmt Implement when suspend/startup */
+	SND_SOC_DAPM_DAC("Right DAC", "Right Playback", SND_SOC_NOPM, 6, 1),

gModify.Cmmt?

sound/soc/codecs/es8323.c line 440

Quoted 5 lines
sound/soc/codecs/es8323.c new file +5 -0
+/*
+ * Note that this should be called from init rather than from hw_params.
+ */
+static int es8323_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+				 int clk_id, unsigned int freq, int dir)

Why?

sound/soc/codecs/es8323.c line 484

Quoted 6 lines
sound/soc/codecs/es8323.c new file +6 -0
+	/* set master/slave audio interface */
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBM_CFM:	/* MASTER MODE */
+		iface |= 0x80;
+		break;
+	case SND_SOC_DAIFMT_CBS_CFS:	/* SLAVE MODE */

Please use the modern naming with _CBP_CFP and so on.

Quoted 6 lines
sound/soc/codecs/es8323.c new file +6 -0
+static int es8323_mute(struct snd_soc_dai *dai, int mute,  int stream)
+{
+	struct snd_soc_component *component = dai->component;
+	struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component);
+
+	if (mute) {

sound/soc/codecs/es8323.c line 629

Quoted 10 lines
sound/soc/codecs/es8323.c new file +10 -0
+		es8323_set_gpio(ES8323_CODEC_SET_SPK,
+				!es8323->spk_gpio_level, es8323->spk_ctl_gpio);
+		usleep_range(2000, 3000);
+		snd_soc_component_write(component, ES8323_DAC_MUTE, 0x06);
+	} else {
+		snd_soc_component_write(component, ES8323_DAC_MUTE, 0x02);
+		usleep_range(2000, 3000);
+		if (!es8323->hp_inserted)
+			es8323_set_gpio(ES8323_CODEC_SET_SPK,
+					es8323->spk_gpio_level, es8323->spk_ctl_gpio);

This appears to be controlling the speaker based on jack detection. Unless there is some hardware restriction this should be done via DAPM and the user allowed to manage when the speaker is used depending on their use case.

sound/soc/codecs/es8323.c line 673

Quoted 7 lines
sound/soc/codecs/es8323.c new file +7 -0
+static int es8323_suspend(struct snd_soc_component *component)
+{
+	snd_soc_component_write(component, ES8323_DAC_MUTE, 0x06);
+	snd_soc_component_write(component, ES8323_LOUT1_VOL, 0x00);
+	snd_soc_component_write(component, ES8323_ROUT1_VOL, 0x00);
+	snd_soc_component_write(component, ES8323_LOUT2_VOL, 0x00);
+	snd_soc_component_write(component, ES8323_ROUT2_VOL, 0x00);

This will overwrite user settings when suspending, the controls should be unaffected by suspend. If the device needs this then use cache bypass to do the writes during suspend and resync the cache on resume.

sound/soc/codecs/es8323.c line 683

Quoted 3 lines
sound/soc/codecs/es8323.c new file +3 -0
+	snd_soc_component_write(component, ES8323_CONTROL1, 0x06);
+	snd_soc_component_write(component, ES8323_CONTROL2, 0x58);
+	usleep_range(18000, 20000);

Use fsleep().

sound/soc/codecs/es8323.c line 705

Quoted 10 lines
sound/soc/codecs/es8323.c new file +9 -0
+static void es8323_init_component_regs(struct snd_soc_component *component)
+{
 
+	snd_soc_component_write(component, ES8323_ADCCONTROL1, 0x88);
+	snd_soc_component_write(component, ES8323_ADCCONTROL2, 0xF0);
+	snd_soc_component_write(component, ES8323_ADCCONTROL3, 0x02);
+	snd_soc_component_write(component, ES8323_ADCCONTROL4, 0x0C);
+	snd_soc_component_write(component, ES8323_ADCCONTROL5, 0x02);
+	snd_soc_component_write(component, ES8323_LADC_VOL, 0x00);
+	snd_soc_component_write(component, ES8323_RADC_VOL, 0x00);

User visible controls should use the chip defaults as standard, userspace can configure what it needs and this avoids us worrying about individual use cases in the driver.

sound/soc/codecs/es8323.c line 732

Quoted 8 lines
sound/soc/codecs/es8323.c new file +8 -0
+static int es8323_resume(struct snd_soc_component *component)
+{
+	es8323_init_component_regs(component);
+	/* open dac output */
+	snd_soc_component_write(component, ES8323_DACPOWER, 0x3c);
+
+	return 0;
+}

This doesn't restore any user settings.

sound/soc/codecs/es8323.c line 789

Quoted 10 lines
sound/soc/codecs/es8323.c new file +10 -0
+static int es8323_i2c_probe(struct i2c_client *i2c)
+{
+	struct es8323_priv *es8323;
+	struct i2c_adapter *adapter = to_i2c_adapter(i2c->dev.parent);
+
+	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
+		dev_warn(&adapter->dev,
+			 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
+		return -EIO;
+	}

Does the device really need this? It seems to be doing very basic I/O which should be SMBus compatible. In any case when you move to regmap this should be redundant.

maintainer
#14 lore raw

Re: [PATCH v1 04/10] ASoC: codecs: Add uda1342 codec driver

In reply to Binbin Zhou
Quoted 2 lines · Binbin Zhou

The UDA1342 is an NXP audio codec, support 2x Stereo audio ADC (4x PGA mic inputs), stereo audio DAC, with basic audio processing.

This looks basically fine overall, there's some issues below but they're mostly fairly small and stylistic rather than anything major.

sound/soc/codecs/uda1342.c line 3

Quoted 6 lines
sound/soc/codecs/uda1342.c new file +3 -0
@@ -0,0 +1,397 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * uda1342.c  --  UDA1342 ALSA SoC Codec driver

Please keep the entire comment a C++ one so things look more intentional.

sound/soc/codecs/uda1342.c line 64

Quoted 8 lines
sound/soc/codecs/uda1342.c new file +8 -0
+static int uda1342_mute(struct snd_soc_dai *dai, int mute, int direction)
+{
+	struct snd_soc_component *component = dai->component;
+	struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
+	unsigned int mask;
+	unsigned int val = 0;
+
+	dev_info(&uda1342->i2c->dev, "mute: %d\n", mute);

This is far too noisy to be logged and will DoS the logs, please just remove it.

sound/soc/codecs/uda1342.c line 68

Quoted 4 lines
sound/soc/codecs/uda1342.c new file +4 -0
+
+	/* Master mute */
+	mask = BIT(5);
+	val = mute ? mask : 0;

Please use normal conditional statements to improve legibility.

sound/soc/codecs/uda1342.c line 104

Quoted 8 lines
sound/soc/codecs/uda1342.c new file +8 -0
+static void uda1342_shutdown(struct snd_pcm_substream *substream,
+			     struct snd_soc_dai *dai)
+{
+	struct snd_soc_component *component = dai->component;
+	struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
+
+	if (uda1342->master_substream == substream)
+		uda1342->master_substream = uda1342->slave_substream;

Please avoid using master/slave terminology, we've tended to go for provider/consumer in ASoC.

sound/soc/codecs/uda1342.c line 120

Quoted 12 lines
sound/soc/codecs/uda1342.c new file +12 -0
+static int uda1342_hw_params(struct snd_pcm_substream *substream,
+			     struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+	struct snd_soc_component *component = dai->component;
+	struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
+	struct device *dev = &uda1342->i2c->dev;
+	unsigned int hw_params = 0;
+
+	if (substream == uda1342->slave_substream) {
+		dev_info(dev, "ignoring hw_params for slave substream\n");
+		return 0;
+	}

This is also too noisy, it should be _dbg() at most.

sound/soc/codecs/uda1342.c line 201

Quoted 5 lines
sound/soc/codecs/uda1342.c new file +5 -0
+	/* codec supports only full slave mode */
+	if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
+		dev_err(dev, "unsupported slave mode.\n");
+		return -EINVAL;
+	}

Use the more modern _CBC_CFC.

sound/soc/codecs/uda1342.c line 207

Quoted 5 lines
sound/soc/codecs/uda1342.c new file +5 -0
+	/*
+	 * We can't setup DAI format here as it depends on the word bit num,
+	 * so let's just store the value for later
+	 */
+	uda1342->dai_fmt = fmt;

No need to even store it if only one value is supported.

Quoted 6 lines
sound/soc/codecs/uda1342.c new file +6 -0
+static int uda1342_set_bias_level(struct snd_soc_component *component,
+				  enum snd_soc_bias_level level)
+{
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		break;

sound/soc/codecs/uda1342.c line 227

Quoted 10 lines
sound/soc/codecs/uda1342.c new file +10 -0
+	case SND_SOC_BIAS_PREPARE:
+		break;
+	case SND_SOC_BIAS_STANDBY:
+		break;
+	case SND_SOC_BIAS_OFF:
+		break;
+	}
+
+	return 0;
+}

This does nothing so it can just be removed.

sound/soc/codecs/uda1342.c line 235

Quoted 4 lines
sound/soc/codecs/uda1342.c new file +4 -0
+static const struct soc_enum uda1342_mixer_enum[] = {
+	SOC_ENUM_SINGLE(0x10, 3, 0x04, uda1342_deemph),
+	SOC_ENUM_SINGLE(0x10, 0, 0x04, uda1342_mixmode),
+};

This doesn't seem to be referenced anywhere so can be removed, or should be added to the controls or DAPM?

sound/soc/codecs/uda1342.c line 305

Quoted 10 lines
sound/soc/codecs/uda1342.c new file +10 -0
+static int uda1342_soc_probe(struct snd_soc_component *component)
+{
+	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
+
+	snd_soc_add_component_controls(component, uda1342_snd_controls,
+				       ARRAY_SIZE(uda1342_snd_controls));
+	snd_soc_dapm_new_controls(dapm, uda1342_dapm_widgets,
+				  ARRAY_SIZE(uda1342_dapm_widgets));
+	snd_soc_dapm_add_routes(dapm, uda1342_dapm_routes,
+				ARRAY_SIZE(uda1342_dapm_routes));

You can point to these arrays from the component struct and have the core register them for you.

sound/soc/codecs/uda1342.c line 325

Quoted 7 lines
sound/soc/codecs/uda1342.c new file +7 -0
+static const struct regmap_config uda1342_regmap = {
+	.reg_bits = 8,
+	.val_bits = 16,
+	.max_register = 0x21,
+	.reg_defaults = uda1342_reg_defaults,
+	.num_reg_defaults = ARRAY_SIZE(uda1342_reg_defaults),
+	.cache_type = REGCACHE_RBTREE,

In general _MAPLE is preferred for new things unless you have a specific reason to use _RBTREE, it uses a more modern data structure and should generally do better.

maintainer
#18 lore raw

Re: [PATCH v1 05/10] ASoC: loongson: Improve code readability

In reply to Binbin Zhou
Quoted 6 lines · Binbin Zhou

This patch attempts to clean up driver code formatting issues. Mainly as follows:
1. Use the BIT macro;
2. Use dev_err_probe() in every error path in probe in loongson_card driver;
3. Introduce loongson_card_acpi_find_device() to streamlined code.

Please split these out into three separate patches to make them easier to review. I see there's also some other code reordering and reformatting in there which should also be split out separately. I think the changes are probably good overall but there's too much different stuff going on in one patch to check properly.

maintainer
#28 lore raw

Re: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device

In reply to Binbin Zhou
Quoted 4 lines · Binbin Zhou

The Loongson I2S controller exists not only in PCI form (LS7A bridge chip), but also in platform device form (Loongson-2K1000 SoC).

This patch adds support for platform device I2S controller.

Can some of this be shared with the PCI version - is it the same IP in a different wrapper, or is it a new IP?

#10 lore raw

Re: [PATCH v1 02/10] ASoC: codecs: Add support for ES8323

In reply to Binbin Zhou
kernel test robot noticed the following build warnings:

Hi Binbin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 097a44db5747403b19d05a9664e8ec6adba27e3b]

url:    https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/ASoC-dt-bindings-Add-Everest-ES8323-Codec/20240905-150958
base:   097a44db5747403b19d05a9664e8ec6adba27e3b
patch link:    https://lore.kernel.org/r/c44a6525d77941ef235825a58a9ea91f9f7d7042.1725518229.git.zhoubinbin%40loongson.cn
patch subject: [PATCH v1 02/10] ASoC: codecs: Add support for ES8323
config: parisc-randconfig-r071-20240906 (https://download.01.org/0day-ci/archive/20240906/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240906/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> sound/soc/codecs/es8323.c:173:38: warning: 'es8323_right_pga_controls' defined but not used [-Wunused-const-variable=]
     173 | static const struct snd_kcontrol_new es8323_right_pga_controls =
         |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from include/sound/tlv.h:10,
                    from sound/soc/codecs/es8323.c:25:
>> sound/soc/codecs/es8323.c:114:35: warning: 'pga_tlv' defined but not used [-Wunused-const-variable=]
     114 | static const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 300, 0);
         |                                   ^~~~~~~
   include/uapi/sound/tlv.h:53:22: note: in definition of macro 'SNDRV_CTL_TLVD_DECLARE_DB_SCALE'
      53 |         unsigned int name[] = { \
         |                      ^~~~
   sound/soc/codecs/es8323.c:114:14: note: in expansion of macro 'DECLARE_TLV_DB_SCALE'
     114 | static const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 300, 0);
         |              ^~~~~~~~~~~~~~~~~~~~

vim +/es8323_right_pga_controls +173 sound/soc/codecs/es8323.c

113

 > 114	static const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 300, 0);
   115	static const DECLARE_TLV_DB_SCALE(adc_tlv, -9600, 50, 1);
   116	static const DECLARE_TLV_DB_SCALE(dac_tlv, -9600, 50, 1);
   117	static const DECLARE_TLV_DB_SCALE(out_tlv, -4500, 150, 0);
   118	static const DECLARE_TLV_DB_SCALE(bypass_tlv, 0, 300, 0);
   119	static const DECLARE_TLV_DB_SCALE(bypass_tlv2, -15, 300, 0);
   120	
   121	static const struct snd_kcontrol_new es8323_snd_controls[] = {
   122		SOC_ENUM("3D Mode", es8323_enum[4]),
   123		SOC_ENUM("ALC Capture Function", es8323_enum[5]),
   124		SOC_SINGLE("ALC Capture ZC Switch", ES8323_ADCCONTROL13, 6, 1, 0),
   125		SOC_SINGLE("ALC Capture Decay Time", ES8323_ADCCONTROL12, 4, 15, 0),
   126		SOC_SINGLE("ALC Capture Attack Time", ES8323_ADCCONTROL12, 0, 15, 0),
   127		SOC_SINGLE("ALC Capture NG Threshold", ES8323_ADCCONTROL14, 3, 31, 0),
   128		SOC_ENUM("ALC Capture NG Type", es8323_enum[6]),
   129		SOC_SINGLE("ALC Capture NG Switch", ES8323_ADCCONTROL14, 0, 1, 0),
   130		SOC_SINGLE("ZC Timeout Switch", ES8323_ADCCONTROL13, 6, 1, 0),
   131		SOC_DOUBLE_R_TLV("Capture Digital Volume", ES8323_LADC_VOL,
   132				 ES8323_RADC_VOL, 0, 192, 1, adc_tlv),
   133		SOC_SINGLE("Capture Mute", ES8323_ADC_MUTE, 2, 1, 0),
   134		SOC_SINGLE_TLV("Left Channel Capture Volume", ES8323_ADCCONTROL1, 4, 8,
   135			       0, bypass_tlv),
   136		SOC_SINGLE_TLV("Right Channel Capture Volume", ES8323_ADCCONTROL1, 0,
   137			       8, 0, bypass_tlv),
   138		SOC_ENUM("Playback De-emphasis", es8323_enum[7]),
   139		SOC_ENUM("Capture Polarity", es8323_enum[8]),
   140		SOC_DOUBLE_R_TLV("PCM Volume", ES8323_LDAC_VOL, ES8323_RDAC_VOL,
   141				 0, 192, 1, dac_tlv),
   142		SOC_SINGLE_TLV("Left Mixer Left Bypass Volume", ES8323_DACCONTROL17, 3,
   143			       7, 1, bypass_tlv2),
   144		SOC_SINGLE_TLV("Right Mixer Right Bypass Volume", ES8323_DACCONTROL20,
   145			       3, 7, 1, bypass_tlv2),
   146		SOC_DOUBLE_R_TLV("Output 1 Playback Volume", ES8323_LOUT1_VOL,
   147				 ES8323_ROUT1_VOL, 0, 33, 0, out_tlv),
   148		SOC_DOUBLE_R_TLV("Output 2 Playback Volume", ES8323_LOUT2_VOL,
   149				 ES8323_ROUT2_VOL, 0, 33, 0, out_tlv),
   150	};
   151	
   152	static const struct snd_kcontrol_new es8323_left_dac_mux_controls =
   153		SOC_DAPM_ENUM("Route", es8323_left_dac_enum);
   154	
   155	static const struct snd_kcontrol_new es8323_right_dac_mux_controls =
   156		SOC_DAPM_ENUM("Route", es8323_right_dac_enum);
   157	
   158	static const struct snd_kcontrol_new es8323_left_line_controls =
   159		SOC_DAPM_ENUM("LLIN Mux", es8323_llin_enum);
   160	
   161	static const struct snd_kcontrol_new es8323_right_line_controls =
   162		SOC_DAPM_ENUM("RLIN Mux", es8323_rlin_enum);
   163	
   164	/* Differential Mux */
   165	static const struct snd_kcontrol_new es8323_diffmux_controls =
   166		SOC_DAPM_ENUM("Route2", es8323_diff_enum);
   167	
   168	/* Mono ADC Mux */
   169	static const struct snd_kcontrol_new es8323_monomux_controls =
   170		SOC_DAPM_ENUM("Mono Mux", es8323_mono_enum);
   171	
   172	/* Right PGA Mux */
 > 173	static const struct snd_kcontrol_new es8323_right_pga_controls =

174 SOC_DAPM_ENUM("Route", es8323_enum[3]);
175

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#31 lore raw

Re: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device

In reply to Binbin Zhou
kernel test robot noticed the following build errors:

Hi Binbin,

kernel test robot noticed the following build errors:

[auto build test ERROR on 097a44db5747403b19d05a9664e8ec6adba27e3b]

url:    https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/ASoC-dt-bindings-Add-Everest-ES8323-Codec/20240905-150958
base:   097a44db5747403b19d05a9664e8ec6adba27e3b
patch link:    https://lore.kernel.org/r/282dadefdaac7917fd681a6e84a5f0f07d0557bc.1725518229.git.zhoubinbin%40loongson.cn
patch subject: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20240906/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240906/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

>> sound/soc/loongson/loongson_i2s_pci.c:157:1: warning: data definition has no type or storage class
     157 | module_pci_driver(loongson_i2s_driver);
         | ^~~~~~~~~~~~~~~~~
>> sound/soc/loongson/loongson_i2s_pci.c:157:1: error: type defaults to 'int' in declaration of 'module_pci_driver' [-Wimplicit-int]
>> sound/soc/loongson/loongson_i2s_pci.c:157:1: error: parameter names (without types) in function declaration [-Wdeclaration-missing-parameter-type]
>> sound/soc/loongson/loongson_i2s_pci.c:149:26: warning: 'loongson_i2s_driver' defined but not used [-Wunused-variable]
     149 | static struct pci_driver loongson_i2s_driver = {
         |                          ^~~~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for SND_SOC_LOONGSON_I2S_PCI
Depends on [n]: SOUND [=m] && SND [=m] && SND_SOC [=m] && (LOONGARCH || COMPILE_TEST [=y]) && PCI [=n] Selected by [m]:
- SND_SOC_LOONGSON_CARD [=m] && SOUND [=m] && SND [=m] && SND_SOC [=m] && (LOONGARCH || COMPILE_TEST [=y])

vim +/loongson_i2s_driver +149 sound/soc/loongson/loongson_i2s_pci.c

d84881e06836dc1 Yingkun Meng 2023-06-15 148

d84881e06836dc1 Yingkun Meng 2023-06-15 @149  static struct pci_driver loongson_i2s_driver = {
d84881e06836dc1 Yingkun Meng 2023-06-15  150  	.name = "loongson-i2s-pci",
d84881e06836dc1 Yingkun Meng 2023-06-15  151  	.id_table = loongson_i2s_ids,
d84881e06836dc1 Yingkun Meng 2023-06-15  152  	.probe = loongson_i2s_pci_probe,
d84881e06836dc1 Yingkun Meng 2023-06-15  153  	.driver = {
d84881e06836dc1 Yingkun Meng 2023-06-15  154  		.pm = pm_sleep_ptr(&loongson_i2s_pm),
d84881e06836dc1 Yingkun Meng 2023-06-15  155  	},
d84881e06836dc1 Yingkun Meng 2023-06-15  156  };
d84881e06836dc1 Yingkun Meng 2023-06-15 @157  module_pci_driver(loongson_i2s_driver);

d84881e06836dc1 Yingkun Meng 2023-06-15 158

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#16 lore raw

Re: [PATCH v1 04/10] ASoC: codecs: Add uda1342 codec driver

In reply to Binbin Zhou
kernel test robot noticed the following build warnings:

Hi Binbin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 097a44db5747403b19d05a9664e8ec6adba27e3b]

url:    https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/ASoC-dt-bindings-Add-Everest-ES8323-Codec/20240905-150958
base:   097a44db5747403b19d05a9664e8ec6adba27e3b
patch link:    https://lore.kernel.org/r/3fd0c3a04f5f3bd293168732db457f6854db706e.1725518229.git.zhoubinbin%40loongson.cn
patch subject: [PATCH v1 04/10] ASoC: codecs: Add uda1342 codec driver
config: parisc-randconfig-r071-20240906 (https://download.01.org/0day-ci/archive/20240906/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240906/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

sound/soc/codecs/uda1342.c: In function 'uda1342_i2c_probe':

>> sound/soc/codecs/uda1342.c:331:13: warning: unused variable 'ret' [-Wunused-variable]
     331 |         int ret;
         |             ^~~
   sound/soc/codecs/uda1342.c: At top level:
>> sound/soc/codecs/uda1342.c:358:12: warning: 'uda1342_resume' defined but not used [-Wunused-function]
     358 | static int uda1342_resume(struct device *dev)
         |            ^~~~~~~~~~~~~~
>> sound/soc/codecs/uda1342.c:349:12: warning: 'uda1342_suspend' defined but not used [-Wunused-function]
     349 | static int uda1342_suspend(struct device *dev)
         |            ^~~~~~~~~~~~~~~
>> sound/soc/codecs/uda1342.c:232:30: warning: 'uda1342_mixer_enum' defined but not used [-Wunused-const-variable=]
     232 | static const struct soc_enum uda1342_mixer_enum[] = {
         |                              ^~~~~~~~~~~~~~~~~~

vim +/ret +331 sound/soc/codecs/uda1342.c

231

 > 232	static const struct soc_enum uda1342_mixer_enum[] = {
   233		SOC_ENUM_SINGLE(0x10, 3, 0x04, uda1342_deemph),
   234		SOC_ENUM_SINGLE(0x10, 0, 0x04, uda1342_mixmode),
   235	};
   236	
   237	static const struct snd_kcontrol_new uda1342_snd_controls[] = {
   238		SOC_SINGLE("Master Playback Volume", 0x11, 0, 0x3F, 1),
   239		SOC_SINGLE("Analog1 Volume", 0x12, 0, 0x1F, 1),
   240	};
   241	
   242	/* Common DAPM widgets */
   243	static const struct snd_soc_dapm_widget uda1342_dapm_widgets[] = {
   244		SND_SOC_DAPM_INPUT("VINL1"),
   245		SND_SOC_DAPM_INPUT("VINR1"),
   246		SND_SOC_DAPM_INPUT("VINL2"),
   247		SND_SOC_DAPM_INPUT("VINR2"),
   248	
   249		SND_SOC_DAPM_DAC("DAC", "Playback", 0, 1, 0),
   250		SND_SOC_DAPM_ADC("ADC", "Capture", 0, 9, 0),
   251	
   252		SND_SOC_DAPM_OUTPUT("VOUTL"),
   253		SND_SOC_DAPM_OUTPUT("VOUTR"),
   254	};
   255	
   256	static const struct snd_soc_dapm_route uda1342_dapm_routes[] = {
   257		{ "ADC", NULL, "VINL1" },
   258		{ "ADC", NULL, "VINR1" },
   259		{ "ADC", NULL, "VINL2" },
   260		{ "ADC", NULL, "VINR2" },
   261		{ "VOUTL", NULL, "DAC" },
   262		{ "VOUTR", NULL, "DAC" },
   263	};
   264	
   265	static const struct snd_soc_dai_ops uda1342_dai_ops = {
   266		.startup	= uda1342_startup,
   267		.shutdown	= uda1342_shutdown,
   268		.hw_params	= uda1342_hw_params,
   269		.mute_stream	= uda1342_mute,
   270		.set_sysclk	= uda1342_set_dai_sysclk,
   271		.set_fmt	= uda1342_set_dai_fmt,
   272	};
   273	
   274	static struct snd_soc_dai_driver uda1342_dai = {
   275		.name = "uda1342-hifi",
   276		/* playback capabilities */
   277		.playback = {
   278			.stream_name = "Playback",
   279			.channels_min = 1,
   280			.channels_max = 2,
   281			.rates = SNDRV_PCM_RATE_8000_48000,
   282			.formats = UDA134X_FORMATS,
   283		},
   284		/* capture capabilities */
   285		.capture = {
   286			.stream_name = "Capture",
   287			.channels_min = 1,
   288			.channels_max = 2,
   289			.rates = SNDRV_PCM_RATE_8000_48000,
   290			.formats = UDA134X_FORMATS,
   291		},
   292		/* pcm operations */
   293		.ops = &uda1342_dai_ops,
   294	};
   295	
   296	static int uda1342_soc_probe(struct snd_soc_component *component)
   297	{
   298		struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
   299	
   300		snd_soc_add_component_controls(component, uda1342_snd_controls,
   301					       ARRAY_SIZE(uda1342_snd_controls));
   302		snd_soc_dapm_new_controls(dapm, uda1342_dapm_widgets,
   303					  ARRAY_SIZE(uda1342_dapm_widgets));
   304		snd_soc_dapm_add_routes(dapm, uda1342_dapm_routes,
   305					ARRAY_SIZE(uda1342_dapm_routes));
   306	
   307		return 0;
   308	}
   309	
   310	static const struct snd_soc_component_driver soc_component_dev_uda1342 = {
   311		.probe			= uda1342_soc_probe,
   312		.set_bias_level		= uda1342_set_bias_level,
   313		.suspend_bias_off	= 1,
   314		.idle_bias_on		= 1,
   315		.use_pmdown_time	= 1,
   316		.endianness		= 1,
   317	};
   318	
   319	static const struct regmap_config uda1342_regmap = {
   320		.reg_bits = 8,
   321		.val_bits = 16,
   322		.max_register = 0x21,
   323		.reg_defaults = uda1342_reg_defaults,
   324		.num_reg_defaults = ARRAY_SIZE(uda1342_reg_defaults),
   325		.cache_type = REGCACHE_RBTREE,
   326	};
   327	
   328	static int uda1342_i2c_probe(struct i2c_client *i2c)
   329	{
   330		struct uda1342_priv *uda1342;
 > 331		int ret;
   332	
   333		uda1342 = devm_kzalloc(&i2c->dev, sizeof(*uda1342), GFP_KERNEL);
   334		if (!uda1342)
   335			return -ENOMEM;
   336	
   337		uda1342->regmap = devm_regmap_init_i2c(i2c, &uda1342_regmap);
   338		if (IS_ERR(uda1342->regmap))
   339			return PTR_ERR(uda1342->regmap);
   340	
   341		i2c_set_clientdata(i2c, uda1342);
   342		uda1342->i2c = i2c;
   343	
   344		return devm_snd_soc_register_component(&i2c->dev,
   345						       &soc_component_dev_uda1342,
   346						       &uda1342_dai, 1);
   347	}
   348	
 > 349	static int uda1342_suspend(struct device *dev)
   350	{
   351		struct uda1342_priv *uda1342 = dev_get_drvdata(dev);
   352	
   353		regcache_cache_only(uda1342->regmap, true);
   354	
   355		return 0;
   356	}
   357	
 > 358	static int uda1342_resume(struct device *dev)

359 {
360 struct uda1342_priv *uda1342 = dev_get_drvdata(dev);
361
362 regcache_mark_dirty(uda1342->regmap);
363 regcache_sync(uda1342->regmap);
364
365 return 0;
366 }
367

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#32 lore raw

Re: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device

In reply to Binbin Zhou
kernel test robot noticed the following build warnings:

Hi Binbin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 097a44db5747403b19d05a9664e8ec6adba27e3b]

url:    https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/ASoC-dt-bindings-Add-Everest-ES8323-Codec/20240905-150958
base:   097a44db5747403b19d05a9664e8ec6adba27e3b
patch link:    https://lore.kernel.org/r/282dadefdaac7917fd681a6e84a5f0f07d0557bc.1725518229.git.zhoubinbin%40loongson.cn
patch subject: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device
config: i386-kismet-CONFIG_SND_SOC_LOONGSON_I2S_PCI-CONFIG_SND_SOC_LOONGSON_CARD-0-0 (https://download.01.org/0day-ci/archive/20240906/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20240906/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for SND_SOC_LOONGSON_I2S_PCI when selected by SND_SOC_LOONGSON_CARD

WARNING: unmet direct dependencies detected for SND_SOC_LOONGSON_I2S_PCI
Depends on [n]: SOUND [=y] && SND [=y] && SND_SOC [=y] && (LOONGARCH || COMPILE_TEST [=y]) && PCI [=n] Selected by [y]:
- SND_SOC_LOONGSON_CARD [=y] && SOUND [=y] && SND [=y] && SND_SOC [=y] && (LOONGARCH || COMPILE_TEST [=y])

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw

Re: [PATCH v1 01/10] ASoC: dt-bindings: Add Everest ES8323 Codec

In reply to Binbin Zhou
Quoted 35 lines · Binbin Zhou

Add Everest Semiconductor ES8316 low power audio CODEC binding with DT schema format using json-schema.

---
 .../bindings/sound/everest,es8323.yaml        | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/everest,es8323.yaml
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +20 -0
new file mode 100644
index 000000000000..0450d0f49d03
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/everest,es8323.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Everest ES8323 audio CODECs
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: everest,es8323
+
+  reg:
+    maxItems: 1

Documentation/devicetree/bindings/sound/everest,es8323.yaml line 30

Quoted 10 lines
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +10 -0
+
+  clocks:
+    description: clock for master clock (MCLK)
+    maxItems: 1
+
+  clock-names:
+    const: mclk
+
+  '#sound-dai-cells':
+    const: 0

No audio-graph-port? Are you sure? It looks exactly like everest,es8316...

Quoted 7 lines
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +7 -0
+
+required:
+  - compatible
+  - reg
+  - '#sound-dai-cells'
+
+unevaluatedProperties: false

Documentation/devicetree/bindings/sound/everest,es8323.yaml line 47

Quoted 10 lines
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +10 -0
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      codec@10 {
+        compatible = "everest,es8323";
+        reg = <0x10>;
+        #sound-dai-cells = <0>;

Make the example complete. Assuming this binding stays...

Best regards,
Krzysztof

Reviewed-by on v1 3/10
#12 lore raw

Re: [PATCH v1 03/10] ASoC: dt-bindings: Add NXP uda1342 Codec

In reply to Binbin Zhou
Quoted 7 lines · Binbin Zhou

Add NXP uda1342 CODEC binding with DT schema format using json-schema.

---
 .../bindings/sound/nxp,uda1342.yaml           | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nxp,uda1342.yaml

Best regards,
Krzysztof

#25 lore raw

Re: [PATCH v1 07/10] ASoC: dt-bindings: Add Loongson I2S controller

In reply to Binbin Zhou

Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml

Quoted 14 lines · Binbin Zhou

Add Loongson I2S controller binding with DT schema format using json-schema.

---
 .../bindings/sound/loongson,ls2k-i2s.yaml     | 66 +++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +0 -0
new file mode 100644
index 000000000000..a2e3bbe00dab

Filename matching compatible.

Quoted 11 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +10 -0
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/loongson,ls2k-i2s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson-2K I2S controller
+
+maintainers:
+  - Binbin Zhou <[email protected]>

Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml line 20

Quoted 10 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +10 -0
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: loongson,ls2k1000-i2s
+
+  reg:
+    maxItems: 2

List and describe items instead.

Quoted 18 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +18 -0
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  dmas:
+    maxItems: 2
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  '#sound-dai-cells':
+    const: 0
+

Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml line 48

Quoted 10 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +10 -0
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - dmas
+  - dma-names
+  - '#sound-dai-cells'
+
+additionalProperties: false

Instead:
unevaluatedProperties: false

Best regards,
Krzysztof

#21 lore raw

Re: [PATCH v1 06/10] ASoC: loongson: Fix codec detection failure on FDT systems

In reply to Binbin Zhou
Quoted 32 lines · Binbin Zhou

When the Codec is compiled into a module, we can't use snd_soc_of_get_dlc() to get the codec dai_name, use snd_soc_get_dai_name() instead.

Also, for the cpu dailink, its dai_name is already defined as "loongson-i2s", so just get the corresponding of_node attribute here.

---
 sound/soc/loongson/loongson_card.c | 89 +++++++++++++++++++++---------
 1 file changed, 63 insertions(+), 26 deletions(-)
sound/soc/loongson/loongson_card.c +3 -6
index a25287efdd5c..d45a3e77cb90 100644
@@ -119,44 +119,81 @@ static int loongson_card_parse_acpi(struct loongson_card_data *data)
 	return 0;
 }
 
-static int loongson_card_parse_of(struct loongson_card_data *data)
+static int loongson_parse_cpu(struct device *dev, struct device_node **dai_node)
 {
-	struct snd_soc_card *card = &data->snd_card;
-	struct device_node *cpu, *codec;
-	struct device *dev = card->dev;
-	int ret, i;
+	struct device_node *cpu;
+	int ret = 0;
 
 	cpu = of_get_child_by_name(dev->of_node, "cpu");
-	if (!cpu) {

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 135

Quoted 10 lines
sound/soc/loongson/loongson_card.c +7 -2
-		dev_err(dev, "platform property missing or invalid\n");
+	if (!cpu)
 		return -EINVAL;
-	}
+
+	*dai_node = of_parse_phandle(cpu, "sound-dai", 0);
+	if (!*dai_node)
+		ret = -EINVAL;
+
+	of_node_put(cpu);

This goes just after of_parse_phandle, which simplifies your code.

Quoted 4 lines
sound/soc/loongson/loongson_card.c +4 -0
+	return ret;
+}
+
+static int loongson_parse_codec(struct device *dev, struct device_node **dai_node,

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 147

Quoted 10 lines
sound/soc/loongson/loongson_card.c +6 -2
+				const char **dai_name)
+{
+	struct of_phandle_args args;
+	struct device_node *codec;
+	int ret = 0;
 
 	codec = of_get_child_by_name(dev->of_node, "codec");
-	if (!codec) {
-		dev_err(dev, "audio-codec property missing or invalid\n");
+	if (!codec)

Hm? So you exit here and then caller does of_node_put on stack value. This is buggy.

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 155

Quoted 8 lines
sound/soc/loongson/loongson_card.c +8 -0
+		return -EINVAL;
+
+	ret = of_parse_phandle_with_args(codec, "sound-dai", "#sound-dai-cells", 0, &args);
+	if (ret)
+		goto free_codec;
+
+	ret = snd_soc_get_dai_name(&args, dai_name);
+	if (ret)

Your error paths should clean here. Each function is responsible to clean up after itself in case of errors, not rely on caller.

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 162

Quoted 8 lines
sound/soc/loongson/loongson_card.c +6 -1
+		goto free_codec;
+
+	*dai_node = of_parse_phandle(codec, "sound-dai", 0);
+	if (!*dai_node)
 		ret = -EINVAL;
-		goto free_cpu;
+
+free_codec:

You are not freeing any resources here (at least not directly). You are dropping reference. Use matching label name. free is associated with kalloc()..

Quoted 38 lines
sound/soc/loongson/loongson_card.c +24 -11
+	of_node_put(codec);
+	return ret;
+}
+
+static int loongson_card_parse_of(struct loongson_card_data *data)
+{
+	struct device_node *codec_dai_node, *cpu_dai_node;
+	struct snd_soc_card *card = &data->snd_card;
+	struct device *dev = card->dev;
+	const char *codec_dai_name;
+	int ret = 0, i;
+
+	ret = loongson_parse_cpu(dev, &cpu_dai_node);
+	if (ret) {
+		dev_err(dev, "cpu property missing or invalid.\n");
+		goto out;
+	}
+
+	ret = loongson_parse_codec(dev, &codec_dai_node, &codec_dai_name);
+	if (ret) {
+		dev_err(dev, "audio-codec property missing or invalid.\n");
+		goto out;
 	}
 
 	for (i = 0; i < card->num_links; i++) {
-		ret = snd_soc_of_get_dlc(cpu, NULL, loongson_dai_links[i].cpus, 0);
-		if (ret) {
-			dev_err(dev, "getting cpu dlc error (%d)\n", ret);
-			goto free_codec;
-		}
-
-		ret = snd_soc_of_get_dlc(codec, NULL, loongson_dai_links[i].codecs, 0);
-		if (ret) {
-			dev_err(dev, "getting codec dlc error (%d)\n", ret);
-			goto free_codec;
-		}
+		loongson_dai_links[i].platforms->of_node = cpu_dai_node;
+		loongson_dai_links[i].cpus->of_node = cpu_dai_node;

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 195

Quoted 10 lines
sound/soc/loongson/loongson_card.c +4 -4
+		loongson_dai_links[i].codecs->of_node = codec_dai_node;
+		loongson_dai_links[i].codecs->dai_name = codec_dai_name;
 	}
 
-free_codec:
-	of_node_put(codec);
-free_cpu:
-	of_node_put(cpu);
+out:
+	of_node_put(codec_dai_node);

Yeah, so here we see drop of reference from stack-based pointer...

Best regards,
Krzysztof

#33 lore raw

Re: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device

In reply to Binbin Zhou

Hi Binbin,

Quoted 6 lines · Binbin Zhou

The Loongson I2S controller exists not only in PCI form (LS7A bridge chip), but also in platform device form (Loongson-2K1000 SoC).

This patch adds support for platform device I2S controller.

Thanks for your patch!

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 17

Quoted 8 lines
sound/soc/loongson/Kconfig +2 -0
@@ -13,10 +13,20 @@ config SND_SOC_LOONGSON_I2S_PCI
          The controller is found in loongson bridge chips or SoCs,
          and work as a PCI device.
 
+config SND_SOC_LOONGSON_I2S_PLATFORM
+       tristate "Loongson I2S controller as platform device"

depends on LOONGARCH || COMPILE_TEST

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 19

Quoted 12 lines
sound/soc/loongson/Kconfig +8 -1
+       select SND_SOC_GENERIC_DMAENGINE_PCM
+       help
+         Say Y or M if you want to add support for I2S driver for
+         Loongson I2S controller.
+
+         The controller work as a platform device, found in loongson
+         SoCs.
+
 config SND_SOC_LOONGSON_CARD
        tristate "Loongson Sound Card Driver"
        select SND_SOC_LOONGSON_I2S_PCI
-       depends on PCI

"select SND_SOC_LOONGSON_I2S_PCI if PCI"?

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 29

Quoted 1 line
sound/soc/loongson/Kconfig +1 -0
+       select SND_SOC_LOONGSON_I2S_PLATFORM

Or perhaps do it the other way around, i,e. let SND_SOC_LOONGSON_I2S_{PCI,PLATFORM} select SND_SOC_LOONGSON_CARD? That would be similar to SPI_LOONGSON_{PCI,PLATFORM}, which select SPI_LOONGSON_CORE.

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 32

Quoted 3 lines
sound/soc/loongson/Kconfig +0 -0
        help
          Say Y or M if you want to add support for SoC audio using
          loongson I2S controller.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#19 lore raw

Re: [PATCH v1 05/10] ASoC: loongson: Improve code readability

In reply to Mark Brown
Quoted 9 lines · Mark Brown
Quoted 6 lines · Binbin Zhou

This patch attempts to clean up driver code formatting issues. Mainly as follows:
1. Use the BIT macro;
2. Use dev_err_probe() in every error path in probe in loongson_card driver;
3. Introduce loongson_card_acpi_find_device() to streamlined code.

Quoted 5 lines

Please split these out into three separate patches to make them easier to review. I see there's also some other code reordering and reformatting in there which should also be split out separately. I think the changes are probably good overall but there's too much different stuff going on in one patch to check properly.

Hi Mark:

Thanks for your reply.

That was my fault, indeed this patch is too cluttered. I will try to split them up and make them as a separate patch series.

Thanks.
Binbin

#29 lore raw

Re: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device

In reply to Mark Brown
Quoted 9 lines · Mark Brown
Quoted 4 lines · Binbin Zhou

The Loongson I2S controller exists not only in PCI form (LS7A bridge chip), but also in platform device form (Loongson-2K1000 SoC).

This patch adds support for platform device I2S controller.

Can some of this be shared with the PCI version - is it the same IP in a different wrapper, or is it a new IP?

Hi Mark:

Thanks for your reply.

To be exact, they are similar, such as the definition of the controller registers.
But for example, DMA data processing is different. In the pci version of i2s, the DMA controller is built-in, while the DMA controller here is external, using ls2x-apbdma (drivers/dma/ls2x-apb-dma.c)

Thanks.
Binbin

#34 lore raw

Re: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device

In reply to Geert Uytterhoeven

Hi Geert:

Thanks for your reply.

Quoted 19 lines · Geert Uytterhoeven

Hi Binbin,

Quoted 6 lines · Binbin Zhou

The Loongson I2S controller exists not only in PCI form (LS7A bridge chip), but also in platform device form (Loongson-2K1000 SoC).

This patch adds support for platform device I2S controller.

Thanks for your patch!

Quoted 6 lines
sound/soc/loongson/Kconfig +0 -0
@@ -13,10 +13,20 @@ config SND_SOC_LOONGSON_I2S_PCI
          The controller is found in loongson bridge chips or SoCs,
          and work as a PCI device.
 
Quoted 4 lines

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 17

Quoted 2 lines
sound/soc/loongson/Kconfig +2 -0
+config SND_SOC_LOONGSON_I2S_PLATFORM
+       tristate "Loongson I2S controller as platform device"

depends on LOONGARCH || COMPILE_TEST

This is will put under SND_SOC_LOONGSON_CARD.

Quoted 16 lines

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 19

Quoted 13 lines
sound/soc/loongson/Kconfig +8 -1
+       select SND_SOC_GENERIC_DMAENGINE_PCM
+       help
+         Say Y or M if you want to add support for I2S driver for
+         Loongson I2S controller.
+
+         The controller work as a platform device, found in loongson
+         SoCs.
+
 config SND_SOC_LOONGSON_CARD
        tristate "Loongson Sound Card Driver"
        select SND_SOC_LOONGSON_I2S_PCI
-       depends on PCI

"select SND_SOC_LOONGSON_I2S_PCI if PCI"?

Quoted 6 lines

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 29

Quoted 1 line
sound/soc/loongson/Kconfig +1 -0
+       select SND_SOC_LOONGSON_I2S_PLATFORM

Or perhaps do it the other way around, i,e. let SND_SOC_LOONGSON_I2S_{PCI,PLATFORM} select SND_SOC_LOONGSON_CARD? That would be similar to SPI_LOONGSON_{PCI,PLATFORM}, which select SPI_LOONGSON_CORE.

Yes, it would be clearer. I'll modify it in the next version.

Thanks.
Binbin

Quoted 15 lines

sound/soc/loongson/Kconfig config SND_SOC_LOONGSON_I2S_PCI · line 32

Quoted 4 lines
sound/soc/loongson/Kconfig +0 -0
        help
          Say Y or M if you want to add support for SoC audio using
          loongson I2S controller.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#26 lore raw

Re: [PATCH v1 07/10] ASoC: dt-bindings: Add Loongson I2S controller

In reply to Krzysztof Kozlowski

Hi Krzysztof:

Thanks for your reply.

Quoted 11 lines · Krzysztof Kozlowski
Quoted 9 lines · Binbin Zhou

Add Loongson I2S controller binding with DT schema format using json-schema.

---
 .../bindings/sound/loongson,ls2k-i2s.yaml     | 66 +++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml
Quoted 7 lines

Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml

Quoted 5 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +0 -0
new file mode 100644
index 000000000000..a2e3bbe00dab

Filename matching compatible.

I will rename it as loongson,ls2k1000-i2s.yaml

Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +14 -0
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/loongson,ls2k-i2s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson-2K I2S controller
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
Quoted 8 lines

Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml line 20

Quoted 6 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +6 -0
+properties:
+  compatible:
+    const: loongson,ls2k1000-i2s
+
+  reg:
+    maxItems: 2

List and describe items instead.

OK..

Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +23 -0
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  dmas:
+    maxItems: 2
+
+  dma-names:
+    items:
+      - const: tx
+      - const: rx
+
+  '#sound-dai-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
Quoted 8 lines

Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml line 48

Quoted 5 lines
Documentation/devicetree/bindings/sound/loongson,ls2k-i2s.yaml new file +5 -0
+  - dmas
+  - dma-names
+  - '#sound-dai-cells'
+
+additionalProperties: false

Instead:
unevaluatedProperties: false

OK...

Thanks.
Binbin

Quoted 4 lines

Best regards,
Krzysztof

maintainer
#30 lore raw

Re: [PATCH v1 08/10] ASoC: loongson: Add I2S controller driver as platform device

In reply to Binbin Zhou
Quoted 10 lines · Binbin Zhou
Quoted 2 lines · Mark Brown

Can some of this be shared with the PCI version - is it the same IP in a different wrapper, or is it a new IP?

To be exact, they are similar, such as the definition of the controller registers.
But for example, DMA data processing is different. In the pci version of i2s, the DMA controller is built-in, while the DMA controller here is external, using ls2x-apbdma (drivers/dma/ls2x-apb-dma.c)

OK, if all the registers are the same it might be worth trying to share that code but possibly not with the DMA being split like this.

#22 lore raw

Re: [PATCH v1 06/10] ASoC: loongson: Fix codec detection failure on FDT systems

In reply to Krzysztof Kozlowski

Hi Krzysztof:

Thanks for your detailed review.

Quoted 32 lines · Krzysztof Kozlowski
Quoted 30 lines · Binbin Zhou

When the Codec is compiled into a module, we can't use snd_soc_of_get_dlc() to get the codec dai_name, use snd_soc_get_dai_name() instead.

Also, for the cpu dailink, its dai_name is already defined as "loongson-i2s", so just get the corresponding of_node attribute here.

---
 sound/soc/loongson/loongson_card.c | 89 +++++++++++++++++++++---------
 1 file changed, 63 insertions(+), 26 deletions(-)
sound/soc/loongson/loongson_card.c +3 -5
index a25287efdd5c..d45a3e77cb90 100644
@@ -119,44 +119,81 @@ static int loongson_card_parse_acpi(struct loongson_card_data *data)
      return 0;
 }
 
-static int loongson_card_parse_of(struct loongson_card_data *data)
+static int loongson_parse_cpu(struct device *dev, struct device_node **dai_node)
 {
-     struct snd_soc_card *card = &data->snd_card;
-     struct device_node *cpu, *codec;
-     struct device *dev = card->dev;
-     int ret, i;
+     struct device_node *cpu;
+     int ret = 0;
 
Quoted 14 lines

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 135

Quoted 12 lines
sound/soc/loongson/loongson_card.c +7 -3
      cpu = of_get_child_by_name(dev->of_node, "cpu");
-     if (!cpu) {
-             dev_err(dev, "platform property missing or invalid\n");
+     if (!cpu)
              return -EINVAL;
-     }
+
+     *dai_node = of_parse_phandle(cpu, "sound-dai", 0);
+     if (!*dai_node)
+             ret = -EINVAL;
+
+     of_node_put(cpu);

This goes just after of_parse_phandle, which simplifies your code.

OK.. the ret param is unnecessary also.

Quoted 11 lines
Quoted 11 lines
sound/soc/loongson/loongson_card.c +9 -0
+     return ret;
+}
+
+static int loongson_parse_codec(struct device *dev, struct device_node **dai_node,
+                             const char **dai_name)
+{
+     struct of_phandle_args args;
+     struct device_node *codec;
+     int ret = 0;
 
Quoted 7 lines

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 147

Quoted 4 lines
sound/soc/loongson/loongson_card.c +1 -2
      codec = of_get_child_by_name(dev->of_node, "codec");
-     if (!codec) {
-             dev_err(dev, "audio-codec property missing or invalid\n");
+     if (!codec)

Hm? So you exit here and then caller does of_node_put on stack value. This is buggy.

Sorry, I can not get your point, I think there is nothing that should be put.

Quoted 12 lines

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 155

Quoted 9 lines
sound/soc/loongson/loongson_card.c +8 -0
+             return -EINVAL;
+
+     ret = of_parse_phandle_with_args(codec, "sound-dai", "#sound-dai-cells", 0, &args);
+     if (ret)
+             goto free_codec;
+
+     ret = snd_soc_get_dai_name(&args, dai_name);
+     if (ret)

Your error paths should clean here. Each function is responsible to clean up after itself in case of errors, not rely on caller.

Yes, I should of_node_put(args.np); here

Quoted 14 lines

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 162

Quoted 9 lines
sound/soc/loongson/loongson_card.c +6 -1
+             goto free_codec;
+
+     *dai_node = of_parse_phandle(codec, "sound-dai", 0);
+     if (!*dai_node)
              ret = -EINVAL;
-             goto free_cpu;
+
+free_codec:

You are not freeing any resources here (at least not directly). You are dropping reference. Use matching label name. free is associated with kalloc()..

OK, I will rename the label name as codec_put.

Thanks.
Binbin

Quoted 55 lines
Quoted 39 lines
sound/soc/loongson/loongson_card.c +24 -11
+     of_node_put(codec);
+     return ret;
+}
+
+static int loongson_card_parse_of(struct loongson_card_data *data)
+{
+     struct device_node *codec_dai_node, *cpu_dai_node;
+     struct snd_soc_card *card = &data->snd_card;
+     struct device *dev = card->dev;
+     const char *codec_dai_name;
+     int ret = 0, i;
+
+     ret = loongson_parse_cpu(dev, &cpu_dai_node);
+     if (ret) {
+             dev_err(dev, "cpu property missing or invalid.\n");
+             goto out;
+     }
+
+     ret = loongson_parse_codec(dev, &codec_dai_node, &codec_dai_name);
+     if (ret) {
+             dev_err(dev, "audio-codec property missing or invalid.\n");
+             goto out;
      }
 
      for (i = 0; i < card->num_links; i++) {
-             ret = snd_soc_of_get_dlc(cpu, NULL, loongson_dai_links[i].cpus, 0);
-             if (ret) {
-                     dev_err(dev, "getting cpu dlc error (%d)\n", ret);
-                     goto free_codec;
-             }
-
-             ret = snd_soc_of_get_dlc(codec, NULL, loongson_dai_links[i].codecs, 0);
-             if (ret) {
-                     dev_err(dev, "getting codec dlc error (%d)\n", ret);
-                     goto free_codec;
-             }
+             loongson_dai_links[i].platforms->of_node = cpu_dai_node;
+             loongson_dai_links[i].cpus->of_node = cpu_dai_node;

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 195

Quoted 10 lines
sound/soc/loongson/loongson_card.c +4 -4
+             loongson_dai_links[i].codecs->of_node = codec_dai_node;
+             loongson_dai_links[i].codecs->dai_name = codec_dai_name;
      }
 
-free_codec:
-     of_node_put(codec);
-free_cpu:
-     of_node_put(cpu);
+out:
+     of_node_put(codec_dai_node);

Yeah, so here we see drop of reference from stack-based pointer...

Best regards,
Krzysztof

#23 lore raw

Re: [PATCH v1 06/10] ASoC: loongson: Fix codec detection failure on FDT systems

Quoted 19 lines · Binbin Zhou
Quoted 11 lines
Quoted 11 lines
sound/soc/loongson/loongson_card.c +9 -0
+     return ret;
+}
+
+static int loongson_parse_codec(struct device *dev, struct device_node **dai_node,
+                             const char **dai_name)
+{
+     struct of_phandle_args args;
+     struct device_node *codec;
+     int ret = 0;
Quoted 7 lines

sound/soc/loongson/loongson_card.c static int loongson_card_parse_acpi(struct loongson_card_data *data) · line 147

Quoted 4 lines
      codec = of_get_child_by_name(dev->of_node, "codec");
sound/soc/loongson/loongson_card.c +1 -2
-     if (!codec) {
-             dev_err(dev, "audio-codec property missing or invalid\n");
+     if (!codec)

Hm? So you exit here and then caller does of_node_put on stack value. This is buggy.

Quoted 1 line

Sorry, I can not get your point, I think there is nothing that should be put.

You drop reference from a pointer which is a random stack value.

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v1 01/10] ASoC: dt-bindings: Add Everest ES8323 Codec

In reply to Krzysztof Kozlowski

Hi Krzysztof:

Thanks for your review.

Quoted 42 lines · Krzysztof Kozlowski
Quoted 40 lines · Binbin Zhou

Add Everest Semiconductor ES8316 low power audio CODEC binding with DT schema format using json-schema.

---
 .../bindings/sound/everest,es8323.yaml        | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/everest,es8323.yaml
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +25 -0
new file mode 100644
index 000000000000..0450d0f49d03
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/everest,es8323.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Everest ES8323 audio CODECs
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: everest,es8323
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    description: clock for master clock (MCLK)
+    maxItems: 1
+
Quoted 8 lines

Documentation/devicetree/bindings/sound/everest,es8323.yaml line 30

Quoted 5 lines
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +5 -0
+  clock-names:
+    const: mclk
+
+  '#sound-dai-cells':
+    const: 0

No audio-graph-port? Are you sure? It looks exactly like everest,es8316...

I checked and they are indeed very similar and it seems I just need to add to everest,es8316.yaml instead of a new file.

Thanks.
Binbin

Quoted 24 lines
Quoted 8 lines
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +7 -0
+
+required:
+  - compatible
+  - reg
+  - '#sound-dai-cells'
+
+unevaluatedProperties: false

Documentation/devicetree/bindings/sound/everest,es8323.yaml line 47

Quoted 10 lines
Documentation/devicetree/bindings/sound/everest,es8323.yaml new file +10 -0
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      codec@10 {
+        compatible = "everest,es8323";
+        reg = <0x10>;
+        #sound-dai-cells = <0>;

Make the example complete. Assuming this binding stays...

Best regards,
Krzysztof

#15 lore raw

Re: [PATCH v1 04/10] ASoC: codecs: Add uda1342 codec driver

In reply to Mark Brown

Hi Mark:

Thanks for your detailed review.

Quoted 19 lines · Mark Brown
Quoted 2 lines · Binbin Zhou

The UDA1342 is an NXP audio codec, support 2x Stereo audio ADC (4x PGA mic inputs), stereo audio DAC, with basic audio processing.

This looks basically fine overall, there's some issues below but they're mostly fairly small and stylistic rather than anything major.

sound/soc/codecs/uda1342.c line 3

Quoted 6 lines
sound/soc/codecs/uda1342.c new file +3 -0
@@ -0,0 +1,397 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * uda1342.c  --  UDA1342 ALSA SoC Codec driver

Please keep the entire comment a C++ one so things look more intentional.

Quoted 11 lines

sound/soc/codecs/uda1342.c line 64

Quoted 8 lines
sound/soc/codecs/uda1342.c new file +8 -0
+static int uda1342_mute(struct snd_soc_dai *dai, int mute, int direction)
+{
+     struct snd_soc_component *component = dai->component;
+     struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
+     unsigned int mask;
+     unsigned int val = 0;
+
+     dev_info(&uda1342->i2c->dev, "mute: %d\n", mute);

This is far too noisy to be logged and will DoS the logs, please just remove it.

OK, I will drop it.

Quoted 7 lines

sound/soc/codecs/uda1342.c line 68

Quoted 5 lines
sound/soc/codecs/uda1342.c new file +4 -0
+
+     /* Master mute */
+     mask = BIT(5);
+     val = mute ? mask : 0;

Please use normal conditional statements to improve legibility.

OK, the code as following:

if (mute)

                val = mask;
Quoted 12 lines

sound/soc/codecs/uda1342.c line 104

Quoted 9 lines
sound/soc/codecs/uda1342.c new file +8 -0
+static void uda1342_shutdown(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai)
+{
+     struct snd_soc_component *component = dai->component;
+     struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
+
+     if (uda1342->master_substream == substream)
+             uda1342->master_substream = uda1342->slave_substream;

Please avoid using master/slave terminology, we've tended to go for provider/consumer in ASoC.

OK, I see, I will rename it.

Quoted 15 lines

sound/soc/codecs/uda1342.c line 120

Quoted 13 lines
sound/soc/codecs/uda1342.c new file +12 -0
+static int uda1342_hw_params(struct snd_pcm_substream *substream,
+                          struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+     struct snd_soc_component *component = dai->component;
+     struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
+     struct device *dev = &uda1342->i2c->dev;
+     unsigned int hw_params = 0;
+
+     if (substream == uda1342->slave_substream) {
+             dev_info(dev, "ignoring hw_params for slave substream\n");
+             return 0;
+     }

This is also too noisy, it should be _dbg() at most.

OK, I will drop it.

Quoted 8 lines

sound/soc/codecs/uda1342.c line 201

Quoted 6 lines
sound/soc/codecs/uda1342.c new file +5 -0
+     /* codec supports only full slave mode */
+     if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
+             dev_err(dev, "unsupported slave mode.\n");
+             return -EINVAL;
+     }

Use the more modern _CBC_CFC.

OK, it should be replaced by SND_SOC_DAIFMT_BC_FC.

Quoted 8 lines

sound/soc/codecs/uda1342.c line 207

Quoted 6 lines
sound/soc/codecs/uda1342.c new file +5 -0
+     /*
+      * We can't setup DAI format here as it depends on the word bit num,
+      * so let's just store the value for later
+      */
+     uda1342->dai_fmt = fmt;

No need to even store it if only one value is supported.

Emm, I will put the fmt setting here from the hw_param function. Also, the dai_fmt could be dropped.

Quoted 11 lines
Quoted 11 lines
sound/soc/codecs/uda1342.c new file +10 -0
+static int uda1342_set_bias_level(struct snd_soc_component *component,
+                               enum snd_soc_bias_level level)
+{
+     switch (level) {
+     case SND_SOC_BIAS_ON:
+             break;
+     case SND_SOC_BIAS_PREPARE:
+             break;
+     case SND_SOC_BIAS_STANDBY:
+             break;
Quoted 8 lines

sound/soc/codecs/uda1342.c line 227

Quoted 6 lines
sound/soc/codecs/uda1342.c new file +6 -0
+     case SND_SOC_BIAS_OFF:
+             break;
+     }
+
+     return 0;
+}

This does nothing so it can just be removed.

I will drop it.

Quoted 8 lines

sound/soc/codecs/uda1342.c line 235

Quoted 5 lines
sound/soc/codecs/uda1342.c new file +4 -0
+static const struct soc_enum uda1342_mixer_enum[] = {
+     SOC_ENUM_SINGLE(0x10, 3, 0x04, uda1342_deemph),
+     SOC_ENUM_SINGLE(0x10, 0, 0x04, uda1342_mixmode),
+};

This doesn't seem to be referenced anywhere so can be removed, or should be added to the controls or DAPM?

I will drop it.

Quoted 14 lines

sound/soc/codecs/uda1342.c line 305

Quoted 11 lines
sound/soc/codecs/uda1342.c new file +10 -0
+static int uda1342_soc_probe(struct snd_soc_component *component)
+{
+     struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
+
+     snd_soc_add_component_controls(component, uda1342_snd_controls,
+                                    ARRAY_SIZE(uda1342_snd_controls));
+     snd_soc_dapm_new_controls(dapm, uda1342_dapm_widgets,
+                               ARRAY_SIZE(uda1342_dapm_widgets));
+     snd_soc_dapm_add_routes(dapm, uda1342_dapm_routes,
+                             ARRAY_SIZE(uda1342_dapm_routes));

You can point to these arrays from the component struct and have the core register them for you.

OK, I will do it.

Thanks.
Binbin

Quoted 12 lines

sound/soc/codecs/uda1342.c line 325

Quoted 8 lines
sound/soc/codecs/uda1342.c new file +7 -0
+static const struct regmap_config uda1342_regmap = {
+     .reg_bits = 8,
+     .val_bits = 16,
+     .max_register = 0x21,
+     .reg_defaults = uda1342_reg_defaults,
+     .num_reg_defaults = ARRAY_SIZE(uda1342_reg_defaults),
+     .cache_type = REGCACHE_RBTREE,

In general _MAPLE is preferred for new things unless you have a specific reason to use _RBTREE, it uses a more modern data structure and should generally do better.

#6 lore raw

Re: [PATCH v1 02/10] ASoC: codecs: Add support for ES8323

In reply to Mark Brown

Hi Mark:

Thanks for your detailed review.

Quoted 10 lines · Mark Brown

On Thu, Sep 05, 2024 at 03:02:15PM +0800, Binbin Zhou wrote:

This looks like it was based on some *extremely* old code and needs quite a few updates to bring it up to modern standards.

Quoted 1 line

+ * Author: Mark Brown <[email protected]>

Oh?

Quoted 11 lines

sound/soc/codecs/es8323.c line 41

Quoted 8 lines
sound/soc/codecs/es8323.c new file +8 -0
+/*
+ * es8323 register cache
+ * We can't read the es8323 register space when we
+ * are using 2 wire for device control, so we cache them instead.
+ */
+static u16 es8323_reg[] = {
+     0x06, 0x1C, 0xC3, 0xFC, /*  0 */
+     0xC0, 0x00, 0x00, 0x7C, /*  4 */

There's a bunch of regmap reimplementation in the driver, the cache and I/O code all looks totally generic. Just use regmap.

Sorry, I don't really understand this point.
Do you mean to use regmap_read()/regmap_write() instead of snd_soc_component_read()/snd_soc_component_write()?

If so, are there any rules for using snd_soc_component_xxx()?

Quoted 9 lines

sound/soc/codecs/es8323.c line 101

Quoted 6 lines
sound/soc/codecs/es8323.c new file +5 -0
+static const struct soc_enum es8323_enum[] = {
+     SOC_VALUE_ENUM_SINGLE(ES8323_DACCONTROL16, 3, 7, ARRAY_SIZE(es8323_line_texts),
+                           es8323_line_texts, es8323_line_values),   /* LLINE */
+     SOC_VALUE_ENUM_SINGLE(ES8323_DACCONTROL16, 0, 7, ARRAY_SIZE(es8323_line_texts),
+                           es8323_line_texts, es8323_line_values),   /* RLINE */

Use named variables for the enums rather than putting them into an array that's not otherwise used...

OK, I will use macro like SOC_ENUM_SINGLE_DECL() to define them.

Quoted 24 lines

sound/soc/codecs/es8323.c line 123

Quoted 4 lines
sound/soc/codecs/es8323.c new file +3 -0
+static const struct snd_kcontrol_new es8323_snd_controls[] = {
+     SOC_ENUM("3D Mode", es8323_enum[4]),
+     SOC_ENUM("ALC Capture Function", es8323_enum[5]),

...it's *vastly* more readable and maintainable.

Quoted 1 line

+ SOC_SINGLE("Capture Mute", ES8323_ADC_MUTE, 2, 1, 0),

On/off switches should end in Switch, see control-names.rst.

sound/soc/codecs/es8323.c line 214

Quoted 2 lines
sound/soc/codecs/es8323.c new file +2 -0
+     /* gModify.Cmmt Implement when suspend/startup */
+     SND_SOC_DAPM_DAC("Right DAC", "Right Playback", SND_SOC_NOPM, 6, 1),

gModify.Cmmt?

sound/soc/codecs/es8323.c line 440

Quoted 5 lines
sound/soc/codecs/es8323.c new file +5 -0
+/*
+ * Note that this should be called from init rather than from hw_params.
+ */
+static int es8323_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+                              int clk_id, unsigned int freq, int dir)

Why?

Quoted 8 lines

sound/soc/codecs/es8323.c line 484

Quoted 6 lines
sound/soc/codecs/es8323.c new file +6 -0
+     /* set master/slave audio interface */
+     switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+     case SND_SOC_DAIFMT_CBM_CFM:    /* MASTER MODE */
+             iface |= 0x80;
+             break;
+     case SND_SOC_DAIFMT_CBS_CFS:    /* SLAVE MODE */

Please use the modern naming with _CBP_CFP and so on.

Get. SND_SOC_DAIFMT_BC_FP/SND_SOC_DAIFMT_BC_FC will be used.

Quoted 14 lines
Quoted 14 lines
sound/soc/codecs/es8323.c new file +13 -0
+static int es8323_mute(struct snd_soc_dai *dai, int mute,  int stream)
+{
+     struct snd_soc_component *component = dai->component;
+     struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component);
+
+     if (mute) {
+             es8323_set_gpio(ES8323_CODEC_SET_SPK,
+                             !es8323->spk_gpio_level, es8323->spk_ctl_gpio);
+             usleep_range(2000, 3000);
+             snd_soc_component_write(component, ES8323_DAC_MUTE, 0x06);
+     } else {
+             snd_soc_component_write(component, ES8323_DAC_MUTE, 0x02);
+             usleep_range(2000, 3000);
Quoted 8 lines

sound/soc/codecs/es8323.c line 629

Quoted 3 lines
sound/soc/codecs/es8323.c new file +3 -0
+             if (!es8323->hp_inserted)
+                     es8323_set_gpio(ES8323_CODEC_SET_SPK,
+                                     es8323->spk_gpio_level, es8323->spk_ctl_gpio);

This appears to be controlling the speaker based on jack detection. Unless there is some hardware restriction this should be done via DAPM and the user allowed to manage when the speaker is used depending on their use case.

In this version of the patch, I plan to remove the jack related functions, and I will add them later.

Quoted 12 lines

sound/soc/codecs/es8323.c line 673

Quoted 8 lines
sound/soc/codecs/es8323.c new file +7 -0
+static int es8323_suspend(struct snd_soc_component *component)
+{
+     snd_soc_component_write(component, ES8323_DAC_MUTE, 0x06);
+     snd_soc_component_write(component, ES8323_LOUT1_VOL, 0x00);
+     snd_soc_component_write(component, ES8323_ROUT1_VOL, 0x00);
+     snd_soc_component_write(component, ES8323_LOUT2_VOL, 0x00);
+     snd_soc_component_write(component, ES8323_ROUT2_VOL, 0x00);

This will overwrite user settings when suspending, the controls should be unaffected by suspend. If the device needs this then use cache bypass to do the writes during suspend and resync the cache on resume.

regcache_cache_only() and regcache_sync() will be used.

Quoted 33 lines

sound/soc/codecs/es8323.c line 683

Quoted 4 lines
sound/soc/codecs/es8323.c new file +3 -0
+     snd_soc_component_write(component, ES8323_CONTROL1, 0x06);
+     snd_soc_component_write(component, ES8323_CONTROL2, 0x58);
+     usleep_range(18000, 20000);

Use fsleep().

sound/soc/codecs/es8323.c line 705

Quoted 10 lines
sound/soc/codecs/es8323.c new file +9 -0
+static void es8323_init_component_regs(struct snd_soc_component *component)
+{
 
+     snd_soc_component_write(component, ES8323_ADCCONTROL1, 0x88);
+     snd_soc_component_write(component, ES8323_ADCCONTROL2, 0xF0);
+     snd_soc_component_write(component, ES8323_ADCCONTROL3, 0x02);
+     snd_soc_component_write(component, ES8323_ADCCONTROL4, 0x0C);
+     snd_soc_component_write(component, ES8323_ADCCONTROL5, 0x02);
+     snd_soc_component_write(component, ES8323_LADC_VOL, 0x00);
+     snd_soc_component_write(component, ES8323_RADC_VOL, 0x00);

User visible controls should use the chip defaults as standard, userspace can configure what it needs and this avoids us worrying about individual use cases in the driver.

sound/soc/codecs/es8323.c line 732

Quoted 8 lines
sound/soc/codecs/es8323.c new file +8 -0
+static int es8323_resume(struct snd_soc_component *component)
+{
+     es8323_init_component_regs(component);
+     /* open dac output */
+     snd_soc_component_write(component, ES8323_DACPOWER, 0x3c);
+
+     return 0;
+}

This doesn't restore any user settings.

Quoted 14 lines

sound/soc/codecs/es8323.c line 789

Quoted 10 lines
sound/soc/codecs/es8323.c new file +10 -0
+static int es8323_i2c_probe(struct i2c_client *i2c)
+{
+     struct es8323_priv *es8323;
+     struct i2c_adapter *adapter = to_i2c_adapter(i2c->dev.parent);
+
+     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
+             dev_warn(&adapter->dev,
+                      "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
+             return -EIO;
+     }

Does the device really need this? It seems to be doing very basic I/O which should be SMBus compatible. In any case when you move to regmap this should be redundant.

Emm, I will drop it.

Thanks.
Binbin

maintainer
#7 lore raw

Re: [PATCH v1 02/10] ASoC: codecs: Add support for ES8323

Quoted 14 lines · Binbin Zhou
Quoted 11 lines · Mark Brown

sound/soc/codecs/es8323.c line 41

Quoted 8 lines
sound/soc/codecs/es8323.c new file +8 -0
+/*
+ * es8323 register cache
+ * We can't read the es8323 register space when we
+ * are using 2 wire for device control, so we cache them instead.
+ */
+static u16 es8323_reg[] = {
+     0x06, 0x1C, 0xC3, 0xFC, /*  0 */
+     0xC0, 0x00, 0x00, 0x7C, /*  4 */

There's a bunch of regmap reimplementation in the driver, the cache and I/O code all looks totally generic. Just use regmap.

Quoted 5 lines

Sorry, I don't really understand this point.
Do you mean to use regmap_read()/regmap_write() instead of snd_soc_component_read()/snd_soc_component_write()?

If so, are there any rules for using snd_soc_component_xxx()?

No, it's fine to use the component wrappers if you happen to have a component to hand. What's an issue is things like writing your own register cache code (the above bit is part of an open coded cache implementation), or I2C read/write functions if there's not something unusual with how the device does I/O.

#8 lore raw

Re: [PATCH v1 02/10] ASoC: codecs: Add support for ES8323

Hi Mark:

Thanks for your explanation.

Quoted 20 lines · Mark Brown
Quoted 17 lines · Binbin Zhou
Quoted 11 lines · Mark Brown

sound/soc/codecs/es8323.c line 41

Quoted 8 lines
sound/soc/codecs/es8323.c new file +8 -0
+/*
+ * es8323 register cache
+ * We can't read the es8323 register space when we
+ * are using 2 wire for device control, so we cache them instead.
+ */
+static u16 es8323_reg[] = {
+     0x06, 0x1C, 0xC3, 0xFC, /*  0 */
+     0xC0, 0x00, 0x00, 0x7C, /*  4 */

There's a bunch of regmap reimplementation in the driver, the cache and I/O code all looks totally generic. Just use regmap.

Sorry, I don't really understand this point.
Do you mean to use regmap_read()/regmap_write() instead of snd_soc_component_read()/snd_soc_component_write()?

Quoted 7 lines
Quoted 1 line

If so, are there any rules for using snd_soc_component_xxx()?

No, it's fine to use the component wrappers if you happen to have a component to hand. What's an issue is things like writing your own register cache code (the above bit is part of an open coded cache implementation), or I2C read/write functions if there's not something unusual with how the device does I/O.

Indeed, I misunderstood it before. As I understand it, we should use regmap_config.reg_defaults instead of snd_soc_component_driver.{read/write}.

Thanks.
Binbin

maintainer
#9 lore raw

Re: [PATCH v1 02/10] ASoC: codecs: Add support for ES8323

Quoted 11 lines · Binbin Zhou
Quoted 5 lines · Mark Brown

No, it's fine to use the component wrappers if you happen to have a component to hand. What's an issue is things like writing your own register cache code (the above bit is part of an open coded cache implementation), or I2C read/write functions if there's not something unusual with how the device does I/O.

Indeed, I misunderstood it before. As I understand it, we should use regmap_config.reg_defaults instead of snd_soc_component_driver.{read/write}.

I think so - I'll need to see your actual patch to confirm but that sounds like the right direction.