]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
ASoC: cs35l41: Update handling of test key registers
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Fri, 7 Jan 2022 16:06:35 +0000 (16:06 +0000)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:41:37 +0000 (14:41 +0200)
BugLink: https://bugs.launchpad.net/bugs/1965496
In preparation for the addition of PM runtime support move the test
key out of the register patches themselves. This is necessary to
allow the test key to be held during cache synchronisation, which is
required by the OTP settings which were unpacked from the device and
written by the driver.

Also whilst at it, the driver uses a mixture of accessing the test key
register by name and by address, consistently use the name.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20220107160636.6555-2-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit d92321bbe46b0ecae0941461379d39599610d869)
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Acked-by: Andrea Righi <andrea.righi@canonical.com>
Acked-by: Paolo Pisati <paolo.pisati@canonical.com>
include/sound/cs35l41.h
sound/soc/codecs/cs35l41-lib.c
sound/soc/codecs/cs35l41.c

index 29a527457b4862f1de4e95ce8f8dd4b1dc529190..56289b67b9a0ecd3e21930c85e0c1e84f2e2dfd1 100644 (file)
@@ -762,6 +762,8 @@ struct cs35l41_otp_map_element_t {
 extern struct regmap_config cs35l41_regmap_i2c;
 extern struct regmap_config cs35l41_regmap_spi;
 
+int cs35l41_test_key_unlock(struct device *dev, struct regmap *regmap);
+int cs35l41_test_key_lock(struct device *dev, struct regmap *regmap);
 int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap);
 int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsigned int reg_revid);
 int cs35l41_set_channels(struct device *dev, struct regmap *reg,
index 639dcd25b17e950da0379041db50609e8ae6eec3..ecaf67fd7653102247d17ca62cf48337499a3d2e 100644 (file)
@@ -623,8 +623,6 @@ static const struct cs35l41_otp_packed_element_t otp_map_2[CS35L41_NUM_OTP_ELEM]
 };
 
 static const struct reg_sequence cs35l41_reva0_errata_patch[] = {
-       { 0x00000040,                    0x00005555 },
-       { 0x00000040,                    0x0000AAAA },
        { 0x00003854,                    0x05180240 },
        { CS35L41_VIMON_SPKMON_RESYNC,   0x00000000 },
        { 0x00004310,                    0x00000000 },
@@ -637,38 +635,28 @@ static const struct reg_sequence cs35l41_reva0_errata_patch[] = {
        { CS35L41_IRQ2_DB3,              0x00000000 },
        { CS35L41_DSP1_YM_ACCEL_PL0_PRI, 0x00000000 },
        { CS35L41_DSP1_XM_ACCEL_PL0_PRI, 0x00000000 },
-       { 0x00000040,                    0x0000CCCC },
-       { 0x00000040,                    0x00003333 },
        { CS35L41_PWR_CTRL2,             0x00000000 },
        { CS35L41_AMP_GAIN_CTRL,         0x00000000 },
 };
 
 static const struct reg_sequence cs35l41_revb0_errata_patch[] = {
-       { 0x00000040,                    0x00005555 },
-       { 0x00000040,                    0x0000AAAA },
        { CS35L41_VIMON_SPKMON_RESYNC,   0x00000000 },
        { 0x00004310,                    0x00000000 },
        { CS35L41_VPVBST_FS_SEL,         0x00000000 },
        { CS35L41_BSTCVRT_DCM_CTRL,      0x00000051 },
        { CS35L41_DSP1_YM_ACCEL_PL0_PRI, 0x00000000 },
        { CS35L41_DSP1_XM_ACCEL_PL0_PRI, 0x00000000 },
-       { 0x00000040,                    0x0000CCCC },
-       { 0x00000040,                    0x00003333 },
        { CS35L41_PWR_CTRL2,             0x00000000 },
        { CS35L41_AMP_GAIN_CTRL,         0x00000000 },
 };
 
 static const struct reg_sequence cs35l41_revb2_errata_patch[] = {
-       { 0x00000040,                    0x00005555 },
-       { 0x00000040,                    0x0000AAAA },
        { CS35L41_VIMON_SPKMON_RESYNC,   0x00000000 },
        { 0x00004310,                    0x00000000 },
        { CS35L41_VPVBST_FS_SEL,         0x00000000 },
        { CS35L41_BSTCVRT_DCM_CTRL,      0x00000051 },
        { CS35L41_DSP1_YM_ACCEL_PL0_PRI, 0x00000000 },
        { CS35L41_DSP1_XM_ACCEL_PL0_PRI, 0x00000000 },
-       { 0x00000040,                    0x0000CCCC },
-       { 0x00000040,                    0x00003333 },
        { CS35L41_PWR_CTRL2,             0x00000000 },
        { CS35L41_AMP_GAIN_CTRL,         0x00000000 },
 };
@@ -756,6 +744,39 @@ static const struct cs35l41_otp_map_element_t *cs35l41_find_otp_map(u32 otp_id)
        return NULL;
 }
 
