Skip to contentSkip to conversation

ASoC: simple-card: simplify code

PATCH Applied Jean-Francois Moine 2 participants 16 messages Jan 15, 2014 – Jan 22, 2014 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20140115113551.0eb13409@armhf

#1 lore raw

PATCH v2 1/8 ASoC: simple-card: simplify code

The check of the mandatory fields is done for DT in its specific sequence. Move the global check to the non-DT sequence.

---
 sound/soc/generic/simple-card.c      | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
sound/soc/generic/simple-card.c +9 -9
index 2a1b1b5..f0784ca 100644
@@ -225,16 +225,16 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 
 		memcpy(cinfo, dev->platform_data, sizeof(*cinfo));
 		cinfo->snd_card.dev = dev;
-	}
 
-	if (!cinfo->name	||
-	    !cinfo->card	||
-	    !cinfo->codec_dai.name	||
-	    !(cinfo->codec		|| of_codec)	||
-	    !(cinfo->platform		|| of_platform)	||
-	    !(cinfo->cpu_dai.name	|| of_cpu)) {
-		dev_err(dev, "insufficient asoc_simple_card_info settings\n");
-		return -EINVAL;
+		if (!cinfo->name	||
+		    !cinfo->card	||
+		    !cinfo->codec_dai.name	||
+		    !cinfo->codec	||
+		    !cinfo->platform	||
+		    !cinfo->cpu_dai.name) {
+			dev_err(dev, "insufficient asoc_simple_card_info settings\n");
+			return -EINVAL;
+		}
 	}
 
 	/*
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#2 lore raw
Quoted 2 lines · Jean-Francois Moine

The check of the mandatory fields is done for DT in its specific sequence. Move the global check to the non-DT sequence.

Applied, thanks.

#3 lore raw

PATCH v2 2/8 ASoC: simple-card: simplify code

In reply to a message not in the archive

The DT values are copied to the non-DT structure before being moved to the card structure.
Set directly the DT values in the card and move the non-DT copy to the non-DT sequence.

---
 sound/soc/generic/simple-card.c     | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
sound/soc/generic/simple-card.c +12 -10
index f0784ca..7c5dc73 100644
@@ -169,12 +169,13 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 			    strlen(info->codec_dai.name) + 2,
 			    GFP_KERNEL);
 	sprintf(name, "%s-%s", info->cpu_dai.name, info->codec_dai.name);
-	info->name = info->card = name;
+	info->snd_card.name = name;
+	info->snd_link.name = info->snd_link.stream_name = name;
 
 	/* simple-card assumes platform == cpu */
 	*of_platform = *of_cpu;
 
-	dev_dbg(dev, "card-name : %s\n", info->card);
+	dev_dbg(dev, "card-name : %s\n", name);
 	dev_dbg(dev, "platform : %04x\n", info->daifmt);
 	dev_dbg(dev, "cpu : %s / %04x / %d\n",
 		info->cpu_dai.name,
@@ -217,6 +218,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 				dev_err(dev, "parse error %d\n", ret);
 			return ret;
 		}
+		cinfo->snd_link.cpu_of_node	= of_cpu;
+		cinfo->snd_link.codec_of_node	= of_codec;
+		cinfo->snd_link.platform_of_node = of_platform;
 	} else {
 		if (!dev->platform_data) {
 			dev_err(dev, "no info for asoc-simple-card\n");
@@ -235,26 +239,24 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 			dev_err(dev, "insufficient asoc_simple_card_info settings\n");
 			return -EINVAL;
 		}
+
+		cinfo->snd_card.name		= cinfo->card;
+		cinfo->snd_link.name		= cinfo->name;
+		cinfo->snd_link.stream_name	= cinfo->name;
+		cinfo->snd_link.platform_name	= cinfo->platform;
+		cinfo->snd_link.codec_name	= cinfo->codec;
 	}
 
 	/*
 	 * init snd_soc_dai_link
 	 */
-	cinfo->snd_link.name		= cinfo->name;
-	cinfo->snd_link.stream_name	= cinfo->name;
 	cinfo->snd_link.cpu_dai_name	= cinfo->cpu_dai.name;
