]> Git Repo - linux.git/blob - include/sound/soc-component.h
mm/page_alloc: free pages in a single pass during bulk free
[linux.git] / include / sound / 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 <[email protected]>
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 */
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,
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
67 struct 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
102         /* DT */
103         int (*of_xlate_dai_name)(struct snd_soc_component *component,
104                                  const 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);
113
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);
149         int (*ack)(struct snd_soc_component *component,
150                    struct snd_pcm_substream *substream);
151         snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
152                                    struct snd_pcm_substream *substream);
153
154         const struct snd_compress_ops *compress_ops;
155
156         /* probe ordering - for components with runtime dependencies */
157         int probe_order;
158         int remove_order;
159
160         /*
161          * signal if the module handling the component should not be removed
162          * if a pcm is open. Setting this would prevent the module
163          * refcount being incremented in probe() but allow it be incremented
164          * when a pcm is opened and decremented when it is closed.
165          */
166         unsigned int module_get_upon_open:1;
167
168         /* bits */
169         unsigned int idle_bias_on:1;
170         unsigned int suspend_bias_off:1;
171         unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
172         unsigned int endianness:1;
173         unsigned int non_legacy_dai_naming:1;
174
175         /* this component uses topology and ignore machine driver FEs */
176         const char *ignore_machine;
177         const char *topology_name_prefix;
178         int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
179                                   struct snd_pcm_hw_params *params);
180         bool use_dai_pcm_id;    /* use DAI link PCM ID as PCM device number */
181         int be_pcm_base;        /* base device ID for all BE PCMs */
182 };
183
184 struct snd_soc_component {
185         const char *name;
186         int id;
187         const char *name_prefix;
188         struct device *dev;
189         struct snd_soc_card *card;
190
191         unsigned int active;
192
193         unsigned int suspended:1; /* is in suspend PM state */
194
195         struct list_head list;
196         struct list_head card_aux_list; /* for auxiliary bound components */
197         struct list_head card_list;
198
199         const struct snd_soc_component_driver *driver;
200
201         struct list_head dai_list;
202         int num_dai;
203
204         struct regmap *regmap;
205         int val_bytes;
206
207         struct mutex io_mutex;
208
209         /* attached dynamic objects */
210         struct list_head dobj_list;
211
212         /*
213          * DO NOT use any of the fields below in drivers, they are temporary and
214          * are going to be removed again soon. If you use them in driver code
215          * the driver will be marked as BROKEN when these fields are removed.
216          */
217
218         /* Don't use these, use snd_soc_component_get_dapm() */
219         struct snd_soc_dapm_context dapm;
220
221         /* machine specific init */
222         int (*init)(struct snd_soc_component *component);
223
224         /* function mark */
225         void *mark_module;
226         struct snd_pcm_substream *mark_open;
227         struct snd_pcm_substream *mark_hw_params;
228         struct snd_pcm_substream *mark_trigger;
229         struct snd_compr_stream  *mark_compr_open;
230         void *mark_pm;
231
232         struct dentry *debugfs_root;
233         const char *debugfs_prefix;
234 };
235
236 #define for_each_component_dais(component, dai)\
237         list_for_each_entry(dai, &(component)->dai_list, list)
238 #define for_each_component_dais_safe(component, dai, _dai)\
239         list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
240
241 /**
242  * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
243  *  embedded in
244  * @dapm: The DAPM context to cast to the component
245  *
246  * This function must only be used on DAPM contexts that are known to be part of
247  * a component (e.g. in a component driver). Otherwise the behavior is
248  * undefined.
249  */
250 static inline struct snd_soc_component *snd_soc_dapm_to_component(
251         struct snd_soc_dapm_context *dapm)
252 {
253         return container_of(dapm, struct snd_soc_component, dapm);
254 }
255
256 /**
257  * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
258  *  component
259  * @component: The component for which to get the DAPM context
260  */
261 static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
262         struct snd_soc_component *component)
263 {
264         return &component->dapm;
265 }
266
267 /**
268  * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
269  * @component: The COMPONENT for which to initialize the DAPM bias level
270  * @level: The DAPM level to initialize to
271  *
272  * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
273  */
274 static inline void
275 snd_soc_component_init_bias_level(struct snd_soc_component *component,
276                                   enum snd_soc_bias_level level)
277 {
278         snd_soc_dapm_init_bias_level(
279                 snd_soc_component_get_dapm(component), level);
280 }
281
282 /**
283  * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
284  * @component: The COMPONENT for which to get the DAPM bias level
285  *
286  * Returns: The current DAPM bias level of the COMPONENT.
287  */
288 static inline enum snd_soc_bias_level
289 snd_soc_component_get_bias_level(struct snd_soc_component *component)
290 {
291         return snd_soc_dapm_get_bias_level(
292                 snd_soc_component_get_dapm(component));
293 }
294
295 /**
296  * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
297  * @component: The COMPONENT for which to set the level
298  * @level: The level to set to
299  *
300  * Forces the COMPONENT bias level to a specific state. See
301  * snd_soc_dapm_force_bias_level().
302  */
303 static inline int
304 snd_soc_component_force_bias_level(struct snd_soc_component *component,
305                                    enum snd_soc_bias_level level)
306 {
307         return snd_soc_dapm_force_bias_level(
308                 snd_soc_component_get_dapm(component),
309                 level);
310 }
311
312 /**
313  * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
314  * kcontrol
315  * @kcontrol: The kcontrol
316  *
317  * This function must only be used on DAPM contexts that are known to be part of
318  * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
319  */
320 static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
321         struct snd_kcontrol *kcontrol)
322 {
323         return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
324 }
325
326 /**
327  * snd_soc_component_cache_sync() - Sync the register cache with the hardware
328  * @component: COMPONENT to sync
329  *
330  * Note: This function will call regcache_sync()
331  */
332 static inline int snd_soc_component_cache_sync(
333         struct snd_soc_component *component)
334 {
335         return regcache_sync(component->regmap);
336 }
337
338 static inline int snd_soc_component_is_codec(struct snd_soc_component *component)
339 {
340         return component->driver->non_legacy_dai_naming;
341 }
342
343 void snd_soc_component_set_aux(struct snd_soc_component *component,
344                                struct snd_soc_aux_dev *aux);
345 int snd_soc_component_init(struct snd_soc_component *component);
346 int snd_soc_component_is_dummy(struct snd_soc_component *component);
347
348 /* component IO */
349 unsigned int snd_soc_component_read(struct snd_soc_component *component,
350                                       unsigned int reg);
351 int snd_soc_component_write(struct snd_soc_component *component,
352                             unsigned int reg, unsigned int val);
353 int snd_soc_component_update_bits(struct snd_soc_component *component,
354                                   unsigned int reg, unsigned int mask,
355                                   unsigned int val);
356 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
357                                         unsigned int reg, unsigned int mask,
358                                         unsigned int val);
359 void snd_soc_component_async_complete(struct snd_soc_component *component);
360 int snd_soc_component_test_bits(struct snd_soc_component *component,
361                                 unsigned int reg, unsigned int mask,
362                                 unsigned int value);
363
364 unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
365                                           unsigned int reg, unsigned int mask);
366 int snd_soc_component_write_field(struct snd_soc_component *component,
367                                   unsigned int reg, unsigned int mask,
368                                   unsigned int val);
369
370 /* component wide operations */
371 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
372                                  int clk_id, int source,
373                                  unsigned int freq, int dir);
374 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
375                               int source, unsigned int freq_in,
376                               unsigned int freq_out);
377 int snd_soc_component_set_jack(struct snd_soc_component *component,
378                                struct snd_soc_jack *jack, void *data);
379
380 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
381                                     enum snd_soc_dapm_type type, int subseq);
382 int snd_soc_component_stream_event(struct snd_soc_component *component,
383                                    int event);
384 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
385                                      enum snd_soc_bias_level level);
386
387 void snd_soc_component_setup_regmap(struct snd_soc_component *component);
388 #ifdef CONFIG_REGMAP
389 void snd_soc_component_init_regmap(struct snd_soc_component *component,
390                                    struct regmap *regmap);
391 void snd_soc_component_exit_regmap(struct snd_soc_component *component);
392 #endif
393
394 #define snd_soc_component_module_get_when_probe(component)\
395         snd_soc_component_module_get(component, NULL, 0)
396 #define snd_soc_component_module_get_when_open(component, substream)    \
397         snd_soc_component_module_get(component, substream, 1)
398 int snd_soc_component_module_get(struct snd_soc_component *component,
399                                  void *mark, int upon_open);
400 #define snd_soc_component_module_put_when_remove(component)     \
401         snd_soc_component_module_put(component, NULL, 0, 0)
402 #define snd_soc_component_module_put_when_close(component, substream, rollback) \
403         snd_soc_component_module_put(component, substream, 1, rollback)
404 void snd_soc_component_module_put(struct snd_soc_component *component,
405                                   void *mark, int upon_open, int rollback);
406
407 static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
408                                                  void *data)
409 {
410         dev_set_drvdata(c->dev, data);
411 }
412
413 static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
414 {
415         return dev_get_drvdata(c->dev);
416 }
417
418 static inline unsigned int
419 snd_soc_component_active(struct snd_soc_component *component)
420 {
421         return component->active;
422 }
423
424 /* component pin */
425 int snd_soc_component_enable_pin(struct snd_soc_component *component,
426                                  const char *pin);
427 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
428                                           const char *pin);
429 int snd_soc_component_disable_pin(struct snd_soc_component *component,
430                                   const char *pin);
431 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
432                                            const char *pin);
433 int snd_soc_component_nc_pin(struct snd_soc_component *component,
434                              const char *pin);
435 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
436                                       const char *pin);
437 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
438                                      const char *pin);
439 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
440                                        const char *pin);
441 int snd_soc_component_force_enable_pin_unlocked(
442         struct snd_soc_component *component,
443         const char *pin);
444
445 /* component driver ops */
446 int snd_soc_component_open(struct snd_soc_component *component,
447                            struct snd_pcm_substream *substream);
448 int snd_soc_component_close(struct snd_soc_component *component,
449                             struct snd_pcm_substream *substream,
450                             int rollback);
451 void snd_soc_component_suspend(struct snd_soc_component *component);
452 void snd_soc_component_resume(struct snd_soc_component *component);
453 int snd_soc_component_is_suspended(struct snd_soc_component *component);
454 int snd_soc_component_probe(struct snd_soc_component *component);
455 void snd_soc_component_remove(struct snd_soc_component *component);
456 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
457                                       struct device_node *ep);
458 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
459                                         const struct of_phandle_args *args,
460                                         const char **dai_name);
461 int snd_soc_component_compr_open(struct snd_soc_component *component,
462                                  struct snd_compr_stream *cstream);
463 void snd_soc_component_compr_free(struct snd_soc_component *component,
464                                   struct snd_compr_stream *cstream,
465                                   int rollback);
466 int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
467 int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
468                                        struct snd_compr_params *params);
469 int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
470                                        struct snd_codec *params);
471 int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
472                                      struct snd_compr_caps *caps);
473 int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
474                                            struct snd_compr_codec_caps *codec);
475 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
476 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
477                                     struct snd_compr_tstamp *tstamp);
478 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
479                                  char __user *buf, size_t count);
480 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
481                                          struct snd_compr_metadata *metadata);
482 int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
483                                          struct snd_compr_metadata *metadata);
484
485 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
486 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
487                                 unsigned int cmd, void *arg);
488 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
489 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
490                                     int channel, unsigned long pos,
491                                     void __user *buf, unsigned long bytes);
492 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
493                                         unsigned long offset);
494 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
495                                struct vm_area_struct *vma);
496 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
497 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
498 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
499 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
500                                     struct snd_pcm_hw_params *params);
501 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
502                                    int rollback);
503 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
504                                   int cmd, int rollback);
505 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
506                                          void *stream);
507 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
508                                           void *stream, int rollback);
509 int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream);
510 void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
511                                  snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
512
513 #endif /* __SOC_COMPONENT_H */
This page took 0.060779 seconds and 4 git commands to generate.