Commit f5d6def5 authored by Wu Fengguang's avatar Wu Fengguang Committed by Takashi Iwai

ALSA: hda - vectorize get_empty_pcm_device()

This unifies the code and data structure,
and makes it easy to add more HDMI devices.
Signed-off-by: default avatarWu Fengguang <fengguang.wu@intel.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 739b47f1
...@@ -2885,43 +2885,26 @@ static int get_empty_pcm_device(struct hda_bus *bus, int type) ...@@ -2885,43 +2885,26 @@ static int get_empty_pcm_device(struct hda_bus *bus, int type)
static const char *dev_name[HDA_PCM_NTYPES] = { static const char *dev_name[HDA_PCM_NTYPES] = {
"Audio", "SPDIF", "HDMI", "Modem" "Audio", "SPDIF", "HDMI", "Modem"
}; };
/* starting device index for each PCM type */ /* audio device indices; not linear to keep compatibility */
static int dev_idx[HDA_PCM_NTYPES] = { static int audio_idx[HDA_PCM_NTYPES][5] = {
[HDA_PCM_TYPE_AUDIO] = 0, [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
[HDA_PCM_TYPE_SPDIF] = 1, [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
[HDA_PCM_TYPE_HDMI] = 3, [HDA_PCM_TYPE_HDMI] = { 3, -1 },
[HDA_PCM_TYPE_MODEM] = 6 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
}; };
/* normal audio device indices; not linear to keep compatibility */ int i;
static int audio_idx[4] = { 0, 2, 4, 5 };
int i, dev; if (type >= HDA_PCM_NTYPES) {
switch (type) {
case HDA_PCM_TYPE_AUDIO:
for (i = 0; i < ARRAY_SIZE(audio_idx); i++) {
dev = audio_idx[i];
if (!test_bit(dev, bus->pcm_dev_bits))
goto ok;
}
snd_printk(KERN_WARNING "Too many audio devices\n");
return -EAGAIN;
case HDA_PCM_TYPE_SPDIF:
case HDA_PCM_TYPE_HDMI:
case HDA_PCM_TYPE_MODEM:
dev = dev_idx[type];
if (test_bit(dev, bus->pcm_dev_bits)) {
snd_printk(KERN_WARNING "%s already defined\n",
dev_name[type]);
return -EAGAIN;
}
break;
default:
snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
return -EINVAL; return -EINVAL;
} }
ok:
set_bit(dev, bus->pcm_dev_bits); for (i = 0; audio_idx[type][i] >= 0 ; i++)
return dev; if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
return audio_idx[type][i];
snd_printk(KERN_WARNING "Too many %s devices\n", dev_name[type]);
return -EAGAIN;
} }
/* /*
......
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