Skip to contentSkip to conversation

Initial prototype of DAPM sample rate domains

RFC PATCH In review Charles Keepax 3 participants 9 messages Oct 11, 2018 – Oct 23, 2018

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

cover Initial prototype of DAPM sample rate domains

Here is a first pass at adding dapm sample rate domain support. Things are still pretty rough in quite a few places and I expect some major refactoring before they are ready to merge, but things are far enough along for people to look at the approach I am taking to the problem. And should provide enough for discussion at the mini-conference, although hopefully I will get some more done next week as well.

The basic high level summary is two new concepts are added to ASoC, one being a sample rate domain and the other being a domain group. The domain groups represent widgets that are limited by hardware restrictions to always run at the same sample rate as each other. Sample rate domains represent a slot on a device for a sample rate. Both of these are currently limited to be within the scope of a single component. The core will track which groups are connected together, then as a group is powered up it will be allocated a domain based on the other groups it is connected to. Domain groups are implemented as a new type of DAPM widget and the domains themselves are a new thing which devices add through their component drivers.

As we have previously discussed my intention would be that we also add bridges between domains although I haven't started work on that yet. The current code is limited to within a single component and I think that the bridges will allow better support for propagating rates between components as well as obviously for SRCs. Currently the SRCs on wm5110 are just being handled as points where the domain groups don't connect to another peer. This allows them to function but doesn't accurately convey things like the limitations which input rates support which output rates on the ISRC.

Thanks,
Charles

Charles Keepax (4):
ASoC: dapm: Add support for hw_free on CODEC to CODEC links
ASoC: dapm: Add support for a rate domain widget
ASoC: domain: Add sample rate domain support
ASoC: arizona: Add rate domain support

 include/sound/soc-dapm.h   |  14 ++
 include/sound/soc-domain.h |  98 +++++++++++
 include/sound/soc.h        |   8 +
 sound/soc/Makefile         |   2 +-
 sound/soc/codecs/arizona.c | 255 ++++++++++++++++++++++------
 sound/soc/codecs/arizona.h |  76 ++++++++-
 sound/soc/codecs/wm5110.c  | 414 ++++++++++++++++++++++++++++++++++-----------
 sound/soc/soc-core.c       |   8 +
 sound/soc/soc-dapm.c       |  57 ++++++-
 sound/soc/soc-domain.c     | 412 ++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 1183 insertions(+), 161 deletions(-)
 create mode 100644 include/sound/soc-domain.h
 create mode 100644 sound/soc/soc-domain.c
Signature · 1 line
2.11.0
#1 lore raw

RFC PATCH 1/4 ASoC: dapm: Add support for hw_free on CODEC to CODEC links

Currently, on power down for a CODEC to CODEC DAI link we only call digital_mute and shutdown. Provide a little more flexibility for drivers by adding a call to hw_free as well.

---
 sound/soc/soc-dapm.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
sound/soc/soc-dapm.c +11 -6
index 8c5b065c88806..a5178845065b3 100644
@@ -3737,25 +3737,30 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
 			ret = 0;
 		}
 
+		substream.stream = SNDRV_PCM_STREAM_CAPTURE;
 		snd_soc_dapm_widget_for_each_source_path(w, path) {
 			source = path->source->priv;
 
+			if (source->driver->ops->hw_free)
+				source->driver->ops->hw_free(&substream,
+							     source);
+
 			source->active--;
-			if (source->driver->ops->shutdown) {
-				substream.stream = SNDRV_PCM_STREAM_CAPTURE;
+			if (source->driver->ops->shutdown)
 				source->driver->ops->shutdown(&substream,
 							      source);
-			}
 		}
 
+		substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
 		snd_soc_dapm_widget_for_each_sink_path(w, path) {
 			sink = path->sink->priv;
 
+			if (sink->driver->ops->hw_free)
+				sink->driver->ops->hw_free(&substream, sink);
+
 			sink->active--;
-			if (sink->driver->ops->shutdown) {
-				substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
+			if (sink->driver->ops->shutdown)
 				sink->driver->ops->shutdown(&substream, sink);
-			}
 		}
 		break;
 
Signature · 1 line
2.11.0
#4 lore raw

RFC PATCH 2/4 ASoC: dapm: Add support for a rate domain widget

In reply to Charles Keepax

Some CODECs can support multiple sample rates internally but frequently groups of functionality will be force to the run on the same sample rate. For example, perhaps all the DACs are required to run at a single rate. Utimately, it would be ideal if the sample rates could be propagated through from the top level DAI links to these groups of widgets. This should allow more complex use-cases involving multiple sample rates to be connected and will also allow detection of errors where blocks with incompatible sample rates are connected.

