From d0735c7d129d35bd91ba1c2c5b5a5201ed4a6c37 Mon Sep 17 00:00:00 2001 From: Arne Fitzenreiter Date: Wed, 6 Jun 2012 08:02:10 +0200 Subject: [PATCH 1/2] bcm2835-ctl: fix alsamixer control. alsamixer read the volume for the screen controller so we had to scale the chipvol back to db for reading. --- sound/arm/bcm2835-ctl.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sound/arm/bcm2835-ctl.c b/sound/arm/bcm2835-ctl.c index c0546e35bdda44..828a8206b31463 100755 --- a/sound/arm/bcm2835-ctl.c +++ b/sound/arm/bcm2835-ctl.c @@ -33,6 +33,19 @@ #include "bcm2835.h" + +/* functions to convert alsa to chip volume and back. */ +int alsa2chip(int vol) +{ + return -((vol << 8) / 100); +} + +int chip2alsa(int vol) +{ + return -((vol * 100) >> 8); +} + + static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { @@ -64,7 +77,7 @@ static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol, BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK)); if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) - ucontrol->value.integer.value[0] = chip->volume; + ucontrol->value.integer.value[0] = chip2alsa(chip->volume); else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) ucontrol->value.integer.value[0] = chip->mute; else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) @@ -85,13 +98,10 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol, changed = 1; } if (changed - || (ucontrol->value.integer.value[0] != chip->volume)) { - int atten; + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) { - chip->volume = ucontrol->value.integer.value[0]; + chip->volume = alsa2chip(ucontrol->value.integer.value[0]); changed = 1; - atten = -((chip->volume << 8) / 100); - chip->volume = atten; } } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) { From 829da61c0229c0734a109339f5de308bf8205bf6 Mon Sep 17 00:00:00 2001 From: Arne Fitzenreiter Date: Wed, 6 Jun 2012 08:06:15 +0200 Subject: [PATCH 2/2] bcm2835-ctl: limit maximal volume to 4db. it makes no sense to set 23.04db as maximum volume since around 3db it start to cliping. So with 4db the alsamixer is much better to control. (86% is 0db) --- sound/arm/bcm2835-ctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/arm/bcm2835-ctl.c b/sound/arm/bcm2835-ctl.c index 828a8206b31463..f901ddd8d05eb1 100755 --- a/sound/arm/bcm2835-ctl.c +++ b/sound/arm/bcm2835-ctl.c @@ -53,7 +53,7 @@ static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol, uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = -10240; - uinfo->value.integer.max = 2303; + uinfo->value.integer.max = 400; /* 2303 */ } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1;