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 
16 #define MAX_NO_PROPS 2
17 #define MAX_HDMI_NUM 4
18 #define SDW_AMP_DAI_ID 2
19 #define SDW_DMIC_DAI_ID 4
20 #define SDW_MAX_CPU_DAIS 16
21 #define SDW_INTEL_BIDIR_PDI_BASE 2
22 
23 /* 8 combinations with 4 links + unused group 0 */
24 #define SDW_MAX_GROUPS 9
25 
26 enum {
27 	SOF_PRE_TGL_HDMI_COUNT = 3,
28 	SOF_TGL_HDMI_COUNT = 4,
29 };
30 
31 enum {
32 	SOF_I2S_SSP0 = BIT(0),
33 	SOF_I2S_SSP1 = BIT(1),
34 	SOF_I2S_SSP2 = BIT(2),
35 	SOF_I2S_SSP3 = BIT(3),
36 	SOF_I2S_SSP4 = BIT(4),
37 	SOF_I2S_SSP5 = BIT(5),
38 };
39 
40 #define SOF_RT711_JDSRC(quirk)		((quirk) & GENMASK(3, 0))
41 #define SOF_SDW_FOUR_SPK		BIT(4)
42 #define SOF_SDW_TGL_HDMI		BIT(5)
43 #define SOF_SDW_PCH_DMIC		BIT(6)
44 #define SOF_SSP_PORT(x)		(((x) & GENMASK(5, 0)) << 7)
45 #define SOF_SSP_GET_PORT(quirk)	(((quirk) >> 7) & GENMASK(5, 0))
46 #define SOF_SDW_NO_AGGREGATION		BIT(14)
47 
48 /* BT audio offload: reserve 3 bits for future */
49 #define SOF_BT_OFFLOAD_SSP_SHIFT	15
50 #define SOF_BT_OFFLOAD_SSP_MASK	(GENMASK(17, 15))
51 #define SOF_BT_OFFLOAD_SSP(quirk)	\
52 	(((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
53 #define SOF_SSP_BT_OFFLOAD_PRESENT	BIT(18)
54 
55 #define SOF_SDW_CODEC_TYPE_JACK		0
56 #define SOF_SDW_CODEC_TYPE_AMP		1
57 #define SOF_SDW_CODEC_TYPE_MIC		2
58 
59 struct sof_sdw_codec_info {
60 	const int part_id;
61 	const int version_id;
62 	const int codec_type;
63 	int amp_num;
64 	const u8 acpi_id[ACPI_ID_LEN];
65 	const bool direction[2]; // playback & capture support
66 	const bool ignore_pch_dmic;
67 	const char *dai_name;
68 	const struct snd_soc_ops *ops;
69 
70 	int  (*init)(struct snd_soc_card *card,
71 		     const struct snd_soc_acpi_link_adr *link,
72 		     struct snd_soc_dai_link *dai_links,
73 		     struct sof_sdw_codec_info *info,
74 		     bool playback);
75 
76 	int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
77 	bool late_probe;
78 	int (*codec_card_late_probe)(struct snd_soc_card *card);
79 };
80 
81 struct mc_private {
82 	struct list_head hdmi_pcm_list;
83 	bool idisp_codec;
84 	struct snd_soc_jack sdw_headset;
85 	struct device *headset_codec_dev; /* only one headset per card */
86 	struct device *amp_dev1, *amp_dev2;
87 };
88 
89 extern unsigned long sof_sdw_quirk;
90 
91 int sdw_startup(struct snd_pcm_substream *substream);
92 int sdw_prepare(struct snd_pcm_substream *substream);
93 int sdw_trigger(struct snd_pcm_substream *substream, int cmd);
94 int sdw_hw_free(struct snd_pcm_substream *substream);
95 void sdw_shutdown(struct snd_pcm_substream *substream);
96 
97 /* generic HDMI support */
98 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd);
99 
100 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card);
101 
102 /* DMIC support */
103 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd);
104 
105 /* RT711 support */
106 int sof_sdw_rt711_init(struct snd_soc_card *card,
107 		       const struct snd_soc_acpi_link_adr *link,
108 		       struct snd_soc_dai_link *dai_links,
109 		       struct sof_sdw_codec_info *info,
110 		       bool playback);
111 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
112 
113 /* RT711-SDCA support */
114 int sof_sdw_rt711_sdca_init(struct snd_soc_card *card,
115 			    const struct snd_soc_acpi_link_adr *link,
116 			    struct snd_soc_dai_link *dai_links,
117 			    struct sof_sdw_codec_info *info,
118 			    bool playback);
119 int sof_sdw_rt711_sdca_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
120 
121 /* RT700 support */
122 int sof_sdw_rt700_init(struct snd_soc_card *card,
123 		       const struct snd_soc_acpi_link_adr *link,
124 		       struct snd_soc_dai_link *dai_links,
125 		       struct sof_sdw_codec_info *info,
126 		       bool playback);
127 
128 /* RT1308 support */
129 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops;
130 
131 int sof_sdw_rt1308_init(struct snd_soc_card *card,
132 			const struct snd_soc_acpi_link_adr *link,
133 			struct snd_soc_dai_link *dai_links,
134 			struct sof_sdw_codec_info *info,
135 			bool playback);
136 int sof_sdw_rt1308_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
137 
138 /* RT1316 support */
139 int sof_sdw_rt1316_init(struct snd_soc_card *card,
140 			const struct snd_soc_acpi_link_adr *link,
141 			struct snd_soc_dai_link *dai_links,
142 			struct sof_sdw_codec_info *info,
143 			bool playback);
144 int sof_sdw_rt1316_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
145 
146 /* RT1318 support */
147 int sof_sdw_rt1318_init(struct snd_soc_card *card,
148 			const struct snd_soc_acpi_link_adr *link,
149 			struct snd_soc_dai_link *dai_links,
150 			struct sof_sdw_codec_info *info,
151 			bool playback);
152 
153 /* RT715 support */
154 int sof_sdw_rt715_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 
160 /* RT715-SDCA support */
161 int sof_sdw_rt715_sdca_init(struct snd_soc_card *card,
162 			    const struct snd_soc_acpi_link_adr *link,
163 			    struct snd_soc_dai_link *dai_links,
164 			    struct sof_sdw_codec_info *info,
165 			    bool playback);
166 
167 /* MAX98373 support */
168 int sof_sdw_mx8373_init(struct snd_soc_card *card,
169 			const struct snd_soc_acpi_link_adr *link,
170 			struct snd_soc_dai_link *dai_links,
171 			struct sof_sdw_codec_info *info,
172 			bool playback);
173 
174 int sof_sdw_mx8373_late_probe(struct snd_soc_card *card);
175 
176 /* RT5682 support */
177 int sof_sdw_rt5682_init(struct snd_soc_card *card,
178 			const struct snd_soc_acpi_link_adr *link,
179 			struct snd_soc_dai_link *dai_links,
180 			struct sof_sdw_codec_info *info,
181 			bool playback);
182 
183 #endif
184