A first step in this process is to provide a mechanism that documents which blocks are tidied together with respect to sample rate and track when they are in use. This is acheived by adding a supply like widget that represents a group of widgets that are bound to a single sample rate. This domain widget should be connected to all inputs and outputs to the group of widgets, that way it will power up whenever anything in that group of widgets does.

---
 include/sound/soc-dapm.h | 4 ++++
 sound/soc/soc-dapm.c     | 5 +++++
 2 files changed, 9 insertions(+)
include/sound/soc-dapm.h +4 -0
index bd8163f151cb8..c0ef27b2d4b22 100644
@@ -273,6 +273,9 @@ struct device;
 	.reg = SND_SOC_NOPM, .event = dapm_pinctrl_event, \
 	.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }
 
+#define SND_SOC_DAPM_RATE(wname, wreg, wshift, winvert, wops, wpriv) \
+{	.id = snd_soc_dapm_rate, .name = wname, \
+	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) }
 
 
 /* dapm kcontrol types */
@@ -519,6 +522,7 @@ enum snd_soc_dapm_type {
 	snd_soc_dapm_asrc,		/* DSP/CODEC ASRC component */
 	snd_soc_dapm_encoder,		/* FW/SW audio encoder component */
 	snd_soc_dapm_decoder,		/* FW/SW audio decoder component */
+	snd_soc_dapm_rate,		/* Rate group */
 };
 
 enum snd_soc_dapm_subclass {
sound/soc/soc-dapm.c +5 -0
index a5178845065b3..7e3858d1e81dc 100644
@@ -68,6 +68,7 @@ static int dapm_up_seq[] = {
 	[snd_soc_dapm_regulator_supply] = 1,
 	[snd_soc_dapm_pinctrl] = 1,
 	[snd_soc_dapm_clock_supply] = 1,
+	[snd_soc_dapm_rate] = 2,
 	[snd_soc_dapm_supply] = 2,
 	[snd_soc_dapm_micbias] = 3,
 	[snd_soc_dapm_dai_link] = 2,
@@ -115,6 +116,7 @@ static int dapm_down_seq[] = {
 	[snd_soc_dapm_dai_out] = 10,
 	[snd_soc_dapm_dai_link] = 11,
 	[snd_soc_dapm_supply] = 12,
+	[snd_soc_dapm_rate] = 12,
 	[snd_soc_dapm_clock_supply] = 13,
 	[snd_soc_dapm_pinctrl] = 13,
 	[snd_soc_dapm_regulator_supply] = 13,
@@ -1912,6 +1914,7 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event)
 			case snd_soc_dapm_vmid:
 				break;
 			case snd_soc_dapm_supply:
+			case snd_soc_dapm_rate:
 			case snd_soc_dapm_regulator_supply:
 			case snd_soc_dapm_pinctrl:
 			case snd_soc_dapm_clock_supply:
@@ -2326,6 +2329,7 @@ static ssize_t dapm_widget_show_component(struct snd_soc_component *cmpnt,
 		case snd_soc_dapm_mixer:
 		case snd_soc_dapm_mixer_named_ctl:
 		case snd_soc_dapm_supply:
+		case snd_soc_dapm_rate:
 		case snd_soc_dapm_regulator_supply:
 		case snd_soc_dapm_pinctrl:
 		case snd_soc_dapm_clock_supply:
@@ -3522,6 +3526,7 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
 		w->power_check = dapm_generic_check_power;
 		break;
 	case snd_soc_dapm_supply:
+	case snd_soc_dapm_rate:
 	case snd_soc_dapm_regulator_supply:
 	case snd_soc_dapm_pinctrl:
 	case snd_soc_dapm_clock_supply:
Signature · 1 line
2.11.0
#5 lore raw

RFC PATCH 3/4 ASoC: domain: Add sample rate domain support

In reply to Charles Keepax

The rate domain widgets allowed tracking of which hardware blocks are physically bound to the same sample rate. The next step is to follow which blocks are connected together as two directly connected blocks should also run at the same rate, even though the hardware may provide independent settings for them.

To acheive this two new concepts are introduced to ASoC, a rate domain and a rate domain group. The rate domain group corresponds to the rate domain widgets previously added to DAPM. And the domains correspond to actual sample rates.

The rate domain groups internally track which other groups they are connected to. These lists of peer groups are updated as DAPM routes are connected/disconnected and form a collection of graphs tracking which domain groups are connected. Note that these graphs are significantly smaller than the DAPM graph itself.

When a domain group's corresponding widget is powered up then the group must locate an actual domain to attach to. Firstly, the group will walk its peer graph, should it find it is attached to widgets that require certain domains it will limit the choice to those. For example if a widget is connected into a graph that is already powered up then it will find the only suitable domain is the one being currently used by the groups in the graph.

---

Thinking about trying to split this into two patches perhaps one to add the tracking of the rate domain groups connecting together and then a second patch to add the actual domains.

Thanks,
Charles

 include/sound/soc-dapm.h   |  12 +-
 include/sound/soc-domain.h |  98 +++++++++++
 include/sound/soc.h        |   8 +
 sound/soc/Makefile         |   2 +-
 sound/soc/soc-core.c       |   8 +
 sound/soc/soc-dapm.c       |  35 ++++
 sound/soc/soc-domain.c     | 412 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 573 insertions(+), 2 deletions(-)
 create mode 100644 include/sound/soc-domain.h
 create mode 100644 sound/soc/soc-domain.c
include/sound/soc-dapm.h +11 -1
index c0ef27b2d4b22..c736b1d3e4931 100644
@@ -275,7 +275,12 @@ struct device;
 
 #define SND_SOC_DAPM_RATE(wname, wreg, wshift, winvert, wops, wpriv) \
 {	.id = snd_soc_dapm_rate, .name = wname, \
-	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert) }
+	SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
+	.event = snd_soc_domain_event, \
+	.event_flags = SND_SOC_DAPM_WILL_PMU | SND_SOC_DAPM_PRE_PMU | \
+		       SND_SOC_DAPM_POST_PMD, \
+	.priv = (&(struct snd_soc_domain_group_driver){ \
+	.name = wname, .ops = wops, .private_data = wpriv}),}
 
 
 /* dapm kcontrol types */
@@ -410,6 +415,9 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
 
+int snd_soc_dapm_connect_domains(struct snd_soc_dapm_context *dapm,
+				 const char * const a, const char * const b);
+
 /* dapm path setup */
 int snd_soc_dapm_new_widgets(struct snd_soc_card *card);
 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm);
@@ -629,6 +637,8 @@ struct snd_soc_dapm_widget {
 	int endpoints[2];
 
 	struct clk *clk;
+
+	struct snd_soc_domain_group *dgroup;
 };
 
 struct snd_soc_dapm_update {
include/sound/soc-domain.h new file +98 -0

98 lines not on this page · raw message

include/sound/soc.h +8 -0
index f1dab1f4b194d..475843a17ebd4 100644
@@ -413,6 +413,7 @@ struct snd_soc_jack_pin;
 #include <sound/soc-dapm.h>
 #include <sound/soc-dpcm.h>
 #include <sound/soc-topology.h>
+#include <sound/soc-domain.h>
 
 struct snd_soc_jack_gpio;
 
@@ -763,6 +764,9 @@ struct snd_soc_component_driver {
 	const struct snd_soc_dapm_route *dapm_routes;
 	unsigned int num_dapm_routes;
 
+	const struct snd_soc_domain_driver *domains;
+	unsigned int num_domains;
+
 	int (*probe)(struct snd_soc_component *);
 	void (*remove)(struct snd_soc_component *);
 	int (*suspend)(struct snd_soc_component *);
@@ -838,6 +842,9 @@ struct snd_soc_component {
 	struct list_head dai_list;
 	int num_dai;
 
+	struct snd_soc_domain *domains;
+	int num_domains;
+
 	struct regmap *regmap;
 	int val_bytes;
 
@@ -1036,6 +1043,7 @@ struct snd_soc_card {
 
 	struct mutex mutex;
 	struct mutex dapm_mutex;
+	struct mutex domain_mutex;
 
 	bool instantiated;
 	bool topology_shortname_created;
sound/soc/Makefile +1 -1
index 62a5f87c3cfc4..185f51aa963a2 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-utils.o
-snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o
+snd-soc-core-objs += soc-pcm.o soc-io.o soc-devres.o soc-ops.o soc-domain.o
 snd-soc-core-$(CONFIG_SND_SOC_COMPRESS) += soc-compress.o
 
 ifneq ($(CONFIG_SND_SOC_TOPOLOGY),)
sound/soc/soc-core.c +8 -0
index 62e8e36062df0..4623adb27543b 100644
@@ -1345,6 +1345,13 @@ static int soc_probe_component(struct snd_soc_card *card,
 		}
 	}
 
+	ret = devm_snd_soc_domain_init(component);
+	if (ret < 0) {
+		dev_err(component->dev, "Failed to initialise domains: %d\n",
+			ret);
+		goto err_probe;
+	}
+
 	if (component->driver->controls)
 		snd_soc_add_component_controls(component,
 					       component->driver->controls,
@@ -2739,6 +2746,7 @@ int snd_soc_register_card(struct snd_soc_card *card)
 	card->instantiated = 0;
 	mutex_init(&card->mutex);
 	mutex_init(&card->dapm_mutex);
+	mutex_init(&card->domain_mutex);
 
 	return snd_soc_bind_card(card);
 }
sound/soc/soc-dapm.c +35 -0
index 7e3858d1e81dc..a3f01626fda76 100644
@@ -2179,6 +2179,9 @@ static void soc_dapm_connect_path(struct snd_soc_dapm_path *path,
 	if (path->connect == connect)
 		return;
 
+	/* TODO: Need to handle routes that are already connected */
+	snd_soc_domain_connect_widgets(path->source, path->sink, connect);
+
 	path->connect = connect;
 	dapm_mark_dirty(path->source, reason);
 	dapm_mark_dirty(path->sink, reason);
@@ -2685,6 +2688,14 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
 	if (wsource->is_supply || wsink->is_supply)
 		path->is_supply = 1;
 
+	switch (wsource->id) {
+	case snd_soc_dapm_rate:
+		wsink->dgroup = wsource->dgroup;
+		break;
+	default:
+		break;
+	}
+
 	/* connect static paths */
 	if (control == NULL) {
 		path->connect = 1;
@@ -3463,6 +3474,14 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
 			goto request_failed;
 		}
 		break;
+	case snd_soc_dapm_rate:
+		w->dgroup = devm_snd_soc_domain_group_new(dapm->component,
+							  w->priv);
+		if (IS_ERR(w->dgroup)) {
+			ret = PTR_ERR(w->dgroup);
+			goto request_failed;
+		}
+		break;
 	default:
 		break;
 	}
@@ -4566,6 +4585,22 @@ void snd_soc_dapm_shutdown(struct snd_soc_card *card)
 					    SND_SOC_BIAS_OFF);
 }
 
+int snd_soc_dapm_connect_domains(struct snd_soc_dapm_context *dapm,
+				 const char * const a, const char * const b)
+{
+	struct snd_soc_dapm_widget *wa, *wb;
+
+	wa = dapm_find_widget(dapm, a, false);
+	if (!wa)
+		return -ENODEV;
+	wb = dapm_find_widget(dapm, b, false);
+	if (!wb)
+		return -ENODEV;
+
+	return snd_soc_domain_connect_widgets(wa, wb, true);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_connect_domains);
+
 /* Module information */
 MODULE_AUTHOR("Liam Girdwood, [email protected]");
 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
sound/soc/soc-domain.c new file +412 -0

412 lines not on this page · raw message

Signature · 1 line
2.11.0
#6 lore raw

RFC PATCH 4/4 ASoC: arizona: Add rate domain support

In reply to Charles Keepax

Move to using sample rate domains on the Arizona CODECs. Rate domain group widgets are added and these are connected to all the widgets they supply.

arizona_hw_params_rate is updated significantly, it now manually attached the AIF sample rate domain group to a domain at the rate requested by the params. This ensures that any widgets powering up that are connected to the audio interface will be placed on the same sample rate domain.

Whilst the SLIMbus technically supports a different sample rate on each channel the driver currently only supports sample rates for capture and playback on each DAI, as such the SLIMBus channels that are grouped onto a single DAI are manually connected together as peers.

---

This one is obviously not quite finished yet, the other CODECs in Arizona need updated and the macros that are duplicated will obviously just be updated in that case.

Thanks,
Charles

 sound/soc/codecs/arizona.c | 255 ++++++++++++++++++++++------
 sound/soc/codecs/arizona.h |  76 ++++++++-
 sound/soc/codecs/wm5110.c  | 414 ++++++++++++++++++++++++++++++++++-----------
 3 files changed, 591 insertions(+), 154 deletions(-)
sound/soc/codecs/arizona.c +204 -51
index 5727ea079ad7a..37ce772691739 100644
@@ -633,12 +633,12 @@ const char *arizona_sample_rate_val_to_name(unsigned int rate_val)
 EXPORT_SYMBOL_GPL(arizona_sample_rate_val_to_name);
 
 const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE] = {
-	"SYNCCLK rate", "8kHz", "16kHz", "ASYNCCLK rate",
+	"SYNCCLK rate", "8kHz", "16kHz", "ASYNCCLK rate", "ASYNCCLK rate 2",
 };
 EXPORT_SYMBOL_GPL(arizona_rate_text);
 
 const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE] = {
-	0, 1, 2, 8,
+	0, 1, 2, 8, 9,
 };
 EXPORT_SYMBOL_GPL(arizona_rate_val);
 
