xref: /linux/include/sound/sdca_asoc.h (revision c41ac86802fc0a22a886915a43bcad2e8d482b02)
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 struct snd_soc_pcm_stream;
29 struct sdca_entity;
30 
31 /* convenient macro to handle the mono volume in 7.8 fixed format representation */
32 #define SDCA_SINGLE_Q78_TLV(xname, xreg, xmin, xmax, xstep, tlv_array) \
33 { \
34 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
35 	.name = (xname), \
36 	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE, \
37 	.tlv.p = (tlv_array), \
38 	.info = snd_soc_info_volsw, \
39 	.get = sdca_asoc_q78_get_volsw, \
40 	.put = sdca_asoc_q78_put_volsw, \
41 	.private_value = (unsigned long)&(struct soc_mixer_control) { \
42 		.reg = (xreg), .rreg = (xreg), \
43 		.min = (xmin), .max = (xmax), \
44 		.shift = (xstep), .rshift = (xstep), \
45 		.sign_bit = 15 \
46 	} \
47 }
48 
49 /* convenient macro for stereo volume in 7.8 fixed format with separate registers for L/R */
50 #define SDCA_DOUBLE_Q78_TLV(xname, xreg_l, xreg_r, xmin, xmax, xstep, tlv_array) \
51 { \
52 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
53 	.name = (xname), \
54 	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE, \
55 	.tlv.p = (tlv_array), \
56 	.info = snd_soc_info_volsw, \
57 	.get = sdca_asoc_q78_get_volsw, \
58 	.put = sdca_asoc_q78_put_volsw, \
59 	.private_value = (unsigned long)&(struct soc_mixer_control) { \
60 		.reg = (xreg_l), .rreg = (xreg_r), \
61 		.min = (xmin), .max = (xmax), \
62 		.shift = (xstep), .rshift = (xstep), \
63 		.sign_bit = 15 \
64 	} \
65 }
66 
67 int sdca_asoc_count_component(struct device *dev, struct sdca_function_data *function,
68 			      int *num_widgets, int *num_routes, int *num_controls,
69 			      int *num_dais);
70 
71 int sdca_asoc_populate_dapm(struct device *dev, struct sdca_function_data *function,
72 			    struct snd_soc_dapm_widget *widgets,
73 			    struct snd_soc_dapm_route *routes);
74 int sdca_asoc_populate_controls(struct device *dev,
75 				struct sdca_function_data *function,
76 				struct snd_kcontrol_new *kctl);
77 int sdca_asoc_populate_dais(struct device *dev, struct sdca_function_data *function,
78 			    struct snd_soc_dai_driver *dais,
79 			    const struct snd_soc_dai_ops *ops);
80 
81 int sdca_asoc_populate_component(struct device *dev,
82 				 struct sdca_function_data *function,
83 				 struct snd_soc_component_driver *component_drv,
84 				 struct snd_soc_dai_driver **dai_drv, int *num_dai_drv,
85 				 const struct snd_soc_dai_ops *ops);
86 
87 int sdca_asoc_populate_rate_format(struct device *dev,
88 				struct sdca_function_data *function,
89 				struct sdca_entity *entity,
90 				struct snd_soc_pcm_stream *stream);
91 
92 int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap,
93 			      struct sdca_function_data *function,
94 			      struct snd_pcm_substream *substream,
95 			      struct snd_soc_dai *dai);
96 void sdca_asoc_free_constraints(struct snd_pcm_substream *substream,
97 				struct snd_soc_dai *dai);
98 int sdca_asoc_get_port(struct device *dev, struct regmap *regmap,
99 		       struct sdca_function_data *function,
100 		       struct snd_soc_dai *dai);
101 int sdca_asoc_hw_params(struct device *dev, struct regmap *regmap,
102 			struct sdca_function_data *function,
103 			struct snd_pcm_substream *substream,
104 			struct snd_pcm_hw_params *params,
105 			struct snd_soc_dai *dai);
106 int sdca_asoc_q78_put_volsw(struct snd_kcontrol *kcontrol,
107 			    struct snd_ctl_elem_value *ucontrol);
108 int sdca_asoc_q78_get_volsw(struct snd_kcontrol *kcontrol,
109 			    struct snd_ctl_elem_value *ucontrol);
110 int sdca_asoc_pde_poll_actual_ps(struct regmap *regmap,
111 				 int function_id, int entity_id,
112 				 int from_ps, int to_ps,
113 				 const struct sdca_pde_delay *pde_delays,
114 				 int num_delays);
115 #endif // __SDCA_ASOC_H__
116