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.
Unified · Split
| @@ -262,10 +262,59 @@ static int tegra20_i2s_probe(struct snd_soc_dai *dai) · 261 unmodified lines | |||
| 262 | return 0; | 262 | return 0; |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 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 | |||
| 265 | static const struct snd_soc_dai_ops tegra20_i2s_dai_ops = { | 313 | static const struct snd_soc_dai_ops tegra20_i2s_dai_ops = { |
| 266 | .set_fmt = tegra20_i2s_set_fmt, | 314 | .set_fmt = tegra20_i2s_set_fmt, |
| 267 | .hw_params = tegra20_i2s_hw_params, | 315 | .hw_params = tegra20_i2s_hw_params, |
| 268 | .trigger = tegra20_i2s_trigger, | 316 | .trigger = tegra20_i2s_trigger, |
| 317 | .startup = tegra20_i2s_startup, | ||
| 269 | }; | 318 | }; |
| 270 | 319 | ||
| 271 | static const struct snd_soc_dai_driver tegra20_i2s_dai_template = { | 320 | static const struct snd_soc_dai_driver tegra20_i2s_dai_template = { |