Merge tag 'perf-tools-for-v6.4-3-2023-05-06' of git://git.kernel.org/pub/scm/linux...
[linux-block.git] / include / sound / soc-component.h
CommitLineData
4ff1fef1
KM
1/* SPDX-License-Identifier: GPL-2.0
2 *
3 * soc-component.h
4 *
45108214
KM
5 * Copyright (C) 2019 Renesas Electronics Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
4ff1fef1
KM
7 */
8#ifndef __SOC_COMPONENT_H
9#define __SOC_COMPONENT_H
10
11#include <sound/soc.h>
12
13/*
14 * Component probe and remove ordering levels for components with runtime
15 * dependencies.
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/* component interface */
c6cb522c
KM
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
4ff1fef1
KM
67struct snd_soc_component_driver {
68 const char *name;
69
70 /* Default control and setup, added after probe() is run */
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 /* pcm creation and destruction */
c64bfc90
KM
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
4ff1fef1
KM
94 /* component wide operations */
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);
df55122b 101 int (*get_jack_type)(struct snd_soc_component *component);
4ff1fef1
KM
102
103 /* DT */
104 int (*of_xlate_dai_name)(struct snd_soc_component *component,
933f98be 105 const struct of_phandle_args *args,
4ff1fef1
KM
106 const char **dai_name);
107 int (*of_xlate_dai_id)(struct snd_soc_component *comment,
108 struct device_node *endpoint);
109 void (*seq_notifier)(struct snd_soc_component *component,
110 enum snd_soc_dapm_type type, int subseq);
111 int (*stream_event)(struct snd_soc_component *component, int event);
112 int (*set_bias_level)(struct snd_soc_component *component,
113 enum snd_soc_bias_level level);
114
e2cb4a14
KM
115 int (*open)(struct snd_soc_component *component,
116 struct snd_pcm_substream *substream);
117 int (*close)(struct snd_soc_component *component,
118 struct snd_pcm_substream *substream);
119 int (*ioctl)(struct snd_soc_component *component,
120 struct snd_pcm_substream *substream,
121 unsigned int cmd, void *arg);
122 int (*hw_params)(struct snd_soc_component *component,
123 struct snd_pcm_substream *substream,
124 struct snd_pcm_hw_params *params);
125 int (*hw_free)(struct snd_soc_component *component,
126 struct snd_pcm_substream *substream);
127 int (*prepare)(struct snd_soc_component *component,
128 struct snd_pcm_substream *substream);
129 int (*trigger)(struct snd_soc_component *component,
130 struct snd_pcm_substream *substream, int cmd);
1e5ddb6b
TI
131 int (*sync_stop)(struct snd_soc_component *component,
132 struct snd_pcm_substream *substream);
e2cb4a14
KM
133 snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
134 struct snd_pcm_substream *substream);
135 int (*get_time_info)(struct snd_soc_component *component,
fcae40c9
BW
136 struct snd_pcm_substream *substream, struct timespec64 *system_ts,
137 struct timespec64 *audio_ts,
e2cb4a14
KM
138 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
139 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
140 int (*copy_user)(struct snd_soc_component *component,
141 struct snd_pcm_substream *substream, int channel,
142 unsigned long pos, void __user *buf,
143 unsigned long bytes);
144 struct page *(*page)(struct snd_soc_component *component,
145 struct snd_pcm_substream *substream,
146 unsigned long offset);
147 int (*mmap)(struct snd_soc_component *component,
148 struct snd_pcm_substream *substream,
149 struct vm_area_struct *vma);
8bdfc045
SW
150 int (*ack)(struct snd_soc_component *component,
151 struct snd_pcm_substream *substream);
403f830e
KM
152 snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
153 struct snd_pcm_substream *substream);
e2cb4a14 154
c6cb522c 155 const struct snd_compress_ops *compress_ops;
4ff1fef1
KM
156
157 /* probe ordering - for components with runtime dependencies */
158 int probe_order;
159 int remove_order;
160
161 /*
162 * signal if the module handling the component should not be removed
163 * if a pcm is open. Setting this would prevent the module
164 * refcount being incremented in probe() but allow it be incremented
165 * when a pcm is opened and decremented when it is closed.
166 */
167 unsigned int module_get_upon_open:1;
168
169 /* bits */
170 unsigned int idle_bias_on:1;
171 unsigned int suspend_bias_off:1;
172 unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
5c832efd
CK
173 /*
174 * Indicates that the component does not care about the endianness of
175 * PCM audio data and the core will ensure that both LE and BE variants
176 * of each used format are present. Typically this is because the
177 * component sits behind a bus that abstracts away the endian of the
178 * original data, ie. one for which the transmission endian is defined
179 * (I2S/SLIMbus/SoundWire), or the concept of endian doesn't exist (PDM,
180 * analogue).
181 */
4ff1fef1 182 unsigned int endianness:1;
1c348f74 183 unsigned int legacy_dai_naming:1;
4ff1fef1
KM
184
185 /* this component uses topology and ignore machine driver FEs */
186 const char *ignore_machine;
187 const char *topology_name_prefix;
188 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
189 struct snd_pcm_hw_params *params);
190 bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */
191 int be_pcm_base; /* base device ID for all BE PCMs */
d462f6ed 192
54fc4b72
CB
193 unsigned int start_dma_last;
194
d462f6ed
HK
195#ifdef CONFIG_DEBUG_FS
196 const char *debugfs_prefix;
197#endif
4ff1fef1
KM
198};
199
200struct snd_soc_component {
201 const char *name;
202 int id;
203 const char *name_prefix;
204 struct device *dev;
205 struct snd_soc_card *card;
206
207 unsigned int active;
208
209 unsigned int suspended:1; /* is in suspend PM state */
210
211 struct list_head list;
212 struct list_head card_aux_list; /* for auxiliary bound components */
213 struct list_head card_list;
214
215 const struct snd_soc_component_driver *driver;
216
217 struct list_head dai_list;
218 int num_dai;
219
220 struct regmap *regmap;
221 int val_bytes;
222
223 struct mutex io_mutex;
224
225 /* attached dynamic objects */
226 struct list_head dobj_list;
227
228 /*
229 * DO NOT use any of the fields below in drivers, they are temporary and
230 * are going to be removed again soon. If you use them in driver code
231 * the driver will be marked as BROKEN when these fields are removed.
232 */
233
234 /* Don't use these, use snd_soc_component_get_dapm() */
235 struct snd_soc_dapm_context dapm;
236
237 /* machine specific init */
238 int (*init)(struct snd_soc_component *component);
239
51aff91a 240 /* function mark */
a739fdc2 241 void *mark_module;
51aff91a 242 struct snd_pcm_substream *mark_open;
3a36a64a 243 struct snd_pcm_substream *mark_hw_params;
6374f493 244 struct snd_pcm_substream *mark_trigger;
f94ba9ac 245 struct snd_compr_stream *mark_compr_open;
939a5cfb 246 void *mark_pm;
51aff91a 247
4ff1fef1
KM
248 struct dentry *debugfs_root;
249 const char *debugfs_prefix;
4ff1fef1
KM
250};
251
252#define for_each_component_dais(component, dai)\
253 list_for_each_entry(dai, &(component)->dai_list, list)
254#define for_each_component_dais_safe(component, dai, _dai)\
255 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
256
257/**
258 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
259 * embedded in
260 * @dapm: The DAPM context to cast to the component
261 *
262 * This function must only be used on DAPM contexts that are known to be part of
263 * a component (e.g. in a component driver). Otherwise the behavior is
264 * undefined.
265 */
266static inline struct snd_soc_component *snd_soc_dapm_to_component(
267 struct snd_soc_dapm_context *dapm)
268{
269 return container_of(dapm, struct snd_soc_component, dapm);
270}
271
272/**
273 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
274 * component
275 * @component: The component for which to get the DAPM context
276 */
277static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
278 struct snd_soc_component *component)
279{
280 return &component->dapm;
281}
282
283/**
284 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
285 * @component: The COMPONENT for which to initialize the DAPM bias level
286 * @level: The DAPM level to initialize to
287 *
288 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
289 */
290static inline void
291snd_soc_component_init_bias_level(struct snd_soc_component *component,
292 enum snd_soc_bias_level level)
293{
294 snd_soc_dapm_init_bias_level(
295 snd_soc_component_get_dapm(component), level);
296}
297
298/**
299 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
300 * @component: The COMPONENT for which to get the DAPM bias level
301 *
302 * Returns: The current DAPM bias level of the COMPONENT.
303 */
304static inline enum snd_soc_bias_level
305snd_soc_component_get_bias_level(struct snd_soc_component *component)
306{
307 return snd_soc_dapm_get_bias_level(
308 snd_soc_component_get_dapm(component));
309}
310
311/**
312 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
313 * @component: The COMPONENT for which to set the level
314 * @level: The level to set to
315 *
316 * Forces the COMPONENT bias level to a specific state. See
317 * snd_soc_dapm_force_bias_level().
318 */
319static inline int
320snd_soc_component_force_bias_level(struct snd_soc_component *component,
321 enum snd_soc_bias_level level)
322{
323 return snd_soc_dapm_force_bias_level(
324 snd_soc_component_get_dapm(component),
325 level);
326}
327
328/**
329 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
330 * kcontrol
331 * @kcontrol: The kcontrol
332 *
333 * This function must only be used on DAPM contexts that are known to be part of
334 * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
335 */
336static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
337 struct snd_kcontrol *kcontrol)
338{
339 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
340}
341
342/**
343 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
344 * @component: COMPONENT to sync
345 *
346 * Note: This function will call regcache_sync()
347 */
348static inline int snd_soc_component_cache_sync(
349 struct snd_soc_component *component)
350{
351 return regcache_sync(component->regmap);
352}
353
257c4dac
KM
354void snd_soc_component_set_aux(struct snd_soc_component *component,
355 struct snd_soc_aux_dev *aux);
356int snd_soc_component_init(struct snd_soc_component *component);
8f1a1681 357int snd_soc_component_is_dummy(struct snd_soc_component *component);
536aba1d 358
4ff1fef1 359/* component IO */
cf6e26c7 360unsigned int snd_soc_component_read(struct snd_soc_component *component,
4ff1fef1
KM
361 unsigned int reg);
362int snd_soc_component_write(struct snd_soc_component *component,
363 unsigned int reg, unsigned int val);
364int snd_soc_component_update_bits(struct snd_soc_component *component,
365 unsigned int reg, unsigned int mask,
366 unsigned int val);
367int snd_soc_component_update_bits_async(struct snd_soc_component *component,
368 unsigned int reg, unsigned int mask,
369 unsigned int val);
370void snd_soc_component_async_complete(struct snd_soc_component *component);
371int snd_soc_component_test_bits(struct snd_soc_component *component,
372 unsigned int reg, unsigned int mask,
373 unsigned int value);
374
1da0b989
SK
375unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
376 unsigned int reg, unsigned int mask);
377int snd_soc_component_write_field(struct snd_soc_component *component,
378 unsigned int reg, unsigned int mask,
379 unsigned int val);
380
4ff1fef1
KM
381/* component wide operations */
382int snd_soc_component_set_sysclk(struct snd_soc_component *component,
383 int clk_id, int source,
384 unsigned int freq, int dir);
385int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
386 int source, unsigned int freq_in,
387 unsigned int freq_out);
388int snd_soc_component_set_jack(struct snd_soc_component *component,
389 struct snd_soc_jack *jack, void *data);
df55122b 390int snd_soc_component_get_jack_type(struct snd_soc_component *component);
4ff1fef1 391
9d415fbf
KM
392void snd_soc_component_seq_notifier(struct snd_soc_component *component,
393 enum snd_soc_dapm_type type, int subseq);
8e2a990d
KM
394int snd_soc_component_stream_event(struct snd_soc_component *component,
395 int event);
7951b146
KM
396int snd_soc_component_set_bias_level(struct snd_soc_component *component,
397 enum snd_soc_bias_level level);
9d415fbf 398
c7d75b59 399void snd_soc_component_setup_regmap(struct snd_soc_component *component);
4ff1fef1
KM
400#ifdef CONFIG_REGMAP
401void snd_soc_component_init_regmap(struct snd_soc_component *component,
402 struct regmap *regmap);
403void snd_soc_component_exit_regmap(struct snd_soc_component *component);
404#endif
405
4a81e8f3 406#define snd_soc_component_module_get_when_probe(component)\
51aff91a
KM
407 snd_soc_component_module_get(component, NULL, 0)
408#define snd_soc_component_module_get_when_open(component, substream) \
409 snd_soc_component_module_get(component, substream, 1)
4a81e8f3 410int snd_soc_component_module_get(struct snd_soc_component *component,
a739fdc2 411 void *mark, int upon_open);
4a81e8f3 412#define snd_soc_component_module_put_when_remove(component) \
51aff91a
KM
413 snd_soc_component_module_put(component, NULL, 0, 0)
414#define snd_soc_component_module_put_when_close(component, substream, rollback) \
415 snd_soc_component_module_put(component, substream, 1, rollback)
4a81e8f3 416void snd_soc_component_module_put(struct snd_soc_component *component,
a739fdc2 417 void *mark, int upon_open, int rollback);
4a81e8f3 418
4ff1fef1
KM
419static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
420 void *data)
421{
422 dev_set_drvdata(c->dev, data);
423}
424
425static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
426{
427 return dev_get_drvdata(c->dev);
428}
429
488b2ca5
KM
430static inline unsigned int
431snd_soc_component_active(struct snd_soc_component *component)
432{
433 return component->active;
434}
435
4ff1fef1
KM
436/* component pin */
437int snd_soc_component_enable_pin(struct snd_soc_component *component,
438 const char *pin);
439int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
440 const char *pin);
441int snd_soc_component_disable_pin(struct snd_soc_component *component,
442 const char *pin);
443int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
444 const char *pin);
445int snd_soc_component_nc_pin(struct snd_soc_component *component,
446 const char *pin);
447int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
448 const char *pin);
449int snd_soc_component_get_pin_status(struct snd_soc_component *component,
450 const char *pin);
451int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
452 const char *pin);
453int snd_soc_component_force_enable_pin_unlocked(
454 struct snd_soc_component *component,
455 const char *pin);
456
ae2f4849
KM
457/* component driver ops */
458int snd_soc_component_open(struct snd_soc_component *component,
459 struct snd_pcm_substream *substream);
3672beb8 460int snd_soc_component_close(struct snd_soc_component *component,
51aff91a
KM
461 struct snd_pcm_substream *substream,
462 int rollback);
66c51573 463void snd_soc_component_suspend(struct snd_soc_component *component);
9a840cba 464void snd_soc_component_resume(struct snd_soc_component *component);
e40fadbc 465int snd_soc_component_is_suspended(struct snd_soc_component *component);
08e837dd 466int snd_soc_component_probe(struct snd_soc_component *component);
03b34dd7 467void snd_soc_component_remove(struct snd_soc_component *component);
2c7b1704
KM
468int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
469 struct device_node *ep);
a2a34175 470int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
933f98be 471 const struct of_phandle_args *args,
a2a34175 472 const char **dai_name);
cd46f382
PU
473int snd_soc_component_compr_open(struct snd_soc_component *component,
474 struct snd_compr_stream *cstream);
475void snd_soc_component_compr_free(struct snd_soc_component *component,
476 struct snd_compr_stream *cstream,
f94ba9ac 477 int rollback);
08aee251 478int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
ff08cf80
KM
479int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
480 struct snd_compr_params *params);
77c221ec
KM
481int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
482 struct snd_codec *params);
d67fcb2d
KM
483int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
484 struct snd_compr_caps *caps);
0f6fe097
KM
485int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
486 struct snd_compr_codec_caps *codec);
0506b885 487int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
03ecea64
KM
488int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
489 struct snd_compr_tstamp *tstamp);
b5852e66
KM
490int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
491 char __user *buf, size_t count);
1b308fb1
KM
492int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
493 struct snd_compr_metadata *metadata);
bab78c23
KM
494int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
495 struct snd_compr_metadata *metadata);
ae2f4849 496
0035e256 497int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
96a47908
KM
498int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
499 unsigned int cmd, void *arg);
1e5ddb6b 500int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
82d81f5c
KM
501int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
502 int channel, unsigned long pos,
503 void __user *buf, unsigned long bytes);
9c712e4f
KM
504struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
505 unsigned long offset);
205875e1
KM
506int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
507 struct vm_area_struct *vma);
b2b2afbb
KM
508int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
509void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
4f39514f 510int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
e1bafa82 511int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
3a36a64a 512 struct snd_pcm_hw_params *params);
04751119 513void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
3a36a64a 514 int rollback);
32fd1204 515int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
6374f493 516 int cmd, int rollback);
939a5cfb
KM
517int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
518 void *stream);
519void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
520 void *stream, int rollback);
8bdfc045 521int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream);
403f830e
KM
522void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
523 snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
0035e256 524
4ff1fef1 525#endif /* __SOC_COMPONENT_H */