ASoC: loongson: Refactor DMA handling and regmap
Subsystems (4)
Binbin Zhou
maintainerv2 cover ASoC: loongson: Refactor DMA handling and regmap
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.
Patch 5 adjusts a few register values in the es8323 codec driver to improve power control and output volume on Loongson platforms.
These changes have been tested on Loongson-2K0300 (platform, eDMA) and Loongson-3K2000 (PCI, iDMA) boards.
Thanks.
Binbin
========
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 (5):
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
ASoC: codecs: es8323: Adjust the initialization of certain registers
MAINTAINERS | 9 ++ sound/soc/codecs/es8323.c | 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 | 55 ++++++++- sound/soc/loongson/loongson_i2s.h | 7 +- sound/soc/loongson/loongson_i2s_pci.c | 59 +--------- sound/soc/loongson/loongson_i2s_plat.c | 67 +---------- 9 files changed, 190 insertions(+), 174 deletions(-)
base-commit: 8cd773d4f8235aaf0b04927b3c9d2d0326def09b
Signature · 1 line
2.52.0
Binbin Zhou
maintainerPATCH v2 1/5 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 v2 2/5 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 only RX_DATA and TX_DATA as volatile registers. The PCI version incorrectly marked CFG/CTRL/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 | 55 +++++++++++++++++++++++++- 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, 55 insertions(+), 63 deletions(-)
sound/soc/loongson/loongson_i2s.c +54 -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,57 @@ 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_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
Mark Brown
maintainerRe: [PATCH v2 2/5] ASoC: loongson: Combined regmap definitions
Quoted 4 lines · Binbin Zhou
While moving, adjust the following:
- Mark onlyRX_DATAandTX_DATAas volatile registers. The PCI version incorrectly marked CFG/CTRL/CFG1 as volatile, which prevented proper regcache synchronization.
The driver also polls LS_I2S_CTRL for MCLK_READY and CLK_READY, either we need to bypass the cache when doing that or that register needs to be volatile too.
Re: [PATCH v2 2/5] ASoC: loongson: Combined regmap definitions
Hi Mark:
Quoted 11 lines · Mark Brown
Quoted 4 lines · Binbin Zhou
While moving, adjust the following:
- Mark onlyRX_DATAandTX_DATAas volatile registers. The PCI version incorrectly marked CFG/CTRL/CFG1 as volatile, which prevented proper regcache synchronization.The driver also polls
LS_I2S_CTRLforMCLK_READYandCLK_READY, either we need to bypass the cache when doing that or that register needs to be volatile too.
Yes, the LS_I2S_CTRL should be volatile, otherwise, a timeout error may occur.
Signature · 2 lines
Thanks. Binbin
Binbin Zhou
maintainerPATCH v2 3/5 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 v2 4/5 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
Binbin Zhou
maintainerPATCH v2 5/5 ASoC: codecs: es8323: Adjust the initialization of certain registers
In reply to Binbin ZhouA few additional register initializations are required for proper operation.
- During hw_params, write ES8323_DACPOWER (0x3c) to ensure DAC power is correctly configured for the selected sample rate.
- In the probe function, initialize DACCONTROL17, DACCONTROL20, ADCCONTROL10, LOUT1_VOL, and ROUT1_VOL to improve analog output stability and volume level.
- In set_bias_level, set CHIPPOWER to 0x00 when powering up and to 0xff when powering off, fully controlling the chip's power state.
--- sound/soc/codecs/es8323.c | 9 +++++++++ 1 file changed, 9 insertions(+)
sound/soc/codecs/es8323.c +9 -0
@@ -613,6 +613,8 @@ static int es8323_pcm_hw_params(struct snd_pcm_substream *substream,snd_soc_component_write_field (component,ES8323_DACCONTROL1 ,ES8323_DACCONTROL1_DACWL , wl_mode); +snd_soc_component_write (component,ES8323_DACPOWER ,0x3c ); +return 0 ; }
@@ -675,7 +677,12 @@ static int es8323_probe(struct snd_soc_component *component) }snd_soc_component_write (component,ES8323_CONTROL2 ,0x60 ); +snd_soc_component_write (component,ES8323_DACCONTROL17 ,0xb8 ); +snd_soc_component_write (component,ES8323_DACCONTROL20 ,0xb8 );snd_soc_component_write (component,ES8323_DACCONTROL21 ,0x80 ); +snd_soc_component_write (component,ES8323_ADCCONTROL10 ,0xea ); +snd_soc_component_write (component,ES8323_LOUT1_VOL ,0x1b ); +snd_soc_component_write (component,ES8323_ROUT1_VOL ,0x1b );return 0 ; }
@@ -694,6 +701,7 @@ static int es8323_set_bias_level(struct snd_soc_component *component,if (ret)return ret; +snd_soc_component_write (component,ES8323_CHIPPOWER ,0x00 );snd_soc_component_write (component,ES8323_CHIPLOPOW1 ,0x00 );snd_soc_component_write (component,ES8323_CHIPLOPOW2 ,0x00 ); snd_soc_component_update_bits(component, ES8323_ADCPOWER,
@@ -702,6 +710,7 @@ static int es8323_set_bias_level(struct snd_soc_component *component,case SND_SOC_BIAS_STANDBY :break ;case SND_SOC_BIAS_OFF : +snd_soc_component_write (component,ES8323_CHIPPOWER ,0xff );snd_soc_component_write (component,ES8323_CHIPLOPOW1 ,0xff );snd_soc_component_write (component,ES8323_CHIPLOPOW2 ,0xff );clk_disable_unprepare (es8323->mclk);
Signature · 1 line
2.52.0
Mark Brown
maintainerRe: [PATCH v2 5/5] ASoC: codecs: es8323: Adjust the initialization of certain registers
Quoted 5 lines · Binbin Zhou
A few additional register initializations are required for proper operation.
- During
hw_params, writeES8323_DACPOWER(0x3c) to ensure DAC power is correctly configured for the selected sample rate.
Is it just a write that's needed (even if the DAC is already enabled), or is it that we need the DAC to be powered? If it's the latter should this be managed using DAPM? What does this write actually do?
Quoted 3 lines
- In the probe function, initialize DACCONTROL17, DACCONTROL20, ADCCONTROL10,
LOUT1_VOL, andROUT1_VOLto improve analog output stability and volume level.
The volumes should be left at the chip defaults, users can adjust them via the existing Output 1 Playback Volume control and UCM can be used to provide defaults. We don't configure this in the kernel because the settings needed for different boards can be very different and tweaking the configuration in the kernel causes them all to collide with each other. The chip defaults might not always be helpful but at least they're a concrete thing that provides a fixed point for configuration.
We also seem to already have volume controls exposed in at least DACCONTROL17 and DACCONTROL20.
Quoted 3 lines
- In
set_bias_level, set CHIPPOWER to0x00when powering up and to0xffwhen powering off, fully controlling the chip's power state.
It looks like this register is managed by DAPM already, presumably there's some bug or missing configuration there but
Re: [PATCH v2 5/5] ASoC: codecs: es8323: Adjust the initialization of certain registers
Hi Mark:
Thanks for your reply.
Quoted 11 lines · Mark Brown
Quoted 5 lines · Binbin Zhou
A few additional register initializations are required for proper operation.
- During
hw_params, writeES8323_DACPOWER(0x3c) to ensure DAC power is correctly configured for the selected sample rate.Is it just a write that's needed (even if the DAC is already enabled), or is it that we need the DAC to be powered? If it's the latter should this be managed using DAPM? What does this write actually do?
This doesn't seem to be necessary; I checked, and it was being affected by the preceding I2S_CTRL.
Quoted 13 lines
Quoted 4 lines
- In the probe function, initialize DACCONTROL17, DACCONTROL20, ADCCONTROL10,
LOUT1_VOL, andROUT1_VOLto improve analog output stability and volume level.The volumes should be left at the chip defaults, users can adjust them via the existing Output 1 Playback Volume control and UCM can be used to provide defaults. We don't configure this in the kernel because the settings needed for different boards can be very different and tweaking the configuration in the kernel causes them all to collide with each other. The chip defaults might not always be helpful but at least they're a concrete thing that provides a fixed point for configuration.
Quoted 2 lines
We also seem to already have volume controls exposed in at least DACCONTROL17 and DACCONTROL20.
Thanks for the explanation.
I tried adjusting the relevant controls with amixer, and both recording and playback are working fine. My initial idea was to preset the relevant registers, but this seems to differ from the standard approach for I2S.
Quoted 7 lines
Quoted 4 lines
- In
set_bias_level, set CHIPPOWER to0x00when powering up and to0xffwhen powering off, fully controlling the chip's power state.It looks like this register is managed by DAPM already, presumably there's some bug or missing configuration there but
This doesn't seem to be necessary; I checked, and it was being affected by the preceding I2S_CTRL.
Sorry, please ignore this patch.
--
Thanks.
Binbin