sdw.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include <linux/soundwire/sdw.h>
  10. #include <sound/asound.h>
  11. #include <sound/pcm.h>
  12. #include <sound/pcm_params.h>
  13. #ifndef __INCLUDE_SOUND_SDW_H
  14. #define __INCLUDE_SOUND_SDW_H
  15. /**
  16. * snd_sdw_params_to_config() - Conversion from hw_params to SoundWire config
  17. *
  18. * @substream: Pointer to the PCM substream structure
  19. * @params: Pointer to the hardware params structure
  20. * @stream_config: Stream configuration for the SoundWire audio stream
  21. * @port_config: Port configuration for the SoundWire audio stream
  22. *
  23. * This function provides a basic conversion from the hw_params structure to
  24. * SoundWire configuration structures. The user will at a minimum need to also
  25. * set the port number in the port config, but may also override more of the
  26. * setup, or in the case of a complex user, not use this helper at all and
  27. * open-code everything.
  28. */
  29. static inline void snd_sdw_params_to_config(struct snd_pcm_substream *substream,
  30. struct snd_pcm_hw_params *params,
  31. struct sdw_stream_config *stream_config,
  32. struct sdw_port_config *port_config)
  33. {
  34. stream_config->frame_rate = params_rate(params);
  35. stream_config->ch_count = params_channels(params);
  36. stream_config->bps = snd_pcm_format_width(params_format(params));
  37. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  38. stream_config->direction = SDW_DATA_DIR_RX;
  39. else
  40. stream_config->direction = SDW_DATA_DIR_TX;
  41. port_config->ch_mask = GENMASK(stream_config->ch_count - 1, 0);
  42. }
  43. #endif