Skip to content

Commit bfa4671

Browse files
digetxbroonie
authored andcommitted
ASoC: tegra20: i2s: Filter out unsupported rates
Support new nvidia,fixed-parent-rate device-tree property which instructs I2S that board wants parent clock rate to stay at a fixed rate. This allows to play audio over S/PDIF and I2S simultaneously. The root of the problem is that audio components on Tegra share the same audio PLL, and thus, only a subset of rates can be supported if we want to play audio simultaneously. Filter out audio rates that don't match parent clock rate if device-tree has the nvidia,fixed-parent-rate property. Signed-off-by: Dmitry Osipenko <[email protected]> Acked-by: Thierry Reding <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 9d8f51c commit bfa4671

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

sound/soc/tegra/tegra20_i2s.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,59 @@ static int tegra20_i2s_probe(struct snd_soc_dai *dai)
262262
return 0;
263263
}
264264

265+
static const unsigned int tegra20_i2s_rates[] = {
266+
8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000
267+
};
268+
269+
static int tegra20_i2s_filter_rates(struct snd_pcm_hw_params *params,
270+
struct snd_pcm_hw_rule *rule)
271+
{
272+
struct snd_interval *r = hw_param_interval(params, rule->var);
273+
struct snd_soc_dai *dai = rule->private;
274+
struct tegra20_i2s *i2s = dev_get_drvdata(dai->dev);
275+
struct clk *parent = clk_get_parent(i2s->clk_i2s);
276+
long i, parent_rate, valid_rates = 0;
277+
278+
parent_rate = clk_get_rate(parent);
279+
if (parent_rate <= 0) {
280+
dev_err(dai->dev, "Can't get parent clock rate: %ld\n",
281+
parent_rate);
282+
return parent_rate ?: -EINVAL;
283+
}
284+
285+
for (i = 0; i < ARRAY_SIZE(tegra20_i2s_rates); i++) {
286+
if (parent_rate % (tegra20_i2s_rates[i] * 128) == 0)
287+
valid_rates |= BIT(i);
288+
}
289+
290+
/*
291+
* At least one rate must be valid, otherwise the parent clock isn't
292+
* audio PLL. Nothing should be filtered in this case.
293+
*/
294+
if (!valid_rates)
295+
valid_rates = BIT(ARRAY_SIZE(tegra20_i2s_rates)) - 1;
296+
297+
return snd_interval_list(r, ARRAY_SIZE(tegra20_i2s_rates),
298+
tegra20_i2s_rates, valid_rates);
299+
}
300+
301+
static int tegra20_i2s_startup(struct snd_pcm_substream *substream,
302+
struct snd_soc_dai *dai)
303+
{
304+
if (!device_property_read_bool(dai->dev, "nvidia,fixed-parent-rate"))
305+
return 0;
306+
307+
return snd_pcm_hw_rule_add(substream->runtime, 0,
308+
SNDRV_PCM_HW_PARAM_RATE,
309+
tegra20_i2s_filter_rates, dai,
310+
SNDRV_PCM_HW_PARAM_RATE, -1);
311+
}
312+
265313
static const struct snd_soc_dai_ops tegra20_i2s_dai_ops = {
266314
.set_fmt = tegra20_i2s_set_fmt,
267315
.hw_params = tegra20_i2s_hw_params,
268316
.trigger = tegra20_i2s_trigger,
317+
.startup = tegra20_i2s_startup,
269318
};
270319

271320
static const struct snd_soc_dai_driver tegra20_i2s_dai_template = {

0 commit comments

Comments
 (0)