[Letux-kernel] [PATCH 1/2] sound: soc: simple-card: add clk_div support

Andreas Kemnade andreas at kemnade.info
Mon Aug 20 23:29:30 CEST 2018


This enables support for specifying clk_div parameters
via devicetree. For now only one divider is supported per codec.

Signed-off-by: Andreas Kemnade <andreas at kemnade.info>
---
 include/sound/simple_card_utils.h     |  3 +++
 sound/soc/generic/simple-card-utils.c |  8 ++++++++
 sound/soc/generic/simple-card.c       | 18 ++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index 7e25afce6566..d2d8a92bc4bd 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -16,6 +16,9 @@ struct asoc_simple_dai {
 	const char *name;
 	unsigned int sysclk;
 	int clk_direction;
+	int clk_div_id;
+	int clk_div;
+	bool clk_div_set;
 	int slots;
 	int slot_width;
 	unsigned int tx_slot_mask;
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 3751a07de6aa..3d1a37ba0a93 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -176,6 +176,7 @@ int asoc_simple_card_parse_clk(struct device *dev,
 {
 	struct clk *clk;
 	u32 val;
+	u32 divider[2];
 
 	/*
 	 * Parse dai->sysclk come from "clocks = <&xxx>"
@@ -202,6 +203,13 @@ int asoc_simple_card_parse_clk(struct device *dev,
 	dev_dbg(dev, "%s : sysclk = %d, direction %d\n", name,
 		simple_dai->sysclk, simple_dai->clk_direction);
 
+	if (!of_property_read_u32_array(node, "clkdiv", divider, 2)) {
+		simple_dai->clk_div_id = divider[0];
+		simple_dai->clk_div = divider[1];
+		simple_dai->clk_div_set = true;
+	} else {
+		simple_dai->clk_div_set = false;
+	}
 	return 0;
 }
 EXPORT_SYMBOL_GPL(asoc_simple_card_parse_clk);
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 8b374af86a6e..ac06557d5293 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -147,6 +147,17 @@ static int asoc_simple_set_clk_rate(struct asoc_simple_dai *simple_dai,
 	return clk_set_rate(simple_dai->clk, rate);
 }
 
+static int asoc_simple_set_clkdiv(struct snd_soc_dai *dai,
+				  struct asoc_simple_dai *simple_dai)
+{
+	if (!simple_dai->clk_div_set)
+		return 0;
+
+	return snd_soc_dai_set_clkdiv(dai,
+				      simple_dai->clk_div_id,
+				      simple_dai->clk_div);
+}
+
 static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
 				      struct snd_pcm_hw_params *params)
 {
@@ -185,6 +196,13 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
 		if (ret && ret != -ENOTSUPP)
 			goto err;
 	}
+	ret = asoc_simple_set_clkdiv(codec_dai, &dai_props->codec_dai);
+	if (ret < 0)
+		return ret;
+
+	ret = asoc_simple_set_clkdiv(cpu_dai, &dai_props->cpu_dai);
+	if (ret < 0)
+		return ret;
 	return 0;
 err:
 	return ret;
-- 
2.11.0



More information about the Letux-kernel mailing list