1 /* SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2019 Renesas Electronics Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8 #ifndef __SOC_COMPONENT_H
9 #define __SOC_COMPONENT_H
11 #include <sound/soc.h>
14 * Component probe and remove ordering levels for components with runtime
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
23 #define for_each_comp_order(order) \
24 for (order = SND_SOC_COMP_ORDER_FIRST; \
25 order <= SND_SOC_COMP_ORDER_LAST; \
28 /* component interface */
29 struct 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,
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);
67 struct snd_soc_component_driver {
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;
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);
83 unsigned int (*read)(struct snd_soc_component *component,
85 int (*write)(struct snd_soc_component *component,
86 unsigned int reg, unsigned int val);
88 /* pcm creation and destruction */
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,
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);
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);
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);
150 const struct snd_compress_ops *compress_ops;
152 /* probe ordering - for components with runtime dependencies */
157 * signal if the module handling the component should not be removed
158 * if a pcm is open. Setting this would prevent the module
159 * refcount being incremented in probe() but allow it be incremented
160 * when a pcm is opened and decremented when it is closed.
162 unsigned int module_get_upon_open:1;
165 unsigned int idle_bias_on:1;
166 unsigned int suspend_bias_off:1;
167 unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
168 unsigned int endianness:1;
169 unsigned int non_legacy_dai_naming:1;
171 /* this component uses topology and ignore machine driver FEs */
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; /* use DAI link PCM ID as PCM device number */
177 int be_pcm_base; /* base device ID for all BE PCMs */
180 struct snd_soc_component {
183 const char *name_prefix;
185 struct snd_soc_card *card;
189 unsigned int suspended:1; /* is in suspend PM state */
191 struct list_head list;
192 struct list_head card_aux_list; /* for auxiliary bound components */
193 struct list_head card_list;
195 const struct snd_soc_component_driver *driver;
197 struct list_head dai_list;
200 struct regmap *regmap;
203 struct mutex io_mutex;
205 /* attached dynamic objects */
206 struct list_head dobj_list;
209 * DO NOT use any of the fields below in drivers, they are temporary and
210 * are going to be removed again soon. If you use them in driver code
211 * the driver will be marked as BROKEN when these fields are removed.
214 /* Don't use these, use snd_soc_component_get_dapm() */
215 struct snd_soc_dapm_context dapm;
217 /* machine specific init */
218 int (*init)(struct snd_soc_component *component);
221 struct snd_pcm_substream *mark_module;
222 struct snd_pcm_substream *mark_open;
223 struct snd_pcm_substream *mark_hw_params;
224 struct snd_pcm_substream *mark_trigger;
225 struct snd_compr_stream *mark_compr_open;
228 #ifdef CONFIG_DEBUG_FS
229 struct dentry *debugfs_root;
230 const char *debugfs_prefix;
234 #define for_each_component_dais(component, dai)\
235 list_for_each_entry(dai, &(component)->dai_list, list)
236 #define for_each_component_dais_safe(component, dai, _dai)\
237 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
240 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
242 * @dapm: The DAPM context to cast to the component
244 * This function must only be used on DAPM contexts that are known to be part of
245 * a component (e.g. in a component driver). Otherwise the behavior is
248 static inline struct snd_soc_component *snd_soc_dapm_to_component(
249 struct snd_soc_dapm_context *dapm)
251 return container_of(dapm, struct snd_soc_component, dapm);
255 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
257 * @component: The component for which to get the DAPM context
259 static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
260 struct snd_soc_component *component)
262 return &component->dapm;
266 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
267 * @component: The COMPONENT for which to initialize the DAPM bias level
268 * @level: The DAPM level to initialize to
270 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
273 snd_soc_component_init_bias_level(struct snd_soc_component *component,
274 enum snd_soc_bias_level level)
276 snd_soc_dapm_init_bias_level(
277 snd_soc_component_get_dapm(component), level);
281 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
282 * @component: The COMPONENT for which to get the DAPM bias level
284 * Returns: The current DAPM bias level of the COMPONENT.
286 static inline enum snd_soc_bias_level
287 snd_soc_component_get_bias_level(struct snd_soc_component *component)
289 return snd_soc_dapm_get_bias_level(
290 snd_soc_component_get_dapm(component));
294 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
295 * @component: The COMPONENT for which to set the level
296 * @level: The level to set to
298 * Forces the COMPONENT bias level to a specific state. See
299 * snd_soc_dapm_force_bias_level().
302 snd_soc_component_force_bias_level(struct snd_soc_component *component,
303 enum snd_soc_bias_level level)
305 return snd_soc_dapm_force_bias_level(
306 snd_soc_component_get_dapm(component),
311 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
313 * @kcontrol: The kcontrol
315 * This function must only be used on DAPM contexts that are known to be part of
316 * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
318 static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
319 struct snd_kcontrol *kcontrol)
321 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
325 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
326 * @component: COMPONENT to sync
328 * Note: This function will call regcache_sync()
330 static inline int snd_soc_component_cache_sync(
331 struct snd_soc_component *component)
333 return regcache_sync(component->regmap);
336 void snd_soc_component_set_aux(struct snd_soc_component *component,
337 struct snd_soc_aux_dev *aux);
338 int snd_soc_component_init(struct snd_soc_component *component);
341 unsigned int snd_soc_component_read(struct snd_soc_component *component,
343 int snd_soc_component_write(struct snd_soc_component *component,
344 unsigned int reg, unsigned int val);
345 int snd_soc_component_update_bits(struct snd_soc_component *component,
346 unsigned int reg, unsigned int mask,
348 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
349 unsigned int reg, unsigned int mask,
351 void snd_soc_component_async_complete(struct snd_soc_component *component);
352 int snd_soc_component_test_bits(struct snd_soc_component *component,
353 unsigned int reg, unsigned int mask,
356 unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
357 unsigned int reg, unsigned int mask);
358 int snd_soc_component_write_field(struct snd_soc_component *component,
359 unsigned int reg, unsigned int mask,
362 /* component wide operations */
363 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
364 int clk_id, int source,
365 unsigned int freq, int dir);
366 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
367 int source, unsigned int freq_in,
368 unsigned int freq_out);
369 int snd_soc_component_set_jack(struct snd_soc_component *component,
370 struct snd_soc_jack *jack, void *data);
372 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
373 enum snd_soc_dapm_type type, int subseq);
374 int snd_soc_component_stream_event(struct snd_soc_component *component,
376 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
377 enum snd_soc_bias_level level);
379 void snd_soc_component_setup_regmap(struct snd_soc_component *component);
381 void snd_soc_component_init_regmap(struct snd_soc_component *component,
382 struct regmap *regmap);
383 void snd_soc_component_exit_regmap(struct snd_soc_component *component);
386 #define snd_soc_component_module_get_when_probe(component)\
387 snd_soc_component_module_get(component, NULL, 0)
388 #define snd_soc_component_module_get_when_open(component, substream) \
389 snd_soc_component_module_get(component, substream, 1)
390 int snd_soc_component_module_get(struct snd_soc_component *component,
391 struct snd_pcm_substream *substream,
393 #define snd_soc_component_module_put_when_remove(component) \
394 snd_soc_component_module_put(component, NULL, 0, 0)
395 #define snd_soc_component_module_put_when_close(component, substream, rollback) \
396 snd_soc_component_module_put(component, substream, 1, rollback)
397 void snd_soc_component_module_put(struct snd_soc_component *component,
398 struct snd_pcm_substream *substream,
399 int upon_open, int rollback);
401 static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
404 dev_set_drvdata(c->dev, data);
407 static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
409 return dev_get_drvdata(c->dev);
412 static inline unsigned int
413 snd_soc_component_active(struct snd_soc_component *component)
415 return component->active;
419 int snd_soc_component_enable_pin(struct snd_soc_component *component,
421 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
423 int snd_soc_component_disable_pin(struct snd_soc_component *component,
425 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
427 int snd_soc_component_nc_pin(struct snd_soc_component *component,
429 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
431 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
433 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
435 int snd_soc_component_force_enable_pin_unlocked(
436 struct snd_soc_component *component,
439 /* component driver ops */
440 int snd_soc_component_open(struct snd_soc_component *component,
441 struct snd_pcm_substream *substream);
442 int snd_soc_component_close(struct snd_soc_component *component,
443 struct snd_pcm_substream *substream,
445 void snd_soc_component_suspend(struct snd_soc_component *component);
446 void snd_soc_component_resume(struct snd_soc_component *component);
447 int snd_soc_component_is_suspended(struct snd_soc_component *component);
448 int snd_soc_component_probe(struct snd_soc_component *component);
449 void snd_soc_component_remove(struct snd_soc_component *component);
450 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
451 struct device_node *ep);
452 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
453 struct of_phandle_args *args,
454 const char **dai_name);
455 int snd_soc_component_compr_open(struct snd_compr_stream *cstream);
456 void snd_soc_component_compr_free(struct snd_compr_stream *cstream,
458 int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
459 int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
460 struct snd_compr_params *params);
461 int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
462 struct snd_codec *params);
463 int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
464 struct snd_compr_caps *caps);
465 int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
466 struct snd_compr_codec_caps *codec);
467 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
468 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
469 struct snd_compr_tstamp *tstamp);
470 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
471 char __user *buf, size_t count);
472 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
473 struct snd_compr_metadata *metadata);
474 int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
475 struct snd_compr_metadata *metadata);
477 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
478 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
479 unsigned int cmd, void *arg);
480 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
481 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
482 int channel, unsigned long pos,
483 void __user *buf, unsigned long bytes);
484 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
485 unsigned long offset);
486 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
487 struct vm_area_struct *vma);
488 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
489 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
490 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
491 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
492 struct snd_pcm_hw_params *params);
493 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
495 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
496 int cmd, int rollback);
497 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
499 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
500 void *stream, int rollback);
502 #endif /* __SOC_COMPONENT_H */