-	cinfo->snd_link.platform_name	= cinfo->platform;
-	cinfo->snd_link.codec_name	= cinfo->codec;
 	cinfo->snd_link.codec_dai_name	= cinfo->codec_dai.name;
-	cinfo->snd_link.cpu_of_node	= of_cpu;
-	cinfo->snd_link.codec_of_node	= of_codec;
-	cinfo->snd_link.platform_of_node = of_platform;
 	cinfo->snd_link.init		= asoc_simple_card_dai_init;
 
 	/*
 	 * init snd_soc_card
 	 */
-	cinfo->snd_card.name		= cinfo->card;
 	cinfo->snd_card.owner		= THIS_MODULE;
 	cinfo->snd_card.dai_link	= &cinfo->snd_link;
 	cinfo->snd_card.num_links	= 1;
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#4 lore raw
Quoted 4 lines · Jean-Francois Moine

The DT values are copied to the non-DT structure before being moved to the card structure.
Set directly the DT values in the card and move the non-DT copy to the non-DT sequence.

Applied, thanks. Every patch in this series seems to have the same subject line - please don't do that, it makes things harder to work with.

#5 lore raw

PATCH v2 3/8 ASoC: simple-card: simplify code

In reply to a message not in the archive

The OF pointers are put in the stack and then copied to the card descriptor.
Put them directly at their right place.

---
 sound/soc/generic/simple-card.c     | 55 ++++++++--------------
 1 file changed, 20 insertions(+), 35 deletions(-)
sound/soc/generic/simple-card.c +20 -35
index 7c5dc73..89f83b3 100644
@@ -60,8 +60,9 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
 static int
 asoc_simple_card_sub_parse_of(struct device_node *np,
 			      struct asoc_simple_dai *dai,
-			      struct device_node **node)
+			      const struct device_node **p_node)
 {
+	struct device_node *node;
 	struct clk *clk;
 	int ret;
 
@@ -69,9 +70,10 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
 	 * get node via "sound-dai = <&phandle port>"
 	 * it will be used as xxx_of_node on soc_bind_dai_link()
 	 */
-	*node = of_parse_phandle(np, "sound-dai", 0);
-	if (!*node)
+	node = of_parse_phandle(np, "sound-dai", 0);
+	if (!node)
 		return -ENODEV;
+	*p_node = node;
 
 	/* get dai->name */
 	ret = snd_soc_of_get_dai_name(np, &dai->name);
@@ -104,7 +106,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
 				     "system-clock-frequency",
 				     &dai->sysclk);
 	} else {
-		clk = of_clk_get(*node, 0);
+		clk = of_clk_get(node, 0);
 		if (!IS_ERR(clk))
 			dai->sysclk = clk_get_rate(clk);
 	}
@@ -112,17 +114,14 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
 	ret = 0;
 
 parse_error:
-	of_node_put(*node);
+	of_node_put(node);
 
 	return ret;
 }
 
 static int asoc_simple_card_parse_of(struct device_node *node,
 				     struct asoc_simple_card_info *info,
-				     struct device *dev,
-				     struct device_node **of_cpu,
-				     struct device_node **of_codec,
-				     struct device_node **of_platform)
+				     struct device *dev)
 {
 	struct device_node *np;
 	char *name;
@@ -146,7 +145,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
 						  &info->cpu_dai,
-						  of_cpu);
+						  &info->snd_link.cpu_of_node);
 	if (ret < 0)
 		return ret;
 
@@ -156,7 +155,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
 						  &info->codec_dai,
-						  of_codec);
+						  &info->snd_link.codec_of_node);
 	if (ret < 0)
 		return ret;
 
@@ -173,7 +172,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	info->snd_link.name = info->snd_link.stream_name = name;
 
 	/* simple-card assumes platform == cpu */
-	*of_platform = *of_cpu;
+	info->snd_link.platform_of_node = info->snd_link.cpu_of_node;
 
 	dev_dbg(dev, "card-name : %s\n", name);
 	dev_dbg(dev, "platform : %04x\n", info->daifmt);
@@ -193,34 +192,29 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 {
 	struct asoc_simple_card_info *cinfo;
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *of_cpu, *of_codec, *of_platform;
 	struct device *dev = &pdev->dev;
 	int ret;
 
-	cinfo		= NULL;
-	of_cpu		= NULL;
-	of_codec	= NULL;
-	of_platform	= NULL;
-
 	cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL);
 	if (!cinfo)
 		return -ENOMEM;
 
