forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MFD support in SOF with a single client device for audio. The audio client is a registered as a separate platform device under the SOF PCI device. This patch deals with partitioning the DSP hardware initialisation parts and the audio specific code. The hardware initialization, FW load/boot, IPC init is done at the top-level PCI device probe. The audio client platform device's probe deals with registering the component driver, creating the machine driver and loading the topology. The device hierarchy is altered with the addition of the platform device for the audio client. The machine driver and the component driver will now be children of the sof-audio platform device. Signed-off-by: Ranjani Sridharan <[email protected]>
- Loading branch information
Showing
8 changed files
with
218 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) | ||
// | ||
// This file is provided under a dual BSD/GPLv2 license. When using or | ||
// redistributing this file, you may do so under either license. | ||
// | ||
// Copyright(c) 2019 Intel Corporation. All rights reserved. | ||
// | ||
// Author: Ranjani Sridharan <[email protected]> | ||
// | ||
|
||
#include <linux/device.h> | ||
#include <linux/module.h> | ||
#include <linux/platform_device.h> | ||
#include <linux/pm_runtime.h> | ||
#include <sound/sof.h> | ||
#include "sof-priv.h" | ||
#include "ops.h" | ||
|
||
/* | ||
* SOF Driver enumeration. | ||
*/ | ||
static int sof_machine_check(struct snd_sof_dev *sdev) | ||
{ | ||
struct snd_sof_pdata *plat_data = sdev->pdata; | ||
#if IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC) | ||
struct snd_soc_acpi_mach *machine; | ||
int ret; | ||
#endif | ||
|
||
if (plat_data->machine) | ||
return 0; | ||
|
||
#if !IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC) | ||
dev_err(sdev->dev, "error: no matching ASoC machine driver found - aborting probe\n"); | ||
return -ENODEV; | ||
#else | ||
/* fallback to nocodec mode */ | ||
dev_warn(sdev->dev, "No ASoC machine driver found - using nocodec\n"); | ||
machine = devm_kzalloc(sdev->dev, sizeof(*machine), GFP_KERNEL); | ||
if (!machine) | ||
return -ENOMEM; | ||
|
||
ret = sof_nocodec_setup(sdev->dev, plat_data, machine, | ||
plat_data->desc, plat_data->desc->ops); | ||
if (ret < 0) | ||
return ret; | ||
|
||
plat_data->machine = machine; | ||
|
||
return 0; | ||
#endif | ||
} | ||
|
||
static int sof_audio_probe(struct platform_device *pdev) | ||
{ | ||
struct snd_sof_dev *sdev = dev_get_drvdata(&pdev->dev); | ||
struct snd_sof_pdata *plat_data = sdev->pdata; | ||
struct snd_soc_acpi_mach *machine = plat_data->machine; | ||
const char *drv_name; | ||
int size; | ||
int ret; | ||
|
||
/* check machine info */ | ||
ret = sof_machine_check(sdev); | ||
if (ret < 0) { | ||
dev_err(&pdev->dev, "error: failed to get machine info %d\n", | ||
ret); | ||
goto err; | ||
} | ||
|
||
/* set platform name */ | ||
machine->mach_params.platform = dev_name(&pdev->dev); | ||
plat_data->platform = dev_name(&pdev->dev); | ||
|
||
/* set up platform component driver */ | ||
snd_sof_new_platform_drv(sdev); | ||
|
||
/* now register audio DSP platform driver and dai */ | ||
ret = devm_snd_soc_register_component(&pdev->dev, &sdev->plat_drv, | ||
sof_ops(sdev)->drv, | ||
sof_ops(sdev)->num_drv); | ||
if (ret < 0) { | ||
dev_err(&pdev->dev, | ||
"error: failed to register DSP DAI driver %d\n", ret); | ||
goto err; | ||
} | ||
|
||
drv_name = plat_data->machine->drv_name; | ||
size = sizeof(*plat_data->machine); | ||
|
||
/* register machine driver, pass machine info as pdata */ | ||
plat_data->pdev_mach = | ||
platform_device_register_data(&pdev->dev, drv_name, | ||
PLATFORM_DEVID_NONE, | ||
(const void *)machine, size); | ||
|
||
if (IS_ERR(plat_data->pdev_mach)) { | ||
ret = PTR_ERR(plat_data->pdev_mach); | ||
goto err; | ||
} | ||
|
||
dev_dbg(&pdev->dev, "created machine %s\n", | ||
dev_name(&plat_data->pdev_mach->dev)); | ||
|
||
/* enable runtime PM */ | ||
pm_runtime_set_autosuspend_delay(&pdev->dev, SND_SOF_SUSPEND_DELAY_MS); | ||
pm_runtime_use_autosuspend(&pdev->dev); | ||
|
||
pm_runtime_enable(&pdev->dev); | ||
|
||
pm_runtime_mark_last_busy(&pdev->dev); | ||
|
||
pm_runtime_put_noidle(&pdev->dev); | ||
|
||
return 0; | ||
|
||
err: | ||
snd_sof_remove(sdev); | ||
snd_sof_fw_unload(sdev); | ||
snd_sof_ipc_free(sdev); | ||
snd_sof_free_debug(sdev); | ||
return ret; | ||
} | ||
|
||
static struct platform_driver sof_audio_driver = { | ||
.driver = { | ||
.name = "sof-audio", | ||
}, | ||
|
||
.probe = sof_audio_probe, | ||
}; | ||
|
||
module_platform_driver(sof_audio_driver); | ||
|
||
MODULE_DESCRIPTION("SOF Audio Client Platform Driver"); | ||
MODULE_LICENSE("Dual BSD/GPL"); | ||
MODULE_ALIAS("platform:sof-audio"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) | ||
// | ||
// This file is provided under a dual BSD/GPLv2 license. When using or | ||
// redistributing this file, you may do so under either license. | ||
// | ||
// Copyright(c) 2019 Intel Corporation. All rights reserved. | ||
// | ||
// Author: Ranjani Sridharan <[email protected]> | ||
// | ||
#include <linux/device.h> | ||
#include "sof-mfd.h" | ||
|
||
void sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, | ||
struct platform_device *pdev) | ||
{ | ||
int ret; | ||
|
||
pdev = platform_device_alloc(name, -1); | ||
if (!pdev) { | ||
dev_err(sdev->dev, "error: Failed to allocate %s\n", name); | ||
return; | ||
} | ||
|
||
pdev->dev.parent = sdev->dev; | ||
dev_set_drvdata(&pdev->dev, sdev); | ||
ret = platform_device_add(pdev); | ||
if (ret) { | ||
dev_err(sdev->dev, "error: Failed to register %s: %d\n", name, | ||
ret); | ||
platform_device_put(pdev); | ||
pdev = NULL; | ||
} | ||
dev_dbg(sdev->dev, "%s client registered\n", name); | ||
} | ||
EXPORT_SYMBOL(sof_client_dev_register); | ||
|
||
void sof_client_dev_unregister(struct platform_device *pdev) | ||
{ | ||
platform_device_del(pdev); | ||
} | ||
EXPORT_SYMBOL(sof_client_dev_unregister); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ | ||
/* | ||
* This file is provided under a dual BSD/GPLv2 license. When using or | ||
* redistributing this file, you may do so under either license. | ||
* | ||
* Copyright(c) 2019 Intel Corporation. All rights reserved. | ||
* | ||
* Author: Ranjani Sridharan <[email protected]> | ||
*/ | ||
#include <linux/platform_device.h> | ||
#include "sof-priv.h" | ||
|
||
#ifndef __SOUND_SOC_SOF_MFD_H | ||
#define __SOUND_SOC_SOF_MFD_H | ||
|
||
/* client register/unregister */ | ||
void sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, | ||
struct platform_device *pdev); | ||
void sof_client_dev_unregister(struct platform_device *pdev); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters