xref: /linux/sound/soc/intel/boards/sof_sdw_common.h (revision 90d32e92011eaae8e70a9169b4e7acf4ca8f9d3a)
1 /* SPDX-License-Identifier: GPL-2.0-only
2  *  Copyright (c) 2020 Intel Corporation
3  */
4 
5 /*
6  *  sof_sdw_common.h - prototypes for common helpers
7  */
8 
9 #ifndef SND_SOC_SOF_SDW_COMMON_H
10 #define SND_SOC_SOF_SDW_COMMON_H
11 
12 #include <linux/bits.h>
13 #include <linux/types.h>
14 #include <sound/soc.h>
15 #include "sof_hdmi_common.h"
16 
17 #define MAX_NO_PROPS 2
18 #define MAX_HDMI_NUM 4
19 #define SDW_UNUSED_DAI_ID -1
20 #define SDW_JACK_OUT_DAI_ID 0
21 #define SDW_JACK_IN_DAI_ID 1
22 #define SDW_AMP_OUT_DAI_ID 2
23 #define SDW_AMP_IN_DAI_ID 3
24 #define SDW_DMIC_DAI_ID 4
25 #define SDW_MAX_CPU_DAIS 16
26 #define SDW_INTEL_BIDIR_PDI_BASE 2
27 
28 #define SDW_MAX_LINKS		4
29 
30 /* 8 combinations with 4 links + unused group 0 */
31 #define SDW_MAX_GROUPS 9
32 
33 enum {
34 	SOF_PRE_TGL_HDMI_COUNT = 3,
35 	SOF_TGL_HDMI_COUNT = 4,
36 };
37 
38 enum {
39 	SOF_I2S_SSP0 = BIT(0),
40 	SOF_I2S_SSP1 = BIT(1),
41 	SOF_I2S_SSP2 = BIT(2),
42 	SOF_I2S_SSP3 = BIT(3),
43 	SOF_I2S_SSP4 = BIT(4),
44 	SOF_I2S_SSP5 = BIT(5),
45 };
46 
47 #define SOF_JACK_JDSRC(quirk)		((quirk) & GENMASK(3, 0))
48 /* Deprecated and no longer supported by the code */
49 #define SOF_SDW_FOUR_SPK		BIT(4)
50 #define SOF_SDW_TGL_HDMI		BIT(5)
51 #define SOF_SDW_PCH_DMIC		BIT(6)
52 #define SOF_SSP_PORT(x)		(((x) & GENMASK(5, 0)) << 7)
53 #define SOF_SSP_GET_PORT(quirk)	(((quirk) >> 7) & GENMASK(5, 0))
54 /* Deprecated and no longer supported by the code */
55 #define SOF_SDW_NO_AGGREGATION		BIT(14)
56 /* If a CODEC has an optional speaker output, this quirk will enable it */
57 #define SOF_CODEC_SPKR			BIT(15)
58 /*
59  * If the CODEC has additional devices attached directly to it.
60  *
61  * For the cs42l43:
62  *   - 0 - No speaker output
63  *   - SOF_CODEC_SPKR - CODEC internal speaker
64  *   - SOF_SIDECAR_AMPS - 2x Sidecar amplifiers + CODEC internal speaker
65  *   - SOF_CODEC_SPKR | SOF_SIDECAR_AMPS - Not currently supported
66  */
67 #define SOF_SIDECAR_AMPS		BIT(16)
68 
69 /* BT audio offload: reserve 3 bits for future */
70 #define SOF_BT_OFFLOAD_SSP_SHIFT	15
71 #define SOF_BT_OFFLOAD_SSP_MASK	(GENMASK(17, 15))
72 #define SOF_BT_OFFLOAD_SSP(quirk)	\
73 	(((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
74 #define SOF_SSP_BT_OFFLOAD_PRESENT	BIT(18)
75 
76 #define SOF_SDW_DAI_TYPE_JACK		0
77 #define SOF_SDW_DAI_TYPE_AMP		1
78 #define SOF_SDW_DAI_TYPE_MIC		2
79 
80 #define SOF_SDW_MAX_DAI_NUM		8
81 
82 struct sof_sdw_codec_info;
83 
84 struct sof_sdw_dai_info {
85 	const bool direction[2]; /* playback & capture support */
86 	const char *dai_name;
87 	const int dai_type;
88 	const int dailink[2]; /* dailink id for each direction */
89 	const struct snd_kcontrol_new *controls;
90 	const int num_controls;
91 	const struct snd_soc_dapm_widget *widgets;
92 	const int num_widgets;
93 	int  (*init)(struct snd_soc_card *card,
94 		     struct snd_soc_dai_link *dai_links,
95 		     struct sof_sdw_codec_info *info,
96 		     bool playback);
97 	int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
98 	int (*rtd_init)(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
99 	bool rtd_init_done; /* Indicate that the rtd_init callback is done */
100 	unsigned long quirk;
101 };
102 
103 struct sof_sdw_codec_info {
104 	const int part_id;
105 	const int version_id;
106 	const char *codec_name;
107 	int amp_num;
108 	const u8 acpi_id[ACPI_ID_LEN];
109 	const bool ignore_pch_dmic;
110 	const struct snd_soc_ops *ops;
111 	struct sof_sdw_dai_info dais[SOF_SDW_MAX_DAI_NUM];
112 	const int dai_num;
113 
114 	int (*codec_card_late_probe)(struct snd_soc_card *card);
115 
116 	int  (*count_sidecar)(struct snd_soc_card *card,
117 			      int *num_dais, int *num_devs);
118 	int  (*add_sidecar)(struct snd_soc_card *card,
119 			    struct snd_soc_dai_link **dai_links,
120 			    struct snd_soc_codec_conf **codec_conf);
121 };
122 
123 struct mc_private {
124 	struct snd_soc_card card;
125 	struct snd_soc_jack sdw_headset;
126 	struct sof_hdmi_private hdmi;
127 	struct device *headset_codec_dev; /* only one headset per card */
128 	struct device *amp_dev1, *amp_dev2;
129 	/* To store SDW Pin index for each SoundWire link */
130 	unsigned int sdw_pin_index[SDW_MAX_LINKS];
131 	bool append_dai_type;
132 	bool ignore_pch_dmic;
133 };
134 
135 extern unsigned long sof_sdw_quirk;
136 
137 struct snd_soc_dai *get_codec_dai_by_name(struct snd_soc_pcm_runtime *rtd,
138 					  const char * const dai_name[],
139 					  int num_dais);
140 
141 int sdw_startup(struct snd_pcm_substream *substream);
142 int sdw_prepare(struct snd_pcm_substream *substream);
143 int sdw_trigger(struct snd_pcm_substream *substream, int cmd);
144 int sdw_hw_params(struct snd_pcm_substream *substream,
145 		  struct snd_pcm_hw_params *params);
146 int sdw_hw_free(struct snd_pcm_substream *substream);
147 void sdw_shutdown(struct snd_pcm_substream *substream);
148 
149 /* generic HDMI support */
150 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd);
151 
152 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card);
153 
154 /* DMIC support */
155 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd);
156 
157 /* RT711 support */
158 int sof_sdw_rt711_init(struct snd_soc_card *card,
159 		       struct snd_soc_dai_link *dai_links,
160 		       struct sof_sdw_codec_info *info,
161 		       bool playback);
162 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
163 
164 /* RT711-SDCA support */
165 int sof_sdw_rt_sdca_jack_init(struct snd_soc_card *card,
166 			      struct snd_soc_dai_link *dai_links,
167 			      struct sof_sdw_codec_info *info,
168 			      bool playback);
169 int sof_sdw_rt_sdca_jack_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
170 
171 /* RT1308 I2S support */
172 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops;
173 
174 /* generic amp support */
175 int sof_sdw_rt_amp_init(struct snd_soc_card *card,
176 			struct snd_soc_dai_link *dai_links,
177 			struct sof_sdw_codec_info *info,
178 			bool playback);
179 int sof_sdw_rt_amp_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
180 
181 /* MAXIM codec support */
182 int sof_sdw_maxim_init(struct snd_soc_card *card,
183 		       struct snd_soc_dai_link *dai_links,
184 		       struct sof_sdw_codec_info *info,
185 		       bool playback);
186 
187 /* CS42L43 support */
188 int sof_sdw_cs42l43_spk_init(struct snd_soc_card *card,
189 			     struct snd_soc_dai_link *dai_links,
190 			     struct sof_sdw_codec_info *info,
191 			     bool playback);
192 
193 /* CS AMP support */
194 int bridge_cs35l56_count_sidecar(struct snd_soc_card *card,
195 				 int *num_dais, int *num_devs);
196 int bridge_cs35l56_add_sidecar(struct snd_soc_card *card,
197 			       struct snd_soc_dai_link **dai_links,
198 			       struct snd_soc_codec_conf **codec_conf);
199 int bridge_cs35l56_spk_init(struct snd_soc_card *card,
200 			    struct snd_soc_dai_link *dai_links,
201 			    struct sof_sdw_codec_info *info,
202 			    bool playback);
203 
204 int sof_sdw_cs_amp_init(struct snd_soc_card *card,
205 			struct snd_soc_dai_link *dai_links,
206 			struct sof_sdw_codec_info *info,
207 			bool playback);
208 
209 /* dai_link init callbacks */
210 
211 int cs42l42_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
212 int cs42l43_hs_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
213 int cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
214 int cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
215 int cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
216 int maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
217 int rt5682_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
218 int rt700_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
219 int rt711_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
220 int rt712_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
221 int rt722_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
222 int rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
223 int rt_amp_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
224 int rt_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
225 
226 #endif
227