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
- }
36
+ /* volume maximum and minimum in terms of 0.01dB */
37
+ #define CTRL_VOL_MAX 400
38
+ #define CTRL_VOL_MIN -10239 /* originally -10240 */
47
39
48
40
49
41
static int snd_bcm2835_ctl_info (struct snd_kcontrol * kcontrol ,
50
42
struct snd_ctl_elem_info * uinfo )
51
43
{
44
+ audio_info (" ... IN " );
52
45
if (kcontrol -> private_value == PCM_PLAYBACK_VOLUME ) {
53
46
uinfo -> type = SNDRV_CTL_ELEM_TYPE_INTEGER ;
54
47
uinfo -> count = 1 ;
55
- uinfo -> value .integer .min = -10240 ;
56
- uinfo -> value .integer .max = 400 ; /* 2303 */
48
+ uinfo -> value .integer .min = CTRL_VOL_MIN ;
49
+ uinfo -> value .integer .max = CTRL_VOL_MAX ; /* 2303 */
57
50
} else if (kcontrol -> private_value == PCM_PLAYBACK_MUTE ) {
58
- uinfo -> type = SNDRV_CTL_ELEM_TYPE_INTEGER ;
51
+ uinfo -> type = SNDRV_CTL_ELEM_TYPE_BOOLEAN ;
59
52
uinfo -> count = 1 ;
60
53
uinfo -> value .integer .min = 0 ;
61
54
uinfo -> value .integer .max = 1 ;
62
55
} else if (kcontrol -> private_value == PCM_PLAYBACK_DEVICE ) {
63
56
uinfo -> type = SNDRV_CTL_ELEM_TYPE_INTEGER ;
64
57
uinfo -> count = 1 ;
65
58
uinfo -> value .integer .min = 0 ;
66
- uinfo -> value .integer .max = AUDIO_DEST_MAX - 0 ;
59
+ uinfo -> value .integer .max = AUDIO_DEST_MAX - 1 ;
67
60
}
68
-
61
+ audio_info ( " ... OUT " );
69
62
return 0 ;
70
63
}
71
64
65
+ /* toggles mute on or off depending on the value of nmute, and returns
66
+ * 1 if the mute value was changed, otherwise 0
67
+ */
68
+ static int toggle_mute (struct bcm2835_chip * chip , int nmute )
69
+ {
70
+ /* if settings are ok, just return 0 */
71
+ if (chip -> mute == nmute )
72
+ return 0 ;
73
+
74
+ /* if the sound is muted then we need to unmute */
75
+ if (chip -> mute == CTRL_VOL_MUTE )
76
+ {
77
+ chip -> volume = chip -> old_volume ; /* copy the old volume back */
78
+ audio_info ("Unmuting, old_volume = %d, volume = %d ..." , chip -> old_volume , chip -> volume );
79
+ }
80
+ else /* otherwise we mute */
81
+ {
82
+ chip -> old_volume = chip -> volume ;
83
+ chip -> volume = 26214 ; /* set volume to minimum level AKA mute */
84
+ audio_info ("Muting, old_volume = %d, volume = %d ..." , chip -> old_volume , chip -> volume );
85
+ }
86
+
87
+ chip -> mute = nmute ;
88
+ return 1 ;
89
+ }
90
+
72
91
static int snd_bcm2835_ctl_get (struct snd_kcontrol * kcontrol ,
73
92
struct snd_ctl_elem_value * ucontrol )
74
93
{
@@ -93,9 +112,10 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
93
112
int changed = 0 ;
94
113
95
114
if (kcontrol -> private_value == PCM_PLAYBACK_VOLUME ) {
96
- if (chip -> mute ) {
97
- chip -> mute = 0 ;
98
- changed = 1 ;
115
+ audio_info ("Volume change attempted.. volume = %d new_volume = %d" , chip -> volume , (int )ucontrol -> value .integer .value [0 ]);
116
+ if (chip -> mute == CTRL_VOL_MUTE ) {
117
+ /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
118
+ return 1 ; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
99
119
}
100
120
if (changed
101
121
|| (ucontrol -> value .integer .value [0 ] != chip2alsa (chip -> volume ))) {
@@ -105,11 +125,10 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
105
125
}
106
126
107
127
} else if (kcontrol -> private_value == PCM_PLAYBACK_MUTE ) {
108
- /* Not implemented */
109
- if (ucontrol -> value .integer .value [0 ] != chip -> mute ) {
110
- chip -> mute = ucontrol -> value .integer .value [0 ];
111
- changed = 0 ;
112
- }
128
+ /* Now implemented */
129
+ audio_info (" Mute attempted" );
130
+ changed = toggle_mute (chip , ucontrol -> value .integer .value [0 ]);
131
+
113
132
} else if (kcontrol -> private_value == PCM_PLAYBACK_DEVICE ) {
114
133
if (ucontrol -> value .integer .value [0 ] != chip -> dest ) {
115
134
chip -> dest = ucontrol -> value .integer .value [0 ];
@@ -125,22 +144,21 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
125
144
return changed ;
126
145
}
127
146
128
- static DECLARE_TLV_DB_SCALE (snd_bcm2835_db_scale , -10240 , 1 , 1 ) ;
147
+ static DECLARE_TLV_DB_SCALE (snd_bcm2835_db_scale , CTRL_VOL_MIN , 1 , 1 ) ;
129
148
130
149
static struct snd_kcontrol_new snd_bcm2835_ctl [] __devinitdata = {
131
150
{
132
151
.iface = SNDRV_CTL_ELEM_IFACE_MIXER ,
133
152
.name = "PCM Playback Volume" ,
134
153
.index = 0 ,
135
- .access =
136
- SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE ,
154
+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ ,
137
155
.private_value = PCM_PLAYBACK_VOLUME ,
138
156
.info = snd_bcm2835_ctl_info ,
139
157
.get = snd_bcm2835_ctl_get ,
140
158
.put = snd_bcm2835_ctl_put ,
141
159
.count = 1 ,
142
160
.tlv = {.p = snd_bcm2835_db_scale }
143
- },
161
+ },
144
162
{
145
163
.iface = SNDRV_CTL_ELEM_IFACE_MIXER ,
146
164
.name = "PCM Playback Switch" ,
@@ -162,7 +180,7 @@ static struct snd_kcontrol_new snd_bcm2835_ctl[] __devinitdata = {
162
180
.get = snd_bcm2835_ctl_get ,
163
181
.put = snd_bcm2835_ctl_put ,
164
182
.count = 1 ,
165
- },
183
+ },
166
184
};
167
185
168
186
int __devinit snd_bcm2835_new_ctl (bcm2835_chip_t * chip )
0 commit comments