Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ba72ba1 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

[ALSA] hda-intel - Fix PCM device number assignment



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: default avatarTakashi Iwai <tiwai@suse.de>
parent 6c4cc3a8
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -590,11 +590,21 @@ struct hda_pcm_stream {
	struct hda_pcm_ops ops;
	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 */
/* for PCM creation */
struct hda_pcm {
struct hda_pcm {
	char *name;
	char *name;
	struct hda_pcm_stream stream[2];
	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 */
/* codec information */
+47 −42
Original line number Original line Diff line number Diff line
@@ -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 */
/* max buffer size - no h/w limit, you can increase as you like */
#define AZX_MAX_BUF_SIZE	(1024*1024*1024)
#define AZX_MAX_BUF_SIZE	(1024*1024*1024)
/* max number of PCM devics per card */
/* max number of PCM devics per card */
#define AZX_MAX_AUDIO_PCMS	6
#define AZX_MAX_PCMS		8
#define AZX_MAX_MODEM_PCMS	2
#define AZX_MAX_PCMS		(AZX_MAX_AUDIO_PCMS + AZX_MAX_MODEM_PCMS)


/* RIRB int mask: overrun[2], response[0] */
/* RIRB int mask: overrun[2], response[0] */
#define RIRB_INT_RESPONSE	0x01
#define RIRB_INT_RESPONSE	0x01
@@ -350,7 +348,6 @@ struct azx {
	struct azx_dev *azx_dev;
	struct azx_dev *azx_dev;


	/* PCM */
	/* PCM */
	unsigned int pcm_devs;
	struct snd_pcm *pcm[AZX_MAX_PCMS];
	struct snd_pcm *pcm[AZX_MAX_PCMS];


	/* HD codec */
	/* 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,
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;
	int err;
	struct snd_pcm *pcm;
	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);
	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[0].substreams,
			  cpcm->stream[1].substreams,
			  cpcm->stream[1].substreams,
			  &pcm);
			  &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_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
					      snd_dma_pci_data(chip->pci),
					      snd_dma_pci_data(chip->pci),
					      1024 * 64, 1024 * 1024);
					      1024 * 64, 1024 * 1024);
	chip->pcm[pcm_dev] = pcm;
	chip->pcm[cpcm->device] = pcm;
	if (chip->pcm_devs < pcm_dev + 1)
		chip->pcm_devs = pcm_dev + 1;

	return 0;
	return 0;
}
}


static int __devinit azx_pcm_create(struct azx *chip)
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;
	struct hda_codec *codec;
	int c, err;
	int c, err;
	int pcm_dev;
	int num_devs[HDA_PCM_NTYPES];


	err = snd_hda_build_pcms(chip->bus);
	err = snd_hda_build_pcms(chip->bus);
	if (err < 0)
	if (err < 0)
		return err;
		return err;


	/* create audio PCMs */
	/* create audio PCMs */
	pcm_dev = 0;
	memset(num_devs, 0, sizeof(num_devs));
	list_for_each_entry(codec, &chip->bus->codec_list, list) {
	list_for_each_entry(codec, &chip->bus->codec_list, list) {
		for (c = 0; c < codec->num_pcms; c++) {
		for (c = 0; c < codec->num_pcms; c++) {
			if (codec->pcm_info[c].is_modem)
			struct hda_pcm *cpcm = &codec->pcm_info[c];
				continue; /* create later */
			int type = cpcm->pcm_type;
			if (pcm_dev >= AZX_MAX_AUDIO_PCMS) {
			switch (type) {
				snd_printk(KERN_ERR SFX
			case HDA_PCM_TYPE_AUDIO:
					   "Too many audio PCMs\n");
				if (num_devs[type] >= ARRAY_SIZE(audio_idx)) {
				return -EINVAL;
					snd_printk(KERN_WARNING
			}
						   "Too many audio devices\n");
			err = create_codec_pcm(chip, codec,
					continue;
					       &codec->pcm_info[c], pcm_dev);
			if (err < 0)
				return err;
			pcm_dev++;
				}
				}
				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];
	/* create modem PCMs */
				break;
	pcm_dev = AZX_MAX_AUDIO_PCMS;
			default:
	list_for_each_entry(codec, &chip->bus->codec_list, list) {
				snd_printk(KERN_WARNING
		for (c = 0; c < codec->num_pcms; c++) {
					   "Invalid PCM type %d\n", type);
			if (!codec->pcm_info[c].is_modem)
				continue;
				continue; /* already created */
			if (pcm_dev >= AZX_MAX_PCMS) {
				snd_printk(KERN_ERR SFX
					   "Too many modem PCMs\n");
				return -EINVAL;
			}
			}
			err = create_codec_pcm(chip, codec,
			num_devs[type]++;
					       &codec->pcm_info[c], pcm_dev);
			err = create_codec_pcm(chip, codec, cpcm);
			if (err < 0)
			if (err < 0)
				return err;
				return err;
			chip->pcm[pcm_dev]->dev_class = SNDRV_PCM_CLASS_MODEM;
			pcm_dev++;
		}
		}
	}
	}
	return 0;
	return 0;
@@ -1587,7 +1592,7 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
	int i;
	int i;


	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
	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]);
		snd_pcm_suspend_all(chip->pcm[i]);
	if (chip->initialized)
	if (chip->initialized)
		snd_hda_suspend(chip->bus, state);
		snd_hda_suspend(chip->bus, state);
+1 −0
Original line number Original line Diff line number Diff line
@@ -359,6 +359,7 @@ static int ad198x_build_pcms(struct hda_codec *codec)
		info++;
		info++;
		codec->num_pcms++;
		codec->num_pcms++;
		info->name = "AD198x Digital";
		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] = ad198x_pcm_digital_playback;
		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
		if (spec->dig_in_nid) {
		if (spec->dig_in_nid) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -116,6 +116,7 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
	codec->pcm_info = info;
	codec->pcm_info = info;


	info->name = "ATI HDMI";
	info->name = "ATI HDMI";
	info->pcm_type = HDA_PCM_TYPE_HDMI;
	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;


	return 0;
	return 0;
+1 −0
Original line number Original line Diff line number Diff line
@@ -571,6 +571,7 @@ static int cmi9880_build_pcms(struct hda_codec *codec)
		codec->num_pcms++;
		codec->num_pcms++;
		info++;
		info++;
		info->name = "CMI9880 Digital";
		info->name = "CMI9880 Digital";
		info->pcm_type = HDA_PCM_TYPE_SPDIF;
		if (spec->multiout.dig_out_nid) {
		if (spec->multiout.dig_out_nid) {
			info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
			info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
			info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Loading