]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/sound/soc-component.h
Merge branch 'printk-rework' into for-linus
[mirror_ubuntu-jammy-kernel.git] / include / sound / soc-component.h
CommitLineData
4ff1fef1
KM
1/* SPDX-License-Identifier: GPL-2.0
2 *
3 * soc-component.h
4 *
5 * Copyright (c) 2019 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
4ff1fef1
KM
6 */
7#ifndef __SOC_COMPONENT_H
8#define __SOC_COMPONENT_H
9
10#include <sound/soc.h>
11
12/*
13 * Component probe and remove ordering levels for components with runtime
14 * dependencies.
15 */
16#define SND_SOC_COMP_ORDER_FIRST -2
17#define SND_SOC_COMP_ORDER_EARLY -1
18#define SND_SOC_COMP_ORDER_NORMAL 0
19#define SND_SOC_COMP_ORDER_LATE 1
20#define SND_SOC_COMP_ORDER_LAST 2
21
22#define for_each_comp_order(order) \
23 for (order = SND_SOC_COMP_ORDER_FIRST; \
24 order <= SND_SOC_COMP_ORDER_LAST; \
25 order++)
26
27/* component interface */
c6cb522c
KM
28struct snd_compress_ops {
29 int (*open)(struct snd_soc_component *component,
30 struct snd_compr_stream *stream);
31 int (*free)(struct snd_soc_component *component,
32 struct snd_compr_stream *stream);
33 int (*set_params)(struct snd_soc_component *component,
34 struct snd_compr_stream *stream,
35 struct snd_compr_params *params);
36 int (*get_params)(struct snd_soc_component *component,
37 struct snd_compr_stream *stream,
38 struct snd_codec *params);
39 int (*set_metadata)(struct snd_soc_component *component,
40 struct snd_compr_stream *stream,
41 struct snd_compr_metadata *metadata);
42 int (*get_metadata)(struct snd_soc_component *component,
43 struct snd_compr_stream *stream,
44 struct snd_compr_metadata *metadata);
45 int (*trigger)(struct snd_soc_component *component,
46 struct snd_compr_stream *stream, int cmd);
47 int (*pointer)(struct snd_soc_component *component,
48 struct snd_compr_stream *stream,
49 struct snd_compr_tstamp *tstamp);
50 int (*copy)(struct snd_soc_component *component,
51 struct snd_compr_stream *stream, char __user *buf,
52 size_t count);
53 int (*mmap)(struct snd_soc_component *component,
54 struct snd_compr_stream *stream,
55 struct vm_area_struct *vma);
56 int (*ack)(struct snd_soc_component *component,
57 struct snd_compr_stream *stream, size_t bytes);
58 int (*get_caps)(struct snd_soc_component *component,
59 struct snd_compr_stream *stream,
60 struct snd_compr_caps *caps);
61 int (*get_codec_caps)(struct snd_soc_component *component,
62 struct snd_compr_stream *stream,
63 struct snd_compr_codec_caps *codec);
64};
65
4ff1fef1
KM
66struct snd_soc_component_driver {
67 const char *name;
68
69 /* Default control and setup, added after probe() is run */
70 const struct snd_kcontrol_new *controls;
71 unsigned int num_controls;
72 const struct snd_soc_dapm_widget *dapm_widgets;
73 unsigned int num_dapm_widgets;
74 const struct snd_soc_dapm_route *dapm_routes;
75 unsigned int num_dapm_routes;
76
77 int (*probe)(struct snd_soc_component *component);
78 void (*remove)(struct snd_soc_component *component);
79 int (*suspend)(struct snd_soc_component *component);
80 int (*resume)(struct snd_soc_component *component);
81
82 unsigned int (*read)(struct snd_soc_component *component,
83 unsigned int reg);
84 int (*write)(struct snd_soc_component *component,
85 unsigned int reg, unsigned int val);
86
87 /* pcm creation and destruction */
c64bfc90
KM
88 int (*pcm_construct)(struct snd_soc_component *component,
89 struct snd_soc_pcm_runtime *rtd);
90 void (*pcm_destruct)(struct snd_soc_component *component,
91 struct snd_pcm *pcm);
92
4ff1fef1
KM
93 /* component wide operations */
94 int (*set_sysclk)(struct snd_soc_component *component,
95 int clk_id, int source, unsigned int freq, int dir);
96 int (*set_pll)(struct snd_soc_component *component, int pll_id,
97 int source, unsigned int freq_in, unsigned int freq_out);
98 int (*set_jack)(struct snd_soc_component *component,
99 struct snd_soc_jack *jack, void *data);
100
101 /* DT */
102 int (*of_xlate_dai_name)(struct snd_soc_component *component,
103 struct of_phandle_args *args,
104 const char **dai_name);
105 int (*of_xlate_dai_id)(struct snd_soc_component *comment,
106 struct device_node *endpoint);
107 void (*seq_notifier)(struct snd_soc_component *component,
108 enum snd_soc_dapm_type type, int subseq);
109 int (*stream_event)(struct snd_soc_component *component, int event);
110 int (*set_bias_level)(struct snd_soc_component *component,
111 enum snd_soc_bias_level level);
112
e2cb4a14
KM
113 int (*open)(struct snd_soc_component *component,
114 struct snd_pcm_substream *substream);
115 int (*close)(struct snd_soc_component *component,
116 struct snd_pcm_substream *substream);
117 int (*ioctl)(struct snd_soc_component *component,
118 struct snd_pcm_substream *substream,
119 unsigned int cmd, void *arg);
120 int (*hw_params)(struct snd_soc_component *component,
121 struct snd_pcm_substream *substream,
122 struct snd_pcm_hw_params *params);
123 int (*hw_free)(struct snd_soc_component *component,
124 struct snd_pcm_substream *substream);
125 int (*prepare)(struct snd_soc_component *component,
126 struct snd_pcm_substream *substream);
127 int (*trigger)(struct snd_soc_component *component,
128 struct snd_pcm_substream *substream, int cmd);
1e5ddb6b
TI
129 int (*sync_stop)(struct snd_soc_component *component,
130 struct snd_pcm_substream *substream);
e2cb4a14
KM
131 snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
132 struct snd_pcm_substream *substream);
133 int (*get_time_info)(struct snd_soc_component *component,
fcae40c9
BW
134 struct snd_pcm_substream *substream, struct timespec64 *system_ts,
135 struct timespec64 *audio_ts,
e2cb4a14
KM
136 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
137 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
138 int (*copy_user)(struct snd_soc_component *component,
139 struct snd_pcm_substream *substream, int channel,
140 unsigned long pos, void __user *buf,
141 unsigned long bytes);
142 struct page *(*page)(struct snd_soc_component *component,
143 struct snd_pcm_substream *substream,
144 unsigned long offset);
145 int (*mmap)(struct snd_soc_component *component,
146 struct snd_pcm_substream *substream,
147 struct vm_area_struct *vma);
148
c6cb522c 149 const struct snd_compress_ops *compress_ops;
4ff1fef1
KM
150
151 /* probe ordering - for components with runtime dependencies */
152 int probe_order;
153 int remove_order;
154
155 /*
156 * signal if the module handling the component should not be removed
157 * if a pcm is open. Setting this would prevent the module
158 * refcount being incremented in probe() but allow it be incremented
159 * when a pcm is opened and decremented when it is closed.
160 */
161 unsigned int module_get_upon_open:1;
162
163 /* bits */
164 unsigned int idle_bias_on:1;
165 unsigned int suspend_bias_off:1;
166 unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
167 unsigned int endianness:1;
168 unsigned int non_legacy_dai_naming:1;
169
170 /* this component uses topology and ignore machine driver FEs */
171 const char *ignore_machine;
172 const char *topology_name_prefix;
173 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
174 struct snd_pcm_hw_params *params);
175 bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */
176 int be_pcm_base; /* base device ID for all BE PCMs */
177};
178
179struct snd_soc_component {
180 const char *name;
181 int id;
182 const char *name_prefix;
183 struct device *dev;
184 struct snd_soc_card *card;
185
186 unsigned int active;
187
188 unsigned int suspended:1; /* is in suspend PM state */
189
190 struct list_head list;
191 struct list_head card_aux_list; /* for auxiliary bound components */
192 struct list_head card_list;
193
194 const struct snd_soc_component_driver *driver;
195
196 struct list_head dai_list;
197 int num_dai;
198
199 struct regmap *regmap;
200 int val_bytes;
201
202 struct mutex io_mutex;
203
204 /* attached dynamic objects */
205 struct list_head dobj_list;
206
207 /*
208 * DO NOT use any of the fields below in drivers, they are temporary and
209 * are going to be removed again soon. If you use them in driver code
210 * the driver will be marked as BROKEN when these fields are removed.
211 */
212
213 /* Don't use these, use snd_soc_component_get_dapm() */
214 struct snd_soc_dapm_context dapm;
215
216 /* machine specific init */
217 int (*init)(struct snd_soc_component *component);
218
219#ifdef CONFIG_DEBUG_FS
220 struct dentry *debugfs_root;
221 const char *debugfs_prefix;
222#endif
223};
224
225#define for_each_component_dais(component, dai)\
226 list_for_each_entry(dai, &(component)->dai_list, list)
227#define for_each_component_dais_safe(component, dai, _dai)\
228 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
229
230/**
231 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
232 * embedded in
233 * @dapm: The DAPM context to cast to the component
234 *
235 * This function must only be used on DAPM contexts that are known to be part of
236 * a component (e.g. in a component driver). Otherwise the behavior is
237 * undefined.
238 */
239static inline struct snd_soc_component *snd_soc_dapm_to_component(
240 struct snd_soc_dapm_context *dapm)
241{
242 return container_of(dapm, struct snd_soc_component, dapm);
243}
244
245/**
246 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
247 * component
248 * @component: The component for which to get the DAPM context
249 */
250static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
251 struct snd_soc_component *component)
252{
253 return &component->dapm;
254}
255
256/**
257 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
258 * @component: The COMPONENT for which to initialize the DAPM bias level
259 * @level: The DAPM level to initialize to
260 *
261 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
262 */
263static inline void
264snd_soc_component_init_bias_level(struct snd_soc_component *component,
265 enum snd_soc_bias_level level)
266{
267 snd_soc_dapm_init_bias_level(
268 snd_soc_component_get_dapm(component), level);
269}
270
271/**
272 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
273 * @component: The COMPONENT for which to get the DAPM bias level
274 *
275 * Returns: The current DAPM bias level of the COMPONENT.
276 */
277static inline enum snd_soc_bias_level
278snd_soc_component_get_bias_level(struct snd_soc_component *component)
279{
280 return snd_soc_dapm_get_bias_level(
281 snd_soc_component_get_dapm(component));
282}
283
284/**
285 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
286 * @component: The COMPONENT for which to set the level
287 * @level: The level to set to
288 *
289 * Forces the COMPONENT bias level to a specific state. See
290 * snd_soc_dapm_force_bias_level().
291 */
292static inline int
293snd_soc_component_force_bias_level(struct snd_soc_component *component,
294 enum snd_soc_bias_level level)
295{
296 return snd_soc_dapm_force_bias_level(
297 snd_soc_component_get_dapm(component),
298 level);
299}
300
301/**
302 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
303 * kcontrol
304 * @kcontrol: The kcontrol
305 *
306 * This function must only be used on DAPM contexts that are known to be part of
307 * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
308 */
309static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
310 struct snd_kcontrol *kcontrol)
311{
312 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
313}
314
315/**
316 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
317 * @component: COMPONENT to sync
318 *
319 * Note: This function will call regcache_sync()
320 */
321static inline int snd_soc_component_cache_sync(
322 struct snd_soc_component *component)
323{
324 return regcache_sync(component->regmap);
325}
326
327/* component IO */
328int snd_soc_component_read(struct snd_soc_component *component,
329 unsigned int reg, unsigned int *val);
330unsigned int snd_soc_component_read32(struct snd_soc_component *component,
331 unsigned int reg);
332int snd_soc_component_write(struct snd_soc_component *component,
333 unsigned int reg, unsigned int val);
334int snd_soc_component_update_bits(struct snd_soc_component *component,
335 unsigned int reg, unsigned int mask,
336 unsigned int val);
337int snd_soc_component_update_bits_async(struct snd_soc_component *component,
338 unsigned int reg, unsigned int mask,
339 unsigned int val);
340void snd_soc_component_async_complete(struct snd_soc_component *component);
341int snd_soc_component_test_bits(struct snd_soc_component *component,
342 unsigned int reg, unsigned int mask,
343 unsigned int value);
344
345/* component wide operations */
346int snd_soc_component_set_sysclk(struct snd_soc_component *component,
347 int clk_id, int source,
348 unsigned int freq, int dir);
349int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
350 int source, unsigned int freq_in,
351 unsigned int freq_out);
352int snd_soc_component_set_jack(struct snd_soc_component *component,
353 struct snd_soc_jack *jack, void *data);
354
9d415fbf
KM
355void snd_soc_component_seq_notifier(struct snd_soc_component *component,
356 enum snd_soc_dapm_type type, int subseq);
8e2a990d
KM
357int snd_soc_component_stream_event(struct snd_soc_component *component,
358 int event);
7951b146
KM
359int snd_soc_component_set_bias_level(struct snd_soc_component *component,
360 enum snd_soc_bias_level level);
9d415fbf 361
4ff1fef1
KM
362#ifdef CONFIG_REGMAP
363void snd_soc_component_init_regmap(struct snd_soc_component *component,
364 struct regmap *regmap);
365void snd_soc_component_exit_regmap(struct snd_soc_component *component);
366#endif
367
4a81e8f3
KM
368#define snd_soc_component_module_get_when_probe(component)\
369 snd_soc_component_module_get(component, 0)
370#define snd_soc_component_module_get_when_open(component) \
371 snd_soc_component_module_get(component, 1)
372int snd_soc_component_module_get(struct snd_soc_component *component,
373 int upon_open);
374#define snd_soc_component_module_put_when_remove(component) \
375 snd_soc_component_module_put(component, 0)
376#define snd_soc_component_module_put_when_close(component) \
377 snd_soc_component_module_put(component, 1)
378void snd_soc_component_module_put(struct snd_soc_component *component,
379 int upon_open);
380
4ff1fef1
KM
381static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
382 void *data)
383{
384 dev_set_drvdata(c->dev, data);
385}
386
387static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
388{
389 return dev_get_drvdata(c->dev);
390}
391
488b2ca5
KM
392static inline unsigned int
393snd_soc_component_active(struct snd_soc_component *component)
394{
395 return component->active;
396}
397
4ff1fef1
KM
398/* component pin */
399int snd_soc_component_enable_pin(struct snd_soc_component *component,
400 const char *pin);
401int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
402 const char *pin);
403int snd_soc_component_disable_pin(struct snd_soc_component *component,
404 const char *pin);
405int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
406 const char *pin);
407int snd_soc_component_nc_pin(struct snd_soc_component *component,
408 const char *pin);
409int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
410 const char *pin);
411int snd_soc_component_get_pin_status(struct snd_soc_component *component,
412 const char *pin);
413int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
414 const char *pin);
415int snd_soc_component_force_enable_pin_unlocked(
416 struct snd_soc_component *component,
417 const char *pin);
418
ae2f4849
KM
419/* component driver ops */
420int snd_soc_component_open(struct snd_soc_component *component,
421 struct snd_pcm_substream *substream);
3672beb8
KM
422int snd_soc_component_close(struct snd_soc_component *component,
423 struct snd_pcm_substream *substream);
6d537233
KM
424int snd_soc_component_prepare(struct snd_soc_component *component,
425 struct snd_pcm_substream *substream);
245c539a
KM
426int snd_soc_component_hw_params(struct snd_soc_component *component,
427 struct snd_pcm_substream *substream,
428 struct snd_pcm_hw_params *params);
eae7136a
KM
429int snd_soc_component_hw_free(struct snd_soc_component *component,
430 struct snd_pcm_substream *substream);
5693d50c
KM
431int snd_soc_component_trigger(struct snd_soc_component *component,
432 struct snd_pcm_substream *substream,
433 int cmd);
66c51573 434void snd_soc_component_suspend(struct snd_soc_component *component);
9a840cba 435void snd_soc_component_resume(struct snd_soc_component *component);
e40fadbc 436int snd_soc_component_is_suspended(struct snd_soc_component *component);
08e837dd 437int snd_soc_component_probe(struct snd_soc_component *component);
03b34dd7 438void snd_soc_component_remove(struct snd_soc_component *component);
2c7b1704
KM
439int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
440 struct device_node *ep);
a2a34175
KM
441int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
442 struct of_phandle_args *args,
443 const char **dai_name);
ae2f4849 444
0035e256 445int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
96a47908
KM
446int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
447 unsigned int cmd, void *arg);
1e5ddb6b 448int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
82d81f5c
KM
449int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
450 int channel, unsigned long pos,
451 void __user *buf, unsigned long bytes);
9c712e4f
KM
452struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
453 unsigned long offset);
205875e1
KM
454int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
455 struct vm_area_struct *vma);
b2b2afbb
KM
456int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
457void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
0035e256 458
4ff1fef1 459#endif /* __SOC_COMPONENT_H */