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 lola_init_pin(struct lola
*chip
, struct lola_pin
*pin
,
38 err
= lola_read_param(chip
, nid
, LOLA_PAR_AUDIO_WIDGET_CAP
, &val
);
40 dev_err(chip
->card
->dev
, "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 dev_err(chip
->card
->dev
, "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 dev_err(chip
->card
->dev
, "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 dev_err(chip
->card
->dev
, "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 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 lola_init_mixer_widget(struct lola
*chip
, int nid
)
120 err
= lola_read_param(chip
, nid
, LOLA_PAR_AUDIO_WIDGET_CAP
, &val
);
122 dev_err(chip
->card
->dev
, "Can't read wcaps for 0x%x\n", nid
);
126 if ((val
& 0xfff00000) != 0x02f00000) { /* test SubType and Type */
127 dev_dbg(chip
->card
->dev
, "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 dev_err(chip
->card
->dev
, "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 dev_dbg(chip
->card
->dev
, "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 dev_dbg(chip
->card
->dev
,
240 "lola_mixer_set_src_gain (id=%d, gain=%d) enable=%x\n",
242 writew(gain
, &chip
->mixer
.array
->src_gain
[id
]);
243 writel(val
, &chip
->mixer
.array
->src_gain_enable
);
244 lola_codec_flush(chip
);
245 /* inform micro-controller about the new source gain */
246 return lola_codec_write(chip
, chip
->mixer
.nid
,
247 LOLA_VERB_SET_SOURCE_GAIN
, id
, 0);
251 static int lola_mixer_set_src_gains(struct lola
*chip
, unsigned int mask
,
252 unsigned short *gains
)
256 if ((chip
->mixer
.src_mask
& mask
) != mask
)
258 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
259 if (mask
& (1 << i
)) {
260 writew(*gains
, &chip
->mixer
.array
->src_gain
[i
]);
264 writel(mask
, &chip
->mixer
.array
->src_gain_enable
);
265 lola_codec_flush(chip
);
266 if (chip
->mixer
.caps
& LOLA_PEAK_METER_CAN_AGC_MASK
) {
267 /* update for all srcs at once */
268 return lola_codec_write(chip
, chip
->mixer
.nid
,
269 LOLA_VERB_SET_SOURCE_GAIN
, 0x80, 0);
271 /* update manually */
272 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
273 if (mask
& (1 << i
)) {
274 lola_codec_write(chip
, chip
->mixer
.nid
,
275 LOLA_VERB_SET_SOURCE_GAIN
, i
, 0);
280 #endif /* not used */
282 static int lola_mixer_set_mapping_gain(struct lola
*chip
,
283 unsigned int src
, unsigned int dest
,
284 unsigned short gain
, bool on
)
288 if (!(chip
->mixer
.src_mask
& (1 << src
)) ||
289 !(chip
->mixer
.dest_mask
& (1 << dest
)))
292 writew(gain
, &chip
->mixer
.array
->dest_mix_gain
[dest
][src
]);
293 val
= readl(&chip
->mixer
.array
->dest_mix_gain_enable
[dest
]);
298 writel(val
, &chip
->mixer
.array
->dest_mix_gain_enable
[dest
]);
299 lola_codec_flush(chip
);
300 return lola_codec_write(chip
, chip
->mixer
.nid
, LOLA_VERB_SET_MIX_GAIN
,
305 static int lola_mixer_set_dest_gains(struct lola
*chip
, unsigned int id
,
306 unsigned int mask
, unsigned short *gains
)
310 if (!(chip
->mixer
.dest_mask
& (1 << id
)) ||
311 (chip
->mixer
.src_mask
& mask
) != mask
)
313 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
314 if (mask
& (1 << i
)) {
315 writew(*gains
, &chip
->mixer
.array
->dest_mix_gain
[id
][i
]);
319 writel(mask
, &chip
->mixer
.array
->dest_mix_gain_enable
[id
]);
320 lola_codec_flush(chip
);
321 /* update for all dests at once */
322 return lola_codec_write(chip
, chip
->mixer
.nid
,
323 LOLA_VERB_SET_DESTINATION_GAIN
, id
, 0);
325 #endif /* not used */
330 static int set_analog_volume(struct lola
*chip
, int dir
,
331 unsigned int idx
, unsigned int val
,
334 int lola_setup_all_analog_gains(struct lola
*chip
, int dir
, bool mute
)
336 struct lola_pin
*pin
;
339 pin
= chip
->pin
[dir
].pins
;
340 max_idx
= chip
->pin
[dir
].num_pins
;
341 for (idx
= 0; idx
< max_idx
; idx
++) {
342 if (pin
[idx
].is_analog
) {
343 unsigned int val
= mute
? 0 : pin
[idx
].cur_gain_step
;
344 /* set volume and do not save the value */
345 set_analog_volume(chip
, dir
, idx
, val
, false);
348 return lola_codec_flush(chip
);
351 void lola_save_mixer(struct lola
*chip
)
353 /* mute analog output */
354 if (chip
->mixer
.array_saved
) {
355 /* store contents of mixer array */
356 memcpy_fromio(chip
->mixer
.array_saved
, chip
->mixer
.array
,
357 sizeof(*chip
->mixer
.array
));
359 lola_setup_all_analog_gains(chip
, PLAY
, true); /* output mute */
362 void lola_restore_mixer(struct lola
*chip
)
366 /*lola_reset_setups(chip);*/
367 if (chip
->mixer
.array_saved
) {
368 /* restore contents of mixer array */
369 memcpy_toio(chip
->mixer
.array
, chip
->mixer
.array_saved
,
370 sizeof(*chip
->mixer
.array
));
371 /* inform micro-controller about all restored values
372 * and ignore return values
374 for (i
= 0; i
< chip
->mixer
.src_phys_ins
; i
++)
375 lola_codec_write(chip
, chip
->mixer
.nid
,
376 LOLA_VERB_SET_SOURCE_GAIN
,
378 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++)
379 lola_codec_write(chip
, chip
->mixer
.nid
,
380 LOLA_VERB_SET_SOURCE_GAIN
,
381 chip
->mixer
.src_stream_out_ofs
+ i
, 0);
382 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++)
383 lola_codec_write(chip
, chip
->mixer
.nid
,
384 LOLA_VERB_SET_DESTINATION_GAIN
,
386 for (i
= 0; i
< chip
->mixer
.dest_phys_outs
; i
++)
387 lola_codec_write(chip
, chip
->mixer
.nid
,
388 LOLA_VERB_SET_DESTINATION_GAIN
,
389 chip
->mixer
.dest_phys_out_ofs
+ i
, 0);
390 lola_codec_flush(chip
);
397 static int set_analog_volume(struct lola
*chip
, int dir
,
398 unsigned int idx
, unsigned int val
,
401 struct lola_pin
*pin
;
404 if (idx
>= chip
->pin
[dir
].num_pins
)
406 pin
= &chip
->pin
[dir
].pins
[idx
];
407 if (!pin
->is_analog
|| pin
->amp_num_steps
<= val
)
409 if (external_call
&& pin
->cur_gain_step
== val
)
412 lola_codec_flush(chip
);
413 dev_dbg(chip
->card
->dev
,
414 "set_analog_volume (dir=%d idx=%d, volume=%d)\n",
416 err
= lola_codec_write(chip
, pin
->nid
,
417 LOLA_VERB_SET_AMP_GAIN_MUTE
, val
, 0);
421 pin
->cur_gain_step
= val
;
425 int lola_set_src_config(struct lola
*chip
, unsigned int src_mask
, bool update
)
431 /* SRC can be activated and the dwInputSRCMask is valid? */
432 if ((chip
->input_src_caps_mask
& src_mask
) != src_mask
)
434 /* handle all even Inputs - SRC is a stereo setting !!! */
435 for (n
= 0; n
< chip
->pin
[CAPT
].num_pins
; n
+= 2) {
436 unsigned int mask
= 3U << n
; /* handle the stereo case */
437 unsigned int new_src
, src_state
;
438 if (!(chip
->input_src_caps_mask
& mask
))
440 /* if one IO needs SRC, both stereo IO will get SRC */
441 new_src
= (src_mask
& mask
) != 0;
443 src_state
= (chip
->input_src_mask
& mask
) != 0;
444 if (src_state
== new_src
)
445 continue; /* nothing to change for this IO */
447 err
= lola_codec_write(chip
, chip
->pcm
[CAPT
].streams
[n
].nid
,
448 LOLA_VERB_SET_SRC
, new_src
, 0);
455 ret
= lola_codec_flush(chip
);
457 chip
->input_src_mask
= src_mask
;
463 static int init_mixer_values(struct lola
*chip
)
467 /* all sample rate converters on */
468 lola_set_src_config(chip
, (1 << chip
->pin
[CAPT
].num_pins
) - 1, false);
470 /* clear all mixer matrix settings */
471 memset_io(chip
->mixer
.array
, 0, sizeof(*chip
->mixer
.array
));
472 /* inform firmware about all updated matrix columns - capture part */
473 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++)
474 lola_codec_write(chip
, chip
->mixer
.nid
,
475 LOLA_VERB_SET_DESTINATION_GAIN
,
477 /* inform firmware about all updated matrix columns - output part */
478 for (i
= 0; i
< chip
->mixer
.dest_phys_outs
; i
++)
479 lola_codec_write(chip
, chip
->mixer
.nid
,
480 LOLA_VERB_SET_DESTINATION_GAIN
,
481 chip
->mixer
.dest_phys_out_ofs
+ i
, 0);
483 /* set all digital input source (master) gains to 0dB */
484 for (i
= 0; i
< chip
->mixer
.src_phys_ins
; i
++)
485 lola_mixer_set_src_gain(chip
, i
, 336, true); /* 0dB */
487 /* set all digital playback source (master) gains to 0dB */
488 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++)
489 lola_mixer_set_src_gain(chip
,
490 i
+ chip
->mixer
.src_stream_out_ofs
,
491 336, true); /* 0dB */
492 /* set gain value 0dB diagonally in matrix - part INPUT -> CAPTURE */
493 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++) {
494 int src
= i
% chip
->mixer
.src_phys_ins
;
495 lola_mixer_set_mapping_gain(chip
, src
, i
, 336, true);
497 /* set gain value 0dB diagonally in matrix , part PLAYBACK -> OUTPUT
498 * (LoLa280 : playback channel 0,2,4,6 linked to output channel 0)
499 * (LoLa280 : playback channel 1,3,5,7 linked to output channel 1)
501 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++) {
502 int src
= chip
->mixer
.src_stream_out_ofs
+ i
;
503 int dst
= chip
->mixer
.dest_phys_out_ofs
+
504 i
% chip
->mixer
.dest_phys_outs
;
505 lola_mixer_set_mapping_gain(chip
, src
, dst
, 336, true);
511 * analog mixer control element
513 static int lola_analog_vol_info(struct snd_kcontrol
*kcontrol
,
514 struct snd_ctl_elem_info
*uinfo
)
516 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
517 int dir
= kcontrol
->private_value
;
519 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
520 uinfo
->count
= chip
->pin
[dir
].num_pins
;
521 uinfo
->value
.integer
.min
= 0;
522 uinfo
->value
.integer
.max
= chip
->pin
[dir
].pins
[0].amp_num_steps
;
526 static int lola_analog_vol_get(struct snd_kcontrol
*kcontrol
,
527 struct snd_ctl_elem_value
*ucontrol
)
529 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
530 int dir
= kcontrol
->private_value
;
533 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++)
534 ucontrol
->value
.integer
.value
[i
] =
535 chip
->pin
[dir
].pins
[i
].cur_gain_step
;
539 static int lola_analog_vol_put(struct snd_kcontrol
*kcontrol
,
540 struct snd_ctl_elem_value
*ucontrol
)
542 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
543 int dir
= kcontrol
->private_value
;
546 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++) {
547 err
= set_analog_volume(chip
, dir
, i
,
548 ucontrol
->value
.integer
.value
[i
],
556 static int lola_analog_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
557 unsigned int size
, unsigned int __user
*tlv
)
559 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
560 int dir
= kcontrol
->private_value
;
561 unsigned int val1
, val2
;
562 struct lola_pin
*pin
;
564 if (size
< 4 * sizeof(unsigned int))
566 pin
= &chip
->pin
[dir
].pins
[0];
568 val2
= pin
->amp_step_size
* 25;
569 val1
= -1 * (int)pin
->amp_offset
* (int)val2
;
570 #ifdef TLV_DB_SCALE_MUTE
571 val2
|= TLV_DB_SCALE_MUTE
;
573 if (put_user(SNDRV_CTL_TLVT_DB_SCALE
, tlv
))
575 if (put_user(2 * sizeof(unsigned int), tlv
+ 1))
577 if (put_user(val1
, tlv
+ 2))
579 if (put_user(val2
, tlv
+ 3))
584 static struct snd_kcontrol_new lola_analog_mixer
= {
585 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
586 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
587 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
588 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
),
589 .info
= lola_analog_vol_info
,
590 .get
= lola_analog_vol_get
,
591 .put
= lola_analog_vol_put
,
592 .tlv
.c
= lola_analog_vol_tlv
,
595 static int create_analog_mixer(struct lola
*chip
, int dir
, char *name
)
597 if (!chip
->pin
[dir
].num_pins
)
599 /* no analog volumes on digital only adapters */
600 if (chip
->pin
[dir
].num_pins
!= chip
->pin
[dir
].num_analog_pins
)
602 lola_analog_mixer
.name
= name
;
603 lola_analog_mixer
.private_value
= dir
;
604 return snd_ctl_add(chip
->card
,
605 snd_ctl_new1(&lola_analog_mixer
, chip
));
609 * Hardware sample rate converter on digital input
611 static int lola_input_src_info(struct snd_kcontrol
*kcontrol
,
612 struct snd_ctl_elem_info
*uinfo
)
614 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
616 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
617 uinfo
->count
= chip
->pin
[CAPT
].num_pins
;
618 uinfo
->value
.integer
.min
= 0;
619 uinfo
->value
.integer
.max
= 1;
623 static int lola_input_src_get(struct snd_kcontrol
*kcontrol
,
624 struct snd_ctl_elem_value
*ucontrol
)
626 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
629 for (i
= 0; i
< chip
->pin
[CAPT
].num_pins
; i
++)
630 ucontrol
->value
.integer
.value
[i
] =
631 !!(chip
->input_src_mask
& (1 << i
));
635 static int lola_input_src_put(struct snd_kcontrol
*kcontrol
,
636 struct snd_ctl_elem_value
*ucontrol
)
638 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
643 for (i
= 0; i
< chip
->pin
[CAPT
].num_pins
; i
++)
644 if (ucontrol
->value
.integer
.value
[i
])
646 return lola_set_src_config(chip
, mask
, true);
649 static struct snd_kcontrol_new lola_input_src_mixer
= {
650 .name
= "Digital SRC Capture Switch",
651 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
652 .info
= lola_input_src_info
,
653 .get
= lola_input_src_get
,
654 .put
= lola_input_src_put
,
658 * Lola16161 or Lola881 can have Hardware sample rate converters
659 * on its digital input pins
661 static int create_input_src_mixer(struct lola
*chip
)
663 if (!chip
->input_src_caps_mask
)
666 return snd_ctl_add(chip
->card
,
667 snd_ctl_new1(&lola_input_src_mixer
, chip
));
673 static int lola_src_gain_info(struct snd_kcontrol
*kcontrol
,
674 struct snd_ctl_elem_info
*uinfo
)
676 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
678 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
679 uinfo
->count
= count
;
680 uinfo
->value
.integer
.min
= 0;
681 uinfo
->value
.integer
.max
= 409;
685 static int lola_src_gain_get(struct snd_kcontrol
*kcontrol
,
686 struct snd_ctl_elem_value
*ucontrol
)
688 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
689 unsigned int ofs
= kcontrol
->private_value
& 0xff;
690 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
691 unsigned int mask
, i
;
693 mask
= readl(&chip
->mixer
.array
->src_gain_enable
);
694 for (i
= 0; i
< count
; i
++) {
695 unsigned int idx
= ofs
+ i
;
697 if (!(chip
->mixer
.src_mask
& (1 << idx
)))
699 if (mask
& (1 << idx
))
700 val
= readw(&chip
->mixer
.array
->src_gain
[idx
]) + 1;
703 ucontrol
->value
.integer
.value
[i
] = val
;
708 static int lola_src_gain_put(struct snd_kcontrol
*kcontrol
,
709 struct snd_ctl_elem_value
*ucontrol
)
711 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
712 unsigned int ofs
= kcontrol
->private_value
& 0xff;
713 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
716 for (i
= 0; i
< count
; i
++) {
717 unsigned int idx
= ofs
+ i
;
718 unsigned short val
= ucontrol
->value
.integer
.value
[i
];
721 err
= lola_mixer_set_src_gain(chip
, idx
, val
, !!val
);
728 /* raw value: 0 = -84dB, 336 = 0dB, 408=18dB, incremented 1 for mute */
729 static const DECLARE_TLV_DB_SCALE(lola_src_gain_tlv
, -8425, 25, 1);
731 static struct snd_kcontrol_new lola_src_gain_mixer
= {
732 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
733 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
734 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
735 .info
= lola_src_gain_info
,
736 .get
= lola_src_gain_get
,
737 .put
= lola_src_gain_put
,
738 .tlv
.p
= lola_src_gain_tlv
,
741 static int create_src_gain_mixer(struct lola
*chip
,
742 int num
, int ofs
, char *name
)
744 lola_src_gain_mixer
.name
= name
;
745 lola_src_gain_mixer
.private_value
= ofs
+ (num
<< 8);
746 return snd_ctl_add(chip
->card
,
747 snd_ctl_new1(&lola_src_gain_mixer
, chip
));
752 * destination gain (matrix-like) mixer
754 static int lola_dest_gain_info(struct snd_kcontrol
*kcontrol
,
755 struct snd_ctl_elem_info
*uinfo
)
757 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
759 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
760 uinfo
->count
= src_num
;
761 uinfo
->value
.integer
.min
= 0;
762 uinfo
->value
.integer
.max
= 433;
766 static int lola_dest_gain_get(struct snd_kcontrol
*kcontrol
,
767 struct snd_ctl_elem_value
*ucontrol
)
769 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
770 unsigned int src_ofs
= kcontrol
->private_value
& 0xff;
771 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
772 unsigned int dst_ofs
= (kcontrol
->private_value
>> 16) & 0xff;
773 unsigned int dst
, mask
, i
;
775 dst
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + dst_ofs
;
776 mask
= readl(&chip
->mixer
.array
->dest_mix_gain_enable
[dst
]);
777 for (i
= 0; i
< src_num
; i
++) {
778 unsigned int src
= src_ofs
+ i
;
780 if (!(chip
->mixer
.src_mask
& (1 << src
)))
782 if (mask
& (1 << dst
))
783 val
= readw(&chip
->mixer
.array
->dest_mix_gain
[dst
][src
]) + 1;
786 ucontrol
->value
.integer
.value
[i
] = val
;
791 static int lola_dest_gain_put(struct snd_kcontrol
*kcontrol
,
792 struct snd_ctl_elem_value
*ucontrol
)
794 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
795 unsigned int src_ofs
= kcontrol
->private_value
& 0xff;
796 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
797 unsigned int dst_ofs
= (kcontrol
->private_value
>> 16) & 0xff;
798 unsigned int dst
, mask
;
799 unsigned short gains
[MAX_STREAM_COUNT
];
804 for (i
= 0; i
< src_num
; i
++) {
805 unsigned short val
= ucontrol
->value
.integer
.value
[i
];
807 gains
[num
++] = val
- 1;
812 dst
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + dst_ofs
;
813 return lola_mixer_set_dest_gains(chip
, dst
, mask
, gains
);
816 static const DECLARE_TLV_DB_SCALE(lola_dest_gain_tlv
, -8425, 25, 1);
818 static struct snd_kcontrol_new lola_dest_gain_mixer
= {
819 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
820 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
821 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
822 .info
= lola_dest_gain_info
,
823 .get
= lola_dest_gain_get
,
824 .put
= lola_dest_gain_put
,
825 .tlv
.p
= lola_dest_gain_tlv
,
828 static int create_dest_gain_mixer(struct lola
*chip
,
829 int src_num
, int src_ofs
,
830 int num
, int ofs
, char *name
)
832 lola_dest_gain_mixer
.count
= num
;
833 lola_dest_gain_mixer
.name
= name
;
834 lola_dest_gain_mixer
.private_value
=
835 src_ofs
+ (src_num
<< 8) + (ofs
<< 16) + (num
<< 24);
836 return snd_ctl_add(chip
->card
,
837 snd_ctl_new1(&lola_dest_gain_mixer
, chip
));
839 #endif /* not used */
843 int lola_create_mixer(struct lola
*chip
)
847 err
= create_analog_mixer(chip
, PLAY
, "Analog Playback Volume");
850 err
= create_analog_mixer(chip
, CAPT
, "Analog Capture Volume");
853 err
= create_input_src_mixer(chip
);
856 err
= create_src_gain_mixer(chip
, chip
->mixer
.src_phys_ins
, 0,
857 "Digital Capture Volume");
860 err
= create_src_gain_mixer(chip
, chip
->mixer
.src_stream_outs
,
861 chip
->mixer
.src_stream_out_ofs
,
862 "Digital Playback Volume");
866 /* FIXME: buggy mixer matrix handling */
867 err
= create_dest_gain_mixer(chip
,
868 chip
->mixer
.src_phys_ins
, 0,
869 chip
->mixer
.dest_stream_ins
, 0,
870 "Line Capture Volume");
873 err
= create_dest_gain_mixer(chip
,
874 chip
->mixer
.src_stream_outs
,
875 chip
->mixer
.src_stream_out_ofs
,
876 chip
->mixer
.dest_stream_ins
, 0,
877 "Stream-Loopback Capture Volume");
880 err
= create_dest_gain_mixer(chip
,
881 chip
->mixer
.src_phys_ins
, 0,
882 chip
->mixer
.dest_phys_outs
,
883 chip
->mixer
.dest_phys_out_ofs
,
884 "Line-Loopback Playback Volume");
887 err
= create_dest_gain_mixer(chip
,
888 chip
->mixer
.src_stream_outs
,
889 chip
->mixer
.src_stream_out_ofs
,
890 chip
->mixer
.dest_phys_outs
,
891 chip
->mixer
.dest_phys_out_ofs
,
892 "Stream Playback Volume");
896 return init_mixer_values(chip
);