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