ASoC: Add support for Airoha AN7581
Subsystems (4)
v3 cover ASoC: Add support for Airoha AN7581
Add all the patch and documentation to support Airoha AN7581 sound driver.
The card follows similar implementation with Mediatek with the codec present on i2c but with a simplified implementation register wise and additional frequency supported.
Changes v3:
- Major fix to the ETDM code
- Add duplex support
- Improve Kconfig setup
- Rework and improve YAML schema
Changes v2:
- Fix wrong edit in MAINTAINERS file
Christian Marangi (4):
ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card.
ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
ASoC: mediatek: common: permit to provide dedicated regmap for irq
ASoC: airoha: Add AFE and machine driver for Airoha AN7581
.../bindings/sound/airoha,an7581-afe.yaml | 41 ++ .../bindings/sound/airoha,an7581-wm8960.yaml | 71 +++ MAINTAINERS | 8 + sound/soc/mediatek/Kconfig | 27 +- sound/soc/mediatek/Makefile | 1 + sound/soc/mediatek/an7581/Makefile | 9 + sound/soc/mediatek/an7581/an7581-afe-common.h | 48 ++ sound/soc/mediatek/an7581/an7581-afe-pcm.c | 529 ++++++++++++++++++ sound/soc/mediatek/an7581/an7581-dai-etdm.c | 453 +++++++++++++++ sound/soc/mediatek/an7581/an7581-reg.h | 114 ++++ sound/soc/mediatek/an7581/an7581-wm8960.c | 156 ++++++ sound/soc/mediatek/common/mtk-afe-fe-dai.c | 14 +- sound/soc/mediatek/common/mtk-base-afe.h | 2 + 13 files changed, 1467 insertions(+), 6 deletions(-) create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml create mode 100644 sound/soc/mediatek/an7581/Makefile create mode 100644 sound/soc/mediatek/an7581/an7581-afe-common.h create mode 100644 sound/soc/mediatek/an7581/an7581-afe-pcm.c create mode 100644 sound/soc/mediatek/an7581/an7581-dai-etdm.c create mode 100644 sound/soc/mediatek/an7581/an7581-reg.h create mode 100644 sound/soc/mediatek/an7581/an7581-wm8960.c
Signature · 1 line
2.53.0
PATCH v3 1/4 ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card.
Add YAML schema for Airoha AN7581 AFE SoC sound card.
--- .../bindings/sound/airoha,an7581-afe.yaml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml
Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml new file +41 -0
@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/airoha,an7581-afe.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AFE PCM controller for AN7581 + +maintainers: + - Christian Marangi <[email protected]> + +properties: + compatible: + const: airoha,an7581-afe + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/interrupt-controller/irq.h> + + afe@1fbe2200 { + compatible = "airoha,an7581-afe"; + reg = <0x1fbe2200 0x9000>; + + interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>; + }; + +...
Signature · 1 line
2.53.0
PATCH v3 2/4 ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
In reply to Christian MarangiAdd YAML schema for Airoha AN7581 AFE with the specific WM8960 i2c Codec.
This gives example on how to define and connect the AFE driver with the WM9860 for full functionality.
--- .../bindings/sound/airoha,an7581-wm8960.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml new file +71 -0
@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/airoha,an7581-wm8960.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN7581 sound card with WM8960 codec + +maintainers: + - Christian Marangi <[email protected]> + +allOf: + - $ref: sound-card-common.yaml# + +properties: + compatible: + const: airoha,an7581-wm8960-sound + + platform: + type: object + + properties: + sound-dai: + items: + - description: The phandle of AN7581 platform. + + required: + - sound-dai + + additionalProperties: false + + codec: + type: object + + properties: + sound-dai: + items: + - description: The phandle of WM8960 i2c codec. + + required: + - sound-dai + + additionalProperties: false + +unevaluatedProperties: false + +required: + - compatible + - audio-routing + - platform + - codec + +examples: + - | + sound { + compatible = "airoha,an7581-wm8960-sound"; + model = "an7581-wm8960"; + audio-routing = + "Headphone", "HP_L", + "Headphone", "HP_R", + "LINPUT1", "AMIC", + "RINPUT1", "AMIC"; + + platform { + sound-dai = <&afe>; + }; + + codec { + sound-dai = <&wm8960>; + }; + };
Signature · 1 line
2.53.0
PATCH v3 3/4 ASoC: mediatek: common: permit to provide dedicated regmap for irq
In reply to Christian MarangiSome SoC might require dedicated regmap to configure some specific IRQ register.
Add an extra entry in the irq_data struct and use the specific regmap if defined.
If not defined then the global AFE regmap is used instead.
--- sound/soc/mediatek/common/mtk-afe-fe-dai.c | 14 +++++++++----- sound/soc/mediatek/common/mtk-base-afe.h | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-)
sound/soc/mediatek/common/mtk-afe-fe-dai.c +9 -5
@@ -204,11 +204,15 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,struct mtk_base_afe_irq *irqs = &afe->irqs[memif->irq_usage];const struct mtk_base_irq_data *irq_data = irqs->irq_data;unsigned int counter = runtime->period_size; +struct regmap *regmap = afe->regmap;int fs;int ret;dev_dbg (afe->dev,"%s %s cmd=%d\n" , __func__, memif->data->name, cmd); +if (irq_data->regmap) + regmap = irq_data->regmap; +switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME :
@@ -220,7 +224,7 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd, }/* set irq counter */ -mtk_regmap_update_bits (afe->regmap, irq_data->irq_cnt_reg, +mtk_regmap_update_bits (regmap, irq_data->irq_cnt_reg, irq_data->irq_cnt_maskbit, counter, irq_data->irq_cnt_shift);
@@ -230,12 +234,12 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,if (fs <0 )return -EINVAL ; -mtk_regmap_update_bits (afe->regmap, irq_data->irq_fs_reg, +mtk_regmap_update_bits (regmap, irq_data->irq_fs_reg, irq_data->irq_fs_maskbit, fs, irq_data->irq_fs_shift);/* enable interrupt */ -mtk_regmap_update_bits (afe->regmap, irq_data->irq_en_reg, +mtk_regmap_update_bits (regmap, irq_data->irq_en_reg,1 ,1 , irq_data->irq_en_shift);return 0 ;
@@ -248,10 +252,10 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd, }/* disable interrupt */ -mtk_regmap_update_bits (afe->regmap, irq_data->irq_en_reg, +mtk_regmap_update_bits (regmap, irq_data->irq_en_reg,1 ,0 , irq_data->irq_en_shift);/* and clear pending IRQ */ -mtk_regmap_write (afe->regmap, irq_data->irq_clr_reg, +mtk_regmap_write (regmap, irq_data->irq_clr_reg,1 << irq_data->irq_clr_shift);return ret;default :
sound/soc/mediatek/common/mtk-base-afe.h +2 -0
@@ -87,6 +87,8 @@ struct mtk_base_irq_data {int irq_clr_reg;int irq_clr_shift;int irq_status_shift; + +struct regmap *regmap; };struct device ;
Signature · 1 line
2.53.0
PATCH v3 4/4 ASoC: airoha: Add AFE and machine driver for Airoha AN7581
In reply to Christian MarangiAdd support for the Sound system present on Airoha AN7581 SoC. This is based on the mediatek AFE drivers.
Also add the machine driver to create an actual sound card for the AFE.
--- MAINTAINERS | 8 + sound/soc/mediatek/Kconfig | 27 +- sound/soc/mediatek/Makefile | 1 + sound/soc/mediatek/an7581/Makefile | 9 + sound/soc/mediatek/an7581/an7581-afe-common.h | 48 ++ sound/soc/mediatek/an7581/an7581-afe-pcm.c | 529 ++++++++++++++++++ sound/soc/mediatek/an7581/an7581-dai-etdm.c | 453 +++++++++++++++ sound/soc/mediatek/an7581/an7581-reg.h | 114 ++++ sound/soc/mediatek/an7581/an7581-wm8960.c | 156 ++++++ 9 files changed, 1344 insertions(+), 1 deletion(-) create mode 100644 sound/soc/mediatek/an7581/Makefile create mode 100644 sound/soc/mediatek/an7581/an7581-afe-common.h create mode 100644 sound/soc/mediatek/an7581/an7581-afe-pcm.c create mode 100644 sound/soc/mediatek/an7581/an7581-dai-etdm.c create mode 100644 sound/soc/mediatek/an7581/an7581-reg.h create mode 100644 sound/soc/mediatek/an7581/an7581-wm8960.c
MAINTAINERS +8 -0
@@ -762,6 +762,14 @@ F: Documentation/devicetree/bindings/phy/airoha,en7581-pcie-phy.yaml F: drivers/phy/phy-airoha-pcie-regs.h F: drivers/phy/phy-airoha-pcie.c +AIROHA SOUND DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml +F: Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml +F: sound/soc/mediatek/an7581/* + AIROHA SPI SNFI DRIVER M: Lorenzo Bianconi <[email protected]> M: Ray Liu <[email protected]>
sound/soc/mediatek/Kconfig +26 -1
@@ -1,10 +1,35 @@ # SPDX-License-Identifier: GPL-2.0-only -menu "Mediatek" config SND_SOC_MEDIATEK tristate select REGMAP_MMIO +menu "Airoha" + +config SND_SOC_AN7581 + tristate "ASoC support for Airoha AN7581 chip" + depends on ARCH_AIROHA || COMPILE_TEST + select SND_SOC_MEDIATEK + help + This adds ASoC platform driver support for Airoha AN7581 chip + that can be used with other codecs. + Select Y if you have such device. + If unsure select "N". + +config SND_SOC_AN7581_WM8960 + tristate "ASoc Audio driver for Airoha AN7581 with WM8960 codec" + depends on SND_SOC_AN7581 && I2C + select SND_SOC_WM8960 + help + This adds support for ASoC machine driver for Airoha AN7581 + boards with the WM8960 codecs. + Select Y if you have such device. + If unsure select "N". + +endmenu + +menu "Mediatek" + config SND_SOC_MT2701 tristate "ASoC support for Mediatek MT2701 chip" depends on ARCH_MEDIATEK
sound/soc/mediatek/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_SND_SOC_MEDIATEK) += common/ +obj-$(CONFIG_SND_SOC_AN7581) += an7581/ obj-$(CONFIG_SND_SOC_MT2701) += mt2701/ obj-$(CONFIG_SND_SOC_MT6797) += mt6797/ obj-$(CONFIG_SND_SOC_MT7986) += mt7986/
sound/soc/mediatek/an7581/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 + +# platform driver +snd-soc-an7581-afe-y := \ + an7581-afe-pcm.o \ + an7581-dai-etdm.o + +obj-$(CONFIG_SND_SOC_AN7581) += snd-soc-an7581-afe.o +obj-$(CONFIG_SND_SOC_AN7581_WM8960) += an7581-wm8960.o
sound/soc/mediatek/an7581/an7581-afe-common.h new file +48 -0
48 lines not on this page · raw message
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +529 -0
529 lines not on this page · raw message
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +453 -0
453 lines not on this page · raw message
sound/soc/mediatek/an7581/an7581-reg.h new file +114 -0
114 lines not on this page · raw message
sound/soc/mediatek/an7581/an7581-wm8960.c new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 2/4] ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Typo in the commit message: 'WM9860' instead of 'WM8960'. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Typo in the commit message: 'WM9860' instead of 'WM8960'.
--
commit 2e862912f90e2fbb165cf085da96b1e3501d00ef
Author: Christian Marangi <[email protected]>
ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
This commit adds a YAML schema for the Airoha AN7581 AFE with the specific WM8960 i2c codec. It provides an example of how to define and connect the AFE driver with the codec for full functionality.
Quoted 2 lines
This gives example on how to define and connect the AFE driver with the WM9860 for full functionality.
[Severity: Low]
This isn't a bug, but there is a typo in the commit message where the codec is referenced as WM9860 instead of WM8960.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 3/4] ASoC: mediatek: common: permit to provide dedicated regmap for irq
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Architectural Anti-Pattern: Adding a dynamically allocated per-device pointer to a global static…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Architectural Anti-Pattern: Adding a dynamically allocated per-device pointer to a global static hardware description structure. --
commit b0a6d4d7d0d69f71dca69402decc8e6c50ee4811
Author: Christian Marangi <[email protected]>
ASoC: mediatek: common: permit to provide dedicated regmap for irq
This commit adds an extra entry in the irq_data struct to allow using a specific regmap if defined. If it is not defined, the global AFE regmap is used as a fallback.
Quoted 3 lines
sound/soc/mediatek/common/mtk-base-afe.h +0
-0
[ ... ]
sound/soc/mediatek/common/mtk-base-afe.h struct mtk_base_irq_data { · line 91
Quoted 6 lines
sound/soc/mediatek/common/mtk-base-afe.h +2
-0@@ -87,6 +87,8 @@ struct mtk_base_irq_data {int irq_clr_reg;int irq_clr_shift;int irq_status_shift; + +struct regmap *regmap;
[Severity: High]
Does this change violate the Linux device model by adding a dynamically allocated per-device pointer to a global static hardware description structure?
If a devm-managed regmap is assigned to this global static array during device probe, and the driver is unbound via sysfs, the devm framework will free the regmap. This would leave a dangling pointer in the global irq_data array.
Could this lead to a use-after-free if an interrupt handler directly accesses this global array to retrieve the regmap during teardown, or if multiple device instances exist?
Would it be safer to place the instance-specific regmap pointer in struct mtk_base_afe_irq instead, which is properly dynamically allocated per device instance during probe?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v3 4/4] ASoC: airoha: Add AFE and machine driver for Airoha AN7581
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider: - [High] IRQ handler is requested before its required data structures are allocated, leading to a potential…
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [High] IRQ handler is requested before its required data structures are allocated, leading to a potential NULL pointer dereference.
- [High] The interrupt handler fails to clear all active interrupts when multiple fire simultaneously, causing an interrupt storm and duplicate ALSA state updates.
- [High] Potential NULL pointer dereference in mtk_dai_etdm_config() if the .set_fmt callback is not invoked.
- [High] Device-specific regmaps are stored in a static global array, breaking multi-instance support.
- [Medium] Unconditional memory allocation in the .set_fmt callback causes a memory leak.
- [Medium] Device tree node references are leaked on successful probe in the machine driver.
- [Medium] Clock inversion settings parsed in .set_fmt are silently ignored during hardware configuration.
- [Medium] Incorrect constraint applied to SNDRV_PCM_HW_PARAM_PERIOD_SIZE, forcing excessive latency.
- [Medium] Hardware enablement state and atomic user counters are updated non-atomically, leading to a TOCTOU race condition.
--
commit 7488a2b7823cb2f6f02588d00f40f601dc2dcb3a
Author: Christian Marangi <[email protected]>
ASoC: airoha: Add AFE and machine driver for Airoha AN7581
Add support for the Sound system present on Airoha AN7581 SoC. This is based on the mediatek AFE drivers.
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +0
-0
[ ... ]
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 269
Quoted 3 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +3
-0+static struct mtk_base_irq_data irq_data[AN7581_IRQ_NUM ] = { + [AN7581_IRQ_0 ] = { + .id =AN7581_IRQ_0 ,
[Severity: High]
Does this break support for multiple AFE hardware instances?
The device-specific regmap pointers are written directly into this static global array during an7581_afe_pcm_dev_probe(), which would cause the first device's IRQ handler to access the second device's memory-mapped registers.
[ ... ]
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +5
-0+static int an7581_afe_fe_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct snd_pcm_runtime *runtime = substream->runtime; +struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 149
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+int ret; + + ret =mtk_afe_fe_startup (substream, dai); +if (ret <0 ) +return ret; + +if (substream->stream ==SNDRV_PCM_STREAM_CAPTURE ) { + ret =snd_pcm_hw_constraint_minmax (runtime, +SNDRV_PCM_HW_PARAM_PERIOD_SIZE , +0x2000 ,UINT_MAX );
[Severity: Medium]
Will this enforce excessive latency?
The constraint is applied to SNDRV_PCM_HW_PARAM_PERIOD_SIZE, which is measured in frames. At an 8000 Hz sample rate, a minimum of 0x2000 (8192) frames enforces a minimum period latency of over 1 second. Was the intention to constrain SNDRV_PCM_HW_PARAM_PERIOD_BYTES instead?
[ ... ]
Quoted 24 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +24
-0+static irqreturn_t an7581_afe_irq_handler (int irq_id,void *dev) +{ +const struct an7581_memif_irq_desc *irq_desc; +struct mtk_base_afe *afe = dev; +struct regmap *irq_regmap; +u32 clear_reg, status; +int substream, i; + +regmap_read (afe->regmap,AFE_IRQ_STS , &status); +if (status &AFE_IRQ_STS_PLAY ) + substream =AN7581_MEMIF_DL1 ; +else + substream =AN7581_MEMIF_UL1 ; + + irq_desc = &an7581_memif_irq_descs[substream]; + irq_regmap = irq_data[irq_desc->irq].regmap; + clear_reg = irq_desc->clear_reg; + +for (i =0 ; i <AN7581_MEMIF_NUM ; i++) { +struct mtk_base_afe_memif *memif = &afe->memif[i]; + +if (!memif->substream) +continue ; +
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 345
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+if (memif->irq_usage <0 ) +continue ; + + irq_desc = &an7581_memif_irq_descs[i]; +if (status & irq_desc->status_bit) +snd_pcm_period_elapsed (memif->substream); + } + +regmap_set_bits (irq_regmap, clear_reg, +BIT (AFE_IRQ_CLR_SHIFT ));
[Severity: High]
Can this cause an interrupt storm and duplicate ALSA state updates?
If both AFE_IRQ_STS_PLAY and AFE_IRQ_STS_RECORD are set in the status register, the if/else block only selects AN7581_MEMIF_DL1. As a result, only the playback interrupt is cleared, leaving the capture interrupt active.
The loop then calls snd_pcm_period_elapsed() for both streams. Since the capture interrupt isn't cleared, the IRQ handler will immediately re-trigger, observe the capture interrupt bit, clear it, and call snd_pcm_period_elapsed() a second time for the same capture period.
[ ... ]
Quoted 9 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +9
-0+static int an7581_afe_pcm_dev_probe (struct platform_device *pdev) +{ +struct an7581_afe_private *afe_priv; +struct reset_control *reset; +struct mtk_base_afe *afe; +struct device *dev; +int i, irq_id, ret; +void *base; +
[ ... ]
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +4
-0+/* request irq */ + irq_id =platform_get_irq (pdev,0 ); +if (irq_id <0 ) +return irq_id;
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 465
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+ + ret =devm_request_irq (dev, irq_id, an7581_afe_irq_handler, +IRQF_TRIGGER_NONE ,"asys-isr" , (void *)afe); +if (ret) +return dev_err_probe (dev, ret,"Failed to request irq for asys-isr\n" ); + +/* init memif */ + afe->memif_size =AN7581_MEMIF_NUM ; + afe->memif =devm_kcalloc (dev, afe->memif_size,sizeof (*afe->memif), +GFP_KERNEL );
[Severity: High]
Could this result in a NULL pointer dereference?
The IRQ handler is requested before afe->memif is allocated. If an interrupt triggers immediately (e.g., from pending bootloader state or a shared IRQ line), an7581_afe_irq_handler() will execute and unconditionally iterate over afe->memif. Accessing &afe->memif[i] when the pointer is NULL will cause a panic.
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +0
-0
[ ... ]
Quoted 14 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +14
-0+static int mtk_dai_etdm_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai); +struct an7581_afe_private *afe_priv = afe->platform_priv; + +regmap_set_bits (afe->regmap,AFE_DAC_CON0 , +BIT (AFE_AFE_ENABLE_SHIFT )); + +atomic_inc (&afe_priv->users); + +return 0 ; +} +
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 142
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +10
-0+static void mtk_dai_etdm_shutdown (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai); +struct an7581_afe_private *afe_priv = afe->platform_priv; + +if (atomic_dec_and_test (&afe_priv->users)) +regmap_clear_bits (afe->regmap,AFE_DAC_CON0 , +BIT (AFE_AFE_ENABLE_SHIFT )); +}
[Severity: Medium]
Could this introduce a race condition?
The hardware enablement state and atomic user counters are updated non-atomically. If multiple streams are opened/closed concurrently, thread A could increment the atomic counter immediately after thread B decrements it to 0 but before thread B disables the hardware. Thread B will then disable the hardware while thread A considers it successfully enabled, leaving the hardware incorrectly powered off.
[ ... ]
Quoted 11 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +11
-0+static int mtk_dai_etdm_config (struct mtk_base_afe *afe, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai, +int stream) +{ +struct an7581_afe_private *afe_priv = afe->platform_priv; +struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; +unsigned int rate =params_rate (params); +unsigned int etdm_rate =an7581_etdm_rate_transform (afe->dev, rate); +unsigned int channels =params_channels (params); +unsigned int bit_width =params_width (params);
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 178
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +10
-0+unsigned int wlen =get_etdm_wlen (bit_width); +unsigned int val =0 , val1 =0 ; +unsigned int mask =0 , mask1 =0 ; + +dev_dbg (afe->dev,"%s(), stream %d, rate %u, bitwidth %u\n" , + __func__, stream, rate, bit_width); + +/* CON0 */ + mask |=ETDM_SLAVE_MODE ; +if (etdm_data->slave_mode)
[Severity: High]
Can this cause a NULL pointer dereference?
The etdm_data pointer is dynamically allocated and assigned in mtk_dai_etdm_set_fmt(). If a machine driver does not define a dai_fmt and the .set_fmt callback is never invoked, etdm_data will remain NULL. When an audio stream is started, this will unconditionally dereference etdm_data, causing a panic.
[Severity: Medium]
Are the clock inversion settings being ignored?
The .set_fmt callback parses SND_SOC_DAIFMT_INV_MASK and populates etdm_data->bck_inv and etdm_data->lrck_inv. However, these fields are never read or programmed into the hardware registers here in mtk_dai_etdm_config(), meaning any requested phase inversions are silently ignored.
[ ... ]
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +10
-0+static int mtk_dai_etdm_set_fmt (struct snd_soc_dai *dai,unsigned int fmt) +{ +struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai); +struct an7581_afe_private *afe_priv = afe->platform_priv; +struct mtk_dai_etdm_priv *etdm_data; +void *priv_data; + +switch (dai->id) { +case AN7581_DAI_ETDM : +break ;
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 343
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +10
-0+default : +dev_warn (afe->dev,"%s(), id %d not support\n" , + __func__, dai->id); +return -EINVAL ; + } + + priv_data =devm_kzalloc (afe->dev,sizeof (struct mtk_dai_etdm_priv ), +GFP_KERNEL ); +if (!priv_data) +return -ENOMEM ;
[Severity: Medium]
Does this cause a memory leak?
A new mtk_dai_etdm_priv struct is allocated via devm_kzalloc() on every invocation of mtk_dai_etdm_set_fmt(). Since snd_soc_dai_set_fmt() can be called multiple times during the device lifecycle (e.g., from hw_params or userspace topologies), each call leaks the previously allocated memory until the device is unbound.
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +0
-0
[ ... ]
Quoted 63 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +63
-0+static int an7581_wm8960_machine_probe (struct platform_device *pdev) +{ +struct device_node *platform_dai_node, *codec_dai_node; +struct snd_soc_card *card = &an7581_wm8960_card; +struct device_node *platform, *codec; +struct snd_soc_dai_link *dai_link; +int ret, i; + + card->dev = &pdev->dev; + + platform =of_get_child_by_name (pdev->dev.of_node,"platform" ); + +if (platform) { + platform_dai_node =of_parse_phandle (platform,"sound-dai" ,0 ); +of_node_put (platform); + +if (!platform_dai_node) { +dev_err (&pdev->dev,"Failed to parse platform/sound-dai property\n" ); +return -EINVAL ; + } + }else { +dev_err (&pdev->dev,"Property 'platform' missing or invalid\n" ); +return -EINVAL ; + } + +for_each_card_prelinks (card, i, dai_link) { +if (dai_link->platforms->name) +continue ; + dai_link->platforms->of_node = platform_dai_node; + } + + codec =of_get_child_by_name (pdev->dev.of_node,"codec" ); + +if (codec) { + codec_dai_node =of_parse_phandle (codec,"sound-dai" ,0 ); +of_node_put (codec); + +if (!codec_dai_node) { +of_node_put (platform_dai_node); +dev_err (&pdev->dev,"Failed to parse codec/sound-dai property\n" ); +return -EINVAL ; + } + }else { +of_node_put (platform_dai_node); +dev_err (&pdev->dev,"Property 'codec' missing or invalid\n" ); +return -EINVAL ; + } + +for_each_card_prelinks (card, i, dai_link) { +if (dai_link->codecs->name) +continue ; + dai_link->codecs->of_node = codec_dai_node; + } + + ret =snd_soc_of_parse_audio_routing (card,"audio-routing" ); +if (ret) { +dev_err (&pdev->dev,"Failed to parse audio-routing: %d\n" , ret); + goto err_of_node_put; + } + + ret =devm_snd_soc_register_card (&pdev->dev, card); +if (ret) { +dev_err_probe (&pdev->dev, ret,"%s snd_soc_register_card fail\n" , __func__);
sound/soc/mediatek/an7581/an7581-wm8960.c line 138
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +10
-0+ goto err_of_node_put; + } + +return 0 ; + +err_of_node_put: +of_node_put (platform_dai_node); +of_node_put (codec_dai_node); +return ret; +}
[Severity: Medium]
Are device tree node references leaked here on successful probe?
The of_parse_phandle() function increments the reference count of the returned nodes for platform_dai_node and codec_dai_node. While the error paths correctly call of_node_put(), the success path returns 0 without ever dropping these references. Since there is no .remove callback or devres action to clean them up, the OF nodes are permanently leaked.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v3 1/4] ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card.
In reply to Christian MarangiQuoted 2 lines · Christian Marangi
Add YAML schema for Airoha AN7581 AFE SoC sound card.
Nit: subject, drop final stop.
Quoted 22 lines
Signed-off-by Christian Marangi <[email protected]>--- .../bindings/sound/airoha,an7581-afe.yaml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-afe.yamlDocumentation/devicetree/bindings/sound/airoha,an7581-afe.yaml new file +10
-0@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/airoha,an7581-afe.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AFE PCM controller for AN7581 + +maintainers: + - Christian Marangi <[email protected]>
Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml line 20
Quoted 10 lines
Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml new file +10
-0+ +properties: + compatible: + const: airoha,an7581-afe + + reg: + maxItems: 1 + + interrupts: + maxItems: 1
This looks incomplete - missing at least clocks. Are you sure that AFE here is so limited, comparing to other Mediatek designs?
Best regards,
Krzysztof
Re: [PATCH v3 2/4] ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
In reply to Christian MarangiQuoted 1 line · Christian Marangi
Add YAML schema for Airoha AN7581 AFE with the specific WM8960 i2c Codec.
DT schema. There is no YAML schema.
Also, looks like sound card, not AFE... but previous patch said it is a sound card (while it was AFE), so completely confusing...
Quoted 27 lines
This gives example on how to define and connect the AFE driver with the WM9860 for full functionality.
Signed-off-by Christian Marangi <[email protected]>--- .../bindings/sound/airoha,an7581-wm8960.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yamlDocumentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml new file +11
-0@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/airoha,an7581-wm8960.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN7581 sound card with WM8960 codec + +maintainers: + - Christian Marangi <[email protected]> +
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml new file +10
-0+allOf: + - $ref: sound-card-common.yaml# + +properties: + compatible: + const: airoha,an7581-wm8960-sound + + platform: + type: object +
additionalProperties go here. Looks at other Mediatek sound cards.
Quoted 14 lines
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml new file +14
-0+ properties: + sound-dai: + items: + - description: The phandle of AN7581 platform. + + required: + - sound-dai + + additionalProperties: false + + codec: + type: object + + properties:
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml line 45
Quoted 10 lines
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml new file +10
-0+ sound-dai: + items: + - description: The phandle of WM8960 i2c codec. + + required: + - sound-dai + + additionalProperties: false + +unevaluatedProperties: false
This goes after "required:".
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml line 48
Quoted 3 lines
Documentation/devicetree/bindings/sound/airoha,an7581-wm8960.yaml new file +3
-0+ +required: + - compatible
Best regards,
Krzysztof
Re: [PATCH v3 1/4] ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card.
In reply to Krzysztof KozlowskiQuoted 34 lines · Krzysztof Kozlowski
Quoted 2 lines · Christian Marangi
Add YAML schema for Airoha AN7581 AFE SoC sound card.
Nit: subject, drop final stop.
Quoted 27 lines
Signed-off-by Christian Marangi <[email protected]>--- .../bindings/sound/airoha,an7581-afe.yaml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/airoha,an7581-afe.yamlDocumentation/devicetree/bindings/sound/airoha,an7581-afe.yaml new file +15
-0@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/airoha,an7581-afe.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AFE PCM controller for AN7581 + +maintainers: + - Christian Marangi <[email protected]> + +properties: + compatible: + const: airoha,an7581-afe +
Quoted 9 lines
Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml line 20
Quoted 5 lines
Documentation/devicetree/bindings/sound/airoha,an7581-afe.yaml new file +5
-0+ reg: + maxItems: 1 + + interrupts: + maxItems: 1This looks incomplete - missing at least clocks. Are you sure that AFE here is so limited, comparing to other Mediatek designs?
Sorry for the late reply, I checked documentation and the SoC doesn't have a clock for AFE, Airoha reported that it's always enable from reset condition. The clock driver doesn't expose it.
Quoted 1 line
Signature · 1 line
Ansuel