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

📄 aci.c

📁 讲述linux的初始化过程
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Audio Command Interface (ACI) driver (sound/aci.c) * * ACI is a protocol used to communicate with the microcontroller on * some sound cards produced by miro, e.g. the miroSOUND PCM12 and * PCM20. The ACI has been developed for miro by Norberto Pellicci * <pellicci@home.com>. Special thanks to both him and miro for * providing the ACI specification. * * The main function of the ACI is to control the mixer and to get a * product identification. On the PCM20, ACI also controls the radio * tuner on this card, this is supported in the Video for Linux  * radio-miropcm20 driver. *  * This Voxware ACI driver currently only supports the ACI functions * on the miroSOUND PCM12 and PCM20 card. Support for miro sound cards  * with additional ACI functions can easily be added later. * * / NOTE / When compiling as a module, make sure to load the module  * after loading the mad16 module. The initialisation code expects the * MAD16 default mixer to be already available. * * Revision history: * *   1995-11-10  Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de> *        First version written. *   1995-12-31  Markus Kuhn *        Second revision, general code cleanup. *   1996-05-16	 Hannu Savolainen *	  Integrated with other parts of the driver. *   1996-05-28  Markus Kuhn *        Initialize CS4231A mixer, make ACI first mixer, *        use new private mixer API for solo mode. *   1998-08-18  Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl> *	  Small modification to export ACI functions and  *	  complete modularisation. *//* * Some driver specific information and features: * * This mixer driver identifies itself to applications as "ACI" in * mixer_info.id as retrieved by ioctl(fd, SOUND_MIXER_INFO, &mixer_info). * * Proprietary mixer features that go beyond the standard OSS mixer * interface are: *  * Full duplex solo configuration: * *   int solo_mode; *   ioctl(fd, SOUND_MIXER_PRIVATE1, &solo_mode); * *   solo_mode = 0: deactivate solo mode (default) *   solo_mode > 0: activate solo mode *                  With activated solo mode, the PCM input can not any *                  longer hear the signals produced by the PCM output. *                  Activating solo mode is important in duplex mode in order *                  to avoid feedback distortions. *   solo_mode < 0: do not change solo mode (just retrieve the status) * *   When the ioctl() returns 0, solo_mode contains the previous *   status (0 = deactivated, 1 = activated). If solo mode is not *   implemented on this card, ioctl() returns -1 and sets errno to *   EINVAL. * */#include <linux/init.h>#include <linux/module.h> #include "sound_config.h"#undef  DEBUG		/* if defined, produce a verbose report via syslog */int aci_port = 0x354;	/* as determined by bit 4 in the OPTi 929 MC4 register */unsigned char aci_idcode[2] = {0, 0};	/* manufacturer and product ID */unsigned char aci_version = 0;		/* ACI firmware version	*/int aci_solo;		/* status bit of the card that can't be		*			 * checked with ACI versions prior to 0xb0	*/static int aci_present = 0;#ifdef MODULE                  /* Whether the aci mixer is to be reset.    */int aci_reset = 0;             /* Default: don't reset if the driver is a  */MODULE_PARM(aci_reset,"i");#else                          /* module; use "insmod aci.o aci_reset=1" */int aci_reset = 1;             /* to override.                             */#endif#define COMMAND_REGISTER    (aci_port)#define STATUS_REGISTER     (aci_port + 1)#define BUSY_REGISTER       (aci_port + 2)/* * Wait until the ACI microcontroller has set the READYFLAG in the * Busy/IRQ Source Register to 0. This is required to avoid * overrunning the sound card microcontroller. We do a busy wait here, * because the microcontroller is not supposed to signal a busy * condition for more than a few clock cycles. In case of a time-out, * this function returns -1. * * This busy wait code normally requires less than 15 loops and * practically always less than 100 loops on my i486/DX2 66 MHz. * * Warning: Waiting on the general status flag after reseting the MUTE * function can take a VERY long time, because the PCM12 does some kind * of fade-in effect. For this reason, access to the MUTE function has * not been implemented at all. */static int busy_wait(void){	long timeout;	for (timeout = 0; timeout < 10000000L; timeout++)		if ((inb_p(BUSY_REGISTER) & 1) == 0)			return 0;#ifdef DEBUG	printk("ACI: READYFLAG timed out.\n");#endif	return -1;}/* * Read the GENERAL STATUS register. */static int read_general_status(void){	unsigned long flags;	int status;	save_flags(flags);	cli();		if (busy_wait()) {		restore_flags(flags);		return -1;	}		status = (unsigned) inb_p(STATUS_REGISTER);	restore_flags(flags);	return status;}/* * The four ACI command types (implied, write, read and indexed) can * be sent to the microcontroller using the following four functions. * If a problem occurred, they return -1. */int aci_implied_cmd(unsigned char opcode){	unsigned long flags;#ifdef DEBUG	printk("ACI: aci_implied_cmd(0x%02x)\n", opcode);#endif	save_flags(flags);	cli();    	if (read_general_status() < 0 || busy_wait()) {		restore_flags(flags);		return -1;	}		outb_p(opcode, COMMAND_REGISTER);	restore_flags(flags);	return 0;}int aci_write_cmd(unsigned char opcode, unsigned char parameter){	unsigned long flags;	int status;#ifdef DEBUG	printk("ACI: aci_write_cmd(0x%02x, 0x%02x)\n", opcode, parameter);#endif	save_flags(flags);	cli();		if (read_general_status() < 0 || busy_wait()) {		restore_flags(flags);		return -1;	}	outb_p(opcode, COMMAND_REGISTER);	if (busy_wait()) {		restore_flags(flags);		return -1;	}	outb_p(parameter, COMMAND_REGISTER);	if ((status = read_general_status()) < 0) {		restore_flags(flags);		return -1;	}	/* polarity of the INVALID flag depends on ACI version */	if ((aci_version <  0xb0 && (status & 0x40) != 0) ||	  (aci_version >= 0xb0 && (status & 0x40) == 0)) {	  	restore_flags(flags);		printk("ACI: invalid write command 0x%02x, 0x%02x.\n",			opcode, parameter);		return -1;	}	restore_flags(flags);	return 0;}/* * This write command send 2 parameters instead of one. * Only used in PCM20 radio frequency tuning control */int aci_write_cmd_d(unsigned char opcode, unsigned char parameter, unsigned char parameter2){	unsigned long flags;	int status;#ifdef DEBUG	printk("ACI: aci_write_cmd_d(0x%02x, 0x%02x)\n", opcode, parameter, parameter2);#endif	save_flags(flags);	cli();		if (read_general_status() < 0 || busy_wait()) {		restore_flags(flags);		return -1;	}	outb_p(opcode, COMMAND_REGISTER);	if (busy_wait()) {		restore_flags(flags);		return -1;	}	outb_p(parameter, COMMAND_REGISTER);	if (busy_wait()) {		restore_flags(flags);		return -1;	}		outb_p(parameter2, COMMAND_REGISTER);		if ((status = read_general_status()) < 0) {		restore_flags(flags);		return -1;	}		/* polarity of the INVALID flag depends on ACI version */	if ((aci_version <  0xb0 && (status & 0x40) != 0) ||	  (aci_version >= 0xb0 && (status & 0x40) == 0)) {		restore_flags(flags);#if 0	/* Frequency tuning works, but the INVALID flag is set ??? */		printk("ACI: invalid write (double) command 0x%02x, 0x%02x, 0x%02x.\n",			opcode, parameter, parameter2);#endif		return -1;  	}		restore_flags(flags);	return 0;}int aci_read_cmd(unsigned char opcode, int length, unsigned char *parameter){	unsigned long flags;	int i = 0;		save_flags(flags);	cli();  	if (read_general_status() < 0) {		restore_flags(flags);		return -1;	}	while (i < length) {		if (busy_wait()) {			restore_flags(flags);			return -1;		}					outb_p(opcode, COMMAND_REGISTER);		if (busy_wait()) {			restore_flags(flags);			return -1;		}					parameter[i++] = inb_p(STATUS_REGISTER);#ifdef DEBUG		if (i == 1)			printk("ACI: aci_read_cmd(0x%02x, %d) = 0x%02x\n",				opcode, length, parameter[i-1]);		else			printk("ACI: aci_read_cmd cont.: 0x%02x\n", parameter[i-1]);#endif	}	restore_flags(flags);	return 0;}int aci_indexed_cmd(unsigned char opcode, unsigned char index,		       unsigned char *parameter){	unsigned long flags;	save_flags(flags);	cli();  	if (read_general_status() < 0 || busy_wait()) {	  	restore_flags(flags);		return -1;	}		outb_p(opcode, COMMAND_REGISTER);	if (busy_wait()) {		restore_flags(flags);		return -1;	}		outb_p(index, COMMAND_REGISTER);	if (busy_wait()) {		restore_flags(flags);		return -1;	}		*parameter = inb_p(STATUS_REGISTER);#ifdef DEBUG	printk("ACI: aci_indexed_cmd(0x%02x, 0x%02x) = 0x%02x\n", opcode, index,		*parameter);#endif	restore_flags(flags);	return 0;}/* * The following macro SCALE can be used to scale one integer volume * value into another one using only integer arithmetic. If the input * value x is in the range 0 <= x <= xmax, then the result will be in * the range 0 <= SCALE(xmax,ymax,x) <= ymax. * * This macro has for all xmax, ymax > 0 and all 0 <= x <= xmax the

⌨️ 快捷键说明

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