@@ -1681,40 +1681,15 @@ static int arizona_hw_params_rate(struct snd_pcm_substream *substream,
 	struct snd_soc_component *component = dai->component;
 	struct arizona_priv *priv = snd_soc_component_get_drvdata(component);
 	struct arizona_dai_priv *dai_priv = &priv->dai[dai->id - 1];
-	int base = dai->driver->base;
-	int i, sr_val, ret;
-
-	/*
-	 * We will need to be more flexible than this in future,
-	 * currently we use a single sample rate for SYSCLK.
-	 */
-	for (i = 0; i < ARRAY_SIZE(arizona_sr_vals); i++)
-		if (arizona_sr_vals[i] == params_rate(params))
-			break;
-	if (i == ARRAY_SIZE(arizona_sr_vals)) {
-		arizona_aif_err(dai, "Unsupported sample rate %dHz\n",
-				params_rate(params));
-		return -EINVAL;
-	}
-	sr_val = i;
-
-	switch (priv->arizona->type) {
-	case WM5102:
-	case WM8997:
-		if (arizona_sr_vals[sr_val] >= 88200)
-			ret = arizona_dvfs_up(component, ARIZONA_DVFS_SR1_RQ);
-		else
-			ret = arizona_dvfs_down(component, ARIZONA_DVFS_SR1_RQ);
+	int ret;
+	struct snd_soc_domain_group *dgrp;
 
-		if (ret) {
-			arizona_aif_err(dai, "Failed to change DVFS %d\n", ret);
-			return ret;
-		}
-		break;
-	default:
-		break;
-	}
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		dgrp = dai->playback_widget->dgroup;
+	else
+		dgrp = dai->capture_widget->dgroup;
 
+	/* TODO: This should be handled on power up of the OUT_RATE widget */
 	switch (dai_priv->clk) {
 	case ARIZONA_CLK_SYSCLK:
 		switch (priv->arizona->type) {
@@ -1725,31 +1700,38 @@ static int arizona_hw_params_rate(struct snd_pcm_substream *substream,
 		default:
 			break;
 		}
-
-		snd_soc_component_update_bits(component, ARIZONA_SAMPLE_RATE_1,
-					      ARIZONA_SAMPLE_RATE_1_MASK,
-					      sr_val);
-		if (base)
-			snd_soc_component_update_bits(component,
-					base + ARIZONA_AIF_RATE_CTRL,
-					ARIZONA_AIF1_RATE_MASK, 0);
 		break;
 	case ARIZONA_CLK_ASYNCCLK:
-		snd_soc_component_update_bits(component,
-					      ARIZONA_ASYNC_SAMPLE_RATE_1,
-					      ARIZONA_ASYNC_SAMPLE_RATE_1_MASK,
-					      sr_val);
-		if (base)
-			snd_soc_component_update_bits(component,
-					base + ARIZONA_AIF_RATE_CTRL,
-					ARIZONA_AIF1_RATE_MASK,
-					8 << ARIZONA_AIF1_RATE_SHIFT);
 		break;
 	default:
 		arizona_aif_err(dai, "Invalid clock %d\n", dai_priv->clk);
 		return -EINVAL;
 	}
 
+	/* TODO: Needs updated to handle multiple calls of hw_params */
+	ret = snd_soc_domain_attach(dgrp);
+	if (ret)
+		return ret;
+
+	ret = snd_soc_domain_set_rate(dgrp, params_rate(params));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int arizona_hw_free(struct snd_pcm_substream *substream,
+			   struct snd_soc_dai *dai)
+{
+	struct snd_soc_domain_group *dgrp;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		dgrp = dai->playback_widget->dgroup;
+	else
+		dgrp = dai->capture_widget->dgroup;
+
+	snd_soc_domain_detach(dgrp);
+
 	return 0;
 }
 
@@ -2029,6 +2011,7 @@ const struct snd_soc_dai_ops arizona_dai_ops = {
 	.set_fmt = arizona_set_fmt,
 	.set_tdm_slot = arizona_set_tdm_slot,
 	.hw_params = arizona_hw_params,
+	.hw_free = arizona_hw_free,
 	.set_sysclk = arizona_dai_set_sysclk,
 	.set_tristate = arizona_set_tristate,
 };
@@ -2858,6 +2841,176 @@ int arizona_of_get_audio_pdata(struct arizona *arizona)
 }
 EXPORT_SYMBOL_GPL(arizona_of_get_audio_pdata);
 
+static int arizona_set_rate(struct snd_soc_domain *dom, int rate)
+{
+	struct snd_soc_component *component = dom->component;
+	struct arizona *arizona = dev_get_drvdata(component->dev->parent);
+	const struct arizona_rate_dom_priv *dpriv = dom->driver->private_data;
+	int i, ret;
+
+	dev_dbg(arizona->dev, "Set %s to %d Hz\n", dom->driver->name, rate);
+
+	switch (arizona->type) {
+	case WM5102:
+	case WM8997:
+		if (rate >= 88200)
+			ret = arizona_dvfs_up(component, dpriv->dvfs_mask);
+		else
+			ret = arizona_dvfs_down(component, dpriv->dvfs_mask);
+
+		if (ret) {
+			dev_err(arizona->dev,
+				"Failed to change DVFS for %s: %d\n",
+				dom->driver->name, ret);
+			return ret;
+		}
+		break;
+	default:
+		break;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(arizona_sr_vals); i++) {
+		if (arizona_sr_vals[i] == rate)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(arizona_sr_vals)) {
+		dev_err(arizona->dev, "Invalid sample rate: %d Hz\n", rate);
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(arizona->regmap, dpriv->reg,
+				  ARIZONA_SAMPLE_RATE_1_MASK, i);
+}
+
+static int arizona_get_rate(struct snd_soc_domain *dom)
+{
+	struct snd_soc_component *component = dom->component;
+	struct arizona *arizona = dev_get_drvdata(component->dev->parent);
+	const struct arizona_rate_dom_priv *dpriv = dom->driver->private_data;
+	unsigned int rate;
+	int ret;
+
+	ret = regmap_read(arizona->regmap, dpriv->reg, &rate);
+	if (ret)
+		return ret;
+
+	rate &= ARIZONA_SAMPLE_RATE_1_MASK;
+
+	if (rate >= ARRAY_SIZE(arizona_sr_vals)) {
+		dev_err(arizona->dev, "Read bad sample rate: 0x%x\n", rate);
+		return -EINVAL;
+	}
+
+	rate = arizona_sr_vals[rate];
+
+	dev_dbg(arizona->dev, "Got %u Hz for %s\n", rate, dom->driver->name);
+
+	return (int)rate;
+}
+
+static const struct snd_soc_domain_ops arizona_dom_ops = {
+	.set_rate = arizona_set_rate,
+	.get_rate = arizona_get_rate,
+};
+
+const struct snd_soc_domain_driver arizona_rate_domains[ARIZONA_RATE_ENUM_SIZE] = {
+	{
+		.name = "Sample Rate 1",
+		.ops = &arizona_dom_ops,
+		.private_data = &(struct arizona_rate_dom_priv){
+			.reg = ARIZONA_SAMPLE_RATE_1,
+			.val = 0,
+			.dvfs_mask = ARIZONA_DVFS_SR1_RQ,
+		},
+	},
+	{
+		.name = "Sample Rate 2",
+		.ops = &arizona_dom_ops,
+		.private_data = &(struct arizona_rate_dom_priv){
+			.reg = ARIZONA_SAMPLE_RATE_2,
+			.val = 1,
+			.dvfs_mask = ARIZONA_DVFS_SR2_RQ,
+		},
+	},
+	{
+		.name = "Sample Rate 3",
+		.ops = &arizona_dom_ops,
+		.private_data = &(struct arizona_rate_dom_priv){
+			.reg = ARIZONA_SAMPLE_RATE_3,
+			.val = 2,
+			.dvfs_mask = ARIZONA_DVFS_SR3_RQ,
+		},
+	},
+	{
+		.name = "Async Sample Rate 1",
+		.ops = &arizona_dom_ops,
+		.private_data = &(struct arizona_rate_dom_priv){
+			.reg = ARIZONA_ASYNC_SAMPLE_RATE_1,
+			.val = 8,
+			.dvfs_mask = ARIZONA_DVFS_ASR1_RQ,
+		},
+	},
+	{
+		.name = "Async Sample Rate 2",
+		.ops = &arizona_dom_ops,
+		.private_data = &(struct arizona_rate_dom_priv){
+			.reg = ARIZONA_ASYNC_SAMPLE_RATE_2,
+			.val = 9,
+			.dvfs_mask = ARIZONA_DVFS_ASR2_RQ,
+		},
+	},
+};
+
+int arizona_set_domain(struct snd_soc_domain_group *dgrp, int dom)
+{
+	struct arizona *arizona = dev_get_drvdata(dgrp->component->dev->parent);
+	const struct arizona_rate_grp_priv *gpriv = dgrp->driver->private_data;
+	const struct arizona_rate_dom_priv *dpriv = arizona_rate_domains[dom].private_data;
+
+	return regmap_update_bits(arizona->regmap, gpriv->reg, gpriv->mask,
+			dpriv->val << gpriv->shift);
+}
+
+int arizona_mask_domain(struct snd_soc_domain_group *dgrp, unsigned long *mask)
+{
+	const struct arizona_rate_grp_priv *gpriv = dgrp->driver->private_data;
+	struct snd_soc_component *component = dgrp->component;
+	struct arizona_priv *priv = snd_soc_component_get_drvdata(component);
+	unsigned long supported = 0;
+
+	switch (gpriv->reg) {
+	case ARIZONA_AIF1_RATE_CTRL:
+	case ARIZONA_AIF2_RATE_CTRL:
+	case ARIZONA_AIF3_RATE_CTRL:
+		switch (priv->dai[ARIZONA_AIF1_RATE_CTRL - gpriv->reg].clk) {
+		case ARIZONA_CLK_ASYNCCLK:
+			supported |= 0x18;
+			break;
+		default:
+			supported |= 0x7;
+			break;
+		}
+		break;
+	default:
+		if (gpriv->sync)
+			supported |= 0x7;
+		if (gpriv->async)
+			supported |= 0x18;
+		break;
+	}
+
+	*mask &= supported;
+
+	return 0;
+}
+
+const struct snd_soc_domain_group_ops arizona_dgrp_ops = {
+	.set_domain = arizona_set_domain,
+	.mask_domains = arizona_mask_domain,
+};
+EXPORT_SYMBOL_GPL(arizona_dgrp_ops);
+
 MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support");
 MODULE_AUTHOR("Mark Brown <[email protected]>");
 MODULE_LICENSE("GPL");
sound/soc/codecs/arizona.h +75 -1

104 lines not on this page · raw message

sound/soc/codecs/wm5110.c +312 -102

444 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#2 lore raw

Applied "ASoC: dapm: Add support for hw_free on CODEC to CODEC links" to the asoc tree

In reply to Charles Keepax

The patch

ASoC: dapm: Add support for hw_free on CODEC to CODEC links

has been applied to the asoc tree at

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

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

Quoted 1 line

From 3c01b0e129e9486c8004e43eba3a70de7393f645 Mon Sep 17 00:00:00 2001

From: Charles Keepax <[email protected]>
Date: Thu, 11 Oct 2018 17:28:28 +0100
Subject: [PATCH] ASoC: dapm: Add support for hw_free on CODEC to CODEC links

Currently, on power down for a CODEC to CODEC DAI link we only call digital_mute and shutdown. Provide a little more flexibility for drivers by adding a call to hw_free as well.

---
 sound/soc/soc-dapm.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
sound/soc/soc-dapm.c +11 -6
index 8c5b065c8880..a5178845065b 100644
@@ -3737,25 +3737,30 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
 			ret = 0;
 		}
 
+		substream.stream = SNDRV_PCM_STREAM_CAPTURE;
 		snd_soc_dapm_widget_for_each_source_path(w, path) {
 			source = path->source->priv;
 
+			if (source->driver->ops->hw_free)
+				source->driver->ops->hw_free(&substream,
+							     source);
+
 			source->active--;
-			if (source->driver->ops->shutdown) {
-				substream.stream = SNDRV_PCM_STREAM_CAPTURE;
+			if (source->driver->ops->shutdown)
 				source->driver->ops->shutdown(&substream,
 							      source);
-			}
 		}
 
+		substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
 		snd_soc_dapm_widget_for_each_sink_path(w, path) {
 			sink = path->sink->priv;
 
+			if (sink->driver->ops->hw_free)
+				sink->driver->ops->hw_free(&substream, sink);
+
 			sink->active--;
-			if (sink->driver->ops->shutdown) {
-				substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
+			if (sink->driver->ops->shutdown)
 				sink->driver->ops->shutdown(&substream, sink);
-			}
 		}
 		break;
 
Signature · 1 line
2.19.0.rc2
maintainer
#3 lore raw

Applied "ASoC: dapm: Add support for hw_free on CODEC to CODEC links" to the asoc tree

In reply to Charles Keepax

The patch

ASoC: dapm: Add support for hw_free on CODEC to CODEC links

has been applied to the asoc tree at

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

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

Quoted 1 line

From 3c01b0e129e9486c8004e43eba3a70de7393f645 Mon Sep 17 00:00:00 2001

From: Charles Keepax <[email protected]>
Date: Thu, 11 Oct 2018 17:28:28 +0100
Subject: [PATCH] ASoC: dapm: Add support for hw_free on CODEC to CODEC links

Currently, on power down for a CODEC to CODEC DAI link we only call digital_mute and shutdown. Provide a little more flexibility for drivers by adding a call to hw_free as well.

---
 sound/soc/soc-dapm.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
sound/soc/soc-dapm.c +11 -6
index 8c5b065c8880..a5178845065b 100644
@@ -3737,25 +3737,30 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
 			ret = 0;
 		}
 
