From 8e4a0ef17fc8bf4503fb77f059d580a03e67b5f1 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Mon, 28 Sep 2015 17:18:47 +0200 Subject: [PATCH] staging: most: add multi channel support to sound AIM This patch adds 5.1 surround configuration with subbuffer cross-check, when establishing a link to the core. For the sake of simplicity, only one specific channel configuration is allowed. Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/aim-sound/sound.c | 27 ++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c index 0d7425b19f1e..88221f030325 100644 --- a/drivers/staging/most/aim-sound/sound.c +++ b/drivers/staging/most/aim-sound/sound.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -75,7 +76,7 @@ static struct snd_pcm_hardware pcm_hardware_template = { .rate_min = 48000, .rate_max = 48000, .channels_min = 1, - .channels_max = 8, + .channels_max = 1, }; #define swap16(val) ( \ @@ -355,10 +356,18 @@ static int pcm_close(struct snd_pcm_substream *substream) static int pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { + int ret; + pr_info("pcm_hw_params()\n"); - return snd_pcm_lib_alloc_vmalloc_buffer(substream, + if ((params_channels(hw_params) > pcm_hardware_template.channels_max) || + (params_channels(hw_params) < pcm_hardware_template.channels_min) || + !(params_format(hw_params) != pcm_hardware_template.formats)) + return -EINVAL; + ret = snd_pcm_lib_alloc_vmalloc_buffer(substream, params_buffer_bytes(hw_params)); + + return ret; } /** @@ -511,20 +520,34 @@ static int audio_set_pcm_format(char *pcm_format, if (cfg->subbuffer_size != 4) goto error; pr_info("PCM format is 16-bit stereo\n"); + pcm_hardware_template.channels_min = 2; + pcm_hardware_template.channels_max = 2; pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE; } else if (!strcmp(pcm_format, "2x24")) { if (cfg->subbuffer_size != 6) goto error; pr_info("PCM format is 24-bit stereo\n"); + pcm_hardware_template.channels_min = 2; + pcm_hardware_template.channels_max = 2; pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE; } else if (!strcmp(pcm_format, "2x32")) { if (cfg->subbuffer_size != 8) goto error; pr_info("PCM format is 32-bit stereo\n"); + pcm_hardware_template.channels_min = 2; + pcm_hardware_template.channels_max = 2; pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE; + } else if (!strcmp(pcm_format, "6x16")) { + if (cfg->subbuffer_size != 12) + goto error; + pr_info("PCM format is 16-bit 5.1 multi channel\n"); + pcm_hardware_template.channels_min = 6; + pcm_hardware_template.channels_max = 6; + pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S16_BE; } else { pr_err("PCM format %s not supported\n", pcm_format); return -EIO; -- 2.30.2