sof-pci-dev.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // This file is provided under a dual BSD/GPLv2 license. When using or
  4. // redistributing this file, you may do so under either license.
  5. //
  6. // Copyright(c) 2018 Intel Corporation
  7. //
  8. // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
  9. //
  10. #include <linux/firmware.h>
  11. #include <linux/dmi.h>
  12. #include <linux/module.h>
  13. #include <linux/pci.h>
  14. #include <linux/platform_data/x86/soc.h>
  15. #include <linux/pm_runtime.h>
  16. #include <sound/soc-acpi.h>
  17. #include <sound/soc-acpi-intel-match.h>
  18. #include <sound/sof.h>
  19. #include "ops.h"
  20. #include "sof-pci-dev.h"
  21. static char *fw_path;
  22. module_param(fw_path, charp, 0444);
  23. MODULE_PARM_DESC(fw_path, "deprecated - moved to snd-sof module.");
  24. static char *fw_filename;
  25. module_param(fw_filename, charp, 0444);
  26. MODULE_PARM_DESC(fw_filename, "deprecated - moved to snd-sof module.");
  27. static char *lib_path;
  28. module_param(lib_path, charp, 0444);
  29. MODULE_PARM_DESC(lib_path, "deprecated - moved to snd-sof module.");
  30. static char *tplg_path;
  31. module_param(tplg_path, charp, 0444);
  32. MODULE_PARM_DESC(tplg_path, "deprecated - moved to snd-sof module.");
  33. static char *tplg_filename;
  34. module_param(tplg_filename, charp, 0444);
  35. MODULE_PARM_DESC(tplg_filename, "deprecated - moved to snd-sof module.");
  36. static int sof_pci_debug;
  37. module_param_named(sof_pci_debug, sof_pci_debug, int, 0444);
  38. MODULE_PARM_DESC(sof_pci_debug, "SOF PCI debug options (0x0 all off)");
  39. static int sof_pci_ipc_type = -1;
  40. module_param_named(ipc_type, sof_pci_ipc_type, int, 0444);
  41. MODULE_PARM_DESC(ipc_type, "deprecated - moved to snd-sof module.");
  42. static const char *sof_dmi_override_tplg_name;
  43. static bool sof_dmi_use_community_key;
  44. #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
  45. static int sof_tplg_cb(const struct dmi_system_id *id)
  46. {
  47. sof_dmi_override_tplg_name = id->driver_data;
  48. return 1;
  49. }
  50. static const struct dmi_system_id sof_tplg_table[] = {
  51. {
  52. .callback = sof_tplg_cb,
  53. .matches = {
  54. DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
  55. DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
  56. },
  57. .driver_data = "sof-tgl-rt5682-ssp0-max98373-ssp2.tplg",
  58. },
  59. {
  60. .callback = sof_tplg_cb,
  61. .matches = {
  62. DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
  63. DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
  64. DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
  65. },
  66. .driver_data = "sof-adl-rt5682-ssp0-max98373-ssp2.tplg",
  67. },
  68. {
  69. .callback = sof_tplg_cb,
  70. .matches = {
  71. DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
  72. DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
  73. },
  74. .driver_data = "sof-adl-max98390-ssp2-rt5682-ssp0.tplg",
  75. },
  76. {
  77. .callback = sof_tplg_cb,
  78. .matches = {
  79. DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
  80. DMI_MATCH(DMI_OEM_STRING, "AUDIO_AMP-MAX98360_ALC5682VS_I2S_2WAY"),
  81. },
  82. .driver_data = "sof-adl-max98360a-rt5682-2way.tplg",
  83. },
  84. {
  85. .callback = sof_tplg_cb,
  86. .matches = {
  87. DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
  88. DMI_MATCH(DMI_OEM_STRING, "AUDIO-AUDIO_MAX98357_ALC5682I_I2S_2WAY"),
  89. },
  90. .driver_data = "sof-adl-max98357a-rt5682-2way.tplg",
  91. },
  92. {
  93. .callback = sof_tplg_cb,
  94. .matches = {
  95. DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
  96. DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
  97. },
  98. .driver_data = "sof-adl-max98357a-rt5682.tplg",
  99. },
  100. {}
  101. };
  102. /* all Up boards use the community key */
  103. static int up_use_community_key(const struct dmi_system_id *id)
  104. {
  105. sof_dmi_use_community_key = true;
  106. return 1;
  107. }
  108. /*
  109. * For ApolloLake Chromebooks we want to force the use of the Intel production key.
  110. * All newer platforms use the community key
  111. */
  112. static int chromebook_use_community_key(const struct dmi_system_id *id)
  113. {
  114. if (!soc_intel_is_apl())
  115. sof_dmi_use_community_key = true;
  116. return 1;
  117. }
  118. static const struct dmi_system_id community_key_platforms[] = {
  119. {
  120. .ident = "Up boards",
  121. .callback = up_use_community_key,
  122. .matches = {
  123. DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
  124. }
  125. },
  126. {
  127. .ident = "Google Chromebooks",
  128. .callback = chromebook_use_community_key,
  129. .matches = {
  130. DMI_MATCH(DMI_PRODUCT_FAMILY, "Google"),
  131. }
  132. },
  133. {
  134. .ident = "Google firmware",
  135. .callback = chromebook_use_community_key,
  136. .matches = {
  137. DMI_MATCH(DMI_BIOS_VERSION, "Google"),
  138. }
  139. },
  140. {},
  141. };
  142. EXPORT_NS_DEV_PM_OPS(sof_pci_pm, SND_SOC_SOF_PCI_DEV) = {
  143. .prepare = snd_sof_prepare,
  144. .complete = snd_sof_complete,
  145. SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
  146. RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
  147. snd_sof_runtime_idle)
  148. };
  149. static void sof_pci_probe_complete(struct device *dev)
  150. {
  151. dev_dbg(dev, "Completing SOF PCI probe");
  152. if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
  153. return;
  154. /* allow runtime_pm */
  155. pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
  156. pm_runtime_use_autosuspend(dev);
  157. /*
  158. * runtime pm for pci device is "forbidden" by default.
  159. * so call pm_runtime_allow() to enable it.
  160. */
  161. pm_runtime_allow(dev);
  162. /* mark last_busy for pm_runtime to make sure not suspend immediately */
  163. pm_runtime_mark_last_busy(dev);
  164. /* follow recommendation in pci-driver.c to decrement usage counter */
  165. pm_runtime_put_noidle(dev);
  166. }
  167. int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  168. {
  169. struct sof_loadable_file_profile *path_override;
  170. struct device *dev = &pci->dev;
  171. const struct sof_dev_desc *desc =
  172. (const struct sof_dev_desc *)pci_id->driver_data;
  173. struct snd_sof_pdata *sof_pdata;
  174. int ret;
  175. dev_dbg(&pci->dev, "PCI DSP detected");
  176. if (!desc) {
  177. dev_err(dev, "error: no matching PCI descriptor\n");
  178. return -ENODEV;
  179. }
  180. if (!desc->ops) {
  181. dev_err(dev, "error: no matching PCI descriptor ops\n");
  182. return -ENODEV;
  183. }
  184. sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
  185. if (!sof_pdata)
  186. return -ENOMEM;
  187. ret = pcim_enable_device(pci);
  188. if (ret < 0)
  189. return ret;
  190. ret = pcim_request_all_regions(pci, "Audio DSP");
  191. if (ret < 0)
  192. return ret;
  193. sof_pdata->name = pci_name(pci);
  194. /* PCI defines a vendor ID of 0xFFFF as invalid. */
  195. if (pci->subsystem_vendor != 0xFFFF) {
  196. sof_pdata->subsystem_vendor = pci->subsystem_vendor;
  197. sof_pdata->subsystem_device = pci->subsystem_device;
  198. sof_pdata->subsystem_id_set = true;
  199. }
  200. sof_pdata->desc = desc;
  201. sof_pdata->dev = dev;
  202. path_override = &sof_pdata->ipc_file_profile_base;
  203. if (sof_pci_ipc_type < 0) {
  204. path_override->ipc_type = desc->ipc_default;
  205. } else if (sof_pci_ipc_type < SOF_IPC_TYPE_COUNT) {
  206. path_override->ipc_type = sof_pci_ipc_type;
  207. } else {
  208. dev_err(dev, "Invalid IPC type requested: %d\n", sof_pci_ipc_type);
  209. return -EINVAL;
  210. }
  211. path_override->fw_path = fw_path;
  212. path_override->fw_name = fw_filename;
  213. path_override->fw_lib_path = lib_path;
  214. path_override->tplg_path = tplg_path;
  215. if (dmi_check_system(community_key_platforms) &&
  216. sof_dmi_use_community_key) {
  217. path_override->fw_path_postfix = "community";
  218. path_override->fw_lib_path_postfix = "community";
  219. }
  220. /*
  221. * the topology filename will be provided in the machine descriptor, unless
  222. * it is overridden by a module parameter or DMI quirk.
  223. */
  224. if (tplg_filename) {
  225. path_override->tplg_name = tplg_filename;
  226. } else {
  227. dmi_check_system(sof_tplg_table);
  228. if (sof_dmi_override_tplg_name)
  229. path_override->tplg_name = sof_dmi_override_tplg_name;
  230. }
  231. /* set callback to be called on successful device probe to enable runtime_pm */
  232. sof_pdata->sof_probe_complete = sof_pci_probe_complete;
  233. /* call sof helper for DSP hardware probe */
  234. return snd_sof_device_probe(dev, sof_pdata);
  235. }
  236. EXPORT_SYMBOL_NS(sof_pci_probe, "SND_SOC_SOF_PCI_DEV");
  237. void sof_pci_remove(struct pci_dev *pci)
  238. {
  239. /* call sof helper for DSP hardware remove */
  240. snd_sof_device_remove(&pci->dev);
  241. /* follow recommendation in pci-driver.c to increment usage counter */
  242. if (snd_sof_device_probe_completed(&pci->dev) &&
  243. !(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
  244. pm_runtime_get_noresume(&pci->dev);
  245. }
  246. EXPORT_SYMBOL_NS(sof_pci_remove, "SND_SOC_SOF_PCI_DEV");
  247. void sof_pci_shutdown(struct pci_dev *pci)
  248. {
  249. snd_sof_device_shutdown(&pci->dev);
  250. }
  251. EXPORT_SYMBOL_NS(sof_pci_shutdown, "SND_SOC_SOF_PCI_DEV");
  252. MODULE_LICENSE("Dual BSD/GPL");
  253. MODULE_DESCRIPTION("SOF support for PCI platforms");