Commit 1a497983 authored by Mengdong Lin's avatar Mengdong Lin Committed by Mark Brown

ASoC: Change the PCM runtime array to a list

Currently the number of DAI links is statically defined by the machine
driver at build time using an array. This makes it difficult to shrink/
grow the number of DAI links at runtime in order to reflect any changes
in topology.

We can change the DAI link array in the core to a list so that PCMs and
FE DAI links can be added and deleted at runtime to reflect changes in
use case and DSP topology. The machine driver can still register DAI links
as an array.

As the 1st step, this patch change the PCM runtime array to a list. A new
PCM runtime is added to the list when a DAI link is bound successfully.

Later patches will further implement the DAI link list.

More:
- define snd_soc_new/free_pcm_runtime() to create/free a runtime.
- define soc_add_pcm_runtime() to add a runtime to the rtd list.
- define soc_remove_pcm_runtimes() to clean up the runtime list.

- traverse the rtd list to probe the link components and dais.

- Add a field "num" to PCM runtime struct, used to specify the device
  number when creating the pcm device, and for a soc card to access
  its dai_props array.

- The following 3rd party machine/platform drivers iterate the rtd list
  to check the runtimes:
  sound/soc/intel/atom/sst-mfld-platform-pcm.c
  sound/soc/intel/boards/cht_bsw_rt5645.c
  sound/soc/intel/boards/cht_bsw_rt5672.c
  sound/soc/intel/boards/cht_bsw_max98090_ti.c
