blob: 92b2a6db4fdc15edea12a61ccbdcfa522da7a534 [file] [log] [blame]
Markus Rechbergera52932b2008-01-05 09:55:47 -03001/*
2 * Empiatech em28x1 audio extension
3 *
4 * Copyright (C) 2006 Markus Rechberger <mrechberger@gmail.com>
5 *
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -03006 * Copyright (C) 2007 Mauro Carvalho Chehab <mchehab@infradead.org>
7 * - Port to work with the in-kernel driver
8 * - Several cleanups
9 *
Markus Rechbergera52932b2008-01-05 09:55:47 -030010 * This driver is based on my previous au600 usb pstn audio driver
11 * and inherits all the copyrights
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/kernel.h>
29#include <linux/usb.h>
30#include <linux/init.h>
31#include <linux/sound.h>
32#include <linux/spinlock.h>
33#include <linux/soundcard.h>
34#include <linux/slab.h>
35#include <linux/vmalloc.h>
36#include <linux/proc_fs.h>
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030037#include <linux/module.h>
Markus Rechbergera52932b2008-01-05 09:55:47 -030038#include <sound/core.h>
39#include <sound/pcm.h>
40#include <sound/pcm_params.h>
41#include <sound/info.h>
42#include <sound/initval.h>
43#include <sound/control.h>
Markus Rechbergera52932b2008-01-05 09:55:47 -030044#include <media/v4l2-common.h>
45#include "em28xx.h"
46
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030047static int debug;
48module_param(debug, int, 0644);
49MODULE_PARM_DESC(debug, "activates debug info");
50
51#define dprintk(fmt, arg...) do { \
52 if (debug) \
53 printk(KERN_INFO "em28xx-audio %s: " fmt, \
Harvey Harrisond80e1342008-04-08 23:20:00 -030054 __func__, ##arg); \
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030055 } while (0)
56
Markus Rechbergera52932b2008-01-05 09:55:47 -030057static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
Markus Rechbergera52932b2008-01-05 09:55:47 -030058
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030059static int em28xx_isoc_audio_deinit(struct em28xx *dev)
Markus Rechbergera52932b2008-01-05 09:55:47 -030060{
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030061 int i;
62
63 dprintk("Stopping isoc\n");
64 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
65 usb_kill_urb(dev->adev->urb[i]);
66 usb_free_urb(dev->adev->urb[i]);
67 dev->adev->urb[i] = NULL;
Markus Rechbergera52932b2008-01-05 09:55:47 -030068 }
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030069
Markus Rechbergera52932b2008-01-05 09:55:47 -030070 return 0;
71}
72
Markus Rechbergera52932b2008-01-05 09:55:47 -030073static void em28xx_audio_isocirq(struct urb *urb)
74{
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030075 struct em28xx *dev = urb->context;
76 int i;
77 unsigned int oldptr;
78 unsigned long flags;
79 int period_elapsed = 0;
80 int status;
81 unsigned char *cp;
82 unsigned int stride;
Markus Rechbergera52932b2008-01-05 09:55:47 -030083 struct snd_pcm_substream *substream;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030084 struct snd_pcm_runtime *runtime;
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -030085 if (dev->adev->capture_pcm_substream) {
86 substream = dev->adev->capture_pcm_substream;
87 runtime = substream->runtime;
Markus Rechbergera52932b2008-01-05 09:55:47 -030088 stride = runtime->frame_bits >> 3;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -030089
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -030090 for (i = 0; i < urb->number_of_packets; i++) {
91 int length =
92 urb->iso_frame_desc[i].actual_length / stride;
93 cp = (unsigned char *)urb->transfer_buffer +
94 urb->iso_frame_desc[i].offset;
Markus Rechbergera52932b2008-01-05 09:55:47 -030095
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -030096 if (!length)
Markus Rechbergera52932b2008-01-05 09:55:47 -030097 continue;
98
99 spin_lock_irqsave(&dev->adev->slock, flags);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300100
Markus Rechbergera52932b2008-01-05 09:55:47 -0300101 oldptr = dev->adev->hwptr_done_capture;
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300102 dev->adev->hwptr_done_capture += length;
103 if (dev->adev->hwptr_done_capture >=
104 runtime->buffer_size)
105 dev->adev->hwptr_done_capture -=
106 runtime->buffer_size;
Markus Rechbergera52932b2008-01-05 09:55:47 -0300107
108 dev->adev->capture_transfer_done += length;
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300109 if (dev->adev->capture_transfer_done >=
110 runtime->period_size) {
111 dev->adev->capture_transfer_done -=
112 runtime->period_size;
113 period_elapsed = 1;
Markus Rechbergera52932b2008-01-05 09:55:47 -0300114 }
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300115
Markus Rechbergera52932b2008-01-05 09:55:47 -0300116 spin_unlock_irqrestore(&dev->adev->slock, flags);
117
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300118 if (oldptr + length >= runtime->buffer_size) {
119 unsigned int cnt =
120 runtime->buffer_size - oldptr - 1;
121 memcpy(runtime->dma_area + oldptr * stride, cp,
122 cnt * stride);
123 memcpy(runtime->dma_area, cp + cnt,
124 length * stride - cnt * stride);
Markus Rechbergera52932b2008-01-05 09:55:47 -0300125 } else {
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300126 memcpy(runtime->dma_area + oldptr * stride, cp,
127 length * stride);
Markus Rechbergera52932b2008-01-05 09:55:47 -0300128 }
129 }
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300130 if (period_elapsed)
Markus Rechbergera52932b2008-01-05 09:55:47 -0300131 snd_pcm_period_elapsed(substream);
Markus Rechbergera52932b2008-01-05 09:55:47 -0300132 }
133 urb->status = 0;
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300134
135 if (dev->adev->shutdown)
Markus Rechbergera52932b2008-01-05 09:55:47 -0300136 return;
137
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300138 status = usb_submit_urb(urb, GFP_ATOMIC);
139 if (status < 0) {
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300140 em28xx_errdev("resubmit of audio urb failed (error=%i)\n",
141 status);
Markus Rechbergera52932b2008-01-05 09:55:47 -0300142 }
143 return;
144}
145
Markus Rechbergera52932b2008-01-05 09:55:47 -0300146static int em28xx_init_audio_isoc(struct em28xx *dev)
147{
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300148 int i, errCode;
149 const int sb_size = EM28XX_NUM_AUDIO_PACKETS *
150 EM28XX_AUDIO_MAX_PACKET_SIZE;
151
152 dprintk("Starting isoc transfers\n");
Markus Rechbergera52932b2008-01-05 09:55:47 -0300153
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300154 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
Markus Rechbergera52932b2008-01-05 09:55:47 -0300155 struct urb *urb;
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300156 int j, k;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300157
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300158 dev->adev->transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300159 if (!dev->adev->transfer_buffer[i])
Markus Rechbergera52932b2008-01-05 09:55:47 -0300160 return -ENOMEM;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300161
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300162 memset(dev->adev->transfer_buffer[i], 0x80, sb_size);
163 urb = usb_alloc_urb(EM28XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300164 if (!urb)
Markus Rechbergera52932b2008-01-05 09:55:47 -0300165 return -ENOMEM;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300166
167 urb->dev = dev->udev;
168 urb->context = dev;
169 urb->pipe = usb_rcvisocpipe(dev->udev, 0x83);
170 urb->transfer_flags = URB_ISO_ASAP;
171 urb->transfer_buffer = dev->adev->transfer_buffer[i];
172 urb->interval = 1;
173 urb->complete = em28xx_audio_isocirq;
174 urb->number_of_packets = EM28XX_NUM_AUDIO_PACKETS;
175 urb->transfer_buffer_length = sb_size;
176
177 for (j = k = 0; j < EM28XX_NUM_AUDIO_PACKETS;
178 j++, k += EM28XX_AUDIO_MAX_PACKET_SIZE) {
179 urb->iso_frame_desc[j].offset = k;
180 urb->iso_frame_desc[j].length =
181 EM28XX_AUDIO_MAX_PACKET_SIZE;
Markus Rechbergera52932b2008-01-05 09:55:47 -0300182 }
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300183 dev->adev->urb[i] = urb;
Markus Rechbergera52932b2008-01-05 09:55:47 -0300184 }
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300185
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300186 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
Markus Rechbergera52932b2008-01-05 09:55:47 -0300187 errCode = usb_submit_urb(dev->adev->urb[i], GFP_ATOMIC);
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300188 if (errCode) {
Markus Rechbergera52932b2008-01-05 09:55:47 -0300189 em28xx_isoc_audio_deinit(dev);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300190
Markus Rechbergera52932b2008-01-05 09:55:47 -0300191 return errCode;
192 }
193 }
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300194
Markus Rechbergera52932b2008-01-05 09:55:47 -0300195 return 0;
196}
197
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300198static int em28xx_cmd(struct em28xx *dev, int cmd, int arg)
Markus Rechbergera52932b2008-01-05 09:55:47 -0300199{
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300200 dprintk("%s transfer\n", (dev->adev->capture_stream == STREAM_ON)?
201 "stop" : "start");
202
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300203 switch (cmd) {
204 case EM28XX_CAPTURE_STREAM_EN:
205 if (dev->adev->capture_stream == STREAM_OFF && arg == 1) {
206 dev->adev->capture_stream = STREAM_ON;
207 em28xx_init_audio_isoc(dev);
208 } else if (dev->adev->capture_stream == STREAM_ON && arg == 0) {
209 dev->adev->capture_stream = STREAM_OFF;
210 em28xx_isoc_audio_deinit(dev);
211 } else {
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300212 printk(KERN_ERR "An underrun very likely occurred. "
213 "Ignoring it.\n");
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300214 }
215 return 0;
216 default:
217 return -EINVAL;
Markus Rechbergera52932b2008-01-05 09:55:47 -0300218 }
219}
220
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300221static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
222 size_t size)
223{
224 struct snd_pcm_runtime *runtime = subs->runtime;
225
226 dprintk("Alocating vbuffer\n");
227 if (runtime->dma_area) {
228 if (runtime->dma_bytes > size)
229 return 0;
230
231 vfree(runtime->dma_area);
232 }
233 runtime->dma_area = vmalloc(size);
234 if (!runtime->dma_area)
235 return -ENOMEM;
236
237 runtime->dma_bytes = size;
238
239 return 0;
240}
241
242static struct snd_pcm_hardware snd_em28xx_hw_capture = {
243 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
244 SNDRV_PCM_INFO_MMAP |
245 SNDRV_PCM_INFO_INTERLEAVED |
246 SNDRV_PCM_INFO_MMAP_VALID,
247
248 .formats = SNDRV_PCM_FMTBIT_S16_LE,
249
250 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_KNOT,
251
252 .rate_min = 48000,
253 .rate_max = 48000,
254 .channels_min = 2,
255 .channels_max = 2,
256 .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */
257 .period_bytes_min = 64, /* 12544/2, */
258 .period_bytes_max = 12544,
259 .periods_min = 2,
260 .periods_max = 98, /* 12544, */
261};
262
263static int snd_em28xx_capture_open(struct snd_pcm_substream *substream)
264{
265 struct em28xx *dev = snd_pcm_substream_chip(substream);
266 struct snd_pcm_runtime *runtime = substream->runtime;
267 int ret = 0;
268
269 dprintk("opening device and trying to acquire exclusive lock\n");
270
271 /* Sets volume, mute, etc */
Mauro Carvalho Chehab92ea42f2008-02-06 18:52:15 -0300272
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300273 dev->mute = 0;
Mauro Carvalho Chehab92ea42f2008-02-06 18:52:15 -0300274 mutex_lock(&dev->lock);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300275 ret = em28xx_audio_analog_set(dev);
Mauro Carvalho Chehab92ea42f2008-02-06 18:52:15 -0300276 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300277 if (ret < 0)
278 goto err;
279
280 runtime->hw = snd_em28xx_hw_capture;
281 if (dev->alt == 0 && dev->adev->users == 0) {
282 int errCode;
283 dev->alt = 7;
284 errCode = usb_set_interface(dev->udev, 0, 7);
285 dprintk("changing alternate number to 7\n");
286 }
287
288 dev->adev->users++;
289
290 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
291 dev->adev->capture_pcm_substream = substream;
292 runtime->private_data = dev;
293
294 return 0;
295err:
296 printk(KERN_ERR "Error while configuring em28xx mixer\n");
297 return ret;
298}
299
300static int snd_em28xx_pcm_close(struct snd_pcm_substream *substream)
301{
302 struct em28xx *dev = snd_pcm_substream_chip(substream);
303 dev->adev->users--;
304
305 dprintk("closing device\n");
306
307 dev->mute = 1;
Mauro Carvalho Chehab92ea42f2008-02-06 18:52:15 -0300308 mutex_lock(&dev->lock);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300309 em28xx_audio_analog_set(dev);
Mauro Carvalho Chehab92ea42f2008-02-06 18:52:15 -0300310 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300311
312 if (dev->adev->users == 0 && dev->adev->shutdown == 1) {
313 dprintk("audio users: %d\n", dev->adev->users);
314 dprintk("disabling audio stream!\n");
315 dev->adev->shutdown = 0;
316 dprintk("released lock\n");
317 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 0);
318 }
319 return 0;
320}
321
322static int snd_em28xx_hw_capture_params(struct snd_pcm_substream *substream,
323 struct snd_pcm_hw_params *hw_params)
324{
325 unsigned int channels, rate, format;
326 int ret;
327
328 dprintk("Setting capture parameters\n");
329
330 ret = snd_pcm_alloc_vmalloc_buffer(substream,
331 params_buffer_bytes(hw_params));
332 format = params_format(hw_params);
333 rate = params_rate(hw_params);
334 channels = params_channels(hw_params);
335
336 /* TODO: set up em28xx audio chip to deliver the correct audio format,
337 current default is 48000hz multiplexed => 96000hz mono
338 which shouldn't matter since analogue TV only supports mono */
339 return 0;
340}
341
342static int snd_em28xx_hw_capture_free(struct snd_pcm_substream *substream)
343{
344 struct em28xx *dev = snd_pcm_substream_chip(substream);
345
346 dprintk("Stop capture, if needed\n");
347
348 if (dev->adev->capture_stream == STREAM_ON)
349 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 0);
350
351 return 0;
352}
353
354static int snd_em28xx_prepare(struct snd_pcm_substream *substream)
355{
356 return 0;
357}
358
359static int snd_em28xx_capture_trigger(struct snd_pcm_substream *substream,
360 int cmd)
361{
362 struct em28xx *dev = snd_pcm_substream_chip(substream);
363
364 dprintk("Should %s capture\n", (cmd == SNDRV_PCM_TRIGGER_START)?
365 "start": "stop");
366 switch (cmd) {
367 case SNDRV_PCM_TRIGGER_START:
368 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 1);
369 return 0;
370 case SNDRV_PCM_TRIGGER_STOP:
371 dev->adev->shutdown = 1;
372 return 0;
373 default:
374 return -EINVAL;
375 }
376}
377
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300378static snd_pcm_uframes_t snd_em28xx_capture_pointer(struct snd_pcm_substream
379 *substream)
Markus Rechbergera52932b2008-01-05 09:55:47 -0300380{
381 struct em28xx *dev;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300382
Markus Rechbergera52932b2008-01-05 09:55:47 -0300383 snd_pcm_uframes_t hwptr_done;
384 dev = snd_pcm_substream_chip(substream);
385 hwptr_done = dev->adev->hwptr_done_capture;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300386
Markus Rechbergera52932b2008-01-05 09:55:47 -0300387 return hwptr_done;
388}
389
390static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
391 unsigned long offset)
392{
393 void *pageptr = subs->runtime->dma_area + offset;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300394
Markus Rechbergera52932b2008-01-05 09:55:47 -0300395 return vmalloc_to_page(pageptr);
396}
397
398static struct snd_pcm_ops snd_em28xx_pcm_capture = {
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300399 .open = snd_em28xx_capture_open,
400 .close = snd_em28xx_pcm_close,
401 .ioctl = snd_pcm_lib_ioctl,
Markus Rechbergera52932b2008-01-05 09:55:47 -0300402 .hw_params = snd_em28xx_hw_capture_params,
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300403 .hw_free = snd_em28xx_hw_capture_free,
404 .prepare = snd_em28xx_prepare,
405 .trigger = snd_em28xx_capture_trigger,
406 .pointer = snd_em28xx_capture_pointer,
407 .page = snd_pcm_get_vmalloc_page,
Markus Rechbergera52932b2008-01-05 09:55:47 -0300408};
409
Markus Rechbergera52932b2008-01-05 09:55:47 -0300410static int em28xx_audio_init(struct em28xx *dev)
411{
412 struct em28xx_audio *adev;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300413 struct snd_pcm *pcm;
414 struct snd_card *card;
415 static int devnr;
416 int ret, err;
417
418 printk(KERN_INFO "em28xx-audio.c: probing for em28x1 "
419 "non standard usbaudio\n");
420 printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
421 "Rechberger\n");
422
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300423 adev = kzalloc(sizeof(*adev), GFP_KERNEL);
424 if (!adev) {
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300425 printk(KERN_ERR "em28xx-audio.c: out of memory\n");
Markus Rechbergera52932b2008-01-05 09:55:47 -0300426 return -1;
427 }
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300428 card = snd_card_new(index[devnr], "Em28xx Audio", THIS_MODULE, 0);
429 if (card == NULL) {
Markus Rechbergera52932b2008-01-05 09:55:47 -0300430 kfree(adev);
431 return -ENOMEM;
432 }
433
434 spin_lock_init(&adev->slock);
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300435 ret = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
Markus Rechbergera52932b2008-01-05 09:55:47 -0300436 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
437 pcm->info_flags = 0;
438 pcm->private_data = dev;
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300439 strcpy(pcm->name, "Empia 28xx Capture");
Markus Rechbergera52932b2008-01-05 09:55:47 -0300440 strcpy(card->driver, "Empia Em28xx Audio");
441 strcpy(card->shortname, "Em28xx Audio");
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300442 strcpy(card->longname, "Empia Em28xx Audio");
Markus Rechbergera52932b2008-01-05 09:55:47 -0300443
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300444 err = snd_card_register(card);
445 if (err < 0) {
Markus Rechbergera52932b2008-01-05 09:55:47 -0300446 snd_card_free(card);
447 return -ENOMEM;
448 }
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300449 adev->sndcard = card;
450 adev->udev = dev->udev;
451 dev->adev = adev;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300452
Markus Rechbergera52932b2008-01-05 09:55:47 -0300453 return 0;
454}
455
456static int em28xx_audio_fini(struct em28xx *dev)
457{
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300458 if (dev == NULL)
Markus Rechbergera52932b2008-01-05 09:55:47 -0300459 return 0;
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300460
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300461 if (dev->adev) {
Markus Rechbergera52932b2008-01-05 09:55:47 -0300462 snd_card_free(dev->adev->sndcard);
463 kfree(dev->adev);
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300464 dev->adev = NULL;
Markus Rechbergera52932b2008-01-05 09:55:47 -0300465 }
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300466
Markus Rechbergera52932b2008-01-05 09:55:47 -0300467 return 0;
468}
469
470static struct em28xx_ops audio_ops = {
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300471 .id = EM28XX_AUDIO,
Mauro Carvalho Chehab1a6f11e2008-01-05 09:56:24 -0300472 .name = "Em28xx Audio Extension",
473 .init = em28xx_audio_init,
474 .fini = em28xx_audio_fini,
Markus Rechbergera52932b2008-01-05 09:55:47 -0300475};
476
477static int __init em28xx_alsa_register(void)
478{
Markus Rechbergera52932b2008-01-05 09:55:47 -0300479 return em28xx_register_extension(&audio_ops);
480}
481
482static void __exit em28xx_alsa_unregister(void)
483{
484 em28xx_unregister_extension(&audio_ops);
485}
486
487MODULE_LICENSE("GPL");
488MODULE_AUTHOR("Markus Rechberger <mrechberger@gmail.com>");
Mauro Carvalho Chehab6d794682008-01-05 09:57:31 -0300489MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
Markus Rechbergera52932b2008-01-05 09:55:47 -0300490MODULE_DESCRIPTION("Em28xx Audio driver");
491
492module_init(em28xx_alsa_register);
493module_exit(em28xx_alsa_unregister);