sof-of-dev.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // Copyright 2019 NXP
  4. //
  5. // Author: Daniel Baluta <daniel.baluta@nxp.com>
  6. //
  7. #include <linux/firmware.h>
  8. #include <linux/module.h>
  9. #include <linux/moduleparam.h>
  10. #include <linux/pm_runtime.h>
  11. #include <sound/sof.h>
  12. #include "sof-of-dev.h"
  13. #include "ops.h"
  14. static char *fw_path;
  15. module_param(fw_path, charp, 0444);
  16. MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
  17. static char *tplg_path;
  18. module_param(tplg_path, charp, 0444);
  19. MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
  20. const struct dev_pm_ops sof_of_pm = {
  21. .prepare = snd_sof_prepare,
  22. .complete = snd_sof_complete,
  23. SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
  24. SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
  25. NULL)
  26. };
  27. EXPORT_SYMBOL(sof_of_pm);
  28. static void sof_of_probe_complete(struct device *dev)
  29. {
  30. /* allow runtime_pm */
  31. pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
  32. pm_runtime_use_autosuspend(dev);
  33. pm_runtime_mark_last_busy(dev);
  34. pm_runtime_set_active(dev);
  35. pm_runtime_enable(dev);
  36. }
  37. int sof_of_probe(struct platform_device *pdev)
  38. {
  39. struct device *dev = &pdev->dev;
  40. const struct sof_dev_desc *desc;
  41. struct snd_sof_pdata *sof_pdata;
  42. dev_info(&pdev->dev, "DT DSP detected");
  43. sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
  44. if (!sof_pdata)
  45. return -ENOMEM;
  46. desc = device_get_match_data(dev);
  47. if (!desc)
  48. return -ENODEV;
  49. if (!desc->ops) {
  50. dev_err(dev, "error: no matching DT descriptor ops\n");
  51. return -ENODEV;
  52. }
  53. sof_pdata->desc = desc;
  54. sof_pdata->dev = &pdev->dev;
  55. sof_pdata->ipc_file_profile_base.ipc_type = desc->ipc_default;
  56. sof_pdata->ipc_file_profile_base.fw_path = fw_path;
  57. sof_pdata->ipc_file_profile_base.tplg_path = tplg_path;
  58. /* set callback to be called on successful device probe to enable runtime_pm */
  59. sof_pdata->sof_probe_complete = sof_of_probe_complete;
  60. /* call sof helper for DSP hardware probe */
  61. return snd_sof_device_probe(dev, sof_pdata);
  62. }
  63. EXPORT_SYMBOL(sof_of_probe);
  64. void sof_of_remove(struct platform_device *pdev)
  65. {
  66. pm_runtime_disable(&pdev->dev);
  67. /* call sof helper for DSP hardware remove */
  68. snd_sof_device_remove(&pdev->dev);
  69. }
  70. EXPORT_SYMBOL(sof_of_remove);
  71. void sof_of_shutdown(struct platform_device *pdev)
  72. {
  73. snd_sof_device_shutdown(&pdev->dev);
  74. }
  75. EXPORT_SYMBOL(sof_of_shutdown);
  76. MODULE_LICENSE("Dual BSD/GPL");
  77. MODULE_DESCRIPTION("SOF support for OF/DT platforms");