sof-of-dev.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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, "deprecated - moved to snd-sof module.");
  17. static char *fw_filename;
  18. module_param(fw_filename, charp, 0444);
  19. MODULE_PARM_DESC(fw_filename, "deprecated - moved to snd-sof module.");
  20. static char *tplg_path;
  21. module_param(tplg_path, charp, 0444);
  22. MODULE_PARM_DESC(tplg_path, "deprecated - moved to snd-sof module.");
  23. static char *tplg_filename;
  24. module_param(tplg_filename, charp, 0444);
  25. MODULE_PARM_DESC(tplg_filename, "deprecated - moved to snd-sof module.");
  26. EXPORT_DEV_PM_OPS(sof_of_pm) = {
  27. .prepare = snd_sof_prepare,
  28. .complete = snd_sof_complete,
  29. SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
  30. RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, NULL)
  31. };
  32. static void sof_of_probe_complete(struct device *dev)
  33. {
  34. /* allow runtime_pm */
  35. pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
  36. pm_runtime_use_autosuspend(dev);
  37. pm_runtime_mark_last_busy(dev);
  38. pm_runtime_set_active(dev);
  39. pm_runtime_enable(dev);
  40. }
  41. int sof_of_probe(struct platform_device *pdev)
  42. {
  43. struct device *dev = &pdev->dev;
  44. const struct sof_dev_desc *desc;
  45. struct snd_sof_pdata *sof_pdata;
  46. dev_info(&pdev->dev, "DT DSP detected");
  47. sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
  48. if (!sof_pdata)
  49. return -ENOMEM;
  50. desc = device_get_match_data(dev);
  51. if (!desc)
  52. return -ENODEV;
  53. if (!desc->ops) {
  54. dev_err(dev, "error: no matching DT descriptor ops\n");
  55. return -ENODEV;
  56. }
  57. sof_pdata->desc = desc;
  58. sof_pdata->dev = &pdev->dev;
  59. sof_pdata->ipc_file_profile_base.ipc_type = desc->ipc_default;
  60. sof_pdata->ipc_file_profile_base.fw_path = fw_path;
  61. sof_pdata->ipc_file_profile_base.tplg_path = tplg_path;
  62. sof_pdata->ipc_file_profile_base.fw_name = fw_filename;
  63. sof_pdata->ipc_file_profile_base.tplg_name = tplg_filename;
  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. void 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. }
  76. EXPORT_SYMBOL(sof_of_remove);
  77. void sof_of_shutdown(struct platform_device *pdev)
  78. {
  79. snd_sof_device_shutdown(&pdev->dev);
  80. }
  81. EXPORT_SYMBOL(sof_of_shutdown);
  82. MODULE_LICENSE("Dual BSD/GPL");
  83. MODULE_DESCRIPTION("SOF support for OF/DT platforms");