+	/*
+	 * init snd_soc_card
+	 */
+	cinfo->snd_card.owner		= THIS_MODULE;
+	cinfo->snd_card.dev = dev;
+	cinfo->snd_card.dai_link	= &cinfo->snd_link;
+	cinfo->snd_card.num_links	= 1;
+
 	if (np && of_device_is_available(np)) {
-		cinfo->snd_card.dev = dev;
 
-		ret = asoc_simple_card_parse_of(np, cinfo, dev,
-						&of_cpu,
-						&of_codec,
-						&of_platform);
+		ret = asoc_simple_card_parse_of(np, cinfo, dev);
 		if (ret < 0) {
 			if (ret != -EPROBE_DEFER)
 				dev_err(dev, "parse error %d\n", ret);
 			return ret;
 		}
-		cinfo->snd_link.cpu_of_node	= of_cpu;
-		cinfo->snd_link.codec_of_node	= of_codec;
-		cinfo->snd_link.platform_of_node = of_platform;
 	} else {
 		if (!dev->platform_data) {
 			dev_err(dev, "no info for asoc-simple-card\n");
@@ -228,8 +222,6 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 		}
 
 		memcpy(cinfo, dev->platform_data, sizeof(*cinfo));
-		cinfo->snd_card.dev = dev;
-
 		if (!cinfo->name	||
 		    !cinfo->card	||
 		    !cinfo->codec_dai.name	||
@@ -254,13 +246,6 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 	cinfo->snd_link.codec_dai_name	= cinfo->codec_dai.name;
 	cinfo->snd_link.init		= asoc_simple_card_dai_init;
 
-	/*
-	 * init snd_soc_card
-	 */
-	cinfo->snd_card.owner		= THIS_MODULE;
-	cinfo->snd_card.dai_link	= &cinfo->snd_link;
-	cinfo->snd_card.num_links	= 1;
-
 	snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo);
 
 	return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card);
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#6 lore raw
Quoted 3 lines · Jean-Francois Moine

The OF pointers are put in the stack and then copied to the card descriptor.
Put them directly at their right place.

Applied, thanks.

#7 lore raw

PATCH v2 4/8 ASoC: simple-card: simplify code

In reply to a message not in the archive

Have a cleaner code using a DAI link pointer.

---
 sound/soc/generic/simple-card.c     | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)
sound/soc/generic/simple-card.c +16 -13
index 89f83b3..797696f 100644
@@ -123,6 +123,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 				     struct asoc_simple_card_info *info,
 				     struct device *dev)
 {
+	struct snd_soc_dai_link *dai_link = info->snd_card.dai_link;
 	struct device_node *np;
 	char *name;
 	int ret;
@@ -145,7 +146,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
 						  &info->cpu_dai,
-						  &info->snd_link.cpu_of_node);
+						  &dai_link->cpu_of_node);
 	if (ret < 0)
 		return ret;
 
@@ -155,7 +156,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
 						  &info->codec_dai,
-						  &info->snd_link.codec_of_node);
+						  &dai_link->codec_of_node);
 	if (ret < 0)
 		return ret;
 
@@ -169,10 +170,10 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 			    GFP_KERNEL);
 	sprintf(name, "%s-%s", info->cpu_dai.name, info->codec_dai.name);
 	info->snd_card.name = name;
-	info->snd_link.name = info->snd_link.stream_name = name;
+	dai_link->name = dai_link->stream_name = name;
 
 	/* simple-card assumes platform == cpu */
-	info->snd_link.platform_of_node = info->snd_link.cpu_of_node;
+	dai_link->platform_of_node = dai_link->cpu_of_node;
 
 	dev_dbg(dev, "card-name : %s\n", name);
 	dev_dbg(dev, "platform : %04x\n", info->daifmt);
