@@ -158,6 +158,20 @@ static void snd_soc_read_signed(struct snd_soc_component *component,
158
158
* signed_val = ret ;
159
159
}
160
160
161
+ static int soc_mixer_mask (struct soc_mixer_control * mc )
162
+ {
163
+ if (mc -> sign_bit )
164
+ return GENMASK (mc -> sign_bit , 0 );
165
+ else
166
+ return GENMASK (fls (mc -> max ) - 1 , 0 );
167
+ }
168
+
169
+ static int soc_mixer_sx_mask (struct soc_mixer_control * mc )
170
+ {
171
+ // min + max will take us 1-bit over the size of the mask
172
+ return GENMASK (fls (mc -> min + mc -> max ) - 2 , 0 );
173
+ }
174
+
161
175
/**
162
176
* snd_soc_info_volsw - single mixer info callback
163
177
* @kcontrol: mixer control
@@ -260,13 +274,10 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
260
274
int max = mc -> max ;
261
275
int min = mc -> min ;
262
276
int sign_bit = mc -> sign_bit ;
263
- unsigned int mask = ( 1ULL << fls ( max )) - 1 ;
277
+ unsigned int mask = soc_mixer_mask ( mc ) ;
264
278
unsigned int invert = mc -> invert ;
265
279
int val ;
266
280
267
- if (sign_bit )
268
- mask = BIT (sign_bit + 1 ) - 1 ;
269
-
270
281
snd_soc_read_signed (component , reg , mask , shift , sign_bit , & val );
271
282
272
283
ucontrol -> value .integer .value [0 ] = val - min ;
@@ -312,17 +323,13 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
312
323
unsigned int rshift = mc -> rshift ;
313
324
int max = mc -> max ;
314
325
int min = mc -> min ;
315
- unsigned int sign_bit = mc -> sign_bit ;
316
- unsigned int mask = (1 << fls (max )) - 1 ;
326
+ unsigned int mask = soc_mixer_mask (mc );
317
327
unsigned int invert = mc -> invert ;
318
328
int err , ret ;
319
329
bool type_2r = false;
320
330
unsigned int val2 = 0 ;
321
331
unsigned int val , val_mask ;
322
332
323
- if (sign_bit )
324
- mask = BIT (sign_bit + 1 ) - 1 ;
325
-
326
333
if (ucontrol -> value .integer .value [0 ] < 0 )
327
334
return - EINVAL ;
328
335
val = ucontrol -> value .integer .value [0 ];
@@ -391,9 +398,8 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
391
398
unsigned int reg2 = mc -> rreg ;
392
399
unsigned int shift = mc -> shift ;
393
400
unsigned int rshift = mc -> rshift ;
394
- int max = mc -> max ;
395
401
int min = mc -> min ;
396
- unsigned int mask = ( 1U << ( fls ( min + max ) - 1 )) - 1 ;
402
+ unsigned int mask = soc_mixer_sx_mask ( mc ) ;
397
403
unsigned int val ;
398
404
399
405
val = snd_soc_component_read (component , reg );
@@ -431,7 +437,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
431
437
unsigned int val , val_mask ;
432
438
int max = mc -> max ;
433
439
int min = mc -> min ;
434
- unsigned int mask = ( 1U << ( fls ( min + max ) - 1 )) - 1 ;
440
+ unsigned int mask = soc_mixer_sx_mask ( mc ) ;
435
441
int err = 0 ;
436
442
int ret ;
437
443
@@ -525,7 +531,7 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
525
531
unsigned int shift = mc -> shift ;
526
532
int min = mc -> min ;
527
533
int max = mc -> max ;
528
- unsigned int mask = ( 1 << fls ( max )) - 1 ;
534
+ unsigned int mask = soc_mixer_mask ( mc ) ;
529
535
unsigned int invert = mc -> invert ;
530
536
unsigned int val , val_mask ;
531
537
int err , ret , tmp ;
@@ -597,7 +603,7 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
597
603
unsigned int shift = mc -> shift ;
598
604
int min = mc -> min ;
599
605
int max = mc -> max ;
600
- unsigned int mask = ( 1 << fls ( max )) - 1 ;
606
+ unsigned int mask = soc_mixer_mask ( mc ) ;
601
607
unsigned int invert = mc -> invert ;
602
608
unsigned int val ;
603
609
@@ -891,9 +897,9 @@ int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
891
897
unsigned int regbase = mc -> regbase ;
892
898
unsigned int regcount = mc -> regcount ;
893
899
unsigned int regwshift = component -> val_bytes * BITS_PER_BYTE ;
894
- unsigned int regwmask = (1UL << regwshift ) - 1 ;
900
+ unsigned int regwmask = GENMASK (regwshift - 1 , 0 );
901
+ unsigned long mask = GENMASK (mc -> nbits - 1 , 0 );
895
902
unsigned int invert = mc -> invert ;
896
- unsigned long mask = (1UL << mc -> nbits ) - 1 ;
897
903
long min = mc -> min ;
898
904
long max = mc -> max ;
899
905
long val = 0 ;
@@ -938,9 +944,9 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
938
944
unsigned int regbase = mc -> regbase ;
939
945
unsigned int regcount = mc -> regcount ;
940
946
unsigned int regwshift = component -> val_bytes * BITS_PER_BYTE ;
941
- unsigned int regwmask = (1UL << regwshift ) - 1 ;
947
+ unsigned int regwmask = GENMASK (regwshift - 1 , 0 );
948
+ unsigned long mask = GENMASK (mc -> nbits - 1 , 0 );
942
949
unsigned int invert = mc -> invert ;
943
- unsigned long mask = (1UL << mc -> nbits ) - 1 ;
944
950
long max = mc -> max ;
945
951
long val = ucontrol -> value .integer .value [0 ];
946
952
int ret = 0 ;
@@ -986,7 +992,7 @@ int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
986
992
(struct soc_mixer_control * )kcontrol -> private_value ;
987
993
unsigned int reg = mc -> reg ;
988
994
unsigned int shift = mc -> shift ;
989
- unsigned int mask = 1 << shift ;
995
+ unsigned int mask = BIT ( shift ) ;
990
996
unsigned int invert = mc -> invert != 0 ;
991
997
unsigned int val ;
992
998
@@ -1019,7 +1025,7 @@ int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
1019
1025
(struct soc_mixer_control * )kcontrol -> private_value ;
1020
1026
unsigned int reg = mc -> reg ;
1021
1027
unsigned int shift = mc -> shift ;
1022
- unsigned int mask = 1 << shift ;
1028
+ unsigned int mask = BIT ( shift ) ;
1023
1029
unsigned int invert = mc -> invert != 0 ;
1024
1030
unsigned int strobe = ucontrol -> value .enumerated .item [0 ] != 0 ;
1025
1031
unsigned int val1 = (strobe ^ invert ) ? mask : 0 ;
0 commit comments