Skip to contentSkip to conversation

ASoC: codecs: Add support for Fortemedia FM34NE DSP

PATCH Superseded Svyatoslav Ryhel 3 participants 6 messages Oct 19 – Oct 20

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover ASoC: codecs: Add support for Fortemedia FM34NE DSP

The Fortemedia FM34NE is digital sound processing chip used for active noise suppression mainly on ASUS Transformers.

---
Changes in v2:
- remove ports from schema
- schema moved to dsp
- add return value check in fm34ne_dsp_set_config()
- dropped unused headers
---

Svyatoslav Ryhel (2):
ASoC: dt-bindings: Document FM34NE DSP
ASoC: codecs: Add support for Fortemedia FM34NE DSP

 .../bindings/dsp/asus,tf201-dsp.yaml          |   77 ++
 sound/soc/codecs/Kconfig                      |   12 +
 sound/soc/codecs/Makefile                     |    2 +
 sound/soc/codecs/fm34ne-dsp.c                 |  390 +++++++
 sound/soc/codecs/fm34ne-dsp.h                 | 1030 +++++++++++++++++
 5 files changed, 1511 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml
 create mode 100644 sound/soc/codecs/fm34ne-dsp.c
 create mode 100644 sound/soc/codecs/fm34ne-dsp.h
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/2 ASoC: dt-bindings: Document FM34NE DSP

Document the FM34NE DSP based voice processor used in the ASUS Transformer devices.

---
 .../bindings/dsp/asus,tf201-dsp.yaml          | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml
Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml new file +77 -0
new file mode 100644
index 0000000000000..46308a462af16
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dsp/asus,tf201-dsp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Fortemedia FM34NE based voice processor
+
+description:
+  Fortemedia FM34NE is a hardware voice processor (DSP — Digital Signal
+  Processor) designed by Fortemedia. It specializes in real-time audio
+  processing, focusing on noise suppression and echo cancellation.
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    enum:
+      - asus,sl101-dsp
+      - asus,tf101-dsp
+      - asus,tf201-dsp
+      - asus,tf300t-dsp
+      - asus,tf700t-dsp
+      - pegatron,chagall-dsp
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Master clock to the DSP
+
+  reset-gpios:
+    maxItems: 1
+
+  bypass-gpios:
+    maxItems: 1
+    description: Signal that switches DSP into programming mode.
+
+  vdd-supply: true
+
+  port:
+    $ref: audio-graph-port.yaml#
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - bypass-gpios
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        codec@60 {
+            compatible = "asus,tf201-dsp";
+            reg = <0x60>;
+
+            clocks = <&fm34ne_clk>;
+
+            bypass-gpios = <&gpio 222 GPIO_ACTIVE_HIGH>;
+            reset-gpios = <&gpio 115 GPIO_ACTIVE_LOW>;
+
+            vdd-supply = <&vdd_1v8_dsp>;
+        };
+    };
+...
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 1/2] ASoC: dt-bindings: Document FM34NE DSP

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] dt-bindings: dsp: relative $ref to sound schemas fails dt_binding_check --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dt-bindings: dsp: relative $ref to sound schemas fails dt_binding_check --

commit fb615b13d5875feacbe1263da737f849cd8294c6
Author: Svyatoslav Ryhel <[email protected]>

ASoC: dt-bindings: Document FM34NE DSP

This commit adds a device tree binding schema for the Fortemedia FM34NE DSP voice processor used in ASUS Transformer devices.

Quoted 44 lines
Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml new file +38 -0
new file mode 100644
index 0000000000000..46308a462af16
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dsp/asus,tf201-dsp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Fortemedia FM34NE based voice processor
+
+description:
+  Fortemedia FM34NE is a hardware voice processor (DSP — Digital Signal
+  Processor) designed by Fortemedia. It specializes in real-time audio
+  processing, focusing on noise suppression and echo cancellation.
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    enum:
+      - asus,sl101-dsp
+      - asus,tf101-dsp
+      - asus,tf201-dsp
+      - asus,tf300t-dsp
+      - asus,tf700t-dsp
+      - pegatron,chagall-dsp
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Master clock to the DSP
+
+  reset-gpios:
+    maxItems: 1

Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml line 48

