Skip to content

Commit bb92b7c

Browse files
Raymond Yautiwai
authored andcommitted
ALSA: Au88x0 - Implement subdevice volume controls
- add "PCM Playback Volume" controls for 16 playback subdevices This allow application to change the volume of each subdevice by using hardware mixer of au88x0 and default is zero gain/attenunation. Signed-off-by: Raymond Yau <superquad.vortex2@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent dcd6c92 commit bb92b7c

3 files changed

Lines changed: 145 additions & 13 deletions

File tree

‎sound/pci/au88x0/au88x0.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <sound/mpu401.h>
2727
#include <sound/hwdep.h>
2828
#include <sound/ac97_codec.h>
29-
29+
#include <sound/tlv.h>
3030
#endif
3131

3232
#ifndef CHIP_AU8820
@@ -107,6 +107,14 @@
107107
#define NR_WTPB 0x20 /* WT channels per each bank. */
108108
#define NR_PCM 0x10
109109

110+
struct pcm_vol {
111+
struct snd_kcontrol *kctl;
112+
int active;
113+
int dma;
114+
int mixin[4];
115+
int vol[4];
116+
};
117+
110118
/* Structs */
111119
typedef struct {
112120
//int this_08; /* Still unknown */
@@ -168,6 +176,7 @@ struct snd_vortex {
168176
/* Xtalk canceler */
169177
int xt_mode; /* 1: speakers, 0:headphones. */
170178
#endif
179+
struct pcm_vol pcm_vol[NR_PCM];
171180

172181
int isquad; /* cache of extended ID codec flag. */
173182

@@ -239,7 +248,7 @@ static int vortex_alsafmt_aspfmt(int alsafmt);
239248
/* Connection stuff. */
240249
static void vortex_connect_default(vortex_t * vortex, int en);
241250
static int vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch,
242-
int dir, int type);
251+
int dir, int type, int subdev);
243252
static char vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out,
244253
int restype);
245254
#ifndef CHIP_AU8810

‎sound/pci/au88x0/au88x0_core.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,8 +2050,6 @@ vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out, int restype)
20502050
}
20512051

20522052
/* Default Connections */
2053-
static int
2054-
vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch, int dir, int type);
20552053

20562054
static void vortex_connect_default(vortex_t * vortex, int en)
20572055
{
@@ -2111,15 +2109,13 @@ static void vortex_connect_default(vortex_t * vortex, int en)
21112109
Return: Return allocated DMA or same DMA passed as "dma" when dma >= 0.
21122110
*/
21132111
static int
2114-
vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch, int dir, int type)
2112+
vortex_adb_allocroute(vortex_t *vortex, int dma, int nr_ch, int dir,
2113+
int type, int subdev)
21152114
{
21162115
stream_t *stream;
21172116
int i, en;
2117+
struct pcm_vol *p;
21182118

2119-
if ((nr_ch == 3)
2120-
|| ((dir == SNDRV_PCM_STREAM_CAPTURE) && (nr_ch > 2)))
2121-
return -EBUSY;
2122-
21232119
if (dma >= 0) {
21242120
en = 0;
21252121
vortex_adb_checkinout(vortex,
@@ -2250,6 +2246,14 @@ vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch, int dir, int type)
22502246
MIX_DEFIGAIN);
22512247
#endif
22522248
}
2249+
if (stream->type == VORTEX_PCM_ADB && en) {
2250+
p = &vortex->pcm_vol[subdev];
2251+
p->dma = dma;
2252+
for (i = 0; i < nr_ch; i++)
2253+
p->mixin[i] = mix[i];
2254+
for (i = 0; i < ch_top; i++)
2255+
p->vol[i] = 0;
2256+
}
22532257
}
22542258
#ifndef CHIP_AU8820
22552259
else {

‎sound/pci/au88x0/au88x0_pcm.c‎

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ static struct snd_pcm_hw_constraint_list hw_constraints_au8830_channels = {
122122
.mask = 0,
123123
};
124124
#endif
125+
126+
static void vortex_notify_pcm_vol_change(struct snd_card *card,
127+
struct snd_kcontrol *kctl, int activate)
128+
{
129+
if (activate)
130+
kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
131+
else
132+
kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
133+
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE |
134+
SNDRV_CTL_EVENT_MASK_INFO, &(kctl->id));
135+
}
136+
125137
/* open callback */
126138
static int snd_vortex_pcm_open(struct snd_pcm_substream *substream)
127139
{
@@ -230,12 +242,14 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
230242
if (stream != NULL)
231243
vortex_adb_allocroute(chip, stream->dma,
232244
stream->nr_ch, stream->dir,
233-
stream->type);
245+
stream->type,
246+
substream->number);
234247
/* Alloc routes. */
235248
dma =
236249
vortex_adb_allocroute(chip, -1,
237250
params_channels(hw_params),
238-
substream->stream, type);
251+
substream->stream, type,
252+
substream->number);
239253
if (dma < 0) {
240254
spin_unlock_irq(&chip->lock);
241255
return dma;
@@ -246,6 +260,11 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
246260
vortex_adbdma_setbuffers(chip, dma,
247261
params_period_bytes(hw_params),
248262
params_periods(hw_params));
263+
if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_ADB) {
264+
chip->pcm_vol[substream->number].active = 1;
265+
vortex_notify_pcm_vol_change(chip->card,
266+
chip->pcm_vol[substream->number].kctl, 1);
267+
}
249268
}
250269
#ifndef CHIP_AU8810
251270
else {
@@ -275,10 +294,18 @@ static int snd_vortex_pcm_hw_free(struct snd_pcm_substream *substream)
275294
spin_lock_irq(&chip->lock);
276295
// Delete audio routes.
277296
if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
278-
if (stream != NULL)
297+
if (stream != NULL) {
298+
if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_ADB) {
299+
chip->pcm_vol[substream->number].active = 0;
300+
vortex_notify_pcm_vol_change(chip->card,
301+
chip->pcm_vol[substream->number].kctl,
302+
0);
303+
}
279304
vortex_adb_allocroute(chip, stream->dma,
280305
stream->nr_ch, stream->dir,
281-
stream->type);
306+
stream->type,
307+
substream->number);
308+
}
282309
}
283310
#ifndef CHIP_AU8810
284311
else {
@@ -506,6 +533,83 @@ static struct snd_kcontrol_new snd_vortex_mixer_spdif[] __devinitdata = {
506533
},
507534
};
508535

