101 static void ca0106_set_capture_source(
struct snd_ca0106 *emu)
105 source = (val << 28) | (val << 24) | (val << 20) | (val << 16);
110 static void ca0106_set_i2c_capture_source(
struct snd_ca0106 *emu,
111 unsigned int val,
int force)
113 unsigned int ngain, ogain;
119 if (force || ngain != ogain)
123 if (force || ngain != ogain)
130 static void ca0106_set_capture_mic_line_in(
struct snd_ca0106 *emu)
148 static void ca0106_set_spdif_bits(
struct snd_ca0106 *emu,
int idx)
158 #define snd_ca0106_shared_spdif_info snd_ctl_boolean_mono_info
160 static int snd_ca0106_shared_spdif_get(
struct snd_kcontrol *kcontrol,
169 static int snd_ca0106_shared_spdif_put(
struct snd_kcontrol *kcontrol,
176 val = !!ucontrol->
value.integer.value[0];
180 ca0106_spdif_enable(emu);
185 static int snd_ca0106_capture_source_info(
struct snd_kcontrol *kcontrol,
188 static char *texts[6] = {
189 "IEC958 out",
"i2s mixer out",
"IEC958 in",
"i2s in",
"AC97 in",
"SRC out"
201 static int snd_ca0106_capture_source_get(
struct snd_kcontrol *kcontrol,
210 static int snd_ca0106_capture_source_put(
struct snd_kcontrol *kcontrol,
217 val = ucontrol->
value.enumerated.item[0] ;
223 ca0106_set_capture_source(emu);
228 static int snd_ca0106_i2c_capture_source_info(
struct snd_kcontrol *kcontrol,
231 static char *texts[6] = {
232 "Phone",
"Mic",
"Line in",
"Aux"
244 static int snd_ca0106_i2c_capture_source_get(
struct snd_kcontrol *kcontrol,
253 static int snd_ca0106_i2c_capture_source_put(
struct snd_kcontrol *kcontrol,
257 unsigned int source_id;
263 source_id = ucontrol->
value.enumerated.item[0] ;
268 ca0106_set_i2c_capture_source(emu, source_id, 0);
273 static int snd_ca0106_capture_line_in_side_out_info(
struct snd_kcontrol *kcontrol,
276 static char *texts[2] = {
"Side out",
"Line in" };
287 static int snd_ca0106_capture_mic_line_in_info(
struct snd_kcontrol *kcontrol,
290 static char *texts[2] = {
"Line in",
"Mic in" };
301 static int snd_ca0106_capture_mic_line_in_get(
struct snd_kcontrol *kcontrol,
310 static int snd_ca0106_capture_mic_line_in_put(
struct snd_kcontrol *kcontrol,
317 val = ucontrol->
value.enumerated.item[0] ;
323 ca0106_set_capture_mic_line_in(emu);
331 .name =
"Shared Mic/Line in Capture Switch",
332 .info = snd_ca0106_capture_mic_line_in_info,
333 .get = snd_ca0106_capture_mic_line_in_get,
334 .put = snd_ca0106_capture_mic_line_in_put
337 static struct snd_kcontrol_new snd_ca0106_capture_line_in_side_out __devinitdata =
340 .name =
"Shared Line in/Side out Capture Switch",
341 .info = snd_ca0106_capture_line_in_side_out_info,
342 .get = snd_ca0106_capture_mic_line_in_get,
343 .put = snd_ca0106_capture_mic_line_in_put
347 static int snd_ca0106_spdif_info(
struct snd_kcontrol *kcontrol,
355 static void decode_spdif_bits(
unsigned char *
status,
unsigned int bits)
357 status[0] = (bits >> 0) & 0xff;
358 status[1] = (bits >> 8) & 0xff;
359 status[2] = (bits >> 16) & 0xff;
360 status[3] = (bits >> 24) & 0xff;
363 static int snd_ca0106_spdif_get_default(
struct snd_kcontrol *kcontrol,
367 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
369 decode_spdif_bits(ucontrol->
value.iec958.status,
374 static int snd_ca0106_spdif_get_stream(
struct snd_kcontrol *kcontrol,
378 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
380 decode_spdif_bits(ucontrol->
value.iec958.status,
385 static int snd_ca0106_spdif_get_mask(
struct snd_kcontrol *kcontrol,
388 ucontrol->
value.iec958.status[0] = 0xff;
389 ucontrol->
value.iec958.status[1] = 0xff;
390 ucontrol->
value.iec958.status[2] = 0xff;
391 ucontrol->
value.iec958.status[3] = 0xff;
395 static unsigned int encode_spdif_bits(
unsigned char *
status)
397 return ((
unsigned int)status[0] << 0) |
398 ((
unsigned int)status[1] << 8) |
399 ((
unsigned int)status[2] << 16) |
400 ((
unsigned int)status[3] << 24);
403 static int snd_ca0106_spdif_put_default(
struct snd_kcontrol *kcontrol,
407 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
410 val = encode_spdif_bits(ucontrol->
value.iec958.status);
417 ca0106_set_spdif_bits(emu, idx);
423 static int snd_ca0106_spdif_put_stream(
struct snd_kcontrol *kcontrol,
427 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
430 val = encode_spdif_bits(ucontrol->
value.iec958.status);
433 ca0106_set_spdif_bits(emu, idx);
439 static int snd_ca0106_volume_info(
struct snd_kcontrol *kcontrol,
449 static int snd_ca0106_volume_get(
struct snd_kcontrol *kcontrol,
460 ucontrol->
value.integer.value[0] = 0xff - ((value >> 24) & 0xff);
461 ucontrol->
value.integer.value[1] = 0xff - ((value >> 16) & 0xff);
465 static int snd_ca0106_volume_put(
struct snd_kcontrol *kcontrol,
469 unsigned int oval, nval;
476 nval = ((0xff - ucontrol->
value.integer.value[0]) << 24) |
477 ((0xff - ucontrol->
value.integer.value[1]) << 16);
478 nval |= ((0xff - ucontrol->
value.integer.value[0]) << 8) |
479 ((0xff - ucontrol->
value.integer.value[1]) );
486 static int snd_ca0106_i2c_volume_info(
struct snd_kcontrol *kcontrol,
496 static int snd_ca0106_i2c_volume_get(
struct snd_kcontrol *kcontrol,
509 static int snd_ca0106_i2c_volume_put(
struct snd_kcontrol *kcontrol,
520 ngain = ucontrol->
value.integer.value[0];
523 if (ogain != ngain) {
530 ngain = ucontrol->
value.integer.value[1];
533 if (ogain != ngain) {
543 #define spi_mute_info snd_ctl_boolean_mono_info
565 if (ucontrol->
value.integer.value[0]) {
579 #define CA_VOLUME(xname,chid,reg) \
581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
582 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
583 SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
584 .info = snd_ca0106_volume_info, \
585 .get = snd_ca0106_volume_get, \
586 .put = snd_ca0106_volume_put, \
587 .tlv = { .p = snd_ca0106_db_scale1 }, \
588 .private_value = ((chid) << 8) | (reg) \
592 CA_VOLUME(
"Analog Front Playback Volume",
596 CA_VOLUME(
"Analog Center/LFE Playback Volume",
601 CA_VOLUME(
"IEC958 Front Playback Volume",
605 CA_VOLUME(
"IEC958 Center/LFE Playback Volume",
607 CA_VOLUME(
"IEC958 Unknown Playback Volume",
610 CA_VOLUME(
"CAPTURE feedback Playback Volume",
618 .info = snd_ca0106_spdif_info,
619 .get = snd_ca0106_spdif_get_mask
623 .name =
"IEC958 Playback Switch",
625 .get = snd_ca0106_shared_spdif_get,
626 .put = snd_ca0106_shared_spdif_put
630 .name =
"Digital Source Capture Enum",
631 .info = snd_ca0106_capture_source_info,
632 .get = snd_ca0106_capture_source_get,
633 .put = snd_ca0106_capture_source_put
637 .name =
"Analog Source Capture Enum",
638 .info = snd_ca0106_i2c_capture_source_info,
639 .get = snd_ca0106_i2c_capture_source_get,
640 .put = snd_ca0106_i2c_capture_source_put
646 .info = snd_ca0106_spdif_info,
647 .get = snd_ca0106_spdif_get_default,
648 .put = snd_ca0106_spdif_put_default
654 .info = snd_ca0106_spdif_info,
655 .get = snd_ca0106_spdif_get_stream,
656 .put = snd_ca0106_spdif_put_stream
660 #define I2C_VOLUME(xname,chid) \
662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
663 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
664 SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
665 .info = snd_ca0106_i2c_volume_info, \
666 .get = snd_ca0106_i2c_volume_get, \
667 .put = snd_ca0106_i2c_volume_put, \
668 .tlv = { .p = snd_ca0106_db_scale2 }, \
669 .private_value = chid \
672 static struct snd_kcontrol_new snd_ca0106_volume_i2c_adc_ctls[] __devinitdata = {
679 static const int spi_dmute_reg[] = {
686 static const int spi_dmute_bit[] = {
705 spi_switch.
get = spi_mute_get;
706 spi_switch.
put = spi_mute_put;
708 switch (channel_id) {
710 spi_switch.
name =
"Analog Front Playback Switch";
711 dac_id = (details->spi_dac & 0xf000) >> (4 * 3);
714 spi_switch.
name =
"Analog Rear Playback Switch";
715 dac_id = (details->spi_dac & 0x0f00) >> (4 * 2);
718 spi_switch.
name =
"Analog Center/LFE Playback Switch";
719 dac_id = (details->spi_dac & 0x00f0) >> (4 * 1);
722 spi_switch.
name =
"Analog Side Playback Switch";
723 dac_id = (details->spi_dac & 0x000f) >> (4 * 0);
730 reg = spi_dmute_reg[dac_id];
731 bit = spi_dmute_bit[dac_id];
741 memset(&
id, 0,
sizeof(
id));
767 #define ADD_CTLS(emu, ctls) \
770 for (i = 0; i < ARRAY_SIZE(ctls); i++) { \
771 _err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \
780 static char *slave_vols[] __devinitdata = {
781 "Analog Front Playback Volume",
782 "Analog Rear Playback Volume",
783 "Analog Center/LFE Playback Volume",
784 "Analog Side Playback Volume",
785 "IEC958 Front Playback Volume",
786 "IEC958 Rear Playback Volume",
787 "IEC958 Center/LFE Playback Volume",
788 "IEC958 Unknown Playback Volume",
789 "CAPTURE feedback Playback Volume",
793 static char *slave_sws[] __devinitdata = {
794 "Analog Front Playback Switch",
795 "Analog Rear Playback Switch",
796 "Analog Center/LFE Playback Switch",
797 "Analog Side Playback Switch",
798 "IEC958 Playback Switch",
805 for (; *
list; list++) {
808 snd_ctl_add_slave(master, slave);
818 static char *ca0106_remove_ctls[] = {
819 "Master Mono Playback Switch",
820 "Master Mono Playback Volume",
821 "3D Control - Switch",
822 "3D Control Sigmatel - Depth",
823 "PCM Playback Switch",
824 "PCM Playback Volume",
825 "CD Playback Switch",
826 "CD Playback Volume",
827 "Phone Playback Switch",
828 "Phone Playback Volume",
829 "Video Playback Switch",
830 "Video Playback Volume",
831 "Beep Playback Switch",
832 "Beep Playback Volume",
833 "Mono Output Select",
837 "External Amplifier",
838 "Sigmatel 4-Speaker Stereo Playback Switch",
839 "Surround Phase Inversion Playback Switch",
842 static char *ca0106_rename_ctls[] = {
843 "Master Playback Switch",
"Capture Switch",
844 "Master Playback Volume",
"Capture Volume",
845 "Line Playback Switch",
"AC97 Line Capture Switch",
846 "Line Playback Volume",
"AC97 Line Capture Volume",
847 "Aux Playback Switch",
"AC97 Aux Capture Switch",
848 "Aux Playback Volume",
"AC97 Aux Capture Volume",
849 "Mic Playback Switch",
"AC97 Mic Capture Switch",
850 "Mic Playback Volume",
"AC97 Mic Capture Volume",
851 "Mic Select",
"AC97 Mic Select",
852 "Mic Boost (+20dB)",
"AC97 Mic Boost (+20dB)",
856 for (c = ca0106_remove_ctls; *
c; c++)
857 remove_ctl(card, *c);
858 for (c = ca0106_rename_ctls; *
c; c += 2)
859 rename_ctl(card, c[0], c[1]);
862 ADD_CTLS(emu, snd_ca0106_volume_ctls);
863 if (emu->
details->i2c_adc == 1) {
864 ADD_CTLS(emu, snd_ca0106_volume_i2c_adc_ctls);
865 if (emu->
details->gpio_type == 1)
876 ctl = snd_ca0106_volume_spi_dac_ctl(emu->
details, i);
887 snd_ca0106_master_db_scale);
893 add_slaves(card, vmaster, slave_vols);
903 add_slaves(card, vmaster, slave_sws);
910 #ifdef CONFIG_PM_SLEEP
911 struct ca0106_vol_tbl {
912 unsigned int channel_id;
916 static struct ca0106_vol_tbl saved_volumes[NUM_SAVED_VOLUMES] = {
933 for (i = 0; i < NUM_SAVED_VOLUMES; i++)
936 saved_volumes[i].channel_id);
943 for (i = 0; i < NUM_SAVED_VOLUMES; i++)
945 saved_volumes[i].channel_id,
948 ca0106_spdif_enable(chip);
949 ca0106_set_capture_source(chip);
951 for (i = 0; i < 4; i++)
952 ca0106_set_spdif_bits(chip, i);
954 ca0106_set_capture_mic_line_in(chip);