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_DMIC_DAI_ID 4
19 #define SDW_MAX_CPU_DAIS 16
20 #define SDW_INTEL_BIDIR_PDI_BASE 2
21 
22 /* 8 combinations with 4 links + unused group 0 */
23 #define SDW_MAX_GROUPS 9
24 
25 enum {
26 	SOF_PRE_TGL_HDMI_COUNT = 3,
27 	SOF_TGL_HDMI_COUNT = 4,
28 };
29 
30 enum {
31 	SOF_I2S_SSP0 = BIT(0),
32 	SOF_I2S_SSP1 = BIT(1),
33 	SOF_I2S_SSP2 = BIT(2),
34 	SOF_I2S_SSP3 = BIT(3),
35 	SOF_I2S_SSP4 = BIT(4),
36 	SOF_I2S_SSP5 = BIT(5),
37 };
38 
39 #define SOF_RT711_JDSRC(quirk)		((quirk) & GENMASK(3, 0))
40 #define SOF_SDW_FOUR_SPK		BIT(4)
41 #define SOF_SDW_TGL_HDMI		BIT(5)
42 #define SOF_SDW_PCH_DMIC		BIT(6)
43 #define SOF_SSP_PORT(x)		(((x) & GENMASK(5, 0)) << 7)
44 #define SOF_SSP_GET_PORT(quirk)	(((quirk) >> 7) & GENMASK(5, 0))
45 #define SOF_RT715_DAI_ID_FIX		BIT(13)
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 struct sof_sdw_codec_info {
56 	const int part_id;
57 	const int version_id;
58 	int amp_num;
59 	const u8 acpi_id[ACPI_ID_LEN];
60 	const bool direction[2]; // playback & capture support
61 	const bool ignore_pch_dmic;
62 	const char *dai_name;
63 	const struct snd_soc_ops *ops;
64 
65 	int  (*init)(struct snd_soc_card *card,
66 		     const struct snd_soc_acpi_link_adr *link,
67 		     struct snd_soc_dai_link *dai_links,
68 		     struct sof_sdw_codec_info *info,
69 		     bool playback);
70 
71 	int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
72 	bool late_probe;
73 	int (*codec_card_late_probe)(struct snd_soc_card *card);
74 };
75 
76 struct mc_private {
77 	struct list_head hdmi_pcm_list;
78 	bool idisp_codec;
79 	struct snd_soc_jack sdw_headset;
80 	struct device *headset_codec_dev; /* only one headset per card */
81 };
82 
83 extern unsigned long sof_sdw_quirk;
84 
85 int sdw_startup(struct snd_pcm_substream *substream);
86 int sdw_prepare(struct snd_pcm_substream *substream);
87 int sdw_trigger(struct snd_pcm_substream *substream, int cmd);
88 int sdw_hw_free(struct snd_pcm_substream *substream);
89 void sdw_shutdown(struct snd_pcm_substream *substream);
90 
91 /* generic HDMI support */
92 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd);
93 
94 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card);
95 
96 /* DMIC support */
97 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd);
98 
99 /* RT711 support */
100 int sof_sdw_rt711_init(struct snd_soc_card *card,
101 		       const struct snd_soc_acpi_link_adr *link,
102 		       struct snd_soc_dai_link *dai_links,
103 		       struct sof_sdw_codec_info *info,
104 		       bool playback);
105 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
106 
107 /* RT711-SDCA support */
108 int sof_sdw_rt711_sdca_init(struct snd_soc_card *card,
109 			    const struct snd_soc_acpi_link_adr *link,
110 			    struct snd_soc_dai_link *dai_links,
111 			    struct sof_sdw_codec_info *info,
112 			    bool playback);
113 int sof_sdw_rt711_sdca_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
114 
115 /* RT700 support */
116 int sof_sdw_rt700_init(struct snd_soc_card *card,
117 		       const struct snd_soc_acpi_link_adr *link,
118 		       struct snd_soc_dai_link *dai_links,
119 		       struct sof_sdw_codec_info *info,
120 		       bool playback);
121 
122 /* RT1308 support */
123 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops;
124 
125 int sof_sdw_rt1308_init(struct snd_soc_card *card,
126 			const struct snd_soc_acpi_link_adr *link,
127 			struct snd_soc_dai_link *dai_links,
128 			struct sof_sdw_codec_info *info,
129 			bool playback);
130 
131 /* RT1316 support */
132 int sof_sdw_rt1316_init(struct snd_soc_card *card,
133 			const struct snd_soc_acpi_link_adr *link,
134 			struct snd_soc_dai_link *dai_links,
135 			struct sof_sdw_codec_info *info,
136 			bool playback);
137 
138 /* RT715 support */
139 int sof_sdw_rt715_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 
145 /* RT715-SDCA support */
146 int sof_sdw_rt715_sdca_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 
152 /* MAX98373 support */
153 int sof_sdw_mx8373_init(struct snd_soc_card *card,
154 			const struct snd_soc_acpi_link_adr *link,
155 			struct snd_soc_dai_link *dai_links,
156 			struct sof_sdw_codec_info *info,
157 			bool playback);
158 
159 int sof_sdw_mx8373_late_probe(struct snd_soc_card *card);
160 
161 /* RT5682 support */
162 int sof_sdw_rt5682_init(struct snd_soc_card *card,
163 			const struct snd_soc_acpi_link_adr *link,
164 			struct snd_soc_dai_link *dai_links,
165 			struct sof_sdw_codec_info *info,
166 			bool playback);
167 
168 #endif
169