xref: /linux/include/sound/sdca_asoc.h (revision e76ccf19e22a74309bb9c14e64bb97ade3c5fee8)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * The MIPI SDCA specification is available for public downloads at
4  * https://www.mipi.org/mipi-sdca-v1-0-download
5  *
6  * Copyright (C) 2025 Cirrus Logic, Inc. and
7  *                    Cirrus Logic International Semiconductor Ltd.
8  */
9 
10 #ifndef __SDCA_ASOC_H__
11 #define __SDCA_ASOC_H__
12 
13 struct device;
14 struct regmap;
15 struct sdca_function_data;
16 struct sdca_pde_delay;
17 struct snd_ctl_elem_value;
18 struct snd_kcontrol;
19 struct snd_kcontrol_new;
20 struct snd_pcm_hw_params;
21 struct snd_pcm_substream;
22 struct snd_soc_component_driver;
23 struct snd_soc_dai;
24 struct snd_soc_dai_driver;
25 struct snd_soc_dai_ops;
26 struct snd_soc_dapm_route;
27 struct snd_soc_dapm_widget;
28 
29 /* convenient macro to handle the mono volume in 7.8 fixed format representation */
30 #define SDCA_SINGLE_Q78_TLV(xname, xreg, xmin, xmax, xstep, tlv_array) \
31 { \
32 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
33 	.name = (xname), \
34 	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE, \
35 	.tlv.p = (tlv_array), \
36 	.info = snd_soc_info_volsw, \
37 	.get = sdca_asoc_q78_get_volsw, \
38 	.put = sdca_asoc_q78_put_volsw, \
39 	.private_value = (unsigned long)&(struct soc_mixer_control) { \
40 		.reg = (xreg), .rreg = (xreg), \
41 		.min = (xmin), .max = (xmax), \
42 		.shift = (xstep), .rshift = (xstep), \
43 		.sign_bit = 15 \
44 	} \
45 }
46 
47 /* convenient macro for stereo volume in 7.8 fixed format with separate registers for L/R */
48 #define SDCA_DOUBLE_Q78_TLV(xname, xreg_l, xreg_r, xmin, xmax, xstep, tlv_array) \
49 { \
50 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
51 	.name = (xname), \
52 	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE, \
53 	.tlv.p = (tlv_array), \
54 	.info = snd_soc_info_volsw, \
55 	.get = sdca_asoc_q78_get_volsw, \
56 	.put = sdca_asoc_q78_put_volsw, \
57 	.private_value = (unsigned long)&(struct soc_mixer_control) { \
58 		.reg = (xreg_l), .rreg = (xreg_r), \
59 		.min = (xmin), .max = (xmax), \
60 		.shift = (xstep), .rshift = (xstep), \
61 		.sign_bit = 15 \
62 	} \
63 }
64 
65 int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function,
66 			      int *num_widgets, int *num_routes, int *num_controls,
67 			      int *num_dais);
68 
69 int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *function,
70 			    struct snd_soc_dapm_widget *widgets,
71 			    struct snd_soc_dapm_route *routes);
72 int sdca_asoc_populate_controls(struct device *dev,
73 				struct sdca_function_data *function,
74 				struct snd_kcontrol_new *kctl);
75 int sdca_asoc_populate_dais(struct device *dev, struct sdca_function_data *function,
76 			    struct snd_soc_dai_driver *dais,
77 			    const struct snd_soc_dai_ops *ops);
78 
79 int sdca_asoc_populate_component(struct device *dev,
80 				 struct sdca_function_data *function,
81 				 struct snd_soc_component_driver *component_drv,
82 				 struct snd_soc_dai_driver **dai_drv, int *num_dai_drv,
83 				 const struct snd_soc_dai_ops *ops);
84 
85 int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap,
86 			      struct sdca_function_data *function,
87 			      struct snd_pcm_substream *substream,
88 			      struct snd_soc_dai *dai);
89 void sdca_asoc_free_constraints(struct snd_pcm_substream *substream,
90 				struct snd_soc_dai *dai);
91 int sdca_asoc_get_port(struct device *dev, struct regmap *regmap,
92 		       struct sdca_function_data *function,
93 		       struct snd_soc_dai *dai);
94 int sdca_asoc_hw_params(struct device *dev, struct regmap *regmap,
95 			struct sdca_function_data *function,
96 			struct snd_pcm_substream *substream,
97 			struct snd_pcm_hw_params *params,
98 			struct snd_soc_dai *dai);
99 int sdca_asoc_q78_put_volsw(struct snd_kcontrol *kcontrol,
100 			    struct snd_ctl_elem_value *ucontrol);
101 int sdca_asoc_q78_get_volsw(struct snd_kcontrol *kcontrol,
102 			    struct snd_ctl_elem_value *ucontrol);
103 int sdca_asoc_pde_poll_actual_ps(struct device *dev, struct regmap *regmap,
104 				 int function_id, int entity_id,
105 			    int from_ps, int to_ps,
106 			    const struct sdca_pde_delay *pde_delays,
107 			    int num_delays);
108 #endif // __SDCA_ASOC_H__
109