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/moduleparam.h>
29 #include <linux/kernel.h>
30 #include <linux/interrupt.h>
31 #include <linux/slab.h>
32 #include <linux/sound.h>
33 #include <linux/soundcard.h>
35 #include "saa7134-reg.h"
38 /* ------------------------------------------------------------------ */
40 static unsigned int debug = 0;
41 module_param(debug, int, 0644);
42 MODULE_PARM_DESC(debug,"enable debug messages [oss]");
44 static unsigned int rate = 0;
45 module_param(rate, int, 0444);
46 MODULE_PARM_DESC(rate,"sample rate (valid are: 32000,48000)");
48 static unsigned int dsp_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
49 MODULE_PARM_DESC(dsp_nr, "device numbers for SAA7134 capture interface(s).");
50 module_param_array(dsp_nr, int, NULL, 0444);
52 static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
53 MODULE_PARM_DESC(mixer_nr, "mixer numbers for SAA7134 capture interface(s).");
54 module_param_array(mixer_nr, int, NULL, 0444);
56 #define dprintk(fmt, arg...) if (debug) \
57 printk(KERN_DEBUG "%s/oss: " fmt, dev->name , ## arg)
60 /* ------------------------------------------------------------------ */
62 static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks)
66 if (blksize > 0x10000)
71 if ((blksize * blocks) > 1024*1024)
72 blocks = 1024*1024 / blksize;
74 dev->dmasound.blocks = blocks;
75 dev->dmasound.blksize = blksize;
76 dev->dmasound.bufsize = blksize * blocks;
78 dprintk("buffer config: %d blocks / %d bytes, %d kB total\n",
79 blocks,blksize,blksize * blocks / 1024);
83 static int dsp_buffer_init(struct saa7134_dev *dev)
87 if (!dev->dmasound.bufsize)
89 videobuf_dma_init(&dev->dmasound.dma);
90 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE,
91 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
97 static int dsp_buffer_free(struct saa7134_dev *dev)
99 if (!dev->dmasound.blksize)
101 videobuf_dma_free(&dev->dmasound.dma);
102 dev->dmasound.blocks = 0;
103 dev->dmasound.blksize = 0;
104 dev->dmasound.bufsize = 0;
108 static void dsp_dma_start(struct saa7134_dev *dev)
110 dev->dmasound.dma_blk = 0;
111 dev->dmasound.dma_running = 1;
112 saa7134_set_dmabits(dev);
115 static void dsp_dma_stop(struct saa7134_dev *dev)
117 dev->dmasound.dma_blk = -1;
118 dev->dmasound.dma_running = 0;
119 saa7134_set_dmabits(dev);
122 static int dsp_rec_start(struct saa7134_dev *dev)
124 int err, bswap, sign;
129 if (0 != (err = videobuf_dma_pci_map(dev->pci,&dev->dmasound.dma)))
131 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt)))
133 if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->dmasound.pt,
134 dev->dmasound.dma.sglist,
135 dev->dmasound.dma.sglen,
140 switch (dev->dmasound.afmt) {
142 case AFMT_S8: fmt = 0x00; break;
146 case AFMT_S16_BE: fmt = 0x01; break;
152 switch (dev->dmasound.afmt) {
155 case AFMT_S16_BE: sign = 1; break;
156 default: sign = 0; break;
159 switch (dev->dmasound.afmt) {
161 case AFMT_S16_BE: bswap = 1; break;
162 default: bswap = 0; break;
165 switch (dev->pci->device) {
166 case PCI_DEVICE_ID_PHILIPS_SAA7134:
167 if (1 == dev->dmasound.channels)
169 if (2 == dev->dmasound.channels)
173 fmt |= (TV == dev->dmasound.input) ? 0xc0 : 0x80;
175 saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->dmasound.blksize - 1) & 0x0000ff));
176 saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->dmasound.blksize - 1) & 0x00ff00) >> 8);
177 saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->dmasound.blksize - 1) & 0xff0000) >> 16);
178 saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt);
181 case PCI_DEVICE_ID_PHILIPS_SAA7133:
182 case PCI_DEVICE_ID_PHILIPS_SAA7135:
183 if (1 == dev->dmasound.channels)
185 if (2 == dev->dmasound.channels)
189 saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -4);
190 saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24));
193 dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
194 dev->dmasound.afmt, dev->dmasound.channels, fmt,
197 /* dma: setup channel 6 (= AUDIO) */
198 control = SAA7134_RS_CONTROL_BURST_16 |
199 SAA7134_RS_CONTROL_ME |
200 (dev->dmasound.pt.dma >> 12);
202 control |= SAA7134_RS_CONTROL_BSWAP;
203 saa_writel(SAA7134_RS_BA1(6),0);
204 saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize);
205 saa_writel(SAA7134_RS_PITCH(6),0);
206 saa_writel(SAA7134_RS_CONTROL(6),control);
209 dev->dmasound.recording_on = 1;
210 spin_lock_irqsave(&dev->slock,flags);
212 spin_unlock_irqrestore(&dev->slock,flags);
216 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
218 videobuf_dma_pci_unmap(dev->pci,&dev->dmasound.dma);
222 static int dsp_rec_stop(struct saa7134_dev *dev)
226 dprintk("rec_stop dma_blk=%d\n",dev->dmasound.dma_blk);
229 dev->dmasound.recording_on = 0;
230 spin_lock_irqsave(&dev->slock,flags);
232 spin_unlock_irqrestore(&dev->slock,flags);
235 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
236 videobuf_dma_pci_unmap(dev->pci,&dev->dmasound.dma);
240 /* ------------------------------------------------------------------ */
242 static int dsp_open(struct inode *inode, struct file *file)
244 int minor = iminor(inode);
245 struct saa7134_dev *h,*dev = NULL;
246 struct list_head *list;
249 list_for_each(list,&saa7134_devlist) {
250 h = list_entry(list, struct saa7134_dev, devlist);
251 if (h->dmasound.minor_dsp == minor)
257 down(&dev->dmasound.lock);
259 if (dev->dmasound.users_dsp)
261 dev->dmasound.users_dsp++;
262 file->private_data = dev;
264 dev->dmasound.afmt = AFMT_U8;
265 dev->dmasound.channels = 1;
266 dev->dmasound.read_count = 0;
267 dev->dmasound.read_offset = 0;
268 dsp_buffer_conf(dev,PAGE_SIZE,64);
269 err = dsp_buffer_init(dev);
273 up(&dev->dmasound.lock);
277 dev->dmasound.users_dsp--;
279 up(&dev->dmasound.lock);
283 static int dsp_release(struct inode *inode, struct file *file)
285 struct saa7134_dev *dev = file->private_data;
287 down(&dev->dmasound.lock);
288 if (dev->dmasound.recording_on)
290 dsp_buffer_free(dev);
291 dev->dmasound.users_dsp--;
292 file->private_data = NULL;
293 up(&dev->dmasound.lock);
297 static ssize_t dsp_read(struct file *file, char __user *buffer,
298 size_t count, loff_t *ppos)
300 struct saa7134_dev *dev = file->private_data;
301 DECLARE_WAITQUEUE(wait, current);
306 add_wait_queue(&dev->dmasound.wq, &wait);
307 down(&dev->dmasound.lock);
309 /* wait for data if needed */
310 if (0 == dev->dmasound.read_count) {
311 if (!dev->dmasound.recording_on) {
312 err = dsp_rec_start(dev);
319 if (dev->dmasound.recording_on &&
320 !dev->dmasound.dma_running) {
321 /* recover from overruns */
322 spin_lock_irqsave(&dev->slock,flags);
324 spin_unlock_irqrestore(&dev->slock,flags);
326 if (file->f_flags & O_NONBLOCK) {
331 up(&dev->dmasound.lock);
332 set_current_state(TASK_INTERRUPTIBLE);
333 if (0 == dev->dmasound.read_count)
335 set_current_state(TASK_RUNNING);
336 down(&dev->dmasound.lock);
337 if (signal_pending(current)) {
344 /* copy data to userspace */
346 if (bytes > dev->dmasound.read_count)
347 bytes = dev->dmasound.read_count;
348 if (bytes > dev->dmasound.bufsize - dev->dmasound.read_offset)
349 bytes = dev->dmasound.bufsize - dev->dmasound.read_offset;
350 if (copy_to_user(buffer + ret,
351 dev->dmasound.dma.vmalloc + dev->dmasound.read_offset,
360 dev->dmasound.read_count -= bytes;
361 dev->dmasound.read_offset += bytes;
362 if (dev->dmasound.read_offset == dev->dmasound.bufsize)
363 dev->dmasound.read_offset = 0;
365 up(&dev->dmasound.lock);
366 remove_wait_queue(&dev->dmasound.wq, &wait);
370 static ssize_t dsp_write(struct file *file, const char __user *buffer,
371 size_t count, loff_t *ppos)
376 static const char *osspcm_ioctls[] = {
377 "RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT",
378 "CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS",
379 "GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER",
380 "GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO",
381 "SETDUPLEX", "GETODELAY"
383 #define OSSPCM_IOCTLS ARRAY_SIZE(osspcm_ioctls)
385 static void saa7134_oss_print_ioctl(char *name, unsigned int cmd)
389 switch (_IOC_DIR(cmd)) {
390 case _IOC_NONE: dir = "--"; break;
391 case _IOC_READ: dir = "r-"; break;
392 case _IOC_WRITE: dir = "-w"; break;
393 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
394 default: dir = "??"; break;
396 switch (_IOC_TYPE(cmd)) {
398 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n",
399 name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ?
400 osspcm_ioctls[_IOC_NR(cmd)] : "???");
403 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n",
404 name, cmd, dir, _IOC_NR(cmd));
407 printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",
408 name, cmd, dir, _IOC_NR(cmd));
412 static int dsp_ioctl(struct inode *inode, struct file *file,
413 unsigned int cmd, unsigned long arg)
415 struct saa7134_dev *dev = file->private_data;
416 void __user *argp = (void __user *) arg;
417 int __user *p = argp;
421 saa7134_oss_print_ioctl(dev->name,cmd);
424 return put_user(SOUND_VERSION, p);
425 case SNDCTL_DSP_GETCAPS:
428 case SNDCTL_DSP_SPEED:
429 if (get_user(val, p))
432 case SOUND_PCM_READ_RATE:
433 return put_user(dev->dmasound.rate, p);
435 case SNDCTL_DSP_STEREO:
436 if (get_user(val, p))
438 down(&dev->dmasound.lock);
439 dev->dmasound.channels = val ? 2 : 1;
440 if (dev->dmasound.recording_on) {
444 up(&dev->dmasound.lock);
445 return put_user(dev->dmasound.channels-1, p);
447 case SNDCTL_DSP_CHANNELS:
448 if (get_user(val, p))
450 if (val != 1 && val != 2)
452 down(&dev->dmasound.lock);
453 dev->dmasound.channels = val;
454 if (dev->dmasound.recording_on) {
458 up(&dev->dmasound.lock);
460 case SOUND_PCM_READ_CHANNELS:
461 return put_user(dev->dmasound.channels, p);
463 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
464 return put_user(AFMT_U8 | AFMT_S8 |
465 AFMT_U16_LE | AFMT_U16_BE |
466 AFMT_S16_LE | AFMT_S16_BE, p);
468 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
469 if (get_user(val, p))
481 down(&dev->dmasound.lock);
482 dev->dmasound.afmt = val;
483 if (dev->dmasound.recording_on) {
487 up(&dev->dmasound.lock);
488 return put_user(dev->dmasound.afmt, p);
493 case SOUND_PCM_READ_BITS:
494 switch (dev->dmasound.afmt) {
497 return put_user(8, p);
502 return put_user(16, p);
507 case SNDCTL_DSP_NONBLOCK:
508 file->f_flags |= O_NONBLOCK;
511 case SNDCTL_DSP_RESET:
512 down(&dev->dmasound.lock);
513 if (dev->dmasound.recording_on)
515 up(&dev->dmasound.lock);
517 case SNDCTL_DSP_GETBLKSIZE:
518 return put_user(dev->dmasound.blksize, p);
520 case SNDCTL_DSP_SETFRAGMENT:
521 if (get_user(val, p))
523 if (dev->dmasound.recording_on)
525 dsp_buffer_free(dev);
526 /* used to be arg >> 16 instead of val >> 16; fixed */
527 dsp_buffer_conf(dev,1 << (val & 0xffff), (val >> 16) & 0xffff);
528 dsp_buffer_init(dev);
531 case SNDCTL_DSP_SYNC:
535 case SNDCTL_DSP_GETISPACE:
538 info.fragsize = dev->dmasound.blksize;
539 info.fragstotal = dev->dmasound.blocks;
540 info.bytes = dev->dmasound.read_count;
541 info.fragments = info.bytes / info.fragsize;
542 if (copy_to_user(argp, &info, sizeof(info)))
551 static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait)
553 struct saa7134_dev *dev = file->private_data;
554 unsigned int mask = 0;
556 poll_wait(file, &dev->dmasound.wq, wait);
558 if (0 == dev->dmasound.read_count) {
559 down(&dev->dmasound.lock);
560 if (!dev->dmasound.recording_on)
562 up(&dev->dmasound.lock);
564 mask |= (POLLIN | POLLRDNORM);
568 struct file_operations saa7134_dsp_fops = {
569 .owner = THIS_MODULE,
571 .release = dsp_release,
579 /* ------------------------------------------------------------------ */
582 mixer_recsrc_7134(struct saa7134_dev *dev)
586 switch (dev->dmasound.input) {
588 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0);
589 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
594 analog_io = (LINE1 == dev->dmasound.input) ? 0x00 : 0x08;
595 rate = (32000 == dev->dmasound.rate) ? 0x01 : 0x03;
596 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io);
597 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80);
598 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate);
605 mixer_recsrc_7133(struct saa7134_dev *dev)
609 xbarin = 0x03; // adc
611 switch (dev->dmasound.input) {
613 xbarin = 0; // Demodulator
617 anabar = 0; // aux1, aux1
621 anabar = 9; // aux2, aux2
624 /* output xbar always main channel */
625 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10);
626 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
627 saa_writel(0x594 >> 2, anabar);
633 mixer_recsrc(struct saa7134_dev *dev, enum saa7134_audio_in src)
635 static const char *iname[] = { "Oops", "TV", "LINE1", "LINE2" };
637 dev->dmasound.count++;
638 dev->dmasound.input = src;
639 dprintk("mixer input = %s\n",iname[dev->dmasound.input]);
641 switch (dev->pci->device) {
642 case PCI_DEVICE_ID_PHILIPS_SAA7134:
643 mixer_recsrc_7134(dev);
645 case PCI_DEVICE_ID_PHILIPS_SAA7133:
646 case PCI_DEVICE_ID_PHILIPS_SAA7135:
647 mixer_recsrc_7133(dev);
654 mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level)
656 switch (dev->pci->device) {
657 case PCI_DEVICE_ID_PHILIPS_SAA7134:
663 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10,
664 (100 == level) ? 0x00 : 0x10);
668 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20,
669 (100 == level) ? 0x00 : 0x20);
673 case PCI_DEVICE_ID_PHILIPS_SAA7133:
674 case PCI_DEVICE_ID_PHILIPS_SAA7135:
681 /* ------------------------------------------------------------------ */
683 static int mixer_open(struct inode *inode, struct file *file)
685 int minor = iminor(inode);
686 struct saa7134_dev *h,*dev = NULL;
687 struct list_head *list;
689 list_for_each(list,&saa7134_devlist) {
690 h = list_entry(list, struct saa7134_dev, devlist);
691 if (h->dmasound.minor_mixer == minor)
697 file->private_data = dev;
701 static int mixer_release(struct inode *inode, struct file *file)
703 file->private_data = NULL;
707 static int mixer_ioctl(struct inode *inode, struct file *file,
708 unsigned int cmd, unsigned long arg)
710 struct saa7134_dev *dev = file->private_data;
711 enum saa7134_audio_in input;
713 void __user *argp = (void __user *) arg;
714 int __user *p = argp;
717 saa7134_oss_print_ioctl(dev->name,cmd);
720 return put_user(SOUND_VERSION, p);
721 case SOUND_MIXER_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 info.modify_counter = dev->dmasound.count;
728 if (copy_to_user(argp, &info, sizeof(info)))
732 case SOUND_OLD_MIXER_INFO:
734 _old_mixer_info info;
735 memset(&info,0,sizeof(info));
736 strlcpy(info.id, "TV audio", sizeof(info.id));
737 strlcpy(info.name, dev->name, sizeof(info.name));
738 if (copy_to_user(argp, &info, sizeof(info)))
742 case MIXER_READ(SOUND_MIXER_CAPS):
743 return put_user(SOUND_CAP_EXCL_INPUT, p);
744 case MIXER_READ(SOUND_MIXER_STEREODEVS):
745 return put_user(0, p);
746 case MIXER_READ(SOUND_MIXER_RECMASK):
747 case MIXER_READ(SOUND_MIXER_DEVMASK):
748 val = SOUND_MASK_LINE1 | SOUND_MASK_LINE2;
749 if (32000 == dev->dmasound.rate)
750 val |= SOUND_MASK_VIDEO;
751 return put_user(val, p);
753 case MIXER_WRITE(SOUND_MIXER_RECSRC):
754 if (get_user(val, p))
756 input = dev->dmasound.input;
757 if (32000 == dev->dmasound.rate &&
758 val & SOUND_MASK_VIDEO && dev->dmasound.input != TV)
760 if (val & SOUND_MASK_LINE1 && dev->dmasound.input != LINE1)
762 if (val & SOUND_MASK_LINE2 && dev->dmasound.input != LINE2)
764 if (input != dev->dmasound.input)
765 mixer_recsrc(dev,input);
767 case MIXER_READ(SOUND_MIXER_RECSRC):
768 switch (dev->dmasound.input) {
769 case TV: ret = SOUND_MASK_VIDEO; break;
770 case LINE1: ret = SOUND_MASK_LINE1; break;
771 case LINE2: ret = SOUND_MASK_LINE2; break;
774 return put_user(ret, p);
776 case MIXER_WRITE(SOUND_MIXER_VIDEO):
777 case MIXER_READ(SOUND_MIXER_VIDEO):
778 if (32000 != dev->dmasound.rate)
780 return put_user(100 | 100 << 8, p);
782 case MIXER_WRITE(SOUND_MIXER_LINE1):
783 if (get_user(val, p))
786 val = (val <= 50) ? 50 : 100;
787 dev->dmasound.line1 = val;
788 mixer_level(dev,LINE1,dev->dmasound.line1);
790 case MIXER_READ(SOUND_MIXER_LINE1):
791 return put_user(dev->dmasound.line1 | dev->dmasound.line1 << 8, p);
793 case MIXER_WRITE(SOUND_MIXER_LINE2):
794 if (get_user(val, p))
797 val = (val <= 50) ? 50 : 100;
798 dev->dmasound.line2 = val;
799 mixer_level(dev,LINE2,dev->dmasound.line2);
801 case MIXER_READ(SOUND_MIXER_LINE2):
802 return put_user(dev->dmasound.line2 | dev->dmasound.line2 << 8, p);
809 struct file_operations saa7134_mixer_fops = {
810 .owner = THIS_MODULE,
812 .release = mixer_release,
813 .ioctl = mixer_ioctl,
817 /* ------------------------------------------------------------------ */
819 static irqreturn_t saa7134_oss_irq(int irq, void *dev_id, struct pt_regs *regs)
821 struct saa7134_dmasound *dmasound = dev_id;
822 struct saa7134_dev *dev = dmasound->priv_data;
823 unsigned long report, status;
824 int loop, handled = 0;
826 for (loop = 0; loop < 10; loop++) {
827 report = saa_readl(SAA7134_IRQ_REPORT);
828 status = saa_readl(SAA7134_IRQ_STATUS);
830 if (report & SAA7134_IRQ_REPORT_DONE_RA3) {
832 saa_writel(SAA7134_IRQ_REPORT,report);
833 saa7134_irq_oss_done(dev, status);
840 dprintk("error! looping IRQ!");
843 return IRQ_RETVAL(handled);
846 int saa7134_oss_init1(struct saa7134_dev *dev)
849 if ((request_irq(dev->pci->irq, saa7134_oss_irq,
850 SA_SHIRQ | SA_INTERRUPT, dev->name,
851 (void*) &dev->dmasound)) < 0)
855 init_MUTEX(&dev->dmasound.lock);
856 init_waitqueue_head(&dev->dmasound.wq);
858 switch (dev->pci->device) {
859 case PCI_DEVICE_ID_PHILIPS_SAA7133:
860 case PCI_DEVICE_ID_PHILIPS_SAA7135:
861 saa_writel(0x588 >> 2, 0x00000fff);
862 saa_writel(0x58c >> 2, 0x00543210);
863 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbbbb);
868 dev->dmasound.rate = 32000;
870 dev->dmasound.rate = rate;
871 dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000;
874 dev->dmasound.line1 = 50;
875 dev->dmasound.line2 = 50;
876 mixer_level(dev,LINE1,dev->dmasound.line1);
877 mixer_level(dev,LINE2,dev->dmasound.line2);
878 mixer_recsrc(dev, (dev->dmasound.rate == 32000) ? TV : LINE2);
883 int saa7134_oss_fini(struct saa7134_dev *dev)
889 void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
891 int next_blk, reg = 0;
893 spin_lock(&dev->slock);
894 if (UNSET == dev->dmasound.dma_blk) {
895 dprintk("irq: recording stopped\n");
898 if (0 != (status & 0x0f000000))
899 dprintk("irq: lost %ld\n", (status >> 24) & 0x0f);
900 if (0 == (status & 0x10000000)) {
902 if (0 == (dev->dmasound.dma_blk & 0x01))
903 reg = SAA7134_RS_BA1(6);
906 if (1 == (dev->dmasound.dma_blk & 0x01))
907 reg = SAA7134_RS_BA2(6);
910 dprintk("irq: field oops [%s]\n",
911 (status & 0x10000000) ? "even" : "odd");
914 if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) {
915 dprintk("irq: overrun [full=%d/%d]\n",dev->dmasound.read_count,
916 dev->dmasound.bufsize);
921 /* next block addr */
922 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks;
923 saa_writel(reg,next_blk * dev->dmasound.blksize);
925 dprintk("irq: ok, %s, next_blk=%d, addr=%x\n",
926 (status & 0x10000000) ? "even" : "odd ", next_blk,
927 next_blk * dev->dmasound.blksize);
929 /* update status & wake waiting readers */
930 dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks;
931 dev->dmasound.read_count += dev->dmasound.blksize;
932 wake_up(&dev->dmasound.wq);
935 spin_unlock(&dev->slock);
938 static int saa7134_dsp_create(struct saa7134_dev *dev)
942 err = dev->dmasound.minor_dsp =
943 register_sound_dsp(&saa7134_dsp_fops,
948 printk(KERN_INFO "%s: registered device dsp%d\n",
949 dev->name,dev->dmasound.minor_dsp >> 4);
951 err = dev->dmasound.minor_mixer =
952 register_sound_mixer(&saa7134_mixer_fops,
956 printk(KERN_INFO "%s: registered device mixer%d\n",
957 dev->name,dev->dmasound.minor_mixer >> 4);
962 unregister_sound_dsp(dev->dmasound.minor_dsp);
968 static int oss_device_init(struct saa7134_dev *dev)
970 dev->dmasound.priv_data = dev;
971 saa7134_oss_init1(dev);
972 saa7134_dsp_create(dev);
976 static int oss_device_exit(struct saa7134_dev *dev)
979 unregister_sound_mixer(dev->dmasound.minor_mixer);
980 unregister_sound_dsp(dev->dmasound.minor_dsp);
982 saa7134_oss_fini(dev);
984 if (dev->pci->irq > 0) {
985 synchronize_irq(dev->pci->irq);
986 free_irq(dev->pci->irq,&dev->dmasound);
989 dev->dmasound.priv_data = NULL;
993 static int saa7134_oss_init(void)
995 struct saa7134_dev *dev = NULL;
996 struct list_head *list;
998 if (!dmasound_init && !dmasound_exit) {
999 dmasound_init = oss_device_init;
1000 dmasound_exit = oss_device_exit;
1002 printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n");
1006 printk(KERN_INFO "saa7134 OSS driver for DMA sound loaded\n");
1009 list_for_each(list,&saa7134_devlist) {
1010 dev = list_entry(list, struct saa7134_dev, devlist);
1011 if (dev->dmasound.priv_data == NULL) {
1012 oss_device_init(dev);
1014 printk(KERN_ERR "saa7134 OSS: DMA sound is being handled by ALSA, ignoring %s\n",dev->name);
1020 printk(KERN_INFO "saa7134 OSS: no saa7134 cards found\n");
1026 static void saa7134_oss_exit(void)
1028 struct saa7134_dev *dev = NULL;
1029 struct list_head *list;
1031 list_for_each(list,&saa7134_devlist) {
1032 dev = list_entry(list, struct saa7134_dev, devlist);
1034 /* Device isn't registered by OSS, probably ALSA's */
1035 if (!dev->dmasound.minor_dsp)
1038 oss_device_exit(dev);
1042 dmasound_init = NULL;
1043 dmasound_exit = NULL;
1045 printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n");
1050 /* We initialize this late, to make sure the sound system is up and running */
1051 late_initcall(saa7134_oss_init);
1052 module_exit(saa7134_oss_exit);
1053 MODULE_LICENSE("GPL");
1054 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
1056 /* ----------------------------------------------------------- */