ASoC: Add support for Airoha AN7581
Subsystems (4)
v5 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 v5:
- Address comments from bot
- Better handle concurrent irq status bit
- Protect enable etdm
- Add Review tag for documentation patch
- Address formal comments from Cezary
Changes v4:
- Improve Documentation YAML
- Move IRQ regmap to mtk_base_afe_irq
- Use mutex for user tracking in ETDM
- Register IRQ after memif allocation
- Address suggestion from bot
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 | 49 ++ sound/soc/mediatek/an7581/an7581-afe-pcm.c | 517 ++++++++++++++++++ sound/soc/mediatek/an7581/an7581-dai-etdm.c | 433 +++++++++++++++ sound/soc/mediatek/an7581/an7581-reg.h | 114 ++++ sound/soc/mediatek/an7581/an7581-wm8960.c | 161 ++++++ sound/soc/mediatek/common/mtk-afe-fe-dai.c | 14 +- sound/soc/mediatek/common/mtk-base-afe.h | 2 + 13 files changed, 1441 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 v5 1/4 ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card
Add YAML schema for Airoha AN7581 AFE SoC sound card.
The AFE handling on this SoC is very basic with clock always enabled and all the power saving feature not available.
--- .../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 v5 2/4 ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
In reply to Christian MarangiAdd DT schema for Airoha AN7581 Sound Card with the specific WM8960 i2c Codec.
--- .../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 + + additionalProperties: false + + properties: + sound-dai: + items: + - description: The phandle of AN7581 platform. + + required: + - sound-dai + + codec: + type: object + + additionalProperties: false + + properties: + sound-dai: + items: + - description: The phandle of WM8960 i2c codec. + + required: + - sound-dai + +required: + - compatible + - audio-routing + - platform + - codec + +unevaluatedProperties: false + +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 v5 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 base_afe_irq 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 (irqs->regmap) + regmap = irqs->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
@@ -153,6 +153,8 @@ struct mtk_base_afe_memif {struct mtk_base_afe_irq {const struct mtk_base_irq_data *irq_data;int irq_occupyed; + +struct regmap *regmap; };struct mtk_base_afe_dai {
Signature · 1 line
2.53.0
PATCH v5 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 | 49 ++ sound/soc/mediatek/an7581/an7581-afe-pcm.c | 517 ++++++++++++++++++ sound/soc/mediatek/an7581/an7581-dai-etdm.c | 433 +++++++++++++++ sound/soc/mediatek/an7581/an7581-reg.h | 114 ++++ sound/soc/mediatek/an7581/an7581-wm8960.c | 161 ++++++ 9 files changed, 1318 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
@@ -768,6 +768,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 || COMPILE_TEST
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 +49 -0
49 lines not on this page · raw message
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +517 -0
517 lines not on this page · raw message
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +433 -0
433 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 +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v5 4/4] ASoC: airoha: Add AFE and machine driver for Airoha AN7581
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] Use of uninitialized `dev` pointer and zero-sized allocation for `afe->irqs` and `afe->memif`…
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] Use of uninitialized dev pointer and zero-sized allocation for afe->irqs and afe->memif causes a kernel panic on probe.
- [High] Potential NULL pointer dereference in mtk_dai_etdm_config if set_fmt is not called.
- [Medium] Unconditional devm_kzalloc in mtk_dai_etdm_set_fmt leads to a memory leak on repeated calls.
- [Medium] Device tree node reference leak on the success path in an7581_wm8960_machine_probe.
- [Medium] IRQ handler inappropriately returns IRQ_HANDLED when no interrupts match.
- [Medium] Clock inversion flags are successfully parsed but completely ignored by hardware configuration.
- [Medium] The IRQ handler clears the interrupt status flag after processing the event, potentially discarding new interrupts.
- [Medium] The machine driver modifies a globally defined static snd_soc_dai_link array during probe.
--
--- Patch [4]: [PATCH v5 4/4] ASoC: airoha: Add AFE and machine driver for Airoha AN7581 --- commit c3c67d6bafbbabd1b6c6e75b8c29e6aac51229d2
Author: Christian Marangi <[email protected]>
ASoC: airoha: Add AFE and machine driver for Airoha AN7581
This adds support for the Sound system present on the Airoha AN7581 SoC, based on the mediatek AFE drivers. It also includes the machine driver to create an actual sound card for the AFE.
Quoted 23 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +16
-0@@ -0,0 +1,517 @@ +static irqreturn_t an7581_afe_irq_handler (int irq_id,void *dev) +{ +for (i =0 ; i <AN7581_MEMIF_NUM ; i++) { +struct mtk_base_afe_memif *memif = &afe->memif[i]; + +if (!memif->substream) +continue ; + +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); + } +
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 331
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+for (i =0 ; i <AN7581_MEMIF_NUM ; i++) { +struct regmap *irq_regmap; + + irq_desc = &an7581_memif_irq_descs[i]; +if (!(status & irq_desc->status_bit)) +continue ; + + irq_regmap = afe->irqs[irq_desc->irq].regmap; +regmap_set_bits (irq_regmap, irq_desc->clear_reg, +BIT (AFE_IRQ_CLR_SHIFT ));
[Severity: Medium]
By clearing the interrupt status flag after calling the potentially time-consuming snd_pcm_period_elapsed(), is there a risk of inadvertently acknowledging and dropping a new interrupt that fired during the handler's execution?
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 341
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+regmap_clear_bits (irq_regmap, irq_desc->clear_reg, +BIT (AFE_IRQ_CLR_SHIFT )); + +regmap_set_bits (irq_regmap, irq_desc->clear_reg, +BIT (AFE_IRQ_MISS_FLG_CLR_SHIFT )); +regmap_clear_bits (irq_regmap, irq_desc->clear_reg, +BIT (AFE_IRQ_MISS_FLG_CLR_SHIFT )); + } + +return IRQ_HANDLED ;
[Severity: Medium]
Should this return IRQ_NONE if no interrupt flags were actually matched in the status register? Returning IRQ_HANDLED unconditionally might prevent the IRQ subsystem from detecting a spurious interrupt storm.
Quoted 7 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +6
-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;
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 385
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+struct device *dev; +int i, irq_id, ret; +void *base; + + afe =devm_kzalloc (&pdev->dev,sizeof (*afe),GFP_KERNEL ); +if (!afe) +return -ENOMEM ; + + afe->irqs =devm_kcalloc (dev, afe->irqs_size,sizeof (*afe->irqs), +GFP_KERNEL );
[Severity: High]
Is it safe to use the dev pointer here before it is initialized? It looks like dev gets assigned later in this function.
Also, since afe was just allocated with devm_kzalloc(), wouldn't afe->irqs_size be 0? Passing a size of 0 to devm_kcalloc() will return ZERO_SIZE_PTR, which could cause a panic when it is dereferenced later during initialization.
Quoted 13 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +2
-0+if (!afe->irqs) +return -ENOMEM ;sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +4
-0@@ -0,0 +1,433 @@ +static int mtk_dai_etdm_config (struct mtk_base_afe *afe, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai, +int stream)
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 187
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +9
-0+{ +struct an7581_afe_private *afe_priv = afe->platform_priv; +struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; +/* CON0 */ + mask =ETDM_SLAVE_MODE |ETDM_BIT_LEN |ETDM_WRD_LEN | +ETDM_FMT |ETDM_CH_NUM ; + val =FIELD_PREP (ETDM_BIT_LEN ,params_width (params) -1 ) | +FIELD_PREP (ETDM_WRD_LEN ,get_etdm_wlen (bit_width) -1 ) | + FIELD_PREP(ETDM_FMT, etdm_data->format) |
[Severity: High]
Is it possible for mtk_dai_etdm_config() to be called without set_fmt having been called first? If so, could dereferencing etdm_data->format here result in a NULL pointer dereference, as etdm_data is only allocated in mtk_dai_etdm_set_fmt()?
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 191
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +4
-0+FIELD_PREP (ETDM_CH_NUM , +get_etdm_ch_fixup (params_channels (params)) -1 ); +if (etdm_data->slave_mode) + val |=ETDM_SLAVE_MODE ;
[Severity: Medium]
Does the hardware configuration ignore the etdm_data->bck_inv and etdm_data->lrck_inv flags? It appears they are parsed from the format mask in mtk_dai_etdm_set_fmt() but never actually applied to any hardware registers here.
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 321
Quoted 10 lines
[ ... ]
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +9
-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; + + priv_data =devm_kzalloc (afe->dev,sizeof (struct mtk_dai_etdm_priv ), +GFP_KERNEL );
[Severity: Medium]
Could this unconditionally allocate memory on every call, potentially leaking the previous allocation if set_fmt is called multiple times by ALSA core or machine drivers?
Quoted 13 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +5
-0+if (!priv_data) +return -ENOMEM ; + + afe_priv->dai_priv[dai->id] = priv_data; + etdm_data = afe_priv->dai_priv[dai->id];sound/soc/mediatek/an7581/an7581-wm8960.c new file +1
-0@@ -0,0 +1,161 @@ +static int an7581_wm8960_machine_probe (struct platform_device *pdev)
sound/soc/mediatek/an7581/an7581-wm8960.c line 98
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +9
-0+{ +for_each_card_prelinks (card, i, dai_link) { +struct snd_soc_dai_link_component *platform; + + dai_link->num_platforms =2 ; +for_each_link_platforms (dai_link, d, platform) { +if (platform->name) +continue ; + platform->of_node = platform_dai_node;
[Severity: Medium]
Could modifying the globally defined static an7581_wm8960_dai_links array here cause stale pointers to be left behind across module reloads or unbind/bind cycles?
Quoted 6 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +5
-0+ } + } + 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 143
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]
Does returning 0 early in the success path skip the of_node_put() calls, leaking the device tree node references acquired earlier via of_parse_phandle()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Mark Brown
maintainerRe: [PATCH v5 4/4] ASoC: airoha: Add AFE and machine driver for Airoha AN7581
In reply to Christian MarangiQuoted 4 lines · Christian Marangi
Add 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.
This should be more patches, the machine driver should be a separate patch at a minimum. Possibly PCM and ETDM drivers too.
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 382
Quoted 12 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +12
-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; + + afe =devm_kzalloc (&pdev->dev,sizeof (*afe),GFP_KERNEL ); +if (!afe) +return -ENOMEM ;
We allocate afe here with devm_kzalloc() so everything is zero...
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 387
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +4
-0+ afe->irqs =devm_kcalloc (dev, afe->irqs_size,sizeof (*afe->irqs), +GFP_KERNEL ); +if (!afe->irqs) +return -ENOMEM ;
...then we allocate an array using a size read from the struct which must therefore have zero elements. We also didn't assign dev, either we should assign it and use it consistently or we should drop it and use &pdev->dev like the first allocation.
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +5
-0+/* register component */ + ret =devm_snd_soc_register_component (&pdev->dev, + &mtk_afe_pcm_platform, +NULL ,0 ); +if (ret)
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 496
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+return dev_err_probe (dev, ret,"Cannot register AFE component\n" ); + + ret =devm_snd_soc_register_component (afe->dev, + &an7581_afe_pcm_dai_component, + afe->dai_drivers, + afe->num_dai_drivers); +if (ret) +return dev_err_probe (dev, ret,"Cannot register PCM DAI component\n" ); + +platform_set_drvdata (pdev, afe);
The component registration might result in a card being instantiated so we need the driver data initialized before we try to register.
Re: [PATCH v5 4/4] ASoC: airoha: Add AFE and machine driver for Airoha AN7581
Quoted 9 lines · Mark Brown
Quoted 4 lines · Christian Marangi
Add 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.
This should be more patches, the machine driver should be a separate patch at a minimum. Possibly PCM and ETDM drivers too.
Sooo you are suggesting 3 patch? one for machine, one for basic pcm and one for etdm?
Quoted 15 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 382
Quoted 12 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +12
-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; + + afe =devm_kzalloc (&pdev->dev,sizeof (*afe),GFP_KERNEL ); +if (!afe) +return -ENOMEM ;We allocate afe here with
devm_kzalloc()so everything is zero...
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 387
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +4
-0+ afe->irqs =devm_kcalloc (dev, afe->irqs_size,sizeof (*afe->irqs), +GFP_KERNEL ); +if (!afe->irqs) +return -ENOMEM ;...then we allocate an array using a size read from the struct which must therefore have zero elements. We also didn't assign dev, either we should assign it and use it consistently or we should drop it and use
&pdev->devlike the first allocation.
Nono these were just my mistake with moving code... I already fixed them... sorry for the mistake.
Quoted 10 lines
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+/* register component */ + ret =devm_snd_soc_register_component (&pdev->dev, + &mtk_afe_pcm_platform, +NULL ,0 ); +if (ret) +return dev_err_probe (dev, ret,"Cannot register AFE component\n" ); + + ret = devm_snd_soc_register_component(afe->dev, + &an7581_afe_pcm_dai_component, + afe->dai_drivers,
Quoted 8 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 496
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +5
-0+ afe->num_dai_drivers); +if (ret) +return dev_err_probe (dev, ret,"Cannot register PCM DAI component\n" ); + +platform_set_drvdata (pdev, afe);The component registration might result in a card being instantiated so we need the driver data initialized before we try to register.
Sorry this was asked to be moved in the previous revision by another review. I will revert following the pattern done in other AFE driver...
Signature · 1 line
Ansuel
Mark Brown
maintainerRe: [PATCH v5 4/4] ASoC: airoha: Add AFE and machine driver for Airoha AN7581
Quoted 7 lines · Christian Marangi
Quoted 2 lines · Mark Brown
This should be more patches, the machine driver should be a separate patch at a minimum. Possibly PCM and ETDM drivers too.
Sooo you are suggesting 3 patch? one for machine, one for basic pcm and one for etdm?
At least, yes. Basically one driver per patch.
Quoted 10 lines · Christian Marangi
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 v5:
- Address comments from bot
- Better handle concurrent irq status bit
- Protect enable etdm
- Add Review tag for documentation patch
- Address formal comments from Cezary
Please do include the reviewers in To/CC when providing new revisions.