21 #include <linux/kernel.h>
44 if (val == 0x00400200)
46 else if (val == 0x0040000a && dir ==
CAPT)
48 else if (val == 0x0040000c && dir ==
PLAY)
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++;
111 if (chip->
mixer.array_saved)
126 if ((val & 0xfff00000) != 0x02f00000) {
131 chip->
mixer.nid = nid;
140 chip->
mixer.src_stream_outs = chip->
pcm[
PLAY].num_streams;
144 chip->
mixer.dest_stream_ins = chip->
pcm[
CAPT].num_streams;
150 chip->
mixer.src_stream_out_ofs = chip->
mixer.src_phys_ins +
152 chip->
mixer.dest_phys_out_ofs = chip->
mixer.dest_stream_ins +
209 chip->
mixer.src_mask = ((1
U << chip->
mixer.src_phys_ins) - 1) |
210 (((1
U << chip->
mixer.src_stream_outs) - 1)
211 << chip->
mixer.src_stream_out_ofs);
212 chip->
mixer.dest_mask = ((1
U << chip->
mixer.dest_stream_ins) - 1) |
213 (((1
U << chip->
mixer.dest_phys_outs) - 1)
214 << chip->
mixer.dest_phys_out_ofs);
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);
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",
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)
258 if (mask & (1 << i)) {
272 if (mask & (1 << i)) {
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]);
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)
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]);
329 static int set_analog_volume(
struct lola *chip,
int dir,
330 unsigned int idx,
unsigned int val,
338 pin = chip->
pin[dir].pins;
339 max_idx = chip->
pin[dir].num_pins;
340 for (idx = 0; idx <
max_idx; idx++) {
344 set_analog_volume(chip, dir, idx, val,
false);
353 if (chip->
mixer.array_saved) {
356 sizeof(*chip->
mixer.array));
366 if (chip->
mixer.array_saved) {
369 sizeof(*chip->
mixer.array));
373 for (i = 0; i < chip->
mixer.src_phys_ins; i++)
377 for (i = 0; i < chip->
mixer.src_stream_outs; i++)
380 chip->
mixer.src_stream_out_ofs + i, 0);
381 for (i = 0; i < chip->
mixer.dest_stream_ins; i++)
385 for (i = 0; i < chip->
mixer.dest_phys_outs; i++)
388 chip->
mixer.dest_phys_out_ofs + i, 0);
396 static int set_analog_volume(
struct lola *chip,
int dir,
397 unsigned int idx,
unsigned int val,
403 if (idx >= chip->
pin[dir].num_pins)
405 pin = &chip->
pin[dir].pins[
idx];
412 snd_printdd(
"set_analog_volume (dir=%d idx=%d, volume=%d)\n",
433 for (n = 0; n < chip->
pin[
CAPT].num_pins; n += 2) {
434 unsigned int mask = 3
U <<
n;
435 unsigned int new_src, src_state;
439 new_src = (src_mask &
mask) != 0;
442 if (src_state == new_src)
461 static int init_mixer_values(
struct lola *chip)
471 for (i = 0; i < chip->
mixer.dest_stream_ins; i++)
476 for (i = 0; i < chip->
mixer.dest_phys_outs; i++)
479 chip->
mixer.dest_phys_out_ofs + i, 0);
482 for (i = 0; i < chip->
mixer.src_phys_ins; i++)
483 lola_mixer_set_src_gain(chip, i, 336,
true);
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,
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);
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);
511 static int lola_analog_vol_info(
struct snd_kcontrol *kcontrol,
518 uinfo->
count = chip->
pin[dir].num_pins;
524 static int lola_analog_vol_get(
struct snd_kcontrol *kcontrol,
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,
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)
559 unsigned int val1, val2;
562 if (size < 4 *
sizeof(
unsigned int))
564 pin = &chip->
pin[dir].pins[0];
568 #ifdef TLV_DB_SCALE_MUTE
573 if (
put_user(2 *
sizeof(
unsigned int), tlv + 1))
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,
595 if (!chip->
pin[dir].num_pins)
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;
609 static int lola_input_src_info(
struct snd_kcontrol *kcontrol,
621 static int lola_input_src_get(
struct snd_kcontrol *kcontrol,
627 for (i = 0; i < chip->
pin[
CAPT].num_pins; i++)
628 ucontrol->
value.integer.value[i] =
633 static int lola_input_src_put(
struct snd_kcontrol *kcontrol,
641 for (i = 0; i < chip->
pin[
CAPT].num_pins; i++)
642 if (ucontrol->
value.integer.value[i])
648 .
name =
"Digital SRC Capture Switch",
650 .info = lola_input_src_info,
651 .get = lola_input_src_get,
652 .put = lola_input_src_put,
659 static int __devinit create_input_src_mixer(
struct lola *chip)
671 static int lola_src_gain_info(
struct snd_kcontrol *kcontrol,
683 static int lola_src_gain_get(
struct snd_kcontrol *kcontrol,
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;
706 static int lola_src_gain_put(
struct snd_kcontrol *kcontrol,
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);
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);
752 static int lola_dest_gain_info(
struct snd_kcontrol *kcontrol,
755 unsigned int src_num = (kcontrol->
private_value >> 8) & 0xff;
758 uinfo->
count = src_num;
764 static int lola_dest_gain_get(
struct snd_kcontrol *kcontrol,
769 unsigned int src_num = (kcontrol->
private_value >> 8) & 0xff;
770 unsigned int dst_ofs = (kcontrol->
private_value >> 16) & 0xff;
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;
789 static int lola_dest_gain_put(
struct snd_kcontrol *kcontrol,
794 unsigned int src_num = (kcontrol->
private_value >> 8) & 0xff;
795 unsigned int dst_ofs = (kcontrol->
private_value >> 16) & 0xff;
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);
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);
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");
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);