Add TDM audio on StarFive JH7110
Subsystems (6)
Walker Chen
maintainerv2 cover Add TDM audio on StarFive JH7110
This patchset adds TDM audio driver for the StarFive JH7110 SoC. The first patch adds device tree binding for TDM module. The second patch adds the item for JH7110 audio board to the dt-binding of StarFive SoC-based boards. The third patch adds tdm driver support for JH7110 SoC. The last patch adds device node of tdm and sound card to JH7110 dts.
The series has been tested on the VisionFive 2 board by plugging the raspberry pie audio board.
For more information of raspberry pie audio board, you can take a look at the following webpage:
https://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/
The last patch should be applied after the following patchset:
https://lore.kernel.org/all/[email protected]/
Changes since v1:
- Rebased on Linux 6.3-rc4.
- Added the dts file dedicated to describe audio card.
- Added the item for JH7110 audio board to the dt-binding of StarFive SoC-based boards.
---
v1: https://lore.kernel.org/all/[email protected]/
Walker Chen (4):
dt-bindings: sound: Add TDM for StarFive JH7110
dt-bindings: riscv: Add item for StarFive JH7110 audio board
ASoC: starfive: Add JH7110 TDM driver
riscv: dts: starfive: add tdm node and sound card
.../devicetree/bindings/riscv/starfive.yaml | 1 + .../bindings/sound/starfive,jh7110-tdm.yaml | 98 +++ MAINTAINERS | 6 + arch/riscv/boot/dts/starfive/Makefile | 1 + .../starfive/jh7110-starfive-audio-card.dts | 67 ++ .../jh7110-starfive-visionfive-2.dtsi | 40 ++ arch/riscv/boot/dts/starfive/jh7110.dtsi | 21 + sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/starfive/Kconfig | 15 + sound/soc/starfive/Makefile | 2 + sound/soc/starfive/jh7110_tdm.c | 579 ++++++++++++++++++ sound/soc/starfive/jh7110_tdm.h | 155 +++++ 13 files changed, 987 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml create mode 100644 arch/riscv/boot/dts/starfive/jh7110-starfive-audio-card.dts create mode 100644 sound/soc/starfive/Kconfig create mode 100644 sound/soc/starfive/Makefile create mode 100644 sound/soc/starfive/jh7110_tdm.c create mode 100644 sound/soc/starfive/jh7110_tdm.h
base-commit: 197b6b60ae7bc51dd0814953c562833143b292aa
prerequisite-patch-id: 30bec4dba6f250a6edd0c2cbab2ce09442e50e8a
prerequisite-patch-id: bb939c0c7c26b08addfccd890f9d3974b6eaec53
prerequisite-patch-id: 8a6f135bcabdad4a4bfb21f0c6a0ffd2bb57efe7
prerequisite-patch-id: c2366f993a9d85e28c06d8d09f064dd5e8b29a61
prerequisite-patch-id: 50d53a21f91f4087fc80b6f1f72864adfb0002b9
prerequisite-patch-id: 0df3703af91c30f1ca2c47f5609012f2d7200028
prerequisite-patch-id: 89f049f951e5acf75aab92541992f816fd0acc0d
prerequisite-patch-id: 551fae54377090044c3612fca9740a9b359abdd2
prerequisite-patch-id: c7fdf904f398d478f0ed6d57eb878982bc73329d
prerequisite-patch-id: 1b2d0982b18da060c82134f05bf3ce16425bac8d
prerequisite-patch-id: 090ba4b78d47bc19204916e76fdbc70021785388
prerequisite-patch-id: a5d9e0f7d4f8163f566678894cf693015119f2d9
prerequisite-patch-id: 4637a8fa2334a45fa6b64351f4e9e28d3e2d60d3
prerequisite-patch-id: 32647ec60a3b614e1c59ec8e54cb511ae832c22f
prerequisite-patch-id: aa06658ecf89c92d0dfdd6a4ba6d9e6e67532971
prerequisite-patch-id: 1387a7e87b446329dfc21f3e575ceae7ebcf954c
prerequisite-patch-id: 258ea5f9b8bf41b6981345dcc81795f25865d38f
prerequisite-patch-id: 8b6f2c9660c0ac0ee4e73e4c21aca8e6b75e81b9
prerequisite-patch-id: dbb0c0151b8bdf093e6ce79fd2fe3f60791a6e0b
prerequisite-patch-id: 9007c8610fdcd387592475949864edde874c20a2
prerequisite-patch-id: d57e95d31686772abc4c4d5aa1cadc344dc293cd
prerequisite-patch-id: 9f911969d0a550648493952c99096d26e05d4d83
prerequisite-patch-id: 2ddada18ab6ea5cd1da14212aaf59632f5203d40
prerequisite-patch-id: 80042661ff6156ce577a72e9eb8c0b218b624829
prerequisite-patch-id: 398744c61913c76a35754de867c4f820ca7a8d99
prerequisite-patch-id: f59269382164b5d642a5e10443ca447f5caa595c
prerequisite-patch-id: 1babe83d6bf999bad17584dc595480f9070a5369
prerequisite-patch-id: 77be3d122d66df813f13088141ce27b21107a341
prerequisite-patch-id: 9fbb7ad1dd258bb8ff5946c4a0e59de4bfd82a04
prerequisite-patch-id: 6f6984916dffd0cc66aa733c9b6bd3a55495a50c
prerequisite-patch-id: 39e1be2a3d1593577ab997f55f59367cba665aa7
prerequisite-patch-id: 584c256c9acb52ee2773d0c81c3f4977fc18155a
prerequisite-patch-id: b37ac15032973e1fcd918f157c82a0606775c9e9
prerequisite-patch-id: 32deea16304859842af5c2151bc41d91cf6dfc9b
prerequisite-patch-id: 20ac2450fb93b3f69f83fc720fd4800a95e618a6
prerequisite-patch-id: 6abf359fa445f4104432ddee27044dfbfb128417
Signature · 1 line
2.17.1
Walker Chen
maintainerPATCH v2 1/4 dt-bindings: sound: Add TDM for StarFive JH7110
Add bindings to describe the TDM driver for the StarFive JH7110 SoC.
--- .../bindings/sound/starfive,jh7110-tdm.yaml | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml
Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml new file +98 -0
@@ -0,0 +1,98 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/starfive,jh7110-tdm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive JH7110 TDM Controller + +description: | + The TDM Controller is a Time Division Multiplexed audio interface + integrated in StarFive JH7110 SoC, allowing up to 8 channels of + audio over a serial interface. The TDM controller can operate both + in master and slave mode. + +maintainers: + - Walker Chen <[email protected]> + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + enum: + - starfive,jh7110-tdm + + reg: + maxItems: 1 + + clocks: + items: + - description: TDM AHB Clock + - description: TDM APB Clock + - description: TDM Internal Clock + - description: TDM Clock + - description: Inner MCLK + - description: TDM External Clock + + clock-names: + items: + - const: tdm_ahb + - const: tdm_apb + - const: tdm_internal + - const: tdm + - const: mclk_inner + - const: tdm_ext + + resets: + items: + - description: tdm ahb reset line + - description: tdm apb reset line + - description: tdm core reset line + + dmas: + items: + - description: RX DMA Channel + - description: TX DMA Channel + + dma-names: + items: + - const: rx + - const: tx + + "#sound-dai-cells": + const: 0 + +required: + - compatible + - reg + - clocks + - clock-names + - resets + - dmas + - dma-names + - "#sound-dai-cells" + +additionalProperties: false + +examples: + - | + tdm@10090000 { + compatible = "starfive,jh7110-tdm"; + reg = <0x10090000 0x1000>; + clocks = <&syscrg 184>, + <&syscrg 185>, + <&syscrg 186>, + <&syscrg 187>, + <&syscrg 17>, + <&tdm_ext>; + clock-names = "tdm_ahb", "tdm_apb", + "tdm_internal", "tdm", + "mclk_inner", "tdm_ext"; + resets = <&syscrg 105>, + <&syscrg 107>, + <&syscrg 106>; + dmas = <&dma 20>, <&dma 21>; + dma-names = "rx","tx"; + #sound-dai-cells = <0>; + };
Signature · 1 line
2.17.1
Re: [PATCH v2 1/4] dt-bindings: sound: Add TDM for StarFive JH7110
Quoted 8 lines · Walker Chen
Add bindings to describe the TDM driver for the StarFive JH7110 SoC.
Signed-off-by Walker Chen <[email protected]>--- .../bindings/sound/starfive,jh7110-tdm.yaml | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml
Best regards,
Krzysztof
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Walker Chen
maintainerPATCH v2 2/4 dt-bindings: riscv: Add item for StarFive JH7110 audio board
In reply to Walker ChenAdd bindings to describe the audio board that works in conjunction with the VisionFive2 board.
--- Documentation/devicetree/bindings/riscv/starfive.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/riscv/starfive.yaml +1 -0
@@ -28,6 +28,7 @@ properties: - enum: - starfive,visionfive-2-v1.2a - starfive,visionfive-2-v1.3b + - starfive,visionfive-2-audio - const: starfive,jh7110 additionalProperties: true
Signature · 1 line
2.17.1
Re: [PATCH v2 2/4] dt-bindings: riscv: Add item for StarFive JH7110 audio board
Quoted 5 lines · Walker Chen
Add bindings to describe the audio board that works in conjunction with the VisionFive2 board.
Signed-off-by Walker Chen <[email protected]>---
Best regards,
Krzysztof
Walker Chen
maintainerPATCH v2 3/4 ASoC: starfive: Add JH7110 TDM driver
In reply to Walker ChenAdd tdm driver support for the StarFive JH7110 SoC.
--- MAINTAINERS | 6 + sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/starfive/Kconfig | 15 + sound/soc/starfive/Makefile | 2 + sound/soc/starfive/jh7110_tdm.c | 579 ++++++++++++++++++++++++++++++++ sound/soc/starfive/jh7110_tdm.h | 155 +++++++++ 7 files changed, 759 insertions(+) create mode 100644 sound/soc/starfive/Kconfig create mode 100644 sound/soc/starfive/Makefile create mode 100644 sound/soc/starfive/jh7110_tdm.c create mode 100644 sound/soc/starfive/jh7110_tdm.h
MAINTAINERS +6 -0
@@ -19945,6 +19945,12 @@ F: Documentation/devicetree/bindings/power/starfive* F: drivers/soc/starfive/jh71xx_pmu.c F: include/dt-bindings/power/starfive,jh7110-pmu.h +STARFIVE JH7110 TDM DRIVERS +M: Walker Chen <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/sound/starfive,jh7110-tdm.yaml +F: sound/soc/starfive/jh7110-tdm.* + STARFIVE SOC DRIVERS M: Conor Dooley <[email protected]> S: Maintained
sound/soc/Kconfig +1 -0
@@ -91,6 +91,7 @@ source "sound/soc/sh/Kconfig" source "sound/soc/sof/Kconfig" source "sound/soc/spear/Kconfig" source "sound/soc/sprd/Kconfig" +source "sound/soc/starfive/Kconfig" source "sound/soc/sti/Kconfig" source "sound/soc/stm/Kconfig" source "sound/soc/sunxi/Kconfig"
sound/soc/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_SND_SOC) += sh/ obj-$(CONFIG_SND_SOC) += sof/ obj-$(CONFIG_SND_SOC) += spear/ obj-$(CONFIG_SND_SOC) += sprd/ +obj-$(CONFIG_SND_SOC) += starfive/ obj-$(CONFIG_SND_SOC) += sti/ obj-$(CONFIG_SND_SOC) += stm/ obj-$(CONFIG_SND_SOC) += sunxi/
sound/soc/starfive/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +config SND_SOC_STARFIVE + tristate "Audio support for StarFive SoC" + depends on COMPILE_TEST || SOC_STARFIVE + help + Say Y or M if you want to add support for codecs attached to + the Starfive SoCs' Audio interfaces. You will also need to + select the audio interfaces to support below. + +config SND_SOC_JH7110_TDM + tristate "JH7110 TDM device driver" + depends on HAVE_CLK && SND_SOC_STARFIVE + select SND_SOC_GENERIC_DMAENGINE_PCM + help + Say Y or M if you want to add support for StarFive TDM driver.
sound/soc/starfive/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# StarFive Platform Support +obj-$(CONFIG_SND_SOC_JH7110_TDM) += jh7110_tdm.o
sound/soc/starfive/jh7110_tdm.c new file +579 -0
579 lines not on this page · raw message
sound/soc/starfive/jh7110_tdm.h new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH v2 3/4] ASoC: starfive: Add JH7110 TDM driver
Quoted 1 line · Walker Chen
Add tdm driver support for the StarFive JH7110 SoC.
This is mostly fine, though the code all feels a bit messy somehow. A lot of this is just coding style, I've highlighted a bunch of things below. There's also a couple of more substantial issues.
sound/soc/starfive/jh7110_tdm.c line 5
Quoted 6 lines
sound/soc/starfive/jh7110_tdm.c new file +5
-0@@ -0,0 +1,579 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* TDM driver for the StarFive JH7110 SoC +* +* Copyright (C) 2023 StarFive Technology Co., Ltd.
Please make the entire comment a C++ one so things look more intentional.
sound/soc/starfive/jh7110_tdm.c line 81
Quoted 6 lines
sound/soc/starfive/jh7110_tdm.c new file +6
-0+static int jh7110_tdm_syncdiv (struct jh7110_tdm_dev *tdm) +{ +u32 sl, sscale, syncdiv; + + sl = (tdm->rx.sl >= tdm->tx.sl) ? tdm->rx.sl : tdm->tx.sl; + sscale = (tdm->rx.sscale >= tdm->tx.sscale) ? tdm->rx.sscale : tdm->tx.sscale;
Please write normal conditional statements to improve legibility.
sound/soc/starfive/jh7110_tdm.c line 198
Quoted 9 lines
sound/soc/starfive/jh7110_tdm.c new file +8
-0+static int jh7110_tdm_clk_enable (struct jh7110_tdm_dev *tdm) +{ + ret =clk_set_parent (tdm->clk_tdm, tdm->clk_tdm_ext); +if (ret) { +dev_err (tdm->dev,"Can't set clock source for clk_tdm: %d\n" , +ret); + goto dis_tdm_clk; + }
It's a bit weird to enable clocks and then reparent afterwards, that seems more likely to run into issues with glitches doing something bad than reparenting with the clock disabled.
This parenting looks like a system specific configuration (what if the SoC is driving the audio bus?), and might be better done by using the clock bindings. It's also strange that the driver is reparenting every single time it enables the clocks rather than doing that once on init.
Quoted 5 lines
sound/soc/starfive/jh7110_tdm.c new file +5
-0+static int jh7110_tdm_suspend (struct snd_soc_component *component) +{ +return pm_runtime_force_suspend (component->dev); +} +
sound/soc/starfive/jh7110_tdm.c line 250
Quoted 10 lines
sound/soc/starfive/jh7110_tdm.c new file +10
-0+static int jh7110_tdm_resume (struct snd_soc_component *component) +{ +struct jh7110_tdm_dev *tdm =snd_soc_component_get_drvdata (component); + +/* restore context */ +jh7110_tdm_writel (tdm,TDM_PCMGBCR , tdm->saved_pcmgbcr); +jh7110_tdm_writel (tdm,TDM_PCMDIV , tdm->saved_pcmdiv); + +return pm_runtime_force_resume (component->dev); +}
It is weird that we restore context that we don't save on suspend, the code *works* but it looks off.
sound/soc/starfive/jh7110_tdm.c line 275
Quoted 13 lines
sound/soc/starfive/jh7110_tdm.c new file +13
-0+static int jh7110_tdm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct jh7110_tdm_dev *tdm =snd_soc_dai_get_drvdata (dai); +int chan_wl, chan_sl, chan_nr; +unsigned int data_width; +unsigned int dma_bus_width; +struct snd_dmaengine_dai_dma_data *dma_data =NULL ; +struct snd_soc_pcm_runtime *rtd =asoc_substream_to_rtd (substream); +struct snd_soc_dai_link *dai_link = rtd->dai_link; + + dai_link->stop_dma_first =1 ;
A driver shouldn't be forcing dai_link settings, and hw_params is claerly the wrong place to be configuring something like this which never varies at runtime - it should be done on init(). If the DAI really needs this you should extend the core so there's a flag in the dai_driver which gets checked.
sound/soc/starfive/jh7110_tdm.c line 306
Quoted 6 lines
sound/soc/starfive/jh7110_tdm.c new file +6
-0+switch (chan_nr) { +case ONE_CHANNEL_SUPPORT : +case TWO_CHANNEL_SUPPORT : +case FOUR_CHANNEL_SUPPORT : +case SIX_CHANNEL_SUPPORT : +case EIGHT_CHANNEL_SUPPORT :
I am having a *really* hard time finding these definitions (which aren't namespaced...) helpful. Just write the numbers directly.
Quoted 7 lines
sound/soc/starfive/jh7110_tdm.c new file +7
-0+static int jh7110_tdm_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_dai *dai) +{ +struct jh7110_tdm_dev *tdm =snd_soc_dai_get_drvdata (dai); +int ret =0 ; + +switch (cmd) {
sound/soc/starfive/jh7110_tdm.c line 351
Quoted 10 lines
sound/soc/starfive/jh7110_tdm.c new file +10
-0+case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +/* restore context */ +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) +jh7110_tdm_writel (tdm,TDM_PCMTXCR , tdm->saved_pcmtxcr); +else +jh7110_tdm_writel (tdm,TDM_PCMRXCR , tdm->saved_pcmrxcr); + +jh7110_tdm_start (tdm, substream);
Why is the write to CR not part of start()?
sound/soc/starfive/jh7110_tdm.c line 440
Quoted 13 lines
sound/soc/starfive/jh7110_tdm.c new file +13
-0+static void jh7110_tdm_init_params (struct jh7110_tdm_dev *tdm) +{ + tdm->clkpolity =TDM_TX_RASING_RX_FALLING ; +if (tdm->frame_mode ==SHORT_LATER ) { + tdm->elm =TDM_ELM_LATE ; + tdm->syncm =TDM_SYNCM_SHORT ; + }else if (tdm->frame_mode ==SHORT_EARLY ) { + tdm->elm =TDM_ELM_EARLY ; + tdm->syncm =TDM_SYNCM_SHORT ; + }else { + tdm->elm =TDM_ELM_EARLY ; + tdm->syncm =TDM_SYNCM_LONG ; + }
This looks like it should be a switch statement, and the defintiions namespaced. I can't see anyhwere where this ever gets configured to anything other than SHORT_LATER ever being used so might be better to just delete.
sound/soc/starfive/jh7110_tdm.c line 442
Quoted 1 line
sound/soc/starfive/jh7110_tdm.c new file +1
-0+ tdm->ms_mode =TDM_AS_SLAVE ;
Please use the modern provider/consumer terminology for clocking.
sound/soc/starfive/jh7110_tdm.c line 488
Quoted 6 lines
sound/soc/starfive/jh7110_tdm.c new file +6
-0+ tdm->clk_tdm_ahb = clks[0 ].clk; + tdm->clk_tdm_apb = clks[1 ].clk; + tdm->clk_tdm_internal = clks[2 ].clk; + tdm->clk_tdm = clks[3 ].clk; + tdm->clk_mclk_inner = clks[4 ].clk; + tdm->clk_tdm_ext = clks[5 ].clk;
Given that the driver only ever interacts with the clocks en masse is there any point in having all the specific named variables, that'd mean that the enable/disable could just use loops.
sound/soc/starfive/jh7110_tdm.h line 45
Quoted 3 lines
sound/soc/starfive/jh7110_tdm.h new file +3
-0+/* DMA registers */ +#define TDM_FIFO 0x170c0000 +#define TDM_FIFO_DEPTH 32
None of the defines in the header are namespaced and some of them (like the above) seem generic enough to be likely to result in conflicts.
Walker Chen
maintainerRe: [PATCH v2 3/4] ASoC: starfive: Add JH7110 TDM driver
Quoted 6 lines · Mark Brown
Quoted 1 line · Walker Chen
Add tdm driver support for the StarFive JH7110 SoC.
This is mostly fine, though the code all feels a bit messy somehow. A lot of this is just coding style, I've highlighted a bunch of things below. There's also a couple of more substantial issues.
Hey Mark,
Firstly thanks for your patient review and detailed comments.
Quoted 10 lines
sound/soc/starfive/jh7110_tdm.c line 5
Quoted 7 lines
sound/soc/starfive/jh7110_tdm.c new file +5
-0@@ -0,0 +1,579 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* TDM driver for the StarFive JH7110 SoC +* +* Copyright (C) 2023 StarFive Technology Co., Ltd. Please make the entire comment a C++ one so things look more intentional.
OK, can reference to other platform's format.
Quoted 9 lines
sound/soc/starfive/jh7110_tdm.c line 81
Quoted 7 lines
sound/soc/starfive/jh7110_tdm.c new file +6
-0+static int jh7110_tdm_syncdiv (struct jh7110_tdm_dev *tdm) +{ +u32 sl, sscale, syncdiv; + + sl = (tdm->rx.sl >= tdm->tx.sl) ? tdm->rx.sl : tdm->tx.sl; + sscale = (tdm->rx.sscale >= tdm->tx.sscale) ? tdm->rx.sscale : tdm->tx.sscale;Please write normal conditional statements to improve legibility.
Will be modified.
Quoted 11 lines
sound/soc/starfive/jh7110_tdm.c line 198
Quoted 10 lines
sound/soc/starfive/jh7110_tdm.c new file +8
-0+static int jh7110_tdm_clk_enable (struct jh7110_tdm_dev *tdm) +{ + ret =clk_set_parent (tdm->clk_tdm, tdm->clk_tdm_ext); +if (ret) { +dev_err (tdm->dev,"Can't set clock source for clk_tdm: %d\n" , +ret); + goto dis_tdm_clk; + }
Quoted 3 lines
It's a bit weird to enable clocks and then reparent afterwards, that seems more likely to run into issues with glitches doing something bad than reparenting with the clock disabled.
This TDM module ultimately uses an external clock. It firstly must uses internal clock before being enabled, and then is switched to external clock, otherwise failed to reset. This limitation is determined by the chip.
Quoted 6 lines
This parenting looks like a system specific configuration (what if the SoC is driving the audio bus?), and might be better done by using the clock bindings. It's also strange that the driver is reparenting every single time it enables the clocks rather than doing that once on init.
To save power consumption, need to disable clock in suspend() and enable clock in resume(). As mentioned above, the internal clock must be selected before enabling clock every time, and then switch to external clock.
Quoted 11 lines
Quoted 11 lines
sound/soc/starfive/jh7110_tdm.c new file +10
-0+static int jh7110_tdm_suspend (struct snd_soc_component *component) +{ +return pm_runtime_force_suspend (component->dev); +} + +static int jh7110_tdm_resume (struct snd_soc_component *component) +{ +struct jh7110_tdm_dev *tdm =snd_soc_component_get_drvdata (component); + +/* restore context */
Quoted 8 lines
sound/soc/starfive/jh7110_tdm.c line 250
Quoted 5 lines
sound/soc/starfive/jh7110_tdm.c new file +5
-0+jh7110_tdm_writel (tdm,TDM_PCMGBCR , tdm->saved_pcmgbcr); +jh7110_tdm_writel (tdm,TDM_PCMDIV , tdm->saved_pcmdiv); + +return pm_runtime_force_resume (component->dev); +}It is weird that we restore context that we don't save on suspend, the code *works* but it looks off.
Should be pairing operation in suspend() and resume().
Quoted 12 lines
Quoted 12 lines
sound/soc/starfive/jh7110_tdm.c new file +11
-0+static int jh7110_tdm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct jh7110_tdm_dev *tdm =snd_soc_dai_get_drvdata (dai); +int chan_wl, chan_sl, chan_nr; +unsigned int data_width; +unsigned int dma_bus_width; +struct snd_dmaengine_dai_dma_data *dma_data =NULL ; +struct snd_soc_pcm_runtime *rtd =asoc_substream_to_rtd (substream); +struct snd_soc_dai_link *dai_link = rtd->dai_link;
Quoted 8 lines
sound/soc/starfive/jh7110_tdm.c line 275
Quoted 2 lines
sound/soc/starfive/jh7110_tdm.c new file +2
-0+ + dai_link->stop_dma_first =1 ;A driver shouldn't be forcing
dai_linksettings, andhw_paramsis claerly the wrong place to be configuring something like this which never varies at runtime - it should be done oninit(). If the DAI really needs this you should extend the core so there's a flag in thedai_driverwhich gets checked.
Yes, should be done at startup of dai_driver, doing that once on initialize stage.
Quoted 10 lines
sound/soc/starfive/jh7110_tdm.c line 306
Quoted 7 lines
sound/soc/starfive/jh7110_tdm.c new file +6
-0+switch (chan_nr) { +case ONE_CHANNEL_SUPPORT : +case TWO_CHANNEL_SUPPORT : +case FOUR_CHANNEL_SUPPORT : +case SIX_CHANNEL_SUPPORT : +case EIGHT_CHANNEL_SUPPORT :I am having a *really* hard time finding these definitions (which aren't namespaced...) helpful. Just write the numbers directly.
OK, will be changed.
Quoted 12 lines
Quoted 12 lines
sound/soc/starfive/jh7110_tdm.c new file +11
-0+static int jh7110_tdm_trigger (struct snd_pcm_substream *substream, +int cmd,struct snd_soc_dai *dai) +{ +struct jh7110_tdm_dev *tdm =snd_soc_dai_get_drvdata (dai); +int ret =0 ; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +/* restore context */
Quoted 8 lines
sound/soc/starfive/jh7110_tdm.c line 351
Quoted 6 lines
sound/soc/starfive/jh7110_tdm.c new file +6
-0+if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) +jh7110_tdm_writel (tdm,TDM_PCMTXCR , tdm->saved_pcmtxcr); +else +jh7110_tdm_writel (tdm,TDM_PCMRXCR , tdm->saved_pcmrxcr); + +jh7110_tdm_start (tdm, substream);Why is the write to CR not part of
start()?
OK, will be changed.
Quoted 11 lines
Quoted 11 lines
sound/soc/starfive/jh7110_tdm.c new file +10
-0+static void jh7110_tdm_init_params (struct jh7110_tdm_dev *tdm) +{ + tdm->clkpolity =TDM_TX_RASING_RX_FALLING ; +if (tdm->frame_mode ==SHORT_LATER ) { + tdm->elm =TDM_ELM_LATE ; + tdm->syncm =TDM_SYNCM_SHORT ; + }else if (tdm->frame_mode ==SHORT_EARLY ) { + tdm->elm =TDM_ELM_EARLY ; + tdm->syncm =TDM_SYNCM_SHORT ; + }else {
Quoted 8 lines
sound/soc/starfive/jh7110_tdm.c line 440
Quoted 3 lines
sound/soc/starfive/jh7110_tdm.c new file +3
-0+ tdm->elm =TDM_ELM_EARLY ; + tdm->syncm =TDM_SYNCM_LONG ; + }This looks like it should be a switch statement, and the defintiions namespaced. I can't see anyhwere where this ever gets configured to anything other than
SHORT_LATERever being used so might be better to just delete.
Will be modified according to your suggestion.
Quoted 5 lines
sound/soc/starfive/jh7110_tdm.c line 442
Quoted 2 lines
sound/soc/starfive/jh7110_tdm.c new file +1
-0+ tdm->ms_mode =TDM_AS_SLAVE ;Please use the modern provider/consumer terminology for clocking.
Quoted 10 lines
sound/soc/starfive/jh7110_tdm.c line 488
Quoted 6 lines
sound/soc/starfive/jh7110_tdm.c new file +6
-0+ tdm->clk_tdm_ahb = clks[0 ].clk; + tdm->clk_tdm_apb = clks[1 ].clk; + tdm->clk_tdm_internal = clks[2 ].clk; + tdm->clk_tdm = clks[3 ].clk; + tdm->clk_mclk_inner = clks[4 ].clk; + tdm->clk_tdm_ext = clks[5 ].clk;Given that the driver only ever interacts with the clocks en masse is there any point in having all the specific named variables, that'd mean that the enable/disable could just use loops.
Will be changed.
Quoted 7 lines
sound/soc/starfive/jh7110_tdm.h line 45
Quoted 4 lines
sound/soc/starfive/jh7110_tdm.h new file +3
-0+/* DMA registers */ +#define TDM_FIFO 0x170c0000 +#define TDM_FIFO_DEPTH 32None of the defines in the header are namespaced and some of them (like the above) seem generic enough to be likely to result in conflicts.
Will add unified JH7110_TDM_ prefix.
Thank you very much for your suggestion.
Best regards,
Walker
Walker Chen
maintainerPATCH v2 4/4 riscv: dts: starfive: add tdm node and sound card
In reply to Walker ChenAdd the tdm controller node and sound card for the StarFive JH7110 SoC.
--- arch/riscv/boot/dts/starfive/Makefile | 1 + .../starfive/jh7110-starfive-audio-card.dts | 67 +++++++++++++++++++ .../jh7110-starfive-visionfive-2.dtsi | 40 +++++++++++ arch/riscv/boot/dts/starfive/jh7110.dtsi | 21 ++++++ 4 files changed, 129 insertions(+) create mode 100644 arch/riscv/boot/dts/starfive/jh7110-starfive-audio-card.dts
arch/riscv/boot/dts/starfive/Makefile +1 -0
@@ -4,3 +4,4 @@ dtb-$(CONFIG_ARCH_STARFIVE) += jh7100-starfive-visionfive-v1.dtb dtb-$(CONFIG_ARCH_STARFIVE) += jh7110-starfive-visionfive-2-v1.2a.dtb dtb-$(CONFIG_ARCH_STARFIVE) += jh7110-starfive-visionfive-2-v1.3b.dtb +dtb-$(CONFIG_ARCH_STARFIVE) += jh7110-starfive-audio-card.dtb
arch/riscv/boot/dts/starfive/jh7110-starfive-audio-card.dts new file +67 -0
67 lines not on this page · raw message
arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi +40 -0
@@ -214,6 +214,40 @@ slew-rate = <0>; }; }; + + tdm0_pins: tdm0-pins { + tdm0-pins-tx { + pinmux = <GPIOMUX(44, GPOUT_SYS_TDM_TXD, + GPOEN_ENABLE, + GPI_NONE)>; + bias-pull-up; + drive-strength = <2>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + + tdm0-pins-rx { + pinmux = <GPIOMUX(61, GPOUT_HIGH, + GPOEN_DISABLE, + GPI_SYS_TDM_RXD)>; + input-enable; + }; + + tdm0-pins-sync { + pinmux = <GPIOMUX(63, GPOUT_HIGH, + GPOEN_DISABLE, + GPI_SYS_TDM_SYNC)>; + input-enable; + }; + + tdm0-pins-pcmclk { + pinmux = <GPIOMUX(38, GPOUT_HIGH, + GPOEN_DISABLE, + GPI_SYS_TDM_CLK)>; + input-enable; + }; + }; }; &uart0 {
@@ -221,3 +255,9 @@ pinctrl-0 = <&uart0_pins>; status = "okay"; }; + +&tdm { + pinctrl-names = "default"; + pinctrl-0 = <&tdm0_pins>; + status = "okay"; +};
arch/riscv/boot/dts/starfive/jh7110.dtsi +21 -0
@@ -366,6 +366,27 @@ status = "disabled"; }; + tdm: tdm@10090000 { + compatible = "starfive,jh7110-tdm"; + reg = <0x0 0x10090000 0x0 0x1000>; + clocks = <&syscrg JH7110_SYSCLK_TDM_AHB>, + <&syscrg JH7110_SYSCLK_TDM_APB>, + <&syscrg JH7110_SYSCLK_TDM_INTERNAL>, + <&syscrg JH7110_SYSCLK_TDM_TDM>, + <&syscrg JH7110_SYSCLK_MCLK_INNER>, + <&tdm_ext>; + clock-names = "tdm_ahb", "tdm_apb", + "tdm_internal", "tdm", + "mclk_inner", "tdm_ext"; + resets = <&syscrg JH7110_SYSRST_TDM_AHB>, + <&syscrg JH7110_SYSRST_TDM_APB>, + <&syscrg JH7110_SYSRST_TDM_CORE>; + dmas = <&dma 20>, <&dma 21>; + dma-names = "rx","tx"; + #sound-dai-cells = <0>; + status = "disabled"; + }; + stgcrg: clock-controller@10230000 { compatible = "starfive,jh7110-stgcrg"; reg = <0x0 0x10230000 0x0 0x10000>;
Signature · 1 line
2.17.1
Conor Dooley
maintainerRe: [PATCH v2 4/4] riscv: dts: starfive: add tdm node and sound card
Hey Walker,
Quoted 1 line · Walker Chen
Add the tdm controller node and sound card for the StarFive JH7110 SoC.
Is this one of these waveshare things + a visionfive 2?
https://www.waveshare.com/wm8960-audio-hat.htm
I'm a bit lost as to why this needs a whole new board, should it not just be an overlay that you can apply to the existing dts?
Taking this to an extreme, should I expect to see a new devicetree for everything RPi hat that you decide to use with a VisionFive 2?
Also, it'd be nice to provide a Link: to where someone can find more info on this combination of items. Google for "wm8960 visionfive 2" gives me nothing, nor does "starfive audio card" etc.
Thanks,
Conor.
Quoted 182 lines
Reviewed-by Hal Feng <[email protected]>Signed-off-by Walker Chen <[email protected]>--- arch/riscv/boot/dts/starfive/Makefile | 1 + .../starfive/jh7110-starfive-audio-card.dts | 67 +++++++++++++++++++ .../jh7110-starfive-visionfive-2.dtsi | 40 +++++++++++ arch/riscv/boot/dts/starfive/jh7110.dtsi | 21 ++++++ 4 files changed, 129 insertions(+) create mode 100644 arch/riscv/boot/dts/starfive/jh7110-starfive-audio-card.dtsarch/riscv/boot/dts/starfive/Makefile +1
-0@@ -4,3 +4,4 @@ dtb-$(CONFIG_ARCH_STARFIVE) += jh7100-starfive-visionfive-v1.dtb dtb-$(CONFIG_ARCH_STARFIVE) += jh7110-starfive-visionfive-2-v1.2a.dtb dtb-$(CONFIG_ARCH_STARFIVE) += jh7110-starfive-visionfive-2-v1.3b.dtb +dtb-$(CONFIG_ARCH_STARFIVE) += jh7110-starfive-audio-card.dtbarch/riscv/boot/dts/starfive/jh7110-starfive-audio-card.dts new file +67
-0@@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/* + * Device Tree for JH7110 + Simple Audio Card + * + * Copyright (C) 2023 StarFive Technology Co., Ltd. + */ + +/dts-v1/; +#include "jh7110-starfive-visionfive-2-v1.3b.dts" + +/ { + model = "StarFive VisionFive 2 Audio Board"; + compatible = "starfive,visionfive-2-audio", "starfive,jh7110"; + + wm8960_mclk: wm8960-mclk { + compatible = "fixed-clock"; + clock-output-names = "wm8960_mclk"; + #clock-cells = <0>; + clock-frequency = <24576000>; + }; + + sound { + compatible = "simple-audio-card"; + + #address-cells = <1>; + #size-cells = <0>; + + simple-audio-card,name = "Starfive-TDM-Sound-Card"; + simple-audio-card,widgets = "Microphone", "Mic Jack", + "Line", "Line In", + "Line", "Line Out", + "Speaker", "Speaker", + "Headphone", "Headphone Jack"; + simple-audio-card,routing = "Headphone Jack", "HP_L", + "Headphone Jack", "HP_R", + "Speaker", "SPK_LP", + "Speaker", "SPK_LN", + "LINPUT1", "Mic Jack", + "LINPUT3", "Mic Jack", + "RINPUT1", "Mic Jack", + "RINPUT2", "Mic Jack"; + + simple-audio-card,dai-link@0 { + reg = <0>; + format = "dsp_a"; + bitclock-master = <&dailink_master>; + frame-master = <&dailink_master>; + + cpu { + sound-dai = <&tdm>; + }; + dailink_master: codec { + sound-dai = <&wm8960>; + clocks = <&wm8960_mclk>; + }; + }; + }; +}; + +&i2c0 { + wm8960: codec@1a { + compatible = "wlf,wm8960"; + reg = <0x1a>; + wlf,shared-lrclk; + #sound-dai-cells = <0>; + }; +};arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi +40
-0@@ -214,6 +214,40 @@ slew-rate = <0>; }; }; + + tdm0_pins: tdm0-pins { + tdm0-pins-tx { + pinmux = <GPIOMUX(44, GPOUT_SYS_TDM_TXD, + GPOEN_ENABLE, + GPI_NONE)>; + bias-pull-up; + drive-strength = <2>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + + tdm0-pins-rx { + pinmux = <GPIOMUX(61, GPOUT_HIGH, + GPOEN_DISABLE, + GPI_SYS_TDM_RXD)>; + input-enable; + }; + + tdm0-pins-sync { + pinmux = <GPIOMUX(63, GPOUT_HIGH, + GPOEN_DISABLE, + GPI_SYS_TDM_SYNC)>; + input-enable; + }; + + tdm0-pins-pcmclk { + pinmux = <GPIOMUX(38, GPOUT_HIGH, + GPOEN_DISABLE, + GPI_SYS_TDM_CLK)>; + input-enable; + }; + }; }; &uart0 {@@ -221,3 +255,9 @@ pinctrl-0 = <&uart0_pins>; status = "okay"; }; + +&tdm { + pinctrl-names = "default"; + pinctrl-0 = <&tdm0_pins>; + status = "okay"; +};arch/riscv/boot/dts/starfive/jh7110.dtsi +21
-0@@ -366,6 +366,27 @@ status = "disabled"; }; + tdm: tdm@10090000 { + compatible = "starfive,jh7110-tdm"; + reg = <0x0 0x10090000 0x0 0x1000>; + clocks = <&syscrg JH7110_SYSCLK_TDM_AHB>, + <&syscrg JH7110_SYSCLK_TDM_APB>, + <&syscrg JH7110_SYSCLK_TDM_INTERNAL>, + <&syscrg JH7110_SYSCLK_TDM_TDM>, + <&syscrg JH7110_SYSCLK_MCLK_INNER>, + <&tdm_ext>; + clock-names = "tdm_ahb", "tdm_apb", + "tdm_internal", "tdm", + "mclk_inner", "tdm_ext"; + resets = <&syscrg JH7110_SYSRST_TDM_AHB>, + <&syscrg JH7110_SYSRST_TDM_APB>, + <&syscrg JH7110_SYSRST_TDM_CORE>; + dmas = <&dma 20>, <&dma 21>; + dma-names = "rx","tx"; + #sound-dai-cells = <0>; + status = "disabled"; + }; + stgcrg: clock-controller@10230000 { compatible = "starfive,jh7110-stgcrg"; reg = <0x0 0x10230000 0x0 0x10000>;Signature · 1 line
2.17.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Walker Chen
maintainerRe: [PATCH v2 4/4] riscv: dts: starfive: add tdm node and sound card
Quoted 7 lines · Conor Dooley
Hey Walker,
Quoted 1 line · Walker Chen
Add the tdm controller node and sound card for the StarFive JH7110 SoC.
Is this one of these waveshare things + a visionfive 2?
https://www.waveshare.com/wm8960-audio-hat.htm
Hey Conor,
I'm glad to receive your comments.
Now we are using this board + VisionFive2 :
https://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/
Quoted 6 lines
I'm a bit lost as to why this needs a whole new board, should it not just be an overlay that you can apply to the existing dts?
Taking this to an extreme, should I expect to see a new devicetree for everything RPi hat that you decide to use with a VisionFive 2?
For your response, I did some thinking. Because wm8960 codec is not integrated
on the VisionFive2 board, perhaps using overlay is a better way.
Quoted 11 lines
Also, it'd be nice to provide a Link: to where someone can find more info on this combination of items. Google for "wm8960 visionfive 2" gives me nothing, nor does "starfive audio card" etc.
Thanks,
Conor.Quoted 3 lines
Reviewed-by Hal Feng <[email protected]>Signed-off-by Walker Chen <[email protected]>---
Best regards,
Walker
Conor Dooley
maintainerRe: [PATCH v2 4/4] riscv: dts: starfive: add tdm node and sound card
Quoted 18 lines · Walker Chen
Quoted 7 lines · Conor Dooley
Hey Walker,
Quoted 1 line · Walker Chen
Add the tdm controller node and sound card for the StarFive JH7110 SoC.
Is this one of these waveshare things + a visionfive 2?
https://www.waveshare.com/wm8960-audio-hat.htmHey Conor,
I'm glad to receive your comments.Now we are using this board + VisionFive2 :
https://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/Quoted 1 line
Quoted 8 lines
Quoted 5 lines
I'm a bit lost as to why this needs a whole new board, should it not just be an overlay that you can apply to the existing dts?
Taking this to an extreme, should I expect to see a new devicetree for everything RPi hat that you decide to use with a VisionFive 2?
For your response, I did some thinking. Because wm8960 codec is not integrated
on the VisionFive2 board, perhaps using overlay is a better way.
Aye. I think so too. From my PoV, if this particular seeed audio board is something you're bundling with VisionFive 2 boards on your storefront etc, then I'm fine with taking it as an in-tree overlay.
If it is just a "random" RPi hat (that happens to be exactly what you need for testing the audio drivers), then I don't know where to draw a line for what is & what is not acceptable for inclusion.
In both cases, it's Emil's call.
Cheers,
Conor.
Quoted 3 lines
Quoted 3 lines
Also, it'd be nice to provide a Link: to where someone can find more info on this combination of items. Google for "wm8960 visionfive 2" gives me nothing, nor does "starfive audio card" etc.
Re: [PATCH v2 4/4] riscv: dts: starfive: add tdm node and sound card
Quoted 28 lines · Conor Dooley
Quoted 18 lines · Walker Chen
Quoted 7 lines · Conor Dooley
Hey Walker,
Quoted 1 line · Walker Chen
Add the tdm controller node and sound card for the StarFive JH7110 SoC.
Is this one of these waveshare things + a visionfive 2?
https://www.waveshare.com/wm8960-audio-hat.htmHey Conor,
I'm glad to receive your comments.Now we are using this board + VisionFive2 :
https://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/Quoted 1 line
Quoted 8 lines
Quoted 5 lines
I'm a bit lost as to why this needs a whole new board, should it not just be an overlay that you can apply to the existing dts?
Taking this to an extreme, should I expect to see a new devicetree for everything RPi hat that you decide to use with a VisionFive 2?
For your response, I did some thinking. Because wm8960 codec is not integrated
on the VisionFive2 board, perhaps using overlay is a better way.
Quoted 8 lines
Aye. I think so too. From my PoV, if this particular seeed audio board is something you're bundling with VisionFive 2 boards on your storefront etc, then I'm fine with taking it as an in-tree overlay.
If it is just a "random" RPi hat (that happens to be exactly what you need for testing the audio drivers), then I don't know where to draw a line for what is & what is not acceptable for inclusion.In both cases, it's Emil's call.
I'm not aware of any shop bundling the VF2 with an audio board. I
agree: please don't add device trees for combinations of VF2s and hats. That should be an overlay.
/Emil
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Also, it'd be nice to provide a Link: to where someone can find more info on this combination of items. Google for "wm8960 visionfive 2" gives me nothing, nor does "starfive audio card" etc.
Walker Chen
maintainerRe: [PATCH v2 4/4] riscv: dts: starfive: add tdm node and sound card
Quoted 36 lines · Emil Renner Berthing
Quoted 35 lines · Conor Dooley
Quoted 18 lines · Walker Chen
Quoted 7 lines · Conor Dooley
Hey Walker,
Quoted 1 line · Walker Chen
Add the tdm controller node and sound card for the StarFive JH7110 SoC.
Is this one of these waveshare things + a visionfive 2?
https://www.waveshare.com/wm8960-audio-hat.htmHey Conor,
I'm glad to receive your comments.Now we are using this board + VisionFive2 :
https://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/Quoted 1 line
Quoted 8 lines
Quoted 5 lines
I'm a bit lost as to why this needs a whole new board, should it not just be an overlay that you can apply to the existing dts?
Taking this to an extreme, should I expect to see a new devicetree for everything RPi hat that you decide to use with a VisionFive 2?
For your response, I did some thinking. Because wm8960 codec is not integrated
on the VisionFive2 board, perhaps using overlay is a better way.Aye. I think so too. From my PoV, if this particular seeed audio board is something you're bundling with VisionFive 2 boards on your storefront etc, then I'm fine with taking it as an in-tree overlay.
If it is just a "random" RPi hat (that happens to be exactly what you need for testing the audio drivers), then I don't know where to draw a line for what is & what is not acceptable for inclusion.
Quoted 7 lines
Quoted 1 line
In both cases, it's Emil's call.
I'm not aware of any shop bundling the VF2 with an audio board. I
agree: please don't add device trees for combinations of VF2s and hats. That should be an overlay./Emil
Since you guys agree, so let's do it this way.
Thanks.
Best regards,
Walker