Signed-off-by: default avatarMengdong Lin <mengdong.lin@linux.intel.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5015920a
...@@ -1106,7 +1106,7 @@ struct snd_soc_card { ...@@ -1106,7 +1106,7 @@ struct snd_soc_card {
/* CPU <--> Codec DAI links */ /* CPU <--> Codec DAI links */
struct snd_soc_dai_link *dai_link; struct snd_soc_dai_link *dai_link;
int num_links; int num_links;
struct snd_soc_pcm_runtime *rtd; struct list_head rtd_list;
int num_rtd; int num_rtd;
/* optional codec specific configuration */ /* optional codec specific configuration */
...@@ -1201,6 +1201,9 @@ struct snd_soc_pcm_runtime { ...@@ -1201,6 +1201,9 @@ struct snd_soc_pcm_runtime {
struct dentry *debugfs_dpcm_root; struct dentry *debugfs_dpcm_root;
struct dentry *debugfs_dpcm_state; struct dentry *debugfs_dpcm_state;
#endif #endif
unsigned int num; /* 0-based and monotonic increasing */
struct list_head list; /* rtd list of the soc card */
}; };
/* mixer control */ /* mixer control */
......
...@@ -45,7 +45,7 @@ static int asoc_simple_card_startup(struct snd_pcm_substream *substream) ...@@ -45,7 +45,7 @@ static int asoc_simple_card_startup(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *dai_props = struct simple_dai_props *dai_props =
&priv->dai_props[rtd - rtd->card->rtd]; &priv->dai_props[rtd->num];
int ret; int ret;
ret = clk_prepare_enable(dai_props->cpu_dai.clk); ret = clk_prepare_enable(dai_props->cpu_dai.clk);
...@@ -64,7 +64,7 @@ static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream) ...@@ -64,7 +64,7 @@ static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *dai_props = struct simple_dai_props *dai_props =
&priv->dai_props[rtd - rtd->card->rtd]; &priv->dai_props[rtd->num];
clk_disable_unprepare(dai_props->cpu_dai.clk); clk_disable_unprepare(dai_props->cpu_dai.clk);
...@@ -78,8 +78,7 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream, ...@@ -78,8 +78,7 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai = rtd->codec_dai;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
struct simple_dai_props *dai_props = struct simple_dai_props *dai_props = &priv->dai_props[rtd->num];
&priv->dai_props[rtd - rtd->card->rtd];
unsigned int mclk, mclk_fs = 0; unsigned int mclk, mclk_fs = 0;
int ret = 0; int ret = 0;
...@@ -174,10 +173,9 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) ...@@ -174,10 +173,9 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
struct snd_soc_dai *codec = rtd->codec_dai; struct snd_soc_dai *codec = rtd->codec_dai;
struct snd_soc_dai *cpu = rtd->cpu_dai; struct snd_soc_dai *cpu = rtd->cpu_dai;
struct simple_dai_props *dai_props; struct simple_dai_props *dai_props;
int num, ret; int ret;
num = rtd - rtd->card->rtd; dai_props = &priv->dai_props[rtd->num];
dai_props = &priv->dai_props[num];
ret = __asoc_simple_card_dai_init(codec, &dai_props->codec_dai); ret = __asoc_simple_card_dai_init(codec, &dai_props->codec_dai);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -760,15 +760,15 @@ static int sst_platform_remove(struct platform_device *pdev) ...@@ -760,15 +760,15 @@ static int sst_platform_remove(struct platform_device *pdev)
static int sst_soc_prepare(struct device *dev) static int sst_soc_prepare(struct device *dev)
{ {
struct sst_data *drv = dev_get_drvdata(dev); struct sst_data *drv = dev_get_drvdata(dev);
int i; struct snd_soc_pcm_runtime *rtd;
/* suspend all pcms first */ /* suspend all pcms first */
snd_soc_suspend(drv->soc_card->dev); snd_soc_suspend(drv->soc_card->dev);
snd_soc_poweroff(drv->soc_card->dev); snd_soc_poweroff(drv->soc_card->dev);
/* set the SSPs to idle */ /* set the SSPs to idle */
for (i = 0; i < drv->soc_card->num_rtd; i++) { list_for_each_entry(rtd, &drv->soc_card->rtd_list, list) {
struct snd_soc_dai *dai = drv->soc_card->rtd[i].cpu_dai; struct snd_soc_dai *dai = rtd->cpu_dai;
if (dai->active) { if (dai->active) {
send_ssp_cmd(dai, dai->name, 0); send_ssp_cmd(dai, dai->name, 0);
...@@ -782,11 +782,11 @@ static int sst_soc_prepare(struct device *dev) ...@@ -782,11 +782,11 @@ static int sst_soc_prepare(struct device *dev)
static void sst_soc_complete(struct device *dev) static void sst_soc_complete(struct device *dev)
{ {
struct sst_data *drv = dev_get_drvdata(dev); struct sst_data *drv = dev_get_drvdata(dev);
int i; struct snd_soc_pcm_runtime *rtd;
/* restart SSPs */ /* restart SSPs */
for (i = 0; i < drv->soc_card->num_rtd; i++) { list_for_each_entry(rtd, &drv->soc_card->rtd_list, list) {
struct snd_soc_dai *dai = drv->soc_card->rtd[i].cpu_dai; struct snd_soc_dai *dai = rtd->cpu_dai;
if (dai->active) { if (dai->active) {
sst_handle_vb_timer(dai, true); sst_handle_vb_timer(dai, true);
......
...@@ -41,12 +41,9 @@ struct cht_mc_private { ...@@ -41,12 +41,9 @@ struct cht_mc_private {
static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card) static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
{ {
int i; struct snd_soc_pcm_runtime *rtd;
for (i = 0; i < card->num_rtd; i++) { list_for_each_entry(rtd, &card->rtd_list, list) {
struct snd_soc_pcm_runtime *rtd;
rtd = card->rtd + i;
if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI, if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI,
strlen(CHT_CODEC_DAI))) strlen(CHT_CODEC_DAI)))
return rtd->codec_dai; return rtd->codec_dai;
......
...@@ -47,12 +47,9 @@ struct cht_mc_private { ...@@ -47,12 +47,9 @@ struct cht_mc_private {
static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card) static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
{ {
int i; struct snd_soc_pcm_runtime *rtd;
for (i = 0; i < card->num_rtd; i++) {
struct snd_soc_pcm_runtime *rtd;
rtd = card->rtd + i; list_for_each_entry(rtd, &card->rtd_list, list) {
if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI, if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI,
strlen(CHT_CODEC_DAI))) strlen(CHT_CODEC_DAI)))
return rtd->codec_dai; return rtd->codec_dai;
......
...@@ -46,12 +46,9 @@ static struct snd_soc_jack_pin cht_bsw_headset_pins[] = { ...@@ -46,12 +46,9 @@ static struct snd_soc_jack_pin cht_bsw_headset_pins[] = {
static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card) static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
{ {
int i; struct snd_soc_pcm_runtime *rtd;
for (i = 0; i < card->num_rtd; i++) { list_for_each_entry(rtd, &card->rtd_list, list) {
struct snd_soc_pcm_runtime *rtd;
rtd = card->rtd + i;
if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI, if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI,
strlen(CHT_CODEC_DAI))) strlen(CHT_CODEC_DAI)))
return rtd->codec_dai; return rtd->codec_dai;
......
...@@ -1040,7 +1040,7 @@ static int __rsnd_kctrl_new(struct rsnd_mod *mod, ...@@ -1040,7 +1040,7 @@ static int __rsnd_kctrl_new(struct rsnd_mod *mod,
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = name, .name = name,
.info = rsnd_kctrl_info, .info = rsnd_kctrl_info,
.index = rtd - soc_card->rtd, .index = rtd->num,
.get = rsnd_kctrl_get, .get = rsnd_kctrl_get,
.put = rsnd_kctrl_put, .put = rsnd_kctrl_put,
.private_value = (unsigned long)cfg, .private_value = (unsigned long)cfg,
......
...@@ -75,7 +75,7 @@ static int rsrc_card_startup(struct snd_pcm_substream *substream) ...@@ -75,7 +75,7 @@ static int rsrc_card_startup(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct rsrc_card_dai *dai_props = struct rsrc_card_dai *dai_props =
rsrc_priv_to_props(priv, rtd - rtd->card->rtd); rsrc_priv_to_props(priv, rtd->num);
return clk_prepare_enable(dai_props->clk); return clk_prepare_enable(dai_props->clk);
} }
...@@ -85,7 +85,7 @@ static void rsrc_card_shutdown(struct snd_pcm_substream *substream) ...@@ -85,7 +85,7 @@ static void rsrc_card_shutdown(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct rsrc_card_dai *dai_props = struct rsrc_card_dai *dai_props =
rsrc_priv_to_props(priv, rtd - rtd->card->rtd); rsrc_priv_to_props(priv, rtd->num);
clk_disable_unprepare(dai_props->clk); clk_disable_unprepare(dai_props->clk);
} }
...@@ -101,7 +101,7 @@ static int rsrc_card_dai_init(struct snd_soc_pcm_runtime *rtd) ...@@ -101,7 +101,7 @@ static int rsrc_card_dai_init(struct snd_soc_pcm_runtime *rtd)
struct snd_soc_dai *dai; struct snd_soc_dai *dai;
struct snd_soc_dai_link *dai_link; struct snd_soc_dai_link *dai_link;
struct rsrc_card_dai *dai_props; struct rsrc_card_dai *dai_props;
int num = rtd - rtd->card->rtd; int num = rtd->num;
int ret; int ret;
dai_link = rsrc_priv_to_link(priv, num); dai_link = rsrc_priv_to_link(priv, num);
......
This diff is collapsed.
...@@ -3893,13 +3893,10 @@ static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream, ...@@ -3893,13 +3893,10 @@ static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream,
void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card) void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card)
{ {
struct snd_soc_pcm_runtime *rtd = card->rtd; struct snd_soc_pcm_runtime *rtd;
int i;
/* for each BE DAI link... */ /* for each BE DAI link... */
for (i = 0; i < card->num_rtd; i++) { list_for_each_entry(rtd, &card->rtd_list, list) {
rtd = &card->rtd[i];
/* /*
* dynamic FE links have no fixed DAI mapping. * dynamic FE links have no fixed DAI mapping.
* CODEC<->CODEC links have no direct connection. * CODEC<->CODEC links have no direct connection.
......
...@@ -1213,11 +1213,10 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, ...@@ -1213,11 +1213,10 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
struct snd_soc_dapm_widget *widget, int stream) struct snd_soc_dapm_widget *widget, int stream)
{ {
struct snd_soc_pcm_runtime *be; struct snd_soc_pcm_runtime *be;
int i, j; int i;
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
for (i = 0; i < card->num_links; i++) { list_for_each_entry(be, &card->rtd_list, list) {
be = &card->rtd[i];
if (!be->dai_link->no_pcm) if (!be->dai_link->no_pcm)
continue; continue;
...@@ -1225,16 +1224,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, ...@@ -1225,16 +1224,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
if (be->cpu_dai->playback_widget == widget) if (be->cpu_dai->playback_widget == widget)
return be; return be;
for (j = 0; j < be->num_codecs; j++) { for (i = 0; i < be->num_codecs; i++) {
struct snd_soc_dai *dai = be->codec_dais[j]; struct snd_soc_dai *dai = be->codec_dais[i];
if (dai->playback_widget == widget) if (dai->playback_widget == widget)
return be; return be;
} }
} }
} else { } else {
for (i = 0; i < card->num_links; i++) { list_for_each_entry(be, &card->rtd_list, list) {
be = &card->rtd[i];
if (!be->dai_link->no_pcm) if (!be->dai_link->no_pcm)
continue; continue;
...@@ -1242,8 +1240,8 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, ...@@ -1242,8 +1240,8 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
if (be->cpu_dai->capture_widget == widget) if (be->cpu_dai->capture_widget == widget)
return be; return be;
for (j = 0; j < be->num_codecs; j++) { for (i = 0; i < be->num_codecs; i++) {
struct snd_soc_dai *dai = be->codec_dais[j]; struct snd_soc_dai *dai = be->codec_dais[i];
if (dai->capture_widget == widget) if (dai->capture_widget == widget)
return be; return be;
} }
...@@ -2343,12 +2341,12 @@ static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream) ...@@ -2343,12 +2341,12 @@ static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)
*/ */
int soc_dpcm_runtime_update(struct snd_soc_card *card) int soc_dpcm_runtime_update(struct snd_soc_card *card)
{ {
int i, old, new, paths; struct snd_soc_pcm_runtime *fe;
int old, new, paths;
mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME); mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
for (i = 0; i < card->num_rtd; i++) { list_for_each_entry(fe, &card->rtd_list, list) {
struct snd_soc_dapm_widget_list *list; struct snd_soc_dapm_widget_list *list;
struct snd_soc_pcm_runtime *fe = &card->rtd[i];
/* make sure link is FE */ /* make sure link is FE */
if (!fe->dai_link->dynamic) if (!fe->dai_link->dynamic)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment