Skip to content

Commit 85f7a8b

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: Add a new dai_get_clk topology IPC op
This will help make the code for getting the mclk and bclk IPC specific. Add the implementation for IPC3 as well. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Rander Wang <rander.wang@intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Link: https://lore.kernel.org/r/20220317175044.1752400-20-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 31cd6e4 commit 85f7a8b

3 files changed

Lines changed: 42 additions & 24 deletions

File tree

sound/soc/sof/ipc3-topology.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,34 @@ static int sof_ipc3_tear_down_all_pipelines(struct snd_sof_dev *sdev, bool verif
22522252
return 0;
22532253
}
22542254

2255+
static int sof_ipc3_dai_get_clk(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type)
2256+
{
2257+
struct sof_dai_private_data *private = dai->private;
2258+
2259+
if (!private || !private->dai_config)
2260+
return 0;
2261+
2262+
switch (private->dai_config->type) {
2263+
case SOF_DAI_INTEL_SSP:
2264+
switch (clk_type) {
2265+
case SOF_DAI_CLK_INTEL_SSP_MCLK:
2266+
return private->dai_config->ssp.mclk_rate;
2267+
case SOF_DAI_CLK_INTEL_SSP_BCLK:
2268+
return private->dai_config->ssp.bclk_rate;
2269+
default:
2270+
break;
2271+
}
2272+
dev_err(sdev->dev, "fail to get SSP clk %d rate\n", clk_type);
2273+
break;
2274+
default:
2275+
/* not yet implemented for platforms other than the above */
2276+
dev_err(sdev->dev, "DAI type %d not supported yet!\n", private->dai_config->type);
2277+
break;
2278+
}
2279+
2280+
return -EINVAL;
2281+
}
2282+
22552283
/* token list for each topology object */
22562284
static enum sof_tokens host_token_list[] = {
22572285
SOF_CORE_TOKENS,
@@ -2359,6 +2387,7 @@ const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
23592387
.widget_free = sof_ipc3_widget_free,
23602388
.widget_setup = sof_ipc3_widget_setup,
23612389
.dai_config = sof_ipc3_dai_config,
2390+
.dai_get_clk = sof_ipc3_dai_get_clk,
23622391
.set_up_all_pipelines = sof_ipc3_set_up_all_pipelines,
23632392
.tear_down_all_pipelines = sof_ipc3_tear_down_all_pipelines,
23642393
};

sound/soc/sof/sof-audio.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -628,40 +628,23 @@ struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
628628
return NULL;
629629
}
630630

631-
#define SOF_DAI_CLK_INTEL_SSP_MCLK 0
632-
#define SOF_DAI_CLK_INTEL_SSP_BCLK 1
633-
634631
static int sof_dai_get_clk(struct snd_soc_pcm_runtime *rtd, int clk_type)
635632
{
636633
struct snd_soc_component *component =
637634
snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
638635
struct snd_sof_dai *dai =
639636
snd_sof_find_dai(component, (char *)rtd->dai_link->name);
640-
struct sof_dai_private_data *private = dai->private;
637+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
638+
const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
641639

642640
/* use the tplg configured mclk if existed */
643-
if (!dai || !private || !private->dai_config)
641+
if (!dai)
644642
return 0;
645643

646-
switch (private->dai_config->type) {
647-
case SOF_DAI_INTEL_SSP:
648-
switch (clk_type) {
649-
case SOF_DAI_CLK_INTEL_SSP_MCLK:
650-
return private->dai_config->ssp.mclk_rate;
651-
case SOF_DAI_CLK_INTEL_SSP_BCLK:
652-
return private->dai_config->ssp.bclk_rate;
653-
default:
654-
dev_err(rtd->dev, "fail to get SSP clk %d rate\n",
655-
clk_type);
656-
return -EINVAL;
657-
}
658-
break;
659-
default:
660-
/* not yet implemented for platforms other than the above */
661-
dev_err(rtd->dev, "DAI type %d not supported yet!\n",
662-
private->dai_config->type);
663-
return -EINVAL;
664-
}
644+
if (tplg_ops->dai_get_clk)
645+
return tplg_ops->dai_get_clk(sdev, dai, clk_type);
646+
647+
return 0;
665648
}
666649

667650
/*

sound/soc/sof/sof-audio.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
#define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
3232

33+
#define SOF_DAI_CLK_INTEL_SSP_MCLK 0
34+
#define SOF_DAI_CLK_INTEL_SSP_BCLK 1
35+
3336
/*
3437
* Volume fractional word length define to 16 sets
3538
* the volume linear gain value to use Qx.16 format
@@ -39,6 +42,7 @@
3942
struct snd_sof_widget;
4043
struct snd_sof_route;
4144
struct snd_sof_control;
45+
struct snd_sof_dai;
4246

4347
struct snd_sof_dai_config_data {
4448
int dai_index;
@@ -117,6 +121,7 @@ struct sof_ipc_tplg_widget_ops {
117121
* @widget_setup: Function pointer for setting up setup in the DSP
118122
* @widget_free: Function pointer for freeing widget in the DSP
119123
* @dai_config: Function pointer for sending DAI config IPC to the DSP
124+
* @dai_get_clk: Function pointer for getting the DAI clock setting
120125
* @set_up_all_pipelines: Function pointer for setting up all topology pipelines
121126
* @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
122127
*/
@@ -132,6 +137,7 @@ struct sof_ipc_tplg_ops {
132137
int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
133138
int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
134139
unsigned int flags, struct snd_sof_dai_config_data *data);
140+
int (*dai_get_clk)(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type);
135141
int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
136142
int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
137143
};

0 commit comments

Comments
 (0)