+		substream.stream = SNDRV_PCM_STREAM_CAPTURE;
 		snd_soc_dapm_widget_for_each_source_path(w, path) {
 			source = path->source->priv;
 
+			if (source->driver->ops->hw_free)
+				source->driver->ops->hw_free(&substream,
+							     source);
+
 			source->active--;
-			if (source->driver->ops->shutdown) {
-				substream.stream = SNDRV_PCM_STREAM_CAPTURE;
+			if (source->driver->ops->shutdown)
 				source->driver->ops->shutdown(&substream,
 							      source);
-			}
 		}
 
+		substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
 		snd_soc_dapm_widget_for_each_sink_path(w, path) {
 			sink = path->sink->priv;
 
+			if (sink->driver->ops->hw_free)
+				sink->driver->ops->hw_free(&substream, sink);
+
 			sink->active--;
-			if (sink->driver->ops->shutdown) {
-				substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
+			if (sink->driver->ops->shutdown)
 				sink->driver->ops->shutdown(&substream, sink);
-			}
 		}
 		break;
 
Signature · 1 line
2.19.0.rc2
#7 lore raw
In reply to Charles Keepax
Quoted 7 lines · Charles Keepax

Here is a first pass at adding dapm sample rate domain support. Things are still pretty rough in quite a few places and I expect some major refactoring before they are ready to merge, but things are far enough along for people to look at the approach I am taking to the problem. And should provide enough for discussion at the mini-conference, although hopefully I will get some more done next week as well.

