xref: /linux/sound/soc/intel/boards/sof_board_helpers.h (revision 90d32e92011eaae8e70a9169b4e7acf4ca8f9d3a)
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 };
61 
62 #define SOF_LINK_ORDER_MASK	(0xF)
63 #define SOF_LINK_ORDER_SHIFT	(4)
64 
65 #define SOF_LINK_ORDER(k1, k2, k3, k4, k5, k6, k7) \
66 	((((k1) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 0)) | \
67 	 (((k2) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 1)) | \
68 	 (((k3) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 2)) | \
69 	 (((k4) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 3)) | \
70 	 (((k5) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 4)) | \
71 	 (((k6) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 5)) | \
72 	 (((k7) & SOF_LINK_ORDER_MASK) << (SOF_LINK_ORDER_SHIFT * 6)))
73 
74 #define SOF_LINK_IDS_MASK	(0xF)
75 #define SOF_LINK_IDS_SHIFT	(4)
76 
77 #define SOF_LINK_IDS(k1, k2, k3, k4, k5, k6, k7) \
78 	((((k1) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 0)) | \
79 	 (((k2) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 1)) | \
80 	 (((k3) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 2)) | \
81 	 (((k4) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 3)) | \
82 	 (((k5) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 4)) | \
83 	 (((k6) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 5)) | \
84 	 (((k7) & SOF_LINK_IDS_MASK) << (SOF_LINK_IDS_SHIFT * 6)))
85 
86 /*
87  * sof_da7219_private: private data for da7219 machine driver
88  *
89  * @is_jsl_board: true for JSL boards
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 is_jsl_board;
95 	bool mclk_en;
96 	bool pll_bypass;
97 };
98 
99 /*
100  * sof_rt5682_private: private data for rt5682 machine driver
101  *
102  * @mclk: mclk clock data
103  * @is_legacy_cpu: true for BYT/CHT boards
104  * @mclk_en: true for mclk pin is connected
105  */
106 struct sof_rt5682_private {
107 	struct clk *mclk;
108 	bool is_legacy_cpu;
109 	bool mclk_en;
110 };
111 
112 /*
113  * sof_card_private: common data for machine drivers
114  *
115  * @headset_jack: headset jack data
116  * @hdmi: init data for hdmi dai link
117  * @codec_type: type of headset codec
118  * @amp_type: type of speaker amplifier
119  * @dmic_be_num: number of Intel PCH DMIC BE link
120  * @hdmi_num: number of Intel HDMI BE link
121  * @ssp_codec: ssp port number of headphone BE link
122  * @ssp_amp: ssp port number of speaker BE link
123  * @ssp_bt: ssp port number of BT offload BE link
124  * @ssp_mask_hdmi_in: ssp port mask of HDMI-IN BE link
125  * @bt_offload_present: true to create BT offload BE link
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 
150 	struct snd_soc_dai_link *codec_link;
151 	struct snd_soc_dai_link *amp_link;
152 
153 	unsigned long link_order_overwrite;
154 	/*
155 	 * A variable stores id for all BE DAI links, use SOF_LINK_IDS macro to
156 	 * build the value; use DAI link array index as id if zero.
157 	 */
158 	unsigned long link_id_overwrite;
159 
160 	union {
161 		struct sof_da7219_private da7219;
162 		struct sof_rt5682_private rt5682;
163 	};
164 };
165 
166 int sof_intel_board_card_late_probe(struct snd_soc_card *card);
167 int sof_intel_board_set_dai_link(struct device *dev, struct snd_soc_card *card,
168 				 struct sof_card_private *ctx);
169 struct sof_card_private *
170 sof_intel_board_get_ctx(struct device *dev, unsigned long board_quirk);
171 
172 #endif /* __SOF_INTEL_BOARD_HELPERS_H */
173