Skip to contentSkip to conversation

ASoC: rt1308-sdw: configure amplifier with set_tdm_slot()

PATCH In review Pierre-Louis Bossart 2 participants 5 messages Mar 25, 2020 – Mar 26, 2020

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

cover ASoC: rt1308-sdw: configure amplifier with set_tdm_slot()

When two (or more) amplifiers are on the same link, the integrator may:
a) assign dedicated slots for each of the amplifiers.
b) provide the same configuration to all amplifiers, and rely on additional controls/processing in the amplifier to generate different outputs.

case a) was the initial direction for SoundWire and is required for amplifiers with limited capabilities, but to deal with orientation or 'posture' changes it's easier to implement case b) when the amplifier can deal with multiple channels.

This patchset suggest the use of the set_tdm_slot() API to define which of the channels will be consumed by what amplifiers. This maps well with SoundWire's 'ChannelEnable' registers. The notion of slot_width is however irrelevant here and ignored, and SoundWire ports are typically single direction, so only one of the two masks shall be used.

Pierre-Louis Bossart (2):
ASoC: rt1308-sdw: add set_tdm_slot() support
ASoC: rt1308-sdw: use slot and rx_mask to configure stream

 sound/soc/codecs/rt1308-sdw.c | 38 +++++++++++++++++++++++++++++++----
 sound/soc/codecs/rt1308-sdw.h |  2 ++
 2 files changed, 36 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 ASoC: rt1308-sdw: add set_tdm_slot() support

Add ability to select which of the channels is used, or both, in case two RT1308 amplifiers are located on the same link.

---
 sound/soc/codecs/rt1308-sdw.c | 23 +++++++++++++++++++++++
 sound/soc/codecs/rt1308-sdw.h |  2 ++
 2 files changed, 25 insertions(+)
sound/soc/codecs/rt1308-sdw.c +23 -0
index d930f60cb797..8763192434c4 100644
@@ -507,6 +507,28 @@ static void rt1308_sdw_shutdown(struct snd_pcm_substream *substream,
 	kfree(stream);
 }
 
+static int rt1308_sdw_set_tdm_slot(struct snd_soc_dai *dai,
+				   unsigned int tx_mask,
+				   unsigned int rx_mask,
+				   int slots, int slot_width)
+{
+	struct snd_soc_component *component = dai->component;
+	struct rt1308_sdw_priv *rt1308 =
+		snd_soc_component_get_drvdata(component);
+
+	if (tx_mask)
+		return -EINVAL;
+
+	if (slots > 2)
+		return -EINVAL;
+
+	rt1308->rx_mask = rx_mask;
+	rt1308->slots = slots;
+	/* slot_width is not used since it's irrelevant for SoundWire */
+
+	return 0;
+}
+
 static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
@@ -597,6 +619,7 @@ static const struct snd_soc_dai_ops rt1308_aif_dai_ops = {
 	.hw_free	= rt1308_sdw_pcm_hw_free,
 	.set_sdw_stream	= rt1308_set_sdw_stream,
 	.shutdown	= rt1308_sdw_shutdown,
+	.set_tdm_slot	= rt1308_sdw_set_tdm_slot,
 };
 
 #define RT1308_STEREO_RATES SNDRV_PCM_RATE_48000
sound/soc/codecs/rt1308-sdw.h +2 -0
index c9341e70d6cf..c5ce75666dcc 100644
@@ -160,6 +160,8 @@ struct rt1308_sdw_priv {
 	struct sdw_bus_params params;
 	bool hw_init;
 	bool first_hw_init;
+	int rx_mask;
+	int slots;
 };
 
 struct sdw_stream_data {
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Applied "ASoC: rt1308-sdw: add set_tdm_slot() support" to the asoc tree

The patch

ASoC: rt1308-sdw: add set_tdm_slot() support

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

From f7cc9b996e7417708b8168697762e4bc97fa6696 Mon Sep 17 00:00:00 2001
From: Pierre-Louis Bossart <[email protected]>
Date: Wed, 25 Mar 2020 16:29:04 -0500
Subject: [PATCH] ASoC: rt1308-sdw: add set_tdm_slot() support

Add ability to select which of the channels is used, or both, in case two RT1308 amplifiers are located on the same link.

---
 sound/soc/codecs/rt1308-sdw.c | 23 +++++++++++++++++++++++
 sound/soc/codecs/rt1308-sdw.h |  2 ++
 2 files changed, 25 insertions(+)
sound/soc/codecs/rt1308-sdw.c +23 -0
index d930f60cb797..8763192434c4 100644
@@ -507,6 +507,28 @@ static void rt1308_sdw_shutdown(struct snd_pcm_substream *substream,
 	kfree(stream);
 }
 
+static int rt1308_sdw_set_tdm_slot(struct snd_soc_dai *dai,
+				   unsigned int tx_mask,
+				   unsigned int rx_mask,
+				   int slots, int slot_width)
+{
+	struct snd_soc_component *component = dai->component;
+	struct rt1308_sdw_priv *rt1308 =
+		snd_soc_component_get_drvdata(component);
+
+	if (tx_mask)
+		return -EINVAL;
+
+	if (slots > 2)
+		return -EINVAL;
+
+	rt1308->rx_mask = rx_mask;
+	rt1308->slots = slots;
+	/* slot_width is not used since it's irrelevant for SoundWire */
+
+	return 0;
+}
+
 static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
@@ -597,6 +619,7 @@ static const struct snd_soc_dai_ops rt1308_aif_dai_ops = {
 	.hw_free	= rt1308_sdw_pcm_hw_free,
 	.set_sdw_stream	= rt1308_set_sdw_stream,
 	.shutdown	= rt1308_sdw_shutdown,
+	.set_tdm_slot	= rt1308_sdw_set_tdm_slot,
 };
 
 #define RT1308_STEREO_RATES SNDRV_PCM_RATE_48000
sound/soc/codecs/rt1308-sdw.h +2 -0
index c9341e70d6cf..c5ce75666dcc 100644
@@ -160,6 +160,8 @@ struct rt1308_sdw_priv {
 	struct sdw_bus_params params;
 	bool hw_init;
 	bool first_hw_init;
+	int rx_mask;
+	int slots;
 };
 
 struct sdw_stream_data {
Signature · 1 line
2.20.1
#3 lore raw

PATCH 2/2 ASoC: rt1308-sdw: use slot and rx_mask to configure stream

In reply to Pierre-Louis Bossart

If the DAI was configured with a set_tdm_slots() call, use the information.

A platform or machine driver may configure each amplifier to extract different bitSlots from the frame, or extract the same data and use processing to generate the relevant output. The latter case is easier to handle in case of orientation changes.

---
 sound/soc/codecs/rt1308-sdw.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
sound/soc/codecs/rt1308-sdw.c +11 -4
index 8763192434c4..a5a7e46de246 100644
@@ -539,7 +539,7 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
 	struct sdw_port_config port_config;
 	enum sdw_data_direction direction;
 	struct sdw_stream_data *stream;
-	int retval, port, num_channels;
+	int retval, port, num_channels, ch_mask;
 
 	dev_dbg(dai->dev, "%s %s", __func__, dai->name);
 	stream = snd_soc_dai_get_dma_data(dai, substream);
@@ -559,13 +559,20 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
+	if (rt1308->slots) {
+		num_channels = rt1308->slots;
+		ch_mask = rt1308->rx_mask;
+	} else {
+		num_channels = params_channels(params);
+		ch_mask = (1 << num_channels) - 1;
+	}
+
 	stream_config.frame_rate = params_rate(params);
-	stream_config.ch_count = params_channels(params);
+	stream_config.ch_count = num_channels;
 	stream_config.bps = snd_pcm_format_width(params_format(params));
 	stream_config.direction = direction;
 
-	num_channels = params_channels(params);
-	port_config.ch_mask = (1 << (num_channels)) - 1;
+	port_config.ch_mask = ch_mask;
 	port_config.num = port;
 
 	retval = sdw_stream_add_slave(rt1308->sdw_slave, &stream_config,
Signature · 1 line
2.20.1
maintainer
#4 lore raw

Applied "ASoC: rt1308-sdw: use slot and rx_mask to configure stream" to the asoc tree

The patch

ASoC: rt1308-sdw: use slot and rx_mask to configure stream

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

From 27a18e9e673f03b48a881e133a532c1619b711c7 Mon Sep 17 00:00:00 2001
From: Pierre-Louis Bossart <[email protected]>
Date: Wed, 25 Mar 2020 16:29:05 -0500
Subject: [PATCH] ASoC: rt1308-sdw: use slot and rx_mask to configure stream

If the DAI was configured with a set_tdm_slots() call, use the information.

A platform or machine driver may configure each amplifier to extract different bitSlots from the frame, or extract the same data and use processing to generate the relevant output. The latter case is easier to handle in case of orientation changes.

---
 sound/soc/codecs/rt1308-sdw.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
sound/soc/codecs/rt1308-sdw.c +11 -4
index 8763192434c4..a5a7e46de246 100644
@@ -539,7 +539,7 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
 	struct sdw_port_config port_config;
 	enum sdw_data_direction direction;
 	struct sdw_stream_data *stream;
-	int retval, port, num_channels;
+	int retval, port, num_channels, ch_mask;
 
 	dev_dbg(dai->dev, "%s %s", __func__, dai->name);
 	stream = snd_soc_dai_get_dma_data(dai, substream);
@@ -559,13 +559,20 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
+	if (rt1308->slots) {
+		num_channels = rt1308->slots;
+		ch_mask = rt1308->rx_mask;
+	} else {
+		num_channels = params_channels(params);
+		ch_mask = (1 << num_channels) - 1;
+	}
+
 	stream_config.frame_rate = params_rate(params);
-	stream_config.ch_count = params_channels(params);
+	stream_config.ch_count = num_channels;
 	stream_config.bps = snd_pcm_format_width(params_format(params));
 	stream_config.direction = direction;
 
-	num_channels = params_channels(params);
-	port_config.ch_mask = (1 << (num_channels)) - 1;
+	port_config.ch_mask = ch_mask;
 	port_config.num = port;
 
 	retval = sdw_stream_add_slave(rt1308->sdw_slave, &stream_config,
Signature · 1 line
2.20.1