sof-of-dev.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // Copyright 2019 NXP
  4. //
  5. // Author: Daniel Baluta <[email protected]>
  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->fw_filename = desc->default_fw_filename[SOF_IPC];
  56. if (fw_path)
  57. sof_pdata->fw_filename_prefix = fw_path;
  58. else
  59. sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path[SOF_IPC];
  60. if (tplg_path)
  61. sof_pdata->tplg_filename_prefix = tplg_path;
  62. else
  63. sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path[SOF_IPC];
  64. /* set callback to be called on successful device probe to enable runtime_pm */
  65. sof_pdata->sof_probe_complete = sof_of_probe_complete;
  66. /* call sof helper for DSP hardware probe */
  67. return snd_sof_device_probe(dev, sof_pdata);
  68. }
  69. EXPORT_SYMBOL(sof_of_probe);
  70. int sof_of_remove(struct platform_device *pdev)
  71. {
  72. pm_runtime_disable(&pdev->dev);
  73. /* call sof helper for DSP hardware remove */
  74. snd_sof_device_remove(&pdev->dev);
  75. return 0;
  76. }
  77. EXPORT_SYMBOL(sof_of_remove);
  78. void sof_of_shutdown(struct platform_device *pdev)
  79. {
  80. snd_sof_device_shutdown(&pdev->dev);
  81. }
  82. EXPORT_SYMBOL(sof_of_shutdown);
  83. MODULE_LICENSE("Dual BSD/GPL");