soc-acpi.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (C) 2013-15, Intel Corporation
  4. */
  5. #ifndef __LINUX_SND_SOC_ACPI_H
  6. #define __LINUX_SND_SOC_ACPI_H
  7. #include <linux/stddef.h>
  8. #include <linux/acpi.h>
  9. #include <linux/mod_devicetable.h>
  10. #include <linux/soundwire/sdw.h>
  11. #include <sound/soc.h>
  12. struct snd_soc_acpi_package_context {
  13. char *name; /* package name */
  14. int length; /* number of elements */
  15. struct acpi_buffer *format;
  16. struct acpi_buffer *state;
  17. bool data_valid;
  18. };
  19. /* codec name is used in DAIs is i2c-<HID>:00 with HID being 8 chars */
  20. #define SND_ACPI_I2C_ID_LEN (4 + ACPI_ID_LEN + 3 + 1)
  21. #if IS_ENABLED(CONFIG_ACPI)
  22. /* acpi match */
  23. struct snd_soc_acpi_mach *
  24. snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines);
  25. bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
  26. struct snd_soc_acpi_package_context *ctx);
  27. /* check all codecs */
  28. struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg);
  29. #else
  30. /* acpi match */
  31. static inline struct snd_soc_acpi_mach *
  32. snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
  33. {
  34. return NULL;
  35. }
  36. static inline bool
  37. snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
  38. struct snd_soc_acpi_package_context *ctx)
  39. {
  40. return false;
  41. }
  42. /* check all codecs */
  43. static inline struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
  44. {
  45. return NULL;
  46. }
  47. #endif
  48. /**
  49. * snd_soc_acpi_mach_params: interface for machine driver configuration
  50. *
  51. * @acpi_ipc_irq_index: used for BYT-CR detection
  52. * @platform: string used for HDAudio codec support
  53. * @codec_mask: used for HDAudio support
  54. * @dmic_num: number of SoC- or chipset-attached PDM digital microphones
  55. * @link_mask: SoundWire links enabled on the board
  56. * @links: array of SoundWire link _ADR descriptors, null terminated
  57. * @i2s_link_mask: I2S/TDM links enabled on the board
  58. * @num_dai_drivers: number of elements in @dai_drivers
  59. * @dai_drivers: pointer to dai_drivers, used e.g. in nocodec mode
  60. * @subsystem_vendor: optional PCI SSID vendor value
  61. * @subsystem_device: optional PCI SSID device value
  62. * @subsystem_rev: optional PCI SSID revision value
  63. * @subsystem_id_set: true if a value has been written to
  64. * subsystem_vendor and subsystem_device.
  65. * @bt_link_mask: BT offload link enabled on the board
  66. */
  67. struct snd_soc_acpi_mach_params {
  68. u32 acpi_ipc_irq_index;
  69. const char *platform;
  70. u32 codec_mask;
  71. u32 dmic_num;
  72. u32 link_mask;
  73. const struct snd_soc_acpi_link_adr *links;
  74. u32 i2s_link_mask;
  75. u32 num_dai_drivers;
  76. struct snd_soc_dai_driver *dai_drivers;
  77. unsigned short subsystem_vendor;
  78. unsigned short subsystem_device;
  79. unsigned short subsystem_rev;
  80. bool subsystem_id_set;
  81. u32 bt_link_mask;
  82. };
  83. /**
  84. * snd_soc_acpi_endpoint - endpoint descriptor
  85. * @num: endpoint number (mandatory, unique per device)
  86. * @aggregated: 0 (independent) or 1 (logically grouped)
  87. * @group_position: zero-based order (only when @aggregated is 1)
  88. * @group_id: platform-unique group identifier (only when @aggregrated is 1)
  89. */
  90. struct snd_soc_acpi_endpoint {
  91. u8 num;
  92. u8 aggregated;
  93. u8 group_position;
  94. u8 group_id;
  95. };
  96. /**
  97. * snd_soc_acpi_adr_device - descriptor for _ADR-enumerated device
  98. * @adr: 64 bit ACPI _ADR value
  99. * @num_endpoints: number of endpoints for this device
  100. * @endpoints: array of endpoints
  101. * @name_prefix: string used for codec controls
  102. */
  103. struct snd_soc_acpi_adr_device {
  104. u64 adr;
  105. u8 num_endpoints;
  106. const struct snd_soc_acpi_endpoint *endpoints;
  107. const char *name_prefix;
  108. };
  109. /**
  110. * snd_soc_acpi_link_adr - ACPI-based list of _ADR enumerated devices
  111. * @mask: one bit set indicates the link this list applies to
  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.
  117. */
  118. struct snd_soc_acpi_link_adr {
  119. u32 mask;
  120. u32 num_adr;
  121. const struct snd_soc_acpi_adr_device *adr_d;
  122. };
  123. /*
  124. * when set the topology uses the -ssp<N> suffix, where N is determined based on
  125. * BIOS or DMI information
  126. */
  127. #define SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER BIT(0)
  128. /*
  129. * when more than one SSP is reported in the link mask, use the most significant.
  130. * This choice was found to be valid on platforms with ES8336 codecs.
  131. */
  132. #define SND_SOC_ACPI_TPLG_INTEL_SSP_MSB BIT(1)
  133. /*
  134. * when set the topology uses the -dmic<N>ch suffix, where N is determined based on
  135. * BIOS or DMI information
  136. */
  137. #define SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER BIT(2)
  138. /*
  139. * when set the speaker amplifier name suffix (i.e. "-max98360a") will be
  140. * appended to topology file name
  141. */
  142. #define SND_SOC_ACPI_TPLG_INTEL_AMP_NAME BIT(3)
  143. /*
  144. * when set the headphone codec name suffix (i.e. "-rt5682") will be appended to
  145. * topology file name
  146. */
  147. #define SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME BIT(4)
  148. /**
  149. * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
  150. * related to the hardware, except for the firmware and topology file names.
  151. * A platform supported by legacy and Sound Open Firmware (SOF) would expose
  152. * all firmware/topology related fields.
  153. *
  154. * @id: ACPI ID (usually the codec's) used to find a matching machine driver.
  155. * @uid: ACPI Unique ID, can be used to disambiguate matches.
  156. * @comp_ids: list of compatible audio codecs using the same machine driver,
  157. * firmware and topology
  158. * @link_mask: describes required board layout, e.g. for SoundWire.
  159. * @links: array of link _ADR descriptors, null terminated.
  160. * @drv_name: machine driver name
  161. * @fw_filename: firmware file name. Used when SOF is not enabled.
  162. * @tplg_filename: topology file name. Used when SOF is not enabled.
  163. * @board: board name
  164. * @machine_quirk: pointer to quirk, usually based on DMI information when
  165. * ACPI ID alone is not sufficient, wrong or misleading
  166. * @quirk_data: data used to uniquely identify a machine, usually a list of
  167. * audio codecs whose presence if checked with ACPI
  168. * @machine_check: pointer to quirk function. The functionality is similar to
  169. * the use of @machine_quirk, except that the return value is a boolean: the intent
  170. * is to skip a machine if the additional hardware/firmware verification invalidates
  171. * the initial selection in the snd_soc_acpi_mach table.
  172. * @pdata: intended for platform data or machine specific-ops. This structure
  173. * is not constant since this field may be updated at run-time
  174. * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
  175. * @tplg_quirk_mask: quirks to select different topology files dynamically
  176. * @get_function_tplg_files: This is an optional callback, if specified then instead of
  177. * the single sof_tplg_filename the callback will return the list of function topology
  178. * files to be loaded.
  179. * Return value: The number of the files or negative ERRNO. 0 means that the single topology
  180. * file should be used, no function topology split can be used on the machine.
  181. * @card: the pointer of the card
  182. * @mach: the pointer of the machine driver
  183. * @prefix: the prefix of the topology file name. Typically, it is the path.
  184. * @tplg_files: the pointer of the array of the topology file names.
  185. * @best_effort: ignore non supported links and try to build the card in best effort
  186. * with supported links
  187. */
  188. /* Descriptor for SST ASoC machine driver */
  189. struct snd_soc_acpi_mach {
  190. u8 id[ACPI_ID_LEN];
  191. const char *uid;
  192. const struct snd_soc_acpi_codecs *comp_ids;
  193. const u32 link_mask;
  194. const struct snd_soc_acpi_link_adr *links;
  195. const char *drv_name;
  196. const char *fw_filename;
  197. const char *tplg_filename;
  198. const char *board;
  199. struct snd_soc_acpi_mach * (*machine_quirk)(void *arg);
  200. const void *quirk_data;
  201. bool (*machine_check)(void *arg);
  202. void *pdata;
  203. struct snd_soc_acpi_mach_params mach_params;
  204. const char *sof_tplg_filename;
  205. const u32 tplg_quirk_mask;
  206. int (*get_function_tplg_files)(struct snd_soc_card *card,
  207. const struct snd_soc_acpi_mach *mach,
  208. const char *prefix, const char ***tplg_files,
  209. bool best_effort);
  210. };
  211. #define SND_SOC_ACPI_MAX_CODECS 3
  212. /**
  213. * struct snd_soc_acpi_codecs: Structure to hold secondary codec information
  214. * apart from the matched one, this data will be passed to the quirk function
  215. * to match with the ACPI detected devices
  216. *
  217. * @num_codecs: number of secondary codecs used in the platform
  218. * @codecs: holds the codec IDs
  219. *
  220. */
  221. struct snd_soc_acpi_codecs {
  222. int num_codecs;
  223. u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN];
  224. };
  225. static inline bool snd_soc_acpi_sof_parent(struct device *dev)
  226. {
  227. return dev->parent && dev->parent->driver && dev->parent->driver->name &&
  228. !strncmp(dev->parent->driver->name, "sof-audio-acpi", strlen("sof-audio-acpi"));
  229. }
  230. bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev,
  231. const struct snd_soc_acpi_link_adr *link,
  232. struct sdw_peripherals *peripherals);
  233. #endif