aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7134/saa7134-alsa.c
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/media/video/saa7134/saa7134-alsa.c
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/media/video/saa7134/saa7134-alsa.c')
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c130
1 files changed, 66 insertions, 64 deletions
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 0025191f616..289ca3ac99b 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;