Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __SOUND_PCM_PARAMS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __SOUND_PCM_PARAMS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  PCM params helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 			   struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 			   snd_pcm_hw_param_t var, int *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 			  struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 			  snd_pcm_hw_param_t var, int *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 			   snd_pcm_hw_param_t var, int *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define SNDRV_MASK_BITS	64	/* we use so far 64bits only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define SNDRV_MASK_SIZE	(SNDRV_MASK_BITS / 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define MASK_OFS(i)	((i) >> 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define MASK_BIT(i)	(1U << ((i) & 31))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static inline void snd_mask_none(struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	memset(mask, 0, sizeof(*mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static inline void snd_mask_any(struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	memset(mask, 0xff, SNDRV_MASK_SIZE * sizeof(u_int32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static inline int snd_mask_empty(const struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	for (i = 0; i < SNDRV_MASK_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (mask->bits[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static inline unsigned int snd_mask_min(const struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	for (i = 0; i < SNDRV_MASK_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		if (mask->bits[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			return __ffs(mask->bits[i]) + (i << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static inline unsigned int snd_mask_max(const struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	for (i = SNDRV_MASK_SIZE - 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		if (mask->bits[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			return __fls(mask->bits[i]) + (i << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static inline void snd_mask_set(struct snd_mask *mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	mask->bits[MASK_OFS(val)] |= MASK_BIT(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /* Most of drivers need only this one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static inline void snd_mask_set_format(struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				       snd_pcm_format_t format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	snd_mask_set(mask, (__force unsigned int)format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static inline void snd_mask_reset(struct snd_mask *mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	mask->bits[MASK_OFS(val)] &= ~MASK_BIT(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static inline void snd_mask_set_range(struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				      unsigned int from, unsigned int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	for (i = from; i <= to; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		mask->bits[MASK_OFS(i)] |= MASK_BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static inline void snd_mask_reset_range(struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 					unsigned int from, unsigned int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	for (i = from; i <= to; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		mask->bits[MASK_OFS(i)] &= ~MASK_BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static inline void snd_mask_leave(struct snd_mask *mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	unsigned int v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	v = mask->bits[MASK_OFS(val)] & MASK_BIT(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	snd_mask_none(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	mask->bits[MASK_OFS(val)] = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static inline void snd_mask_intersect(struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				      const struct snd_mask *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	for (i = 0; i < SNDRV_MASK_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		mask->bits[i] &= v->bits[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static inline int snd_mask_eq(const struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			      const struct snd_mask *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return ! memcmp(mask, v, SNDRV_MASK_SIZE * sizeof(u_int32_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static inline void snd_mask_copy(struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 				 const struct snd_mask *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	*mask = *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static inline int snd_mask_test(const struct snd_mask *mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return mask->bits[MASK_OFS(val)] & MASK_BIT(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* Most of drivers need only this one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline int snd_mask_test_format(const struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				       snd_pcm_format_t format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return snd_mask_test(mask, (__force unsigned int)format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static inline int snd_mask_single(const struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int i, c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	for (i = 0; i < SNDRV_MASK_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (! mask->bits[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		if (mask->bits[i] & (mask->bits[i] - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		c++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static inline int snd_mask_refine(struct snd_mask *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				  const struct snd_mask *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct snd_mask old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	snd_mask_copy(&old, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	snd_mask_intersect(mask, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (snd_mask_empty(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return !snd_mask_eq(mask, &old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static inline int snd_mask_refine_first(struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (snd_mask_single(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	snd_mask_leave(mask, snd_mask_min(mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static inline int snd_mask_refine_last(struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (snd_mask_single(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	snd_mask_leave(mask, snd_mask_max(mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static inline int snd_mask_refine_min(struct snd_mask *mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (snd_mask_min(mask) >= val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	snd_mask_reset_range(mask, 0, val - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (snd_mask_empty(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static inline int snd_mask_refine_max(struct snd_mask *mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (snd_mask_max(mask) <= val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	snd_mask_reset_range(mask, val + 1, SNDRV_MASK_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (snd_mask_empty(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static inline int snd_mask_refine_set(struct snd_mask *mask, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	int changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	changed = !snd_mask_single(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	snd_mask_leave(mask, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (snd_mask_empty(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static inline int snd_mask_value(const struct snd_mask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return snd_mask_min(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static inline void snd_interval_any(struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	i->min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	i->openmin = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	i->max = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	i->openmax = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	i->integer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	i->empty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static inline void snd_interval_none(struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	i->empty = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static inline int snd_interval_checkempty(const struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	return (i->min > i->max ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		(i->min == i->max && (i->openmin || i->openmax)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static inline int snd_interval_empty(const struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return i->empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static inline int snd_interval_single(const struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return (i->min == i->max || 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		(i->min + 1 == i->max && (i->openmin || i->openmax)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static inline int snd_interval_value(const struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (i->openmin && !i->openmax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return i->max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return i->min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline int snd_interval_min(const struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return i->min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static inline int snd_interval_max(const struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	unsigned int v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	v = i->max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (i->openmax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		v--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static inline int snd_interval_test(const struct snd_interval *i, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	return !((i->min > val || (i->min == val && i->openmin) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		  i->max < val || (i->max == val && i->openmax)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static inline void snd_interval_copy(struct snd_interval *d, const struct snd_interval *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	*d = *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static inline int snd_interval_setinteger(struct snd_interval *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (i->integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (i->openmin && i->openmax && i->min == i->max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	i->integer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static inline int snd_interval_eq(const struct snd_interval *i1, const struct snd_interval *i2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (i1->empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return i2->empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (i2->empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return i1->empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return i1->min == i2->min && i1->openmin == i2->openmin &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		i1->max == i2->max && i1->openmax == i2->openmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * params_access - get the access type from the hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * @p: hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static inline snd_pcm_access_t params_access(const struct snd_pcm_hw_params *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return (__force snd_pcm_access_t)snd_mask_min(hw_param_mask_c(p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		SNDRV_PCM_HW_PARAM_ACCESS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * params_format - get the sample format from the hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * @p: hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline snd_pcm_format_t params_format(const struct snd_pcm_hw_params *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return (__force snd_pcm_format_t)snd_mask_min(hw_param_mask_c(p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		SNDRV_PCM_HW_PARAM_FORMAT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * params_subformat - get the sample subformat from the hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * @p: hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static inline snd_pcm_subformat_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) params_subformat(const struct snd_pcm_hw_params *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return (__force snd_pcm_subformat_t)snd_mask_min(hw_param_mask_c(p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		SNDRV_PCM_HW_PARAM_SUBFORMAT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * params_period_bytes - get the period size (in bytes) from the hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * @p: hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static inline unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) params_period_bytes(const struct snd_pcm_hw_params *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIOD_BYTES)->min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * params_width - get the number of bits of the sample format from the hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  * @p: hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  * This function returns the number of bits per sample that the selected sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  * format of the hw params has.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static inline int params_width(const struct snd_pcm_hw_params *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return snd_pcm_format_width(params_format(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * params_physical_width - get the storage size of the sample format from the hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * @p: hw params
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * This functions returns the number of bits per sample that the selected sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * format of the hw params takes up in memory. This will be equal or larger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  * params_width().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static inline int params_physical_width(const struct snd_pcm_hw_params *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	return snd_pcm_format_physical_width(params_format(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) params_set_format(struct snd_pcm_hw_params *p, snd_pcm_format_t fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	snd_mask_set_format(hw_param_mask(p, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #endif /* __SOUND_PCM_PARAMS_H */