@@ -191,6 +192,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 static int asoc_simple_card_probe(struct platform_device *pdev)
 {
 	struct asoc_simple_card_info *cinfo;
+	struct snd_soc_dai_link *dai_link;
 	struct device_node *np = pdev->dev.of_node;
 	struct device *dev = &pdev->dev;
 	int ret;
@@ -204,8 +206,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 	 */
 	cinfo->snd_card.owner		= THIS_MODULE;
 	cinfo->snd_card.dev = dev;
-	cinfo->snd_card.dai_link	= &cinfo->snd_link;
-	cinfo->snd_card.num_links	= 1;
+	dai_link = &cinfo->snd_link;
+	cinfo->snd_card.dai_link = dai_link;
+	cinfo->snd_card.num_links = 1;
 
 	if (np && of_device_is_available(np)) {
 
@@ -233,18 +236,18 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 		}
 
 		cinfo->snd_card.name		= cinfo->card;
-		cinfo->snd_link.name		= cinfo->name;
-		cinfo->snd_link.stream_name	= cinfo->name;
-		cinfo->snd_link.platform_name	= cinfo->platform;
-		cinfo->snd_link.codec_name	= cinfo->codec;
+		dai_link->name		= cinfo->name;
+		dai_link->stream_name	= cinfo->name;
+		dai_link->platform_name	= cinfo->platform;
+		dai_link->codec_name	= cinfo->codec;
 	}
 
 	/*
 	 * init snd_soc_dai_link
 	 */
-	cinfo->snd_link.cpu_dai_name	= cinfo->cpu_dai.name;
-	cinfo->snd_link.codec_dai_name	= cinfo->codec_dai.name;
-	cinfo->snd_link.init		= asoc_simple_card_dai_init;
+	dai_link->cpu_dai_name	= cinfo->cpu_dai.name;
+	dai_link->codec_dai_name = cinfo->codec_dai.name;
+	dai_link->init = asoc_simple_card_dai_init;
 
 	snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo);
 
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#8 lore raw
Quoted 1 line · Jean-Francois Moine

Have a cleaner code using a DAI link pointer.

Applied, thanks.

#9 lore raw

PATCH v2 5/8 ASoC: simple-card: simplify code

In reply to a message not in the archive

The CPU and CODEC DAI names are still copied to the user info structure. Put them directly in the DAI links.

---
 sound/soc/generic/simple-card.c     | 28 ++++++++++++----------
 1 file changed, 16 insertions(+), 12 deletions(-)
sound/soc/generic/simple-card.c +16 -12
index 797696f..9068ab4 100644
@@ -60,7 +60,8 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
 static int
 asoc_simple_card_sub_parse_of(struct device_node *np,
 			      struct asoc_simple_dai *dai,
-			      const struct device_node **p_node)
+			      const struct device_node **p_node,
+			      const char **name)
 {
 	struct device_node *node;
 	struct clk *clk;
@@ -76,7 +77,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
 	*p_node = node;
 
 	/* get dai->name */
-	ret = snd_soc_of_get_dai_name(np, &dai->name);
+	ret = snd_soc_of_get_dai_name(np, name);
 	if (ret < 0)
 		goto parse_error;
 
@@ -146,7 +147,8 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
 						  &info->cpu_dai,
-						  &dai_link->cpu_of_node);
+						  &dai_link->cpu_of_node,
+						  &dai_link->cpu_dai_name);
 	if (ret < 0)
 		return ret;
 
@@ -156,19 +158,21 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
 						  &info->codec_dai,
-						  &dai_link->codec_of_node);
+						  &dai_link->codec_of_node,
+						  &dai_link->codec_dai_name);
 	if (ret < 0)
 		return ret;
 
-	if (!info->cpu_dai.name || !info->codec_dai.name)
+	if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name)
 		return -EINVAL;
 
 	/* card name is created from CPU/CODEC dai name */
 	name = devm_kzalloc(dev,
-			    strlen(info->cpu_dai.name)   +
-			    strlen(info->codec_dai.name) + 2,
+			    strlen(dai_link->cpu_dai_name)   +
+			    strlen(dai_link->codec_dai_name) + 2,
 			    GFP_KERNEL);
-	sprintf(name, "%s-%s", info->cpu_dai.name, info->codec_dai.name);
+	sprintf(name, "%s-%s", dai_link->cpu_dai_name,
+				dai_link->codec_dai_name);
 	info->snd_card.name = name;
 	dai_link->name = dai_link->stream_name = name;
 
