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