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 I2S support */
129 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops;
130 
131 /* generic amp support */
132 int sof_sdw_rt_amp_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 int sof_sdw_rt_amp_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
138 
139 /* RT1316 support */
140 
141 /* RT715 support */
142 int sof_sdw_rt715_init(struct snd_soc_card *card,
143 		       const struct snd_soc_acpi_link_adr *link,
144 		       struct snd_soc_dai_link *dai_links,
145 		       struct sof_sdw_codec_info *info,
146 		       bool playback);
147 
148 /* RT715-SDCA support */
149 int sof_sdw_rt715_sdca_init(struct snd_soc_card *card,
150 			    const struct snd_soc_acpi_link_adr *link,
151 			    struct snd_soc_dai_link *dai_links,
152 			    struct sof_sdw_codec_info *info,
153 			    bool playback);
154 
155 /* MAX98373 support */
156 int sof_sdw_mx8373_init(struct snd_soc_card *card,
157 			const struct snd_soc_acpi_link_adr *link,
158 			struct snd_soc_dai_link *dai_links,
159 			struct sof_sdw_codec_info *info,
160 			bool playback);
161 
162 int sof_sdw_mx8373_late_probe(struct snd_soc_card *card);
163 
164 /* RT5682 support */
165 int sof_sdw_rt5682_init(struct snd_soc_card *card,
166 			const struct snd_soc_acpi_link_adr *link,
167 			struct snd_soc_dai_link *dai_links,
168 			struct sof_sdw_codec_info *info,
169 			bool playback);
170 
171 #endif
172