[MTD] [NAND] subpage read feature as a way to increase performance.
[linux-2.6/linux-2.6-openrd.git] / sound / isa / wavefront / wavefront_fx.c
blob2efaa7f205aa617f56c64db3e26f3e279db25246
1 /*
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
19 #include <asm/io.h>
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
37 #ifdef CONFIG_SND_WAVEFRONT_FIRMWARE_IN_KERNEL
38 #include "yss225.c"
39 static const struct firmware yss225_registers_firmware = {
40 .data = (u8 *)yss225_registers,
41 .size = sizeof yss225_registers
43 #endif
45 static int
46 wavefront_fx_idle (snd_wavefront_t *dev)
49 int i;
50 unsigned int x = 0x80;
52 for (i = 0; i < 1000; i++) {
53 x = inb (dev->fx_status);
54 if ((x & 0x80) == 0) {
55 break;
59 if (x & 0x80) {
60 snd_printk ("FX device never idle.\n");
61 return 0;
64 return (1);
67 static void
68 wavefront_fx_mute (snd_wavefront_t *dev, int onoff)
71 if (!wavefront_fx_idle(dev)) {
72 return;
75 outb (onoff ? 0x02 : 0x00, dev->fx_op);
78 static int
79 wavefront_fx_memset (snd_wavefront_t *dev,
80 int page,
81 int addr,
82 int cnt,
83 unsigned short *data)
85 if (page < 0 || page > 7) {
86 snd_printk ("FX memset: "
87 "page must be >= 0 and <= 7\n");
88 return -(EINVAL);
91 if (addr < 0 || addr > 0x7f) {
92 snd_printk ("FX memset: "
93 "addr must be >= 0 and <= 7f\n");
94 return -(EINVAL);
97 if (cnt == 1) {
99 outb (FX_LSB_TRANSFER, dev->fx_lcr);
100 outb (page, dev->fx_dsp_page);
101 outb (addr, dev->fx_dsp_addr);
102 outb ((data[0] >> 8), dev->fx_dsp_msb);
103 outb ((data[0] & 0xff), dev->fx_dsp_lsb);
105 snd_printk ("FX: addr %d:%x set to 0x%x\n",
106 page, addr, data[0]);
108 } else {
109 int i;
111 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev->fx_lcr);
112 outb (page, dev->fx_dsp_page);
113 outb (addr, dev->fx_dsp_addr);
115 for (i = 0; i < cnt; i++) {
116 outb ((data[i] >> 8), dev->fx_dsp_msb);
117 outb ((data[i] & 0xff), dev->fx_dsp_lsb);
118 if (!wavefront_fx_idle (dev)) {
119 break;
123 if (i != cnt) {
124 snd_printk ("FX memset "
125 "(0x%x, 0x%x, 0x%lx, %d) incomplete\n",
126 page, addr, (unsigned long) data, cnt);
127 return -(EIO);
131 return 0;
135 snd_wavefront_fx_detect (snd_wavefront_t *dev)
138 /* This is a crude check, but its the best one I have for now.
139 Certainly on the Maui and the Tropez, wavefront_fx_idle() will
140 report "never idle", which suggests that this test should
141 work OK.
144 if (inb (dev->fx_status) & 0x80) {
145 snd_printk ("Hmm, probably a Maui or Tropez.\n");
146 return -1;
149 return 0;
153 snd_wavefront_fx_open (struct snd_hwdep *hw, struct file *file)
156 if (!try_module_get(hw->card->module))
157 return -EFAULT;
158 file->private_data = hw;
159 return 0;
162 int
163 snd_wavefront_fx_release (struct snd_hwdep *hw, struct file *file)
166 module_put(hw->card->module);
167 return 0;
171 snd_wavefront_fx_ioctl (struct snd_hwdep *sdev, struct file *file,
172 unsigned int cmd, unsigned long arg)
175 struct snd_card *card;
176 snd_wavefront_card_t *acard;
177 snd_wavefront_t *dev;
178 wavefront_fx_info r;
179 unsigned short *page_data = NULL;
180 unsigned short *pd;
181 int err = 0;
183 snd_assert(sdev->card != NULL, return -ENODEV);
185 card = sdev->card;
187 snd_assert(card->private_data != NULL, return -ENODEV);
189 acard = card->private_data;
190 dev = &acard->wavefront;
192 if (copy_from_user (&r, (void __user *)arg, sizeof (wavefront_fx_info)))
193 return -EFAULT;
195 switch (r.request) {
196 case WFFX_MUTE:
197 wavefront_fx_mute (dev, r.data[0]);
198 return -EIO;
200 case WFFX_MEMSET:
201 if (r.data[2] <= 0) {
202 snd_printk ("cannot write "
203 "<= 0 bytes to FX\n");
204 return -EIO;
205 } else if (r.data[2] == 1) {
206 pd = (unsigned short *) &r.data[3];
207 } else {
208 if (r.data[2] > 256) {
209 snd_printk ("cannot write "
210 "> 512 bytes to FX\n");
211 return -EIO;
213 page_data = kmalloc(r.data[2] * sizeof(short), GFP_KERNEL);
214 if (!page_data)
215 return -ENOMEM;
216 if (copy_from_user (page_data,
217 (unsigned char __user *) r.data[3],
218 r.data[2] * sizeof(short))) {
219 kfree(page_data);
220 return -EFAULT;
222 pd = page_data;
225 err = wavefront_fx_memset (dev,
226 r.data[0], /* page */
227 r.data[1], /* addr */
228 r.data[2], /* cnt */
229 pd);
230 kfree(page_data);
231 break;
233 default:
234 snd_printk ("FX: ioctl %d not yet supported\n",
235 r.request);
236 return -ENOTTY;
238 return err;
241 /* YSS225 initialization.
243 This code was developed using DOSEMU. The Turtle Beach SETUPSND
244 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
245 of the port I/O done, using the Yamaha faxback document as a guide
246 to add more logic to the code. Its really pretty weird.
248 This is the approach of just dumping the whole I/O
249 sequence as a series of port/value pairs and a simple loop
250 that outputs it.
253 int __devinit
254 snd_wavefront_fx_start (snd_wavefront_t *dev)
256 unsigned int i;
257 int err;
258 const struct firmware *firmware = NULL;
260 if (dev->fx_initialized)
261 return 0;
263 #ifdef CONFIG_SND_WAVEFRONT_FIRMWARE_IN_KERNEL
264 firmware = &yss225_registers_firmware;
265 #else
266 err = request_firmware(&firmware, "yamaha/yss225_registers.bin",
267 dev->card->dev);
268 if (err < 0) {
269 err = -1;
270 goto out;
272 #endif
274 for (i = 0; i + 1 < firmware->size; i += 2) {
275 if (firmware->data[i] >= 8 && firmware->data[i] < 16) {
276 outb(firmware->data[i + 1],
277 dev->base + firmware->data[i]);
278 } else if (firmware->data[i] == WAIT_IDLE) {
279 if (!wavefront_fx_idle(dev)) {
280 err = -1;
281 goto out;
283 } else {
284 snd_printk(KERN_ERR "invalid address"
285 " in register data\n");
286 err = -1;
287 goto out;
291 dev->fx_initialized = 1;
292 err = 0;
294 out:
295 #ifndef CONFIG_SND_WAVEFRONT_FIRMWARE_IN_KERNEL
296 release_firmware(firmware);
297 #endif
298 return err;
301 #ifndef CONFIG_SND_WAVEFRONT_FIRMWARE_IN_KERNEL
302 MODULE_FIRMWARE("yamaha/yss225_registers.bin");
303 #endif