29 #include <linux/stddef.h>
30 #include <linux/string.h>
38 #define NEUTRAL16 0x00
41 static int dma_ioctl(
int dev,
unsigned int cmd,
void __user *
arg);
43 static int set_format(
int dev,
int fmt)
76 int mode = translate_mode(file);
92 if (!try_module_get(driver->
owner))
99 if (!try_module_get(coprocessor->
owner))
113 set_format(dev, bits);
124 module_put(coprocessor->
owner);
130 module_put(driver->
owner);
135 static void sync_output(
int dev)
164 for (i = dmap->
qlen + 1; i < dmap->
nbufs; i++)
166 p = (p + 1) % dmap->
nbufs;
182 int mode = translate_mode(file);
204 module_put(coprocessor->
owner);
211 static void translate_bytes(
const unsigned char *
table,
unsigned char *buff,
int n)
218 for (i = 0; i <
n; ++
i)
219 buff[i] = table[buff[i]];
271 printk(
KERN_ERR "audio: Buffer error 3 (%lx,%d), (%lx, %d)\n", (
long) dma_buf, l, (
long)
audio_devs[dev]->dmap_out->raw_buf, (
int)
audio_devs[dev]->dmap_out->buffsize);
274 if (dma_buf <
audio_devs[dev]->dmap_out->raw_buf)
292 translate_bytes(ulaw_dsp, (
unsigned char *) dma_buf, l);
349 translate_bytes(dsp_ulaw, (
unsigned char *) dmabuf, l);
353 char *fixit = dmabuf;
389 if (
audio_devs[dev]->dmap_out->fragment_size == 0)
399 if (
audio_devs[dev]->dmap_out->fragment_size == 0)
418 val = set_format(dev, val);
426 return dma_ioctl(dev, cmd, arg);
433 return dma_ioctl(dev, cmd, arg);
438 spin_unlock(&file->
f_lock);
467 if (val > 1 || val < 0)
521 spin_unlock_irqrestore(&dmap->
lock,flags);
526 return dma_ioctl(dev, cmd, arg);
547 unsigned sr, nc, sz, bsz;
549 sr = dsp_dev->
d->set_speed(dev, 0);
550 nc = dsp_dev->
d->set_channels(dev, 0);
551 sz = dsp_dev->
d->set_bits(dev, 0);
558 if (sr < 1 || nc < 1 || sz < 1)
632 #ifdef OS_DMA_ALIGN_CHECK
633 OS_DMA_ALIGN_CHECK(bsz);
658 for (i = 0; i < dmap->
nbufs; i++)
666 static int dma_subdivide(
int dev,
struct dma_buffparms *dmap,
int fact)
681 if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact != 16)
688 static int dma_set_fragment(
int dev,
struct dma_buffparms *dmap,
int fact)
699 bytes = fact & 0xffff;
700 count = (fact >> 16) & 0x7fff;
707 if (bytes < 4 || bytes > 17)
721 #ifdef OS_DMA_MINBITS
722 if (bytes < OS_DMA_MINBITS)
723 bytes = OS_DMA_MINBITS;
737 return bytes | ((count - 1) << 16);
740 static int dma_ioctl(
int dev,
unsigned int cmd,
void __user *
arg)
754 if (
get_user(fact, (
int __user *)arg))
757 ret = dma_subdivide(dev, dmap_out, fact);
763 ret = dma_subdivide(dev, dmap_in, fact);
822 if (
get_user(bits, (
int __user *)arg))
831 if (bits & PCM_ENABLE_INPUT)
838 if ((err =
audio_devs[dev]->
d->prepare_for_input(dev,
840 spin_unlock_irqrestore(&dmap_in->
lock,flags);
848 spin_unlock_irqrestore(&dmap_in->
lock,flags);
850 if (bits & PCM_ENABLE_OUTPUT)
866 spin_unlock_irqrestore(&dmap_out->
lock,flags);
897 spin_unlock_irqrestore(&dmap_in->
lock,flags);
915 spin_unlock_irqrestore(&dmap_out->
lock,flags);
938 spin_unlock_irqrestore(&dmap_out->
lock,flags);
963 if (
get_user(fact, (
int __user *)arg))
966 ret = dma_set_fragment(dev, dmap_out, fact);
972 ret = dma_set_fragment(dev, dmap_in, fact);
984 return put_user(ret, (
int __user *)arg);