diff options
author | Mark Brown <broonie@kernel.org> | 2022-11-11 17:01:39 +0000 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2022-11-11 17:01:48 +0000 |
commit | e5fa3ccad328bdfc6d118874b7a2bf89178f076b (patch) | |
tree | 2fd61d38a40ac7459ecb5fd0d12e9701efd54cea /sound/soc/codecs | |
parent | 9f63869a5682d5fa9bc5563577fe3270e7cbf4f2 (diff) | |
parent | cf6946d95005add8437f874e0952ec4f28fe5c02 (diff) |
ASoC: Set BQ parameters for some Dell models
There are some Dell SKUs that need to set the parameters of the
crossover filter (biquad). Each amplifier connects to one tweeter
speaker and one woofer speaker. We should control HPF/LPF to output the
proper frequency for the different speakers. If the codec driver got
the BQ parameters from the device property, it will apply these
parameters to the hardware.
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r-- | sound/soc/codecs/rt1308-sdw.c | 39 | ||||
-rw-r--r-- | sound/soc/codecs/rt1308-sdw.h | 2 | ||||
-rw-r--r-- | sound/soc/codecs/rt1316-sdw.c | 39 | ||||
-rw-r--r-- | sound/soc/codecs/rt1316-sdw.h | 2 |
4 files changed, 82 insertions, 0 deletions
diff --git a/sound/soc/codecs/rt1308-sdw.c b/sound/soc/codecs/rt1308-sdw.c index f99aed353f10..7f4248284f35 100644 --- a/sound/soc/codecs/rt1308-sdw.c +++ b/sound/soc/codecs/rt1308-sdw.c @@ -197,6 +197,17 @@ static void rt1308_apply_calib_params(struct rt1308_sdw_priv *rt1308) efuse_c_btl_l, efuse_c_btl_r); } +static void rt1308_apply_bq_params(struct rt1308_sdw_priv *rt1308) +{ + unsigned int i, reg, data; + + for (i = 0; i < rt1308->bq_params_cnt; i += 3) { + reg = rt1308->bq_params[i] | (rt1308->bq_params[i + 1] << 8); + data = rt1308->bq_params[i + 2]; + regmap_write(rt1308->regmap, reg, data); + } +} + static int rt1308_io_init(struct device *dev, struct sdw_slave *slave) { struct rt1308_sdw_priv *rt1308 = dev_get_drvdata(dev); @@ -619,14 +630,42 @@ static const struct sdw_slave_ops rt1308_slave_ops = { .bus_config = rt1308_bus_config, }; +static int rt1308_sdw_parse_dt(struct rt1308_sdw_priv *rt1308, struct device *dev) +{ + int ret = 0; + + device_property_read_u32(dev, "realtek,bq-params-cnt", &rt1308->bq_params_cnt); + if (rt1308->bq_params_cnt) { + rt1308->bq_params = devm_kzalloc(dev, rt1308->bq_params_cnt, GFP_KERNEL); + if (!rt1308->bq_params) { + dev_err(dev, "Could not allocate bq_params memory\n"); + ret = -ENOMEM; + } else { + ret = device_property_read_u8_array(dev, "realtek,bq-params", rt1308->bq_params, rt1308->bq_params_cnt); + if (ret < 0) + dev_err(dev, "Could not read list of realtek,bq-params\n"); + } + } + + dev_dbg(dev, "bq_params_cnt=%d\n", rt1308->bq_params_cnt); + return ret; +} + static int rt1308_sdw_component_probe(struct snd_soc_component *component) { + struct rt1308_sdw_priv *rt1308 = snd_soc_component_get_drvdata(component); int ret; + rt1308->component = component; + rt1308_sdw_parse_dt(rt1308, &rt1308->sdw_slave->dev); + ret = pm_runtime_resume(component->dev); if (ret < 0 && ret != -EACCES) return ret; + /* apply BQ params */ + rt1308_apply_bq_params(rt1308); + return 0; } diff --git a/sound/soc/codecs/rt1308-sdw.h b/sound/soc/codecs/rt1308-sdw.h index 62ce27799307..1eaaef9f351b 100644 --- a/sound/soc/codecs/rt1308-sdw.h +++ b/sound/soc/codecs/rt1308-sdw.h @@ -166,6 +166,8 @@ struct rt1308_sdw_priv { int rx_mask; int slots; int hw_ver; + unsigned char *bq_params; + unsigned int bq_params_cnt; }; struct sdw_stream_data { diff --git a/sound/soc/codecs/rt1316-sdw.c b/sound/soc/codecs/rt1316-sdw.c index ed0a11436362..2db7ee6c6d33 100644 --- a/sound/soc/codecs/rt1316-sdw.c +++ b/sound/soc/codecs/rt1316-sdw.c @@ -254,6 +254,17 @@ static int rt1316_read_prop(struct sdw_slave *slave) return 0; } +static void rt1316_apply_bq_params(struct rt1316_sdw_priv *rt1316) +{ + unsigned int i, reg, data; + + for (i = 0; i < rt1316->bq_params_cnt; i += 3) { + reg = rt1316->bq_params[i] | (rt1316->bq_params[i + 1] << 8); + data = rt1316->bq_params[i + 2]; + regmap_write(rt1316->regmap, reg, data); + } +} + static int rt1316_io_init(struct device *dev, struct sdw_slave *slave) { struct rt1316_sdw_priv *rt1316 = dev_get_drvdata(dev); @@ -590,14 +601,42 @@ static struct sdw_slave_ops rt1316_slave_ops = { .update_status = rt1316_update_status, }; +static int rt1316_sdw_parse_dt(struct rt1316_sdw_priv *rt1316, struct device *dev) +{ + int ret = 0; + + device_property_read_u32(dev, "realtek,bq-params-cnt", &rt1316->bq_params_cnt); + if (rt1316->bq_params_cnt) { + rt1316->bq_params = devm_kzalloc(dev, rt1316->bq_params_cnt, GFP_KERNEL); + if (!rt1316->bq_params) { + dev_err(dev, "Could not allocate bq_params memory\n"); + ret = -ENOMEM; + } else { + ret = device_property_read_u8_array(dev, "realtek,bq-params", rt1316->bq_params, rt1316->bq_params_cnt); + if (ret < 0) + dev_err(dev, "Could not read list of realtek,bq-params\n"); + } + } + + dev_dbg(dev, "bq_params_cnt=%d\n", rt1316->bq_params_cnt); + return ret; +} + static int rt1316_sdw_component_probe(struct snd_soc_component *component) { + struct rt1316_sdw_priv *rt1316 = snd_soc_component_get_drvdata(component); int ret; + rt1316->component = component; + rt1316_sdw_parse_dt(rt1316, &rt1316->sdw_slave->dev); + ret = pm_runtime_resume(component->dev); if (ret < 0 && ret != -EACCES) return ret; + /* apply BQ params */ + rt1316_apply_bq_params(rt1316); + return 0; } diff --git a/sound/soc/codecs/rt1316-sdw.h b/sound/soc/codecs/rt1316-sdw.h index cbcdaa8f8cfa..57dbd49993b0 100644 --- a/sound/soc/codecs/rt1316-sdw.h +++ b/sound/soc/codecs/rt1316-sdw.h @@ -46,6 +46,8 @@ struct rt1316_sdw_priv { struct sdw_bus_params params; bool hw_init; bool first_hw_init; + unsigned char *bq_params; + unsigned int bq_params_cnt; }; struct sdw_stream_data { |