Interesting, too bad I couldn't be in Edinburgh this year.

Quoted 13 lines

The basic high level summary is two new concepts are added to ASoC, one being a sample rate domain and the other being a domain group. The domain groups represent widgets that are limited by hardware restrictions to always run at the same sample rate as each other. Sample rate domains represent a slot on a device for a sample rate. Both of these are currently limited to be within the scope of a single component. The core will track which groups are connected together, then as a group is powered up it will be allocated a domain based on the other groups it is connected to. Domain groups are implemented as a new type of DAPM widget and the domains themselves are a new thing which devices add through their component drivers.

Quoted 9 lines

As we have previously discussed my intention would be that we also add bridges between domains although I haven't started work on that yet. The current code is limited to within a single component and I think that the bridges will allow better support for propagating rates between components as well as obviously for SRCs. Currently the SRCs on wm5110 are just being handled as points where the domain groups don't connect to another peer. This allows them to function but doesn't accurately convey things like the limitations which input rates support which output rates on the ISRC.

My feedback would be: why limit the domains to sample rate definition? we can also have additional criteria such as number of channels, channel maps and bit depth - maybe also audio/non-audio for compressed stuff. It'd be interesting to start with a non-scalar descriptor from day1. To some extent we'd also want something similar to .info definitions, with domains defined with masks to allow for flexibility in the conversions and easier bridge implementations. e.g. it'd be interesting to have a domain definition supporting more than one sampling frequency (8, 16, 48kHz) with the bridge doing the relevant conversion to adapt to the connected domain (fixed 48kHz DAI for example)

