xref: /linux/sound/soc/intel/boards/sof_board_helpers.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright(c) 2023 Intel Corporation.
4  */
5 
6 #ifndef __SOF_INTEL_BOARD_HELPERS_H
7 #define __SOF_INTEL_BOARD_HELPERS_H
8 
9 #include <sound/soc.h>
10 #include <sound/soc-acpi-intel-ssp-common.h>
11 #include "sof_hdmi_common.h"
12 
13 /*
14  * Common board quirks: from bit 8 to 31, LSB 8 bits reserved for machine
15  *                      drivers
16  */
17 
18 /* SSP port number for headphone codec: 3 bits */
19 #define SOF_SSP_PORT_CODEC_SHIFT		8
20 #define SOF_SSP_PORT_CODEC_MASK			(GENMASK(10, 8))
21 #define SOF_SSP_PORT_CODEC(quirk)		\
22 	(((quirk) << SOF_SSP_PORT_CODEC_SHIFT) & SOF_SSP_PORT_CODEC_MASK)
23 
24 /* SSP port number for speaker amplifier: 3 bits */
25 #define SOF_SSP_PORT_AMP_SHIFT			11
26 #define SOF_SSP_PORT_AMP_MASK			(GENMASK(13, 11))
27 #define SOF_SSP_PORT_AMP(quirk)			\
28 	(((quirk) << SOF_SSP_PORT_AMP_SHIFT) & SOF_SSP_PORT_AMP_MASK)
29 
30 /* SSP port number for BT audio offload: 3 bits */
31 #define SOF_SSP_PORT_BT_OFFLOAD_SHIFT		14
32 #define SOF_SSP_PORT_BT_OFFLOAD_MASK		(GENMASK(16, 14))
33 #define SOF_SSP_PORT_BT_OFFLOAD(quirk)		\
34 	(((quirk) << SOF_SSP_PORT_BT_OFFLOAD_SHIFT) & SOF_SSP_PORT_BT_OFFLOAD_MASK)
35 
36 /* SSP port mask for HDMI capture: 6 bits */
37 #define SOF_SSP_MASK_HDMI_CAPTURE_SHIFT		17
38 #define SOF_SSP_MASK_HDMI_CAPTURE_MASK		(GENMASK(22, 17))
39 #define SOF_SSP_MASK_HDMI_CAPTURE(quirk)	\
40 	(((quirk) << SOF_SSP_MASK_HDMI_CAPTURE_SHIFT) & SOF_SSP_MASK_HDMI_CAPTURE_MASK)
41 
42 /* Number of idisp HDMI BE link: 3 bits */
43 #define SOF_NUM_IDISP_HDMI_SHIFT		23
44 #define SOF_NUM_IDISP_HDMI_MASK			(GENMASK(25, 23))
45 #define SOF_NUM_IDISP_HDMI(quirk)		\
46 	(((quirk) << SOF_NUM_IDISP_HDMI_SHIFT) & SOF_NUM_IDISP_HDMI_MASK)
47 
48 /* Board uses BT audio offload */
49 #define SOF_BT_OFFLOAD_PRESENT			BIT(26)
50 
51 enum {
52 	SOF_LINK_NONE = 0,
53 	SOF_LINK_CODEC,
54 	SOF_LINK_DMIC01,
55 	SOF_LINK_DMIC16K,
56 	SOF_LINK_IDISP_HDMI,
57 	SOF_LINK_AMP,
58 	SOF_LINK_BT_OFFLOAD,
59 	SOF_LINK_HDMI_IN,
60 	SOF_LINK_HDA,
61 };
62 
63 #define SOF_LINK_ORDER_MASK	(0xF)
64 #define SOF_LINK_ORDER_SHIFT	(4)
65 
66 #define SOF_LINK_ORDER(k1, k2, k3, k4, k5, k6, k7) \
67 	((((k1) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 0)) | \
68 	 (((k2) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 1)) | \
69 	 (((k3) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 2)) | \
70 	 (((k4) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 3)) | \
71 	 (((k5) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 4)) | \
72 	 (((k6) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 5)) | \
73 	 (((k7) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 6)))
74 
75 #define SOF_LINK_IDS_MASK	(0xF)
76 #define SOF_LINK_IDS_SHIFT	(4)
77 
78 #define SOF_LINK_IDS(k1, k2, k3, k4, k5, k6, k7) \
79 	((((k1) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 0)) | \
80 	 (((k2) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 1)) | \
81 	 (((k3) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 2)) | \
82 	 (((k4) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 3)) | \
83 	 (((k5) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 4)) | \
84 	 (((k6) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 5)) | \
85 	 (((k7) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 6)))
86 
87 /*
88  * sof_da7219_private: private data for da7219 machine driver
89  *
90  * @mclk_en: true for mclk pin is connected
91  * @pll_bypass: true for PLL bypass mode
92  */
93 struct sof_da7219_private {
94 	bool mclk_en;
95 	bool pll_bypass;
96 };
97 
98 /*
99  * sof_rt5682_private: private data for rt5682 machine driver
100  *
101  * @mclk: mclk clock data
102  * @is_legacy_cpu: true for BYT/CHT boards
103  * @mclk_en: true for mclk pin is connected
104  */
105 struct sof_rt5682_private {
106 	struct clk *mclk;
107 	bool is_legacy_cpu;
108 	bool mclk_en;
109 };
110 
111 /*
112  * sof_card_private: common data for machine drivers
113  *
114  * @headset_jack: headset jack data
115  * @hdmi: init data for hdmi dai link
116  * @codec_type: type of headset codec
117  * @amp_type: type of speaker amplifier
118  * @dmic_be_num: number of Intel PCH DMIC BE link
119  * @hdmi_num: number of Intel HDMI BE link
120  * @ssp_codec: ssp port number of headphone BE link
121  * @ssp_amp: ssp port number of speaker BE link
122  * @ssp_bt: ssp port number of BT offload BE link
123  * @ssp_mask_hdmi_in: ssp port mask of HDMI-IN BE link
124  * @bt_offload_present: true to create BT offload BE link
125  * @hda_codec_present: true to create HDA codec BE links
126  * @codec_link: pointer to headset codec dai link
127  * @amp_link: pointer to speaker amplifier dai link
128  * @link_order_overwrite: custom DAI link order
129  * @link_id_overwrite: custom DAI link ID
130  * @da7219: private data for da7219 machine driver
131  * @rt5682: private data for rt5682 machine driver
132  */
133 struct sof_card_private {
134 	struct snd_soc_jack headset_jack;
135 	struct sof_hdmi_private hdmi;
136 
137 	enum snd_soc_acpi_intel_codec codec_type;
138 	enum snd_soc_acpi_intel_codec amp_type;
139 
140 	int dmic_be_num;
141 	int hdmi_num;
142 
143 	int ssp_codec;
144 	int ssp_amp;
145 	int ssp_bt;
146 	unsigned long ssp_mask_hdmi_in;
147 
148 	bool bt_offload_present;
149 	bool hda_codec_present;
150 
151 	struct snd_soc_dai_link *codec_link;
152 	struct snd_soc_dai_link *amp_link;
153 
154 	unsigned long link_order_overwrite;
155 	/*
156 	 * A variable stores id for all BE DAI links, use SOF_LINK_IDS macro to
157 	 * build the value; use DAI link array index as id if zero.
158 	 */
159 	unsigned long link_id_overwrite;
160 
161 	union {
162 		struct sof_da7219_private da7219;
163 		struct sof_rt5682_private rt5682;
164 	};
165 };
166 
167 int sof_intel_board_card_late_probe(struct snd_soc_card *card);
168 int sof_intel_board_set_dai_link(struct device *dev, struct snd_soc_card *card,
169 				 struct sof_card_private *ctx);
170 struct sof_card_private *
171 sof_intel_board_get_ctx(struct device *dev, unsigned long board_quirk);
172 
173 #endif /* __SOF_INTEL_BOARD_HELPERS_H */
174