Loading...
1/* SPDX-License-Identifier: GPL-2.0
2 *
3 * soc-component.h
4 *
5 * Copyright (c) 2019 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef __SOC_COMPONENT_H
12#define __SOC_COMPONENT_H
13
14#include <sound/soc.h>
15
16/*
17 * Component probe and remove ordering levels for components with runtime
18 * dependencies.
19 */
20#define SND_SOC_COMP_ORDER_FIRST -2
21#define SND_SOC_COMP_ORDER_EARLY -1
22#define SND_SOC_COMP_ORDER_NORMAL 0
23#define SND_SOC_COMP_ORDER_LATE 1
24#define SND_SOC_COMP_ORDER_LAST 2
25
26#define for_each_comp_order(order) \
27 for (order = SND_SOC_COMP_ORDER_FIRST; \
28 order <= SND_SOC_COMP_ORDER_LAST; \
29 order++)
30
31/* component interface */
32struct snd_soc_component_driver {
33 const char *name;
34
35 /* Default control and setup, added after probe() is run */
36 const struct snd_kcontrol_new *controls;
37 unsigned int num_controls;
38 const struct snd_soc_dapm_widget *dapm_widgets;
39 unsigned int num_dapm_widgets;
40 const struct snd_soc_dapm_route *dapm_routes;
41 unsigned int num_dapm_routes;
42
43 int (*probe)(struct snd_soc_component *component);
44 void (*remove)(struct snd_soc_component *component);
45 int (*suspend)(struct snd_soc_component *component);
46 int (*resume)(struct snd_soc_component *component);
47
48 unsigned int (*read)(struct snd_soc_component *component,
49 unsigned int reg);
50 int (*write)(struct snd_soc_component *component,
51 unsigned int reg, unsigned int val);
52
53 /* pcm creation and destruction */
54 int (*pcm_new)(struct snd_soc_pcm_runtime *rtd);
55 void (*pcm_free)(struct snd_pcm *pcm);
56
57 /* component wide operations */
58 int (*set_sysclk)(struct snd_soc_component *component,
59 int clk_id, int source, unsigned int freq, int dir);
60 int (*set_pll)(struct snd_soc_component *component, int pll_id,
61 int source, unsigned int freq_in, unsigned int freq_out);
62 int (*set_jack)(struct snd_soc_component *component,
63 struct snd_soc_jack *jack, void *data);
64
65 /* DT */
66 int (*of_xlate_dai_name)(struct snd_soc_component *component,
67 struct of_phandle_args *args,
68 const char **dai_name);
69 int (*of_xlate_dai_id)(struct snd_soc_component *comment,
70 struct device_node *endpoint);
71 void (*seq_notifier)(struct snd_soc_component *component,
72 enum snd_soc_dapm_type type, int subseq);
73 int (*stream_event)(struct snd_soc_component *component, int event);
74 int (*set_bias_level)(struct snd_soc_component *component,
75 enum snd_soc_bias_level level);
76
77 const struct snd_pcm_ops *ops;
78 const struct snd_compr_ops *compr_ops;
79
80 /* probe ordering - for components with runtime dependencies */
81 int probe_order;
82 int remove_order;
83
84 /*
85 * signal if the module handling the component should not be removed
86 * if a pcm is open. Setting this would prevent the module
87 * refcount being incremented in probe() but allow it be incremented
88 * when a pcm is opened and decremented when it is closed.
89 */
90 unsigned int module_get_upon_open:1;
91
92 /* bits */
93 unsigned int idle_bias_on:1;
94 unsigned int suspend_bias_off:1;
95 unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
96 unsigned int endianness:1;
97 unsigned int non_legacy_dai_naming:1;
98
99 /* this component uses topology and ignore machine driver FEs */
100 const char *ignore_machine;
101 const char *topology_name_prefix;
102 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
103 struct snd_pcm_hw_params *params);
104 bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */
105 int be_pcm_base; /* base device ID for all BE PCMs */
106};
107
108struct snd_soc_component {
109 const char *name;
110 int id;
111 const char *name_prefix;
112 struct device *dev;
113 struct snd_soc_card *card;
114
115 unsigned int active;
116
117 unsigned int suspended:1; /* is in suspend PM state */
118
119 struct list_head list;
120 struct list_head card_aux_list; /* for auxiliary bound components */
121 struct list_head card_list;
122
123 const struct snd_soc_component_driver *driver;
124
125 struct list_head dai_list;
126 int num_dai;
127
128 struct regmap *regmap;
129 int val_bytes;
130
131 struct mutex io_mutex;
132
133 /* attached dynamic objects */
134 struct list_head dobj_list;
135
136 /*
137 * DO NOT use any of the fields below in drivers, they are temporary and
138 * are going to be removed again soon. If you use them in driver code
139 * the driver will be marked as BROKEN when these fields are removed.
140 */
141
142 /* Don't use these, use snd_soc_component_get_dapm() */
143 struct snd_soc_dapm_context dapm;
144
145 /* machine specific init */
146 int (*init)(struct snd_soc_component *component);
147
148#ifdef CONFIG_DEBUG_FS
149 struct dentry *debugfs_root;
150 const char *debugfs_prefix;
151#endif
152};
153
154#define for_each_component_dais(component, dai)\
155 list_for_each_entry(dai, &(component)->dai_list, list)
156#define for_each_component_dais_safe(component, dai, _dai)\
157 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
158
159/**
160 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
161 * embedded in
162 * @dapm: The DAPM context to cast to the component
163 *
164 * This function must only be used on DAPM contexts that are known to be part of
165 * a component (e.g. in a component driver). Otherwise the behavior is
166 * undefined.
167 */
168static inline struct snd_soc_component *snd_soc_dapm_to_component(
169 struct snd_soc_dapm_context *dapm)
170{
171 return container_of(dapm, struct snd_soc_component, dapm);
172}
173
174/**
175 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
176 * component
177 * @component: The component for which to get the DAPM context
178 */
179static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
180 struct snd_soc_component *component)
181{
182 return &component->dapm;
183}
184
185/**
186 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
187 * @component: The COMPONENT for which to initialize the DAPM bias level
188 * @level: The DAPM level to initialize to
189 *
190 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
191 */
192static inline void
193snd_soc_component_init_bias_level(struct snd_soc_component *component,
194 enum snd_soc_bias_level level)
195{
196 snd_soc_dapm_init_bias_level(
197 snd_soc_component_get_dapm(component), level);
198}
199
200/**
201 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
202 * @component: The COMPONENT for which to get the DAPM bias level
203 *
204 * Returns: The current DAPM bias level of the COMPONENT.
205 */
206static inline enum snd_soc_bias_level
207snd_soc_component_get_bias_level(struct snd_soc_component *component)
208{
209 return snd_soc_dapm_get_bias_level(
210 snd_soc_component_get_dapm(component));
211}
212
213/**
214 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
215 * @component: The COMPONENT for which to set the level
216 * @level: The level to set to
217 *
218 * Forces the COMPONENT bias level to a specific state. See
219 * snd_soc_dapm_force_bias_level().
220 */
221static inline int
222snd_soc_component_force_bias_level(struct snd_soc_component *component,
223 enum snd_soc_bias_level level)
224{
225 return snd_soc_dapm_force_bias_level(
226 snd_soc_component_get_dapm(component),
227 level);
228}
229
230/**
231 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
232 * kcontrol
233 * @kcontrol: The kcontrol
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 undefined
237 */
238static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
239 struct snd_kcontrol *kcontrol)
240{
241 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
242}
243
244/**
245 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
246 * @component: COMPONENT to sync
247 *
248 * Note: This function will call regcache_sync()
249 */
250static inline int snd_soc_component_cache_sync(
251 struct snd_soc_component *component)
252{
253 return regcache_sync(component->regmap);
254}
255
256/* component IO */
257int snd_soc_component_read(struct snd_soc_component *component,
258 unsigned int reg, unsigned int *val);
259unsigned int snd_soc_component_read32(struct snd_soc_component *component,
260 unsigned int reg);
261int snd_soc_component_write(struct snd_soc_component *component,
262 unsigned int reg, unsigned int val);
263int snd_soc_component_update_bits(struct snd_soc_component *component,
264 unsigned int reg, unsigned int mask,
265 unsigned int val);
266int snd_soc_component_update_bits_async(struct snd_soc_component *component,
267 unsigned int reg, unsigned int mask,
268 unsigned int val);
269void snd_soc_component_async_complete(struct snd_soc_component *component);
270int snd_soc_component_test_bits(struct snd_soc_component *component,
271 unsigned int reg, unsigned int mask,
272 unsigned int value);
273
274/* component wide operations */
275int snd_soc_component_set_sysclk(struct snd_soc_component *component,
276 int clk_id, int source,
277 unsigned int freq, int dir);
278int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
279 int source, unsigned int freq_in,
280 unsigned int freq_out);
281int snd_soc_component_set_jack(struct snd_soc_component *component,
282 struct snd_soc_jack *jack, void *data);
283
284void snd_soc_component_seq_notifier(struct snd_soc_component *component,
285 enum snd_soc_dapm_type type, int subseq);
286int snd_soc_component_stream_event(struct snd_soc_component *component,
287 int event);
288int snd_soc_component_set_bias_level(struct snd_soc_component *component,
289 enum snd_soc_bias_level level);
290
291#ifdef CONFIG_REGMAP
292void snd_soc_component_init_regmap(struct snd_soc_component *component,
293 struct regmap *regmap);
294void snd_soc_component_exit_regmap(struct snd_soc_component *component);
295#endif
296
297#define snd_soc_component_module_get_when_probe(component)\
298 snd_soc_component_module_get(component, 0)
299#define snd_soc_component_module_get_when_open(component) \
300 snd_soc_component_module_get(component, 1)
301int snd_soc_component_module_get(struct snd_soc_component *component,
302 int upon_open);
303#define snd_soc_component_module_put_when_remove(component) \
304 snd_soc_component_module_put(component, 0)
305#define snd_soc_component_module_put_when_close(component) \
306 snd_soc_component_module_put(component, 1)
307void snd_soc_component_module_put(struct snd_soc_component *component,
308 int upon_open);
309
310static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
311 void *data)
312{
313 dev_set_drvdata(c->dev, data);
314}
315
316static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
317{
318 return dev_get_drvdata(c->dev);
319}
320
321static inline bool snd_soc_component_is_active(
322 struct snd_soc_component *component)
323{
324 return component->active != 0;
325}
326
327/* component pin */
328int snd_soc_component_enable_pin(struct snd_soc_component *component,
329 const char *pin);
330int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
331 const char *pin);
332int snd_soc_component_disable_pin(struct snd_soc_component *component,
333 const char *pin);
334int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
335 const char *pin);
336int snd_soc_component_nc_pin(struct snd_soc_component *component,
337 const char *pin);
338int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
339 const char *pin);
340int snd_soc_component_get_pin_status(struct snd_soc_component *component,
341 const char *pin);
342int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
343 const char *pin);
344int snd_soc_component_force_enable_pin_unlocked(
345 struct snd_soc_component *component,
346 const char *pin);
347
348/* component driver ops */
349int snd_soc_component_open(struct snd_soc_component *component,
350 struct snd_pcm_substream *substream);
351int snd_soc_component_close(struct snd_soc_component *component,
352 struct snd_pcm_substream *substream);
353int snd_soc_component_prepare(struct snd_soc_component *component,
354 struct snd_pcm_substream *substream);
355int snd_soc_component_hw_params(struct snd_soc_component *component,
356 struct snd_pcm_substream *substream,
357 struct snd_pcm_hw_params *params);
358int snd_soc_component_hw_free(struct snd_soc_component *component,
359 struct snd_pcm_substream *substream);
360int snd_soc_component_trigger(struct snd_soc_component *component,
361 struct snd_pcm_substream *substream,
362 int cmd);
363void snd_soc_component_suspend(struct snd_soc_component *component);
364void snd_soc_component_resume(struct snd_soc_component *component);
365int snd_soc_component_is_suspended(struct snd_soc_component *component);
366int snd_soc_component_probe(struct snd_soc_component *component);
367void snd_soc_component_remove(struct snd_soc_component *component);
368int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
369 struct device_node *ep);
370int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
371 struct of_phandle_args *args,
372 const char **dai_name);
373
374int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
375int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
376 unsigned int cmd, void *arg);
377int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
378 int channel, unsigned long pos,
379 void __user *buf, unsigned long bytes);
380struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
381 unsigned long offset);
382int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
383 struct vm_area_struct *vma);
384int snd_soc_pcm_component_new(struct snd_pcm *pcm);
385void snd_soc_pcm_component_free(struct snd_pcm *pcm);
386
387#endif /* __SOC_COMPONENT_H */
1/* SPDX-License-Identifier: GPL-2.0
2 *
3 * soc-component.h
4 *
5 * Copyright (C) 2019 Renesas Electronics Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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 */
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
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 */
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
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);
101 int (*get_jack_type)(struct snd_soc_component *component);
102
103 /* DT */
104 int (*of_xlate_dai_name)(struct snd_soc_component *component,
105 const struct of_phandle_args *args,
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
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);
131 int (*sync_stop)(struct snd_soc_component *component,
132 struct snd_pcm_substream *substream);
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,
136 struct snd_pcm_substream *substream, struct timespec64 *system_ts,
137 struct timespec64 *audio_ts,
138 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
139 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
140 int (*copy)(struct snd_soc_component *component,
141 struct snd_pcm_substream *substream, int channel,
142 unsigned long pos, struct iov_iter *iter,
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);
150 int (*ack)(struct snd_soc_component *component,
151 struct snd_pcm_substream *substream);
152 snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
153 struct snd_pcm_substream *substream);
154
155 const struct snd_compress_ops *compress_ops;
156
157 /* probe ordering - for components with runtime dependencies */
158 int probe_order;
159 int remove_order;
160
161 /*
162 * soc_pcm_trigger() start/stop sequence.
163 * see also
164 * snd_soc_dai_link
165 * soc_pcm_trigger()
166 */
167 enum snd_soc_trigger_order trigger_start;
168 enum snd_soc_trigger_order trigger_stop;
169
170 /*
171 * signal if the module handling the component should not be removed
172 * if a pcm is open. Setting this would prevent the module
173 * refcount being incremented in probe() but allow it be incremented
174 * when a pcm is opened and decremented when it is closed.
175 */
176 unsigned int module_get_upon_open:1;
177
178 /* bits */
179 unsigned int idle_bias_on:1;
180 unsigned int suspend_bias_off:1;
181 unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
182 /*
183 * Indicates that the component does not care about the endianness of
184 * PCM audio data and the core will ensure that both LE and BE variants
185 * of each used format are present. Typically this is because the
186 * component sits behind a bus that abstracts away the endian of the
187 * original data, ie. one for which the transmission endian is defined
188 * (I2S/SLIMbus/SoundWire), or the concept of endian doesn't exist (PDM,
189 * analogue).
190 */
191 unsigned int endianness:1;
192 unsigned int legacy_dai_naming:1;
193
194 /* this component uses topology and ignore machine driver FEs */
195 const char *ignore_machine;
196 const char *topology_name_prefix;
197 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
198 struct snd_pcm_hw_params *params);
199 bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */
200 int be_pcm_base; /* base device ID for all BE PCMs */
201
202#ifdef CONFIG_DEBUG_FS
203 const char *debugfs_prefix;
204#endif
205};
206
207struct snd_soc_component {
208 const char *name;
209 int id;
210 const char *name_prefix;
211 struct device *dev;
212 struct snd_soc_card *card;
213
214 unsigned int active;
215
216 unsigned int suspended:1; /* is in suspend PM state */
217
218 struct list_head list;
219 struct list_head card_aux_list; /* for auxiliary bound components */
220 struct list_head card_list;
221
222 const struct snd_soc_component_driver *driver;
223
224 struct list_head dai_list;
225 int num_dai;
226
227 struct regmap *regmap;
228 int val_bytes;
229
230 struct mutex io_mutex;
231
232 /* attached dynamic objects */
233 struct list_head dobj_list;
234
235 /*
236 * DO NOT use any of the fields below in drivers, they are temporary and
237 * are going to be removed again soon. If you use them in driver code
238 * the driver will be marked as BROKEN when these fields are removed.
239 */
240
241 /* Don't use these, use snd_soc_component_get_dapm() */
242 struct snd_soc_dapm_context dapm;
243
244 /* machine specific init */
245 int (*init)(struct snd_soc_component *component);
246
247 /* function mark */
248 void *mark_module;
249 struct snd_pcm_substream *mark_open;
250 struct snd_pcm_substream *mark_hw_params;
251 struct snd_pcm_substream *mark_trigger;
252 struct snd_compr_stream *mark_compr_open;
253 void *mark_pm;
254
255 struct dentry *debugfs_root;
256 const char *debugfs_prefix;
257};
258
259#define for_each_component_dais(component, dai)\
260 list_for_each_entry(dai, &(component)->dai_list, list)
261#define for_each_component_dais_safe(component, dai, _dai)\
262 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
263
264/**
265 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
266 * embedded in
267 * @dapm: The DAPM context to cast to the component
268 *
269 * This function must only be used on DAPM contexts that are known to be part of
270 * a component (e.g. in a component driver). Otherwise the behavior is
271 * undefined.
272 */
273static inline struct snd_soc_component *snd_soc_dapm_to_component(
274 struct snd_soc_dapm_context *dapm)
275{
276 return container_of(dapm, struct snd_soc_component, dapm);
277}
278
279/**
280 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
281 * component
282 * @component: The component for which to get the DAPM context
283 */
284static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
285 struct snd_soc_component *component)
286{
287 return &component->dapm;
288}
289
290/**
291 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
292 * @component: The COMPONENT for which to initialize the DAPM bias level
293 * @level: The DAPM level to initialize to
294 *
295 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
296 */
297static inline void
298snd_soc_component_init_bias_level(struct snd_soc_component *component,
299 enum snd_soc_bias_level level)
300{
301 snd_soc_dapm_init_bias_level(
302 snd_soc_component_get_dapm(component), level);
303}
304
305/**
306 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
307 * @component: The COMPONENT for which to get the DAPM bias level
308 *
309 * Returns: The current DAPM bias level of the COMPONENT.
310 */
311static inline enum snd_soc_bias_level
312snd_soc_component_get_bias_level(struct snd_soc_component *component)
313{
314 return snd_soc_dapm_get_bias_level(
315 snd_soc_component_get_dapm(component));
316}
317
318/**
319 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
320 * @component: The COMPONENT for which to set the level
321 * @level: The level to set to
322 *
323 * Forces the COMPONENT bias level to a specific state. See
324 * snd_soc_dapm_force_bias_level().
325 */
326static inline int
327snd_soc_component_force_bias_level(struct snd_soc_component *component,
328 enum snd_soc_bias_level level)
329{
330 return snd_soc_dapm_force_bias_level(
331 snd_soc_component_get_dapm(component),
332 level);
333}
334
335/**
336 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
337 * kcontrol
338 * @kcontrol: The kcontrol
339 *
340 * This function must only be used on DAPM contexts that are known to be part of
341 * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
342 */
343static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
344 struct snd_kcontrol *kcontrol)
345{
346 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
347}
348
349/**
350 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
351 * @component: COMPONENT to sync
352 *
353 * Note: This function will call regcache_sync()
354 */
355static inline int snd_soc_component_cache_sync(
356 struct snd_soc_component *component)
357{
358 return regcache_sync(component->regmap);
359}
360
361void snd_soc_component_set_aux(struct snd_soc_component *component,
362 struct snd_soc_aux_dev *aux);
363int snd_soc_component_init(struct snd_soc_component *component);
364int snd_soc_component_is_dummy(struct snd_soc_component *component);
365
366/* component IO */
367unsigned int snd_soc_component_read(struct snd_soc_component *component,
368 unsigned int reg);
369int snd_soc_component_write(struct snd_soc_component *component,
370 unsigned int reg, unsigned int val);
371int snd_soc_component_update_bits(struct snd_soc_component *component,
372 unsigned int reg, unsigned int mask,
373 unsigned int val);
374int snd_soc_component_update_bits_async(struct snd_soc_component *component,
375 unsigned int reg, unsigned int mask,
376 unsigned int val);
377void snd_soc_component_async_complete(struct snd_soc_component *component);
378int snd_soc_component_test_bits(struct snd_soc_component *component,
379 unsigned int reg, unsigned int mask,
380 unsigned int value);
381
382unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
383 unsigned int reg, unsigned int mask);
384int snd_soc_component_write_field(struct snd_soc_component *component,
385 unsigned int reg, unsigned int mask,
386 unsigned int val);
387
388/* component wide operations */
389int snd_soc_component_set_sysclk(struct snd_soc_component *component,
390 int clk_id, int source,
391 unsigned int freq, int dir);
392int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
393 int source, unsigned int freq_in,
394 unsigned int freq_out);
395int snd_soc_component_set_jack(struct snd_soc_component *component,
396 struct snd_soc_jack *jack, void *data);
397int snd_soc_component_get_jack_type(struct snd_soc_component *component);
398
399void snd_soc_component_seq_notifier(struct snd_soc_component *component,
400 enum snd_soc_dapm_type type, int subseq);
401int snd_soc_component_stream_event(struct snd_soc_component *component,
402 int event);
403int snd_soc_component_set_bias_level(struct snd_soc_component *component,
404 enum snd_soc_bias_level level);
405
406void snd_soc_component_setup_regmap(struct snd_soc_component *component);
407#ifdef CONFIG_REGMAP
408void snd_soc_component_init_regmap(struct snd_soc_component *component,
409 struct regmap *regmap);
410void snd_soc_component_exit_regmap(struct snd_soc_component *component);
411#endif
412
413#define snd_soc_component_module_get_when_probe(component)\
414 snd_soc_component_module_get(component, NULL, 0)
415#define snd_soc_component_module_get_when_open(component, substream) \
416 snd_soc_component_module_get(component, substream, 1)
417int snd_soc_component_module_get(struct snd_soc_component *component,
418 void *mark, int upon_open);
419#define snd_soc_component_module_put_when_remove(component) \
420 snd_soc_component_module_put(component, NULL, 0, 0)
421#define snd_soc_component_module_put_when_close(component, substream, rollback) \
422 snd_soc_component_module_put(component, substream, 1, rollback)
423void snd_soc_component_module_put(struct snd_soc_component *component,
424 void *mark, int upon_open, int rollback);
425
426static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
427 void *data)
428{
429 dev_set_drvdata(c->dev, data);
430}
431
432static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
433{
434 return dev_get_drvdata(c->dev);
435}
436
437static inline unsigned int
438snd_soc_component_active(struct snd_soc_component *component)
439{
440 return component->active;
441}
442
443/* component pin */
444int snd_soc_component_enable_pin(struct snd_soc_component *component,
445 const char *pin);
446int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
447 const char *pin);
448int snd_soc_component_disable_pin(struct snd_soc_component *component,
449 const char *pin);
450int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
451 const char *pin);
452int snd_soc_component_nc_pin(struct snd_soc_component *component,
453 const char *pin);
454int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
455 const char *pin);
456int snd_soc_component_get_pin_status(struct snd_soc_component *component,
457 const char *pin);
458int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
459 const char *pin);
460int snd_soc_component_force_enable_pin_unlocked(
461 struct snd_soc_component *component,
462 const char *pin);
463
464/* component controls */
465int snd_soc_component_notify_control(struct snd_soc_component *component,
466 const char * const ctl);
467
468/* component driver ops */
469int snd_soc_component_open(struct snd_soc_component *component,
470 struct snd_pcm_substream *substream);
471int snd_soc_component_close(struct snd_soc_component *component,
472 struct snd_pcm_substream *substream,
473 int rollback);
474void snd_soc_component_suspend(struct snd_soc_component *component);
475void snd_soc_component_resume(struct snd_soc_component *component);
476int snd_soc_component_is_suspended(struct snd_soc_component *component);
477int snd_soc_component_probe(struct snd_soc_component *component);
478void snd_soc_component_remove(struct snd_soc_component *component);
479int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
480 struct device_node *ep);
481int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
482 const struct of_phandle_args *args,
483 const char **dai_name);
484int snd_soc_component_compr_open(struct snd_soc_component *component,
485 struct snd_compr_stream *cstream);
486void snd_soc_component_compr_free(struct snd_soc_component *component,
487 struct snd_compr_stream *cstream,
488 int rollback);
489int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
490int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
491 struct snd_compr_params *params);
492int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
493 struct snd_codec *params);
494int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
495 struct snd_compr_caps *caps);
496int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
497 struct snd_compr_codec_caps *codec);
498int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
499int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
500 struct snd_compr_tstamp *tstamp);
501int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
502 char __user *buf, size_t count);
503int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
504 struct snd_compr_metadata *metadata);
505int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
506 struct snd_compr_metadata *metadata);
507
508int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
509int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
510 unsigned int cmd, void *arg);
511int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
512int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream,
513 int channel, unsigned long pos,
514 struct iov_iter *iter, unsigned long bytes);
515struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
516 unsigned long offset);
517int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
518 struct vm_area_struct *vma);
519int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
520void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
521int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
522int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
523 struct snd_pcm_hw_params *params);
524void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
525 int rollback);
526int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
527 int cmd, int rollback);
528int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
529 void *stream);
530void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
531 void *stream, int rollback);
532int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream);
533void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
534 snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
535
536#endif /* __SOC_COMPONENT_H */