diff mbox series

[v3,1/9] sound: sdw: Add hw_params to SoundWire config helper function

Message ID 20221123165432.594972-1-ckeepax@opensource.cirrus.com (mailing list archive)
State Accepted
Commit e45875168d19051ebf0fc4b091da6256f3ea3669
Headers show
Series [v3,1/9] sound: sdw: Add hw_params to SoundWire config helper function | expand

Commit Message

Charles Keepax Nov. 23, 2022, 4:54 p.m. UTC
The vast majority of the current users of the SoundWire framework
have almost identical code for converting from hw_params to SoundWire
configuration. Whilst complex devices might require more, it is very
likely that most new devices will follow the same pattern. Save a
little code by factoring this out into a helper function.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

I  was a little bit two minds about whether to make this an inline or
not, so any thoughts on that would be super welcome. The function does
very little, especially given that SNDRV_PCM_STREAM_PLAYBACK ==
SDW_DATA_DIR_RX so the if is also really just an assignment.

Thanks,
Charles

Changes since v2:
 - No difference
Changes since v1:
 - Correct spelling error in commit message

 include/sound/sdw.h | 49 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 include/sound/sdw.h

Comments

Mark Brown Nov. 28, 2022, 4:39 p.m. UTC | #1
On Wed, 23 Nov 2022 16:54:24 +0000, Charles Keepax wrote:
> The vast majority of the current users of the SoundWire framework
> have almost identical code for converting from hw_params to SoundWire
> configuration. Whilst complex devices might require more, it is very
> likely that most new devices will follow the same pattern. Save a
> little code by factoring this out into a helper function.
> 
> 
> [...]

Applied to

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

Thanks!

[1/9] sound: sdw: Add hw_params to SoundWire config helper function
      commit: e45875168d19051ebf0fc4b091da6256f3ea3669
[2/9] ASoC: max98373-sdw: Switch to new snd_sdw_params_to_config helper
      commit: d12f106177288a65b58b236304b6ceea4370f65d
[3/9] ASoC: rt1308-sdw: Switch to new snd_sdw_params_to_config helper
      commit: 896c59edcdafc4e213761184294cbccf47126a23
[4/9] ASoC: rt1316-sdw: Switch to new snd_sdw_params_to_config helper
      commit: 0725dd0461fc682e9c1bcf9f436e60160dba65a5
[5/9] ASoC: rt5682-sdw: Switch to new snd_sdw_params_to_config helper
      commit: 5b75bc7fc28af62622c57d80f607536b19796d8f
[6/9] ASoC: rt700: Switch to new snd_sdw_params_to_config helper
      commit: ae7ad90e7cf29f3337ac1fe4e60162c51782c2b5
[7/9] ASoC: rt711: Switch to new snd_sdw_params_to_config helper
      commit: 754bef6752259ce5633814a0333f96fa06f6e3e8
[8/9] ASoC: rt715: Switch to new snd_sdw_params_to_config helper
      commit: 99ae8cf0a06b7911ec1d9c6d9190dcb3384255c9
[9/9] ASoC: sdw-mockup: Switch to new snd_sdw_params_to_config helper
      commit: c5f81301d06898080c9a59eda91f6b8605f98a2a

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
diff mbox series

Patch

diff --git a/include/sound/sdw.h b/include/sound/sdw.h
new file mode 100644
index 0000000000000..6dcdb3228dba6
--- /dev/null
+++ b/include/sound/sdw.h
@@ -0,0 +1,49 @@ 
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * linux/sound/sdw.h -- SoundWire helpers for ALSA/ASoC
+ *
+ * Copyright (c) 2022 Cirrus Logic Inc.
+ *
+ * Author: Charles Keepax <ckeepax@opensource.cirrus.com>
+ */
+
+#include <linux/soundwire/sdw.h>
+#include <sound/asound.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+
+#ifndef __INCLUDE_SOUND_SDW_H
+#define __INCLUDE_SOUND_SDW_H
+
+/**
+ * snd_sdw_params_to_config() - Conversion from hw_params to SoundWire config
+ *
+ * @substream: Pointer to the PCM substream structure
+ * @params: Pointer to the hardware params structure
+ * @stream_config: Stream configuration for the SoundWire audio stream
+ * @port_config: Port configuration for the SoundWire audio stream
+ *
+ * This function provides a basic conversion from the hw_params structure to
+ * SoundWire configuration structures. The user will at a minimum need to also
+ * set the port number in the port config, but may also override more of the
+ * setup, or in the case of a complex user, not use this helper at all and
+ * open-code everything.
+ */
+static inline void snd_sdw_params_to_config(struct snd_pcm_substream *substream,
+					    struct snd_pcm_hw_params *params,
+					    struct sdw_stream_config *stream_config,
+					    struct sdw_port_config *port_config)
+{
+	stream_config->frame_rate = params_rate(params);
+	stream_config->ch_count = params_channels(params);
+	stream_config->bps = snd_pcm_format_width(params_format(params));
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		stream_config->direction = SDW_DATA_DIR_RX;
+	else
+		stream_config->direction = SDW_DATA_DIR_TX;
+
+	port_config->ch_mask = GENMASK(stream_config->ch_count - 1, 0);
+}
+
+#endif