Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/sound/soc-dai.h -- ALSA SoC Layer |
| 3 | * |
| 4 | * Copyright: 2005-2008 Wolfson Microelectronics. PLC. |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 5 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * Digital Audio Interface (DAI) API. |
| 12 | */ |
| 13 | |
| 14 | #ifndef __LINUX_SND_SOC_DAI_H |
| 15 | #define __LINUX_SND_SOC_DAI_H |
| 16 | |
| 17 | |
| 18 | #include <linux/list.h> |
| 19 | |
| 20 | struct snd_pcm_substream; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 21 | struct snd_soc_dapm_widget; |
Vinod Koul | 0ff2361 | 2012-08-16 17:10:40 +0530 | [diff] [blame] | 22 | struct snd_compr_stream; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * DAI hardware audio formats. |
| 26 | * |
| 27 | * Describes the physical PCM data formating and clocking. Add new formats |
| 28 | * to the end. |
| 29 | */ |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 30 | #define SND_SOC_DAIFMT_I2S 1 /* I2S mode */ |
| 31 | #define SND_SOC_DAIFMT_RIGHT_J 2 /* Right Justified mode */ |
| 32 | #define SND_SOC_DAIFMT_LEFT_J 3 /* Left Justified mode */ |
| 33 | #define SND_SOC_DAIFMT_DSP_A 4 /* L data MSB after FRM LRC */ |
| 34 | #define SND_SOC_DAIFMT_DSP_B 5 /* L data MSB during FRM LRC */ |
| 35 | #define SND_SOC_DAIFMT_AC97 6 /* AC97 */ |
| 36 | #define SND_SOC_DAIFMT_PDM 7 /* Pulse density modulation */ |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 37 | |
| 38 | /* left and right justified also known as MSB and LSB respectively */ |
| 39 | #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J |
| 40 | #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J |
| 41 | |
| 42 | /* |
| 43 | * DAI Clock gating. |
| 44 | * |
Peter Meerwald | 47db8e8 | 2009-07-13 23:05:11 +0100 | [diff] [blame] | 45 | * 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] | 46 | * sending or receiving PCM data in a frame. This can be used to save power. |
| 47 | */ |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 48 | #define SND_SOC_DAIFMT_CONT (1 << 4) /* continuous clock */ |
| 49 | #define SND_SOC_DAIFMT_GATED (2 << 4) /* clock is gated */ |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 50 | |
| 51 | /* |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 52 | * DAI hardware signal inversions. |
| 53 | * |
| 54 | * Specifies whether the DAI can also support inverted clocks for the specified |
| 55 | * format. |
| 56 | */ |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 57 | #define SND_SOC_DAIFMT_NB_NF (1 << 8) /* normal bit clock + frame */ |
| 58 | #define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */ |
| 59 | #define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */ |
| 60 | #define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */ |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * DAI hardware clock masters. |
| 64 | * |
| 65 | * This is wrt the codec, the inverse is true for the interface |
Peter Meerwald | 47db8e8 | 2009-07-13 23:05:11 +0100 | [diff] [blame] | 66 | * 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] | 67 | * clk and frame slave. |
| 68 | */ |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 69 | #define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */ |
| 70 | #define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */ |
| 71 | #define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */ |
| 72 | #define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */ |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 73 | |
| 74 | #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f |
| 75 | #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0 |
| 76 | #define SND_SOC_DAIFMT_INV_MASK 0x0f00 |
| 77 | #define SND_SOC_DAIFMT_MASTER_MASK 0xf000 |
| 78 | |
| 79 | /* |
| 80 | * Master Clock Directions |
| 81 | */ |
| 82 | #define SND_SOC_CLOCK_IN 0 |
| 83 | #define SND_SOC_CLOCK_OUT 1 |
| 84 | |
Mark Brown | 8f738d5 | 2009-08-09 20:08:31 +0100 | [diff] [blame] | 85 | #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S8 |\ |
| 86 | SNDRV_PCM_FMTBIT_S16_LE |\ |
| 87 | SNDRV_PCM_FMTBIT_S16_BE |\ |
| 88 | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 89 | SNDRV_PCM_FMTBIT_S20_3BE |\ |
| 90 | SNDRV_PCM_FMTBIT_S24_3LE |\ |
| 91 | SNDRV_PCM_FMTBIT_S24_3BE |\ |
Jon Smirl | d34c430 | 2009-05-13 21:59:14 -0400 | [diff] [blame] | 92 | SNDRV_PCM_FMTBIT_S32_LE |\ |
| 93 | SNDRV_PCM_FMTBIT_S32_BE) |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 94 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 95 | struct snd_soc_dai_driver; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 96 | struct snd_soc_dai; |
| 97 | struct snd_ac97_bus_ops; |
| 98 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 99 | /* Digital Audio Interface registration */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 100 | int snd_soc_register_dai(struct device *dev, |
| 101 | struct snd_soc_dai_driver *dai_drv); |
| 102 | void snd_soc_unregister_dai(struct device *dev); |
| 103 | int snd_soc_register_dais(struct device *dev, |
| 104 | struct snd_soc_dai_driver *dai_drv, size_t count); |
| 105 | void snd_soc_unregister_dais(struct device *dev, size_t count); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 106 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 107 | /* Digital Audio Interface clocking API.*/ |
| 108 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 109 | unsigned int freq, int dir); |
| 110 | |
| 111 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 112 | int div_id, int div); |
| 113 | |
| 114 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 115 | 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] | 116 | |
| 117 | /* Digital Audio interface formatting */ |
| 118 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt); |
| 119 | |
| 120 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 121 | 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] | 122 | |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 123 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 124 | unsigned int tx_num, unsigned int *tx_slot, |
| 125 | unsigned int rx_num, unsigned int *rx_slot); |
| 126 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 127 | int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai, |
| 128 | unsigned int *tx_num, unsigned int *tx_slot, |
| 129 | unsigned int *rx_num, unsigned int *rx_slot); |
| 130 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 131 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate); |
| 132 | |
| 133 | /* Digital Audio Interface mute */ |
| 134 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute); |
| 135 | |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 136 | struct snd_soc_dai_ops { |
| 137 | /* |
| 138 | * DAI clocking configuration, all optional. |
| 139 | * Called by soc_card drivers, normally in their hw_params. |
| 140 | */ |
| 141 | int (*set_sysclk)(struct snd_soc_dai *dai, |
| 142 | int clk_id, unsigned int freq, int dir); |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 143 | int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source, |
| 144 | unsigned int freq_in, unsigned int freq_out); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 145 | int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div); |
| 146 | |
| 147 | /* |
| 148 | * DAI format configuration |
| 149 | * Called by soc_card drivers, normally in their hw_params. |
| 150 | */ |
| 151 | int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt); |
| 152 | int (*set_tdm_slot)(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 153 | unsigned int tx_mask, unsigned int rx_mask, |
| 154 | int slots, int slot_width); |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 155 | int (*set_channel_map)(struct snd_soc_dai *dai, |
| 156 | unsigned int tx_num, unsigned int *tx_slot, |
| 157 | unsigned int rx_num, unsigned int *rx_slot); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 158 | int (*set_tristate)(struct snd_soc_dai *dai, int tristate); |
| 159 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 160 | int (*get_channel_map)(struct snd_soc_dai *dai, |
| 161 | unsigned int *tx_num, unsigned int *tx_slot, |
| 162 | unsigned int *rx_num, unsigned int *rx_slot); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 163 | /* |
| 164 | * DAI digital mute - optional. |
| 165 | * Called by soc-core to minimise any pops. |
| 166 | */ |
| 167 | int (*digital_mute)(struct snd_soc_dai *dai, int mute); |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 168 | |
| 169 | /* |
| 170 | * ALSA PCM audio operations - all optional. |
| 171 | * Called by soc-core during audio PCM operations. |
| 172 | */ |
| 173 | int (*startup)(struct snd_pcm_substream *, |
| 174 | struct snd_soc_dai *); |
| 175 | void (*shutdown)(struct snd_pcm_substream *, |
| 176 | struct snd_soc_dai *); |
| 177 | int (*hw_params)(struct snd_pcm_substream *, |
| 178 | struct snd_pcm_hw_params *, struct snd_soc_dai *); |
| 179 | int (*hw_free)(struct snd_pcm_substream *, |
| 180 | struct snd_soc_dai *); |
| 181 | int (*prepare)(struct snd_pcm_substream *, |
| 182 | struct snd_soc_dai *); |
| 183 | int (*trigger)(struct snd_pcm_substream *, int, |
| 184 | struct snd_soc_dai *); |
Liam Girdwood | 59c96f1 | 2011-03-08 15:11:02 +0000 | [diff] [blame] | 185 | int (*bespoke_trigger)(struct snd_pcm_substream *, int, |
| 186 | struct snd_soc_dai *); |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 187 | /* |
| 188 | * For hardware based FIFO caused delay reporting. |
| 189 | * Optional. |
| 190 | */ |
| 191 | snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *, |
| 192 | struct snd_soc_dai *); |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | /* |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 196 | * Digital Audio Interface Driver. |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 197 | * |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 198 | * Describes the Digital Audio Interface in terms of its ALSA, DAI and AC97 |
| 199 | * operations and capabilities. Codec and platform drivers will register this |
| 200 | * structure for every DAI they have. |
| 201 | * |
| 202 | * This structure covers the clocking, formating and ALSA operations for each |
| 203 | * interface. |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 204 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 205 | struct snd_soc_dai_driver { |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 206 | /* DAI description */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 207 | const char *name; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 208 | unsigned int id; |
Mark Brown | 3ba9e10 | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 209 | int ac97_control; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 210 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 211 | /* DAI driver callbacks */ |
| 212 | int (*probe)(struct snd_soc_dai *dai); |
| 213 | int (*remove)(struct snd_soc_dai *dai); |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 214 | int (*suspend)(struct snd_soc_dai *dai); |
| 215 | int (*resume)(struct snd_soc_dai *dai); |
Vinod Koul | 0ff2361 | 2012-08-16 17:10:40 +0530 | [diff] [blame] | 216 | /* compress dai */ |
| 217 | bool compress_dai; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 218 | |
| 219 | /* ops */ |
Mark Brown | 1ee46eb | 2010-12-02 16:10:09 +0000 | [diff] [blame] | 220 | const struct snd_soc_dai_ops *ops; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 221 | |
| 222 | /* DAI capabilities */ |
| 223 | struct snd_soc_pcm_stream capture; |
| 224 | struct snd_soc_pcm_stream playback; |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 225 | unsigned int symmetric_rates:1; |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 226 | |
| 227 | /* probe ordering - for components with runtime dependencies */ |
| 228 | int probe_order; |
| 229 | int remove_order; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | /* |
| 233 | * Digital Audio Interface runtime data. |
| 234 | * |
| 235 | * Holds runtime data for a DAI. |
| 236 | */ |
| 237 | struct snd_soc_dai { |
| 238 | const char *name; |
| 239 | int id; |
| 240 | struct device *dev; |
| 241 | void *ac97_pdata; /* platform_data for the ac97 codec */ |
| 242 | |
| 243 | /* driver ops */ |
| 244 | struct snd_soc_dai_driver *driver; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 245 | |
| 246 | /* DAI runtime info */ |
Helen Zeng | 5749b09 | 2012-06-10 11:50:29 -0700 | [diff] [blame] | 247 | unsigned int capture_active; /* stream is in use */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 248 | unsigned int playback_active:1; /* stream is in use */ |
| 249 | unsigned int symmetric_rates:1; |
| 250 | struct snd_pcm_runtime *runtime; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 251 | unsigned int active; |
| 252 | unsigned char pop_wait:1; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 253 | unsigned char probed:1; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 254 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 255 | struct snd_soc_dapm_widget *playback_widget; |
| 256 | struct snd_soc_dapm_widget *capture_widget; |
| 257 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 258 | /* DAI DMA data */ |
| 259 | void *playback_dma_data; |
| 260 | void *capture_dma_data; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 261 | |
Dong Aisheng | 1784102 | 2011-08-29 17:15:14 +0800 | [diff] [blame] | 262 | /* Symmetry data - only valid if symmetry is being enforced */ |
| 263 | unsigned int rate; |
| 264 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 265 | /* parent platform/codec */ |
Mark Brown | 2466ab9 | 2012-03-02 16:18:30 +0000 | [diff] [blame] | 266 | struct snd_soc_platform *platform; |
| 267 | struct snd_soc_codec *codec; |
| 268 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 269 | struct snd_soc_card *card; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 270 | |
| 271 | struct list_head list; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 272 | struct list_head card_list; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 273 | |
| 274 | /* runtime AIF widget and channel mmap updates */ |
| 275 | u64 playback_channel_map; |
| 276 | u64 capture_channel_map; |
| 277 | struct snd_soc_dapm_widget *playback_aif; |
| 278 | struct snd_soc_dapm_widget *capture_aif; |
| 279 | bool channel_map_instanciated; |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 280 | }; |
| 281 | |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 282 | static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai, |
| 283 | const struct snd_pcm_substream *ss) |
| 284 | { |
| 285 | return (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 286 | dai->playback_dma_data : dai->capture_dma_data; |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static inline void snd_soc_dai_set_dma_data(struct snd_soc_dai *dai, |
| 290 | const struct snd_pcm_substream *ss, |
| 291 | void *data) |
| 292 | { |
| 293 | if (ss->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 294 | dai->playback_dma_data = data; |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 295 | else |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 296 | dai->capture_dma_data = data; |
| 297 | } |
| 298 | |
| 299 | static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai, |
| 300 | void *data) |
| 301 | { |
| 302 | dev_set_drvdata(dai->dev, data); |
| 303 | } |
| 304 | |
| 305 | static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai) |
| 306 | { |
| 307 | return dev_get_drvdata(dai->dev); |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Liam Girdwood | bfe7dc4 | 2011-01-31 21:26:35 +0000 | [diff] [blame] | 310 | /* Backend DAI PCM ops */ |
| 311 | static inline int snd_soc_dai_startup(struct snd_pcm_substream *substream, |
| 312 | struct snd_soc_dai *dai) |
| 313 | { |
| 314 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 315 | int ret = 0; |
| 316 | |
| 317 | mutex_lock(&rtd->pcm_mutex); |
| 318 | |
| 319 | if (dai->driver->ops->startup) |
| 320 | ret = dai->driver->ops->startup(substream, dai); |
| 321 | |
| 322 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 323 | dai->playback_active++; |
| 324 | else |
| 325 | dai->capture_active++; |
| 326 | |
| 327 | dai->active++; |
| 328 | |
| 329 | mutex_unlock(&rtd->pcm_mutex); |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | static inline void snd_soc_dai_shutdown(struct snd_pcm_substream *substream, |
| 334 | struct snd_soc_dai *dai) |
| 335 | { |
| 336 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 337 | |
| 338 | mutex_lock(&rtd->pcm_mutex); |
| 339 | |
| 340 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 341 | dai->playback_active--; |
| 342 | else |
| 343 | dai->capture_active--; |
| 344 | |
| 345 | dai->active--; |
| 346 | |
| 347 | if (dai->driver->ops->shutdown) |
| 348 | dai->driver->ops->shutdown(substream, dai); |
| 349 | mutex_unlock(&rtd->pcm_mutex); |
| 350 | } |
| 351 | |
| 352 | static inline int snd_soc_dai_hw_params(struct snd_pcm_substream * substream, |
| 353 | struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) |
| 354 | { |
| 355 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 356 | int ret = 0; |
| 357 | |
| 358 | mutex_lock(&rtd->pcm_mutex); |
| 359 | |
| 360 | if (dai->driver->ops->hw_params) |
| 361 | ret = dai->driver->ops->hw_params(substream, hw_params, dai); |
| 362 | |
| 363 | mutex_unlock(&rtd->pcm_mutex); |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | static inline int snd_soc_dai_hw_free(struct snd_pcm_substream *substream, |
| 368 | struct snd_soc_dai *dai) |
| 369 | { |
| 370 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 371 | int ret = 0; |
| 372 | |
| 373 | mutex_lock(&rtd->pcm_mutex); |
| 374 | |
| 375 | if (dai->driver->ops->hw_free) |
| 376 | ret = dai->driver->ops->hw_free(substream, dai); |
| 377 | |
| 378 | mutex_unlock(&rtd->pcm_mutex); |
| 379 | return ret; |
| 380 | } |
| 381 | |
| 382 | static inline int snd_soc_dai_prepare(struct snd_pcm_substream *substream, |
| 383 | struct snd_soc_dai *dai) |
| 384 | { |
| 385 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 386 | int ret = 0; |
| 387 | |
| 388 | mutex_lock(&rtd->pcm_mutex); |
| 389 | |
| 390 | if (dai->driver->ops->prepare) |
| 391 | ret = dai->driver->ops->prepare(substream, dai); |
| 392 | |
| 393 | mutex_unlock(&rtd->pcm_mutex); |
| 394 | return ret; |
| 395 | } |
| 396 | |
| 397 | static inline int snd_soc_dai_trigger(struct snd_pcm_substream *substream, |
| 398 | int cmd, struct snd_soc_dai *dai) |
| 399 | { |
| 400 | if (dai->driver->ops->trigger) |
| 401 | return dai->driver->ops->trigger(substream, cmd, dai); |
| 402 | return 0; |
| 403 | } |
Mark Brown | a47cbe7 | 2008-07-23 14:03:07 +0100 | [diff] [blame] | 404 | #endif |