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

📄 ac97_codec.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* read or write the recmask, the ac97 can really have left and right recording   inputs independantly set, but OSS doesn't seem to want us to express that to   the user. the caller guarantees that we have a supported bit set, and they   must be holding the card's spinlock */static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask) {	unsigned int val;	if (rw) {		/* read it from the card */		val = codec->codec_read(codec, AC97_RECORD_SELECT);#ifdef DEBUG		printk("ac97_codec: ac97 recmask to set to 0x%04x\n", val);#endif		return (1 << ac97_rm2oss[val & 0x07]);	}	/* else, write the first set in the mask as the	   output */		/* clear out current set value first (AC97 supports only 1 input!) */	val = (1 << ac97_rm2oss[codec->codec_read(codec, AC97_RECORD_SELECT) & 0x07]);	if (mask != val)	    mask &= ~val;       	val = ffs(mask); 	val = ac97_oss_rm[val-1];	val |= val << 8;  /* set both channels */#ifdef DEBUG	printk("ac97_codec: setting ac97 recmask to 0x%04x\n", val);#endif	codec->codec_write(codec, AC97_RECORD_SELECT, val);	return 0;};static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg){	int i, val = 0;	if (cmd == SOUND_MIXER_INFO) {		mixer_info info;		strncpy(info.id, codec->name, sizeof(info.id));		strncpy(info.name, codec->name, sizeof(info.name));		info.modify_counter = codec->modcnt;		if (copy_to_user((void *)arg, &info, sizeof(info)))			return -EFAULT;		return 0;	}	if (cmd == SOUND_OLD_MIXER_INFO) {		_old_mixer_info info;		strncpy(info.id, codec->name, sizeof(info.id));		strncpy(info.name, codec->name, sizeof(info.name));		if (copy_to_user((void *)arg, &info, sizeof(info)))			return -EFAULT;		return 0;	}	if (_IOC_TYPE(cmd) != 'M' || _IOC_SIZE(cmd) != sizeof(int))		return -EINVAL;	if (cmd == OSS_GETVERSION)		return put_user(SOUND_VERSION, (int *)arg);	if (_IOC_DIR(cmd) == _IOC_READ) {		switch (_IOC_NR(cmd)) {		case SOUND_MIXER_RECSRC: /* give them the current record source */			if (!codec->recmask_io) {				val = 0;			} else {				val = codec->recmask_io(codec, 1, 0);			}			break;		case SOUND_MIXER_DEVMASK: /* give them the supported mixers */			val = codec->supported_mixers;			break;		case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */			val = codec->record_sources;			break;		case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */			val = codec->stereo_mixers;			break;		case SOUND_MIXER_CAPS:			val = SOUND_CAP_EXCL_INPUT;			break;		default: /* read a specific mixer */			i = _IOC_NR(cmd);			if (!supported_mixer(codec, i)) 				return -EINVAL;			/* do we ever want to touch the hardware? */		        /* val = codec->read_mixer(codec, i); */			val = codec->mixer_state[i]; 			break;		}		return put_user(val, (int *)arg);	}	if (_IOC_DIR(cmd) == (_IOC_WRITE|_IOC_READ)) {		codec->modcnt++;		if (get_user(val, (int *)arg))			return -EFAULT;		switch (_IOC_NR(cmd)) {		case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */			if (!codec->recmask_io) return -EINVAL;			if (!val) return 0;			if (!(val &= codec->record_sources)) return -EINVAL;			codec->recmask_io(codec, 0, val);			return 0;		default: /* write a specific mixer */			i = _IOC_NR(cmd);			if (!supported_mixer(codec, i)) 				return -EINVAL;			ac97_set_mixer(codec, i, val);			return 0;		}	}	return -EINVAL;}/* entry point for /proc/driver/controller_vendor/ac97/%d */int ac97_read_proc (char *page, char **start, off_t off,		    int count, int *eof, void *data){	int len = 0, cap, extid, val, id1, id2;	struct ac97_codec *codec;	int is_ac97_20 = 0;	if ((codec = data) == NULL)		return -ENODEV;	id1 = codec->codec_read(codec, AC97_VENDOR_ID1);	id2 = codec->codec_read(codec, AC97_VENDOR_ID2);	len += sprintf (page+len, "Vendor name      : %s\n", codec->name);	len += sprintf (page+len, "Vendor id        : %04X %04X\n", id1, id2);	extid = codec->codec_read(codec, AC97_EXTENDED_ID);	extid &= ~((1<<2)|(1<<4)|(1<<5)|(1<<10)|(1<<11)|(1<<12)|(1<<13));	len += sprintf (page+len, "AC97 Version     : %s\n",			extid ? "2.0 or later" : "1.0");	if (extid) is_ac97_20 = 1;	cap = codec->codec_read(codec, AC97_RESET);	len += sprintf (page+len, "Capabilities     :%s%s%s%s%s%s\n",			cap & 0x0001 ? " -dedicated MIC PCM IN channel-" : "",			cap & 0x0002 ? " -reserved1-" : "",			cap & 0x0004 ? " -bass & treble-" : "",			cap & 0x0008 ? " -simulated stereo-" : "",			cap & 0x0010 ? " -headphone out-" : "",			cap & 0x0020 ? " -loudness-" : "");	val = cap & 0x00c0;	len += sprintf (page+len, "DAC resolutions  :%s%s%s\n",			" -16-bit-",			val & 0x0040 ? " -18-bit-" : "",			val & 0x0080 ? " -20-bit-" : "");	val = cap & 0x0300;	len += sprintf (page+len, "ADC resolutions  :%s%s%s\n",			" -16-bit-",			val & 0x0100 ? " -18-bit-" : "",			val & 0x0200 ? " -20-bit-" : "");	len += sprintf (page+len, "3D enhancement   : %s\n",			ac97_stereo_enhancements[(cap >> 10) & 0x1f]);	val = codec->codec_read(codec, AC97_GENERAL_PURPOSE);	len += sprintf (page+len, "POP path         : %s 3D\n"			"Sim. stereo      : %s\n"			"3D enhancement   : %s\n"			"Loudness         : %s\n"			"Mono output      : %s\n"			"MIC select       : %s\n"			"ADC/DAC loopback : %s\n",			val & 0x8000 ? "post" : "pre",			val & 0x4000 ? "on" : "off",			val & 0x2000 ? "on" : "off",			val & 0x1000 ? "on" : "off",			val & 0x0200 ? "MIC" : "MIX",			val & 0x0100 ? "MIC2" : "MIC1",			val & 0x0080 ? "on" : "off");	extid = codec->codec_read(codec, AC97_EXTENDED_ID);	cap = extid;	len += sprintf (page+len, "Ext Capabilities :%s%s%s%s%s%s%s\n",			cap & 0x0001 ? " -var rate PCM audio-" : "",			cap & 0x0002 ? " -2x PCM audio out-" : "",			cap & 0x0008 ? " -var rate MIC in-" : "",			cap & 0x0040 ? " -PCM center DAC-" : "",			cap & 0x0080 ? " -PCM surround DAC-" : "",			cap & 0x0100 ? " -PCM LFE DAC-" : "",			cap & 0x0200 ? " -slot/DAC mappings-" : "");	if (is_ac97_20) {		len += sprintf (page+len, "Front DAC rate   : %d\n",				codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE));	}	return len;}/** *	ac97_probe_codec - Initialize and setup AC97-compatible codec *	@codec: (in/out) Kernel info for a single AC97 codec * *	Reset the AC97 codec, then initialize the mixer and *	the rest of the @codec structure. * *	The codec_read and codec_write fields of @codec are *	required to be setup and working when this function *	is called.  All other fields are set by this function. * *	codec_wait field of @codec can optionally be provided *	when calling this function.  If codec_wait is not %NULL, *	this function will call codec_wait any time it is *	necessary to wait for the audio chip to reach the *	codec-ready state.  If codec_wait is %NULL, then *	the default behavior is to call schedule_timeout. *	Currently codec_wait is used to wait for AC97 codec *	reset to complete.  * *	Returns 1 (true) on success, or 0 (false) on failure. */ int ac97_probe_codec(struct ac97_codec *codec){	u16 id1, id2;	u16 audio, modem;	int i;	/* probing AC97 codec, AC97 2.0 says that bit 15 of register 0x00 (reset) should 	 * be read zero.	 *	 * FIXME: is the following comment outdated?  -jgarzik 	 * Probing of AC97 in this way is not reliable, it is not even SAFE !!	 */	codec->codec_write(codec, AC97_RESET, 0L);	/* also according to spec, we wait for codec-ready state */		if (codec->codec_wait)		codec->codec_wait(codec);	else		udelay(10);	if ((audio = codec->codec_read(codec, AC97_RESET)) & 0x8000) {		printk(KERN_ERR "ac97_codec: %s ac97 codec not present\n",		       codec->id ? "Secondary" : "Primary");		return 0;	}	/* probe for Modem Codec */	codec->codec_write(codec, AC97_EXTENDED_MODEM_ID, 0L);	modem = codec->codec_read(codec, AC97_EXTENDED_MODEM_ID);	codec->name = NULL;	codec->codec_init = NULL;	id1 = codec->codec_read(codec, AC97_VENDOR_ID1);	id2 = codec->codec_read(codec, AC97_VENDOR_ID2);	for (i = 0; i < arraysize(ac97_codec_ids); i++) {		if (ac97_codec_ids[i].id == ((id1 << 16) | id2)) {			codec->type = ac97_codec_ids[i].id;			codec->name = ac97_codec_ids[i].name;			codec->codec_init = ac97_codec_ids[i].init;			break;		}	}	if (codec->name == NULL)		codec->name = "Unknown";	printk(KERN_INFO "ac97_codec: AC97 %s codec, id: 0x%04x:"	       "0x%04x (%s)\n", audio ? "Audio" : (modem ? "Modem" : ""),	       id1, id2, codec->name);	return ac97_init_mixer(codec);}static int ac97_init_mixer(struct ac97_codec *codec){	u16 cap;	int i;	cap = codec->codec_read(codec, AC97_RESET);	/* mixer masks */	codec->supported_mixers = AC97_SUPPORTED_MASK;	codec->stereo_mixers = AC97_STEREO_MASK;	codec->record_sources = AC97_RECORD_MASK;	if (!(cap & 0x04))		codec->supported_mixers &= ~(SOUND_MASK_BASS|SOUND_MASK_TREBLE);	if (!(cap & 0x10))		codec->supported_mixers &= ~SOUND_MASK_ALTPCM;	/* detect bit resolution */	codec->codec_write(codec, AC97_MASTER_VOL_STEREO, 0x2020);	if(codec->codec_read(codec, AC97_MASTER_VOL_STEREO) == 0x1f1f)		codec->bit_resolution = 5;	else		codec->bit_resolution = 6;	/* generic OSS to AC97 wrapper */	codec->read_mixer = ac97_read_mixer;	codec->write_mixer = ac97_write_mixer;	codec->recmask_io = ac97_recmask_io;	codec->mixer_ioctl = ac97_mixer_ioctl;	/* codec specific initialization for 4-6 channel output or secondary codec stuff */	if (codec->codec_init != NULL) {		codec->codec_init(codec);	}	/* initilize mixer channel volumes */	for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {		struct mixer_defaults *md = &mixer_defaults[i];		if (md->mixer == -1) 			break;		if (!supported_mixer(codec, md->mixer)) 			continue;		ac97_set_mixer(codec, md->mixer, md->value);	}	return 1;}static int sigmatel_init(struct ac97_codec * codec){	/* Only set up secondary codec */	if (codec->id == 0)		return 1;	codec->codec_write(codec, AC97_SURROUND_MASTER, 0L);	/* initialize SigmaTel STAC9721/23 as secondary codec, decoding AC link	   sloc 3,4 = 0x01, slot 7,8 = 0x00, */	codec->codec_write(codec, 0x74, 0x00);	/* we don't have the crystal when we are on an AMR card, so use	   BIT_CLK as our clock source. Write the magic word ABBA and read	   back to enable register 0x78 */	codec->codec_write(codec, 0x76, 0xabba);	codec->codec_read(codec, 0x76);	/* sync all the clocks*/	codec->codec_write(codec, 0x78, 0x3802);	return 1;}/* *	Bring up an AD1885 */ static int enable_eapd(struct ac97_codec * codec){	codec->codec_write(codec, AC97_POWER_CONTROL,		codec->codec_read(codec, AC97_POWER_CONTROL)|0x8000);	return 0;}	EXPORT_SYMBOL(ac97_read_proc);EXPORT_SYMBOL(ac97_probe_codec);

⌨️ 快捷键说明

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