2 * card driver for models with PCM1796 DACs (Xonar D2/D2X/HDAV1.3/ST/STX)
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2.
10 * This driver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
25 * SPI 0 -> 1st PCM1796 (front)
26 * SPI 1 -> 2nd PCM1796 (surround)
27 * SPI 2 -> 3rd PCM1796 (center/LFE)
28 * SPI 4 -> 4th PCM1796 (back)
30 * GPIO 2 -> M0 of CS5381
31 * GPIO 3 -> M1 of CS5381
32 * GPIO 5 <- external power present (D2X only)
34 * GPIO 8 -> enable output to speakers
38 * LINE_OUT -> input of ADC
44 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
48 * Xonar HDAV1.3 (Deluxe)
49 * ----------------------
53 * I²C <-> PCM1796 (addr 1001100) (front)
55 * GPI 0 <- external power present
57 * GPIO 0 -> enable HDMI (0) or speaker (1) output
58 * GPIO 2 -> M0 of CS5381
59 * GPIO 3 -> M1 of CS5381
60 * GPIO 4 <- daughterboard detection
61 * GPIO 5 <- daughterboard detection
64 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
66 * UART <-> HDMI controller
70 * LINE_OUT -> input of ADC
76 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
89 * I²C <-> PCM1796 (addr 1001101) (surround)
90 * <-> PCM1796 (addr 1001110) (center/LFE)
91 * <-> PCM1796 (addr 1001111) (back)
93 * unknown daughterboard
94 * ---------------------
99 * I²C <-> CS4362A (addr 0011000) (surround, center/LFE, back)
103 * Xonar Essence ST (Deluxe)/STX
104 * -----------------------------
108 * I²C <-> PCM1792A (addr 1001100)
109 * <-> CS2000 (addr 1001110) (ST only)
111 * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
113 * GPI 0 <- external power present (STX only)
115 * GPIO 0 -> enable output to speakers
116 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
117 * GPIO 2 -> M0 of CS5381
118 * GPIO 3 -> M1 of CS5381
119 * GPIO 4 <- daughterboard detection
120 * GPIO 5 <- daughterboard detection
122 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
123 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
127 * SCK <- CLK_OUT of CS2000 (ST only)
131 * LINE_OUT -> input of ADC
136 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
151 * I²C <-> PCM1796 (addr 1001100) (front)
152 * <-> CS4362A (addr 0011000) (surround, center/LFE, back)
153 * <-> CS2000 (addr 1001110)
155 * ADC1 MCLK -> REF_CLK of CS2000
157 * GPI 0 <- external power present
159 * GPIO 0 -> enable output
160 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
161 * GPIO 2 -> M0 of CS5381
162 * GPIO 3 -> M1 of CS5381
163 * GPIO 4 -> enable output
164 * GPIO 5 -> enable output
166 * GPIO 7 -> route output to HP (0) or speaker (1)
167 * GPIO 8 -> route input jack to mic-in (0) or line-in (1)
171 * LINE_OUT -> input of ADC
177 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
178 * GPO 1 -> route mic-in from input jack (0) or front panel header (1)
181 #include <linux/pci.h>
182 #include <linux/delay.h>
183 #include <linux/mutex.h>
184 #include <sound/ac97_codec.h>
185 #include <sound/control.h>
186 #include <sound/core.h>
187 #include <sound/info.h>
188 #include <sound/pcm.h>
189 #include <sound/pcm_params.h>
190 #include <sound/tlv.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)) /* 10011, ii, /W=0 */
216 #define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
218 #define PCM1796_REG_BASE 16
221 struct xonar_pcm179x {
222 struct xonar_generic generic;
224 u8 pcm1796_regs[4][5];
225 unsigned int current_rate;
230 u8 cs2000_regs[0x1f];
234 struct xonar_pcm179x pcm179x;
235 struct xonar_hdmi hdmi;
239 static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
242 /* maps ALSA channel pair number to SPI output */
243 static const u8 codec_map[4] = {
246 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
247 OXYGEN_SPI_DATA_LENGTH_2 |
248 OXYGEN_SPI_CLOCK_160 |
249 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
250 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
254 static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
257 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
260 static void pcm1796_write(struct oxygen *chip, unsigned int codec,
263 struct xonar_pcm179x *data = chip->model_data;
265 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
267 pcm1796_write_spi(chip, codec, reg, value);
269 pcm1796_write_i2c(chip, codec, reg, value);
270 if ((unsigned int)(reg - PCM1796_REG_BASE)
271 < ARRAY_SIZE(data->pcm1796_regs[codec]))
272 data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
275 static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
278 struct xonar_pcm179x *data = chip->model_data;
280 if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
281 pcm1796_write(chip, codec, reg, value);
284 static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
286 struct xonar_pcm179x *data = chip->model_data;
288 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
289 data->cs2000_regs[reg] = value;
292 static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
294 struct xonar_pcm179x *data = chip->model_data;
296 if (value != data->cs2000_regs[reg])
297 cs2000_write(chip, reg, value);
300 static void pcm1796_registers_init(struct oxygen *chip)
302 struct xonar_pcm179x *data = chip->model_data;
307 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
308 for (i = 0; i < data->dacs; ++i) {
309 /* set ATLD before ATL/ATR */
310 pcm1796_write(chip, i, 18,
311 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
312 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
314 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
316 pcm1796_write(chip, i, 19,
317 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
318 pcm1796_write(chip, i, 20,
319 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
320 pcm1796_write(chip, i, 21, 0);
324 static void pcm1796_init(struct oxygen *chip)
326 struct xonar_pcm179x *data = chip->model_data;
328 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
329 PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
330 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
331 PCM1796_FLT_SHARP | PCM1796_ATS_1;
332 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
333 pcm1796_registers_init(chip);
334 data->current_rate = 48000;
337 static void xonar_d2_init(struct oxygen *chip)
339 struct xonar_pcm179x *data = chip->model_data;
341 data->generic.anti_pop_delay = 300;
342 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
347 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
348 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
350 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
352 xonar_init_cs53x1(chip);
353 xonar_enable_output(chip);
355 snd_component_add(chip->card, "PCM1796");
356 snd_component_add(chip->card, "CS5381");
359 static void xonar_d2x_init(struct oxygen *chip)
361 struct xonar_pcm179x *data = chip->model_data;
363 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
364 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
365 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
366 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
367 xonar_init_ext_power(chip);
371 static void xonar_hdav_init(struct oxygen *chip)
373 struct xonar_hdav *data = chip->model_data;
375 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
376 OXYGEN_2WIRE_LENGTH_8 |
377 OXYGEN_2WIRE_INTERRUPT_MASK |
378 OXYGEN_2WIRE_SPEED_STANDARD);
380 data->pcm179x.generic.anti_pop_delay = 100;
381 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
382 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
383 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
384 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
385 data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
389 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
390 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
391 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
393 xonar_init_cs53x1(chip);
394 xonar_init_ext_power(chip);
395 xonar_hdmi_init(chip, &data->hdmi);
396 xonar_enable_output(chip);
398 snd_component_add(chip->card, "PCM1796");
399 snd_component_add(chip->card, "CS5381");
402 static void xonar_st_init_i2c(struct oxygen *chip)
404 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
405 OXYGEN_2WIRE_LENGTH_8 |
406 OXYGEN_2WIRE_INTERRUPT_MASK |
407 OXYGEN_2WIRE_SPEED_STANDARD);
410 static void xonar_st_init_common(struct oxygen *chip)
412 struct xonar_pcm179x *data = chip->model_data;
414 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
415 data->dacs = chip->model.dac_channels_mixer / 2;
416 data->hp_gain_offset = 2*-18;
420 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
421 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
422 GPIO_ST_MAGIC | GPIO_ST_HP);
423 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
424 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
426 xonar_init_cs53x1(chip);
427 xonar_enable_output(chip);
429 snd_component_add(chip->card, "PCM1792A");
430 snd_component_add(chip->card, "CS5381");
433 static void cs2000_registers_init(struct oxygen *chip)
435 struct xonar_pcm179x *data = chip->model_data;
437 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
438 cs2000_write(chip, CS2000_DEV_CTRL, 0);
439 cs2000_write(chip, CS2000_DEV_CFG_1,
441 (0 << CS2000_R_SEL_SHIFT) |
442 CS2000_AUX_OUT_SRC_REF_CLK |
443 CS2000_EN_DEV_CFG_1);
444 cs2000_write(chip, CS2000_DEV_CFG_2,
445 (0 << CS2000_LOCK_CLK_SHIFT) |
446 CS2000_FRAC_N_SRC_STATIC);
447 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
448 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
449 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
450 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
451 cs2000_write(chip, CS2000_FUN_CFG_1,
452 data->cs2000_regs[CS2000_FUN_CFG_1]);
453 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
454 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
455 msleep(3); /* PLL lock delay */
458 static void xonar_st_init(struct oxygen *chip)
460 struct xonar_pcm179x *data = chip->model_data;
462 data->generic.anti_pop_delay = 100;
463 data->has_cs2000 = 1;
464 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
466 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
467 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
468 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
469 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
471 xonar_st_init_i2c(chip);
472 cs2000_registers_init(chip);
473 xonar_st_init_common(chip);
475 snd_component_add(chip->card, "CS2000");
478 static void xonar_stx_init(struct oxygen *chip)
480 struct xonar_pcm179x *data = chip->model_data;
482 xonar_st_init_i2c(chip);
483 data->generic.anti_pop_delay = 800;
484 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
485 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
486 data->generic.ext_power_bit = GPI_EXT_POWER;
487 xonar_init_ext_power(chip);
488 xonar_st_init_common(chip);
491 static void xonar_d2_cleanup(struct oxygen *chip)
493 xonar_disable_output(chip);
496 static void xonar_hdav_cleanup(struct oxygen *chip)
498 xonar_hdmi_cleanup(chip);
499 xonar_disable_output(chip);
503 static void xonar_st_cleanup(struct oxygen *chip)
505 xonar_disable_output(chip);
508 static void xonar_d2_suspend(struct oxygen *chip)
510 xonar_d2_cleanup(chip);
513 static void xonar_hdav_suspend(struct oxygen *chip)
515 xonar_hdav_cleanup(chip);
518 static void xonar_st_suspend(struct oxygen *chip)
520 xonar_st_cleanup(chip);
523 static void xonar_d2_resume(struct oxygen *chip)
525 pcm1796_registers_init(chip);
526 xonar_enable_output(chip);
529 static void xonar_hdav_resume(struct oxygen *chip)
531 struct xonar_hdav *data = chip->model_data;
533 pcm1796_registers_init(chip);
534 xonar_hdmi_resume(chip, &data->hdmi);
535 xonar_enable_output(chip);
538 static void xonar_stx_resume(struct oxygen *chip)
540 pcm1796_registers_init(chip);
541 xonar_enable_output(chip);
544 static void xonar_st_resume(struct oxygen *chip)
546 cs2000_registers_init(chip);
547 xonar_stx_resume(chip);
550 static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
552 struct xonar_pcm179x *data = chip->model_data;
555 return OXYGEN_I2S_MCLK_512;
556 else if (rate <= 48000 && data->os_128)
557 return OXYGEN_I2S_MCLK_512;
558 else if (rate <= 96000)
559 return OXYGEN_I2S_MCLK_256;
561 return OXYGEN_I2S_MCLK_128;
564 static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
565 unsigned int channel,
566 struct snd_pcm_hw_params *params)
568 if (channel == PCM_MULTICH)
569 return mclk_from_rate(chip, params_rate(params));
571 return oxygen_default_i2s_mclk(chip, channel, params);
574 static void update_pcm1796_oversampling(struct oxygen *chip)
576 struct xonar_pcm179x *data = chip->model_data;
580 if (data->current_rate <= 32000)
581 reg = PCM1796_OS_128;
582 else if (data->current_rate <= 48000 && data->os_128)
583 reg = PCM1796_OS_128;
584 else if (data->current_rate <= 96000 || data->os_128)
588 for (i = 0; i < data->dacs; ++i)
589 pcm1796_write_cached(chip, i, 20, reg);
592 static void set_pcm1796_params(struct oxygen *chip,
593 struct snd_pcm_hw_params *params)
595 struct xonar_pcm179x *data = chip->model_data;
598 data->current_rate = params_rate(params);
599 update_pcm1796_oversampling(chip);
602 static void update_pcm1796_volume(struct oxygen *chip)
604 struct xonar_pcm179x *data = chip->model_data;
608 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
609 for (i = 0; i < data->dacs; ++i) {
610 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
612 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
617 static void update_pcm1796_mute(struct oxygen *chip)
619 struct xonar_pcm179x *data = chip->model_data;
623 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
625 value |= PCM1796_MUTE;
626 for (i = 0; i < data->dacs; ++i)
627 pcm1796_write_cached(chip, i, 18, value);
630 static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
632 struct xonar_pcm179x *data = chip->model_data;
636 /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */
638 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
642 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
644 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128;
648 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
650 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128;
653 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
656 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
659 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
662 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
665 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
668 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
669 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
670 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128)
671 reg = CS2000_REF_CLK_DIV_1;
673 reg = CS2000_REF_CLK_DIV_2;
674 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
675 msleep(3); /* PLL lock delay */
678 static void set_st_params(struct oxygen *chip,
679 struct snd_pcm_hw_params *params)
681 update_cs2000_rate(chip, params_rate(params));
682 set_pcm1796_params(chip, params);
685 static void set_hdav_params(struct oxygen *chip,
686 struct snd_pcm_hw_params *params)
688 struct xonar_hdav *data = chip->model_data;
690 set_pcm1796_params(chip, params);
691 xonar_set_hdmi_params(chip, &data->hdmi, params);
694 static const struct snd_kcontrol_new alt_switch = {
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "Analog Loopback Switch",
697 .info = snd_ctl_boolean_mono_info,
698 .get = xonar_gpio_bit_switch_get,
699 .put = xonar_gpio_bit_switch_put,
700 .private_value = GPIO_D2_ALT,
703 static int rolloff_info(struct snd_kcontrol *ctl,
704 struct snd_ctl_elem_info *info)
706 static const char *const names[2] = {
707 "Sharp Roll-off", "Slow Roll-off"
710 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
712 info->value.enumerated.items = 2;
713 if (info->value.enumerated.item >= 2)
714 info->value.enumerated.item = 1;
715 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
719 static int rolloff_get(struct snd_kcontrol *ctl,
720 struct snd_ctl_elem_value *value)
722 struct oxygen *chip = ctl->private_data;
723 struct xonar_pcm179x *data = chip->model_data;
725 value->value.enumerated.item[0] =
726 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
727 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
731 static int rolloff_put(struct snd_kcontrol *ctl,
732 struct snd_ctl_elem_value *value)
734 struct oxygen *chip = ctl->private_data;
735 struct xonar_pcm179x *data = chip->model_data;
740 mutex_lock(&chip->mutex);
741 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
742 reg &= ~PCM1796_FLT_MASK;
743 if (!value->value.enumerated.item[0])
744 reg |= PCM1796_FLT_SHARP;
746 reg |= PCM1796_FLT_SLOW;
747 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
749 for (i = 0; i < data->dacs; ++i)
750 pcm1796_write(chip, i, 19, reg);
752 mutex_unlock(&chip->mutex);
756 static const struct snd_kcontrol_new rolloff_control = {
757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
758 .name = "DAC Filter Playback Enum",
759 .info = rolloff_info,
764 static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
766 static const char *const names[2] = { "64x", "128x" };
768 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
770 info->value.enumerated.items = 2;
771 if (info->value.enumerated.item >= 2)
772 info->value.enumerated.item = 1;
773 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
777 static int os_128_get(struct snd_kcontrol *ctl,
778 struct snd_ctl_elem_value *value)
780 struct oxygen *chip = ctl->private_data;
781 struct xonar_pcm179x *data = chip->model_data;
783 value->value.enumerated.item[0] = data->os_128;
787 static int os_128_put(struct snd_kcontrol *ctl,
788 struct snd_ctl_elem_value *value)
790 struct oxygen *chip = ctl->private_data;
791 struct xonar_pcm179x *data = chip->model_data;
794 mutex_lock(&chip->mutex);
795 changed = value->value.enumerated.item[0] != data->os_128;
797 data->os_128 = value->value.enumerated.item[0];
798 if (data->has_cs2000)
799 update_cs2000_rate(chip, data->current_rate);
800 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
801 mclk_from_rate(chip, data->current_rate),
802 OXYGEN_I2S_MCLK_MASK);
804 update_pcm1796_oversampling(chip);
806 mutex_unlock(&chip->mutex);
810 static const struct snd_kcontrol_new os_128_control = {
811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
812 .name = "DAC Oversampling Playback Enum",
818 static const struct snd_kcontrol_new hdav_hdmi_control = {
819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
820 .name = "HDMI Playback Switch",
821 .info = snd_ctl_boolean_mono_info,
822 .get = xonar_gpio_bit_switch_get,
823 .put = xonar_gpio_bit_switch_put,
824 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
827 static int st_output_switch_info(struct snd_kcontrol *ctl,
828 struct snd_ctl_elem_info *info)
830 static const char *const names[3] = {
831 "Speakers", "Headphones", "FP Headphones"
834 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
836 info->value.enumerated.items = 3;
837 if (info->value.enumerated.item >= 3)
838 info->value.enumerated.item = 2;
839 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
843 static int st_output_switch_get(struct snd_kcontrol *ctl,
844 struct snd_ctl_elem_value *value)
846 struct oxygen *chip = ctl->private_data;
849 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
850 if (!(gpio & GPIO_ST_HP))
851 value->value.enumerated.item[0] = 0;
852 else if (gpio & GPIO_ST_HP_REAR)
853 value->value.enumerated.item[0] = 1;
855 value->value.enumerated.item[0] = 2;
860 static int st_output_switch_put(struct snd_kcontrol *ctl,
861 struct snd_ctl_elem_value *value)
863 struct oxygen *chip = ctl->private_data;
864 struct xonar_pcm179x *data = chip->model_data;
867 mutex_lock(&chip->mutex);
868 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
870 switch (value->value.enumerated.item[0]) {
872 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
875 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
878 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
881 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
882 data->hp_active = gpio & GPIO_ST_HP;
883 update_pcm1796_volume(chip);
884 mutex_unlock(&chip->mutex);
885 return gpio != gpio_old;
888 static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
889 struct snd_ctl_elem_info *info)
891 static const char *const names[3] = {
892 "< 64 ohms", "64-300 ohms", "300-600 ohms"
895 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
897 info->value.enumerated.items = 3;
898 if (info->value.enumerated.item > 2)
899 info->value.enumerated.item = 2;
900 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
904 static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
905 struct snd_ctl_elem_value *value)
907 struct oxygen *chip = ctl->private_data;
908 struct xonar_pcm179x *data = chip->model_data;
910 mutex_lock(&chip->mutex);
911 if (data->hp_gain_offset < 2*-6)
912 value->value.enumerated.item[0] = 0;
913 else if (data->hp_gain_offset < 0)
914 value->value.enumerated.item[0] = 1;
916 value->value.enumerated.item[0] = 2;
917 mutex_unlock(&chip->mutex);
922 static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
923 struct snd_ctl_elem_value *value)
925 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
926 struct oxygen *chip = ctl->private_data;
927 struct xonar_pcm179x *data = chip->model_data;
931 if (value->value.enumerated.item[0] > 2)
933 offset = offsets[value->value.enumerated.item[0]];
934 mutex_lock(&chip->mutex);
935 changed = offset != data->hp_gain_offset;
937 data->hp_gain_offset = offset;
938 update_pcm1796_volume(chip);
940 mutex_unlock(&chip->mutex);
944 static const struct snd_kcontrol_new st_controls[] = {
946 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
947 .name = "Analog Output",
948 .info = st_output_switch_info,
949 .get = st_output_switch_get,
950 .put = st_output_switch_put,
953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
954 .name = "Headphones Impedance Playback Enum",
955 .info = st_hp_volume_offset_info,
956 .get = st_hp_volume_offset_get,
957 .put = st_hp_volume_offset_put,
961 static void xonar_line_mic_ac97_switch(struct oxygen *chip,
962 unsigned int reg, unsigned int mute)
964 if (reg == AC97_LINE) {
965 spin_lock_irq(&chip->reg_lock);
966 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
967 mute ? GPIO_INPUT_ROUTE : 0,
969 spin_unlock_irq(&chip->reg_lock);
973 static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
975 static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
977 if (!strncmp(template->name, "CD Capture ", 11))
978 /* CD in is actually connected to the video in pin */
979 template->private_value ^= AC97_CD ^ AC97_VIDEO;
983 static int add_pcm1796_controls(struct oxygen *chip)
987 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
990 err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip));
996 static int xonar_d2_mixer_init(struct oxygen *chip)
1000 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
1003 err = add_pcm1796_controls(chip);
1009 static int xonar_hdav_mixer_init(struct oxygen *chip)
1013 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
1016 err = add_pcm1796_controls(chip);
1022 static int xonar_st_mixer_init(struct oxygen *chip)
1027 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
1028 err = snd_ctl_add(chip->card,
1029 snd_ctl_new1(&st_controls[i], chip));
1033 err = add_pcm1796_controls(chip);
1039 static void dump_pcm1796_registers(struct oxygen *chip,
1040 struct snd_info_buffer *buffer)
1042 struct xonar_pcm179x *data = chip->model_data;
1043 unsigned int dac, i;
1045 for (dac = 0; dac < data->dacs; ++dac) {
1046 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
1047 for (i = 0; i < 5; ++i)
1048 snd_iprintf(buffer, " %02x",
1049 data->pcm1796_regs[dac][i]);
1051 snd_iprintf(buffer, "\n");
1054 static void dump_cs2000_registers(struct oxygen *chip,
1055 struct snd_info_buffer *buffer)
1057 struct xonar_pcm179x *data = chip->model_data;
1060 if (data->has_cs2000) {
1061 snd_iprintf(buffer, "\nCS2000:\n00: ");
1062 for (i = 1; i < 0x10; ++i)
1063 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1064 snd_iprintf(buffer, "\n10:");
1065 for (i = 0x10; i < 0x1f; ++i)
1066 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1067 snd_iprintf(buffer, "\n");
1071 static void dump_st_registers(struct oxygen *chip,
1072 struct snd_info_buffer *buffer)
1074 dump_pcm1796_registers(chip, buffer);
1075 dump_cs2000_registers(chip, buffer);
1078 static const struct oxygen_model model_xonar_d2 = {
1079 .longname = "Asus Virtuoso 200",
1081 .init = xonar_d2_init,
1082 .control_filter = xonar_d2_control_filter,
1083 .mixer_init = xonar_d2_mixer_init,
1084 .cleanup = xonar_d2_cleanup,
1085 .suspend = xonar_d2_suspend,
1086 .resume = xonar_d2_resume,
1087 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1088 .set_dac_params = set_pcm1796_params,
1089 .set_adc_params = xonar_set_cs53x1_params,
1090 .update_dac_volume = update_pcm1796_volume,
1091 .update_dac_mute = update_pcm1796_mute,
1092 .dump_registers = dump_pcm1796_registers,
1093 .dac_tlv = pcm1796_db_scale,
1094 .model_data_size = sizeof(struct xonar_pcm179x),
1095 .device_config = PLAYBACK_0_TO_I2S |
1096 PLAYBACK_1_TO_SPDIF |
1097 CAPTURE_0_FROM_I2S_2 |
1098 CAPTURE_1_FROM_SPDIF |
1102 .dac_channels_pcm = 8,
1103 .dac_channels_mixer = 8,
1104 .dac_volume_min = 255 - 2*60,
1105 .dac_volume_max = 255,
1106 .misc_flags = OXYGEN_MISC_MIDI,
1107 .function_flags = OXYGEN_FUNCTION_SPI |
1108 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1109 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1110 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1113 static const struct oxygen_model model_xonar_hdav = {
1114 .longname = "Asus Virtuoso 200",
1116 .init = xonar_hdav_init,
1117 .mixer_init = xonar_hdav_mixer_init,
1118 .cleanup = xonar_hdav_cleanup,
1119 .suspend = xonar_hdav_suspend,
1120 .resume = xonar_hdav_resume,
1121 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1122 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1123 .set_dac_params = set_hdav_params,
1124 .set_adc_params = xonar_set_cs53x1_params,
1125 .update_dac_volume = update_pcm1796_volume,
1126 .update_dac_mute = update_pcm1796_mute,
1127 .uart_input = xonar_hdmi_uart_input,
1128 .ac97_switch = xonar_line_mic_ac97_switch,
1129 .dump_registers = dump_pcm1796_registers,
1130 .dac_tlv = pcm1796_db_scale,
1131 .model_data_size = sizeof(struct xonar_hdav),
1132 .device_config = PLAYBACK_0_TO_I2S |
1133 PLAYBACK_1_TO_SPDIF |
1134 CAPTURE_0_FROM_I2S_2 |
1135 CAPTURE_1_FROM_SPDIF,
1136 .dac_channels_pcm = 8,
1137 .dac_channels_mixer = 2,
1138 .dac_volume_min = 255 - 2*60,
1139 .dac_volume_max = 255,
1140 .misc_flags = OXYGEN_MISC_MIDI,
1141 .function_flags = OXYGEN_FUNCTION_2WIRE,
1142 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1143 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1146 static const struct oxygen_model model_xonar_st = {
1147 .longname = "Asus Virtuoso 100",
1149 .init = xonar_st_init,
1150 .mixer_init = xonar_st_mixer_init,
1151 .cleanup = xonar_st_cleanup,
1152 .suspend = xonar_st_suspend,
1153 .resume = xonar_st_resume,
1154 .get_i2s_mclk = get_pcm1796_i2s_mclk,
1155 .set_dac_params = set_st_params,
1156 .set_adc_params = xonar_set_cs53x1_params,
1157 .update_dac_volume = update_pcm1796_volume,
1158 .update_dac_mute = update_pcm1796_mute,
1159 .ac97_switch = xonar_line_mic_ac97_switch,
1160 .dump_registers = dump_st_registers,
1161 .dac_tlv = pcm1796_db_scale,
1162 .model_data_size = sizeof(struct xonar_pcm179x),
1163 .device_config = PLAYBACK_0_TO_I2S |
1164 PLAYBACK_1_TO_SPDIF |
1165 CAPTURE_0_FROM_I2S_2 |
1167 .dac_channels_pcm = 2,
1168 .dac_channels_mixer = 2,
1169 .dac_volume_min = 255 - 2*60,
1170 .dac_volume_max = 255,
1171 .function_flags = OXYGEN_FUNCTION_2WIRE,
1172 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1173 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1176 int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1177 const struct pci_device_id *id)
1179 switch (id->subdevice) {
1181 chip->model = model_xonar_d2;
1182 chip->model.shortname = "Xonar D2";
1185 chip->model = model_xonar_d2;
1186 chip->model.shortname = "Xonar D2X";
1187 chip->model.init = xonar_d2x_init;
1190 chip->model = model_xonar_hdav;
1191 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1192 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1194 chip->model.shortname = "Xonar HDAV1.3";
1197 chip->model.shortname = "Xonar HDAV1.3+H6";
1198 chip->model.dac_channels_mixer = 8;
1203 chip->model = model_xonar_st;
1204 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1205 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1207 chip->model.shortname = "Xonar ST";
1210 chip->model.shortname = "Xonar ST+H6";
1211 chip->model.dac_channels_pcm = 8;
1212 chip->model.dac_channels_mixer = 8;
1217 chip->model = model_xonar_st;
1218 chip->model.shortname = "Xonar STX";
1219 chip->model.init = xonar_stx_init;
1220 chip->model.resume = xonar_stx_resume;
1221 chip->model.set_dac_params = set_pcm1796_params;
1224 snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");