xref: /linux/include/sound/sdw.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * linux/sound/sdw.h -- SoundWire helpers for ALSA/ASoC
4  *
5  * Copyright (c) 2022 Cirrus Logic Inc.
6  *
7  * Author: Charles Keepax <ckeepax@opensource.cirrus.com>
8  */
9 
10 #include <linux/soundwire/sdw.h>
11 #include <sound/asound.h>
12 #include <sound/pcm.h>
13 #include <sound/pcm_params.h>
14 
15 #ifndef __INCLUDE_SOUND_SDW_H
16 #define __INCLUDE_SOUND_SDW_H
17 
18 /**
19  * snd_sdw_params_to_config() - Conversion from hw_params to SoundWire config
20  *
21  * @substream: Pointer to the PCM substream structure
22  * @params: Pointer to the hardware params structure
23  * @stream_config: Stream configuration for the SoundWire audio stream
24  * @port_config: Port configuration for the SoundWire audio stream
25  *
26  * This function provides a basic conversion from the hw_params structure to
27  * SoundWire configuration structures. The user will at a minimum need to also
28  * set the port number in the port config, but may also override more of the
29  * setup, or in the case of a complex user, not use this helper at all and
30  * open-code everything.
31  */
32 static inline void snd_sdw_params_to_config(struct snd_pcm_substream *substream,
33 					    struct snd_pcm_hw_params *params,
34 					    struct sdw_stream_config *stream_config,
35 					    struct sdw_port_config *port_config)
36 {
37 	stream_config->frame_rate = params_rate(params);
38 	stream_config->ch_count = params_channels(params);
39 	stream_config->bps = snd_pcm_format_width(params_format(params));
40 
41 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
42 		stream_config->direction = SDW_DATA_DIR_RX;
43 	else
44 		stream_config->direction = SDW_DATA_DIR_TX;
45 
46 	port_config->ch_mask = GENMASK(stream_config->ch_count - 1, 0);
47 }
48 
49 #endif
50