]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: cs35l56: Read silicon ID during initialization and save it
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Tue, 21 Oct 2025 10:50:12 +0000 (11:50 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 27 Oct 2025 14:07:41 +0000 (14:07 +0000)
Read the silicon ID from the amp during one-time cs35l56_hw_init()
and store it in struct cs35l56_base, instead of reading it from
registers every time it is needed.

Note that marking it non-volatile without a default in regmap isn't
a suitable alternative because this causes regcache_sync() to always
write the cached value out to the registers. This could trigger a bus
fault interrupt inside the amp, which we want to avoid.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20251021105022.1013685-2-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/cs35l56.h
sound/soc/codecs/cs35l56-shared.c

index ab044ce2aa8b351c325c4ef7e75a10757206fb2a..ec9b1072d6bedc5f5a74d13887008f635194badf 100644 (file)
@@ -309,6 +309,7 @@ struct cs35l56_base {
        struct cs35l56_spi_payload *spi_payload_buf;
        const struct cs35l56_fw_reg *fw_reg;
        const struct cirrus_amp_cal_controls *calibration_controls;
+       u64 silicon_uid;
 };
 
 static inline bool cs35l56_is_otp_register(unsigned int reg)
index 9e6b9ca2f3547d273b932b544518a6a4e3b4d3f6..1ecfc38d8eb48fe18163f7f3908c248725f44e0f 100644 (file)
@@ -853,7 +853,7 @@ struct cs35l56_pte {
 } __packed;
 static_assert((sizeof(struct cs35l56_pte) % sizeof(u32)) == 0);
 
-static int cs35l56_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid)
+static int cs35l56_read_silicon_uid(struct cs35l56_base *cs35l56_base)
 {
        struct cs35l56_pte pte;
        u64 unique_id;
@@ -870,14 +870,15 @@ static int cs35l56_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid)
        unique_id |= (u32)pte.x | ((u32)pte.y << 8) | ((u32)pte.wafer_id << 16) |
                     ((u32)pte.dvs << 24);
 
-       *uid = unique_id;
+       cs35l56_base->silicon_uid = unique_id;
 
        return 0;
 }
 
-static int cs35l63_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid)
+static int cs35l63_read_silicon_uid(struct cs35l56_base *cs35l56_base)
 {
        u32 tmp[2];
+       u64 unique_id;
        int ret;
 
        ret = regmap_bulk_read(cs35l56_base->regmap, CS35L56_DIE_STS1, tmp, ARRAY_SIZE(tmp));
@@ -886,9 +887,11 @@ static int cs35l63_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid)
                return ret;
        }
 
-       *uid = tmp[1];
-       *uid <<= 32;
-       *uid |= tmp[0];
+       unique_id = tmp[1];
+       unique_id <<= 32;
+       unique_id |= tmp[0];
+
+       cs35l56_base->silicon_uid = unique_id;
 
        return 0;
 }
@@ -915,33 +918,14 @@ static const struct cirrus_amp_cal_controls cs35l63_calibration_controls = {
 
 int cs35l56_get_calibration(struct cs35l56_base *cs35l56_base)
 {
-       u64 silicon_uid = 0;
        int ret;
 
        /* Driver can't apply calibration to a secured part, so skip */
        if (cs35l56_base->secured)
                return 0;
 
-       switch (cs35l56_base->type) {
-       case 0x54:
-       case 0x56:
-       case 0x57:
-               ret = cs35l56_read_silicon_uid(cs35l56_base, &silicon_uid);
-               break;
-       case 0x63:
-               ret = cs35l63_read_silicon_uid(cs35l56_base, &silicon_uid);
-               break;
-       default:
-               ret = -ENODEV;
-               break;
-       }
-
-       if (ret < 0)
-               return ret;
-
-       dev_dbg(cs35l56_base->dev, "UniqueID = %#llx\n", silicon_uid);
-
-       ret = cs_amp_get_efi_calibration_data(cs35l56_base->dev, silicon_uid,
+       ret = cs_amp_get_efi_calibration_data(cs35l56_base->dev,
+                                             cs35l56_base->silicon_uid,
                                              cs35l56_base->cal_index,
                                              &cs35l56_base->cal_data);
 
@@ -1111,6 +1095,21 @@ int cs35l56_hw_init(struct cs35l56_base *cs35l56_base)
                           CS35L56_TEMP_ERR_EINT1_MASK,
                           0);
 
+       switch (cs35l56_base->type) {
+       case 0x54:
+       case 0x56:
+       case 0x57:
+               ret = cs35l56_read_silicon_uid(cs35l56_base);
+               break;
+       default:
+               ret = cs35l63_read_silicon_uid(cs35l56_base);
+               break;
+       }
+       if (ret)
+               return ret;
+
+       dev_dbg(cs35l56_base->dev, "SiliconID = %#llx\n", cs35l56_base->silicon_uid);
+
        return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cs35l56_hw_init, "SND_SOC_CS35L56_SHARED");