soc-acpi.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (C) 2013-15, Intel Corporation. All rights reserved.
  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. struct snd_soc_acpi_package_context {
  11. char *name; /* package name */
  12. int length; /* number of elements */
  13. struct acpi_buffer *format;
  14. struct acpi_buffer *state;
  15. bool data_valid;
  16. };
  17. /* codec name is used in DAIs is i2c-<HID>:00 with HID being 8 chars */
  18. #define SND_ACPI_I2C_ID_LEN (4 + ACPI_ID_LEN + 3 + 1)
  19. #if IS_ENABLED(CONFIG_ACPI)
  20. /* acpi match */
  21. struct snd_soc_acpi_mach *
  22. snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines);
  23. bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
  24. struct snd_soc_acpi_package_context *ctx);
  25. /* check all codecs */
  26. struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg);
  27. #else
  28. /* acpi match */
  29. static inline struct snd_soc_acpi_mach *
  30. snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
  31. {
  32. return NULL;
  33. }
  34. static inline bool
  35. snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
  36. struct snd_soc_acpi_package_context *ctx)
  37. {
  38. return false;
  39. }
  40. /* check all codecs */
  41. static inline struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
  42. {
  43. return NULL;
  44. }
  45. #endif
  46. /**
  47. * snd_soc_acpi_mach_params: interface for machine driver configuration
  48. *
  49. * @acpi_ipc_irq_index: used for BYT-CR detection
  50. * @platform: string used for HDAudio codec support
  51. * @codec_mask: used for HDAudio support
  52. * @dmic_num: number of SoC- or chipset-attached PDM digital microphones
  53. * @common_hdmi_codec_drv: use commom HDAudio HDMI codec driver
  54. * @link_mask: SoundWire links enabled on the board
  55. * @links: array of SoundWire link _ADR descriptors, null terminated
  56. * @i2s_link_mask: I2S/TDM links enabled on the board
  57. * @num_dai_drivers: number of elements in @dai_drivers
  58. * @dai_drivers: pointer to dai_drivers, used e.g. in nocodec mode
  59. * @subsystem_vendor: optional PCI SSID vendor value
  60. * @subsystem_device: optional PCI SSID device value
  61. * @subsystem_id_set: true if a value has been written to
  62. * subsystem_vendor and subsystem_device.
  63. */
  64. struct snd_soc_acpi_mach_params {
  65. u32 acpi_ipc_irq_index;
  66. const char *platform;
  67. u32 codec_mask;
  68. u32 dmic_num;
  69. bool common_hdmi_codec_drv;
  70. u32 link_mask;
  71. const struct snd_soc_acpi_link_adr *links;
  72. u32 i2s_link_mask;
  73. u32 num_dai_drivers;
  74. struct snd_soc_dai_driver *dai_drivers;
  75. unsigned short subsystem_vendor;
  76. unsigned short subsystem_device;
  77. bool subsystem_id_set;
  78. };
  79. /**
  80. * snd_soc_acpi_endpoint - endpoint descriptor
  81. * @num: endpoint number (mandatory, unique per device)
  82. * @aggregated: 0 (independent) or 1 (logically grouped)
  83. * @group_position: zero-based order (only when @aggregated is 1)
  84. * @group_id: platform-unique group identifier (only when @aggregrated is 1)
  85. */
  86. struct snd_soc_acpi_endpoint {
  87. u8 num;
  88. u8 aggregated;
  89. u8 group_position;
  90. u8 group_id;
  91. };
  92. /**
  93. * snd_soc_acpi_adr_device - descriptor for _ADR-enumerated device
  94. * @adr: 64 bit ACPI _ADR value
  95. * @num_endpoints: number of endpoints for this device
  96. * @endpoints: array of endpoints
  97. * @name_prefix: string used for codec controls
  98. */
  99. struct snd_soc_acpi_adr_device {
  100. const u64 adr;
  101. const u8 num_endpoints;
  102. const struct snd_soc_acpi_endpoint *endpoints;
  103. const char *name_prefix;
  104. };
  105. /**
  106. * snd_soc_acpi_link_adr - ACPI-based list of _ADR enumerated devices
  107. * @mask: one bit set indicates the link this list applies to
  108. * @num_adr: ARRAY_SIZE of devices
  109. * @adr_d: array of devices
  110. *
  111. * The number of devices per link can be more than 1, e.g. in SoundWire
  112. * multi-drop configurations.
  113. */
  114. struct snd_soc_acpi_link_adr {
  115. const u32 mask;
  116. const u32 num_adr;
  117. const struct snd_soc_acpi_adr_device *adr_d;
  118. };
  119. /*
  120. * when set the topology uses the -ssp<N> suffix, where N is determined based on
  121. * BIOS or DMI information
  122. */
  123. #define SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER BIT(0)
  124. /*
  125. * when more than one SSP is reported in the link mask, use the most significant.
  126. * This choice was found to be valid on platforms with ES8336 codecs.
  127. */
  128. #define SND_SOC_ACPI_TPLG_INTEL_SSP_MSB BIT(1)
  129. /*
  130. * when set the topology uses the -dmic<N>ch suffix, where N is determined based on
  131. * BIOS or DMI information
  132. */
  133. #define SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER BIT(2)
  134. /**
  135. * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
  136. * related to the hardware, except for the firmware and topology file names.
  137. * A platform supported by legacy and Sound Open Firmware (SOF) would expose
  138. * all firmware/topology related fields.
  139. *
  140. * @id: ACPI ID (usually the codec's) used to find a matching machine driver.
  141. * @comp_ids: list of compatible audio codecs using the same machine driver,
  142. * firmware and topology
  143. * @link_mask: describes required board layout, e.g. for SoundWire.
  144. * @links: array of link _ADR descriptors, null terminated.
  145. * @drv_name: machine driver name
  146. * @fw_filename: firmware file name. Used when SOF is not enabled.
  147. * @tplg_filename: topology file name. Used when SOF is not enabled.
  148. * @board: board name
  149. * @machine_quirk: pointer to quirk, usually based on DMI information when
  150. * ACPI ID alone is not sufficient, wrong or misleading
  151. * @quirk_data: data used to uniquely identify a machine, usually a list of
  152. * audio codecs whose presence if checked with ACPI
  153. * @pdata: intended for platform data or machine specific-ops. This structure
  154. * is not constant since this field may be updated at run-time
  155. * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
  156. * @tplg_quirk_mask: quirks to select different topology files dynamically
  157. */
  158. /* Descriptor for SST ASoC machine driver */
  159. struct snd_soc_acpi_mach {
  160. u8 id[ACPI_ID_LEN];
  161. const char *uid;
  162. const struct snd_soc_acpi_codecs *comp_ids;
  163. const u32 link_mask;
  164. const struct snd_soc_acpi_link_adr *links;
  165. const char *drv_name;
  166. const char *fw_filename;
  167. const char *tplg_filename;
  168. const char *board;
  169. struct snd_soc_acpi_mach * (*machine_quirk)(void *arg);
  170. const void *quirk_data;
  171. void *pdata;
  172. struct snd_soc_acpi_mach_params mach_params;
  173. const char *sof_tplg_filename;
  174. const u32 tplg_quirk_mask;
  175. };
  176. #define SND_SOC_ACPI_MAX_CODECS 3
  177. /**
  178. * struct snd_soc_acpi_codecs: Structure to hold secondary codec information
  179. * apart from the matched one, this data will be passed to the quirk function
  180. * to match with the ACPI detected devices
  181. *
  182. * @num_codecs: number of secondary codecs used in the platform
  183. * @codecs: holds the codec IDs
  184. *
  185. */
  186. struct snd_soc_acpi_codecs {
  187. int num_codecs;
  188. u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN];
  189. };
  190. static inline bool snd_soc_acpi_sof_parent(struct device *dev)
  191. {
  192. return dev->parent && dev->parent->driver && dev->parent->driver->name &&
  193. !strncmp(dev->parent->driver->name, "sof-audio-acpi", strlen("sof-audio-acpi"));
  194. }
  195. #endif