Add SoundWire port constraints into SDCA stream
Subsystems (3)
Charles Keepax
maintainerv4 cover Add SoundWire port constraints into SDCA stream
SDCA adds constraints onto the DAI based on the DisCo properties for the Input/Output Terminal. As the SoundWire port for a Terminal can be selected it is possible for the SoundWire port to support fewer options than the Terminal. These patches add the SoundWire port properties into the constraints for the DAI startup to cover these situations.
Changes since v3:
- Added defaults for the word length min/max
- Removed unused static_assert
Changes since v2:
- Add check for ending up with a zero mask for channels
- Switch to using SNDRV_PCM_HW_PARAM_FORMAT, rather than SAMPLE_BITS
Changes since v1:
- Move constraint allocation to DAI probe/remove
- Use BIT macro where appropriate
- Correct GENMASK usage
- Add missing array indexing
- Correct channel masking
- Reorder the priority of SDCA properties
- Handle the case of the word length not being specified
- Add a static_assert to check the constraint array is large enough for the word length mask
Charles Keepax (3):
ASoC: SDCA: Move DAI constraint allocation
ASoC: SDCA: Factor out helper for creating mask of Cluster channels
ASoC: SDCA: Add port constraints into sdca_asoc_set_constraints()
include/sound/sdca_asoc.h | 9 +- sound/soc/sdca/sdca_asoc.c | 246 +++++++++++++++++++++------ sound/soc/sdca/sdca_class_function.c | 6 +- 3 files changed, 206 insertions(+), 55 deletions(-)
Signature · 1 line
2.47.3
Charles Keepax
maintainerPATCH v4 1/3 ASoC: SDCA: Move DAI constraint allocation
It isn't necessary to allocate memory for constraints every time a DAI link is opened. It is faster to allocate them once when the DAI link is probed, update the SDCA code to do so.
---
No changes since v3.
include/sound/sdca_asoc.h | 5 +- sound/soc/sdca/sdca_asoc.c | 75 +++++++++++++++++----------- sound/soc/sdca/sdca_class_function.c | 3 +- 3 files changed, 52 insertions(+), 31 deletions(-)
include/sound/sdca_asoc.h +3 -2
@@ -89,12 +89,13 @@ int sdca_asoc_populate_rate_format(struct device *dev,struct sdca_entity *entity, struct snd_soc_pcm_stream *stream); +int sdca_asoc_alloc_constraints (struct snd_soc_dai *dai); +int sdca_asoc_free_constraints (struct snd_soc_dai *dai);int sdca_asoc_set_constraints (struct device *dev,struct regmap *regmap,struct sdca_function_data *function,struct snd_pcm_substream *substream,struct snd_soc_dai *dai); -void sdca_asoc_free_constraints (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai); +int sdca_asoc_get_port (struct device *dev,struct regmap *regmap,struct sdca_function_data *function,struct snd_soc_dai *dai);
sound/soc/sdca/sdca_asoc.c +47 -28
106 lines not on this page · raw message
sound/soc/sdca/sdca_class_function.c +2 -1
@@ -184,8 +184,9 @@ static int class_function_sdw_set_stream(struct snd_soc_dai *dai, void *sdw_stre }static const struct snd_soc_dai_ops class_function_sdw_ops = { + .probe = sdca_asoc_alloc_constraints, + .remove = sdca_asoc_free_constraints, .startup = class_function_startup, - .shutdown = sdca_asoc_free_constraints, .set_stream = class_function_sdw_set_stream, .hw_params = class_function_sdw_add_peripheral, .hw_free = class_function_sdw_remove_peripheral,
Signature · 1 line
2.47.3
Charles Keepax
maintainerPATCH v4 2/3 ASoC: SDCA: Factor out helper for creating mask of Cluster channels
In reply to Charles KeepaxFactor out the code that builds a mask of the allowed channels from the Cluster information. This is slightly cleaner and prepares for additional constraints to be added to sdca_asoc_set_constraints().
---
No changes since v3.
sound/soc/sdca/sdca_asoc.c | 64 +++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 25 deletions(-)
sound/soc/sdca/sdca_asoc.c +39 -25
@@ -1476,6 +1476,37 @@ int sdca_asoc_free_constraints(struct snd_soc_dai *dai) }EXPORT_SYMBOL_NS (sdca_asoc_free_constraints,"SND_SOC_SDCA" ); +static int get_cluster_mask (struct device *dev,struct sdca_function_data *function, +struct sdca_entity *entity,unsigned int *ch_mask) +{ +struct sdca_control_range *range; +struct sdca_control *control; +int i; + + control =sdca_selector_find_control (dev, entity,SDCA_CTL_IT_CLUSTERINDEX ); +if (!control) +return -EINVAL ; + + range =sdca_control_find_range (dev, entity, control,SDCA_CLUSTER_NCOLS ,0 ); +if (!range) +return -EINVAL ; + + *ch_mask =0 ; + +for (i =0 ; i < range->rows; i++) { +int clusterid =sdca_range (range,SDCA_CLUSTER_CLUSTERID , i); +struct sdca_cluster *cluster; + + cluster =sdca_id_find_cluster (dev, function, clusterid); +if (!cluster) +return -ENODEV ; + + *ch_mask |=BIT (cluster->num_channels -1 ); + } + +return 0 ; +} +/** * sdca_asoc_set_constraints - constrain channels available on a DAI * @dev: Pointer to the device, used for error messages.
@@ -1499,42 +1530,25 @@ int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap, };struct sdca_asoc_constraints *constraints =snd_soc_dai_to_priv (dai);struct sdca_entity *entity = &function->entities[dai->id]; -struct sdca_control_range *range; -struct sdca_control *control; -unsigned int channel_mask =0 ; -int i, ret; +unsigned int cluster_ch_mask; +int ret;static_assert (ARRAY_SIZE (channel_list) ==SDCA_MAX_CHANNEL_COUNT ); -static_assert (sizeof (channel_mask) *BITS_PER_BYTE >=SDCA_MAX_CHANNEL_COUNT ); +static_assert (sizeof (cluster_ch_mask) *BITS_PER_BYTE >=SDCA_MAX_CHANNEL_COUNT );if (entity->type !=SDCA_ENTITY_TYPE_IT )return 0 ; - control =sdca_selector_find_control (dev, entity,SDCA_CTL_IT_CLUSTERINDEX ); -if (!control) -return -EINVAL ; - - range =sdca_control_find_range (dev, entity, control,SDCA_CLUSTER_NCOLS ,0 ); -if (!range) -return -EINVAL ; - -for (i =0 ; i < range->rows; i++) { -int clusterid =sdca_range (range,SDCA_CLUSTER_CLUSTERID , i); -struct sdca_cluster *cluster; - - cluster =sdca_id_find_cluster (dev, function, clusterid); -if (!cluster) -return -ENODEV ; - - channel_mask |= (1 << (cluster->num_channels -1 )); - } + ret =get_cluster_mask (dev, function, entity, &cluster_ch_mask); +if (ret) +return ret;dev_dbg (dev,"%s: set channel constraint mask: %#x\n" , - entity->label, channel_mask); + entity->label, cluster_ch_mask); constraints->channels.count =ARRAY_SIZE (channel_list); constraints->channels.list = channel_list; - constraints->channels.mask = channel_mask; + constraints->channels.mask = cluster_ch_mask; ret = snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
Signature · 1 line
2.47.3
Charles Keepax
maintainerPATCH v4 3/3 ASoC: SDCA: Add port constraints into sdca_asoc_set_constraints()
In reply to Charles KeepaxCurrently the SDCA code constrains the params based on the DisCo for the SDCA Terminal used. However, it ignores the properties of the SoundWire port, which in some cases may further constrain the allowed params. Add additional constraints to apply these restrictions.
Some minor additional refactoring is required since port constraints should be applied for both Input and Output Terminals, whereas currently Cluster constraints are only handled for Input Terminals.
---
Changes since v3:
- Added defaults for the word length min/max
- Removed unused static_assert
Also regarding ch_min/ch_max one can't assume defaults locally for those as 0/0 is a valid combo. I have a patch that adds defaults at the soundwire end, I will upstream that likely tomorrow.
include/sound/sdca_asoc.h | 4 +- sound/soc/sdca/sdca_asoc.c | 133 +++++++++++++++++++++++++-- sound/soc/sdca/sdca_class_function.c | 3 +- 3 files changed, 128 insertions(+), 12 deletions(-)
include/sound/sdca_asoc.h +3 -1
@@ -12,6 +12,7 @@struct device ;struct regmap ; +struct sdw_slave ;struct sdca_function_data ;struct sdca_pde_delay ;struct snd_ctl_elem_value ;
@@ -91,7 +92,8 @@ int sdca_asoc_populate_rate_format(struct device *dev,int sdca_asoc_alloc_constraints (struct snd_soc_dai *dai);int sdca_asoc_free_constraints (struct snd_soc_dai *dai); -int sdca_asoc_set_constraints (struct device *dev,struct regmap *regmap, +int sdca_asoc_set_constraints (struct device *dev,struct sdw_slave *sdw, +struct regmap *regmap,struct sdca_function_data *function,struct snd_pcm_substream *substream,struct snd_soc_dai *dai);
sound/soc/sdca/sdca_asoc.c +123 -10
187 lines not on this page · raw message
sound/soc/sdca/sdca_class_function.c +2 -1
@@ -121,8 +121,9 @@ static int class_function_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) {struct class_function_drv *drv =snd_soc_component_get_drvdata (dai->component); +struct sdw_slave *sdw =dev_to_sdw_dev (drv->dev->parent); -return sdca_asoc_set_constraints (drv->dev, drv->regmap, drv->function, +return sdca_asoc_set_constraints (drv->dev, sdw, drv->regmap, drv->function, substream, dai); }
Signature · 1 line
2.47.3
Quoted 30 lines · Charles Keepax
SDCA adds constraints onto the DAI based on the DisCo properties for the Input/Output Terminal. As the SoundWire port for a Terminal can be selected it is possible for the SoundWire port to support fewer options than the Terminal. These patches add the SoundWire port properties into the constraints for the DAI startup to cover these situations.
Changes since v3:
- Added defaults for the word length min/max
- Removed unusedstatic_assertChanges since v2:
- Add check for ending up with a zero mask for channels
- Switch to usingSNDRV_PCM_HW_PARAM_FORMAT, rather thanSAMPLE_BITSChanges since v1:
- Move constraint allocation to DAI probe/remove
- Use BIT macro where appropriate
- Correct GENMASK usage
- Add missing array indexing
- Correct channel masking
- Reorder the priority of SDCA properties
- Handle the case of the word length not being specified
- Add astatic_assertto check the constraint array is large enough for the word length maskCharles Keepax (3):
ASoC: SDCA: Move DAI constraint allocation
ASoC: SDCA: Factor out helper for creating mask of Cluster channels
ASoC: SDCA: Add port constraints intosdca_asoc_set_constraints()
Quoted 4 lines
include/sound/sdca_asoc.h | 9 +- sound/soc/sdca/sdca_asoc.c | 246 +++++++++++++++++++++------ sound/soc/sdca/sdca_class_function.c | 6 +- 3 files changed, 206 insertions(+), 55 deletions(-)
LGTM
Mark Brown
maintainerQuoted 9 lines · Charles Keepax
Add SoundWire port constraints into SDCA stream
SDCA adds constraints onto the DAI based on the DisCo properties for the Input/Output Terminal. As the SoundWire port for a Terminal can be selected it is possible for the SoundWire port to support fewer options than the Terminal. These patches add the SoundWire port properties into the constraints for the DAI startup to cover these situations.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5
Thanks!
[1/3] ASoC: SDCA: Move DAI constraint allocation
https://git.kernel.org/broonie/sound/c/0bad08d2865a [2/3] ASoC: SDCA: Factor out helper for creating mask of Cluster channels https://git.kernel.org/broonie/sound/c/5ee6093d3a84 [3/3] ASoC: SDCA: Add port constraints into sdca_asoc_set_constraints() https://git.kernel.org/broonie/sound/c/8bb24d87078f
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