Skip to content

Commit d92321b

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: cs35l41: Update handling of test key registers
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f6fdf77 commit d92321b

File tree

3 files changed

+54
-47
lines changed

3 files changed

+54
-47
lines changed

include/sound/cs35l41.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ struct cs35l41_otp_map_element_t {
762762
extern struct regmap_config cs35l41_regmap_i2c;
763763
extern struct regmap_config cs35l41_regmap_spi;
764764

765+
int cs35l41_test_key_unlock(struct device *dev, struct regmap *regmap);
766+
int cs35l41_test_key_lock(struct device *dev, struct regmap *regmap);
765767
int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap);
766768
int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsigned int reg_revid);
767769
int cs35l41_set_channels(struct device *dev, struct regmap *reg,

sound/soc/codecs/cs35l41-lib.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,6 @@ static const struct cs35l41_otp_packed_element_t otp_map_2[CS35L41_NUM_OTP_ELEM]
623623
};
624624

625625
static const struct reg_sequence cs35l41_reva0_errata_patch[] = {
626-
{ 0x00000040, 0x00005555 },
627-
{ 0x00000040, 0x0000AAAA },
628626
{ 0x00003854, 0x05180240 },
629627
{ CS35L41_VIMON_SPKMON_RESYNC, 0x00000000 },
630628
{ 0x00004310, 0x00000000 },
@@ -637,38 +635,28 @@ static const struct reg_sequence cs35l41_reva0_errata_patch[] = {
637635
{ CS35L41_IRQ2_DB3, 0x00000000 },
638636
{ CS35L41_DSP1_YM_ACCEL_PL0_PRI, 0x00000000 },
639637
{ CS35L41_DSP1_XM_ACCEL_PL0_PRI, 0x00000000 },
640-
{ 0x00000040, 0x0000CCCC },
641-
{ 0x00000040, 0x00003333 },
642638
{ CS35L41_PWR_CTRL2, 0x00000000 },
643639
{ CS35L41_AMP_GAIN_CTRL, 0x00000000 },
644640
};
645641

646642
static const struct reg_sequence cs35l41_revb0_errata_patch[] = {
647-
{ 0x00000040, 0x00005555 },
648-
{ 0x00000040, 0x0000AAAA },
649643
{ CS35L41_VIMON_SPKMON_RESYNC, 0x00000000 },
650644
{ 0x00004310, 0x00000000 },
651645
{ CS35L41_VPVBST_FS_SEL, 0x00000000 },
652646
{ CS35L41_BSTCVRT_DCM_CTRL, 0x00000051 },
653647
{ CS35L41_DSP1_YM_ACCEL_PL0_PRI, 0x00000000 },
654648
{ CS35L41_DSP1_XM_ACCEL_PL0_PRI, 0x00000000 },
655-
{ 0x00000040, 0x0000CCCC },
656-
{ 0x00000040, 0x00003333 },
657649
{ CS35L41_PWR_CTRL2, 0x00000000 },
658650
{ CS35L41_AMP_GAIN_CTRL, 0x00000000 },
659651
};
660652

661653
static const struct reg_sequence cs35l41_revb2_errata_patch[] = {
662-
{ 0x00000040, 0x00005555 },
663-
{ 0x00000040, 0x0000AAAA },
664654
{ CS35L41_VIMON_SPKMON_RESYNC, 0x00000000 },
665655
{ 0x00004310, 0x00000000 },
666656
{ CS35L41_VPVBST_FS_SEL, 0x00000000 },
667657
{ CS35L41_BSTCVRT_DCM_CTRL, 0x00000051 },
668658
{ CS35L41_DSP1_YM_ACCEL_PL0_PRI, 0x00000000 },
669659
{ CS35L41_DSP1_XM_ACCEL_PL0_PRI, 0x00000000 },
670-
{ 0x00000040, 0x0000CCCC },
671-
{ 0x00000040, 0x00003333 },
672660
{ CS35L41_PWR_CTRL2, 0x00000000 },
673661
{ CS35L41_AMP_GAIN_CTRL, 0x00000000 },
674662
};
@@ -756,6 +744,39 @@ static const struct cs35l41_otp_map_element_t *cs35l41_find_otp_map(u32 otp_id)
756744
return NULL;
757745
}
758746

747+
int cs35l41_test_key_unlock(struct device *dev, struct regmap *regmap)
748+
{
749+
static const struct reg_sequence unlock[] = {
750+
{ CS35L41_TEST_KEY_CTL, 0x00000055 },
751+
{ CS35L41_TEST_KEY_CTL, 0x000000AA },
752+
};
753+
int ret;
754+
755+
ret = regmap_multi_reg_write(regmap, unlock, ARRAY_SIZE(unlock));
756+
if (ret)
757+
dev_err(dev, "Failed to unlock test key: %d\n", ret);
758+
759+
return ret;
760+
}
761+
EXPORT_SYMBOL_GPL(cs35l41_test_key_unlock);
762+
763+
int cs35l41_test_key_lock(struct device *dev, struct regmap *regmap)
764+
{
765+
static const struct reg_sequence unlock[] = {
766+
{ CS35L41_TEST_KEY_CTL, 0x000000CC },
767+
{ CS35L41_TEST_KEY_CTL, 0x00000033 },
768+
};
769+
int ret;
770+
771+
ret = regmap_multi_reg_write(regmap, unlock, ARRAY_SIZE(unlock));
772+
if (ret)
773+
dev_err(dev, "Failed to lock test key: %d\n", ret);
774+
775+
return ret;
776+
}
777+
EXPORT_SYMBOL_GPL(cs35l41_test_key_lock);
778+
779+
/* Must be called with the TEST_KEY unlocked */
759780
int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap)
760781
{
761782
const struct cs35l41_otp_map_element_t *otp_map_match;
@@ -794,17 +815,6 @@ int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap)
794815
bit_offset = otp_map_match->bit_offset;
795816
word_offset = otp_map_match->word_offset;
796817

