V4L/DVB (12732): cx25821: fix bad whitespacing
[deliverable/linux.git] / drivers / staging / cx25821 / cx25821-alsa.c
CommitLineData
02b20b0b
MCC
1/*\r
2 * Driver for the Conexant CX25821 PCIe bridge\r
3 *\r
4 * Copyright (C) 2009 Conexant Systems Inc. \r
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>\r
6 * Based on SAA713x ALSA driver and CX88 driver\r
7 *\r
8 * This program is free software; you can redistribute it and/or modify\r
9 * it under the terms of the GNU General Public License as published by\r
10 * the Free Software Foundation, version 2\r
11 *\r
12 * This program is distributed in the hope that it will be useful,\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
15 * GNU General Public License for more details.\r
16 *\r
17 * You should have received a copy of the GNU General Public License\r
18 * along with this program; if not, write to the Free Software\r
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
20 *\r
21 */\r
22\r
23\r
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/device.h>
27#include <linux/interrupt.h>
28#include <linux/vmalloc.h>
29#include <linux/dma-mapping.h>
30#include <linux/pci.h>
31
32#include <asm/delay.h>
33#include <sound/core.h>
34#include <sound/pcm.h>
35#include <sound/pcm_params.h>
36#include <sound/control.h>
37#include <sound/initval.h>
38#include <sound/tlv.h>
39
40
41#include "cx25821.h"
42#include "cx25821-reg.h"
43
44#define AUDIO_SRAM_CHANNEL SRAM_CH08
45
46#define dprintk(level,fmt, arg...) if (debug >= level) \
47 printk(KERN_INFO "%s/1: " fmt, chip->dev->name , ## arg)
48
49#define dprintk_core(level,fmt, arg...) if (debug >= level) \
50 printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name , ## arg)
51
52
53/****************************************************************************
54 Data type declarations - Can be moded to a header file later
55 ****************************************************************************/
56
57
58static struct snd_card *snd_cx25821_cards[SNDRV_CARDS];
59static int devno;
60
61struct cx25821_audio_dev {
62 struct cx25821_dev *dev;
63 struct cx25821_dmaqueue q;
64
65 /* pci i/o */
66 struct pci_dev *pci;
67
68 /* audio controls */
69 int irq;
70
71 struct snd_card *card;
72
73 unsigned long iobase;
74 spinlock_t reg_lock;
bb4c9a74 75 atomic_t count;
02b20b0b
MCC
76
77 unsigned int dma_size;
78 unsigned int period_size;
79 unsigned int num_periods;
80
81 struct videobuf_dmabuf *dma_risc;
82
83 struct cx25821_buffer *buf;
84
85 struct snd_pcm_substream *substream;
86};
87typedef struct cx25821_audio_dev snd_cx25821_card_t;
88
89
90
91/****************************************************************************
92 Module global static vars
93 ****************************************************************************/
94
95static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
96static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
97static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1};
98
99module_param_array(enable, bool, NULL, 0444);
100MODULE_PARM_DESC(enable, "Enable cx25821 soundcard. default enabled.");
101
102module_param_array(index, int, NULL, 0444);
103MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s).");
104
105
106/****************************************************************************
107 Module macros
108 ****************************************************************************/
109
110MODULE_DESCRIPTION("ALSA driver module for cx25821 based capture cards");
111MODULE_AUTHOR("Hiep Huynh");
112MODULE_LICENSE("GPL");
113MODULE_SUPPORTED_DEVICE("{{Conexant,25821}");//"{{Conexant,23881},"
114
115static unsigned int debug;
116module_param(debug,int,0644);
117MODULE_PARM_DESC(debug,"enable debug messages");
118
119/****************************************************************************
120 Module specific funtions
121 ****************************************************************************/
122/* Constants taken from cx88-reg.h */
123#define AUD_INT_DN_RISCI1 (1 << 0)
124#define AUD_INT_UP_RISCI1 (1 << 1)
125#define AUD_INT_RDS_DN_RISCI1 (1 << 2)
126#define AUD_INT_DN_RISCI2 (1 << 4) /* yes, 3 is skipped */
127#define AUD_INT_UP_RISCI2 (1 << 5)
128#define AUD_INT_RDS_DN_RISCI2 (1 << 6)
129#define AUD_INT_DN_SYNC (1 << 12)
130#define AUD_INT_UP_SYNC (1 << 13)
131#define AUD_INT_RDS_DN_SYNC (1 << 14)
132#define AUD_INT_OPC_ERR (1 << 16)
133#define AUD_INT_BER_IRQ (1 << 20)
134#define AUD_INT_MCHG_IRQ (1 << 21)
135#define GP_COUNT_CONTROL_RESET 0x3
136
137#define PCI_MSK_AUD_EXT (1 << 4)
138#define PCI_MSK_AUD_INT (1 << 3)
139/*
140 * BOARD Specific: Sets audio DMA
141 */
142
143static int _cx25821_start_audio_dma(snd_cx25821_card_t *chip)
144{
145 struct cx25821_buffer *buf = chip->buf;
146 struct cx25821_dev * dev = chip->dev;
147 struct sram_channel *audio_ch = &cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
148 u32 tmp = 0;
149
150 // enable output on the GPIO 0 for the MCLK ADC (Audio)
151 cx25821_set_gpiopin_direction( chip->dev, 0, 0 );
152
153 /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
154 cx_clear(AUD_INT_DMA_CTL, FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN );
155
156 /* setup fifo + format - out channel */
157 cx25821_sram_channel_setup_audio(chip->dev, audio_ch, buf->bpl, buf->risc.dma);
158
159 /* sets bpl size */
160 cx_write(AUD_A_LNGTH, buf->bpl);
161
162 /* reset counter */
163 cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET); //GP_COUNT_CONTROL_RESET = 0x3
164 atomic_set(&chip->count, 0);
165
166 //Set the input mode to 16-bit
167 tmp = cx_read(AUD_A_CFG);
168 cx_write(AUD_A_CFG, tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE | FLD_AUD_CLK_ENABLE);
169
170 //printk(KERN_INFO "DEBUG: Start audio DMA, %d B/line, cmds_start(0x%x)= %d lines/FIFO, %d periods, %d "
171 // "byte buffer\n", buf->bpl, audio_ch->cmds_start, cx_read(audio_ch->cmds_start + 12)>>1,
172 // chip->num_periods, buf->bpl * chip->num_periods);
173
174
175 /* Enables corresponding bits at AUD_INT_STAT */
176 cx_write(AUD_A_INT_MSK, FLD_AUD_DST_RISCI1 | FLD_AUD_DST_OF | FLD_AUD_DST_SYNC | FLD_AUD_DST_OPC_ERR );
177
178 /* Clean any pending interrupt bits already set */
179 cx_write(AUD_A_INT_STAT, ~0);
180
181 /* enable audio irqs */
182 cx_set(PCI_INT_MSK, chip->dev->pci_irqmask | PCI_MSK_AUD_INT);
183
184 // Turn on audio downstream fifo and risc enable 0x101
185 tmp = cx_read(AUD_INT_DMA_CTL);
186 cx_set(AUD_INT_DMA_CTL, tmp | (FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN) );
187
188 mdelay(100);
189 return 0;
190}
191
192/*
193 * BOARD Specific: Resets audio DMA
194 */
195static int _cx25821_stop_audio_dma(snd_cx25821_card_t *chip)
196{
197 struct cx25821_dev *dev = chip->dev;
198
199 /* stop dma */
200 cx_clear(AUD_INT_DMA_CTL, FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN );
201
202 /* disable irqs */
203 cx_clear(PCI_INT_MSK, PCI_MSK_AUD_INT);
204 cx_clear(AUD_A_INT_MSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC | AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
205
206 return 0;
207}
208
209#define MAX_IRQ_LOOP 50
210
211/*
212 * BOARD Specific: IRQ dma bits
213 */
214static char *cx25821_aud_irqs[32] = {
215 "dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */
216 NULL, /* reserved */
217 "dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */
218 NULL, /* reserved */
219 "dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */
220 NULL, /* reserved */
221 "dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */
222 NULL, /* reserved */
223 "opc_err", "par_err", "rip_err", /* 16-18 */
224 "pci_abort", "ber_irq", "mchg_irq" /* 19-21 */
225};
226
227/*
228 * BOARD Specific: Threats IRQ audio specific calls
229 */
230static void cx25821_aud_irq(snd_cx25821_card_t *chip, u32 status, u32 mask)
231{
232 struct cx25821_dev *dev = chip->dev;
233
234 if (0 == (status & mask))
235 {
236 return;
237 }
238
239 cx_write(AUD_A_INT_STAT, status);
240 if (debug > 1 || (status & mask & ~0xff))
241 cx25821_print_irqbits(dev->name, "irq aud",
242 cx25821_aud_irqs, ARRAY_SIZE(cx25821_aud_irqs),
243 status, mask);
244
245 /* risc op code error */
246 if (status & AUD_INT_OPC_ERR) {
247 printk(KERN_WARNING "WARNING %s/1: Audio risc op code error\n",dev->name);
248
249 cx_clear(AUD_INT_DMA_CTL, FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN );
250 cx25821_sram_channel_dump_audio(dev, &cx25821_sram_channels[AUDIO_SRAM_CHANNEL]);
251 }
252 if (status & AUD_INT_DN_SYNC) {
253 printk(KERN_WARNING "WARNING %s: Downstream sync error!\n",dev->name);
254 cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
255 return;
256 }
257
258
259 /* risc1 downstream */
260 if (status & AUD_INT_DN_RISCI1) {
261 atomic_set(&chip->count, cx_read(AUD_A_GPCNT));
262 snd_pcm_period_elapsed(chip->substream);
263 }
264}
265
266
267/*
268 * BOARD Specific: Handles IRQ calls
269 */
270static irqreturn_t cx25821_irq(int irq, void *dev_id)
271{
272 snd_cx25821_card_t *chip = dev_id;
273 struct cx25821_dev *dev = chip->dev;
274 u32 status, pci_status;
275 u32 audint_status, audint_mask;
276 int loop, handled = 0;
277 int audint_count = 0;
278
279
280 audint_status = cx_read(AUD_A_INT_STAT);
281 audint_mask = cx_read(AUD_A_INT_MSK);
282 audint_count = cx_read(AUD_A_GPCNT);
283 status = cx_read(PCI_INT_STAT);
284
285 for (loop = 0; loop < 1; loop++)
286 {
287 status = cx_read(PCI_INT_STAT);
288 if (0 == status)
289 {
290 status = cx_read(PCI_INT_STAT);
291 audint_status = cx_read(AUD_A_INT_STAT);
292 audint_mask = cx_read(AUD_A_INT_MSK);
293
294 if (status)
295 {
296 handled = 1;
297 cx_write(PCI_INT_STAT, status);
298
299 cx25821_aud_irq(chip, audint_status, audint_mask);
300 break;
301 }
302 else
303 goto out;
304 }
305
306 handled = 1;
307 cx_write(PCI_INT_STAT, status);
308
309 cx25821_aud_irq(chip, audint_status, audint_mask);
310 }
311
312 pci_status = cx_read(PCI_INT_STAT);
313
314 if (handled)
315 cx_write(PCI_INT_STAT, pci_status);
316
317 out:
318 return IRQ_RETVAL(handled);
319}
320
321
322static int dsp_buffer_free(snd_cx25821_card_t *chip)
323{
324 BUG_ON(!chip->dma_size);
325
326 dprintk(2,"Freeing buffer\n");
327 videobuf_sg_dma_unmap(&chip->pci->dev, chip->dma_risc);
328 videobuf_dma_free(chip->dma_risc);
329 btcx_riscmem_free(chip->pci,&chip->buf->risc);
330 kfree(chip->buf);
331
332 chip->dma_risc = NULL;
333 chip->dma_size = 0;
334
335 return 0;
336}
337
338/****************************************************************************
339 ALSA PCM Interface
340 ****************************************************************************/
341
342/*
343 * Digital hardware definition
344 */
345#define DEFAULT_FIFO_SIZE 384
346static struct snd_pcm_hardware snd_cx25821_digital_hw = {
347 .info = SNDRV_PCM_INFO_MMAP |
348 SNDRV_PCM_INFO_INTERLEAVED |
349 SNDRV_PCM_INFO_BLOCK_TRANSFER |
350 SNDRV_PCM_INFO_MMAP_VALID,
351 .formats = SNDRV_PCM_FMTBIT_S16_LE,
352
353 .rates = SNDRV_PCM_RATE_48000,
354 .rate_min = 48000,
355 .rate_max = 48000,
356 .channels_min = 2,
357 .channels_max = 2,
358 /* Analog audio output will be full of clicks and pops if there
359 are not exactly four lines in the SRAM FIFO buffer. */
360 .period_bytes_min = DEFAULT_FIFO_SIZE/3,
361 .period_bytes_max = DEFAULT_FIFO_SIZE/3,
362 .periods_min = 1,
363 .periods_max = AUDIO_LINE_SIZE,
364 .buffer_bytes_max = (AUDIO_LINE_SIZE*AUDIO_LINE_SIZE), //128*128 = 16384 = 1024 * 16
365};
366
367
368
369/*
370 * audio pcm capture open callback
371 */
372static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
373{
374 snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
375 struct snd_pcm_runtime *runtime = substream->runtime;
376 int err;
377 unsigned int bpl = 0;
378
379 if (!chip) {
380 printk(KERN_ERR "DEBUG: cx25821 can't find device struct."
381 " Can't proceed with open\n");
382 return -ENODEV;
383 }
384
385 err = snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS);
386 if (err < 0)
387 goto _error;
388
389 chip->substream = substream;
390
391 runtime->hw = snd_cx25821_digital_hw;
392
393 if (cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size != DEFAULT_FIFO_SIZE)
394 {
395 bpl = cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 3; //since there are 3 audio Clusters
396 bpl &= ~7; /* must be multiple of 8 */
397
398 if( bpl > AUDIO_LINE_SIZE )
399 {
400 bpl = AUDIO_LINE_SIZE;
401 }
402 runtime->hw.period_bytes_min = bpl;
403 runtime->hw.period_bytes_max = bpl;
404 }
405
406 return 0;
407_error:
408 dprintk(1,"Error opening PCM!\n");
409 return err;
410}
411
412/*
413 * audio close callback
414 */
415static int snd_cx25821_close(struct snd_pcm_substream *substream)
416{
417 return 0;
418}
419
420/*
421 * hw_params callback
422 */
423static int snd_cx25821_hw_params(struct snd_pcm_substream * substream,
424 struct snd_pcm_hw_params * hw_params)
425{
426 snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
427 struct videobuf_dmabuf *dma;
428
429 struct cx25821_buffer *buf;
430 int ret;
431
432 if (substream->runtime->dma_area) {
433 dsp_buffer_free(chip);
434 substream->runtime->dma_area = NULL;
435 }
436
437
438 chip->period_size = params_period_bytes(hw_params);
439 chip->num_periods = params_periods(hw_params);
440 chip->dma_size = chip->period_size * params_periods(hw_params);
441
442 BUG_ON(!chip->dma_size);
443 BUG_ON(chip->num_periods & (chip->num_periods-1));
444
445 buf = videobuf_sg_alloc(sizeof(*buf));
446 if (NULL == buf)
447 return -ENOMEM;
448
449
450 if( chip->period_size > AUDIO_LINE_SIZE )
451 {
452 chip->period_size = AUDIO_LINE_SIZE;
453 }
454
455
456 buf->vb.memory = V4L2_MEMORY_MMAP;
457 buf->vb.field = V4L2_FIELD_NONE;
458 buf->vb.width = chip->period_size;
459 buf->bpl = chip->period_size;
460 buf->vb.height = chip->num_periods;
461 buf->vb.size = chip->dma_size;
462
463 dma = videobuf_to_dma(&buf->vb);
464 videobuf_dma_init(dma);
465
466 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
467 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT));
468 if (ret < 0)
469 goto error;
470
471 ret = videobuf_sg_dma_map(&chip->pci->dev, dma);
472 if (ret < 0)
473 goto error;
474
475
476 ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist, buf->vb.width, buf->vb.height, 1);
477 if (ret < 0)
478 {
479 printk(KERN_INFO "DEBUG: ERROR after cx25821_risc_databuffer_audio() \n");
480 goto error;
481 }
482
483
484 /* Loop back to start of program */
485 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC);
486 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
487 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
488
489 buf->vb.state = VIDEOBUF_PREPARED;
490
491 chip->buf = buf;
492 chip->dma_risc = dma;
493
494 substream->runtime->dma_area = chip->dma_risc->vmalloc;
495 substream->runtime->dma_bytes = chip->dma_size;
496 substream->runtime->dma_addr = 0;
497
498 return 0;
499
500error:
501 kfree(buf);
502 return ret;
503}
504
505/*
506 * hw free callback
507 */
508static int snd_cx25821_hw_free(struct snd_pcm_substream * substream)
509{
510 snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
511
512 if (substream->runtime->dma_area) {
513 dsp_buffer_free(chip);
514 substream->runtime->dma_area = NULL;
515 }
516
517 return 0;
518}
519
520/*
521 * prepare callback
522 */
523static int snd_cx25821_prepare(struct snd_pcm_substream *substream)
524{
525 return 0;
526}
527
528/*
529 * trigger callback
530 */
531static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream, int cmd)
532{
533 snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
534 int err = 0;
535
536 /* Local interrupts are already disabled by ALSA */
537 spin_lock(&chip->reg_lock);
538
539 switch (cmd)
540 {
541 case SNDRV_PCM_TRIGGER_START:
542 err = _cx25821_start_audio_dma(chip);
543 break;
544 case SNDRV_PCM_TRIGGER_STOP:
545 err = _cx25821_stop_audio_dma(chip);
546 break;
547 default:
548 err = -EINVAL;
549 break;
550 }
551
552 spin_unlock(&chip->reg_lock);
553
554 return err;
555}
556
557/*
558 * pointer callback
559 */
560static snd_pcm_uframes_t snd_cx25821_pointer(struct snd_pcm_substream *substream)
561{
562 snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
563 struct snd_pcm_runtime *runtime = substream->runtime;
564 u16 count;
565
566 count = atomic_read(&chip->count);
567
568 return runtime->period_size * (count & (runtime->periods-1));
569}
570
571/*
572 * page callback (needed for mmap)
573 */
574static struct page *snd_cx25821_page(struct snd_pcm_substream *substream,
575 unsigned long offset)
576{
577 void *pageptr = substream->runtime->dma_area + offset;
578
579 return vmalloc_to_page(pageptr);
580}
581
582/*
583 * operators
584 */
585static struct snd_pcm_ops snd_cx25821_pcm_ops = {
586 .open = snd_cx25821_pcm_open,
587 .close = snd_cx25821_close,
588 .ioctl = snd_pcm_lib_ioctl,
589 .hw_params = snd_cx25821_hw_params,
590 .hw_free = snd_cx25821_hw_free,
591 .prepare = snd_cx25821_prepare,
592 .trigger = snd_cx25821_card_trigger,
593 .pointer = snd_cx25821_pointer,
594 .page = snd_cx25821_page,
595};
596
597
598/*
599 * ALSA create a PCM device: Called when initializing the board. Sets up the name and hooks up
600 * the callbacks
601 */
602static int snd_cx25821_pcm(snd_cx25821_card_t *chip, int device, char *name)
603{
604 struct snd_pcm *pcm;
605 int err;
606
607 err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
608 if (err < 0)
609 {
610 printk(KERN_INFO "ERROR: FAILED snd_pcm_new() in %s\n", __func__);
611 return err;
612 }
613 pcm->private_data = chip;
614 pcm->info_flags = 0;
615 strcpy(pcm->name, name);
616 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx25821_pcm_ops);
617
618 return 0;
619}
620
621
622/****************************************************************************
623 Basic Flow for Sound Devices
624 ****************************************************************************/
625
626/*
627 * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
628 * Only boards with eeprom and byte 1 at eeprom=1 have it
629 */
630
631static struct pci_device_id cx25821_audio_pci_tbl[] __devinitdata = {
632 {0x14f1,0x0920,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
633 {0, }
634};
635MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
636
637/*\r
638 * Not used in the function snd_cx25821_dev_free so removing\r
639 * from the file.\r
640 */\r
641/*
642static int snd_cx25821_free(snd_cx25821_card_t *chip)
643{
644 if (chip->irq >= 0)
645 free_irq(chip->irq, chip);
646
647 cx25821_dev_unregister(chip->dev);
648 pci_disable_device(chip->pci);
649
650 return 0;
651}
652*/\r
653
654/*
655 * Component Destructor
656 */
657static void snd_cx25821_dev_free(struct snd_card * card)
658{
659 snd_cx25821_card_t *chip = card->private_data;
660
661 //snd_cx25821_free(chip);
662 snd_card_free(chip->card);
663}
664
665
666/*
667 * Alsa Constructor - Component probe
668 */
669static int cx25821_audio_initdev(struct cx25821_dev *dev)
670{
671 struct snd_card *card;
672 snd_cx25821_card_t *chip;
673 int err;
674
675 if (devno >= SNDRV_CARDS)
676 {
677 printk(KERN_INFO "DEBUG ERROR: devno >= SNDRV_CARDS %s\n", __func__);
678 return (-ENODEV);
679 }
680
681 if (!enable[devno]) {
682 ++devno;
683 printk(KERN_INFO "DEBUG ERROR: !enable[devno] %s\n", __func__);
684 return (-ENOENT);
685 }
686
687 card = snd_card_new(index[devno], id[devno], THIS_MODULE, sizeof(snd_cx25821_card_t));
688 if (!card)
689 {
690 printk(KERN_INFO "DEBUG ERROR: cannot create snd_card_new in %s\n", __func__);
691 return (-ENOMEM);
692 }
693
694 strcpy(card->driver, "cx25821");
695
696 /* Card "creation" */
697 card->private_free = snd_cx25821_dev_free;
698 chip = (snd_cx25821_card_t *) card->private_data;
699 spin_lock_init(&chip->reg_lock);
700
701 chip->dev = dev;
702 chip->card = card;
703 chip->pci = dev->pci;
704 chip->iobase = pci_resource_start(dev->pci, 0);
705
706
707 chip->irq = dev->pci->irq;
708
709 err = request_irq(dev->pci->irq, cx25821_irq,
710 IRQF_SHARED | IRQF_DISABLED, chip->dev->name, chip);
711
712 if (err < 0) {
713 printk(KERN_ERR "ERROR %s: can't get IRQ %d for ALSA\n", chip->dev->name, dev->pci->irq);
714 goto error;
715 }
716
717
718 if ((err = snd_cx25821_pcm(chip, 0, "cx25821 Digital")) < 0)
719 {
720 printk(KERN_INFO "DEBUG ERROR: cannot create snd_cx25821_pcm %s\n", __func__);
721 goto error;
722 }
723
724 snd_card_set_dev(card, &chip->pci->dev);
725
726
727 strcpy(card->shortname, "cx25821");
728 sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name, chip->iobase, chip->irq);
729 strcpy (card->mixername, "CX25821");
730
731 printk(KERN_INFO "%s/%i: ALSA support for cx25821 boards\n", card->driver, devno);
732
733 err = snd_card_register(card);
734 if (err < 0)
735 {
736 printk(KERN_INFO "DEBUG ERROR: cannot register sound card %s\n", __func__);
737 goto error;
738 }
739
740 snd_cx25821_cards[devno] = card;
741
742 devno++;
743 return 0;
744
745error:
746 snd_card_free(card);
747 return err;
748}
749
750
751/****************************************************************************
752 LINUX MODULE INIT
753 ****************************************************************************/
754static void cx25821_audio_fini(void)
755{
756 snd_card_free(snd_cx25821_cards[0]);
757}
758
759/*
760 * Module initializer
761 *
762 * Loops through present saa7134 cards, and assigns an ALSA device
763 * to each one
764 *
765 */
766static int cx25821_alsa_init(void)
767{
768 struct cx25821_dev *dev = NULL;
769 struct list_head *list;
770
771 list_for_each(list,&cx25821_devlist) {
772 dev = list_entry(list, struct cx25821_dev, devlist);
773 cx25821_audio_initdev(dev);
774 }
775
776 if (dev == NULL)
777 printk(KERN_INFO "cx25821 ERROR ALSA: no cx25821 cards found\n");
778
779 return 0;
780
781}
782
783late_initcall(cx25821_alsa_init);
784module_exit(cx25821_audio_fini);
785
786/* ----------------------------------------------------------- */
787/*
788 * Local variables:
789 * c-basic-offset: 8
790 * End:
791 */
This page took 0.054107 seconds and 5 git commands to generate.