Skip to content

Commit

Permalink
ASoC: SOF: move to component model
Browse files Browse the repository at this point in the history
Prepare for the transition to 4.18, these changes should be enough
to check for any regression

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
  • Loading branch information
plbossart committed Aug 15, 2018
1 parent 2a7a5d9 commit 6d312cc
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 78 deletions.
17 changes: 9 additions & 8 deletions include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,14 @@ struct snd_soc_component_driver {
unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
unsigned int endianness:1;
unsigned int non_legacy_dai_naming:1;

/* this component uses topology and ignore machine driver FEs */
const char *ignore_machine;
const char *topology_name_prefix;
int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params);
bool use_dai_pcm_id; /* use the DAI link PCM ID as PCM device number */
int be_pcm_base; /* base device ID for all BE PCMs */
};

struct snd_soc_component {
Expand Down Expand Up @@ -1017,14 +1025,6 @@ struct snd_soc_platform_driver {

/* platform stream compress ops */
const struct snd_compr_ops *compr_ops;

/* this platform uses topology and ignore machine driver FEs */
const char *ignore_machine;
const char *topology_name_prefix;
int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params);
bool use_dai_pcm_id; /* use the DAI link PCM ID as PCM device number */
int be_pcm_base; /* base device ID for all BE PCMs */
};

