1
2
3
4
5
6
7
8#ifndef __SOC_COMPONENT_H
9#define __SOC_COMPONENT_H
10
11#include <sound/soc.h>
12
13
14
15
16
17#define SND_SOC_COMP_ORDER_FIRST -2
18#define SND_SOC_COMP_ORDER_EARLY -1
19#define SND_SOC_COMP_ORDER_NORMAL 0
20#define SND_SOC_COMP_ORDER_LATE 1
21#define SND_SOC_COMP_ORDER_LAST 2
22
23#define for_each_comp_order(order) \
24 for (order = SND_SOC_COMP_ORDER_FIRST; \
25 order <= SND_SOC_COMP_ORDER_LAST; \
26 order++)
27
28
29struct snd_compress_ops {
30 int (*open)(struct snd_soc_component *component,
31 struct snd_compr_stream *stream);
32 int (*free)(struct snd_soc_component *component,
33 struct snd_compr_stream *stream);
34 int (*set_params)(struct snd_soc_component *component,
35 struct snd_compr_stream *stream,
36 struct snd_compr_params *params);
37 int (*get_params)(struct snd_soc_component *component,
38 struct snd_compr_stream *stream,
39 struct snd_codec *params);
40 int (*set_metadata)(struct snd_soc_component *component,
41 struct snd_compr_stream *stream,
42 struct snd_compr_metadata *metadata);
43 int (*get_metadata)(struct snd_soc_component *component,
44 struct snd_compr_stream *stream,
45 struct snd_compr_metadata *metadata);
46 int (*trigger)(struct snd_soc_component *component,
47 struct snd_compr_stream *stream, int cmd);
48 int (*pointer)(struct snd_soc_component *component,
49 struct snd_compr_stream *stream,
50 struct snd_compr_tstamp *tstamp);
51 int (*copy)(struct snd_soc_component *component,
52 struct snd_compr_stream *stream, char __user *buf,
53 size_t count);
54 int (*mmap)(struct snd_soc_component *component,
55 struct snd_compr_stream *stream,
56 struct vm_area_struct *vma);
57 int (*ack)(struct snd_soc_component *component,
58 struct snd_compr_stream *stream, size_t bytes);
59 int (*get_caps)(struct snd_soc_component *component,
60 struct snd_compr_stream *stream,
61 struct snd_compr_caps *caps);
62 int (*get_codec_caps)(struct snd_soc_component *component,
63 struct snd_compr_stream *stream,
64 struct snd_compr_codec_caps *codec);
65};
66
67struct snd_soc_component_driver {
68 const char *name;
69
70
71 const struct snd_kcontrol_new *controls;
72 unsigned int num_controls;
73 const struct snd_soc_dapm_widget *dapm_widgets;
74 unsigned int num_dapm_widgets;
75 const struct snd_soc_dapm_route *dapm_routes;
76 unsigned int num_dapm_routes;
77
78 int (*probe)(struct snd_soc_component *component);
79 void (*remove)(struct snd_soc_component *component);
80 int (*suspend)(struct snd_soc_component *component);
81 int (*resume)(struct snd_soc_component *component);
82
83 unsigned int (*read)(struct snd_soc_component *component,
84 unsigned int reg);
85 int (*write)(struct snd_soc_component *component,
86 unsigned int reg, unsigned int val);
87
88
89 int (*pcm_construct)(struct snd_soc_component *component,
90 struct snd_soc_pcm_runtime *rtd);
91 void (*pcm_destruct)(struct snd_soc_component *component,
92 struct snd_pcm *pcm);
93
94
95 int (*set_sysclk)(struct snd_soc_component *component,
96 int clk_id, int source, unsigned int freq, int dir);
97 int (*set_pll)(struct snd_soc_component *component, int pll_id,
98 int source, unsigned int freq_in, unsigned int freq_out);
99 int (*set_jack)(struct snd_soc_component *component,
100 struct snd_soc_jack *jack, void *data);
101
102
103 int (*of_xlate_dai_name)(struct snd_soc_component *component,
104 struct of_phandle_args *args,
105 const char **dai_name);
106 int (*of_xlate_dai_id)(struct snd_soc_component *comment,
107 struct device_node *endpoint);
108 void (*seq_notifier)(struct snd_soc_component *component,
109 enum snd_soc_dapm_type type, int subseq);
110 int (*stream_event)(struct snd_soc_component *component, int event);
111 int (*set_bias_level)(struct snd_soc_component *component,
112 enum snd_soc_bias_level level);
113
114 int (*open)(struct snd_soc_component *component,
115 struct snd_pcm_substream *substream);
116 int (*close)(struct snd_soc_component *component,
117 struct snd_pcm_substream *substream);
118 int (*ioctl)(struct snd_soc_component *component,
119 struct snd_pcm_substream *substream,
120 unsigned int cmd, void *arg);
121 int (*hw_params)(struct snd_soc_component *component,
122 struct snd_pcm_substream *substream,
123 struct snd_pcm_hw_params *params);
124 int (*hw_free)(struct snd_soc_component *component,
125 struct snd_pcm_substream *substream);
126 int (*prepare)(struct snd_soc_component *component,
127 struct snd_pcm_substream *substream);
128 int (*trigger)(struct snd_soc_component *component,
129 struct snd_pcm_substream *substream, int cmd);
130 int (*sync_stop)(struct snd_soc_component *component,
131 struct snd_pcm_substream *substream);
132 snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
133 struct snd_pcm_substream *substream);
134 int (*get_time_info)(struct snd_soc_component *component,
135 struct snd_pcm_substream *substream, struct timespec64 *system_ts,
136 struct timespec64 *audio_ts,
137 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
138 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
139 int (*copy_user)(struct snd_soc_component *component,
140 struct snd_pcm_substream *substream, int channel,
141 unsigned long pos, void __user *buf,
142 unsigned long bytes);
143 struct page *(*page)(struct snd_soc_component *component,
144 struct snd_pcm_substream *substream,
145 unsigned long offset);
146 int (*mmap)(struct snd_soc_component *component,
147 struct snd_pcm_substream *substream,
148 struct vm_area_struct *vma);
149
150 const struct snd_compress_ops *compress_ops;
151
152
153 int probe_order;
154 int remove_order;
155
156
157
158
159
160
161
162 unsigned int module_get_upon_open:1;
163
164
165 unsigned int idle_bias_on:1;
166 unsigned int suspend_bias_off:1;
167 unsigned int use_pmdown_time:1;
168 unsigned int endianness:1;
169 unsigned int non_legacy_dai_naming:1;
170
171
172 const char *ignore_machine;
173 const char *topology_name_prefix;
174 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
175 struct snd_pcm_hw_params *params);
176 bool use_dai_pcm_id;
177 int be_pcm_base;
178};
179
180struct snd_soc_component {
181 const char *name;
182 int id;
183 const char *name_prefix;
184 struct device *dev;
185 struct snd_soc_card *card;
186
187 unsigned int active;
188
189 unsigned int suspended:1;
190
191 struct list_head list;
192 struct list_head card_aux_list;
193 struct list_head card_list;
194
195 const struct snd_soc_component_driver *driver;
196
197 struct list_head dai_list;
198 int num_dai;
199
200 struct regmap *regmap;
201 int val_bytes;
202
203 struct mutex io_mutex;
204
205
206 struct list_head dobj_list;
207
208
209
210
211
212
213
214
215 struct snd_soc_dapm_context dapm;
216
217
218 int (*init)(struct snd_soc_component *component);
219
220#ifdef CONFIG_DEBUG_FS
221 struct dentry *debugfs_root;
222 const char *debugfs_prefix;
223#endif
224};
225
226#define for_each_component_dais(component, dai)\
227 list_for_each_entry(dai, &(component)->dai_list, list)
228#define for_each_component_dais_safe(component, dai, _dai)\
229 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
230
231
232
233
234
235
236
237
238
239
240static inline struct snd_soc_component *snd_soc_dapm_to_component(
241 struct snd_soc_dapm_context *dapm)
242{
243 return container_of(dapm, struct snd_soc_component, dapm);
244}
245
246
247
248
249
250
251static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
252 struct snd_soc_component *component)
253{
254 return &component->dapm;
255}
256
257
258
259
260
261
262
263
264static inline void
265snd_soc_component_init_bias_level(struct snd_soc_component *component,
266 enum snd_soc_bias_level level)
267{
268 snd_soc_dapm_init_bias_level(
269 snd_soc_component_get_dapm(component), level);
270}
271
272
273
274
275
276
277
278static inline enum snd_soc_bias_level
279snd_soc_component_get_bias_level(struct snd_soc_component *component)
280{
281 return snd_soc_dapm_get_bias_level(
282 snd_soc_component_get_dapm(component));
283}
284
285
286
287
288
289
290
291
292
293static inline int
294snd_soc_component_force_bias_level(struct snd_soc_component *component,
295 enum snd_soc_bias_level level)
296{
297 return snd_soc_dapm_force_bias_level(
298 snd_soc_component_get_dapm(component),
299 level);
300}
301
302
303
304
305
306
307
308
309
310static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
311 struct snd_kcontrol *kcontrol)
312{
313 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
314}
315
316
317
318
319
320
321
322static inline int snd_soc_component_cache_sync(
323 struct snd_soc_component *component)
324{
325 return regcache_sync(component->regmap);
326}
327
328void snd_soc_component_set_aux(struct snd_soc_component *component,
329 struct snd_soc_aux_dev *aux);
330int snd_soc_component_init(struct snd_soc_component *component);
331
332
333unsigned int snd_soc_component_read(struct snd_soc_component *component,
334 unsigned int reg);
335int snd_soc_component_write(struct snd_soc_component *component,
336 unsigned int reg, unsigned int val);
337int snd_soc_component_update_bits(struct snd_soc_component *component,
338 unsigned int reg, unsigned int mask,
339 unsigned int val);
340int snd_soc_component_update_bits_async(struct snd_soc_component *component,
341 unsigned int reg, unsigned int mask,
342 unsigned int val);
343void snd_soc_component_async_complete(struct snd_soc_component *component);
344int snd_soc_component_test_bits(struct snd_soc_component *component,
345 unsigned int reg, unsigned int mask,
346 unsigned int value);
347
348
349int snd_soc_component_set_sysclk(struct snd_soc_component *component,
350 int clk_id, int source,
351 unsigned int freq, int dir);
352int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
353 int source, unsigned int freq_in,
354 unsigned int freq_out);
355int snd_soc_component_set_jack(struct snd_soc_component *component,
356 struct snd_soc_jack *jack, void *data);
357
358void snd_soc_component_seq_notifier(struct snd_soc_component *component,
359 enum snd_soc_dapm_type type, int subseq);
360int snd_soc_component_stream_event(struct snd_soc_component *component,
361 int event);
362int snd_soc_component_set_bias_level(struct snd_soc_component *component,
363 enum snd_soc_bias_level level);
364
365void snd_soc_component_setup_regmap(struct snd_soc_component *component);
366#ifdef CONFIG_REGMAP
367void snd_soc_component_init_regmap(struct snd_soc_component *component,
368 struct regmap *regmap);
369void snd_soc_component_exit_regmap(struct snd_soc_component *component);
370#endif
371
372#define snd_soc_component_module_get_when_probe(component)\
373 snd_soc_component_module_get(component, 0)
374#define snd_soc_component_module_get_when_open(component) \
375 snd_soc_component_module_get(component, 1)
376int snd_soc_component_module_get(struct snd_soc_component *component,
377 int upon_open);
378#define snd_soc_component_module_put_when_remove(component) \
379 snd_soc_component_module_put(component, 0)
380#define snd_soc_component_module_put_when_close(component) \
381 snd_soc_component_module_put(component, 1)
382void snd_soc_component_module_put(struct snd_soc_component *component,
383 int upon_open);
384
385static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
386 void *data)
387{
388 dev_set_drvdata(c->dev, data);
389}
390
391static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
392{
393 return dev_get_drvdata(c->dev);
394}
395
396static inline unsigned int
397snd_soc_component_active(struct snd_soc_component *component)
398{
399 return component->active;
400}
401
402
403int snd_soc_component_enable_pin(struct snd_soc_component *component,
404 const char *pin);
405int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
406 const char *pin);
407int snd_soc_component_disable_pin(struct snd_soc_component *component,
408 const char *pin);
409int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
410 const char *pin);
411int snd_soc_component_nc_pin(struct snd_soc_component *component,
412 const char *pin);
413int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
414 const char *pin);
415int snd_soc_component_get_pin_status(struct snd_soc_component *component,
416 const char *pin);
417int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
418 const char *pin);
419int snd_soc_component_force_enable_pin_unlocked(
420 struct snd_soc_component *component,
421 const char *pin);
422
423
424int snd_soc_component_open(struct snd_soc_component *component,
425 struct snd_pcm_substream *substream);
426int snd_soc_component_close(struct snd_soc_component *component,
427 struct snd_pcm_substream *substream);
428void snd_soc_component_suspend(struct snd_soc_component *component);
429void snd_soc_component_resume(struct snd_soc_component *component);
430int snd_soc_component_is_suspended(struct snd_soc_component *component);
431int snd_soc_component_probe(struct snd_soc_component *component);
432void snd_soc_component_remove(struct snd_soc_component *component);
433int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
434 struct device_node *ep);
435int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
436 struct of_phandle_args *args,
437 const char **dai_name);
438
439int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
440int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
441 unsigned int cmd, void *arg);
442int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
443int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
444 int channel, unsigned long pos,
445 void __user *buf, unsigned long bytes);
446struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
447 unsigned long offset);
448int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
449 struct vm_area_struct *vma);
450int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
451void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
452int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
453int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
454 struct snd_pcm_hw_params *params,
455 struct snd_soc_component **last);
456void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
457 struct snd_soc_component *last);
458int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
459 int cmd);
460
461#endif
462