2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* device driver for philips saa7134 based TV cards
|
|
|
|
* oss dsp interface
|
|
|
|
*
|
|
|
|
* (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
|
2005-11-13 17:08:00 -07:00
|
|
|
* 2005 conversion to standalone module:
|
|
|
|
* Ricardo Cerqueira <v4l@cerqueira.org>
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/kernel.h>
|
2005-11-13 17:08:00 -07:00
|
|
|
#include <linux/interrupt.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/slab.h>
|
2005-11-13 17:08:00 -07:00
|
|
|
#include <linux/sound.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/soundcard.h>
|
|
|
|
|
|
|
|
#include "saa7134-reg.h"
|
|
|
|
#include "saa7134.h"
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
2005-11-13 17:08:00 -07:00
|
|
|
static unsigned int debug = 0;
|
|
|
|
module_param(debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(debug,"enable debug messages [oss]");
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-13 17:08:00 -07:00
|
|
|
static unsigned int rate = 0;
|
|
|
|
module_param(rate, int, 0444);
|
|
|
|
MODULE_PARM_DESC(rate,"sample rate (valid are: 32000,48000)");
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-13 17:08:00 -07:00
|
|
|
static unsigned int dsp_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
|
|
|
|
MODULE_PARM_DESC(dsp_nr, "device numbers for SAA7134 capture interface(s).");
|
|
|
|
module_param_array(dsp_nr, int, NULL, 0444);
|
|
|
|
|
|
|
|
static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
|
|
|
|
MODULE_PARM_DESC(mixer_nr, "mixer numbers for SAA7134 capture interface(s).");
|
|
|
|
module_param_array(mixer_nr, int, NULL, 0444);
|
|
|
|
|
|
|
|
#define dprintk(fmt, arg...) if (debug) \
|
2005-04-16 15:20:36 -07:00
|
|
|
printk(KERN_DEBUG "%s/oss: " fmt, dev->name , ## arg)
|
|
|
|
|
2005-11-08 22:37:11 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks)
|
|
|
|
{
|
|
|
|
if (blksize < 0x100)
|
|
|
|
blksize = 0x100;
|
|
|
|
if (blksize > 0x10000)
|
|
|
|
blksize = 0x10000;
|
|
|
|
|
|
|
|
if (blocks < 2)
|
|
|
|
blocks = 2;
|
|
|
|
if ((blksize * blocks) > 1024*1024)
|
|
|
|
blocks = 1024*1024 / blksize;
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.blocks = blocks;
|
|
|
|
dev->dmasound.blksize = blksize;
|
|
|
|
dev->dmasound.bufsize = blksize * blocks;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
dprintk("buffer config: %d blocks / %d bytes, %d kB total\n",
|
2005-11-08 22:37:43 -07:00
|
|
|
blocks,blksize,blksize * blocks / 1024);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dsp_buffer_init(struct saa7134_dev *dev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2006-03-13 09:17:11 -07:00
|
|
|
BUG_ON(!dev->dmasound.bufsize);
|
2005-11-08 22:38:54 -07:00
|
|
|
videobuf_dma_init(&dev->dmasound.dma);
|
|
|
|
err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE,
|
|
|
|
(dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
|
2005-04-16 15:20:36 -07:00
|
|
|
if (0 != err)
|
|
|
|
return err;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dsp_buffer_free(struct saa7134_dev *dev)
|
|
|
|
{
|
2006-03-13 09:17:11 -07:00
|
|
|
BUG_ON(!dev->dmasound.blksize);
|
2005-11-08 22:38:54 -07:00
|
|
|
videobuf_dma_free(&dev->dmasound.dma);
|
|
|
|
dev->dmasound.blocks = 0;
|
|
|
|
dev->dmasound.blksize = 0;
|
|
|
|
dev->dmasound.bufsize = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsp_dma_start(struct saa7134_dev *dev)
|
|
|
|
{
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.dma_blk = 0;
|
|
|
|
dev->dmasound.dma_running = 1;
|
2005-04-16 15:20:36 -07:00
|
|
|
saa7134_set_dmabits(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsp_dma_stop(struct saa7134_dev *dev)
|
|
|
|
{
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.dma_blk = -1;
|
|
|
|
dev->dmasound.dma_running = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
saa7134_set_dmabits(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dsp_rec_start(struct saa7134_dev *dev)
|
|
|
|
{
|
|
|
|
int err, bswap, sign;
|
|
|
|
u32 fmt, control;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* prepare buffer */
|
2006-03-10 08:29:15 -07:00
|
|
|
if (0 != (err = videobuf_pci_dma_map(dev->pci,&dev->dmasound.dma)))
|
2005-04-16 15:20:36 -07:00
|
|
|
return err;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt)))
|
2005-04-16 15:20:36 -07:00
|
|
|
goto fail1;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->dmasound.pt,
|
|
|
|
dev->dmasound.dma.sglist,
|
|
|
|
dev->dmasound.dma.sglen,
|
2005-04-16 15:20:36 -07:00
|
|
|
0)))
|
|
|
|
goto fail2;
|
|
|
|
|
|
|
|
/* sample format */
|
2005-11-08 22:38:54 -07:00
|
|
|
switch (dev->dmasound.afmt) {
|
2005-04-16 15:20:36 -07:00
|
|
|
case AFMT_U8:
|
|
|
|
case AFMT_S8: fmt = 0x00; break;
|
|
|
|
case AFMT_U16_LE:
|
|
|
|
case AFMT_U16_BE:
|
|
|
|
case AFMT_S16_LE:
|
|
|
|
case AFMT_S16_BE: fmt = 0x01; break;
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
goto fail2;
|
|
|
|
}
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
switch (dev->dmasound.afmt) {
|
2005-04-16 15:20:36 -07:00
|
|
|
case AFMT_S8:
|
|
|
|
case AFMT_S16_LE:
|
|
|
|
case AFMT_S16_BE: sign = 1; break;
|
|
|
|
default: sign = 0; break;
|
|
|
|
}
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
switch (dev->dmasound.afmt) {
|
2005-04-16 15:20:36 -07:00
|
|
|
case AFMT_U16_BE:
|
|
|
|
case AFMT_S16_BE: bswap = 1; break;
|
|
|
|
default: bswap = 0; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dev->pci->device) {
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7134:
|
2005-11-08 22:38:54 -07:00
|
|
|
if (1 == dev->dmasound.channels)
|
2005-04-16 15:20:36 -07:00
|
|
|
fmt |= (1 << 3);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (2 == dev->dmasound.channels)
|
2005-04-16 15:20:36 -07:00
|
|
|
fmt |= (3 << 3);
|
|
|
|
if (sign)
|
|
|
|
fmt |= 0x04;
|
2005-11-08 22:38:54 -07:00
|
|
|
fmt |= (TV == dev->dmasound.input) ? 0xc0 : 0x80;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->dmasound.blksize - 1) & 0x0000ff));
|
|
|
|
saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->dmasound.blksize - 1) & 0x00ff00) >> 8);
|
|
|
|
saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->dmasound.blksize - 1) & 0xff0000) >> 16);
|
2005-04-16 15:20:36 -07:00
|
|
|
saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt);
|
2005-06-23 22:05:09 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
break;
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7133:
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7135:
|
2005-11-08 22:38:54 -07:00
|
|
|
if (1 == dev->dmasound.channels)
|
2005-04-16 15:20:36 -07:00
|
|
|
fmt |= (1 << 4);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (2 == dev->dmasound.channels)
|
2005-04-16 15:20:36 -07:00
|
|
|
fmt |= (2 << 4);
|
|
|
|
if (!sign)
|
|
|
|
fmt |= 0x04;
|
2005-11-08 22:38:54 -07:00
|
|
|
saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -4);
|
2005-11-08 22:37:11 -07:00
|
|
|
saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24));
|
2005-04-16 15:20:36 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.afmt, dev->dmasound.channels, fmt,
|
2005-04-16 15:20:36 -07:00
|
|
|
bswap ? 'b' : '-');
|
|
|
|
|
|
|
|
/* dma: setup channel 6 (= AUDIO) */
|
|
|
|
control = SAA7134_RS_CONTROL_BURST_16 |
|
|
|
|
SAA7134_RS_CONTROL_ME |
|
2005-11-08 22:38:54 -07:00
|
|
|
(dev->dmasound.pt.dma >> 12);
|
2005-04-16 15:20:36 -07:00
|
|
|
if (bswap)
|
|
|
|
control |= SAA7134_RS_CONTROL_BSWAP;
|
|
|
|
saa_writel(SAA7134_RS_BA1(6),0);
|
2005-11-08 22:38:54 -07:00
|
|
|
saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize);
|
2005-04-16 15:20:36 -07:00
|
|
|
saa_writel(SAA7134_RS_PITCH(6),0);
|
|
|
|
saa_writel(SAA7134_RS_CONTROL(6),control);
|
|
|
|
|
|
|
|
/* start dma */
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.recording_on = 1;
|
2005-04-16 15:20:36 -07:00
|
|
|
spin_lock_irqsave(&dev->slock,flags);
|
|
|
|
dsp_dma_start(dev);
|
|
|
|
spin_unlock_irqrestore(&dev->slock,flags);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail2:
|
2005-11-08 22:38:54 -07:00
|
|
|
saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
|
2005-04-16 15:20:36 -07:00
|
|
|
fail1:
|
2006-03-10 08:29:15 -07:00
|
|
|
videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
|
2005-04-16 15:20:36 -07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dsp_rec_stop(struct saa7134_dev *dev)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
dprintk("rec_stop dma_blk=%d\n",dev->dmasound.dma_blk);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* stop dma */
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.recording_on = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
spin_lock_irqsave(&dev->slock,flags);
|
|
|
|
dsp_dma_stop(dev);
|
|
|
|
spin_unlock_irqrestore(&dev->slock,flags);
|
|
|
|
|
|
|
|
/* unlock buffer */
|
2005-11-08 22:38:54 -07:00
|
|
|
saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
|
2006-03-10 08:29:15 -07:00
|
|
|
videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
static int dsp_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
int minor = iminor(inode);
|
|
|
|
struct saa7134_dev *h,*dev = NULL;
|
|
|
|
struct list_head *list;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
list_for_each(list,&saa7134_devlist) {
|
|
|
|
h = list_entry(list, struct saa7134_dev, devlist);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (h->dmasound.minor_dsp == minor)
|
2005-04-16 15:20:36 -07:00
|
|
|
dev = h;
|
|
|
|
}
|
|
|
|
if (NULL == dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
err = -EBUSY;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (dev->dmasound.users_dsp)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto fail1;
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.users_dsp++;
|
2005-04-16 15:20:36 -07:00
|
|
|
file->private_data = dev;
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.afmt = AFMT_U8;
|
|
|
|
dev->dmasound.channels = 1;
|
|
|
|
dev->dmasound.read_count = 0;
|
|
|
|
dev->dmasound.read_offset = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_buffer_conf(dev,PAGE_SIZE,64);
|
|
|
|
err = dsp_buffer_init(dev);
|
|
|
|
if (0 != err)
|
|
|
|
goto fail2;
|
|
|
|
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail2:
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.users_dsp--;
|
2005-04-16 15:20:36 -07:00
|
|
|
fail1:
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dsp_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct saa7134_dev *dev = file->private_data;
|
|
|
|
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (dev->dmasound.recording_on)
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_rec_stop(dev);
|
|
|
|
dsp_buffer_free(dev);
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.users_dsp--;
|
2005-04-16 15:20:36 -07:00
|
|
|
file->private_data = NULL;
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dsp_read(struct file *file, char __user *buffer,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct saa7134_dev *dev = file->private_data;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
unsigned int bytes;
|
|
|
|
unsigned long flags;
|
|
|
|
int err,ret = 0;
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
add_wait_queue(&dev->dmasound.wq, &wait);
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
while (count > 0) {
|
|
|
|
/* wait for data if needed */
|
2005-11-08 22:38:54 -07:00
|
|
|
if (0 == dev->dmasound.read_count) {
|
|
|
|
if (!dev->dmasound.recording_on) {
|
2005-04-16 15:20:36 -07:00
|
|
|
err = dsp_rec_start(dev);
|
|
|
|
if (err < 0) {
|
|
|
|
if (0 == ret)
|
|
|
|
ret = err;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-08 22:38:54 -07:00
|
|
|
if (dev->dmasound.recording_on &&
|
|
|
|
!dev->dmasound.dma_running) {
|
2005-04-16 15:20:36 -07:00
|
|
|
/* recover from overruns */
|
|
|
|
spin_lock_irqsave(&dev->slock,flags);
|
|
|
|
dsp_dma_start(dev);
|
|
|
|
spin_unlock_irqrestore(&dev->slock,flags);
|
|
|
|
}
|
|
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
|
|
if (0 == ret)
|
|
|
|
ret = -EAGAIN;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (0 == dev->dmasound.read_count)
|
2005-04-16 15:20:36 -07:00
|
|
|
schedule();
|
|
|
|
set_current_state(TASK_RUNNING);
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
if (0 == ret)
|
|
|
|
ret = -EINTR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy data to userspace */
|
|
|
|
bytes = count;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (bytes > dev->dmasound.read_count)
|
|
|
|
bytes = dev->dmasound.read_count;
|
|
|
|
if (bytes > dev->dmasound.bufsize - dev->dmasound.read_offset)
|
|
|
|
bytes = dev->dmasound.bufsize - dev->dmasound.read_offset;
|
2005-04-16 15:20:36 -07:00
|
|
|
if (copy_to_user(buffer + ret,
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.dma.vmalloc + dev->dmasound.read_offset,
|
2005-04-16 15:20:36 -07:00
|
|
|
bytes)) {
|
|
|
|
if (0 == ret)
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret += bytes;
|
|
|
|
count -= bytes;
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.read_count -= bytes;
|
|
|
|
dev->dmasound.read_offset += bytes;
|
|
|
|
if (dev->dmasound.read_offset == dev->dmasound.bufsize)
|
|
|
|
dev->dmasound.read_offset = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
remove_wait_queue(&dev->dmasound.wq, &wait);
|
2005-04-16 15:20:36 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dsp_write(struct file *file, const char __user *buffer,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-01-09 10:32:31 -07:00
|
|
|
static const char *osspcm_ioctls[] = {
|
|
|
|
"RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT",
|
|
|
|
"CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS",
|
|
|
|
"GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER",
|
|
|
|
"GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO",
|
|
|
|
"SETDUPLEX", "GETODELAY"
|
|
|
|
};
|
|
|
|
#define OSSPCM_IOCTLS ARRAY_SIZE(osspcm_ioctls)
|
|
|
|
|
|
|
|
static void saa7134_oss_print_ioctl(char *name, unsigned int cmd)
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
switch (_IOC_DIR(cmd)) {
|
|
|
|
case _IOC_NONE: dir = "--"; break;
|
|
|
|
case _IOC_READ: dir = "r-"; break;
|
|
|
|
case _IOC_WRITE: dir = "-w"; break;
|
|
|
|
case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
|
|
|
|
default: dir = "??"; break;
|
|
|
|
}
|
|
|
|
switch (_IOC_TYPE(cmd)) {
|
|
|
|
case 'P':
|
|
|
|
printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n",
|
|
|
|
name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ?
|
|
|
|
osspcm_ioctls[_IOC_NR(cmd)] : "???");
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n",
|
|
|
|
name, cmd, dir, _IOC_NR(cmd));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",
|
|
|
|
name, cmd, dir, _IOC_NR(cmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
static int dsp_ioctl(struct inode *inode, struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
struct saa7134_dev *dev = file->private_data;
|
|
|
|
void __user *argp = (void __user *) arg;
|
|
|
|
int __user *p = argp;
|
|
|
|
int val = 0;
|
|
|
|
|
2005-11-13 17:08:00 -07:00
|
|
|
if (debug > 1)
|
2006-01-09 10:32:31 -07:00
|
|
|
saa7134_oss_print_ioctl(dev->name,cmd);
|
2005-11-08 22:37:43 -07:00
|
|
|
switch (cmd) {
|
|
|
|
case OSS_GETVERSION:
|
|
|
|
return put_user(SOUND_VERSION, p);
|
|
|
|
case SNDCTL_DSP_GETCAPS:
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_SPEED:
|
2005-04-16 15:20:36 -07:00
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
|
|
|
/* fall through */
|
2005-11-08 22:37:43 -07:00
|
|
|
case SOUND_PCM_READ_RATE:
|
2005-11-08 22:38:54 -07:00
|
|
|
return put_user(dev->dmasound.rate, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_STEREO:
|
2005-04-16 15:20:36 -07:00
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.channels = val ? 2 : 1;
|
|
|
|
if (dev->dmasound.recording_on) {
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_rec_stop(dev);
|
|
|
|
dsp_rec_start(dev);
|
|
|
|
}
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
return put_user(dev->dmasound.channels-1, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_CHANNELS:
|
2005-04-16 15:20:36 -07:00
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
|
|
|
if (val != 1 && val != 2)
|
|
|
|
return -EINVAL;
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.channels = val;
|
|
|
|
if (dev->dmasound.recording_on) {
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_rec_stop(dev);
|
|
|
|
dsp_rec_start(dev);
|
|
|
|
}
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
/* fall through */
|
2005-11-08 22:37:43 -07:00
|
|
|
case SOUND_PCM_READ_CHANNELS:
|
2005-11-08 22:38:54 -07:00
|
|
|
return put_user(dev->dmasound.channels, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_GETFMTS: /* Returns a mask */
|
2005-04-16 15:20:36 -07:00
|
|
|
return put_user(AFMT_U8 | AFMT_S8 |
|
|
|
|
AFMT_U16_LE | AFMT_U16_BE |
|
|
|
|
AFMT_S16_LE | AFMT_S16_BE, p);
|
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
|
2005-04-16 15:20:36 -07:00
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
|
|
|
switch (val) {
|
|
|
|
case AFMT_QUERY:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
case AFMT_U8:
|
|
|
|
case AFMT_S8:
|
|
|
|
case AFMT_U16_LE:
|
|
|
|
case AFMT_U16_BE:
|
|
|
|
case AFMT_S16_LE:
|
|
|
|
case AFMT_S16_BE:
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.afmt = val;
|
|
|
|
if (dev->dmasound.recording_on) {
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_rec_stop(dev);
|
|
|
|
dsp_rec_start(dev);
|
|
|
|
}
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
return put_user(dev->dmasound.afmt, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SOUND_PCM_READ_BITS:
|
2005-11-08 22:38:54 -07:00
|
|
|
switch (dev->dmasound.afmt) {
|
2005-04-16 15:20:36 -07:00
|
|
|
case AFMT_U8:
|
|
|
|
case AFMT_S8:
|
|
|
|
return put_user(8, p);
|
|
|
|
case AFMT_U16_LE:
|
|
|
|
case AFMT_U16_BE:
|
|
|
|
case AFMT_S16_LE:
|
|
|
|
case AFMT_S16_BE:
|
|
|
|
return put_user(16, p);
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_NONBLOCK:
|
|
|
|
file->f_flags |= O_NONBLOCK;
|
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_RESET:
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (dev->dmasound.recording_on)
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_rec_stop(dev);
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_GETBLKSIZE:
|
2005-11-08 22:38:54 -07:00
|
|
|
return put_user(dev->dmasound.blksize, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_SETFRAGMENT:
|
2005-04-16 15:20:36 -07:00
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (dev->dmasound.recording_on)
|
2005-04-16 15:20:36 -07:00
|
|
|
return -EBUSY;
|
|
|
|
dsp_buffer_free(dev);
|
|
|
|
/* used to be arg >> 16 instead of val >> 16; fixed */
|
|
|
|
dsp_buffer_conf(dev,1 << (val & 0xffff), (val >> 16) & 0xffff);
|
|
|
|
dsp_buffer_init(dev);
|
|
|
|
return 0;
|
|
|
|
|
2005-11-08 22:37:43 -07:00
|
|
|
case SNDCTL_DSP_SYNC:
|
2005-04-16 15:20:36 -07:00
|
|
|
/* NOP */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SNDCTL_DSP_GETISPACE:
|
|
|
|
{
|
|
|
|
audio_buf_info info;
|
2005-11-08 22:38:54 -07:00
|
|
|
info.fragsize = dev->dmasound.blksize;
|
|
|
|
info.fragstotal = dev->dmasound.blocks;
|
|
|
|
info.bytes = dev->dmasound.read_count;
|
2005-04-16 15:20:36 -07:00
|
|
|
info.fragments = info.bytes / info.fragsize;
|
|
|
|
if (copy_to_user(argp, &info, sizeof(info)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait)
|
|
|
|
{
|
|
|
|
struct saa7134_dev *dev = file->private_data;
|
|
|
|
unsigned int mask = 0;
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
poll_wait(file, &dev->dmasound.wq, wait);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
if (0 == dev->dmasound.read_count) {
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_lock(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (!dev->dmasound.recording_on)
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_rec_start(dev);
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_unlock(&dev->dmasound.lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
} else
|
|
|
|
mask |= (POLLIN | POLLRDNORM);
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct file_operations saa7134_dsp_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = dsp_open,
|
|
|
|
.release = dsp_release,
|
|
|
|
.read = dsp_read,
|
|
|
|
.write = dsp_write,
|
|
|
|
.ioctl = dsp_ioctl,
|
|
|
|
.poll = dsp_poll,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
static int
|
|
|
|
mixer_recsrc_7134(struct saa7134_dev *dev)
|
|
|
|
{
|
|
|
|
int analog_io,rate;
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
switch (dev->dmasound.input) {
|
2005-04-16 15:20:36 -07:00
|
|
|
case TV:
|
|
|
|
saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0);
|
|
|
|
saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
|
|
|
|
break;
|
|
|
|
case LINE1:
|
|
|
|
case LINE2:
|
|
|
|
case LINE2_LEFT:
|
2005-11-08 22:38:54 -07:00
|
|
|
analog_io = (LINE1 == dev->dmasound.input) ? 0x00 : 0x08;
|
|
|
|
rate = (32000 == dev->dmasound.rate) ? 0x01 : 0x03;
|
2005-04-16 15:20:36 -07:00
|
|
|
saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io);
|
|
|
|
saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80);
|
|
|
|
saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mixer_recsrc_7133(struct saa7134_dev *dev)
|
|
|
|
{
|
2005-07-12 13:59:01 -07:00
|
|
|
u32 anabar, xbarin;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-07-12 13:59:01 -07:00
|
|
|
xbarin = 0x03; // adc
|
|
|
|
anabar = 0;
|
2005-11-08 22:38:54 -07:00
|
|
|
switch (dev->dmasound.input) {
|
2005-04-16 15:20:36 -07:00
|
|
|
case TV:
|
2005-07-12 13:59:01 -07:00
|
|
|
xbarin = 0; // Demodulator
|
2005-11-08 22:37:43 -07:00
|
|
|
anabar = 2; // DACs
|
2005-04-16 15:20:36 -07:00
|
|
|
break;
|
|
|
|
case LINE1:
|
2005-07-12 13:59:01 -07:00
|
|
|
anabar = 0; // aux1, aux1
|
2005-04-16 15:20:36 -07:00
|
|
|
break;
|
|
|
|
case LINE2:
|
|
|
|
case LINE2_LEFT:
|
2005-07-12 13:59:01 -07:00
|
|
|
anabar = 9; // aux2, aux2
|
2005-04-16 15:20:36 -07:00
|
|
|
break;
|
|
|
|
}
|
2005-07-12 13:59:01 -07:00
|
|
|
/* output xbar always main channel */
|
|
|
|
saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10);
|
|
|
|
saa_dsp_writel(dev, 0x464 >> 2, xbarin);
|
|
|
|
saa_writel(0x594 >> 2, anabar);
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mixer_recsrc(struct saa7134_dev *dev, enum saa7134_audio_in src)
|
|
|
|
{
|
|
|
|
static const char *iname[] = { "Oops", "TV", "LINE1", "LINE2" };
|
|
|
|
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.count++;
|
|
|
|
dev->dmasound.input = src;
|
|
|
|
dprintk("mixer input = %s\n",iname[dev->dmasound.input]);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
switch (dev->pci->device) {
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7134:
|
|
|
|
mixer_recsrc_7134(dev);
|
|
|
|
break;
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7133:
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7135:
|
|
|
|
mixer_recsrc_7133(dev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level)
|
|
|
|
{
|
|
|
|
switch (dev->pci->device) {
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7134:
|
|
|
|
switch (src) {
|
|
|
|
case TV:
|
|
|
|
/* nothing */
|
|
|
|
break;
|
|
|
|
case LINE1:
|
|
|
|
saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10,
|
|
|
|
(100 == level) ? 0x00 : 0x10);
|
|
|
|
break;
|
|
|
|
case LINE2:
|
|
|
|
case LINE2_LEFT:
|
|
|
|
saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20,
|
|
|
|
(100 == level) ? 0x00 : 0x20);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7133:
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7135:
|
|
|
|
/* nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
static int mixer_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
int minor = iminor(inode);
|
|
|
|
struct saa7134_dev *h,*dev = NULL;
|
|
|
|
struct list_head *list;
|
|
|
|
|
|
|
|
list_for_each(list,&saa7134_devlist) {
|
|
|
|
h = list_entry(list, struct saa7134_dev, devlist);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (h->dmasound.minor_mixer == minor)
|
2005-04-16 15:20:36 -07:00
|
|
|
dev = h;
|
|
|
|
}
|
|
|
|
if (NULL == dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
file->private_data = dev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mixer_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
file->private_data = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mixer_ioctl(struct inode *inode, struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
struct saa7134_dev *dev = file->private_data;
|
|
|
|
enum saa7134_audio_in input;
|
|
|
|
int val,ret;
|
|
|
|
void __user *argp = (void __user *) arg;
|
|
|
|
int __user *p = argp;
|
|
|
|
|
2005-11-13 17:08:00 -07:00
|
|
|
if (debug > 1)
|
2006-01-09 10:32:31 -07:00
|
|
|
saa7134_oss_print_ioctl(dev->name,cmd);
|
2005-11-08 22:37:43 -07:00
|
|
|
switch (cmd) {
|
|
|
|
case OSS_GETVERSION:
|
|
|
|
return put_user(SOUND_VERSION, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
case SOUND_MIXER_INFO:
|
|
|
|
{
|
|
|
|
mixer_info info;
|
|
|
|
memset(&info,0,sizeof(info));
|
2005-11-08 22:37:43 -07:00
|
|
|
strlcpy(info.id, "TV audio", sizeof(info.id));
|
|
|
|
strlcpy(info.name, dev->name, sizeof(info.name));
|
2005-11-08 22:38:54 -07:00
|
|
|
info.modify_counter = dev->dmasound.count;
|
2005-11-08 22:37:43 -07:00
|
|
|
if (copy_to_user(argp, &info, sizeof(info)))
|
|
|
|
return -EFAULT;
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SOUND_OLD_MIXER_INFO:
|
|
|
|
{
|
|
|
|
_old_mixer_info info;
|
|
|
|
memset(&info,0,sizeof(info));
|
2005-11-08 22:37:43 -07:00
|
|
|
strlcpy(info.id, "TV audio", sizeof(info.id));
|
|
|
|
strlcpy(info.name, dev->name, sizeof(info.name));
|
|
|
|
if (copy_to_user(argp, &info, sizeof(info)))
|
|
|
|
return -EFAULT;
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case MIXER_READ(SOUND_MIXER_CAPS):
|
|
|
|
return put_user(SOUND_CAP_EXCL_INPUT, p);
|
|
|
|
case MIXER_READ(SOUND_MIXER_STEREODEVS):
|
|
|
|
return put_user(0, p);
|
|
|
|
case MIXER_READ(SOUND_MIXER_RECMASK):
|
|
|
|
case MIXER_READ(SOUND_MIXER_DEVMASK):
|
|
|
|
val = SOUND_MASK_LINE1 | SOUND_MASK_LINE2;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (32000 == dev->dmasound.rate)
|
2005-04-16 15:20:36 -07:00
|
|
|
val |= SOUND_MASK_VIDEO;
|
|
|
|
return put_user(val, p);
|
|
|
|
|
|
|
|
case MIXER_WRITE(SOUND_MIXER_RECSRC):
|
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
2005-11-08 22:38:54 -07:00
|
|
|
input = dev->dmasound.input;
|
|
|
|
if (32000 == dev->dmasound.rate &&
|
|
|
|
val & SOUND_MASK_VIDEO && dev->dmasound.input != TV)
|
2005-04-16 15:20:36 -07:00
|
|
|
input = TV;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (val & SOUND_MASK_LINE1 && dev->dmasound.input != LINE1)
|
2005-04-16 15:20:36 -07:00
|
|
|
input = LINE1;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (val & SOUND_MASK_LINE2 && dev->dmasound.input != LINE2)
|
2005-04-16 15:20:36 -07:00
|
|
|
input = LINE2;
|
2005-11-08 22:38:54 -07:00
|
|
|
if (input != dev->dmasound.input)
|
2005-04-16 15:20:36 -07:00
|
|
|
mixer_recsrc(dev,input);
|
|
|
|
/* fall throuth */
|
|
|
|
case MIXER_READ(SOUND_MIXER_RECSRC):
|
2005-11-08 22:38:54 -07:00
|
|
|
switch (dev->dmasound.input) {
|
2005-04-16 15:20:36 -07:00
|
|
|
case TV: ret = SOUND_MASK_VIDEO; break;
|
|
|
|
case LINE1: ret = SOUND_MASK_LINE1; break;
|
|
|
|
case LINE2: ret = SOUND_MASK_LINE2; break;
|
|
|
|
default: ret = 0;
|
|
|
|
}
|
|
|
|
return put_user(ret, p);
|
|
|
|
|
|
|
|
case MIXER_WRITE(SOUND_MIXER_VIDEO):
|
|
|
|
case MIXER_READ(SOUND_MIXER_VIDEO):
|
2005-11-08 22:38:54 -07:00
|
|
|
if (32000 != dev->dmasound.rate)
|
2005-04-16 15:20:36 -07:00
|
|
|
return -EINVAL;
|
|
|
|
return put_user(100 | 100 << 8, p);
|
|
|
|
|
|
|
|
case MIXER_WRITE(SOUND_MIXER_LINE1):
|
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
|
|
|
val &= 0xff;
|
|
|
|
val = (val <= 50) ? 50 : 100;
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.line1 = val;
|
|
|
|
mixer_level(dev,LINE1,dev->dmasound.line1);
|
2005-04-16 15:20:36 -07:00
|
|
|
/* fall throuth */
|
|
|
|
case MIXER_READ(SOUND_MIXER_LINE1):
|
2005-11-08 22:38:54 -07:00
|
|
|
return put_user(dev->dmasound.line1 | dev->dmasound.line1 << 8, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
case MIXER_WRITE(SOUND_MIXER_LINE2):
|
|
|
|
if (get_user(val, p))
|
|
|
|
return -EFAULT;
|
|
|
|
val &= 0xff;
|
|
|
|
val = (val <= 50) ? 50 : 100;
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.line2 = val;
|
|
|
|
mixer_level(dev,LINE2,dev->dmasound.line2);
|
2005-04-16 15:20:36 -07:00
|
|
|
/* fall throuth */
|
|
|
|
case MIXER_READ(SOUND_MIXER_LINE2):
|
2005-11-08 22:38:54 -07:00
|
|
|
return put_user(dev->dmasound.line2 | dev->dmasound.line2 << 8, p);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct file_operations saa7134_mixer_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = mixer_open,
|
|
|
|
.release = mixer_release,
|
|
|
|
.ioctl = mixer_ioctl,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 06:55:46 -07:00
|
|
|
static irqreturn_t saa7134_oss_irq(int irq, void *dev_id)
|
2005-11-13 17:08:00 -07:00
|
|
|
{
|
2005-12-12 01:37:27 -07:00
|
|
|
struct saa7134_dmasound *dmasound = dev_id;
|
|
|
|
struct saa7134_dev *dev = dmasound->priv_data;
|
|
|
|
unsigned long report, status;
|
|
|
|
int loop, handled = 0;
|
|
|
|
|
|
|
|
for (loop = 0; loop < 10; loop++) {
|
|
|
|
report = saa_readl(SAA7134_IRQ_REPORT);
|
|
|
|
status = saa_readl(SAA7134_IRQ_STATUS);
|
|
|
|
|
|
|
|
if (report & SAA7134_IRQ_REPORT_DONE_RA3) {
|
2005-12-12 01:37:28 -07:00
|
|
|
handled = 1;
|
|
|
|
saa_writel(SAA7134_IRQ_REPORT,report);
|
|
|
|
saa7134_irq_oss_done(dev, status);
|
2005-12-12 01:37:27 -07:00
|
|
|
} else {
|
2005-12-12 01:37:28 -07:00
|
|
|
goto out;
|
2005-12-12 01:37:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loop == 10) {
|
|
|
|
dprintk("error! looping IRQ!");
|
|
|
|
}
|
2005-11-13 17:08:00 -07:00
|
|
|
out:
|
2005-12-12 01:37:27 -07:00
|
|
|
return IRQ_RETVAL(handled);
|
2005-11-13 17:08:00 -07:00
|
|
|
}
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
int saa7134_oss_init1(struct saa7134_dev *dev)
|
|
|
|
{
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
if ((request_irq(dev->pci->irq, saa7134_oss_irq,
|
2006-07-01 19:29:37 -07:00
|
|
|
IRQF_SHARED | IRQF_DISABLED, dev->name,
|
2005-11-13 17:08:00 -07:00
|
|
|
(void*) &dev->dmasound)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/* general */
|
2006-02-07 01:49:14 -07:00
|
|
|
mutex_init(&dev->dmasound.lock);
|
2005-11-08 22:38:54 -07:00
|
|
|
init_waitqueue_head(&dev->dmasound.wq);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
switch (dev->pci->device) {
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7133:
|
|
|
|
case PCI_DEVICE_ID_PHILIPS_SAA7135:
|
|
|
|
saa_writel(0x588 >> 2, 0x00000fff);
|
|
|
|
saa_writel(0x58c >> 2, 0x00543210);
|
|
|
|
saa_dsp_writel(dev, 0x46c >> 2, 0xbbbbbb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dsp */
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.rate = 32000;
|
2005-11-13 17:08:00 -07:00
|
|
|
if (rate)
|
|
|
|
dev->dmasound.rate = rate;
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* mixer */
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.line1 = 50;
|
|
|
|
dev->dmasound.line2 = 50;
|
|
|
|
mixer_level(dev,LINE1,dev->dmasound.line1);
|
|
|
|
mixer_level(dev,LINE2,dev->dmasound.line2);
|
|
|
|
mixer_recsrc(dev, (dev->dmasound.rate == 32000) ? TV : LINE2);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int saa7134_oss_fini(struct saa7134_dev *dev)
|
|
|
|
{
|
|
|
|
/* nothing */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
|
|
|
|
{
|
|
|
|
int next_blk, reg = 0;
|
|
|
|
|
|
|
|
spin_lock(&dev->slock);
|
2005-11-08 22:38:54 -07:00
|
|
|
if (UNSET == dev->dmasound.dma_blk) {
|
2005-04-16 15:20:36 -07:00
|
|
|
dprintk("irq: recording stopped\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (0 != (status & 0x0f000000))
|
|
|
|
dprintk("irq: lost %ld\n", (status >> 24) & 0x0f);
|
|
|
|
if (0 == (status & 0x10000000)) {
|
|
|
|
/* odd */
|
2005-11-08 22:38:54 -07:00
|
|
|
if (0 == (dev->dmasound.dma_blk & 0x01))
|
2005-04-16 15:20:36 -07:00
|
|
|
reg = SAA7134_RS_BA1(6);
|
|
|
|
} else {
|
|
|
|
/* even */
|
2005-11-08 22:38:54 -07:00
|
|
|
if (1 == (dev->dmasound.dma_blk & 0x01))
|
2005-04-16 15:20:36 -07:00
|
|
|
reg = SAA7134_RS_BA2(6);
|
|
|
|
}
|
|
|
|
if (0 == reg) {
|
|
|
|
dprintk("irq: field oops [%s]\n",
|
|
|
|
(status & 0x10000000) ? "even" : "odd");
|
|
|
|
goto done;
|
|
|
|
}
|
2005-11-08 22:38:54 -07:00
|
|
|
if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) {
|
|
|
|
dprintk("irq: overrun [full=%d/%d]\n",dev->dmasound.read_count,
|
|
|
|
dev->dmasound.bufsize);
|
2005-04-16 15:20:36 -07:00
|
|
|
dsp_dma_stop(dev);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next block addr */
|
2005-11-08 22:38:54 -07:00
|
|
|
next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks;
|
|
|
|
saa_writel(reg,next_blk * dev->dmasound.blksize);
|
2005-11-13 17:08:00 -07:00
|
|
|
if (debug > 2)
|
2005-04-16 15:20:36 -07:00
|
|
|
dprintk("irq: ok, %s, next_blk=%d, addr=%x\n",
|
|
|
|
(status & 0x10000000) ? "even" : "odd ", next_blk,
|
2005-11-08 22:38:54 -07:00
|
|
|
next_blk * dev->dmasound.blksize);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* update status & wake waiting readers */
|
2005-11-08 22:38:54 -07:00
|
|
|
dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks;
|
|
|
|
dev->dmasound.read_count += dev->dmasound.blksize;
|
|
|
|
wake_up(&dev->dmasound.wq);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
done:
|
|
|
|
spin_unlock(&dev->slock);
|
|
|
|
}
|
|
|
|
|
2005-12-01 01:51:35 -07:00
|
|
|
static int saa7134_dsp_create(struct saa7134_dev *dev)
|
2005-11-13 17:08:00 -07:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2005-12-01 01:51:20 -07:00
|
|
|
err = dev->dmasound.minor_dsp =
|
|
|
|
register_sound_dsp(&saa7134_dsp_fops,
|
2005-12-12 01:37:28 -07:00
|
|
|
dsp_nr[dev->nr]);
|
2005-12-01 01:51:20 -07:00
|
|
|
if (err < 0) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
printk(KERN_INFO "%s: registered device dsp%d\n",
|
2005-12-12 01:37:28 -07:00
|
|
|
dev->name,dev->dmasound.minor_dsp >> 4);
|
2005-12-01 01:51:20 -07:00
|
|
|
|
|
|
|
err = dev->dmasound.minor_mixer =
|
|
|
|
register_sound_mixer(&saa7134_mixer_fops,
|
2005-12-12 01:37:28 -07:00
|
|
|
mixer_nr[dev->nr]);
|
2005-12-01 01:51:20 -07:00
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
|
|
|
printk(KERN_INFO "%s: registered device mixer%d\n",
|
2005-12-12 01:37:28 -07:00
|
|
|
dev->name,dev->dmasound.minor_mixer >> 4);
|
2005-11-13 17:08:00 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2005-12-12 01:37:27 -07:00
|
|
|
unregister_sound_dsp(dev->dmasound.minor_dsp);
|
2005-11-13 17:08:00 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-12-01 01:51:20 -07:00
|
|
|
static int oss_device_init(struct saa7134_dev *dev)
|
|
|
|
{
|
|
|
|
dev->dmasound.priv_data = dev;
|
|
|
|
saa7134_oss_init1(dev);
|
|
|
|
saa7134_dsp_create(dev);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int oss_device_exit(struct saa7134_dev *dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
unregister_sound_mixer(dev->dmasound.minor_mixer);
|
|
|
|
unregister_sound_dsp(dev->dmasound.minor_dsp);
|
|
|
|
|
|
|
|
saa7134_oss_fini(dev);
|
|
|
|
|
|
|
|
if (dev->pci->irq > 0) {
|
|
|
|
synchronize_irq(dev->pci->irq);
|
|
|
|
free_irq(dev->pci->irq,&dev->dmasound);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->dmasound.priv_data = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-11-13 17:08:00 -07:00
|
|
|
static int saa7134_oss_init(void)
|
|
|
|
{
|
2005-12-12 01:37:27 -07:00
|
|
|
struct saa7134_dev *dev = NULL;
|
|
|
|
struct list_head *list;
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2006-07-15 11:19:56 -07:00
|
|
|
if (!saa7134_dmasound_init && !saa7134_dmasound_exit) {
|
|
|
|
saa7134_dmasound_init = oss_device_init;
|
|
|
|
saa7134_dmasound_exit = oss_device_exit;
|
2005-12-20 13:26:26 -07:00
|
|
|
} else {
|
|
|
|
printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
printk(KERN_INFO "saa7134 OSS driver for DMA sound loaded\n");
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2005-12-20 13:26:26 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
list_for_each(list,&saa7134_devlist) {
|
|
|
|
dev = list_entry(list, struct saa7134_dev, devlist);
|
2005-11-13 17:08:00 -07:00
|
|
|
if (dev->dmasound.priv_data == NULL) {
|
2005-12-01 01:51:20 -07:00
|
|
|
oss_device_init(dev);
|
2005-11-13 17:08:00 -07:00
|
|
|
} else {
|
2005-12-12 01:37:27 -07:00
|
|
|
printk(KERN_ERR "saa7134 OSS: DMA sound is being handled by ALSA, ignoring %s\n",dev->name);
|
2005-11-13 17:08:00 -07:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
2005-12-12 01:37:27 -07:00
|
|
|
}
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
if (dev == NULL)
|
|
|
|
printk(KERN_INFO "saa7134 OSS: no saa7134 cards found\n");
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
return 0;
|
2005-11-13 17:08:00 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-12-01 01:51:35 -07:00
|
|
|
static void saa7134_oss_exit(void)
|
2005-11-13 17:08:00 -07:00
|
|
|
{
|
2005-12-12 01:37:27 -07:00
|
|
|
struct saa7134_dev *dev = NULL;
|
|
|
|
struct list_head *list;
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
list_for_each(list,&saa7134_devlist) {
|
|
|
|
dev = list_entry(list, struct saa7134_dev, devlist);
|
2005-11-13 17:08:00 -07:00
|
|
|
|
|
|
|
/* Device isn't registered by OSS, probably ALSA's */
|
|
|
|
if (!dev->dmasound.minor_dsp)
|
|
|
|
continue;
|
|
|
|
|
2005-12-01 01:51:20 -07:00
|
|
|
oss_device_exit(dev);
|
2005-12-12 01:37:28 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
}
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2006-07-15 11:19:56 -07:00
|
|
|
saa7134_dmasound_init = NULL;
|
|
|
|
saa7134_dmasound_exit = NULL;
|
2005-12-20 13:26:26 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n");
|
2005-11-13 17:08:00 -07:00
|
|
|
|
2005-12-12 01:37:27 -07:00
|
|
|
return;
|
2005-11-13 17:08:00 -07:00
|
|
|
}
|
|
|
|
|
2005-12-21 15:52:32 -07:00
|
|
|
/* We initialize this late, to make sure the sound system is up and running */
|
|
|
|
late_initcall(saa7134_oss_init);
|
2005-11-13 17:08:00 -07:00
|
|
|
module_exit(saa7134_oss_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/* ----------------------------------------------------------- */
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|