blob: e5fbbf1895a4ebc9fc8d750eb99a42ad4da1aad4 [file] [log] [blame]
Vinod Koulc78fe9c2011-09-02 11:36:23 +05301/*
2 * compress_driver.h - compress offload driver definations
3 *
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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
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.
12 *
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.
17 *
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.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 *
24 */
25#ifndef __COMPRESS_DRIVER_H
26#define __COMPRESS_DRIVER_H
27
28#include <sound/compress_offload.h>
29#include <sound/asound.h>
30#include <sound/pcm.h>
31
32struct snd_compr_ops;
33
34/**
35 * struct snd_compr_runtime: runtime stream description
36 * @state: stream state
37 * @ops: pointer to DSP callbacks
38 * @buffer: pointer to kernel buffer, valid only when not in mmap mode or
39 * DSP doesn't implement copy
40 * @buffer_size: size of the above buffer
41 * @fragment_size: size of buffer fragment in bytes
42 * @periods: number of such fragments
43 * @hw_pointer: offset of last location in buffer where DSP copied data
44 * @app_pointer: offset of last location in buffer where app wrote data
45 * @sleep: poll sleep
46 */
47struct snd_compr_runtime {
48 snd_pcm_state_t state;
49 struct snd_compr_ops *ops;
50 void *buffer;
51 size_t buffer_size;
52 size_t fragment_size;
53 unsigned int periods;
54 size_t hw_pointer;
55 size_t app_pointer;
56 wait_queue_head_t sleep;
57};
58
59/**
60 * struct snd_compr_stream: compressed stream
61 * @name: device name
62 * @ops: pointer to DSP callbacks
63 * @runtime: pointer to runtime structure
64 * @device: device pointer
65 * @direction: stream direction, playback/recording
66 * @private_data: pointer to DSP private data
67 */
68struct snd_compr_stream {
69 const char *name;
70 struct snd_compr_ops *ops;
71 struct snd_compr_runtime *runtime;
72 struct snd_compr *device;
73 unsigned int direction;
74 void *private_data;
75};
76
77/**
78 * struct snd_compr_ops: compressed path DSP operations
79 * @open: Open the compressed stream
80 * This callback is mandatory and shall keep dsp ready to receive the stream parameter
81 * @free: Close the compressed stream, mandatory
82 * @set_params: Sets the compressed stream parameters, mandatory
83 * This can be called in during stream creation only to set codec params
84 * and the stream properties
85 * @get_params: retrieve the codec parameters, mandatory
86 * @trigger: Trigger operations like start, pause, resume, drain, stop. Mandatory
87 * @pointer: Retrieve current h/w pointer information. Mandatory
88 * @copy: Copy the compressed data to/from userspace, Optional
89 * Can't be implemented if DSP supports mmap
90 * @mmap: DSP mmap method to mmap DSP memory
91 * @ack: Ack for DSP when data is written to audio buffer, Optional
92 * Not valid if copy is implemented
93 * @get_caps: Retrieve DSP capabilities, mandatory
94 * @get_codec_caps: Retrieve capabilities for a specific codec, mandatory
95 */
96struct snd_compr_ops {
97 int (*open)(struct snd_compr_stream *stream);
98 int (*free)(struct snd_compr_stream *stream);
99 int (*set_params)(struct snd_compr_stream *stream,
100 struct snd_compr_params *params);
101 int (*get_params)(struct snd_compr_stream *stream,
102 struct snd_compr_params *params);
103 int (*trigger)(struct snd_compr_stream *stream, int cmd);
104 int (*pointer)(struct snd_compr_stream *stream,
105 struct snd_compr_tstamp *tstamp);
106 int (*copy)(struct snd_compr_stream *stream, const char __user *buf,
107 size_t count);
108 int (*mmap)(struct snd_compr_stream *stream, struct vm_area_struct *vma);
109 int (*ack)(struct snd_compr_stream *stream);
110 int (*get_caps) (struct snd_compr_stream *stream,
111 struct snd_compr_caps *caps);
112 int (*get_codec_caps) (struct snd_compr_stream *stream,
113 struct snd_compr_codec_caps *codec);
114};
115
116/**
117 * struct snd_compr: Compressed device
118 * @name: DSP device name
119 * @dev: Device pointer
120 * @lock: device lock
121 * @ops: pointer to DSP callbacks
122 * @private_data: pointer to DSP pvt data
123 */
124struct snd_compr {
125 const char *name;
126 struct device *dev;
127 struct mutex lock;
128 struct snd_compr_ops *ops;
129 struct list_head list;
130 void *private_data;
131};
132
133
134int snd_compress_register(struct snd_compr *device);
135int snd_compress_deregister(struct snd_compr *device);
136void snd_compr_period_elapsed(struct snd_compr_stream *stream);
137
138#endif