xref: /openbmc/linux/include/sound/soc-acpi.h (revision 004bd4163104e4d8b6c1433b31ead10a69c69845)
17730bb13SKuninori Morimoto /* SPDX-License-Identifier: GPL-2.0
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>
127feb2f78SPierre-Louis Bossart 
137feb2f78SPierre-Louis Bossart struct snd_soc_acpi_package_context {
147feb2f78SPierre-Louis Bossart 	char *name;           /* package name */
157feb2f78SPierre-Louis Bossart 	int length;           /* number of elements */
167feb2f78SPierre-Louis Bossart 	struct acpi_buffer *format;
177feb2f78SPierre-Louis Bossart 	struct acpi_buffer *state;
187feb2f78SPierre-Louis Bossart 	bool data_valid;
197feb2f78SPierre-Louis Bossart };
207feb2f78SPierre-Louis Bossart 
212be2d579SPierre-Louis Bossart /* codec name is used in DAIs is i2c-<HID>:00 with HID being 8 chars */
222be2d579SPierre-Louis Bossart #define SND_ACPI_I2C_ID_LEN (4 + ACPI_ID_LEN + 3 + 1)
232be2d579SPierre-Louis Bossart 
247feb2f78SPierre-Louis Bossart #if IS_ENABLED(CONFIG_ACPI)
255e484ec1SPierre-Louis Bossart /* acpi match */
265e484ec1SPierre-Louis Bossart struct snd_soc_acpi_mach *
275e484ec1SPierre-Louis Bossart snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines);
285e484ec1SPierre-Louis Bossart 
297feb2f78SPierre-Louis Bossart bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
307feb2f78SPierre-Louis Bossart 				    struct snd_soc_acpi_package_context *ctx);
315e484ec1SPierre-Louis Bossart 
325e484ec1SPierre-Louis Bossart /* check all codecs */
335e484ec1SPierre-Louis Bossart struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg);
345e484ec1SPierre-Louis Bossart 
357feb2f78SPierre-Louis Bossart #else
365e484ec1SPierre-Louis Bossart /* acpi match */
375e484ec1SPierre-Louis Bossart static inline struct snd_soc_acpi_mach *
385e484ec1SPierre-Louis Bossart snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
395e484ec1SPierre-Louis Bossart {
405e484ec1SPierre-Louis Bossart 	return NULL;
415e484ec1SPierre-Louis Bossart }
425e484ec1SPierre-Louis Bossart 
437feb2f78SPierre-Louis Bossart static inline bool
447feb2f78SPierre-Louis Bossart snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
457feb2f78SPierre-Louis Bossart 				   struct snd_soc_acpi_package_context *ctx)
467feb2f78SPierre-Louis Bossart {
477feb2f78SPierre-Louis Bossart 	return false;
487feb2f78SPierre-Louis Bossart }
497feb2f78SPierre-Louis Bossart 
505e484ec1SPierre-Louis Bossart /* check all codecs */
515e484ec1SPierre-Louis Bossart static inline struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
525e484ec1SPierre-Louis Bossart {
535e484ec1SPierre-Louis Bossart 	return NULL;
545e484ec1SPierre-Louis Bossart }
555e484ec1SPierre-Louis Bossart #endif
567feb2f78SPierre-Louis Bossart 
577feb2f78SPierre-Louis Bossart /**
588679284bSPierre-Louis Bossart  * snd_soc_acpi_mach_params: interface for machine driver configuration
598679284bSPierre-Louis Bossart  *
608679284bSPierre-Louis Bossart  * @acpi_ipc_irq_index: used for BYT-CR detection
618679284bSPierre-Louis Bossart  * @platform: string used for HDaudio codec support
628679284bSPierre-Louis Bossart  * @codec_mask: used for HDAudio support
637de9a47cSKai Vehmanen  * @common_hdmi_codec_drv: use commom HDAudio HDMI codec driver
64efb6f315SPierre-Louis Bossart  * @link_mask: links enabled on the board
65efb6f315SPierre-Louis Bossart  * @links: array of link _ADR descriptors, null terminated
668679284bSPierre-Louis Bossart  */
678679284bSPierre-Louis Bossart struct snd_soc_acpi_mach_params {
688679284bSPierre-Louis Bossart 	u32 acpi_ipc_irq_index;
698679284bSPierre-Louis Bossart 	const char *platform;
708679284bSPierre-Louis Bossart 	u32 codec_mask;
71b92826faSPierre-Louis Bossart 	u32 dmic_num;
727de9a47cSKai Vehmanen 	bool common_hdmi_codec_drv;
73efb6f315SPierre-Louis Bossart 	u32 link_mask;
74efb6f315SPierre-Louis Bossart 	const struct snd_soc_acpi_link_adr *links;
75efb6f315SPierre-Louis Bossart };
76efb6f315SPierre-Louis Bossart 
77efb6f315SPierre-Louis Bossart /**
78*004bd416SPierre-Louis Bossart  * snd_soc_acpi_endpoint - endpoint descriptor
79*004bd416SPierre-Louis Bossart  * @num: endpoint number (mandatory, unique per device)
80*004bd416SPierre-Louis Bossart  * @aggregated: 0 (independent) or 1 (logically grouped)
81*004bd416SPierre-Louis Bossart  * @group_position: zero-based order (only when @aggregated is 1)
82*004bd416SPierre-Louis Bossart  * @group_id: platform-unique group identifier (only when @aggregrated is 1)
83*004bd416SPierre-Louis Bossart  */
84*004bd416SPierre-Louis Bossart struct snd_soc_acpi_endpoint {
85*004bd416SPierre-Louis Bossart 	u8 num;
86*004bd416SPierre-Louis Bossart 	u8 aggregated;
87*004bd416SPierre-Louis Bossart 	u8 group_position;
88*004bd416SPierre-Louis Bossart 	u8 group_id;
89*004bd416SPierre-Louis Bossart };
90*004bd416SPierre-Louis Bossart 
91*004bd416SPierre-Louis Bossart /**
92*004bd416SPierre-Louis Bossart  * snd_soc_acpi_adr_device - descriptor for _ADR-enumerated device
93*004bd416SPierre-Louis Bossart  * @adr: 64 bit ACPI _ADR value
94*004bd416SPierre-Louis Bossart  * @num_endpoints: number of endpoints for this device
95*004bd416SPierre-Louis Bossart  * @endpoints: array of endpoints
96*004bd416SPierre-Louis Bossart  */
97*004bd416SPierre-Louis Bossart struct snd_soc_acpi_adr_device {
98*004bd416SPierre-Louis Bossart 	const u64 adr;
99*004bd416SPierre-Louis Bossart 	const u8 num_endpoints;
100*004bd416SPierre-Louis Bossart 	const struct snd_soc_acpi_endpoint *endpoints;
101*004bd416SPierre-Louis Bossart };
102*004bd416SPierre-Louis Bossart 
103*004bd416SPierre-Louis Bossart /**
104*004bd416SPierre-Louis Bossart  * snd_soc_acpi_link_adr - ACPI-based list of _ADR enumerated devices
105efb6f315SPierre-Louis Bossart  * @mask: one bit set indicates the link this list applies to
106*004bd416SPierre-Louis Bossart  * @num_adr: ARRAY_SIZE of devices
107*004bd416SPierre-Louis Bossart  * @adr_d: array of devices
108*004bd416SPierre-Louis Bossart  *
109*004bd416SPierre-Louis Bossart  * The number of devices per link can be more than 1, e.g. in SoundWire
110*004bd416SPierre-Louis Bossart  * multi-drop configurations.
111efb6f315SPierre-Louis Bossart  */
112efb6f315SPierre-Louis Bossart 
113efb6f315SPierre-Louis Bossart struct snd_soc_acpi_link_adr {
114efb6f315SPierre-Louis Bossart 	const u32 mask;
115efb6f315SPierre-Louis Bossart 	const u32 num_adr;
116*004bd416SPierre-Louis Bossart 	const struct snd_soc_acpi_adr_device *adr_d;
1178679284bSPierre-Louis Bossart };
1188679284bSPierre-Louis Bossart 
1198679284bSPierre-Louis Bossart /**
1207feb2f78SPierre-Louis Bossart  * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
1217feb2f78SPierre-Louis Bossart  * related to the hardware, except for the firmware and topology file names.
122976b5a0eSPierre-Louis Bossart  * A platform supported by legacy and Sound Open Firmware (SOF) would expose
123976b5a0eSPierre-Louis Bossart  * all firmware/topology related fields.
1247feb2f78SPierre-Louis Bossart  *
1257feb2f78SPierre-Louis Bossart  * @id: ACPI ID (usually the codec's) used to find a matching machine driver.
126af78cec4SPierre-Louis Bossart  * @link_mask: describes required board layout, e.g. for SoundWire.
127efb6f315SPierre-Louis Bossart  * @links: array of link _ADR descriptors, null terminated.
1287feb2f78SPierre-Louis Bossart  * @drv_name: machine driver name
129976b5a0eSPierre-Louis Bossart  * @fw_filename: firmware file name. Used when SOF is not enabled.
1307feb2f78SPierre-Louis Bossart  * @board: board name
1317feb2f78SPierre-Louis Bossart  * @machine_quirk: pointer to quirk, usually based on DMI information when
1327feb2f78SPierre-Louis Bossart  * ACPI ID alone is not sufficient, wrong or misleading
1337feb2f78SPierre-Louis Bossart  * @quirk_data: data used to uniquely identify a machine, usually a list of
1347feb2f78SPierre-Louis Bossart  * audio codecs whose presence if checked with ACPI
1357feb2f78SPierre-Louis Bossart  * @pdata: intended for platform data or machine specific-ops. This structure
1367feb2f78SPierre-Louis Bossart  *  is not constant since this field may be updated at run-time
137976b5a0eSPierre-Louis Bossart  * @sof_fw_filename: Sound Open Firmware file name, if enabled
138976b5a0eSPierre-Louis Bossart  * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
1397feb2f78SPierre-Louis Bossart  */
1407feb2f78SPierre-Louis Bossart /* Descriptor for SST ASoC machine driver */
1417feb2f78SPierre-Louis Bossart struct snd_soc_acpi_mach {
1427feb2f78SPierre-Louis Bossart 	const u8 id[ACPI_ID_LEN];
143af78cec4SPierre-Louis Bossart 	const u32 link_mask;
144efb6f315SPierre-Louis Bossart 	const struct snd_soc_acpi_link_adr *links;
1457feb2f78SPierre-Louis Bossart 	const char *drv_name;
1467feb2f78SPierre-Louis Bossart 	const char *fw_filename;
1477feb2f78SPierre-Louis Bossart 	const char *board;
1487feb2f78SPierre-Louis Bossart 	struct snd_soc_acpi_mach * (*machine_quirk)(void *arg);
1497feb2f78SPierre-Louis Bossart 	const void *quirk_data;
1507feb2f78SPierre-Louis Bossart 	void *pdata;
1518679284bSPierre-Louis Bossart 	struct snd_soc_acpi_mach_params mach_params;
152976b5a0eSPierre-Louis Bossart 	const char *sof_fw_filename;
153976b5a0eSPierre-Louis Bossart 	const char *sof_tplg_filename;
1547feb2f78SPierre-Louis Bossart };
1557feb2f78SPierre-Louis Bossart 
1567feb2f78SPierre-Louis Bossart #define SND_SOC_ACPI_MAX_CODECS 3
1577feb2f78SPierre-Louis Bossart 
1587feb2f78SPierre-Louis Bossart /**
1597feb2f78SPierre-Louis Bossart  * struct snd_soc_acpi_codecs: Structure to hold secondary codec information
1607feb2f78SPierre-Louis Bossart  * apart from the matched one, this data will be passed to the quirk function
1617feb2f78SPierre-Louis Bossart  * to match with the ACPI detected devices
1627feb2f78SPierre-Louis Bossart  *
1637feb2f78SPierre-Louis Bossart  * @num_codecs: number of secondary codecs used in the platform
1647feb2f78SPierre-Louis Bossart  * @codecs: holds the codec IDs
1657feb2f78SPierre-Louis Bossart  *
1667feb2f78SPierre-Louis Bossart  */
1677feb2f78SPierre-Louis Bossart struct snd_soc_acpi_codecs {
1687feb2f78SPierre-Louis Bossart 	int num_codecs;
1697feb2f78SPierre-Louis Bossart 	u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN];
1707feb2f78SPierre-Louis Bossart };
1717feb2f78SPierre-Louis Bossart 
1727feb2f78SPierre-Louis Bossart #endif
173