ASoC: Add Loongson-2K0300 I2S controller and sound card support
Subsystems (5)
Binbin Zhou
maintainerv2 cover ASoC: Add Loongson-2K0300 I2S controller and sound card support
Hi all:
This series adds ASoC support for the Loongson-2K0300 SoC and its associated development boards, including the CTCISZ Forever Pi and the ATK-DL2K0300B.
Key changes:
- Extend DT bindings to support ls2k0300-i2s and new audio card compatibles.
- Refactor the platform I2S driver to handle SoC differences via per-device configuration (rev_id, optional APB DMA config, reset sequence).
- Refactor the audio machine driver to support board-specific DAI formats, GPIO-based headphone detection/mute, speaker enable, and DAPM routing.
- Add jack detection and automatic switching between headphones and speakers for the DL2K0300B board.
The patchset also cleans up the existing audio card binding by referencing the common sound-card properties, and adds new compatibles for the Loongson-2K0300 variants with proper DAI format handling.
All changes have been tested on Loongson-2K2000 (PCI), Loongson-2K0300 Forever Pi and Loongson-2K0300 DL2K0300B boards.
Thanks.
Binbin
========
v2:
- The first four patches for V1 (related to code cleanup) have been accepted as a separate series. The link is as follows:
https://lore.kernel.org/all/178041371415.93058.4794135670349989571.b4-ty@b4/
Patch (1/7):
- Add Reviewed-by tag from Krzysztof Kozlowski;
Patch (3/7):
- New patch;
- Reference sound-card-common.yaml, drop custom model property;
Patch (4/7)(5/7):
- New patches;
- Support Forever Pi board with different DAI format;
Patch (6/7)(7/7):
- New patches;
- Implement headphone jack detection and DAPM routing for ATK-DL2K0300B board.
Link to V1:
https://lore.kernel.org/all/[email protected]/
Binbin Zhou (7):
ASoC: dt-bindings: loongson,ls2k1000-i2s: Document Loongson-2K0300
compatible
ASoC: loongson: Add Loongson-2K0300 I2S controller support
ASoC: dt-bindings: loongson,ls-audio-card: Use common sound card
ASoC: dt-bindings: loongson,ls-audio-card: Add ctcisz forever pi
compatible
ASoC: loongson: Add Loongson-2K0300 CTCISZ Forever Pi sound card
support
ASoC: dt-bindings: loongson,ls-audio-card: Add ATK-DL2K0300B
compatible
ASoC: loongson: Add headphone jack detection and DAPM routing
.../sound/loongson,ls-audio-card.yaml | 52 +++++- .../bindings/sound/loongson,ls2k1000-i2s.yaml | 22 ++- sound/soc/loongson/loongson_card.c | 163 +++++++++++++++++- sound/soc/loongson/loongson_i2s_plat.c | 42 ++++- 4 files changed, 256 insertions(+), 23 deletions(-)
base-commit: b2a71527074f5e4d273a25f6c89fb159172b2877
Signature · 1 line
2.52.0
Binbin Zhou
maintainerPATCH v2 1/7 ASoC: dt-bindings: loongson,ls2k1000-i2s: Document Loongson-2K0300 compatible
Add a new compatible string loongson,ls2k0300-i2s for the I2S controller found on Loongson-2K0300 SoC.
Unlike Loongson-2K1000, Loongson-2K0300 does not require the second register region for APB DMA configuration, so update the binding to allow a single reg entry.
--- .../bindings/sound/loongson,ls2k1000-i2s.yaml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/sound/loongson,ls2k1000-i2s.yaml +21 -1
@@ -14,9 +14,12 @@ allOf: properties: compatible: - const: loongson,ls2k1000-i2s + enum: + - loongson,ls2k0300-i2s + - loongson,ls2k1000-i2s reg: + minItems: 1 items: - description: Loongson I2S controller Registers. - description: APB DMA config register for Loongson I2S controller.
@@ -49,6 +52,23 @@ required: unevaluatedProperties: false +if: + properties: + compatible: + contains: + enum: + - loongson,ls2k1000-i2s + +then: + properties: + reg: + minItems: 2 + +else: + properties: + reg: + maxItems: 1 + examples: - | #include <dt-bindings/clock/loongson,ls2k-clk.h>
Signature · 1 line
2.52.0
Binbin Zhou
maintainerPATCH v2 2/7 ASoC: loongson: Add Loongson-2K0300 I2S controller support
In reply to Binbin ZhouThe Loongson-2K0300 I2S interface differs significantly from the Loongson-2K1000. Although both utilize external DMA controllers, the Loongson-2K0300 does not require additional registers for routing configuration.
Due to hardware design flaw, an extra controller reset sequence is required during probe.
--- sound/soc/loongson/loongson_i2s_plat.c | 42 +++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-)
sound/soc/loongson/loongson_i2s_plat.c +35 -7
@@ -2,7 +2,7 @@// // Loongson I2S controller master mode dirver(platform device) // -// Copyright (C) 2023-2024 Loongson Technology Corporation Limited +// Copyright (C) 2023-2026 Loongson Technology Corporation Limited // // Author: Yingkun Meng <[email protected]> // Binbin Zhou <[email protected]>
@@ -21,6 +21,7 @@#include "loongson_i2s.h" #include "loongson_dma.h" +/* Loongson-2K1000 APBDMA routing */ #define LOONGSON_I2S_RX_DMA_OFFSET 21#define LOONGSON_I2S_TX_DMA_OFFSET 18
@@ -30,6 +31,11 @@#define LOONGSON_DMA3_CONF 0x3#define LOONGSON_DMA4_CONF 0x4 +struct loongson_i2s_plat_config { +int rev_id; +int (*i2s_dma_config)(struct platform_device *pdev); +}; +static int loongson_i2s_apbdma_config (struct platform_device *pdev) {int val;
@@ -47,8 +53,18 @@ static int loongson_i2s_apbdma_config(struct platform_device *pdev)return 0 ; } +static struct loongson_i2s_plat_config ls2k1000_i2s_plat_config = { + .rev_id =0 , + .i2s_dma_config = loongson_i2s_apbdma_config, +}; + +static struct loongson_i2s_plat_config ls2k0300_i2s_plat_config = { + .rev_id =1 , +}; +static int loongson_i2s_plat_probe (struct platform_device *pdev) { +const struct loongson_i2s_plat_config *plat_config;struct device *dev = &pdev->dev;struct loongson_i2s *i2s;struct resource *res;
@@ -59,12 +75,17 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev)if (!i2s)return -ENOMEM ; - ret =loongson_i2s_apbdma_config (pdev); -if (ret) -return ret; + plat_config =device_get_match_data (dev); +if (!plat_config) +return -EINVAL ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - i2s->reg_base =devm_ioremap_resource (&pdev->dev, res); +if (plat_config->i2s_dma_config) { + ret = plat_config->i2s_dma_config (pdev); +if (ret) +return ret; + } + + i2s->reg_base =devm_platform_get_and_ioremap_resource (pdev,0 , &res);if (IS_ERR (i2s->reg_base))return dev_err_probe (dev,PTR_ERR (i2s->reg_base),"devm_ioremap_resource failed\n" );
@@ -87,11 +108,17 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev)if (IS_ERR (i2s_clk))return dev_err_probe (dev,PTR_ERR (i2s_clk),"clock property invalid\n" ); i2s->clk_rate =clk_get_rate (i2s_clk); + i2s->rev_id = plat_config->rev_id;dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 ));dev_set_name (dev,LS_I2S_DRVNAME );dev_set_drvdata (dev, i2s); +if (i2s->rev_id ==1 ) { +regmap_update_bits (i2s->regmap,LS_I2S_CTRL ,I2S_CTRL_RESET ,I2S_CTRL_RESET ); +fsleep (200 ); + } + ret =devm_snd_soc_register_component (dev, &loongson_i2s_edma_component, &loongson_i2s_dai,1 );if (ret)
@@ -102,7 +129,8 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev) }static const struct of_device_id loongson_i2s_ids[] = { - { .compatible ="loongson,ls2k1000-i2s" }, + { .compatible ="loongson,ls2k0300-i2s" , .data = &ls2k0300_i2s_plat_config }, + { .compatible ="loongson,ls2k1000-i2s" , .data = &ls2k1000_i2s_plat_config }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, loongson_i2s_ids);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v2 2/7] ASoC: loongson: Add Loongson-2K0300 I2S controller support
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The hardware reset sequence is executed during probe but is missing from the resume path, which…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The hardware reset sequence is executed during probe but is missing from the resume path, which will cause the device to malfunction after waking up from sleep.
- [Low] Platform configuration structures are not marked as const.
--
commit 33b4276799f09ecdd4e5a93ded6b7cc2b6154e10
Author: Binbin Zhou <[email protected]>
ASoC: loongson: Add Loongson-2K0300 I2S controller support
This commit adds support for the Loongson-2K0300 I2S controller. It introduces new match data structures and applies an extra hardware reset sequence during probe to work around a controller design flaw.
Quoted 4 lines
sound/soc/loongson/loongson_i2s_plat.c +0
-0
[ ... ]
sound/soc/loongson/loongson_i2s_plat.c static int loongson_i2s_apbdma_config(struct platform_device *pdev) · line 64
Quoted 13 lines
sound/soc/loongson/loongson_i2s_plat.c +9
-0@@ -47,8 +53,18 @@ static int loongson_i2s_apbdma_config(struct platform_device *pdev)return 0 ; } +static struct loongson_i2s_plat_config ls2k1000_i2s_plat_config = { + .rev_id =0 , + .i2s_dma_config = loongson_i2s_apbdma_config, +}; + +static struct loongson_i2s_plat_config ls2k0300_i2s_plat_config = { + .rev_id =1 , +}; +
[Severity: Low]
Should these platform configuration structures be marked as const?
Since they are statically allocated and used exclusively as read-only match data, omitting const places them in the mutable .data section instead of .rodata. Marking them as const would save RAM and reduce the mutable attack surface.
Quoted 2 lines
sound/soc/loongson/loongson_i2s_plat.c +0
-0static int loongson_i2s_plat_probe (struct platform_device *pdev) {
[ ... ]
Quoted 5 lines
sound/soc/loongson/loongson_i2s_plat.c +1
-0@@ -87,11 +108,17 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev)if (IS_ERR (i2s_clk))return dev_err_probe (dev,PTR_ERR (i2s_clk),"clock property invalid\n" ); i2s->clk_rate =clk_get_rate (i2s_clk); + i2s->rev_id = plat_config->rev_id;
sound/soc/loongson/loongson_i2s_plat.c static int loongson_i2s_plat_probe(struct platform_device *pdev) · line 121
Quoted 10 lines
sound/soc/loongson/loongson_i2s_plat.c +5
-0dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 ));dev_set_name (dev,LS_I2S_DRVNAME );dev_set_drvdata (dev, i2s); +if (i2s->rev_id ==1 ) { +regmap_update_bits (i2s->regmap,LS_I2S_CTRL ,I2S_CTRL_RESET ,I2S_CTRL_RESET ); +fsleep (200 ); + } +
[Severity: High]
Will the device malfunction after waking up from sleep because this reset sequence is missing from the resume path?
If the device loses power during system suspend, it will wake up in its default flawed state. The shared PM operations only perform a regcache_sync() during resume:
sound/soc/loongson/loongson_i2s.c:i2s_resume() {
struct loongson_i2s *i2s = dev_get_drvdata(dev);
regcache_cache_only(i2s->regmap, false);
return regcache_sync(i2s->regmap);
}Because LS_I2S_CTRL is a volatile register, regcache_sync() skips it. Without reapplying this reset sequence in i2s_resume(), does the controller remain in an unstable state after resuming?
Quoted 3 lines
sound/soc/loongson/loongson_i2s_plat.c +0
-0ret =devm_snd_soc_register_component (dev, &loongson_i2s_edma_component, &loongson_i2s_dai,1 );if (ret)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Huacai Chen
maintainerRe: [PATCH v2 2/7] ASoC: loongson: Add Loongson-2K0300 I2S controller support
In reply to Binbin ZhouHi, Binbin,
Quoted 49 lines · Binbin Zhou
The Loongson-2K0300 I2S interface differs significantly from the Loongson-2K1000. Although both utilize external DMA controllers, the Loongson-2K0300 does not require additional registers for routing configuration.
Due to hardware design flaw, an extra controller reset sequence is required during probe.
Signed-off-by Binbin Zhou <[email protected]>--- sound/soc/loongson/loongson_i2s_plat.c | 42 +++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-)sound/soc/loongson/loongson_i2s_plat.c +7
-1@@ -2,7 +2,7 @@// // Loongson I2S controller master mode dirver(platform device) // -// Copyright (C) 2023-2024 Loongson Technology Corporation Limited +// Copyright (C) 2023-2026 Loongson Technology Corporation Limited // // Author: Yingkun Meng <[email protected]> // Binbin Zhou <[email protected]> @@ -21,6 +21,7 @@#include "loongson_i2s.h" #include "loongson_dma.h" +/* Loongson-2K1000 APBDMA routing */ #define LOONGSON_I2S_RX_DMA_OFFSET 21#define LOONGSON_I2S_TX_DMA_OFFSET 18@@ -30,6 +31,11 @@#define LOONGSON_DMA3_CONF 0x3#define LOONGSON_DMA4_CONF 0x4 +struct loongson_i2s_plat_config { +int rev_id; +int (*i2s_dma_config)(struct platform_device *pdev); +}; +static int loongson_i2s_apbdma_config (struct platform_device *pdev) {int val;@@ -47,8 +53,18 @@ static int loongson_i2s_apbdma_config(struct platform_device *pdev)return 0 ;
sound/soc/loongson/loongson_i2s_plat.c static int loongson_i2s_apbdma_config(struct platform_device *pdev) · line 63
Quoted 10 lines
sound/soc/loongson/loongson_i2s_plat.c +8
-0} +static struct loongson_i2s_plat_config ls2k1000_i2s_plat_config = { + .rev_id =0 , + .i2s_dma_config = loongson_i2s_apbdma_config, +}; + +static struct loongson_i2s_plat_config ls2k0300_i2s_plat_config = { + .rev_id =1 , +};
Put ls2k0300_i2s_plat_config before ls2k1000_i2s_plat_config?
Huacai
Quoted 62 lines
sound/soc/loongson/loongson_i2s_plat.c +20
-7+static int loongson_i2s_plat_probe (struct platform_device *pdev) { +const struct loongson_i2s_plat_config *plat_config;struct device *dev = &pdev->dev;struct loongson_i2s *i2s;struct resource *res;@@ -59,12 +75,17 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev)if (!i2s)return -ENOMEM ; - ret =loongson_i2s_apbdma_config (pdev); -if (ret) -return ret; + plat_config =device_get_match_data (dev); +if (!plat_config) +return -EINVAL ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - i2s->reg_base =devm_ioremap_resource (&pdev->dev, res); +if (plat_config->i2s_dma_config) { + ret = plat_config->i2s_dma_config (pdev); +if (ret) +return ret; + } + + i2s->reg_base =devm_platform_get_and_ioremap_resource (pdev,0 , &res);if (IS_ERR (i2s->reg_base))return dev_err_probe (dev,PTR_ERR (i2s->reg_base),"devm_ioremap_resource failed\n" );@@ -87,11 +108,17 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev)if (IS_ERR (i2s_clk))return dev_err_probe (dev,PTR_ERR (i2s_clk),"clock property invalid\n" ); i2s->clk_rate =clk_get_rate (i2s_clk); + i2s->rev_id = plat_config->rev_id;dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 ));dev_set_name (dev,LS_I2S_DRVNAME );dev_set_drvdata (dev, i2s); +if (i2s->rev_id ==1 ) { +regmap_update_bits (i2s->regmap,LS_I2S_CTRL ,I2S_CTRL_RESET ,I2S_CTRL_RESET ); +fsleep (200 ); + } + ret =devm_snd_soc_register_component (dev, &loongson_i2s_edma_component, &loongson_i2s_dai,1 );if (ret)@@ -102,7 +129,8 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev) }static const struct of_device_id loongson_i2s_ids[] = { - { .compatible ="loongson,ls2k1000-i2s" }, + { .compatible ="loongson,ls2k0300-i2s" , .data = &ls2k0300_i2s_plat_config }, + { .compatible ="loongson,ls2k1000-i2s" , .data = &ls2k1000_i2s_plat_config }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, loongson_i2s_ids); --2.52.0
Re: [PATCH v2 2/7] ASoC: loongson: Add Loongson-2K0300 I2S controller support
Quoted 55 lines · Huacai Chen
Hi, Binbin,
Quoted 51 lines · Binbin Zhou
The Loongson-2K0300 I2S interface differs significantly from the Loongson-2K1000. Although both utilize external DMA controllers, the Loongson-2K0300 does not require additional registers for routing configuration.
Due to hardware design flaw, an extra controller reset sequence is required during probe.
Signed-off-by Binbin Zhou <[email protected]>--- sound/soc/loongson/loongson_i2s_plat.c | 42 +++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-)sound/soc/loongson/loongson_i2s_plat.c +7
-1@@ -2,7 +2,7 @@// // Loongson I2S controller master mode dirver(platform device) // -// Copyright (C) 2023-2024 Loongson Technology Corporation Limited +// Copyright (C) 2023-2026 Loongson Technology Corporation Limited // // Author: Yingkun Meng <[email protected]> // Binbin Zhou <[email protected]> @@ -21,6 +21,7 @@#include "loongson_i2s.h" #include "loongson_dma.h" +/* Loongson-2K1000 APBDMA routing */ #define LOONGSON_I2S_RX_DMA_OFFSET 21#define LOONGSON_I2S_TX_DMA_OFFSET 18@@ -30,6 +31,11 @@#define LOONGSON_DMA3_CONF 0x3#define LOONGSON_DMA4_CONF 0x4 +struct loongson_i2s_plat_config { +int rev_id; +int (*i2s_dma_config)(struct platform_device *pdev); +}; +static int loongson_i2s_apbdma_config (struct platform_device *pdev) {int val;@@ -47,8 +53,18 @@ static int loongson_i2s_apbdma_config(struct platform_device *pdev)return 0 ; }
Quoted 9 lines
sound/soc/loongson/loongson_i2s_plat.c static int loongson_i2s_apbdma_config(struct platform_device *pdev) · line 63
Quoted 8 lines
sound/soc/loongson/loongson_i2s_plat.c +8
-0+static struct loongson_i2s_plat_config ls2k1000_i2s_plat_config = { + .rev_id =0 , + .i2s_dma_config = loongson_i2s_apbdma_config, +}; + +static struct loongson_i2s_plat_config ls2k0300_i2s_plat_config = { + .rev_id =1 , +};Put
ls2k0300_i2s_plat_configbeforels2k1000_i2s_plat_config?
OK, I will do it in the next version.
Quoted 65 lines
Huacai
Quoted 62 lines
sound/soc/loongson/loongson_i2s_plat.c +20
-7+static int loongson_i2s_plat_probe (struct platform_device *pdev) { +const struct loongson_i2s_plat_config *plat_config;struct device *dev = &pdev->dev;struct loongson_i2s *i2s;struct resource *res;@@ -59,12 +75,17 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev)if (!i2s)return -ENOMEM ; - ret =loongson_i2s_apbdma_config (pdev); -if (ret) -return ret; + plat_config =device_get_match_data (dev); +if (!plat_config) +return -EINVAL ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - i2s->reg_base =devm_ioremap_resource (&pdev->dev, res); +if (plat_config->i2s_dma_config) { + ret = plat_config->i2s_dma_config (pdev); +if (ret) +return ret; + } + + i2s->reg_base =devm_platform_get_and_ioremap_resource (pdev,0 , &res);if (IS_ERR (i2s->reg_base))return dev_err_probe (dev,PTR_ERR (i2s->reg_base),"devm_ioremap_resource failed\n" );@@ -87,11 +108,17 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev)if (IS_ERR (i2s_clk))return dev_err_probe (dev,PTR_ERR (i2s_clk),"clock property invalid\n" ); i2s->clk_rate =clk_get_rate (i2s_clk); + i2s->rev_id = plat_config->rev_id;dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 ));dev_set_name (dev,LS_I2S_DRVNAME );dev_set_drvdata (dev, i2s); +if (i2s->rev_id ==1 ) { +regmap_update_bits (i2s->regmap,LS_I2S_CTRL ,I2S_CTRL_RESET ,I2S_CTRL_RESET ); +fsleep (200 ); + } + ret =devm_snd_soc_register_component (dev, &loongson_i2s_edma_component, &loongson_i2s_dai,1 );if (ret)@@ -102,7 +129,8 @@ static int loongson_i2s_plat_probe(struct platform_device *pdev) }static const struct of_device_id loongson_i2s_ids[] = { - { .compatible ="loongson,ls2k1000-i2s" }, + { .compatible ="loongson,ls2k0300-i2s" , .data = &ls2k0300_i2s_plat_config }, + { .compatible ="loongson,ls2k1000-i2s" , .data = &ls2k1000_i2s_plat_config }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, loongson_i2s_ids); --2.52.0
Signature · 2 lines
Thanks. Binbin
Binbin Zhou
maintainerPATCH v2 3/7 ASoC: dt-bindings: loongson,ls-audio-card: Use common sound card
In reply to Binbin ZhouReference the common sound card properties. This allows removing the model property and directly using the common audio-routing property later on.
--- .../bindings/sound/loongson,ls-audio-card.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +5 -6
@@ -8,20 +8,20 @@ title: Loongson 7axxx/2kxxx ASoC audio sound card driver maintainers: - Yingkun Meng <[email protected]> + - Binbin Zhou <[email protected]> description: The binding describes the sound card present in loongson 7axxx/2kxxx platform. The sound card is an ASoC component which uses Loongson I2S controller to transfer the audio data. +allOf: + - $ref: sound-card-common.yaml# + properties: compatible: const: loongson,ls-audio-card - model: - $ref: /schemas/types.yaml#/definitions/string - description: User specified audio sound card name - mclk-fs: $ref: simple-card.yaml#/definitions/mclk-fs
@@ -47,12 +47,11 @@ properties: required: - compatible - - model - mclk-fs - cpu - codec -additionalProperties: false +unevaluatedProperties: false examples: - |
Signature · 1 line
2.52.0
Re: [PATCH v2 3/7] ASoC: dt-bindings: loongson,ls-audio-card: Use common sound card
Quoted 9 lines · Binbin Zhou
Reference the common sound card properties. This allows removing the
modelproperty and directly using the commonaudio-routingproperty later on.Signed-off-by Binbin Zhou <[email protected]>--- .../bindings/sound/loongson,ls-audio-card.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
Binbin Zhou
maintainerPATCH v2 4/7 ASoC: dt-bindings: loongson,ls-audio-card: Add ctcisz forever pi compatible
In reply to Binbin ZhouAdd a new compatible string loongson,ls2k0300-ctcisz-audio-card for the audio card on Loongson-2K0300 ctcisz forever pi SoC. It uses a different DAI format compared to existing Loongson platforms.
The existing "loongson,ls-audio-card" remains valid for LS7A, Loongson-2K1000 and Loongson-2K2000.
--- .../devicetree/bindings/sound/loongson,ls-audio-card.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +3 -1
@@ -20,7 +20,9 @@ allOf: properties: compatible: - const: loongson,ls-audio-card + enum: + - loongson,ls-audio-card # Loongson-2K1000/Loongson-2K2000/LS7A + - loongson,ls2k0300-forever-pi-audio-card # CTCISZ Forever Pi mclk-fs: $ref: simple-card.yaml#/definitions/mclk-fs
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v2 4/7] ASoC: dt-bindings: loongson,ls-audio-card: Add ctcisz forever pi compatible
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message specifies a different compatible string than what is actually added in the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message specifies a different compatible string than what is actually added in the code. --
commit 9b240b4406c6099d7dd0c7904cdd748ee7b2bb68
Author: Binbin Zhou <[email protected]>
ASoC: dt-bindings: loongson,ls-audio-card: Add ctcisz forever pi compatible
This commit adds a new compatible string for the audio card on the Loongson-2K0300 ctcisz forever pi SoC.
Quoted 2 lines
Add a new compatible string
loongson,ls2k0300-ctcisz-audio-cardfor the audio card on Loongson-2K0300 ctcisz forever pi SoC.
[Severity: Medium]
Is the compatible string in this description accurate? The commit message specifies loongson,ls2k0300-ctcisz-audio-card, but the code actually adds loongson,ls2k0300-forever-pi-audio-card to the properties enum in the device tree bindings.
Subsequent patches in the series correctly implement driver support for loongson,ls2k0300-forever-pi-audio-card, which suggests the code is correct but the commit message is inaccurate. Could the commit message be updated to match the code?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Binbin Zhou
maintainerPATCH v2 5/7 ASoC: loongson: Add Loongson-2K0300 CTCISZ Forever Pi sound card support
In reply to Binbin ZhouThe Loongson-2K0300 audio card uses a different DAI format compared to existing Loongson platforms.
Move the dai_fmt setting from the static DAI link to runtime hw_params via snd_soc_runtime_set_dai_fmt(), and pass the correct format through driver match data.
--- sound/soc/loongson/loongson_card.c | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
sound/soc/loongson/loongson_card.c +29 -5
@@ -2,8 +2,9 @@// // Loongson ASoC Audio Machine driver // -// Copyright (C) 2023 Loongson Technology Corporation Limited +// Copyright (C) 2023-2026 Loongson Technology Corporation Limited // Author: Yingkun Meng <[email protected]> +// Binbin Zhou <[email protected]> // #include <linux/module.h>
@@ -18,6 +19,19 @@ static char codec_name[SND_ACPI_I2C_ID_LEN];struct loongson_card_data {struct snd_soc_card snd_card;unsigned int mclk_fs; +const struct loongson_card_config *cfg; +}; + +struct loongson_card_config { +unsigned int fmt; +}; + +static const struct loongson_card_config ls2k1000_card_config = { + .fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_IB_NF |SND_SOC_DAIFMT_CBC_CFC , +}; + +static const struct loongson_card_config ls2k0300_forever_pi_card_config = { + .fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_CBC_CFC , }; static int loongson_card_hw_params(struct snd_pcm_substream *substream,
@@ -45,7 +59,7 @@ static int loongson_card_hw_params(struct snd_pcm_substream *substream,return ret; } -return 0 ; +return snd_soc_runtime_set_dai_fmt (rtd, ls_card->cfg->fmt); }static const struct snd_soc_ops loongson_ops = {
@@ -61,8 +75,6 @@ static struct snd_soc_dai_link loongson_dai_links[] = { { .name = "Loongson Audio Port", .stream_name ="Loongson Audio" , - .dai_fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_IB_NF - |SND_SOC_DAIFMT_CBC_CFC ,SND_SOC_DAILINK_REG (analog), .ops = &loongson_ops, },
@@ -175,6 +187,10 @@ static int loongson_asoc_card_probe(struct platform_device *pdev)if (!ls_priv)return -ENOMEM ; + ls_priv->cfg = (const struct loongson_card_config *)device_get_match_data (dev); +if (!ls_priv->cfg) +return -EINVAL ; + card = &ls_priv->snd_card; card->dev = dev;
@@ -200,7 +216,15 @@ static int loongson_asoc_card_probe(struct platform_device *pdev) }static const struct of_device_id loongson_asoc_dt_ids[] = { - { .compatible ="loongson,ls-audio-card" }, +/* Loongson-2K1000/Loongson-2K2000/LS7A */ + { + .compatible ="loongson,ls-audio-card" , + .data = &ls2k1000_card_config + }, + { + .compatible ="loongson,ls2k0300-forever-pi-audio-card" , + .data = &ls2k0300_forever_pi_card_config + }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, loongson_asoc_dt_ids);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v2 5/7] ASoC: loongson: Add Loongson-2K0300 CTCISZ Forever Pi sound card support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Uninitialized pointer codec_dai_name is used if the required device property is missing. --
commit ca8a45881e3592679d02b8f941222c143f73d4c0
Author: Binbin Zhou <[email protected]>
ASoC: loongson: Add Loongson-2K0300 CTCISZ Forever Pi sound card support
The Loongson-2K0300 audio card uses a different DAI format compared to existing Loongson platforms. Move the dai_fmt setting from the static DAI link to runtime hw_params via snd_soc_runtime_set_dai_fmt(), and pass the correct format through driver match data.
sound/soc/loongson/loongson_card.c
Quoted 4 lines
sound/soc/loongson/loongson_card.c +0
-0
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this file I noticed a pre-existing issue in loongson_card_parse_acpi().
Is it possible for the "codec-dai-name" device property to be missing?
In loongson_card_parse_acpi(), codec_dai_name is declared without being initialized:
const char *codec_dai_name;
...
device_property_read_string(card->dev, "codec-dai-name", &codec_dai_name);
for (i = 0; i < card->num_links; i++) {
loongson_dai_links[i].platforms->name = dev_name(phy_dev);
loongson_dai_links[i].codecs->name = codec_name;
loongson_dai_links[i].codecs->dai_name = codec_dai_name;
}If device_property_read_string() returns an error because the property is missing, codec_dai_name remains uninitialized garbage. This garbage pointer is then assigned to the global loongson_dai_links[i].codecs->dai_name, which ASoC core will dereference during component matching.
Could this lead to a kernel panic if the firmware lacks this property? Should the return value of device_property_read_string() be checked or a default value be provided?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Binbin Zhou
maintainerPATCH v2 6/7 ASoC: dt-bindings: loongson,ls-audio-card: Add ATK-DL2K0300B compatible
In reply to Binbin ZhouAdd new compatible for the ATK-DL2K0300B development board based on Loongson-2K0300.
Unlike others, this board features GPIO-controlled headphone detection, headphone mute, and speaker enable.
--- .../sound/loongson,ls-audio-card.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+)
Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +37 -0
@@ -23,6 +23,7 @@ properties: enum: - loongson,ls-audio-card # Loongson-2K1000/Loongson-2K2000/LS7A - loongson,ls2k0300-forever-pi-audio-card # CTCISZ Forever Pi + - loongson,ls2k0300-dl2k0300b-audio-card # ATK-DL2K0300B mclk-fs: $ref: simple-card.yaml#/definitions/mclk-fs
@@ -47,6 +48,18 @@ properties: required: - sound-dai + loongson,spkr-en-gpios: + maxItems: 1 + description: The GPIO that enables the speakers + + loongson,hp-mute-gpios: + maxItems: 1 + description: The GPIO that mutes the headphones + + loongson,hp-det-gpios: + maxItems: 1 + description: The GPIO that detect headphones are plugged in + required: - compatible - mclk-fs
@@ -69,3 +82,27 @@ examples: sound-dai = <&es8323>; }; }; + + - | + #include <dt-bindings/gpio/gpio.h> + + sound { + compatible = "loongson,ls2k0300-dl2k0300b-audio-card"; + model = "loongson-audio"; + mclk-fs = <512>; + loongson,hp-det-gpios = <&gpio 81 GPIO_ACTIVE_HIGH>; + loongson,spkr-en-gpios = <&gpio 86 GPIO_ACTIVE_HIGH>; + loongson,hp-mute-gpios = <&gpio 87 GPIO_ACTIVE_HIGH>; + audio-routing = + "Headphone", "LOUT1", + "Headphone", "ROUT1", + "Speaker", "LOUT2", + "Speaker", "ROUT2"; + + cpu { + sound-dai = <&i2s>; + }; + codec { + sound-dai = <&es8388>; + }; + };
Signature · 1 line
2.52.0
Rob Herring
maintainerRe: [PATCH v2 6/7] ASoC: dt-bindings: loongson,ls-audio-card: Add ATK-DL2K0300B compatible
Quoted 28 lines · Binbin Zhou
Add new compatible for the ATK-DL2K0300B development board based on Loongson-2K0300.
Unlike others, this board features GPIO-controlled headphone detection, headphone mute, and speaker enable.
Signed-off-by Binbin Zhou <[email protected]>--- .../sound/loongson,ls-audio-card.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+)Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +2
-0@@ -23,6 +23,7 @@ properties: enum: - loongson,ls-audio-card # Loongson-2K1000/Loongson-2K2000/LS7A - loongson,ls2k0300-forever-pi-audio-card # CTCISZ Forever Pi + - loongson,ls2k0300-dl2k0300b-audio-card # ATK-DL2K0300B mclk-fs: $ref: simple-card.yaml#/definitions/mclk-fs@@ -47,6 +48,18 @@ properties: required: - sound-dai + loongson,spkr-en-gpios:
Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml properties: · line 61
Quoted 10 lines
Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +10
-0+ maxItems: 1 + description: The GPIO that enables the speakers + + loongson,hp-mute-gpios: + maxItems: 1 + description: The GPIO that mutes the headphones + + loongson,hp-det-gpios: + maxItems: 1 + description: The GPIO that detect headphones are plugged in
We have standard properties for at least this one. If you see multiple $vendor,foo-bar properties, don't add yet another vendor foo-bar property.
Rob
Re: [PATCH v2 6/7] ASoC: dt-bindings: loongson,ls-audio-card: Add ATK-DL2K0300B compatible
Hi Rob:
Thanks for your review.
Quoted 29 lines · Rob Herring
Quoted 27 lines · Binbin Zhou
Add new compatible for the ATK-DL2K0300B development board based on Loongson-2K0300.
Unlike others, this board features GPIO-controlled headphone detection, headphone mute, and speaker enable.
Signed-off-by Binbin Zhou <[email protected]>--- .../sound/loongson,ls-audio-card.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+)Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +1
-0@@ -23,6 +23,7 @@ properties: enum: - loongson,ls-audio-card # Loongson-2K1000/Loongson-2K2000/LS7A - loongson,ls2k0300-forever-pi-audio-card # CTCISZ Forever Pi + - loongson,ls2k0300-dl2k0300b-audio-card # ATK-DL2K0300B mclk-fs: $ref: simple-card.yaml#/definitions/mclk-fs@@ -47,6 +48,18 @@ properties: required: - sound-dai
Quoted 15 lines
Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml properties: · line 61
Quoted 11 lines
Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +11
-0+ loongson,spkr-en-gpios: + maxItems: 1 + description: The GPIO that enables the speakers + + loongson,hp-mute-gpios: + maxItems: 1 + description: The GPIO that mutes the headphones + + loongson,hp-det-gpios: + maxItems: 1 + description: The GPIO that detect headphones are plugged inWe have standard properties for at least this one. If you see multiple $vendor,foo-bar properties, don't add yet another vendor foo-bar property.
Yes, the hp-det-gpios property can be found in audio-graph-card2.yaml or audio-graph-card.yaml, but I don't seem to be able to reference it directly.
I’m not sure if I understood your suggestion correctly—to remove the vendor prefix? If so, could I use the fsl sound card[1] as a reference?
Also, the description for hp-mute-gpios is inaccurate; it actually controls the enable state of the hp. I will rename it to hp-ctl-gpios, as follows:
spkr-en-gpios:
maxItems: 1
description: The GPIO that enables the speakers
hp-ctl-gpios:
maxItems: 1
description: The GPIO that controls the headphones
hp-det-gpios:
maxItems: 1
description: The GPIO that detects when headphones are plugged in
Quoted 2 lines
Rob
--
Thanks.
Binbin
Binbin Zhou
maintainerPATCH v2 7/7 ASoC: loongson: Add headphone jack detection and DAPM routing
In reply to Binbin ZhouExtend the Loongson audio machine driver with jack detection, DAPM widgets support, enabling proper switching between headphones and speakers on the Loongson-2K0300 ATK-DL2K0300B board.
--- sound/soc/loongson/loongson_card.c | 129 ++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 3 deletions(-)
sound/soc/loongson/loongson_card.c +126 -3
@@ -7,33 +7,129 @@// Binbin Zhou <[email protected]> // -#include <linux/module.h> -#include <sound/soc.h> -#include <sound/soc-acpi.h> #include <linux/acpi.h> +#include <linux/gpio/consumer.h> +#include <linux/module.h> #include <linux/pci.h> +#include <sound/jack.h> #include <sound/pcm_params.h> +#include <sound/soc.h> +#include <sound/soc-acpi.h> static char codec_name[SND_ACPI_I2C_ID_LEN ];struct loongson_card_data {struct snd_soc_card snd_card;unsigned int mclk_fs; +struct gpio_desc *gpiod_hp_det; +struct gpio_desc *gpiod_hp_mute; +struct gpio_desc *gpiod_spkr_en;const struct loongson_card_config *cfg; };struct loongson_card_config {unsigned int fmt; +bool add_hp_jack; +bool add_dapm_widgets; };static const struct loongson_card_config ls2k1000_card_config = { .fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_IB_NF |SND_SOC_DAIFMT_CBC_CFC , + .add_hp_jack = false, + .add_dapm_widgets = false, };static const struct loongson_card_config ls2k0300_forever_pi_card_config = { .fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_CBC_CFC , + .add_hp_jack = false, + .add_dapm_widgets = false, +}; + +static const struct loongson_card_config ls2k0300_dl2k0300b_card_config = { + .fmt =SND_SOC_DAIFMT_I2S |SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_CBC_CFC , + .add_hp_jack = true, + .add_dapm_widgets = true, +}; + +/* DAPM widget event: control headphone mute GPIO */ +static int headphone_widget_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) +{ +struct snd_soc_card *card =snd_soc_dapm_to_card (w->dapm); +struct loongson_card_data *priv =snd_soc_card_get_drvdata (card); + +gpiod_set_value_cansleep (priv->gpiod_hp_mute,SND_SOC_DAPM_EVENT_ON (event)); + +return 0 ; +} + +/* DAPM widget event: control speaker enable GPIO */ +static int speaker_widget_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) +{ +struct snd_soc_card *card =snd_soc_dapm_to_card (w->dapm); +struct loongson_card_data *priv =snd_soc_card_get_drvdata (card); + +gpiod_set_value_cansleep (priv->gpiod_spkr_en,SND_SOC_DAPM_EVENT_ON (event)); + +return 0 ; +} + +static const struct snd_soc_dapm_widget loongson_aosc_dapm_widgets[] = { +SND_SOC_DAPM_HP ("Headphone" , headphone_widget_event), +SND_SOC_DAPM_SPK ("Speaker" , speaker_widget_event), +}; + +/* Headphones Jack */ + +static struct snd_soc_jack loongson_asoc_hp_jack; + +static struct snd_soc_jack_pin loongson_asoc_hp_jack_pins[] = { + { + .pin ="Headphone" , + .mask =SND_JACK_HEADPHONE + }, + { + .pin ="Speaker" , + .mask =SND_JACK_HEADPHONE , + .invert =1 + }, }; +static struct snd_soc_jack_gpio loongson_asoc_hp_jack_gpio = { + .name ="Headphones detection" , + .report =SND_JACK_HEADPHONE , + .debounce_time =150 , +}; + +static int loongson_asoc_machine_init (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_card *card = rtd->card; +struct loongson_card_data *ls_priv =snd_soc_card_get_drvdata (card); +int ret =0 ; + +if (!ls_priv->cfg->add_hp_jack) +return 0 ; + + ret =snd_soc_card_jack_new_pins (card,"Headphones Jack" , +SND_JACK_HEADPHONE , + &loongson_asoc_hp_jack, + loongson_asoc_hp_jack_pins, +ARRAY_SIZE (loongson_asoc_hp_jack_pins)); +if (ret) { +dev_err (rtd->dev,"Headphones Jack creation failed: %d\n" , ret); +return ret; + } + + loongson_asoc_hp_jack_gpio.desc = ls_priv->gpiod_hp_det; + + ret =snd_soc_jack_add_gpios (&loongson_asoc_hp_jack,1 , &loongson_asoc_hp_jack_gpio); +if (ret) +dev_err (rtd->dev,"Headphone GPIO not added: %d\n" , ret); + +return ret; +} +static int loongson_card_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) {
@@ -75,6 +171,7 @@ static struct snd_soc_dai_link loongson_dai_links[] = { { .name = "Loongson Audio Port", .stream_name = "Loongson Audio", + .init = loongson_asoc_machine_init,SND_SOC_DAILINK_REG (analog), .ops = &loongson_ops, },
@@ -197,6 +294,12 @@ static int loongson_asoc_card_probe(struct platform_device *pdev) card->owner =THIS_MODULE ; card->dai_link = loongson_dai_links; card->num_links =ARRAY_SIZE (loongson_dai_links); + +if (ls_priv->cfg->add_dapm_widgets) { + card->dapm_widgets = loongson_aosc_dapm_widgets; + card->num_dapm_widgets =ARRAY_SIZE (loongson_aosc_dapm_widgets); + } +snd_soc_card_set_drvdata (card, ls_priv); ret =device_property_read_string (dev,"model" , &card->name);
@@ -207,6 +310,22 @@ static int loongson_asoc_card_probe(struct platform_device *pdev)if (ret)return dev_err_probe (dev, ret,"Error parsing mclk-fs\n" ); + ls_priv->gpiod_hp_det =devm_gpiod_get_optional (dev,"loongson,hp-det" ,GPIOD_IN ); +if (IS_ERR (ls_priv->gpiod_hp_det)) +return PTR_ERR (ls_priv->gpiod_hp_det); + + ls_priv->gpiod_hp_mute =devm_gpiod_get_optional (dev,"loongson,hp-mute" ,GPIOD_OUT_LOW ); +if (IS_ERR (ls_priv->gpiod_hp_mute)) +return PTR_ERR (ls_priv->gpiod_hp_mute); + + ls_priv->gpiod_spkr_en =devm_gpiod_get_optional (dev,"loongson,spkr-en" ,GPIOD_OUT_LOW ); +if (IS_ERR (ls_priv->gpiod_spkr_en)) +return PTR_ERR (ls_priv->gpiod_spkr_en); + + ret =snd_soc_of_parse_audio_routing (card,"audio-routing" ); +if (ret) +dev_warn (dev,"Unable to parse routing\n" ); + ret =has_acpi_companion (dev) ?loongson_card_parse_acpi (ls_priv) :loongson_card_parse_of (ls_priv);if (ret)
@@ -225,6 +344,10 @@ static const struct of_device_id loongson_asoc_dt_ids[] = { .compatible = "loongson,ls2k0300-forever-pi-audio-card", .data = &ls2k0300_forever_pi_card_config }, + { + .compatible = "loongson,ls2k0300-dl2k0300b-audio-card", + .data = &ls2k0300_dl2k0300b_card_config + }, { /* sentinel */ }, };MODULE_DEVICE_TABLE (of, loongson_asoc_dt_ids);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v2 7/7] ASoC: loongson: Add headphone jack detection and DAPM routing
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The headphone mute GPIO is incorrectly asserted when the headphone widget powers on, muting the…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The headphone mute GPIO is incorrectly asserted when the headphone widget powers on, muting the audio.
- [High] Double-free / reference count underflow of the headphone detection GPIO descriptor on device unbind or probe failure.
- [Medium] The sound card probe fails completely if the optional headphone detection GPIO is omitted from the device tree. --
commit 5cf0c58f5dc0c2adba751fce8cc39fa382767c93
Author: Binbin Zhou <[email protected]>
Subject: ASoC: loongson: Add headphone jack detection and DAPM routing
This commit adds headphone jack detection and DAPM routing to the Loongson audio machine driver. It enables proper switching between headphones and speakers on the Loongson-2K0300 ATK-DL2K0300B board.
Quoted 4 lines
sound/soc/loongson/loongson_card.c +0
-0
[ ... ]
sound/soc/loongson/loongson_card.c line 61
Quoted 8 lines
sound/soc/loongson/loongson_card.c +8
-0+/* DAPM widget event: control headphone mute GPIO */ +static int headphone_widget_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) +{ +struct snd_soc_card *card =snd_soc_dapm_to_card (w->dapm); +struct loongson_card_data *priv =snd_soc_card_get_drvdata (card); + +gpiod_set_value_cansleep (priv->gpiod_hp_mute,SND_SOC_DAPM_EVENT_ON (event));
[Severity: High]
Does this logic assert the mute signal exactly when the headphones should be active?
The hp-mute GPIO is initialized with GPIOD_OUT_LOW (unmuted) during probe. When the widget powers on, SND_SOC_DAPM_EVENT_ON evaluates to 1, asserting the mute and resulting in no sound. When it powers off, it evaluates to 0, unmuting.
Should this logic be inverted so the headphones remain muted while powered off and unmuted when active?
Quoted 3 lines
sound/soc/loongson/loongson_card.c +3
-0+ +return 0 ; +}
[ ... ]
Quoted 12 lines
sound/soc/loongson/loongson_card.c +12
-0+static int loongson_asoc_machine_init (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_card *card = rtd->card; +struct loongson_card_data *ls_priv =snd_soc_card_get_drvdata (card); +int ret =0 ; + +if (!ls_priv->cfg->add_hp_jack) +return 0 ; + + ret = snd_soc_card_jack_new_pins(card, "Headphones Jack", + SND_JACK_HEADPHONE, + &loongson_asoc_hp_jack,
sound/soc/loongson/loongson_card.c line 126
Quoted 10 lines
sound/soc/loongson/loongson_card.c +10
-0+ loongson_asoc_hp_jack_pins, + ARRAY_SIZE(loongson_asoc_hp_jack_pins)); +if (ret) { +dev_err (rtd->dev,"Headphones Jack creation failed: %d\n" , ret); +return ret; + } + + loongson_asoc_hp_jack_gpio.desc = ls_priv->gpiod_hp_det; + + ret =snd_soc_jack_add_gpios (&loongson_asoc_hp_jack,1 , &loongson_asoc_hp_jack_gpio);
[Severity: Medium]
Will this cause the sound card probe to fail completely if the optional headphone detection GPIO is omitted from the device tree?
The loongson,hp-det GPIO is acquired using devm_gpiod_get_optional() during loongson_asoc_card_probe(), which returns NULL if the property is absent.
If the descriptor is NULL, passing it to snd_soc_jack_add_gpios() without setting gpiod_dev causes it to return -EINVAL. This propagates back through the DAI link initialization, breaking the device initialization.
[Severity: High]
Will this result in a double-free of the headphone detection GPIO descriptor on device unbind or probe failure?
The gpiod_hp_det descriptor is acquired with devm_gpiod_get_optional(), which registers a devres action to call gpiod_put() when the device is unbound.
Passing this explicitly acquired descriptor directly to snd_soc_jack_add_gpios() transfers ownership, as it registers its own devres action that also unconditionally calls gpiod_put().
On probe failure or unbind, devres will execute both cleanup actions, causing a reference count underflow and leading to a use-after-free of the gpio_device.
Quoted 5 lines
sound/soc/loongson/loongson_card.c +5
-0+if (ret) +dev_err (rtd->dev,"Headphone GPIO not added: %d\n" , ret); + +return ret; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Mark Brown
maintainerRe: [PATCH v2 7/7] ASoC: loongson: Add headphone jack detection and DAPM routing
In reply to Binbin Zhousound/soc/loongson/loongson_card.c static int loongson_asoc_card_probe(struct platform_device *pdev) · line 327
Quoted 3 lines · Binbin Zhou
sound/soc/loongson/loongson_card.c +3
-0+ ret =snd_soc_of_parse_audio_routing (card,"audio-routing" ); +if (ret) +dev_warn (dev,"Unable to parse routing\n" );
The routing is optional in the schema but the helper will return an error if it's missing AFAICT (the of_property_count_strings() won't find the property). I'm wondering if it makes more sense to have the check for a missing property here or in the helper...
Re: [PATCH v2 7/7] ASoC: loongson: Add headphone jack detection and DAPM routing
Hi Mark:
Thanks for your reply.
Quoted 11 lines · Mark Brown
sound/soc/loongson/loongson_card.c static int loongson_asoc_card_probe(struct platform_device *pdev) · line 327
Quoted 3 lines · Binbin Zhou
sound/soc/loongson/loongson_card.c +3
-0+ ret =snd_soc_of_parse_audio_routing (card,"audio-routing" ); +if (ret) +dev_warn (dev,"Unable to parse routing\n" );The routing is optional in the schema but the helper will return an error if it's missing AFAICT (the
of_property_count_strings()won't find the property). I'm wondering if it makes more sense to have the check for a missing property here or in the helper...
Yes, I noticed that too.
In the next version, I'll add an add_dapm_routes field to struct loongson_card_config to indicate whether dapm_routes needs to be parsed, in order to avoid unnecessary warning output.
Also, since the newly added parsing items only apply to FDT, I’ll move them to loongson_card_parse_of() as well, which should make the code clearer.
Signature · 2 lines
Thanks. Binbin