From: Binbin Zhou Date: Mon, 1 Jun 2026 09:29:37 +0000 (+0800) Subject: ASoC: loongson: Combined regmap definitions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a6fd33770154c2c02292c6890c57382c551a906;p=thirdparty%2Fkernel%2Flinux.git ASoC: loongson: Combined regmap definitions Previously, 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. Signed-off-by: Binbin Zhou Link: https://patch.msgid.link/e32d24479fc382dc3de6aded6351c13b43b6391d.1780304703.git.zhoubinbin@loongson.cn Signed-off-by: Mark Brown --- diff --git a/sound/soc/loongson/loongson_i2s.c b/sound/soc/loongson/loongson_i2s.c index e336656e13eba..cfe102a8b6046 100644 --- a/sound/soc/loongson/loongson_i2s.c +++ b/sound/soc/loongson/loongson_i2s.c @@ -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"); diff --git a/sound/soc/loongson/loongson_i2s.h b/sound/soc/loongson/loongson_i2s.h index c8052a762c1b3..e73ffa954ec9a 100644 --- a/sound/soc/loongson/loongson_i2s.h +++ b/sound/soc/loongson/loongson_i2s.h @@ -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; diff --git a/sound/soc/loongson/loongson_i2s_pci.c b/sound/soc/loongson/loongson_i2s_pci.c index 1ea5501a97f81..dea1e4ebee299 100644 --- a/sound/soc/loongson/loongson_i2s_pci.c +++ b/sound/soc/loongson/loongson_i2s_pci.c @@ -18,60 +18,6 @@ #define DRIVER_NAME "loongson-i2s-pci" -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_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_volatile_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 const struct regmap_config loongson_i2s_regmap_config = { - .reg_bits = 32, - .reg_stride = 4, - .val_bits = 32, - .max_register = LS_I2S_CFG1, - .writeable_reg = loongson_i2s_wr_reg, - .readable_reg = loongson_i2s_rd_reg, - .volatile_reg = loongson_i2s_volatile_reg, - .cache_type = REGCACHE_FLAT, -}; - static int loongson_i2s_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) { diff --git a/sound/soc/loongson/loongson_i2s_plat.c b/sound/soc/loongson/loongson_i2s_plat.c index fa2e450ff618d..f8d7aca8b9033 100644 --- a/sound/soc/loongson/loongson_i2s_plat.c +++ b/sound/soc/loongson/loongson_i2s_plat.c @@ -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;