Commit 0b7990e3 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: add for_each_rtd_codec_dai() macro

ALSA SoC snd_soc_pcm_runtime has snd_soc_dai array for codec_dai.
To be more readable code, this patch adds
new for_each_rtd_codec_dai() macro, and replace existing code to it.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 3db769f1
...@@ -1158,6 +1158,13 @@ struct snd_soc_pcm_runtime { ...@@ -1158,6 +1158,13 @@ struct snd_soc_pcm_runtime {
unsigned int dev_registered:1; unsigned int dev_registered:1;
unsigned int pop_wait:1; unsigned int pop_wait:1;
}; };
#define for_each_rtd_codec_dai(rtd, i, dai)\
for ((i) = 0; \
((i) < rtd->num_codecs) && ((dai) = rtd->codec_dais[i]); \
(i)++)
#define for_each_rtd_codec_dai_reverse(rtd, i, dai) \
for (; ((i--) >= 0) && ((dai) = rtd->codec_dais[i]);)
/* mixer control */ /* mixer control */
struct soc_mixer_control { struct soc_mixer_control {
......
...@@ -488,11 +488,10 @@ static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream, ...@@ -488,11 +488,10 @@ static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *codec_dai;
int ret = 0, j; int ret = 0, j;
for (j = 0; j < rtd->num_codecs; j++) { for_each_rtd_codec_dai(rtd, j, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) { if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
/* /*
* Use channel 4 and 5 for the first amp * Use channel 4 and 5 for the first amp
......
...@@ -353,11 +353,10 @@ static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream, ...@@ -353,11 +353,10 @@ static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *codec_dai;
int ret = 0, j; int ret = 0, j;
for (j = 0; j < rtd->num_codecs; j++) { for_each_rtd_codec_dai(rtd, j, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) { if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) {
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16); ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16);
if (ret < 0) { if (ret < 0) {
......
...@@ -44,11 +44,10 @@ static int mt8173_rt5650_rt5514_hw_params(struct snd_pcm_substream *substream, ...@@ -44,11 +44,10 @@ static int mt8173_rt5650_rt5514_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *codec_dai;
int i, ret; int i, ret;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
/* pll from mclk 12.288M */ /* pll from mclk 12.288M */
ret = snd_soc_dai_set_pll(codec_dai, 0, 0, MCLK_FOR_CODECS, ret = snd_soc_dai_set_pll(codec_dai, 0, 0, MCLK_FOR_CODECS,
params_rate(params) * 512); params_rate(params) * 512);
......
...@@ -48,11 +48,10 @@ static int mt8173_rt5650_rt5676_hw_params(struct snd_pcm_substream *substream, ...@@ -48,11 +48,10 @@ static int mt8173_rt5650_rt5676_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *codec_dai;
int i, ret; int i, ret;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
/* pll from mclk 12.288M */ /* pll from mclk 12.288M */
ret = snd_soc_dai_set_pll(codec_dai, 0, 0, MCLK_FOR_CODECS, ret = snd_soc_dai_set_pll(codec_dai, 0, 0, MCLK_FOR_CODECS,
params_rate(params) * 512); params_rate(params) * 512);
......
...@@ -59,6 +59,7 @@ static int mt8173_rt5650_hw_params(struct snd_pcm_substream *substream, ...@@ -59,6 +59,7 @@ static int mt8173_rt5650_hw_params(struct snd_pcm_substream *substream,
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
unsigned int mclk_clock; unsigned int mclk_clock;
struct snd_soc_dai *codec_dai;
int i, ret; int i, ret;
switch (mt8173_rt5650_priv.pll_from) { switch (mt8173_rt5650_priv.pll_from) {
...@@ -76,9 +77,7 @@ static int mt8173_rt5650_hw_params(struct snd_pcm_substream *substream, ...@@ -76,9 +77,7 @@ static int mt8173_rt5650_hw_params(struct snd_pcm_substream *substream,
break; break;
} }
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
/* pll from mclk */ /* pll from mclk */
ret = snd_soc_dai_set_pll(codec_dai, 0, 0, mclk_clock, ret = snd_soc_dai_set_pll(codec_dai, 0, 0, mclk_clock,
params_rate(params) * 512); params_rate(params) * 512);
......
...@@ -168,8 +168,7 @@ static int axg_card_tdm_be_hw_params(struct snd_pcm_substream *substream, ...@@ -168,8 +168,7 @@ static int axg_card_tdm_be_hw_params(struct snd_pcm_substream *substream,
if (be->mclk_fs) { if (be->mclk_fs) {
mclk = params_rate(params) * be->mclk_fs; mclk = params_rate(params) * be->mclk_fs;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
codec_dai = rtd->codec_dais[i];
ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
SND_SOC_CLOCK_IN); SND_SOC_CLOCK_IN);
if (ret && ret != -ENOTSUPP) if (ret && ret != -ENOTSUPP)
...@@ -197,8 +196,7 @@ static int axg_card_tdm_dai_init(struct snd_soc_pcm_runtime *rtd) ...@@ -197,8 +196,7 @@ static int axg_card_tdm_dai_init(struct snd_soc_pcm_runtime *rtd)
struct snd_soc_dai *codec_dai; struct snd_soc_dai *codec_dai;
int ret, i; int ret, i;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
codec_dai = rtd->codec_dais[i];
ret = snd_soc_dai_set_tdm_slot(codec_dai, ret = snd_soc_dai_set_tdm_slot(codec_dai,
be->codec_masks[i].tx, be->codec_masks[i].tx,
be->codec_masks[i].rx, be->codec_masks[i].rx,
......
...@@ -452,12 +452,12 @@ int snd_soc_suspend(struct device *dev) ...@@ -452,12 +452,12 @@ int snd_soc_suspend(struct device *dev)
/* mute any active DACs */ /* mute any active DACs */
list_for_each_entry(rtd, &card->rtd_list, list) { list_for_each_entry(rtd, &card->rtd_list, list) {
struct snd_soc_dai *dai;
if (rtd->dai_link->ignore_suspend) if (rtd->dai_link->ignore_suspend)
continue; continue;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, dai) {
struct snd_soc_dai *dai = rtd->codec_dais[i];
struct snd_soc_dai_driver *drv = dai->driver; struct snd_soc_dai_driver *drv = dai->driver;
if (drv->ops->digital_mute && dai->playback_active) if (drv->ops->digital_mute && dai->playback_active)
...@@ -625,12 +625,12 @@ static void soc_resume_deferred(struct work_struct *work) ...@@ -625,12 +625,12 @@ static void soc_resume_deferred(struct work_struct *work)
/* unmute any active DACs */ /* unmute any active DACs */
list_for_each_entry(rtd, &card->rtd_list, list) { list_for_each_entry(rtd, &card->rtd_list, list) {
struct snd_soc_dai *dai;
if (rtd->dai_link->ignore_suspend) if (rtd->dai_link->ignore_suspend)
continue; continue;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, dai) {
struct snd_soc_dai *dai = rtd->codec_dais[i];
struct snd_soc_dai_driver *drv = dai->driver; struct snd_soc_dai_driver *drv = dai->driver;
if (drv->ops->digital_mute && dai->playback_active) if (drv->ops->digital_mute && dai->playback_active)
...@@ -674,15 +674,14 @@ int snd_soc_resume(struct device *dev) ...@@ -674,15 +674,14 @@ int snd_soc_resume(struct device *dev)
/* activate pins from sleep state */ /* activate pins from sleep state */
list_for_each_entry(rtd, &card->rtd_list, list) { list_for_each_entry(rtd, &card->rtd_list, list) {
struct snd_soc_dai **codec_dais = rtd->codec_dais; struct snd_soc_dai *codec_dai;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
int j; int j;
if (cpu_dai->active) if (cpu_dai->active)
pinctrl_pm_select_default_state(cpu_dai->dev); pinctrl_pm_select_default_state(cpu_dai->dev);
for (j = 0; j < rtd->num_codecs; j++) { for_each_rtd_codec_dai(rtd, j, codec_dai) {
struct snd_soc_dai *codec_dai = codec_dais[j];
if (codec_dai->active) if (codec_dai->active)
pinctrl_pm_select_default_state(codec_dai->dev); pinctrl_pm_select_default_state(codec_dai->dev);
} }
...@@ -877,6 +876,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card, ...@@ -877,6 +876,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card,
rtd->num_codecs = dai_link->num_codecs; rtd->num_codecs = dai_link->num_codecs;
/* Find CODEC from registered CODECs */ /* Find CODEC from registered CODECs */
/* we can use for_each_rtd_codec_dai() after this */
codec_dais = rtd->codec_dais; codec_dais = rtd->codec_dais;
for (i = 0; i < rtd->num_codecs; i++) { for (i = 0; i < rtd->num_codecs; i++) {
codec_dais[i] = snd_soc_find_dai(&codecs[i]); codec_dais[i] = snd_soc_find_dai(&codecs[i]);
...@@ -959,6 +959,7 @@ static void soc_remove_link_dais(struct snd_soc_card *card, ...@@ -959,6 +959,7 @@ static void soc_remove_link_dais(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd, int order) struct snd_soc_pcm_runtime *rtd, int order)
{ {
int i; int i;
struct snd_soc_dai *codec_dai;
/* unregister the rtd device */ /* unregister the rtd device */
if (rtd->dev_registered) { if (rtd->dev_registered) {
...@@ -967,8 +968,8 @@ static void soc_remove_link_dais(struct snd_soc_card *card, ...@@ -967,8 +968,8 @@ static void soc_remove_link_dais(struct snd_soc_card *card,
} }
/* remove the CODEC DAI */ /* remove the CODEC DAI */
for (i = 0; i < rtd->num_codecs; i++) for_each_rtd_codec_dai(rtd, i, codec_dai)
soc_remove_dai(rtd->codec_dais[i], order); soc_remove_dai(codec_dai, order);
soc_remove_dai(rtd->cpu_dai, order); soc_remove_dai(rtd->cpu_dai, order);
} }
...@@ -1511,6 +1512,7 @@ static int soc_probe_link_dais(struct snd_soc_card *card, ...@@ -1511,6 +1512,7 @@ static int soc_probe_link_dais(struct snd_soc_card *card,
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_rtdcom_list *rtdcom; struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_component *component; struct snd_soc_component *component;
struct snd_soc_dai *codec_dai;
int i, ret, num; int i, ret, num;
dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
...@@ -1524,8 +1526,8 @@ static int soc_probe_link_dais(struct snd_soc_card *card, ...@@ -1524,8 +1526,8 @@ static int soc_probe_link_dais(struct snd_soc_card *card,
return ret; return ret;
/* probe the CODEC DAI */ /* probe the CODEC DAI */
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
ret = soc_probe_dai(rtd->codec_dais[i], order); ret = soc_probe_dai(codec_dai, order);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -1712,14 +1714,12 @@ static void soc_remove_aux_devices(struct snd_soc_card *card) ...@@ -1712,14 +1714,12 @@ static void soc_remove_aux_devices(struct snd_soc_card *card)
int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
unsigned int dai_fmt) unsigned int dai_fmt)
{ {
struct snd_soc_dai **codec_dais = rtd->codec_dais;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai;
unsigned int i; unsigned int i;
int ret; int ret;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
struct snd_soc_dai *codec_dai = codec_dais[i];
ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
if (ret != 0 && ret != -ENOTSUPP) { if (ret != 0 && ret != -ENOTSUPP) {
dev_warn(codec_dai->dev, dev_warn(codec_dai->dev,
...@@ -2266,11 +2266,11 @@ int snd_soc_poweroff(struct device *dev) ...@@ -2266,11 +2266,11 @@ int snd_soc_poweroff(struct device *dev)
/* deactivate pins to sleep state */ /* deactivate pins to sleep state */
list_for_each_entry(rtd, &card->rtd_list, list) { list_for_each_entry(rtd, &card->rtd_list, list) {
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai;
int i; int i;
pinctrl_pm_select_sleep_state(cpu_dai->dev); pinctrl_pm_select_sleep_state(cpu_dai->dev);
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
pinctrl_pm_select_sleep_state(codec_dai->dev); pinctrl_pm_select_sleep_state(codec_dai->dev);
} }
} }
...@@ -2776,10 +2776,10 @@ int snd_soc_register_card(struct snd_soc_card *card) ...@@ -2776,10 +2776,10 @@ int snd_soc_register_card(struct snd_soc_card *card)
/* deactivate pins to sleep state */ /* deactivate pins to sleep state */
list_for_each_entry(rtd, &card->rtd_list, list) { list_for_each_entry(rtd, &card->rtd_list, list) {
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai;
int j; int j;
for (j = 0; j < rtd->num_codecs; j++) { for_each_rtd_codec_dai(rtd, j, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
if (!codec_dai->active) if (!codec_dai->active)
pinctrl_pm_select_sleep_state(codec_dai->dev); pinctrl_pm_select_sleep_state(codec_dai->dev);
} }
......
...@@ -2370,12 +2370,13 @@ static ssize_t dapm_widget_show(struct device *dev, ...@@ -2370,12 +2370,13 @@ static ssize_t dapm_widget_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
struct snd_soc_dai *codec_dai;
int i, count = 0; int i, count = 0;
mutex_lock(&rtd->card->dapm_mutex); mutex_lock(&rtd->card->dapm_mutex);
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
struct snd_soc_component *cmpnt = rtd->codec_dais[i]->component; struct snd_soc_component *cmpnt = codec_dai->component;
count += dapm_widget_show_component(cmpnt, buf + count); count += dapm_widget_show_component(cmpnt, buf + count);
} }
...@@ -4110,11 +4111,11 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card, ...@@ -4110,11 +4111,11 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd) struct snd_soc_pcm_runtime *rtd)
{ {
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai;
struct snd_soc_dapm_widget *sink, *source; struct snd_soc_dapm_widget *sink, *source;
int i; int i;
for (i = 0; i < rtd->num_codecs; i++) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
/* connect BE DAI playback if widgets are valid */ /* connect BE DAI playback if widgets are valid */
if (codec_dai->playback_widget && cpu_dai->playback_widget) { if (codec_dai->playback_widget && cpu_dai->playback_widget) {
...@@ -4202,11 +4203,12 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card) ...@@ -4202,11 +4203,12 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card)
static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
int event) int event)
{ {
struct snd_soc_dai *codec_dai;
int i; int i;
soc_dapm_dai_stream_event(rtd->cpu_dai, stream, event); soc_dapm_dai_stream_event(rtd->cpu_dai, stream, event);
for (i = 0; i < rtd->num_codecs; i++) for_each_rtd_codec_dai(rtd, i, codec_dai)
soc_dapm_dai_stream_event(rtd->codec_dais[i], stream, event); soc_dapm_dai_stream_event(codec_dai, stream, event);
dapm_power_widgets(rtd->card, event); dapm_power_widgets(rtd->card, event);
} }
......
This diff is collapsed.
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