536+
/* subdevice PCM Volume control */
537+
538+
static int snd_vortex_pcm_vol_info(struct snd_kcontrol *kcontrol,
539+
struct snd_ctl_elem_info *uinfo)
540+
{
541+
vortex_t *vortex = snd_kcontrol_chip(kcontrol);
542+
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
543+
uinfo->count = (VORTEX_IS_QUAD(vortex) ? 4 : 2);
544+
uinfo->value.integer.min = -128;
545+
uinfo->value.integer.max = 32;
546+
return 0;
547+
}
548+
549+
static int snd_vortex_pcm_vol_get(struct snd_kcontrol *kcontrol,
550+
struct snd_ctl_elem_value *ucontrol)
551+
{
552+
int i;
553+
vortex_t *vortex = snd_kcontrol_chip(kcontrol);
554+
int subdev = kcontrol->id.subdevice;
555+
struct pcm_vol *p = &vortex->pcm_vol[subdev];
556+
int max_chn = (VORTEX_IS_QUAD(vortex) ? 4 : 2);
557+
for (i = 0; i < max_chn; i++)
558+
ucontrol->value.integer.value[i] = p->vol[i];
559+
return 0;
560+
}
561+
562+
static int snd_vortex_pcm_vol_put(struct snd_kcontrol *kcontrol,
563+
struct snd_ctl_elem_value *ucontrol)
564+
{
565+
int i;
566+
int changed = 0;
567+
int mixin;
568+
unsigned char vol;
569+
vortex_t *vortex = snd_kcontrol_chip(kcontrol);
570+
int subdev = kcontrol->id.subdevice;
571+
struct pcm_vol *p = &vortex->pcm_vol[subdev];
572+
int max_chn = (VORTEX_IS_QUAD(vortex) ? 4 : 2);
573+
for (i = 0; i < max_chn; i++) {
574+
if (p->vol[i] != ucontrol->value.integer.value[i]) {
575+
p->vol[i] = ucontrol->value.integer.value[i];
576+
if (p->active) {
577+
switch (vortex->dma_adb[p->dma].nr_ch) {
578+
case 1:
579+
mixin = p->mixin[0];
580+
break;
581+
case 2:
582+
default:
583+
mixin = p->mixin[(i < 2) ? i : (i - 2)];
584+
break;
585+
case 4:
586+
mixin = p->mixin[i];
587+
break;
588+
};
589+
vol = p->vol[i];
590+
vortex_mix_setinputvolumebyte(vortex,
591+
vortex->mixplayb[i], mixin, vol);
592+
}
593+
changed = 1;
594+
}
595+
}
596+
return changed;
597+
}
598+
599+
static const DECLARE_TLV_DB_MINMAX(vortex_pcm_vol_db_scale, -9600, 2400);
600+
601+
static struct snd_kcontrol_new snd_vortex_pcm_vol __devinitdata = {
602+
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
603+
.name = "PCM Playback Volume",
604+
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
605+
SNDRV_CTL_ELEM_ACCESS_TLV_READ |
606+
SNDRV_CTL_ELEM_ACCESS_INACTIVE,
607+
.info = snd_vortex_pcm_vol_info,
608+
.get = snd_vortex_pcm_vol_get,
609+
.put = snd_vortex_pcm_vol_put,
610+
.tlv = { .p = vortex_pcm_vol_db_scale },
611+
};
612+
509613
/* create a pcm device */
510614
static int __devinit snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
511615
{
@@ -555,5 +659,20 @@ static int __devinit snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
555659
return err;
556660
}
557661
}
662+
if (VORTEX_PCM_TYPE(pcm) == VORTEX_PCM_ADB) {
663+
for (i = 0; i < NR_PCM; i++) {
664+
chip->pcm_vol[i].active = 0;
665+
chip->pcm_vol[i].dma = -1;
666+
kctl = snd_ctl_new1(&snd_vortex_pcm_vol, chip);
667+
if (!kctl)
668+
return -ENOMEM;
669+
chip->pcm_vol[i].kctl = kctl;
670+
kctl->id.device = 0;
671+
kctl->id.subdevice = i;
672+
err = snd_ctl_add(chip->card, kctl);
673+
if (err < 0)
674+
return err;
675+
}
676+
}
558677
return 0;
559678
}

0 commit comments

Comments
 (0)