Quoted 10 lines
Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml new file +10 -0
+
+  bypass-gpios:
+    maxItems: 1
+    description: Signal that switches DSP into programming mode.
+
+  vdd-supply: true
+
+  port:
+    $ref: audio-graph-port.yaml#
+    unevaluatedProperties: false

[Severity: Medium]
Since the $id for this schema is under /schemas/dsp/, relative $ref entries resolve against http://devicetree.org/schemas/dsp/. Because dai-common.yaml and audio-graph-port.yaml are located in Documentation/devicetree/bindings/sound/ rather than Documentation/devicetree/bindings/dsp/, won't these relative references fail to resolve during dt_binding_check?

Should these references use /schemas/sound/dai-common.yaml# and /schemas/sound/audio-graph-port.yaml# instead?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v2 1/2] ASoC: dt-bindings: Document FM34NE DSP

In reply to Svyatoslav Ryhel
Quoted 9 lines · Svyatoslav Ryhel

Document the FM34NE DSP based voice processor used in the ASUS Transformer devices.

---
 .../bindings/dsp/asus,tf201-dsp.yaml          | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml: Unresolvable reference: dai-common.yaml#
Documentation/devicetree/bindings/dsp/asus,tf201-dsp.example.dtb: codec@60 (asus,tf201-dsp): False schema does not allow {'compatible': ['asus,tf201-dsp'], 'reg': [[96]], 'clocks': [[4294967295]], 'bypass-gpios': [[4294967295, 222, 0]], 'reset-gpios': [[4294967295, 115, 1]], 'vdd-supply': [[4294967295]], '$nodename': ['codec@60']}
from schema $id: http://devicetree.org/schemas/dsp/asus,tf201-dsp.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.kernel.org/project/devicetree/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#4 lore raw

PATCH v2 2/2 ASoC: codecs: Add support for Fortemedia FM34NE DSP

In reply to Svyatoslav Ryhel

The Fortemedia FM34NE is a digital sound processing chip used for active noise suppression mainly on ASUS Transformers.

---
 sound/soc/codecs/Kconfig      |   12 +
 sound/soc/codecs/Makefile     |    2 +
 sound/soc/codecs/fm34ne-dsp.c |  390 +++++++++++++
 sound/soc/codecs/fm34ne-dsp.h | 1030 +++++++++++++++++++++++++++++++++
 4 files changed, 1434 insertions(+)
 create mode 100644 sound/soc/codecs/fm34ne-dsp.c
 create mode 100644 sound/soc/codecs/fm34ne-dsp.h
sound/soc/codecs/Kconfig +12 -0
index ba59dabeeccde..c40e84f499671 100644
@@ -127,6 +127,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_ES9356
 	imply SND_SOC_ES7134
 	imply SND_SOC_ES7241
+	imply SND_SOC_FM34NE_DSP
 	imply SND_SOC_FRAMER
 	imply SND_SOC_FS210X
 	imply SND_SOC_GTM601
@@ -1338,6 +1339,17 @@ config SND_SOC_ES9356
 	select REGMAP_SOUNDWIRE
 	select REGMAP_SOUNDWIRE_MBQ
 
+config SND_SOC_FM34NE_DSP
+	tristate "DSP FM34NE driver"
+	depends on I2C && GPIOLIB
+	help
+	  Say Y here if you want to add support for Fortemedia FM34NE DSP
+	  mainly used in ASUS T20/T30 Transformers for input noise
+	  processing.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called snd-soc-fm34ne-dsp.
+
 config SND_SOC_FRAMER
 	tristate "Framer codec"
 	depends on GENERIC_FRAMER
