ASoC: loongson: Refactor DMA and regmap handling
Subsystems (4)
Binbin Zhou
maintainerv3 cover ASoC: loongson: Refactor DMA and regmap handling
Hi all:
This series refactors the Loongson I2S ASoC drivers, reducing code duplication and improving DMA differentiation. It also adds an entry in MAINTAINERS and applies a few fixes to the es8323 codec driver.
Patch 1 adds a MAINTAINERS entry to track the Loongson audio drivers.
Patch 2 consolidates duplicate regmap configurations from the PCI and platform glue drivers into the shared loongson_i2s.c. It also fixes volatile register marking and switches from REGCACHE_FLAT to REGCACHE_MAPLE.
Patch 3 renames internal DMA structures and functions with an "idma" prefix to clearly distinguish them from external DMA (eDMA) support.
Patch 4 extracts the external DMA logic from the platform driver into loongson_dma.c, making it reusable and avoiding duplication with the internal DMA implementation.
These changes have been tested on Loongson-2K0300 (platform, eDMA) and Loongson-2K2000 (PCI, iDMA) boards.
Thanks.
Binbin
========
V3:
- Drop es8323 patch.
Patch (2/4):
- Add I2S_CTRL as volatile register.
Link to V2:
https://lore.kernel.org/all/[email protected]/
V2:
Patch (2/5):
- Fix volatile register handling, and switch from REGCACHE_FLAT to
REGCACHE_MAPLE;
Patch (5/5):
- New patch for ES8323 coedc.
Link to V1:
https://lore.kernel.org/all/[email protected]/
Change from [1]:
Patch (2/4):
- Reordered the write function to follow the read function;
Patch (3/4)/(4/4):
- Use idma (internal dma) and edma (external dma) for short.
[1]:
https://lore.kernel.org/all/[email protected]/
Binbin Zhou (4):
MAINTAINERS: Add entry for Loongson ASoC driver
ASoC: loongson: Combined regmap definitions
ASoC: loongson: Use the idma identifier for internal DMA variables
ASoC: loongson: Separate external shared DMA from the platform
interface
MAINTAINERS | 9 ++ sound/soc/loongson/Makefile | 4 +- sound/soc/loongson/loongson_dma.c | 148 +++++++++++++++++-------- sound/soc/loongson/loongson_dma.h | 6 +- sound/soc/loongson/loongson_i2s.c | 56 +++++++++- sound/soc/loongson/loongson_i2s.h | 7 +- sound/soc/loongson/loongson_i2s_pci.c | 59 +--------- sound/soc/loongson/loongson_i2s_plat.c | 67 +---------- 8 files changed, 182 insertions(+), 174 deletions(-)
base-commit: 9617ce6798f8eee61d8068f0ea03a08ce051932e
Signature · 1 line
2.52.0
Binbin Zhou
maintainerPATCH v3 1/4 MAINTAINERS: Add entry for Loongson ASoC driver
Add MAINTAINERS entry for Loongson I2S ASoC drivers to track changes in sound/soc/loongson/ directory.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -15050,6 +15050,15 @@ F: arch/loongarch/ F: drivers/*/*loongarch* F: drivers/cpufreq/loongson3_cpufreq.c +LOONGSON AUDIO (ASoC) DRIVERS +M: Binbin Zhou <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/sound/loongson,ls-audio-card.yaml +F: Documentation/devicetree/bindings/sound/loongson,ls2k1000-i2s.yaml +F: sound/soc/loongson/loongson_*.c +F: sound/soc/loongson/loongson_*.h + LOONGSON GPIO DRIVER M: Yinbo Zhu <[email protected]> L: [email protected]
Signature · 1 line
2.52.0
Binbin Zhou
maintainerPATCH v3 2/4 ASoC: loongson: Combined regmap definitions
In reply to Binbin ZhouPreviously, the regmap configuration for Loongson I2S controller was duplicated in both PCI and platform glue drivers. Move the common regmap configuration into the shared loongson_i2s.c to avoid code duplication and centralize register access handling.
While moving, adjust the following:
- Mark RX_DATA/TX_DATA/I2S_CTRL as volatile registers. The PCI version incorrectly marked CFG/CFG1 as volatile, which prevented proper regcache synchronization.
- Change cache type from REGCACHE_FLAT to REGCACHE_MAPLE. The register map is sparse and the number of registers is small; MAPLE tree provides better scalability and is the recommended cache type for modern regmap users.
Also, the following warning for the i2s_plat driver will be eliminated:
loongson-i2s-plat loongson-i2s: using zero-initialized flat cache, this may cause unexpected behavior.
--- sound/soc/loongson/loongson_i2s.c | 56 +++++++++++++++++++++++++- sound/soc/loongson/loongson_i2s.h | 1 + sound/soc/loongson/loongson_i2s_pci.c | 54 ------------------------- sound/soc/loongson/loongson_i2s_plat.c | 8 ---- 4 files changed, 56 insertions(+), 63 deletions(-)
sound/soc/loongson/loongson_i2s.c +55 -1
@@ -254,6 +254,7 @@ static int i2s_suspend(struct device *dev)struct loongson_i2s *i2s =dev_get_drvdata (dev);regcache_cache_only (i2s->regmap, true); +regcache_mark_dirty (i2s->regmap);return 0 ; }
@@ -263,7 +264,7 @@ static int i2s_resume(struct device *dev)struct loongson_i2s *i2s =dev_get_drvdata (dev);regcache_cache_only (i2s->regmap, false); -regcache_mark_dirty (i2s->regmap); +return regcache_sync (i2s->regmap); }
@@ -272,5 +273,58 @@ const struct dev_pm_ops loongson_i2s_pm = { };EXPORT_SYMBOL_GPL (loongson_i2s_pm); +static bool loongson_i2s_rd_reg (struct device *dev,unsigned int reg) +{ +switch (reg) { +case LS_I2S_VER : +case LS_I2S_CFG : +case LS_I2S_CTRL : +case LS_I2S_RX_DATA : +case LS_I2S_TX_DATA : +case LS_I2S_CFG1 : +return true; +default : +return false; + }; +} + +static bool loongson_i2s_wr_reg (struct device *dev,unsigned int reg) +{ +switch (reg) { +case LS_I2S_CFG : +case LS_I2S_CTRL : +case LS_I2S_RX_DATA : +case LS_I2S_TX_DATA : +case LS_I2S_CFG1 : +return true; +default : +return false; + }; +} + +static bool loongson_i2s_volatile_reg (struct device *dev,unsigned int reg) +{ +switch (reg) { +case LS_I2S_CTRL : +case LS_I2S_RX_DATA : +case LS_I2S_TX_DATA : +return true; +default : +return false; + }; +} + +const struct regmap_config loongson_i2s_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .max_register =LS_I2S_CFG1 , + .readable_reg = loongson_i2s_rd_reg, + .writeable_reg = loongson_i2s_wr_reg, + .volatile_reg = loongson_i2s_volatile_reg, + .cache_type =REGCACHE_MAPLE , +}; +EXPORT_SYMBOL_GPL (loongson_i2s_regmap_config); +MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("Common functions for loongson I2S controller driver" );
sound/soc/loongson/loongson_i2s.h +1 -0
@@ -65,6 +65,7 @@ struct loongson_i2s {u32 sysclk; }; +extern const struct regmap_config loongson_i2s_regmap_config;extern const struct dev_pm_ops loongson_i2s_pm;extern struct snd_soc_dai_driver loongson_i2s_dai;
sound/soc/loongson/loongson_i2s_pci.c +0 -54
60 lines not on this page · raw message
sound/soc/loongson/loongson_i2s_plat.c +0 -8
@@ -85,14 +85,6 @@ static const struct snd_soc_component_driver loongson_i2s_component_driver = { .open = loongson_pcm_open, }; -static const struct regmap_config loongson_i2s_regmap_config = { - .reg_bits =32 , - .reg_stride =4 , - .val_bits =32 , - .max_register =0x14 , - .cache_type =REGCACHE_FLAT , -}; -static int loongson_i2s_apbdma_config (struct platform_device *pdev) {int val;
Signature · 1 line
2.52.0
Binbin Zhou
maintainerPATCH v3 3/4 ASoC: loongson: Use the `idma` identifier for internal DMA variables
In reply to Binbin ZhouThe Loongson I2S controller can work with two types of DMA:
- Internal DMA (iDMA): integrated DMA engine, driven by dedicated registers and interrupts.
- External DMA (eDMA): generic DMA engine (e.g., dw_dmac), using the standard dmaengine API.
To distinguish these two distinct implementations, rename all internal-DMA-related structures, functions, and the component driver to use the "idma" prefix.
No functional change intended.
--- sound/soc/loongson/loongson_dma.c | 89 ++++++++++++++------------- sound/soc/loongson/loongson_dma.h | 4 +- sound/soc/loongson/loongson_i2s.h | 6 +- sound/soc/loongson/loongson_i2s_pci.c | 5 +- 4 files changed, 52 insertions(+), 52 deletions(-)
sound/soc/loongson/loongson_dma.c +45 -44
@@ -4,6 +4,7 @@// // Copyright (C) 2023 Loongson Technology Corporation Limited // Author: Yingkun Meng <[email protected]> +// Binbin ZHou <[email protected]> // #include <linux/module.h>
@@ -16,7 +17,7 @@#include <sound/pcm_params.h> #include "loongson_i2s.h" -/* DMA dma_order Register */ +/* Internal DMA dma_order Register */ #define DMA_ORDER_STOP BIT(4)/* DMA stop */ #define DMA_ORDER_START BIT(3)/* DMA start */ #define DMA_ORDER_ASK_VALID BIT(2)/* DMA ask valid flag */
@@ -27,9 +28,9 @@#define DMA_ORDER_CTRL_MASK (0x0fUL)/* Control mask */ /* -* DMA registers descriptor. +* Internal DMA registers descriptor. */ -struct loongson_dma_desc { +struct loongson_idma_desc {u32 order;/* Next descriptor address register */ u32 saddr;/* Source address register */ u32 daddr;/* Device address register */
@@ -44,17 +45,17 @@ struct loongson_dma_desc { } __packed;struct loongson_runtime_data { -struct loongson_dma_data *dma_data; +struct loongson_idma_data *dma_data; -struct loongson_dma_desc *dma_desc_arr; +struct loongson_idma_desc *dma_desc_arr;dma_addr_t dma_desc_arr_phy;int dma_desc_arr_size; -struct loongson_dma_desc *dma_pos_desc; +struct loongson_idma_desc *dma_pos_desc;dma_addr_t dma_pos_desc_phy; }; -static const struct snd_pcm_hardware ls_pcm_hardware = { +static const struct snd_pcm_hardware loongson_idma_hardware = { .info =SNDRV_PCM_INFO_MMAP |SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID |
@@ -67,12 +68,11 @@ static const struct snd_pcm_hardware ls_pcm_hardware = { .period_bytes_min = 128, .period_bytes_max = 128 * 1024, .periods_min = 1, - .periods_max = PAGE_SIZE / sizeof(struct loongson_dma_desc), + .periods_max = PAGE_SIZE / sizeof(struct loongson_idma_desc), .buffer_bytes_max = 1024 * 1024, }; -static struct -loongson_dma_desc *dma_desc_save (struct loongson_runtime_data *prtd) +static struct loongson_idma_desc *dma_desc_save (struct loongson_runtime_data *prtd) {void __iomem *order_reg = prtd->dma_data->order_addr;u64 val;
@@ -88,8 +88,8 @@ loongson_dma_desc *dma_desc_save(struct loongson_runtime_data *prtd)return prtd->dma_pos_desc; } -static int loongson_pcm_trigger (struct snd_soc_component *component, -struct snd_pcm_substream *substream,int cmd) +static int loongson_idma_pcm_trigger (struct snd_soc_component *component, +struct snd_pcm_substream *substream,int cmd) {struct loongson_runtime_data *prtd = substream->runtime->private_data;struct device *dev = substream->pcm->card->dev;
@@ -131,9 +131,9 @@ static int loongson_pcm_trigger(struct snd_soc_component *component,return 0 ; } -static int loongson_pcm_hw_params (struct snd_soc_component *component, -struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params) +static int loongson_idma_pcm_hw_params (struct snd_soc_component *component, +struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) {struct snd_pcm_runtime *runtime = substream->runtime;struct device *dev = substream->pcm->card->dev;
@@ -141,7 +141,7 @@ static int loongson_pcm_hw_params(struct snd_soc_component *component,size_t buf_len =params_buffer_bytes (params);size_t period_len =params_period_bytes (params);dma_addr_t order_addr, mem_addr; -struct loongson_dma_desc *desc; +struct loongson_idma_desc *desc;u32 num_periods;int i;
@@ -195,12 +195,12 @@ static int loongson_pcm_hw_params(struct snd_soc_component *component, }static snd_pcm_uframes_t -loongson_pcm_pointer (struct snd_soc_component *component, -struct snd_pcm_substream *substream) +loongson_idma_pcm_pointer (struct snd_soc_component *component, +struct snd_pcm_substream *substream) {struct snd_pcm_runtime *runtime = substream->runtime;struct loongson_runtime_data *prtd = runtime->private_data; -struct loongson_dma_desc *desc; +struct loongson_idma_desc *desc;snd_pcm_uframes_t x;u64 addr;
@@ -213,7 +213,7 @@ loongson_pcm_pointer(struct snd_soc_component *component,return x; } -static irqreturn_t loongson_pcm_dma_irq (int irq,void *devid) +static irqreturn_t loongson_idma_pcm_dma_irq (int irq,void *devid) {struct snd_pcm_substream *substream = devid;
@@ -221,14 +221,14 @@ static irqreturn_t loongson_pcm_dma_irq(int irq, void *devid)return IRQ_HANDLED ; } -static int loongson_pcm_open (struct snd_soc_component *component, -struct snd_pcm_substream *substream) +static int loongson_idma_pcm_open (struct snd_soc_component *component, +struct snd_pcm_substream *substream) {struct snd_pcm_runtime *runtime = substream->runtime;struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_card *card = substream->pcm->card;struct loongson_runtime_data *prtd; -struct loongson_dma_data *dma_data; +struct loongson_idma_data *dma_data;/* * For mysterious reasons (and despite what the manual says)
@@ -241,7 +241,7 @@ static int loongson_pcm_open(struct snd_soc_component *component, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 128);snd_pcm_hw_constraint_integer (substream->runtime,SNDRV_PCM_HW_PARAM_PERIODS ); -snd_soc_set_runtime_hwparams (substream, &ls_pcm_hardware); +snd_soc_set_runtime_hwparams (substream, &loongson_idma_hardware); prtd =kzalloc_obj (*prtd);if (!prtd)
@@ -277,8 +277,8 @@ static int loongson_pcm_open(struct snd_soc_component *component,return -ENOMEM ; } -static int loongson_pcm_close (struct snd_soc_component *component, -struct snd_pcm_substream *substream) +static int loongson_idma_pcm_close (struct snd_soc_component *component, +struct snd_pcm_substream *substream) {struct snd_card *card = substream->pcm->card;struct loongson_runtime_data *prtd = substream->runtime->private_data;
@@ -293,21 +293,21 @@ static int loongson_pcm_close(struct snd_soc_component *component,return 0 ; } -static int loongson_pcm_mmap (struct snd_soc_component *component, -struct snd_pcm_substream *substream, -struct vm_area_struct *vma) +static int loongson_idma_pcm_mmap (struct snd_soc_component *component, +struct snd_pcm_substream *substream, +struct vm_area_struct *vma) {return remap_pfn_range (vma, vma->vm_start, - substream->dma_buffer.addr >>PAGE_SHIFT , - vma->vm_end - vma->vm_start, vma->vm_page_prot); + substream->dma_buffer.addr >>PAGE_SHIFT , + vma->vm_end - vma->vm_start, vma->vm_page_prot); } -static int loongson_pcm_new (struct snd_soc_component *component, -struct snd_soc_pcm_runtime *rtd) +static int loongson_idma_pcm_new (struct snd_soc_component *component, +struct snd_soc_pcm_runtime *rtd) {struct snd_card *card = rtd->card->snd_card;struct snd_pcm_substream *substream; -struct loongson_dma_data *dma_data; +struct loongson_idma_data *dma_data;unsigned int i;int ret;
@@ -319,7 +319,7 @@ static int loongson_pcm_new(struct snd_soc_component *component, dma_data =snd_soc_dai_get_dma_data (snd_soc_rtd_to_cpu (rtd,0 ), substream); ret =devm_request_irq (card->dev, dma_data->irq, - loongson_pcm_dma_irq, + loongson_idma_pcm_dma_irq,IRQF_TRIGGER_HIGH ,LS_I2S_DRVNAME , substream);if (ret <0 ) {
@@ -330,16 +330,17 @@ static int loongson_pcm_new(struct snd_soc_component *component,return snd_pcm_set_fixed_buffer_all (rtd->pcm,SNDRV_DMA_TYPE_DEV , card->dev, - ls_pcm_hardware.buffer_bytes_max); + loongson_idma_hardware.buffer_bytes_max); } -const struct snd_soc_component_driver loongson_i2s_component = { +/* Internal DMA component */ +const struct snd_soc_component_driver loongson_i2s_idma_component = { .name =LS_I2S_DRVNAME , - .open = loongson_pcm_open, - .close = loongson_pcm_close, - .hw_params = loongson_pcm_hw_params, - .trigger = loongson_pcm_trigger, - .pointer = loongson_pcm_pointer, - .mmap = loongson_pcm_mmap, - .pcm_new = loongson_pcm_new, + .open = loongson_idma_pcm_open, + .close = loongson_idma_pcm_close, + .hw_params = loongson_idma_pcm_hw_params, + .trigger = loongson_idma_pcm_trigger, + .pointer = loongson_idma_pcm_pointer, + .mmap = loongson_idma_pcm_mmap, + .pcm_new = loongson_idma_pcm_new, };
sound/soc/loongson/loongson_dma.h +1 -3
@@ -9,8 +9,6 @@#ifndef _LOONGSON_DMA_H#define _LOONGSON_DMA_H -#include <sound/soc.h> - -extern const struct snd_soc_component_driver loongson_i2s_component; +extern const struct snd_soc_component_driver loongson_i2s_idma_component;#endif
sound/soc/loongson/loongson_i2s.h +3 -3
@@ -42,7 +42,7 @@#define LS_I2S_DRVNAME "loongson-i2s" -struct loongson_dma_data { +struct loongson_idma_data {dma_addr_t dev_addr;/* device physical address for DMA */ void __iomem *order_addr;/* DMA order register */ int irq;/* DMA irq */
@@ -52,11 +52,11 @@ struct loongson_i2s {struct device *dev;union {struct snd_dmaengine_dai_dma_data playback_dma_data; -struct loongson_dma_data tx_dma_data; +struct loongson_idma_data tx_dma_data; };union {struct snd_dmaengine_dai_dma_data capture_dma_data; -struct loongson_dma_data rx_dma_data; +struct loongson_idma_data rx_dma_data; };struct regmap *regmap;void __iomem *reg_base;
sound/soc/loongson/loongson_i2s_pci.c +3 -2
@@ -13,6 +13,7 @@#include <linux/acpi.h> #include <linux/pci.h> #include <sound/soc.h> +#include "loongson_i2s.h" #include "loongson_dma.h"
@@ -22,7 +23,7 @@ static int loongson_i2s_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) {const struct fwnode_handle *fwnode = pdev->dev.fwnode; -struct loongson_dma_data *tx_data, *rx_data; +struct loongson_idma_data *tx_data, *rx_data;struct device *dev = &pdev->dev;struct loongson_i2s *i2s;int ret;
@@ -79,7 +80,7 @@ static int loongson_i2s_pci_probe(struct pci_dev *pdev,udelay (200 ); } - ret =devm_snd_soc_register_component (dev, &loongson_i2s_component, + ret =devm_snd_soc_register_component (dev, &loongson_i2s_idma_component, &loongson_i2s_dai,1 );if (ret)return dev_err_probe (dev, ret,"register DAI failed\n" );
Signature · 1 line
2.52.0
Binbin Zhou
maintainerPATCH v3 4/4 ASoC: loongson: Separate external shared DMA from the platform interface
In reply to Binbin ZhouThe Loongson I2S platform driver (used on LS2K1000, LS7A etc.) relies on an external DMA engine (e.g., dw_dmac) rather than the internal DMA. However, its DMA-related code was originally embedded in loongson_i2s_plat.c, duplicating logic that should be shared.
Extract the external DMA (eDMA) support from the platform driver and move it into loongson_dma.c alongside the existing internal DMA (iDMA) code.
This change eliminates code duplication and prepares for future consolidation of DMA selection logic.
--- sound/soc/loongson/Makefile | 4 +- sound/soc/loongson/loongson_dma.c | 59 ++++++++++++++++++++++++++ sound/soc/loongson/loongson_dma.h | 2 + sound/soc/loongson/loongson_i2s_plat.c | 59 +------------------------- 4 files changed, 65 insertions(+), 59 deletions(-)
sound/soc/loongson/Makefile +2 -2
@@ -1,12 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 #Platform Support -snd-soc-loongson-i2s-pci-y := loongson_i2s_pci.o loongson_dma.o +snd-soc-loongson-i2s-pci-y := loongson_i2s_pci.o obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PCI) += snd-soc-loongson-i2s-pci.o snd-soc-loongson-i2s.o snd-soc-loongson-i2s-plat-y := loongson_i2s_plat.o obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PLATFORM) += snd-soc-loongson-i2s-plat.o snd-soc-loongson-i2s.o -snd-soc-loongson-i2s-y := loongson_i2s.o +snd-soc-loongson-i2s-y := loongson_i2s.o loongson_dma.o obj-$(CONFIG_SND_LOONGSON1_AC97) += loongson1_ac97.o
sound/soc/loongson/loongson_dma.c +59 -0
62 lines not on this page · raw message
sound/soc/loongson/loongson_dma.h +2 -0
@@ -10,5 +10,7 @@#define _LOONGSON_DMA_Hextern const struct snd_soc_component_driver loongson_i2s_idma_component; +extern const struct snd_soc_component_driver loongson_i2s_edma_component; +extern const struct snd_dmaengine_pcm_config loongson_dmaengine_pcm_config;#endif
sound/soc/loongson/loongson_i2s_plat.c +2 -57
77 lines not on this page · raw message
Signature · 1 line
2.52.0
Mark Brown
maintainerQuoted 9 lines · Binbin Zhou
ASoC: loongson: Refactor DMA and regmap handling
Hi all:
This series refactors the Loongson I2S ASoC drivers, reducing code duplication and improving DMA differentiation. It also adds an entry in
MAINTAINERSand applies a few fixes to the es8323 codec driver.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2
Thanks!
[1/4] MAINTAINERS: Add entry for Loongson ASoC driver
https://git.kernel.org/broonie/sound/c/90c6f9c8cbb6 [2/4] ASoC: loongson: Combined regmap definitions https://git.kernel.org/broonie/sound/c/8a6fd3377015 [3/4] ASoC: loongson: Use the `idma` identifier for internal DMA variables https://git.kernel.org/broonie/sound/c/353530ece852 [4/4] ASoC: loongson: Separate external shared DMA from the platform interface https://git.kernel.org/broonie/sound/c/767a1b50c1f0
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark