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 };
87 
88 extern unsigned long sof_sdw_quirk;
89 
90 int sdw_startup(struct snd_pcm_substream *substream);
91 int sdw_prepare(struct snd_pcm_substream *substream);
92 int sdw_trigger(struct snd_pcm_substream *substream, int cmd);
93 int sdw_hw_free(struct snd_pcm_substream *substream);
94 void sdw_shutdown(struct snd_pcm_substream *substream);
95 
96 /* generic HDMI support */
97 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd);
98 
99 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card);
100 
101 /* DMIC support */
102 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd);
103 
104 /* RT711 support */
105 int sof_sdw_rt711_init(struct snd_soc_card *card,
106 		       const struct snd_soc_acpi_link_adr *link,
107 		       struct snd_soc_dai_link *dai_links,
108 		       struct sof_sdw_codec_info *info,
109 		       bool playback);
110 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
111 
112 /* RT711-SDCA support */
113 int sof_sdw_rt711_sdca_init(struct snd_soc_card *card,
114 			    const struct snd_soc_acpi_link_adr *link,
115 			    struct snd_soc_dai_link *dai_links,
116 			    struct sof_sdw_codec_info *info,
117 			    bool playback);
118 int sof_sdw_rt711_sdca_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
119 
120 /* RT700 support */
121 int sof_sdw_rt700_init(struct snd_soc_card *card,
122 		       const struct snd_soc_acpi_link_adr *link,
123 		       struct snd_soc_dai_link *dai_links,
124 		       struct sof_sdw_codec_info *info,
125 		       bool playback);
126 
127 /* RT1308 support */
128 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops;
129 
130 int sof_sdw_rt1308_init(struct snd_soc_card *card,
131 			const struct snd_soc_acpi_link_adr *link,
132 			struct snd_soc_dai_link *dai_links,
133 			struct sof_sdw_codec_info *info,
134 			bool playback);
135 
136 /* RT1316 support */
137 int sof_sdw_rt1316_init(struct snd_soc_card *card,
138 			const struct snd_soc_acpi_link_adr *link,
139 			struct snd_soc_dai_link *dai_links,
140 			struct sof_sdw_codec_info *info,
141 			bool playback);
142 
143 /* RT715 support */
144 int sof_sdw_rt715_init(struct snd_soc_card *card,
145 		       const struct snd_soc_acpi_link_adr *link,
146 		       struct snd_soc_dai_link *dai_links,
147 		       struct sof_sdw_codec_info *info,
148 		       bool playback);
149 
150 /* RT715-SDCA support */
151 int sof_sdw_rt715_sdca_init(struct snd_soc_card *card,
152 			    const struct snd_soc_acpi_link_adr *link,
153 			    struct snd_soc_dai_link *dai_links,
154 			    struct sof_sdw_codec_info *info,
155 			    bool playback);
156 
157 /* MAX98373 support */
158 int sof_sdw_mx8373_init(struct snd_soc_card *card,
159 			const struct snd_soc_acpi_link_adr *link,
160 			struct snd_soc_dai_link *dai_links,
161 			struct sof_sdw_codec_info *info,
162 			bool playback);
163 
164 int sof_sdw_mx8373_late_probe(struct snd_soc_card *card);
165 
166 /* RT5682 support */
167 int sof_sdw_rt5682_init(struct snd_soc_card *card,
168 			const struct snd_soc_acpi_link_adr *link,
169 			struct snd_soc_dai_link *dai_links,
170 			struct sof_sdw_codec_info *info,
171 			bool playback);
172 
173 #endif
174