3 * device driver for philips saa7134 based TV cards
6 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 * 2005 conversion to standalone module:
8 * Ricardo Cerqueira <v4l@cerqueira.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/init.h>
26 #include <linux/list.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/interrupt.h>
30 #include <linux/slab.h>
31 #include <linux/sound.h>
32 #include <linux/soundcard.h>
34 #include "saa7134-reg.h"
37 /* ------------------------------------------------------------------ */
39 static unsigned int debug = 0;
40 module_param(debug, int, 0644);
41 MODULE_PARM_DESC(debug,"enable debug messages [oss]");
43 static unsigned int rate = 0;
44 module_param(rate, int, 0444);
45 MODULE_PARM_DESC(rate,"sample rate (valid are: 32000,48000)");
47 static unsigned int dsp_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
48 MODULE_PARM_DESC(dsp_nr, "device numbers for SAA7134 capture interface(s).");
49 module_param_array(dsp_nr, int, NULL, 0444);
51 static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
52 MODULE_PARM_DESC(mixer_nr, "mixer numbers for SAA7134 capture interface(s).");
53 module_param_array(mixer_nr, int, NULL, 0444);
55 #define dprintk(fmt, arg...) if (debug) \
56 printk(KERN_DEBUG "%s/oss: " fmt, dev->name , ## arg)
59 /* ------------------------------------------------------------------ */
61 static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks)
65 if (blksize > 0x10000)
70 if ((blksize * blocks) > 1024*1024)
71 blocks = 1024*1024 / blksize;
73 dev->dmasound.blocks = blocks;
74 dev->dmasound.blksize = blksize;
75 dev->dmasound.bufsize = blksize * blocks;
77 dprintk("buffer config: %d blocks / %d bytes, %d kB total\n",
78 blocks,blksize,blksize * blocks / 1024);
82 static int dsp_buffer_init(struct saa7134_dev *dev)
86 BUG_ON(!dev->dmasound.bufsize);
87 videobuf_dma_init(&dev->dmasound.dma);
88 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE,
89 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
95 static int dsp_buffer_free(struct saa7134_dev *dev)
97 BUG_ON(!dev->dmasound.blksize);
98 videobuf_dma_free(&dev->dmasound.dma);
99 dev->dmasound.blocks = 0;
100 dev->dmasound.blksize = 0;
101 dev->dmasound.bufsize = 0;
105 static void dsp_dma_start(struct saa7134_dev *dev)
107 dev->dmasound.dma_blk = 0;
108 dev->dmasound.dma_running = 1;
109 saa7134_set_dmabits(dev);
112 static void dsp_dma_stop(struct saa7134_dev *dev)
114 dev->dmasound.dma_blk = -1;
115 dev->dmasound.dma_running = 0;
116 saa7134_set_dmabits(dev);
119 static int dsp_rec_start(struct saa7134_dev *dev)
121 int err, bswap, sign;
126 if (0 != (err = videobuf_pci_dma_map(dev->pci,&dev->dmasound.dma)))
128 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt)))
130 if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->dmasound.pt,
131 dev->dmasound.dma.sglist,
132 dev->dmasound.dma.sglen,
137 switch (dev->dmasound.afmt) {
139 case AFMT_S8: fmt = 0x00; break;
143 case AFMT_S16_BE: fmt = 0x01; break;
149 switch (dev->dmasound.afmt) {
152 case AFMT_S16_BE: sign = 1; break;
153 default: sign = 0; break;
156 switch (dev->dmasound.afmt) {
158 case AFMT_S16_BE: bswap = 1; break;
159 default: bswap = 0; break;
162 switch (dev->pci->device) {
163 case PCI_DEVICE_ID_PHILIPS_SAA7134:
164 if (1 == dev->dmasound.channels)
166 if (2 == dev->dmasound.channels)
170 fmt |= (TV == dev->dmasound.input) ? 0xc0 : 0x80;
172 saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->dmasound.blksize - 1) & 0x0000ff));
173 saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->dmasound.blksize - 1) & 0x00ff00) >> 8);
174 saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->dmasound.blksize - 1) & 0xff0000) >> 16);
175 saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt);
178 case PCI_DEVICE_ID_PHILIPS_SAA7133:
179 case PCI_DEVICE_ID_PHILIPS_SAA7135:
180 if (1 == dev->dmasound.channels)
182 if (2 == dev->dmasound.channels)
186 saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -4);
187 saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24));
190 dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
191 dev->dmasound.afmt, dev->dmasound.channels, fmt,
194 /* dma: setup channel 6 (= AUDIO) */
195 control = SAA7134_RS_CONTROL_BURST_16 |
196 SAA7134_RS_CONTROL_ME |
197 (dev->dmasound.pt.dma >> 12);
199 control |= SAA7134_RS_CONTROL_BSWAP;
200 saa_writel(SAA7134_RS_BA1(6),0);
201 saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize);
202 saa_writel(SAA7134_RS_PITCH(6),0);
203 saa_writel(SAA7134_RS_CONTROL(6),control);
206 dev->dmasound.recording_on = 1;
207 spin_lock_irqsave(&dev->slock,flags);
209 spin_unlock_irqrestore(&dev->slock,flags);
213 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
215 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
219 static int dsp_rec_stop(struct saa7134_dev *dev)
223 dprintk("rec_stop dma_blk=%d\n",dev->dmasound.dma_blk);
226 dev->dmasound.recording_on = 0;
227 spin_lock_irqsave(&dev->slock,flags);
229 spin_unlock_irqrestore(&dev->slock,flags);
232 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
233 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
237 /* ------------------------------------------------------------------ */
239 static int dsp_open(struct inode *inode, struct file *file)
241 int minor = iminor(inode);
242 struct saa7134_dev *dev;
245 list_for_each_entry(dev, &saa7134_devlist, devlist)
246 if (dev->dmasound.minor_dsp == minor)
251 mutex_lock(&dev->dmasound.lock);
253 if (dev->dmasound.users_dsp)
255 dev->dmasound.users_dsp++;
256 file->private_data = dev;
258 dev->dmasound.afmt = AFMT_U8;
259 dev->dmasound.channels = 1;
260 dev->dmasound.read_count = 0;
261 dev->dmasound.read_offset = 0;
262 dsp_buffer_conf(dev,PAGE_SIZE,64);
263 err = dsp_buffer_init(dev);
267 mutex_unlock(&dev->dmasound.lock);
271 dev->dmasound.users_dsp--;
273 mutex_unlock(&dev->dmasound.lock);
277 static int dsp_release(struct inode *inode, struct file *file)
279 struct saa7134_dev *dev = file->private_data;
281 mutex_lock(&dev->dmasound.lock);
282 if (dev->dmasound.recording_on)
284 dsp_buffer_free(dev);
285 dev->dmasound.users_dsp--;
286 file->private_data = NULL;
287 mutex_unlock(&dev->dmasound.lock);
291 static ssize_t dsp_read(struct file *file, char __user *buffer,
292 size_t count, loff_t *ppos)
294 struct saa7134_dev *dev = file->private_data;
295 DECLARE_WAITQUEUE(wait, current);
300 add_wait_queue(&dev->dmasound.wq, &wait);
301 mutex_lock(&dev->dmasound.lock);
303 /* wait for data if needed */
304 if (0 == dev->dmasound.read_count) {
305 if (!dev->dmasound.recording_on) {
306 err = dsp_rec_start(dev);
313 if (dev->dmasound.recording_on &&
314 !dev->dmasound.dma_running) {
315 /* recover from overruns */
316 spin_lock_irqsave(&dev->slock,flags);
318 spin_unlock_irqrestore(&dev->slock,flags);
320 if (file->f_flags & O_NONBLOCK) {
325 mutex_unlock(&dev->dmasound.lock);
326 set_current_state(TASK_INTERRUPTIBLE);
327 if (0 == dev->dmasound.read_count)
329 set_current_state(TASK_RUNNING);
330 mutex_lock(&dev->dmasound.lock);
331 if (signal_pending(current)) {
338 /* copy data to userspace */
340 if (bytes > dev->dmasound.read_count)
341 bytes = dev->dmasound.read_count;
342 if (bytes > dev->dmasound.bufsize - dev->dmasound.read_offset)
343 bytes = dev->dmasound.bufsize - dev->dmasound.read_offset;
344 if (copy_to_user(buffer + ret,
345 dev->dmasound.dma.vmalloc + dev->dmasound.read_offset,
354 dev->dmasound.read_count -= bytes;
355 dev->dmasound.read_offset += bytes;
356 if (dev->dmasound.read_offset == dev->dmasound.bufsize)
357 dev->dmasound.read_offset = 0;
359 mutex_unlock(&dev->dmasound.lock);
360 remove_wait_queue(&dev->dmasound.wq, &wait);
364 static ssize_t dsp_write(struct file *file, const char __user *buffer,
365 size_t count, loff_t *ppos)
370 static const char *osspcm_ioctls[] = {
371 "RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT",
372 "CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS",
373 "GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER",
374 "GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO",
375 "SETDUPLEX", "GETODELAY"
377 #define OSSPCM_IOCTLS ARRAY_SIZE(osspcm_ioctls)
379 static void saa7134_oss_print_ioctl(char *name, unsigned int cmd)
383 switch (_IOC_DIR(cmd)) {
384 case _IOC_NONE: dir = "--"; break;
385 case _IOC_READ: dir = "r-"; break;
386 case _IOC_WRITE: dir = "-w"; break;
387 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
388 default: dir = "??"; break;
390 switch (_IOC_TYPE(cmd)) {
392 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n",
393 name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ?
394 osspcm_ioctls[_IOC_NR(cmd)] : "???");
397 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n",
398 name, cmd, dir, _IOC_NR(cmd));
401 printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",
402 name, cmd, dir, _IOC_NR(cmd));
406 static int dsp_ioctl(struct inode *inode, struct file *file,
407 unsigned int cmd, unsigned long arg)
409 struct saa7134_dev *dev = file->private_data;
410 void __user *argp = (void __user *) arg;
411 int __user *p = argp;
415 saa7134_oss_print_ioctl(dev->name,cmd);
418 return put_user(SOUND_VERSION, p);
419 case SNDCTL_DSP_GETCAPS:
422 case SNDCTL_DSP_SPEED:
423 if (get_user(val, p))
426 case SOUND_PCM_READ_RATE:
427 return put_user(dev->dmasound.rate, p);
429 case SNDCTL_DSP_STEREO:
430 if (get_user(val, p))
432 mutex_lock(&dev->dmasound.lock);
433 dev->dmasound.channels = val ? 2 : 1;
434 if (dev->dmasound.recording_on) {
438 mutex_unlock(&dev->dmasound.lock);
439 return put_user(dev->dmasound.channels-1, p);
441 case SNDCTL_DSP_CHANNELS:
442 if (get_user(val, p))
444 if (val != 1 && val != 2)
446 mutex_lock(&dev->dmasound.lock);
447 dev->dmasound.channels = val;
448 if (dev->dmasound.recording_on) {
452 mutex_unlock(&dev->dmasound.lock);
454 case SOUND_PCM_READ_CHANNELS:
455 return put_user(dev->dmasound.channels, p);
457 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
458 return put_user(AFMT_U8 | AFMT_S8 |
459 AFMT_U16_LE | AFMT_U16_BE |
460 AFMT_S16_LE | AFMT_S16_BE, p);
462 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
463 if (get_user(val, p))
475 mutex_lock(&dev->dmasound.lock);
476 dev->dmasound.afmt = val;
477 if (dev->dmasound.recording_on) {
481 mutex_unlock(&dev->dmasound.lock);
482 return put_user(dev->dmasound.afmt, p);
487 case SOUND_PCM_READ_BITS:
488 switch (dev->dmasound.afmt) {
491 return put_user(8, p);
496 return put_user(16, p);
501 case SNDCTL_DSP_NONBLOCK:
502 file->f_flags |= O_NONBLOCK;
505 case SNDCTL_DSP_RESET:
506 mutex_lock(&dev->dmasound.lock);
507 if (dev->dmasound.recording_on)
509 mutex_unlock(&dev->dmasound.lock);
511 case SNDCTL_DSP_GETBLKSIZE:
512 return put_user(dev->dmasound.blksize, p);
514 case SNDCTL_DSP_SETFRAGMENT:
515 if (get_user(val, p))
517 if (dev->dmasound.recording_on)
519 dsp_buffer_free(dev);
520 /* used to be arg >> 16 instead of val >> 16; fixed */
521 dsp_buffer_conf(dev,1 << (val & 0xffff), (val >> 16) & 0xffff);
522 dsp_buffer_init(dev);
525 case SNDCTL_DSP_SYNC:
529 case SNDCTL_DSP_GETISPACE:
532 info.fragsize = dev->dmasound.blksize;
533 info.fragstotal = dev->dmasound.blocks;
534 info.bytes = dev->dmasound.read_count;
535 info.fragments = info.bytes / info.fragsize;
536 if (copy_to_user(argp, &info, sizeof(info)))
545 static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait)
547 struct saa7134_dev *dev = file->private_data;
548 unsigned int mask = 0;
550 poll_wait(file, &dev->dmasound.wq, wait);
552 if (0 == dev->dmasound.read_count) {
553 mutex_lock(&dev->dmasound.lock);
554 if (!dev->dmasound.recording_on)
556 mutex_unlock(&dev->dmasound.lock);
558 mask |= (POLLIN | POLLRDNORM);
562 const struct file_operations saa7134_dsp_fops = {
563 .owner = THIS_MODULE,
565 .release = dsp_release,
573 /* ------------------------------------------------------------------ */
576 mixer_recsrc_7134(struct saa7134_dev *dev)
580 switch (dev->dmasound.input) {
582 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0);
583 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
588 analog_io = (LINE1 == dev->dmasound.input) ? 0x00 : 0x08;
589 rate = (32000 == dev->dmasound.rate) ? 0x01 : 0x03;
590 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io);
591 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80);
592 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate);
599 mixer_recsrc_7133(struct saa7134_dev *dev)
603 xbarin = 0x03; // adc
605 switch (dev->dmasound.input) {
607 xbarin = 0; // Demodulator
611 anabar = 0; // aux1, aux1
615 anabar = 9; // aux2, aux2
618 /* output xbar always main channel */
619 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10);
620 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
621 saa_writel(0x594 >> 2, anabar);
627 mixer_recsrc(struct saa7134_dev *dev, enum saa7134_audio_in src)
629 static const char *iname[] = { "Oops", "TV", "LINE1", "LINE2" };
631 dev->dmasound.count++;
632 dev->dmasound.input = src;
633 dprintk("mixer input = %s\n",iname[dev->dmasound.input]);
635 switch (dev->pci->device) {
636 case PCI_DEVICE_ID_PHILIPS_SAA7134:
637 mixer_recsrc_7134(dev);
639 case PCI_DEVICE_ID_PHILIPS_SAA7133:
640 case PCI_DEVICE_ID_PHILIPS_SAA7135:
641 mixer_recsrc_7133(dev);
648 mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level)
650 switch (dev->pci->device) {
651 case PCI_DEVICE_ID_PHILIPS_SAA7134:
657 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10,
658 (100 == level) ? 0x00 : 0x10);
662 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20,
663 (100 == level) ? 0x00 : 0x20);
667 case PCI_DEVICE_ID_PHILIPS_SAA7133:
668 case PCI_DEVICE_ID_PHILIPS_SAA7135:
675 /* ------------------------------------------------------------------ */
677 static int mixer_open(struct inode *inode, struct file *file)
679 int minor = iminor(inode);
680 struct saa7134_dev *dev;
682 list_for_each_entry(dev, &saa7134_devlist, devlist)
683 if (dev->dmasound.minor_mixer == minor) {
684 file->private_data = dev;
690 static int mixer_release(struct inode *inode, struct file *file)
692 file->private_data = NULL;
696 static int mixer_ioctl(struct inode *inode, struct file *file,
697 unsigned int cmd, unsigned long arg)
699 struct saa7134_dev *dev = file->private_data;
700 enum saa7134_audio_in input;
702 void __user *argp = (void __user *) arg;
703 int __user *p = argp;
706 saa7134_oss_print_ioctl(dev->name,cmd);
709 return put_user(SOUND_VERSION, p);
710 case SOUND_MIXER_INFO:
713 memset(&info,0,sizeof(info));
714 strlcpy(info.id, "TV audio", sizeof(info.id));
715 strlcpy(info.name, dev->name, sizeof(info.name));
716 info.modify_counter = dev->dmasound.count;
717 if (copy_to_user(argp, &info, sizeof(info)))
721 case SOUND_OLD_MIXER_INFO:
723 _old_mixer_info info;
724 memset(&info,0,sizeof(info));
725 strlcpy(info.id, "TV audio", sizeof(info.id));
726 strlcpy(info.name, dev->name, sizeof(info.name));
727 if (copy_to_user(argp, &info, sizeof(info)))
731 case MIXER_READ(SOUND_MIXER_CAPS):
732 return put_user(SOUND_CAP_EXCL_INPUT, p);
733 case MIXER_READ(SOUND_MIXER_STEREODEVS):
734 return put_user(0, p);
735 case MIXER_READ(SOUND_MIXER_RECMASK):
736 case MIXER_READ(SOUND_MIXER_DEVMASK):
737 val = SOUND_MASK_LINE1 | SOUND_MASK_LINE2;
738 if (32000 == dev->dmasound.rate)
739 val |= SOUND_MASK_VIDEO;
740 return put_user(val, p);
742 case MIXER_WRITE(SOUND_MIXER_RECSRC):
743 if (get_user(val, p))
745 input = dev->dmasound.input;
746 if (32000 == dev->dmasound.rate &&
747 val & SOUND_MASK_VIDEO && dev->dmasound.input != TV)
749 if (val & SOUND_MASK_LINE1 && dev->dmasound.input != LINE1)
751 if (val & SOUND_MASK_LINE2 && dev->dmasound.input != LINE2)
753 if (input != dev->dmasound.input)
754 mixer_recsrc(dev,input);
756 case MIXER_READ(SOUND_MIXER_RECSRC):
757 switch (dev->dmasound.input) {
758 case TV: ret = SOUND_MASK_VIDEO; break;
759 case LINE1: ret = SOUND_MASK_LINE1; break;
760 case LINE2: ret = SOUND_MASK_LINE2; break;
763 return put_user(ret, p);
765 case MIXER_WRITE(SOUND_MIXER_VIDEO):
766 case MIXER_READ(SOUND_MIXER_VIDEO):
767 if (32000 != dev->dmasound.rate)
769 return put_user(100 | 100 << 8, p);
771 case MIXER_WRITE(SOUND_MIXER_LINE1):
772 if (get_user(val, p))
775 val = (val <= 50) ? 50 : 100;
776 dev->dmasound.line1 = val;
777 mixer_level(dev,LINE1,dev->dmasound.line1);
779 case MIXER_READ(SOUND_MIXER_LINE1):
780 return put_user(dev->dmasound.line1 | dev->dmasound.line1 << 8, p);
782 case MIXER_WRITE(SOUND_MIXER_LINE2):
783 if (get_user(val, p))
786 val = (val <= 50) ? 50 : 100;
787 dev->dmasound.line2 = val;
788 mixer_level(dev,LINE2,dev->dmasound.line2);
790 case MIXER_READ(SOUND_MIXER_LINE2):
791 return put_user(dev->dmasound.line2 | dev->dmasound.line2 << 8, p);
798 const struct file_operations saa7134_mixer_fops = {
799 .owner = THIS_MODULE,
801 .release = mixer_release,
802 .ioctl = mixer_ioctl,
806 /* ------------------------------------------------------------------ */
808 static irqreturn_t saa7134_oss_irq(int irq, void *dev_id)
810 struct saa7134_dmasound *dmasound = dev_id;
811 struct saa7134_dev *dev = dmasound->priv_data;
812 unsigned long report, status;
813 int loop, handled = 0;
815 for (loop = 0; loop < 10; loop++) {
816 report = saa_readl(SAA7134_IRQ_REPORT);
817 status = saa_readl(SAA7134_IRQ_STATUS);
819 if (report & SAA7134_IRQ_REPORT_DONE_RA3) {
821 saa_writel(SAA7134_IRQ_REPORT,report);
822 saa7134_irq_oss_done(dev, status);
829 dprintk("error! looping IRQ!");
832 return IRQ_RETVAL(handled);
835 int saa7134_oss_init1(struct saa7134_dev *dev)
838 if ((request_irq(dev->pci->irq, saa7134_oss_irq,
839 IRQF_SHARED | IRQF_DISABLED, dev->name,
840 (void*) &dev->dmasound)) < 0)
844 mutex_init(&dev->dmasound.lock);
845 init_waitqueue_head(&dev->dmasound.wq);
847 switch (dev->pci->device) {
848 case PCI_DEVICE_ID_PHILIPS_SAA7133:
849 case PCI_DEVICE_ID_PHILIPS_SAA7135:
850 saa_writel(0x588 >> 2, 0x00000fff);
851 saa_writel(0x58c >> 2, 0x00543210);
852 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbbbb);
857 dev->dmasound.rate = 32000;
859 dev->dmasound.rate = rate;
860 dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000;
863 dev->dmasound.line1 = 50;
864 dev->dmasound.line2 = 50;
865 mixer_level(dev,LINE1,dev->dmasound.line1);
866 mixer_level(dev,LINE2,dev->dmasound.line2);
867 mixer_recsrc(dev, (dev->dmasound.rate == 32000) ? TV : LINE2);
872 int saa7134_oss_fini(struct saa7134_dev *dev)
878 void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
880 int next_blk, reg = 0;
882 spin_lock(&dev->slock);
883 if (UNSET == dev->dmasound.dma_blk) {
884 dprintk("irq: recording stopped\n");
887 if (0 != (status & 0x0f000000))
888 dprintk("irq: lost %ld\n", (status >> 24) & 0x0f);
889 if (0 == (status & 0x10000000)) {
891 if (0 == (dev->dmasound.dma_blk & 0x01))
892 reg = SAA7134_RS_BA1(6);
895 if (1 == (dev->dmasound.dma_blk & 0x01))
896 reg = SAA7134_RS_BA2(6);
899 dprintk("irq: field oops [%s]\n",
900 (status & 0x10000000) ? "even" : "odd");
903 if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) {
904 dprintk("irq: overrun [full=%d/%d]\n",dev->dmasound.read_count,
905 dev->dmasound.bufsize);
910 /* next block addr */
911 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks;
912 saa_writel(reg,next_blk * dev->dmasound.blksize);
914 dprintk("irq: ok, %s, next_blk=%d, addr=%x\n",
915 (status & 0x10000000) ? "even" : "odd ", next_blk,
916 next_blk * dev->dmasound.blksize);
918 /* update status & wake waiting readers */
919 dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks;
920 dev->dmasound.read_count += dev->dmasound.blksize;
921 wake_up(&dev->dmasound.wq);
924 spin_unlock(&dev->slock);
927 static int saa7134_dsp_create(struct saa7134_dev *dev)
931 err = dev->dmasound.minor_dsp =
932 register_sound_dsp(&saa7134_dsp_fops,
937 printk(KERN_INFO "%s: registered device dsp%d\n",
938 dev->name,dev->dmasound.minor_dsp >> 4);
940 err = dev->dmasound.minor_mixer =
941 register_sound_mixer(&saa7134_mixer_fops,
945 printk(KERN_INFO "%s: registered device mixer%d\n",
946 dev->name,dev->dmasound.minor_mixer >> 4);
951 unregister_sound_dsp(dev->dmasound.minor_dsp);
957 static int oss_device_init(struct saa7134_dev *dev)
959 dev->dmasound.priv_data = dev;
960 saa7134_oss_init1(dev);
961 saa7134_dsp_create(dev);
965 static int oss_device_exit(struct saa7134_dev *dev)
968 unregister_sound_mixer(dev->dmasound.minor_mixer);
969 unregister_sound_dsp(dev->dmasound.minor_dsp);
971 saa7134_oss_fini(dev);
973 if (dev->pci->irq > 0) {
974 synchronize_irq(dev->pci->irq);
975 free_irq(dev->pci->irq,&dev->dmasound);
978 dev->dmasound.priv_data = NULL;
982 static int saa7134_oss_init(void)
984 struct saa7134_dev *dev = NULL;
985 struct list_head *list;
987 if (!saa7134_dmasound_init && !saa7134_dmasound_exit) {
988 saa7134_dmasound_init = oss_device_init;
989 saa7134_dmasound_exit = oss_device_exit;
991 printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n");
995 printk(KERN_INFO "saa7134 OSS driver for DMA sound loaded\n");
998 list_for_each(list,&saa7134_devlist) {
999 dev = list_entry(list, struct saa7134_dev, devlist);
1000 if (dev->dmasound.priv_data == NULL) {
1001 oss_device_init(dev);
1003 printk(KERN_ERR "saa7134 OSS: DMA sound is being handled by ALSA, ignoring %s\n",dev->name);
1009 printk(KERN_INFO "saa7134 OSS: no saa7134 cards found\n");
1015 static void saa7134_oss_exit(void)
1017 struct saa7134_dev *dev;
1019 list_for_each_entry(dev, &saa7134_devlist, devlist) {
1020 /* Device isn't registered by OSS, probably ALSA's */
1021 if (!dev->dmasound.minor_dsp)
1024 oss_device_exit(dev);
1027 saa7134_dmasound_init = NULL;
1028 saa7134_dmasound_exit = NULL;
1030 printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n");
1035 /* We initialize this late, to make sure the sound system is up and running */
1036 late_initcall(saa7134_oss_init);
1037 module_exit(saa7134_oss_exit);
1038 MODULE_LICENSE("GPL");
1039 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
1041 /* ----------------------------------------------------------- */