aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRicardo Cerqueira <v4l@cerqueira.org>2005-11-13 19:08:00 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-13 21:14:19 -0500
commit4aabf6331f89c18a46e7f083ca0b27f15ca85422 (patch)
tree2a512246717df6fb37f6dd6c3444972b43aea51b /drivers
parent714a095abfa22dfe2accf641118a65796e966a98 (diff)
[PATCH] v4l: (951) Make saa7134-oss as a stand-alone module
- saa7134-oss is now a standalone module as well - remaining DMA sound code has been removed from core the module - Lots of small cleanups and variable renames to get more consistency between the OSS and ALSA drivers - Fixed saa7134-alsa spinlock bug - Added missing #include in saa7134-oss Signed-off-by: Ricardo Cerqueira <v4l@cerqueira.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/saa7134/Makefile7
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c130
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c118
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c161
-rw-r--r--drivers/media/video/saa7134/saa7134.h1
5 files changed, 250 insertions, 167 deletions
diff --git a/drivers/media/video/saa7134/Makefile b/drivers/media/video/saa7134/Makefile
index e0b28f0533af..4226b61cc613 100644
--- a/drivers/media/video/saa7134/Makefile
+++ b/drivers/media/video/saa7134/Makefile
@@ -1,10 +1,11 @@
1 1
2saa7134-objs := saa7134-cards.o saa7134-core.o saa7134-i2c.o \ 2saa7134-objs := saa7134-cards.o saa7134-core.o saa7134-i2c.o \
3 saa7134-oss.o saa7134-ts.o saa7134-tvaudio.o \ 3 saa7134-ts.o saa7134-tvaudio.o saa7134-vbi.o \
4 saa7134-vbi.o saa7134-video.o saa7134-input.o 4 saa7134-video.o saa7134-input.o
5 5
6obj-$(CONFIG_VIDEO_SAA7134) += saa7134.o saa7134-empress.o \ 6obj-$(CONFIG_VIDEO_SAA7134) += saa7134.o saa7134-empress.o \
7 saa6752hs.o saa7134-alsa.o 7 saa6752hs.o saa7134-alsa.o \
8 saa7134-oss.o
8obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o 9obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o
9 10
10EXTRA_CFLAGS += -I$(src)/.. 11EXTRA_CFLAGS += -I$(src)/..
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 0025191f616a..289ca3ac99b2 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -71,7 +71,7 @@ typedef struct snd_card_saa7134 {
71 int mixer_volume[MIXER_ADDR_LAST+1][2]; 71 int mixer_volume[MIXER_ADDR_LAST+1][2];
72 int capture_source[MIXER_ADDR_LAST+1][2]; 72 int capture_source[MIXER_ADDR_LAST+1][2];
73 struct pci_dev *pci; 73 struct pci_dev *pci;
74 struct saa7134_dev *saadev; 74 struct saa7134_dev *dev;
75 75
76 unsigned long iobase; 76 unsigned long iobase;
77 int irq; 77 int irq;
@@ -86,12 +86,10 @@ typedef struct snd_card_saa7134 {
86 */ 86 */
87 87
88typedef struct snd_card_saa7134_pcm { 88typedef struct snd_card_saa7134_pcm {
89 struct saa7134_dev *saadev; 89 struct saa7134_dev *dev;
90 90
91 spinlock_t lock; 91 spinlock_t lock;
92 unsigned int pcm_size; /* buffer size */ 92
93 unsigned int pcm_count; /* bytes per period */
94 unsigned int pcm_bps; /* bytes per second */
95 snd_pcm_substream_t *substream; 93 snd_pcm_substream_t *substream;
96} snd_card_saa7134_pcm_t; 94} snd_card_saa7134_pcm_t;
97 95
@@ -193,6 +191,7 @@ void saa7134_irq_alsa_done(struct saa7134_dev *dev, unsigned long status)
193 snd_pcm_period_elapsed(dev->dmasound.substream); 191 snd_pcm_period_elapsed(dev->dmasound.substream);
194 spin_lock(&dev->slock); 192 spin_lock(&dev->slock);
195 } 193 }
194
196 done: 195 done:
197 spin_unlock(&dev->slock); 196 spin_unlock(&dev->slock);
198 197
@@ -208,8 +207,9 @@ void saa7134_irq_alsa_done(struct saa7134_dev *dev, unsigned long status)
208 207
209static irqreturn_t saa7134_alsa_irq(int irq, void *dev_id, struct pt_regs *regs) 208static irqreturn_t saa7134_alsa_irq(int irq, void *dev_id, struct pt_regs *regs)
210{ 209{
211 snd_card_saa7134_t *saa7134 = dev_id; 210 struct saa7134_dmasound *dmasound = dev_id;
212 struct saa7134_dev *dev = saa7134->saadev; 211 struct saa7134_dev *dev = dmasound->priv_data;
212
213 unsigned long report, status; 213 unsigned long report, status;
214 int loop, handled = 0; 214 int loop, handled = 0;
215 215
@@ -248,8 +248,8 @@ static int snd_card_saa7134_capture_trigger(snd_pcm_substream_t * substream,
248 int cmd) 248 int cmd)
249{ 249{
250 snd_pcm_runtime_t *runtime = substream->runtime; 250 snd_pcm_runtime_t *runtime = substream->runtime;
251 snd_card_saa7134_pcm_t *saapcm = runtime->private_data; 251 snd_card_saa7134_pcm_t *pcm = runtime->private_data;
252 struct saa7134_dev *dev=saapcm->saadev; 252 struct saa7134_dev *dev=pcm->dev;
253 int err = 0; 253 int err = 0;
254 254
255 spin_lock_irq(&dev->slock); 255 spin_lock_irq(&dev->slock);
@@ -315,8 +315,8 @@ static int dsp_buffer_init(struct saa7134_dev *dev)
315{ 315{
316 int err; 316 int err;
317 317
318 if (!dev->dmasound.bufsize) 318 BUG_ON(!dev->dmasound.bufsize);
319 BUG(); 319
320 videobuf_dma_init(&dev->dmasound.dma); 320 videobuf_dma_init(&dev->dmasound.dma);
321 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE, 321 err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE,
322 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT); 322 (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
@@ -344,28 +344,18 @@ static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream)
344 u32 fmt, control; 344 u32 fmt, control;
345 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); 345 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
346 struct saa7134_dev *dev; 346 struct saa7134_dev *dev;
347 snd_card_saa7134_pcm_t *saapcm = runtime->private_data; 347 snd_card_saa7134_pcm_t *pcm = runtime->private_data;
348 unsigned int bps;
349 unsigned long size; 348 unsigned long size;
350 unsigned count; 349 unsigned count;
351 350
352 size = snd_pcm_lib_buffer_bytes(substream); 351 size = snd_pcm_lib_buffer_bytes(substream);
353 count = snd_pcm_lib_period_bytes(substream); 352 count = snd_pcm_lib_period_bytes(substream);
354 353
355 saapcm->saadev->dmasound.substream = substream; 354 pcm->dev->dmasound.substream = substream;
356 bps = runtime->rate * runtime->channels;
357 bps *= snd_pcm_format_width(runtime->format);
358 bps /= 8;
359 if (bps <= 0)
360 return -EINVAL;
361 saapcm->pcm_bps = bps;
362 saapcm->pcm_size = snd_pcm_lib_buffer_bytes(substream);
363 saapcm->pcm_count = snd_pcm_lib_period_bytes(substream);
364
365 355
366 dev=saa7134->saadev; 356 dev=saa7134->dev;
367 357
368 dsp_buffer_conf(dev,saapcm->pcm_count,(saapcm->pcm_size/saapcm->pcm_count)); 358 dsp_buffer_conf(dev,count,(size/count));
369 359
370 err = dsp_buffer_init(dev); 360 err = dsp_buffer_init(dev);
371 if (0 != err) 361 if (0 != err)
@@ -445,7 +435,6 @@ static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream)
445 fmt |= 0x04; 435 fmt |= 0x04;
446 saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -1); 436 saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -1);
447 saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24)); 437 saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24));
448 //saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210);
449 break; 438 break;
450 } 439 }
451 440
@@ -496,10 +485,8 @@ static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream)
496static snd_pcm_uframes_t snd_card_saa7134_capture_pointer(snd_pcm_substream_t * substream) 485static snd_pcm_uframes_t snd_card_saa7134_capture_pointer(snd_pcm_substream_t * substream)
497{ 486{
498 snd_pcm_runtime_t *runtime = substream->runtime; 487 snd_pcm_runtime_t *runtime = substream->runtime;
499 snd_card_saa7134_pcm_t *saapcm = runtime->private_data; 488 snd_card_saa7134_pcm_t *pcm = runtime->private_data;
500 struct saa7134_dev *dev=saapcm->saadev; 489 struct saa7134_dev *dev=pcm->dev;
501
502
503 490
504 if (dev->dmasound.read_count) { 491 if (dev->dmasound.read_count) {
505 dev->dmasound.read_count -= snd_pcm_lib_period_bytes(substream); 492 dev->dmasound.read_count -= snd_pcm_lib_period_bytes(substream);
@@ -540,9 +527,9 @@ static snd_pcm_hardware_t snd_card_saa7134_capture =
540 527
541static void snd_card_saa7134_runtime_free(snd_pcm_runtime_t *runtime) 528static void snd_card_saa7134_runtime_free(snd_pcm_runtime_t *runtime)
542{ 529{
543 snd_card_saa7134_pcm_t *saapcm = runtime->private_data; 530 snd_card_saa7134_pcm_t *pcm = runtime->private_data;
544 531
545 kfree(saapcm); 532 kfree(pcm);
546} 533}
547 534
548 535
@@ -571,7 +558,7 @@ static int snd_card_saa7134_hw_params(snd_pcm_substream_t * substream,
571 * 558 *
572 * Called after closing the device, but before snd_card_saa7134_capture_close 559 * Called after closing the device, but before snd_card_saa7134_capture_close
573 * Usually used in ALSA to free the DMA, but since we don't use the 560 * Usually used in ALSA to free the DMA, but since we don't use the
574 * ALSA DMA I'm almost sure this isn't necessary. 561 * ALSA DMA it does nothing
575 * 562 *
576 */ 563 */
577 564
@@ -614,7 +601,7 @@ static int dsp_buffer_free(struct saa7134_dev *dev)
614static int snd_card_saa7134_capture_close(snd_pcm_substream_t * substream) 601static int snd_card_saa7134_capture_close(snd_pcm_substream_t * substream)
615{ 602{
616 snd_card_saa7134_t *chip = snd_pcm_substream_chip(substream); 603 snd_card_saa7134_t *chip = snd_pcm_substream_chip(substream);
617 struct saa7134_dev *dev = chip->saadev; 604 struct saa7134_dev *dev = chip->dev;
618 605
619 /* unlock buffer */ 606 /* unlock buffer */
620 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt); 607 saa7134_pgtable_free(dev->pci,&dev->dmasound.pt);
@@ -637,29 +624,28 @@ static int snd_card_saa7134_capture_close(snd_pcm_substream_t * substream)
637static int snd_card_saa7134_capture_open(snd_pcm_substream_t * substream) 624static int snd_card_saa7134_capture_open(snd_pcm_substream_t * substream)
638{ 625{
639 snd_pcm_runtime_t *runtime = substream->runtime; 626 snd_pcm_runtime_t *runtime = substream->runtime;
640 snd_card_saa7134_pcm_t *saapcm; 627 snd_card_saa7134_pcm_t *pcm;
641 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); 628 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
642 struct saa7134_dev *dev = saa7134->saadev; 629 struct saa7134_dev *dev = saa7134->dev;
643 int err; 630 int err;
644 631
645 down(&dev->dmasound.lock); 632 down(&dev->dmasound.lock);
646 633
647 dev->dmasound.afmt = SNDRV_PCM_FORMAT_U8;
648 dev->dmasound.channels = 2;
649 dev->dmasound.read_count = 0; 634 dev->dmasound.read_count = 0;
650 dev->dmasound.read_offset = 0; 635 dev->dmasound.read_offset = 0;
651 636
652 up(&dev->dmasound.lock); 637 up(&dev->dmasound.lock);
653 638
654 saapcm = kzalloc(sizeof(*saapcm), GFP_KERNEL); 639 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
655 if (saapcm == NULL) 640 if (pcm == NULL)
656 return -ENOMEM; 641 return -ENOMEM;
657 saapcm->saadev=saa7134->saadev;
658 642
659 spin_lock_init(&saapcm->lock); 643 pcm->dev=saa7134->dev;
644
645 spin_lock_init(&pcm->lock);
660 646
661 saapcm->substream = substream; 647 pcm->substream = substream;
662 runtime->private_data = saapcm; 648 runtime->private_data = pcm;
663 runtime->private_free = snd_card_saa7134_runtime_free; 649 runtime->private_free = snd_card_saa7134_runtime_free;
664 runtime->hw = snd_card_saa7134_capture; 650 runtime->hw = snd_card_saa7134_capture;
665 651
@@ -782,6 +768,7 @@ static int snd_saa7134_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_
782 ucontrol->value.integer.value[0] = chip->capture_source[addr][0]; 768 ucontrol->value.integer.value[0] = chip->capture_source[addr][0];
783 ucontrol->value.integer.value[1] = chip->capture_source[addr][1]; 769 ucontrol->value.integer.value[1] = chip->capture_source[addr][1];
784 spin_unlock_irqrestore(&chip->mixer_lock, flags); 770 spin_unlock_irqrestore(&chip->mixer_lock, flags);
771
785 return 0; 772 return 0;
786} 773}
787 774
@@ -794,7 +781,7 @@ static int snd_saa7134_capsrc_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_
794 int analog_io, rate; 781 int analog_io, rate;
795 struct saa7134_dev *dev; 782 struct saa7134_dev *dev;
796 783
797 dev = chip->saadev; 784 dev = chip->dev;
798 785
799 left = ucontrol->value.integer.value[0] & 1; 786 left = ucontrol->value.integer.value[0] & 1;
800 right = ucontrol->value.integer.value[1] & 1; 787 right = ucontrol->value.integer.value[1] & 1;
@@ -904,11 +891,16 @@ static int snd_saa7134_dev_free(snd_device_t *device)
904{ 891{
905 snd_card_saa7134_t *chip = device->device_data; 892 snd_card_saa7134_t *chip = device->device_data;
906 893
894 if (chip->dev->dmasound.priv_data == NULL)
895 return 0;
896
907 if (chip->irq >= 0) { 897 if (chip->irq >= 0) {
908 synchronize_irq(chip->irq); 898 synchronize_irq(chip->irq);
909 free_irq(chip->irq, (void *) chip); 899 free_irq(chip->irq, &chip->dev->dmasound);
910 } 900 }
911 901
902 chip->dev->dmasound.priv_data = NULL;
903
912 return 0; 904 return 0;
913} 905}
914 906
@@ -920,7 +912,7 @@ static int snd_saa7134_dev_free(snd_device_t *device)
920 * 912 *
921 */ 913 */
922 914
923int alsa_card_saa7134_create(struct saa7134_dev *saadev, int dev) 915int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
924{ 916{
925 917
926 snd_card_t *card; 918 snd_card_t *card;
@@ -931,12 +923,12 @@ int alsa_card_saa7134_create(struct saa7134_dev *saadev, int dev)
931 }; 923 };
932 924
933 925
934 if (dev >= SNDRV_CARDS) 926 if (devnum >= SNDRV_CARDS)
935 return -ENODEV; 927 return -ENODEV;
936 if (!enable[dev]) 928 if (!enable[devnum])
937 return -ENODEV; 929 return -ENODEV;
938 930
939 card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(snd_card_saa7134_t)); 931 card = snd_card_new(index[devnum], id[devnum], THIS_MODULE, sizeof(snd_card_saa7134_t));
940 932
941 if (card == NULL) 933 if (card == NULL)
942 return -ENOMEM; 934 return -ENOMEM;
@@ -951,23 +943,27 @@ int alsa_card_saa7134_create(struct saa7134_dev *saadev, int dev)
951 spin_lock_init(&chip->lock); 943 spin_lock_init(&chip->lock);
952 spin_lock_init(&chip->mixer_lock); 944 spin_lock_init(&chip->mixer_lock);
953 945
954 chip->saadev = saadev; 946 chip->dev = dev;
955 947
956 chip->card = card; 948 chip->card = card;
957 949
958 chip->pci = saadev->pci; 950 chip->pci = dev->pci;
959 chip->irq = saadev->pci->irq; 951 chip->irq = dev->pci->irq;
960 chip->iobase = pci_resource_start(saadev->pci, 0); 952 chip->iobase = pci_resource_start(dev->pci, 0);
953
961 954
962 err = request_irq(saadev->pci->irq, saa7134_alsa_irq, 955 err = request_irq(dev->pci->irq, saa7134_alsa_irq,
963 SA_SHIRQ | SA_INTERRUPT, saadev->name, (void *)chip); 956 SA_SHIRQ | SA_INTERRUPT, dev->name,
957 (void*) &dev->dmasound);
964 958
965 if (err < 0) { 959 if (err < 0) {
966 printk(KERN_ERR "%s: can't get IRQ %d for ALSA\n", 960 printk(KERN_ERR "%s: can't get IRQ %d for ALSA\n",
967 saadev->name, saadev->pci->irq); 961 dev->name, dev->pci->irq);
968 goto __nodev; 962 goto __nodev;
969 } 963 }
970 964
965 init_MUTEX(&dev->dmasound.lock);
966
971 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 967 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
972 goto __nodev; 968 goto __nodev;
973 } 969 }
@@ -984,10 +980,10 @@ int alsa_card_saa7134_create(struct saa7134_dev *saadev, int dev)
984 980
985 strcpy(card->shortname, "SAA7134"); 981 strcpy(card->shortname, "SAA7134");
986 sprintf(card->longname, "%s at 0x%lx irq %d", 982 sprintf(card->longname, "%s at 0x%lx irq %d",
987 chip->saadev->name, chip->iobase, chip->irq); 983 chip->dev->name, chip->iobase, chip->irq);
988 984
989 if ((err = snd_card_register(card)) == 0) { 985 if ((err = snd_card_register(card)) == 0) {
990 snd_saa7134_cards[dev] = card; 986 snd_saa7134_cards[devnum] = card;
991 return 0; 987 return 0;
992 } 988 }
993 989
@@ -1006,7 +1002,7 @@ __nodev:
1006 1002
1007static int saa7134_alsa_init(void) 1003static int saa7134_alsa_init(void)
1008{ 1004{
1009 struct saa7134_dev *saadev = NULL; 1005 struct saa7134_dev *dev = NULL;
1010 struct list_head *list; 1006 struct list_head *list;
1011 1007
1012 position = 0; 1008 position = 0;
@@ -1014,12 +1010,18 @@ static int saa7134_alsa_init(void)
1014 printk(KERN_INFO "saa7134 ALSA driver for DMA sound loaded\n"); 1010 printk(KERN_INFO "saa7134 ALSA driver for DMA sound loaded\n");
1015 1011
1016 list_for_each(list,&saa7134_devlist) { 1012 list_for_each(list,&saa7134_devlist) {
1017 saadev = list_entry(list, struct saa7134_dev, devlist); 1013 dev = list_entry(list, struct saa7134_dev, devlist);
1018 alsa_card_saa7134_create(saadev,position); 1014 if (dev->dmasound.priv_data == NULL) {
1019 position++; 1015 dev->dmasound.priv_data = dev;
1016 alsa_card_saa7134_create(dev,position);
1017 position++;
1018 } else {
1019 printk(KERN_ERR "saa7134 ALSA: DMA sound is being handled by OSS. ignoring %s\n",dev->name);
1020 return -EBUSY;
1021 }
1020 } 1022 }
1021 1023
1022 if (saadev == NULL) 1024 if (dev == NULL)
1023 printk(KERN_INFO "saa7134 ALSA: no saa7134 cards found\n"); 1025 printk(KERN_INFO "saa7134 ALSA: no saa7134 cards found\n");
1024 1026
1025 return 0; 1027 return 0;
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 14347854f98c..4275d2ddb864 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -53,13 +53,13 @@ static unsigned int gpio_tracking = 0;
53module_param(gpio_tracking, int, 0644); 53module_param(gpio_tracking, int, 0644);
54MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]"); 54MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]");
55 55
56static unsigned int oss = 0;
57module_param(oss, int, 0444);
58MODULE_PARM_DESC(oss,"register oss devices (default: no)");
59
60static unsigned int alsa = 0; 56static unsigned int alsa = 0;
61module_param(alsa, int, 0444); 57module_param(alsa, int, 0644);
62MODULE_PARM_DESC(alsa,"register alsa devices (default: no)"); 58MODULE_PARM_DESC(alsa,"enable ALSA DMA sound [dmasound]");
59
60static unsigned int oss = 0;
61module_param(oss, int, 0644);
62MODULE_PARM_DESC(oss,"enable OSS DMA sound [dmasound]");
63 63
64static unsigned int latency = UNSET; 64static unsigned int latency = UNSET;
65module_param(latency, int, 0444); 65module_param(latency, int, 0444);
@@ -68,24 +68,18 @@ MODULE_PARM_DESC(latency,"pci latency timer");
68static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 68static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
69static unsigned int vbi_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 69static unsigned int vbi_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
70static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 70static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
71static unsigned int dsp_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
72static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
73static unsigned int tuner[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 71static unsigned int tuner[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
74static unsigned int card[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 72static unsigned int card[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
75 73
76module_param_array(video_nr, int, NULL, 0444); 74module_param_array(video_nr, int, NULL, 0444);
77module_param_array(vbi_nr, int, NULL, 0444); 75module_param_array(vbi_nr, int, NULL, 0444);
78module_param_array(radio_nr, int, NULL, 0444); 76module_param_array(radio_nr, int, NULL, 0444);
79module_param_array(dsp_nr, int, NULL, 0444);
80module_param_array(mixer_nr, int, NULL, 0444);
81module_param_array(tuner, int, NULL, 0444); 77module_param_array(tuner, int, NULL, 0444);
82module_param_array(card, int, NULL, 0444); 78module_param_array(card, int, NULL, 0444);
83 79
84MODULE_PARM_DESC(video_nr, "video device number"); 80MODULE_PARM_DESC(video_nr, "video device number");
85MODULE_PARM_DESC(vbi_nr, "vbi device number"); 81MODULE_PARM_DESC(vbi_nr, "vbi device number");
86MODULE_PARM_DESC(radio_nr, "radio device number"); 82MODULE_PARM_DESC(radio_nr, "radio device number");
87MODULE_PARM_DESC(dsp_nr, "oss dsp device number");
88MODULE_PARM_DESC(mixer_nr, "oss mixer device number");
89MODULE_PARM_DESC(tuner, "tuner type"); 83MODULE_PARM_DESC(tuner, "tuner type");
90MODULE_PARM_DESC(card, "card type"); 84MODULE_PARM_DESC(card, "card type");
91 85
@@ -195,6 +189,7 @@ void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
195static int need_empress; 189static int need_empress;
196static int need_dvb; 190static int need_dvb;
197static int need_alsa; 191static int need_alsa;
192static int need_oss;
198 193
199static int pending_call(struct notifier_block *self, unsigned long state, 194static int pending_call(struct notifier_block *self, unsigned long state,
200 void *module) 195 void *module)
@@ -208,6 +203,8 @@ static int pending_call(struct notifier_block *self, unsigned long state,
208 request_module("saa7134-dvb"); 203 request_module("saa7134-dvb");
209 if (need_alsa) 204 if (need_alsa)
210 request_module("saa7134-alsa"); 205 request_module("saa7134-alsa");
206 if (need_oss)
207 request_module("saa7134-oss");
211 return NOTIFY_DONE; 208 return NOTIFY_DONE;
212} 209}
213 210
@@ -218,10 +215,11 @@ static struct notifier_block pending_notifier = {
218 215
219static void request_module_depend(char *name, int *flag) 216static void request_module_depend(char *name, int *flag)
220{ 217{
218 int err;
221 switch (THIS_MODULE->state) { 219 switch (THIS_MODULE->state) {
222 case MODULE_STATE_COMING: 220 case MODULE_STATE_COMING:
223 if (!pending_registered) { 221 if (!pending_registered) {
224 register_module_notifier(&pending_notifier); 222 err = register_module_notifier(&pending_notifier);
225 pending_registered = 1; 223 pending_registered = 1;
226 } 224 }
227 *flag = 1; 225 *flag = 1;
@@ -578,12 +576,14 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id, struct pt_regs *regs)
578 goto out; 576 goto out;
579 } 577 }
580 578
581 /* If alsa support is active and we get a sound report, exit 579 /* If dmasound support is active and we get a sound report, exit
582 and let the saa7134-alsa module deal with it */ 580 and let the saa7134-alsa/oss module deal with it */
583 581
584 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) && alsa) { 582 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) &&
583 (dev->dmasound.priv_data != NULL) )
584 {
585 if (irq_debug > 1) 585 if (irq_debug > 1)
586 printk(KERN_DEBUG "%s/irq: ignoring interrupt for ALSA\n", 586 printk(KERN_DEBUG "%s/irq: ignoring interrupt for DMA sound\n",
587 dev->name); 587 dev->name);
588 goto out; 588 goto out;
589 } 589 }
@@ -609,12 +609,6 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id, struct pt_regs *regs)
609 card_has_mpeg(dev)) 609 card_has_mpeg(dev))
610 saa7134_irq_ts_done(dev,status); 610 saa7134_irq_ts_done(dev,status);
611 611
612 if ((report & SAA7134_IRQ_REPORT_DONE_RA3)) {
613 if (oss) {
614 saa7134_irq_oss_done(dev,status);
615 }
616 }
617
618 if ((report & (SAA7134_IRQ_REPORT_GPIO16 | 612 if ((report & (SAA7134_IRQ_REPORT_GPIO16 |
619 SAA7134_IRQ_REPORT_GPIO18)) && 613 SAA7134_IRQ_REPORT_GPIO18)) &&
620 dev->remote) 614 dev->remote)
@@ -689,14 +683,6 @@ static int saa7134_hwinit1(struct saa7134_dev *dev)
689 * audio will not work. 683 * audio will not work.
690 */ 684 */
691 685
692 switch (dev->pci->device) {
693 case PCI_DEVICE_ID_PHILIPS_SAA7134:
694 case PCI_DEVICE_ID_PHILIPS_SAA7133:
695 case PCI_DEVICE_ID_PHILIPS_SAA7135:
696 saa7134_oss_init1(dev);
697 break;
698 }
699
700 /* enable peripheral devices */ 686 /* enable peripheral devices */
701 saa_writeb(SAA7134_SPECIAL_MODE, 0x01); 687 saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
702 688
@@ -740,13 +726,6 @@ static int saa7134_hwfini(struct saa7134_dev *dev)
740{ 726{
741 dprintk("hwfini\n"); 727 dprintk("hwfini\n");
742 728
743 switch (dev->pci->device) {
744 case PCI_DEVICE_ID_PHILIPS_SAA7134:
745 case PCI_DEVICE_ID_PHILIPS_SAA7133:
746 case PCI_DEVICE_ID_PHILIPS_SAA7135:
747 saa7134_oss_fini(dev);
748 break;
749 }
750 if (card_has_mpeg(dev)) 729 if (card_has_mpeg(dev))
751 saa7134_ts_fini(dev); 730 saa7134_ts_fini(dev);
752 saa7134_input_fini(dev); 731 saa7134_input_fini(dev);
@@ -984,11 +963,12 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
984 if (card_is_dvb(dev)) 963 if (card_is_dvb(dev))
985 request_module_depend("saa7134-dvb",&need_dvb); 964 request_module_depend("saa7134-dvb",&need_dvb);
986 965
987 if (!oss && alsa) { 966
988 dprintk("Requesting ALSA module\n"); 967 if (alsa)
989 request_module_depend("saa7134-alsa",&need_alsa); 968 request_module_depend("saa7134-alsa",&need_alsa);
990 }
991 969
970 if (oss)
971 request_module_depend("saa7134-oss",&need_oss);
992 972
993 v4l2_prio_init(&dev->prio); 973 v4l2_prio_init(&dev->prio);
994 974
@@ -1022,32 +1002,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1022 dev->name,dev->radio_dev->minor & 0x1f); 1002 dev->name,dev->radio_dev->minor & 0x1f);
1023 } 1003 }
1024 1004
1025 /* register oss devices */
1026 switch (dev->pci->device) {
1027 case PCI_DEVICE_ID_PHILIPS_SAA7134:
1028 case PCI_DEVICE_ID_PHILIPS_SAA7133:
1029 case PCI_DEVICE_ID_PHILIPS_SAA7135:
1030 if (oss) {
1031 err = dev->dmasound.minor_dsp =
1032 register_sound_dsp(&saa7134_dsp_fops,
1033 dsp_nr[dev->nr]);
1034 if (err < 0) {
1035 goto fail4;
1036 }
1037 printk(KERN_INFO "%s: registered device dsp%d\n",
1038 dev->name,dev->dmasound.minor_dsp >> 4);
1039
1040 err = dev->dmasound.minor_mixer =
1041 register_sound_mixer(&saa7134_mixer_fops,
1042 mixer_nr[dev->nr]);
1043 if (err < 0)
1044 goto fail5;
1045 printk(KERN_INFO "%s: registered device mixer%d\n",
1046 dev->name,dev->dmasound.minor_mixer >> 4);
1047 }
1048 break;
1049 }
1050
1051 /* everything worked */ 1005 /* everything worked */
1052 pci_set_drvdata(pci_dev,dev); 1006 pci_set_drvdata(pci_dev,dev);
1053 saa7134_devcount++; 1007 saa7134_devcount++;
@@ -1065,15 +1019,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1065 1019
1066 return 0; 1020 return 0;
1067 1021
1068 fail5:
1069 switch (dev->pci->device) {
1070 case PCI_DEVICE_ID_PHILIPS_SAA7134:
1071 case PCI_DEVICE_ID_PHILIPS_SAA7133:
1072 case PCI_DEVICE_ID_PHILIPS_SAA7135:
1073 if (oss)
1074 unregister_sound_dsp(dev->dmasound.minor_dsp);
1075 break;
1076 }
1077 fail4: 1022 fail4:
1078 saa7134_unregister_video(dev); 1023 saa7134_unregister_video(dev);
1079 saa7134_i2c_unregister(dev); 1024 saa7134_i2c_unregister(dev);
@@ -1124,19 +1069,16 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1124 saa7134_devcount--; 1069 saa7134_devcount--;
1125 1070
1126 saa7134_i2c_unregister(dev); 1071 saa7134_i2c_unregister(dev);
1127 switch (dev->pci->device) {
1128 case PCI_DEVICE_ID_PHILIPS_SAA7134:
1129 case PCI_DEVICE_ID_PHILIPS_SAA7133:
1130 case PCI_DEVICE_ID_PHILIPS_SAA7135:
1131 if (oss) {
1132 unregister_sound_mixer(dev->dmasound.minor_mixer);
1133 unregister_sound_dsp(dev->dmasound.minor_dsp);
1134 }
1135 break;
1136 }
1137 saa7134_unregister_video(dev); 1072 saa7134_unregister_video(dev);
1138 1073
1139 /* release ressources */ 1074 /* the DMA sound modules should be unloaded before reaching
1075 this, but just in case they are still present... */
1076 if (dev->dmasound.priv_data != NULL) {
1077 free_irq(pci_dev->irq, &dev->dmasound);
1078 dev->dmasound.priv_data = NULL;
1079 }
1080
1081 /* release resources */
1140 free_irq(pci_dev->irq, dev); 1082 free_irq(pci_dev->irq, dev);
1141 iounmap(dev->lmmio); 1083 iounmap(dev->lmmio);
1142 release_mem_region(pci_resource_start(pci_dev,0), 1084 release_mem_region(pci_resource_start(pci_dev,0),
@@ -1224,7 +1166,7 @@ EXPORT_SYMBOL(saa7134_i2c_call_clients);
1224EXPORT_SYMBOL(saa7134_devlist); 1166EXPORT_SYMBOL(saa7134_devlist);
1225EXPORT_SYMBOL(saa7134_boards); 1167EXPORT_SYMBOL(saa7134_boards);
1226 1168
1227/* ----------------- For ALSA -------------------------------- */ 1169/* ----------------- for the DMA sound modules --------------- */
1228 1170
1229EXPORT_SYMBOL(saa7134_pgtable_free); 1171EXPORT_SYMBOL(saa7134_pgtable_free);
1230EXPORT_SYMBOL(saa7134_pgtable_build); 1172EXPORT_SYMBOL(saa7134_pgtable_build);
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index fd53dfcc1644..fd9ed11ab1e2 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -4,6 +4,8 @@
4 * oss dsp interface 4 * oss dsp interface
5 * 5 *
6 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 6 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 * 2005 conversion to standalone module:
8 * Ricardo Cerqueira <v4l@cerqueira.org>
7 * 9 *
8 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
@@ -25,7 +27,9 @@
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
27#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/interrupt.h>
28#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/sound.h>
29#include <linux/soundcard.h> 33#include <linux/soundcard.h>
30 34
31#include "saa7134-reg.h" 35#include "saa7134-reg.h"
@@ -33,15 +37,23 @@
33 37
34/* ------------------------------------------------------------------ */ 38/* ------------------------------------------------------------------ */
35 39
36static unsigned int oss_debug = 0; 40static unsigned int debug = 0;
37module_param(oss_debug, int, 0644); 41module_param(debug, int, 0644);
38MODULE_PARM_DESC(oss_debug,"enable debug messages [oss]"); 42MODULE_PARM_DESC(debug,"enable debug messages [oss]");
39 43
40static unsigned int oss_rate = 0; 44static unsigned int rate = 0;
41module_param(oss_rate, int, 0444); 45module_param(rate, int, 0444);
42MODULE_PARM_DESC(oss_rate,"sample rate (valid are: 32000,48000)"); 46MODULE_PARM_DESC(rate,"sample rate (valid are: 32000,48000)");
43 47
44#define dprintk(fmt, arg...) if (oss_debug) \ 48static unsigned int dsp_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
49MODULE_PARM_DESC(dsp_nr, "device numbers for SAA7134 capture interface(s).");
50module_param_array(dsp_nr, int, NULL, 0444);
51
52static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
53MODULE_PARM_DESC(mixer_nr, "mixer numbers for SAA7134 capture interface(s).");
54module_param_array(mixer_nr, int, NULL, 0444);
55
56#define dprintk(fmt, arg...) if (debug) \
45 printk(KERN_DEBUG "%s/oss: " fmt, dev->name , ## arg) 57 printk(KERN_DEBUG "%s/oss: " fmt, dev->name , ## arg)
46 58
47 59
@@ -369,7 +381,7 @@ static int dsp_ioctl(struct inode *inode, struct file *file,
369 int __user *p = argp; 381 int __user *p = argp;
370 int val = 0; 382 int val = 0;
371 383
372 if (oss_debug > 1) 384 if (debug > 1)
373 saa7134_print_ioctl(dev->name,cmd); 385 saa7134_print_ioctl(dev->name,cmd);
374 switch (cmd) { 386 switch (cmd) {
375 case OSS_GETVERSION: 387 case OSS_GETVERSION:
@@ -665,7 +677,7 @@ static int mixer_ioctl(struct inode *inode, struct file *file,
665 void __user *argp = (void __user *) arg; 677 void __user *argp = (void __user *) arg;
666 int __user *p = argp; 678 int __user *p = argp;
667 679
668 if (oss_debug > 1) 680 if (debug > 1)
669 saa7134_print_ioctl(dev->name,cmd); 681 saa7134_print_ioctl(dev->name,cmd);
670 switch (cmd) { 682 switch (cmd) {
671 case OSS_GETVERSION: 683 case OSS_GETVERSION:
@@ -768,8 +780,41 @@ struct file_operations saa7134_mixer_fops = {
768 780
769/* ------------------------------------------------------------------ */ 781/* ------------------------------------------------------------------ */
770 782
783static irqreturn_t saa7134_oss_irq(int irq, void *dev_id, struct pt_regs *regs)
784{
785 struct saa7134_dmasound *dmasound = dev_id;
786 struct saa7134_dev *dev = dmasound->priv_data;
787 unsigned long report, status;
788 int loop, handled = 0;
789
790 for (loop = 0; loop < 10; loop++) {
791 report = saa_readl(SAA7134_IRQ_REPORT);
792 status = saa_readl(SAA7134_IRQ_STATUS);
793
794 if (report & SAA7134_IRQ_REPORT_DONE_RA3) {
795 handled = 1;
796 saa_writel(SAA7134_IRQ_REPORT,report);
797 saa7134_irq_oss_done(dev, status);
798 } else {
799 goto out;
800 }
801 }
802
803 if (loop == 10) {
804 dprintk("error! looping IRQ!");
805 }
806out:
807 return IRQ_RETVAL(handled);
808}
809
771int saa7134_oss_init1(struct saa7134_dev *dev) 810int saa7134_oss_init1(struct saa7134_dev *dev)
772{ 811{
812
813 if ((request_irq(dev->pci->irq, saa7134_oss_irq,
814 SA_SHIRQ | SA_INTERRUPT, dev->name,
815 (void*) &dev->dmasound)) < 0)
816 return -1;
817
773 /* general */ 818 /* general */
774 init_MUTEX(&dev->dmasound.lock); 819 init_MUTEX(&dev->dmasound.lock);
775 init_waitqueue_head(&dev->dmasound.wq); 820 init_waitqueue_head(&dev->dmasound.wq);
@@ -785,8 +830,8 @@ int saa7134_oss_init1(struct saa7134_dev *dev)
785 830
786 /* dsp */ 831 /* dsp */
787 dev->dmasound.rate = 32000; 832 dev->dmasound.rate = 32000;
788 if (oss_rate) 833 if (rate)
789 dev->dmasound.rate = oss_rate; 834 dev->dmasound.rate = rate;
790 dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000; 835 dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000;
791 836
792 /* mixer */ 837 /* mixer */
@@ -840,7 +885,7 @@ void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
840 /* next block addr */ 885 /* next block addr */
841 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks; 886 next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks;
842 saa_writel(reg,next_blk * dev->dmasound.blksize); 887 saa_writel(reg,next_blk * dev->dmasound.blksize);
843 if (oss_debug > 2) 888 if (debug > 2)
844 dprintk("irq: ok, %s, next_blk=%d, addr=%x\n", 889 dprintk("irq: ok, %s, next_blk=%d, addr=%x\n",
845 (status & 0x10000000) ? "even" : "odd ", next_blk, 890 (status & 0x10000000) ? "even" : "odd ", next_blk,
846 next_blk * dev->dmasound.blksize); 891 next_blk * dev->dmasound.blksize);
@@ -854,6 +899,98 @@ void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status)
854 spin_unlock(&dev->slock); 899 spin_unlock(&dev->slock);
855} 900}
856 901
902int saa7134_dsp_create(struct saa7134_dev *dev)
903{
904 int err;
905
906 err = dev->dmasound.minor_dsp =
907 register_sound_dsp(&saa7134_dsp_fops,
908 dsp_nr[dev->nr]);
909 if (err < 0) {
910 goto fail;
911 }
912 printk(KERN_INFO "%s: registered device dsp%d\n",
913 dev->name,dev->dmasound.minor_dsp >> 4);
914
915 err = dev->dmasound.minor_mixer =
916 register_sound_mixer(&saa7134_mixer_fops,
917 mixer_nr[dev->nr]);
918 if (err < 0)
919 goto fail;
920 printk(KERN_INFO "%s: registered device mixer%d\n",
921 dev->name,dev->dmasound.minor_mixer >> 4);
922
923 return 0;
924
925fail:
926 unregister_sound_dsp(dev->dmasound.minor_dsp);
927 return 0;
928
929
930}
931
932static int saa7134_oss_init(void)
933{
934 struct saa7134_dev *dev = NULL;
935 struct list_head *list;
936
937 printk(KERN_INFO "saa7134 OSS driver for DMA sound loaded\n");
938
939 list_for_each(list,&saa7134_devlist) {
940 dev = list_entry(list, struct saa7134_dev, devlist);
941 if (dev->dmasound.priv_data == NULL) {
942 dev->dmasound.priv_data = dev;
943 saa7134_oss_init1(dev);
944 saa7134_dsp_create(dev);
945 } else {
946 printk(KERN_ERR "saa7134 OSS: DMA sound is being handled by ALSA, ignoring %s\n",dev->name);
947 return -EBUSY;
948 }
949 }
950
951 if (dev == NULL)
952 printk(KERN_INFO "saa7134 OSS: no saa7134 cards found\n");
953
954 return 0;
955
956}
957
958void saa7134_oss_exit(void)
959{
960 struct saa7134_dev *dev = NULL;
961 struct list_head *list;
962
963 list_for_each(list,&saa7134_devlist) {
964 dev = list_entry(list, struct saa7134_dev, devlist);
965
966 /* Device isn't registered by OSS, probably ALSA's */
967 if (!dev->dmasound.minor_dsp)
968 continue;
969
970 unregister_sound_mixer(dev->dmasound.minor_mixer);
971 unregister_sound_dsp(dev->dmasound.minor_dsp);
972
973 saa7134_oss_fini(dev);
974
975 if (dev->pci->irq > 0) {
976 synchronize_irq(dev->pci->irq);
977 free_irq(dev->pci->irq,&dev->dmasound);
978 }
979
980 dev->dmasound.priv_data = NULL;
981
982 }
983
984 printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n");
985
986 return;
987}
988
989module_init(saa7134_oss_init);
990module_exit(saa7134_oss_exit);
991MODULE_LICENSE("GPL");
992MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
993
857/* ----------------------------------------------------------- */ 994/* ----------------------------------------------------------- */
858/* 995/*
859 * Local variables: 996 * Local variables:
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index fb9727471661..85ba30978e84 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -383,6 +383,7 @@ struct saa7134_dmasound {
383 unsigned int dma_blk; 383 unsigned int dma_blk;
384 unsigned int read_offset; 384 unsigned int read_offset;
385 unsigned int read_count; 385 unsigned int read_count;
386 void * priv_data;
386 snd_pcm_substream_t *substream; 387 snd_pcm_substream_t *substream;
387}; 388};
388 389