ASoC: SoundWire codecs: make regmap cache-only in probe
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Wed, 2 Aug 2023 15:36:15 +0000 (10:36 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 7 Aug 2023 13:32:20 +0000 (14:32 +0100)
The SoundWire bus may start after the probe where the SoundWire ASoC
components are registered. This creates a time window where the card
can be created and the registers be accessed.

As discussed on the mailing list, we can't really control when codecs
are enumerated and initialized, but we can make sure the access to the
codecs is cached until the hardware is accessible.

This patch configures regcache_cache_only() with a 'true' parameter in
the probe function, and a 'false' parameter in the io_init routine.

The rt5682 is handled through a different patch due to its specific
cache handling.

Link: https://lore.kernel.org/alsa-devel/20230503144102.242240-1-krzysztof.kozlowski@linaro.org/
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20230802153629.53576-3-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
12 files changed:
sound/soc/codecs/max98363.c
sound/soc/codecs/max98373-sdw.c
sound/soc/codecs/rt1308-sdw.c
sound/soc/codecs/rt1316-sdw.c
sound/soc/codecs/rt1318-sdw.c
sound/soc/codecs/rt700.c
sound/soc/codecs/rt711-sdca.c
sound/soc/codecs/rt711.c
sound/soc/codecs/rt712-sdca-dmic.c
sound/soc/codecs/rt712-sdca.c
sound/soc/codecs/rt715-sdca.c
sound/soc/codecs/rt715.c

index b5c69bba0e4888fa21e55e0430893196cb5a3a51..80a1cb482183636129ac5fbef199c3c002a5d89e 100644 (file)
@@ -160,10 +160,9 @@ static int max98363_io_init(struct sdw_slave *slave)
        struct max98363_priv *max98363 = dev_get_drvdata(dev);
        int ret, reg;
 
-       if (max98363->first_hw_init) {
-               regcache_cache_only(max98363->regmap, false);
+       regcache_cache_only(max98363->regmap, false);
+       if (max98363->first_hw_init)
                regcache_cache_bypass(max98363->regmap, true);
-       }
 
        /*
         * PM runtime is only enabled when a Slave reports as Attached
@@ -409,6 +408,8 @@ static int max98363_init(struct sdw_slave *slave, struct regmap *regmap)
        max98363->regmap = regmap;
        max98363->slave = slave;
 
+       regcache_cache_only(max98363->regmap, true);
+
        max98363->hw_init = false;
        max98363->first_hw_init = false;
 
index df92242af960ee65af7e952bc0d68b8c76cb2981..92d2b872f9f8fcc82734366d5e5e279293fc67c0 100644 (file)
@@ -361,10 +361,9 @@ static int max98373_io_init(struct sdw_slave *slave)
        struct device *dev = &slave->dev;
        struct max98373_priv *max98373 = dev_get_drvdata(dev);
 
-       if (max98373->first_hw_init) {
-               regcache_cache_only(max98373->regmap, false);
+       regcache_cache_only(max98373->regmap, false);
+       if (max98373->first_hw_init)
                regcache_cache_bypass(max98373->regmap, true);
-       }
 
        /*
         * PM runtime is only enabled when a Slave reports as Attached
@@ -753,6 +752,8 @@ static int max98373_init(struct sdw_slave *slave, struct regmap *regmap)
        max98373->regmap = regmap;
        max98373->slave = slave;
 
+       regcache_cache_only(max98373->regmap, true);
+
        max98373->cache_num = ARRAY_SIZE(max98373_sdw_cache_reg);
        max98373->cache = devm_kcalloc(dev, max98373->cache_num,
                                       sizeof(*max98373->cache),
index a7740549d35c9ffed0f93b1a5c2651d5a209bdbb..2c4e5330c2df1c7ed19edd61e25b9455c82efa95 100644 (file)
@@ -218,10 +218,9 @@ static int rt1308_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt1308->hw_init)
                return 0;
 
-       if (rt1308->first_hw_init) {
-               regcache_cache_only(rt1308->regmap, false);
+       regcache_cache_only(rt1308->regmap, false);
+       if (rt1308->first_hw_init)
                regcache_cache_bypass(rt1308->regmap, true);
-       }
 
        /*
         * PM runtime is only enabled when a Slave reports as Attached
@@ -688,6 +687,8 @@ static int rt1308_sdw_init(struct device *dev, struct regmap *regmap,
        rt1308->sdw_slave = slave;
        rt1308->regmap = regmap;
 
+       regcache_cache_only(rt1308->regmap, true);
+
        /*
         * Mark hw_init to false
         * HW init will be performed when device reports present
index 10a53c8d48742cf0c3fcf4eee1b4f0404bd208b5..57abbe2de7cf9a614947524a67059cc4a1b1909a 100644 (file)
@@ -272,8 +272,8 @@ static int rt1316_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt1316->hw_init)
                return 0;
 
+       regcache_cache_only(rt1316->regmap, false);
        if (rt1316->first_hw_init) {
-               regcache_cache_only(rt1316->regmap, false);
                regcache_cache_bypass(rt1316->regmap, true);
        } else {
                /*
@@ -674,6 +674,8 @@ static int rt1316_sdw_init(struct device *dev, struct regmap *regmap,
        rt1316->sdw_slave = slave;
        rt1316->regmap = regmap;
 
+       regcache_cache_only(rt1316->regmap, true);
+
        /*
         * Mark hw_init to false
         * HW init will be performed when device reports present
index 16d750102c8c049ad5a6c842d2dd562326a2f934..d7803342f5c22a9fb409ed531a451301a1bc72fb 100644 (file)
@@ -408,8 +408,8 @@ static int rt1318_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt1318->hw_init)
                return 0;
 
+       regcache_cache_only(rt1318->regmap, false);
        if (rt1318->first_hw_init) {
-               regcache_cache_only(rt1318->regmap, false);
                regcache_cache_bypass(rt1318->regmap, true);
        } else {
                /*
@@ -752,6 +752,8 @@ static int rt1318_sdw_init(struct device *dev, struct regmap *regmap,
        rt1318->sdw_slave = slave;
        rt1318->regmap = regmap;
 
+       regcache_cache_only(rt1318->regmap, true);
+
        /*
         * Mark hw_init to false
         * HW init will be performed when device reports present
index a04b9246256b4711cd09e8464e4dd19e7cd57768..b774349dfdae13ea3e630b08573ad39f86a44648 100644 (file)
@@ -1099,6 +1099,8 @@ int rt700_init(struct device *dev, struct regmap *sdw_regmap,
        rt700->sdw_regmap = sdw_regmap;
        rt700->regmap = regmap;
 
+       regcache_cache_only(rt700->regmap, true);
+
        mutex_init(&rt700->disable_irq_lock);
 
        INIT_DELAYED_WORK(&rt700->jack_detect_work,
@@ -1132,10 +1134,9 @@ int rt700_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt700->hw_init)
                return 0;
 
-       if (rt700->first_hw_init) {
-               regcache_cache_only(rt700->regmap, false);
+       regcache_cache_only(rt700->regmap, false);
+       if (rt700->first_hw_init)
                regcache_cache_bypass(rt700->regmap, true);
-       }
 
        /*
         * PM runtime is only enabled when a Slave reports as Attached
index 07640d2f6e560797bb300513309f022606f35bdb..bd0f5e05874bb244ec2139682a4d8528ffce0dce 100644 (file)
@@ -1406,6 +1406,9 @@ int rt711_sdca_init(struct device *dev, struct regmap *regmap,
        rt711->regmap = regmap;
        rt711->mbq_regmap = mbq_regmap;
 
+       regcache_cache_only(rt711->regmap, true);
+       regcache_cache_only(rt711->mbq_regmap, true);
+
        mutex_init(&rt711->calibrate_mutex);
        mutex_init(&rt711->disable_irq_lock);
 
@@ -1500,10 +1503,11 @@ int rt711_sdca_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt711->hw_init)
                return 0;
 
+       regcache_cache_only(rt711->regmap, false);
+       regcache_cache_only(rt711->mbq_regmap, false);
+
        if (rt711->first_hw_init) {
-               regcache_cache_only(rt711->regmap, false);
                regcache_cache_bypass(rt711->regmap, true);
-               regcache_cache_only(rt711->mbq_regmap, false);
                regcache_cache_bypass(rt711->mbq_regmap, true);
        } else {
                /*
index af53cbcc7bf2dd8636937accdeebb514c7f9ddcb..0ca955e2f4e76cea46dc90e72be048675746b4e3 100644 (file)
@@ -1183,6 +1183,8 @@ int rt711_init(struct device *dev, struct regmap *sdw_regmap,
        rt711->sdw_regmap = sdw_regmap;
        rt711->regmap = regmap;
 
+       regcache_cache_only(rt711->regmap, true);
+
        mutex_init(&rt711->calibrate_mutex);
        mutex_init(&rt711->disable_irq_lock);
 
@@ -1219,10 +1221,9 @@ int rt711_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt711->hw_init)
                return 0;
 
-       if (rt711->first_hw_init) {
-               regcache_cache_only(rt711->regmap, false);
+       regcache_cache_only(rt711->regmap, false);
+       if (rt711->first_hw_init)
                regcache_cache_bypass(rt711->regmap, true);
-       }
 
        /*
         * PM runtime is only enabled when a Slave reports as Attached
index 869cc7bfd17840e31b58640901ab763815f1a8eb..0102bad0b66a6f72cdff73d248d5bd80e9596bb2 100644 (file)
@@ -182,10 +182,10 @@ static int rt712_sdca_dmic_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt712->hw_init)
                return 0;
 
+       regcache_cache_only(rt712->regmap, false);
+       regcache_cache_only(rt712->mbq_regmap, false);
        if (rt712->first_hw_init) {
-               regcache_cache_only(rt712->regmap, false);
                regcache_cache_bypass(rt712->regmap, true);
-               regcache_cache_only(rt712->mbq_regmap, false);
                regcache_cache_bypass(rt712->mbq_regmap, true);
        } else {
                /*
@@ -777,6 +777,9 @@ static int rt712_sdca_dmic_init(struct device *dev, struct regmap *regmap,
        rt712->regmap = regmap;
        rt712->mbq_regmap = mbq_regmap;
 
+       regcache_cache_only(rt712->regmap, true);
+       regcache_cache_only(rt712->mbq_regmap, true);
+
        /*
         * Mark hw_init to false
         * HW init will be performed when device reports present
index 89d245655ca480ac2a8f7b548f62bbd62412ebda..88f6c895722e6e48ce919df6b19db9a051098def 100644 (file)
@@ -1183,6 +1183,9 @@ int rt712_sdca_init(struct device *dev, struct regmap *regmap,
        rt712->regmap = regmap;
        rt712->mbq_regmap = mbq_regmap;
 
+       regcache_cache_only(rt712->regmap, true);
+       regcache_cache_only(rt712->mbq_regmap, true);
+
        mutex_init(&rt712->calibrate_mutex);
        mutex_init(&rt712->disable_irq_lock);
 
@@ -1224,10 +1227,10 @@ int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt712->hw_init)
                return 0;
 
+       regcache_cache_only(rt712->regmap, false);
+       regcache_cache_only(rt712->mbq_regmap, false);
        if (rt712->first_hw_init) {
-               regcache_cache_only(rt712->regmap, false);
                regcache_cache_bypass(rt712->regmap, true);
-               regcache_cache_only(rt712->mbq_regmap, false);
                regcache_cache_bypass(rt712->mbq_regmap, true);
        } else {
                /*
index b989f907784b9d4dd1f36c52f3362b1886f44bbf..176340a4344613fefcdc9bb7d89906c18119016b 100644 (file)
@@ -977,6 +977,10 @@ int rt715_sdca_init(struct device *dev, struct regmap *mbq_regmap,
        rt715->regmap = regmap;
        rt715->mbq_regmap = mbq_regmap;
        rt715->hw_sdw_ver = slave->id.sdw_version;
+
+       regcache_cache_only(rt715->regmap, true);
+       regcache_cache_only(rt715->mbq_regmap, true);
+
        /*
         * Mark hw_init to false
         * HW init will be performed when device reports present
@@ -1000,6 +1004,9 @@ int rt715_sdca_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt715->hw_init)
                return 0;
 
+       regcache_cache_only(rt715->regmap, false);
+       regcache_cache_only(rt715->mbq_regmap, false);
+
        /*
         * PM runtime is only enabled when a Slave reports as Attached
         */
index 6c2e165dd6218a7dbe15ea80df5cc43411d93bd4..1bd2fe8aa62597a0b3d3a8b6862356e97871843f 100644 (file)
@@ -984,6 +984,8 @@ int rt715_init(struct device *dev, struct regmap *sdw_regmap,
        rt715->regmap = regmap;
        rt715->sdw_regmap = sdw_regmap;
 
+       regcache_cache_only(rt715->regmap, true);
+
        /*
         * Mark hw_init to false
         * HW init will be performed when device reports present
@@ -1006,6 +1008,8 @@ int rt715_io_init(struct device *dev, struct sdw_slave *slave)
        if (rt715->hw_init)
                return 0;
 
+       regcache_cache_only(rt715->regmap, false);
+
        /*
         * PM runtime is only enabled when a Slave reports as Attached
         */