Skip to content

Commit

Permalink
Volume control altered to enable 'alsamixer' to appear to work normal…
Browse files Browse the repository at this point in the history
…ly. HOWEVER:

Based on the code, assumption was made that the volume value passed to chip->volume should be between
-10240 and 2303.

It now crudely does that, allowing ALSA volume to appear to be between 0 and 100, while supplying the card
with a value between the two points.

However, this seems to have little to no effect on the actual output volume...
  • Loading branch information
benosteen committed Apr 18, 2012
1 parent 0ec4154 commit 067ac7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
25 changes: 15 additions & 10 deletions sound/arm/bcm2835-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@

#include "bcm2835.h"

long int alsa_vol_to_bcm2835(long int vol) {
return (long int)(125 * vol - 10240);
}

long int bcm2835_vol_to_alsa(long int vol) {
return (long int)((vol + 10240) / 125);
}

static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = -10240;
uinfo->value.integer.max = 2303;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 100;
} else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
Expand All @@ -64,7 +72,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] = bcm2835_vol_to_alsa(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)
Expand All @@ -78,20 +86,17 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
{
struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
int changed = 0;

if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
if (chip->mute) {
chip->mute = 0;
changed = 1;
}
if (changed
|| (ucontrol->value.integer.value[0] != chip->volume)) {
int atten;
|| (ucontrol->value.integer.value[0] != bcm2835_vol_to_alsa(chip->volume))) {

chip->volume = ucontrol->value.integer.value[0];
chip->volume = alsa_vol_to_bcm2835(ucontrol->value.integer.value[0]);
changed = 1;
atten = -((chip->volume << 8) / 100);
chip->volume = atten;
}

} else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
Expand All @@ -115,7 +120,7 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
return changed;
}

static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, -10240, 1, 1);
static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, 0, 1, 1);

static struct snd_kcontrol_new snd_bcm2835_ctl[] __devinitdata = {
{
Expand Down
5 changes: 3 additions & 2 deletions sound/arm/bcm2835.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <linux/workqueue.h>

/* #define DUMP_RAW_DATA */
//#define AUDIO_DEBUG_ENABLE
#define AUDIO_DEBUG_ENABLE
//#define AUDIO_VERBOSE_DEBUG_ENABLE

/* Debug macros */
Expand Down Expand Up @@ -171,7 +171,8 @@ typedef struct bcm2835_chip {
struct platform_device *pdev[MAX_SUBSTREAMS];
struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];

int volume;
long int volume; // to match ALSA
// int volume;
int dest;
int mute;
} bcm2835_chip_t;
Expand Down

0 comments on commit 067ac7c

Please sign in to comment.