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 */ 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_tstamp64 *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 int (*pcm_new)(struct snd_soc_component *component, 94 struct snd_soc_pcm_runtime *rtd); 95 void (*pcm_free)(struct snd_soc_component *component, 96 struct snd_pcm *pcm); 97 98 /* component wide operations */ 99 int (*set_sysclk)(struct snd_soc_component *component, 100 int clk_id, int source, unsigned int freq, int dir); 101 int (*set_pll)(struct snd_soc_component *component, int pll_id, 102 int source, unsigned int freq_in, unsigned int freq_out); 103 int (*set_jack)(struct snd_soc_component *component, 104 struct snd_soc_jack *jack, void *data); 105 int (*get_jack_type)(struct snd_soc_component *component); 106 107 /* DT */ 108 int (*of_xlate_dai_name)(struct snd_soc_component *component, 109 const struct of_phandle_args *args, 110 const char **dai_name); 111 int (*of_xlate_dai_id)(struct snd_soc_component *comment, 112 struct device_node *endpoint); 113 void (*seq_notifier)(struct snd_soc_component *component, 114 enum snd_soc_dapm_type type, int subseq); 115 int (*stream_event)(struct snd_soc_component *component, int event); 116 int (*set_bias_level)(struct snd_soc_component *component, 117 enum snd_soc_bias_level level); 118 119 int (*open)(struct snd_soc_component *component, 120 struct snd_pcm_substream *substream); 121 int (*close)(struct snd_soc_component *component, 122 struct snd_pcm_substream *substream); 123 int (*ioctl)(struct snd_soc_component *component, 124 struct snd_pcm_substream *substream, 125 unsigned int cmd, void *arg); 126 int (*hw_params)(struct snd_soc_component *component, 127 struct snd_pcm_substream *substream, 128 struct snd_pcm_hw_params *params); 129 int (*hw_free)(struct snd_soc_component *component, 130 struct snd_pcm_substream *substream); 131 int (*prepare)(struct snd_soc_component *component, 132 struct snd_pcm_substream *substream); 133 int (*trigger)(struct snd_soc_component *component, 134 struct snd_pcm_substream *substream, int cmd); 135 int (*sync_stop)(struct snd_soc_component *component, 136 struct snd_pcm_substream *substream); 137 snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component, 138 struct snd_pcm_substream *substream); 139 int (*get_time_info)(struct snd_soc_component *component, 140 struct snd_pcm_substream *substream, struct timespec64 *system_ts, 141 struct timespec64 *audio_ts, 142 struct snd_pcm_audio_tstamp_config *audio_tstamp_config, 143 struct snd_pcm_audio_tstamp_report *audio_tstamp_report); 144 int (*copy)(struct snd_soc_component *component, 145 struct snd_pcm_substream *substream, int channel, 146 unsigned long pos, struct iov_iter *iter, 147 unsigned long bytes); 148 struct page *(*page)(struct snd_soc_component *component, 149 struct snd_pcm_substream *substream, 150 unsigned long offset); 151 int (*mmap)(struct snd_soc_component *component, 152 struct snd_pcm_substream *substream, 153 struct vm_area_struct *vma); 154 int (*ack)(struct snd_soc_component *component, 155 struct snd_pcm_substream *substream); 156 snd_pcm_sframes_t (*delay)(struct snd_soc_component *component, 157 struct snd_pcm_substream *substream); 158 159 const struct snd_compress_ops *compress_ops; 160 161 /* probe ordering - for components with runtime dependencies */ 162 int probe_order; 163 int remove_order; 164 165 /* 166 * soc_pcm_trigger() start/stop sequence. 167 * see also 168 * snd_soc_dai_link 169 * soc_pcm_trigger() 170 */ 171 enum snd_soc_trigger_order trigger_start; 172 enum snd_soc_trigger_order trigger_stop; 173 174 /* 175 * signal if the module handling the component should not be removed 176 * if a pcm is open. Setting this would prevent the module 177 * refcount being incremented in probe() but allow it be incremented 178 * when a pcm is opened and decremented when it is closed. 179 */ 180 unsigned int module_get_upon_open:1; 181 182 /* bits */ 183 unsigned int idle_bias_on:1; 184 unsigned int suspend_bias_off:1; 185 unsigned int use_pmdown_time:1; /* care pmdown_time at stop */ 186 /* 187 * Indicates that the component does not care about the endianness of 188 * PCM audio data and the core will ensure that both LE and BE variants 189 * of each used format are present. Typically this is because the 190 * component sits behind a bus that abstracts away the endian of the 191 * original data, ie. one for which the transmission endian is defined 192 * (I2S/SLIMbus/SoundWire), or the concept of endian doesn't exist (PDM, 193 * analogue). 194 */ 195 unsigned int endianness:1; 196 unsigned int legacy_dai_naming:1; 197 198 /* this component uses topology and ignore machine driver FEs */ 199 const char *ignore_machine; 200 const char *topology_name_prefix; 201 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd, 202 struct snd_pcm_hw_params *params); 203 bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */ 204 int be_pcm_base; /* base device ID for all BE PCMs */ 205 206 #ifdef CONFIG_DEBUG_FS 207 const char *debugfs_prefix; 208 #endif 209 }; 210 211 struct snd_soc_component { 212 const char *name; 213 const char *name_prefix; 214 struct device *dev; 215 struct snd_soc_card *card; 216 217 unsigned int active; 218 219 unsigned int suspended:1; /* is in suspend PM state */ 220 221 struct list_head list; 222 struct list_head card_aux_list; /* for auxiliary bound components */ 223 struct list_head card_list; 224 225 const struct snd_soc_component_driver *driver; 226 227 struct list_head dai_list; 228 int num_dai; 229 230 struct regmap *regmap; 231 int val_bytes; 232 233 struct mutex io_mutex; 234 235 /* attached dynamic objects */ 236 struct list_head dobj_list; 237 238 /* 239 * DO NOT use any of the fields below in drivers, they are temporary and 240 * are going to be removed again soon. If you use them in driver code 241 * the driver will be marked as BROKEN when these fields are removed. 242 */ 243 244 struct snd_soc_dapm_context *dapm; 245 246 /* machine specific init */ 247 int (*init)(struct snd_soc_component *component); 248 249 /* function mark */ 250 void *mark_module; 251 struct snd_pcm_substream *mark_open; 252 struct snd_pcm_substream *mark_hw_params; 253 struct snd_pcm_substream *mark_trigger; 254 struct snd_compr_stream *mark_compr_open; 255 void *mark_pm; 256 257 struct dentry *debugfs_root; 258 const char *debugfs_prefix; 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 void snd_soc_component_set_aux(struct snd_soc_component *component, 290 struct snd_soc_aux_dev *aux); 291 int snd_soc_component_init(struct snd_soc_component *component); 292 int snd_soc_component_is_dummy(struct snd_soc_component *component); 293 294 /* component IO */ 295 unsigned int snd_soc_component_read(struct snd_soc_component *component, 296 unsigned int reg); 297 int snd_soc_component_write(struct snd_soc_component *component, 298 unsigned int reg, unsigned int val); 299 int snd_soc_component_update_bits(struct snd_soc_component *component, 300 unsigned int reg, unsigned int mask, 301 unsigned int val); 302 int snd_soc_component_update_bits_async(struct snd_soc_component *component, 303 unsigned int reg, unsigned int mask, 304 unsigned int val); 305 void snd_soc_component_async_complete(struct snd_soc_component *component); 306 int snd_soc_component_test_bits(struct snd_soc_component *component, 307 unsigned int reg, unsigned int mask, 308 unsigned int value); 309 310 unsigned int snd_soc_component_read_field(struct snd_soc_component *component, 311 unsigned int reg, unsigned int mask); 312 int snd_soc_component_write_field(struct snd_soc_component *component, 313 unsigned int reg, unsigned int mask, 314 unsigned int val); 315 316 /* component wide operations */ 317 int snd_soc_component_set_sysclk(struct snd_soc_component *component, 318 int clk_id, int source, 319 unsigned int freq, int dir); 320 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, 321 int source, unsigned int freq_in, 322 unsigned int freq_out); 323 int snd_soc_component_set_jack(struct snd_soc_component *component, 324 struct snd_soc_jack *jack, void *data); 325 int snd_soc_component_get_jack_type(struct snd_soc_component *component); 326 327 void snd_soc_component_seq_notifier(struct snd_soc_component *component, 328 enum snd_soc_dapm_type type, int subseq); 329 int snd_soc_component_stream_event(struct snd_soc_component *component, 330 int event); 331 int snd_soc_component_set_bias_level(struct snd_soc_component *component, 332 enum snd_soc_bias_level level); 333 334 void snd_soc_component_setup_regmap(struct snd_soc_component *component); 335 #ifdef CONFIG_REGMAP 336 void snd_soc_component_init_regmap(struct snd_soc_component *component, 337 struct regmap *regmap); 338 void snd_soc_component_exit_regmap(struct snd_soc_component *component); 339 #endif 340 341 #define snd_soc_component_module_get_when_probe(component)\ 342 snd_soc_component_module_get(component, NULL, 0) 343 #define snd_soc_component_module_get_when_open(component, substream) \ 344 snd_soc_component_module_get(component, substream, 1) 345 int snd_soc_component_module_get(struct snd_soc_component *component, 346 void *mark, int upon_open); 347 #define snd_soc_component_module_put_when_remove(component) \ 348 snd_soc_component_module_put(component, NULL, 0, 0) 349 #define snd_soc_component_module_put_when_close(component, substream, rollback) \ 350 snd_soc_component_module_put(component, substream, 1, rollback) 351 void snd_soc_component_module_put(struct snd_soc_component *component, 352 void *mark, int upon_open, int rollback); 353 354 static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c, 355 void *data) 356 { 357 dev_set_drvdata(c->dev, data); 358 } 359 360 static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c) 361 { 362 return dev_get_drvdata(c->dev); 363 } 364 365 static inline unsigned int 366 snd_soc_component_active(struct snd_soc_component *component) 367 { 368 return component->active; 369 } 370 371 /* component controls */ 372 struct snd_kcontrol *snd_soc_component_get_kcontrol(struct snd_soc_component *component, 373 const char * const ctl); 374 int snd_soc_component_notify_control(struct snd_soc_component *component, 375 const char * const ctl); 376 377 /* component driver ops */ 378 int snd_soc_component_open(struct snd_soc_component *component, 379 struct snd_pcm_substream *substream); 380 int snd_soc_component_close(struct snd_soc_component *component, 381 struct snd_pcm_substream *substream, 382 int rollback); 383 void snd_soc_component_suspend(struct snd_soc_component *component); 384 void snd_soc_component_resume(struct snd_soc_component *component); 385 int snd_soc_component_is_suspended(struct snd_soc_component *component); 386 int snd_soc_component_probe(struct snd_soc_component *component); 387 void snd_soc_component_remove(struct snd_soc_component *component); 388 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, 389 struct device_node *ep); 390 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, 391 const struct of_phandle_args *args, 392 const char **dai_name); 393 int snd_soc_component_compr_open(struct snd_soc_component *component, 394 struct snd_compr_stream *cstream); 395 void snd_soc_component_compr_free(struct snd_soc_component *component, 396 struct snd_compr_stream *cstream, 397 int rollback); 398 int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd); 399 int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, 400 struct snd_compr_params *params); 401 int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream, 402 struct snd_codec *params); 403 int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, 404 struct snd_compr_caps *caps); 405 int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, 406 struct snd_compr_codec_caps *codec); 407 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes); 408 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream, 409 struct snd_compr_tstamp64 *tstamp); 410 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream, 411 char __user *buf, size_t count); 412 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream, 413 struct snd_compr_metadata *metadata); 414 int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream, 415 struct snd_compr_metadata *metadata); 416 417 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); 418 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, 419 unsigned int cmd, void *arg); 420 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream); 421 int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream, 422 int channel, unsigned long pos, 423 struct iov_iter *iter, unsigned long bytes); 424 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, 425 unsigned long offset); 426 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, 427 struct vm_area_struct *vma); 428 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd); 429 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd); 430 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream); 431 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, 432 struct snd_pcm_hw_params *params); 433 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, 434 int rollback); 435 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, 436 int cmd, int rollback); 437 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd, 438 void *stream); 439 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd, 440 void *stream, int rollback); 441 int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream); 442 void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream, 443 snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay); 444 445 #endif /* __SOC_COMPONENT_H */ 446