ASoC: Add support for Airoha AN7581
Subsystems (4)
v4 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 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 | 50 ++ sound/soc/mediatek/an7581/an7581-afe-pcm.c | 529 ++++++++++++++++++ sound/soc/mediatek/an7581/an7581-dai-etdm.c | 458 +++++++++++++++ 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, 1479 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 v4 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
Re: [PATCH v4 1/4] ASoC: dt-bindings: Add Airoha AN7581 AFE Sound card
Quoted 11 lines · Christian Marangi
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.
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.yaml
PATCH v4 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 and AFE as platform driver.
This gives example on how to define and connect the AFE driver with the WM8960 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 + + 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
Re: [PATCH v4 2/4] ASoC: dt-bindings: Add Airoha AN7581 AFE with WM8960 Codec schema
Quoted 2 lines · Christian Marangi
Add DT schema for Airoha AN7581 Sound Card with the specific WM8960 i2c Codec and AFE as platform driver.
You have unwrapped commit msg and should drop references to platform driver.
Quoted 3 lines
This gives example on how to define and connect the AFE driver with the WM8960 for full functionality.
This is not necessary. You desribe here hardware, not example.
Best regards,
Krzysztof
PATCH v4 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 v4 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 | 50 ++ sound/soc/mediatek/an7581/an7581-afe-pcm.c | 529 ++++++++++++++++++ sound/soc/mediatek/an7581/an7581-dai-etdm.c | 458 +++++++++++++++ sound/soc/mediatek/an7581/an7581-reg.h | 114 ++++ sound/soc/mediatek/an7581/an7581-wm8960.c | 161 ++++++ 9 files changed, 1356 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 +50 -0
50 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 +458 -0
458 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 v4 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] The IRQ handler fails to clear the capture interrupt when playback and capture interrupts fire…
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] The IRQ handler fails to clear the capture interrupt when playback and capture interrupts fire simultaneously, causing an interrupt storm.
- [High] A race condition between mtk_dai_etdm_startup and mtk_dai_etdm_shutdown can leave the AFE hardware disabled despite an active stream.
- [High] mtk_dai_etdm_config() unconditionally dereferences etdm_data, causing a NULL pointer dereference if set_fmt was never called.
- [Medium] Device node references acquired via of_parse_phandle() are leaked on the successful execution of the machine driver probe.
- [Medium] Memory leak in mtk_dai_etdm_set_fmt() due to unconditional devm_kzalloc() on every invocation.
- [Medium] Resource leak in the error path of the frontend startup callback.
- [Medium] Userspace can flood the kernel log by requesting an unsupported audio sample rate.
- [Medium] The driver parses clock inversion formats but ignores them during hardware configuration.
--
--- Patch [4]: [PATCH v4 4/4] ASoC: airoha: Add AFE and machine driver for Airoha AN7581 --- commit 3f052d96adc8dfcd1fd37b31f3811e7ab7a88417
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. Also add the machine driver to create an actual sound card for the AFE.
Quoted 6 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +0
-0@@ -0,0 +1,529 @@
[ ... ]
Quoted 3 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +3
-0+unsigned int an7581_afe_rate_transform (struct device *dev,unsigned int rate) +{ +switch (rate) {
[ ... ]
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 82
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +5
-0+case 384000 : +return ARH_AFE_RATE_384K ; +default : +dev_warn (dev,"%s(), rate %u invalid, using %d!!!\n" , + __func__, rate,ARH_AFE_RATE_48K );
[Severity: Medium]
Could this un-ratelimited warning allow a local user to flood the kernel log?
If a user requests a valid ALSA rate like 64000 Hz via hw_params, it will fall through to this default case. Calling this in a loop might spam dmesg and cause a denial of service.
Quoted 3 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +3
-0+return ARH_AFE_RATE_48K ; + } +}
[ ... ]
Quoted 7 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +7
-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); +int ret; +
sound/soc/mediatek/an7581/an7581-afe-pcm.c line 151
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +10
-0+ 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 ); +if (ret <0 ) +dev_err (afe->dev,"hw_constraint_minmax failed\n" );
[Severity: Medium]
Will this leak resources if snd_pcm_hw_constraint_minmax() fails?
If this function returns a negative error code here, the ALSA core won't invoke the shutdown callback, meaning mtk_afe_fe_shutdown() is skipped and the resources acquired by mtk_afe_fe_startup() remain held.
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +4
-0+ } + +return ret; +}
[ ... ]
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 = afe->irqs[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]
Does this logic leave capture interrupts un-cleared if playback and capture interrupts fire simultaneously?
If both AFE_IRQ_STS_PLAY and AFE_IRQ_STS_RECORD are set in the status, the initial branch statically assigns substream = AN7581_MEMIF_DL1 and clear_reg to the DL1 clear register. While both ALSA streams will be notified, only the DL1 interrupt is cleared here. The hardware would keep the capture interrupt active, resulting in an interrupt storm upon exiting the ISR.
Quoted 2 lines
sound/soc/mediatek/an7581/an7581-afe-pcm.c new file +2
-0+regmap_clear_bits (irq_regmap, clear_reg, +BIT (AFE_IRQ_CLR_SHIFT ));
[ ... ]
Quoted 6 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +0
-0@@ -0,0 +1,458 @@
[ ... ]
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 130
Quoted 12 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +12
-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 )); + +mutex_lock (&afe_priv->user_lock); + afe_priv->users++; +mutex_unlock (&afe_priv->user_lock);
[Severity: High]
Is there a race condition between mtk_dai_etdm_startup() and mtk_dai_etdm_shutdown() that could leave the hardware disabled while active?
By setting AFE_AFE_ENABLE_SHIFT before acquiring user_lock, if shutdown() is executing concurrently for a different stream (e.g., stopping capture while starting playback), shutdown() might acquire the lock, decrement users to 0, and clear the enable bit right after startup() sets it. When startup() eventually increments users, the driver thinks the hardware is active, but it remains disabled.
Quoted 3 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +3
-0+ +return 0 ; +}
[ ... ]
Quoted 12 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +12
-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); +unsigned int wlen =get_etdm_wlen (bit_width);
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 184
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +10
-0+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) + val |=ETDM_SLAVE_MODE ;
[Severity: High]
Could this result in a NULL pointer dereference if a machine driver omits the .dai_fmt configuration?
If mtk_dai_etdm_set_fmt() is never called, etdm_data will remain NULL, and dereferencing it here would crash the kernel.
[Severity: Medium]
Are the clock inversion flags from etdm_data intentionally ignored here?
In mtk_dai_etdm_set_fmt(), SND_SOC_DAIFMT_INV_MASK is parsed and sets etdm_data->bck_inv and etdm_data->lrck_inv. However, they appear to be unused during this hardware configuration step, meaning the IN_CLK_INV and OUT_CLK_INV hardware registers are never updated to reflect the requested inversion.
Quoted 2 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +2
-0+ mask |=ETDM_BIT_LEN ; + val |=FIELD_PREP (ETDM_BIT_LEN , bit_width -1 );
[ ... ]
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +4
-0+static int mtk_dai_etdm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{
[ ... ]
Quoted 1 line
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +1
-0+switch (rate) {
[ ... ]
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 288
Quoted 8 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +8
-0+case 352800 : +case 384000 : +mtk_dai_etdm_config (afe, params, dai, substream->stream); +return 0 ; +default : +dev_err (afe->dev, +"Sample rate %d invalid\n" , + rate);
[Severity: Medium]
Could this un-ratelimited error allow a local user to flood the kernel log?
If a user requests a valid ALSA rate like 64000 Hz, it falls through to this default case, similarly to an7581_afe_rate_transform().
Quoted 3 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +3
-0+return -EINVAL ; + } +}
[ ... ]
Quoted 12 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +12
-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 ; +default : + dev_warn(afe->dev, "%s(), id %d not support\n",
sound/soc/mediatek/an7581/an7581-dai-etdm.c line 350
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +10
-0+ __func__, dai->id); +return -EINVAL ; + } + + priv_data =devm_kzalloc (afe->dev,sizeof (struct mtk_dai_etdm_priv ), +GFP_KERNEL ); +if (!priv_data) +return -ENOMEM ; + + afe_priv->dai_priv[dai->id] = priv_data;
[Severity: Medium]
Does allocating priv_data unconditionally on every invocation leak memory?
The ASoC framework can call .set_fmt multiple times (e.g., dynamically from userspace). Each call overwrites the dai_priv pointer, leaving the prior devm_kzalloc() allocations leaked for the lifetime of the device.
Quoted 1 line
sound/soc/mediatek/an7581/an7581-dai-etdm.c new file +1
-0+ etdm_data = afe_priv->dai_priv[dai->id];
[ ... ]
Quoted 6 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +0
-0@@ -0,0 +1,161 @@
[ ... ]
Quoted 2 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +2
-0+static int an7581_wm8960_machine_probe (struct platform_device *pdev) +{
[ ... ]
sound/soc/mediatek/an7581/an7581-wm8960.c line 137
Quoted 13 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +13
-0+ 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__); + goto err_of_node_put; + } + +return 0 ;
[Severity: Medium]
Does returning here leak the references to the device nodes?
of_parse_phandle() increments the reference count of the returned nodes. By returning successfully, it bypasses the of_node_put() calls in the error block. Because the driver has no .remove callback or devm action to release them upon device unbind, the references seem permanently leaked.
Quoted 6 lines
sound/soc/mediatek/an7581/an7581-wm8960.c new file +6
-0+ +err_of_node_put: +of_node_put (platform_dai_node); +of_node_put (codec_dai_node); +return ret; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v4 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.
...
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +2
-0@@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/*
sound/soc/mediatek/an7581/an7581-afe-common.h line 12
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+* an7581-afe-common.h -- Airoha AN7581 audio driver definitions +*/ + +#ifndef _AN7581_AFE_COMMON_H_ +#define _AN7581_AFE_COMMON_H_ + +#include <linux/atomic.h> +#include <sound/soc.h> +#include <linux/list.h> +#include <linux/regmap.h>
Sort these, linux/ comes before sound/.
Quoted 19 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +19
-0+#include "../../mediatek/common/mtk-base-afe.h" + +enum { +AN7581_MEMIF_DL1 , +AN7581_MEMIF_UL1 , +AN7581_MEMIF_NUM , +AN7581_DAI_ETDM =AN7581_MEMIF_NUM , +AN7581_DAI_NUM , +}; + +enum { +AN7581_IRQ_0 , +AN7581_IRQ_1 , +AN7581_IRQ_NUM , +}; + +struct an7581_memif_irq_desc { +u8 irq; +u32 status_bit;
sound/soc/mediatek/an7581/an7581-afe-common.h line 41
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+u32 clear_reg; +}; + +struct an7581_afe_private { +unsigned int users; +/* protect concurrent ETDM user tracking */ +struct mutex user_lock; + +/* dai */ +void *dai_priv[AN7581_DAI_NUM ];
The comment is redundant.
sound/soc/mediatek/an7581/an7581-afe-common.h line 48
Quoted 7 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +7
-0+}; + +unsigned int an7581_afe_rate_transform (struct device *dev, +unsigned int rate); + +/* dai register */ +int an7581_dai_etdm_register (struct mtk_base_afe *afe);
Ditto.
Quoted 2 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +2
-0+ +#endif
...
Quoted 32 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +32
-0+unsigned int an7581_afe_rate_transform (struct device *dev,unsigned int rate) +{ +switch (rate) { +case 7350 : +return ARH_AFE_RATE_7K ; +case 8000 : +return ARH_AFE_RATE_8K ; +case 11025 : +return ARH_AFE_RATE_11K ; +case 12000 : +return ARH_AFE_RATE_12K ; +case 14700 : +return ARH_AFE_RATE_14K ; +case 16000 : +return ARH_AFE_RATE_16K ; +case 22050 : +return ARH_AFE_RATE_22K ; +case 24000 : +return ARH_AFE_RATE_24K ; +case 29400 : +return ARH_AFE_RATE_29K ; +case 32000 : +return ARH_AFE_RATE_32K ; +case 44100 : +return ARH_AFE_RATE_44K ; +case 48000 : +return ARH_AFE_RATE_48K ; +case 88200 : +return ARH_AFE_RATE_88K ; +case 96000 : +return ARH_AFE_RATE_96K ; +case 176400 :
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+return ARH_AFE_RATE_176K ; +case 192000 : +return ARH_AFE_RATE_192K ; +case 352800 : +return ARH_AFE_RATE_352K ; +case 384000 : +return ARH_AFE_RATE_384K ; +default : +dev_warn (dev,"%s(), rate %u invalid, using %d!!!\n" , + __func__, rate,ARH_AFE_RATE_48K );
Three '!', really? :)
Quoted 7 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +6
-0+return ARH_AFE_RATE_48K ; + } +} +static const struct snd_pcm_hardware an7581_afe_hardware = { + .info =SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED |
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+ SNDRV_PCM_INFO_MMAP_VALID, + .formats =SNDRV_PCM_FMTBIT_S16_LE | +SNDRV_PCM_FMTBIT_S24_LE | + SNDRV_PCM_FMTBIT_S32_LE, + .period_bytes_min = 512, + .period_bytes_max = 128 * 1024, + .periods_min = 2, + .periods_max = 256, + .buffer_bytes_max = 256 * 1024, + .fifo_size = 0,
static takes care of this unless you want to explicitly state the fifo_size must be 0 - in such case comment is necessary, otherwise drop the assignment.
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +4
-0+}; + +static int an7581_memif_fs (struct snd_pcm_substream *substream, +unsigned int rate)
For the entire file - char limit is 100, there is no reason not to utilize it.
Quoted 7 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +7
-0+{ +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct snd_soc_component *component =snd_soc_rtdcom_lookup (rtd,AFE_PCM_NAME ); +struct mtk_base_afe *afe =snd_soc_component_get_drvdata (component); + +return an7581_afe_rate_transform (afe->dev, rate); +}
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+ +static int an7581_irq_fs (struct snd_pcm_substream *substream, +unsigned int rate) +{ +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct snd_soc_component *component =snd_soc_rtdcom_lookup (rtd,AFE_PCM_NAME ); +struct mtk_base_afe *afe =snd_soc_component_get_drvdata (component); + +return an7581_afe_rate_transform (afe->dev, rate); +}
These two functions seem to be identical.
Quoted 11 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +11
-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); +int ret; + + ret =mtk_afe_fe_startup (substream, dai); +if (ret <0 ) +return ret;
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+ +if (substream->stream ==SNDRV_PCM_STREAM_CAPTURE ) { + ret =snd_pcm_hw_constraint_minmax (runtime, +SNDRV_PCM_HW_PARAM_PERIOD_SIZE , +0x2000 ,UINT_MAX ); +if (ret <0 ) +dev_err (afe->dev,"hw_constraint_minmax failed\n" ); + } + +return ret;
mtk_afe_fe_startup() acquires irq via mtk_dynamic_irq_acquire(). Do we need to unwind the process if snd_pcm_hw_constraint_minmax() fails?
Quoted 1 line
+}
...
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 13 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +13
-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 ; +platform_set_drvdata (pdev, afe);
Typically drvdata is assigned last, one we know probe() is successful. Is there some specific reason why you assign the pointer immediately?
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 5 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +5
-0+ + afe->platform_priv =devm_kzalloc (&pdev->dev,sizeof (*afe_priv), +GFP_KERNEL ); +if (!afe->platform_priv) +return -ENOMEM ;
Especially when the memory allocation is still ongoing..
Quoted 30 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +30
-0+ + afe_priv = afe->platform_priv; +mutex_init (&afe_priv->user_lock); + afe->dev = &pdev->dev; + dev = afe->dev; + + reset =devm_reset_control_get_exclusive (dev,NULL ); +if (IS_ERR (reset)) +return PTR_ERR (reset); + +/* Global reset I2S */ +reset_control_assert (reset); +usleep_range (10 ,20 ); +reset_control_deassert (reset); + + afe->base_addr =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (afe->base_addr)) +return PTR_ERR (afe->base_addr); + + base =devm_platform_ioremap_resource (pdev,1 ); +if (IS_ERR (base)) +return PTR_ERR (base); + + ret =devm_pm_runtime_enable (dev); +if (ret) +return ret; + + afe->regmap =devm_regmap_init_mmio (&pdev->dev, afe->base_addr, + &an7581_afe_regmap_config); +if (IS_ERR (afe->regmap))
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+return PTR_ERR (afe->regmap); + +mutex_init (&afe->irq_alloc_lock); + +/* irq initialize */ + afe->irqs_size =AN7581_IRQ_NUM ; + afe->irqs =devm_kcalloc (dev, afe->irqs_size,sizeof (*afe->irqs), +GFP_KERNEL ); +if (!afe->irqs) +return -ENOMEM ;
If the size is known upfront, I'd just move all the allocations to the top.
Quoted 70 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +70
-0+ +for (i =0 ; i < afe->irqs_size; i++) + afe->irqs[i].irq_data = &irq_data[i]; + + afe->irqs[AN7581_IRQ_0 ].regmap = afe->regmap; + afe->irqs[AN7581_IRQ_1 ].regmap =devm_regmap_init_mmio (&pdev->dev, base, + &an7581_afe_irq1_regmap_config); +if (IS_ERR (afe->irqs[AN7581_IRQ_1 ].regmap)) +return PTR_ERR (afe->irqs[AN7581_IRQ_1 ].regmap); + +/* request irq */ + irq_id =platform_get_irq (pdev,0 ); +if (irq_id <0 ) +return irq_id; + +/* init memif */ + afe->memif_size =AN7581_MEMIF_NUM ; + afe->memif =devm_kcalloc (dev, afe->memif_size,sizeof (*afe->memif), +GFP_KERNEL ); +if (!afe->memif) +return -ENOMEM ; + +for (i =0 ; i < afe->memif_size; i++) { +int sel_irq = an7581_memif_irq_descs[i].irq; + + afe->memif[i].data = &memif_data[i]; + afe->memif[i].irq_usage = sel_irq; + afe->memif[i].const_irq =1 ; + afe->irqs[sel_irq].irq_occupyed = true; + } + +/* init sub_dais */ +INIT_LIST_HEAD (&afe->sub_dais); + + 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" ); + +for (i =0 ; i <ARRAY_SIZE (dai_register_cbs); i++) { + ret = dai_register_cbs[i](afe); +if (ret) +return dev_err_probe (dev, ret,"DAI register failed, i: %d\n" , i); + } + +/* init dai_driver and component_driver */ + ret =mtk_afe_combine_sub_dai (afe); +if (ret) +return dev_err_probe (dev, ret,"mtk_afe_combine_sub_dai fail\n" ); + + afe->mtk_afe_hardware = &an7581_afe_hardware; + afe->memif_fs = an7581_memif_fs; + afe->irq_fs = an7581_irq_fs; + +/* 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, + afe->num_dai_drivers); +if (ret) +return dev_err_probe (dev, ret,"Cannot register PCM DAI component\n" ); + +return 0 ; +}
...
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 11 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +11
-0+/* dai ops */ +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 )); + +mutex_lock (&afe_priv->user_lock);
I'd suggest to switch to guards, see cleanup.h.
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +4
-0+ afe_priv->users++; +mutex_unlock (&afe_priv->user_lock); + +return 0 ;
Why skip the return code of regmap_set_bits()?
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +4
-0+} + +static void mtk_dai_etdm_shutdown (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai)
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+{ +struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai); +struct an7581_afe_private *afe_priv = afe->platform_priv; + +mutex_lock (&afe_priv->user_lock); + afe_priv->users--; +if (!afe_priv->users) +regmap_clear_bits (afe->regmap,AFE_DAC_CON0 , +BIT (AFE_AFE_ENABLE_SHIFT )); +mutex_unlock (&afe_priv->user_lock);
Well, here we clear bits in locked state whereas above they're set unlocked. Typically such inconsistency translates to an issue.
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +4
-0+} + +static unsigned int get_etdm_ch_fixup (unsigned int channels) +{
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+if (channels >16 ) +return 24 ; +else if (channels >8 ) +return 16 ; +else if (channels >4 ) +return 8 ; +else if (channels >2 ) +return 4 ; +else +return 2 ;
Refactor, not a single 'else-if' is needed here as well as 'else'. If a preceding if-statement ends with 'return' there is no elsing anything.
Quoted 4 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +4
-0+} + +static int mtk_dai_etdm_config(struct mtk_base_afe *afe, + struct snd_pcm_hw_params *params,
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+ 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); +unsigned int wlen =get_etdm_wlen (bit_width);
All the format variables are used once or twice. I'd drop them. Right now you have 11 (!) locals on the stack.
Quoted 8 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +8
-0+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 ;
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+if (etdm_data->slave_mode) + val |=ETDM_SLAVE_MODE ; + mask |=ETDM_BIT_LEN ; + val |=FIELD_PREP (ETDM_BIT_LEN , bit_width -1 ); + mask |=ETDM_WRD_LEN ; + val |=FIELD_PREP (ETDM_WRD_LEN , wlen -1 ); + mask |=ETDM_FMT ; + val |=FIELD_PREP (ETDM_FMT , etdm_data->format); + mask |=ETDM_CH_NUM ; + val |=FIELD_PREP (ETDM_CH_NUM ,get_etdm_ch_fixup (channels) -1 );
I'd group 'mask' and 'val' together, easier to follow. These do not seem intertwined.
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 12 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +12
-0+ +/* CON1 */ + mask1 |=EDTM_LRCK_AUTO_MODE ; + val1 |=EDTM_LRCK_AUTO_MODE ; + mask1 |=EDTM_CKEN_SEL ; + val1 |=EDTM_CKEN_SEL ; + mask1 |=EDTM_LRCK_AUTO_OFF ; + val1 |=EDTM_LRCK_AUTO_OFF ; + mask1 |=EDTM_INITIAL_POINT ; + val1 |=FIELD_PREP (EDTM_INITIAL_POINT ,14 ); + mask1 |=EDTM_INITIAL_COUNT ; + val1 |=FIELD_PREP (EDTM_INITIAL_COUNT ,14 );
Ditto.
Quoted 18 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +18
-0+ +switch (stream) { +case SNDRV_PCM_STREAM_PLAYBACK : +/* set ETDM_OUT1_CON0 */ +regmap_update_bits (afe->regmap,ETDM_OUT1_CON0 , mask, val); + + mask1 |=EDTM_DIRECT_INPUT_MASTER_BCK ; + val1 |=EDTM_DIRECT_INPUT_MASTER_BCK ; + +/* set ETDM_OUT1_CON1 */ +regmap_update_bits (afe->regmap,ETDM_OUT1_CON1 , mask1, val1); + +/* set ETDM_OUT1_CON4 */ +regmap_update_bits (afe->regmap,ETDM_OUT1_CON4 ,OUT_SEL_FS , +FIELD_PREP (OUT_SEL_FS , etdm_rate)); + + regmap_update_bits(afe->irqs[AN7581_IRQ_0].regmap, + afe->irqs[AN7581_IRQ_0].irq_data->irq_en_reg,
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+ AFE_IRQ_EN_SEL, AFE_IRQ_EN_SEL_I2SOUT); +break ; +case SNDRV_PCM_STREAM_CAPTURE : +/* set ETDM_IN1_CON0 */ +regmap_update_bits (afe->regmap,ETDM_IN1_CON0 , mask, val); + +/* set ETDM_IN1_CON1 */ +regmap_update_bits (afe->regmap,ETDM_IN1_CON1 , mask1, val1); + +/* set ETDM_IN1_CON3 */
All the comments found in this function do not explain anything. Drop them.
Quoted 42 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +42
-0+regmap_update_bits (afe->regmap,ETDM_IN1_CON3 ,IN_SEL_FS , +FIELD_PREP (IN_SEL_FS , etdm_rate)); + +regmap_update_bits (afe->irqs[AN7581_IRQ_1 ].regmap, + afe->irqs[AN7581_IRQ_1 ].irq_data->irq_en_reg, +AFE_IRQ_EN_SEL ,AFE_IRQ_EN_SEL_I2SIN ); +break ; +default : +break ; + } + +return 0 ; +} + +static int mtk_dai_etdm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +unsigned int rate =params_rate (params); +struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai); + +regmap_update_bits (afe->regmap,ETDM_COWORK_CON0 , +EDTM_IN1_SLAVE_SEL , +EDTM_IN1_SLAVE_FROM_ETDMIN1_SLAVE ); +regmap_update_bits (afe->regmap,ETDM_COWORK_CON0 , +EDTM_OUT1_SLAVE_SEL , +EDTM_OUT1_SLAVE_FROM_ETDMOUT1_SLAVE ); +regmap_update_bits (afe->regmap,ETDM_COWORK_CON1 , +EDTM_IN1_SDATA0_SEL , +EDTM_IN1_SDATA0_FROM_PAD ); + +switch (rate) { +case 7350 : +case 8000 : +case 11025 : +case 12000 : +case 14700 : +case 16000 : +case 22050 : +case 24000 : +case 29400 : +case 32000 :
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+case 44100 : +case 48000 : +case 88200 : +case 96000 : +case 176400 : +case 192000 : +case 352800 : +case 384000 : +mtk_dai_etdm_config (afe, params, dai, substream->stream); +return 0 ;
Again, skipping return code of the main procedure. I'd avoid blind 'return 0'.
Quoted 7 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +7
-0+default : +dev_err (afe->dev, +"Sample rate %d invalid\n" , + rate); +return -EINVAL ; + } +}
...
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 13 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +13
-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 ; +default : +dev_warn (afe->dev,"%s(), id %d not support\n" , + __func__, dai->id);
s/support/supported/
Though this entire check looks weird. Why should set_fmt() care about DAI's ID? Such check shall be done once, early with the rest of the runtime doing just the important stuff.
Quoted 14 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +14
-0+return -EINVAL ; + } + + priv_data =devm_kzalloc (afe->dev,sizeof (struct mtk_dai_etdm_priv ), +GFP_KERNEL ); +if (!priv_data) +return -ENOMEM ; + + afe_priv->dai_priv[dai->id] = priv_data; + etdm_data = afe_priv->dai_priv[dai->id]; + +switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) { +case SND_SOC_DAIFMT_I2S : + etdm_data->format =MTK_DAI_ETDM_FORMAT_I2S ;
sound/soc/mediatek/an7581/an7581-afe-common.h
Quoted 10 lines
sound/soc/mediatek/an7581/an7581-afe-common.h new file +10
-0+break ; +case SND_SOC_DAIFMT_DSP_A : + etdm_data->format =MTK_DAI_ETDM_FORMAT_DSPA ; +break ; +case SND_SOC_DAIFMT_DSP_B : + etdm_data->format =MTK_DAI_ETDM_FORMAT_DSPB ; +break ; +default : +return -EINVAL ; + }
Please waterfall the points to all the functions/files. I can do another round once this batch is addressed or explained first.
Kind regards,
Czarek