@@ -178,11 +182,11 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	dev_dbg(dev, "card-name : %s\n", name);
 	dev_dbg(dev, "platform : %04x\n", info->daifmt);
 	dev_dbg(dev, "cpu : %s / %04x / %d\n",
-		info->cpu_dai.name,
+		dai_link->cpu_dai_name,
 		info->cpu_dai.fmt,
 		info->cpu_dai.sysclk);
 	dev_dbg(dev, "codec : %s / %04x / %d\n",
-		info->codec_dai.name,
+		dai_link->codec_dai_name,
 		info->codec_dai.fmt,
 		info->codec_dai.sysclk);
 
@@ -240,13 +244,13 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 		dai_link->stream_name	= cinfo->name;
 		dai_link->platform_name	= cinfo->platform;
 		dai_link->codec_name	= cinfo->codec;
+		dai_link->cpu_dai_name	= cinfo->cpu_dai.name;
+		dai_link->codec_dai_name = cinfo->codec_dai.name;
 	}
 
 	/*
 	 * init snd_soc_dai_link
 	 */
-	dai_link->cpu_dai_name	= cinfo->cpu_dai.name;
-	dai_link->codec_dai_name = cinfo->codec_dai.name;
 	dai_link->init = asoc_simple_card_dai_init;
 
 	snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo);
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#10 lore raw
Quoted 2 lines · Jean-Francois Moine

The CPU and CODEC DAI names are still copied to the user info structure. Put them directly in the DAI links.

Applied, thanks.

#11 lore raw

PATCH v2 6/8 ASoC: simple-card: simplify code

In reply to a message not in the archive

In the non-DT sequence, the platform data is copied as a whole to the dynamic card info and the same pointer 'cinfo' is used to copy the platform information to the card.

Use 'priv' as the pointer to the dynamic card info and copy only the useful information from the platform data.

---
 sound/soc/generic/simple-card.c     | 34 +++++++++++++---------
 1 file changed, 20 insertions(+), 14 deletions(-)
sound/soc/generic/simple-card.c +20 -14
index 9068ab4..90c6fd5 100644
@@ -195,40 +195,42 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 
 static int asoc_simple_card_probe(struct platform_device *pdev)
 {
-	struct asoc_simple_card_info *cinfo;
+	struct asoc_simple_card_info *priv;
 	struct snd_soc_dai_link *dai_link;
 	struct device_node *np = pdev->dev.of_node;
 	struct device *dev = &pdev->dev;
 	int ret;
 
-	cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL);
-	if (!cinfo)
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
 		return -ENOMEM;
 
 	/*
 	 * init snd_soc_card
 	 */
-	cinfo->snd_card.owner		= THIS_MODULE;
-	cinfo->snd_card.dev = dev;
-	dai_link = &cinfo->snd_link;
-	cinfo->snd_card.dai_link = dai_link;
-	cinfo->snd_card.num_links = 1;
+	priv->snd_card.owner = THIS_MODULE;
+	priv->snd_card.dev = dev;
+	dai_link = &priv->snd_link;
+	priv->snd_card.dai_link = dai_link;
+	priv->snd_card.num_links = 1;
 
 	if (np && of_device_is_available(np)) {
 
-		ret = asoc_simple_card_parse_of(np, cinfo, dev);
+		ret = asoc_simple_card_parse_of(np, priv, dev);
 		if (ret < 0) {
 			if (ret != -EPROBE_DEFER)
 				dev_err(dev, "parse error %d\n", ret);
 			return ret;
 		}
 	} else {
-		if (!dev->platform_data) {
+		struct asoc_simple_card_info *cinfo;
+
+		cinfo = dev->platform_data;
+		if (!cinfo) {
 			dev_err(dev, "no info for asoc-simple-card\n");
 			return -EINVAL;
 		}
 
-		memcpy(cinfo, dev->platform_data, sizeof(*cinfo));
 		if (!cinfo->name	||
 		    !cinfo->card	||
 		    !cinfo->codec_dai.name	||
@@ -239,13 +241,17 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 			return -EINVAL;
 		}
 
-		cinfo->snd_card.name		= cinfo->card;
+		priv->snd_card.name	= cinfo->card;
 		dai_link->name		= cinfo->name;
 		dai_link->stream_name	= cinfo->name;
 		dai_link->platform_name	= cinfo->platform;
 		dai_link->codec_name	= cinfo->codec;
 		dai_link->cpu_dai_name	= cinfo->cpu_dai.name;
 		dai_link->codec_dai_name = cinfo->codec_dai.name;
+		memcpy(&priv->cpu_dai, &cinfo->cpu_dai,
+						sizeof(priv->cpu_dai));
+		memcpy(&priv->codec_dai, &cinfo->codec_dai,
+						sizeof(priv->codec_dai));
 	}
 
 	/*
@@ -253,9 +259,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 	 */
 	dai_link->init = asoc_simple_card_dai_init;
 
-	snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo);
+	snd_soc_card_set_drvdata(&priv->snd_card, priv);
 
