xref: /linux/include/sound/soc-acpi.h (revision 65dc80a78c5f42f5648396b218f50374cf1c2770)
1 /* SPDX-License-Identifier: GPL-2.0-only
2  *
3  * Copyright (C) 2013-15, Intel Corporation
4  */
5 
6 #ifndef __LINUX_SND_SOC_ACPI_H
7 #define __LINUX_SND_SOC_ACPI_H
8 
9 #include <linux/stddef.h>
10 #include <linux/acpi.h>
11 #include <linux/mod_devicetable.h>
12 #include <linux/soundwire/sdw.h>
13 
14 struct snd_soc_acpi_package_context {
15 	char *name;           /* package name */
16 	int length;           /* number of elements */
17 	struct acpi_buffer *format;
18 	struct acpi_buffer *state;
19 	bool data_valid;
20 };
21 
22 /* codec name is used in DAIs is i2c-<HID>:00 with HID being 8 chars */
23 #define SND_ACPI_I2C_ID_LEN (4 + ACPI_ID_LEN + 3 + 1)
24 
25 #if IS_ENABLED(CONFIG_ACPI)
26 /* acpi match */
27 struct snd_soc_acpi_mach *
28 snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines);
29 
30 bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
31 				    struct snd_soc_acpi_package_context *ctx);
32 
33 /* check all codecs */
34 struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg);
35 
36 #else
37 /* acpi match */
38 static inline struct snd_soc_acpi_mach *
39 snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
40 {
41 	return NULL;
42 }
43 
44 static inline bool
45 snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
46 				   struct snd_soc_acpi_package_context *ctx)
47 {
48 	return false;
49 }
50 
51 /* check all codecs */
52 static inline struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
53 {
54 	return NULL;
55 }
56 #endif
57 
58 /**
59  * snd_soc_acpi_mach_params: interface for machine driver configuration
60  *
61  * @acpi_ipc_irq_index: used for BYT-CR detection
62  * @platform: string used for HDAudio codec support
63  * @codec_mask: used for HDAudio support
64  * @dmic_num: number of SoC- or chipset-attached PDM digital microphones
65  * @common_hdmi_codec_drv: use commom HDAudio HDMI codec driver
66  * @link_mask: SoundWire links enabled on the board
67  * @links: array of SoundWire link _ADR descriptors, null terminated
68  * @i2s_link_mask: I2S/TDM links enabled on the board
69  * @num_dai_drivers: number of elements in @dai_drivers
70  * @dai_drivers: pointer to dai_drivers, used e.g. in nocodec mode
71  * @subsystem_vendor: optional PCI SSID vendor value
72  * @subsystem_device: optional PCI SSID device value
73  * @subsystem_rev: optional PCI SSID revision value
74  * @subsystem_id_set: true if a value has been written to
75  *		      subsystem_vendor and subsystem_device.
76  * @bt_link_mask: BT offload link enabled on the board
77  */
78 struct snd_soc_acpi_mach_params {
79 	u32 acpi_ipc_irq_index;
80 	const char *platform;
81 	u32 codec_mask;
82 	u32 dmic_num;
83 	bool common_hdmi_codec_drv;
84 	u32 link_mask;
85 	const struct snd_soc_acpi_link_adr *links;
86 	u32 i2s_link_mask;
87 	u32 num_dai_drivers;
88 	struct snd_soc_dai_driver *dai_drivers;
89 	unsigned short subsystem_vendor;
90 	unsigned short subsystem_device;
91 	unsigned short subsystem_rev;
92 	bool subsystem_id_set;
93 	u32 bt_link_mask;
94 };
95 
96 /**
97  * snd_soc_acpi_endpoint - endpoint descriptor
98  * @num: endpoint number (mandatory, unique per device)
99  * @aggregated: 0 (independent) or 1 (logically grouped)
100  * @group_position: zero-based order (only when @aggregated is 1)
101  * @group_id: platform-unique group identifier (only when @aggregrated is 1)
102  */
103 struct snd_soc_acpi_endpoint {
104 	u8 num;
105 	u8 aggregated;
106 	u8 group_position;
107 	u8 group_id;
108 };
109 
110 /**
111  * snd_soc_acpi_adr_device - descriptor for _ADR-enumerated device
112  * @adr: 64 bit ACPI _ADR value
113  * @num_endpoints: number of endpoints for this device
114  * @endpoints: array of endpoints
115  * @name_prefix: string used for codec controls
116  */
117 struct snd_soc_acpi_adr_device {
118 	const u64 adr;
119 	const u8 num_endpoints;
120 	const struct snd_soc_acpi_endpoint *endpoints;
121 	const char *name_prefix;
122 };
123 
124 /**
125  * snd_soc_acpi_link_adr - ACPI-based list of _ADR enumerated devices
126  * @mask: one bit set indicates the link this list applies to
127  * @num_adr: ARRAY_SIZE of devices
128  * @adr_d: array of devices
129  *
130  * The number of devices per link can be more than 1, e.g. in SoundWire
131  * multi-drop configurations.
132  */
133 
134 struct snd_soc_acpi_link_adr {
135 	const u32 mask;
136 	const u32 num_adr;
137 	const struct snd_soc_acpi_adr_device *adr_d;
138 };
139 
140 /*
141  * when set the topology uses the -ssp<N> suffix, where N is determined based on
142  * BIOS or DMI information
143  */
144 #define SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER BIT(0)
145 
146 /*
147  * when more than one SSP is reported in the link mask, use the most significant.
148  * This choice was found to be valid on platforms with ES8336 codecs.
149  */
150 #define SND_SOC_ACPI_TPLG_INTEL_SSP_MSB BIT(1)
151 
152 /*
153  * when set the topology uses the -dmic<N>ch suffix, where N is determined based on
154  * BIOS or DMI information
155  */
156 #define SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER BIT(2)
157 
158 /*
159  * when set the speaker amplifier name suffix (i.e. "-max98360a") will be
160  * appended to topology file name
161  */
162 #define SND_SOC_ACPI_TPLG_INTEL_AMP_NAME BIT(3)
163 
164 /*
165  * when set the headphone codec name suffix (i.e. "-rt5682") will be appended to
166  * topology file name
167  */
168 #define SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME BIT(4)
169 
170 /**
171  * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
172  * related to the hardware, except for the firmware and topology file names.
173  * A platform supported by legacy and Sound Open Firmware (SOF) would expose
174  * all firmware/topology related fields.
175  *
176  * @id: ACPI ID (usually the codec's) used to find a matching machine driver.
177  * @uid: ACPI Unique ID, can be used to disambiguate matches.
178  * @comp_ids: list of compatible audio codecs using the same machine driver,
179  * firmware and topology
180  * @link_mask: describes required board layout, e.g. for SoundWire.
181  * @links: array of link _ADR descriptors, null terminated.
182  * @drv_name: machine driver name
183  * @fw_filename: firmware file name. Used when SOF is not enabled.
184  * @tplg_filename: topology file name. Used when SOF is not enabled.
185  * @board: board name
186  * @machine_quirk: pointer to quirk, usually based on DMI information when
187  * ACPI ID alone is not sufficient, wrong or misleading
188  * @quirk_data: data used to uniquely identify a machine, usually a list of
189  * audio codecs whose presence if checked with ACPI
190  * @pdata: intended for platform data or machine specific-ops. This structure
191  *  is not constant since this field may be updated at run-time
192  * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
193  * @tplg_quirk_mask: quirks to select different topology files dynamically
194  */
195 /* Descriptor for SST ASoC machine driver */
196 struct snd_soc_acpi_mach {
197 	u8 id[ACPI_ID_LEN];
198 	const char *uid;
199 	const struct snd_soc_acpi_codecs *comp_ids;
200 	const u32 link_mask;
201 	const struct snd_soc_acpi_link_adr *links;
202 	const char *drv_name;
203 	const char *fw_filename;
204 	const char *tplg_filename;
205 	const char *board;
206 	struct snd_soc_acpi_mach * (*machine_quirk)(void *arg);
207 	const void *quirk_data;
208 	void *pdata;
209 	struct snd_soc_acpi_mach_params mach_params;
210 	const char *sof_tplg_filename;
211 	const u32 tplg_quirk_mask;
212 };
213 
214 #define SND_SOC_ACPI_MAX_CODECS 3
215 
216 /**
217  * struct snd_soc_acpi_codecs: Structure to hold secondary codec information
218  * apart from the matched one, this data will be passed to the quirk function
219  * to match with the ACPI detected devices
220  *
221  * @num_codecs: number of secondary codecs used in the platform
222  * @codecs: holds the codec IDs
223  *
224  */
225 struct snd_soc_acpi_codecs {
226 	int num_codecs;
227 	u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN];
228 };
229 
230 static inline bool snd_soc_acpi_sof_parent(struct device *dev)
231 {
232 	return dev->parent && dev->parent->driver && dev->parent->driver->name &&
233 		!strncmp(dev->parent->driver->name, "sof-audio-acpi", strlen("sof-audio-acpi"));
234 }
235 
236 bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
237 					const struct snd_soc_acpi_link_adr *link,
238 					struct sdw_extended_slave_id *ids,
239 					int num_slaves);
240 
241 #endif
242