xref: /OK3568_Linux_fs/kernel/include/sound/soc-acpi.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Copyright (C) 2013-15, Intel Corporation. All rights reserved.
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #ifndef __LINUX_SND_SOC_ACPI_H
7*4882a593Smuzhiyun #define __LINUX_SND_SOC_ACPI_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/stddef.h>
10*4882a593Smuzhiyun #include <linux/acpi.h>
11*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun struct snd_soc_acpi_package_context {
14*4882a593Smuzhiyun 	char *name;           /* package name */
15*4882a593Smuzhiyun 	int length;           /* number of elements */
16*4882a593Smuzhiyun 	struct acpi_buffer *format;
17*4882a593Smuzhiyun 	struct acpi_buffer *state;
18*4882a593Smuzhiyun 	bool data_valid;
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /* codec name is used in DAIs is i2c-<HID>:00 with HID being 8 chars */
22*4882a593Smuzhiyun #define SND_ACPI_I2C_ID_LEN (4 + ACPI_ID_LEN + 3 + 1)
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_ACPI)
25*4882a593Smuzhiyun /* acpi match */
26*4882a593Smuzhiyun struct snd_soc_acpi_mach *
27*4882a593Smuzhiyun snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines);
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
30*4882a593Smuzhiyun 				    struct snd_soc_acpi_package_context *ctx);
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun /* check all codecs */
33*4882a593Smuzhiyun struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg);
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #else
36*4882a593Smuzhiyun /* acpi match */
37*4882a593Smuzhiyun static inline struct snd_soc_acpi_mach *
snd_soc_acpi_find_machine(struct snd_soc_acpi_mach * machines)38*4882a593Smuzhiyun snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	return NULL;
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun static inline bool
snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],struct snd_soc_acpi_package_context * ctx)44*4882a593Smuzhiyun snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
45*4882a593Smuzhiyun 				   struct snd_soc_acpi_package_context *ctx)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun 	return false;
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /* check all codecs */
snd_soc_acpi_codec_list(void * arg)51*4882a593Smuzhiyun static inline struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun 	return NULL;
54*4882a593Smuzhiyun }
55*4882a593Smuzhiyun #endif
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /**
58*4882a593Smuzhiyun  * snd_soc_acpi_mach_params: interface for machine driver configuration
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * @acpi_ipc_irq_index: used for BYT-CR detection
61*4882a593Smuzhiyun  * @platform: string used for HDAudio codec support
62*4882a593Smuzhiyun  * @codec_mask: used for HDAudio support
63*4882a593Smuzhiyun  * @common_hdmi_codec_drv: use commom HDAudio HDMI codec driver
64*4882a593Smuzhiyun  * @link_mask: links enabled on the board
65*4882a593Smuzhiyun  * @links: array of link _ADR descriptors, null terminated
66*4882a593Smuzhiyun  */
67*4882a593Smuzhiyun struct snd_soc_acpi_mach_params {
68*4882a593Smuzhiyun 	u32 acpi_ipc_irq_index;
69*4882a593Smuzhiyun 	const char *platform;
70*4882a593Smuzhiyun 	u32 codec_mask;
71*4882a593Smuzhiyun 	u32 dmic_num;
72*4882a593Smuzhiyun 	bool common_hdmi_codec_drv;
73*4882a593Smuzhiyun 	u32 link_mask;
74*4882a593Smuzhiyun 	const struct snd_soc_acpi_link_adr *links;
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /**
78*4882a593Smuzhiyun  * snd_soc_acpi_endpoint - endpoint descriptor
79*4882a593Smuzhiyun  * @num: endpoint number (mandatory, unique per device)
80*4882a593Smuzhiyun  * @aggregated: 0 (independent) or 1 (logically grouped)
81*4882a593Smuzhiyun  * @group_position: zero-based order (only when @aggregated is 1)
82*4882a593Smuzhiyun  * @group_id: platform-unique group identifier (only when @aggregrated is 1)
83*4882a593Smuzhiyun  */
84*4882a593Smuzhiyun struct snd_soc_acpi_endpoint {
85*4882a593Smuzhiyun 	u8 num;
86*4882a593Smuzhiyun 	u8 aggregated;
87*4882a593Smuzhiyun 	u8 group_position;
88*4882a593Smuzhiyun 	u8 group_id;
89*4882a593Smuzhiyun };
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /**
92*4882a593Smuzhiyun  * snd_soc_acpi_adr_device - descriptor for _ADR-enumerated device
93*4882a593Smuzhiyun  * @adr: 64 bit ACPI _ADR value
94*4882a593Smuzhiyun  * @num_endpoints: number of endpoints for this device
95*4882a593Smuzhiyun  * @endpoints: array of endpoints
96*4882a593Smuzhiyun  * @name_prefix: string used for codec controls
97*4882a593Smuzhiyun  */
98*4882a593Smuzhiyun struct snd_soc_acpi_adr_device {
99*4882a593Smuzhiyun 	const u64 adr;
100*4882a593Smuzhiyun 	const u8 num_endpoints;
101*4882a593Smuzhiyun 	const struct snd_soc_acpi_endpoint *endpoints;
102*4882a593Smuzhiyun 	const char *name_prefix;
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun  * snd_soc_acpi_link_adr - ACPI-based list of _ADR enumerated devices
107*4882a593Smuzhiyun  * @mask: one bit set indicates the link this list applies to
108*4882a593Smuzhiyun  * @num_adr: ARRAY_SIZE of devices
109*4882a593Smuzhiyun  * @adr_d: array of devices
110*4882a593Smuzhiyun  *
111*4882a593Smuzhiyun  * The number of devices per link can be more than 1, e.g. in SoundWire
112*4882a593Smuzhiyun  * multi-drop configurations.
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun struct snd_soc_acpi_link_adr {
116*4882a593Smuzhiyun 	const u32 mask;
117*4882a593Smuzhiyun 	const u32 num_adr;
118*4882a593Smuzhiyun 	const struct snd_soc_acpi_adr_device *adr_d;
119*4882a593Smuzhiyun };
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /**
122*4882a593Smuzhiyun  * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
123*4882a593Smuzhiyun  * related to the hardware, except for the firmware and topology file names.
124*4882a593Smuzhiyun  * A platform supported by legacy and Sound Open Firmware (SOF) would expose
125*4882a593Smuzhiyun  * all firmware/topology related fields.
126*4882a593Smuzhiyun  *
127*4882a593Smuzhiyun  * @id: ACPI ID (usually the codec's) used to find a matching machine driver.
128*4882a593Smuzhiyun  * @link_mask: describes required board layout, e.g. for SoundWire.
129*4882a593Smuzhiyun  * @links: array of link _ADR descriptors, null terminated.
130*4882a593Smuzhiyun  * @drv_name: machine driver name
131*4882a593Smuzhiyun  * @fw_filename: firmware file name. Used when SOF is not enabled.
132*4882a593Smuzhiyun  * @board: board name
133*4882a593Smuzhiyun  * @machine_quirk: pointer to quirk, usually based on DMI information when
134*4882a593Smuzhiyun  * ACPI ID alone is not sufficient, wrong or misleading
135*4882a593Smuzhiyun  * @quirk_data: data used to uniquely identify a machine, usually a list of
136*4882a593Smuzhiyun  * audio codecs whose presence if checked with ACPI
137*4882a593Smuzhiyun  * @pdata: intended for platform data or machine specific-ops. This structure
138*4882a593Smuzhiyun  *  is not constant since this field may be updated at run-time
139*4882a593Smuzhiyun  * @sof_fw_filename: Sound Open Firmware file name, if enabled
140*4882a593Smuzhiyun  * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
141*4882a593Smuzhiyun  */
142*4882a593Smuzhiyun /* Descriptor for SST ASoC machine driver */
143*4882a593Smuzhiyun struct snd_soc_acpi_mach {
144*4882a593Smuzhiyun 	const u8 id[ACPI_ID_LEN];
145*4882a593Smuzhiyun 	const u32 link_mask;
146*4882a593Smuzhiyun 	const struct snd_soc_acpi_link_adr *links;
147*4882a593Smuzhiyun 	const char *drv_name;
148*4882a593Smuzhiyun 	const char *fw_filename;
149*4882a593Smuzhiyun 	const char *board;
150*4882a593Smuzhiyun 	struct snd_soc_acpi_mach * (*machine_quirk)(void *arg);
151*4882a593Smuzhiyun 	const void *quirk_data;
152*4882a593Smuzhiyun 	void *pdata;
153*4882a593Smuzhiyun 	struct snd_soc_acpi_mach_params mach_params;
154*4882a593Smuzhiyun 	const char *sof_fw_filename;
155*4882a593Smuzhiyun 	const char *sof_tplg_filename;
156*4882a593Smuzhiyun };
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun #define SND_SOC_ACPI_MAX_CODECS 3
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun /**
161*4882a593Smuzhiyun  * struct snd_soc_acpi_codecs: Structure to hold secondary codec information
162*4882a593Smuzhiyun  * apart from the matched one, this data will be passed to the quirk function
163*4882a593Smuzhiyun  * to match with the ACPI detected devices
164*4882a593Smuzhiyun  *
165*4882a593Smuzhiyun  * @num_codecs: number of secondary codecs used in the platform
166*4882a593Smuzhiyun  * @codecs: holds the codec IDs
167*4882a593Smuzhiyun  *
168*4882a593Smuzhiyun  */
169*4882a593Smuzhiyun struct snd_soc_acpi_codecs {
170*4882a593Smuzhiyun 	int num_codecs;
171*4882a593Smuzhiyun 	u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN];
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun #endif
175