Blame view

include/sound/compress_driver.h 6.41 KB
b3ed4c86a   Kuninori Morimoto   ASoC: soc-compres...
1
2
  /* SPDX-License-Identifier: GPL-2.0
   *
e60061a37   Vinod Koul   ALSA: core: add A...
3
4
5
6
7
   *  compress_driver.h - compress offload driver definations
   *
   *  Copyright (C) 2011 Intel Corporation
   *  Authors:	Vinod Koul <vinod.koul@linux.intel.com>
   *		Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
e60061a37   Vinod Koul   ALSA: core: add A...
8
   */
b3ed4c86a   Kuninori Morimoto   ASoC: soc-compres...
9

e60061a37   Vinod Koul   ALSA: core: add A...
10
11
12
13
14
  #ifndef __COMPRESS_DRIVER_H
  #define __COMPRESS_DRIVER_H
  
  #include <linux/types.h>
  #include <linux/sched.h>
7b617289b   Qais Yousef   ALSA: compress_dr...
15
  #include <sound/core.h>
e60061a37   Vinod Koul   ALSA: core: add A...
16
17
18
19
20
21
22
23
24
25
  #include <sound/compress_offload.h>
  #include <sound/asound.h>
  #include <sound/pcm.h>
  
  struct snd_compr_ops;
  
  /**
   * struct snd_compr_runtime: runtime stream description
   * @state: stream state
   * @ops: pointer to DSP callbacks
ba02eed9f   Srinivas Kandagatla   ALSA: soc-compres...
26
   * @dma_buffer_p: runtime dma buffer pointer
e60061a37   Vinod Koul   ALSA: core: add A...
27
28
29
30
31
   * @buffer: pointer to kernel buffer, valid only when not in mmap mode or
   *	DSP doesn't implement copy
   * @buffer_size: size of the above buffer
   * @fragment_size: size of buffer fragment in bytes
   * @fragments: number of such fragments
e60061a37   Vinod Koul   ALSA: core: add A...
32
33
34
35
   * @total_bytes_available: cumulative number of bytes made available in
   *	the ring buffer
   * @total_bytes_transferred: cumulative bytes transferred by offload DSP
   * @sleep: poll sleep
859b2e374   Vinod Koul   ALSA: compress: f...
36
   * @private_data: driver private data pointer
e60061a37   Vinod Koul   ALSA: core: add A...
37
38
39
40
   */
  struct snd_compr_runtime {
  	snd_pcm_state_t state;
  	struct snd_compr_ops *ops;
ba02eed9f   Srinivas Kandagatla   ALSA: soc-compres...
41
  	struct snd_dma_buffer *dma_buffer_p;
e60061a37   Vinod Koul   ALSA: core: add A...
42
43
44
45
  	void *buffer;
  	u64 buffer_size;
  	u32 fragment_size;
  	u32 fragments;
e60061a37   Vinod Koul   ALSA: core: add A...
46
47
48
  	u64 total_bytes_available;
  	u64 total_bytes_transferred;
  	wait_queue_head_t sleep;
496810778   Vinod Koul   ASoC: add definat...
49
  	void *private_data;
e60061a37   Vinod Koul   ALSA: core: add A...
50
51
52
53
54
55
56
57
  };
  
  /**
   * struct snd_compr_stream: compressed stream
   * @name: device name
   * @ops: pointer to DSP callbacks
   * @runtime: pointer to runtime structure
   * @device: device pointer
a4f2d87c6   Charles Keepax   ALSA: compress: A...
58
   * @error_work: delayed work used when closing the stream due to an error
e60061a37   Vinod Koul   ALSA: core: add A...
59
   * @direction: stream direction, playback/recording
9727b490e   Jeeja KP   ALSA: compress: a...
60
   * @metadata_set: metadata set flag, true when set
1a6ab46fa   Masanari Iida   ALSA: Fix spellin...
61
   * @next_track: has userspace signal next track transition, true when set
e60061a37   Vinod Koul   ALSA: core: add A...
62
63
64
65
66
67
68
   * @private_data: pointer to DSP private data
   */
  struct snd_compr_stream {
  	const char *name;
  	struct snd_compr_ops *ops;
  	struct snd_compr_runtime *runtime;
  	struct snd_compr *device;
a4f2d87c6   Charles Keepax   ALSA: compress: A...
69
  	struct delayed_work error_work;
e60061a37   Vinod Koul   ALSA: core: add A...
70
  	enum snd_compr_direction direction;
9727b490e   Jeeja KP   ALSA: compress: a...
71
72
  	bool metadata_set;
  	bool next_track;
e60061a37   Vinod Koul   ALSA: core: add A...
73
74
75
76
77
78
79
80
81
82
83
84
85
  	void *private_data;
  };
  
  /**
   * struct snd_compr_ops: compressed path DSP operations
   * @open: Open the compressed stream
   * This callback is mandatory and shall keep dsp ready to receive the stream
   * parameter
   * @free: Close the compressed stream, mandatory
   * @set_params: Sets the compressed stream parameters, mandatory
   * This can be called in during stream creation only to set codec params
   * and the stream properties
   * @get_params: retrieve the codec parameters, mandatory
859b2e374   Vinod Koul   ALSA: compress: f...
86
   * @set_metadata: Set the metadata values for a stream
1a6ab46fa   Masanari Iida   ALSA: Fix spellin...
87
   * @get_metadata: retrieves the requested metadata values from stream
e60061a37   Vinod Koul   ALSA: core: add A...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
   * @trigger: Trigger operations like start, pause, resume, drain, stop.
   * This callback is mandatory
   * @pointer: Retrieve current h/w pointer information. Mandatory
   * @copy: Copy the compressed data to/from userspace, Optional
   * Can't be implemented if DSP supports mmap
   * @mmap: DSP mmap method to mmap DSP memory
   * @ack: Ack for DSP when data is written to audio buffer, Optional
   * Not valid if copy is implemented
   * @get_caps: Retrieve DSP capabilities, mandatory
   * @get_codec_caps: Retrieve capabilities for a specific codec, mandatory
   */
  struct snd_compr_ops {
  	int (*open)(struct snd_compr_stream *stream);
  	int (*free)(struct snd_compr_stream *stream);
  	int (*set_params)(struct snd_compr_stream *stream,
  			struct snd_compr_params *params);
  	int (*get_params)(struct snd_compr_stream *stream,
  			struct snd_codec *params);
9727b490e   Jeeja KP   ALSA: compress: a...
106
107
108
109
  	int (*set_metadata)(struct snd_compr_stream *stream,
  			struct snd_compr_metadata *metadata);
  	int (*get_metadata)(struct snd_compr_stream *stream,
  			struct snd_compr_metadata *metadata);
e60061a37   Vinod Koul   ALSA: core: add A...
110
111
112
  	int (*trigger)(struct snd_compr_stream *stream, int cmd);
  	int (*pointer)(struct snd_compr_stream *stream,
  			struct snd_compr_tstamp *tstamp);
4daf891cd   Charles Keepax   ALSA: compress_co...
113
  	int (*copy)(struct snd_compr_stream *stream, char __user *buf,
e60061a37   Vinod Koul   ALSA: core: add A...
114
115
116
117
118
119
120
121
122
123
124
125
126
  		       size_t count);
  	int (*mmap)(struct snd_compr_stream *stream,
  			struct vm_area_struct *vma);
  	int (*ack)(struct snd_compr_stream *stream, size_t bytes);
  	int (*get_caps) (struct snd_compr_stream *stream,
  			struct snd_compr_caps *caps);
  	int (*get_codec_caps) (struct snd_compr_stream *stream,
  			struct snd_compr_codec_caps *codec);
  };
  
  /**
   * struct snd_compr: Compressed device
   * @name: DSP device name
04c5d5a43   Takashi Iwai   ALSA: compress: E...
127
   * @dev: associated device instance
e60061a37   Vinod Koul   ALSA: core: add A...
128
129
130
131
132
133
134
135
136
   * @ops: pointer to DSP callbacks
   * @private_data: pointer to DSP pvt data
   * @card: sound card pointer
   * @direction: Playback or capture direction
   * @lock: device lock
   * @device: device id
   */
  struct snd_compr {
  	const char *name;
04c5d5a43   Takashi Iwai   ALSA: compress: E...
137
  	struct device dev;
e60061a37   Vinod Koul   ALSA: core: add A...
138
139
140
141
142
143
  	struct snd_compr_ops *ops;
  	void *private_data;
  	struct snd_card *card;
  	unsigned int direction;
  	struct mutex lock;
  	int device;
317427247   Richard Fitzgerald   ALSA: compress: A...
144
  #ifdef CONFIG_SND_VERBOSE_PROCFS
f84551e45   Takashi Iwai   ALSA: compress: F...
145
  	/* private: */
317427247   Richard Fitzgerald   ALSA: compress: A...
146
147
148
149
  	char id[64];
  	struct snd_info_entry *proc_root;
  	struct snd_info_entry *proc_info_entry;
  #endif
e60061a37   Vinod Koul   ALSA: core: add A...
150
151
152
153
154
155
  };
  
  /* compress device register APIs */
  int snd_compress_register(struct snd_compr *device);
  int snd_compress_deregister(struct snd_compr *device);
  int snd_compress_new(struct snd_card *card, int device,
e5241a8c4   Richard Fitzgerald   ALSA: compress: P...
156
  			int type, const char *id, struct snd_compr *compr);
