mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: SDCA: Combine width_find_mask() and get_word_mask()
@ 2026-11-23 11:52 Charles Keepax
  0 siblings, 0 replies; only message in thread
From: Charles Keepax @ 2026-11-23 11:52 UTC (permalink / raw)
  To: broonie
  Cc: lgirdwood, yung-chuan.liao, pierre-louis.bossart, linux-sound,
	linux-kernel, patches

Both of these functions take a bit width and return the ALSA mask
bits for that width. Remove get_word_mask() and use width_find_mask()
in all cases.

As part of this the function is expanded with a few additional
formats. The big endian versions are added to the mask, for
the original dai driver users of width_find_mask() these would
be added by the ASoC core, however that isn't true when used for
ALSA constraint users of get_word_mask(). The 3LE versions are also
added as the memory size shouldn't be a factor once on the SoundWire
bus. Finally, support for the unsigned formats is removed relative
to get_word_mask(), these are not commonly used and the SoundWire
specification has no obvious mechanism to indicate if they are
supported. So better these are only added once a user comes forward.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 sound/soc/sdca/sdca_asoc.c | 56 ++++++++++++--------------------------
 1 file changed, 18 insertions(+), 38 deletions(-)

diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c
index aaa84156f20a8..d58be660ced7f 100644
--- a/sound/soc/sdca/sdca_asoc.c
+++ b/sound/soc/sdca/sdca_asoc.c
@@ -1214,19 +1214,28 @@ static u64 width_find_mask(unsigned int bits)
 {
 	switch (bits) {
 	case 0:
-		return SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |
-		       SNDRV_PCM_FMTBIT_S20_LE | SNDRV_PCM_FMTBIT_S24_LE |
-		       SNDRV_PCM_FMTBIT_S32_LE;
+		return SNDRV_PCM_FMTBIT_S8 |
+		       SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
+		       SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE |
+		       SNDRV_PCM_FMTBIT_S20_LE | SNDRV_PCM_FMTBIT_S20_BE |
+		       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE |
+		       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |
+		       SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |
+		       SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
 	case 8:
 		return SNDRV_PCM_FMTBIT_S8;
 	case 16:
-		return SNDRV_PCM_FMTBIT_S16_LE;
+		return SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE;
+	case 18:
+		return SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE;
 	case 20:
-		return SNDRV_PCM_FMTBIT_S20_LE;
+		return SNDRV_PCM_FMTBIT_S20_LE | SNDRV_PCM_FMTBIT_S20_BE |
+		       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE;
 	case 24:
-		return SNDRV_PCM_FMTBIT_S24_LE;
+		return SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |
+		       SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE;
 	case 32:
-		return SNDRV_PCM_FMTBIT_S32_LE;
+		return SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE;
 	default:
 		return 0;
 	}
@@ -1510,35 +1519,6 @@ static int get_cluster_mask(struct device *dev, struct sdca_function_data *funct
 	return 0;
 }
 
-static u64 get_word_mask(unsigned int width)
-{
-	switch (width) {
-	case 8:
-		return SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8;
-	case 16:
-		return SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
-		       SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE;
-	case 18:
-		return SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_U18_3LE |
-		       SNDRV_PCM_FMTBIT_S18_3BE | SNDRV_PCM_FMTBIT_U18_3BE;
-	case 20:
-		return SNDRV_PCM_FMTBIT_S20_LE | SNDRV_PCM_FMTBIT_U20_LE |
-		       SNDRV_PCM_FMTBIT_S20_BE | SNDRV_PCM_FMTBIT_U20_BE |
-		       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE |
-		       SNDRV_PCM_FMTBIT_S20_3BE | SNDRV_PCM_FMTBIT_U20_3BE;
-	case 24:
-		return SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |
-		       SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |
-		       SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3LE |
-		       SNDRV_PCM_FMTBIT_S24_3BE | SNDRV_PCM_FMTBIT_U24_3BE;
-	case 32:
-		return SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |
-		       SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE;
-	default:
-		return 0;
-	}
-}
-
 static int get_port_masks(struct sdw_slave *sdw, unsigned int port,
 			  struct snd_pcm_substream *substream,
 			  u64 *word_mask, unsigned int *ch_mask)
@@ -1564,7 +1544,7 @@ static int get_port_masks(struct sdw_slave *sdw, unsigned int port,
 
 		if (prop[i].num_words) {
 			for (j = 0; j < prop[i].num_words; j++)
-				*word_mask |= get_word_mask(prop[i].words[j]);
+				*word_mask |= width_find_mask(prop[i].words[j]);
 		} else {
 			unsigned int max = prop[i].max_word;
 
@@ -1572,7 +1552,7 @@ static int get_port_masks(struct sdw_slave *sdw, unsigned int port,
 				max = 32;
 
 			for (j = MAX(1, prop[i].min_word); j <= max; j++)
-				*word_mask |= get_word_mask(j);
+				*word_mask |= width_find_mask(j);
 		}
 
 		/* Only handle the number of channels for constraints. */
-- 
2.47.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 11:52 [PATCH] ASoC: SDCA: Combine width_find_mask() and get_word_mask() Charles Keepax

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®