|
| 1 | +// SPDX-License-Identifier: (GPL-2.0 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) 2019 Intel Corporation. All rights reserved. |
| 7 | +// |
| 8 | +// Author: Ranjani Sridharan <[email protected]> |
| 9 | +// |
| 10 | + |
| 11 | +#include <linux/device.h> |
| 12 | +#include <linux/module.h> |
| 13 | +#include <linux/platform_device.h> |
| 14 | +#include <linux/pm_runtime.h> |
| 15 | +#include <sound/sof.h> |
| 16 | +#include "sof-priv.h" |
| 17 | +#include "ops.h" |
| 18 | + |
| 19 | +/* |
| 20 | + * SOF Driver enumeration. |
| 21 | + */ |
| 22 | +static int sof_machine_check(struct snd_sof_dev *sdev) |
| 23 | +{ |
| 24 | + struct snd_sof_pdata *plat_data = sdev->pdata; |
| 25 | +#if IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC) |
| 26 | + struct snd_soc_acpi_mach *machine; |
| 27 | + int ret; |
| 28 | +#endif |
| 29 | + |
| 30 | + if (plat_data->machine) |
| 31 | + return 0; |
| 32 | + |
| 33 | +#if !IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC) |
| 34 | + dev_err(sdev->dev, "error: no matching ASoC machine driver found - aborting probe\n"); |
| 35 | + return -ENODEV; |
| 36 | +#else |
| 37 | + /* fallback to nocodec mode */ |
| 38 | + dev_warn(sdev->dev, "No ASoC machine driver found - using nocodec\n"); |
| 39 | + machine = devm_kzalloc(sdev->dev, sizeof(*machine), GFP_KERNEL); |
| 40 | + if (!machine) |
| 41 | + return -ENOMEM; |
| 42 | + |
| 43 | + ret = sof_nocodec_setup(sdev->dev, plat_data, machine, |
| 44 | + plat_data->desc, plat_data->desc->ops); |
| 45 | + if (ret < 0) |
| 46 | + return ret; |
| 47 | + |
| 48 | + plat_data->machine = machine; |
| 49 | + |
| 50 | + return 0; |
| 51 | +#endif |
| 52 | +} |
| 53 | + |
| 54 | +static int sof_audio_probe(struct platform_device *pdev) |
| 55 | +{ |
| 56 | + struct snd_sof_dev *sdev = dev_get_drvdata(&pdev->dev); |
| 57 | + struct snd_sof_pdata *plat_data = sdev->pdata; |
| 58 | + struct snd_soc_acpi_mach *machine = plat_data->machine; |
| 59 | + const char *drv_name; |
| 60 | + int size; |
| 61 | + int ret; |
| 62 | + |
| 63 | + /* check machine info */ |
| 64 | + ret = sof_machine_check(sdev); |
| 65 | + if (ret < 0) { |
| 66 | + dev_err(&pdev->dev, "error: failed to get machine info %d\n", |
| 67 | + ret); |
| 68 | + goto err; |
| 69 | + } |
| 70 | + |
| 71 | + /* set platform name */ |
| 72 | + machine->mach_params.platform = dev_name(&pdev->dev); |
| 73 | + plat_data->platform = dev_name(&pdev->dev); |
| 74 | + |
| 75 | + /* set up platform component driver */ |
| 76 | + snd_sof_new_platform_drv(sdev); |
| 77 | + |
| 78 | + /* now register audio DSP platform driver and dai */ |
| 79 | + ret = devm_snd_soc_register_component(&pdev->dev, &sdev->plat_drv, |
| 80 | + sof_ops(sdev)->drv, |
| 81 | + sof_ops(sdev)->num_drv); |
| 82 | + if (ret < 0) { |
| 83 | + dev_err(&pdev->dev, |
| 84 | + "error: failed to register DSP DAI driver %d\n", ret); |
| 85 | + goto err; |
| 86 | + } |
| 87 | + |
| 88 | + drv_name = plat_data->machine->drv_name; |
| 89 | + size = sizeof(*plat_data->machine); |
| 90 | + |
| 91 | + /* register machine driver, pass machine info as pdata */ |
| 92 | + plat_data->pdev_mach = |
| 93 | + platform_device_register_data(&pdev->dev, drv_name, |
| 94 | + PLATFORM_DEVID_NONE, |
| 95 | + (const void *)machine, size); |
| 96 | + |
| 97 | + if (IS_ERR(plat_data->pdev_mach)) { |
| 98 | + ret = PTR_ERR(plat_data->pdev_mach); |
| 99 | + goto err; |
| 100 | + } |
| 101 | + |
| 102 | + dev_dbg(&pdev->dev, "created machine %s\n", |
| 103 | + dev_name(&plat_data->pdev_mach->dev)); |
| 104 | + |
| 105 | + /* enable runtime PM */ |
| 106 | + pm_runtime_set_autosuspend_delay(&pdev->dev, SND_SOF_SUSPEND_DELAY_MS); |
| 107 | + pm_runtime_use_autosuspend(&pdev->dev); |
| 108 | + |
| 109 | + pm_runtime_enable(&pdev->dev); |
| 110 | + |
| 111 | + pm_runtime_mark_last_busy(&pdev->dev); |
| 112 | + |
| 113 | + pm_runtime_put_noidle(&pdev->dev); |
| 114 | + |
| 115 | + return 0; |
| 116 | + |
| 117 | +err: |
| 118 | + snd_sof_remove(sdev); |
| 119 | + snd_sof_fw_unload(sdev); |
| 120 | + snd_sof_ipc_free(sdev); |
| 121 | + snd_sof_free_debug(sdev); |
| 122 | + return ret; |
| 123 | +} |
| 124 | + |
| 125 | +static struct platform_driver sof_audio_driver = { |
| 126 | + .driver = { |
| 127 | + .name = "sof-audio", |
| 128 | + }, |
| 129 | + |
| 130 | + .probe = sof_audio_probe, |
| 131 | +}; |
| 132 | + |
| 133 | +module_platform_driver(sof_audio_driver); |
| 134 | + |
| 135 | +MODULE_DESCRIPTION("SOF Audio Client Platform Driver"); |
| 136 | +MODULE_LICENSE("Dual BSD/GPL"); |
| 137 | +MODULE_ALIAS("platform:sof-audio"); |
0 commit comments