0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __SOC_COMPONENT_H
0009 #define __SOC_COMPONENT_H
0010
0011 #include <sound/soc.h>
0012
0013
0014
0015
0016
0017 #define SND_SOC_COMP_ORDER_FIRST -2
0018 #define SND_SOC_COMP_ORDER_EARLY -1
0019 #define SND_SOC_COMP_ORDER_NORMAL 0
0020 #define SND_SOC_COMP_ORDER_LATE 1
0021 #define SND_SOC_COMP_ORDER_LAST 2
0022
0023 #define for_each_comp_order(order) \
0024 for (order = SND_SOC_COMP_ORDER_FIRST; \
0025 order <= SND_SOC_COMP_ORDER_LAST; \
0026 order++)
0027
0028
0029 struct snd_compress_ops {
0030 int (*open)(struct snd_soc_component *component,
0031 struct snd_compr_stream *stream);
0032 int (*free)(struct snd_soc_component *component,
0033 struct snd_compr_stream *stream);
0034 int (*set_params)(struct snd_soc_component *component,
0035 struct snd_compr_stream *stream,
0036 struct snd_compr_params *params);
0037 int (*get_params)(struct snd_soc_component *component,
0038 struct snd_compr_stream *stream,
0039 struct snd_codec *params);
0040 int (*set_metadata)(struct snd_soc_component *component,
0041 struct snd_compr_stream *stream,
0042 struct snd_compr_metadata *metadata);
0043 int (*get_metadata)(struct snd_soc_component *component,
0044 struct snd_compr_stream *stream,
0045 struct snd_compr_metadata *metadata);
0046 int (*trigger)(struct snd_soc_component *component,
0047 struct snd_compr_stream *stream, int cmd);
0048 int (*pointer)(struct snd_soc_component *component,
0049 struct snd_compr_stream *stream,
0050 struct snd_compr_tstamp *tstamp);
0051 int (*copy)(struct snd_soc_component *component,
0052 struct snd_compr_stream *stream, char __user *buf,
0053 size_t count);
0054 int (*mmap)(struct snd_soc_component *component,
0055 struct snd_compr_stream *stream,
0056 struct vm_area_struct *vma);
0057 int (*ack)(struct snd_soc_component *component,
0058 struct snd_compr_stream *stream, size_t bytes);
0059 int (*get_caps)(struct snd_soc_component *component,
0060 struct snd_compr_stream *stream,
0061 struct snd_compr_caps *caps);
0062 int (*get_codec_caps)(struct snd_soc_component *component,
0063 struct snd_compr_stream *stream,
0064 struct snd_compr_codec_caps *codec);
0065 };
0066
0067 struct snd_soc_component_driver {
0068 const char *name;
0069
0070
0071 const struct snd_kcontrol_new *controls;
0072 unsigned int num_controls;
0073 const struct snd_soc_dapm_widget *dapm_widgets;
0074 unsigned int num_dapm_widgets;
0075 const struct snd_soc_dapm_route *dapm_routes;
0076 unsigned int num_dapm_routes;
0077
0078 int (*probe)(struct snd_soc_component *component);
0079 void (*remove)(struct snd_soc_component *component);
0080 int (*suspend)(struct snd_soc_component *component);
0081 int (*resume)(struct snd_soc_component *component);
0082
0083 unsigned int (*read)(struct snd_soc_component *component,
0084 unsigned int reg);
0085 int (*write)(struct snd_soc_component *component,
0086 unsigned int reg, unsigned int val);
0087
0088
0089 int (*pcm_construct)(struct snd_soc_component *component,
0090 struct snd_soc_pcm_runtime *rtd);
0091 void (*pcm_destruct)(struct snd_soc_component *component,
0092 struct snd_pcm *pcm);
0093
0094
0095 int (*set_sysclk)(struct snd_soc_component *component,
0096 int clk_id, int source, unsigned int freq, int dir);
0097 int (*set_pll)(struct snd_soc_component *component, int pll_id,
0098 int source, unsigned int freq_in, unsigned int freq_out);
0099 int (*set_jack)(struct snd_soc_component *component,
0100 struct snd_soc_jack *jack, void *data);
0101
0102
0103 int (*of_xlate_dai_name)(struct snd_soc_component *component,
0104 const struct of_phandle_args *args,
0105 const char **dai_name);
0106 int (*of_xlate_dai_id)(struct snd_soc_component *comment,
0107 struct device_node *endpoint);
0108 void (*seq_notifier)(struct snd_soc_component *component,
0109 enum snd_soc_dapm_type type, int subseq);
0110 int (*stream_event)(struct snd_soc_component *component, int event);
0111 int (*set_bias_level)(struct snd_soc_component *component,
0112 enum snd_soc_bias_level level);
0113
0114 int (*open)(struct snd_soc_component *component,
0115 struct snd_pcm_substream *substream);
0116 int (*close)(struct snd_soc_component *component,
0117 struct snd_pcm_substream *substream);
0118 int (*ioctl)(struct snd_soc_component *component,
0119 struct snd_pcm_substream *substream,
0120 unsigned int cmd, void *arg);
0121 int (*hw_params)(struct snd_soc_component *component,
0122 struct snd_pcm_substream *substream,
0123 struct snd_pcm_hw_params *params);
0124 int (*hw_free)(struct snd_soc_component *component,
0125 struct snd_pcm_substream *substream);
0126 int (*prepare)(struct snd_soc_component *component,
0127 struct snd_pcm_substream *substream);
0128 int (*trigger)(struct snd_soc_component *component,
0129 struct snd_pcm_substream *substream, int cmd);
0130 int (*sync_stop)(struct snd_soc_component *component,
0131 struct snd_pcm_substream *substream);
0132 snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
0133 struct snd_pcm_substream *substream);
0134 int (*get_time_info)(struct snd_soc_component *component,
0135 struct snd_pcm_substream *substream, struct timespec64 *system_ts,
0136 struct timespec64 *audio_ts,
0137 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
0138 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
0139 int (*copy_user)(struct snd_soc_component *component,
0140 struct snd_pcm_substream *substream, int channel,
0141 unsigned long pos, void __user *buf,
0142 unsigned long bytes);
0143 struct page *(*page)(struct snd_soc_component *component,
0144 struct snd_pcm_substream *substream,
0145 unsigned long offset);
0146 int (*mmap)(struct snd_soc_component *component,
0147 struct snd_pcm_substream *substream,
0148 struct vm_area_struct *vma);
0149 int (*ack)(struct snd_soc_component *component,
0150 struct snd_pcm_substream *substream);
0151 snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
0152 struct snd_pcm_substream *substream);
0153
0154 const struct snd_compress_ops *compress_ops;
0155
0156
0157 int probe_order;
0158 int remove_order;
0159
0160
0161
0162
0163
0164
0165
0166 unsigned int module_get_upon_open:1;
0167
0168
0169 unsigned int idle_bias_on:1;
0170 unsigned int suspend_bias_off:1;
0171 unsigned int use_pmdown_time:1;
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 unsigned int endianness:1;
0182 unsigned int legacy_dai_naming:1;
0183
0184
0185 const char *ignore_machine;
0186 const char *topology_name_prefix;
0187 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
0188 struct snd_pcm_hw_params *params);
0189 bool use_dai_pcm_id;
0190 int be_pcm_base;
0191
0192 #ifdef CONFIG_DEBUG_FS
0193 const char *debugfs_prefix;
0194 #endif
0195 };
0196
0197 struct snd_soc_component {
0198 const char *name;
0199 int id;
0200 const char *name_prefix;
0201 struct device *dev;
0202 struct snd_soc_card *card;
0203
0204 unsigned int active;
0205
0206 unsigned int suspended:1;
0207
0208 struct list_head list;
0209 struct list_head card_aux_list;
0210 struct list_head card_list;
0211
0212 const struct snd_soc_component_driver *driver;
0213
0214 struct list_head dai_list;
0215 int num_dai;
0216
0217 struct regmap *regmap;
0218 int val_bytes;
0219
0220 struct mutex io_mutex;
0221
0222
0223 struct list_head dobj_list;
0224
0225
0226
0227
0228
0229
0230
0231
0232 struct snd_soc_dapm_context dapm;
0233
0234
0235 int (*init)(struct snd_soc_component *component);
0236
0237
0238 void *mark_module;
0239 struct snd_pcm_substream *mark_open;
0240 struct snd_pcm_substream *mark_hw_params;
0241 struct snd_pcm_substream *mark_trigger;
0242 struct snd_compr_stream *mark_compr_open;
0243 void *mark_pm;
0244
0245 struct dentry *debugfs_root;
0246 const char *debugfs_prefix;
0247 };
0248
0249 #define for_each_component_dais(component, dai)\
0250 list_for_each_entry(dai, &(component)->dai_list, list)
0251 #define for_each_component_dais_safe(component, dai, _dai)\
0252 list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 static inline struct snd_soc_component *snd_soc_dapm_to_component(
0264 struct snd_soc_dapm_context *dapm)
0265 {
0266 return container_of(dapm, struct snd_soc_component, dapm);
0267 }
0268
0269
0270
0271
0272
0273
0274 static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
0275 struct snd_soc_component *component)
0276 {
0277 return &component->dapm;
0278 }
0279
0280
0281
0282
0283
0284
0285
0286
0287 static inline void
0288 snd_soc_component_init_bias_level(struct snd_soc_component *component,
0289 enum snd_soc_bias_level level)
0290 {
0291 snd_soc_dapm_init_bias_level(
0292 snd_soc_component_get_dapm(component), level);
0293 }
0294
0295
0296
0297
0298
0299
0300
0301 static inline enum snd_soc_bias_level
0302 snd_soc_component_get_bias_level(struct snd_soc_component *component)
0303 {
0304 return snd_soc_dapm_get_bias_level(
0305 snd_soc_component_get_dapm(component));
0306 }
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316 static inline int
0317 snd_soc_component_force_bias_level(struct snd_soc_component *component,
0318 enum snd_soc_bias_level level)
0319 {
0320 return snd_soc_dapm_force_bias_level(
0321 snd_soc_component_get_dapm(component),
0322 level);
0323 }
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333 static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
0334 struct snd_kcontrol *kcontrol)
0335 {
0336 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
0337 }
0338
0339
0340
0341
0342
0343
0344
0345 static inline int snd_soc_component_cache_sync(
0346 struct snd_soc_component *component)
0347 {
0348 return regcache_sync(component->regmap);
0349 }
0350
0351 void snd_soc_component_set_aux(struct snd_soc_component *component,
0352 struct snd_soc_aux_dev *aux);
0353 int snd_soc_component_init(struct snd_soc_component *component);
0354 int snd_soc_component_is_dummy(struct snd_soc_component *component);
0355
0356
0357 unsigned int snd_soc_component_read(struct snd_soc_component *component,
0358 unsigned int reg);
0359 int snd_soc_component_write(struct snd_soc_component *component,
0360 unsigned int reg, unsigned int val);
0361 int snd_soc_component_update_bits(struct snd_soc_component *component,
0362 unsigned int reg, unsigned int mask,
0363 unsigned int val);
0364 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
0365 unsigned int reg, unsigned int mask,
0366 unsigned int val);
0367 void snd_soc_component_async_complete(struct snd_soc_component *component);
0368 int snd_soc_component_test_bits(struct snd_soc_component *component,
0369 unsigned int reg, unsigned int mask,
0370 unsigned int value);
0371
0372 unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
0373 unsigned int reg, unsigned int mask);
0374 int snd_soc_component_write_field(struct snd_soc_component *component,
0375 unsigned int reg, unsigned int mask,
0376 unsigned int val);
0377
0378
0379 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
0380 int clk_id, int source,
0381 unsigned int freq, int dir);
0382 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
0383 int source, unsigned int freq_in,
0384 unsigned int freq_out);
0385 int snd_soc_component_set_jack(struct snd_soc_component *component,
0386 struct snd_soc_jack *jack, void *data);
0387
0388 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
0389 enum snd_soc_dapm_type type, int subseq);
0390 int snd_soc_component_stream_event(struct snd_soc_component *component,
0391 int event);
0392 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
0393 enum snd_soc_bias_level level);
0394
0395 void snd_soc_component_setup_regmap(struct snd_soc_component *component);
0396 #ifdef CONFIG_REGMAP
0397 void snd_soc_component_init_regmap(struct snd_soc_component *component,
0398 struct regmap *regmap);
0399 void snd_soc_component_exit_regmap(struct snd_soc_component *component);
0400 #endif
0401
0402 #define snd_soc_component_module_get_when_probe(component)\
0403 snd_soc_component_module_get(component, NULL, 0)
0404 #define snd_soc_component_module_get_when_open(component, substream) \
0405 snd_soc_component_module_get(component, substream, 1)
0406 int snd_soc_component_module_get(struct snd_soc_component *component,
0407 void *mark, int upon_open);
0408 #define snd_soc_component_module_put_when_remove(component) \
0409 snd_soc_component_module_put(component, NULL, 0, 0)
0410 #define snd_soc_component_module_put_when_close(component, substream, rollback) \
0411 snd_soc_component_module_put(component, substream, 1, rollback)
0412 void snd_soc_component_module_put(struct snd_soc_component *component,
0413 void *mark, int upon_open, int rollback);
0414
0415 static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
0416 void *data)
0417 {
0418 dev_set_drvdata(c->dev, data);
0419 }
0420
0421 static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
0422 {
0423 return dev_get_drvdata(c->dev);
0424 }
0425
0426 static inline unsigned int
0427 snd_soc_component_active(struct snd_soc_component *component)
0428 {
0429 return component->active;
0430 }
0431
0432
0433 int snd_soc_component_enable_pin(struct snd_soc_component *component,
0434 const char *pin);
0435 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
0436 const char *pin);
0437 int snd_soc_component_disable_pin(struct snd_soc_component *component,
0438 const char *pin);
0439 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
0440 const char *pin);
0441 int snd_soc_component_nc_pin(struct snd_soc_component *component,
0442 const char *pin);
0443 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
0444 const char *pin);
0445 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
0446 const char *pin);
0447 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
0448 const char *pin);
0449 int snd_soc_component_force_enable_pin_unlocked(
0450 struct snd_soc_component *component,
0451 const char *pin);
0452
0453
0454 int snd_soc_component_open(struct snd_soc_component *component,
0455 struct snd_pcm_substream *substream);
0456 int snd_soc_component_close(struct snd_soc_component *component,
0457 struct snd_pcm_substream *substream,
0458 int rollback);
0459 void snd_soc_component_suspend(struct snd_soc_component *component);
0460 void snd_soc_component_resume(struct snd_soc_component *component);
0461 int snd_soc_component_is_suspended(struct snd_soc_component *component);
0462 int snd_soc_component_probe(struct snd_soc_component *component);
0463 void snd_soc_component_remove(struct snd_soc_component *component);
0464 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
0465 struct device_node *ep);
0466 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
0467 const struct of_phandle_args *args,
0468 const char **dai_name);
0469 int snd_soc_component_compr_open(struct snd_soc_component *component,
0470 struct snd_compr_stream *cstream);
0471 void snd_soc_component_compr_free(struct snd_soc_component *component,
0472 struct snd_compr_stream *cstream,
0473 int rollback);
0474 int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
0475 int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
0476 struct snd_compr_params *params);
0477 int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
0478 struct snd_codec *params);
0479 int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
0480 struct snd_compr_caps *caps);
0481 int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
0482 struct snd_compr_codec_caps *codec);
0483 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
0484 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
0485 struct snd_compr_tstamp *tstamp);
0486 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
0487 char __user *buf, size_t count);
0488 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
0489 struct snd_compr_metadata *metadata);
0490 int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
0491 struct snd_compr_metadata *metadata);
0492
0493 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
0494 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
0495 unsigned int cmd, void *arg);
0496 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
0497 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
0498 int channel, unsigned long pos,
0499 void __user *buf, unsigned long bytes);
0500 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
0501 unsigned long offset);
0502 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
0503 struct vm_area_struct *vma);
0504 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
0505 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
0506 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
0507 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
0508 struct snd_pcm_hw_params *params);
0509 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
0510 int rollback);
0511 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
0512 int cmd, int rollback);
0513 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
0514 void *stream);
0515 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
0516 void *stream, int rollback);
0517 int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream);
0518 void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
0519 snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
0520
0521 #endif