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