+int cs35l41_test_key_unlock(struct device *dev, struct regmap *regmap)
+{
+       static const struct reg_sequence unlock[] = {
+               { CS35L41_TEST_KEY_CTL, 0x00000055 },
+               { CS35L41_TEST_KEY_CTL, 0x000000AA },
+       };
+       int ret;
+
+       ret = regmap_multi_reg_write(regmap, unlock, ARRAY_SIZE(unlock));
+       if (ret)
+               dev_err(dev, "Failed to unlock test key: %d\n", ret);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(cs35l41_test_key_unlock);
+
+int cs35l41_test_key_lock(struct device *dev, struct regmap *regmap)
+{
+       static const struct reg_sequence unlock[] = {
+               { CS35L41_TEST_KEY_CTL, 0x000000CC },
+               { CS35L41_TEST_KEY_CTL, 0x00000033 },
+       };
+       int ret;
+
+       ret = regmap_multi_reg_write(regmap, unlock, ARRAY_SIZE(unlock));
+       if (ret)
+               dev_err(dev, "Failed to lock test key: %d\n", ret);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(cs35l41_test_key_lock);
+
+/* Must be called with the TEST_KEY unlocked */
 int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap)
 {
        const struct cs35l41_otp_map_element_t *otp_map_match;
@@ -794,17 +815,6 @@ int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap)
        bit_offset = otp_map_match->bit_offset;
        word_offset = otp_map_match->word_offset;
 
-       ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x00000055);
-       if (ret) {
-               dev_err(dev, "Write Unlock key failed 1/2: %d\n", ret);
-               goto err_otp_unpack;
-       }
-       ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x000000AA);
-       if (ret) {
-               dev_err(dev, "Write Unlock key failed 2/2: %d\n", ret);
-               goto err_otp_unpack;
-       }
-
        for (i = 0; i < otp_map_match->num_elements; i++) {
                dev_dbg(dev, "bitoffset= %d, word_offset=%d, bit_sum mod 32=%d\n",
                        bit_offset, word_offset, bit_sum % 32);
@@ -840,16 +850,6 @@ int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap)
                }
        }
 
-       ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x000000CC);
-       if (ret) {
-               dev_err(dev, "Write Lock key failed 1/2: %d\n", ret);
-               goto err_otp_unpack;
-       }
-       ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x00000033);
-       if (ret) {
-               dev_err(dev, "Write Lock key failed 2/2: %d\n", ret);
-               goto err_otp_unpack;
-       }
        ret = 0;
 
 err_otp_unpack:
@@ -859,6 +859,7 @@ err_otp_unpack:
 }
 EXPORT_SYMBOL_GPL(cs35l41_otp_unpack);
 
+/* Must be called with the TEST_KEY unlocked */
 int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsigned int reg_revid)
 {
        char *rev;
index 3920bd7b426153144d3ddbf4451c5d4c925d480d..e188d4d1e0426b303354313bb7c9f9b31dc0d93d 100644 (file)
@@ -534,19 +534,19 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
 }
 
 static const struct reg_sequence cs35l41_pup_patch[] = {
-       { 0x00000040, 0x00000055 },
-       { 0x00000040, 0x000000AA },
+       { CS35L41_TEST_KEY_CTL, 0x00000055 },
+       { CS35L41_TEST_KEY_CTL, 0x000000AA },
        { 0x00002084, 0x002F1AA0 },
-       { 0x00000040, 0x000000CC },
-       { 0x00000040, 0x00000033 },
+       { CS35L41_TEST_KEY_CTL, 0x000000CC },
+       { CS35L41_TEST_KEY_CTL, 0x00000033 },
 };
 
 static const struct reg_sequence cs35l41_pdn_patch[] = {
-       { 0x00000040, 0x00000055 },
-       { 0x00000040, 0x000000AA },
+       { CS35L41_TEST_KEY_CTL, 0x00000055 },
+       { CS35L41_TEST_KEY_CTL, 0x000000AA },
        { 0x00002084, 0x002F1AA3 },
-       { 0x00000040, 0x000000CC },
-       { 0x00000040, 0x00000033 },
+       { CS35L41_TEST_KEY_CTL, 0x000000CC },
+       { CS35L41_TEST_KEY_CTL, 0x00000033 },
 };
 
 static int cs35l41_main_amp_event(struct snd_soc_dapm_widget *w,
@@ -1329,10 +1329,20 @@ int cs35l41_probe(struct cs35l41_private *cs35l41,
                goto err;
        }
 
+       cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap);
+
        ret = cs35l41_register_errata_patch(cs35l41->dev, cs35l41->regmap, reg_revid);
        if (ret)
                goto err;
 
+       ret = cs35l41_otp_unpack(cs35l41->dev, cs35l41->regmap);
+       if (ret < 0) {
+               dev_err(cs35l41->dev, "OTP Unpack failed: %d\n", ret);
+               goto err;
+       }
+
+       cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap);
+
        irq_pol = cs35l41_irq_gpio_config(cs35l41);
 
        /* Set interrupt masks for critical errors */
@@ -1347,12 +1357,6 @@ int cs35l41_probe(struct cs35l41_private *cs35l41,
                goto err;
        }
 
-       ret = cs35l41_otp_unpack(cs35l41->dev, cs35l41->regmap);
-       if (ret < 0) {
-               dev_err(cs35l41->dev, "OTP Unpack failed: %d\n", ret);
-               goto err;
-       }
-
        ret = cs35l41_set_pdata(cs35l41);
        if (ret < 0) {
                dev_err(cs35l41->dev, "Set pdata failed: %d\n", ret);