Thanks for starting the discussion!

-Pierre

Quoted 24 lines

Thanks,
Charles

Charles Keepax (4):
ASoC: dapm: Add support for hw_free on CODEC to CODEC links
ASoC: dapm: Add support for a rate domain widget
ASoC: domain: Add sample rate domain support
ASoC: arizona: Add rate domain support

  include/sound/soc-dapm.h   |  14 ++
  include/sound/soc-domain.h |  98 +++++++++++
  include/sound/soc.h        |   8 +
  sound/soc/Makefile         |   2 +-
  sound/soc/codecs/arizona.c | 255 ++++++++++++++++++++++------
  sound/soc/codecs/arizona.h |  76 ++++++++-
  sound/soc/codecs/wm5110.c  | 414 ++++++++++++++++++++++++++++++++++-----------
  sound/soc/soc-core.c       |   8 +
  sound/soc/soc-dapm.c       |  57 ++++++-
  sound/soc/soc-domain.c     | 412 ++++++++++++++++++++++++++++++++++++++++++++
  10 files changed, 1183 insertions(+), 161 deletions(-)

create mode 100644 include/sound/soc-domain.h
create mode 100644 sound/soc/soc-domain.c

#8 lore raw
Quoted 14 lines · Pierre-Louis Bossart

On 10/11/18 11:28 AM, Charles Keepax wrote:
My feedback would be: why limit the domains to sample rate definition? we can also have additional criteria such as number of channels, channel maps and bit depth - maybe also audio/non-audio for compressed stuff. It'd be interesting to start with a non-scalar descriptor from day1. To some extent we'd also want something similar to .info definitions, with domains defined with masks to allow for flexibility in the conversions and easier bridge implementations. e.g. it'd be interesting to have a domain definition supporting more than one sampling frequency (8, 16, 48kHz) with the bridge doing the relevant conversion to adapt to the connected domain (fixed 48kHz DAI for example)

Quoted 1 line

Thanks for starting the discussion!

I don't think there really is anything about the way I am approaching the code that will limit this to just sample rates, it's more that is the part I need at the moment so is what I am implementing. I have basically a "domain" structure, that gets assigned as the groups power up, this is in no way specific to rates. We can just extend that struct to have other properties and add new ops on the domains as people discover additional features they require. Currently at that point in the code you will see a TODO which says to consider using a hw_params struct instead of just an int for the rate. I think based on your comments and others at the conference I will definitely be switching to that in the next spin. Although implementing the additional callbacks etc. is not something I can find sensible use-cases for on our devices, so someone else might need to pick up that part.

Thanks,
Charles