struct snd_soc_dai_link_component {
Expand Down Expand Up @@ -1183,6 +1183,7 @@ struct snd_soc_card {
struct mutex dapm_mutex;

bool instantiated;
bool topology_shortname_created;

int (*probe)(struct snd_soc_card *card);
int (*late_probe)(struct snd_soc_card *card);
Expand Down
51 changes: 34 additions & 17 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,8 @@ static int soc_probe_link_dais(struct snd_soc_card *card,
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_component *component;
int i, ret, num;

dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
Expand Down Expand Up @@ -1721,18 +1723,23 @@ static int soc_probe_link_dais(struct snd_soc_card *card,
soc_dpcm_debugfs_add(rtd);
#endif

num = rtd->num;

/*
* most drivers will register their PCMs using DAI link ordering but
* topology based drivers can use the DAI link id field to set PCM
* device number and then use rtd + a base offset of the BEs.
*/
if (rtd->platform->driver->use_dai_pcm_id) {
for_each_rtdcom(rtd, rtdcom) {
component = rtdcom->component;

if (!component->driver->use_dai_pcm_id)
continue;

if (rtd->dai_link->no_pcm)
num = rtd->platform->driver->be_pcm_base + rtd->num;
num += component->driver->be_pcm_base;
else
num = rtd->dai_link->id;
} else {
num = rtd->num;
}

if (cpu_dai->driver->compress_new) {
Expand Down Expand Up @@ -2095,21 +2102,22 @@ EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);

static void soc_check_tplg_fes(struct snd_soc_card *card)
{
struct snd_soc_platform *platform;
struct snd_soc_component *component;
const struct snd_soc_component_driver *comp_drv;
struct snd_soc_dai_link *dai_link;
int i;

list_for_each_entry(platform, &platform_list, list) {
list_for_each_entry(component, &component_list, list) {

/* does this platform override FEs ? */
if (!platform->driver->ignore_machine)
/* does this component override FEs ? */
if (!component->driver->ignore_machine)
continue;

/* for this machine ? */
if (!strcmp(platform->driver->ignore_machine,
if (!strcmp(component->driver->ignore_machine,
card->dev->driver->name))
goto match;
if (strcmp(platform->driver->ignore_machine,
if (strcmp(component->driver->ignore_machine,
dev_name(card->dev)))
continue;
match:
Expand All @@ -2127,15 +2135,15 @@ static void soc_check_tplg_fes(struct snd_soc_card *card)
dev_info(card->dev, "info: override FE DAI link %s\n",
card->dai_link[i].name);

/* override platform */
dai_link->platform_name = platform->component.name;
/* override platform component */
dai_link->platform_name = component->name;

/* convert non BE into BE */
dai_link->no_pcm = 1;

/* override any BE fixups */
dai_link->be_hw_params_fixup =
platform->driver->be_hw_params_fixup;
component->driver->be_hw_params_fixup;

/* most BE links don't set stream name, so set it to
* dai link name if it's NULL to help bind widgets.
Expand All @@ -2145,10 +2153,19 @@ static void soc_check_tplg_fes(struct snd_soc_card *card)
}

/* Inform userspace we are using alternate topology */
if (platform->driver->topology_name_prefix) {
snprintf(card->topology_shortname, 32, "%s-%s",
platform->driver->topology_name_prefix,
card->name);
if (component->driver->topology_name_prefix) {

/* topology shortname created ? */
if (!card->topology_shortname_created) {
comp_drv = component->driver;

snprintf(card->topology_shortname, 32, "%s-%s",
comp_drv->topology_name_prefix,
card->name);
card->topology_shortname_created = true;
}

/* use topology shortname */
card->name = card->topology_shortname;
}
}
Expand Down
22 changes: 17 additions & 5 deletions sound/soc/sof/compressed.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
#include <uapi/sound/sof-ipc.h>
#include "sof-priv.h"

#define DRV_NAME "sof-audio"

static int sof_compressed_open(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component =
snd_soc_rtdcom_lookup(rtd, DRV_NAME);
struct snd_sof_dev *sdev =
snd_soc_platform_get_drvdata(rtd->platform);
snd_soc_component_get_drvdata(component);
struct snd_sof_pcm *spcm = rtd->sof;

mutex_lock(&spcm->mutex);
Expand All @@ -36,8 +40,10 @@ static int sof_compressed_open(struct snd_compr_stream *cstream)
static int sof_compressed_free(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component =
snd_soc_rtdcom_lookup(rtd, DRV_NAME);
struct snd_sof_dev *sdev =
snd_soc_platform_get_drvdata(rtd->platform);
snd_soc_component_get_drvdata(component);
struct snd_sof_pcm *spcm = rtd->sof;

mutex_lock(&spcm->mutex);
Expand All @@ -62,8 +68,10 @@ static int sof_compressed_set_params(struct snd_compr_stream *cstream,
struct snd_compr_params *params)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component =
snd_soc_rtdcom_lookup(rtd, DRV_NAME);
struct snd_sof_dev *sdev =
snd_soc_platform_get_drvdata(rtd->platform);
snd_soc_component_get_drvdata(component);

switch (params->codec.id) {
case SND_AUDIOCODEC_VORBIS:
Expand All @@ -80,8 +88,10 @@ static int sof_compressed_set_params(struct snd_compr_stream *cstream,
static int sof_compressed_trigger(struct snd_compr_stream *cstream, int cmd)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component =
snd_soc_rtdcom_lookup(rtd, DRV_NAME);
struct snd_sof_dev *sdev =
snd_soc_platform_get_drvdata(rtd->platform);
snd_soc_component_get_drvdata(component);
struct snd_sof_pcm *spcm = rtd->sof;
struct sof_ipc_stream stream;
struct sof_ipc_reply reply;
Expand Down Expand Up @@ -118,8 +128,10 @@ static int sof_compressed_pointer(struct snd_compr_stream *cstream,
struct snd_compr_tstamp *tstamp)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component =
snd_soc_rtdcom_lookup(rtd, DRV_NAME);
struct snd_sof_dev *sdev =
snd_soc_platform_get_drvdata(rtd->platform);
snd_soc_component_get_drvdata(component);
struct sof_ipc_stream_posn posn;
struct snd_sof_pcm *spcm = rtd->sof;

Expand Down
17 changes: 4 additions & 13 deletions sound/soc/sof/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ static int sof_probe(struct platform_device *pdev)

/* set up platform component driver */
snd_sof_new_platform_drv(sdev);
snd_sof_new_dai_drv(sdev);

/* set default timeouts if none provided */
if (plat_data->desc->ipc_timeout == 0)
Expand Down Expand Up @@ -307,17 +306,10 @@ static int sof_probe(struct platform_device *pdev)
goto fw_run_err;
}

/* now register audio DSP platform driver */
ret = snd_soc_register_platform(&pdev->dev, &sdev->plat_drv);
if (ret < 0) {
dev_err(sdev->dev,
"error: failed to register DSP platform driver %d\n",
ret);
goto fw_run_err;
}

ret = snd_soc_register_component(&pdev->dev, sdev->cmpnt_drv,
sdev->ops->drv, sdev->ops->num_drv);
/* now register audio DSP platform driver and dai */
ret = snd_soc_register_component(&pdev->dev, &sdev->plat_drv,
sdev->ops->drv,
sdev->ops->num_drv);
if (ret < 0) {
dev_err(sdev->dev,
"error: failed to register DSP DAI driver %d\n", ret);
Expand Down Expand Up @@ -361,7 +353,6 @@ static int sof_remove(struct platform_device *pdev)
{
struct snd_sof_dev *sdev = dev_get_drvdata(&pdev->dev);

snd_soc_unregister_platform(&pdev->dev);
snd_soc_unregister_component(&pdev->dev);
snd_sof_fw_unload(sdev);
snd_sof_ipc_free(sdev);
Expand Down
Loading

0 comments on commit 6d312cc

Please sign in to comment.