1 /* SPDX-License-Identifier: GPL-2.0 2 * 3 * linux/sound/soc.h -- ALSA SoC Layer 4 * 5 * Author: Liam Girdwood 6 * Created: Aug 11th 2005 7 * Copyright: Wolfson Microelectronics. PLC. 8 */ 9 10 #ifndef __LINUX_SND_SOC_H 11 #define __LINUX_SND_SOC_H 12 13 #include <linux/of.h> 14 #include <linux/platform_device.h> 15 #include <linux/types.h> 16 #include <linux/notifier.h> 17 #include <linux/workqueue.h> 18 #include <linux/interrupt.h> 19 #include <linux/kernel.h> 20 #include <linux/regmap.h> 21 #include <linux/log2.h> 22 #include <sound/core.h> 23 #include <sound/pcm.h> 24 #include <sound/compress_driver.h> 25 #include <sound/control.h> 26 #include <sound/ac97_codec.h> 27 28 /* 29 * Convenience kcontrol builders 30 */ 31 #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert, xautodisable) \ 32 ((unsigned long)&(struct soc_mixer_control) \ 33 {.reg = xreg, .rreg = xreg, .shift = shift_left, \ 34 .rshift = shift_right, .max = xmax, .platform_max = xmax, \ 35 .invert = xinvert, .autodisable = xautodisable}) 36 #define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \ 37 ((unsigned long)&(struct soc_mixer_control) \ 38 {.reg = xreg, .rreg = xreg, .shift = shift_left, \ 39 .rshift = shift_right, .min = xmin, .max = xmax, .platform_max = xmax, \ 40 .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable}) 41 #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \ 42 SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable) 43 #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \ 44 ((unsigned long)&(struct soc_mixer_control) \ 45 {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert}) 46 #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \ 47 ((unsigned long)&(struct soc_mixer_control) \ 48 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \ 49 .max = xmax, .platform_max = xmax, .invert = xinvert}) 50 #define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \ 51 ((unsigned long)&(struct soc_mixer_control) \ 52 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \ 53 .max = xmax, .min = xmin, .platform_max = xmax, .sign_bit = xsign_bit, \ 54 .invert = xinvert}) 55 #define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \ 56 ((unsigned long)&(struct soc_mixer_control) \ 57 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \ 58 .min = xmin, .max = xmax, .platform_max = xmax, .invert = xinvert}) 59 #define SOC_SINGLE(xname, reg, shift, max, invert) \ 60 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 61 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ 62 .put = snd_soc_put_volsw, \ 63 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) } 64 #define SOC_SINGLE_RANGE(xname, xreg, xshift, xmin, xmax, xinvert) \ 65 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 66 .info = snd_soc_info_volsw_range, .get = snd_soc_get_volsw_range, \ 67 .put = snd_soc_put_volsw_range, \ 68 .private_value = (unsigned long)&(struct soc_mixer_control) \ 69 {.reg = xreg, .rreg = xreg, .shift = xshift, \ 70 .rshift = xshift, .min = xmin, .max = xmax, \ 71 .platform_max = xmax, .invert = xinvert} } 72 #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \ 73 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 74 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 75 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 76 .tlv.p = (tlv_array), \ 77 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ 78 .put = snd_soc_put_volsw, \ 79 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) } 80 #define SOC_SINGLE_SX_TLV(xname, xreg, xshift, xmin, xmax, tlv_array) \ 81 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 82 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 83 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 84 .tlv.p = (tlv_array),\ 85 .info = snd_soc_info_volsw_sx, \ 86 .get = snd_soc_get_volsw_sx,\ 87 .put = snd_soc_put_volsw_sx, \ 88 .private_value = (unsigned long)&(struct soc_mixer_control) \ 89 {.reg = xreg, .rreg = xreg, \ 90 .shift = xshift, .rshift = xshift, \ 91 .max = xmax, .min = xmin} } 92 #define SOC_SINGLE_RANGE_TLV(xname, xreg, xshift, xmin, xmax, xinvert, tlv_array) \ 93 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 94 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 95 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 96 .tlv.p = (tlv_array), \ 97 .info = snd_soc_info_volsw_range, \ 98 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ 99 .private_value = (unsigned long)&(struct soc_mixer_control) \ 100 {.reg = xreg, .rreg = xreg, .shift = xshift, \ 101 .rshift = xshift, .min = xmin, .max = xmax, \ 102 .platform_max = xmax, .invert = xinvert} } 103 #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \ 104 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 105 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ 106 .put = snd_soc_put_volsw, \ 107 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \ 108 max, invert, 0) } 109 #define SOC_DOUBLE_STS(xname, reg, shift_left, shift_right, max, invert) \ 110 { \ 111 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 112 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ 113 .access = SNDRV_CTL_ELEM_ACCESS_READ | \ 114 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ 115 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \ 116 max, invert, 0) } 117 #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \ 118 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 119 .info = snd_soc_info_volsw, \ 120 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \ 121 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \ 122 xmax, xinvert) } 123 #define SOC_DOUBLE_R_RANGE(xname, reg_left, reg_right, xshift, xmin, \ 124 xmax, xinvert) \ 125 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 126 .info = snd_soc_info_volsw_range, \ 127 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ 128 .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \ 129 xshift, xmin, xmax, xinvert) } 130 #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \ 131 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 132 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 133 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 134 .tlv.p = (tlv_array), \ 135 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ 136 .put = snd_soc_put_volsw, \ 137 .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \ 138 max, invert, 0) } 139 #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \ 140 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 141 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 142 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 143 .tlv.p = (tlv_array), \ 144 .info = snd_soc_info_volsw, \ 145 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \ 146 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \ 147 xmax, xinvert) } 148 #define SOC_DOUBLE_R_RANGE_TLV(xname, reg_left, reg_right, xshift, xmin, \ 149 xmax, xinvert, tlv_array) \ 150 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 151 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 152 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 153 .tlv.p = (tlv_array), \ 154 .info = snd_soc_info_volsw_range, \ 155 .get = snd_soc_get_volsw_range, .put = snd_soc_put_volsw_range, \ 156 .private_value = SOC_DOUBLE_R_RANGE_VALUE(reg_left, reg_right, \ 157 xshift, xmin, xmax, xinvert) } 158 #define SOC_DOUBLE_R_SX_TLV(xname, xreg, xrreg, xshift, xmin, xmax, tlv_array) \ 159 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 160 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 161 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 162 .tlv.p = (tlv_array), \ 163 .info = snd_soc_info_volsw_sx, \ 164 .get = snd_soc_get_volsw_sx, \ 165 .put = snd_soc_put_volsw_sx, \ 166 .private_value = (unsigned long)&(struct soc_mixer_control) \ 167 {.reg = xreg, .rreg = xrreg, \ 168 .shift = xshift, .rshift = xshift, \ 169 .max = xmax, .min = xmin} } 170 #define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \ 171 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 172 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 173 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 174 .tlv.p = (tlv_array), \ 175 .info = snd_soc_info_volsw, \ 176 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \ 177 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \ 178 xmin, xmax, xsign_bit, xinvert) } 179 #define SOC_SINGLE_S_TLV(xname, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \ 180 SOC_DOUBLE_R_S_TLV(xname, xreg, xreg, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) 181 #define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \ 182 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 183 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 184 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 185 .tlv.p = (tlv_array), \ 186 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ 187 .put = snd_soc_put_volsw, \ 188 .private_value = (unsigned long)&(struct soc_mixer_control) \ 189 {.reg = xreg, .rreg = xreg, \ 190 .min = xmin, .max = xmax, .platform_max = xmax, \ 191 .sign_bit = 7,} } 192 #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \ 193 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 194 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 195 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 196 .tlv.p = (tlv_array), \ 197 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ 198 .put = snd_soc_put_volsw, \ 199 .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) } 200 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \ 201 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 202 .items = xitems, .texts = xtexts, \ 203 .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0} 204 #define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \ 205 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts) 206 #define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \ 207 { .items = xitems, .texts = xtexts } 208 #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \ 209 { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 210 .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues} 211 #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \ 212 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues) 213 #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \ 214 { .reg = xreg, .shift_l = xshift, .shift_r = xshift, \ 215 .mask = xmask, .items = xitems, .texts = xtexts, \ 216 .values = xvalues, .autodisable = 1} 217 #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \ 218 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts) 219 #define SOC_ENUM(xname, xenum) \ 220 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\ 221 .info = snd_soc_info_enum_double, \ 222 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \ 223 .private_value = (unsigned long)&xenum } 224 #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\ 225 xhandler_get, xhandler_put) \ 226 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 227 .info = snd_soc_info_volsw, \ 228 .get = xhandler_get, .put = xhandler_put, \ 229 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) } 230 #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\ 231 xhandler_get, xhandler_put) \ 232 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 233 .info = snd_soc_info_volsw, \ 234 .get = xhandler_get, .put = xhandler_put, \ 235 .private_value = \ 236 SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert, 0) } 237 #define SOC_DOUBLE_R_EXT(xname, reg_left, reg_right, xshift, xmax, xinvert,\ 238 xhandler_get, xhandler_put) \ 239 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 240 .info = snd_soc_info_volsw, \ 241 .get = xhandler_get, .put = xhandler_put, \ 242 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \ 243 xmax, xinvert) } 244 #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\ 245 xhandler_get, xhandler_put, tlv_array) \ 246 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 247 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 248 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 249 .tlv.p = (tlv_array), \ 250 .info = snd_soc_info_volsw, \ 251 .get = xhandler_get, .put = xhandler_put, \ 252 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) } 253 #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \ 254 xhandler_get, xhandler_put, tlv_array) \ 255 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 256 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 257 SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 258 .tlv.p = (tlv_array), \ 259 .info = snd_soc_info_volsw_range, \ 260 .get = xhandler_get, .put = xhandler_put, \ 261 .private_value = (unsigned long)&(struct soc_mixer_control) \ 262 {.reg = xreg, .rreg = xreg, .shift = xshift, \ 263 .rshift = xshift, .min = xmin, .max = xmax, \ 264 .platform_max = xmax, .invert = xinvert} } 265 #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\ 266 xhandler_get, xhandler_put, tlv_array) \ 267 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 268 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 269 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 270 .tlv.p = (tlv_array), \ 271 .info = snd_soc_info_volsw, \ 272 .get = xhandler_get, .put = xhandler_put, \ 273 .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \ 274 xmax, xinvert, 0) } 275 #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\ 276 xhandler_get, xhandler_put, tlv_array) \ 277 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 278 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 279 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 280 .tlv.p = (tlv_array), \ 281 .info = snd_soc_info_volsw, \ 282 .get = xhandler_get, .put = xhandler_put, \ 283 .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \ 284 xmax, xinvert) } 285 #define SOC_DOUBLE_R_S_EXT_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, \ 286 xsign_bit, xinvert, xhandler_get, xhandler_put, \ 287 tlv_array) \ 288 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 289 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 290 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 291 .tlv.p = (tlv_array), \ 292 .info = snd_soc_info_volsw, \ 293 .get = xhandler_get, .put = xhandler_put, \ 294 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \ 295 xmin, xmax, xsign_bit, xinvert) } 296 #define SOC_SINGLE_S_EXT_TLV(xname, xreg, xshift, xmin, xmax, \ 297 xsign_bit, xinvert, xhandler_get, xhandler_put, \ 298 tlv_array) \ 299 SOC_DOUBLE_R_S_EXT_TLV(xname, xreg, xreg, xshift, xmin, xmax, \ 300 xsign_bit, xinvert, xhandler_get, xhandler_put, \ 301 tlv_array) 302 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \ 303 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 304 .info = snd_soc_info_bool_ext, \ 305 .get = xhandler_get, .put = xhandler_put, \ 306 .private_value = xdata } 307 #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \ 308 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 309 .info = snd_soc_info_enum_double, \ 310 .get = xhandler_get, .put = xhandler_put, \ 311 .private_value = (unsigned long)&xenum } 312 #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \ 313 SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) 314 315 #define SND_SOC_BYTES(xname, xbase, xregs) \ 316 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 317 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \ 318 .put = snd_soc_bytes_put, .private_value = \ 319 ((unsigned long)&(struct soc_bytes) \ 320 {.base = xbase, .num_regs = xregs }) } 321 #define SND_SOC_BYTES_E(xname, xbase, xregs, xhandler_get, xhandler_put) \ 322 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 323 .info = snd_soc_bytes_info, .get = xhandler_get, \ 324 .put = xhandler_put, .private_value = \ 325 ((unsigned long)&(struct soc_bytes) \ 326 {.base = xbase, .num_regs = xregs }) } 327 328 #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask) \ 329 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 330 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \ 331 .put = snd_soc_bytes_put, .private_value = \ 332 ((unsigned long)&(struct soc_bytes) \ 333 {.base = xbase, .num_regs = xregs, \ 334 .mask = xmask }) } 335 336 /* 337 * SND_SOC_BYTES_EXT is deprecated, please USE SND_SOC_BYTES_TLV instead 338 */ 339 #define SND_SOC_BYTES_EXT(xname, xcount, xhandler_get, xhandler_put) \ 340 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 341 .info = snd_soc_bytes_info_ext, \ 342 .get = xhandler_get, .put = xhandler_put, \ 343 .private_value = (unsigned long)&(struct soc_bytes_ext) \ 344 {.max = xcount} } 345 #define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \ 346 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 347 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \ 348 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \ 349 .tlv.c = (snd_soc_bytes_tlv_callback), \ 350 .info = snd_soc_bytes_info_ext, \ 351 .private_value = (unsigned long)&(struct soc_bytes_ext) \ 352 {.max = xcount, .get = xhandler_get, .put = xhandler_put, } } 353 #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \ 354 xmin, xmax, xinvert) \ 355 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 356 .info = snd_soc_info_xr_sx, .get = snd_soc_get_xr_sx, \ 357 .put = snd_soc_put_xr_sx, \ 358 .private_value = (unsigned long)&(struct soc_mreg_control) \ 359 {.regbase = xregbase, .regcount = xregcount, .nbits = xnbits, \ 360 .invert = xinvert, .min = xmin, .max = xmax} } 361 362 #define SOC_SINGLE_STROBE(xname, xreg, xshift, xinvert) \ 363 SOC_SINGLE_EXT(xname, xreg, xshift, 1, xinvert, \ 364 snd_soc_get_strobe, snd_soc_put_strobe) 365 366 /* 367 * Simplified versions of above macros, declaring a struct and calculating 368 * ARRAY_SIZE internally 369 */ 370 #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \ 371 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \ 372 ARRAY_SIZE(xtexts), xtexts) 373 #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \ 374 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts) 375 #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \ 376 const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts) 377 #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \ 378 const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \ 379 ARRAY_SIZE(xtexts), xtexts, xvalues) 380 #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \ 381 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues) 382 383 #define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \ 384 const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \ 385 xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues) 386 387 #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \ 388 const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts) 389 390 struct device_node; 391 struct snd_jack; 392 struct snd_soc_card; 393 struct snd_soc_pcm_stream; 394 struct snd_soc_ops; 395 struct snd_soc_pcm_runtime; 396 struct snd_soc_dai; 397 struct snd_soc_dai_driver; 398 struct snd_soc_dai_link; 399 struct snd_soc_component; 400 struct snd_soc_component_driver; 401 struct soc_enum; 402 struct snd_soc_jack; 403 struct snd_soc_jack_zone; 404 struct snd_soc_jack_pin; 405 #include <sound/soc-dapm.h> 406 #include <sound/soc-dpcm.h> 407 #include <sound/soc-topology.h> 408 409 struct snd_soc_jack_gpio; 410 411 enum snd_soc_pcm_subclass { 412 SND_SOC_PCM_CLASS_PCM = 0, 413 SND_SOC_PCM_CLASS_BE = 1, 414 }; 415 416 int snd_soc_register_card(struct snd_soc_card *card); 417 int snd_soc_unregister_card(struct snd_soc_card *card); 418 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card); 419 #ifdef CONFIG_PM_SLEEP 420 int snd_soc_suspend(struct device *dev); 421 int snd_soc_resume(struct device *dev); 422 #else 423 static inline int snd_soc_suspend(struct device *dev) 424 { 425 return 0; 426 } 427 428 static inline int snd_soc_resume(struct device *dev) 429 { 430 return 0; 431 } 432 #endif 433 int snd_soc_poweroff(struct device *dev); 434 int snd_soc_component_initialize(struct snd_soc_component *component, 435 const struct snd_soc_component_driver *driver, 436 struct device *dev); 437 int snd_soc_add_component(struct snd_soc_component *component, 438 struct snd_soc_dai_driver *dai_drv, 439 int num_dai); 440 int snd_soc_register_component(struct device *dev, 441 const struct snd_soc_component_driver *component_driver, 442 struct snd_soc_dai_driver *dai_drv, int num_dai); 443 int devm_snd_soc_register_component(struct device *dev, 444 const struct snd_soc_component_driver *component_driver, 445 struct snd_soc_dai_driver *dai_drv, int num_dai); 446 void snd_soc_unregister_component(struct device *dev); 447 void snd_soc_unregister_component_by_driver(struct device *dev, 448 const struct snd_soc_component_driver *component_driver); 449 struct snd_soc_component *snd_soc_lookup_component_nolocked(struct device *dev, 450 const char *driver_name); 451 struct snd_soc_component *snd_soc_lookup_component(struct device *dev, 452 const char *driver_name); 453 454 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num); 455 #ifdef CONFIG_SND_SOC_COMPRESS 456 int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num); 457 #else 458 static inline int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) 459 { 460 return 0; 461 } 462 #endif 463 464 void snd_soc_disconnect_sync(struct device *dev); 465 466 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, 467 struct snd_soc_dai_link *dai_link); 468 469 bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd); 470 471 void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd, 472 int stream, int action); 473 static inline void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, 474 int stream) 475 { 476 snd_soc_runtime_action(rtd, stream, 1); 477 } 478 static inline void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, 479 int stream) 480 { 481 snd_soc_runtime_action(rtd, stream, -1); 482 } 483 484 int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd, 485 struct snd_pcm_hardware *hw, int stream); 486 487 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, 488 unsigned int dai_fmt); 489 490 #ifdef CONFIG_DMI 491 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour); 492 #else 493 static inline int snd_soc_set_dmi_name(struct snd_soc_card *card, 494 const char *flavour) 495 { 496 return 0; 497 } 498 #endif 499 500 /* Utility functions to get clock rates from various things */ 501 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots); 502 int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params); 503 int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots); 504 int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms); 505 int snd_soc_tdm_params_to_bclk(struct snd_pcm_hw_params *params, 506 int tdm_width, int tdm_slots, int slot_multiple); 507 508 /* set runtime hw params */ 509 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, 510 const struct snd_pcm_hardware *hw); 511 512 struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component); 513 struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component, 514 unsigned int id, unsigned int id_mask); 515 void snd_soc_free_ac97_component(struct snd_ac97 *ac97); 516 517 #ifdef CONFIG_SND_SOC_AC97_BUS 518 int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops); 519 int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, 520 struct platform_device *pdev); 521 522 extern struct snd_ac97_bus_ops *soc_ac97_ops; 523 #else 524 static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, 525 struct platform_device *pdev) 526 { 527 return 0; 528 } 529 530 static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops) 531 { 532 return 0; 533 } 534 #endif 535 536 /* 537 *Controls 538 */ 539 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 540 void *data, const char *long_name, 541 const char *prefix); 542 int snd_soc_add_component_controls(struct snd_soc_component *component, 543 const struct snd_kcontrol_new *controls, unsigned int num_controls); 544 int snd_soc_add_card_controls(struct snd_soc_card *soc_card, 545 const struct snd_kcontrol_new *controls, int num_controls); 546 int snd_soc_add_dai_controls(struct snd_soc_dai *dai, 547 const struct snd_kcontrol_new *controls, int num_controls); 548 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, 549 struct snd_ctl_elem_info *uinfo); 550 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, 551 struct snd_ctl_elem_value *ucontrol); 552 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 553 struct snd_ctl_elem_value *ucontrol); 554 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, 555 struct snd_ctl_elem_info *uinfo); 556 int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol, 557 struct snd_ctl_elem_info *uinfo); 558 #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info 559 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, 560 struct snd_ctl_elem_value *ucontrol); 561 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, 562 struct snd_ctl_elem_value *ucontrol); 563 #define snd_soc_get_volsw_2r snd_soc_get_volsw 564 #define snd_soc_put_volsw_2r snd_soc_put_volsw 565 int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, 566 struct snd_ctl_elem_value *ucontrol); 567 int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, 568 struct snd_ctl_elem_value *ucontrol); 569 int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, 570 struct snd_ctl_elem_info *uinfo); 571 int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, 572 struct snd_ctl_elem_value *ucontrol); 573 int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, 574 struct snd_ctl_elem_value *ucontrol); 575 int snd_soc_limit_volume(struct snd_soc_card *card, 576 const char *name, int max); 577 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, 578 struct snd_ctl_elem_info *uinfo); 579 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, 580 struct snd_ctl_elem_value *ucontrol); 581 int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, 582 struct snd_ctl_elem_value *ucontrol); 583 int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol, 584 struct snd_ctl_elem_info *ucontrol); 585 int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag, 586 unsigned int size, unsigned int __user *tlv); 587 int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, 588 struct snd_ctl_elem_info *uinfo); 589 int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, 590 struct snd_ctl_elem_value *ucontrol); 591 int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, 592 struct snd_ctl_elem_value *ucontrol); 593 int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, 594 struct snd_ctl_elem_value *ucontrol); 595 int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, 596 struct snd_ctl_elem_value *ucontrol); 597 598 /* SoC PCM stream information */ 599 struct snd_soc_pcm_stream { 600 const char *stream_name; 601 u64 formats; /* SNDRV_PCM_FMTBIT_* */ 602 unsigned int rates; /* SNDRV_PCM_RATE_* */ 603 unsigned int rate_min; /* min rate */ 604 unsigned int rate_max; /* max rate */ 605 unsigned int channels_min; /* min channels */ 606 unsigned int channels_max; /* max channels */ 607 unsigned int sig_bits; /* number of bits of content */ 608 }; 609 610 /* SoC audio ops */ 611 struct snd_soc_ops { 612 int (*startup)(struct snd_pcm_substream *); 613 void (*shutdown)(struct snd_pcm_substream *); 614 int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *); 615 int (*hw_free)(struct snd_pcm_substream *); 616 int (*prepare)(struct snd_pcm_substream *); 617 int (*trigger)(struct snd_pcm_substream *, int); 618 }; 619 620 struct snd_soc_compr_ops { 621 int (*startup)(struct snd_compr_stream *); 622 void (*shutdown)(struct snd_compr_stream *); 623 int (*set_params)(struct snd_compr_stream *); 624 int (*trigger)(struct snd_compr_stream *); 625 }; 626 627 struct snd_soc_component* 628 snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd, 629 const char *driver_name); 630 631 struct snd_soc_dai_link_component { 632 const char *name; 633 struct device_node *of_node; 634 const char *dai_name; 635 }; 636 637 struct snd_soc_dai_link { 638 /* config - must be set by machine driver */ 639 const char *name; /* Codec name */ 640 const char *stream_name; /* Stream name */ 641 642 /* 643 * You MAY specify the link's CPU-side device, either by device name, 644 * or by DT/OF node, but not both. If this information is omitted, 645 * the CPU-side DAI is matched using .cpu_dai_name only, which hence 646 * must be globally unique. These fields are currently typically used 647 * only for codec to codec links, or systems using device tree. 648 */ 649 /* 650 * You MAY specify the DAI name of the CPU DAI. If this information is 651 * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node 652 * only, which only works well when that device exposes a single DAI. 653 */ 654 struct snd_soc_dai_link_component *cpus; 655 unsigned int num_cpus; 656 657 /* 658 * You MUST specify the link's codec, either by device name, or by 659 * DT/OF node, but not both. 660 */ 661 /* You MUST specify the DAI name within the codec */ 662 struct snd_soc_dai_link_component *codecs; 663 unsigned int num_codecs; 664 665 /* 666 * You MAY specify the link's platform/PCM/DMA driver, either by 667 * device name, or by DT/OF node, but not both. Some forms of link 668 * do not need a platform. In such case, platforms are not mandatory. 669 */ 670 struct snd_soc_dai_link_component *platforms; 671 unsigned int num_platforms; 672 673 int id; /* optional ID for machine driver link identification */ 674 675 const struct snd_soc_pcm_stream *params; 676 unsigned int num_params; 677 678 unsigned int dai_fmt; /* format to set on init */ 679 680 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */ 681 682 /* codec/machine specific init - e.g. add machine controls */ 683 int (*init)(struct snd_soc_pcm_runtime *rtd); 684 685 /* codec/machine specific exit - dual of init() */ 686 void (*exit)(struct snd_soc_pcm_runtime *rtd); 687 688 /* optional hw_params re-writing for BE and FE sync */ 689 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd, 690 struct snd_pcm_hw_params *params); 691 692 /* machine stream operations */ 693 const struct snd_soc_ops *ops; 694 const struct snd_soc_compr_ops *compr_ops; 695 696 /* Mark this pcm with non atomic ops */ 697 unsigned int nonatomic:1; 698 699 /* For unidirectional dai links */ 700 unsigned int playback_only:1; 701 unsigned int capture_only:1; 702 703 /* Keep DAI active over suspend */ 704 unsigned int ignore_suspend:1; 705 706 /* Symmetry requirements */ 707 unsigned int symmetric_rate:1; 708 unsigned int symmetric_channels:1; 709 unsigned int symmetric_sample_bits:1; 710 711 /* Do not create a PCM for this DAI link (Backend link) */ 712 unsigned int no_pcm:1; 713 714 /* This DAI link can route to other DAI links at runtime (Frontend)*/ 715 unsigned int dynamic:1; 716 717 /* DPCM capture and Playback support */ 718 unsigned int dpcm_capture:1; 719 unsigned int dpcm_playback:1; 720 721 /* DPCM used FE & BE merged format */ 722 unsigned int dpcm_merged_format:1; 723 /* DPCM used FE & BE merged channel */ 724 unsigned int dpcm_merged_chan:1; 725 /* DPCM used FE & BE merged rate */ 726 unsigned int dpcm_merged_rate:1; 727 728 /* pmdown_time is ignored at stop */ 729 unsigned int ignore_pmdown_time:1; 730 731 /* Do not create a PCM for this DAI link (Backend link) */ 732 unsigned int ignore:1; 733 734 /* This flag will reorder stop sequence. By enabling this flag 735 * DMA controller stop sequence will be invoked first followed by 736 * CPU DAI driver stop sequence 737 */ 738 unsigned int stop_dma_first:1; 739 740 #ifdef CONFIG_SND_SOC_TOPOLOGY 741 struct snd_soc_dobj dobj; /* For topology */ 742 #endif 743 }; 744 745 static inline struct snd_soc_dai_link_component* 746 asoc_link_to_cpu(struct snd_soc_dai_link *link, int n) { 747 return &(link)->cpus[n]; 748 } 749 750 static inline struct snd_soc_dai_link_component* 751 asoc_link_to_codec(struct snd_soc_dai_link *link, int n) { 752 return &(link)->codecs[n]; 753 } 754 755 static inline struct snd_soc_dai_link_component* 756 asoc_link_to_platform(struct snd_soc_dai_link *link, int n) { 757 return &(link)->platforms[n]; 758 } 759 760 #define for_each_link_codecs(link, i, codec) \ 761 for ((i) = 0; \ 762 ((i) < link->num_codecs) && \ 763 ((codec) = asoc_link_to_codec(link, i)); \ 764 (i)++) 765 766 #define for_each_link_platforms(link, i, platform) \ 767 for ((i) = 0; \ 768 ((i) < link->num_platforms) && \ 769 ((platform) = asoc_link_to_platform(link, i)); \ 770 (i)++) 771 772 #define for_each_link_cpus(link, i, cpu) \ 773 for ((i) = 0; \ 774 ((i) < link->num_cpus) && \ 775 ((cpu) = asoc_link_to_cpu(link, i)); \ 776 (i)++) 777 778 /* 779 * Sample 1 : Single CPU/Codec/Platform 780 * 781 * SND_SOC_DAILINK_DEFS(test, 782 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai")), 783 * DAILINK_COMP_ARRAY(COMP_CODEC("codec", "codec_dai")), 784 * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform"))); 785 * 786 * struct snd_soc_dai_link link = { 787 * ... 788 * SND_SOC_DAILINK_REG(test), 789 * }; 790 * 791 * Sample 2 : Multi CPU/Codec, no Platform 792 * 793 * SND_SOC_DAILINK_DEFS(test, 794 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"), 795 * COMP_CPU("cpu_dai2")), 796 * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"), 797 * COMP_CODEC("codec2", "codec_dai2"))); 798 * 799 * struct snd_soc_dai_link link = { 800 * ... 801 * SND_SOC_DAILINK_REG(test), 802 * }; 803 * 804 * Sample 3 : Define each CPU/Codec/Platform manually 805 * 806 * SND_SOC_DAILINK_DEF(test_cpu, 807 * DAILINK_COMP_ARRAY(COMP_CPU("cpu_dai1"), 808 * COMP_CPU("cpu_dai2"))); 809 * SND_SOC_DAILINK_DEF(test_codec, 810 * DAILINK_COMP_ARRAY(COMP_CODEC("codec1", "codec_dai1"), 811 * COMP_CODEC("codec2", "codec_dai2"))); 812 * SND_SOC_DAILINK_DEF(test_platform, 813 * DAILINK_COMP_ARRAY(COMP_PLATFORM("platform"))); 814 * 815 * struct snd_soc_dai_link link = { 816 * ... 817 * SND_SOC_DAILINK_REG(test_cpu, 818 * test_codec, 819 * test_platform), 820 * }; 821 * 822 * Sample 4 : Sample3 without platform 823 * 824 * struct snd_soc_dai_link link = { 825 * ... 826 * SND_SOC_DAILINK_REG(test_cpu, 827 * test_codec); 828 * }; 829 */ 830 831 #define SND_SOC_DAILINK_REG1(name) SND_SOC_DAILINK_REG3(name##_cpus, name##_codecs, name##_platforms) 832 #define SND_SOC_DAILINK_REG2(cpu, codec) SND_SOC_DAILINK_REG3(cpu, codec, null_dailink_component) 833 #define SND_SOC_DAILINK_REG3(cpu, codec, platform) \ 834 .cpus = cpu, \ 835 .num_cpus = ARRAY_SIZE(cpu), \ 836 .codecs = codec, \ 837 .num_codecs = ARRAY_SIZE(codec), \ 838 .platforms = platform, \ 839 .num_platforms = ARRAY_SIZE(platform) 840 841 #define SND_SOC_DAILINK_REGx(_1, _2, _3, func, ...) func 842 #define SND_SOC_DAILINK_REG(...) \ 843 SND_SOC_DAILINK_REGx(__VA_ARGS__, \ 844 SND_SOC_DAILINK_REG3, \ 845 SND_SOC_DAILINK_REG2, \ 846 SND_SOC_DAILINK_REG1)(__VA_ARGS__) 847 848 #define SND_SOC_DAILINK_DEF(name, def...) \ 849 static struct snd_soc_dai_link_component name[] = { def } 850 851 #define SND_SOC_DAILINK_DEFS(name, cpu, codec, platform...) \ 852 SND_SOC_DAILINK_DEF(name##_cpus, cpu); \ 853 SND_SOC_DAILINK_DEF(name##_codecs, codec); \ 854 SND_SOC_DAILINK_DEF(name##_platforms, platform) 855 856 #define DAILINK_COMP_ARRAY(param...) param 857 #define COMP_EMPTY() { } 858 #define COMP_CPU(_dai) { .dai_name = _dai, } 859 #define COMP_CODEC(_name, _dai) { .name = _name, .dai_name = _dai, } 860 #define COMP_PLATFORM(_name) { .name = _name } 861 #define COMP_AUX(_name) { .name = _name } 862 #define COMP_CODEC_CONF(_name) { .name = _name } 863 #define COMP_DUMMY() { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", } 864 865 extern struct snd_soc_dai_link_component null_dailink_component[0]; 866 867 868 struct snd_soc_codec_conf { 869 /* 870 * specify device either by device name, or by 871 * DT/OF node, but not both. 872 */ 873 struct snd_soc_dai_link_component dlc; 874 875 /* 876 * optional map of kcontrol, widget and path name prefixes that are 877 * associated per device 878 */ 879 const char *name_prefix; 880 }; 881 882 struct snd_soc_aux_dev { 883 /* 884 * specify multi-codec either by device name, or by 885 * DT/OF node, but not both. 886 */ 887 struct snd_soc_dai_link_component dlc; 888 889 /* codec/machine specific init - e.g. add machine controls */ 890 int (*init)(struct snd_soc_component *component); 891 }; 892 893 /* SoC card */ 894 struct snd_soc_card { 895 const char *name; 896 const char *long_name; 897 const char *driver_name; 898 const char *components; 899 #ifdef CONFIG_DMI 900 char dmi_longname[80]; 901 #endif /* CONFIG_DMI */ 902 char topology_shortname[32]; 903 904 struct device *dev; 905 struct snd_card *snd_card; 906 struct module *owner; 907 908 struct mutex mutex; 909 struct mutex dapm_mutex; 910 911 /* Mutex for PCM operations */ 912 struct mutex pcm_mutex; 913 enum snd_soc_pcm_subclass pcm_subclass; 914 915 int (*probe)(struct snd_soc_card *card); 916 int (*late_probe)(struct snd_soc_card *card); 917 int (*remove)(struct snd_soc_card *card); 918 919 /* the pre and post PM functions are used to do any PM work before and 920 * after the codec and DAI's do any PM work. */ 921 int (*suspend_pre)(struct snd_soc_card *card); 922 int (*suspend_post)(struct snd_soc_card *card); 923 int (*resume_pre)(struct snd_soc_card *card); 924 int (*resume_post)(struct snd_soc_card *card); 925 926 /* callbacks */ 927 int (*set_bias_level)(struct snd_soc_card *, 928 struct snd_soc_dapm_context *dapm, 929 enum snd_soc_bias_level level); 930 int (*set_bias_level_post)(struct snd_soc_card *, 931 struct snd_soc_dapm_context *dapm, 932 enum snd_soc_bias_level level); 933 934 int (*add_dai_link)(struct snd_soc_card *, 935 struct snd_soc_dai_link *link); 936 void (*remove_dai_link)(struct snd_soc_card *, 937 struct snd_soc_dai_link *link); 938 939 long pmdown_time; 940 941 /* CPU <--> Codec DAI links */ 942 struct snd_soc_dai_link *dai_link; /* predefined links only */ 943 int num_links; /* predefined links only */ 944 945 struct list_head rtd_list; 946 int num_rtd; 947 948 /* optional codec specific configuration */ 949 struct snd_soc_codec_conf *codec_conf; 950 int num_configs; 951 952 /* 953 * optional auxiliary devices such as amplifiers or codecs with DAI 954 * link unused 955 */ 956 struct snd_soc_aux_dev *aux_dev; 957 int num_aux_devs; 958 struct list_head aux_comp_list; 959 960 const struct snd_kcontrol_new *controls; 961 int num_controls; 962 963 /* 964 * Card-specific routes and widgets. 965 * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in. 966 */ 967 const struct snd_soc_dapm_widget *dapm_widgets; 968 int num_dapm_widgets; 969 const struct snd_soc_dapm_route *dapm_routes; 970 int num_dapm_routes; 971 const struct snd_soc_dapm_widget *of_dapm_widgets; 972 int num_of_dapm_widgets; 973 const struct snd_soc_dapm_route *of_dapm_routes; 974 int num_of_dapm_routes; 975 976 /* lists of probed devices belonging to this card */ 977 struct list_head component_dev_list; 978 struct list_head list; 979 980 struct list_head widgets; 981 struct list_head paths; 982 struct list_head dapm_list; 983 struct list_head dapm_dirty; 984 985 /* attached dynamic objects */ 986 struct list_head dobj_list; 987 988 /* Generic DAPM context for the card */ 989 struct snd_soc_dapm_context dapm; 990 struct snd_soc_dapm_stats dapm_stats; 991 struct snd_soc_dapm_update *update; 992 993 #ifdef CONFIG_DEBUG_FS 994 struct dentry *debugfs_card_root; 995 #endif 996 #ifdef CONFIG_PM_SLEEP 997 struct work_struct deferred_resume_work; 998 #endif 999 u32 pop_time; 1000 1001 /* bit field */ 1002 unsigned int instantiated:1; 1003 unsigned int topology_shortname_created:1; 1004 unsigned int fully_routed:1; 1005 unsigned int disable_route_checks:1; 1006 unsigned int probed:1; 1007 unsigned int component_chaining:1; 1008 1009 void *drvdata; 1010 }; 1011 #define for_each_card_prelinks(card, i, link) \ 1012 for ((i) = 0; \ 1013 ((i) < (card)->num_links) && ((link) = &(card)->dai_link[i]); \ 1014 (i)++) 1015 #define for_each_card_pre_auxs(card, i, aux) \ 1016 for ((i) = 0; \ 1017 ((i) < (card)->num_aux_devs) && ((aux) = &(card)->aux_dev[i]); \ 1018 (i)++) 1019 1020 #define for_each_card_rtds(card, rtd) \ 1021 list_for_each_entry(rtd, &(card)->rtd_list, list) 1022 #define for_each_card_rtds_safe(card, rtd, _rtd) \ 1023 list_for_each_entry_safe(rtd, _rtd, &(card)->rtd_list, list) 1024 1025 #define for_each_card_auxs(card, component) \ 1026 list_for_each_entry(component, &card->aux_comp_list, card_aux_list) 1027 #define for_each_card_auxs_safe(card, component, _comp) \ 1028 list_for_each_entry_safe(component, _comp, \ 1029 &card->aux_comp_list, card_aux_list) 1030 1031 #define for_each_card_components(card, component) \ 1032 list_for_each_entry(component, &(card)->component_dev_list, card_list) 1033 1034 #define for_each_card_dapms(card, dapm) \ 1035 list_for_each_entry(dapm, &card->dapm_list, list) 1036 1037 #define for_each_card_widgets(card, w)\ 1038 list_for_each_entry(w, &card->widgets, list) 1039 #define for_each_card_widgets_safe(card, w, _w) \ 1040 list_for_each_entry_safe(w, _w, &card->widgets, list) 1041 1042 /* SoC machine DAI configuration, glues a codec and cpu DAI together */ 1043 struct snd_soc_pcm_runtime { 1044 struct device *dev; 1045 struct snd_soc_card *card; 1046 struct snd_soc_dai_link *dai_link; 1047 struct snd_pcm_ops ops; 1048 1049 unsigned int params_select; /* currently selected param for dai link */ 1050 1051 /* Dynamic PCM BE runtime data */ 1052 struct snd_soc_dpcm_runtime dpcm[2]; 1053 1054 long pmdown_time; 1055 1056 /* runtime devices */ 1057 struct snd_pcm *pcm; 1058 struct snd_compr *compr; 1059 1060 /* 1061 * dais = cpu_dai + codec_dai 1062 * see 1063 * soc_new_pcm_runtime() 1064 * asoc_rtd_to_cpu() 1065 * asoc_rtd_to_codec() 1066 */ 1067 struct snd_soc_dai **dais; 1068 unsigned int num_codecs; 1069 unsigned int num_cpus; 1070 1071 struct snd_soc_dapm_widget *playback_widget; 1072 struct snd_soc_dapm_widget *capture_widget; 1073 1074 struct delayed_work delayed_work; 1075 void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd); 1076 #ifdef CONFIG_DEBUG_FS 1077 struct dentry *debugfs_dpcm_root; 1078 #endif 1079 1080 unsigned int num; /* 0-based and monotonic increasing */ 1081 struct list_head list; /* rtd list of the soc card */ 1082 1083 /* function mark */ 1084 struct snd_pcm_substream *mark_startup; 1085 struct snd_pcm_substream *mark_hw_params; 1086 struct snd_pcm_substream *mark_trigger; 1087 struct snd_compr_stream *mark_compr_startup; 1088 1089 /* bit field */ 1090 unsigned int pop_wait:1; 1091 unsigned int fe_compr:1; /* for Dynamic PCM */ 1092 1093 int num_components; 1094 struct snd_soc_component *components[]; /* CPU/Codec/Platform */ 1095 }; 1096 /* see soc_new_pcm_runtime() */ 1097 #define asoc_rtd_to_cpu(rtd, n) (rtd)->dais[n] 1098 #define asoc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->num_cpus] 1099 #define asoc_substream_to_rtd(substream) \ 1100 (struct snd_soc_pcm_runtime *)snd_pcm_substream_chip(substream) 1101 1102 #define for_each_rtd_components(rtd, i, component) \ 1103 for ((i) = 0, component = NULL; \ 1104 ((i) < rtd->num_components) && ((component) = rtd->components[i]);\ 1105 (i)++) 1106 #define for_each_rtd_cpu_dais(rtd, i, dai) \ 1107 for ((i) = 0; \ 1108 ((i) < rtd->num_cpus) && ((dai) = asoc_rtd_to_cpu(rtd, i)); \ 1109 (i)++) 1110 #define for_each_rtd_codec_dais(rtd, i, dai) \ 1111 for ((i) = 0; \ 1112 ((i) < rtd->num_codecs) && ((dai) = asoc_rtd_to_codec(rtd, i)); \ 1113 (i)++) 1114 #define for_each_rtd_dais(rtd, i, dai) \ 1115 for ((i) = 0; \ 1116 ((i) < (rtd)->num_cpus + (rtd)->num_codecs) && \ 1117 ((dai) = (rtd)->dais[i]); \ 1118 (i)++) 1119 1120 void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd); 1121 1122 /* mixer control */ 1123 struct soc_mixer_control { 1124 int min, max, platform_max; 1125 int reg, rreg; 1126 unsigned int shift, rshift; 1127 unsigned int sign_bit; 1128 unsigned int invert:1; 1129 unsigned int autodisable:1; 1130 #ifdef CONFIG_SND_SOC_TOPOLOGY 1131 struct snd_soc_dobj dobj; 1132 #endif 1133 }; 1134 1135 struct soc_bytes { 1136 int base; 1137 int num_regs; 1138 u32 mask; 1139 }; 1140 1141 struct soc_bytes_ext { 1142 int max; 1143 #ifdef CONFIG_SND_SOC_TOPOLOGY 1144 struct snd_soc_dobj dobj; 1145 #endif 1146 /* used for TLV byte control */ 1147 int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes, 1148 unsigned int size); 1149 int (*put)(struct snd_kcontrol *kcontrol, const unsigned int __user *bytes, 1150 unsigned int size); 1151 }; 1152 1153 /* multi register control */ 1154 struct soc_mreg_control { 1155 long min, max; 1156 unsigned int regbase, regcount, nbits, invert; 1157 }; 1158 1159 /* enumerated kcontrol */ 1160 struct soc_enum { 1161 int reg; 1162 unsigned char shift_l; 1163 unsigned char shift_r; 1164 unsigned int items; 1165 unsigned int mask; 1166 const char * const *texts; 1167 const unsigned int *values; 1168 unsigned int autodisable:1; 1169 #ifdef CONFIG_SND_SOC_TOPOLOGY 1170 struct snd_soc_dobj dobj; 1171 #endif 1172 }; 1173 1174 static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc) 1175 { 1176 if (mc->reg == mc->rreg && mc->shift == mc->rshift) 1177 return false; 1178 /* 1179 * mc->reg == mc->rreg && mc->shift != mc->rshift, or 1180 * mc->reg != mc->rreg means that the control is 1181 * stereo (bits in one register or in two registers) 1182 */ 1183 return true; 1184 } 1185 1186 static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e, 1187 unsigned int val) 1188 { 1189 unsigned int i; 1190 1191 if (!e->values) 1192 return val; 1193 1194 for (i = 0; i < e->items; i++) 1195 if (val == e->values[i]) 1196 return i; 1197 1198 return 0; 1199 } 1200 1201 static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e, 1202 unsigned int item) 1203 { 1204 if (!e->values) 1205 return item; 1206 1207 return e->values[item]; 1208 } 1209 1210 /** 1211 * snd_soc_kcontrol_component() - Returns the component that registered the 1212 * control 1213 * @kcontrol: The control for which to get the component 1214 * 1215 * Note: This function will work correctly if the control has been registered 1216 * for a component. With snd_soc_add_codec_controls() or via table based 1217 * setup for either a CODEC or component driver. Otherwise the behavior is 1218 * undefined. 1219 */ 1220 static inline struct snd_soc_component *snd_soc_kcontrol_component( 1221 struct snd_kcontrol *kcontrol) 1222 { 1223 return snd_kcontrol_chip(kcontrol); 1224 } 1225 1226 int snd_soc_util_init(void); 1227 void snd_soc_util_exit(void); 1228 1229 int snd_soc_of_parse_card_name(struct snd_soc_card *card, 1230 const char *propname); 1231 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, 1232 const char *propname); 1233 int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop); 1234 int snd_soc_of_get_slot_mask(struct device_node *np, 1235 const char *prop_name, 1236 unsigned int *mask); 1237 int snd_soc_of_parse_tdm_slot(struct device_node *np, 1238 unsigned int *tx_mask, 1239 unsigned int *rx_mask, 1240 unsigned int *slots, 1241 unsigned int *slot_width); 1242 void snd_soc_of_parse_node_prefix(struct device_node *np, 1243 struct snd_soc_codec_conf *codec_conf, 1244 struct device_node *of_node, 1245 const char *propname); 1246 static inline 1247 void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card, 1248 struct snd_soc_codec_conf *codec_conf, 1249 struct device_node *of_node, 1250 const char *propname) 1251 { 1252 snd_soc_of_parse_node_prefix(card->dev->of_node, 1253 codec_conf, of_node, propname); 1254 } 1255 1256 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 1257 const char *propname); 1258 int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname); 1259 1260 unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt); 1261 unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame); 1262 1263 unsigned int snd_soc_daifmt_parse_format(struct device_node *np, const char *prefix); 1264 unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np, 1265 const char *prefix, 1266 struct device_node **bitclkmaster, 1267 struct device_node **framemaster); 1268 #define snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix) \ 1269 snd_soc_daifmt_parse_clock_provider_raw(np, prefix, NULL, NULL) 1270 #define snd_soc_daifmt_parse_clock_provider_as_phandle \ 1271 snd_soc_daifmt_parse_clock_provider_raw 1272 #define snd_soc_daifmt_parse_clock_provider_as_flag(np, prefix) \ 1273 snd_soc_daifmt_clock_provider_from_bitmap( \ 1274 snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix)) 1275 1276 int snd_soc_get_dai_id(struct device_node *ep); 1277 int snd_soc_get_dai_name(const struct of_phandle_args *args, 1278 const char **dai_name); 1279 int snd_soc_of_get_dai_name(struct device_node *of_node, 1280 const char **dai_name); 1281 int snd_soc_of_get_dai_link_codecs(struct device *dev, 1282 struct device_node *of_node, 1283 struct snd_soc_dai_link *dai_link); 1284 void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link); 1285 int snd_soc_of_get_dai_link_cpus(struct device *dev, 1286 struct device_node *of_node, 1287 struct snd_soc_dai_link *dai_link); 1288 void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link); 1289 1290 int snd_soc_add_pcm_runtime(struct snd_soc_card *card, 1291 struct snd_soc_dai_link *dai_link); 1292 void snd_soc_remove_pcm_runtime(struct snd_soc_card *card, 1293 struct snd_soc_pcm_runtime *rtd); 1294 1295 struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component, 1296 struct snd_soc_dai_driver *dai_drv, 1297 bool legacy_dai_naming); 1298 struct snd_soc_dai *devm_snd_soc_register_dai(struct device *dev, 1299 struct snd_soc_component *component, 1300 struct snd_soc_dai_driver *dai_drv, 1301 bool legacy_dai_naming); 1302 void snd_soc_unregister_dai(struct snd_soc_dai *dai); 1303 1304 struct snd_soc_dai *snd_soc_find_dai( 1305 const struct snd_soc_dai_link_component *dlc); 1306 struct snd_soc_dai *snd_soc_find_dai_with_mutex( 1307 const struct snd_soc_dai_link_component *dlc); 1308 1309 #include <sound/soc-dai.h> 1310 1311 static inline 1312 int snd_soc_fixup_dai_links_platform_name(struct snd_soc_card *card, 1313 const char *platform_name) 1314 { 1315 struct snd_soc_dai_link *dai_link; 1316 const char *name; 1317 int i; 1318 1319 if (!platform_name) /* nothing to do */ 1320 return 0; 1321 1322 /* set platform name for each dailink */ 1323 for_each_card_prelinks(card, i, dai_link) { 1324 /* only single platform is supported for now */ 1325 if (dai_link->num_platforms != 1) 1326 return -EINVAL; 1327 1328 if (!dai_link->platforms) 1329 return -EINVAL; 1330 1331 name = devm_kstrdup(card->dev, platform_name, GFP_KERNEL); 1332 if (!name) 1333 return -ENOMEM; 1334 1335 /* only single platform is supported for now */ 1336 dai_link->platforms->name = name; 1337 } 1338 1339 return 0; 1340 } 1341 1342 #ifdef CONFIG_DEBUG_FS 1343 extern struct dentry *snd_soc_debugfs_root; 1344 #endif 1345 1346 extern const struct dev_pm_ops snd_soc_pm_ops; 1347 1348 /* Helper functions */ 1349 static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm) 1350 { 1351 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 1352 } 1353 1354 static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm) 1355 { 1356 mutex_unlock(&dapm->card->dapm_mutex); 1357 } 1358 1359 #include <sound/soc-component.h> 1360 #include <sound/soc-card.h> 1361 #include <sound/soc-jack.h> 1362 1363 #endif 1364