blob: 2fd1604cc86e245de2f83e3a628d5597c9e1fd53 [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
Vinod Koulf15a95c2011-09-09 06:03:51 +053042 * @fragments: number of such fragments
Vinod Koulc78fe9c2011-09-02 11:36:23 +053043 * @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;
Vinod Koulf15a95c2011-09-09 06:03:51 +053053 unsigned int fragments;
Vinod Koulc78fe9c2011-09-02 11:36:23 +053054 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
Vinod Koulf15a95c2011-09-09 06:03:51 +053080 * This callback is mandatory and shall keep dsp ready to receive the stream
81 * parameter
Vinod Koulc78fe9c2011-09-02 11:36:23 +053082 * @free: Close the compressed stream, mandatory
83 * @set_params: Sets the compressed stream parameters, mandatory
84 * This can be called in during stream creation only to set codec params
85 * and the stream properties
86 * @get_params: retrieve the codec parameters, mandatory
Vinod Koulf15a95c2011-09-09 06:03:51 +053087 * @trigger: Trigger operations like start, pause, resume, drain, stop.
88 * This callback is mandatory
Vinod Koulc78fe9c2011-09-02 11:36:23 +053089 * @pointer: Retrieve current h/w pointer information. Mandatory
90 * @copy: Copy the compressed data to/from userspace, Optional
91 * Can't be implemented if DSP supports mmap
92 * @mmap: DSP mmap method to mmap DSP memory
93 * @ack: Ack for DSP when data is written to audio buffer, Optional
94 * Not valid if copy is implemented
95 * @get_caps: Retrieve DSP capabilities, mandatory
96 * @get_codec_caps: Retrieve capabilities for a specific codec, mandatory
97 */
98struct snd_compr_ops {
99 int (*open)(struct snd_compr_stream *stream);
100 int (*free)(struct snd_compr_stream *stream);
101 int (*set_params)(struct snd_compr_stream *stream,
102 struct snd_compr_params *params);
103 int (*get_params)(struct snd_compr_stream *stream,
104 struct snd_compr_params *params);
105 int (*trigger)(struct snd_compr_stream *stream, int cmd);
106 int (*pointer)(struct snd_compr_stream *stream,
107 struct snd_compr_tstamp *tstamp);
108 int (*copy)(struct snd_compr_stream *stream, const char __user *buf,
109 size_t count);
Vinod Koulf15a95c2011-09-09 06:03:51 +0530110 int (*mmap)(struct snd_compr_stream *stream,
111 struct vm_area_struct *vma);
Vinod Koulc78fe9c2011-09-02 11:36:23 +0530112 int (*ack)(struct snd_compr_stream *stream);
113 int (*get_caps) (struct snd_compr_stream *stream,
114 struct snd_compr_caps *caps);
115 int (*get_codec_caps) (struct snd_compr_stream *stream,
116 struct snd_compr_codec_caps *codec);
117};
118
119/**
120 * struct snd_compr: Compressed device
121 * @name: DSP device name
122 * @dev: Device pointer
123 * @lock: device lock
124 * @ops: pointer to DSP callbacks
125 * @private_data: pointer to DSP pvt data
126 */
127struct snd_compr {
128 const char *name;
129 struct device *dev;
130 struct mutex lock;
131 struct snd_compr_ops *ops;
132 struct list_head list;
133 void *private_data;
134};
135
Vinod Koulf15a95c2011-09-09 06:03:51 +0530136/* compress device register APIs */
Vinod Koulc78fe9c2011-09-02 11:36:23 +0530137int snd_compress_register(struct snd_compr *device);
138int snd_compress_deregister(struct snd_compr *device);
Vinod Koulf15a95c2011-09-09 06:03:51 +0530139
140/* dsp driver callback apis
141 * For playback: driver should call snd_compress_fragment_elapsed() to let the
142 * framework know that a fragment has been consumed from the ring buffer
143 * For recording: we may want to know when a frame is available or when
144 * at least one frame is available for userspace, a different
145 * snd_compress_frame_elapsed() callback should be used
146 */
147void snd_compr_fragment_elapsed(struct snd_compr_stream *stream);
148void snd_compr_frame_elapsed(struct snd_compr_stream *stream);
Vinod Koulc78fe9c2011-09-02 11:36:23 +0530149
150#endif