Skip to content

Commit e1830f6

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs35l56: Add helper functions for amp calibration
Adds some helper functions and data for applying amp calibration. 1. cs35l56_read_silicon_uid() to get the silicon ID that is used to search for the correct calibration data entry. 2. Add the registers for the silicon ID to the readable registers. 3. cs35l56_get_calibration() wrapper around cs_amp_get_efi_calibration_data() 4. cs35l56_calibration_controls() table of the firmware controls for calibration data. 5. Added members to struct cs35l56_base to store the calibration data. Signed-off-by: Richard Fitzgerald <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1cad872 commit e1830f6

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

include/sound/cs35l56.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/firmware/cirrus/cs_dsp.h>
1313
#include <linux/regulator/consumer.h>
1414
#include <linux/regmap.h>
15+
#include <sound/cs-amp-lib.h>
1516

1617
#define CS35L56_DEVID 0x0000000
1718
#define CS35L56_REVID 0x0000004
@@ -23,6 +24,9 @@
2324
#define CS35L56_BLOCK_ENABLES2 0x000201C
2425
#define CS35L56_REFCLK_INPUT 0x0002C04
2526
#define CS35L56_GLOBAL_SAMPLE_RATE 0x0002C0C
27+
#define CS35L56_OTP_MEM_53 0x00300D4
28+
#define CS35L56_OTP_MEM_54 0x00300D8
29+
#define CS35L56_OTP_MEM_55 0x00300DC
2630
#define CS35L56_ASP1_ENABLES1 0x0004800
2731
#define CS35L56_ASP1_CONTROL1 0x0004804
2832
#define CS35L56_ASP1_CONTROL2 0x0004808
@@ -262,13 +266,18 @@ struct cs35l56_base {
262266
bool fw_patched;
263267
bool secured;
264268
bool can_hibernate;
269+
bool cal_data_valid;
270+
s8 cal_index;
271+
struct cirrus_amp_cal_data cal_data;
265272
struct gpio_desc *reset_gpio;
266273
};
267274

268275
extern struct regmap_config cs35l56_regmap_i2c;
269276
extern struct regmap_config cs35l56_regmap_spi;
270277
extern struct regmap_config cs35l56_regmap_sdw;
271278

279+
extern const struct cirrus_amp_cal_controls cs35l56_calibration_controls;
280+
272281
extern const char * const cs35l56_tx_input_texts[CS35L56_NUM_INPUT_SRC];
273282
extern const unsigned int cs35l56_tx_input_values[CS35L56_NUM_INPUT_SRC];
274283

@@ -286,6 +295,7 @@ int cs35l56_is_fw_reload_needed(struct cs35l56_base *cs35l56_base);
286295
int cs35l56_runtime_suspend_common(struct cs35l56_base *cs35l56_base);
287296
int cs35l56_runtime_resume_common(struct cs35l56_base *cs35l56_base, bool is_soundwire);
288297
void cs35l56_init_cs_dsp(struct cs35l56_base *cs35l56_base, struct cs_dsp *cs_dsp);
298+
int cs35l56_get_calibration(struct cs35l56_base *cs35l56_base);
289299
int cs35l56_read_prot_status(struct cs35l56_base *cs35l56_base,
290300
bool *fw_missing, unsigned int *fw_version);
291301
int cs35l56_hw_init(struct cs35l56_base *cs35l56_base);

sound/soc/codecs/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ config SND_SOC_CS35L56
798798
tristate
799799

800800
config SND_SOC_CS35L56_SHARED
801+
select SND_SOC_CS_AMP_LIB
801802
tristate
802803

803804
config SND_SOC_CS35L56_I2C

sound/soc/codecs/cs35l56-shared.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
// Copyright (C) 2023 Cirrus Logic, Inc. and
66
// Cirrus Logic International Semiconductor Ltd.
77

8+
#include <linux/firmware/cirrus/wmfw.h>
89
#include <linux/gpio/consumer.h>
910
#include <linux/regmap.h>
1011
#include <linux/regulator/consumer.h>
1112
#include <linux/types.h>
13+
#include <sound/cs-amp-lib.h>
1214

1315
#include "cs35l56.h"
1416

@@ -36,6 +38,8 @@ int cs35l56_set_patch(struct cs35l56_base *cs35l56_base)
3638
EXPORT_SYMBOL_NS_GPL(cs35l56_set_patch, SND_SOC_CS35L56_SHARED);
3739