-	return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card);
+	return devm_snd_soc_register_card(&pdev->dev, &priv->snd_card);
 }
 
 static const struct of_device_id asoc_simple_of_match[] = {
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#12 lore raw
Quoted 3 lines · Jean-Francois Moine

In the non-DT sequence, the platform data is copied as a whole to the dynamic card info and the same pointer 'cinfo' is used to copy the platform information to the card.

Applied, thanks.

#13 lore raw

PATCH v2 7/8 ASoC: simple-card: simplify code

In reply to a message not in the archive

The platform data structure contains information which is used only by the driver, and the driver allocates platform information fields which are of no use.
Move the driver specific data to a new private structure and cleanup the platform data structure.

---
 include/sound/simple_card.h     |  4 --
 sound/soc/generic/simple-card.c | 14 +++++++++++---
 2 files changed, 11 insertions(+), 7 deletions(-)
include/sound/simple_card.h +0 -4
index 6c74527..e1ac996 100644
@@ -29,10 +29,6 @@ struct asoc_simple_card_info {
 	unsigned int daifmt;
 	struct asoc_simple_dai cpu_dai;
 	struct asoc_simple_dai codec_dai;
-
-	/* used in simple-card.c */
-	struct snd_soc_dai_link snd_link;
-	struct snd_soc_card snd_card;
 };
 
 #endif /* __SIMPLE_CARD_H */
sound/soc/generic/simple-card.c +11 -3
index 90c6fd5..0f11c28 100644
@@ -15,6 +15,14 @@
 #include <linux/string.h>
 #include <sound/simple_card.h>
 
+struct simple_card_data {
+	struct snd_soc_card snd_card;
+	unsigned int daifmt;
+	struct asoc_simple_dai cpu_dai;
+	struct asoc_simple_dai codec_dai;
+	struct snd_soc_dai_link snd_link;
+};
+
 static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
 				       struct asoc_simple_dai *set,
 				       unsigned int daifmt)
