Path: blob/master/sound/isa/wavefront/wavefront_fx.c
10817 views
/*1* Copyright (c) 1998-2002 by Paul Davis <[email protected]>2*3* This program is free software; you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation; either version 2 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA16*/1718#include <asm/io.h>19#include <linux/init.h>20#include <linux/time.h>21#include <linux/wait.h>22#include <linux/slab.h>23#include <linux/firmware.h>24#include <sound/core.h>25#include <sound/snd_wavefront.h>26#include <sound/initval.h>2728/* Control bits for the Load Control Register29*/3031#define FX_LSB_TRANSFER 0x01 /* transfer after DSP LSB byte written */32#define FX_MSB_TRANSFER 0x02 /* transfer after DSP MSB byte written */33#define FX_AUTO_INCR 0x04 /* auto-increment DSP address after transfer */3435#define WAIT_IDLE 0xff3637static int38wavefront_fx_idle (snd_wavefront_t *dev)3940{41int i;42unsigned int x = 0x80;4344for (i = 0; i < 1000; i++) {45x = inb (dev->fx_status);46if ((x & 0x80) == 0) {47break;48}49}5051if (x & 0x80) {52snd_printk ("FX device never idle.\n");53return 0;54}5556return (1);57}5859static void60wavefront_fx_mute (snd_wavefront_t *dev, int onoff)6162{63if (!wavefront_fx_idle(dev)) {64return;65}6667outb (onoff ? 0x02 : 0x00, dev->fx_op);68}6970static int71wavefront_fx_memset (snd_wavefront_t *dev,72int page,73int addr,74int cnt,75unsigned short *data)76{77if (page < 0 || page > 7) {78snd_printk ("FX memset: "79"page must be >= 0 and <= 7\n");80return -(EINVAL);81}8283if (addr < 0 || addr > 0x7f) {84snd_printk ("FX memset: "85"addr must be >= 0 and <= 7f\n");86return -(EINVAL);87}8889if (cnt == 1) {9091outb (FX_LSB_TRANSFER, dev->fx_lcr);92outb (page, dev->fx_dsp_page);93outb (addr, dev->fx_dsp_addr);94outb ((data[0] >> 8), dev->fx_dsp_msb);95outb ((data[0] & 0xff), dev->fx_dsp_lsb);9697snd_printk ("FX: addr %d:%x set to 0x%x\n",98page, addr, data[0]);99100} else {101int i;102103outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev->fx_lcr);104outb (page, dev->fx_dsp_page);105outb (addr, dev->fx_dsp_addr);106107for (i = 0; i < cnt; i++) {108outb ((data[i] >> 8), dev->fx_dsp_msb);109outb ((data[i] & 0xff), dev->fx_dsp_lsb);110if (!wavefront_fx_idle (dev)) {111break;112}113}114115if (i != cnt) {116snd_printk ("FX memset "117"(0x%x, 0x%x, 0x%lx, %d) incomplete\n",118page, addr, (unsigned long) data, cnt);119return -(EIO);120}121}122123return 0;124}125126int127snd_wavefront_fx_detect (snd_wavefront_t *dev)128129{130/* This is a crude check, but its the best one I have for now.131Certainly on the Maui and the Tropez, wavefront_fx_idle() will132report "never idle", which suggests that this test should133work OK.134*/135136if (inb (dev->fx_status) & 0x80) {137snd_printk ("Hmm, probably a Maui or Tropez.\n");138return -1;139}140141return 0;142}143144int145snd_wavefront_fx_open (struct snd_hwdep *hw, struct file *file)146147{148if (!try_module_get(hw->card->module))149return -EFAULT;150file->private_data = hw;151return 0;152}153154int155snd_wavefront_fx_release (struct snd_hwdep *hw, struct file *file)156157{158module_put(hw->card->module);159return 0;160}161162int163snd_wavefront_fx_ioctl (struct snd_hwdep *sdev, struct file *file,164unsigned int cmd, unsigned long arg)165166{167struct snd_card *card;168snd_wavefront_card_t *acard;169snd_wavefront_t *dev;170wavefront_fx_info r;171unsigned short *page_data = NULL;172unsigned short *pd;173int err = 0;174175card = sdev->card;176if (snd_BUG_ON(!card))177return -ENODEV;178if (snd_BUG_ON(!card->private_data))179return -ENODEV;180181acard = card->private_data;182dev = &acard->wavefront;183184if (copy_from_user (&r, (void __user *)arg, sizeof (wavefront_fx_info)))185return -EFAULT;186187switch (r.request) {188case WFFX_MUTE:189wavefront_fx_mute (dev, r.data[0]);190return -EIO;191192case WFFX_MEMSET:193if (r.data[2] <= 0) {194snd_printk ("cannot write "195"<= 0 bytes to FX\n");196return -EIO;197} else if (r.data[2] == 1) {198pd = (unsigned short *) &r.data[3];199} else {200if (r.data[2] > 256) {201snd_printk ("cannot write "202"> 512 bytes to FX\n");203return -EIO;204}205page_data = memdup_user((unsigned char __user *)206r.data[3],207r.data[2] * sizeof(short));208if (IS_ERR(page_data))209return PTR_ERR(page_data);210pd = page_data;211}212213err = wavefront_fx_memset (dev,214r.data[0], /* page */215r.data[1], /* addr */216r.data[2], /* cnt */217pd);218kfree(page_data);219break;220221default:222snd_printk ("FX: ioctl %d not yet supported\n",223r.request);224return -ENOTTY;225}226return err;227}228229/* YSS225 initialization.230231This code was developed using DOSEMU. The Turtle Beach SETUPSND232utility was run with I/O tracing in DOSEMU enabled, and a reconstruction233of the port I/O done, using the Yamaha faxback document as a guide234to add more logic to the code. Its really pretty weird.235236This is the approach of just dumping the whole I/O237sequence as a series of port/value pairs and a simple loop238that outputs it.239*/240241int __devinit242snd_wavefront_fx_start (snd_wavefront_t *dev)243{244unsigned int i;245int err;246const struct firmware *firmware = NULL;247248if (dev->fx_initialized)249return 0;250251err = request_firmware(&firmware, "yamaha/yss225_registers.bin",252dev->card->dev);253if (err < 0) {254err = -1;255goto out;256}257258for (i = 0; i + 1 < firmware->size; i += 2) {259if (firmware->data[i] >= 8 && firmware->data[i] < 16) {260outb(firmware->data[i + 1],261dev->base + firmware->data[i]);262} else if (firmware->data[i] == WAIT_IDLE) {263if (!wavefront_fx_idle(dev)) {264err = -1;265goto out;266}267} else {268snd_printk(KERN_ERR "invalid address"269" in register data\n");270err = -1;271goto out;272}273}274275dev->fx_initialized = 1;276err = 0;277278out:279release_firmware(firmware);280return err;281}282283MODULE_FIRMWARE("yamaha/yss225_registers.bin");284285286