1 /* SPDX-License-Identifier: GPL-2.0
3 * linux/sound/sdw.h -- SoundWire helpers for ALSA/ASoC
5 * Copyright (c) 2022 Cirrus Logic Inc.
7 * Author: Charles Keepax <ckeepax@opensource.cirrus.com>
10 #include <linux/soundwire/sdw.h>
11 #include <sound/asound.h>
12 #include <sound/pcm.h>
13 #include <sound/pcm_params.h>
15 #ifndef __INCLUDE_SOUND_SDW_H
16 #define __INCLUDE_SOUND_SDW_H
19 * snd_sdw_params_to_config() - Conversion from hw_params to SoundWire config
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
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.
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
)
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
));
41 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
42 stream_config
->direction
= SDW_DATA_DIR_RX
;
44 stream_config
->direction
= SDW_DATA_DIR_TX
;
46 port_config
->ch_mask
= GENMASK(stream_config
->ch_count
- 1, 0);