[PATCH 2/2] ASoC: meson: meson-card: use priv instead of card on each functions
Kuninori Morimoto
kuninori.morimoto.gx at renesas.com
Mon Jul 20 18:36:59 PDT 2026
We can get card via priv->card, use priv for function param.
No functional change, but is preparation for Card capsuling.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
sound/soc/meson/axg-card.c | 63 ++++++++++++++++--------------
sound/soc/meson/gx-card.c | 23 +++++------
sound/soc/meson/meson-card-utils.c | 58 ++++++++++++++-------------
sound/soc/meson/meson-card.h | 11 +++---
4 files changed, 82 insertions(+), 73 deletions(-)
diff --git a/sound/soc/meson/axg-card.c b/sound/soc/meson/axg-card.c
index b4dca80e15e40..3d345dc33cb6f 100644
--- a/sound/soc/meson/axg-card.c
+++ b/sound/soc/meson/axg-card.c
@@ -100,28 +100,28 @@ static int axg_card_tdm_dai_lb_init(struct snd_soc_pcm_runtime *rtd)
return 0;
}
-static int axg_card_add_tdm_loopback(struct snd_soc_card *card,
+static int axg_card_add_tdm_loopback(struct meson_card *priv,
int *index)
{
- struct meson_card *priv = snd_soc_card_get_drvdata(card);
struct snd_soc_dai_link *pad;
struct snd_soc_dai_link *lb;
struct snd_soc_dai_link_component *dlc;
+ struct device *dev = priv->card.dev;
int ret;
/* extend links */
- ret = meson_card_reallocate_links(card, card->num_links + 1);
+ ret = meson_card_reallocate_links(priv, priv->card.num_links + 1);
if (ret)
return ret;
- pad = &card->dai_link[*index];
- lb = &card->dai_link[*index + 1];
+ pad = &priv->card.dai_link[*index];
+ lb = &priv->card.dai_link[*index + 1];
- lb->name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-lb", pad->name);
+ lb->name = devm_kasprintf(dev, GFP_KERNEL, "%s-lb", pad->name);
if (!lb->name)
return -ENOMEM;
- dlc = devm_kzalloc(card->dev, sizeof(*dlc), GFP_KERNEL);
+ dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
if (!dlc)
return -ENOMEM;
@@ -153,18 +153,19 @@ static int axg_card_add_tdm_loopback(struct snd_soc_card *card,
return 0;
}
-static int axg_card_parse_cpu_tdm_slots(struct snd_soc_card *card,
+static int axg_card_parse_cpu_tdm_slots(struct meson_card *priv,
struct snd_soc_dai_link *link,
struct device_node *node,
struct axg_dai_link_tdm_data *be)
{
+ struct device *dev = priv->card.dev;
char propname[32];
u32 tx, rx;
int i;
- be->tx_mask = devm_kcalloc(card->dev, AXG_TDM_NUM_LANES,
+ be->tx_mask = devm_kcalloc(dev, AXG_TDM_NUM_LANES,
sizeof(*be->tx_mask), GFP_KERNEL);
- be->rx_mask = devm_kcalloc(card->dev, AXG_TDM_NUM_LANES,
+ be->rx_mask = devm_kcalloc(dev, AXG_TDM_NUM_LANES,
sizeof(*be->rx_mask), GFP_KERNEL);
if (!be->tx_mask || !be->rx_mask)
return -ENOMEM;
@@ -191,7 +192,7 @@ static int axg_card_parse_cpu_tdm_slots(struct snd_soc_card *card,
/* ... but the interface should at least have one direction */
if (!tx && !rx) {
- dev_err(card->dev, "tdm link has no cpu slots\n");
+ dev_err(dev, "tdm link has no cpu slots\n");
return -EINVAL;
}
@@ -207,7 +208,7 @@ static int axg_card_parse_cpu_tdm_slots(struct snd_soc_card *card,
* Error if the slots can't accommodate the largest mask or
* if it is just too big
*/
- dev_err(card->dev, "bad slot number\n");
+ dev_err(dev, "bad slot number\n");
return -EINVAL;
}
@@ -216,14 +217,15 @@ static int axg_card_parse_cpu_tdm_slots(struct snd_soc_card *card,
return 0;
}
-static int axg_card_parse_codecs_masks(struct snd_soc_card *card,
+static int axg_card_parse_codecs_masks(struct meson_card *priv,
struct snd_soc_dai_link *link,
struct device_node *node,
struct axg_dai_link_tdm_data *be)
{
struct axg_dai_link_tdm_mask *codec_mask;
+ struct device *dev = priv->card.dev;
- codec_mask = devm_kcalloc(card->dev, link->num_codecs,
+ codec_mask = devm_kcalloc(dev, link->num_codecs,
sizeof(*codec_mask), GFP_KERNEL);
if (!codec_mask)
return -ENOMEM;
@@ -242,17 +244,17 @@ static int axg_card_parse_codecs_masks(struct snd_soc_card *card,
return 0;
}
-static int axg_card_parse_tdm(struct snd_soc_card *card,
+static int axg_card_parse_tdm(struct meson_card *priv,
struct device_node *node,
int *index)
{
- struct meson_card *priv = snd_soc_card_get_drvdata(card);
- struct snd_soc_dai_link *link = &card->dai_link[*index];
+ struct snd_soc_dai_link *link = &priv->card.dai_link[*index];
struct axg_dai_link_tdm_data *be;
+ struct device *dev = priv->card.dev;
int ret;
/* Allocate tdm link parameters */
- be = devm_kzalloc(card->dev, sizeof(*be), GFP_KERNEL);
+ be = devm_kzalloc(dev, sizeof(*be), GFP_KERNEL);
if (!be)
return -ENOMEM;
priv->link_data[*index] = be;
@@ -264,19 +266,19 @@ static int axg_card_parse_tdm(struct snd_soc_card *card,
of_property_read_u32(node, "mclk-fs", &be->mclk_fs);
- ret = axg_card_parse_cpu_tdm_slots(card, link, node, be);
+ ret = axg_card_parse_cpu_tdm_slots(priv, link, node, be);
if (ret) {
- dev_err(card->dev, "error parsing tdm link slots\n");
+ dev_err(dev, "error parsing tdm link slots\n");
return ret;
}
- ret = axg_card_parse_codecs_masks(card, link, node, be);
+ ret = axg_card_parse_codecs_masks(priv, link, node, be);
if (ret)
return ret;
/* Add loopback if the pad dai has playback */
if (!link->capture_only) {
- ret = axg_card_add_tdm_loopback(card, index);
+ ret = axg_card_add_tdm_loopback(priv, index);
if (ret)
return ret;
}
@@ -305,14 +307,15 @@ static int axg_card_cpu_is_codec(struct device_node *np)
of_device_is_compatible(np, DT_PREFIX "g12a-toacodec");
}
-static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np,
+static int axg_card_add_link(struct meson_card *priv, struct device_node *np,
int *index)
{
- struct snd_soc_dai_link *dai_link = &card->dai_link[*index];
+ struct snd_soc_dai_link *dai_link = &priv->card.dai_link[*index];
struct snd_soc_dai_link_component *cpu;
+ struct device *dev = priv->card.dev;
int ret;
- cpu = devm_kzalloc(card->dev, sizeof(*cpu), GFP_KERNEL);
+ cpu = devm_kzalloc(dev, sizeof(*cpu), GFP_KERNEL);
if (!cpu)
return -ENOMEM;
@@ -320,17 +323,17 @@ static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np,
dai_link->num_cpus = 1;
dai_link->nonatomic = true;
- ret = meson_card_parse_dai(card, np, dai_link->cpus);
+ ret = meson_card_parse_dai(priv, np, dai_link->cpus);
if (ret)
return ret;
if (axg_card_cpu_is_playback_fe(dai_link->cpus->of_node))
- return meson_card_set_fe_link(card, dai_link, np, true);
+ return meson_card_set_fe_link(priv, dai_link, np, true);
else if (axg_card_cpu_is_capture_fe(dai_link->cpus->of_node))
- return meson_card_set_fe_link(card, dai_link, np, false);
+ return meson_card_set_fe_link(priv, dai_link, np, false);
- ret = meson_card_set_be_link(card, dai_link, np);
+ ret = meson_card_set_be_link(priv, dai_link, np);
if (ret)
return ret;
@@ -340,7 +343,7 @@ static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np,
} else {
dai_link->no_pcm = 1;
if (axg_card_cpu_is_tdm_iface(dai_link->cpus->of_node))
- ret = axg_card_parse_tdm(card, np, index);
+ ret = axg_card_parse_tdm(priv, np, index);
}
return ret;
diff --git a/sound/soc/meson/gx-card.c b/sound/soc/meson/gx-card.c
index b408cc2bbc919..c0cbf31f28db5 100644
--- a/sound/soc/meson/gx-card.c
+++ b/sound/soc/meson/gx-card.c
@@ -41,16 +41,16 @@ static const struct snd_soc_ops gx_card_i2s_be_ops = {
.hw_params = gx_card_i2s_be_hw_params,
};
-static int gx_card_parse_i2s(struct snd_soc_card *card,
+static int gx_card_parse_i2s(struct meson_card *priv,
struct device_node *node,
int *index)
{
- struct meson_card *priv = snd_soc_card_get_drvdata(card);
- struct snd_soc_dai_link *link = &card->dai_link[*index];
+ struct snd_soc_dai_link *link = &priv->card.dai_link[*index];
struct gx_dai_link_i2s_data *be;
+ struct device *dev = priv->card.dev;
/* Allocate i2s link parameters */
- be = devm_kzalloc(card->dev, sizeof(*be), GFP_KERNEL);
+ be = devm_kzalloc(dev, sizeof(*be), GFP_KERNEL);
if (!be)
return -ENOMEM;
priv->link_data[*index] = be;
@@ -76,28 +76,29 @@ static int gx_card_cpu_identify(struct snd_soc_dai_link_component *c,
return 0;
}
-static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np,
+static int gx_card_add_link(struct meson_card *priv, struct device_node *np,
int *index)
{
- struct snd_soc_dai_link *dai_link = &card->dai_link[*index];
+ struct snd_soc_dai_link *dai_link = &priv->card.dai_link[*index];
struct snd_soc_dai_link_component *cpu;
+ struct device *dev = priv->card.dev;
int ret;
- cpu = devm_kzalloc(card->dev, sizeof(*cpu), GFP_KERNEL);
+ cpu = devm_kzalloc(dev, sizeof(*cpu), GFP_KERNEL);
if (!cpu)
return -ENOMEM;
dai_link->cpus = cpu;
dai_link->num_cpus = 1;
- ret = meson_card_parse_dai(card, np, dai_link->cpus);
+ ret = meson_card_parse_dai(priv, np, dai_link->cpus);
if (ret)
return ret;
if (gx_card_cpu_identify(dai_link->cpus, "FIFO"))
- return meson_card_set_fe_link(card, dai_link, np, true);
+ return meson_card_set_fe_link(priv, dai_link, np, true);
- ret = meson_card_set_be_link(card, dai_link, np);
+ ret = meson_card_set_be_link(priv, dai_link, np);
if (ret)
return ret;
@@ -109,7 +110,7 @@ static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np,
dai_link->no_pcm = 1;
/* Check if the cpu is the i2s encoder and parse i2s data */
if (gx_card_cpu_identify(dai_link->cpus, "I2S Encoder"))
- ret = gx_card_parse_i2s(card, np, index);
+ ret = gx_card_parse_i2s(priv, np, index);
}
return ret;
diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c
index d144ab79b645b..7329711aefa56 100644
--- a/sound/soc/meson/meson-card-utils.c
+++ b/sound/soc/meson/meson-card-utils.c
@@ -39,10 +39,9 @@ int meson_card_i2s_set_sysclk(struct snd_pcm_substream *substream,
}
EXPORT_SYMBOL_GPL(meson_card_i2s_set_sysclk);
-int meson_card_reallocate_links(struct snd_soc_card *card,
+int meson_card_reallocate_links(struct meson_card *priv,
unsigned int num_links)
{
- struct meson_card *priv = snd_soc_card_get_drvdata(card);
struct snd_soc_dai_link *links;
void **ldata;
@@ -67,10 +66,11 @@ int meson_card_reallocate_links(struct snd_soc_card *card,
}
EXPORT_SYMBOL_GPL(meson_card_reallocate_links);
-int meson_card_parse_dai(struct snd_soc_card *card,
+int meson_card_parse_dai(struct meson_card *priv,
struct device_node *node,
struct snd_soc_dai_link_component *dlc)
{
+ struct device *dev = priv->card.dev;
int ret;
if (!dlc || !node)
@@ -78,18 +78,19 @@ int meson_card_parse_dai(struct snd_soc_card *card,
ret = snd_soc_of_get_dlc(node, NULL, dlc, 0);
if (ret)
- return dev_err_probe(card->dev, ret, "can't parse dai\n");
+ return dev_err_probe(dev, ret, "can't parse dai\n");
return ret;
}
EXPORT_SYMBOL_GPL(meson_card_parse_dai);
-static int meson_card_set_link_name(struct snd_soc_card *card,
+static int meson_card_set_link_name(struct meson_card *priv,
struct snd_soc_dai_link *link,
struct device_node *node,
const char *prefix)
{
- char *name = devm_kasprintf(card->dev, GFP_KERNEL, "%s.%s",
+ struct device *dev = priv->card.dev;
+ char *name = devm_kasprintf(dev, GFP_KERNEL, "%s.%s",
prefix, node->full_name);
if (!name)
return -ENOMEM;
@@ -127,21 +128,22 @@ unsigned int meson_card_parse_daifmt(struct device_node *node,
}
EXPORT_SYMBOL_GPL(meson_card_parse_daifmt);
-int meson_card_set_be_link(struct snd_soc_card *card,
+int meson_card_set_be_link(struct meson_card *priv,
struct snd_soc_dai_link *link,
struct device_node *node)
{
struct snd_soc_dai_link_component *codec;
+ struct device *dev = priv->card.dev;
int ret, num_codecs;
num_codecs = of_get_child_count(node);
if (!num_codecs) {
- dev_err(card->dev, "be link %s has no codec\n",
+ dev_err(dev, "be link %s has no codec\n",
node->full_name);
return -EINVAL;
}
- codec = devm_kcalloc(card->dev, num_codecs, sizeof(*codec), GFP_KERNEL);
+ codec = devm_kcalloc(dev, num_codecs, sizeof(*codec), GFP_KERNEL);
if (!codec)
return -ENOMEM;
@@ -149,22 +151,22 @@ int meson_card_set_be_link(struct snd_soc_card *card,
link->num_codecs = num_codecs;
for_each_child_of_node_scoped(node, np) {
- ret = meson_card_parse_dai(card, np, codec);
+ ret = meson_card_parse_dai(priv, np, codec);
if (ret)
return ret;
codec++;
}
- ret = meson_card_set_link_name(card, link, node, "be");
+ ret = meson_card_set_link_name(priv, link, node, "be");
if (ret)
- dev_err(card->dev, "error setting %pOFn link name\n", node);
+ dev_err(dev, "error setting %pOFn link name\n", node);
return ret;
}
EXPORT_SYMBOL_GPL(meson_card_set_be_link);
-int meson_card_set_fe_link(struct snd_soc_card *card,
+int meson_card_set_fe_link(struct meson_card *priv,
struct snd_soc_dai_link *link,
struct device_node *node,
bool is_playback)
@@ -182,29 +184,29 @@ int meson_card_set_fe_link(struct snd_soc_card *card,
else
link->capture_only = 1;
- return meson_card_set_link_name(card, link, node, "fe");
+ return meson_card_set_link_name(priv, link, node, "fe");
}
EXPORT_SYMBOL_GPL(meson_card_set_fe_link);
-static int meson_card_add_links(struct snd_soc_card *card)
+static int meson_card_add_links(struct meson_card *priv)
{
- struct meson_card *priv = snd_soc_card_get_drvdata(card);
- struct device_node *node = card->dev->of_node;
+ struct device *dev = priv->card.dev;
+ struct device_node *node = dev->of_node;
int num, i, ret;
num = of_get_child_count(node);
if (!num) {
- dev_err(card->dev, "card has no links\n");
+ dev_err(dev, "card has no links\n");
return -EINVAL;
}
- ret = meson_card_reallocate_links(card, num);
+ ret = meson_card_reallocate_links(priv, num);
if (ret)
return ret;
i = 0;
for_each_child_of_node_scoped(node, np) {
- ret = priv->match_data->add_link(card, np, &i);
+ ret = priv->match_data->add_link(priv, np, &i);
if (ret)
return ret;
@@ -214,17 +216,19 @@ static int meson_card_add_links(struct snd_soc_card *card)
return 0;
}
-static int meson_card_parse_of_optional(struct snd_soc_card *card,
+static int meson_card_parse_of_optional(struct meson_card *priv,
const char *propname,
int (*func)(struct snd_soc_card *c,
const char *p))
{
+ struct device *dev = priv->card.dev;
+
/* If property is not provided, don't fail ... */
- if (!of_property_present(card->dev->of_node, propname))
+ if (!of_property_present(dev->of_node, propname))
return 0;
/* ... but do fail if it is provided and the parsing fails */
- return func(card, propname);
+ return func(&priv->card, propname);
}
static void meson_card_clean_references(struct meson_card *priv)
@@ -282,25 +286,25 @@ int meson_card_probe(struct platform_device *pdev)
if (ret < 0)
return ret;
- ret = meson_card_parse_of_optional(&priv->card, "audio-routing",
+ ret = meson_card_parse_of_optional(priv, "audio-routing",
snd_soc_of_parse_audio_routing);
if (ret) {
dev_err(dev, "error while parsing routing\n");
return ret;
}
- ret = meson_card_parse_of_optional(&priv->card, "audio-widgets",
+ ret = meson_card_parse_of_optional(priv, "audio-widgets",
snd_soc_of_parse_audio_simple_widgets);
if (ret) {
dev_err(dev, "error while parsing widgets\n");
return ret;
}
- ret = meson_card_add_links(&priv->card);
+ ret = meson_card_add_links(priv);
if (ret)
goto out_err;
- ret = meson_card_parse_of_optional(&priv->card, "audio-aux-devs",
+ ret = meson_card_parse_of_optional(priv, "audio-aux-devs",
snd_soc_of_parse_aux_devs);
if (ret)
goto out_err;
diff --git a/sound/soc/meson/meson-card.h b/sound/soc/meson/meson-card.h
index a0d693e4f4608..ce8d9042793bb 100644
--- a/sound/soc/meson/meson-card.h
+++ b/sound/soc/meson/meson-card.h
@@ -16,8 +16,9 @@ struct snd_pcm_hw_params;
#define DT_PREFIX "amlogic,"
+struct meson_card;
struct meson_card_match_data {
- int (*add_link)(struct snd_soc_card *card,
+ int (*add_link)(struct meson_card *priv,
struct device_node *node,
int *index);
};
@@ -35,15 +36,15 @@ int meson_card_i2s_set_sysclk(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
unsigned int mclk_fs);
-int meson_card_reallocate_links(struct snd_soc_card *card,
+int meson_card_reallocate_links(struct meson_card *priv,
unsigned int num_links);
-int meson_card_parse_dai(struct snd_soc_card *card,
+int meson_card_parse_dai(struct meson_card *priv,
struct device_node *node,
struct snd_soc_dai_link_component *dlc);
-int meson_card_set_be_link(struct snd_soc_card *card,
+int meson_card_set_be_link(struct meson_card *priv,
struct snd_soc_dai_link *link,
struct device_node *node);
-int meson_card_set_fe_link(struct snd_soc_card *card,
+int meson_card_set_fe_link(struct meson_card *priv,
struct snd_soc_dai_link *link,
struct device_node *node,
bool is_playback);
--
2.53.0
More information about the linux-arm-kernel
mailing list