sound/soc/codecs/Makefile +2 -0
index 3826f9e4fce8a..2ddf08eae181e 100644
@@ -142,6 +142,7 @@ snd-soc-es8375-y := es8375.o
 snd-soc-es8389-y := es8389.o
 snd-soc-es9039q2m-y := es9039q2m.o
 snd-soc-es9356-y := es9356.o
+snd-soc-fm34ne-dsp-y := fm34ne-dsp.o
 snd-soc-framer-y := framer-codec.o
 snd-soc-fs-amp-lib-y := fs-amp-lib.o
 snd-soc-fs210x-y := fs210x.o
@@ -590,6 +591,7 @@ obj-$(CONFIG_SND_SOC_ES8375)    += snd-soc-es8375.o
 obj-$(CONFIG_SND_SOC_ES8389)    += snd-soc-es8389.o
 obj-$(CONFIG_SND_SOC_ES9039Q2M)	+= snd-soc-es9039q2m.o
 obj-$(CONFIG_SND_SOC_ES9356)    += snd-soc-es9356.o
+obj-$(CONFIG_SND_SOC_FM34NE_DSP)	+= snd-soc-fm34ne-dsp.o
 obj-$(CONFIG_SND_SOC_FRAMER)	+= snd-soc-framer.o
 obj-$(CONFIG_SND_SOC_FS_AMP_LIB)+= snd-soc-fs-amp-lib.o
 obj-$(CONFIG_SND_SOC_FS210X)	+= snd-soc-fs210x.o
sound/soc/codecs/fm34ne-dsp.c new file +390 -0

390 lines not on this page · raw message

sound/soc/codecs/fm34ne-dsp.h new file +1030 -0

1,030 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] ASoC: fm34ne-dsp: goto mixing and stuck bypass_gpio in fm34ne_dsp_set_config() - [Medium] ASoC…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] ASoC: fm34ne-dsp: goto mixing and stuck bypass_gpio in fm34ne_dsp_set_config()
- [Medium] ASoC: fm34ne-dsp: conflicting DAPM widget events clobber DSP state
- [Low] ASoC: fm34ne-dsp: reset GPIO left deasserted when DSP is disabled --

commit 44c3b6ffa34580e6c173c2874d0fa14d84f97af1
Author: Svyatoslav Ryhel <[email protected]>

ASoC: codecs: Add support for Fortemedia FM34NE DSP

This commit adds an ASoC codec driver for the Fortemedia FM34NE digital sound processing chip used for active noise suppression on ASUS Transformer devices.

Quoted 5 lines
sound/soc/codecs/fm34ne-dsp.c new file +0 -0
new file mode 100644
index 0000000000000..608b94e6ea0ca

[ ... ]

Quoted 54 lines
sound/soc/codecs/fm34ne-dsp.c new file +54 -0
+static int fm34ne_dsp_set_config(struct fm34ne_dsp *dsp, enum dsp_state state)
+{
+	struct device *dev = &dsp->client->dev;
+	int ret;
+
+	guard(mutex)(&dsp->lock);
+
+	gpiod_set_value_cansleep(dsp->bypass_gpio, 1);
+	msleep(20);
+
+	switch (state) {
+	case FM34NE_NS_ENABLE:
+		ret = i2c_master_send(dsp->client, dsp->info->enable_parameter,
+				      dsp->info->enable_parameter_length);
+		if (ret < 0) {
+			dev_err(dev, "Failed to set DSP enable %d\n", ret);
+			goto exit;
+		}
+
+		ret = i2c_master_send(dsp->client, dsp->info->enable_noise_suppression,
+				      dsp->info->enable_ns_length);
+		if (ret < 0) {
+			dev_err(dev, "Failed to enable DSP noise suppression %d\n", ret);
+			goto exit;
+		}
+
+		break;
+
+	case FM34NE_NS_DISABLE:
+		ret = i2c_master_send(dsp->client, dsp->info->enable_parameter,
+				      dsp->info->enable_parameter_length);
+		if (ret < 0) {
+			dev_err(dev, "Failed to set DSP enable with %d\n", ret);
+			goto exit;
+		}
+
+		ret = i2c_master_send(dsp->client, dsp->info->disable_noise_suppression,
+				      dsp->info->disable_ns_length);
+		if (ret < 0) {
+			dev_err(dev, "Failed to disable DSP noise suppression with %d\n", ret);
+			goto exit;
+		}
+
+		break;
+
+	case FM34NE_BYPASS:
+	default:
+		ret = i2c_master_send(dsp->client, bypass_parameter, sizeof(bypass_parameter));
+		if (ret < 0) {
+			dev_err(dev, "Failed to set DSP bypass with %d\n", ret);
+			goto exit;
+		}
+
+		break;

sound/soc/codecs/fm34ne-dsp.c line 92

Quoted 10 lines
sound/soc/codecs/fm34ne-dsp.c new file +10 -0
+	}
+
+exit:
+	if (ret < 0)
+		return ret;
+
+	gpiod_set_value_cansleep(dsp->bypass_gpio, 0);
+
+	return 0;
+}

[Severity: Medium]
In sound/soc/codecs/fm34ne-dsp.c, fm34ne_dsp_set_config() mixes guard(mutex)(&dsp->lock) with goto exit labels, which goes against the scope-based cleanup guidelines in include/linux/cleanup.h.

Also, if any i2c_master_send() call fails during a DAPM widget event (via fm34ne_dsp_int_state_control() or fm34ne_dsp_ext_state_control()), the exit label returns early when ret < 0 before resetting dsp->bypass_gpio back to 0:

exit:

	if (ret < 0)
		return ret;

	gpiod_set_value_cansleep(dsp->bypass_gpio, 0);

Should fm34ne_dsp_set_config() deassert dsp->bypass_gpio before returning on error so the DSP is not left stuck in programming mode, and avoid mixing guard(mutex) with goto labels (as well as explicitly including <linux/cleanup.h> and <linux/mutex.h>)?

Quoted 39 lines
sound/soc/codecs/fm34ne-dsp.c new file +39 -0
+static int fm34ne_dsp_ext_state_control(struct snd_soc_dapm_widget *w,
+					struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+	struct fm34ne_dsp *dsp = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		return fm34ne_dsp_set_config(dsp, FM34NE_BYPASS);
+
+	default:
+		WARN(1, "Unexpected event");
+		return -EINVAL;
+	}
+}
+
+static int fm34ne_dsp_int_state_control(struct snd_soc_dapm_widget *w,
+					struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+	struct fm34ne_dsp *dsp = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		return fm34ne_dsp_set_config(dsp, FM34NE_NS_ENABLE);
+
+	case SND_SOC_DAPM_PRE_PMD:
+		return fm34ne_dsp_set_config(dsp, FM34NE_NS_DISABLE);
+
+	default:
+		WARN(1, "Unexpected event");
+		return -EINVAL;
+	}
+}
+
+static const struct snd_soc_dapm_widget fm34ne_dsp_dapm_widgets[] = {
+	SND_SOC_DAPM_INPUT("DSP DMIC"),
+	SND_SOC_DAPM_INPUT("DSP AMIC"),
+

sound/soc/codecs/fm34ne-dsp.c line 142

Quoted 10 lines
sound/soc/codecs/fm34ne-dsp.c new file +10 -0
+	SND_SOC_DAPM_OUT_DRV_E("DSP Processing Engine INT", SND_SOC_NOPM,
+			       0, 0, NULL, 0, fm34ne_dsp_int_state_control,
+			       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
+	SND_SOC_DAPM_OUT_DRV_E("DSP Processing Engine EXT", SND_SOC_NOPM,
+			       0, 0, NULL, 0, fm34ne_dsp_ext_state_control,
+			       SND_SOC_DAPM_POST_PMU),
+
+	SND_SOC_DAPM_OUTPUT("DSP Digital Mic"),
+	SND_SOC_DAPM_OUTPUT("DSP Analog Mic"),
+};

[Severity: Medium]
Can transitions between "DSP Processing Engine INT" and "DSP Processing Engine EXT" clobber the shared DSP state?

Both widgets call fm34ne_dsp_set_config() to update the global hardware state without tracking which engine is active:

1. If "DSP Processing Engine EXT" powers up (SND_SOC_DAPM_POST_PMU -> FM34NE_BYPASS) and "DSP Processing Engine INT" subsequently powers down (SND_SOC_DAPM_PRE_PMD -> FM34NE_NS_DISABLE), fm34ne_dsp_int_state_control() sends dsp->info->enable_parameter and dsp->info->disable_noise_suppression, taking the DSP out of bypass mode while the external analog mic path is still active.

2. Conversely, "DSP Processing Engine EXT" only handles SND_SOC_DAPM_POST_PMU and has no PMD handler. If both paths are active and "DSP Processing Engine EXT" powers down while
"DSP Processing Engine INT" remains powered on, the DSP stays in FM34NE_BYPASS instead of restoring FM34NE_NS_ENABLE.

Should the driver coordinate state across these widgets (or model the routing so the active path's configuration is preserved)?

[ ... ]

Quoted 17 lines
sound/soc/codecs/fm34ne-dsp.c new file +17 -0
+static void fm34ne_dsp_reset(struct fm34ne_dsp *dsp)
+{
+	gpiod_set_value_cansleep(dsp->reset_gpio, 1);
+	msleep(20);
+	gpiod_set_value_cansleep(dsp->reset_gpio, 0);
+	msleep(100);
+}
+
+static void fm34ne_dsp_disable_hw(struct fm34ne_dsp *dsp)
+{
+	gpiod_set_value_cansleep(dsp->bypass_gpio, 0);
+	regulator_disable(dsp->vdd_supply);
+	clk_disable_unprepare(dsp->dap_mclk);
+}
+
+static int fm34ne_dsp_probe(struct snd_soc_component *component)
+{

[ ... ]

Quoted 14 lines
sound/soc/codecs/fm34ne-dsp.c new file +14 -0
+exit:
+	fm34ne_dsp_reset(dsp);
+	fm34ne_dsp_disable_hw(dsp);
+
+	return ret;
+}
+
+static void fm34ne_dsp_remove(struct snd_soc_component *component)
+{
+	struct fm34ne_dsp *dsp = snd_soc_component_get_drvdata(component);
+
+	fm34ne_dsp_reset(dsp);
+	fm34ne_dsp_disable_hw(dsp);
+}

[ ... ]

Quoted 2 lines
sound/soc/codecs/fm34ne-dsp.c new file +2 -0
+static int fm34ne_probe(struct i2c_client *client)
+{

[ ... ]

sound/soc/codecs/fm34ne-dsp.c line 278

Quoted 4 lines
sound/soc/codecs/fm34ne-dsp.c new file +4 -0
+	dsp->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(dsp->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(dsp->reset_gpio),
+				     "Failed to get reset GPIO\n");

[Severity: Low]
Is the reset_gpio state inverted during probe and hardware disable?

In fm34ne_probe(), dsp->reset_gpio is requested with GPIOD_OUT_LOW (deasserted) before vdd_supply and dap_mclk are enabled in fm34ne_dsp_enable_hw().

In addition, both fm34ne_dsp_remove() and the error path in fm34ne_dsp_probe() call fm34ne_dsp_reset() right before fm34ne_dsp_disable_hw():

	fm34ne_dsp_reset(dsp);
	fm34ne_dsp_disable_hw(dsp);

fm34ne_dsp_reset() asserts reset_gpio (1) for 20 ms, then deasserts reset_gpio (0) and sleeps 100 ms waiting for the chip to boot, only for fm34ne_dsp_disable_hw() to immediately turn off vdd_supply and dap_mclk with reset_gpio left deasserted.

Should fm34ne_probe() request reset_gpio with GPIOD_OUT_HIGH, and should fm34ne_dsp_disable_hw() assert reset_gpio (1) instead of calling fm34ne_dsp_reset() before power-down?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2