xref: /linux/sound/soc/intel/boards/sof_board_helpers.h (revision a3a02a52bcfcbcc4a637d4b68bf1bc391c9fad02)
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  * @mclk_en: true for mclk pin is connected
90  * @pll_bypass: true for PLL bypass mode
91  */
92 struct sof_da7219_private {
93 	bool mclk_en;
94 	bool pll_bypass;
95 };
96 
97 /*
98  * sof_rt5682_private: private data for rt5682 machine driver
99  *
100  * @mclk: mclk clock data
101  * @is_legacy_cpu: true for BYT/CHT boards
102  * @mclk_en: true for mclk pin is connected
103  */
104 struct sof_rt5682_private {
105 	struct clk *mclk;
106 	bool is_legacy_cpu;
107 	bool mclk_en;
108 };
109 
110 /*
111  * sof_card_private: common data for machine drivers
112  *
113  * @headset_jack: headset jack data
114  * @hdmi: init data for hdmi dai link
115  * @codec_type: type of headset codec
116  * @amp_type: type of speaker amplifier
117  * @dmic_be_num: number of Intel PCH DMIC BE link
118  * @hdmi_num: number of Intel HDMI BE link
119  * @ssp_codec: ssp port number of headphone BE link
120  * @ssp_amp: ssp port number of speaker BE link
121  * @ssp_bt: ssp port number of BT offload BE link
122  * @ssp_mask_hdmi_in: ssp port mask of HDMI-IN BE link
123  * @bt_offload_present: true to create BT offload BE link
124  * @codec_link: pointer to headset codec dai link
125  * @amp_link: pointer to speaker amplifier dai link
126  * @link_order_overwrite: custom DAI link order
127  * @link_id_overwrite: custom DAI link ID
128  * @da7219: private data for da7219 machine driver
129  * @rt5682: private data for rt5682 machine driver
130  */
131 struct sof_card_private {
132 	struct snd_soc_jack headset_jack;
133 	struct sof_hdmi_private hdmi;
134 
135 	enum snd_soc_acpi_intel_codec codec_type;
136 	enum snd_soc_acpi_intel_codec amp_type;
137 
138 	int dmic_be_num;
139 	int hdmi_num;
140 
141 	int ssp_codec;
142 	int ssp_amp;
143 	int ssp_bt;
144 	unsigned long ssp_mask_hdmi_in;
145 
146 	bool bt_offload_present;
147 
148 	struct snd_soc_dai_link *codec_link;
149 	struct snd_soc_dai_link *amp_link;
150 
151 	unsigned long link_order_overwrite;
152 	/*
153 	 * A variable stores id for all BE DAI links, use SOF_LINK_IDS macro to
154 	 * build the value; use DAI link array index as id if zero.
155 	 */
156 	unsigned long link_id_overwrite;
157 
158 	union {
159 		struct sof_da7219_private da7219;
160 		struct sof_rt5682_private rt5682;
161 	};
162 };
163 
164 int sof_intel_board_card_late_probe(struct snd_soc_card *card);
165 int sof_intel_board_set_dai_link(struct device *dev, struct snd_soc_card *card,
166 				 struct sof_card_private *ctx);
167 struct sof_card_private *
168 sof_intel_board_get_ctx(struct device *dev, unsigned long board_quirk);
169 
170 #endif /* __SOF_INTEL_BOARD_HELPERS_H */
171