21 #include <linux/slab.h>
103 #define VOL_MIXER_START MIXER_MASTER_P
104 #define VOL_MIXER_END MIXER_SPDIFI_C
105 #define VOL_MIXER_NUM (VOL_MIXER_END - VOL_MIXER_START + 1)
106 #define SWH_MIXER_START MIXER_PCM_C_S
107 #define SWH_MIXER_END MIXER_DIGITAL_IO_S
108 #define SWH_CAPTURE_START MIXER_PCM_C_S
109 #define SWH_CAPTURE_END MIXER_SPDIFI_C_S
122 .name =
"Master Playback Volume",
126 .name =
"Master Capture Volume",
130 .name =
"PCM Playback Volume",
134 .name =
"PCM Capture Volume",
138 .name =
"Line Playback Volume",
142 .name =
"Line Capture Volume",
146 .name =
"Mic Playback Volume",
150 .name =
"Mic Capture Volume",
154 .name =
"IEC958 Playback Volume",
158 .name =
"IEC958 Capture Volume",
162 .name =
"Digital Playback Volume",
166 .name =
"Front Playback Volume",
170 .name =
"Side Playback Volume",
174 .name =
"Center/LFE Playback Volume",
178 .name =
"Surround Playback Volume",
182 .name =
"PCM Capture Switch",
186 .name =
"Line Capture Switch",
190 .name =
"Mic Capture Switch",
194 .name =
"IEC958 Capture Switch",
198 .name =
"Digital Playback Switch",
202 .name =
"Front Playback Switch",
206 .name =
"Side Playback Switch",
210 .name =
"Center/LFE Playback Switch",
214 .name =
"Surround Playback Switch",
218 .name =
"Digit-IO Playback Switch",
234 switch (alsa_index) {
278 set_switch_state(
struct ct_mixer *mixer,
290 static unsigned int uint16_to_float14(
unsigned int x)
302 for (i = 0; !(x & 0x400); i++)
305 x = (((7 -
i) & 0x7) << 10) | (x & 0x3ff);
310 static unsigned int float14_to_uint16(
unsigned int x)
329 #define VOL_SCALE 0x1c
330 #define VOL_MAX 0x100
334 static int ct_alsa_mix_volume_info(
struct snd_kcontrol *kcontrol,
345 static int ct_alsa_mix_volume_get(
struct snd_kcontrol *kcontrol,
353 for (i = 0; i < 2; i++) {
367 static int ct_alsa_mix_volume_put(
struct snd_kcontrol *kcontrol,
373 struct amixer *amixer;
374 int i,
j,
val, oval, change = 0;
376 for (i = 0; i < 2; i++) {
377 val = ucontrol->
value.integer.value[
i];
384 oval = amixer->
ops->get_scale(amixer);
386 amixer->
ops->set_scale(amixer, val);
387 amixer->
ops->commit_write(amixer);
391 for (j = 1; j < 4; j++) {
394 amixer->
ops->set_scale(amixer, val);
395 amixer->
ops->commit_write(amixer);
408 .info = ct_alsa_mix_volume_info,
409 .get = ct_alsa_mix_volume_get,
410 .put = ct_alsa_mix_volume_put,
411 .tlv = { .p = ct_vol_db_scale },
414 static int output_switch_info(
struct snd_kcontrol *kcontrol,
417 static const char *
const names[3] = {
418 "FP Headphones",
"Headphones",
"Speakers"
424 static int output_switch_get(
struct snd_kcontrol *kcontrol,
436 if (ucontrol->
value.enumerated.item[0] > 2)
443 .name =
"Analog Output Playback Enum",
444 .info = output_switch_info,
445 .get = output_switch_get,
446 .put = output_switch_put,
449 static int mic_source_switch_info(
struct snd_kcontrol *kcontrol,
452 static const char *
const names[3] = {
453 "Mic",
"FP Mic",
"Aux"
459 static int mic_source_switch_get(
struct snd_kcontrol *kcontrol,
471 if (ucontrol->
value.enumerated.item[0] > 2)
474 ucontrol->
value.enumerated.item[0]);
479 .name =
"Mic Source Capture Enum",
480 .info = mic_source_switch_info,
481 .get = mic_source_switch_get,
482 .put = mic_source_switch_put,
503 do_digit_io_switch(
struct ct_atc *atc,
int state)
535 ct_mixer_recording_select(mixer,
536 get_amixer_index(type));
538 ct_mixer_recording_unselect(mixer,
539 get_amixer_index(type));
546 do_line_mic_switch(atc, type);
565 do_digit_io_switch(atc, state);
570 static int ct_alsa_mix_switch_info(
struct snd_kcontrol *kcontrol,
582 static int ct_alsa_mix_switch_get(
struct snd_kcontrol *kcontrol,
589 ucontrol->
value.integer.value[0] = get_switch_state(mixer, type);
593 static int ct_alsa_mix_switch_put(
struct snd_kcontrol *kcontrol,
601 state = ucontrol->
value.integer.value[0];
602 if (get_switch_state(mixer, type) == state)
605 set_switch_state(mixer, type, state);
606 do_switch(atc, type, state);
614 .info = ct_alsa_mix_switch_info,
615 .get = ct_alsa_mix_switch_get,
616 .put = ct_alsa_mix_switch_put
627 static int ct_spdif_get_mask(
struct snd_kcontrol *kcontrol,
630 ucontrol->
value.iec958.status[0] = 0xff;
631 ucontrol->
value.iec958.status[1] = 0xff;
632 ucontrol->
value.iec958.status[2] = 0xff;
633 ucontrol->
value.iec958.status[3] = 0xff;
648 ucontrol->
value.iec958.status[0] = (status >> 0) & 0xff;
649 ucontrol->
value.iec958.status[1] = (status >> 8) & 0xff;
650 ucontrol->
value.iec958.status[2] = (status >> 16) & 0xff;
651 ucontrol->
value.iec958.status[3] = (status >> 24) & 0xff;
661 unsigned int status, old_status;
663 status = (ucontrol->
value.iec958.status[0] << 0) |
664 (ucontrol->
value.iec958.status[1] << 8) |
665 (ucontrol->
value.iec958.status[2] << 16) |
666 (ucontrol->
value.iec958.status[3] << 24);
669 change = (old_status !=
status);
681 .info = ct_spdif_info,
682 .get = ct_spdif_get_mask,
690 .info = ct_spdif_info,
701 .info = ct_spdif_info,
707 #define NUM_IEC958_CTL 3
726 switch (new->private_value) {
728 kctls[0] = kctl;
break;
730 kctls[1] = kctl;
break;
738 static int ct_mixer_kcontrols_create(
struct ct_mixer *mixer)
747 if (ct_kcontrol_init_table[type].
ctl) {
750 err = ct_mixer_kcontrol_new(mixer, &vol_ctl);
759 if (ct_kcontrol_init_table[type].ctl) {
762 err = ct_mixer_kcontrol_new(mixer, &swh_ctl);
768 err = ct_mixer_kcontrol_new(mixer, &iec958_mask_ctl);
772 err = ct_mixer_kcontrol_new(mixer, &iec958_default_ctl);
776 err = ct_mixer_kcontrol_new(mixer, &iec958_ctl);
781 err = ct_mixer_kcontrol_new(mixer, &output_ctl);
787 err = ct_mixer_kcontrol_new(mixer, &mic_source_ctl);
815 struct amixer *amix_d;
819 for (i = 0; i < 2; i++) {
822 amix_d->
ops->set_sum(amix_d, sum_c);
823 amix_d->
ops->commit_write(amix_d);
830 struct amixer *amix_d;
833 for (i = 0; i < 2; i++) {
835 amix_d->
ops->set_sum(amix_d,
NULL);
836 amix_d->
ops->commit_write(amix_d);
840 static int ct_mixer_get_resources(
struct ct_mixer *mixer)
846 struct amixer *amixer;
852 sum_mgr = (
struct sum_mgr *)mixer->
atc->rsc_mgrs[
SUM];
853 sum_desc.
msr = mixer->
atc->msr;
855 err = sum_mgr->
get_sum(sum_mgr, &sum_desc, &sum);
867 amixer_mgr = (
struct amixer_mgr *)mixer->
atc->rsc_mgrs[
AMIXER];
868 am_desc.
msr = mixer->
atc->msr;
870 err = amixer_mgr->
get_amixer(amixer_mgr, &am_desc, &amixer);
894 sum_mgr->
put_sum(sum_mgr, (
struct sum *)mixer->
sums[i]);
902 static int ct_mixer_get_mem(
struct ct_mixer **rmixer)
935 static int ct_mixer_topology_build(
struct ct_mixer *mixer)
938 struct amixer *amix_d, *amix_s;
1050 static int mixer_set_input_port(
struct amixer *amixer,
struct rsc *
rsc)
1052 amixer->
ops->set_input(amixer, rsc);
1053 amixer->
ops->commit_write(amixer);
1078 static int mixer_get_output_ports(
struct ct_mixer *mixer,
1080 struct rsc **rleft,
struct rsc **rright)
1089 &((
struct amixer *)mixer->
amixers[amix*CHN_NUM+1])->rsc;
1094 static int mixer_set_input_left(
struct ct_mixer *mixer,
1099 mixer_set_input_port(mixer->
amixers[amix*CHN_NUM], rsc);
1100 amix = get_recording_amixer(amix);
1102 mixer_set_input_port(mixer->
amixers[amix*CHN_NUM], rsc);
1108 mixer_set_input_right(
struct ct_mixer *mixer,
1113 mixer_set_input_port(mixer->
amixers[amix*CHN_NUM+1], rsc);
1114 amix = get_recording_amixer(amix);
1116 mixer_set_input_port(mixer->
amixers[amix*CHN_NUM+1], rsc);
1121 #ifdef CONFIG_PM_SLEEP
1122 static int mixer_resume(
struct ct_mixer *mixer)
1125 struct amixer *amixer;
1130 amixer->
ops->commit_write(amixer);
1135 state = get_switch_state(mixer, i);
1136 do_switch(mixer->
atc, i, state);
1145 struct sum_mgr *sum_mgr = (
struct sum_mgr *)mixer->
atc->rsc_mgrs[
SUM];
1146 struct amixer_mgr *amixer_mgr =
1147 (
struct amixer_mgr *)mixer->
atc->rsc_mgrs[
AMIXER];
1148 struct amixer *amixer;
1162 sum_mgr->
put_sum(sum_mgr, (
struct sum *)mixer->
sums[i]);
1181 err = ct_mixer_get_mem(&mixer);
1191 #ifdef CONFIG_PM_SLEEP
1192 mixer->resume = mixer_resume;
1196 err = ct_mixer_get_resources(mixer);
1201 ct_mixer_topology_build(mixer);
1220 err = ct_mixer_kcontrols_create((
struct ct_mixer *)atc->
mixer);