1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for Digigram Lola PCI-e boards
5 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/vmalloc.h>
12 #include <sound/core.h>
13 #include <sound/control.h>
14 #include <sound/pcm.h>
15 #include <sound/tlv.h>
18 static int lola_init_pin(struct lola
*chip
, struct lola_pin
*pin
,
25 err
= lola_read_param(chip
, nid
, LOLA_PAR_AUDIO_WIDGET_CAP
, &val
);
27 dev_err(chip
->card
->dev
, "Can't read wcaps for 0x%x\n", nid
);
30 val
&= 0x00f00fff; /* test TYPE and bits 0..11 */
31 if (val
== 0x00400200) /* Type = 4, Digital = 1 */
32 pin
->is_analog
= false;
33 else if (val
== 0x0040000a && dir
== CAPT
) /* Dig=0, InAmp/ovrd */
34 pin
->is_analog
= true;
35 else if (val
== 0x0040000c && dir
== PLAY
) /* Dig=0, OutAmp/ovrd */
36 pin
->is_analog
= true;
38 dev_err(chip
->card
->dev
, "Invalid wcaps 0x%x for 0x%x\n", val
, nid
);
42 /* analog parameters only following, so continue in case of Digital pin
48 err
= lola_read_param(chip
, nid
, LOLA_PAR_AMP_OUT_CAP
, &val
);
50 err
= lola_read_param(chip
, nid
, LOLA_PAR_AMP_IN_CAP
, &val
);
52 dev_err(chip
->card
->dev
, "Can't read AMP-caps for 0x%x\n", nid
);
56 pin
->amp_mute
= LOLA_AMP_MUTE_CAPABLE(val
);
57 pin
->amp_step_size
= LOLA_AMP_STEP_SIZE(val
);
58 pin
->amp_num_steps
= LOLA_AMP_NUM_STEPS(val
);
59 if (pin
->amp_num_steps
) {
60 /* zero as mute state */
64 pin
->amp_offset
= LOLA_AMP_OFFSET(val
);
66 err
= lola_codec_read(chip
, nid
, LOLA_VERB_GET_MAX_LEVEL
, 0, 0, &val
,
69 dev_err(chip
->card
->dev
, "Can't get MAX_LEVEL 0x%x\n", nid
);
72 pin
->max_level
= val
& 0x3ff; /* 10 bits */
74 pin
->config_default_reg
= 0;
75 pin
->fixed_gain_list_len
= 0;
76 pin
->cur_gain_step
= 0;
81 int lola_init_pins(struct lola
*chip
, int dir
, int *nidp
)
85 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++, nid
++) {
86 err
= lola_init_pin(chip
, &chip
->pin
[dir
].pins
[i
], dir
, nid
);
89 if (chip
->pin
[dir
].pins
[i
].is_analog
)
90 chip
->pin
[dir
].num_analog_pins
++;
96 void lola_free_mixer(struct lola
*chip
)
98 vfree(chip
->mixer
.array_saved
);
101 int lola_init_mixer_widget(struct lola
*chip
, int nid
)
106 err
= lola_read_param(chip
, nid
, LOLA_PAR_AUDIO_WIDGET_CAP
, &val
);
108 dev_err(chip
->card
->dev
, "Can't read wcaps for 0x%x\n", nid
);
112 if ((val
& 0xfff00000) != 0x02f00000) { /* test SubType and Type */
113 dev_dbg(chip
->card
->dev
, "No valid mixer widget\n");
117 chip
->mixer
.nid
= nid
;
118 chip
->mixer
.caps
= val
;
119 chip
->mixer
.array
= (struct lola_mixer_array __iomem
*)
120 (chip
->bar
[BAR1
].remap_addr
+ LOLA_BAR1_SOURCE_GAIN_ENABLE
);
122 /* reserve memory to copy mixer data for sleep mode transitions */
123 chip
->mixer
.array_saved
= vmalloc(sizeof(struct lola_mixer_array
));
125 /* mixer matrix sources are physical input data and play streams */
126 chip
->mixer
.src_stream_outs
= chip
->pcm
[PLAY
].num_streams
;
127 chip
->mixer
.src_phys_ins
= chip
->pin
[CAPT
].num_pins
;
129 /* mixer matrix destinations are record streams and physical output */
130 chip
->mixer
.dest_stream_ins
= chip
->pcm
[CAPT
].num_streams
;
131 chip
->mixer
.dest_phys_outs
= chip
->pin
[PLAY
].num_pins
;
133 /* mixer matrix may have unused areas between PhysIn and
134 * Play or Record and PhysOut zones
136 chip
->mixer
.src_stream_out_ofs
= chip
->mixer
.src_phys_ins
+
137 LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(val
);
138 chip
->mixer
.dest_phys_out_ofs
= chip
->mixer
.dest_stream_ins
+
139 LOLA_MIXER_DEST_REC_OUTPUT_SEPARATION(val
);
141 /* example : MixerMatrix of LoLa881 (LoLa16161 uses unused zones)
142 * +-+ 0-------8------16-------8------16
144 * |s| | INPUT | | INPUT | |
145 * | |->| -> |unused | -> |unused |
146 * |r| |CAPTURE| | OUTPUT| |
147 * | | | MIX | | MIX | |
148 * |c| 8--------------------------------
151 * |g| |unused |unused |unused |unused |
154 * | | 16-------------------------------
156 * | | | PLAYBK| | PLAYBK| |
157 * |n|->| -> |unused | -> |unused |
158 * | | |CAPTURE| | OUTPUT| |
159 * | | | MIX | | MIX | |
160 * |a| 8--------------------------------
163 * |a| |unused |unused |unused |unused |
166 * +++ 16--|---------------|------------
167 * +---V---------------V-----------+
168 * | dest_mix_gain_enable array |
169 * +-------------------------------+
171 /* example : MixerMatrix of LoLa280
174 * |s| | INPUT | | INPUT
176 * |c| |CAPTURE| | <- OUTPUT
180 * |i| | PLAYBK| | PLAYBACK
182 * | | |CAPTURE| | <- OUTPUT
185 * |r| +---V----V-------------------+
186 * |a| | dest_mix_gain_enable array |
187 * |y| +----------------------------+
189 if (chip
->mixer
.src_stream_out_ofs
> MAX_AUDIO_INOUT_COUNT
||
190 chip
->mixer
.dest_phys_out_ofs
> MAX_STREAM_IN_COUNT
) {
191 dev_err(chip
->card
->dev
, "Invalid mixer widget size\n");
195 chip
->mixer
.src_mask
= ((1U << chip
->mixer
.src_phys_ins
) - 1) |
196 (((1U << chip
->mixer
.src_stream_outs
) - 1)
197 << chip
->mixer
.src_stream_out_ofs
);
198 chip
->mixer
.dest_mask
= ((1U << chip
->mixer
.dest_stream_ins
) - 1) |
199 (((1U << chip
->mixer
.dest_phys_outs
) - 1)
200 << chip
->mixer
.dest_phys_out_ofs
);
202 dev_dbg(chip
->card
->dev
, "Mixer src_mask=%x, dest_mask=%x\n",
203 chip
->mixer
.src_mask
, chip
->mixer
.dest_mask
);
208 static int lola_mixer_set_src_gain(struct lola
*chip
, unsigned int id
,
209 unsigned short gain
, bool on
)
211 unsigned int oldval
, val
;
213 if (!(chip
->mixer
.src_mask
& (1 << id
)))
215 oldval
= val
= readl(&chip
->mixer
.array
->src_gain_enable
);
220 /* test if values unchanged */
221 if ((val
== oldval
) &&
222 (gain
== readw(&chip
->mixer
.array
->src_gain
[id
])))
225 dev_dbg(chip
->card
->dev
,
226 "lola_mixer_set_src_gain (id=%d, gain=%d) enable=%x\n",
228 writew(gain
, &chip
->mixer
.array
->src_gain
[id
]);
229 writel(val
, &chip
->mixer
.array
->src_gain_enable
);
230 lola_codec_flush(chip
);
231 /* inform micro-controller about the new source gain */
232 return lola_codec_write(chip
, chip
->mixer
.nid
,
233 LOLA_VERB_SET_SOURCE_GAIN
, id
, 0);
237 static int lola_mixer_set_src_gains(struct lola
*chip
, unsigned int mask
,
238 unsigned short *gains
)
242 if ((chip
->mixer
.src_mask
& mask
) != mask
)
244 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
245 if (mask
& (1 << i
)) {
246 writew(*gains
, &chip
->mixer
.array
->src_gain
[i
]);
250 writel(mask
, &chip
->mixer
.array
->src_gain_enable
);
251 lola_codec_flush(chip
);
252 if (chip
->mixer
.caps
& LOLA_PEAK_METER_CAN_AGC_MASK
) {
253 /* update for all srcs at once */
254 return lola_codec_write(chip
, chip
->mixer
.nid
,
255 LOLA_VERB_SET_SOURCE_GAIN
, 0x80, 0);
257 /* update manually */
258 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
259 if (mask
& (1 << i
)) {
260 lola_codec_write(chip
, chip
->mixer
.nid
,
261 LOLA_VERB_SET_SOURCE_GAIN
, i
, 0);
266 #endif /* not used */
268 static int lola_mixer_set_mapping_gain(struct lola
*chip
,
269 unsigned int src
, unsigned int dest
,
270 unsigned short gain
, bool on
)
274 if (!(chip
->mixer
.src_mask
& (1 << src
)) ||
275 !(chip
->mixer
.dest_mask
& (1 << dest
)))
278 writew(gain
, &chip
->mixer
.array
->dest_mix_gain
[dest
][src
]);
279 val
= readl(&chip
->mixer
.array
->dest_mix_gain_enable
[dest
]);
284 writel(val
, &chip
->mixer
.array
->dest_mix_gain_enable
[dest
]);
285 lola_codec_flush(chip
);
286 return lola_codec_write(chip
, chip
->mixer
.nid
, LOLA_VERB_SET_MIX_GAIN
,
291 static int lola_mixer_set_dest_gains(struct lola
*chip
, unsigned int id
,
292 unsigned int mask
, unsigned short *gains
)
296 if (!(chip
->mixer
.dest_mask
& (1 << id
)) ||
297 (chip
->mixer
.src_mask
& mask
) != mask
)
299 for (i
= 0; i
< LOLA_MIXER_DIM
; i
++) {
300 if (mask
& (1 << i
)) {
301 writew(*gains
, &chip
->mixer
.array
->dest_mix_gain
[id
][i
]);
305 writel(mask
, &chip
->mixer
.array
->dest_mix_gain_enable
[id
]);
306 lola_codec_flush(chip
);
307 /* update for all dests at once */
308 return lola_codec_write(chip
, chip
->mixer
.nid
,
309 LOLA_VERB_SET_DESTINATION_GAIN
, id
, 0);
311 #endif /* not used */
316 static int set_analog_volume(struct lola
*chip
, int dir
,
317 unsigned int idx
, unsigned int val
,
320 int lola_setup_all_analog_gains(struct lola
*chip
, int dir
, bool mute
)
322 struct lola_pin
*pin
;
325 pin
= chip
->pin
[dir
].pins
;
326 max_idx
= chip
->pin
[dir
].num_pins
;
327 for (idx
= 0; idx
< max_idx
; idx
++) {
328 if (pin
[idx
].is_analog
) {
329 unsigned int val
= mute
? 0 : pin
[idx
].cur_gain_step
;
330 /* set volume and do not save the value */
331 set_analog_volume(chip
, dir
, idx
, val
, false);
334 return lola_codec_flush(chip
);
337 void lola_save_mixer(struct lola
*chip
)
339 /* mute analog output */
340 if (chip
->mixer
.array_saved
) {
341 /* store contents of mixer array */
342 memcpy_fromio(chip
->mixer
.array_saved
, chip
->mixer
.array
,
343 sizeof(*chip
->mixer
.array
));
345 lola_setup_all_analog_gains(chip
, PLAY
, true); /* output mute */
348 void lola_restore_mixer(struct lola
*chip
)
352 /*lola_reset_setups(chip);*/
353 if (chip
->mixer
.array_saved
) {
354 /* restore contents of mixer array */
355 memcpy_toio(chip
->mixer
.array
, chip
->mixer
.array_saved
,
356 sizeof(*chip
->mixer
.array
));
357 /* inform micro-controller about all restored values
358 * and ignore return values
360 for (i
= 0; i
< chip
->mixer
.src_phys_ins
; i
++)
361 lola_codec_write(chip
, chip
->mixer
.nid
,
362 LOLA_VERB_SET_SOURCE_GAIN
,
364 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++)
365 lola_codec_write(chip
, chip
->mixer
.nid
,
366 LOLA_VERB_SET_SOURCE_GAIN
,
367 chip
->mixer
.src_stream_out_ofs
+ i
, 0);
368 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++)
369 lola_codec_write(chip
, chip
->mixer
.nid
,
370 LOLA_VERB_SET_DESTINATION_GAIN
,
372 for (i
= 0; i
< chip
->mixer
.dest_phys_outs
; i
++)
373 lola_codec_write(chip
, chip
->mixer
.nid
,
374 LOLA_VERB_SET_DESTINATION_GAIN
,
375 chip
->mixer
.dest_phys_out_ofs
+ i
, 0);
376 lola_codec_flush(chip
);
383 static int set_analog_volume(struct lola
*chip
, int dir
,
384 unsigned int idx
, unsigned int val
,
387 struct lola_pin
*pin
;
390 if (idx
>= chip
->pin
[dir
].num_pins
)
392 pin
= &chip
->pin
[dir
].pins
[idx
];
393 if (!pin
->is_analog
|| pin
->amp_num_steps
<= val
)
395 if (external_call
&& pin
->cur_gain_step
== val
)
398 lola_codec_flush(chip
);
399 dev_dbg(chip
->card
->dev
,
400 "set_analog_volume (dir=%d idx=%d, volume=%d)\n",
402 err
= lola_codec_write(chip
, pin
->nid
,
403 LOLA_VERB_SET_AMP_GAIN_MUTE
, val
, 0);
407 pin
->cur_gain_step
= val
;
411 int lola_set_src_config(struct lola
*chip
, unsigned int src_mask
, bool update
)
417 /* SRC can be activated and the dwInputSRCMask is valid? */
418 if ((chip
->input_src_caps_mask
& src_mask
) != src_mask
)
420 /* handle all even Inputs - SRC is a stereo setting !!! */
421 for (n
= 0; n
< chip
->pin
[CAPT
].num_pins
; n
+= 2) {
422 unsigned int mask
= 3U << n
; /* handle the stereo case */
423 unsigned int new_src
, src_state
;
424 if (!(chip
->input_src_caps_mask
& mask
))
426 /* if one IO needs SRC, both stereo IO will get SRC */
427 new_src
= (src_mask
& mask
) != 0;
429 src_state
= (chip
->input_src_mask
& mask
) != 0;
430 if (src_state
== new_src
)
431 continue; /* nothing to change for this IO */
433 err
= lola_codec_write(chip
, chip
->pcm
[CAPT
].streams
[n
].nid
,
434 LOLA_VERB_SET_SRC
, new_src
, 0);
441 ret
= lola_codec_flush(chip
);
443 chip
->input_src_mask
= src_mask
;
449 static int init_mixer_values(struct lola
*chip
)
453 /* all sample rate converters on */
454 lola_set_src_config(chip
, (1 << chip
->pin
[CAPT
].num_pins
) - 1, false);
456 /* clear all mixer matrix settings */
457 memset_io(chip
->mixer
.array
, 0, sizeof(*chip
->mixer
.array
));
458 /* inform firmware about all updated matrix columns - capture part */
459 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++)
460 lola_codec_write(chip
, chip
->mixer
.nid
,
461 LOLA_VERB_SET_DESTINATION_GAIN
,
463 /* inform firmware about all updated matrix columns - output part */
464 for (i
= 0; i
< chip
->mixer
.dest_phys_outs
; i
++)
465 lola_codec_write(chip
, chip
->mixer
.nid
,
466 LOLA_VERB_SET_DESTINATION_GAIN
,
467 chip
->mixer
.dest_phys_out_ofs
+ i
, 0);
469 /* set all digital input source (master) gains to 0dB */
470 for (i
= 0; i
< chip
->mixer
.src_phys_ins
; i
++)
471 lola_mixer_set_src_gain(chip
, i
, 336, true); /* 0dB */
473 /* set all digital playback source (master) gains to 0dB */
474 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++)
475 lola_mixer_set_src_gain(chip
,
476 i
+ chip
->mixer
.src_stream_out_ofs
,
477 336, true); /* 0dB */
478 /* set gain value 0dB diagonally in matrix - part INPUT -> CAPTURE */
479 for (i
= 0; i
< chip
->mixer
.dest_stream_ins
; i
++) {
480 int src
= i
% chip
->mixer
.src_phys_ins
;
481 lola_mixer_set_mapping_gain(chip
, src
, i
, 336, true);
483 /* set gain value 0dB diagonally in matrix , part PLAYBACK -> OUTPUT
484 * (LoLa280 : playback channel 0,2,4,6 linked to output channel 0)
485 * (LoLa280 : playback channel 1,3,5,7 linked to output channel 1)
487 for (i
= 0; i
< chip
->mixer
.src_stream_outs
; i
++) {
488 int src
= chip
->mixer
.src_stream_out_ofs
+ i
;
489 int dst
= chip
->mixer
.dest_phys_out_ofs
+
490 i
% chip
->mixer
.dest_phys_outs
;
491 lola_mixer_set_mapping_gain(chip
, src
, dst
, 336, true);
497 * analog mixer control element
499 static int lola_analog_vol_info(struct snd_kcontrol
*kcontrol
,
500 struct snd_ctl_elem_info
*uinfo
)
502 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
503 int dir
= kcontrol
->private_value
;
505 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
506 uinfo
->count
= chip
->pin
[dir
].num_pins
;
507 uinfo
->value
.integer
.min
= 0;
508 uinfo
->value
.integer
.max
= chip
->pin
[dir
].pins
[0].amp_num_steps
;
512 static int lola_analog_vol_get(struct snd_kcontrol
*kcontrol
,
513 struct snd_ctl_elem_value
*ucontrol
)
515 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
516 int dir
= kcontrol
->private_value
;
519 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++)
520 ucontrol
->value
.integer
.value
[i
] =
521 chip
->pin
[dir
].pins
[i
].cur_gain_step
;
525 static int lola_analog_vol_put(struct snd_kcontrol
*kcontrol
,
526 struct snd_ctl_elem_value
*ucontrol
)
528 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
529 int dir
= kcontrol
->private_value
;
532 for (i
= 0; i
< chip
->pin
[dir
].num_pins
; i
++) {
533 err
= set_analog_volume(chip
, dir
, i
,
534 ucontrol
->value
.integer
.value
[i
],
542 static int lola_analog_vol_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
543 unsigned int size
, unsigned int __user
*tlv
)
545 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
546 int dir
= kcontrol
->private_value
;
547 unsigned int val1
, val2
;
548 struct lola_pin
*pin
;
550 if (size
< 4 * sizeof(unsigned int))
552 pin
= &chip
->pin
[dir
].pins
[0];
554 val2
= pin
->amp_step_size
* 25;
555 val1
= -1 * (int)pin
->amp_offset
* (int)val2
;
556 #ifdef TLV_DB_SCALE_MUTE
557 val2
|= TLV_DB_SCALE_MUTE
;
559 if (put_user(SNDRV_CTL_TLVT_DB_SCALE
, tlv
))
561 if (put_user(2 * sizeof(unsigned int), tlv
+ 1))
563 if (put_user(val1
, tlv
+ 2))
565 if (put_user(val2
, tlv
+ 3))
570 static struct snd_kcontrol_new lola_analog_mixer
= {
571 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
572 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
573 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
574 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
),
575 .info
= lola_analog_vol_info
,
576 .get
= lola_analog_vol_get
,
577 .put
= lola_analog_vol_put
,
578 .tlv
.c
= lola_analog_vol_tlv
,
581 static int create_analog_mixer(struct lola
*chip
, int dir
, char *name
)
583 if (!chip
->pin
[dir
].num_pins
)
585 /* no analog volumes on digital only adapters */
586 if (chip
->pin
[dir
].num_pins
!= chip
->pin
[dir
].num_analog_pins
)
588 lola_analog_mixer
.name
= name
;
589 lola_analog_mixer
.private_value
= dir
;
590 return snd_ctl_add(chip
->card
,
591 snd_ctl_new1(&lola_analog_mixer
, chip
));
595 * Hardware sample rate converter on digital input
597 static int lola_input_src_info(struct snd_kcontrol
*kcontrol
,
598 struct snd_ctl_elem_info
*uinfo
)
600 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
602 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
603 uinfo
->count
= chip
->pin
[CAPT
].num_pins
;
604 uinfo
->value
.integer
.min
= 0;
605 uinfo
->value
.integer
.max
= 1;
609 static int lola_input_src_get(struct snd_kcontrol
*kcontrol
,
610 struct snd_ctl_elem_value
*ucontrol
)
612 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
615 for (i
= 0; i
< chip
->pin
[CAPT
].num_pins
; i
++)
616 ucontrol
->value
.integer
.value
[i
] =
617 !!(chip
->input_src_mask
& (1 << i
));
621 static int lola_input_src_put(struct snd_kcontrol
*kcontrol
,
622 struct snd_ctl_elem_value
*ucontrol
)
624 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
629 for (i
= 0; i
< chip
->pin
[CAPT
].num_pins
; i
++)
630 if (ucontrol
->value
.integer
.value
[i
])
632 return lola_set_src_config(chip
, mask
, true);
635 static const struct snd_kcontrol_new lola_input_src_mixer
= {
636 .name
= "Digital SRC Capture Switch",
637 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
638 .info
= lola_input_src_info
,
639 .get
= lola_input_src_get
,
640 .put
= lola_input_src_put
,
644 * Lola16161 or Lola881 can have Hardware sample rate converters
645 * on its digital input pins
647 static int create_input_src_mixer(struct lola
*chip
)
649 if (!chip
->input_src_caps_mask
)
652 return snd_ctl_add(chip
->card
,
653 snd_ctl_new1(&lola_input_src_mixer
, chip
));
659 static int lola_src_gain_info(struct snd_kcontrol
*kcontrol
,
660 struct snd_ctl_elem_info
*uinfo
)
662 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
664 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
665 uinfo
->count
= count
;
666 uinfo
->value
.integer
.min
= 0;
667 uinfo
->value
.integer
.max
= 409;
671 static int lola_src_gain_get(struct snd_kcontrol
*kcontrol
,
672 struct snd_ctl_elem_value
*ucontrol
)
674 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
675 unsigned int ofs
= kcontrol
->private_value
& 0xff;
676 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
677 unsigned int mask
, i
;
679 mask
= readl(&chip
->mixer
.array
->src_gain_enable
);
680 for (i
= 0; i
< count
; i
++) {
681 unsigned int idx
= ofs
+ i
;
683 if (!(chip
->mixer
.src_mask
& (1 << idx
)))
685 if (mask
& (1 << idx
))
686 val
= readw(&chip
->mixer
.array
->src_gain
[idx
]) + 1;
689 ucontrol
->value
.integer
.value
[i
] = val
;
694 static int lola_src_gain_put(struct snd_kcontrol
*kcontrol
,
695 struct snd_ctl_elem_value
*ucontrol
)
697 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
698 unsigned int ofs
= kcontrol
->private_value
& 0xff;
699 unsigned int count
= (kcontrol
->private_value
>> 8) & 0xff;
702 for (i
= 0; i
< count
; i
++) {
703 unsigned int idx
= ofs
+ i
;
704 unsigned short val
= ucontrol
->value
.integer
.value
[i
];
707 err
= lola_mixer_set_src_gain(chip
, idx
, val
, !!val
);
714 /* raw value: 0 = -84dB, 336 = 0dB, 408=18dB, incremented 1 for mute */
715 static const DECLARE_TLV_DB_SCALE(lola_src_gain_tlv
, -8425, 25, 1);
717 static struct snd_kcontrol_new lola_src_gain_mixer
= {
718 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
719 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
720 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
721 .info
= lola_src_gain_info
,
722 .get
= lola_src_gain_get
,
723 .put
= lola_src_gain_put
,
724 .tlv
.p
= lola_src_gain_tlv
,
727 static int create_src_gain_mixer(struct lola
*chip
,
728 int num
, int ofs
, char *name
)
730 lola_src_gain_mixer
.name
= name
;
731 lola_src_gain_mixer
.private_value
= ofs
+ (num
<< 8);
732 return snd_ctl_add(chip
->card
,
733 snd_ctl_new1(&lola_src_gain_mixer
, chip
));
738 * destination gain (matrix-like) mixer
740 static int lola_dest_gain_info(struct snd_kcontrol
*kcontrol
,
741 struct snd_ctl_elem_info
*uinfo
)
743 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
745 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
746 uinfo
->count
= src_num
;
747 uinfo
->value
.integer
.min
= 0;
748 uinfo
->value
.integer
.max
= 433;
752 static int lola_dest_gain_get(struct snd_kcontrol
*kcontrol
,
753 struct snd_ctl_elem_value
*ucontrol
)
755 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
756 unsigned int src_ofs
= kcontrol
->private_value
& 0xff;
757 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
758 unsigned int dst_ofs
= (kcontrol
->private_value
>> 16) & 0xff;
759 unsigned int dst
, mask
, i
;
761 dst
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + dst_ofs
;
762 mask
= readl(&chip
->mixer
.array
->dest_mix_gain_enable
[dst
]);
763 for (i
= 0; i
< src_num
; i
++) {
764 unsigned int src
= src_ofs
+ i
;
766 if (!(chip
->mixer
.src_mask
& (1 << src
)))
768 if (mask
& (1 << dst
))
769 val
= readw(&chip
->mixer
.array
->dest_mix_gain
[dst
][src
]) + 1;
772 ucontrol
->value
.integer
.value
[i
] = val
;
777 static int lola_dest_gain_put(struct snd_kcontrol
*kcontrol
,
778 struct snd_ctl_elem_value
*ucontrol
)
780 struct lola
*chip
= snd_kcontrol_chip(kcontrol
);
781 unsigned int src_ofs
= kcontrol
->private_value
& 0xff;
782 unsigned int src_num
= (kcontrol
->private_value
>> 8) & 0xff;
783 unsigned int dst_ofs
= (kcontrol
->private_value
>> 16) & 0xff;
784 unsigned int dst
, mask
;
785 unsigned short gains
[MAX_STREAM_COUNT
];
790 for (i
= 0; i
< src_num
; i
++) {
791 unsigned short val
= ucontrol
->value
.integer
.value
[i
];
793 gains
[num
++] = val
- 1;
798 dst
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
) + dst_ofs
;
799 return lola_mixer_set_dest_gains(chip
, dst
, mask
, gains
);
802 static const DECLARE_TLV_DB_SCALE(lola_dest_gain_tlv
, -8425, 25, 1);
804 static struct snd_kcontrol_new lola_dest_gain_mixer
= {
805 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
806 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
807 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
808 .info
= lola_dest_gain_info
,
809 .get
= lola_dest_gain_get
,
810 .put
= lola_dest_gain_put
,
811 .tlv
.p
= lola_dest_gain_tlv
,
814 static int create_dest_gain_mixer(struct lola
*chip
,
815 int src_num
, int src_ofs
,
816 int num
, int ofs
, char *name
)
818 lola_dest_gain_mixer
.count
= num
;
819 lola_dest_gain_mixer
.name
= name
;
820 lola_dest_gain_mixer
.private_value
=
821 src_ofs
+ (src_num
<< 8) + (ofs
<< 16) + (num
<< 24);
822 return snd_ctl_add(chip
->card
,
823 snd_ctl_new1(&lola_dest_gain_mixer
, chip
));
825 #endif /* not used */
829 int lola_create_mixer(struct lola
*chip
)
833 err
= create_analog_mixer(chip
, PLAY
, "Analog Playback Volume");
836 err
= create_analog_mixer(chip
, CAPT
, "Analog Capture Volume");
839 err
= create_input_src_mixer(chip
);
842 err
= create_src_gain_mixer(chip
, chip
->mixer
.src_phys_ins
, 0,
843 "Digital Capture Volume");
846 err
= create_src_gain_mixer(chip
, chip
->mixer
.src_stream_outs
,
847 chip
->mixer
.src_stream_out_ofs
,
848 "Digital Playback Volume");
852 /* FIXME: buggy mixer matrix handling */
853 err
= create_dest_gain_mixer(chip
,
854 chip
->mixer
.src_phys_ins
, 0,
855 chip
->mixer
.dest_stream_ins
, 0,
856 "Line Capture Volume");
859 err
= create_dest_gain_mixer(chip
,
860 chip
->mixer
.src_stream_outs
,
861 chip
->mixer
.src_stream_out_ofs
,
862 chip
->mixer
.dest_stream_ins
, 0,
863 "Stream-Loopback Capture Volume");
866 err
= create_dest_gain_mixer(chip
,
867 chip
->mixer
.src_phys_ins
, 0,
868 chip
->mixer
.dest_phys_outs
,
869 chip
->mixer
.dest_phys_out_ofs
,
870 "Line-Loopback Playback 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_phys_outs
,
877 chip
->mixer
.dest_phys_out_ofs
,
878 "Stream Playback Volume");
882 return init_mixer_values(chip
);