From ae7ad90e7cf29f3337ac1fe4e60162c51782c2b5 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Wed, 23 Nov 2022 16:54:29 +0000 Subject: [PATCH] ASoC: rt700: Switch to new snd_sdw_params_to_config helper The conversion from hw_params to SoundWire config is pretty standard as such most of the conversion can be handled by the new snd_sdw_params_to_config helper function. Signed-off-by: Charles Keepax Link: https://lore.kernel.org/r/20221123165432.594972-6-ckeepax@opensource.cirrus.com Signed-off-by: Mark Brown --- sound/soc/codecs/rt700.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/sound/soc/codecs/rt700.c b/sound/soc/codecs/rt700.c index 055c3ae..6534c9b 100644 --- a/sound/soc/codecs/rt700.c +++ b/sound/soc/codecs/rt700.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -910,11 +911,10 @@ static int rt700_pcm_hw_params(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt700_priv *rt700 = snd_soc_component_get_drvdata(component); - struct sdw_stream_config stream_config; - struct sdw_port_config port_config; - enum sdw_data_direction direction; + struct sdw_stream_config stream_config = {0}; + struct sdw_port_config port_config = {0}; struct sdw_stream_data *stream; - int retval, port, num_channels; + int retval; unsigned int val = 0; dev_dbg(dai->dev, "%s %s", __func__, dai->name); @@ -927,35 +927,25 @@ static int rt700_pcm_hw_params(struct snd_pcm_substream *substream, return -EINVAL; /* SoundWire specific configuration */ + snd_sdw_params_to_config(substream, params, &stream_config, &port_config); + /* This code assumes port 1 for playback and port 2 for capture */ - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - direction = SDW_DATA_DIR_RX; - port = 1; - } else { - direction = SDW_DATA_DIR_TX; - port = 2; - } + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + port_config.num = 1; + else + port_config.num = 2; switch (dai->id) { case RT700_AIF1: break; case RT700_AIF2: - port += 2; + port_config.num += 2; break; default: dev_err(component->dev, "Invalid DAI id %d\n", dai->id); return -EINVAL; } - stream_config.frame_rate = params_rate(params); - stream_config.ch_count = params_channels(params); - 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.num = port; - retval = sdw_stream_add_slave(rt700->slave, &stream_config, &port_config, 1, stream->sdw_stream); if (retval) { -- 2.7.4