3840
static const struct reg_default cs35l56_reg_defaults[] = {
41+
/* no defaults for OTP_MEM - first read populates cache */
42+
3943
{ CS35L56_ASP1_ENABLES1, 0x00000000 },
4044
{ CS35L56_ASP1_CONTROL1, 0x00000028 },
4145
{ CS35L56_ASP1_CONTROL2, 0x18180200 },
@@ -91,6 +95,9 @@ static bool cs35l56_readable_reg(struct device *dev, unsigned int reg)
9195
case CS35L56_BLOCK_ENABLES2:
9296
case CS35L56_REFCLK_INPUT:
9397
case CS35L56_GLOBAL_SAMPLE_RATE:
98+
case CS35L56_OTP_MEM_53:
99+
case CS35L56_OTP_MEM_54:
100+
case CS35L56_OTP_MEM_55:
94101
case CS35L56_ASP1_ENABLES1:
95102
case CS35L56_ASP1_CONTROL1:
96103
case CS35L56_ASP1_CONTROL2:
@@ -628,6 +635,81 @@ void cs35l56_init_cs_dsp(struct cs35l56_base *cs35l56_base, struct cs_dsp *cs_ds
628635
}
629636
EXPORT_SYMBOL_NS_GPL(cs35l56_init_cs_dsp, SND_SOC_CS35L56_SHARED);
630637

638+
struct cs35l56_pte {
639+
u8 x;
640+
u8 wafer_id;
641+
u8 pte[2];
642+
u8 lot[3];
643+
u8 y;
644+
u8 unused[3];
645+
u8 dvs;
646+
} __packed;
647+
static_assert((sizeof(struct cs35l56_pte) % sizeof(u32)) == 0);
648+
649+
static int cs35l56_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid)
650+
{
651+
struct cs35l56_pte pte;
652+
u64 unique_id;
653+
int ret;
654+
655+
ret = regmap_raw_read(cs35l56_base->regmap, CS35L56_OTP_MEM_53, &pte, sizeof(pte));
656+
if (ret) {
657+
dev_err(cs35l56_base->dev, "Failed to read OTP: %d\n", ret);
658+
return ret;
659+
}
660+
661+
unique_id = pte.lot[2] | (pte.lot[1] << 8) | (pte.lot[0] << 16);
662+
unique_id <<= 32;
663+
unique_id |= pte.x | (pte.y << 8) | (pte.wafer_id << 16) | (pte.dvs << 24);
664+
665+
dev_dbg(cs35l56_base->dev, "UniqueID = %#llx\n", unique_id);
666+
667+
*uid = unique_id;
668+
669+
return 0;
670+
}
671+
672+
/* Firmware calibration controls */
673+
const struct cirrus_amp_cal_controls cs35l56_calibration_controls = {
674+
.alg_id = 0x9f210,
675+
.mem_region = WMFW_ADSP2_YM,
676+
.ambient = "CAL_AMBIENT",
677+
.calr = "CAL_R",
678+
.status = "CAL_STATUS",
679+
.checksum = "CAL_CHECKSUM",
680+
};
681+
EXPORT_SYMBOL_NS_GPL(cs35l56_calibration_controls, SND_SOC_CS35L56_SHARED);
682+
683+
int cs35l56_get_calibration(struct cs35l56_base *cs35l56_base)
684+
{
685+
u64 silicon_uid;
686+
int ret;
687+
688+
/* Driver can't apply calibration to a secured part, so skip */
689+
if (cs35l56_base->secured)
690+
return 0;
691+
692+
ret = cs35l56_read_silicon_uid(cs35l56_base, &silicon_uid);
693+
if (ret < 0)
694+
return ret;
695+
696+
ret = cs_amp_get_efi_calibration_data(cs35l56_base->dev, silicon_uid,
697+
cs35l56_base->cal_index,
698+
&cs35l56_base->cal_data);
699+
700+
/* Only return an error status if probe should be aborted */
701+
if ((ret == -ENOENT) || (ret == -EOVERFLOW))
702+
return 0;
703+
704+
if (ret < 0)
705+
return ret;
706+
707+
cs35l56_base->cal_data_valid = true;
708+
709+
return 0;
710+
}
711+
EXPORT_SYMBOL_NS_GPL(cs35l56_get_calibration, SND_SOC_CS35L56_SHARED);
712+
631713
int cs35l56_read_prot_status(struct cs35l56_base *cs35l56_base,
632714
bool *fw_missing, unsigned int *fw_version)
633715
{
@@ -922,3 +1004,4 @@ MODULE_DESCRIPTION("ASoC CS35L56 Shared");
9221004
MODULE_AUTHOR("Richard Fitzgerald <[email protected]>");
9231005
MODULE_AUTHOR("Simon Trimmer <[email protected]>");
9241006
MODULE_LICENSE("GPL");
1007+
MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB);

0 commit comments

Comments
 (0)