| 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 |
|
| 8 |
#include <linux/firmware.h> |
| 9 |
#include <linux/module.h> |
| 10 |
#include <linux/moduleparam.h> |
| 11 |
#include <linux/pm_runtime.h> |
| 12 |
#include <sound/sof.h> |
| 13 |
|
| 14 |
#include "sof-of-dev.h" |
| 15 |
#include "ops.h" |
| 16 |
|
| 17 |
static char *fw_path; |
| 18 |
module_param(fw_path, charp, 0444); |
| 19 |
MODULE_PARM_DESC(fw_path, "deprecated - moved to snd-sof module."); |
| 20 |
|
| 21 |
static char *fw_filename; |
| 22 |
module_param(fw_filename, charp, 0444); |
| 23 |
MODULE_PARM_DESC(fw_filename, "deprecated - moved to snd-sof module."); |
| 24 |
|
| 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 |
|
| 29 |
static char *tplg_filename; |
| 30 |
module_param(tplg_filename, charp, 0444); |
| 31 |
MODULE_PARM_DESC(tplg_filename, "deprecated - moved to snd-sof module."); |
| 32 |
|
| 33 |
EXPORT_DEV_PM_OPS(sof_of_pm) = { |
| 34 |
.prepare = snd_sof_prepare, |
| 35 |
.complete = snd_sof_complete, |
| 36 |
SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) |
| 37 |
RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, NULL) |
| 38 |
}; |
| 39 |
|
| 40 |
static void sof_of_probe_complete(struct device *dev) |
| 41 |
{ |
| 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_mark_last_busy(dev); |
| 46 |
pm_runtime_set_active(dev); |
| 47 |
pm_runtime_enable(dev); |
| 48 |
} |
| 49 |
|
| 50 |
int sof_of_probe(struct platform_device *pdev) |
| 51 |
{ |
| 52 |
struct device *dev = &pdev->dev; |
| 53 |
const struct sof_dev_desc *desc; |
| 54 |
struct snd_sof_pdata *sof_pdata; |
| 55 |
|
| 56 |
dev_info(&pdev->dev, "DT DSP detected"); |
| 57 |
|
| 58 |
sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); |
| 59 |
if (!sof_pdata) |
| 60 |
return -ENOMEM; |
| 61 |
|
| 62 |
desc = device_get_match_data(dev); |
| 63 |
if (!desc) |
| 64 |
return -ENODEV; |
| 65 |
|
| 66 |
if (!desc->ops) { |
| 67 |
dev_err(dev, "error: no matching DT descriptor ops\n"); |
| 68 |
return -ENODEV; |
| 69 |
} |
| 70 |
|
| 71 |
sof_pdata->desc = desc; |
| 72 |
sof_pdata->dev = &pdev->dev; |
| 73 |
|
| 74 |
sof_pdata->ipc_file_profile_base.ipc_type = desc->ipc_default; |
| 75 |
sof_pdata->ipc_file_profile_base.fw_path = fw_path; |
| 76 |
sof_pdata->ipc_file_profile_base.tplg_path = tplg_path; |
| 77 |
sof_pdata->ipc_file_profile_base.fw_name = fw_filename; |
| 78 |
sof_pdata->ipc_file_profile_base.tplg_name = tplg_filename; |
| 79 |
|
| 80 |
/* set callback to be called on successful device probe to enable runtime_pm */ |
| 81 |
sof_pdata->sof_probe_complete = sof_of_probe_complete; |
| 82 |
|
| 83 |
/* call sof helper for DSP hardware probe */ |
| 84 |
return snd_sof_device_probe(dev, sof_pdata); |
| 85 |
} |
| 86 |
EXPORT_SYMBOL(sof_of_probe); |
| 87 |
|
| 88 |
void sof_of_remove(struct platform_device *pdev) |
| 89 |
{ |
| 90 |
pm_runtime_disable(&pdev->dev); |
| 91 |
|
| 92 |
/* call sof helper for DSP hardware remove */ |
| 93 |
snd_sof_device_remove(&pdev->dev); |
| 94 |
} |
| 95 |
EXPORT_SYMBOL(sof_of_remove); |
| 96 |
|
| 97 |
void sof_of_shutdown(struct platform_device *pdev) |
| 98 |
{ |
| 99 |
snd_sof_device_shutdown(&pdev->dev); |
| 100 |
} |
| 101 |
EXPORT_SYMBOL(sof_of_shutdown); |
| 102 |
|
| 103 |
MODULE_LICENSE("Dual BSD/GPL"); |
| 104 |
MODULE_DESCRIPTION("SOF support for OF/DT platforms"); |