2 * Support for Digigram Lola PCI-e boards
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/vmalloc.h>
25 #include <sound/core.h>
26 #include <sound/control.h>
27 #include <sound/pcm.h>
28 #include <sound/tlv.h>
31 static int __devinit
lola_init_pin(struct lola
*chip
, struct lola_pin
*pin
,
38 err
= lola_read_param(chip
, nid
, LOLA_PAR_AUDIO_WIDGET_CAP
, &val
);
40 printk(KERN_ERR SFX
"Can't read wcaps for 0x%x\n", nid
);
43 val
&= 0x00f00fff; /* test TYPE and bits 0..11 */
44 if (val
== 0x00400200) /* Type = 4, Digital = 1 */
45 pin
->is_analog
= false;
46 else if (val
== 0x0040000a && dir
== CAPT
) /* Dig=0, InAmp/ovrd */
47 pin
->is_analog
= true;
48 else if (val
== 0x0040000c && dir
== PLAY
) /* Dig=0, OutAmp/ovrd */
49 pin
->is_analog
= true;
51 printk(KERN_ERR SFX
"Invalid wcaps 0x%x for 0x%x\n", val
, nid
);
55 /* analog parameters only following, so continue in case of Digital pin
61 err
= lola_read_param(chip
, nid
, LOLA_PAR_AMP_OUT_CAP
, &val
);
63 err
= lola_read_param(chip
, nid
, LOLA_PAR_AMP_IN_CAP
, &val
);
65 printk(KERN_ERR SFX
"Can't read AMP-caps for 0x%x\n", nid
);
69 pin
->amp_mute
= LOLA_AMP_MUTE_CAPABLE(val
);
70 pin
->amp_step_size
= LOLA_AMP_STEP_SIZE(val
);
71 pin
->amp_num_steps
= LOLA_AMP_NUM_STEPS(val
);
72 if (pin
->amp_num_steps
) {
73 /* zero as mute state */
77 pin
->amp_offset
= LOLA_AMP_OFFSET(val
);
79 err
= lola_codec_read(chip
, nid
, LOLA_VERB_GET_MAX_LEVEL
, 0, 0, &val
,
82 printk(KERN_ERR SFX
"Can't get MAX_LEVEL 0x%x\n", nid
);
85 pin
->max_level
= val
& 0x3ff; /* 10 bits */
87 pin
->config_default_reg
= 0;
88 pin
->fixed_gain_list_len
= 0;
89 pin
->cur_gain_step
= 0;
94 int __devinit
lola_init_pins(struct lola
*chip
, int dir
, int *nidp
)
98 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++, nid
++) {
99 err
= lola_init_pin(chip
, &chip
->pin
[dir
].pins
[i
], dir
, nid
);
102 if (chip
->pin
[dir
].pins
[i
].is_analog
)
103 chip
->pin
[dir
].num_analog_pins
++;
109 void lola_free_mixer(struct lola
*chip
)
111 if (chip
->mixer
.array_saved
)
112 vfree(chip
->mixer
.array_saved
);
115 int __devinit
lola_init_mixer_widget(struct lola
*chip
, int nid
)
120 err
= lola_read_param(chip
, nid
, LOLA_PAR_AUDIO_WIDGET_CAP
, &val
);
122 printk(KERN_ERR SFX
"Can't read wcaps for 0x%x\n", nid
);
126 if ((val
& 0xfff00000) != 0x02f00000) { /* test SubType and Type */
127 snd_printdd("No valid mixer widget\n");
131 chip
->mixer
.nid
= nid
;
132 chip
->mixer
.caps
= val
;
133 chip
->mixer
.array
= (struct lola_mixer_array __iomem
*)
134 (chip
->bar
[BAR1
].remap_addr
+ LOLA_BAR1_SOURCE_GAIN_ENABLE
);
136 /* reserve memory to copy mixer data for sleep mode transitions */
137 chip
->mixer
.array_saved
= vmalloc(sizeof(struct lola_mixer_array
));
139 /* mixer matrix sources are physical input data and play streams */
140 chip
->mixer
.src_stream_outs
= chip
->pcm
[PLAY
].num_streams
;
141 chip
->mixer
.src_phys_ins
= chip
->pin
[CAPT
].num_pins
;
143 /* mixer matrix destinations are record streams and physical output */
144 chip
->mixer
.dest_stream_ins
= chip
->pcm
[CAPT
].num_streams
;
145 chip
->mixer
.dest_phys_outs
= chip
->pin
[PLAY
].num_pins
;
147 /* mixer matrix may have unused areas between PhysIn and
148 * Play or Record and PhysOut zones
150 chip
->mixer
.src_stream_out_ofs
= chip
->mixer
.src_phys_ins
+
151 LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(val
);
152 chip
->mixer
.dest_phys_out_ofs
= chip
->mixer
.dest_stream_ins
+
153 LOLA_MIXER_DEST_REC_OUTPUT_SEPARATION(val
);
155 /* example : MixerMatrix of LoLa881 (LoLa16161 uses unused zones)
156 * +-+ 0-------8------16-------8------16
158 * |s| | INPUT | | INPUT | |
159 * | |->| -> |unused | -> |unused |
160 * |r| |CAPTURE| | OUTPUT| |
161 * | | | MIX | | MIX | |
162 * |c| 8--------------------------------
165 * |g| |unused |unused |unused |unused |
168 * | | 16-------------------------------
170 * | | | PLAYBK| | PLAYBK| |
171 * |n|->| -> |unused | -> |unused |
172 * | | |CAPTURE| | OUTPUT| |
173 * | | | MIX | | MIX | |
174 * |a| 8--------------------------------
177 * |a| |unused |unused |unused |unused |
180 * +++ 16--|---------------|------------
181 * +---V---------------V-----------+
182 * | dest_mix_gain_enable array |
183 * +-------------------------------+
185 /* example : MixerMatrix of LoLa280
188 * |s| | INPUT | | INPUT
190 * |c| |CAPTURE| | <- OUTPUT
194 * |i| | PLAYBK| | PLAYBACK
196 * | | |CAPTURE| | <- OUTPUT
199 * |r| +---V----V-------------------+
200 * |a| | dest_mix_gain_enable array |
201 * |y| +----------------------------+
203 if (chip
->mixer
.src_stream_out_ofs
> MAX_AUDIO_INOUT_COUNT
||
204 chip
->mixer
.dest_phys_out_ofs
> MAX_STREAM_IN_COUNT
) {
205 printk(KERN_ERR SFX
"Invalid mixer widget size\n");
209 chip
->mixer
.src_mask
= ((1U << chip
->mixer
.src_phys_ins
) - 1) |
210 (((1U << chip
->mixer
.src_stream_outs
) - 1)
211 << chip
->mixer
.src_stream_out_ofs
);
212 chip
->mixer
.dest_mask
= ((1U << chip
->mixer
.dest_stream_ins
) - 1) |
213 (((1U << chip
->mixer
.dest_phys_outs
) - 1)
214 << chip
->mixer
.dest_phys_out_ofs
);
216 snd_printdd("Mixer src_mask=%x, dest_mask=%x\n",
217 chip
->mixer
.src_mask
, chip
->mixer
.dest_mask
);
222 static int lola_mixer_set_src_gain(struct lola
*chip
, unsigned int id
,
223 unsigned short gain
, bool on
)
225 unsigned int oldval
, val
;
227 if (!(chip
->mixer
.src_mask
& (1 << id
)))
229 oldval
= val
= readl(&chip
->mixer
.array
->src_gain_enable
);
234 /* test if values unchanged */
235 if ((val
== oldval
) &&
236 (gain
== readw(&chip
->mixer
.array
->src_gain
[id
])))
239 snd_printdd("lola_mixer_set_src_gain (id=%d, gain=%d) enable=%x\n",
241 writew(gain
, &chip
->mixer
.array
->src_gain
[id
]);
242 writel(val
, &chip
->mixer
.array
->src_gain_enable
);
243 lola_codec_flush(chip
);
244 /* inform micro-controller about the new source gain */
245 return lola_codec_write(chip
, chip
->mixer
.nid
,
246 LOLA_VERB_SET_SOURCE_GAIN
, id
, 0);
250 static int lola_mixer_set_src_gains(struct lola
*chip
, unsigned int mask
,
251 unsigned short *gains
)
255 if ((chip
->mixer
.src_mask
& mask
) != mask
)
257 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
258 if (mask
& (1 << i
)) {
259 writew(*gains
, &chip
->mixer
.array
->src_gain
[i
]);
263 writel(mask
, &chip
->mixer
.array
->src_gain_enable
);
264 lola_codec_flush(chip
);
265 if (chip
->mixer
.caps
& LOLA_PEAK_METER_CAN_AGC_MASK
) {
266 /* update for all srcs at once */
267 return lola_codec_write(chip
, chip
->mixer
.nid
,
268 LOLA_VERB_SET_SOURCE_GAIN
, 0x80, 0);
270 /* update manually */
271 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
272 if (mask
& (1 << i
)) {
273 lola_codec_write(chip
, chip
->mixer
.nid
,
274 LOLA_VERB_SET_SOURCE_GAIN
, i
, 0);
279 #endif /* not used */
281 static int lola_mixer_set_mapping_gain(struct lola
*chip
,
282 unsigned int src
, unsigned int dest
,
283 unsigned short gain
, bool on
)
287 if (!(chip
->mixer
.src_mask
& (1 << src
)) ||
288 !(chip
->mixer
.dest_mask
& (1 << dest
)))
291 writew(gain
, &chip
->mixer
.array
->dest_mix_gain
[dest
][src
]);
292 val
= readl(&chip
->mixer
.array
->dest_mix_gain_enable
[dest
]);
297 writel(val
, &chip
->mixer
.array
->dest_mix_gain_enable
[dest
]);
298 lola_codec_flush(chip
);
299 return lola_codec_write(chip
, chip
->mixer
.nid
, LOLA_VERB_SET_MIX_GAIN
,
304 static int lola_mixer_set_dest_gains(struct lola
*chip
, unsigned int id
,
305 unsigned int mask
, unsigned short *gains
)
309 if (!(chip
->mixer
.dest_mask
& (1 << id
)) ||
310 (chip
->mixer
.src_mask
& mask
) != mask
)
312 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
313 if (mask
& (1 << i
)) {
314 writew(*gains
, &chip
->mixer
.array
->dest_mix_gain
[id
][i
]);
318 writel(mask
, &chip
->mixer
.array
->dest_mix_gain_enable
[id
]);
319 lola_codec_flush(chip
);
320 /* update for all dests at once */
321 return lola_codec_write(chip
, chip
->mixer
.nid
,
322 LOLA_VERB_SET_DESTINATION_GAIN
, id
, 0);
324 #endif /* not used */
329 static int set_analog_volume(struct lola
*chip
, int dir
,
330 unsigned int idx
, unsigned int val
,
333 int lola_setup_all_analog_gains(struct lola
*chip
, int dir
, bool mute
)
335 struct lola_pin
*pin
;
338 pin
= chip
->pin
[dir
].pins
;
339 max_idx
= chip
->pin
[dir
].num_pins
;
340 for (idx
= 0; idx
< max_idx
; idx
++) {
341 if (pin
[idx
].is_analog
) {
342 unsigned int val
= mute
? 0 : pin
[idx
].cur_gain_step
;
343 /* set volume and do not save the value */
344 set_analog_volume(chip
, dir
, idx
, val
, false);
347 return lola_codec_flush(chip
);
350 void lola_save_mixer(struct lola
*chip
)
352 /* mute analog output */
353 if (chip
->mixer
.array_saved
) {
354 /* store contents of mixer array */
355 memcpy_fromio(chip
->mixer
.array_saved
, chip
->mixer
.array
,
356 sizeof(*chip
->mixer
.array
));
358 lola_setup_all_analog_gains(chip
, PLAY
, true); /* output mute */
361 void lola_restore_mixer(struct lola
*chip
)
365 /*lola_reset_setups(chip);*/
366 if (chip
->mixer
.array_saved
) {
367 /* restore contents of mixer array */
368 memcpy_toio(chip
->mixer
.array
, chip
->mixer
.array_saved
,
369 sizeof(*chip
->mixer
.array
));
370 /* inform micro-controller about all restored values
371 * and ignore return values
373 for (i
= 0; i
< chip
->mixer
.src_phys_ins
; i
++)
374 lola_codec_write(chip
, chip
->mixer
.nid
,
375 LOLA_VERB_SET_SOURCE_GAIN
,
377 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++)
378 lola_codec_write(chip
, chip
->mixer
.nid
,
379 LOLA_VERB_SET_SOURCE_GAIN
,
380 chip
->mixer
.src_stream_out_ofs
+ i
, 0);
381 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++)
382 lola_codec_write(chip
, chip
->mixer
.nid
,
383 LOLA_VERB_SET_DESTINATION_GAIN
,
385 for (i
= 0; i
< chip
->mixer
.dest_phys_outs
; i
++)
386 lola_codec_write(chip
, chip
->mixer
.nid
,
387 LOLA_VERB_SET_DESTINATION_GAIN
,
388 chip
->mixer
.dest_phys_out_ofs
+ i
, 0);
389 lola_codec_flush(chip
);
396 static int set_analog_volume(struct lola
*chip
, int dir
,
397 unsigned int idx
, unsigned int val
,
400 struct lola_pin
*pin
;
403 if (idx
>= chip
->pin
[dir
].num_pins
)
405 pin
= &chip
->pin
[dir
].pins
[idx
];
406 if (!pin
->is_analog
|| pin
->amp_num_steps
<= val
)
408 if (external_call
&& pin
->cur_gain_step
== val
)
411 lola_codec_flush(chip
);
412 snd_printdd("set_analog_volume (dir=%d idx=%d, volume=%d)\n",
414 err
= lola_codec_write(chip
, pin
->nid
,
415 LOLA_VERB_SET_AMP_GAIN_MUTE
, val
, 0);
419 pin
->cur_gain_step
= val
;
423 int lola_set_src_config(struct lola
*chip
, unsigned int src_mask
, bool update
)
429 /* SRC can be activated and the dwInputSRCMask is valid? */
430 if ((chip
->input_src_caps_mask
& src_mask
) != src_mask
)
432 /* handle all even Inputs - SRC is a stereo setting !!! */
433 for (n
= 0; n
< chip
->pin
[CAPT
].num_pins
; n
+= 2) {
434 unsigned int mask
= 3U << n
; /* handle the stereo case */
435 unsigned int new_src
, src_state
;
436 if (!(chip
->input_src_caps_mask
& mask
))
438 /* if one IO needs SRC, both stereo IO will get SRC */
439 new_src
= (src_mask
& mask
) != 0;
441 src_state
= (chip
->input_src_mask
& mask
) != 0;
442 if (src_state
== new_src
)
443 continue; /* nothing to change for this IO */
445 err
= lola_codec_write(chip
, chip
->pcm
[CAPT
].streams
[n
].nid
,
446 LOLA_VERB_SET_SRC
, new_src
, 0);
453 ret
= lola_codec_flush(chip
);
455 chip
->input_src_mask
= src_mask
;
461 static int init_mixer_values(struct lola
*chip
)
465 /* all sample rate converters on */
466 lola_set_src_config(chip
, (1 << chip
->pin
[CAPT
].num_pins
) - 1, false);
468 /* clear all mixer matrix settings */
469 memset_io(chip
->mixer
.array
, 0, sizeof(*chip
->mixer
.array
));
470 /* inform firmware about all updated matrix columns - capture part */
471 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++)
472 lola_codec_write(chip
, chip
->mixer
.nid
,
473 LOLA_VERB_SET_DESTINATION_GAIN
,
475 /* inform firmware about all updated matrix columns - output part */
476 for (i
= 0; i
< chip
->mixer
.dest_phys_outs
; i
++)
477 lola_codec_write(chip
, chip
->mixer
.nid
,
478 LOLA_VERB_SET_DESTINATION_GAIN
,
479 chip
->mixer
.dest_phys_out_ofs
+ i
, 0);
481 /* set all digital input source (master) gains to 0dB */
482 for (i
= 0; i
< chip
->mixer
.src_phys_ins
; i
++)
483 lola_mixer_set_src_gain(chip
, i
, 336, true); /* 0dB */
485 /* set all digital playback source (master) gains to 0dB */
486 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++)
487 lola_mixer_set_src_gain(chip
,
488 i
+ chip
->mixer
.src_stream_out_ofs
,
489 336, true); /* 0dB */
490 /* set gain value 0dB diagonally in matrix - part INPUT -> CAPTURE */
491 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++) {
492 int src
= i
% chip
->mixer
.src_phys_ins
;
493 lola_mixer_set_mapping_gain(chip
, src
, i
, 336, true);
495 /* set gain value 0dB diagonally in matrix , part PLAYBACK -> OUTPUT
496 * (LoLa280 : playback channel 0,2,4,6 linked to output channel 0)
497 * (LoLa280 : playback channel 1,3,5,7 linked to output channel 1)
499 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++) {
500 int src
= chip
->mixer
.src_stream_out_ofs
+ i
;
501 int dst
= chip
->mixer
.dest_phys_out_ofs
+
502 i
% chip
->mixer
.dest_phys_outs
;
503 lola_mixer_set_mapping_gain(chip
, src
, dst
, 336, true);
509 * analog mixer control element
511 static int lola_analog_vol_info(struct snd_kcontrol
*kcontrol
,
512 struct snd_ctl_elem_info
*uinfo
)
514 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
515 int dir
= kcontrol
->private_value
;
517 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
518 uinfo
->count
= chip
->pin
[dir
].num_pins
;
519 uinfo
->value
.integer
.min
= 0;
520 uinfo
->value
.integer
.max
= chip
->pin
[dir
].pins
[0].amp_num_steps
;
524 static int lola_analog_vol_get(struct snd_kcontrol
*kcontrol
,
525 struct snd_ctl_elem_value
*ucontrol
)
527 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
528 int dir
= kcontrol
->private_value
;
531 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++)
532 ucontrol
->value
.integer
.value
[i
] =
533 chip
->pin
[dir
].pins
[i
].cur_gain_step
;
537 static int lola_analog_vol_put(struct snd_kcontrol
*kcontrol
,
538 struct snd_ctl_elem_value
*ucontrol
)
540 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
541 int dir
= kcontrol
->private_value
;
544 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++) {
545 err
= set_analog_volume(chip
, dir
, i
,
546 ucontrol
->value
.integer
.value
[i
],
554 static int lola_analog_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
555 unsigned int size
, unsigned int __user
*tlv
)
557 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
558 int dir
= kcontrol
->private_value
;
559 unsigned int val1
, val2
;
560 struct lola_pin
*pin
;
562 if (size
< 4 * sizeof(unsigned int))
564 pin
= &chip
->pin
[dir
].pins
[0];
566 val2
= pin
->amp_step_size
* 25;
567 val1
= -1 * (int)pin
->amp_offset
* (int)val2
;
568 #ifdef TLV_DB_SCALE_MUTE
569 val2
|= TLV_DB_SCALE_MUTE
;
571 if (put_user(SNDRV_CTL_TLVT_DB_SCALE
, tlv
))
573 if (put_user(2 * sizeof(unsigned int), tlv
+ 1))
575 if (put_user(val1
, tlv
+ 2))
577 if (put_user(val2
, tlv
+ 3))
582 static struct snd_kcontrol_new lola_analog_mixer __devinitdata
= {
583 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
584 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
585 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
586 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
),
587 .info
= lola_analog_vol_info
,
588 .get
= lola_analog_vol_get
,
589 .put
= lola_analog_vol_put
,
590 .tlv
.c
= lola_analog_vol_tlv
,
593 static int __devinit
create_analog_mixer(struct lola
*chip
, int dir
, char *name
)
595 if (!chip
->pin
[dir
].num_pins
)
597 /* no analog volumes on digital only adapters */
598 if (chip
->pin
[dir
].num_pins
!= chip
->pin
[dir
].num_analog_pins
)
600 lola_analog_mixer
.name
= name
;
601 lola_analog_mixer
.private_value
= dir
;
602 return snd_ctl_add(chip
->card
,
603 snd_ctl_new1(&lola_analog_mixer
, chip
));
607 * Hardware sample rate converter on digital input
609 static int lola_input_src_info(struct snd_kcontrol
*kcontrol
,
610 struct snd_ctl_elem_info
*uinfo
)
612 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
614 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
615 uinfo
->count
= chip
->pin
[CAPT
].num_pins
;
616 uinfo
->value
.integer
.min
= 0;
617 uinfo
->value
.integer
.max
= 1;
621 static int lola_input_src_get(struct snd_kcontrol
*kcontrol
,
622 struct snd_ctl_elem_value
*ucontrol
)
624 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
627 for (i
= 0; i
< chip
->pin
[CAPT
].num_pins
; i
++)
628 ucontrol
->value
.integer
.value
[i
] =
629 !!(chip
->input_src_mask
& (1 << i
));
633 static int lola_input_src_put(struct snd_kcontrol
*kcontrol
,
634 struct snd_ctl_elem_value
*ucontrol
)
636 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
641 for (i
= 0; i
< chip
->pin
[CAPT
].num_pins
; i
++)
642 if (ucontrol
->value
.integer
.value
[i
])
644 return lola_set_src_config(chip
, mask
, true);
647 static struct snd_kcontrol_new lola_input_src_mixer __devinitdata
= {
648 .name
= "Digital SRC Capture Switch",
649 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
650 .info
= lola_input_src_info
,
651 .get
= lola_input_src_get
,
652 .put
= lola_input_src_put
,
656 * Lola16161 or Lola881 can have Hardware sample rate converters
657 * on its digital input pins
659 static int __devinit
create_input_src_mixer(struct lola
*chip
)
661 if (!chip
->input_src_caps_mask
)
664 return snd_ctl_add(chip
->card
,
665 snd_ctl_new1(&lola_input_src_mixer
, chip
));
671 static int lola_src_gain_info(struct snd_kcontrol
*kcontrol
,
672 struct snd_ctl_elem_info
*uinfo
)
674 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
676 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
677 uinfo
->count
= count
;
678 uinfo
->value
.integer
.min
= 0;
679 uinfo
->value
.integer
.max
= 409;
683 static int lola_src_gain_get(struct snd_kcontrol
*kcontrol
,
684 struct snd_ctl_elem_value
*ucontrol
)
686 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
687 unsigned int ofs
= kcontrol
->private_value
& 0xff;
688 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
689 unsigned int mask
, i
;
691 mask
= readl(&chip
->mixer
.array
->src_gain_enable
);
692 for (i
= 0; i
< count
; i
++) {
693 unsigned int idx
= ofs
+ i
;
695 if (!(chip
->mixer
.src_mask
& (1 << idx
)))
697 if (mask
& (1 << idx
))
698 val
= readw(&chip
->mixer
.array
->src_gain
[idx
]) + 1;
701 ucontrol
->value
.integer
.value
[i
] = val
;
706 static int lola_src_gain_put(struct snd_kcontrol
*kcontrol
,
707 struct snd_ctl_elem_value
*ucontrol
)
709 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
710 unsigned int ofs
= kcontrol
->private_value
& 0xff;
711 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
714 for (i
= 0; i
< count
; i
++) {
715 unsigned int idx
= ofs
+ i
;
716 unsigned short val
= ucontrol
->value
.integer
.value
[i
];
719 err
= lola_mixer_set_src_gain(chip
, idx
, val
, !!val
);
726 /* raw value: 0 = -84dB, 336 = 0dB, 408=18dB, incremented 1 for mute */
727 static const DECLARE_TLV_DB_SCALE(lola_src_gain_tlv
, -8425, 25, 1);
729 static struct snd_kcontrol_new lola_src_gain_mixer __devinitdata
= {
730 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
731 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
732 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
733 .info
= lola_src_gain_info
,
734 .get
= lola_src_gain_get
,
735 .put
= lola_src_gain_put
,
736 .tlv
.p
= lola_src_gain_tlv
,
739 static int __devinit
create_src_gain_mixer(struct lola
*chip
,
740 int num
, int ofs
, char *name
)
742 lola_src_gain_mixer
.name
= name
;
743 lola_src_gain_mixer
.private_value
= ofs
+ (num
<< 8);
744 return snd_ctl_add(chip
->card
,
745 snd_ctl_new1(&lola_src_gain_mixer
, chip
));
750 * destination gain (matrix-like) mixer
752 static int lola_dest_gain_info(struct snd_kcontrol
*kcontrol
,
753 struct snd_ctl_elem_info
*uinfo
)
755 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
757 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
758 uinfo
->count
= src_num
;
759 uinfo
->value
.integer
.min
= 0;
760 uinfo
->value
.integer
.max
= 433;
764 static int lola_dest_gain_get(struct snd_kcontrol
*kcontrol
,
765 struct snd_ctl_elem_value
*ucontrol
)
767 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
768 unsigned int src_ofs
= kcontrol
->private_value
& 0xff;
769 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
770 unsigned int dst_ofs
= (kcontrol
->private_value
>> 16) & 0xff;
771 unsigned int dst
, mask
, i
;
773 dst
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + dst_ofs
;
774 mask
= readl(&chip
->mixer
.array
->dest_mix_gain_enable
[dst
]);
775 for (i
= 0; i
< src_num
; i
++) {
776 unsigned int src
= src_ofs
+ i
;
778 if (!(chip
->mixer
.src_mask
& (1 << src
)))
780 if (mask
& (1 << dst
))
781 val
= readw(&chip
->mixer
.array
->dest_mix_gain
[dst
][src
]) + 1;
784 ucontrol
->value
.integer
.value
[i
] = val
;
789 static int lola_dest_gain_put(struct snd_kcontrol
*kcontrol
,
790 struct snd_ctl_elem_value
*ucontrol
)
792 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
793 unsigned int src_ofs
= kcontrol
->private_value
& 0xff;
794 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
795 unsigned int dst_ofs
= (kcontrol
->private_value
>> 16) & 0xff;
796 unsigned int dst
, mask
;
797 unsigned short gains
[MAX_STREAM_COUNT
];
802 for (i
= 0; i
< src_num
; i
++) {
803 unsigned short val
= ucontrol
->value
.integer
.value
[i
];
805 gains
[num
++] = val
- 1;
810 dst
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + dst_ofs
;
811 return lola_mixer_set_dest_gains(chip
, dst
, mask
, gains
);
814 static const DECLARE_TLV_DB_SCALE(lola_dest_gain_tlv
, -8425, 25, 1);
816 static struct snd_kcontrol_new lola_dest_gain_mixer __devinitdata
= {
817 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
818 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
819 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
820 .info
= lola_dest_gain_info
,
821 .get
= lola_dest_gain_get
,
822 .put
= lola_dest_gain_put
,
823 .tlv
.p
= lola_dest_gain_tlv
,
826 static int __devinit
create_dest_gain_mixer(struct lola
*chip
,
827 int src_num
, int src_ofs
,
828 int num
, int ofs
, char *name
)
830 lola_dest_gain_mixer
.count
= num
;
831 lola_dest_gain_mixer
.name
= name
;
832 lola_dest_gain_mixer
.private_value
=
833 src_ofs
+ (src_num
<< 8) + (ofs
<< 16) + (num
<< 24);
834 return snd_ctl_add(chip
->card
,
835 snd_ctl_new1(&lola_dest_gain_mixer
, chip
));
837 #endif /* not used */
841 int __devinit
lola_create_mixer(struct lola
*chip
)
845 err
= create_analog_mixer(chip
, PLAY
, "Analog Playback Volume");
848 err
= create_analog_mixer(chip
, CAPT
, "Analog Capture Volume");
851 err
= create_input_src_mixer(chip
);
854 err
= create_src_gain_mixer(chip
, chip
->mixer
.src_phys_ins
, 0,
855 "Digital Capture Volume");
858 err
= create_src_gain_mixer(chip
, chip
->mixer
.src_stream_outs
,
859 chip
->mixer
.src_stream_out_ofs
,
860 "Digital Playback Volume");
864 /* FIXME: buggy mixer matrix handling */
865 err
= create_dest_gain_mixer(chip
,
866 chip
->mixer
.src_phys_ins
, 0,
867 chip
->mixer
.dest_stream_ins
, 0,
868 "Line Capture Volume");
871 err
= create_dest_gain_mixer(chip
,
872 chip
->mixer
.src_stream_outs
,
873 chip
->mixer
.src_stream_out_ofs
,
874 chip
->mixer
.dest_stream_ins
, 0,
875 "Stream-Loopback Capture Volume");
878 err
= create_dest_gain_mixer(chip
,
879 chip
->mixer
.src_phys_ins
, 0,
880 chip
->mixer
.dest_phys_outs
,
881 chip
->mixer
.dest_phys_out_ofs
,
882 "Line-Loopback Playback Volume");
885 err
= create_dest_gain_mixer(chip
,
886 chip
->mixer
.src_stream_outs
,
887 chip
->mixer
.src_stream_out_ofs
,
888 chip
->mixer
.dest_phys_outs
,
889 chip
->mixer
.dest_phys_out_ofs
,
890 "Stream Playback Volume");
894 return init_mixer_values(chip
);