2 * Copyright (c) 1998-2002 by Paul Davis <pbd@op.net>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/init.h>
21 #include <linux/time.h>
22 #include <linux/wait.h>
23 #include <linux/firmware.h>
24 #include <sound/core.h>
25 #include <sound/snd_wavefront.h>
26 #include <sound/initval.h>
28 /* Control bits for the Load Control Register
31 #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 */
35 #define WAIT_IDLE 0xff
38 wavefront_fx_idle (snd_wavefront_t *dev)
42 unsigned int x = 0x80;
44 for (i = 0; i < 1000; i++) {
45 x = inb (dev->fx_status);
46 if ((x & 0x80) == 0) {
52 snd_printk ("FX device never idle.\n");
60 wavefront_fx_mute (snd_wavefront_t *dev, int onoff)
63 if (!wavefront_fx_idle(dev)) {
67 outb (onoff ? 0x02 : 0x00, dev->fx_op);
71 wavefront_fx_memset (snd_wavefront_t *dev,
77 if (page < 0 || page > 7) {
78 snd_printk ("FX memset: "
79 "page must be >= 0 and <= 7\n");
83 if (addr < 0 || addr > 0x7f) {
84 snd_printk ("FX memset: "
85 "addr must be >= 0 and <= 7f\n");
91 outb (FX_LSB_TRANSFER, dev->fx_lcr);
92 outb (page, dev->fx_dsp_page);
93 outb (addr, dev->fx_dsp_addr);
94 outb ((data[0] >> 8), dev->fx_dsp_msb);
95 outb ((data[0] & 0xff), dev->fx_dsp_lsb);
97 snd_printk ("FX: addr %d:%x set to 0x%x\n",
103 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev->fx_lcr);
104 outb (page, dev->fx_dsp_page);
105 outb (addr, dev->fx_dsp_addr);
107 for (i = 0; i < cnt; i++) {
108 outb ((data[i] >> 8), dev->fx_dsp_msb);
109 outb ((data[i] & 0xff), dev->fx_dsp_lsb);
110 if (!wavefront_fx_idle (dev)) {
116 snd_printk ("FX memset "
117 "(0x%x, 0x%x, 0x%lx, %d) incomplete\n",
118 page, addr, (unsigned long) data, cnt);
127 snd_wavefront_fx_detect (snd_wavefront_t *dev)
130 /* This is a crude check, but its the best one I have for now.
131 Certainly on the Maui and the Tropez, wavefront_fx_idle() will
132 report "never idle", which suggests that this test should
136 if (inb (dev->fx_status) & 0x80) {
137 snd_printk ("Hmm, probably a Maui or Tropez.\n");
145 snd_wavefront_fx_open (struct snd_hwdep *hw, struct file *file)
148 if (!try_module_get(hw->card->module))
150 file->private_data = hw;
155 snd_wavefront_fx_release (struct snd_hwdep *hw, struct file *file)
158 module_put(hw->card->module);
163 snd_wavefront_fx_ioctl (struct snd_hwdep *sdev, struct file *file,
164 unsigned int cmd, unsigned long arg)
167 struct snd_card *card;
168 snd_wavefront_card_t *acard;
169 snd_wavefront_t *dev;
171 unsigned short *page_data = NULL;
176 if (snd_BUG_ON(!card))
178 if (snd_BUG_ON(!card->private_data))
181 acard = card->private_data;
182 dev = &acard->wavefront;
184 if (copy_from_user (&r, (void __user *)arg, sizeof (wavefront_fx_info)))
189 wavefront_fx_mute (dev, r.data[0]);
193 if (r.data[2] <= 0) {
194 snd_printk ("cannot write "
195 "<= 0 bytes to FX\n");
197 } else if (r.data[2] == 1) {
198 pd = (unsigned short *) &r.data[3];
200 if (r.data[2] > 256) {
201 snd_printk ("cannot write "
202 "> 512 bytes to FX\n");
205 page_data = kmalloc(r.data[2] * sizeof(short), GFP_KERNEL);
208 if (copy_from_user (page_data,
209 (unsigned char __user *) r.data[3],
210 r.data[2] * sizeof(short))) {
217 err = wavefront_fx_memset (dev,
218 r.data[0], /* page */
219 r.data[1], /* addr */
226 snd_printk ("FX: ioctl %d not yet supported\n",
233 /* YSS225 initialization.
235 This code was developed using DOSEMU. The Turtle Beach SETUPSND
236 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
237 of the port I/O done, using the Yamaha faxback document as a guide
238 to add more logic to the code. Its really pretty weird.
240 This is the approach of just dumping the whole I/O
241 sequence as a series of port/value pairs and a simple loop
246 snd_wavefront_fx_start (snd_wavefront_t *dev)
250 const struct firmware *firmware = NULL;
252 if (dev->fx_initialized)
255 err = request_firmware(&firmware, "yamaha/yss225_registers.bin",
262 for (i = 0; i + 1 < firmware->size; i += 2) {
263 if (firmware->data[i] >= 8 && firmware->data[i] < 16) {
264 outb(firmware->data[i + 1],
265 dev->base + firmware->data[i]);
266 } else if (firmware->data[i] == WAIT_IDLE) {
267 if (!wavefront_fx_idle(dev)) {
272 snd_printk(KERN_ERR "invalid address"
273 " in register data\n");
279 dev->fx_initialized = 1;
283 release_firmware(firmware);
287 MODULE_FIRMWARE("yamaha/yss225_registers.bin");