History

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.

Dmitry Osipenko committed 4 years ago

Commit bfa46711 parent 9d8f51c1 file · +49 −0Browse files

Unified · Split

sound/soc/tegra/tegra20_i2s.c+49−0
@@ -262,10 +262,59 @@ static int tegra20_i2s_probe(struct snd_soc_dai *dai) · 261 unmodified lines
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 = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t