diff options
author | Wu Fengguang <fengguang.wu@intel.com> | 2009-10-30 06:38:26 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-10-30 06:38:26 -0400 |
commit | f5d6def5c642587434c42722c57fb65642f61038 (patch) | |
tree | 628136f71a4d4842605a727b2505d56bc4afc6c6 /sound/pci/hda/hda_codec.c | |
parent | 739b47f1e5aa3b36eadd7906cc6b41f0175c6ed1 (diff) |
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: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r-- | sound/pci/hda/hda_codec.c | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index af989f660cca..49289cd50697 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -2885,43 +2885,26 @@ static int get_empty_pcm_device(struct hda_bus *bus, int type) | |||
2885 | static const char *dev_name[HDA_PCM_NTYPES] = { | 2885 | static const char *dev_name[HDA_PCM_NTYPES] = { |
2886 | "Audio", "SPDIF", "HDMI", "Modem" | 2886 | "Audio", "SPDIF", "HDMI", "Modem" |
2887 | }; | 2887 | }; |
2888 | /* starting device index for each PCM type */ | 2888 | /* audio device indices; not linear to keep compatibility */ |
2889 | static int dev_idx[HDA_PCM_NTYPES] = { | 2889 | static int audio_idx[HDA_PCM_NTYPES][5] = { |
2890 | [HDA_PCM_TYPE_AUDIO] = 0, | 2890 | [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 }, |
2891 | [HDA_PCM_TYPE_SPDIF] = 1, | 2891 | [HDA_PCM_TYPE_SPDIF] = { 1, -1 }, |
2892 | [HDA_PCM_TYPE_HDMI] = 3, | 2892 | [HDA_PCM_TYPE_HDMI] = { 3, -1 }, |
2893 | [HDA_PCM_TYPE_MODEM] = 6 | 2893 | [HDA_PCM_TYPE_MODEM] = { 6, -1 }, |
2894 | }; | 2894 | }; |
2895 | /* normal audio device indices; not linear to keep compatibility */ | 2895 | int i; |
2896 | static int audio_idx[4] = { 0, 2, 4, 5 }; | 2896 | |
2897 | int i, dev; | 2897 | if (type >= HDA_PCM_NTYPES) { |
2898 | |||
2899 | switch (type) { | ||
2900 | case HDA_PCM_TYPE_AUDIO: | ||
2901 | for (i = 0; i < ARRAY_SIZE(audio_idx); i++) { | ||
2902 | dev = audio_idx[i]; | ||
2903 | if (!test_bit(dev, bus->pcm_dev_bits)) | ||
2904 | goto ok; | ||
2905 | } | ||
2906 | snd_printk(KERN_WARNING "Too many audio devices\n"); | ||
2907 | return -EAGAIN; | ||
2908 | case HDA_PCM_TYPE_SPDIF: | ||
2909 | case HDA_PCM_TYPE_HDMI: | ||
2910 | case HDA_PCM_TYPE_MODEM: | ||
2911 | dev = dev_idx[type]; | ||
2912 | if (test_bit(dev, bus->pcm_dev_bits)) { | ||
2913 | snd_printk(KERN_WARNING "%s already defined\n", | ||
2914 | dev_name[type]); | ||
2915 | return -EAGAIN; | ||
2916 | } | ||
2917 | break; | ||
2918 | default: | ||
2919 | snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); | 2898 | snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); |
2920 | return -EINVAL; | 2899 | return -EINVAL; |
2921 | } | 2900 | } |
2922 | ok: | 2901 | |
2923 | set_bit(dev, bus->pcm_dev_bits); | 2902 | for (i = 0; audio_idx[type][i] >= 0 ; i++) |
2924 | return dev; | 2903 | if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits)) |
2904 | return audio_idx[type][i]; | ||
2905 | |||
2906 | snd_printk(KERN_WARNING "Too many %s devices\n", dev_name[type]); | ||
2907 | return -EAGAIN; | ||
2925 | } | 2908 | } |
2926 | 2909 | ||
2927 | /* | 2910 | /* |