797-
ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x00000055);
798-
if (ret) {
799-
dev_err(dev, "Write Unlock key failed 1/2: %d\n", ret);
800-
goto err_otp_unpack;
801-
}
802-
ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x000000AA);
803-
if (ret) {
804-
dev_err(dev, "Write Unlock key failed 2/2: %d\n", ret);
805-
goto err_otp_unpack;
806-
}
807-
808818
for (i = 0; i < otp_map_match->num_elements; i++) {
809819
dev_dbg(dev, "bitoffset= %d, word_offset=%d, bit_sum mod 32=%d\n",
810820
bit_offset, word_offset, bit_sum % 32);
@@ -840,16 +850,6 @@ int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap)
840850
}
841851
}
842852

843-
ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x000000CC);
844-
if (ret) {
845-
dev_err(dev, "Write Lock key failed 1/2: %d\n", ret);
846-
goto err_otp_unpack;
847-
}
848-
ret = regmap_write(regmap, CS35L41_TEST_KEY_CTL, 0x00000033);
849-
if (ret) {
850-
dev_err(dev, "Write Lock key failed 2/2: %d\n", ret);
851-
goto err_otp_unpack;
852-
}
853853
ret = 0;
854854

855855
err_otp_unpack:
@@ -859,6 +859,7 @@ int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap)
859859
}
860860
EXPORT_SYMBOL_GPL(cs35l41_otp_unpack);
861861

862+
/* Must be called with the TEST_KEY unlocked */
862863
int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsigned int reg_revid)
863864
{
864865
char *rev;

sound/soc/codecs/cs35l41.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -534,19 +534,19 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
534534
}
535535

536536
static const struct reg_sequence cs35l41_pup_patch[] = {
537-
{ 0x00000040, 0x00000055 },
538-
{ 0x00000040, 0x000000AA },
537+
{ CS35L41_TEST_KEY_CTL, 0x00000055 },
538+
{ CS35L41_TEST_KEY_CTL, 0x000000AA },
539539
{ 0x00002084, 0x002F1AA0 },
540-
{ 0x00000040, 0x000000CC },
541-
{ 0x00000040, 0x00000033 },
540+
{ CS35L41_TEST_KEY_CTL, 0x000000CC },
541+
{ CS35L41_TEST_KEY_CTL, 0x00000033 },
542542
};
543543

544544
static const struct reg_sequence cs35l41_pdn_patch[] = {
545-
{ 0x00000040, 0x00000055 },
546-
{ 0x00000040, 0x000000AA },
545+
{ CS35L41_TEST_KEY_CTL, 0x00000055 },
546+
{ CS35L41_TEST_KEY_CTL, 0x000000AA },
547547
{ 0x00002084, 0x002F1AA3 },
548-
{ 0x00000040, 0x000000CC },
549-
{ 0x00000040, 0x00000033 },
548+
{ CS35L41_TEST_KEY_CTL, 0x000000CC },
549+
{ CS35L41_TEST_KEY_CTL, 0x00000033 },
550550
};
551551

552552
static int cs35l41_main_amp_event(struct snd_soc_dapm_widget *w,
@@ -1329,10 +1329,20 @@ int cs35l41_probe(struct cs35l41_private *cs35l41,
13291329
goto err;
13301330
}
13311331

1332+
cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap);
1333+
13321334
ret = cs35l41_register_errata_patch(cs35l41->dev, cs35l41->regmap, reg_revid);
13331335
if (ret)
13341336
goto err;
13351337

1338+
ret = cs35l41_otp_unpack(cs35l41->dev, cs35l41->regmap);
1339+
if (ret < 0) {
1340+
dev_err(cs35l41->dev, "OTP Unpack failed: %d\n", ret);
1341+
goto err;
1342+
}
1343+
1344+
cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap);
1345+
13361346
irq_pol = cs35l41_irq_gpio_config(cs35l41);
13371347

13381348
/* Set interrupt masks for critical errors */
@@ -1347,12 +1357,6 @@ int cs35l41_probe(struct cs35l41_private *cs35l41,
13471357
goto err;
13481358
}
13491359

1350-
ret = cs35l41_otp_unpack(cs35l41->dev, cs35l41->regmap);
1351-
if (ret < 0) {
1352-
dev_err(cs35l41->dev, "OTP Unpack failed: %d\n", ret);
1353-
goto err;
1354-
}
1355-
13561360
ret = cs35l41_set_pdata(cs35l41);
13571361
if (ret < 0) {
13581362
dev_err(cs35l41->dev, "Set pdata failed: %d\n", ret);

0 commit comments

Comments
 (0)