]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[ALSA] hda-intel - Fix PCM device number assignment
authorTakashi Iwai <tiwai@suse.de>
Wed, 6 Feb 2008 13:03:20 +0000 (14:03 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 24 Apr 2008 10:00:07 +0000 (12:00 +0200)
In the current scheme, PCM device numbers are assigned incrementally
in the order of codecs.  This causes problems when the codec number
is irregular, e.g. codec #0 for HDMI and codec #1 for analog.  Then
the HDMI becomes the first PCM, which is picked up as the default
output device.  Unfortuantely this doesn't work well with normal
setups.

This patch introduced the fixed device numbers for the PCM types,
namely, analog, SPDIF, HDMI and modem.  The PCM devices are assigned
according to the corresponding PCM type.  After this patch, HDMI will
be always assigned to PCM #3, SPDIF to PCM #1, and the first analog
to PCM #0, etc.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_codec.h
sound/pci/hda/hda_intel.c
sound/pci/hda/patch_analog.c
sound/pci/hda/patch_atihdmi.c
sound/pci/hda/patch_cmedia.c
sound/pci/hda/patch_conexant.c
sound/pci/hda/patch_realtek.c
sound/pci/hda/patch_si3054.c
sound/pci/hda/patch_sigmatel.c
sound/pci/hda/patch_via.c

index f14871151be983a307330ec9c61009895a22f944..301b5227bfb134272c5664b809bebb0b6bfa9c86 100644 (file)
@@ -590,11 +590,21 @@ struct hda_pcm_stream {
        struct hda_pcm_ops ops;
 };
 
+/* PCM types */
+enum {
+       HDA_PCM_TYPE_AUDIO,
+       HDA_PCM_TYPE_SPDIF,
+       HDA_PCM_TYPE_HDMI,
+       HDA_PCM_TYPE_MODEM,
+       HDA_PCM_NTYPES
+};
+
 /* for PCM creation */
 struct hda_pcm {
        char *name;
        struct hda_pcm_stream stream[2];
-       unsigned int is_modem;  /* modem codec? */
+       unsigned int pcm_type;  /* HDA_PCM_TYPE_XXX */
+       int device;     /* assigned device number */
 };
 
 /* codec information */
index 4be36c84b36c7c8354a707d9956430602de45e73..18475de074b27e15405baf703b119bf9be386c36 100644 (file)
@@ -211,9 +211,7 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
 /* max buffer size - no h/w limit, you can increase as you like */
 #define AZX_MAX_BUF_SIZE       (1024*1024*1024)
 /* max number of PCM devics per card */
-#define AZX_MAX_AUDIO_PCMS     6
-#define AZX_MAX_MODEM_PCMS     2
-#define AZX_MAX_PCMS           (AZX_MAX_AUDIO_PCMS + AZX_MAX_MODEM_PCMS)
+#define AZX_MAX_PCMS           8
 
 /* RIRB int mask: overrun[2], response[0] */
 #define RIRB_INT_RESPONSE      0x01
@@ -350,7 +348,6 @@ struct azx {
        struct azx_dev *azx_dev;
 
        /* PCM */
-       unsigned int pcm_devs;
        struct snd_pcm *pcm[AZX_MAX_PCMS];
 
        /* HD codec */
@@ -1386,7 +1383,7 @@ static void azx_pcm_free(struct snd_pcm *pcm)
 }
 
 static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
-                                     struct hda_pcm *cpcm, int pcm_dev)
+                                     struct hda_pcm *cpcm)
 {
        int err;
        struct snd_pcm *pcm;
@@ -1400,7 +1397,7 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
 
        snd_assert(cpcm->name, return -EINVAL);
 
-       err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
+       err = snd_pcm_new(chip->card, cpcm->name, cpcm->device,
                          cpcm->stream[0].substreams,
                          cpcm->stream[1].substreams,
                          &pcm);
@@ -1423,59 +1420,67 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
                                              snd_dma_pci_data(chip->pci),
                                              1024 * 64, 1024 * 1024);
