0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef __SOUND_SOC_SOF_AUDIO_H
0012 #define __SOUND_SOC_SOF_AUDIO_H
0013
0014 #include <linux/workqueue.h>
0015
0016 #include <sound/soc.h>
0017 #include <sound/control.h>
0018 #include <sound/sof/stream.h> /* needs to be included before control.h */
0019 #include <sound/sof/control.h>
0020 #include <sound/sof/dai.h>
0021 #include <sound/sof/topology.h>
0022 #include "sof-priv.h"
0023
0024 #define SOF_AUDIO_PCM_DRV_NAME "sof-audio-component"
0025
0026
0027 #define SOF_BE_PCM_BASE 16
0028
0029 #define DMA_CHAN_INVALID 0xFFFFFFFF
0030
0031 #define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
0032 #define WIDGET_IS_AIF(id) ((id) == snd_soc_dapm_aif_in || (id) == snd_soc_dapm_aif_out)
0033 #define WIDGET_IS_AIF_OR_DAI(id) (WIDGET_IS_DAI(id) || WIDGET_IS_AIF(id))
0034
0035 #define SOF_DAI_CLK_INTEL_SSP_MCLK 0
0036 #define SOF_DAI_CLK_INTEL_SSP_BCLK 1
0037
0038 enum sof_widget_op {
0039 SOF_WIDGET_PREPARE,
0040 SOF_WIDGET_SETUP,
0041 SOF_WIDGET_FREE,
0042 SOF_WIDGET_UNPREPARE,
0043 };
0044
0045
0046
0047
0048
0049 #define VOLUME_FWL 16
0050
0051 #define SOF_TLV_ITEMS 3
0052
0053 static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
0054 {
0055 if (value >= size)
0056 return volume_map[size - 1];
0057
0058 return volume_map[value];
0059 }
0060
0061 static inline u32 ipc_to_mixer(u32 value, u32 *volume_map, int size)
0062 {
0063 int i;
0064
0065 for (i = 0; i < size; i++) {
0066 if (volume_map[i] >= value)
0067 return i;
0068 }
0069
0070 return i - 1;
0071 }
0072
0073 struct snd_sof_widget;
0074 struct snd_sof_route;
0075 struct snd_sof_control;
0076 struct snd_sof_dai;
0077
0078 struct snd_sof_dai_config_data {
0079 int dai_index;
0080 int dai_data;
0081 };
0082
0083
0084
0085
0086
0087
0088
0089
0090 struct sof_ipc_pcm_ops {
0091 int (*hw_params)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
0092 struct snd_pcm_hw_params *params,
0093 struct snd_sof_platform_stream_params *platform_params);
0094 int (*hw_free)(struct snd_soc_component *component, struct snd_pcm_substream *substream);
0095 int (*trigger)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
0096 int cmd);
0097 int (*dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
0098 };
0099
0100
0101
0102
0103 struct sof_ipc_tplg_control_ops {
0104 bool (*volume_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0105 int (*volume_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0106 bool (*switch_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0107 int (*switch_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0108 bool (*enum_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0109 int (*enum_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0110 int (*bytes_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0111 int (*bytes_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
0112 int (*bytes_ext_get)(struct snd_sof_control *scontrol,
0113 const unsigned int __user *binary_data, unsigned int size);
0114 int (*bytes_ext_volatile_get)(struct snd_sof_control *scontrol,
0115 const unsigned int __user *binary_data, unsigned int size);
0116 int (*bytes_ext_put)(struct snd_sof_control *scontrol,
0117 const unsigned int __user *binary_data, unsigned int size);
0118
0119 void (*update)(struct snd_sof_dev *sdev, void *ipc_control_message);
0120
0121 int (*widget_kcontrol_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
0122
0123 int (*set_up_volume_table)(struct snd_sof_control *scontrol, int tlv[SOF_TLV_ITEMS],
0124 int size);
0125 };
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 struct sof_ipc_tplg_widget_ops {
0138 int (*ipc_setup)(struct snd_sof_widget *swidget);
0139 void (*ipc_free)(struct snd_sof_widget *swidget);
0140 enum sof_tokens *token_list;
0141 int token_list_size;
0142 int (*bind_event)(struct snd_soc_component *scomp, struct snd_sof_widget *swidget,
0143 u16 event_type);
0144 int (*ipc_prepare)(struct snd_sof_widget *swidget,
0145 struct snd_pcm_hw_params *fe_params,
0146 struct snd_sof_platform_stream_params *platform_params,
0147 struct snd_pcm_hw_params *source_params, int dir);
0148 void (*ipc_unprepare)(struct snd_sof_widget *swidget);
0149 };
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 struct sof_ipc_tplg_ops {
0174 const struct sof_ipc_tplg_widget_ops *widget;
0175 const struct sof_ipc_tplg_control_ops *control;
0176 int (*route_setup)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
0177 int (*route_free)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
0178 const struct sof_token_info *token_list;
0179 int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
0180 int (*control_free)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
0181 int (*pipeline_complete)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
0182 int (*widget_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
0183 int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
0184 int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
0185 unsigned int flags, struct snd_sof_dai_config_data *data);
0186 int (*dai_get_clk)(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type);
0187 int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
0188 int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
0189 int (*parse_manifest)(struct snd_soc_component *scomp, int index,
0190 struct snd_soc_tplg_manifest *man);
0191 };
0192
0193
0194
0195
0196
0197 struct snd_sof_tuple {
0198 u32 token;
0199 union {
0200 u32 v;
0201 const char *s;
0202 } value;
0203 };
0204
0205
0206
0207
0208
0209 enum sof_tokens {
0210 SOF_PCM_TOKENS,
0211 SOF_PIPELINE_TOKENS,
0212 SOF_SCHED_TOKENS,
0213 SOF_ASRC_TOKENS,
0214 SOF_SRC_TOKENS,
0215 SOF_COMP_TOKENS,
0216 SOF_BUFFER_TOKENS,
0217 SOF_VOLUME_TOKENS,
0218 SOF_PROCESS_TOKENS,
0219 SOF_DAI_TOKENS,
0220 SOF_DAI_LINK_TOKENS,
0221 SOF_HDA_TOKENS,
0222 SOF_SSP_TOKENS,
0223 SOF_ALH_TOKENS,
0224 SOF_DMIC_TOKENS,
0225 SOF_DMIC_PDM_TOKENS,
0226 SOF_ESAI_TOKENS,
0227 SOF_SAI_TOKENS,
0228 SOF_AFE_TOKENS,
0229 SOF_CORE_TOKENS,
0230 SOF_COMP_EXT_TOKENS,
0231 SOF_IN_AUDIO_FORMAT_TOKENS,
0232 SOF_OUT_AUDIO_FORMAT_TOKENS,
0233 SOF_AUDIO_FORMAT_BUFFER_SIZE_TOKENS,
0234 SOF_COPIER_GATEWAY_CFG_TOKENS,
0235 SOF_COPIER_TOKENS,
0236 SOF_AUDIO_FMT_NUM_TOKENS,
0237 SOF_COPIER_FORMAT_TOKENS,
0238 SOF_GAIN_TOKENS,
0239 SOF_ACPDMIC_TOKENS,
0240
0241
0242 SOF_TOKEN_COUNT,
0243 };
0244
0245
0246
0247
0248
0249
0250
0251
0252 struct sof_topology_token {
0253 u32 token;
0254 u32 type;
0255 int (*get_token)(void *elem, void *object, u32 offset);
0256 u32 offset;
0257 };
0258
0259 struct sof_token_info {
0260 const char *name;
0261 const struct sof_topology_token *tokens;
0262 int count;
0263 };
0264
0265
0266 struct snd_sof_pcm_stream {
0267 u32 comp_id;
0268 struct snd_dma_buffer page_table;
0269 struct sof_ipc_stream_posn posn;
0270 struct snd_pcm_substream *substream;
0271 struct snd_compr_stream *cstream;
0272 struct work_struct period_elapsed_work;
0273 struct snd_soc_dapm_widget_list *list;
0274 bool d0i3_compatible;
0275
0276
0277
0278
0279 bool suspend_ignored;
0280 };
0281
0282
0283 struct snd_sof_pcm {
0284 struct snd_soc_component *scomp;
0285 struct snd_soc_tplg_pcm pcm;
0286 struct snd_sof_pcm_stream stream[2];
0287 struct list_head list;
0288 struct snd_pcm_hw_params params[2];
0289 bool prepared[2];
0290 };
0291
0292 struct snd_sof_led_control {
0293 unsigned int use_led;
0294 unsigned int direction;
0295 int led_value;
0296 };
0297
0298
0299 struct snd_sof_control {
0300 struct snd_soc_component *scomp;
0301 const char *name;
0302 int comp_id;
0303 int min_volume_step;
0304 int max_volume_step;
0305 int num_channels;
0306 unsigned int access;
0307 int info_type;
0308 int index;
0309 void *priv;
0310 size_t priv_size;
0311 size_t max_size;
0312 void *ipc_control_data;
0313 int max;
0314 u32 size;
0315 u32 *volume_table;
0316
0317 struct list_head list;
0318
0319 struct snd_sof_led_control led_ctl;
0320
0321
0322 bool comp_data_dirty;
0323 };
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 struct snd_sof_dai_link {
0336 struct snd_sof_tuple *tuples;
0337 int num_tuples;
0338 struct snd_soc_dai_link *link;
0339 struct snd_soc_tplg_hw_config *hw_configs;
0340 int num_hw_configs;
0341 int default_hw_cfg_id;
0342 int type;
0343 struct list_head list;
0344 };
0345
0346
0347 struct snd_sof_widget {
0348 struct snd_soc_component *scomp;
0349 int comp_id;
0350 int pipeline_id;
0351
0352
0353
0354
0355 int complete;
0356
0357
0358
0359
0360 bool prepared;
0361 int use_count;
0362 int core;
0363 int id;
0364
0365
0366
0367
0368 int instance_id;
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 bool dynamic_pipeline_widget;
0379
0380 struct snd_soc_dapm_widget *widget;
0381 struct list_head list;
0382 struct snd_sof_widget *pipe_widget;
0383 void *module_info;
0384
0385 const guid_t uuid;
0386
0387 int num_tuples;
0388 struct snd_sof_tuple *tuples;
0389
0390 void *private;
0391 };
0392
0393
0394 struct snd_sof_route {
0395 struct snd_soc_component *scomp;
0396
0397 struct snd_soc_dapm_route *route;
0398 struct list_head list;
0399 struct snd_sof_widget *src_widget;
0400 struct snd_sof_widget *sink_widget;
0401 bool setup;
0402
0403 void *private;
0404 };
0405
0406
0407 struct snd_sof_dai {
0408 struct snd_soc_component *scomp;
0409 const char *name;
0410
0411 int number_configs;
0412 int current_config;
0413 struct list_head list;
0414 void *private;
0415 };
0416
0417
0418
0419
0420
0421 int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
0422 struct snd_ctl_elem_value *ucontrol);
0423 int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
0424 struct snd_ctl_elem_value *ucontrol);
0425 int snd_sof_volume_info(struct snd_kcontrol *kcontrol,
0426 struct snd_ctl_elem_info *uinfo);
0427 int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
0428 struct snd_ctl_elem_value *ucontrol);
0429 int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
0430 struct snd_ctl_elem_value *ucontrol);
0431 int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
0432 struct snd_ctl_elem_value *ucontrol);
0433 int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
0434 struct snd_ctl_elem_value *ucontrol);
0435 int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
0436 struct snd_ctl_elem_value *ucontrol);
0437 int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
0438 struct snd_ctl_elem_value *ucontrol);
0439 int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
0440 const unsigned int __user *binary_data,
0441 unsigned int size);
0442 int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
0443 unsigned int __user *binary_data,
0444 unsigned int size);
0445 int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data,
0446 unsigned int size);
0447 void snd_sof_control_notify(struct snd_sof_dev *sdev,
0448 struct sof_ipc_ctrl_data *cdata);
0449
0450
0451
0452
0453
0454
0455 int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);
0456
0457
0458
0459
0460 int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
0461 struct snd_sof_pcm *spcm, int direction,
0462 struct sof_ipc_stream_posn *posn);
0463
0464 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
0465 const char *name);
0466 struct snd_sof_widget *
0467 snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
0468 const char *pcm_name, int dir);
0469 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
0470 const char *name);
0471
0472 static inline
0473 struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp,
0474 struct snd_soc_pcm_runtime *rtd)
0475 {
0476 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
0477 struct snd_sof_pcm *spcm;
0478
0479 list_for_each_entry(spcm, &sdev->pcm_list, list) {
0480 if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id)
0481 return spcm;
0482 }
0483
0484 return NULL;
0485 }
0486
0487 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
0488 const char *name);
0489 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
0490 unsigned int comp_id,
0491 int *direction);
0492 void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
0493 void snd_sof_pcm_init_elapsed_work(struct work_struct *work);
0494
0495 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
0496 void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
0497 void snd_sof_compr_init_elapsed_work(struct work_struct *work);
0498 #else
0499 static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream) { }
0500 static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { }
0501 #endif
0502
0503
0504 int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
0505
0506
0507 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
0508 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);
0509
0510
0511 int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
0512 void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
0513
0514 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
0515 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
0516 int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
0517 struct snd_soc_dapm_widget *wsink);
0518
0519
0520 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
0521 struct snd_pcm_hw_params *fe_params,
0522 struct snd_sof_platform_stream_params *platform_params,
0523 int dir);
0524 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
0525 int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev,
0526 struct snd_sof_pcm *spcm);
0527 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
0528 struct snd_sof_pcm *spcm, int dir, bool free_widget_list);
0529 int get_token_u32(void *elem, void *object, u32 offset);
0530 int get_token_u16(void *elem, void *object, u32 offset);
0531 int get_token_comp_format(void *elem, void *object, u32 offset);
0532 int get_token_dai_type(void *elem, void *object, u32 offset);
0533 int get_token_uuid(void *elem, void *object, u32 offset);
0534 int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum sof_tokens token_id,
0535 struct snd_sof_tuple *tuples, int num_tuples,
0536 size_t object_size, int token_instance_num);
0537 u32 vol_compute_gain(u32 value, int *tlv);
0538 #endif