Skip to contentSkip to conversation

ASoC: qcom: Use qcom_snd_parse_of() for apq8016_sbc

PATCH In review Stephan Gerhold 3 participants 10 messages Jul 23, 2020 – Jul 24, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ASoC: qcom: Use qcom_snd_parse_of() for apq8016_sbc

At the moment we have two separate functions to parse the sound card properties from the device tree: qcom_snd_parse_of() for DPCM and apq8016_sbc_parse_of() without DPCM. These functions are almost identical except for a few minor differences.

This patch set extends qcom_snd_parse_of() to handle links without DPCM, so that we can use one common function for all (qcom) machine drivers.

Stephan Gerhold (7):
ASoC: qcom: Use devm for resource management
ASoC: qcom: common: Use snd_soc_dai_link_set_capabilities()
ASoC: q6afe: Remove unused q6afe_is_rx_port() function
ASoC: qcom: common: Support parsing links without DPCM
ASoC: qcom: common: Parse properties with "qcom," prefix
ASoC: qcom: apq8016_sbc: Use qcom_snd_parse_of()
ASoC: qcom: common: Avoid printing errors for -EPROBE_DEFER

 sound/soc/qcom/Kconfig       |   1 +
 sound/soc/qcom/apq8016_sbc.c | 120 ++++-------------------------------
 sound/soc/qcom/apq8096.c     |  28 +-------
 sound/soc/qcom/common.c      |  58 ++++++++++-------
 sound/soc/qcom/qdsp6/q6afe.c |   8 ---
 sound/soc/qcom/qdsp6/q6afe.h |   1 -
 sound/soc/qcom/sdm845.c      |  40 ++----------
 7 files changed, 59 insertions(+), 197 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/7 ASoC: qcom: Use devm for resource management

Simplify the machine drivers for newer SoCs a bit by using the devm_* function calls that automatically release the resources when the driver is removed or when probing fails.

Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/qcom/apq8096.c | 28 +++-------------------------
 sound/soc/qcom/common.c  |  3 +--
 sound/soc/qcom/sdm845.c  | 40 ++++++----------------------------------
 3 files changed, 10 insertions(+), 61 deletions(-)
sound/soc/qcom/apq8096.c +3 -25
index 287ad2aa27f3..134f5a81df7f 100644
@@ -109,7 +109,7 @@ static int apq8096_platform_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	int ret;
 
-	card = kzalloc(sizeof(*card), GFP_KERNEL);
+	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
 	if (!card)
 		return -ENOMEM;
 
@@ -117,31 +117,10 @@ static int apq8096_platform_probe(struct platform_device *pdev)
 	dev_set_drvdata(dev, card);
 	ret = qcom_snd_parse_of(card);
 	if (ret)
-		goto err;
+		return ret;
 
 	apq8096_add_be_ops(card);
-	ret = snd_soc_register_card(card);
-	if (ret)
-		goto err_card_register;
-
-	return 0;
-
-err_card_register:
-	kfree(card->dai_link);
-err:
-	kfree(card);
-	return ret;
-}
-
-static int apq8096_platform_remove(struct platform_device *pdev)
-{
-	struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
-
-	snd_soc_unregister_card(card);
-	kfree(card->dai_link);
-	kfree(card);
-
-	return 0;
+	return devm_snd_soc_register_card(dev, card);
 }
 
 static const struct of_device_id msm_snd_apq8096_dt_match[] = {
@@ -153,7 +132,6 @@ MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);
 
 static struct platform_driver msm_snd_apq8096_driver = {
 	.probe  = apq8096_platform_probe,
-	.remove = apq8096_platform_remove,
 	.driver = {
 		.name = "msm-snd-apq8096",
 		.of_match_table = msm_snd_apq8096_dt_match,
sound/soc/qcom/common.c +1 -2
index 8ada4ecba847..d677e83828af 100644
@@ -36,7 +36,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 	num_links = of_get_child_count(dev->of_node);
 
 	/* Allocate the DAI link array */
-	card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
+	card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL);
 	if (!card->dai_link)
 		return -ENOMEM;
 
@@ -143,7 +143,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 	of_node_put(cpu);
 	of_node_put(codec);
 	of_node_put(platform);
-	kfree(card->dai_link);
 	return ret;
 }
 EXPORT_SYMBOL(qcom_snd_parse_of);