-       chip->pcm[pcm_dev] = pcm;
-       if (chip->pcm_devs < pcm_dev + 1)
-               chip->pcm_devs = pcm_dev + 1;
-
+       chip->pcm[cpcm->device] = pcm;
        return 0;
 }
 
 static int __devinit azx_pcm_create(struct azx *chip)
 {
+       static const char *dev_name[HDA_PCM_NTYPES] = {
+               "Audio", "SPDIF", "HDMI", "Modem"
+       };
+       /* starting device index for each PCM type */
+       static int dev_idx[HDA_PCM_NTYPES] = {
+               [HDA_PCM_TYPE_AUDIO] = 0,
+               [HDA_PCM_TYPE_SPDIF] = 1,
+               [HDA_PCM_TYPE_HDMI] = 3,
+               [HDA_PCM_TYPE_MODEM] = 6
+       };
+       /* normal audio device indices; not linear to keep compatibility */
+       static int audio_idx[4] = { 0, 2, 4, 5 };
        struct hda_codec *codec;
        int c, err;
-       int pcm_dev;
+       int num_devs[HDA_PCM_NTYPES];
 
        err = snd_hda_build_pcms(chip->bus);
        if (err < 0)
                return err;
 
        /* create audio PCMs */
-       pcm_dev = 0;
-       list_for_each_entry(codec, &chip->bus->codec_list, list) {
-               for (c = 0; c < codec->num_pcms; c++) {
-                       if (codec->pcm_info[c].is_modem)
-                               continue; /* create later */
-                       if (pcm_dev >= AZX_MAX_AUDIO_PCMS) {
-                               snd_printk(KERN_ERR SFX
-                                          "Too many audio PCMs\n");
-                               return -EINVAL;
-                       }
-                       err = create_codec_pcm(chip, codec,
-                                              &codec->pcm_info[c], pcm_dev);
-                       if (err < 0)
-                               return err;
-                       pcm_dev++;
-               }
-       }
-
-       /* create modem PCMs */
-       pcm_dev = AZX_MAX_AUDIO_PCMS;
+       memset(num_devs, 0, sizeof(num_devs));
        list_for_each_entry(codec, &chip->bus->codec_list, list) {
                for (c = 0; c < codec->num_pcms; c++) {
-                       if (!codec->pcm_info[c].is_modem)
-                               continue; /* already created */
-                       if (pcm_dev >= AZX_MAX_PCMS) {
-                               snd_printk(KERN_ERR SFX
-                                          "Too many modem PCMs\n");
-                               return -EINVAL;
+                       struct hda_pcm *cpcm = &codec->pcm_info[c];
+                       int type = cpcm->pcm_type;
+                       switch (type) {
+                       case HDA_PCM_TYPE_AUDIO:
+                               if (num_devs[type] >= ARRAY_SIZE(audio_idx)) {
+                                       snd_printk(KERN_WARNING
+                                                  "Too many audio devices\n");
+                                       continue;
+                               }
+                               cpcm->device = audio_idx[num_devs[type]];
+                               break;
+                       case HDA_PCM_TYPE_SPDIF:
+                       case HDA_PCM_TYPE_HDMI:
+                       case HDA_PCM_TYPE_MODEM:
+                               if (num_devs[type]) {
+                                       snd_printk(KERN_WARNING
+                                                  "%s already defined\n",
+                                                  dev_name[type]);
+                                       continue;
+                               }
+                               cpcm->device = dev_idx[type];
+                               break;
+                       default:
+                               snd_printk(KERN_WARNING
+                                          "Invalid PCM type %d\n", type);
+                               continue;
                        }
-                       err = create_codec_pcm(chip, codec,
-                                              &codec->pcm_info[c], pcm_dev);
+                       num_devs[type]++;
+                       err = create_codec_pcm(chip, codec, cpcm);
                        if (err < 0)
                                return err;
-                       chip->pcm[pcm_dev]->dev_class = SNDRV_PCM_CLASS_MODEM;
-                       pcm_dev++;
                }
        }
        return 0;
@@ -1587,7 +1592,7 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
        int i;
 
        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       for (i = 0; i < chip->pcm_devs; i++)
+       for (i = 0; i < AZX_MAX_PCMS; i++)
                snd_pcm_suspend_all(chip->pcm[i]);
        if (chip->initialized)
                snd_hda_suspend(chip->bus, state);
index c8649282c2cfec54b191468f52b98bc18b82e385..7286ab86ecc4bbdb34ea82ee95027e58168f8e24 100644 (file)
@@ -359,6 +359,7 @@ static int ad198x_build_pcms(struct hda_codec *codec)
                info++;
                codec->num_pcms++;
                info->name = "AD198x Digital";
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
                info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
                if (spec->dig_in_nid) {
index 27d2e007404b3bc3eba0a66af35d564fd4fe15c5..e0e9ea99568458927b276aa5a33f193bd784426e 100644 (file)
@@ -116,6 +116,7 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
        codec->pcm_info = info;
 
        info->name = "ATI HDMI";
+       info->pcm_type = HDA_PCM_TYPE_HDMI;
        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
 
        return 0;
index 3d6097ba1d68fb98f851fe1668effd6fe1d0a4ba..99ce74b4e9fc8ddb321cdaeee5b8f7eeac12e2d1 100644 (file)
@@ -571,6 +571,7 @@ static int cmi9880_build_pcms(struct hda_codec *codec)
                codec->num_pcms++;
                info++;
                info->name = "CMI9880 Digital";
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                if (spec->multiout.dig_out_nid) {
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
index 7206b30cbf9454c30e19f0c2c49e9dbe9684df2f..bb915ede0ceb1671917a7a742de12b70b8da6ff7 100644 (file)
@@ -284,6 +284,7 @@ static int conexant_build_pcms(struct hda_codec *codec)
                info++;
                codec->num_pcms++;
                info->name = "Conexant Digital";
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
                        conexant_pcm_digital_playback;
                info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
index 45e661e42c0bd121f65e54079c56fa71fbf3ddd2..85ea3f82de1925e217d67ce967f8e277843467ef 100644 (file)
@@ -2499,6 +2499,7 @@ static int alc_build_pcms(struct hda_codec *codec)
                codec->num_pcms = 2;
                info = spec->pcm_rec + 1;
                info->name = spec->stream_name_digital;
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                if (spec->multiout.dig_out_nid &&
                    spec->stream_digital_playback) {
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
index d22f5a6b850f2b82d3f39060a57a13bb769a3d6e..598ee2119bbe2994f42c01345331478998fce470 100644 (file)
@@ -206,7 +206,7 @@ static int si3054_build_pcms(struct hda_codec *codec)
        info->name = "Si3054 Modem";
        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
        info->stream[SNDRV_PCM_STREAM_CAPTURE]  = si3054_pcm;
-       info->is_modem = 1;
+       info->pcm_type = HDA_PCM_TYPE_MODEM;
        return 0;
 }
 
index 4c3c4e6ce3d67c74d22c5bc4f9579f85465ff849..f693011d25a00265c791aa0d823b7984ba3cc5ef 100644 (file)
@@ -1899,6 +1899,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
                codec->num_pcms++;
                info++;
                info->name = "STAC92xx Digital";
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                if (spec->multiout.dig_out_nid) {
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
index 4e5dd4cf36f5f6404852e9ef70a0fc7110fc5730..d9a5c6a2dd9f1288152e9cf2cb684ebf78bd445e 100644 (file)
@@ -523,6 +523,7 @@ static int via_build_pcms(struct hda_codec *codec)
                codec->num_pcms++;
                info++;
                info->name = spec->stream_name_digital;
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                if (spec->multiout.dig_out_nid) {
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
                                *(spec->stream_digital_playback);