sof-acpi-dev.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/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, "deprecated - moved to snd-sof module.");
  25. static char *tplg_path;
  26. module_param(tplg_path, charp, 0444);
  27. MODULE_PARM_DESC(tplg_path, "deprecated - moved to snd-sof module.");
  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. EXPORT_NS_DEV_PM_OPS(sof_acpi_pm, SND_SOC_SOF_ACPI_DEV) = {
  33. SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
  34. RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
  35. snd_sof_runtime_idle)
  36. };
  37. static void sof_acpi_probe_complete(struct device *dev)
  38. {
  39. dev_dbg(dev, "Completing SOF ACPI probe");
  40. if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
  41. return;
  42. /* allow runtime_pm */
  43. pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
  44. pm_runtime_use_autosuspend(dev);
  45. pm_runtime_enable(dev);
  46. }
  47. int sof_acpi_probe(struct platform_device *pdev, const struct sof_dev_desc *desc)
  48. {
  49. struct device *dev = &pdev->dev;
  50. struct snd_sof_pdata *sof_pdata;
  51. dev_dbg(dev, "ACPI DSP detected");
  52. sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
  53. if (!sof_pdata)
  54. return -ENOMEM;
  55. if (!desc->ops) {
  56. dev_err(dev, "error: no matching ACPI descriptor ops\n");
  57. return -ENODEV;
  58. }
  59. sof_pdata->desc = desc;
  60. sof_pdata->dev = &pdev->dev;
  61. sof_pdata->ipc_file_profile_base.ipc_type = desc->ipc_default;
  62. sof_pdata->ipc_file_profile_base.fw_path = fw_path;
  63. sof_pdata->ipc_file_profile_base.tplg_path = tplg_path;
  64. /* set callback to be called on successful device probe to enable runtime_pm */
  65. sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
  66. /* call sof helper for DSP hardware probe */
  67. return snd_sof_device_probe(dev, sof_pdata);
  68. }
  69. EXPORT_SYMBOL_NS(sof_acpi_probe, "SND_SOC_SOF_ACPI_DEV");
  70. void sof_acpi_remove(struct platform_device *pdev)
  71. {
  72. struct device *dev = &pdev->dev;
  73. if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
  74. pm_runtime_disable(dev);
  75. /* call sof helper for DSP hardware remove */
  76. snd_sof_device_remove(dev);
  77. }
  78. EXPORT_SYMBOL_NS(sof_acpi_remove, "SND_SOC_SOF_ACPI_DEV");
  79. MODULE_LICENSE("Dual BSD/GPL");
  80. MODULE_DESCRIPTION("SOF support for ACPI platforms");