| 1 | |
| 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 | struct device_link;
|
| 14 |
|
| 15 | |
| 16 | * Component probe and remove ordering levels for components with runtime
|
| 17 | * dependencies.
|
| 18 |
|
| 19 | #define SND_SOC_COMP_ORDER_FIRST -2
|
| 20 | #define SND_SOC_COMP_ORDER_EARLY -1
|
| 21 | #define SND_SOC_COMP_ORDER_NORMAL 0
|
| 22 | #define SND_SOC_COMP_ORDER_LATE 1
|
| 23 | #define SND_SOC_COMP_ORDER_LAST 2
|
| 24 |
|
| 25 | #define for_each_comp_order(order) \
|
| 26 | for (order = SND_SOC_COMP_ORDER_FIRST; \
|
| 27 | order <= SND_SOC_COMP_ORDER_LAST; \
|
| 28 | order++)
|
| 29 |
|
| 30 |
|
| 31 | struct snd_compress_ops {
|
| 32 | int (*open)(struct snd_soc_component *component,
|
| 33 | struct snd_compr_stream *stream);
|
| 34 | int (*free)(struct snd_soc_component *component,
|
| 35 | struct snd_compr_stream *stream);
|
| 36 | int (*set_params)(struct snd_soc_component *component,
|
| 37 | struct snd_compr_stream *stream,
|
| 38 | struct snd_compr_params *params);
|
| 39 | int (*get_params)(struct snd_soc_component *component,
|
| 40 | struct snd_compr_stream *stream,
|
| 41 | struct snd_codec *params);
|
| 42 | int (*set_metadata)(struct snd_soc_component *component,
|
| 43 | struct snd_compr_stream *stream,
|
| 44 | struct snd_compr_metadata *metadata);
|
| 45 | int (*get_metadata)(struct snd_soc_component *component,
|
| 46 | struct snd_compr_stream *stream,
|
| 47 | struct snd_compr_metadata *metadata);
|
| 48 | int (*trigger)(struct snd_soc_component *component,
|
| 49 | struct snd_compr_stream *stream, int cmd);
|
| 50 | int (*pointer)(struct snd_soc_component *component,
|
| 51 | struct snd_compr_stream *stream,
|
| 52 | struct snd_compr_tstamp64 *tstamp);
|
| 53 | int (*copy)(struct snd_soc_component *component,
|
| 54 | struct snd_compr_stream *stream, char __user *buf,
|
| 55 | size_t count);
|
| 56 | int (*mmap)(struct snd_soc_component *component,
|
| 57 | struct snd_compr_stream *stream,
|
| 58 | struct vm_area_struct *vma);
|
| 59 | int (*ack)(struct snd_soc_component *component,
|
| 60 | struct snd_compr_stream *stream, size_t bytes);
|
| 61 | int (*get_caps)(struct snd_soc_component *component,
|
| 62 | struct snd_compr_stream *stream,
|
| 63 | struct snd_compr_caps *caps);
|
| 64 | int (*get_codec_caps)(struct snd_soc_component *component,
|
| 65 | struct snd_compr_stream *stream,
|
| 66 | struct snd_compr_codec_caps *codec);
|
| 67 | };
|
| 68 |
|
| 69 | struct snd_soc_component_driver {
|
| 70 | const char *name;
|
| 71 |
|
| 72 |
|
| 73 | const struct snd_kcontrol_new *controls;
|
| 74 | unsigned int num_controls;
|
| 75 | const struct snd_soc_dapm_widget *dapm_widgets;
|
| 76 | unsigned int num_dapm_widgets;
|
| 77 | const struct snd_soc_dapm_route *dapm_routes;
|
| 78 | unsigned int num_dapm_routes;
|
| 79 |
|
| 80 | int (*probe)(struct snd_soc_component *component);
|
| 81 | int (*fixup_controls)(struct snd_soc_component *component);
|
| 82 | void (*remove)(struct snd_soc_component *component);
|
| 83 | int (*suspend)(struct snd_soc_component *component);
|
| 84 | int (*resume)(struct snd_soc_component *component);
|
| 85 |
|
| 86 | unsigned int (*read)(struct snd_soc_component *component,
|
| 87 | unsigned int reg);
|
| 88 | int (*write)(struct snd_soc_component *component,
|
| 89 | unsigned int reg, unsigned int val);
|
| 90 |
|
| 91 |
|
| 92 | int (*pcm_new)(struct snd_soc_component *component,
|
| 93 | struct snd_soc_pcm_runtime *rtd);
|
| 94 | void (*pcm_free)(struct snd_soc_component *component,
|
| 95 | struct snd_pcm *pcm);
|
| 96 |
|
| 97 |
|
| 98 | int (*set_sysclk)(struct snd_soc_component *component,
|
| 99 | int clk_id, int source, unsigned int freq, int dir);
|
| 100 | int (*set_pll)(struct snd_soc_component *component, int pll_id,
|
| 101 | int source, unsigned int freq_in, unsigned int freq_out);
|
| 102 | int (*set_jack)(struct snd_soc_component *component,
|
| 103 | struct snd_soc_jack *jack, void *data);
|
| 104 | int (*get_jack_type)(struct snd_soc_component *component);
|
| 105 |
|
| 106 |
|
| 107 | int (*of_xlate_dai_name)(struct snd_soc_component *component,
|
| 108 | const struct of_phandle_args *args,
|
| 109 | const char **dai_name);
|
| 110 | int (*of_xlate_dai_id)(struct snd_soc_component *comment,
|
| 111 | struct device_node *endpoint);
|
| 112 | void (*seq_notifier)(struct snd_soc_component *component,
|
| 113 | enum snd_soc_dapm_type type, int subseq);
|
| 114 | int (*stream_event)(struct snd_soc_component *component, int event);
|
| 115 | int (*set_bias_level)(struct snd_soc_component *component,
|
| 116 | enum snd_soc_bias_level level);
|
| 117 |
|
| 118 | int (*open)(struct snd_soc_component *component,
|
| 119 | struct snd_pcm_substream *substream);
|
| 120 | int (*close)(struct snd_soc_component *component,
|
| 121 | struct snd_pcm_substream *substream);
|
| 122 | int (*ioctl)(struct snd_soc_component *component,
|
| 123 | struct snd_pcm_substream *substream,
|
| 124 | unsigned int cmd, void *arg);
|
| 125 | int (*hw_params)(struct snd_soc_component *component,
|
| 126 | struct snd_pcm_substream *substream,
|
| 127 | struct snd_pcm_hw_params *params);
|
| 128 | int (*hw_free)(struct snd_soc_component *component,
|
| 129 | struct snd_pcm_substream *substream);
|
| 130 | int (*prepare)(struct snd_soc_component *component,
|
| 131 | struct snd_pcm_substream *substream);
|
| 132 | int (*trigger)(struct snd_soc_component *component,
|
| 133 | struct snd_pcm_substream *substream, int cmd);
|
| 134 | int (*sync_stop)(struct snd_soc_component *component,
|
| 135 | struct snd_pcm_substream *substream);
|
| 136 | snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
|
| 137 | struct snd_pcm_substream *substream);
|
| 138 | int (*get_time_info)(struct snd_soc_component *component,
|
| 139 | struct snd_pcm_substream *substream, struct timespec64 *system_ts,
|
| 140 | struct timespec64 *audio_ts,
|
| 141 | struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
|
| 142 | struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
|
| 143 | int (*copy)(struct snd_soc_component *component,
|
| 144 | struct snd_pcm_substream *substream, int channel,
|
| 145 | unsigned long pos, struct iov_iter *iter,
|
| 146 | unsigned long bytes);
|
| 147 | struct page *(*page)(struct snd_soc_component *component,
|
| 148 | struct snd_pcm_substream *substream,
|
| 149 | unsigned long offset);
|
| 150 | int (*mmap)(struct snd_soc_component *component,
|
| 151 | struct snd_pcm_substream *substream,
|
| 152 | struct vm_area_struct *vma);
|
| 153 | int (*ack)(struct snd_soc_component *component,
|
| 154 | struct snd_pcm_substream *substream);
|
| 155 | snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
|
| 156 | struct snd_pcm_substream *substream);
|
| 157 |
|
| 158 | const struct snd_compress_ops *compress_ops;
|
| 159 |
|
| 160 |
|
| 161 | int probe_order;
|
| 162 | int remove_order;
|
| 163 |
|
| 164 | |
| 165 | * soc_pcm_trigger() start/stop sequence.
|
| 166 | * see also
|
| 167 | * snd_soc_dai_link
|
| 168 | * soc_pcm_trigger()
|
| 169 |
|
| 170 | enum snd_soc_trigger_order trigger_start;
|
| 171 | enum snd_soc_trigger_order trigger_stop;
|
| 172 |
|
| 173 | |
| 174 | * signal if the module handling the component should not be removed
|
| 175 | * if a pcm is open. Setting this would prevent the module
|
| 176 | * refcount being incremented in probe() but allow it be incremented
|
| 177 | * when a pcm is opened and decremented when it is closed.
|
| 178 |
|
| 179 | unsigned int module_get_upon_open:1;
|
| 180 |
|
| 181 |
|
| 182 | unsigned int idle_bias_on:1;
|
| 183 | unsigned int suspend_bias_off:1;
|
| 184 | unsigned int use_pmdown_time:1;
|
| 185 | |
| 186 | * Indicates that the component does not care about the endianness of
|
| 187 | * PCM audio data and the core will ensure that both LE and BE variants
|
| 188 | * of each used format are present. Typically this is because the
|
| 189 | * component sits behind a bus that abstracts away the endian of the
|
| 190 | * original data, ie. one for which the transmission endian is defined
|
| 191 | * (I2S/SLIMbus/SoundWire), or the concept of endian doesn't exist (PDM,
|
| 192 | * analogue).
|
| 193 |
|
| 194 | unsigned int endianness:1;
|
| 195 | unsigned int legacy_dai_naming:1;
|
| 196 |
|
| 197 |
|
| 198 | const char *ignore_machine;
|
| 199 | const char *topology_name_prefix;
|
| 200 | int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
|
| 201 | struct snd_pcm_hw_params *params);
|
| 202 | bool use_dai_pcm_id;
|
| 203 | int be_pcm_base;
|
| 204 |
|
| 205 | const char *debugfs_prefix;
|
| 206 | };
|
| 207 |
|
| 208 | struct snd_soc_component {
|
| 209 | const char *name;
|
| 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;
|
| 217 |
|
| 218 | struct list_head list;
|
| 219 | struct list_head card_aux_list;
|
| 220 | struct list_head card_list;
|
| 221 |
|
| 222 | struct device_link *card_device_link;
|
| 223 |
|
| 224 | const struct snd_soc_component_driver *driver;
|
| 225 |
|
| 226 | struct list_head dai_list;
|
| 227 | int num_dai;
|
| 228 |
|
| 229 | struct regmap *regmap;
|
| 230 |
|
| 231 | struct mutex io_mutex;
|
| 232 |
|
| 233 |
|
| 234 | struct list_head dobj_list;
|
| 235 |
|
| 236 | |
| 237 | * DO NOT use any of the fields below in drivers, they are temporary and
|
| 238 | * are going to be removed again soon. If you use them in driver code
|
| 239 | * the driver will be marked as BROKEN when these fields are removed.
|
| 240 |
|
| 241 |
|
| 242 | struct snd_soc_dapm_context *dapm;
|
| 243 |
|
| 244 |
|
| 245 | int (*init)(struct snd_soc_component *component);
|
| 246 |
|
| 247 |
|
| 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 |
|
| 257 |
|
| 258 | void *priv;
|
| 259 | };
|
| 260 |
|
| 261 | #define for_each_component_dais(component, dai)\
|
| 262 | list_for_each_entry(dai, &(component)->dai_list, list)
|
| 263 | #define for_each_component_dais_safe(component, dai, _dai)\
|
| 264 | list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
|
| 265 |
|
| 266 | |
| 267 | * snd_soc_component_to_dapm() - Returns the DAPM context associated with a
|
| 268 | * component
|
| 269 | * @component: The component for which to get the DAPM context
|
| 270 |
|
| 271 | static inline struct snd_soc_dapm_context *snd_soc_component_to_dapm(
|
| 272 | struct snd_soc_component *component)
|
| 273 | {
|
| 274 | return component->dapm;
|
| 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 |
|
| 283 | static inline int snd_soc_component_cache_sync(
|
| 284 | struct snd_soc_component *component)
|
| 285 | {
|
| 286 | return regcache_sync(component->regmap);
|
| 287 | }
|
| 288 |
|
| 289 | struct snd_soc_component *snd_soc_component_alloc(struct device *dev);
|
| 290 |
|
| 291 | void snd_soc_component_set_name(struct snd_soc_component *component, const char *name);
|
| 292 | const char *snd_soc_component_name(struct snd_soc_component *component);
|
| 293 |
|
| 294 | void snd_soc_component_set_priv(struct snd_soc_component *component, void *priv);
|
| 295 | void *snd_soc_component_to_priv(struct snd_soc_component *component);
|
| 296 |
|
| 297 | void snd_soc_component_set_aux(struct snd_soc_component *component,
|
| 298 | struct snd_soc_aux_dev *aux);
|
| 299 | int snd_soc_component_init(struct snd_soc_component *component);
|
| 300 | int snd_soc_component_is_dummy(struct snd_soc_component *component);
|
| 301 |
|
| 302 |
|
| 303 | unsigned int snd_soc_component_read(struct snd_soc_component *component,
|
| 304 | unsigned int reg);
|
| 305 | int snd_soc_component_write(struct snd_soc_component *component,
|
| 306 | unsigned int reg, unsigned int val);
|
| 307 | int snd_soc_component_update_bits(struct snd_soc_component *component,
|
| 308 | unsigned int reg, unsigned int mask,
|
| 309 | unsigned int val);
|
| 310 | int snd_soc_component_update_bits_async(struct snd_soc_component *component,
|
| 311 | unsigned int reg, unsigned int mask,
|
| 312 | unsigned int val);
|
| 313 | void snd_soc_component_async_complete(struct snd_soc_component *component);
|
| 314 | int snd_soc_component_test_bits(struct snd_soc_component *component,
|
| 315 | unsigned int reg, unsigned int mask,
|
| 316 | unsigned int value);
|
| 317 |
|
| 318 | unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
|
| 319 | unsigned int reg, unsigned int mask);
|
| 320 | int snd_soc_component_write_field(struct snd_soc_component *component,
|
| 321 | unsigned int reg, unsigned int mask,
|
| 322 | unsigned int val);
|
| 323 |
|
| 324 |
|
| 325 | int snd_soc_component_set_sysclk(struct snd_soc_component *component,
|
| 326 | int clk_id, int source,
|
| 327 | unsigned int freq, int dir);
|
| 328 | int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
|
| 329 | int source, unsigned int freq_in,
|
| 330 | unsigned int freq_out);
|
| 331 | int snd_soc_component_set_jack(struct snd_soc_component *component,
|
| 332 | struct snd_soc_jack *jack, void *data);
|
| 333 | int snd_soc_component_get_jack_type(struct snd_soc_component *component);
|
| 334 |
|
| 335 | void snd_soc_component_seq_notifier(struct snd_soc_component *component,
|
| 336 | enum snd_soc_dapm_type type, int subseq);
|
| 337 | int snd_soc_component_stream_event(struct snd_soc_component *component,
|
| 338 | int event);
|
| 339 | int snd_soc_component_set_bias_level(struct snd_soc_component *component,
|
| 340 | enum snd_soc_bias_level level);
|
| 341 |
|
| 342 | int snd_soc_component_regmap_val_bytes(struct snd_soc_component *component);
|
| 343 | #ifdef CONFIG_REGMAP
|
| 344 | void snd_soc_component_init_regmap(struct snd_soc_component *component,
|
| 345 | struct regmap *regmap);
|
| 346 | void snd_soc_component_exit_regmap(struct snd_soc_component *component);
|
| 347 | #endif
|
| 348 |
|
| 349 | #define snd_soc_component_module_get_when_probe(component)\
|
| 350 | snd_soc_component_module_get(component, NULL, 0)
|
| 351 | #define snd_soc_component_module_get_when_open(component, substream) \
|
| 352 | snd_soc_component_module_get(component, substream, 1)
|
| 353 | int snd_soc_component_module_get(struct snd_soc_component *component,
|
| 354 | void *mark, int upon_open);
|
| 355 | #define snd_soc_component_module_put_when_remove(component) \
|
| 356 | snd_soc_component_module_put(component, NULL, 0, 0)
|
| 357 | #define snd_soc_component_module_put_when_close(component, substream, rollback) \
|
| 358 | snd_soc_component_module_put(component, substream, 1, rollback)
|
| 359 | void snd_soc_component_module_put(struct snd_soc_component *component,
|
| 360 | void *mark, int upon_open, int rollback);
|
| 361 |
|
| 362 | static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
|
| 363 | void *data)
|
| 364 | {
|
| 365 | dev_set_drvdata(c->dev, data);
|
| 366 | }
|
| 367 |
|
| 368 | static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
|
| 369 | {
|
| 370 | return dev_get_drvdata(c->dev);
|
| 371 | }
|
| 372 |
|
| 373 | static inline unsigned int
|
| 374 | snd_soc_component_active(struct snd_soc_component *component)
|
| 375 | {
|
| 376 | return component->active;
|
| 377 | }
|
| 378 |
|
| 379 |
|
| 380 | struct snd_kcontrol *snd_soc_component_get_kcontrol(struct snd_soc_component *component,
|
| 381 | const char * const ctl);
|
| 382 | int snd_soc_component_notify_control(struct snd_soc_component *component,
|
| 383 | const char * const ctl);
|
| 384 |
|
| 385 |
|
| 386 | int snd_soc_component_open(struct snd_soc_component *component,
|
| 387 | struct snd_pcm_substream *substream);
|
| 388 | int snd_soc_component_close(struct snd_soc_component *component,
|
| 389 | struct snd_pcm_substream *substream,
|
| 390 | int rollback);
|
| 391 | void snd_soc_component_suspend(struct snd_soc_component *component);
|
| 392 | void snd_soc_component_resume(struct snd_soc_component *component);
|
| 393 | int snd_soc_component_is_suspended(struct snd_soc_component *component);
|
| 394 | int snd_soc_component_probe(struct snd_soc_component *component);
|
| 395 | int snd_soc_component_fixup_controls(struct snd_soc_component *component);
|
| 396 | void snd_soc_component_remove(struct snd_soc_component *component);
|
| 397 | int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
|
| 398 | struct device_node *ep);
|
| 399 | int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
|
| 400 | const struct of_phandle_args *args,
|
| 401 | const char **dai_name);
|
| 402 | int snd_soc_component_compr_open(struct snd_soc_component *component,
|
| 403 | struct snd_compr_stream *cstream);
|
| 404 | void snd_soc_component_compr_free(struct snd_soc_component *component,
|
| 405 | struct snd_compr_stream *cstream,
|
| 406 | int rollback);
|
| 407 | int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
|
| 408 | int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
|
| 409 | struct snd_compr_params *params);
|
| 410 | int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
|
| 411 | struct snd_codec *params);
|
| 412 | int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
|
| 413 | struct snd_compr_caps *caps);
|
| 414 | int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
|
| 415 | struct snd_compr_codec_caps *codec);
|
| 416 | int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
|
| 417 | int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
|
| 418 | struct snd_compr_tstamp64 *tstamp);
|
| 419 | int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
|
| 420 | char __user *buf, size_t count);
|
| 421 | int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
|
| 422 | struct snd_compr_metadata *metadata);
|
| 423 | int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
|
| 424 | struct snd_compr_metadata *metadata);
|
| 425 |
|
| 426 | int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
|
| 427 | int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
|
| 428 | unsigned int cmd, void *arg);
|
| 429 | int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
|
| 430 | int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream,
|
| 431 | int channel, unsigned long pos,
|
| 432 | struct iov_iter *iter, unsigned long bytes);
|
| 433 | struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
|
| 434 | unsigned long offset);
|
| 435 | int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
|
| 436 | struct vm_area_struct *vma);
|
| 437 | int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
|
| 438 | void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
|
| 439 | int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
|
| 440 | int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
|
| 441 | struct snd_pcm_hw_params *params);
|
| 442 | void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
|
| 443 | int rollback);
|
| 444 | int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
|
| 445 | int cmd, int rollback);
|
| 446 | int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
|
| 447 | void *stream);
|
| 448 | void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
|
| 449 | void *stream, int rollback);
|
| 450 | int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream);
|
| 451 | void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
|
| 452 | snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
|
| 453 |
|
| 454 | #endif
|