⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac97_pcm.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
				slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE);			if (ac97->ext_id & AC97_EI_SPDIF) {				if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC))					*spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1);				else					*spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2);			}			*rate_table = 1;			break;		case 3:			slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE);			if (ac97->ext_id & AC97_EI_SPDIF)				*spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2);			*rate_table = 2;			break;		}		return slots;	} else {		unsigned short slots;		slots = (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT);		if (ac97->scaps & AC97_SCAP_SURROUND_DAC)			slots |= (1<<AC97_SLOT_PCM_SLEFT)|(1<<AC97_SLOT_PCM_SRIGHT);		if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)			slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE);		if (ac97->ext_id & AC97_EI_SPDIF) {			if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC))				*spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT)|(1<<AC97_SLOT_SPDIF_RIGHT);			else if (!(ac97->scaps & AC97_SCAP_CENTER_LFE_DAC))				*spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1);			else				*spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2);		}		*rate_table = 0;		return slots;	}}static unsigned short get_cslots(ac97_t *ac97){	unsigned short slots;	if (!ac97_is_audio(ac97))		return 0;	slots = (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT);	slots |= (1<<AC97_SLOT_MIC);	return slots;}static unsigned int get_rates(struct ac97_pcm *pcm, unsigned int cidx, unsigned short slots, int dbl){	int i, idx;	unsigned int rates = ~0;	unsigned char reg;	for (i = 3; i < 12; i++) {		if (!(slots & (1 << i)))			continue;		reg = get_slot_reg(pcm, cidx, i, dbl);		switch (reg) {		case AC97_PCM_FRONT_DAC_RATE:	idx = AC97_RATES_FRONT_DAC; break;		case AC97_PCM_SURR_DAC_RATE:	idx = AC97_RATES_SURR_DAC; break;		case AC97_PCM_LFE_DAC_RATE:	idx = AC97_RATES_LFE_DAC; break;		case AC97_PCM_LR_ADC_RATE:	idx = AC97_RATES_ADC; break;		case AC97_PCM_MIC_ADC_RATE:	idx = AC97_RATES_MIC_ADC; break;		default:			idx = AC97_RATES_SPDIF; break;		}		rates &= pcm->r[dbl].codec[cidx]->rates[idx];	}	if (!dbl)		rates &= ~(SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 |			   SNDRV_PCM_RATE_96000);	return rates;}/** * snd_ac97_pcm_assign - assign AC97 slots to given PCM streams * @bus: the ac97 bus instance * @pcms_count: count of PCMs to be assigned * @pcms: PCMs to be assigned * * It assigns available AC97 slots for given PCMs. If none or only * some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members * are reduced and might be zero. */int snd_ac97_pcm_assign(ac97_bus_t *bus,			unsigned short pcms_count,			const struct ac97_pcm *pcms){	int i, j, k;	const struct ac97_pcm *pcm;	struct ac97_pcm *rpcms, *rpcm;	unsigned short avail_slots[2][4];	unsigned char rate_table[2][4];	unsigned short tmp, slots;	unsigned short spdif_slots[4];	unsigned int rates;	ac97_t *codec;	rpcms = kcalloc(pcms_count, sizeof(struct ac97_pcm), GFP_KERNEL);	if (rpcms == NULL)		return -ENOMEM;	memset(avail_slots, 0, sizeof(avail_slots));	memset(rate_table, 0, sizeof(rate_table));	memset(spdif_slots, 0, sizeof(spdif_slots));	for (i = 0; i < 4; i++) {		codec = bus->codec[i];		if (!codec)			continue;		avail_slots[0][i] = get_pslots(codec, &rate_table[0][i], &spdif_slots[i]);		avail_slots[1][i] = get_cslots(codec);		if (!(codec->scaps & AC97_SCAP_INDEP_SDIN)) {			for (j = 0; j < i; j++) {				if (bus->codec[j])					avail_slots[1][i] &= ~avail_slots[1][j];			}		}	}	/* first step - exclusive devices */	for (i = 0; i < pcms_count; i++) {		pcm = &pcms[i];		rpcm = &rpcms[i];		/* low-level driver thinks that it's more clever */		if (pcm->copy_flag) {			*rpcm = *pcm;			continue;		}		rpcm->stream = pcm->stream;		rpcm->exclusive = pcm->exclusive;		rpcm->spdif = pcm->spdif;		rpcm->private_value = pcm->private_value;		rpcm->bus = bus;		rpcm->rates = ~0;		slots = pcm->r[0].slots;		for (j = 0; j < 4 && slots; j++) {			if (!bus->codec[j])				continue;			rates = ~0;			if (pcm->spdif && pcm->stream == 0)				tmp = spdif_slots[j];			else				tmp = avail_slots[pcm->stream][j];			if (pcm->exclusive) {				/* exclusive access */				tmp &= slots;				for (k = 0; k < i; k++) {					if (rpcm->stream == rpcms[k].stream)						tmp &= ~rpcms[k].r[0].rslots[j];				}			} else {				/* non-exclusive access */				tmp &= pcm->r[0].slots;			}			if (tmp) {				rpcm->r[0].rslots[j] = tmp;				rpcm->r[0].codec[j] = bus->codec[j];				rpcm->r[0].rate_table[j] = rate_table[pcm->stream][j];				if (bus->no_vra)					rates = SNDRV_PCM_RATE_48000;				else					rates = get_rates(rpcm, j, tmp, 0);				if (pcm->exclusive)					avail_slots[pcm->stream][j] &= ~tmp;			}			slots &= ~tmp;			rpcm->r[0].slots |= tmp;			rpcm->rates &= rates;		}		/* for double rate, we check the first codec only */		if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK &&		    bus->codec[0] && (bus->codec[0]->flags & AC97_DOUBLE_RATE) &&		    rate_table[pcm->stream][0] == 0) {			tmp = (1<<AC97_SLOT_PCM_LEFT) | (1<<AC97_SLOT_PCM_RIGHT) |			      (1<<AC97_SLOT_PCM_LEFT_0) | (1<<AC97_SLOT_PCM_RIGHT_0);			if ((tmp & pcm->r[1].slots) == tmp) {				rpcm->r[1].slots = tmp;				rpcm->r[1].rslots[0] = tmp;				rpcm->r[1].rate_table[0] = 0;				rpcm->r[1].codec[0] = bus->codec[0];				if (pcm->exclusive)					avail_slots[pcm->stream][0] &= ~tmp;				if (bus->no_vra)					rates = SNDRV_PCM_RATE_96000;				else					rates = get_rates(rpcm, 0, tmp, 1);				rpcm->rates |= rates;			}		}		if (rpcm->rates == ~0)			rpcm->rates = 0; /* not used */	}	bus->pcms_count = pcms_count;	bus->pcms = rpcms;	return 0;}/** * snd_ac97_pcm_open - opens the given AC97 pcm * @pcm: the ac97 pcm instance * @rate: rate in Hz, if codec does not support VRA, this value must be 48000Hz * @cfg: output stream characteristics * @slots: a subset of allocated slots (snd_ac97_pcm_assign) for this pcm * * It locks the specified slots and sets the given rate to AC97 registers. */int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,		      enum ac97_pcm_cfg cfg, unsigned short slots){	ac97_bus_t *bus;	int i, cidx, r, ok_flag;	unsigned int reg_ok[4] = {0,0,0,0};	unsigned char reg;	int err = 0;	r = rate > 48000;	bus = pcm->bus;	if (cfg == AC97_PCM_CFG_SPDIF) {		int err;		for (cidx = 0; cidx < 4; cidx++)			if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) {				err = set_spdif_rate(bus->codec[cidx], rate);				if (err < 0)					return err;			}	}	spin_lock_irq(&pcm->bus->bus_lock);	for (i = 3; i < 12; i++) {		if (!(slots & (1 << i)))			continue;		ok_flag = 0;		for (cidx = 0; cidx < 4; cidx++) {			if (bus->used_slots[pcm->stream][cidx] & (1 << i)) {				spin_unlock_irq(&pcm->bus->bus_lock);				err = -EBUSY;				goto error;			}			if (pcm->r[r].rslots[cidx] & (1 << i)) {				bus->used_slots[pcm->stream][cidx] |= (1 << i);				ok_flag++;			}		}		if (!ok_flag) {			spin_unlock_irq(&pcm->bus->bus_lock);			snd_printk(KERN_ERR "cannot find configuration for AC97 slot %i\n", i);			err = -EAGAIN;			goto error;		}	}	spin_unlock_irq(&pcm->bus->bus_lock);	for (i = 3; i < 12; i++) {		if (!(slots & (1 << i)))			continue;		for (cidx = 0; cidx < 4; cidx++) {			if (pcm->r[r].rslots[cidx] & (1 << i)) {				reg = get_slot_reg(pcm, cidx, i, r);				if (reg == 0xff) {					snd_printk(KERN_ERR "invalid AC97 slot %i?\n", i);					continue;				}				if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE)))					continue;				//printk(KERN_DEBUG "setting ac97 reg 0x%x to rate %d\n", reg, rate);				err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate);				if (err < 0)					snd_printk(KERN_ERR "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", cidx, reg, rate, err);				else					reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE));			}		}	}	pcm->aslots = slots;	return 0; error:	pcm->aslots = slots;	snd_ac97_pcm_close(pcm);	return err;}/** * snd_ac97_pcm_close - closes the given AC97 pcm * @pcm: the ac97 pcm instance * * It frees the locked AC97 slots. */int snd_ac97_pcm_close(struct ac97_pcm *pcm){	ac97_bus_t *bus;	unsigned short slots = pcm->aslots;	int i, cidx;	bus = pcm->bus;	spin_lock_irq(&pcm->bus->bus_lock);	for (i = 3; i < 12; i++) {		if (!(slots & (1 << i)))			continue;		for (cidx = 0; cidx < 4; cidx++)			bus->used_slots[pcm->stream][cidx] &= ~(1 << i);	}	pcm->aslots = 0;	spin_unlock_irq(&pcm->bus->bus_lock);	return 0;}static int double_rate_hw_constraint_rate(snd_pcm_hw_params_t *params,					  snd_pcm_hw_rule_t *rule){	snd_interval_t *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);	if (channels->min > 2) {		static const snd_interval_t single_rates = {			.min = 1,			.max = 48000,		};		snd_interval_t *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);		return snd_interval_refine(rate, &single_rates);	}	return 0;}static int double_rate_hw_constraint_channels(snd_pcm_hw_params_t *params,					      snd_pcm_hw_rule_t *rule){	snd_interval_t *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);	if (rate->min > 48000) {		static const snd_interval_t double_rate_channels = {			.min = 2,			.max = 2,		};		snd_interval_t *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);		return snd_interval_refine(channels, &double_rate_channels);	}	return 0;}/** * snd_ac97_pcm_double_rate_rules - set double rate constraints * @runtime: the runtime of the ac97 front playback pcm * * Installs the hardware constraint rules to prevent using double rates and * more than two channels at the same time. */int snd_ac97_pcm_double_rate_rules(snd_pcm_runtime_t *runtime){	int err;	err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,				  double_rate_hw_constraint_rate, NULL,				  SNDRV_PCM_HW_PARAM_CHANNELS, -1);	if (err < 0)		return err;	err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,				  double_rate_hw_constraint_channels, NULL,				  SNDRV_PCM_HW_PARAM_RATE, -1);	return err;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -