]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: loongson: Combined regmap definitions
authorBinbin Zhou <zhoubinbin@loongson.cn>
Mon, 1 Jun 2026 09:29:37 +0000 (17:29 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 2 Jun 2026 15:21:45 +0000 (16:21 +0100)
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 <zhoubinbin@loongson.cn>
Link: https://patch.msgid.link/e32d24479fc382dc3de6aded6351c13b43b6391d.1780304703.git.zhoubinbin@loongson.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/loongson/loongson_i2s.c
sound/soc/loongson/loongson_i2s.h
sound/soc/loongson/loongson_i2s_pci.c
sound/soc/loongson/loongson_i2s_plat.c

index e336656e13eba5159a83524bfd8176430a959419..cfe102a8b604655b0054f656c80a7910ef04cd4e 100644 (file)
@@ -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");
index c8052a762c1b359b4abb42253723f1e7c2c1eaa0..e73ffa954ec9ac03435a804705b5cd55f2d4caf9 100644 (file)
@@ -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;
 
index 1ea5501a97f814132c0e80949aa0b0b1aaf5cee5..dea1e4ebee29958e7c169da52c34562e99eaeea6 100644 (file)
 
 #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)
 {
index fa2e450ff618d40a9824a3ef3ba5cef2df4eac09..f8d7aca8b9033059ab312ce99658108962c5c74e 100644 (file)
@@ -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;