Commit | Line | Data |
---|---|---|
e149ca29 | 1 | /* SPDX-License-Identifier: GPL-2.0-only |
7feb2f78 | 2 | * |
7730bb13 | 3 | * Copyright (C) 2013-15, Intel Corporation. All rights reserved. |
7feb2f78 PLB |
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> | |
845ab400 | 11 | #include <linux/mod_devicetable.h> |
bb29a33c | 12 | #include <linux/soundwire/sdw.h> |
7feb2f78 PLB |
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 | ||
2be2d579 PLB |
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 | ||
7feb2f78 | 25 | #if IS_ENABLED(CONFIG_ACPI) |
5e484ec1 PLB |
26 | /* acpi match */ |
27 | struct snd_soc_acpi_mach * | |
28 | snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines); | |
29 | ||
7feb2f78 PLB |
30 | bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN], |
31 | struct snd_soc_acpi_package_context *ctx); | |
5e484ec1 PLB |
32 | |
33 | /* check all codecs */ | |
34 | struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg); | |
35 | ||
7feb2f78 | 36 | #else |
5e484ec1 PLB |
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 | ||
7feb2f78 PLB |
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 | } | |
7feb2f78 | 50 | |
5e484ec1 PLB |
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 | |
7feb2f78 | 57 | |
8679284b PLB |
58 | /** |
59 | * snd_soc_acpi_mach_params: interface for machine driver configuration | |
60 | * | |
61 | * @acpi_ipc_irq_index: used for BYT-CR detection | |
135ab457 | 62 | * @platform: string used for HDAudio codec support |
8679284b | 63 | * @codec_mask: used for HDAudio support |
1174442b | 64 | * @dmic_num: number of SoC- or chipset-attached PDM digital microphones |
7de9a47c | 65 | * @common_hdmi_codec_drv: use commom HDAudio HDMI codec driver |
1174442b PLB |
66 | * @link_mask: SoundWire links enabled on the board |
67 | * @links: array of SoundWire link _ADR descriptors, null terminated | |
679aa83a | 68 | * @i2s_link_mask: I2S/TDM links enabled on the board |
ca6a0122 PLB |
69 | * @num_dai_drivers: number of elements in @dai_drivers |
70 | * @dai_drivers: pointer to dai_drivers, used e.g. in nocodec mode | |
8679284b PLB |
71 | */ |
72 | struct snd_soc_acpi_mach_params { | |
73 | u32 acpi_ipc_irq_index; | |
74 | const char *platform; | |
75 | u32 codec_mask; | |
b92826fa | 76 | u32 dmic_num; |
7de9a47c | 77 | bool common_hdmi_codec_drv; |
efb6f315 PLB |
78 | u32 link_mask; |
79 | const struct snd_soc_acpi_link_adr *links; | |
679aa83a | 80 | u32 i2s_link_mask; |
ca6a0122 PLB |
81 | u32 num_dai_drivers; |
82 | struct snd_soc_dai_driver *dai_drivers; | |
efb6f315 PLB |
83 | }; |
84 | ||
85 | /** | |
004bd416 PLB |
86 | * snd_soc_acpi_endpoint - endpoint descriptor |
87 | * @num: endpoint number (mandatory, unique per device) | |
88 | * @aggregated: 0 (independent) or 1 (logically grouped) | |
89 | * @group_position: zero-based order (only when @aggregated is 1) | |
90 | * @group_id: platform-unique group identifier (only when @aggregrated is 1) | |
91 | */ | |
92 | struct snd_soc_acpi_endpoint { | |
93 | u8 num; | |
94 | u8 aggregated; | |
95 | u8 group_position; | |
96 | u8 group_id; | |
97 | }; | |
98 | ||
99 | /** | |
100 | * snd_soc_acpi_adr_device - descriptor for _ADR-enumerated device | |
101 | * @adr: 64 bit ACPI _ADR value | |
102 | * @num_endpoints: number of endpoints for this device | |
103 | * @endpoints: array of endpoints | |
f9380830 | 104 | * @name_prefix: string used for codec controls |
004bd416 PLB |
105 | */ |
106 | struct snd_soc_acpi_adr_device { | |
107 | const u64 adr; | |
108 | const u8 num_endpoints; | |
109 | const struct snd_soc_acpi_endpoint *endpoints; | |
f9380830 | 110 | const char *name_prefix; |
004bd416 PLB |
111 | }; |
112 | ||
113 | /** | |
114 | * snd_soc_acpi_link_adr - ACPI-based list of _ADR enumerated devices | |
efb6f315 | 115 | * @mask: one bit set indicates the link this list applies to |
004bd416 PLB |
116 | * @num_adr: ARRAY_SIZE of devices |
117 | * @adr_d: array of devices | |
118 | * | |
119 | * The number of devices per link can be more than 1, e.g. in SoundWire | |
120 | * multi-drop configurations. | |
efb6f315 PLB |
121 | */ |
122 | ||
123 | struct snd_soc_acpi_link_adr { | |
124 | const u32 mask; | |
125 | const u32 num_adr; | |
004bd416 | 126 | const struct snd_soc_acpi_adr_device *adr_d; |
8679284b PLB |
127 | }; |
128 | ||
4694b838 PLB |
129 | /* |
130 | * when set the topology uses the -ssp<N> suffix, where N is determined based on | |
131 | * BIOS or DMI information | |
132 | */ | |
133 | #define SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER BIT(0) | |
134 | ||
135 | /* | |
136 | * when more than one SSP is reported in the link mask, use the most significant. | |
137 | * This choice was found to be valid on platforms with ES8336 codecs. | |
138 | */ | |
139 | #define SND_SOC_ACPI_TPLG_INTEL_SSP_MSB BIT(1) | |
140 | ||
141 | /* | |
142 | * when set the topology uses the -dmic<N>ch suffix, where N is determined based on | |
143 | * BIOS or DMI information | |
144 | */ | |
145 | #define SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER BIT(2) | |
146 | ||
7feb2f78 PLB |
147 | /** |
148 | * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are | |
149 | * related to the hardware, except for the firmware and topology file names. | |
976b5a0e PLB |
150 | * A platform supported by legacy and Sound Open Firmware (SOF) would expose |
151 | * all firmware/topology related fields. | |
7feb2f78 PLB |
152 | * |
153 | * @id: ACPI ID (usually the codec's) used to find a matching machine driver. | |
9f0d4d47 | 154 | * @uid: ACPI Unique ID, can be used to disambiguate matches. |
cafa39b6 BL |
155 | * @comp_ids: list of compatible audio codecs using the same machine driver, |
156 | * firmware and topology | |
af78cec4 | 157 | * @link_mask: describes required board layout, e.g. for SoundWire. |
efb6f315 | 158 | * @links: array of link _ADR descriptors, null terminated. |
7feb2f78 | 159 | * @drv_name: machine driver name |
976b5a0e | 160 | * @fw_filename: firmware file name. Used when SOF is not enabled. |
f1b3b320 | 161 | * @tplg_filename: topology file name. Used when SOF is not enabled. |
7feb2f78 PLB |
162 | * @board: board name |
163 | * @machine_quirk: pointer to quirk, usually based on DMI information when | |
164 | * ACPI ID alone is not sufficient, wrong or misleading | |
165 | * @quirk_data: data used to uniquely identify a machine, usually a list of | |
166 | * audio codecs whose presence if checked with ACPI | |
167 | * @pdata: intended for platform data or machine specific-ops. This structure | |
168 | * is not constant since this field may be updated at run-time | |
976b5a0e | 169 | * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled |
4694b838 | 170 | * @tplg_quirk_mask: quirks to select different topology files dynamically |
7feb2f78 PLB |
171 | */ |
172 | /* Descriptor for SST ASoC machine driver */ | |
173 | struct snd_soc_acpi_mach { | |
28c916ad | 174 | u8 id[ACPI_ID_LEN]; |
83685510 | 175 | const char *uid; |
cafa39b6 | 176 | const struct snd_soc_acpi_codecs *comp_ids; |
af78cec4 | 177 | const u32 link_mask; |
efb6f315 | 178 | const struct snd_soc_acpi_link_adr *links; |
7feb2f78 PLB |
179 | const char *drv_name; |
180 | const char *fw_filename; | |
f1b3b320 | 181 | const char *tplg_filename; |
7feb2f78 PLB |
182 | const char *board; |
183 | struct snd_soc_acpi_mach * (*machine_quirk)(void *arg); | |
184 | const void *quirk_data; | |
185 | void *pdata; | |
8679284b | 186 | struct snd_soc_acpi_mach_params mach_params; |
976b5a0e | 187 | const char *sof_tplg_filename; |
4694b838 | 188 | const u32 tplg_quirk_mask; |
7feb2f78 PLB |
189 | }; |
190 | ||
191 | #define SND_SOC_ACPI_MAX_CODECS 3 | |
192 | ||
193 | /** | |
194 | * struct snd_soc_acpi_codecs: Structure to hold secondary codec information | |
195 | * apart from the matched one, this data will be passed to the quirk function | |
196 | * to match with the ACPI detected devices | |
197 | * | |
198 | * @num_codecs: number of secondary codecs used in the platform | |
199 | * @codecs: holds the codec IDs | |
200 | * | |
201 | */ | |
202 | struct snd_soc_acpi_codecs { | |
203 | int num_codecs; | |
204 | u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN]; | |
205 | }; | |
206 | ||
644eebdb PLB |
207 | static inline bool snd_soc_acpi_sof_parent(struct device *dev) |
208 | { | |
209 | return dev->parent && dev->parent->driver && dev->parent->driver->name && | |
c7929b15 | 210 | !strncmp(dev->parent->driver->name, "sof-audio-acpi", strlen("sof-audio-acpi")); |
644eebdb PLB |
211 | } |
212 | ||
bb29a33c PLB |
213 | bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev, |
214 | const struct snd_soc_acpi_link_adr *link, | |
215 | struct sdw_extended_slave_id *ids, | |
216 | int num_slaves); | |
217 | ||
7feb2f78 | 218 | #endif |