1e149ca29SPierre-Louis Bossart /* SPDX-License-Identifier: GPL-2.0-only
27730bb13SKuninori Morimoto *
37feb2f78SPierre-Louis Bossart * Copyright (C) 2013-15, Intel Corporation. All rights reserved.
47feb2f78SPierre-Louis Bossart */
57feb2f78SPierre-Louis Bossart
67feb2f78SPierre-Louis Bossart #ifndef __LINUX_SND_SOC_ACPI_H
77feb2f78SPierre-Louis Bossart #define __LINUX_SND_SOC_ACPI_H
87feb2f78SPierre-Louis Bossart
97feb2f78SPierre-Louis Bossart #include <linux/stddef.h>
107feb2f78SPierre-Louis Bossart #include <linux/acpi.h>
11845ab400SPierre-Louis Bossart #include <linux/mod_devicetable.h>
12bb29a33cSPierre-Louis Bossart #include <linux/soundwire/sdw.h>
137feb2f78SPierre-Louis Bossart
147feb2f78SPierre-Louis Bossart struct snd_soc_acpi_package_context {
157feb2f78SPierre-Louis Bossart char *name; /* package name */
167feb2f78SPierre-Louis Bossart int length; /* number of elements */
177feb2f78SPierre-Louis Bossart struct acpi_buffer *format;
187feb2f78SPierre-Louis Bossart struct acpi_buffer *state;
197feb2f78SPierre-Louis Bossart bool data_valid;
207feb2f78SPierre-Louis Bossart };
217feb2f78SPierre-Louis Bossart
222be2d579SPierre-Louis Bossart /* codec name is used in DAIs is i2c-<HID>:00 with HID being 8 chars */
232be2d579SPierre-Louis Bossart #define SND_ACPI_I2C_ID_LEN (4 + ACPI_ID_LEN + 3 + 1)
242be2d579SPierre-Louis Bossart
257feb2f78SPierre-Louis Bossart #if IS_ENABLED(CONFIG_ACPI)
265e484ec1SPierre-Louis Bossart /* acpi match */
275e484ec1SPierre-Louis Bossart struct snd_soc_acpi_mach *
285e484ec1SPierre-Louis Bossart snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines);
295e484ec1SPierre-Louis Bossart
307feb2f78SPierre-Louis Bossart bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
317feb2f78SPierre-Louis Bossart struct snd_soc_acpi_package_context *ctx);
325e484ec1SPierre-Louis Bossart
335e484ec1SPierre-Louis Bossart /* check all codecs */
345e484ec1SPierre-Louis Bossart struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg);
355e484ec1SPierre-Louis Bossart
367feb2f78SPierre-Louis Bossart #else
375e484ec1SPierre-Louis Bossart /* acpi match */
385e484ec1SPierre-Louis Bossart static inline struct snd_soc_acpi_mach *
snd_soc_acpi_find_machine(struct snd_soc_acpi_mach * machines)395e484ec1SPierre-Louis Bossart snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
405e484ec1SPierre-Louis Bossart {
415e484ec1SPierre-Louis Bossart return NULL;
425e484ec1SPierre-Louis Bossart }
435e484ec1SPierre-Louis Bossart
447feb2f78SPierre-Louis Bossart static inline bool
snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],struct snd_soc_acpi_package_context * ctx)457feb2f78SPierre-Louis Bossart snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
467feb2f78SPierre-Louis Bossart struct snd_soc_acpi_package_context *ctx)
477feb2f78SPierre-Louis Bossart {
487feb2f78SPierre-Louis Bossart return false;
497feb2f78SPierre-Louis Bossart }
507feb2f78SPierre-Louis Bossart
515e484ec1SPierre-Louis Bossart /* check all codecs */
snd_soc_acpi_codec_list(void * arg)525e484ec1SPierre-Louis Bossart static inline struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
535e484ec1SPierre-Louis Bossart {
545e484ec1SPierre-Louis Bossart return NULL;
555e484ec1SPierre-Louis Bossart }
565e484ec1SPierre-Louis Bossart #endif
577feb2f78SPierre-Louis Bossart
587feb2f78SPierre-Louis Bossart /**
598679284bSPierre-Louis Bossart * snd_soc_acpi_mach_params: interface for machine driver configuration
608679284bSPierre-Louis Bossart *
618679284bSPierre-Louis Bossart * @acpi_ipc_irq_index: used for BYT-CR detection
62135ab457SPierre-Louis Bossart * @platform: string used for HDAudio codec support
638679284bSPierre-Louis Bossart * @codec_mask: used for HDAudio support
641174442bSPierre-Louis Bossart * @dmic_num: number of SoC- or chipset-attached PDM digital microphones
657de9a47cSKai Vehmanen * @common_hdmi_codec_drv: use commom HDAudio HDMI codec driver
661174442bSPierre-Louis Bossart * @link_mask: SoundWire links enabled on the board
671174442bSPierre-Louis Bossart * @links: array of SoundWire link _ADR descriptors, null terminated
68679aa83aSPierre-Louis Bossart * @i2s_link_mask: I2S/TDM links enabled on the board
69ca6a0122SPierre-Louis Bossart * @num_dai_drivers: number of elements in @dai_drivers
70ca6a0122SPierre-Louis Bossart * @dai_drivers: pointer to dai_drivers, used e.g. in nocodec mode
71*17560515SRichard Fitzgerald * @subsystem_vendor: optional PCI SSID vendor value
72*17560515SRichard Fitzgerald * @subsystem_device: optional PCI SSID device value
73*17560515SRichard Fitzgerald * @subsystem_id_set: true if a value has been written to
74*17560515SRichard Fitzgerald * subsystem_vendor and subsystem_device.
758679284bSPierre-Louis Bossart */
768679284bSPierre-Louis Bossart struct snd_soc_acpi_mach_params {
778679284bSPierre-Louis Bossart u32 acpi_ipc_irq_index;
788679284bSPierre-Louis Bossart const char *platform;
798679284bSPierre-Louis Bossart u32 codec_mask;
80b92826faSPierre-Louis Bossart u32 dmic_num;
817de9a47cSKai Vehmanen bool common_hdmi_codec_drv;
82efb6f315SPierre-Louis Bossart u32 link_mask;
83efb6f315SPierre-Louis Bossart const struct snd_soc_acpi_link_adr *links;
84679aa83aSPierre-Louis Bossart u32 i2s_link_mask;
85ca6a0122SPierre-Louis Bossart u32 num_dai_drivers;
86ca6a0122SPierre-Louis Bossart struct snd_soc_dai_driver *dai_drivers;
87*17560515SRichard Fitzgerald unsigned short subsystem_vendor;
88*17560515SRichard Fitzgerald unsigned short subsystem_device;
89*17560515SRichard Fitzgerald bool subsystem_id_set;
90efb6f315SPierre-Louis Bossart };
91efb6f315SPierre-Louis Bossart
92efb6f315SPierre-Louis Bossart /**
93004bd416SPierre-Louis Bossart * snd_soc_acpi_endpoint - endpoint descriptor
94004bd416SPierre-Louis Bossart * @num: endpoint number (mandatory, unique per device)
95004bd416SPierre-Louis Bossart * @aggregated: 0 (independent) or 1 (logically grouped)
96004bd416SPierre-Louis Bossart * @group_position: zero-based order (only when @aggregated is 1)
97004bd416SPierre-Louis Bossart * @group_id: platform-unique group identifier (only when @aggregrated is 1)
98004bd416SPierre-Louis Bossart */
99004bd416SPierre-Louis Bossart struct snd_soc_acpi_endpoint {
100004bd416SPierre-Louis Bossart u8 num;
101004bd416SPierre-Louis Bossart u8 aggregated;
102004bd416SPierre-Louis Bossart u8 group_position;
103004bd416SPierre-Louis Bossart u8 group_id;
104004bd416SPierre-Louis Bossart };
105004bd416SPierre-Louis Bossart
106004bd416SPierre-Louis Bossart /**
107004bd416SPierre-Louis Bossart * snd_soc_acpi_adr_device - descriptor for _ADR-enumerated device
108004bd416SPierre-Louis Bossart * @adr: 64 bit ACPI _ADR value
109004bd416SPierre-Louis Bossart * @num_endpoints: number of endpoints for this device
110004bd416SPierre-Louis Bossart * @endpoints: array of endpoints
111f9380830SPierre-Louis Bossart * @name_prefix: string used for codec controls
112004bd416SPierre-Louis Bossart */
113004bd416SPierre-Louis Bossart struct snd_soc_acpi_adr_device {
114004bd416SPierre-Louis Bossart const u64 adr;
115004bd416SPierre-Louis Bossart const u8 num_endpoints;
116004bd416SPierre-Louis Bossart const struct snd_soc_acpi_endpoint *endpoints;
117f9380830SPierre-Louis Bossart const char *name_prefix;
118004bd416SPierre-Louis Bossart };
119004bd416SPierre-Louis Bossart
120004bd416SPierre-Louis Bossart /**
121004bd416SPierre-Louis Bossart * snd_soc_acpi_link_adr - ACPI-based list of _ADR enumerated devices
122efb6f315SPierre-Louis Bossart * @mask: one bit set indicates the link this list applies to
123004bd416SPierre-Louis Bossart * @num_adr: ARRAY_SIZE of devices
124004bd416SPierre-Louis Bossart * @adr_d: array of devices
125004bd416SPierre-Louis Bossart *
126004bd416SPierre-Louis Bossart * The number of devices per link can be more than 1, e.g. in SoundWire
127004bd416SPierre-Louis Bossart * multi-drop configurations.
128efb6f315SPierre-Louis Bossart */
129efb6f315SPierre-Louis Bossart
130efb6f315SPierre-Louis Bossart struct snd_soc_acpi_link_adr {
131efb6f315SPierre-Louis Bossart const u32 mask;
132efb6f315SPierre-Louis Bossart const u32 num_adr;
133004bd416SPierre-Louis Bossart const struct snd_soc_acpi_adr_device *adr_d;
1348679284bSPierre-Louis Bossart };
1358679284bSPierre-Louis Bossart
1364694b838SPierre-Louis Bossart /*
1374694b838SPierre-Louis Bossart * when set the topology uses the -ssp<N> suffix, where N is determined based on
1384694b838SPierre-Louis Bossart * BIOS or DMI information
1394694b838SPierre-Louis Bossart */
1404694b838SPierre-Louis Bossart #define SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER BIT(0)
1414694b838SPierre-Louis Bossart
1424694b838SPierre-Louis Bossart /*
1434694b838SPierre-Louis Bossart * when more than one SSP is reported in the link mask, use the most significant.
1444694b838SPierre-Louis Bossart * This choice was found to be valid on platforms with ES8336 codecs.
1454694b838SPierre-Louis Bossart */
1464694b838SPierre-Louis Bossart #define SND_SOC_ACPI_TPLG_INTEL_SSP_MSB BIT(1)
1474694b838SPierre-Louis Bossart
1484694b838SPierre-Louis Bossart /*
1494694b838SPierre-Louis Bossart * when set the topology uses the -dmic<N>ch suffix, where N is determined based on
1504694b838SPierre-Louis Bossart * BIOS or DMI information
1514694b838SPierre-Louis Bossart */
1524694b838SPierre-Louis Bossart #define SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER BIT(2)
1534694b838SPierre-Louis Bossart
1548679284bSPierre-Louis Bossart /**
1557feb2f78SPierre-Louis Bossart * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
1567feb2f78SPierre-Louis Bossart * related to the hardware, except for the firmware and topology file names.
157976b5a0eSPierre-Louis Bossart * A platform supported by legacy and Sound Open Firmware (SOF) would expose
158976b5a0eSPierre-Louis Bossart * all firmware/topology related fields.
1597feb2f78SPierre-Louis Bossart *
1607feb2f78SPierre-Louis Bossart * @id: ACPI ID (usually the codec's) used to find a matching machine driver.
1619f0d4d47SCharles Keepax * @uid: ACPI Unique ID, can be used to disambiguate matches.
162cafa39b6SBrent Lu * @comp_ids: list of compatible audio codecs using the same machine driver,
163cafa39b6SBrent Lu * firmware and topology
164af78cec4SPierre-Louis Bossart * @link_mask: describes required board layout, e.g. for SoundWire.
165efb6f315SPierre-Louis Bossart * @links: array of link _ADR descriptors, null terminated.
1667feb2f78SPierre-Louis Bossart * @drv_name: machine driver name
167976b5a0eSPierre-Louis Bossart * @fw_filename: firmware file name. Used when SOF is not enabled.
168f1b3b320SCezary Rojewski * @tplg_filename: topology file name. Used when SOF is not enabled.
1697feb2f78SPierre-Louis Bossart * @board: board name
1707feb2f78SPierre-Louis Bossart * @machine_quirk: pointer to quirk, usually based on DMI information when
1717feb2f78SPierre-Louis Bossart * ACPI ID alone is not sufficient, wrong or misleading
1727feb2f78SPierre-Louis Bossart * @quirk_data: data used to uniquely identify a machine, usually a list of
1737feb2f78SPierre-Louis Bossart * audio codecs whose presence if checked with ACPI
1747feb2f78SPierre-Louis Bossart * @pdata: intended for platform data or machine specific-ops. This structure
1757feb2f78SPierre-Louis Bossart * is not constant since this field may be updated at run-time
176976b5a0eSPierre-Louis Bossart * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
1774694b838SPierre-Louis Bossart * @tplg_quirk_mask: quirks to select different topology files dynamically
1787feb2f78SPierre-Louis Bossart */
1797feb2f78SPierre-Louis Bossart /* Descriptor for SST ASoC machine driver */
1807feb2f78SPierre-Louis Bossart struct snd_soc_acpi_mach {
18128c916adSHans de Goede u8 id[ACPI_ID_LEN];
18283685510SCezary Rojewski const char *uid;
183cafa39b6SBrent Lu const struct snd_soc_acpi_codecs *comp_ids;
184af78cec4SPierre-Louis Bossart const u32 link_mask;
185efb6f315SPierre-Louis Bossart const struct snd_soc_acpi_link_adr *links;
1867feb2f78SPierre-Louis Bossart const char *drv_name;
1877feb2f78SPierre-Louis Bossart const char *fw_filename;
188f1b3b320SCezary Rojewski const char *tplg_filename;
1897feb2f78SPierre-Louis Bossart const char *board;
1907feb2f78SPierre-Louis Bossart struct snd_soc_acpi_mach * (*machine_quirk)(void *arg);
1917feb2f78SPierre-Louis Bossart const void *quirk_data;
1927feb2f78SPierre-Louis Bossart void *pdata;
1938679284bSPierre-Louis Bossart struct snd_soc_acpi_mach_params mach_params;
194976b5a0eSPierre-Louis Bossart const char *sof_tplg_filename;
1954694b838SPierre-Louis Bossart const u32 tplg_quirk_mask;
1967feb2f78SPierre-Louis Bossart };
1977feb2f78SPierre-Louis Bossart
1987feb2f78SPierre-Louis Bossart #define SND_SOC_ACPI_MAX_CODECS 3
1997feb2f78SPierre-Louis Bossart
2007feb2f78SPierre-Louis Bossart /**
2017feb2f78SPierre-Louis Bossart * struct snd_soc_acpi_codecs: Structure to hold secondary codec information
2027feb2f78SPierre-Louis Bossart * apart from the matched one, this data will be passed to the quirk function
2037feb2f78SPierre-Louis Bossart * to match with the ACPI detected devices
2047feb2f78SPierre-Louis Bossart *
2057feb2f78SPierre-Louis Bossart * @num_codecs: number of secondary codecs used in the platform
2067feb2f78SPierre-Louis Bossart * @codecs: holds the codec IDs
2077feb2f78SPierre-Louis Bossart *
2087feb2f78SPierre-Louis Bossart */
2097feb2f78SPierre-Louis Bossart struct snd_soc_acpi_codecs {
2107feb2f78SPierre-Louis Bossart int num_codecs;
2117feb2f78SPierre-Louis Bossart u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN];
2127feb2f78SPierre-Louis Bossart };
2137feb2f78SPierre-Louis Bossart
snd_soc_acpi_sof_parent(struct device * dev)214644eebdbSPierre-Louis Bossart static inline bool snd_soc_acpi_sof_parent(struct device *dev)
215644eebdbSPierre-Louis Bossart {
216644eebdbSPierre-Louis Bossart return dev->parent && dev->parent->driver && dev->parent->driver->name &&
217c7929b15SPierre-Louis Bossart !strncmp(dev->parent->driver->name, "sof-audio-acpi", strlen("sof-audio-acpi"));
218644eebdbSPierre-Louis Bossart }
219644eebdbSPierre-Louis Bossart
220bb29a33cSPierre-Louis Bossart bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
221bb29a33cSPierre-Louis Bossart const struct snd_soc_acpi_link_adr *link,
222bb29a33cSPierre-Louis Bossart struct sdw_extended_slave_id *ids,
223bb29a33cSPierre-Louis Bossart int num_slaves);
224bb29a33cSPierre-Louis Bossart
2257feb2f78SPierre-Louis Bossart #endif
226