xref: /linux/sound/soc/intel/boards/sof_sdw_common.h (revision eb01fe7abbe2d0b38824d2a93fdb4cc3eaf2ccc1)
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 #define SOF_SDW_FOUR_SPK		BIT(4)
49 #define SOF_SDW_TGL_HDMI		BIT(5)
50 #define SOF_SDW_PCH_DMIC		BIT(6)
51 #define SOF_SSP_PORT(x)		(((x) & GENMASK(5, 0)) << 7)
52 #define SOF_SSP_GET_PORT(quirk)	(((quirk) >> 7) & GENMASK(5, 0))
53 #define SOF_SDW_NO_AGGREGATION		BIT(14)
54 
55 /* BT audio offload: reserve 3 bits for future */
56 #define SOF_BT_OFFLOAD_SSP_SHIFT	15
57 #define SOF_BT_OFFLOAD_SSP_MASK	(GENMASK(17, 15))
58 #define SOF_BT_OFFLOAD_SSP(quirk)	\
59 	(((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
60 #define SOF_SSP_BT_OFFLOAD_PRESENT	BIT(18)
61 
62 #define SOF_SDW_DAI_TYPE_JACK		0
63 #define SOF_SDW_DAI_TYPE_AMP		1
64 #define SOF_SDW_DAI_TYPE_MIC		2
65 
66 #define SOF_SDW_MAX_DAI_NUM		3
67 
68 struct sof_sdw_codec_info;
69 
70 struct sof_sdw_dai_info {
71 	const bool direction[2]; /* playback & capture support */
72 	const char *dai_name;
73 	const int dai_type;
74 	const int dailink[2]; /* dailink id for each direction */
75 	int  (*init)(struct snd_soc_card *card,
76 		     const struct snd_soc_acpi_link_adr *link,
77 		     struct snd_soc_dai_link *dai_links,
78 		     struct sof_sdw_codec_info *info,
79 		     bool playback);
80 	int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
81 	int (*rtd_init)(struct snd_soc_pcm_runtime *rtd);
82 	bool rtd_init_done; /* Indicate that the rtd_init callback is done */
83 };
84 
85 struct sof_sdw_codec_info {
86 	const int part_id;
87 	const int version_id;
88 	const char *codec_name;
89 	int amp_num;
90 	const u8 acpi_id[ACPI_ID_LEN];
91 	const bool ignore_pch_dmic;
92 	const struct snd_soc_ops *ops;
93 	struct sof_sdw_dai_info dais[SOF_SDW_MAX_DAI_NUM];
94 	const int dai_num;
95 
96 	int (*codec_card_late_probe)(struct snd_soc_card *card);
97 };
98 
99 struct mc_private {
100 	struct snd_soc_jack sdw_headset;
101 	struct sof_hdmi_private hdmi;
102 	struct device *headset_codec_dev; /* only one headset per card */
103 	struct device *amp_dev1, *amp_dev2;
104 	/* To store SDW Pin index for each SoundWire link */
105 	unsigned int sdw_pin_index[SDW_MAX_LINKS];
106 };
107 
108 extern unsigned long sof_sdw_quirk;
109 
110 int sdw_startup(struct snd_pcm_substream *substream);
111 int sdw_prepare(struct snd_pcm_substream *substream);
112 int sdw_trigger(struct snd_pcm_substream *substream, int cmd);
113 int sdw_hw_params(struct snd_pcm_substream *substream,
114 		  struct snd_pcm_hw_params *params);
115 int sdw_hw_free(struct snd_pcm_substream *substream);
116 void sdw_shutdown(struct snd_pcm_substream *substream);
117 
118 /* generic HDMI support */
119 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd);
120 
121 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card);
122 
123 /* DMIC support */
124 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd);
125 
126 /* RT711 support */
127 int sof_sdw_rt711_init(struct snd_soc_card *card,
128 		       const struct snd_soc_acpi_link_adr *link,
129 		       struct snd_soc_dai_link *dai_links,
130 		       struct sof_sdw_codec_info *info,
131 		       bool playback);
132 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
133 
134 /* RT711-SDCA support */
135 int sof_sdw_rt_sdca_jack_init(struct snd_soc_card *card,
136 			      const struct snd_soc_acpi_link_adr *link,
137 			      struct snd_soc_dai_link *dai_links,
138 			      struct sof_sdw_codec_info *info,
139 			      bool playback);
140 int sof_sdw_rt_sdca_jack_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
141 
142 /* RT1308 I2S support */
143 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops;
144 
145 /* generic amp support */
146 int sof_sdw_rt_amp_init(struct snd_soc_card *card,
147 			const struct snd_soc_acpi_link_adr *link,
148 			struct snd_soc_dai_link *dai_links,
149 			struct sof_sdw_codec_info *info,
150 			bool playback);
151 int sof_sdw_rt_amp_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
152 
153 /* RT722-SDCA support */
154 int sof_sdw_rt722_spk_init(struct snd_soc_card *card,
155 			   const struct snd_soc_acpi_link_adr *link,
156 			   struct snd_soc_dai_link *dai_links,
157 			   struct sof_sdw_codec_info *info,
158 			   bool playback);
159 int sof_sdw_rt722_sdca_dmic_init(struct snd_soc_card *card,
160 				 const struct snd_soc_acpi_link_adr *link,
161 				 struct snd_soc_dai_link *dai_links,
162 				 struct sof_sdw_codec_info *info,
163 				 bool playback);
164 
165 /* MAXIM codec support */
166 int sof_sdw_maxim_init(struct snd_soc_card *card,
167 		       const struct snd_soc_acpi_link_adr *link,
168 		       struct snd_soc_dai_link *dai_links,
169 		       struct sof_sdw_codec_info *info,
170 		       bool playback);
171 
172 /* CS AMP support */
173 int sof_sdw_cs_amp_init(struct snd_soc_card *card,
174 			const struct snd_soc_acpi_link_adr *link,
175 			struct snd_soc_dai_link *dai_links,
176 			struct sof_sdw_codec_info *info,
177 			bool playback);
178 
179 /* dai_link init callbacks */
180 
181 int cs42l42_rtd_init(struct snd_soc_pcm_runtime *rtd);
182 int cs42l43_hs_rtd_init(struct snd_soc_pcm_runtime *rtd);
183 int cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd);
184 int cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd);
185 int maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd);
186 int rt5682_rtd_init(struct snd_soc_pcm_runtime *rtd);
187 int rt700_rtd_init(struct snd_soc_pcm_runtime *rtd);
188 int rt711_rtd_init(struct snd_soc_pcm_runtime *rtd);
189 int rt712_sdca_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd);
190 int rt712_spk_rtd_init(struct snd_soc_pcm_runtime *rtd);
191 int rt715_rtd_init(struct snd_soc_pcm_runtime *rtd);
192 int rt715_sdca_rtd_init(struct snd_soc_pcm_runtime *rtd);
193 int rt_amp_spk_rtd_init(struct snd_soc_pcm_runtime *rtd);
194 int rt_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd);
195 
196 #endif
197