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 BUG_ON(!dev->dmasound.bufsize);
88 videobuf_dma_init(&dev->dmasound.dma);
89 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE,
90 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
96 static int dsp_buffer_free(struct saa7134_dev *dev)
98 BUG_ON(!dev->dmasound.blksize);
99 videobuf_dma_free(&dev->dmasound.dma);
100 dev->dmasound.blocks = 0;
101 dev->dmasound.blksize = 0;
102 dev->dmasound.bufsize = 0;
106 static void dsp_dma_start(struct saa7134_dev *dev)
108 dev->dmasound.dma_blk = 0;
109 dev->dmasound.dma_running = 1;
110 saa7134_set_dmabits(dev);
113 static void dsp_dma_stop(struct saa7134_dev *dev)
115 dev->dmasound.dma_blk = -1;
116 dev->dmasound.dma_running = 0;
117 saa7134_set_dmabits(dev);
120 static int dsp_rec_start(struct saa7134_dev *dev)
122 int err, bswap, sign;
127 if (0 != (err = videobuf_pci_dma_map(dev->pci,&dev->dmasound.dma)))
129 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt)))
131 if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->dmasound.pt,
132 dev->dmasound.dma.sglist,
133 dev->dmasound.dma.sglen,
138 switch (dev->dmasound.afmt) {
140 case AFMT_S8: fmt = 0x00; break;
144 case AFMT_S16_BE: fmt = 0x01; break;
150 switch (dev->dmasound.afmt) {
153 case AFMT_S16_BE: sign = 1; break;
154 default: sign = 0; break;
157 switch (dev->dmasound.afmt) {
159 case AFMT_S16_BE: bswap = 1; break;
160 default: bswap = 0; break;
163 switch (dev->pci->device) {
164 case PCI_DEVICE_ID_PHILIPS_SAA7134:
165 if (1 == dev->dmasound.channels)
167 if (2 == dev->dmasound.channels)
171 fmt |= (TV == dev->dmasound.input) ? 0xc0 : 0x80;
173 saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->dmasound.blksize - 1) & 0x0000ff));
174 saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->dmasound.blksize - 1) & 0x00ff00) >> 8);
175 saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->dmasound.blksize - 1) & 0xff0000) >> 16);
176 saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt);
179 case PCI_DEVICE_ID_PHILIPS_SAA7133:
180 case PCI_DEVICE_ID_PHILIPS_SAA7135:
181 if (1 == dev->dmasound.channels)
183 if (2 == dev->dmasound.channels)
187 saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -4);
188 saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24));
191 dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
192 dev->dmasound.afmt, dev->dmasound.channels, fmt,
195 /* dma: setup channel 6 (= AUDIO) */
196 control = SAA7134_RS_CONTROL_BURST_16 |
197 SAA7134_RS_CONTROL_ME |
198 (dev->dmasound.pt.dma >> 12);
200 control |= SAA7134_RS_CONTROL_BSWAP;
201 saa_writel(SAA7134_RS_BA1(6),0);
202 saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize);
203 saa_writel(SAA7134_RS_PITCH(6),0);
204 saa_writel(SAA7134_RS_CONTROL(6),control);
207 dev->dmasound.recording_on = 1;
208 spin_lock_irqsave(&dev->slock,flags);
210 spin_unlock_irqrestore(&dev->slock,flags);
214 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
216 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
220 static int dsp_rec_stop(struct saa7134_dev *dev)
224 dprintk("rec_stop dma_blk=%d\n",dev->dmasound.dma_blk);
227 dev->dmasound.recording_on = 0;
228 spin_lock_irqsave(&dev->slock,flags);
230 spin_unlock_irqrestore(&dev->slock,flags);
233 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
234 videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma);
238 /* ------------------------------------------------------------------ */
240 static int dsp_open(struct inode *inode, struct file *file)
242 int minor = iminor(inode);
243 struct saa7134_dev *h,*dev = NULL;
244 struct list_head *list;
247 list_for_each(list,&saa7134_devlist) {
248 h = list_entry(list, struct saa7134_dev, devlist);
249 if (h->dmasound.minor_dsp == minor)
255 mutex_lock(&dev->dmasound.lock);
257 if (dev->dmasound.users_dsp)
259 dev->dmasound.users_dsp++;
260 file->private_data = dev;
262 dev->dmasound.afmt = AFMT_U8;
263 dev->dmasound.channels = 1;
264 dev->dmasound.read_count = 0;
265 dev->dmasound.read_offset = 0;
266 dsp_buffer_conf(dev,PAGE_SIZE,64);
267 err = dsp_buffer_init(dev);
271 mutex_unlock(&dev->dmasound.lock);
275 dev->dmasound.users_dsp--;
277 mutex_unlock(&dev->dmasound.lock);
281 static int dsp_release(struct inode *inode, struct file *file)
283 struct saa7134_dev *dev = file->private_data;
285 mutex_lock(&dev->dmasound.lock);
286 if (dev->dmasound.recording_on)
288 dsp_buffer_free(dev);
289 dev->dmasound.users_dsp--;
290 file->private_data = NULL;
291 mutex_unlock(&dev->dmasound.lock);
295 static ssize_t dsp_read(struct file *file, char __user *buffer,
296 size_t count, loff_t *ppos)
298 struct saa7134_dev *dev = file->private_data;
299 DECLARE_WAITQUEUE(wait, current);
304 add_wait_queue(&dev->dmasound.wq, &wait);
305 mutex_lock(&dev->dmasound.lock);
307 /* wait for data if needed */
308 if (0 == dev->dmasound.read_count) {
309 if (!dev->dmasound.recording_on) {
310 err = dsp_rec_start(dev);
317 if (dev->dmasound.recording_on &&
318 !dev->dmasound.dma_running) {
319 /* recover from overruns */
320 spin_lock_irqsave(&dev->slock,flags);
322 spin_unlock_irqrestore(&dev->slock,flags);
324 if (file->f_flags & O_NONBLOCK) {
329 mutex_unlock(&dev->dmasound.lock);
330 set_current_state(TASK_INTERRUPTIBLE);
331 if (0 == dev->dmasound.read_count)
333 set_current_state(TASK_RUNNING);
334 mutex_lock(&dev->dmasound.lock);
335 if (signal_pending(current)) {
342 /* copy data to userspace */
344 if (bytes > dev->dmasound.read_count)
345 bytes = dev->dmasound.read_count;
346 if (bytes > dev->dmasound.bufsize - dev->dmasound.read_offset)
347 bytes = dev->dmasound.bufsize - dev->dmasound.read_offset;
348 if (copy_to_user(buffer + ret,
349 dev->dmasound.dma.vmalloc + dev->dmasound.read_offset,
358 dev->dmasound.read_count -= bytes;
359 dev->dmasound.read_offset += bytes;
360 if (dev->dmasound.read_offset == dev->dmasound.bufsize)
361 dev->dmasound.read_offset = 0;
363 mutex_unlock(&dev->dmasound.lock);
364 remove_wait_queue(&dev->dmasound.wq, &wait);
368 static ssize_t dsp_write(struct file *file, const char __user *buffer,
369 size_t count, loff_t *ppos)
374 static const char *osspcm_ioctls[] = {
375 "RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT",
376 "CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS",
377 "GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER",
378 "GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO",
379 "SETDUPLEX", "GETODELAY"
381 #define OSSPCM_IOCTLS ARRAY_SIZE(osspcm_ioctls)
383 static void saa7134_oss_print_ioctl(char *name, unsigned int cmd)
387 switch (_IOC_DIR(cmd)) {
388 case _IOC_NONE: dir = "--"; break;
389 case _IOC_READ: dir = "r-"; break;
390 case _IOC_WRITE: dir = "-w"; break;
391 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
392 default: dir = "??"; break;
394 switch (_IOC_TYPE(cmd)) {
396 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n",
397 name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ?
398 osspcm_ioctls[_IOC_NR(cmd)] : "???");
401 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n",
402 name, cmd, dir, _IOC_NR(cmd));
405 printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",
406 name, cmd, dir, _IOC_NR(cmd));
410 static int dsp_ioctl(struct inode *inode, struct file *file,
411 unsigned int cmd, unsigned long arg)
413 struct saa7134_dev *dev = file->private_data;
414 void __user *argp = (void __user *) arg;
415 int __user *p = argp;
419 saa7134_oss_print_ioctl(dev->name,cmd);
422 return put_user(SOUND_VERSION, p);
423 case SNDCTL_DSP_GETCAPS:
426 case SNDCTL_DSP_SPEED:
427 if (get_user(val, p))
430 case SOUND_PCM_READ_RATE:
431 return put_user(dev->dmasound.rate, p);
433 case SNDCTL_DSP_STEREO:
434 if (get_user(val, p))
436 mutex_lock(&dev->dmasound.lock);
437 dev->dmasound.channels = val ? 2 : 1;
438 if (dev->dmasound.recording_on) {
442 mutex_unlock(&dev->dmasound.lock);
443 return put_user(dev->dmasound.channels-1, p);
445 case SNDCTL_DSP_CHANNELS:
446 if (get_user(val, p))
448 if (val != 1 && val != 2)
450 mutex_lock(&dev->dmasound.lock);
451 dev->dmasound.channels = val;
452 if (dev->dmasound.recording_on) {
456 mutex_unlock(&dev->dmasound.lock);
458 case SOUND_PCM_READ_CHANNELS:
459 return put_user(dev->dmasound.channels, p);
461 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
462 return put_user(AFMT_U8 | AFMT_S8 |
463 AFMT_U16_LE | AFMT_U16_BE |
464 AFMT_S16_LE | AFMT_S16_BE, p);
466 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
467 if (get_user(val, p))
479 mutex_lock(&dev->dmasound.lock);
480 dev->dmasound.afmt = val;
481 if (dev->dmasound.recording_on) {
485 mutex_unlock(&dev->dmasound.lock);
486 return put_user(dev->dmasound.afmt, p);
491 case SOUND_PCM_READ_BITS:
492 switch (dev->dmasound.afmt) {
495 return put_user(8, p);
500 return put_user(16, p);
505 case SNDCTL_DSP_NONBLOCK:
506 file->f_flags |= O_NONBLOCK;
509 case SNDCTL_DSP_RESET:
510 mutex_lock(&dev->dmasound.lock);
511 if (dev->dmasound.recording_on)
513 mutex_unlock(&dev->dmasound.lock);
515 case SNDCTL_DSP_GETBLKSIZE:
516 return put_user(dev->dmasound.blksize, p);
518 case SNDCTL_DSP_SETFRAGMENT:
519 if (get_user(val, p))
521 if (dev->dmasound.recording_on)
523 dsp_buffer_free(dev);
524 /* used to be arg >> 16 instead of val >> 16; fixed */
525 dsp_buffer_conf(dev,1 << (val & 0xffff), (val >> 16) & 0xffff);
526 dsp_buffer_init(dev);
529 case SNDCTL_DSP_SYNC:
533 case SNDCTL_DSP_GETISPACE:
536 info.fragsize = dev->dmasound.blksize;
537 info.fragstotal = dev->dmasound.blocks;
538 info.bytes = dev->dmasound.read_count;
539 info.fragments = info.bytes / info.fragsize;
540 if (copy_to_user(argp, &info, sizeof(info)))
549 static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait)
551 struct saa7134_dev *dev = file->private_data;
552 unsigned int mask = 0;
554 poll_wait(file, &dev->dmasound.wq, wait);
556 if (0 == dev->dmasound.read_count) {
557 mutex_lock(&dev->dmasound.lock);
558 if (!dev->dmasound.recording_on)
560 mutex_unlock(&dev->dmasound.lock);
562 mask |= (POLLIN | POLLRDNORM);
566 struct file_operations saa7134_dsp_fops = {
567 .owner = THIS_MODULE,
569 .release = dsp_release,
577 /* ------------------------------------------------------------------ */
580 mixer_recsrc_7134(struct saa7134_dev *dev)
584 switch (dev->dmasound.input) {
586 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0);
587 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
592 analog_io = (LINE1 == dev->dmasound.input) ? 0x00 : 0x08;
593 rate = (32000 == dev->dmasound.rate) ? 0x01 : 0x03;
594 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io);
595 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80);
596 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate);
603 mixer_recsrc_7133(struct saa7134_dev *dev)
607 xbarin = 0x03; // adc
609 switch (dev->dmasound.input) {
611 xbarin = 0; // Demodulator
615 anabar = 0; // aux1, aux1
619 anabar = 9; // aux2, aux2
622 /* output xbar always main channel */
623 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10);
624 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
625 saa_writel(0x594 >> 2, anabar);
631 mixer_recsrc(struct saa7134_dev *dev, enum saa7134_audio_in src)
633 static const char *iname[] = { "Oops", "TV", "LINE1", "LINE2" };
635 dev->dmasound.count++;
636 dev->dmasound.input = src;
637 dprintk("mixer input = %s\n",iname[dev->dmasound.input]);
639 switch (dev->pci->device) {
640 case PCI_DEVICE_ID_PHILIPS_SAA7134:
641 mixer_recsrc_7134(dev);
643 case PCI_DEVICE_ID_PHILIPS_SAA7133:
644 case PCI_DEVICE_ID_PHILIPS_SAA7135:
645 mixer_recsrc_7133(dev);
652 mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level)
654 switch (dev->pci->device) {
655 case PCI_DEVICE_ID_PHILIPS_SAA7134:
661 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10,
662 (100 == level) ? 0x00 : 0x10);
666 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20,
667 (100 == level) ? 0x00 : 0x20);
671 case PCI_DEVICE_ID_PHILIPS_SAA7133:
672 case PCI_DEVICE_ID_PHILIPS_SAA7135:
679 /* ------------------------------------------------------------------ */
681 static int mixer_open(struct inode *inode, struct file *file)
683 int minor = iminor(inode);
684 struct saa7134_dev *h,*dev = NULL;
685 struct list_head *list;
687 list_for_each(list,&saa7134_devlist) {
688 h = list_entry(list, struct saa7134_dev, devlist);
689 if (h->dmasound.minor_mixer == minor)
695 file->private_data = dev;
699 static int mixer_release(struct inode *inode, struct file *file)
701 file->private_data = NULL;
705 static int mixer_ioctl(struct inode *inode, struct file *file,
706 unsigned int cmd, unsigned long arg)
708 struct saa7134_dev *dev = file->private_data;
709 enum saa7134_audio_in input;
711 void __user *argp = (void __user *) arg;
712 int __user *p = argp;
715 saa7134_oss_print_ioctl(dev->name,cmd);
718 return put_user(SOUND_VERSION, p);
719 case SOUND_MIXER_INFO:
722 memset(&info,0,sizeof(info));
723 strlcpy(info.id, "TV audio", sizeof(info.id));
724 strlcpy(info.name, dev->name, sizeof(info.name));
725 info.modify_counter = dev->dmasound.count;
726 if (copy_to_user(argp, &info, sizeof(info)))
730 case SOUND_OLD_MIXER_INFO:
732 _old_mixer_info info;
733 memset(&info,0,sizeof(info));
734 strlcpy(info.id, "TV audio", sizeof(info.id));
735 strlcpy(info.name, dev->name, sizeof(info.name));
736 if (copy_to_user(argp, &info, sizeof(info)))
740 case MIXER_READ(SOUND_MIXER_CAPS):
741 return put_user(SOUND_CAP_EXCL_INPUT, p);
742 case MIXER_READ(SOUND_MIXER_STEREODEVS):
743 return put_user(0, p);
744 case MIXER_READ(SOUND_MIXER_RECMASK):
745 case MIXER_READ(SOUND_MIXER_DEVMASK):
746 val = SOUND_MASK_LINE1 | SOUND_MASK_LINE2;
747 if (32000 == dev->dmasound.rate)
748 val |= SOUND_MASK_VIDEO;
749 return put_user(val, p);
751 case MIXER_WRITE(SOUND_MIXER_RECSRC):
752 if (get_user(val, p))
754 input = dev->dmasound.input;
755 if (32000 == dev->dmasound.rate &&
756 val & SOUND_MASK_VIDEO && dev->dmasound.input != TV)
758 if (val & SOUND_MASK_LINE1 && dev->dmasound.input != LINE1)
760 if (val & SOUND_MASK_LINE2 && dev->dmasound.input != LINE2)
762 if (input != dev->dmasound.input)
763 mixer_recsrc(dev,input);
765 case MIXER_READ(SOUND_MIXER_RECSRC):
766 switch (dev->dmasound.input) {
767 case TV: ret = SOUND_MASK_VIDEO; break;
768 case LINE1: ret = SOUND_MASK_LINE1; break;
769 case LINE2: ret = SOUND_MASK_LINE2; break;
772 return put_user(ret, p);
774 case MIXER_WRITE(SOUND_MIXER_VIDEO):
775 case MIXER_READ(SOUND_MIXER_VIDEO):
776 if (32000 != dev->dmasound.rate)
778 return put_user(100 | 100 << 8, p);
780 case MIXER_WRITE(SOUND_MIXER_LINE1):
781 if (get_user(val, p))
784 val = (val <= 50) ? 50 : 100;
785 dev->dmasound.line1 = val;
786 mixer_level(dev,LINE1,dev->dmasound.line1);
788 case MIXER_READ(SOUND_MIXER_LINE1):
789 return put_user(dev->dmasound.line1 | dev->dmasound.line1 << 8, p);
791 case MIXER_WRITE(SOUND_MIXER_LINE2):
792 if (get_user(val, p))
795 val = (val <= 50) ? 50 : 100;
796 dev->dmasound.line2 = val;
797 mixer_level(dev,LINE2,dev->dmasound.line2);
799 case MIXER_READ(SOUND_MIXER_LINE2):
800 return put_user(dev->dmasound.line2 | dev->dmasound.line2 << 8, p);
807 struct file_operations saa7134_mixer_fops = {
808 .owner = THIS_MODULE,
810 .release = mixer_release,
811 .ioctl = mixer_ioctl,
815 /* ------------------------------------------------------------------ */
817 static irqreturn_t saa7134_oss_irq(int irq, void *dev_id, struct pt_regs *regs)
819 struct saa7134_dmasound *dmasound = dev_id;
820 struct saa7134_dev *dev = dmasound->priv_data;
821 unsigned long report, status;
822 int loop, handled = 0;
824 for (loop = 0; loop < 10; loop++) {
825 report = saa_readl(SAA7134_IRQ_REPORT);
826 status = saa_readl(SAA7134_IRQ_STATUS);
828 if (report & SAA7134_IRQ_REPORT_DONE_RA3) {
830 saa_writel(SAA7134_IRQ_REPORT,report);
831 saa7134_irq_oss_done(dev, status);
838 dprintk("error! looping IRQ!");
841 return IRQ_RETVAL(handled);
844 int saa7134_oss_init1(struct saa7134_dev *dev)
847 if ((request_irq(dev->pci->irq, saa7134_oss_irq,
848 IRQF_SHARED | IRQF_DISABLED, dev->name,
849 (void*) &dev->dmasound)) < 0)
853 mutex_init(&dev->dmasound.lock);
854 init_waitqueue_head(&dev->dmasound.wq);
856 switch (dev->pci->device) {
857 case PCI_DEVICE_ID_PHILIPS_SAA7133:
858 case PCI_DEVICE_ID_PHILIPS_SAA7135:
859 saa_writel(0x588 >> 2, 0x00000fff);
860 saa_writel(0x58c >> 2, 0x00543210);
861 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbbbb);
866 dev->dmasound.rate = 32000;
868 dev->dmasound.rate = rate;
869 dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000;
872 dev->dmasound.line1 = 50;
873 dev->dmasound.line2 = 50;
874 mixer_level(dev,LINE1,dev->dmasound.line1);
875 mixer_level(dev,LINE2,dev->dmasound.line2);
876 mixer_recsrc(dev, (dev->dmasound.rate == 32000) ? TV : LINE2);
881 int saa7134_oss_fini(struct saa7134_dev *dev)
887 void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
889 int next_blk, reg = 0;
891 spin_lock(&dev->slock);
892 if (UNSET == dev->dmasound.dma_blk) {
893 dprintk("irq: recording stopped\n");
896 if (0 != (status & 0x0f000000))
897 dprintk("irq: lost %ld\n", (status >> 24) & 0x0f);
898 if (0 == (status & 0x10000000)) {
900 if (0 == (dev->dmasound.dma_blk & 0x01))
901 reg = SAA7134_RS_BA1(6);
904 if (1 == (dev->dmasound.dma_blk & 0x01))
905 reg = SAA7134_RS_BA2(6);
908 dprintk("irq: field oops [%s]\n",
909 (status & 0x10000000) ? "even" : "odd");
912 if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) {
913 dprintk("irq: overrun [full=%d/%d]\n",dev->dmasound.read_count,
914 dev->dmasound.bufsize);
919 /* next block addr */
920 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks;
921 saa_writel(reg,next_blk * dev->dmasound.blksize);
923 dprintk("irq: ok, %s, next_blk=%d, addr=%x\n",
924 (status & 0x10000000) ? "even" : "odd ", next_blk,
925 next_blk * dev->dmasound.blksize);
927 /* update status & wake waiting readers */
928 dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks;
929 dev->dmasound.read_count += dev->dmasound.blksize;
930 wake_up(&dev->dmasound.wq);
933 spin_unlock(&dev->slock);
936 static int saa7134_dsp_create(struct saa7134_dev *dev)
940 err = dev->dmasound.minor_dsp =
941 register_sound_dsp(&saa7134_dsp_fops,
946 printk(KERN_INFO "%s: registered device dsp%d\n",
947 dev->name,dev->dmasound.minor_dsp >> 4);
949 err = dev->dmasound.minor_mixer =
950 register_sound_mixer(&saa7134_mixer_fops,
954 printk(KERN_INFO "%s: registered device mixer%d\n",
955 dev->name,dev->dmasound.minor_mixer >> 4);
960 unregister_sound_dsp(dev->dmasound.minor_dsp);
966 static int oss_device_init(struct saa7134_dev *dev)
968 dev->dmasound.priv_data = dev;
969 saa7134_oss_init1(dev);
970 saa7134_dsp_create(dev);
974 static int oss_device_exit(struct saa7134_dev *dev)
977 unregister_sound_mixer(dev->dmasound.minor_mixer);
978 unregister_sound_dsp(dev->dmasound.minor_dsp);
980 saa7134_oss_fini(dev);
982 if (dev->pci->irq > 0) {
983 synchronize_irq(dev->pci->irq);
984 free_irq(dev->pci->irq,&dev->dmasound);
987 dev->dmasound.priv_data = NULL;
991 static int saa7134_oss_init(void)
993 struct saa7134_dev *dev = NULL;
994 struct list_head *list;
996 if (!dmasound_init && !dmasound_exit) {
997 dmasound_init = oss_device_init;
998 dmasound_exit = oss_device_exit;
1000 printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n");
1004 printk(KERN_INFO "saa7134 OSS driver for DMA sound loaded\n");
1007 list_for_each(list,&saa7134_devlist) {
1008 dev = list_entry(list, struct saa7134_dev, devlist);
1009 if (dev->dmasound.priv_data == NULL) {
1010 oss_device_init(dev);
1012 printk(KERN_ERR "saa7134 OSS: DMA sound is being handled by ALSA, ignoring %s\n",dev->name);
1018 printk(KERN_INFO "saa7134 OSS: no saa7134 cards found\n");
1024 static void saa7134_oss_exit(void)
1026 struct saa7134_dev *dev = NULL;
1027 struct list_head *list;
1029 list_for_each(list,&saa7134_devlist) {
1030 dev = list_entry(list, struct saa7134_dev, devlist);
1032 /* Device isn't registered by OSS, probably ALSA's */
1033 if (!dev->dmasound.minor_dsp)
1036 oss_device_exit(dev);
1040 dmasound_init = NULL;
1041 dmasound_exit = NULL;
1043 printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n");
1048 /* We initialize this late, to make sure the sound system is up and running */
1049 late_initcall(saa7134_oss_init);
1050 module_exit(saa7134_oss_exit);
1051 MODULE_LICENSE("GPL");
1052 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
1054 /* ----------------------------------------------------------- */