Kuninori Morimoto | e2cfd2c | 2018-07-02 06:22:15 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 3 | * linux/sound/soc-dai.h -- ALSA SoC Layer |
| 4 | * |
| 5 | * Copyright: 2005-2008 Wolfson Microelectronics. PLC. |
| 6 | * |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 7 | * Digital Audio Interface (DAI) API. |
| 8 | */ |
| 9 | |
| 10 | #ifndef __LINUX_SND_SOC_DAI_H |
| 11 | #define __LINUX_SND_SOC_DAI_H |
| 12 | |
| 13 | |
| 14 | #include <linux/list.h> |
Mengdong Lin | d2e3cb8 | 2016-09-29 14:09:14 +0800 | [diff] [blame] | 15 | #include <sound/asoc.h> |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 16 | |
| 17 | struct snd_pcm_substream; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 18 | struct snd_soc_dapm_widget; |
Vinod Koul | 4968107 | 2012-08-16 17:10:40 +0530 | [diff] [blame] | 19 | struct snd_compr_stream; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * DAI hardware audio formats. |
| 23 | * |
| 24 | * Describes the physical PCM data formating and clocking. Add new formats |
| 25 | * to the end. |
| 26 | */ |
Mengdong Lin | d2e3cb8 | 2016-09-29 14:09:14 +0800 | [diff] [blame] | 27 | #define SND_SOC_DAIFMT_I2S SND_SOC_DAI_FORMAT_I2S |
| 28 | #define SND_SOC_DAIFMT_RIGHT_J SND_SOC_DAI_FORMAT_RIGHT_J |
| 29 | #define SND_SOC_DAIFMT_LEFT_J SND_SOC_DAI_FORMAT_LEFT_J |
| 30 | #define SND_SOC_DAIFMT_DSP_A SND_SOC_DAI_FORMAT_DSP_A |
| 31 | #define SND_SOC_DAIFMT_DSP_B SND_SOC_DAI_FORMAT_DSP_B |
| 32 | #define SND_SOC_DAIFMT_AC97 SND_SOC_DAI_FORMAT_AC97 |
| 33 | #define SND_SOC_DAIFMT_PDM SND_SOC_DAI_FORMAT_PDM |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 34 | |
| 35 | /* left and right justified also known as MSB and LSB respectively */ |
| 36 | #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J |
| 37 | #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J |
| 38 | |
| 39 | /* |
| 40 | * DAI Clock gating. |
| 41 | * |
Peter Meerwald | 47db8e89 | 2009-07-13 23:05:11 +0100 | [diff] [blame] | 42 | * DAI bit clocks can be be gated (disabled) when the DAI is not |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 43 | * sending or receiving PCM data in a frame. This can be used to save power. |
| 44 | */ |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 45 | #define SND_SOC_DAIFMT_CONT (1 << 4) /* continuous clock */ |
Kuninori Morimoto | eef28e10 | 2013-01-29 21:03:13 -0800 | [diff] [blame] | 46 | #define SND_SOC_DAIFMT_GATED (0 << 4) /* clock is gated */ |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 47 | |
| 48 | /* |
Anatol Pomozov | 1d387a3 | 2015-10-08 09:37:51 -0700 | [diff] [blame] | 49 | * DAI hardware signal polarity. |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 50 | * |
| 51 | * Specifies whether the DAI can also support inverted clocks for the specified |
| 52 | * format. |
Anatol Pomozov | 1d387a3 | 2015-10-08 09:37:51 -0700 | [diff] [blame] | 53 | * |
| 54 | * BCLK: |
| 55 | * - "normal" polarity means signal is available at rising edge of BCLK |
| 56 | * - "inverted" polarity means signal is available at falling edge of BCLK |
| 57 | * |
| 58 | * FSYNC "normal" polarity depends on the frame format: |
| 59 | * - I2S: frame consists of left then right channel data. Left channel starts |
| 60 | * with falling FSYNC edge, right channel starts with rising FSYNC edge. |
| 61 | * - Left/Right Justified: frame consists of left then right channel data. |
| 62 | * Left channel starts with rising FSYNC edge, right channel starts with |
| 63 | * falling FSYNC edge. |
| 64 | * - DSP A/B: Frame starts with rising FSYNC edge. |
| 65 | * - AC97: Frame starts with rising FSYNC edge. |
| 66 | * |
| 67 | * "Negative" FSYNC polarity is the one opposite of "normal" polarity. |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 68 | */ |
Kuninori Morimoto | 5d16333 | 2013-01-15 20:18:23 -0800 | [diff] [blame] | 69 | #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */ |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 70 | #define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */ |
| 71 | #define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */ |
| 72 | #define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */ |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * DAI hardware clock masters. |
| 76 | * |
| 77 | * This is wrt the codec, the inverse is true for the interface |
Peter Meerwald | 47db8e89 | 2009-07-13 23:05:11 +0100 | [diff] [blame] | 78 | * i.e. if the codec is clk and FRM master then the interface is |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 79 | * clk and frame slave. |
| 80 | */ |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 81 | #define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */ |
| 82 | #define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */ |
| 83 | #define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */ |
| 84 | #define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */ |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 85 | |
| 86 | #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f |
| 87 | #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0 |
| 88 | #define SND_SOC_DAIFMT_INV_MASK 0x0f00 |
| 89 | #define SND_SOC_DAIFMT_MASTER_MASK 0xf000 |
| 90 | |
| 91 | /* |
| 92 | * Master Clock Directions |
| 93 | */ |
| 94 | #define SND_SOC_CLOCK_IN 0 |
| 95 | #define SND_SOC_CLOCK_OUT 1 |
| 96 | |
Mark Brown | 8f738d5 | 2009-08-09 20:08:31 +0100 | [diff] [blame] | 97 | #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\ |
| 98 | SNDRV_PCM_FMTBIT_S16_LE |\ |
| 99 | SNDRV_PCM_FMTBIT_S16_BE |\ |
| 100 | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 101 | SNDRV_PCM_FMTBIT_S20_3BE |\ |
Maciej S. Szmigiero | 823dbb6 | 2017-11-27 23:33:29 +0100 | [diff] [blame] | 102 | SNDRV_PCM_FMTBIT_S20_LE |\ |
| 103 | SNDRV_PCM_FMTBIT_S20_BE |\ |
Mark Brown | 8f738d5 | 2009-08-09 20:08:31 +0100 | [diff] [blame] | 104 | SNDRV_PCM_FMTBIT_S24_3LE |\ |
| 105 | SNDRV_PCM_FMTBIT_S24_3BE |\ |
Jon Smirl | d34c430 | 2009-05-13 21:59:14 -0400 | [diff] [blame] | 106 | SNDRV_PCM_FMTBIT_S32_LE |\ |
| 107 | SNDRV_PCM_FMTBIT_S32_BE) |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 108 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 109 | struct snd_soc_dai_driver; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 110 | struct snd_soc_dai; |
| 111 | struct snd_ac97_bus_ops; |
| 112 | |
| 113 | /* Digital Audio Interface clocking API.*/ |
| 114 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 115 | unsigned int freq, int dir); |
| 116 | |
| 117 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 118 | int div_id, int div); |
| 119 | |
| 120 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 121 | int pll_id, int source, unsigned int freq_in, unsigned int freq_out); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 122 | |
Liam Girdwood | e54cf76 | 2013-09-16 13:01:46 +0100 | [diff] [blame] | 123 | int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio); |
| 124 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 125 | /* Digital Audio interface formatting */ |
| 126 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt); |
| 127 | |
| 128 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 129 | unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 130 | |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 131 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 132 | unsigned int tx_num, unsigned int *tx_slot, |
| 133 | unsigned int rx_num, unsigned int *rx_slot); |
| 134 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 135 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate); |
| 136 | |
| 137 | /* Digital Audio Interface mute */ |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 138 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, |
| 139 | int direction); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 140 | |
Srinivas Kandagatla | 467b061 | 2018-07-23 16:54:03 +0100 | [diff] [blame] | 141 | |
| 142 | int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai, |
| 143 | unsigned int *tx_num, unsigned int *tx_slot, |
| 144 | unsigned int *rx_num, unsigned int *rx_slot); |
| 145 | |
Liam Girdwood | bece9e9 | 2014-01-08 10:40:18 +0000 | [diff] [blame] | 146 | int snd_soc_dai_is_dummy(struct snd_soc_dai *dai); |
| 147 | |
Kuninori Morimoto | aa6166c | 2019-07-22 10:33:04 +0900 | [diff] [blame] | 148 | int snd_soc_dai_hw_params(struct snd_soc_dai *dai, |
| 149 | struct snd_pcm_substream *substream, |
| 150 | struct snd_pcm_hw_params *params); |
Kuninori Morimoto | 846faae | 2019-07-22 10:33:19 +0900 | [diff] [blame] | 151 | void snd_soc_dai_hw_free(struct snd_soc_dai *dai, |
| 152 | struct snd_pcm_substream *substream); |
Kuninori Morimoto | 5a52a04 | 2019-07-22 10:33:32 +0900 | [diff] [blame] | 153 | int snd_soc_dai_startup(struct snd_soc_dai *dai, |
| 154 | struct snd_pcm_substream *substream); |
Kuninori Morimoto | 330fcb5 | 2019-07-22 10:33:39 +0900 | [diff] [blame] | 155 | void snd_soc_dai_shutdown(struct snd_soc_dai *dai, |
| 156 | struct snd_pcm_substream *substream); |
Kuninori Morimoto | 1dea80d | 2019-07-22 10:34:09 +0900 | [diff] [blame] | 157 | snd_pcm_sframes_t snd_soc_dai_delay(struct snd_soc_dai *dai, |
| 158 | struct snd_pcm_substream *substream); |
Kuninori Morimoto | e0f2262 | 2019-07-22 10:34:29 +0900 | [diff] [blame] | 159 | void snd_soc_dai_suspend(struct snd_soc_dai *dai); |
Kuninori Morimoto | 24b09d0 | 2019-07-22 10:34:43 +0900 | [diff] [blame] | 160 | void snd_soc_dai_resume(struct snd_soc_dai *dai); |
Kuninori Morimoto | b423c42 | 2019-07-22 10:35:29 +0900 | [diff] [blame] | 161 | int snd_soc_dai_compress_new(struct snd_soc_dai *dai, |
| 162 | struct snd_soc_pcm_runtime *rtd, int num); |
Kuninori Morimoto | 467fece | 2019-07-22 10:36:16 +0900 | [diff] [blame] | 163 | bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream); |
Kuninori Morimoto | dc82910 | 2020-05-15 09:46:27 +0900 | [diff] [blame] | 164 | void snd_soc_dai_action(struct snd_soc_dai *dai, |
| 165 | int stream, int action); |
| 166 | static inline void snd_soc_dai_activate(struct snd_soc_dai *dai, |
| 167 | int stream) |
| 168 | { |
| 169 | snd_soc_dai_action(dai, stream, 1); |
| 170 | } |
| 171 | static inline void snd_soc_dai_deactivate(struct snd_soc_dai *dai, |
| 172 | int stream) |
| 173 | { |
| 174 | snd_soc_dai_action(dai, stream, -1); |
| 175 | } |
Kuninori Morimoto | efffd9b | 2020-05-15 09:46:37 +0900 | [diff] [blame^] | 176 | int snd_soc_dai_active(struct snd_soc_dai *dai); |
Kuninori Morimoto | aa6166c | 2019-07-22 10:33:04 +0900 | [diff] [blame] | 177 | |
Kuninori Morimoto | 51801ae | 2020-04-24 08:15:15 +0900 | [diff] [blame] | 178 | int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order); |
Kuninori Morimoto | 7eaa313 | 2020-04-24 08:15:20 +0900 | [diff] [blame] | 179 | int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order); |
Kuninori Morimoto | 0b73ba5 | 2020-04-24 08:14:48 +0900 | [diff] [blame] | 180 | int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd); |
Kuninori Morimoto | d108c7f | 2020-04-24 08:14:53 +0900 | [diff] [blame] | 181 | int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream); |
Kuninori Morimoto | 42f2472 | 2020-04-24 08:15:04 +0900 | [diff] [blame] | 182 | int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, int cmd); |
Kuninori Morimoto | 30819358 | 2020-04-24 08:15:09 +0900 | [diff] [blame] | 183 | int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream, |
| 184 | int cmd); |
Kuninori Morimoto | 0b73ba5 | 2020-04-24 08:14:48 +0900 | [diff] [blame] | 185 | |
Kuninori Morimoto | b5ae4cc | 2020-04-24 08:15:24 +0900 | [diff] [blame] | 186 | int snd_soc_dai_compr_startup(struct snd_soc_dai *dai, |
| 187 | struct snd_compr_stream *cstream); |
Kuninori Morimoto | 2b25f81 | 2020-04-24 08:15:28 +0900 | [diff] [blame] | 188 | void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai, |
| 189 | struct snd_compr_stream *cstream); |
Kuninori Morimoto | eb08411 | 2020-04-24 08:15:32 +0900 | [diff] [blame] | 190 | int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai, |
| 191 | struct snd_compr_stream *cstream, int cmd); |
Kuninori Morimoto | 8dfedaf | 2020-04-24 08:15:36 +0900 | [diff] [blame] | 192 | int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai, |
| 193 | struct snd_compr_stream *cstream, |
| 194 | struct snd_compr_params *params); |
Kuninori Morimoto | adbef543 | 2020-04-24 08:15:40 +0900 | [diff] [blame] | 195 | int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai, |
| 196 | struct snd_compr_stream *cstream, |
| 197 | struct snd_codec *params); |
Kuninori Morimoto | 5329435 | 2020-04-24 08:15:45 +0900 | [diff] [blame] | 198 | int snd_soc_dai_compr_ack(struct snd_soc_dai *dai, |
| 199 | struct snd_compr_stream *cstream, |
| 200 | size_t bytes); |
Kuninori Morimoto | ed38cc5 | 2020-04-24 08:15:49 +0900 | [diff] [blame] | 201 | int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai, |
| 202 | struct snd_compr_stream *cstream, |
| 203 | struct snd_compr_tstamp *tstamp); |
Kuninori Morimoto | 88b3a7d | 2020-04-24 08:15:54 +0900 | [diff] [blame] | 204 | int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai, |
| 205 | struct snd_compr_stream *cstream, |
| 206 | struct snd_compr_metadata *metadata); |
Kuninori Morimoto | 94d7281 | 2020-04-24 08:15:59 +0900 | [diff] [blame] | 207 | int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai, |
| 208 | struct snd_compr_stream *cstream, |
| 209 | struct snd_compr_metadata *metadata); |
Kuninori Morimoto | b5ae4cc | 2020-04-24 08:15:24 +0900 | [diff] [blame] | 210 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 211 | struct snd_soc_dai_ops { |
| 212 | /* |
| 213 | * DAI clocking configuration, all optional. |
| 214 | * Called by soc_card drivers, normally in their hw_params. |
| 215 | */ |
| 216 | int (*set_sysclk)(struct snd_soc_dai *dai, |
| 217 | int clk_id, unsigned int freq, int dir); |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 218 | int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source, |
| 219 | unsigned int freq_in, unsigned int freq_out); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 220 | int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div); |
Liam Girdwood | e54cf76 | 2013-09-16 13:01:46 +0100 | [diff] [blame] | 221 | int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * DAI format configuration |
| 225 | * Called by soc_card drivers, normally in their hw_params. |
| 226 | */ |
| 227 | int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt); |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 228 | int (*xlate_tdm_slot_mask)(unsigned int slots, |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 229 | unsigned int *tx_mask, unsigned int *rx_mask); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 230 | int (*set_tdm_slot)(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 231 | unsigned int tx_mask, unsigned int rx_mask, |
| 232 | int slots, int slot_width); |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 233 | int (*set_channel_map)(struct snd_soc_dai *dai, |
| 234 | unsigned int tx_num, unsigned int *tx_slot, |
| 235 | unsigned int rx_num, unsigned int *rx_slot); |
Srinivas Kandagatla | 467b061 | 2018-07-23 16:54:03 +0100 | [diff] [blame] | 236 | int (*get_channel_map)(struct snd_soc_dai *dai, |
| 237 | unsigned int *tx_num, unsigned int *tx_slot, |
| 238 | unsigned int *rx_num, unsigned int *rx_slot); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 239 | int (*set_tristate)(struct snd_soc_dai *dai, int tristate); |
| 240 | |
Shreyas NC | 97349b6 | 2018-04-26 18:38:38 +0530 | [diff] [blame] | 241 | int (*set_sdw_stream)(struct snd_soc_dai *dai, |
| 242 | void *stream, int direction); |
Pierre-Louis Bossart | 36d73c4 | 2020-02-25 11:00:40 -0600 | [diff] [blame] | 243 | void *(*get_sdw_stream)(struct snd_soc_dai *dai, int direction); |
| 244 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 245 | /* |
| 246 | * DAI digital mute - optional. |
| 247 | * Called by soc-core to minimise any pops. |
| 248 | */ |
| 249 | int (*digital_mute)(struct snd_soc_dai *dai, int mute); |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 250 | int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream); |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * ALSA PCM audio operations - all optional. |
| 254 | * Called by soc-core during audio PCM operations. |
| 255 | */ |
| 256 | int (*startup)(struct snd_pcm_substream *, |
| 257 | struct snd_soc_dai *); |
| 258 | void (*shutdown)(struct snd_pcm_substream *, |
| 259 | struct snd_soc_dai *); |
| 260 | int (*hw_params)(struct snd_pcm_substream *, |
| 261 | struct snd_pcm_hw_params *, struct snd_soc_dai *); |
| 262 | int (*hw_free)(struct snd_pcm_substream *, |
| 263 | struct snd_soc_dai *); |
| 264 | int (*prepare)(struct snd_pcm_substream *, |
| 265 | struct snd_soc_dai *); |
Markus Pargmann | 9f1614a | 2013-10-11 12:11:02 +0200 | [diff] [blame] | 266 | /* |
| 267 | * NOTE: Commands passed to the trigger function are not necessarily |
| 268 | * compatible with the current state of the dai. For example this |
| 269 | * sequence of commands is possible: START STOP STOP. |
| 270 | * So do not unconditionally use refcounting functions in the trigger |
| 271 | * function, e.g. clk_enable/disable. |
| 272 | */ |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 273 | int (*trigger)(struct snd_pcm_substream *, int, |
| 274 | struct snd_soc_dai *); |
Liam Girdwood | 07bf84a | 2012-04-25 12:12:52 +0100 | [diff] [blame] | 275 | int (*bespoke_trigger)(struct snd_pcm_substream *, int, |
| 276 | struct snd_soc_dai *); |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 277 | /* |
| 278 | * For hardware based FIFO caused delay reporting. |
| 279 | * Optional. |
| 280 | */ |
| 281 | snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *, |
| 282 | struct snd_soc_dai *); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 283 | }; |
| 284 | |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 285 | struct snd_soc_cdai_ops { |
| 286 | /* |
| 287 | * for compress ops |
| 288 | */ |
| 289 | int (*startup)(struct snd_compr_stream *, |
| 290 | struct snd_soc_dai *); |
| 291 | int (*shutdown)(struct snd_compr_stream *, |
| 292 | struct snd_soc_dai *); |
| 293 | int (*set_params)(struct snd_compr_stream *, |
| 294 | struct snd_compr_params *, struct snd_soc_dai *); |
| 295 | int (*get_params)(struct snd_compr_stream *, |
| 296 | struct snd_codec *, struct snd_soc_dai *); |
| 297 | int (*set_metadata)(struct snd_compr_stream *, |
| 298 | struct snd_compr_metadata *, struct snd_soc_dai *); |
| 299 | int (*get_metadata)(struct snd_compr_stream *, |
| 300 | struct snd_compr_metadata *, struct snd_soc_dai *); |
| 301 | int (*trigger)(struct snd_compr_stream *, int, |
| 302 | struct snd_soc_dai *); |
| 303 | int (*pointer)(struct snd_compr_stream *, |
| 304 | struct snd_compr_tstamp *, struct snd_soc_dai *); |
| 305 | int (*ack)(struct snd_compr_stream *, size_t, |
| 306 | struct snd_soc_dai *); |
| 307 | }; |
| 308 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 309 | /* |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 310 | * Digital Audio Interface Driver. |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 311 | * |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 312 | * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97 |
| 313 | * operations and capabilities. Codec and platform drivers will register this |
| 314 | * structure for every DAI they have. |
| 315 | * |
| 316 | * This structure covers the clocking, formating and ALSA operations for each |
| 317 | * interface. |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 318 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 319 | struct snd_soc_dai_driver { |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 320 | /* DAI description */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 321 | const char *name; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 322 | unsigned int id; |
Mark Brown | 6236829 | 2012-05-01 20:03:32 +0100 | [diff] [blame] | 323 | unsigned int base; |
Mengdong Lin | 68003e6 | 2015-12-31 16:40:43 +0800 | [diff] [blame] | 324 | struct snd_soc_dobj dobj; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 325 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 326 | /* DAI driver callbacks */ |
| 327 | int (*probe)(struct snd_soc_dai *dai); |
| 328 | int (*remove)(struct snd_soc_dai *dai); |
Vinod Koul | 4968107 | 2012-08-16 17:10:40 +0530 | [diff] [blame] | 329 | /* compress dai */ |
Jie Yang | 6f0c422 | 2015-10-13 23:41:00 +0800 | [diff] [blame] | 330 | int (*compress_new)(struct snd_soc_pcm_runtime *rtd, int num); |
Arnaud Pouliquen | 25f7b70 | 2017-01-03 16:52:51 +0100 | [diff] [blame] | 331 | /* Optional Callback used at pcm creation*/ |
| 332 | int (*pcm_new)(struct snd_soc_pcm_runtime *rtd, |
| 333 | struct snd_soc_dai *dai); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 334 | |
| 335 | /* ops */ |
Mark Brown | 1ee46eb | 2010-12-02 16:10:09 +0000 | [diff] [blame] | 336 | const struct snd_soc_dai_ops *ops; |
Vinod Koul | 2e622ae | 2016-11-13 12:10:02 +0530 | [diff] [blame] | 337 | const struct snd_soc_cdai_ops *cops; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 338 | |
| 339 | /* DAI capabilities */ |
| 340 | struct snd_soc_pcm_stream capture; |
| 341 | struct snd_soc_pcm_stream playback; |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 342 | unsigned int symmetric_rates:1; |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 343 | unsigned int symmetric_channels:1; |
| 344 | unsigned int symmetric_samplebits:1; |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 345 | |
| 346 | /* probe ordering - for components with runtime dependencies */ |
| 347 | int probe_order; |
| 348 | int remove_order; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | /* |
| 352 | * Digital Audio Interface runtime data. |
| 353 | * |
| 354 | * Holds runtime data for a DAI. |
| 355 | */ |
| 356 | struct snd_soc_dai { |
| 357 | const char *name; |
| 358 | int id; |
| 359 | struct device *dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 360 | |
| 361 | /* driver ops */ |
| 362 | struct snd_soc_dai_driver *driver; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 363 | |
| 364 | /* DAI runtime info */ |
Kuninori Morimoto | 0f6011f | 2020-02-17 17:28:15 +0900 | [diff] [blame] | 365 | unsigned int stream_active[SNDRV_PCM_STREAM_LAST + 1]; /* usage count */ |
Kuninori Morimoto | 39b2238 | 2016-10-24 05:25:19 +0000 | [diff] [blame] | 366 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 367 | unsigned int active; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 368 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 369 | struct snd_soc_dapm_widget *playback_widget; |
| 370 | struct snd_soc_dapm_widget *capture_widget; |
| 371 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 372 | /* DAI DMA data */ |
| 373 | void *playback_dma_data; |
| 374 | void *capture_dma_data; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 375 | |
Dong Aisheng | 1784102 | 2011-08-29 17:15:14 +0800 | [diff] [blame] | 376 | /* Symmetry data - only valid if symmetry is being enforced */ |
| 377 | unsigned int rate; |
Nicolin Chen | 3635bf0 | 2013-11-13 18:56:24 +0800 | [diff] [blame] | 378 | unsigned int channels; |
| 379 | unsigned int sample_bits; |
Dong Aisheng | 1784102 | 2011-08-29 17:15:14 +0800 | [diff] [blame] | 380 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 381 | /* parent platform/codec */ |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 382 | struct snd_soc_component *component; |
Mark Brown | 2466ab9 | 2012-03-02 16:18:30 +0000 | [diff] [blame] | 383 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 384 | /* CODEC TDM slot masks and params (for fixup) */ |
| 385 | unsigned int tx_mask; |
| 386 | unsigned int rx_mask; |
| 387 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 388 | struct list_head list; |
Kuninori Morimoto | b56be80 | 2020-02-10 12:14:33 +0900 | [diff] [blame] | 389 | |
| 390 | /* bit field */ |
| 391 | unsigned int probed:1; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 392 | }; |
| 393 | |
Kuninori Morimoto | acf253c | 2020-02-19 15:56:30 +0900 | [diff] [blame] | 394 | static inline struct snd_soc_pcm_stream * |
| 395 | snd_soc_dai_get_pcm_stream(const struct snd_soc_dai *dai, int stream) |
| 396 | { |
| 397 | return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
| 398 | &dai->driver->playback : &dai->driver->capture; |
| 399 | } |
| 400 | |
Kuninori Morimoto | 0c01f6c | 2020-02-19 15:56:41 +0900 | [diff] [blame] | 401 | static inline |
| 402 | struct snd_soc_dapm_widget *snd_soc_dai_get_widget( |
| 403 | struct snd_soc_dai *dai, int stream) |
| 404 | { |
| 405 | return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
| 406 | dai->playback_widget : dai->capture_widget; |
| 407 | } |
| 408 | |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 409 | static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai, |
| 410 | const struct snd_pcm_substream *ss) |
| 411 | { |
| 412 | return (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 413 | dai->playback_dma_data : dai->capture_dma_data; |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static inline void snd_soc_dai_set_dma_data(struct snd_soc_dai *dai, |
| 417 | const struct snd_pcm_substream *ss, |
| 418 | void *data) |
| 419 | { |
| 420 | if (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 421 | dai->playback_dma_data = data; |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 422 | else |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 423 | dai->capture_dma_data = data; |
| 424 | } |
| 425 | |
Mark Brown | ecfc0c0 | 2013-10-17 21:13:19 +0100 | [diff] [blame] | 426 | static inline void snd_soc_dai_init_dma_data(struct snd_soc_dai *dai, |
| 427 | void *playback, void *capture) |
| 428 | { |
| 429 | dai->playback_dma_data = playback; |
| 430 | dai->capture_dma_data = capture; |
| 431 | } |
| 432 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 433 | static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai, |
| 434 | void *data) |
| 435 | { |
| 436 | dev_set_drvdata(dai->dev, data); |
| 437 | } |
| 438 | |
| 439 | static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai) |
| 440 | { |
| 441 | return dev_get_drvdata(dai->dev); |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Shreyas NC | 97349b6 | 2018-04-26 18:38:38 +0530 | [diff] [blame] | 444 | /** |
| 445 | * snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation |
| 446 | * @dai: DAI |
| 447 | * @stream: STREAM |
| 448 | * @direction: Stream direction(Playback/Capture) |
| 449 | * SoundWire subsystem doesn't have a notion of direction and we reuse |
| 450 | * the ASoC stream direction to configure sink/source ports. |
| 451 | * Playback maps to source ports and Capture for sink ports. |
| 452 | * |
| 453 | * This should be invoked with NULL to clear the stream set previously. |
| 454 | * Returns 0 on success, a negative error code otherwise. |
| 455 | */ |
| 456 | static inline int snd_soc_dai_set_sdw_stream(struct snd_soc_dai *dai, |
| 457 | void *stream, int direction) |
| 458 | { |
| 459 | if (dai->driver->ops->set_sdw_stream) |
| 460 | return dai->driver->ops->set_sdw_stream(dai, stream, direction); |
| 461 | else |
| 462 | return -ENOTSUPP; |
| 463 | } |
| 464 | |
Pierre-Louis Bossart | 36d73c4 | 2020-02-25 11:00:40 -0600 | [diff] [blame] | 465 | /** |
| 466 | * snd_soc_dai_get_sdw_stream() - Retrieves SDW stream from DAI |
| 467 | * @dai: DAI |
| 468 | * @direction: Stream direction(Playback/Capture) |
| 469 | * |
| 470 | * This routine only retrieves that was previously configured |
| 471 | * with snd_soc_dai_get_sdw_stream() |
| 472 | * |
Srinivas Kandagatla | 308811a | 2020-03-16 15:11:10 +0000 | [diff] [blame] | 473 | * Returns pointer to stream or -ENOTSUPP if callback is not supported; |
Pierre-Louis Bossart | 36d73c4 | 2020-02-25 11:00:40 -0600 | [diff] [blame] | 474 | */ |
| 475 | static inline void *snd_soc_dai_get_sdw_stream(struct snd_soc_dai *dai, |
| 476 | int direction) |
| 477 | { |
| 478 | if (dai->driver->ops->get_sdw_stream) |
| 479 | return dai->driver->ops->get_sdw_stream(dai, direction); |
| 480 | else |
Srinivas Kandagatla | 308811a | 2020-03-16 15:11:10 +0000 | [diff] [blame] | 481 | return ERR_PTR(-ENOTSUPP); |
Pierre-Louis Bossart | 36d73c4 | 2020-02-25 11:00:40 -0600 | [diff] [blame] | 482 | } |
| 483 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 484 | #endif |