Commit cd54fb96 authored by Thierry Reding's avatar Thierry Reding

drm/tegra: sor: Parse more data from HDA format

The HDA format data passed to the SOR from the HDA codec contains more
information than just the rate and number of channels. Parse all the
fields and store them in an internal structure for subsequent use.

While at it, also fix an off-by-one error in the number of channels.
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
parent f25d0a68
...@@ -393,6 +393,13 @@ struct tegra_sor_ops { ...@@ -393,6 +393,13 @@ struct tegra_sor_ops {
int (*remove)(struct tegra_sor *sor); int (*remove)(struct tegra_sor *sor);
}; };
struct tegra_sor_audio {
unsigned int sample_rate;
unsigned int channels;
unsigned int bits;
bool pcm;
};
struct tegra_sor { struct tegra_sor {
struct host1x_client client; struct host1x_client client;
struct tegra_output output; struct tegra_output output;
...@@ -429,10 +436,7 @@ struct tegra_sor { ...@@ -429,10 +436,7 @@ struct tegra_sor {
struct delayed_work scdc; struct delayed_work scdc;
bool scdc_enabled; bool scdc_enabled;
struct { struct tegra_sor_audio audio;
unsigned int sample_rate;
unsigned int channels;
} audio;
}; };
struct tegra_sor_state { struct tegra_sor_state {
...@@ -3195,22 +3199,58 @@ static int tegra_sor_parse_dt(struct tegra_sor *sor) ...@@ -3195,22 +3199,58 @@ static int tegra_sor_parse_dt(struct tegra_sor *sor)
return 0; return 0;
} }
static void tegra_hda_parse_format(unsigned int format, unsigned int *rate, static void tegra_hda_parse_format(unsigned int format,
unsigned int *channels) struct tegra_sor_audio *audio)
{ {
unsigned int mul, div; unsigned int mul, div, bits, channels;
if (format & AC_FMT_TYPE_NON_PCM)
audio->pcm = false;
else
audio->pcm = true;
if (format & AC_FMT_BASE_44K) if (format & AC_FMT_BASE_44K)
*rate = 44100; audio->sample_rate = 44100;
else else
*rate = 48000; audio->sample_rate = 48000;
mul = (format & AC_FMT_MULT_MASK) >> AC_FMT_MULT_SHIFT; mul = (format & AC_FMT_MULT_MASK) >> AC_FMT_MULT_SHIFT;
div = (format & AC_FMT_DIV_MASK) >> AC_FMT_DIV_SHIFT; div = (format & AC_FMT_DIV_MASK) >> AC_FMT_DIV_SHIFT;
*rate = *rate * (mul + 1) / (div + 1); audio->sample_rate = audio->sample_rate * (mul + 1) / (div + 1);
switch (format & AC_FMT_BITS_MASK) {
case AC_FMT_BITS_8:
audio->bits = 8;
break;
case AC_FMT_BITS_16:
audio->bits = 16;
break;
case AC_FMT_BITS_20:
audio->bits = 20;
break;
case AC_FMT_BITS_24:
audio->bits = 24;
break;
case AC_FMT_BITS_32:
audio->bits = 32;
break;
default:
bits = (format & AC_FMT_BITS_MASK) >> AC_FMT_BITS_SHIFT;
WARN(1, "invalid number of bits: %#x\n", bits);
audio->bits = 8;
break;
}
channels = (format & AC_FMT_CHAN_MASK) >> AC_FMT_CHAN_SHIFT;
*channels = (format & AC_FMT_CHAN_MASK) >> AC_FMT_CHAN_SHIFT; /* channels are encoded as n - 1 */
audio->channels = channels + 1;
} }
static irqreturn_t tegra_sor_irq(int irq, void *data) static irqreturn_t tegra_sor_irq(int irq, void *data)
...@@ -3225,14 +3265,11 @@ static irqreturn_t tegra_sor_irq(int irq, void *data) ...@@ -3225,14 +3265,11 @@ static irqreturn_t tegra_sor_irq(int irq, void *data)
value = tegra_sor_readl(sor, SOR_AUDIO_HDA_CODEC_SCRATCH0); value = tegra_sor_readl(sor, SOR_AUDIO_HDA_CODEC_SCRATCH0);
if (value & SOR_AUDIO_HDA_CODEC_SCRATCH0_VALID) { if (value & SOR_AUDIO_HDA_CODEC_SCRATCH0_VALID) {
unsigned int format, sample_rate, channels; unsigned int format;
format = value & SOR_AUDIO_HDA_CODEC_SCRATCH0_FMT_MASK; format = value & SOR_AUDIO_HDA_CODEC_SCRATCH0_FMT_MASK;
tegra_hda_parse_format(format, &sample_rate, &channels); tegra_hda_parse_format(format, &sor->audio);
sor->audio.sample_rate = sample_rate;
sor->audio.channels = channels;
tegra_sor_hdmi_audio_enable(sor); tegra_sor_hdmi_audio_enable(sor);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment