33
33
34
34
#include "bcm2835.h"
35
35
36
+
37
+ /* functions to convert alsa to chip volume and back. */
38
+ int alsa2chip (int vol )
39
+ {
40
+ return - ((vol << 8 ) / 100 );
41
+ }
42
+
43
+ int chip2alsa (int vol )
44
+ {
45
+ return - ((vol * 100 ) >> 8 );
46
+ }
47
+
48
+
36
49
static int snd_bcm2835_ctl_info (struct snd_kcontrol * kcontrol ,
37
50
struct snd_ctl_elem_info * uinfo )
38
51
{
39
52
if (kcontrol -> private_value == PCM_PLAYBACK_VOLUME ) {
40
53
uinfo -> type = SNDRV_CTL_ELEM_TYPE_INTEGER ;
41
54
uinfo -> count = 1 ;
42
55
uinfo -> value .integer .min = -10240 ;
43
- uinfo -> value .integer .max = 2303 ;
56
+ uinfo -> value .integer .max = 400 ; /* 2303 */
44
57
} else if (kcontrol -> private_value == PCM_PLAYBACK_MUTE ) {
45
58
uinfo -> type = SNDRV_CTL_ELEM_TYPE_INTEGER ;
46
59
uinfo -> count = 1 ;
@@ -64,7 +77,7 @@ static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
64
77
BUG_ON (!chip && !(chip -> avail_substreams & AVAIL_SUBSTREAMS_MASK ));
65
78
66
79
if (kcontrol -> private_value == PCM_PLAYBACK_VOLUME )
67
- ucontrol -> value .integer .value [0 ] = chip -> volume ;
80
+ ucontrol -> value .integer .value [0 ] = chip2alsa ( chip -> volume ) ;
68
81
else if (kcontrol -> private_value == PCM_PLAYBACK_MUTE )
69
82
ucontrol -> value .integer .value [0 ] = chip -> mute ;
70
83
else if (kcontrol -> private_value == PCM_PLAYBACK_DEVICE )
@@ -85,13 +98,10 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
85
98
changed = 1 ;
86
99
}
87
100
if (changed
88
- || (ucontrol -> value .integer .value [0 ] != chip -> volume )) {
89
- int atten ;
101
+ || (ucontrol -> value .integer .value [0 ] != chip2alsa (chip -> volume ))) {
90
102
91
- chip -> volume = ucontrol -> value .integer .value [0 ];
103
+ chip -> volume = alsa2chip ( ucontrol -> value .integer .value [0 ]) ;
92
104
changed = 1 ;
93
- atten = - ((chip -> volume << 8 ) / 100 );
94
- chip -> volume = atten ;
95
105
}
96
106
97
107
} else if (kcontrol -> private_value == PCM_PLAYBACK_MUTE ) {
0 commit comments