@@ -39,7 +47,7 @@ static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
 
 static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
 {
-	struct asoc_simple_card_info *info =
+	struct simple_card_data *info =
 				snd_soc_card_get_drvdata(rtd->card);
 	struct snd_soc_dai *codec = rtd->codec_dai;
 	struct snd_soc_dai *cpu = rtd->cpu_dai;
@@ -121,7 +129,7 @@ parse_error:
 }
 
 static int asoc_simple_card_parse_of(struct device_node *node,
-				     struct asoc_simple_card_info *info,
+				     struct simple_card_data *info,
 				     struct device *dev)
 {
 	struct snd_soc_dai_link *dai_link = info->snd_card.dai_link;
@@ -195,7 +203,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 
 static int asoc_simple_card_probe(struct platform_device *pdev)
 {
-	struct asoc_simple_card_info *priv;
+	struct simple_card_data *priv;
 	struct snd_soc_dai_link *dai_link;
 	struct device_node *np = pdev->dev.of_node;
 	struct device *dev = &pdev->dev;
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#14 lore raw
Quoted 3 lines · Jean-Francois Moine

The platform data structure contains information which is used only by the driver, and the driver allocates platform information fields which are of no use.

Applied, thanks.

#15 lore raw

PATCH v2 8/8 ASoC: simple-card: simplify code

In reply to a message not in the archive

Rename the pointer to the private data structure to 'priv' to avoid confusion with the platform data pointer.

---
 sound/soc/generic/simple-card.c     | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)
sound/soc/generic/simple-card.c +16 -16
index 0f11c28..6443c87 100644
@@ -47,18 +47,18 @@ static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
 
 static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
 {
-	struct simple_card_data *info =
+	struct simple_card_data *priv =
 				snd_soc_card_get_drvdata(rtd->card);
 	struct snd_soc_dai *codec = rtd->codec_dai;
 	struct snd_soc_dai *cpu = rtd->cpu_dai;
-	unsigned int daifmt = info->daifmt;
+	unsigned int daifmt = priv->daifmt;
 	int ret;
 
-	ret = __asoc_simple_card_dai_init(codec, &info->codec_dai, daifmt);
+	ret = __asoc_simple_card_dai_init(codec, &priv->codec_dai, daifmt);
 	if (ret < 0)
 		return ret;
 
-	ret = __asoc_simple_card_dai_init(cpu, &info->cpu_dai, daifmt);
+	ret = __asoc_simple_card_dai_init(cpu, &priv->cpu_dai, daifmt);
 	if (ret < 0)
 		return ret;
 
@@ -129,21 +129,21 @@ parse_error:
 }
 
 static int asoc_simple_card_parse_of(struct device_node *node,
-				     struct simple_card_data *info,
+				     struct simple_card_data *priv,
 				     struct device *dev)
 {
-	struct snd_soc_dai_link *dai_link = info->snd_card.dai_link;
+	struct snd_soc_dai_link *dai_link = priv->snd_card.dai_link;
 	struct device_node *np;
 	char *name;
 	int ret;
 
 	/* get CPU/CODEC common format via simple-audio-card,format */
-	info->daifmt = snd_soc_of_parse_daifmt(node, "simple-audio-card,") &
+	priv->daifmt = snd_soc_of_parse_daifmt(node, "simple-audio-card,") &
 		(SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK);
 
 	/* DAPM routes */
 	if (of_property_read_bool(node, "simple-audio-card,routing")) {
-		ret = snd_soc_of_parse_audio_routing(&info->snd_card,
+		ret = snd_soc_of_parse_audio_routing(&priv->snd_card,
 					"simple-audio-card,routing");
 		if (ret)
 			return ret;
@@ -154,7 +154,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	np = of_get_child_by_name(node, "simple-audio-card,cpu");
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
-						  &info->cpu_dai,
+						  &priv->cpu_dai,
 						  &dai_link->cpu_of_node,
 						  &dai_link->cpu_dai_name);
 	if (ret < 0)
@@ -165,7 +165,7 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 	np = of_get_child_by_name(node, "simple-audio-card,codec");
 	if (np)
 		ret = asoc_simple_card_sub_parse_of(np,
-						  &info->codec_dai,
+						  &priv->codec_dai,
 						  &dai_link->codec_of_node,
 						  &dai_link->codec_dai_name);
 	if (ret < 0)
@@ -181,22 +181,22 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 			    GFP_KERNEL);
 	sprintf(name, "%s-%s", dai_link->cpu_dai_name,
 				dai_link->codec_dai_name);
-	info->snd_card.name = name;
+	priv->snd_card.name = name;
 	dai_link->name = dai_link->stream_name = name;
 
 	/* simple-card assumes platform == cpu */
 	dai_link->platform_of_node = dai_link->cpu_of_node;
 
 	dev_dbg(dev, "card-name : %s\n", name);
-	dev_dbg(dev, "platform : %04x\n", info->daifmt);
+	dev_dbg(dev, "platform : %04x\n", priv->daifmt);
 	dev_dbg(dev, "cpu : %s / %04x / %d\n",
 		dai_link->cpu_dai_name,
-		info->cpu_dai.fmt,
-		info->cpu_dai.sysclk);
+		priv->cpu_dai.fmt,
+		priv->cpu_dai.sysclk);
 	dev_dbg(dev, "codec : %s / %04x / %d\n",
 		dai_link->codec_dai_name,
-		info->codec_dai.fmt,
-		info->codec_dai.sysclk);
+		priv->codec_dai.fmt,
+		priv->codec_dai.sysclk);
 
 	return 0;
 }
Signature · 2 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
maintainer Applied
#16 lore raw
Quoted 1 line · Jean-Francois Moine

Rename the pointer to the private data structure to 'priv' to avoid confusion with the platform data pointer.

Applied, thanks.