Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * 2002/06/30 Karsten Wiese:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	removed kernel-version dependencies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	ripped from linux kernel 2.4.18 (OSS Implementation) by me.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	In the OSS Version, this file is compiled to a separate MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	that is used by the pinnacle and the classic driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	since there is no classic driver for alsa yet (i dont have a classic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	& writing one blindfold is difficult) this file's object is statically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	linked into the pinnacle-driver-module for now.	look for the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *		"uncomment this to make this a module again"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *	to do guess what.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * msnd.c - Driver Base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Turtle Beach MultiSound Sound Card Driver for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * Copyright (C) 1998 Andrew Veliath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  ********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "msnd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define LOGNAME			"msnd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) void snd_msnd_init_queue(void __iomem *base, int start, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	writew(PCTODSP_BASED(start), base + JQS_wStart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	writew(PCTODSP_OFFSET(size) - 1, base + JQS_wSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	writew(0, base + JQS_wHead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	writew(0, base + JQS_wTail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) EXPORT_SYMBOL(snd_msnd_init_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int snd_msnd_wait_TXDE(struct snd_msnd *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	unsigned int io = dev->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int timeout = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	while (timeout-- > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		if (inb(io + HP_ISR) & HPISR_TXDE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int snd_msnd_wait_HC0(struct snd_msnd *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned int io = dev->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int timeout = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	while (timeout-- > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		if (!(inb(io + HP_CVR) & HPCVR_HC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) int snd_msnd_send_dsp_cmd(struct snd_msnd *dev, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	spin_lock_irqsave(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (snd_msnd_wait_HC0(dev) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		outb(cmd, dev->io + HP_CVR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		spin_unlock_irqrestore(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	spin_unlock_irqrestore(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	snd_printd(KERN_ERR LOGNAME ": Send DSP command timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) EXPORT_SYMBOL(snd_msnd_send_dsp_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) int snd_msnd_send_word(struct snd_msnd *dev, unsigned char high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		   unsigned char mid, unsigned char low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	unsigned int io = dev->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (snd_msnd_wait_TXDE(dev) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		outb(high, io + HP_TXH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		outb(mid, io + HP_TXM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		outb(low, io + HP_TXL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	snd_printd(KERN_ERR LOGNAME ": Send host word timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) EXPORT_SYMBOL(snd_msnd_send_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int snd_msnd_upload_host(struct snd_msnd *dev, const u8 *bin, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (len % 3 != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		snd_printk(KERN_ERR LOGNAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			   ": Upload host data not multiple of 3!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	for (i = 0; i < len; i += 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (snd_msnd_send_word(dev, bin[i], bin[i + 1], bin[i + 2]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	inb(dev->io + HP_RXL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	inb(dev->io + HP_CVR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) EXPORT_SYMBOL(snd_msnd_upload_host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int snd_msnd_enable_irq(struct snd_msnd *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (dev->irq_ref++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	snd_printdd(LOGNAME ": Enabling IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	spin_lock_irqsave(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (snd_msnd_wait_TXDE(dev) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		outb(inb(dev->io + HP_ICR) | HPICR_TREQ, dev->io + HP_ICR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (dev->type == msndClassic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			outb(dev->irqid, dev->io + HP_IRQM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		outb(inb(dev->io + HP_ICR) & ~HPICR_TREQ, dev->io + HP_ICR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		outb(inb(dev->io + HP_ICR) | HPICR_RREQ, dev->io + HP_ICR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		enable_irq(dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		snd_msnd_init_queue(dev->DSPQ, dev->dspq_data_buff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				    dev->dspq_buff_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		spin_unlock_irqrestore(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	spin_unlock_irqrestore(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	snd_printd(KERN_ERR LOGNAME ": Enable IRQ failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) EXPORT_SYMBOL(snd_msnd_enable_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int snd_msnd_disable_irq(struct snd_msnd *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (--dev->irq_ref > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (dev->irq_ref < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		snd_printd(KERN_WARNING LOGNAME ": IRQ ref count is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			   dev->irq_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	snd_printdd(LOGNAME ": Disabling IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	spin_lock_irqsave(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (snd_msnd_wait_TXDE(dev) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		outb(inb(dev->io + HP_ICR) & ~HPICR_RREQ, dev->io + HP_ICR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		if (dev->type == msndClassic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			outb(HPIRQ_NONE, dev->io + HP_IRQM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		disable_irq(dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		spin_unlock_irqrestore(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	spin_unlock_irqrestore(&dev->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	snd_printd(KERN_ERR LOGNAME ": Disable IRQ failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) EXPORT_SYMBOL(snd_msnd_disable_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static inline long get_play_delay_jiffies(struct snd_msnd *chip, long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	long tmp = (size * HZ * chip->play_sample_size) / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return tmp / (chip->play_sample_rate * chip->play_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static void snd_msnd_dsp_write_flush(struct snd_msnd *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!(chip->mode & FMODE_WRITE) || !test_bit(F_WRITING, &chip->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	set_bit(F_WRITEFLUSH, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /*	interruptible_sleep_on_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		&chip->writeflush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		get_play_delay_jiffies(&chip, chip->DAPF.len));*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	clear_bit(F_WRITEFLUSH, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (!signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		schedule_timeout_interruptible(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			get_play_delay_jiffies(chip, chip->play_period_bytes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	clear_bit(F_WRITING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) void snd_msnd_dsp_halt(struct snd_msnd *chip, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if ((file ? file->f_mode : chip->mode) & FMODE_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		clear_bit(F_READING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		snd_msnd_disable_irq(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			snd_printd(KERN_INFO LOGNAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				   ": Stopping read for %p\n", file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			chip->mode &= ~FMODE_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		clear_bit(F_AUDIO_READ_INUSE, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if ((file ? file->f_mode : chip->mode) & FMODE_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		if (test_bit(F_WRITING, &chip->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			snd_msnd_dsp_write_flush(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		snd_msnd_disable_irq(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			snd_printd(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				   LOGNAME ": Stopping write for %p\n", file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			chip->mode &= ~FMODE_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		clear_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) EXPORT_SYMBOL(snd_msnd_dsp_halt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int snd_msnd_DARQ(struct snd_msnd *chip, int bank)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int /*size, n,*/ timeout = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	u16 wTmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	/* void *DAQD; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/* Increment the tail and check for queue wrap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	wTmp = readw(chip->DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (wTmp > readw(chip->DARQ + JQS_wSize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		wTmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	while (wTmp == readw(chip->DARQ + JQS_wHead) && timeout--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (chip->capturePeriods == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		void __iomem *pDAQ = chip->mappedbase + DARQ_DATA_BUFF +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			     bank * DAQDS__size + DAQDS_wStart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		unsigned short offset = 0x3000 + chip->capturePeriodBytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (readw(pDAQ) != PCTODSP_BASED(0x3000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			offset = 0x3000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		writew(PCTODSP_BASED(offset), pDAQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	writew(wTmp, chip->DARQ + JQS_wTail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* Get our digital audio queue struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	DAQD = bank * DAQDS__size + chip->mappedbase + DARQ_DATA_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/* Get length of data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	size = readw(DAQD + DAQDS_wSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/* Read data from the head (unprotected bank 1 access okay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	   since this is only called inside an interrupt) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	outb(HPBLKSEL_1, chip->io + HP_BLKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	n = msnd_fifo_write(&chip->DARF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			    (char *)(chip->base + bank * DAR_BUFF_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			    size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (n <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		outb(HPBLKSEL_0, chip->io + HP_BLKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	outb(HPBLKSEL_0, chip->io + HP_BLKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) EXPORT_SYMBOL(snd_msnd_DARQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int snd_msnd_DAPQ(struct snd_msnd *chip, int start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	u16	DAPQ_tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	int	protect = start, nbanks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	void	__iomem *DAQD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	static int play_banks_submitted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	/* unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	spin_lock_irqsave(&chip->lock, flags); not necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	DAPQ_tail = readw(chip->DAPQ + JQS_wTail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	while (DAPQ_tail != readw(chip->DAPQ + JQS_wHead) || start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		if (start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			play_banks_submitted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		/* Get our digital audio queue struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		DAQD = bank_num * DAQDS__size + chip->mappedbase +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			DAPQ_DATA_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		/* Write size of this bank */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		writew(chip->play_period_bytes, DAQD + DAQDS_wSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		if (play_banks_submitted < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			++play_banks_submitted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		else if (chip->playPeriods == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			unsigned short offset = chip->play_period_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			if (readw(DAQD + DAQDS_wStart) != PCTODSP_BASED(0x0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			writew(PCTODSP_BASED(offset), DAQD + DAQDS_wStart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		++nbanks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		/* Then advance the tail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		if (protect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			snd_printd(KERN_INFO "B %X %lX\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				   bank_num, xtime.tv_usec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		writew(DAPQ_tail, chip->DAPQ + JQS_wTail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		/* Tell the DSP to play the bank */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		if (protect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			if (2 == bank_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (protect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		snd_printd(KERN_INFO "%lX\n", xtime.tv_usec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/* spin_unlock_irqrestore(&chip->lock, flags); not necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return nbanks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) EXPORT_SYMBOL(snd_msnd_DAPQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static void snd_msnd_play_reset_queue(struct snd_msnd *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				      unsigned int pcm_periods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				      unsigned int pcm_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	int	n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	void	__iomem *pDAQ = chip->mappedbase + DAPQ_DATA_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	chip->last_playbank = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	chip->playLimit = pcm_count * (pcm_periods - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	chip->playPeriods = pcm_periods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DAPQ + JQS_wHead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DAPQ + JQS_wTail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	chip->play_period_bytes = pcm_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	for (n = 0; n < pcm_periods; ++n, pDAQ += DAQDS__size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		writew(PCTODSP_BASED((u32)(pcm_count * n)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			pDAQ + DAQDS_wStart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		writew(0, pDAQ + DAQDS_wSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		writew(1, pDAQ + DAQDS_wFormat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		writew(chip->play_sample_size, pDAQ + DAQDS_wSampleSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		writew(chip->play_channels, pDAQ + DAQDS_wChannels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		writew(chip->play_sample_rate, pDAQ + DAQDS_wSampleRate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		writew(HIMT_PLAY_DONE * 0x100 + n, pDAQ + DAQDS_wIntMsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		writew(n, pDAQ + DAQDS_wFlags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void snd_msnd_capture_reset_queue(struct snd_msnd *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 					 unsigned int pcm_periods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 					 unsigned int pcm_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	int		n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	void		__iomem *pDAQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	/* unsigned long	flags; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	/* snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	chip->last_recbank = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	chip->captureLimit = pcm_count * (pcm_periods - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	chip->capturePeriods = pcm_periods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DARQ + JQS_wHead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	writew(PCTODSP_OFFSET(chip->last_recbank * DAQDS__size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		chip->DARQ + JQS_wTail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) #if 0 /* Critical section: bank 1 access. this is how the OSS driver does it:*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	spin_lock_irqsave(&chip->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	outb(HPBLKSEL_1, chip->io + HP_BLKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	memset_io(chip->mappedbase, 0, DAR_BUFF_SIZE * 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	outb(HPBLKSEL_0, chip->io + HP_BLKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	spin_unlock_irqrestore(&chip->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	chip->capturePeriodBytes = pcm_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	snd_printdd("snd_msnd_capture_reset_queue() %i\n", pcm_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	pDAQ = chip->mappedbase + DARQ_DATA_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	for (n = 0; n < pcm_periods; ++n, pDAQ += DAQDS__size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		u32 tmp = pcm_count * n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		writew(PCTODSP_BASED(tmp + 0x3000), pDAQ + DAQDS_wStart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		writew(pcm_count, pDAQ + DAQDS_wSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		writew(1, pDAQ + DAQDS_wFormat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		writew(chip->capture_sample_size, pDAQ + DAQDS_wSampleSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		writew(chip->capture_channels, pDAQ + DAQDS_wChannels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		writew(chip->capture_sample_rate, pDAQ + DAQDS_wSampleRate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		writew(HIMT_RECORD_DONE * 0x100 + n, pDAQ + DAQDS_wIntMsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		writew(n, pDAQ + DAQDS_wFlags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static const struct snd_pcm_hardware snd_msnd_playback = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	.info =			SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 				SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 				SNDRV_PCM_INFO_MMAP_VALID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 				SNDRV_PCM_INFO_BATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	.rates =		SNDRV_PCM_RATE_8000_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	.rate_min =		8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	.rate_max =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	.channels_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	.channels_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	.buffer_bytes_max =	0x3000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	.period_bytes_min =	0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	.period_bytes_max =	0x1800,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.periods_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	.periods_max =		3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static const struct snd_pcm_hardware snd_msnd_capture = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	.info =			SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 				SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 				SNDRV_PCM_INFO_MMAP_VALID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 				SNDRV_PCM_INFO_BATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	.rates =		SNDRV_PCM_RATE_8000_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	.rate_min =		8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	.rate_max =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	.channels_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	.channels_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	.buffer_bytes_max =	0x3000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	.period_bytes_min =	0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	.period_bytes_max =	0x1800,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	.periods_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	.periods_max =		3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static int snd_msnd_playback_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	set_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	clear_bit(F_WRITING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	snd_msnd_enable_irq(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	runtime->dma_area = (__force void *)chip->mappedbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	runtime->dma_bytes = 0x3000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	chip->playback_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	runtime->hw = snd_msnd_playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static int snd_msnd_playback_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	snd_msnd_disable_irq(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	clear_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static int snd_msnd_playback_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 					struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	int	i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	void	__iomem *pDAQ =	chip->mappedbase + DAPQ_DATA_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	chip->play_sample_size = snd_pcm_format_width(params_format(params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	chip->play_channels = params_channels(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	chip->play_sample_rate = params_rate(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	for (i = 0; i < 3; ++i, pDAQ += DAQDS__size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		writew(chip->play_sample_size, pDAQ + DAQDS_wSampleSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		writew(chip->play_channels, pDAQ + DAQDS_wChannels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		writew(chip->play_sample_rate, pDAQ + DAQDS_wSampleRate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	/* dont do this here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	 * snd_msnd_calibrate_adc(chip->play_sample_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static int snd_msnd_playback_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	unsigned int pcm_size = snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	unsigned int pcm_count = snd_pcm_lib_period_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	unsigned int pcm_periods = pcm_size / pcm_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	snd_msnd_play_reset_queue(chip, pcm_periods, pcm_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	chip->playDMAPos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static int snd_msnd_playback_trigger(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 				     int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	int	result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	if (cmd == SNDRV_PCM_TRIGGER_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		snd_printdd("snd_msnd_playback_trigger(START)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		chip->banksPlayed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		set_bit(F_WRITING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		snd_msnd_DAPQ(chip, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	} else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		snd_printdd("snd_msnd_playback_trigger(STop)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		/* interrupt diagnostic, comment this out later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		clear_bit(F_WRITING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		snd_printd(KERN_ERR "snd_msnd_playback_trigger(?????)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	snd_printdd("snd_msnd_playback_trigger() ENDE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static snd_pcm_uframes_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) snd_msnd_playback_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	return bytes_to_frames(substream->runtime, chip->playDMAPos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static const struct snd_pcm_ops snd_msnd_playback_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	.open =		snd_msnd_playback_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	.close =	snd_msnd_playback_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	.hw_params =	snd_msnd_playback_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	.prepare =	snd_msnd_playback_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	.trigger =	snd_msnd_playback_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	.pointer =	snd_msnd_playback_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static int snd_msnd_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	set_bit(F_AUDIO_READ_INUSE, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	snd_msnd_enable_irq(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	runtime->dma_area = (__force void *)chip->mappedbase + 0x3000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	runtime->dma_bytes = 0x3000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	memset(runtime->dma_area, 0, runtime->dma_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	chip->capture_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	runtime->hw = snd_msnd_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static int snd_msnd_capture_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	snd_msnd_disable_irq(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	clear_bit(F_AUDIO_READ_INUSE, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static int snd_msnd_capture_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	unsigned int pcm_size = snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	unsigned int pcm_count = snd_pcm_lib_period_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	unsigned int pcm_periods = pcm_size / pcm_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	snd_msnd_capture_reset_queue(chip, pcm_periods, pcm_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	chip->captureDMAPos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static int snd_msnd_capture_trigger(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 				    int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	if (cmd == SNDRV_PCM_TRIGGER_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		chip->last_recbank = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		set_bit(F_READING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		if (snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_START) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		clear_bit(F_READING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	} else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		clear_bit(F_READING, &chip->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static snd_pcm_uframes_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) snd_msnd_capture_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	return bytes_to_frames(runtime, chip->captureDMAPos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static int snd_msnd_capture_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 					struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	int		i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	struct snd_msnd *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	void		__iomem *pDAQ = chip->mappedbase + DARQ_DATA_BUFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	chip->capture_sample_size = snd_pcm_format_width(params_format(params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	chip->capture_channels = params_channels(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	chip->capture_sample_rate = params_rate(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	for (i = 0; i < 3; ++i, pDAQ += DAQDS__size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		writew(chip->capture_sample_size, pDAQ + DAQDS_wSampleSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		writew(chip->capture_channels, pDAQ + DAQDS_wChannels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		writew(chip->capture_sample_rate, pDAQ + DAQDS_wSampleRate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static const struct snd_pcm_ops snd_msnd_capture_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	.open =		snd_msnd_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	.close =	snd_msnd_capture_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	.hw_params =	snd_msnd_capture_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	.prepare =	snd_msnd_capture_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	.trigger =	snd_msnd_capture_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	.pointer =	snd_msnd_capture_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) int snd_msnd_pcm(struct snd_card *card, int device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	struct snd_msnd *chip = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	struct snd_pcm	*pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	err = snd_pcm_new(card, "MSNDPINNACLE", device, 1, 1, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_msnd_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_msnd_capture_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	pcm->private_data = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	strcpy(pcm->name, "Hurricane");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) EXPORT_SYMBOL(snd_msnd_pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) MODULE_DESCRIPTION("Common routines for Turtle Beach Multisound drivers");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)