e60061a37   Vinod Koul   ALSA: core: add A...
157
158
159
160
161
162
163
164
165
166
167
168
169
  
  /* dsp driver callback apis
   * For playback: driver should call snd_compress_fragment_elapsed() to let the
   * framework know that a fragment has been consumed from the ring buffer
   *
   * For recording: we want to know when a frame is available or when
   * at least one frame is available so snd_compress_frame_elapsed()
   * callback should be called when a encodeded frame is available
   */
  static inline void snd_compr_fragment_elapsed(struct snd_compr_stream *stream)
  {
  	wake_up(&stream->runtime->sleep);
  }
917f4b5cb   Vinod Koul   ALSA: compress: f...
170
171
  static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
  {
f44f2a541   Vinod Koul   ALSA: compress: f...
172
173
  	if (snd_BUG_ON(!stream))
  		return;
917f4b5cb   Vinod Koul   ALSA: compress: f...
174

4475f8c4a   Charles Keepax   ALSA: compress: F...
175
  	stream->runtime->state = SNDRV_PCM_STATE_SETUP;
4f2ab5e1d   Charles Keepax   ALSA: compress: F...
176

f44f2a541   Vinod Koul   ALSA: compress: f...
177
  	wake_up(&stream->runtime->sleep);
917f4b5cb   Vinod Koul   ALSA: compress: f...
178
  }
ba02eed9f   Srinivas Kandagatla   ALSA: soc-compres...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  /**
   * snd_compr_set_runtime_buffer - Set the Compress runtime buffer
   * @substream: compress substream to set
   * @bufp: the buffer information, NULL to clear
   *
   * Copy the buffer information to runtime buffer when @bufp is non-NULL.
   * Otherwise it clears the current buffer information.
   */
  static inline void snd_compr_set_runtime_buffer(
  					struct snd_compr_stream *substream,
  					struct snd_dma_buffer *bufp)
  {
  	struct snd_compr_runtime *runtime = substream->runtime;
  
  	runtime->dma_buffer_p = bufp;
  }
a4f2d87c6   Charles Keepax   ALSA: compress: A...
195
196
  int snd_compr_stop_error(struct snd_compr_stream *stream,
  			 snd_pcm_state_t state);
e60061a37   Vinod Koul   ALSA: core: add A...
197
  #endif