diff options
| author | Jan Dakinevich <jan.dakinevich@salutedevices.com> | 2026-05-29 00:15:19 +0300 |
|---|---|---|
| committer | Dmitry Rokosov <rockosov@rulkc.org> | 2026-08-13 14:41:35 +0300 |
| commit | 0f315ffd57ae46ba68769375afc7f8f443400647 (patch) | |
| tree | 097bd8add1bba3b28dbab8f8b2bb320d850bf26d | |
| parent | 19a8af03a4658d422f2751aa231cb46bed156720 (diff) | |
| download | linux-0f315ffd57ae46ba68769375afc7f8f443400647.tar.gz linux-0f315ffd57ae46ba68769375afc7f8f443400647.zip | |
ASoC: es7243e: fix constraints handling
Originally, the driver selected constraints in ->set_sysclk() and
installed they in ->startup(). That is incorrect due to following
reasons:
- ->startup() is before called ->set_sysclk(), so no constraints were
applied when the device was accesed for the first time.
- even ->startup() successfully installed constraints ->set_sysclk() is
unable to select another one to satisfy changed sample rate, because
the value of 'freq' passed to ->set_sysclk() is refined by existing
constraints _before_ ->set_sysclk() is called.
Signed-off-by: Jan Dakinevich <jan.dakinevich@salutedevices.com>
Signed-off-by: Dmitry Rokosov <rockosov@rulkc.org>
| -rw-r--r-- | sound/soc/codecs/es7243e.c | 82 |
1 files changed, 28 insertions, 54 deletions
diff --git a/sound/soc/codecs/es7243e.c b/sound/soc/codecs/es7243e.c index fc9239c6030b..5b359cdb8108 100644 --- a/sound/soc/codecs/es7243e.c +++ b/sound/soc/codecs/es7243e.c @@ -92,7 +92,7 @@ struct es7243e_priv { struct clk *sclk; struct clk *lrclk; unsigned int sysclk; - struct snd_pcm_hw_constraint_list *sysclk_constraints; + struct snd_pcm_hw_constraint_list rates; }; static const struct regmap_config es7243e_regmap_config = { @@ -187,61 +187,15 @@ static const struct coeff_div *get_coeff(int mclk, int rate) return NULL; } -static unsigned int rates_12288[] = { - 8000, 12000, 16000, 24000, 32000, 48000, 64000, 96000, 128000, 192000, -}; - -static struct snd_pcm_hw_constraint_list constraints_12288 = { - .count = ARRAY_SIZE(rates_12288), - .list = rates_12288, -}; - -static unsigned int rates_8192[] = { - 8000, 16000, 32000, 64000, 128000, -}; - -static struct snd_pcm_hw_constraint_list constraints_8192 = { - .count = ARRAY_SIZE(rates_8192), - .list = rates_8192, -}; - -static unsigned int rates_112896[] = { - 8000, 11025, 22050, 44100, -}; - -static struct snd_pcm_hw_constraint_list constraints_112896 = { - .count = ARRAY_SIZE(rates_112896), - .list = rates_112896, -}; - static int es7243e_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { struct snd_soc_component *component = dai->component; - struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct es7243e_priv *es7243e = snd_soc_component_get_drvdata(component); - switch (freq) { - case 11289600: - case 22579200: - es7243e->sysclk_constraints = &constraints_112896; - es7243e->sysclk = freq; - break; - case 12288000: - case 24576000: - es7243e->sysclk_constraints = &constraints_12288; - es7243e->sysclk = freq; - break; - case 4096000: - case 8192000: - es7243e->sysclk_constraints = &constraints_8192; - es7243e->sysclk = freq; - break; - default: - return -EINVAL; - } + es7243e->sysclk = freq; - return snd_soc_dapm_sync(dapm); + return 0; } static int es7243e_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) @@ -319,13 +273,9 @@ static int es7243e_pcm_startup(struct snd_pcm_substream *substream, { struct es7243e_priv *es7243e = snd_soc_component_get_drvdata(dai->component); - if (!es7243e->sysclk_constraints) - return 0; - - return snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_RATE, - es7243e->sysclk_constraints); + &es7243e->rates); } static int es7243e_pcm_hw_params(struct snd_pcm_substream *substream, @@ -621,6 +571,26 @@ static const struct snd_soc_component_driver soc_component_dev_es7243e = { .num_dapm_routes = ARRAY_SIZE(es7243e_dapm_routes), }; +static int es7243e_rates_init(struct device *dev) +{ + struct es7243e_priv *es7243e = dev_get_drvdata(dev); + unsigned int *rates; + unsigned int i; + + rates = devm_kcalloc(dev, ARRAY_SIZE(coeff_div), sizeof(*rates), + GFP_KERNEL); + if (!rates) + return -ENOMEM; + + for (i = 0; i < ARRAY_SIZE(coeff_div); i++) + rates[i] = coeff_div[i].sr_rate; + + es7243e->rates.list = rates; + es7243e->rates.count = ARRAY_SIZE(coeff_div); + + return 0; +} + static int es7243e_hw_init(struct device *dev) { struct regmap *regmap = dev_get_regmap(dev, NULL); @@ -675,6 +645,10 @@ static int es7243e_i2c_probe(struct i2c_client *i2c) return dev_err_probe(&i2c->dev, PTR_ERR(es7243e->lrclk), "failed to get lrclk clock\n"); + ret = es7243e_rates_init(&i2c->dev); + if (ret) + return ret; + if (es7243e_hw_init(&i2c->dev)) return -ENODEV; |
