Linux 4.18.10
[linux/fpc-iii.git] / sound / isa / msnd / msnd.c
blob569897f64fda260c6244b4817c9f31ee974e849c
1 /*********************************************************************
3 * 2002/06/30 Karsten Wiese:
4 * removed kernel-version dependencies.
5 * ripped from linux kernel 2.4.18 (OSS Implementation) by me.
6 * In the OSS Version, this file is compiled to a separate MODULE,
7 * that is used by the pinnacle and the classic driver.
8 * since there is no classic driver for alsa yet (i dont have a classic
9 * & writing one blindfold is difficult) this file's object is statically
10 * linked into the pinnacle-driver-module for now. look for the string
11 * "uncomment this to make this a module again"
12 * to do guess what.
14 * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
16 * msnd.c - Driver Base
18 * Turtle Beach MultiSound Sound Card Driver for Linux
20 * Copyright (C) 1998 Andrew Veliath
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 ********************************************************************/
38 #include <linux/kernel.h>
39 #include <linux/sched/signal.h>
40 #include <linux/types.h>
41 #include <linux/interrupt.h>
42 #include <linux/io.h>
43 #include <linux/fs.h>
44 #include <linux/delay.h>
45 #include <linux/module.h>
47 #include <sound/core.h>
48 #include <sound/initval.h>
49 #include <sound/pcm.h>
50 #include <sound/pcm_params.h>
52 #include "msnd.h"
54 #define LOGNAME "msnd"
57 void snd_msnd_init_queue(void *base, int start, int size)
59 writew(PCTODSP_BASED(start), base + JQS_wStart);
60 writew(PCTODSP_OFFSET(size) - 1, base + JQS_wSize);
61 writew(0, base + JQS_wHead);
62 writew(0, base + JQS_wTail);
64 EXPORT_SYMBOL(snd_msnd_init_queue);
66 static int snd_msnd_wait_TXDE(struct snd_msnd *dev)
68 unsigned int io = dev->io;
69 int timeout = 1000;
71 while (timeout-- > 0)
72 if (inb(io + HP_ISR) & HPISR_TXDE)
73 return 0;
75 return -EIO;
78 static int snd_msnd_wait_HC0(struct snd_msnd *dev)
80 unsigned int io = dev->io;
81 int timeout = 1000;
83 while (timeout-- > 0)
84 if (!(inb(io + HP_CVR) & HPCVR_HC))
85 return 0;
87 return -EIO;
90 int snd_msnd_send_dsp_cmd(struct snd_msnd *dev, u8 cmd)
92 unsigned long flags;
94 spin_lock_irqsave(&dev->lock, flags);
95 if (snd_msnd_wait_HC0(dev) == 0) {
96 outb(cmd, dev->io + HP_CVR);
97 spin_unlock_irqrestore(&dev->lock, flags);
98 return 0;
100 spin_unlock_irqrestore(&dev->lock, flags);
102 snd_printd(KERN_ERR LOGNAME ": Send DSP command timeout\n");
104 return -EIO;
106 EXPORT_SYMBOL(snd_msnd_send_dsp_cmd);
108 int snd_msnd_send_word(struct snd_msnd *dev, unsigned char high,
109 unsigned char mid, unsigned char low)
111 unsigned int io = dev->io;
113 if (snd_msnd_wait_TXDE(dev) == 0) {
114 outb(high, io + HP_TXH);
115 outb(mid, io + HP_TXM);
116 outb(low, io + HP_TXL);
117 return 0;
120 snd_printd(KERN_ERR LOGNAME ": Send host word timeout\n");
122 return -EIO;
124 EXPORT_SYMBOL(snd_msnd_send_word);
126 int snd_msnd_upload_host(struct snd_msnd *dev, const u8 *bin, int len)
128 int i;
130 if (len % 3 != 0) {
131 snd_printk(KERN_ERR LOGNAME
132 ": Upload host data not multiple of 3!\n");
133 return -EINVAL;
136 for (i = 0; i < len; i += 3)
137 if (snd_msnd_send_word(dev, bin[i], bin[i + 1], bin[i + 2]))
138 return -EIO;
140 inb(dev->io + HP_RXL);
141 inb(dev->io + HP_CVR);
143 return 0;
145 EXPORT_SYMBOL(snd_msnd_upload_host);
147 int snd_msnd_enable_irq(struct snd_msnd *dev)
149 unsigned long flags;
151 if (dev->irq_ref++)
152 return 0;
154 snd_printdd(LOGNAME ": Enabling IRQ\n");
156 spin_lock_irqsave(&dev->lock, flags);
157 if (snd_msnd_wait_TXDE(dev) == 0) {
158 outb(inb(dev->io + HP_ICR) | HPICR_TREQ, dev->io + HP_ICR);
159 if (dev->type == msndClassic)
160 outb(dev->irqid, dev->io + HP_IRQM);
162 outb(inb(dev->io + HP_ICR) & ~HPICR_TREQ, dev->io + HP_ICR);
163 outb(inb(dev->io + HP_ICR) | HPICR_RREQ, dev->io + HP_ICR);
164 enable_irq(dev->irq);
165 snd_msnd_init_queue(dev->DSPQ, dev->dspq_data_buff,
166 dev->dspq_buff_size);
167 spin_unlock_irqrestore(&dev->lock, flags);
168 return 0;
170 spin_unlock_irqrestore(&dev->lock, flags);
172 snd_printd(KERN_ERR LOGNAME ": Enable IRQ failed\n");
174 return -EIO;
176 EXPORT_SYMBOL(snd_msnd_enable_irq);
178 int snd_msnd_disable_irq(struct snd_msnd *dev)
180 unsigned long flags;
182 if (--dev->irq_ref > 0)
183 return 0;
185 if (dev->irq_ref < 0)
186 snd_printd(KERN_WARNING LOGNAME ": IRQ ref count is %d\n",
187 dev->irq_ref);
189 snd_printdd(LOGNAME ": Disabling IRQ\n");
191 spin_lock_irqsave(&dev->lock, flags);
192 if (snd_msnd_wait_TXDE(dev) == 0) {
193 outb(inb(dev->io + HP_ICR) & ~HPICR_RREQ, dev->io + HP_ICR);
194 if (dev->type == msndClassic)
195 outb(HPIRQ_NONE, dev->io + HP_IRQM);
196 disable_irq(dev->irq);
197 spin_unlock_irqrestore(&dev->lock, flags);
198 return 0;
200 spin_unlock_irqrestore(&dev->lock, flags);
202 snd_printd(KERN_ERR LOGNAME ": Disable IRQ failed\n");
204 return -EIO;
206 EXPORT_SYMBOL(snd_msnd_disable_irq);
208 static inline long get_play_delay_jiffies(struct snd_msnd *chip, long size)
210 long tmp = (size * HZ * chip->play_sample_size) / 8;
211 return tmp / (chip->play_sample_rate * chip->play_channels);
214 static void snd_msnd_dsp_write_flush(struct snd_msnd *chip)
216 if (!(chip->mode & FMODE_WRITE) || !test_bit(F_WRITING, &chip->flags))
217 return;
218 set_bit(F_WRITEFLUSH, &chip->flags);
219 /* interruptible_sleep_on_timeout(
220 &chip->writeflush,
221 get_play_delay_jiffies(&chip, chip->DAPF.len));*/
222 clear_bit(F_WRITEFLUSH, &chip->flags);
223 if (!signal_pending(current))
224 schedule_timeout_interruptible(
225 get_play_delay_jiffies(chip, chip->play_period_bytes));
226 clear_bit(F_WRITING, &chip->flags);
229 void snd_msnd_dsp_halt(struct snd_msnd *chip, struct file *file)
231 if ((file ? file->f_mode : chip->mode) & FMODE_READ) {
232 clear_bit(F_READING, &chip->flags);
233 snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_STOP);
234 snd_msnd_disable_irq(chip);
235 if (file) {
236 snd_printd(KERN_INFO LOGNAME
237 ": Stopping read for %p\n", file);
238 chip->mode &= ~FMODE_READ;
240 clear_bit(F_AUDIO_READ_INUSE, &chip->flags);
242 if ((file ? file->f_mode : chip->mode) & FMODE_WRITE) {
243 if (test_bit(F_WRITING, &chip->flags)) {
244 snd_msnd_dsp_write_flush(chip);
245 snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_STOP);
247 snd_msnd_disable_irq(chip);
248 if (file) {
249 snd_printd(KERN_INFO
250 LOGNAME ": Stopping write for %p\n", file);
251 chip->mode &= ~FMODE_WRITE;
253 clear_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
256 EXPORT_SYMBOL(snd_msnd_dsp_halt);
259 int snd_msnd_DARQ(struct snd_msnd *chip, int bank)
261 int /*size, n,*/ timeout = 3;
262 u16 wTmp;
263 /* void *DAQD; */
265 /* Increment the tail and check for queue wrap */
266 wTmp = readw(chip->DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
267 if (wTmp > readw(chip->DARQ + JQS_wSize))
268 wTmp = 0;
269 while (wTmp == readw(chip->DARQ + JQS_wHead) && timeout--)
270 udelay(1);
272 if (chip->capturePeriods == 2) {
273 void *pDAQ = chip->mappedbase + DARQ_DATA_BUFF +
274 bank * DAQDS__size + DAQDS_wStart;
275 unsigned short offset = 0x3000 + chip->capturePeriodBytes;
277 if (readw(pDAQ) != PCTODSP_BASED(0x3000))
278 offset = 0x3000;
279 writew(PCTODSP_BASED(offset), pDAQ);
282 writew(wTmp, chip->DARQ + JQS_wTail);
284 #if 0
285 /* Get our digital audio queue struct */
286 DAQD = bank * DAQDS__size + chip->mappedbase + DARQ_DATA_BUFF;
288 /* Get length of data */
289 size = readw(DAQD + DAQDS_wSize);
291 /* Read data from the head (unprotected bank 1 access okay
292 since this is only called inside an interrupt) */
293 outb(HPBLKSEL_1, chip->io + HP_BLKS);
294 n = msnd_fifo_write(&chip->DARF,
295 (char *)(chip->base + bank * DAR_BUFF_SIZE),
296 size, 0);
297 if (n <= 0) {
298 outb(HPBLKSEL_0, chip->io + HP_BLKS);
299 return n;
301 outb(HPBLKSEL_0, chip->io + HP_BLKS);
302 #endif
304 return 1;
306 EXPORT_SYMBOL(snd_msnd_DARQ);
308 int snd_msnd_DAPQ(struct snd_msnd *chip, int start)
310 u16 DAPQ_tail;
311 int protect = start, nbanks = 0;
312 void *DAQD;
313 static int play_banks_submitted;
314 /* unsigned long flags;
315 spin_lock_irqsave(&chip->lock, flags); not necessary */
317 DAPQ_tail = readw(chip->DAPQ + JQS_wTail);
318 while (DAPQ_tail != readw(chip->DAPQ + JQS_wHead) || start) {
319 int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
321 if (start) {
322 start = 0;
323 play_banks_submitted = 0;
326 /* Get our digital audio queue struct */
327 DAQD = bank_num * DAQDS__size + chip->mappedbase +
328 DAPQ_DATA_BUFF;
330 /* Write size of this bank */
331 writew(chip->play_period_bytes, DAQD + DAQDS_wSize);
332 if (play_banks_submitted < 3)
333 ++play_banks_submitted;
334 else if (chip->playPeriods == 2) {
335 unsigned short offset = chip->play_period_bytes;
337 if (readw(DAQD + DAQDS_wStart) != PCTODSP_BASED(0x0))
338 offset = 0;
340 writew(PCTODSP_BASED(offset), DAQD + DAQDS_wStart);
342 ++nbanks;
344 /* Then advance the tail */
346 if (protect)
347 snd_printd(KERN_INFO "B %X %lX\n",
348 bank_num, xtime.tv_usec);
351 DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
352 writew(DAPQ_tail, chip->DAPQ + JQS_wTail);
353 /* Tell the DSP to play the bank */
354 snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_START);
355 if (protect)
356 if (2 == bank_num)
357 break;
360 if (protect)
361 snd_printd(KERN_INFO "%lX\n", xtime.tv_usec);
363 /* spin_unlock_irqrestore(&chip->lock, flags); not necessary */
364 return nbanks;
366 EXPORT_SYMBOL(snd_msnd_DAPQ);
368 static void snd_msnd_play_reset_queue(struct snd_msnd *chip,
369 unsigned int pcm_periods,
370 unsigned int pcm_count)
372 int n;
373 void *pDAQ = chip->mappedbase + DAPQ_DATA_BUFF;
375 chip->last_playbank = -1;
376 chip->playLimit = pcm_count * (pcm_periods - 1);
377 chip->playPeriods = pcm_periods;
378 writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DAPQ + JQS_wHead);
379 writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DAPQ + JQS_wTail);
381 chip->play_period_bytes = pcm_count;
383 for (n = 0; n < pcm_periods; ++n, pDAQ += DAQDS__size) {
384 writew(PCTODSP_BASED((u32)(pcm_count * n)),
385 pDAQ + DAQDS_wStart);
386 writew(0, pDAQ + DAQDS_wSize);
387 writew(1, pDAQ + DAQDS_wFormat);
388 writew(chip->play_sample_size, pDAQ + DAQDS_wSampleSize);
389 writew(chip->play_channels, pDAQ + DAQDS_wChannels);
390 writew(chip->play_sample_rate, pDAQ + DAQDS_wSampleRate);
391 writew(HIMT_PLAY_DONE * 0x100 + n, pDAQ + DAQDS_wIntMsg);
392 writew(n, pDAQ + DAQDS_wFlags);
396 static void snd_msnd_capture_reset_queue(struct snd_msnd *chip,
397 unsigned int pcm_periods,
398 unsigned int pcm_count)
400 int n;
401 void *pDAQ;
402 /* unsigned long flags; */
404 /* snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE); */
406 chip->last_recbank = 2;
407 chip->captureLimit = pcm_count * (pcm_periods - 1);
408 chip->capturePeriods = pcm_periods;
409 writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DARQ + JQS_wHead);
410 writew(PCTODSP_OFFSET(chip->last_recbank * DAQDS__size),
411 chip->DARQ + JQS_wTail);
413 #if 0 /* Critical section: bank 1 access. this is how the OSS driver does it:*/
414 spin_lock_irqsave(&chip->lock, flags);
415 outb(HPBLKSEL_1, chip->io + HP_BLKS);
416 memset_io(chip->mappedbase, 0, DAR_BUFF_SIZE * 3);
417 outb(HPBLKSEL_0, chip->io + HP_BLKS);
418 spin_unlock_irqrestore(&chip->lock, flags);
419 #endif
421 chip->capturePeriodBytes = pcm_count;
422 snd_printdd("snd_msnd_capture_reset_queue() %i\n", pcm_count);
424 pDAQ = chip->mappedbase + DARQ_DATA_BUFF;
426 for (n = 0; n < pcm_periods; ++n, pDAQ += DAQDS__size) {
427 u32 tmp = pcm_count * n;
429 writew(PCTODSP_BASED(tmp + 0x3000), pDAQ + DAQDS_wStart);
430 writew(pcm_count, pDAQ + DAQDS_wSize);
431 writew(1, pDAQ + DAQDS_wFormat);
432 writew(chip->capture_sample_size, pDAQ + DAQDS_wSampleSize);
433 writew(chip->capture_channels, pDAQ + DAQDS_wChannels);
434 writew(chip->capture_sample_rate, pDAQ + DAQDS_wSampleRate);
435 writew(HIMT_RECORD_DONE * 0x100 + n, pDAQ + DAQDS_wIntMsg);
436 writew(n, pDAQ + DAQDS_wFlags);
440 static const struct snd_pcm_hardware snd_msnd_playback = {
441 .info = SNDRV_PCM_INFO_MMAP |
442 SNDRV_PCM_INFO_INTERLEAVED |
443 SNDRV_PCM_INFO_MMAP_VALID |
444 SNDRV_PCM_INFO_BATCH,
445 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
446 .rates = SNDRV_PCM_RATE_8000_48000,
447 .rate_min = 8000,
448 .rate_max = 48000,
449 .channels_min = 1,
450 .channels_max = 2,
451 .buffer_bytes_max = 0x3000,
452 .period_bytes_min = 0x40,
453 .period_bytes_max = 0x1800,
454 .periods_min = 2,
455 .periods_max = 3,
456 .fifo_size = 0,
459 static const struct snd_pcm_hardware snd_msnd_capture = {
460 .info = SNDRV_PCM_INFO_MMAP |
461 SNDRV_PCM_INFO_INTERLEAVED |
462 SNDRV_PCM_INFO_MMAP_VALID |
463 SNDRV_PCM_INFO_BATCH,
464 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
465 .rates = SNDRV_PCM_RATE_8000_48000,
466 .rate_min = 8000,
467 .rate_max = 48000,
468 .channels_min = 1,
469 .channels_max = 2,
470 .buffer_bytes_max = 0x3000,
471 .period_bytes_min = 0x40,
472 .period_bytes_max = 0x1800,
473 .periods_min = 2,
474 .periods_max = 3,
475 .fifo_size = 0,
479 static int snd_msnd_playback_open(struct snd_pcm_substream *substream)
481 struct snd_pcm_runtime *runtime = substream->runtime;
482 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
484 set_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
485 clear_bit(F_WRITING, &chip->flags);
486 snd_msnd_enable_irq(chip);
488 runtime->dma_area = chip->mappedbase;
489 runtime->dma_bytes = 0x3000;
491 chip->playback_substream = substream;
492 runtime->hw = snd_msnd_playback;
493 return 0;
496 static int snd_msnd_playback_close(struct snd_pcm_substream *substream)
498 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
500 snd_msnd_disable_irq(chip);
501 clear_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
502 return 0;
506 static int snd_msnd_playback_hw_params(struct snd_pcm_substream *substream,
507 struct snd_pcm_hw_params *params)
509 int i;
510 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
511 void *pDAQ = chip->mappedbase + DAPQ_DATA_BUFF;
513 chip->play_sample_size = snd_pcm_format_width(params_format(params));
514 chip->play_channels = params_channels(params);
515 chip->play_sample_rate = params_rate(params);
517 for (i = 0; i < 3; ++i, pDAQ += DAQDS__size) {
518 writew(chip->play_sample_size, pDAQ + DAQDS_wSampleSize);
519 writew(chip->play_channels, pDAQ + DAQDS_wChannels);
520 writew(chip->play_sample_rate, pDAQ + DAQDS_wSampleRate);
522 /* dont do this here:
523 * snd_msnd_calibrate_adc(chip->play_sample_rate);
526 return 0;
529 static int snd_msnd_playback_prepare(struct snd_pcm_substream *substream)
531 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
532 unsigned int pcm_size = snd_pcm_lib_buffer_bytes(substream);
533 unsigned int pcm_count = snd_pcm_lib_period_bytes(substream);
534 unsigned int pcm_periods = pcm_size / pcm_count;
536 snd_msnd_play_reset_queue(chip, pcm_periods, pcm_count);
537 chip->playDMAPos = 0;
538 return 0;
541 static int snd_msnd_playback_trigger(struct snd_pcm_substream *substream,
542 int cmd)
544 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
545 int result = 0;
547 if (cmd == SNDRV_PCM_TRIGGER_START) {
548 snd_printdd("snd_msnd_playback_trigger(START)\n");
549 chip->banksPlayed = 0;
550 set_bit(F_WRITING, &chip->flags);
551 snd_msnd_DAPQ(chip, 1);
552 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
553 snd_printdd("snd_msnd_playback_trigger(STop)\n");
554 /* interrupt diagnostic, comment this out later */
555 clear_bit(F_WRITING, &chip->flags);
556 snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_STOP);
557 } else {
558 snd_printd(KERN_ERR "snd_msnd_playback_trigger(?????)\n");
559 result = -EINVAL;
562 snd_printdd("snd_msnd_playback_trigger() ENDE\n");
563 return result;
566 static snd_pcm_uframes_t
567 snd_msnd_playback_pointer(struct snd_pcm_substream *substream)
569 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
571 return bytes_to_frames(substream->runtime, chip->playDMAPos);
575 static const struct snd_pcm_ops snd_msnd_playback_ops = {
576 .open = snd_msnd_playback_open,
577 .close = snd_msnd_playback_close,
578 .ioctl = snd_pcm_lib_ioctl,
579 .hw_params = snd_msnd_playback_hw_params,
580 .prepare = snd_msnd_playback_prepare,
581 .trigger = snd_msnd_playback_trigger,
582 .pointer = snd_msnd_playback_pointer,
585 static int snd_msnd_capture_open(struct snd_pcm_substream *substream)
587 struct snd_pcm_runtime *runtime = substream->runtime;
588 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
590 set_bit(F_AUDIO_READ_INUSE, &chip->flags);
591 snd_msnd_enable_irq(chip);
592 runtime->dma_area = chip->mappedbase + 0x3000;
593 runtime->dma_bytes = 0x3000;
594 memset(runtime->dma_area, 0, runtime->dma_bytes);
595 chip->capture_substream = substream;
596 runtime->hw = snd_msnd_capture;
597 return 0;
600 static int snd_msnd_capture_close(struct snd_pcm_substream *substream)
602 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
604 snd_msnd_disable_irq(chip);
605 clear_bit(F_AUDIO_READ_INUSE, &chip->flags);
606 return 0;
609 static int snd_msnd_capture_prepare(struct snd_pcm_substream *substream)
611 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
612 unsigned int pcm_size = snd_pcm_lib_buffer_bytes(substream);
613 unsigned int pcm_count = snd_pcm_lib_period_bytes(substream);
614 unsigned int pcm_periods = pcm_size / pcm_count;
616 snd_msnd_capture_reset_queue(chip, pcm_periods, pcm_count);
617 chip->captureDMAPos = 0;
618 return 0;
621 static int snd_msnd_capture_trigger(struct snd_pcm_substream *substream,
622 int cmd)
624 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
626 if (cmd == SNDRV_PCM_TRIGGER_START) {
627 chip->last_recbank = -1;
628 set_bit(F_READING, &chip->flags);
629 if (snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_START) == 0)
630 return 0;
632 clear_bit(F_READING, &chip->flags);
633 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
634 clear_bit(F_READING, &chip->flags);
635 snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_STOP);
636 return 0;
638 return -EINVAL;
642 static snd_pcm_uframes_t
643 snd_msnd_capture_pointer(struct snd_pcm_substream *substream)
645 struct snd_pcm_runtime *runtime = substream->runtime;
646 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
648 return bytes_to_frames(runtime, chip->captureDMAPos);
652 static int snd_msnd_capture_hw_params(struct snd_pcm_substream *substream,
653 struct snd_pcm_hw_params *params)
655 int i;
656 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
657 void *pDAQ = chip->mappedbase + DARQ_DATA_BUFF;
659 chip->capture_sample_size = snd_pcm_format_width(params_format(params));
660 chip->capture_channels = params_channels(params);
661 chip->capture_sample_rate = params_rate(params);
663 for (i = 0; i < 3; ++i, pDAQ += DAQDS__size) {
664 writew(chip->capture_sample_size, pDAQ + DAQDS_wSampleSize);
665 writew(chip->capture_channels, pDAQ + DAQDS_wChannels);
666 writew(chip->capture_sample_rate, pDAQ + DAQDS_wSampleRate);
668 return 0;
672 static const struct snd_pcm_ops snd_msnd_capture_ops = {
673 .open = snd_msnd_capture_open,
674 .close = snd_msnd_capture_close,
675 .ioctl = snd_pcm_lib_ioctl,
676 .hw_params = snd_msnd_capture_hw_params,
677 .prepare = snd_msnd_capture_prepare,
678 .trigger = snd_msnd_capture_trigger,
679 .pointer = snd_msnd_capture_pointer,
683 int snd_msnd_pcm(struct snd_card *card, int device)
685 struct snd_msnd *chip = card->private_data;
686 struct snd_pcm *pcm;
687 int err;
689 err = snd_pcm_new(card, "MSNDPINNACLE", device, 1, 1, &pcm);
690 if (err < 0)
691 return err;
693 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_msnd_playback_ops);
694 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_msnd_capture_ops);
696 pcm->private_data = chip;
697 strcpy(pcm->name, "Hurricane");
699 return 0;
701 EXPORT_SYMBOL(snd_msnd_pcm);
703 MODULE_DESCRIPTION("Common routines for Turtle Beach Multisound drivers");
704 MODULE_LICENSE("GPL");