greybus: gb-audio: Set I2S Configuration according to ASOC requests

Currently, the audio driver unconditionally sets the I2S
configuration to have a sample rate of 48KHz, two channels,
16 bits per channel, in little endian order.  Make this
more flexible by setting the I2S configuration according to
the arguments passed to the PCM 'hw_params' callback.

To accomplish this, query for the supported I2S configurations
at Greybus protocol init time and save them in the 'snd_dev'
structure.  When the 'hw_params' callback is called, compare its
arguments to the table of supported configurations.  If there is
a match, set the I2S connection accordingly.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Acked-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
diff --git a/drivers/staging/greybus/audio-pcm.c b/drivers/staging/greybus/audio-pcm.c
index 30030f8..b327008 100644
--- a/drivers/staging/greybus/audio-pcm.c
+++ b/drivers/staging/greybus/audio-pcm.c
@@ -220,6 +220,21 @@
 static int gb_pcm_hw_params(struct snd_pcm_substream *substream,
 				struct snd_pcm_hw_params *hw_params)
 {
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct gb_snd *snd_dev;
+	int rate, chans, bytes_per_chan, is_le, ret;
+
+	snd_dev = snd_soc_dai_get_drvdata(rtd->cpu_dai);
+
+	rate = params_rate(hw_params);
+	chans = params_channels(hw_params);
+	bytes_per_chan = snd_pcm_format_width(params_format(hw_params)) / 8;
+	is_le = snd_pcm_format_little_endian(params_format(hw_params));
+
+	ret = gb_i2s_mgmt_set_cfg(snd_dev, rate, chans, bytes_per_chan, is_le);
+	if (ret)
+		return ret;
+
 	return snd_pcm_lib_malloc_pages(substream,
 					params_buffer_bytes(hw_params));
 }