linux/include/sound/soc-component.h
<<
>>
Prefs
   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#ifndef __SOC_COMPONENT_H
   8#define __SOC_COMPONENT_H
   9
  10#include <sound/soc.h>
  11
  12/*
  13 * Component probe and remove ordering levels for components with runtime
  14 * dependencies.
  15 */
  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
  21
  22#define for_each_comp_order(order)              \
  23        for (order  = SND_SOC_COMP_ORDER_FIRST; \
  24             order <= SND_SOC_COMP_ORDER_LAST;  \
  25             order++)
  26
  27/* component interface */
  28struct snd_soc_component_driver {
  29        const char *name;
  30
  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;
  38
  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);
  43
  44        unsigned int (*read)(struct snd_soc_component *component,
  45                             unsigned int reg);
  46        int (*write)(struct snd_soc_component *component,
  47                     unsigned int reg, unsigned int val);
  48
  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,
  53                             struct snd_pcm *pcm);
  54
  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);
  62
  63        /* DT */
  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);
  74
  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 timespec *system_ts,
  97                struct timespec *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);
 110
 111        const struct snd_compr_ops *compr_ops;
 112
 113        /* probe ordering - for components with runtime dependencies */
 114        int probe_order;
 115        int remove_order;
 116
 117        /*
 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.
 122         */
 123        unsigned int module_get_upon_open:1;
 124
 125        /* bits */
 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;
 131
 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 */
 139};
 140
 141struct snd_soc_component {
 142        const char *name;
 143        int id;
 144        const char *name_prefix;
 145        struct device *dev;
 146        struct snd_soc_card *card;
 147
 148        unsigned int active;
 149
 150        unsigned int suspended:1; /* is in suspend PM state */
 151
 152        struct list_head list;
 153        struct list_head card_aux_list; /* for auxiliary bound components */
 154        struct list_head card_list;
 155
 156        const struct snd_soc_component_driver *driver;
 157
 158        struct list_head dai_list;
 159        int num_dai;
 160
 161        struct regmap *regmap;
 162        int val_bytes;
 163
 164        struct mutex io_mutex;
 165
 166        /* attached dynamic objects */
 167        struct list_head dobj_list;
 168
 169        /*
 170         * DO NOT use any of the fields below in drivers, they are temporary and
 171         * are going to be removed again soon. If you use them in driver code
 172         * the driver will be marked as BROKEN when these fields are removed.
 173         */
 174
 175        /* Don't use these, use snd_soc_component_get_dapm() */
 176        struct snd_soc_dapm_context dapm;
 177
 178        /* machine specific init */
 179        int (*init)(struct snd_soc_component *component);
 180
 181#ifdef CONFIG_DEBUG_FS
 182        struct dentry *debugfs_root;
 183        const char *debugfs_prefix;
 184#endif
 185};
 186
 187#define for_each_component_dais(component, dai)\
 188        list_for_each_entry(dai, &(component)->dai_list, list)
 189#define for_each_component_dais_safe(component, dai, _dai)\
 190        list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
 191
 192/**
 193 * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
 194 *  embedded in
 195 * @dapm: The DAPM context to cast to the component
 196 *
 197 * This function must only be used on DAPM contexts that are known to be part of
 198 * a component (e.g. in a component driver). Otherwise the behavior is
 199 * undefined.
 200 */
 201static inline struct snd_soc_component *snd_soc_dapm_to_component(
 202        struct snd_soc_dapm_context *dapm)
 203{
 204        return container_of(dapm, struct snd_soc_component, dapm);
 205}
 206
 207/**
 208 * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
 209 *  component
 210 * @component: The component for which to get the DAPM context
 211 */
 212static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
 213        struct snd_soc_component *component)
 214{
 215        return &component->dapm;
 216}
 217
 218/**
 219 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
 220 * @component: The COMPONENT for which to initialize the DAPM bias level
 221 * @level: The DAPM level to initialize to
 222 *
 223 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
 224 */
 225static inline void
 226snd_soc_component_init_bias_level(struct snd_soc_component *component,
 227                                  enum snd_soc_bias_level level)
 228{
 229        snd_soc_dapm_init_bias_level(
 230                snd_soc_component_get_dapm(component), level);
 231}
 232
 233/**
 234 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
 235 * @component: The COMPONENT for which to get the DAPM bias level
 236 *
 237 * Returns: The current DAPM bias level of the COMPONENT.
 238 */
 239static inline enum snd_soc_bias_level
 240snd_soc_component_get_bias_level(struct snd_soc_component *component)
 241{
 242        return snd_soc_dapm_get_bias_level(
 243                snd_soc_component_get_dapm(component));
 244}
 245
 246/**
 247 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
 248 * @component: The COMPONENT for which to set the level
 249 * @level: The level to set to
 250 *
 251 * Forces the COMPONENT bias level to a specific state. See
 252 * snd_soc_dapm_force_bias_level().
 253 */
 254static inline int
 255snd_soc_component_force_bias_level(struct snd_soc_component *component,
 256                                   enum snd_soc_bias_level level)
 257{
 258        return snd_soc_dapm_force_bias_level(
 259                snd_soc_component_get_dapm(component),
 260                level);
 261}
 262
 263/**
 264 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
 265 * kcontrol
 266 * @kcontrol: The kcontrol
 267 *
 268 * This function must only be used on DAPM contexts that are known to be part of
 269 * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
 270 */
 271static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
 272        struct snd_kcontrol *kcontrol)
 273{
 274        return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
 275}
 276
 277/**
 278 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
 279 * @component: COMPONENT to sync
 280 *
 281 * Note: This function will call regcache_sync()
 282 */
 283static inline int snd_soc_component_cache_sync(
 284        struct snd_soc_component *component)
 285{
 286        return regcache_sync(component->regmap);
 287}
 288
 289/* component IO */
 290int snd_soc_component_read(struct snd_soc_component *component,
 291                           unsigned int reg, unsigned int *val);
 292unsigned int snd_soc_component_read32(struct snd_soc_component *component,
 293                                      unsigned int reg);
 294int snd_soc_component_write(struct snd_soc_component *component,
 295                            unsigned int reg, unsigned int val);
 296int snd_soc_component_update_bits(struct snd_soc_component *component,
 297                                  unsigned int reg, unsigned int mask,
 298                                  unsigned int val);
 299int snd_soc_component_update_bits_async(struct snd_soc_component *component,
 300                                        unsigned int reg, unsigned int mask,
 301                                        unsigned int val);
 302void snd_soc_component_async_complete(struct snd_soc_component *component);
 303int snd_soc_component_test_bits(struct snd_soc_component *component,
 304                                unsigned int reg, unsigned int mask,
 305                                unsigned int value);
 306
 307/* component wide operations */
 308int snd_soc_component_set_sysclk(struct snd_soc_component *component,
 309                                 int clk_id, int source,
 310                                 unsigned int freq, int dir);
 311int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
 312                              int source, unsigned int freq_in,
 313                              unsigned int freq_out);
 314int snd_soc_component_set_jack(struct snd_soc_component *component,
 315                               struct snd_soc_jack *jack, void *data);
 316
 317void snd_soc_component_seq_notifier(struct snd_soc_component *component,
 318                                    enum snd_soc_dapm_type type, int subseq);
 319int snd_soc_component_stream_event(struct snd_soc_component *component,
 320                                   int event);
 321int snd_soc_component_set_bias_level(struct snd_soc_component *component,
 322                                     enum snd_soc_bias_level level);
 323
 324#ifdef CONFIG_REGMAP
 325void snd_soc_component_init_regmap(struct snd_soc_component *component,
 326                                   struct regmap *regmap);
 327void snd_soc_component_exit_regmap(struct snd_soc_component *component);
 328#endif
 329
 330#define snd_soc_component_module_get_when_probe(component)\
 331        snd_soc_component_module_get(component, 0)
 332#define snd_soc_component_module_get_when_open(component)       \
 333        snd_soc_component_module_get(component, 1)
 334int snd_soc_component_module_get(struct snd_soc_component *component,
 335                                 int upon_open);
 336#define snd_soc_component_module_put_when_remove(component)     \
 337        snd_soc_component_module_put(component, 0)
 338#define snd_soc_component_module_put_when_close(component)      \
 339        snd_soc_component_module_put(component, 1)
 340void snd_soc_component_module_put(struct snd_soc_component *component,
 341                                  int upon_open);
 342
 343static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
 344                                                 void *data)
 345{
 346        dev_set_drvdata(c->dev, data);
 347}
 348
 349static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
 350{
 351        return dev_get_drvdata(c->dev);
 352}
 353
 354static inline bool snd_soc_component_is_active(
 355        struct snd_soc_component *component)
 356{
 357        return component->active != 0;
 358}
 359
 360/* component pin */
 361int snd_soc_component_enable_pin(struct snd_soc_component *component,
 362                                 const char *pin);
 363int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
 364                                          const char *pin);
 365int snd_soc_component_disable_pin(struct snd_soc_component *component,
 366                                  const char *pin);
 367int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
 368                                           const char *pin);
 369int snd_soc_component_nc_pin(struct snd_soc_component *component,
 370                             const char *pin);
 371int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
 372                                      const char *pin);
 373int snd_soc_component_get_pin_status(struct snd_soc_component *component,
 374                                     const char *pin);
 375int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
 376                                       const char *pin);
 377int snd_soc_component_force_enable_pin_unlocked(
 378        struct snd_soc_component *component,
 379        const char *pin);
 380
 381/* component driver ops */
 382int snd_soc_component_open(struct snd_soc_component *component,
 383                           struct snd_pcm_substream *substream);
 384int snd_soc_component_close(struct snd_soc_component *component,
 385                            struct snd_pcm_substream *substream);
 386int snd_soc_component_prepare(struct snd_soc_component *component,
 387                              struct snd_pcm_substream *substream);
 388int snd_soc_component_hw_params(struct snd_soc_component *component,
 389                                struct snd_pcm_substream *substream,
 390                                struct snd_pcm_hw_params *params);
 391int snd_soc_component_hw_free(struct snd_soc_component *component,
 392                              struct snd_pcm_substream *substream);
 393int snd_soc_component_trigger(struct snd_soc_component *component,
 394                              struct snd_pcm_substream *substream,
 395                              int cmd);
 396void snd_soc_component_suspend(struct snd_soc_component *component);
 397void snd_soc_component_resume(struct snd_soc_component *component);
 398int snd_soc_component_is_suspended(struct snd_soc_component *component);
 399int snd_soc_component_probe(struct snd_soc_component *component);
 400void snd_soc_component_remove(struct snd_soc_component *component);
 401int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
 402                                      struct device_node *ep);
 403int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
 404                                        struct of_phandle_args *args,
 405                                        const char **dai_name);
 406
 407int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
 408int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
 409                                unsigned int cmd, void *arg);
 410int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
 411int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
 412                                    int channel, unsigned long pos,
 413                                    void __user *buf, unsigned long bytes);
 414struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
 415                                        unsigned long offset);
 416int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
 417                               struct vm_area_struct *vma);
 418int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
 419void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
 420
 421#endif /* __SOC_COMPONENT_H */
 422