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_soc_component_driver {
31 /* Default control and setup, added after probe() is run */
32 const struct snd_kcontrol_new *controls;
33 unsigned int num_controls;
34 const struct snd_soc_dapm_widget *dapm_widgets;
35 unsigned int num_dapm_widgets;
36 const struct snd_soc_dapm_route *dapm_routes;
37 unsigned int num_dapm_routes;
39 int (*probe)(struct snd_soc_component *component);
40 void (*remove)(struct snd_soc_component *component);
41 int (*suspend)(struct snd_soc_component *component);
42 int (*resume)(struct snd_soc_component *component);
44 unsigned int (*read)(struct snd_soc_component *component,
46 int (*write)(struct snd_soc_component *component,
47 unsigned int reg, unsigned int val);
49 /* pcm creation and destruction */
50 int (*pcm_construct)(struct snd_soc_component *component,
51 struct snd_soc_pcm_runtime *rtd);
52 void (*pcm_destruct)(struct snd_soc_component *component,
55 /* component wide operations */
56 int (*set_sysclk)(struct snd_soc_component *component,
57 int clk_id, int source, unsigned int freq, int dir);
58 int (*set_pll)(struct snd_soc_component *component, int pll_id,
59 int source, unsigned int freq_in, unsigned int freq_out);
60 int (*set_jack)(struct snd_soc_component *component,
61 struct snd_soc_jack *jack, void *data);
64 int (*of_xlate_dai_name)(struct snd_soc_component *component,
65 struct of_phandle_args *args,
66 const char **dai_name);
67 int (*of_xlate_dai_id)(struct snd_soc_component *comment,
68 struct device_node *endpoint);
69 void (*seq_notifier)(struct snd_soc_component *component,
70 enum snd_soc_dapm_type type, int subseq);
71 int (*stream_event)(struct snd_soc_component *component, int event);
72 int (*set_bias_level)(struct snd_soc_component *component,
73 enum snd_soc_bias_level level);
75 int (*open)(struct snd_soc_component *component,
76 struct snd_pcm_substream *substream);
77 int (*close)(struct snd_soc_component *component,
78 struct snd_pcm_substream *substream);
79 int (*ioctl)(struct snd_soc_component *component,
80 struct snd_pcm_substream *substream,
81 unsigned int cmd, void *arg);
82 int (*hw_params)(struct snd_soc_component *component,
83 struct snd_pcm_substream *substream,
84 struct snd_pcm_hw_params *params);
85 int (*hw_free)(struct snd_soc_component *component,
86 struct snd_pcm_substream *substream);
87 int (*prepare)(struct snd_soc_component *component,
88 struct snd_pcm_substream *substream);
89 int (*trigger)(struct snd_soc_component *component,
90 struct snd_pcm_substream *substream, int cmd);
91 int (*sync_stop)(struct snd_soc_component *component,
92 struct snd_pcm_substream *substream);
93 snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
94 struct snd_pcm_substream *substream);
95 int (*get_time_info)(struct snd_soc_component *component,
96 struct snd_pcm_substream *substream, struct timespec64 *system_ts,
97 struct timespec64 *audio_ts,
98 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
99 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
100 int (*copy_user)(struct snd_soc_component *component,
101 struct snd_pcm_substream *substream, int channel,
102 unsigned long pos, void __user *buf,
103 unsigned long bytes);
104 struct page *(*page)(struct snd_soc_component *component,
105 struct snd_pcm_substream *substream,
106 unsigned long offset);
107 int (*mmap)(struct snd_soc_component *component,
108 struct snd_pcm_substream *substream,
109 struct vm_area_struct *vma);
111 const struct snd_compr_ops *compr_ops;
113 /* probe ordering - for components with runtime dependencies */
118 * signal if the module handling the component should not be removed
119 * if a pcm is open. Setting this would prevent the module
120 * refcount being incremented in probe() but allow it be incremented
121 * when a pcm is opened and decremented when it is closed.
123 unsigned int module_get_upon_open:1;
126 unsigned int idle_bias_on:1;
127 unsigned int suspend_bias_off:1;
128 unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
129 unsigned int endianness:1;
130 unsigned int non_legacy_dai_naming:1;
132 /* this component uses topology and ignore machine driver FEs */
133 const char *ignore_machine;
134 const char *topology_name_prefix;
135 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
136 struct snd_pcm_hw_params *params);
137 bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */
138 int be_pcm_base; /* base device ID for all BE PCMs */
141 struct snd_soc_component {
144 const char *name_prefix;
146 struct snd_soc_card *card;
150 struct list_head list;
151 struct list_head card_aux_list; /* for auxiliary bound components */
152 struct list_head card_list;
154 const struct snd_soc_component_driver *driver;
156 struct list_head dai_list;
159 struct regmap *regmap;
162 struct mutex io_mutex;
164 /* attached dynamic objects */
165 struct list_head dobj_list;
168 * DO NOT use any of the fields below in drivers, they are temporary and
169 * are going to be removed again soon. If you use them in driver code
170 * the driver will be marked as BROKEN when these fields are removed.
173 /* Don't use these, use snd_soc_component_get_dapm() */
174 struct snd_soc_dapm_context dapm;
176 /* machine specific init */
177 int (*init)(struct snd_soc_component *component);
179 #ifdef CONFIG_DEBUG_FS
180 struct dentry *debugfs_root;
181 const char *debugfs_prefix;
185 unsigned int suspended:1; /* is in suspend PM state */
186 unsigned int opened:1;
187 unsigned int module:1;
190 #define for_each_component_dais(component, dai)\
191 list_for_each_entry(dai, &(component)->dai_list, list)
192 #define for_each_component_dais_safe(component, dai, _dai)\
193 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
196 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
198 * @dapm: The DAPM context to cast to the component
200 * This function must only be used on DAPM contexts that are known to be part of
201 * a component (e.g. in a component driver). Otherwise the behavior is
204 static inline struct snd_soc_component *snd_soc_dapm_to_component(
205 struct snd_soc_dapm_context *dapm)
207 return container_of(dapm, struct snd_soc_component, dapm);
211 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
213 * @component: The component for which to get the DAPM context
215 static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
216 struct snd_soc_component *component)
218 return &component->dapm;
222 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
223 * @component: The COMPONENT for which to initialize the DAPM bias level
224 * @level: The DAPM level to initialize to
226 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
229 snd_soc_component_init_bias_level(struct snd_soc_component *component,
230 enum snd_soc_bias_level level)
232 snd_soc_dapm_init_bias_level(
233 snd_soc_component_get_dapm(component), level);
237 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
238 * @component: The COMPONENT for which to get the DAPM bias level
240 * Returns: The current DAPM bias level of the COMPONENT.
242 static inline enum snd_soc_bias_level
243 snd_soc_component_get_bias_level(struct snd_soc_component *component)
245 return snd_soc_dapm_get_bias_level(
246 snd_soc_component_get_dapm(component));
250 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
251 * @component: The COMPONENT for which to set the level
252 * @level: The level to set to
254 * Forces the COMPONENT bias level to a specific state. See
255 * snd_soc_dapm_force_bias_level().
258 snd_soc_component_force_bias_level(struct snd_soc_component *component,
259 enum snd_soc_bias_level level)
261 return snd_soc_dapm_force_bias_level(
262 snd_soc_component_get_dapm(component),
267 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
269 * @kcontrol: The kcontrol
271 * This function must only be used on DAPM contexts that are known to be part of
272 * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
274 static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
275 struct snd_kcontrol *kcontrol)
277 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
281 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
282 * @component: COMPONENT to sync
284 * Note: This function will call regcache_sync()
286 static inline int snd_soc_component_cache_sync(
287 struct snd_soc_component *component)
289 return regcache_sync(component->regmap);
293 int snd_soc_component_read(struct snd_soc_component *component,
294 unsigned int reg, unsigned int *val);
295 unsigned int snd_soc_component_read32(struct snd_soc_component *component,
297 int snd_soc_component_write(struct snd_soc_component *component,
298 unsigned int reg, unsigned int val);
299 int snd_soc_component_update_bits(struct snd_soc_component *component,
300 unsigned int reg, unsigned int mask,
302 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
303 unsigned int reg, unsigned int mask,
305 void snd_soc_component_async_complete(struct snd_soc_component *component);
306 int snd_soc_component_test_bits(struct snd_soc_component *component,
307 unsigned int reg, unsigned int mask,
310 /* component wide operations */
311 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
312 int clk_id, int source,
313 unsigned int freq, int dir);
314 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
315 int source, unsigned int freq_in,
316 unsigned int freq_out);
317 int snd_soc_component_set_jack(struct snd_soc_component *component,
318 struct snd_soc_jack *jack, void *data);
320 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
321 enum snd_soc_dapm_type type, int subseq);
322 int snd_soc_component_stream_event(struct snd_soc_component *component,
324 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
325 enum snd_soc_bias_level level);
328 void snd_soc_component_init_regmap(struct snd_soc_component *component,
329 struct regmap *regmap);
330 void snd_soc_component_exit_regmap(struct snd_soc_component *component);
333 #define snd_soc_component_module_get_when_probe(component)\
334 snd_soc_component_module_get(component, 0)
335 #define snd_soc_component_module_get_when_open(component) \
336 snd_soc_component_module_get(component, 1)
337 int snd_soc_component_module_get(struct snd_soc_component *component,
339 #define snd_soc_component_module_put_when_remove(component) \
340 snd_soc_component_module_put(component, 0)
341 #define snd_soc_component_module_put_when_close(component) \
342 snd_soc_component_module_put(component, 1)
343 void snd_soc_component_module_put(struct snd_soc_component *component,
346 static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
349 dev_set_drvdata(c->dev, data);
352 static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
354 return dev_get_drvdata(c->dev);
357 static inline bool snd_soc_component_is_active(
358 struct snd_soc_component *component)
360 return component->active != 0;
364 int snd_soc_component_enable_pin(struct snd_soc_component *component,
366 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
368 int snd_soc_component_disable_pin(struct snd_soc_component *component,
370 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
372 int snd_soc_component_nc_pin(struct snd_soc_component *component,
374 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
376 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
378 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
380 int snd_soc_component_force_enable_pin_unlocked(
381 struct snd_soc_component *component,
384 /* component driver ops */
385 int snd_soc_component_open(struct snd_soc_component *component,
386 struct snd_pcm_substream *substream);
387 int snd_soc_component_close(struct snd_soc_component *component,
388 struct snd_pcm_substream *substream);
389 int snd_soc_component_prepare(struct snd_soc_component *component,
390 struct snd_pcm_substream *substream);
391 int snd_soc_component_hw_params(struct snd_soc_component *component,
392 struct snd_pcm_substream *substream,
393 struct snd_pcm_hw_params *params);
394 int snd_soc_component_hw_free(struct snd_soc_component *component,
395 struct snd_pcm_substream *substream);
396 int snd_soc_component_trigger(struct snd_soc_component *component,
397 struct snd_pcm_substream *substream,
399 void snd_soc_component_suspend(struct snd_soc_component *component);
400 void snd_soc_component_resume(struct snd_soc_component *component);
401 int snd_soc_component_is_suspended(struct snd_soc_component *component);
402 int snd_soc_component_probe(struct snd_soc_component *component);
403 void snd_soc_component_remove(struct snd_soc_component *component);
404 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
405 struct device_node *ep);
406 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
407 struct of_phandle_args *args,
408 const char **dai_name);
410 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
411 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
412 unsigned int cmd, void *arg);
413 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
414 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
415 int channel, unsigned long pos,
416 void __user *buf, unsigned long bytes);
417 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
418 unsigned long offset);
419 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
420 struct vm_area_struct *vma);
421 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
422 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
424 #endif /* __SOC_COMPONENT_H */