Commit d8018872 authored by Christian Gromm's avatar Christian Gromm Committed by Greg Kroah-Hartman

staging: most: make hardware parameters channel exclusive

Since the PCM interface's hardware parameters are channel/substream
exclusive, the struct snd_pcm_hardware needs to be embedded in the
channel structure.
Signed-off-by: default avatarChristian Gromm <christian.gromm@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9801345c
...@@ -46,6 +46,7 @@ static struct most_aim audio_aim; ...@@ -46,6 +46,7 @@ static struct most_aim audio_aim;
*/ */
struct channel { struct channel {
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
struct snd_pcm_hardware pcm_hardware;
struct most_interface *iface; struct most_interface *iface;
struct most_channel_config *cfg; struct most_channel_config *cfg;
struct snd_card *card; struct snd_card *card;
...@@ -70,13 +71,12 @@ struct channel { ...@@ -70,13 +71,12 @@ struct channel {
/** /**
* Initialization of struct snd_pcm_hardware * Initialization of struct snd_pcm_hardware
*/ */
static struct snd_pcm_hardware pcm_hardware_template = { static void init_pcm_hardware(struct snd_pcm_hardware *pcm_hw)
.info = MOST_PCM_INFO, {
.rates = SNDRV_PCM_RATE_48000, pcm_hw->info = MOST_PCM_INFO;
.rate_min = 48000, pcm_hw->rates = SNDRV_PCM_RATE_48000;
.rate_max = 48000, pcm_hw->rate_min = 48000;
.channels_min = 1, pcm_hw->rate_max = 48000;
.channels_max = 1,
}; };
#define swap16(val) ( \ #define swap16(val) ( \
...@@ -308,7 +308,7 @@ static int pcm_open(struct snd_pcm_substream *substream) ...@@ -308,7 +308,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
return -EBUSY; return -EBUSY;
} }
runtime->hw = pcm_hardware_template; runtime->hw = channel->pcm_hardware;
runtime->hw.buffer_bytes_max = cfg->num_buffers * cfg->buffer_size; runtime->hw.buffer_bytes_max = cfg->num_buffers * cfg->buffer_size;
runtime->hw.period_bytes_min = cfg->buffer_size; runtime->hw.period_bytes_min = cfg->buffer_size;
runtime->hw.period_bytes_max = cfg->buffer_size; runtime->hw.period_bytes_max = cfg->buffer_size;
...@@ -357,12 +357,13 @@ static int pcm_hw_params(struct snd_pcm_substream *substream, ...@@ -357,12 +357,13 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params) struct snd_pcm_hw_params *hw_params)
{ {
int ret; int ret;
struct channel *channel = substream->private_data;
pr_info("pcm_hw_params()\n"); pr_info("pcm_hw_params()\n");
if ((params_channels(hw_params) > pcm_hardware_template.channels_max) || if ((params_channels(hw_params) > channel->pcm_hardware.channels_max) ||
(params_channels(hw_params) < pcm_hardware_template.channels_min) || (params_channels(hw_params) < channel->pcm_hardware.channels_min) ||
!(params_format(hw_params) != pcm_hardware_template.formats)) !(params_format(hw_params) != channel->pcm_hardware.formats))
return -EINVAL; return -EINVAL;
ret = snd_pcm_lib_alloc_vmalloc_buffer(substream, ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params)); params_buffer_bytes(hw_params));
...@@ -508,45 +509,46 @@ static int split_arg_list(char *buf, char **card_name, char **pcm_format) ...@@ -508,45 +509,46 @@ static int split_arg_list(char *buf, char **card_name, char **pcm_format)
return 0; return 0;
} }
static int audio_set_pcm_format(char *pcm_format, static int audio_set_pcm_format(struct snd_pcm_hardware *pcm_hw,
char *pcm_format,
struct most_channel_config *cfg) struct most_channel_config *cfg)
{ {
if (!strcmp(pcm_format, "1x8")) { if (!strcmp(pcm_format, "1x8")) {
if (cfg->subbuffer_size != 1) if (cfg->subbuffer_size != 1)
goto error; goto error;
pr_info("PCM format is 8-bit mono\n"); pr_info("PCM format is 8-bit mono\n");
pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S8; pcm_hw->formats = SNDRV_PCM_FMTBIT_S8;
} else if (!strcmp(pcm_format, "2x16")) { } else if (!strcmp(pcm_format, "2x16")) {
if (cfg->subbuffer_size != 4) if (cfg->subbuffer_size != 4)
goto error; goto error;
pr_info("PCM format is 16-bit stereo\n"); pr_info("PCM format is 16-bit stereo\n");
pcm_hardware_template.channels_min = 2; pcm_hw->channels_min = 2;
pcm_hardware_template.channels_max = 2; pcm_hw->channels_max = 2;
pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S16_LE | pcm_hw->formats = SNDRV_PCM_FMTBIT_S16_LE |
SNDRV_PCM_FMTBIT_S16_BE; SNDRV_PCM_FMTBIT_S16_BE;
} else if (!strcmp(pcm_format, "2x24")) { } else if (!strcmp(pcm_format, "2x24")) {
if (cfg->subbuffer_size != 6) if (cfg->subbuffer_size != 6)
goto error; goto error;
pr_info("PCM format is 24-bit stereo\n"); pr_info("PCM format is 24-bit stereo\n");
pcm_hardware_template.channels_min = 2; pcm_hw->channels_min = 2;
pcm_hardware_template.channels_max = 2; pcm_hw->channels_max = 2;
pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S24_3LE | pcm_hw->formats = SNDRV_PCM_FMTBIT_S24_3LE |
SNDRV_PCM_FMTBIT_S24_3BE; SNDRV_PCM_FMTBIT_S24_3BE;
} else if (!strcmp(pcm_format, "2x32")) { } else if (!strcmp(pcm_format, "2x32")) {
if (cfg->subbuffer_size != 8) if (cfg->subbuffer_size != 8)
goto error; goto error;
pr_info("PCM format is 32-bit stereo\n"); pr_info("PCM format is 32-bit stereo\n");
pcm_hardware_template.channels_min = 2; pcm_hw->channels_min = 2;
pcm_hardware_template.channels_max = 2; pcm_hw->channels_max = 2;
pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S32_LE | pcm_hw->formats = SNDRV_PCM_FMTBIT_S32_LE |
SNDRV_PCM_FMTBIT_S32_BE; SNDRV_PCM_FMTBIT_S32_BE;
} else if (!strcmp(pcm_format, "6x16")) { } else if (!strcmp(pcm_format, "6x16")) {
if (cfg->subbuffer_size != 12) if (cfg->subbuffer_size != 12)
goto error; goto error;
pr_info("PCM format is 16-bit 5.1 multi channel\n"); pr_info("PCM format is 16-bit 5.1 multi channel\n");
pcm_hardware_template.channels_min = 6; pcm_hw->channels_min = 6;
pcm_hardware_template.channels_max = 6; pcm_hw->channels_max = 6;
pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S16_LE | pcm_hw->formats = SNDRV_PCM_FMTBIT_S16_LE |
SNDRV_PCM_FMTBIT_S16_BE; SNDRV_PCM_FMTBIT_S16_BE;
} else { } else {
pr_err("PCM format %s not supported\n", pcm_format); pr_err("PCM format %s not supported\n", pcm_format);
...@@ -614,8 +616,6 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id, ...@@ -614,8 +616,6 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
pr_info("PCM format missing\n"); pr_info("PCM format missing\n");
return ret; return ret;
} }
if (audio_set_pcm_format(pcm_format, cfg))
return ret;
ret = snd_card_new(NULL, -1, card_name, THIS_MODULE, ret = snd_card_new(NULL, -1, card_name, THIS_MODULE,
sizeof(*channel), &card); sizeof(*channel), &card);
...@@ -627,6 +627,10 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id, ...@@ -627,6 +627,10 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
channel->cfg = cfg; channel->cfg = cfg;
channel->iface = iface; channel->iface = iface;
channel->id = channel_id; channel->id = channel_id;
init_pcm_hardware(&channel->pcm_hardware);
if (audio_set_pcm_format(&channel->pcm_hardware, pcm_format, cfg))
goto err_free_card;
snprintf(card->driver, sizeof(card->driver), "%s", DRIVER_NAME); snprintf(card->driver, sizeof(card->driver), "%s", DRIVER_NAME);
snprintf(card->shortname, sizeof(card->shortname), "Microchip MOST:%d", snprintf(card->shortname, sizeof(card->shortname), "Microchip MOST:%d",
......
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