ALSA: hda: Add api to program stripe control bits
authorSameer Pujar <spujar@nvidia.com>
Mon, 14 Jan 2019 18:21:09 +0000 (23:51 +0530)
committerTakashi Iwai <tiwai@suse.de>
Mon, 14 Jan 2019 18:52:25 +0000 (19:52 +0100)
Controllers and codecs can support striping of audio out across
multiple SDO lines. The number of supported SDO lines can be
specific to chip. GCAP register can be read to know the maximum
supported SDO lines.

snd_hdac_get_stream_stripe_ctl() is exposed to program stripe bits
on controller and codec side.
stripe value: 0 for 1SDO, 1 for 2SDO, 2 for 4SDO lines, etc.,

Signed-off-by: Sameer Pujar <spujar@nvidia.com>
Reviewed-by: Mohan Kumar D <mkumard@nvidia.com>
Reviewed-by: Ravindra Lokhande <rlokhande@nvidia.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/hdaudio.h
sound/hda/hdac_stream.c

index b4fa1c7752510b5216a92f6d663d4fc0d1da3b39..45f944d57982800cc176ed782aedbf9b1d30f1fe 100644 (file)
@@ -539,6 +539,9 @@ void snd_hdac_stream_sync(struct hdac_stream *azx_dev, bool start,
                          unsigned int streams);
 void snd_hdac_stream_timecounter_init(struct hdac_stream *azx_dev,
                                      unsigned int streams);
+int snd_hdac_get_stream_stripe_ctl(struct hdac_bus *bus,
+                               struct snd_pcm_substream *substream);
+
 /*
  * macros for easy use
  */
index ba73a33480b66fb420b749feeb5131c7d44e3861..820694a2061e951f819d42a85251f882f770ad78 100644 (file)
 #include <sound/hda_register.h>
 #include "trace.h"
 
+/**
+ * snd_hdac_get_stream_stripe_ctl - get stripe control value
+ * @bus: HD-audio core bus
+ * @substream: PCM substream
+ */
+int snd_hdac_get_stream_stripe_ctl(struct hdac_bus *bus,
+                                  struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       unsigned int channels = runtime->channels,
+                    rate = runtime->rate,
+                    bits_per_sample = runtime->sample_bits,
+                    max_sdo_lines, value, sdo_line;
+
+       /* T_AZA_GCAP_NSDO is 1:2 bitfields in GCAP */
+       max_sdo_lines = snd_hdac_chip_readl(bus, GCAP) & AZX_GCAP_NSDO;
+
+       /* following is from HD audio spec */
+       for (sdo_line = max_sdo_lines; sdo_line > 0; sdo_line >>= 1) {
+               if (rate > 48000)
+                       value = (channels * bits_per_sample *
+                                       (rate / 48000)) / sdo_line;
+               else
+                       value = (channels * bits_per_sample) / sdo_line;
+
+               if (value >= 8)
+                       break;
+       }
+
+       /* stripe value: 0 for 1SDO, 1 for 2SDO, 2 for 4SDO lines */
+       return sdo_line >> 1;
+}
+EXPORT_SYMBOL_GPL(snd_hdac_get_stream_stripe_ctl);
+
 /**
  * snd_hdac_stream_init - initialize each stream (aka device)
  * @bus: HD-audio core bus