Skip to contentSkip to conversation

ASoC: codecs: Add support for Fortemedia FM34NE DSP

PATCH Superseded Svyatoslav Ryhel 2 participants 4 messages Oct 27

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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

Changes in v3:
- fix port reference
- request reset gpio asserted
- incorporate fm34ne_dsp_reset() into fm34ne_dsp_enable_hw()
- add reset asserting to fm34ne_dsp_disable_hw()
- moved bypass gpio deassertion before return in fm34ne_dsp_set_config()
---

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

 .../bindings/dsp/asus,tf201-dsp.yaml          |   74 ++
 sound/soc/codecs/Kconfig                      |   12 +
 sound/soc/codecs/Makefile                     |    2 +
 sound/soc/codecs/fm34ne-dsp.c                 |  386 ++++++
 sound/soc/codecs/fm34ne-dsp.h                 | 1030 +++++++++++++++++
 5 files changed, 1504 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 v3 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          | 74 +++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml
Documentation/devicetree/bindings/dsp/asus,tf201-dsp.yaml new file +74 -0
new file mode 100644
index 0000000000000..8b39089c99a9d
@@ -0,0 +1,74 @@
+# 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]>
+
+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: /schemas/sound/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>;
+
+        dsp@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

PATCH v3 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 |  386 ++++++++++++
 sound/soc/codecs/fm34ne-dsp.h | 1030 +++++++++++++++++++++++++++++++++
 4 files changed, 1430 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 +386 -0

386 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
#3 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] ASoC: fm34ne-dsp: mixing guard() and goto cleanup in fm34ne_dsp_set_config() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] ASoC: fm34ne-dsp: mixing guard() and goto cleanup in fm34ne_dsp_set_config() --

commit 49a97b167b8daf22a65a613318793960938a84f4
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 88 lines
sound/soc/codecs/fm34ne-dsp.c new file +82 -0
new file mode 100644
index 0000000000000..07f22507a53df
@@ -0,0 +1,386 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/property.h>
+#include <linux/regulator/consumer.h>
+
+#include <sound/core.h>
+#include <sound/soc.h>
+
+#include "fm34ne-dsp.h"
+
+struct fm34ne_dsp {
+	struct i2c_client *client;
+
+	struct gpio_desc *bypass_gpio;
+	struct gpio_desc *reset_gpio;
+
+	struct clk *dap_mclk;
+	struct regulator *vdd_supply;
+	struct mutex lock; /* prevent simultaneous parameter writing */
+
+	const struct fm34ne_dsp_info *info;
+};
+
+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:
+	gpiod_set_value_cansleep(dsp->bypass_gpio, 0);
+
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}

[Severity: Low]
In fm34ne_dsp_set_config(), dsp->lock is acquired via guard(mutex)(&dsp->lock) while i2c_master_send() failure paths jump to the exit label using goto exit to deassert dsp->bypass_gpio.

The cleanup rules in include/linux/cleanup.h state that goto-based cleanup and scope-based cleanup helpers like guard() should not be mixed in the same function:

* Lastly, given that the benefit of cleanup helpers is removal of
* "goto", and that the "goto" statement can jump between scopes, the
* expectation is that usage of "goto" and cleanup helpers is never
* mixed in the same function. I.e. for a given routine, convert all
* resources that need a "goto" cleanup to scope-based cleanup, or
* convert none of them.

Also, sound/soc/codecs/fm34ne-dsp.c uses guard(mutex) and struct mutex without explicitly including linux/cleanup.h and linux/mutex.h.

Could fm34ne_dsp_set_config() avoid mixing guard(mutex) with goto exit (for example by using break from the switch statement or a helper function for the I2C transfers), and include linux/cleanup.h and linux/mutex.h explicitly?

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