sound/soc/qcom/sdm845.c +6 -34
index 68e9388ff46f..580acfaf38e7 100644
@@ -543,16 +543,14 @@ static int sdm845_snd_platform_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	int ret;
 
-	card = kzalloc(sizeof(*card), GFP_KERNEL);
+	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
 	if (!card)
 		return -ENOMEM;
 
 	/* Allocate the private data */
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
-	if (!data) {
-		ret = -ENOMEM;
-		goto data_alloc_fail;
-	}
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
 
 	card->dapm_widgets = sdm845_snd_widgets;
 	card->num_dapm_widgets = ARRAY_SIZE(sdm845_snd_widgets);
@@ -560,38 +558,13 @@ static int sdm845_snd_platform_probe(struct platform_device *pdev)
 	dev_set_drvdata(dev, card);
 	ret = qcom_snd_parse_of(card);
 	if (ret)
-		goto parse_dt_fail;
+		return ret;
 
 	data->card = card;
 	snd_soc_card_set_drvdata(card, data);
 
 	sdm845_add_ops(card);
-	ret = snd_soc_register_card(card);
-	if (ret) {
-		dev_err(dev, "Sound card registration failed\n");
-		goto register_card_fail;
-	}
-	return ret;
-
-register_card_fail:
-	kfree(card->dai_link);
-parse_dt_fail:
-	kfree(data);
-data_alloc_fail:
-	kfree(card);
-	return ret;
-}
-
-static int sdm845_snd_platform_remove(struct platform_device *pdev)
-{
-	struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
-	struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card);
-
-	snd_soc_unregister_card(card);
-	kfree(card->dai_link);
-	kfree(data);
-	kfree(card);
-	return 0;
+	return devm_snd_soc_register_card(dev, card);
 }
 
 static const struct of_device_id sdm845_snd_device_id[]  = {
@@ -604,7 +577,6 @@ MODULE_DEVICE_TABLE(of, sdm845_snd_device_id);
 
 static struct platform_driver sdm845_snd_driver = {
 	.probe = sdm845_snd_platform_probe,
-	.remove = sdm845_snd_platform_remove,
 	.driver = {
 		.name = "msm-snd-sdm845",
 		.of_match_table = sdm845_snd_device_id,
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/7 ASoC: qcom: common: Use snd_soc_dai_link_set_capabilities()

In reply to Stephan Gerhold

Commit a2120089251f ("ASoC: qcom: common: set correct directions for dailinks") introduced a call to q6afe_is_rx_port() to set the dpcm_playback/capture parameters correctly. This is necessary because those parameters are now validated to match the capabilities of the DAIs. [1]

The disadvantage of introducing the call to q6afe_is_rx_port() is that it makes the qcom_snd_parse_of() helper dependent on the QDSP6 driver. When the ADSP is bypassed (e.g. in apq8016-sbc) QDSP6 is not used.

There is a generic solution for this now: The correct direction for the links is already defined by the DAI capabilities (e.g. rx ports only support playback).

Commit 25612477d20b ("ASoC: soc-dai: set dai_link dpcm_ flags with a helper") introduced the snd_soc_dai_link_set_capabilities() function that we can use to set dpcm_playback/dpcm_capture according to the capabilities of the DAIs.

Use that for both FE/BE DAI links to avoid the dependency on the QDSP6 driver.

[1]: https://lore.kernel.org/alsa-devel/[email protected]/

Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/qcom/common.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
sound/soc/qcom/common.c +1 -12
index d677e83828af..030df6026562 100644
@@ -4,7 +4,6 @@
 
 #include <linux/module.h>
 #include "common.h"
-#include "qdsp6/q6afe.h"
 
 int qcom_snd_parse_of(struct snd_soc_card *card)
 {
@@ -102,15 +101,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 			}
 			link->no_pcm = 1;
 			link->ignore_pmdown_time = 1;
-
-			if (q6afe_is_rx_port(link->id)) {
-				link->dpcm_playback = 1;
-				link->dpcm_capture = 0;
-			} else {
-				link->dpcm_playback = 0;
-				link->dpcm_capture = 1;
-			}
-
 		} else {
 			dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
 			if (!dlc)
@@ -123,10 +113,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 			link->codecs->dai_name = "snd-soc-dummy-dai";
 			link->codecs->name = "snd-soc-dummy";
 			link->dynamic = 1;
-			link->dpcm_playback = 1;
-			link->dpcm_capture = 1;
 		}
 
+		snd_soc_dai_link_set_capabilities(link);
 		link->ignore_suspend = 1;
 		link->nonatomic = 1;
 		link->stream_name = link->name;
Signature · 1 line
2.27.0
#3 lore raw

PATCH 3/7 ASoC: q6afe: Remove unused q6afe_is_rx_port() function

In reply to Stephan Gerhold

This reverts commit 4a95737440d ("ASoc: q6afe: add support to get port direction"), since the function is not needed anymore.

q6afe-dai already exposes the possible directions for a DAI through the DAI capabilities (playback/capture-only DAI). Now we use snd_soc_dai_link_set_capabilities() to infer the information directly from the DAI capabilities.

Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/qcom/qdsp6/q6afe.c | 8 --------
 sound/soc/qcom/qdsp6/q6afe.h | 1 -
 2 files changed, 9 deletions(-)
sound/soc/qcom/qdsp6/q6afe.c +0 -8
index 0ce4eb60f984..e0945f7a58c8 100644
@@ -800,14 +800,6 @@ int q6afe_get_port_id(int index)
 }
 EXPORT_SYMBOL_GPL(q6afe_get_port_id);
 
-int q6afe_is_rx_port(int index)
-{
-	if (index < 0 || index >= AFE_PORT_MAX)
-		return -EINVAL;
-
-	return port_maps[index].is_rx;
-}
-EXPORT_SYMBOL_GPL(q6afe_is_rx_port);
 static int afe_apr_send_pkt(struct q6afe *afe, struct apr_pkt *pkt,
 			    struct q6afe_port *port)
 {
sound/soc/qcom/qdsp6/q6afe.h +0 -1
index 1a0f80a14afe..c7ed5422baff 100644
@@ -198,7 +198,6 @@ int q6afe_port_start(struct q6afe_port *port);
 int q6afe_port_stop(struct q6afe_port *port);
 void q6afe_port_put(struct q6afe_port *port);
 int q6afe_get_port_id(int index);
-int q6afe_is_rx_port(int index);
 void q6afe_hdmi_port_prepare(struct q6afe_port *port,
 			    struct q6afe_hdmi_cfg *cfg);
 void q6afe_slim_port_prepare(struct q6afe_port *port,
Signature · 1 line
2.27.0
#4 lore raw

PATCH 4/7 ASoC: qcom: common: Support parsing links without DPCM

In reply to Stephan Gerhold

So far qcom_snd_parse_of() was only used to parse the device tree for boards using the QDSP6 driver together with DPCM. apq8016_sbc uses an almost identical version (apq8016_sbc_parse_of()) which parses links without DPCM.

Given the similarity of the two functions it is useful to combine these two. To allow using qcom_snd_parse_of() in apq8016_sbc we need to support parsing links without DPCM as well.

This is pretty simple: A DPCM link in the device tree is defined using:

- DPCM frontend: "cpu"
- DPCM backend: "cpu", "platform" and "codec"

... while a link without DPCM has "cpu" and "codec" (but no "platform").

Add a few more if conditions to handle links without DPCM correctly.

Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/qcom/common.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
sound/soc/qcom/common.c +19 -7
index 030df6026562..54f5bc60246f 100644
@@ -84,7 +84,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 			goto err;
 		}
 
-		if (codec && platform) {
+		if (platform) {
 			link->platforms->of_node = of_parse_phandle(platform,
 					"sound-dai",
 					0);
@@ -93,15 +93,24 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 				ret = -EINVAL;
 				goto err;
 			}
+		} else {
+			link->platforms->of_node = link->cpus->of_node;
+		}
 
+		if (codec) {
 			ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
 			if (ret < 0) {
 				dev_err(card->dev, "%s: codec dai not found\n", link->name);
 				goto err;
 			}
-			link->no_pcm = 1;
-			link->ignore_pmdown_time = 1;
+
+			if (platform) {
+				/* DPCM backend */
+				link->no_pcm = 1;
+				link->ignore_pmdown_time = 1;
+			}
 		} else {
+			/* DPCM frontend */
 			dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
 			if (!dlc)
 				return -ENOMEM;
@@ -109,15 +118,18 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 			link->codecs	 = dlc;
 			link->num_codecs = 1;
 
-			link->platforms->of_node = link->cpus->of_node;
 			link->codecs->dai_name = "snd-soc-dummy-dai";
 			link->codecs->name = "snd-soc-dummy";
 			link->dynamic = 1;
 		}
 
-		snd_soc_dai_link_set_capabilities(link);
-		link->ignore_suspend = 1;
-		link->nonatomic = 1;
+		if (platform || !codec) {
+			/* DPCM */
+			snd_soc_dai_link_set_capabilities(link);
+			link->ignore_suspend = 1;
+			link->nonatomic = 1;
+		}
+
 		link->stream_name = link->name;
 		link++;
 
Signature · 1 line
2.27.0
#5 lore raw

PATCH 5/7 ASoC: qcom: common: Parse properties with "qcom," prefix

In reply to Stephan Gerhold

The apq8016_sbc device tree binding uses a "qcom," vendor prefix for all device tree properties, while qcom_snd_parse_of() uses the same properties without a prefix.

In the future it would be nice to make this consistent, however, for backwards compatibility we need to parse both names to allow apq8016_sbc to use the common qcom_snd_parse_of() function.

Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/qcom/common.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
sound/soc/qcom/common.c +10 -2
index 54f5bc60246f..84dba0d69e6b 100644
@@ -18,6 +18,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 	int ret, num_links;
 
 	ret = snd_soc_of_parse_card_name(card, "model");
+	if (ret == 0 && !card->name)
+		/* Deprecated, only for compatibility with old device trees */
+		ret = snd_soc_of_parse_card_name(card, "qcom,model");
 	if (ret) {
 		dev_err(dev, "Error parsing card name: %d\n", ret);
 		return ret;
@@ -25,8 +28,13 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 
 	/* DAPM routes */
 	if (of_property_read_bool(dev->of_node, "audio-routing")) {
-		ret = snd_soc_of_parse_audio_routing(card,
-				"audio-routing");
+		ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
+		if (ret)
+			return ret;
+	}
+	/* Deprecated, only for compatibility with old device trees */
+	if (of_property_read_bool(dev->of_node, "qcom,audio-routing")) {
+		ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
 		if (ret)
 			return ret;
 	}
Signature · 1 line
2.27.0
#6 lore raw

PATCH 6/7 ASoC: qcom: apq8016_sbc: Use qcom_snd_parse_of()

In reply to Stephan Gerhold

Now that we have updated qcom_snd_parse_of() to handle the device tree bindings used for apq8016_sbc, update the apq8016_sbc driver to use the common function and remove the duplicated code.

Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/qcom/Kconfig       |   1 +
 sound/soc/qcom/apq8016_sbc.c | 120 ++++-------------------------------
 2 files changed, 15 insertions(+), 106 deletions(-)
sound/soc/qcom/Kconfig +1 -0
index cfca0f730c61..5d6b2466a2f2 100644
@@ -37,6 +37,7 @@ config SND_SOC_APQ8016_SBC
 	tristate "SoC Audio support for APQ8016 SBC platforms"
 	depends on SND_SOC_QCOM
 	select SND_SOC_LPASS_APQ8016
+	select SND_SOC_QCOM_COMMON
 	help
 	  Support for Qualcomm Technologies LPASS audio block in
 	  APQ8016 SOC-based systems.
sound/soc/qcom/apq8016_sbc.c +14 -106

160 lines not on this page · raw message

Signature · 1 line
2.27.0
#7 lore raw

PATCH 7/7 ASoC: qcom: common: Avoid printing errors for -EPROBE_DEFER

In reply to Stephan Gerhold

qcom_snd_parse_of() tends to produce lots of error messages during bootup:

MultiMedia1: error getting cpu dai name

This happens because the DAIs are not probed until the ADSP remoteproc has booted, which takes a while. Until it is ready, snd_soc_of_get_dai_name() returns -EDEFER_PROBE to retry probing later. This is perfectly normal, so cleanup the kernel log a bit by not printing in case of -EPROBE_DEFER.

Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/qcom/common.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
sound/soc/qcom/common.c +6 -2
index 84dba0d69e6b..5194d90ddb96 100644
@@ -88,7 +88,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 
 		ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
 		if (ret) {
-			dev_err(card->dev, "%s: error getting cpu dai name\n", link->name);
+			if (ret != -EPROBE_DEFER)
+				dev_err(card->dev, "%s: error getting cpu dai name: %d\n",
+					link->name, ret);
 			goto err;
 		}
 
@@ -108,7 +110,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 		if (codec) {
 			ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
 			if (ret < 0) {
-				dev_err(card->dev, "%s: codec dai not found\n", link->name);
+				if (ret != -EPROBE_DEFER)
+					dev_err(card->dev, "%s: codec dai not found: %d\n",
+						link->name, ret);
 				goto err;
 			}
 
Signature · 1 line
2.27.0
Tested-by Reviewed-by on the v1 series
#8 lore raw
In reply to Stephan Gerhold

Thanks Stephan for doing this cleanup!

Quoted 8 lines · Stephan Gerhold

At the moment we have two separate functions to parse the sound card properties from the device tree: qcom_snd_parse_of() for DPCM and apq8016_sbc_parse_of() without DPCM. These functions are almost identical except for a few minor differences.

This patch set extends qcom_snd_parse_of() to handle links without DPCM, so that we can use one common function for all (qcom) machine drivers.

Quoted 9 lines

Stephan Gerhold (7):
ASoC: qcom: Use devm for resource management
ASoC: qcom: common: Use snd_soc_dai_link_set_capabilities()
ASoC: q6afe: Remove unused q6afe_is_rx_port() function
ASoC: qcom: common: Support parsing links without DPCM
ASoC: qcom: common: Parse properties with "qcom," prefix
ASoC: qcom: apq8016_sbc: Use qcom_snd_parse_of()
ASoC: qcom: common: Avoid printing errors for -EPROBE_DEFER

All the patches looks good to me,

Tested this on DragonBoard 410c!

---srini

Quoted 9 lines
  sound/soc/qcom/Kconfig       |   1 +
  sound/soc/qcom/apq8016_sbc.c | 120 ++++-------------------------------
  sound/soc/qcom/apq8096.c     |  28 +-------
  sound/soc/qcom/common.c      |  58 ++++++++++-------
  sound/soc/qcom/qdsp6/q6afe.c |   8 ---
  sound/soc/qcom/qdsp6/q6afe.h |   1 -
  sound/soc/qcom/sdm845.c      |  40 ++----------
  7 files changed, 59 insertions(+), 197 deletions(-)
maintainer
#9 lore raw
In reply to Stephan Gerhold
Quoted 9 lines · Stephan Gerhold

At the moment we have two separate functions to parse the sound card properties from the device tree: qcom_snd_parse_of() for DPCM and apq8016_sbc_parse_of() without DPCM. These functions are almost identical except for a few minor differences.

This patch set extends qcom_snd_parse_of() to handle links without DPCM, so that we can use one common function for all (qcom) machine drivers.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/7] ASoC: qcom: Use devm for resource management

      commit: ed3b53e7ffe91c32a1277de435e3fcb3ad5e852a
[2/7] ASoC: qcom: common: Use snd_soc_dai_link_set_capabilities()
      commit: 627ab55d745b2a413e0a2856f2ad2e422a697971
[3/7] ASoC: q6afe: Remove unused q6afe_is_rx_port() function
      commit: 0a8c336a1e020be3832b02e1ddbb92d61da87512
[4/7] ASoC: qcom: common: Support parsing links without DPCM
      commit: 47ea88488209226e03559bb8baaa0156b4025fee
[5/7] ASoC: qcom: common: Parse properties with "qcom," prefix
      commit: f0d67fdba5dcf48865fc79f2d63b49bd75d36671
[6/7] ASoC: qcom: apq8016_sbc: Use qcom_snd_parse_of()
      commit: 118205d241ef6fec395086c34f85717a41a8b4a1
[7/7] ASoC: qcom: common: Avoid printing errors for -EPROBE_DEFER
      commit: a63419beafd4edf20761c37dbefd639a0b1b481e

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark