1 /* SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2019 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 #ifndef __SOC_COMPONENT_H
8 #define __SOC_COMPONENT_H
10 #include <sound/soc.h>
13 * Component probe and remove ordering levels for components with runtime
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
22 #define for_each_comp_order(order) \
23 for (order = SND_SOC_COMP_ORDER_FIRST; \
24 order <= SND_SOC_COMP_ORDER_LAST; \
27 /* component interface */
28 struct 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,
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);
66 struct snd_soc_component_driver {
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;
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);
82 unsigned int (*read)(struct snd_soc_component *component,
84 int (*write)(struct snd_soc_component *component,
85 unsigned int reg, unsigned int val);
87 /* pcm creation and destruction */
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,
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);
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);
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);
129 int (*sync_stop)(struct snd_soc_component *component,
130 struct snd_pcm_substream *substream);
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,
134 struct snd_pcm_substream *substream, struct timespec64 *system_ts,
135 struct timespec64 *audio_ts,
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);
149 const struct snd_compress_ops *compress_ops;
151 /* probe ordering - for components with runtime dependencies */
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.
161 unsigned int module_get_upon_open:1;
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;
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 */
179 struct snd_soc_component {
182 const char *name_prefix;
184 struct snd_soc_card *card;
188 unsigned int suspended:1; /* is in suspend PM state */
190 struct list_head list;
191 struct list_head card_aux_list; /* for auxiliary bound components */
192 struct list_head card_list;
194 const struct snd_soc_component_driver *driver;
196 struct list_head dai_list;
199 struct regmap *regmap;
202 struct mutex io_mutex;
204 /* attached dynamic objects */
205 struct list_head dobj_list;
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.
213 /* Don't use these, use snd_soc_component_get_dapm() */
214 struct snd_soc_dapm_context dapm;
216 /* machine specific init */
217 int (*init)(struct snd_soc_component *component);
219 #ifdef CONFIG_DEBUG_FS
220 struct dentry *debugfs_root;
221 const char *debugfs_prefix;
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)
231 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
233 * @dapm: The DAPM context to cast to the component
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
239 static inline struct snd_soc_component *snd_soc_dapm_to_component(
240 struct snd_soc_dapm_context *dapm)
242 return container_of(dapm, struct snd_soc_component, dapm);
246 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
248 * @component: The component for which to get the DAPM context
250 static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
251 struct snd_soc_component *component)
253 return &component->dapm;
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
261 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
264 snd_soc_component_init_bias_level(struct snd_soc_component *component,
265 enum snd_soc_bias_level level)
267 snd_soc_dapm_init_bias_level(
268 snd_soc_component_get_dapm(component), level);
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
275 * Returns: The current DAPM bias level of the COMPONENT.
277 static inline enum snd_soc_bias_level
278 snd_soc_component_get_bias_level(struct snd_soc_component *component)
280 return snd_soc_dapm_get_bias_level(
281 snd_soc_component_get_dapm(component));
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
289 * Forces the COMPONENT bias level to a specific state. See
290 * snd_soc_dapm_force_bias_level().
293 snd_soc_component_force_bias_level(struct snd_soc_component *component,
294 enum snd_soc_bias_level level)
296 return snd_soc_dapm_force_bias_level(
297 snd_soc_component_get_dapm(component),
302 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
304 * @kcontrol: The kcontrol
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
309 static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
310 struct snd_kcontrol *kcontrol)
312 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
316 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
317 * @component: COMPONENT to sync
319 * Note: This function will call regcache_sync()
321 static inline int snd_soc_component_cache_sync(
322 struct snd_soc_component *component)
324 return regcache_sync(component->regmap);
327 int snd_soc_component_initialize(struct snd_soc_component *component,
328 const struct snd_soc_component_driver *driver,
329 struct device *dev, const char *name);
332 int snd_soc_component_read(struct snd_soc_component *component,
333 unsigned int reg, unsigned int *val);
334 unsigned int snd_soc_component_read32(struct snd_soc_component *component,
336 int snd_soc_component_write(struct snd_soc_component *component,
337 unsigned int reg, unsigned int val);
338 int snd_soc_component_update_bits(struct snd_soc_component *component,
339 unsigned int reg, unsigned int mask,
341 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
342 unsigned int reg, unsigned int mask,
344 void snd_soc_component_async_complete(struct snd_soc_component *component);
345 int snd_soc_component_test_bits(struct snd_soc_component *component,
346 unsigned int reg, unsigned int mask,
349 /* component wide operations */
350 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
351 int clk_id, int source,
352 unsigned int freq, int dir);
353 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
354 int source, unsigned int freq_in,
355 unsigned int freq_out);
356 int snd_soc_component_set_jack(struct snd_soc_component *component,
357 struct snd_soc_jack *jack, void *data);
359 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
360 enum snd_soc_dapm_type type, int subseq);
361 int snd_soc_component_stream_event(struct snd_soc_component *component,
363 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
364 enum snd_soc_bias_level level);
366 void snd_soc_component_setup_regmap(struct snd_soc_component *component);
368 void snd_soc_component_init_regmap(struct snd_soc_component *component,
369 struct regmap *regmap);
370 void snd_soc_component_exit_regmap(struct snd_soc_component *component);
373 #define snd_soc_component_module_get_when_probe(component)\
374 snd_soc_component_module_get(component, 0)
375 #define snd_soc_component_module_get_when_open(component) \
376 snd_soc_component_module_get(component, 1)
377 int snd_soc_component_module_get(struct snd_soc_component *component,
379 #define snd_soc_component_module_put_when_remove(component) \
380 snd_soc_component_module_put(component, 0)
381 #define snd_soc_component_module_put_when_close(component) \
382 snd_soc_component_module_put(component, 1)
383 void snd_soc_component_module_put(struct snd_soc_component *component,
386 static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
389 dev_set_drvdata(c->dev, data);
392 static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
394 return dev_get_drvdata(c->dev);
397 static inline unsigned int
398 snd_soc_component_active(struct snd_soc_component *component)
400 return component->active;
404 int snd_soc_component_enable_pin(struct snd_soc_component *component,
406 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
408 int snd_soc_component_disable_pin(struct snd_soc_component *component,
410 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
412 int snd_soc_component_nc_pin(struct snd_soc_component *component,
414 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
416 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
418 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
420 int snd_soc_component_force_enable_pin_unlocked(
421 struct snd_soc_component *component,
424 /* component driver ops */
425 int snd_soc_component_open(struct snd_soc_component *component,
426 struct snd_pcm_substream *substream);
427 int snd_soc_component_close(struct snd_soc_component *component,
428 struct snd_pcm_substream *substream);
429 int snd_soc_component_prepare(struct snd_soc_component *component,
430 struct snd_pcm_substream *substream);
431 int snd_soc_component_hw_params(struct snd_soc_component *component,
432 struct snd_pcm_substream *substream,
433 struct snd_pcm_hw_params *params);
434 int snd_soc_component_hw_free(struct snd_soc_component *component,
435 struct snd_pcm_substream *substream);
436 int snd_soc_component_trigger(struct snd_soc_component *component,
437 struct snd_pcm_substream *substream,
439 void snd_soc_component_suspend(struct snd_soc_component *component);
440 void snd_soc_component_resume(struct snd_soc_component *component);
441 int snd_soc_component_is_suspended(struct snd_soc_component *component);
442 int snd_soc_component_probe(struct snd_soc_component *component);
443 void snd_soc_component_remove(struct snd_soc_component *component);
444 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
445 struct device_node *ep);
446 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
447 struct of_phandle_args *args,
448 const char **dai_name);
450 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
451 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
452 unsigned int cmd, void *arg);
453 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
454 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
455 int channel, unsigned long pos,
456 void __user *buf, unsigned long bytes);
457 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
458 unsigned long offset);
459 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
460 struct vm_area_struct *vma);
461 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
462 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
464 #endif /* __SOC_COMPONENT_H */