181 #include <linux/pci.h>
197 #define GPIO_D2X_EXT_POWER 0x0020
198 #define GPIO_D2_ALT 0x0080
199 #define GPIO_D2_OUTPUT_ENABLE 0x0100
201 #define GPI_EXT_POWER 0x01
202 #define GPIO_INPUT_ROUTE 0x0100
204 #define GPIO_HDAV_OUTPUT_ENABLE 0x0001
205 #define GPIO_HDAV_MAGIC 0x00c0
207 #define GPIO_DB_MASK 0x0030
208 #define GPIO_DB_H6 0x0000
210 #define GPIO_ST_OUTPUT_ENABLE 0x0001
211 #define GPIO_ST_HP_REAR 0x0002
212 #define GPIO_ST_MAGIC 0x0040
213 #define GPIO_ST_HP 0x0080
215 #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1))
216 #define I2C_DEVICE_CS2000 0x9c
218 #define PCM1796_REG_BASE 16
240 static inline void pcm1796_write_spi(
struct oxygen *
chip,
unsigned int codec,
244 static const u8 codec_map[4] = {
255 static inline void pcm1796_write_i2c(
struct oxygen *chip,
unsigned int codec,
261 static void pcm1796_write(
struct oxygen *chip,
unsigned int codec,
268 pcm1796_write_spi(chip, codec, reg, value);
270 pcm1796_write_i2c(chip, codec, reg, value);
276 static void pcm1796_write_cached(
struct oxygen *chip,
unsigned int codec,
282 pcm1796_write(chip, codec, reg, value);
285 static void cs2000_write(
struct oxygen *chip,
u8 reg,
u8 value)
293 static void cs2000_write_cached(
struct oxygen *chip,
u8 reg,
u8 value)
298 cs2000_write(chip, reg, value);
301 static void pcm1796_registers_init(
struct oxygen *chip)
309 for (i = 0; i < data->
dacs; ++
i) {
311 pcm1796_write(chip, i, 18,
313 pcm1796_write(chip, i, 16, chip->
dac_volume[i * 2]
315 pcm1796_write(chip, i, 17, chip->
dac_volume[i * 2 + 1]
317 pcm1796_write(chip, i, 19,
319 pcm1796_write(chip, i, 20,
321 pcm1796_write(chip, i, 21, 0);
326 static void pcm1796_init(
struct oxygen *chip)
338 pcm1796_registers_init(chip);
342 static void xonar_d2_init(
struct oxygen *chip)
346 data->
generic.anti_pop_delay = 300;
364 static void xonar_d2x_init(
struct oxygen *chip)
376 static void xonar_hdav_init(
struct oxygen *chip)
385 data->
pcm179x.generic.anti_pop_delay = 100;
390 data->
pcm179x.dacs = chip->
model.dac_channels_mixer / 2;
408 static void xonar_st_init_i2c(
struct oxygen *chip)
416 static void xonar_st_init_common(
struct oxygen *chip)
421 data->
dacs = chip->
model.dac_channels_mixer / 2;
439 static void cs2000_registers_init(
struct oxygen *chip)
464 static void xonar_st_init(
struct oxygen *chip)
468 data->
generic.anti_pop_delay = 100;
469 data->
h6 = chip->
model.dac_channels_mixer > 2;
482 xonar_st_init_i2c(chip);
483 cs2000_registers_init(chip);
484 xonar_st_init_common(chip);
489 static void xonar_stx_init(
struct oxygen *chip)
493 xonar_st_init_i2c(chip);
494 data->
generic.anti_pop_delay = 800;
499 xonar_st_init_common(chip);
502 static void xonar_d2_cleanup(
struct oxygen *chip)
507 static void xonar_hdav_cleanup(
struct oxygen *chip)
514 static void xonar_st_cleanup(
struct oxygen *chip)
519 static void xonar_d2_suspend(
struct oxygen *chip)
521 xonar_d2_cleanup(chip);
524 static void xonar_hdav_suspend(
struct oxygen *chip)
526 xonar_hdav_cleanup(chip);
529 static void xonar_st_suspend(
struct oxygen *chip)
531 xonar_st_cleanup(chip);
534 static void xonar_d2_resume(
struct oxygen *chip)
536 pcm1796_registers_init(chip);
540 static void xonar_hdav_resume(
struct oxygen *chip)
544 pcm1796_registers_init(chip);
549 static void xonar_stx_resume(
struct oxygen *chip)
551 pcm1796_registers_init(chip);
555 static void xonar_st_resume(
struct oxygen *chip)
557 cs2000_registers_init(chip);
558 xonar_stx_resume(chip);
561 static void update_pcm1796_oversampling(
struct oxygen *chip)
571 for (i = 0; i < data->
dacs; ++
i)
572 pcm1796_write_cached(chip, i, 20, reg);
575 static void set_pcm1796_params(
struct oxygen *chip,
582 update_pcm1796_oversampling(chip);
585 static void update_pcm1796_volume(
struct oxygen *chip)
592 for (i = 0; i < data->
dacs; ++
i) {
593 pcm1796_write_cached(chip, i, 16, chip->
dac_volume[i * 2]
595 pcm1796_write_cached(chip, i, 17, chip->
dac_volume[i * 2 + 1]
601 static void update_pcm1796_mute(
struct oxygen *chip)
610 for (i = 0; i < data->
dacs; ++
i)
611 pcm1796_write_cached(chip, i, 18, value);
614 static void update_cs2000_rate(
struct oxygen *chip,
unsigned int rate)
637 if (rate <= 96000 && (rate > 48000 || data->
h6)) {
651 static void set_st_params(
struct oxygen *chip,
655 set_pcm1796_params(chip, params);
658 static void set_hdav_params(
struct oxygen *chip,
663 set_pcm1796_params(chip, params);
669 .name =
"Analog Loopback Switch",
679 static const char *
const names[2] = {
680 "Sharp Roll-off",
"Slow Roll-off"
692 value->
value.enumerated.item[0] =
710 if (!value->
value.enumerated.item[0])
716 for (i = 0; i < data->
dacs; ++
i)
717 pcm1796_write(chip, i, 19, reg);
725 .name =
"DAC Filter Playback Enum",
726 .info = rolloff_info,
733 .name =
"HDMI Playback Switch",
740 static int st_output_switch_info(
struct snd_kcontrol *ctl,
743 static const char *
const names[3] = {
744 "Speakers",
"Headphones",
"FP Headphones"
750 static int st_output_switch_get(
struct snd_kcontrol *ctl,
758 value->
value.enumerated.item[0] = 0;
760 value->
value.enumerated.item[0] = 1;
762 value->
value.enumerated.item[0] = 2;
767 static int st_output_switch_put(
struct snd_kcontrol *ctl,
777 switch (value->
value.enumerated.item[0]) {
790 update_pcm1796_volume(chip);
792 return gpio != gpio_old;
795 static int st_hp_volume_offset_info(
struct snd_kcontrol *ctl,
798 static const char *
const names[3] = {
799 "< 64 ohms",
"64-300 ohms",
"300-600 ohms"
805 static int st_hp_volume_offset_get(
struct snd_kcontrol *ctl,
813 value->
value.enumerated.item[0] = 0;
815 value->
value.enumerated.item[0] = 1;
817 value->
value.enumerated.item[0] = 2;
823 static int st_hp_volume_offset_put(
struct snd_kcontrol *ctl,
826 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
832 if (value->
value.enumerated.item[0] > 2)
834 offset = offsets[value->
value.enumerated.item[0]];
839 update_pcm1796_volume(chip);
848 .name =
"Analog Output",
849 .info = st_output_switch_info,
850 .get = st_output_switch_get,
851 .put = st_output_switch_put,
855 .name =
"Headphones Impedance Playback Enum",
856 .info = st_hp_volume_offset_info,
857 .get = st_hp_volume_offset_get,
858 .put = st_hp_volume_offset_put,
862 static void xonar_line_mic_ac97_switch(
struct oxygen *chip,
863 unsigned int reg,
unsigned int mute)
892 static int add_pcm1796_controls(
struct oxygen *chip)
906 static int xonar_d2_mixer_init(
struct oxygen *chip)
913 err = add_pcm1796_controls(chip);
919 static int xonar_hdav_mixer_init(
struct oxygen *chip)
926 err = add_pcm1796_controls(chip);
932 static int xonar_st_mixer_init(
struct oxygen *chip)
943 err = add_pcm1796_controls(chip);
949 static void dump_pcm1796_registers(
struct oxygen *chip,
955 for (dac = 0; dac < data->
dacs; ++dac) {
956 snd_iprintf(buffer,
"\nPCM1796 %u:", dac + 1);
957 for (i = 0; i < 5; ++
i)
958 snd_iprintf(buffer,
" %02x",
961 snd_iprintf(buffer,
"\n");
964 static void dump_cs2000_registers(
struct oxygen *chip,
971 snd_iprintf(buffer,
"\nCS2000:\n00: ");
972 for (i = 1; i < 0x10; ++
i)
973 snd_iprintf(buffer,
" %02x", data->
cs2000_regs[i]);
974 snd_iprintf(buffer,
"\n10:");
975 for (i = 0x10; i < 0x1f; ++
i)
976 snd_iprintf(buffer,
" %02x", data->
cs2000_regs[i]);
977 snd_iprintf(buffer,
"\n");
981 static void dump_st_registers(
struct oxygen *chip,
984 dump_pcm1796_registers(chip, buffer);
985 dump_cs2000_registers(chip, buffer);
989 .longname =
"Asus Virtuoso 200",
991 .init = xonar_d2_init,
992 .control_filter = xonar_d2_control_filter,
993 .mixer_init = xonar_d2_mixer_init,
994 .cleanup = xonar_d2_cleanup,
995 .suspend = xonar_d2_suspend,
996 .resume = xonar_d2_resume,
997 .set_dac_params = set_pcm1796_params,
999 .update_dac_volume = update_pcm1796_volume,
1000 .update_dac_mute = update_pcm1796_mute,
1001 .dump_registers = dump_pcm1796_registers,
1002 .dac_tlv = pcm1796_db_scale,
1011 .dac_channels_pcm = 8,
1012 .dac_channels_mixer = 8,
1013 .dac_volume_min = 255 - 2*60,
1014 .dac_volume_max = 255,
1025 .longname =
"Asus Virtuoso 200",
1027 .init = xonar_hdav_init,
1028 .mixer_init = xonar_hdav_mixer_init,
1029 .cleanup = xonar_hdav_cleanup,
1030 .suspend = xonar_hdav_suspend,
1031 .resume = xonar_hdav_resume,
1033 .set_dac_params = set_hdav_params,
1035 .update_dac_volume = update_pcm1796_volume,
1036 .update_dac_mute = update_pcm1796_mute,
1038 .ac97_switch = xonar_line_mic_ac97_switch,
1039 .dump_registers = dump_pcm1796_registers,
1040 .dac_tlv = pcm1796_db_scale,
1041 .model_data_size =
sizeof(
struct xonar_hdav),
1046 .dac_channels_pcm = 8,
1047 .dac_channels_mixer = 2,
1048 .dac_volume_min = 255 - 2*60,
1049 .dac_volume_max = 255,
1059 .longname =
"Asus Virtuoso 100",
1061 .init = xonar_st_init,
1062 .mixer_init = xonar_st_mixer_init,
1063 .cleanup = xonar_st_cleanup,
1064 .suspend = xonar_st_suspend,
1065 .resume = xonar_st_resume,
1066 .set_dac_params = set_st_params,
1068 .update_dac_volume = update_pcm1796_volume,
1069 .update_dac_mute = update_pcm1796_mute,
1070 .ac97_switch = xonar_line_mic_ac97_switch,
1071 .dump_registers = dump_st_registers,
1072 .dac_tlv = pcm1796_db_scale,
1079 .dac_channels_pcm = 2,
1080 .dac_channels_mixer = 2,
1081 .dac_volume_min = 255 - 2*60,
1082 .dac_volume_max = 255,
1095 chip->
model = model_xonar_d2;
1096 chip->
model.shortname =
"Xonar D2";
1099 chip->
model = model_xonar_d2;
1100 chip->
model.shortname =
"Xonar D2X";
1101 chip->
model.init = xonar_d2x_init;
1104 chip->
model = model_xonar_hdav;
1108 chip->
model.shortname =
"Xonar HDAV1.3";
1111 chip->
model.shortname =
"Xonar HDAV1.3+H6";
1112 chip->
model.dac_channels_mixer = 8;
1118 chip->
model = model_xonar_st;
1122 chip->
model.shortname =
"Xonar ST";
1125 chip->
model.shortname =
"Xonar ST+H6";
1126 chip->
model.control_filter = xonar_st_h6_control_filter;
1127 chip->
model.dac_channels_pcm = 8;
1128 chip->
model.dac_channels_mixer = 8;
1129 chip->
model.dac_volume_min = 255;
1135 chip->
model = model_xonar_st;
1136 chip->
model.shortname =
"Xonar STX";
1137 chip->
model.init = xonar_stx_init;
1138 chip->
model.resume = xonar_stx_resume;
1139 chip->
model.set_dac_params = set_pcm1796_params;