sof-acpi-dev.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. All rights reserved.
  7. //
  8. // Author: Liam Girdwood <[email protected]>
  9. //
  10. #include <linux/acpi.h>
  11. #include <linux/firmware.h>
  12. #include <linux/module.h>
  13. #include <linux/pm_runtime.h>
  14. #include <sound/soc-acpi.h>
  15. #include <sound/soc-acpi-intel-match.h>
  16. #include <sound/sof.h>
  17. #include "../intel/common/soc-intel-quirks.h"
  18. #include "ops.h"
  19. #include "sof-acpi-dev.h"
  20. /* platform specific devices */
  21. #include "intel/shim.h"
  22. static char *fw_path;
  23. module_param(fw_path, charp, 0444);
  24. MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
  25. static char *tplg_path;
  26. module_param(tplg_path, charp, 0444);
  27. MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
  28. static int sof_acpi_debug;
  29. module_param_named(sof_acpi_debug, sof_acpi_debug, int, 0444);
  30. MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI debug options (0x0 all off)");
  31. #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
  32. const struct dev_pm_ops sof_acpi_pm = {
  33. SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
  34. SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
  35. snd_sof_runtime_idle)
  36. };
  37. EXPORT_SYMBOL_NS(sof_acpi_pm, SND_SOC_SOF_ACPI_DEV);
  38. static void sof_acpi_probe_complete(struct device *dev)
  39. {
  40. dev_dbg(dev, "Completing SOF ACPI probe");
  41. if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
  42. return;
  43. /* allow runtime_pm */
  44. pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
  45. pm_runtime_use_autosuspend(dev);
  46. pm_runtime_enable(dev);
  47. }
  48. int sof_acpi_probe(struct platform_device *pdev, const struct sof_dev_desc *desc)
  49. {
  50. struct device *dev = &pdev->dev;
  51. struct snd_sof_pdata *sof_pdata;
  52. dev_dbg(dev, "ACPI DSP detected");
  53. sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
  54. if (!sof_pdata)
  55. return -ENOMEM;
  56. if (!desc->ops) {
  57. dev_err(dev, "error: no matching ACPI descriptor ops\n");
  58. return -ENODEV;
  59. }
  60. sof_pdata->desc = desc;
  61. sof_pdata->dev = &pdev->dev;
  62. sof_pdata->fw_filename = desc->default_fw_filename[SOF_IPC];
  63. /* alternate fw and tplg filenames ? */
  64. if (fw_path)
  65. sof_pdata->fw_filename_prefix = fw_path;
  66. else
  67. sof_pdata->fw_filename_prefix =
  68. sof_pdata->desc->default_fw_path[SOF_IPC];
  69. if (tplg_path)
  70. sof_pdata->tplg_filename_prefix = tplg_path;
  71. else
  72. sof_pdata->tplg_filename_prefix =
  73. sof_pdata->desc->default_tplg_path[SOF_IPC];
  74. /* set callback to be called on successful device probe to enable runtime_pm */
  75. sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
  76. /* call sof helper for DSP hardware probe */
  77. return snd_sof_device_probe(dev, sof_pdata);
  78. }
  79. EXPORT_SYMBOL_NS(sof_acpi_probe, SND_SOC_SOF_ACPI_DEV);
  80. int sof_acpi_remove(struct platform_device *pdev)
  81. {
  82. struct device *dev = &pdev->dev;
  83. if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
  84. pm_runtime_disable(dev);
  85. /* call sof helper for DSP hardware remove */
  86. snd_sof_device_remove(dev);
  87. return 0;
  88. }
  89. EXPORT_SYMBOL_NS(sof_acpi_remove, SND_SOC_SOF_ACPI_DEV);
  90. MODULE_LICENSE("Dual BSD/GPL");