Skip to content

Commit b683e89

Browse files
committed
Merge pull request #33 from Arne-F/rpi-patches
Patches for bcm2835ctl that make alsamixer useable
2 parents 94fbbc4 + 829da61 commit b683e89

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

sound/arm/bcm2835-ctl.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,27 @@
3333

3434
#include "bcm2835.h"
3535

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+
3649
static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
3750
struct snd_ctl_elem_info *uinfo)
3851
{
3952
if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
4053
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4154
uinfo->count = 1;
4255
uinfo->value.integer.min = -10240;
43-
uinfo->value.integer.max = 2303;
56+
uinfo->value.integer.max = 400; /* 2303 */
4457
} else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
4558
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4659
uinfo->count = 1;
@@ -64,7 +77,7 @@ static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
6477
BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
6578

6679
if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
67-
ucontrol->value.integer.value[0] = chip->volume;
80+
ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
6881
else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
6982
ucontrol->value.integer.value[0] = chip->mute;
7083
else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
@@ -85,13 +98,10 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
8598
changed = 1;
8699
}
87100
if (changed
88-
|| (ucontrol->value.integer.value[0] != chip->volume)) {
89-
int atten;
101+
|| (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
90102

91-
chip->volume = ucontrol->value.integer.value[0];
103+
chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
92104
changed = 1;
93-
atten = -((chip->volume << 8) / 100);
94-
chip->volume = atten;
95105
}
96106

97107
} else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {

0 commit comments

Comments
 (0)