2 * compress_core.c - compress offload core
4 * Copyright (C) 2011 Intel Corporation
5 * Authors: Vinod Koul <vinod.koul@linux.intel.com>
6 * Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 #define FORMAT(fmt) "%s: %d: " fmt, __func__, __LINE__
26 #define pr_fmt(fmt) KBUILD_MODNAME ": " FORMAT(fmt)
28 #include <linux/file.h>
30 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/poll.h>
34 #include <linux/slab.h>
35 #include <linux/sched.h>
36 #include <linux/uio.h>
37 #include <linux/uaccess.h>
38 #include <linux/module.h>
39 #include <sound/core.h>
40 #include <sound/initval.h>
41 #include <sound/compress_params.h>
42 #include <sound/compress_offload.h>
43 #include <sound/compress_driver.h>
46 * - add substream support for multiple devices in case of
47 * SND_DYNAMIC_MINORS is not used
48 * - Multiple node representation
49 * driver should be able to register multiple nodes
52 static DEFINE_MUTEX(device_mutex);
54 struct snd_compr_file {
56 struct snd_compr_stream stream;
60 * a note on stream states used:
61 * we use follwing states in the compressed core
62 * SNDRV_PCM_STATE_OPEN: When stream has been opened.
63 * SNDRV_PCM_STATE_SETUP: When stream has been initialized. This is done by
64 * calling SNDRV_COMPRESS_SET_PARAMS. running streams will come to this
65 * state at stop by calling SNDRV_COMPRESS_STOP, or at end of drain.
66 * SNDRV_PCM_STATE_RUNNING: When stream has been started and is
67 * decoding/encoding and rendering/capturing data.
68 * SNDRV_PCM_STATE_DRAINING: When stream is draining current data. This is done
69 * by calling SNDRV_COMPRESS_DRAIN.
70 * SNDRV_PCM_STATE_PAUSED: When stream is paused. This is done by calling
71 * SNDRV_COMPRESS_PAUSE. It can be stopped or resumed by calling
72 * SNDRV_COMPRESS_STOP or SNDRV_COMPRESS_RESUME respectively.
74 static int snd_compr_open(struct inode *inode, struct file *f)
76 struct snd_compr *compr;
77 struct snd_compr_file *data;
78 struct snd_compr_runtime *runtime;
79 enum snd_compr_direction dirn;
80 int maj = imajor(inode);
83 if ((f->f_flags & O_ACCMODE) == O_WRONLY)
84 dirn = SND_COMPRESS_PLAYBACK;
85 else if ((f->f_flags & O_ACCMODE) == O_RDONLY)
86 dirn = SND_COMPRESS_CAPTURE;
91 compr = snd_lookup_minor_data(iminor(inode),
92 SNDRV_DEVICE_TYPE_COMPRESS);
97 pr_err("no device data!!!\n");
101 if (dirn != compr->direction) {
102 pr_err("this device doesn't support this direction\n");
103 snd_card_unref(compr->card);
107 data = kzalloc(sizeof(*data), GFP_KERNEL);
109 snd_card_unref(compr->card);
112 data->stream.ops = compr->ops;
113 data->stream.direction = dirn;
114 data->stream.private_data = compr->private_data;
115 data->stream.device = compr;
116 runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
119 snd_card_unref(compr->card);
122 runtime->state = SNDRV_PCM_STATE_OPEN;
123 init_waitqueue_head(&runtime->sleep);
124 data->stream.runtime = runtime;
125 f->private_data = (void *)data;
126 mutex_lock(&compr->lock);
127 ret = compr->ops->open(&data->stream);
128 mutex_unlock(&compr->lock);
133 snd_card_unref(compr->card);
137 static int snd_compr_free(struct inode *inode, struct file *f)
139 struct snd_compr_file *data = f->private_data;
140 data->stream.ops->free(&data->stream);
141 kfree(data->stream.runtime->buffer);
142 kfree(data->stream.runtime);
147 static int snd_compr_update_tstamp(struct snd_compr_stream *stream,
148 struct snd_compr_tstamp *tstamp)
150 if (!stream->ops->pointer)
152 stream->ops->pointer(stream, tstamp);
153 pr_debug("dsp consumed till %d total %d bytes\n",
154 tstamp->byte_offset, tstamp->copied_total);
155 stream->runtime->hw_pointer = tstamp->byte_offset;
156 if (stream->direction == SND_COMPRESS_PLAYBACK)
157 stream->runtime->total_bytes_transferred = tstamp->copied_total;
159 stream->runtime->total_bytes_available = tstamp->copied_total;
163 static size_t snd_compr_calc_avail(struct snd_compr_stream *stream,
164 struct snd_compr_avail *avail)
166 memset(avail, 0, sizeof(*avail));
167 snd_compr_update_tstamp(stream, &avail->tstamp);
168 /* Still need to return avail even if tstamp can't be filled in */
170 if (stream->runtime->total_bytes_available == 0 &&
171 stream->runtime->state == SNDRV_PCM_STATE_SETUP &&
172 stream->direction == SND_COMPRESS_PLAYBACK) {
173 pr_debug("detected init and someone forgot to do a write\n");
174 return stream->runtime->buffer_size;
176 pr_debug("app wrote %lld, DSP consumed %lld\n",
177 stream->runtime->total_bytes_available,
178 stream->runtime->total_bytes_transferred);
179 if (stream->runtime->total_bytes_available ==
180 stream->runtime->total_bytes_transferred) {
181 if (stream->direction == SND_COMPRESS_PLAYBACK) {
182 pr_debug("both pointers are same, returning full avail\n");
183 return stream->runtime->buffer_size;
185 pr_debug("both pointers are same, returning no avail\n");
190 avail->avail = stream->runtime->total_bytes_available -
191 stream->runtime->total_bytes_transferred;
192 if (stream->direction == SND_COMPRESS_PLAYBACK)
193 avail->avail = stream->runtime->buffer_size - avail->avail;
195 pr_debug("ret avail as %lld\n", avail->avail);
199 static inline size_t snd_compr_get_avail(struct snd_compr_stream *stream)
201 struct snd_compr_avail avail;
203 return snd_compr_calc_avail(stream, &avail);
207 snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg)
209 struct snd_compr_avail ioctl_avail;
212 avail = snd_compr_calc_avail(stream, &ioctl_avail);
213 ioctl_avail.avail = avail;
215 if (copy_to_user((__u64 __user *)arg,
216 &ioctl_avail, sizeof(ioctl_avail)))
221 static int snd_compr_write_data(struct snd_compr_stream *stream,
222 const char __user *buf, size_t count)
226 struct snd_compr_runtime *runtime = stream->runtime;
228 dstn = runtime->buffer + runtime->app_pointer;
229 pr_debug("copying %ld at %lld\n",
230 (unsigned long)count, runtime->app_pointer);
231 if (count < runtime->buffer_size - runtime->app_pointer) {
232 if (copy_from_user(dstn, buf, count))
234 runtime->app_pointer += count;
236 copy = runtime->buffer_size - runtime->app_pointer;
237 if (copy_from_user(dstn, buf, copy))
239 if (copy_from_user(runtime->buffer, buf + copy, count - copy))
241 runtime->app_pointer = count - copy;
243 /* if DSP cares, let it know data has been written */
244 if (stream->ops->ack)
245 stream->ops->ack(stream, count);
249 static ssize_t snd_compr_write(struct file *f, const char __user *buf,
250 size_t count, loff_t *offset)
252 struct snd_compr_file *data = f->private_data;
253 struct snd_compr_stream *stream;
257 if (snd_BUG_ON(!data))
260 stream = &data->stream;
261 mutex_lock(&stream->device->lock);
262 /* write is allowed when stream is running or has been steup */
263 if (stream->runtime->state != SNDRV_PCM_STATE_SETUP &&
264 stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
265 mutex_unlock(&stream->device->lock);
269 avail = snd_compr_get_avail(stream);
270 pr_debug("avail returned %ld\n", (unsigned long)avail);
271 /* calculate how much we can write to buffer */
275 if (stream->ops->copy) {
276 char __user* cbuf = (char __user*)buf;
277 retval = stream->ops->copy(stream, cbuf, avail);
279 retval = snd_compr_write_data(stream, buf, avail);
282 stream->runtime->total_bytes_available += retval;
284 /* while initiating the stream, write should be called before START
285 * call, so in setup move state */
286 if (stream->runtime->state == SNDRV_PCM_STATE_SETUP) {
287 stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
288 pr_debug("stream prepared, Houston we are good to go\n");
291 mutex_unlock(&stream->device->lock);
296 static ssize_t snd_compr_read(struct file *f, char __user *buf,
297 size_t count, loff_t *offset)
299 struct snd_compr_file *data = f->private_data;
300 struct snd_compr_stream *stream;
304 if (snd_BUG_ON(!data))
307 stream = &data->stream;
308 mutex_lock(&stream->device->lock);
310 /* read is allowed when stream is running */
311 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
316 avail = snd_compr_get_avail(stream);
317 pr_debug("avail returned %ld\n", (unsigned long)avail);
318 /* calculate how much we can read from buffer */
322 if (stream->ops->copy) {
323 retval = stream->ops->copy(stream, buf, avail);
329 stream->runtime->total_bytes_transferred += retval;
332 mutex_unlock(&stream->device->lock);
336 static int snd_compr_mmap(struct file *f, struct vm_area_struct *vma)
341 static inline int snd_compr_get_poll(struct snd_compr_stream *stream)
343 if (stream->direction == SND_COMPRESS_PLAYBACK)
344 return POLLOUT | POLLWRNORM;
346 return POLLIN | POLLRDNORM;
349 static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
351 struct snd_compr_file *data = f->private_data;
352 struct snd_compr_stream *stream;
356 if (snd_BUG_ON(!data))
358 stream = &data->stream;
359 if (snd_BUG_ON(!stream))
362 mutex_lock(&stream->device->lock);
363 if (stream->runtime->state == SNDRV_PCM_STATE_PAUSED ||
364 stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
368 poll_wait(f, &stream->runtime->sleep, wait);
370 avail = snd_compr_get_avail(stream);
371 pr_debug("avail is %ld\n", (unsigned long)avail);
372 /* check if we have at least one fragment to fill */
373 switch (stream->runtime->state) {
374 case SNDRV_PCM_STATE_DRAINING:
375 /* stream has been woken up after drain is complete
376 * draining done so set stream state to stopped
378 retval = snd_compr_get_poll(stream);
379 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
381 case SNDRV_PCM_STATE_RUNNING:
382 case SNDRV_PCM_STATE_PREPARED:
383 case SNDRV_PCM_STATE_PAUSED:
384 if (avail >= stream->runtime->fragment_size)
385 retval = snd_compr_get_poll(stream);
388 if (stream->direction == SND_COMPRESS_PLAYBACK)
389 retval = POLLOUT | POLLWRNORM | POLLERR;
391 retval = POLLIN | POLLRDNORM | POLLERR;
395 mutex_unlock(&stream->device->lock);
400 snd_compr_get_caps(struct snd_compr_stream *stream, unsigned long arg)
403 struct snd_compr_caps caps;
405 if (!stream->ops->get_caps)
408 retval = stream->ops->get_caps(stream, &caps);
411 if (copy_to_user((void __user *)arg, &caps, sizeof(caps)))
418 snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg)
421 struct snd_compr_codec_caps *caps;
423 if (!stream->ops->get_codec_caps)
426 caps = kmalloc(sizeof(*caps), GFP_KERNEL);
430 retval = stream->ops->get_codec_caps(stream, caps);
433 if (copy_to_user((void __user *)arg, caps, sizeof(*caps)))
441 /* revisit this with snd_pcm_preallocate_xxx */
442 static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
443 struct snd_compr_params *params)
445 unsigned int buffer_size;
448 buffer_size = params->buffer.fragment_size * params->buffer.fragments;
449 if (stream->ops->copy) {
451 /* if copy is defined the driver will be required to copy
455 buffer = kmalloc(buffer_size, GFP_KERNEL);
459 stream->runtime->fragment_size = params->buffer.fragment_size;
460 stream->runtime->fragments = params->buffer.fragments;
461 stream->runtime->buffer = buffer;
462 stream->runtime->buffer_size = buffer_size;
466 static int snd_compress_check_input(struct snd_compr_params *params)
468 /* first let's check the buffer parameter's */
469 if (params->buffer.fragment_size == 0 ||
470 params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
473 /* now codec parameters */
474 if (params->codec.id == 0 || params->codec.id > SND_AUDIOCODEC_MAX)
477 if (params->codec.ch_in == 0 || params->codec.ch_out == 0)
480 if (!(params->codec.sample_rate & SNDRV_PCM_RATE_8000_192000))
487 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
489 struct snd_compr_params *params;
492 if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
494 * we should allow parameter change only when stream has been
495 * opened not in other cases
497 params = kmalloc(sizeof(*params), GFP_KERNEL);
500 if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
505 retval = snd_compress_check_input(params);
509 retval = snd_compr_allocate_buffer(stream, params);
515 retval = stream->ops->set_params(stream, params);
519 stream->metadata_set = false;
520 stream->next_track = false;
522 if (stream->direction == SND_COMPRESS_PLAYBACK)
523 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
525 stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
535 snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg)
537 struct snd_codec *params;
540 if (!stream->ops->get_params)
543 params = kmalloc(sizeof(*params), GFP_KERNEL);
546 retval = stream->ops->get_params(stream, params);
549 if (copy_to_user((char __user *)arg, params, sizeof(*params)))
558 snd_compr_get_metadata(struct snd_compr_stream *stream, unsigned long arg)
560 struct snd_compr_metadata metadata;
563 if (!stream->ops->get_metadata)
566 if (copy_from_user(&metadata, (void __user *)arg, sizeof(metadata)))
569 retval = stream->ops->get_metadata(stream, &metadata);
573 if (copy_to_user((void __user *)arg, &metadata, sizeof(metadata)))
580 snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg)
582 struct snd_compr_metadata metadata;
585 if (!stream->ops->set_metadata)
588 * we should allow parameter change only when stream has been
589 * opened not in other cases
591 if (copy_from_user(&metadata, (void __user *)arg, sizeof(metadata)))
594 retval = stream->ops->set_metadata(stream, &metadata);
595 stream->metadata_set = true;
601 snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg)
603 struct snd_compr_tstamp tstamp = {0};
606 ret = snd_compr_update_tstamp(stream, &tstamp);
608 ret = copy_to_user((struct snd_compr_tstamp __user *)arg,
609 &tstamp, sizeof(tstamp)) ? -EFAULT : 0;
613 static int snd_compr_pause(struct snd_compr_stream *stream)
617 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING)
619 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH);
621 stream->runtime->state = SNDRV_PCM_STATE_PAUSED;
625 static int snd_compr_resume(struct snd_compr_stream *stream)
629 if (stream->runtime->state != SNDRV_PCM_STATE_PAUSED)
631 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE);
633 stream->runtime->state = SNDRV_PCM_STATE_RUNNING;
637 static int snd_compr_start(struct snd_compr_stream *stream)
641 if (stream->runtime->state != SNDRV_PCM_STATE_PREPARED)
643 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_START);
645 stream->runtime->state = SNDRV_PCM_STATE_RUNNING;
649 static int snd_compr_stop(struct snd_compr_stream *stream)
653 if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
654 stream->runtime->state == SNDRV_PCM_STATE_SETUP)
656 retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
658 stream->runtime->state = SNDRV_PCM_STATE_SETUP;
659 wake_up(&stream->runtime->sleep);
660 stream->runtime->hw_pointer = 0;
661 stream->runtime->app_pointer = 0;
662 stream->runtime->total_bytes_available = 0;
663 stream->runtime->total_bytes_transferred = 0;
668 static int snd_compr_drain(struct snd_compr_stream *stream)
672 if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
673 stream->runtime->state == SNDRV_PCM_STATE_SETUP)
675 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN);
677 stream->runtime->state = SNDRV_PCM_STATE_DRAINING;
678 wake_up(&stream->runtime->sleep);
683 static int snd_compr_next_track(struct snd_compr_stream *stream)
687 /* only a running stream can transition to next track */
688 if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING)
691 /* you can signal next track isf this is intended to be a gapless stream
692 * and current track metadata is set
694 if (stream->metadata_set == false)
697 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_NEXT_TRACK);
700 stream->metadata_set = false;
701 stream->next_track = true;
705 static int snd_compr_partial_drain(struct snd_compr_stream *stream)
708 if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
709 stream->runtime->state == SNDRV_PCM_STATE_SETUP)
711 /* stream can be drained only when next track has been signalled */
712 if (stream->next_track == false)
715 retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN);
717 stream->next_track = false;
721 static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
723 struct snd_compr_file *data = f->private_data;
724 struct snd_compr_stream *stream;
725 int retval = -ENOTTY;
727 if (snd_BUG_ON(!data))
729 stream = &data->stream;
730 if (snd_BUG_ON(!stream))
732 mutex_lock(&stream->device->lock);
733 switch (_IOC_NR(cmd)) {
734 case _IOC_NR(SNDRV_COMPRESS_IOCTL_VERSION):
735 put_user(SNDRV_COMPRESS_VERSION,
736 (int __user *)arg) ? -EFAULT : 0;
738 case _IOC_NR(SNDRV_COMPRESS_GET_CAPS):
739 retval = snd_compr_get_caps(stream, arg);
741 case _IOC_NR(SNDRV_COMPRESS_GET_CODEC_CAPS):
742 retval = snd_compr_get_codec_caps(stream, arg);
744 case _IOC_NR(SNDRV_COMPRESS_SET_PARAMS):
745 retval = snd_compr_set_params(stream, arg);
747 case _IOC_NR(SNDRV_COMPRESS_GET_PARAMS):
748 retval = snd_compr_get_params(stream, arg);
750 case _IOC_NR(SNDRV_COMPRESS_SET_METADATA):
751 retval = snd_compr_set_metadata(stream, arg);
753 case _IOC_NR(SNDRV_COMPRESS_GET_METADATA):
754 retval = snd_compr_get_metadata(stream, arg);
756 case _IOC_NR(SNDRV_COMPRESS_TSTAMP):
757 retval = snd_compr_tstamp(stream, arg);
759 case _IOC_NR(SNDRV_COMPRESS_AVAIL):
760 retval = snd_compr_ioctl_avail(stream, arg);
762 case _IOC_NR(SNDRV_COMPRESS_PAUSE):
763 retval = snd_compr_pause(stream);
765 case _IOC_NR(SNDRV_COMPRESS_RESUME):
766 retval = snd_compr_resume(stream);
768 case _IOC_NR(SNDRV_COMPRESS_START):
769 retval = snd_compr_start(stream);
771 case _IOC_NR(SNDRV_COMPRESS_STOP):
772 retval = snd_compr_stop(stream);
774 case _IOC_NR(SNDRV_COMPRESS_DRAIN):
775 retval = snd_compr_drain(stream);
777 case _IOC_NR(SNDRV_COMPRESS_PARTIAL_DRAIN):
778 retval = snd_compr_partial_drain(stream);
780 case _IOC_NR(SNDRV_COMPRESS_NEXT_TRACK):
781 retval = snd_compr_next_track(stream);
785 mutex_unlock(&stream->device->lock);
789 static const struct file_operations snd_compr_file_ops = {
790 .owner = THIS_MODULE,
791 .open = snd_compr_open,
792 .release = snd_compr_free,
793 .write = snd_compr_write,
794 .read = snd_compr_read,
795 .unlocked_ioctl = snd_compr_ioctl,
796 .mmap = snd_compr_mmap,
797 .poll = snd_compr_poll,
800 static int snd_compress_dev_register(struct snd_device *device)
804 struct snd_compr *compr;
806 if (snd_BUG_ON(!device || !device->device_data))
808 compr = device->device_data;
810 sprintf(str, "comprC%iD%i", compr->card->number, compr->device);
811 pr_debug("reg %s for device %s, direction %d\n", str, compr->name,
813 /* register compressed device */
814 ret = snd_register_device(SNDRV_DEVICE_TYPE_COMPRESS, compr->card,
815 compr->device, &snd_compr_file_ops, compr, str);
817 pr_err("snd_register_device failed\n %d", ret);
824 static int snd_compress_dev_disconnect(struct snd_device *device)
826 struct snd_compr *compr;
828 compr = device->device_data;
829 snd_unregister_device(compr->direction, compr->card, compr->device);
834 * snd_compress_new: create new compress device
835 * @card: sound card pointer
836 * @device: device number
837 * @dirn: device direction, should be of type enum snd_compr_direction
838 * @compr: compress device pointer
840 int snd_compress_new(struct snd_card *card, int device,
841 int dirn, struct snd_compr *compr)
843 static struct snd_device_ops ops = {
845 .dev_register = snd_compress_dev_register,
846 .dev_disconnect = snd_compress_dev_disconnect,
850 compr->device = device;
851 compr->direction = dirn;
852 return snd_device_new(card, SNDRV_DEV_COMPRESS, compr, &ops);
854 EXPORT_SYMBOL_GPL(snd_compress_new);
856 static int snd_compress_add_device(struct snd_compr *device)
863 /* register the card */
864 ret = snd_card_register(device->card);
870 pr_err("failed with %d\n", ret);
875 static int snd_compress_remove_device(struct snd_compr *device)
877 return snd_card_free(device->card);
881 * snd_compress_register - register compressed device
883 * @device: compressed device to register
885 int snd_compress_register(struct snd_compr *device)
889 if (device->name == NULL || device->dev == NULL || device->ops == NULL)
892 pr_debug("Registering compressed device %s\n", device->name);
893 if (snd_BUG_ON(!device->ops->open))
895 if (snd_BUG_ON(!device->ops->free))
897 if (snd_BUG_ON(!device->ops->set_params))
899 if (snd_BUG_ON(!device->ops->trigger))
902 mutex_init(&device->lock);
904 /* register a compressed card */
905 mutex_lock(&device_mutex);
906 retval = snd_compress_add_device(device);
907 mutex_unlock(&device_mutex);
910 EXPORT_SYMBOL_GPL(snd_compress_register);
912 int snd_compress_deregister(struct snd_compr *device)
914 pr_debug("Removing compressed device %s\n", device->name);
915 mutex_lock(&device_mutex);
916 snd_compress_remove_device(device);
917 mutex_unlock(&device_mutex);
920 EXPORT_SYMBOL_GPL(snd_compress_deregister);
922 static int __init snd_compress_init(void)
927 static void __exit snd_compress_exit(void)
931 module_init(snd_compress_init);
932 module_exit(snd_compress_exit);
934 MODULE_DESCRIPTION("ALSA Compressed offload framework");
935 MODULE_AUTHOR("Vinod Koul <vinod.koul@linux.intel.com>");
936 MODULE_LICENSE("GPL v2");