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

📄 wavefront_fx.c

📁 是关于linux2.5.1的完全源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  Copyright (c) 1998-2002 by Paul Davis <pbd@op.net> * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */#define __NO_VERSION__#include <sound/driver.h>#include <asm/io.h>#include <linux/init.h>#include <linux/time.h>#include <linux/wait.h>#include <sound/core.h>#include <sound/snd_wavefront.h>#include <sound/yss225.h>#include <sound/initval.h>/* Control bits for the Load Control Register */#define FX_LSB_TRANSFER 0x01    /* transfer after DSP LSB byte written */#define FX_MSB_TRANSFER 0x02    /* transfer after DSP MSB byte written */#define FX_AUTO_INCR    0x04    /* auto-increment DSP address after transfer */static inline voiddec_mod_count(struct module *module){	if (module)		__MOD_DEC_USE_COUNT(module);}static intwavefront_fx_idle (snd_wavefront_t *dev)     {	int i;	unsigned int x = 0x80;    	for (i = 0; i < 1000; i++) {		x = inb (dev->fx_status);		if ((x & 0x80) == 0) {			break;		}	}    	if (x & 0x80) {		snd_printk ("FX device never idle.\n");		return 0;	}    	return (1);}static voidwavefront_fx_mute (snd_wavefront_t *dev, int onoff)    {	if (!wavefront_fx_idle(dev)) {		return;	}    	outb (onoff ? 0x02 : 0x00, dev->fx_op);}static intwavefront_fx_memset (snd_wavefront_t *dev, 		     int page,		     int addr, 		     int cnt, 		     unsigned short *data){	if (page < 0 || page > 7) {		snd_printk ("FX memset: "			"page must be >= 0 and <= 7\n");		return -(EINVAL);	}	if (addr < 0 || addr > 0x7f) {		snd_printk ("FX memset: "			"addr must be >= 0 and <= 7f\n");		return -(EINVAL);	}	if (cnt == 1) {		outb (FX_LSB_TRANSFER, dev->fx_lcr);		outb (page, dev->fx_dsp_page);		outb (addr, dev->fx_dsp_addr);		outb ((data[0] >> 8), dev->fx_dsp_msb);		outb ((data[0] & 0xff), dev->fx_dsp_lsb);		snd_printk ("FX: addr %d:%x set to 0x%x\n",			page, addr, data[0]);		} else {		int i;		outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev->fx_lcr);		outb (page, dev->fx_dsp_page);		outb (addr, dev->fx_dsp_addr);		for (i = 0; i < cnt; i++) {			outb ((data[i] >> 8), dev->fx_dsp_msb);			outb ((data[i] & 0xff), dev->fx_dsp_lsb);			if (!wavefront_fx_idle (dev)) {				break;			}		}		if (i != cnt) {			snd_printk ("FX memset "				    "(0x%x, 0x%x, 0x%lx, %d) incomplete\n",				    page, addr, (unsigned long) data, cnt);			return -(EIO);		}	}	return 0;}int snd_wavefront_fx_detect (snd_wavefront_t *dev){	/* This is a crude check, but its the best one I have for now.	   Certainly on the Maui and the Tropez, wavefront_fx_idle() will	   report "never idle", which suggests that this test should	   work OK.	*/	if (inb (dev->fx_status) & 0x80) {		snd_printk ("Hmm, probably a Maui or Tropez.\n");		return -1;	}	return 0;}	int snd_wavefront_fx_open (snd_hwdep_t *hw, struct file *file){	MOD_INC_USE_COUNT;	if (!try_inc_mod_count(hw->card->module)) {		MOD_DEC_USE_COUNT;		return -EFAULT;	}	file->private_data = hw;	return 0;}int snd_wavefront_fx_release (snd_hwdep_t *hw, struct file *file){	dec_mod_count(hw->card->module);	MOD_DEC_USE_COUNT;	return 0;}intsnd_wavefront_fx_ioctl (snd_hwdep_t *sdev, struct file *file,			unsigned int cmd, unsigned long arg){	snd_card_t *card;	snd_wavefront_card_t *acard;	snd_wavefront_t *dev;	wavefront_fx_info r;	unsigned short page_data[256];	unsigned short *pd;	snd_assert(sdev->card != NULL, return -ENODEV);		card = sdev->card;	snd_assert(card->private_data != NULL, return -ENODEV);	acard = card->private_data;	dev = &acard->wavefront;	if (copy_from_user (&r, (unsigned char *) arg, sizeof (wavefront_fx_info)))		return -EFAULT;	switch (r.request) {	case WFFX_MUTE:		wavefront_fx_mute (dev, r.data[0]);		return -EIO;	case WFFX_MEMSET:		if (r.data[2] <= 0) {			snd_printk ("cannot write "				"<= 0 bytes to FX\n");			return -EIO;		} else if (r.data[2] == 1) {			pd = (unsigned short *) &r.data[3];		} else {			if (r.data[2] > sizeof (page_data)) {				snd_printk ("cannot write "					    "> 255 bytes to FX\n");				return -EIO;			}			if (copy_from_user (page_data,					    (unsigned char *) r.data[3],					    r.data[2]))				return -EFAULT;			pd = page_data;		}		wavefront_fx_memset (dev,			     r.data[0], /* page */			     r.data[1], /* addr */			     r.data[2], /* cnt */			     pd);		break;	default:		snd_printk ("FX: ioctl %d not yet supported\n",			    r.request);		return -ENOTTY;	}	return 0;}/* YSS225 initialization.   This code was developed using DOSEMU. The Turtle Beach SETUPSND   utility was run with I/O tracing in DOSEMU enabled, and a reconstruction   of the port I/O done, using the Yamaha faxback document as a guide   to add more logic to the code. Its really pretty wierd.   There was an alternative approach of just dumping the whole I/O   sequence as a series of port/value pairs and a simple loop   that output it. However, I hope that eventually I'll get more   control over what this code does, and so I tried to stick with   a somewhat "algorithmic" approach.*/int __initsnd_wavefront_fx_start (snd_wavefront_t *dev){	unsigned int i, j;	/* Set all bits for all channels on the MOD unit to zero */	/* XXX But why do this twice ? */	for (j = 0; j < 2; j++) {		for (i = 0x10; i <= 0xff; i++) {	    			if (!wavefront_fx_idle (dev)) {				return (-1);			}	    			outb (i, dev->fx_mod_addr);			outb (0x0, dev->fx_mod_data);		}	}	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x02, dev->fx_op);                        /* mute on */	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x44, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x42, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x43, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x7c, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x7e, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x46, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x49, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x47, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	if (!wavefront_fx_idle (dev)) return (-1);	outb (0x07, dev->fx_dsp_page);	outb (0x4a, dev->fx_dsp_addr);	outb (0x00, dev->fx_dsp_msb);	outb (0x00, dev->fx_dsp_lsb);	/* either because of stupidity by TB's programmers, or because it	   actually does something, rezero the MOD page.	*/	for (i = 0x10; i <= 0xff; i++) {			if (!wavefront_fx_idle (dev)) {			return (-1);		}			outb (i, dev->fx_mod_addr);		outb (0x0, dev->fx_mod_data);	}	/* load page zero */	outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev->fx_lcr);	outb (0x00, dev->fx_dsp_page);	outb (0x00, dev->fx_dsp_addr);	for (i = 0; i < sizeof (page_zero); i += 2) {		outb (page_zero[i], dev->fx_dsp_msb);		outb (page_zero[i+1], dev->fx_dsp_lsb);		if (!wavefront_fx_idle (dev)) return (-1);

⌨️ 快捷键说明

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