Skip to content

Commit

Permalink
ASoC: cs35l56: Load tunings for the correct speaker models
Browse files Browse the repository at this point in the history
If the "spk-id-gpios" property is present it points to GPIOs whose
value must be used to select the correct bin file to match the
speakers.

Some manufacturers use multiple sources of speakers, which need
different tunings for best performance. On these models the type of
speaker fitted is indicated by the values of one or more GPIOs. The
number formed by the GPIOs identifies the tuning required.

The speaker ID must be used in combination with the subsystem ID
(either from PCI SSID or cirrus,firmware-uid property), because the
GPIOs can only indicate variants of a specific model.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: 1a1c3d7 ("ASoC: cs35l56: Use PCI SSID as the firmware UID")
Link: https://msgid.link/r/20240129162737.497-14-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
rfvirgil authored and broonie committed Feb 1, 2024
1 parent f4ef514 commit 245eeff
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/sound/cs35l56.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ void cs35l56_init_cs_dsp(struct cs35l56_base *cs35l56_base, struct cs_dsp *cs_ds
int cs35l56_read_prot_status(struct cs35l56_base *cs35l56_base,
bool *fw_missing, unsigned int *fw_version);
int cs35l56_hw_init(struct cs35l56_base *cs35l56_base);
int cs35l56_get_speaker_id(struct cs35l56_base *cs35l56_base);
int cs35l56_get_bclk_freq_id(unsigned int freq);
void cs35l56_fill_supply_names(struct regulator_bulk_data *data);

Expand Down
36 changes: 36 additions & 0 deletions sound/soc/codecs/cs35l56-shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright (C) 2023 Cirrus Logic, Inc. and
// Cirrus Logic International Semiconductor Ltd.

#include <linux/gpio/consumer.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/types.h>
Expand Down Expand Up @@ -736,6 +737,41 @@ int cs35l56_hw_init(struct cs35l56_base *cs35l56_base)
}
EXPORT_SYMBOL_NS_GPL(cs35l56_hw_init, SND_SOC_CS35L56_SHARED);

int cs35l56_get_speaker_id(struct cs35l56_base *cs35l56_base)
{
struct gpio_descs *descs;
int speaker_id;
int i, ret;

/* Read the speaker type qualifier from the motherboard GPIOs */
descs = gpiod_get_array_optional(cs35l56_base->dev, "spk-id", GPIOD_IN);
if (!descs) {
return -ENOENT;
} else if (IS_ERR(descs)) {
ret = PTR_ERR(descs);
return dev_err_probe(cs35l56_base->dev, ret, "Failed to get spk-id-gpios\n");
}

speaker_id = 0;
for (i = 0; i < descs->ndescs; i++) {
ret = gpiod_get_value_cansleep(descs->desc[i]);
if (ret < 0) {
dev_err_probe(cs35l56_base->dev, ret, "Failed to read spk-id[%d]\n", i);
goto err;
}

speaker_id |= (ret << i);
}

dev_dbg(cs35l56_base->dev, "Speaker ID = %d\n", speaker_id);
ret = speaker_id;
err:
gpiod_put_array(descs);

return ret;
}
EXPORT_SYMBOL_NS_GPL(cs35l56_get_speaker_id, SND_SOC_CS35L56_SHARED);

static const u32 cs35l56_bclk_valid_for_pll_freq_table[] = {
[0x0C] = 128000,
[0x0F] = 256000,
Expand Down
32 changes: 27 additions & 5 deletions sound/soc/codecs/cs35l56.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,19 @@ static int cs35l56_component_probe(struct snd_soc_component *component)

if (!cs35l56->dsp.system_name &&
(snd_soc_card_get_pci_ssid(component->card, &vendor, &device) == 0)) {
cs35l56->dsp.system_name = devm_kasprintf(cs35l56->base.dev,
GFP_KERNEL,
"%04x%04x",
vendor, device);
/* Append a speaker qualifier if there is a speaker ID */
if (cs35l56->speaker_id >= 0) {
cs35l56->dsp.system_name = devm_kasprintf(cs35l56->base.dev,
GFP_KERNEL,
"%04x%04x-spkid%d",
vendor, device,
cs35l56->speaker_id);
} else {
cs35l56->dsp.system_name = devm_kasprintf(cs35l56->base.dev,
GFP_KERNEL,
"%04x%04x",
vendor, device);
}
if (!cs35l56->dsp.system_name)
return -ENOMEM;
}
Expand Down Expand Up @@ -1245,7 +1254,13 @@ static int cs35l56_get_firmware_uid(struct cs35l56_private *cs35l56)
if (ret < 0)
return 0;

cs35l56->dsp.system_name = devm_kstrdup(dev, prop, GFP_KERNEL);
/* Append a speaker qualifier if there is a speaker ID */
if (cs35l56->speaker_id >= 0)
cs35l56->dsp.system_name = devm_kasprintf(dev, GFP_KERNEL, "%s-spkid%d",
prop, cs35l56->speaker_id);
else
cs35l56->dsp.system_name = devm_kstrdup(dev, prop, GFP_KERNEL);

if (cs35l56->dsp.system_name == NULL)
return -ENOMEM;

Expand All @@ -1260,6 +1275,7 @@ int cs35l56_common_probe(struct cs35l56_private *cs35l56)

init_completion(&cs35l56->init_completion);
mutex_init(&cs35l56->base.irq_lock);
cs35l56->speaker_id = -ENOENT;

dev_set_drvdata(cs35l56->base.dev, cs35l56);

Expand Down Expand Up @@ -1296,6 +1312,12 @@ int cs35l56_common_probe(struct cs35l56_private *cs35l56)
gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 1);
}

ret = cs35l56_get_speaker_id(&cs35l56->base);
if ((ret < 0) && (ret != -ENOENT))
goto err;

cs35l56->speaker_id = ret;

ret = cs35l56_get_firmware_uid(cs35l56);
if (ret != 0)
goto err;
Expand Down
1 change: 1 addition & 0 deletions sound/soc/codecs/cs35l56.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct cs35l56_private {
bool sdw_attached;
struct completion init_completion;

int speaker_id;
u32 rx_mask;
u32 tx_mask;
u8 asp_slot_width;
Expand Down

0 comments on commit 245eeff

Please sign in to comment.