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 (II)
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 GPIO_XENSE_OUTPUT_ENABLE (0x0001 | 0x0010 | 0x0020)
216 #define GPIO_XENSE_SPEAKERS 0x0080
218 #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
219 #define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
221 #define PCM1796_REG_BASE 16
224 struct xonar_pcm179x
{
225 struct xonar_generic generic
;
227 u8 pcm1796_regs
[4][5];
228 unsigned int current_rate
;
233 u8 cs2000_regs
[0x1f];
238 struct xonar_pcm179x pcm179x
;
239 struct xonar_hdmi hdmi
;
243 static inline void pcm1796_write_spi(struct oxygen
*chip
, unsigned int codec
,
246 /* maps ALSA channel pair number to SPI output */
247 static const u8 codec_map
[4] = {
250 oxygen_write_spi(chip
, OXYGEN_SPI_TRIGGER
|
251 OXYGEN_SPI_DATA_LENGTH_2
|
252 OXYGEN_SPI_CLOCK_160
|
253 (codec_map
[codec
] << OXYGEN_SPI_CODEC_SHIFT
) |
254 OXYGEN_SPI_CEN_LATCH_CLOCK_HI
,
258 static inline void pcm1796_write_i2c(struct oxygen
*chip
, unsigned int codec
,
261 oxygen_write_i2c(chip
, I2C_DEVICE_PCM1796(codec
), reg
, value
);
264 static void pcm1796_write(struct oxygen
*chip
, unsigned int codec
,
267 struct xonar_pcm179x
*data
= chip
->model_data
;
269 if ((chip
->model
.function_flags
& OXYGEN_FUNCTION_2WIRE_SPI_MASK
) ==
271 pcm1796_write_spi(chip
, codec
, reg
, value
);
273 pcm1796_write_i2c(chip
, codec
, reg
, value
);
274 if ((unsigned int)(reg
- PCM1796_REG_BASE
)
275 < ARRAY_SIZE(data
->pcm1796_regs
[codec
]))
276 data
->pcm1796_regs
[codec
][reg
- PCM1796_REG_BASE
] = value
;
279 static void pcm1796_write_cached(struct oxygen
*chip
, unsigned int codec
,
282 struct xonar_pcm179x
*data
= chip
->model_data
;
284 if (value
!= data
->pcm1796_regs
[codec
][reg
- PCM1796_REG_BASE
])
285 pcm1796_write(chip
, codec
, reg
, value
);
288 static void cs2000_write(struct oxygen
*chip
, u8 reg
, u8 value
)
290 struct xonar_pcm179x
*data
= chip
->model_data
;
292 oxygen_write_i2c(chip
, I2C_DEVICE_CS2000
, reg
, value
);
293 data
->cs2000_regs
[reg
] = value
;
296 static void cs2000_write_cached(struct oxygen
*chip
, u8 reg
, u8 value
)
298 struct xonar_pcm179x
*data
= chip
->model_data
;
300 if (value
!= data
->cs2000_regs
[reg
])
301 cs2000_write(chip
, reg
, value
);
304 static void pcm1796_registers_init(struct oxygen
*chip
)
306 struct xonar_pcm179x
*data
= chip
->model_data
;
311 gain_offset
= data
->hp_active
? data
->hp_gain_offset
: 0;
312 for (i
= 0; i
< data
->dacs
; ++i
) {
313 /* set ATLD before ATL/ATR */
314 pcm1796_write(chip
, i
, 18,
315 data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
]);
316 pcm1796_write(chip
, i
, 16, chip
->dac_volume
[i
* 2]
318 pcm1796_write(chip
, i
, 17, chip
->dac_volume
[i
* 2 + 1]
320 pcm1796_write(chip
, i
, 19,
321 data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
]);
322 pcm1796_write(chip
, i
, 20,
323 data
->pcm1796_regs
[0][20 - PCM1796_REG_BASE
]);
324 pcm1796_write(chip
, i
, 21, 0);
329 static void pcm1796_init(struct oxygen
*chip
)
331 struct xonar_pcm179x
*data
= chip
->model_data
;
333 data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
] =
334 PCM1796_DMF_DISABLED
| PCM1796_FMT_24_I2S
| PCM1796_ATLD
;
335 if (!data
->broken_i2c
)
336 data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
] |= PCM1796_MUTE
;
337 data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
] =
338 PCM1796_FLT_SHARP
| PCM1796_ATS_1
;
339 data
->pcm1796_regs
[0][20 - PCM1796_REG_BASE
] =
340 data
->h6
? PCM1796_OS_64
: PCM1796_OS_128
;
341 pcm1796_registers_init(chip
);
342 data
->current_rate
= 48000;
345 static void xonar_d2_init(struct oxygen
*chip
)
347 struct xonar_pcm179x
*data
= chip
->model_data
;
349 data
->generic
.anti_pop_delay
= 300;
350 data
->generic
.output_enable_bit
= GPIO_D2_OUTPUT_ENABLE
;
355 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_D2_ALT
);
356 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_D2_ALT
);
358 oxygen_ac97_set_bits(chip
, 0, CM9780_JACK
, CM9780_FMIC2MIC
);
360 xonar_init_cs53x1(chip
);
361 xonar_enable_output(chip
);
363 snd_component_add(chip
->card
, "PCM1796");
364 snd_component_add(chip
->card
, "CS5381");
367 static void xonar_d2x_init(struct oxygen
*chip
)
369 struct xonar_pcm179x
*data
= chip
->model_data
;
371 data
->generic
.ext_power_reg
= OXYGEN_GPIO_DATA
;
372 data
->generic
.ext_power_int_reg
= OXYGEN_GPIO_INTERRUPT_MASK
;
373 data
->generic
.ext_power_bit
= GPIO_D2X_EXT_POWER
;
374 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_D2X_EXT_POWER
);
375 xonar_init_ext_power(chip
);
379 static void xonar_hdav_init(struct oxygen
*chip
)
381 struct xonar_hdav
*data
= chip
->model_data
;
383 oxygen_write16(chip
, OXYGEN_2WIRE_BUS_STATUS
,
384 OXYGEN_2WIRE_LENGTH_8
|
385 OXYGEN_2WIRE_INTERRUPT_MASK
|
386 OXYGEN_2WIRE_SPEED_STANDARD
);
388 data
->pcm179x
.generic
.anti_pop_delay
= 100;
389 data
->pcm179x
.generic
.output_enable_bit
= GPIO_HDAV_OUTPUT_ENABLE
;
390 data
->pcm179x
.generic
.ext_power_reg
= OXYGEN_GPI_DATA
;
391 data
->pcm179x
.generic
.ext_power_int_reg
= OXYGEN_GPI_INTERRUPT_MASK
;
392 data
->pcm179x
.generic
.ext_power_bit
= GPI_EXT_POWER
;
393 data
->pcm179x
.dacs
= chip
->model
.dac_channels_mixer
/ 2;
394 data
->pcm179x
.h6
= chip
->model
.dac_channels_mixer
> 2;
398 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
,
399 GPIO_HDAV_MAGIC
| GPIO_INPUT_ROUTE
);
400 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_INPUT_ROUTE
);
402 xonar_init_cs53x1(chip
);
403 xonar_init_ext_power(chip
);
404 xonar_hdmi_init(chip
, &data
->hdmi
);
405 xonar_enable_output(chip
);
407 snd_component_add(chip
->card
, "PCM1796");
408 snd_component_add(chip
->card
, "CS5381");
411 static void xonar_st_init_i2c(struct oxygen
*chip
)
413 oxygen_write16(chip
, OXYGEN_2WIRE_BUS_STATUS
,
414 OXYGEN_2WIRE_LENGTH_8
|
415 OXYGEN_2WIRE_INTERRUPT_MASK
|
416 OXYGEN_2WIRE_SPEED_STANDARD
);
419 static void xonar_st_init_common(struct oxygen
*chip
)
421 struct xonar_pcm179x
*data
= chip
->model_data
;
423 data
->generic
.output_enable_bit
= GPIO_ST_OUTPUT_ENABLE
;
424 data
->dacs
= chip
->model
.dac_channels_mixer
/ 2;
425 data
->h6
= chip
->model
.dac_channels_mixer
> 2;
426 data
->hp_gain_offset
= 2*-18;
430 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
,
431 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
|
432 GPIO_ST_MAGIC
| GPIO_ST_HP
);
433 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
,
434 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
| GPIO_ST_HP
);
436 xonar_init_cs53x1(chip
);
437 xonar_enable_output(chip
);
439 snd_component_add(chip
->card
, "PCM1792A");
440 snd_component_add(chip
->card
, "CS5381");
443 static void cs2000_registers_init(struct oxygen
*chip
)
445 struct xonar_pcm179x
*data
= chip
->model_data
;
447 cs2000_write(chip
, CS2000_GLOBAL_CFG
, CS2000_FREEZE
);
448 cs2000_write(chip
, CS2000_DEV_CTRL
, 0);
449 cs2000_write(chip
, CS2000_DEV_CFG_1
,
451 (0 << CS2000_R_SEL_SHIFT
) |
452 CS2000_AUX_OUT_SRC_REF_CLK
|
453 CS2000_EN_DEV_CFG_1
);
454 cs2000_write(chip
, CS2000_DEV_CFG_2
,
455 (0 << CS2000_LOCK_CLK_SHIFT
) |
456 CS2000_FRAC_N_SRC_STATIC
);
457 cs2000_write(chip
, CS2000_RATIO_0
+ 0, 0x00); /* 1.0 */
458 cs2000_write(chip
, CS2000_RATIO_0
+ 1, 0x10);
459 cs2000_write(chip
, CS2000_RATIO_0
+ 2, 0x00);
460 cs2000_write(chip
, CS2000_RATIO_0
+ 3, 0x00);
461 cs2000_write(chip
, CS2000_FUN_CFG_1
,
462 data
->cs2000_regs
[CS2000_FUN_CFG_1
]);
463 cs2000_write(chip
, CS2000_FUN_CFG_2
, 0);
464 cs2000_write(chip
, CS2000_GLOBAL_CFG
, CS2000_EN_DEV_CFG_2
);
465 msleep(3); /* PLL lock delay */
468 static void xonar_st_init(struct oxygen
*chip
)
470 struct xonar_pcm179x
*data
= chip
->model_data
;
472 data
->generic
.anti_pop_delay
= 100;
473 data
->h6
= chip
->model
.dac_channels_mixer
> 2;
474 data
->has_cs2000
= 1;
475 data
->cs2000_regs
[CS2000_FUN_CFG_1
] = CS2000_REF_CLK_DIV_1
;
476 data
->broken_i2c
= true;
478 oxygen_write16(chip
, OXYGEN_I2S_A_FORMAT
,
480 OXYGEN_I2S_FORMAT_I2S
|
481 OXYGEN_I2S_MCLK(data
->h6
? MCLK_256
: MCLK_512
) |
486 xonar_st_init_i2c(chip
);
487 cs2000_registers_init(chip
);
488 xonar_st_init_common(chip
);
490 snd_component_add(chip
->card
, "CS2000");
493 static void xonar_stx_init(struct oxygen
*chip
)
495 struct xonar_pcm179x
*data
= chip
->model_data
;
497 xonar_st_init_i2c(chip
);
498 data
->generic
.anti_pop_delay
= 800;
499 data
->generic
.ext_power_reg
= OXYGEN_GPI_DATA
;
500 data
->generic
.ext_power_int_reg
= OXYGEN_GPI_INTERRUPT_MASK
;
501 data
->generic
.ext_power_bit
= GPI_EXT_POWER
;
502 xonar_init_ext_power(chip
);
503 xonar_st_init_common(chip
);
506 static void xonar_xense_init(struct oxygen
*chip
)
508 struct xonar_pcm179x
*data
= chip
->model_data
;
510 data
->generic
.ext_power_reg
= OXYGEN_GPI_DATA
;
511 data
->generic
.ext_power_int_reg
= OXYGEN_GPI_INTERRUPT_MASK
;
512 data
->generic
.ext_power_bit
= GPI_EXT_POWER
;
513 xonar_init_ext_power(chip
);
515 data
->generic
.anti_pop_delay
= 100;
516 data
->has_cs2000
= 1;
517 data
->cs2000_regs
[CS2000_FUN_CFG_1
] = CS2000_REF_CLK_DIV_1
;
519 oxygen_write16(chip
, OXYGEN_I2S_A_FORMAT
,
521 OXYGEN_I2S_FORMAT_I2S
|
522 OXYGEN_I2S_MCLK(MCLK_512
) |
527 xonar_st_init_i2c(chip
);
528 cs2000_registers_init(chip
);
530 data
->generic
.output_enable_bit
= GPIO_XENSE_OUTPUT_ENABLE
;
532 data
->hp_gain_offset
= 2*-18;
536 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
,
537 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
|
538 GPIO_ST_MAGIC
| GPIO_XENSE_SPEAKERS
);
539 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
,
540 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
|
541 GPIO_XENSE_SPEAKERS
);
543 xonar_init_cs53x1(chip
);
544 xonar_enable_output(chip
);
546 snd_component_add(chip
->card
, "PCM1796");
547 snd_component_add(chip
->card
, "CS5381");
548 snd_component_add(chip
->card
, "CS2000");
551 static void xonar_d2_cleanup(struct oxygen
*chip
)
553 xonar_disable_output(chip
);
556 static void xonar_hdav_cleanup(struct oxygen
*chip
)
558 xonar_hdmi_cleanup(chip
);
559 xonar_disable_output(chip
);
563 static void xonar_st_cleanup(struct oxygen
*chip
)
565 xonar_disable_output(chip
);
568 static void xonar_d2_suspend(struct oxygen
*chip
)
570 xonar_d2_cleanup(chip
);
573 static void xonar_hdav_suspend(struct oxygen
*chip
)
575 xonar_hdav_cleanup(chip
);
578 static void xonar_st_suspend(struct oxygen
*chip
)
580 xonar_st_cleanup(chip
);
583 static void xonar_d2_resume(struct oxygen
*chip
)
585 pcm1796_registers_init(chip
);
586 xonar_enable_output(chip
);
589 static void xonar_hdav_resume(struct oxygen
*chip
)
591 struct xonar_hdav
*data
= chip
->model_data
;
593 pcm1796_registers_init(chip
);
594 xonar_hdmi_resume(chip
, &data
->hdmi
);
595 xonar_enable_output(chip
);
598 static void xonar_stx_resume(struct oxygen
*chip
)
600 pcm1796_registers_init(chip
);
601 xonar_enable_output(chip
);
604 static void xonar_st_resume(struct oxygen
*chip
)
606 cs2000_registers_init(chip
);
607 xonar_stx_resume(chip
);
610 static void update_pcm1796_oversampling(struct oxygen
*chip
)
612 struct xonar_pcm179x
*data
= chip
->model_data
;
616 if (data
->current_rate
<= 48000 && !data
->h6
)
617 reg
= PCM1796_OS_128
;
620 for (i
= 0; i
< data
->dacs
; ++i
)
621 pcm1796_write_cached(chip
, i
, 20, reg
);
624 static void set_pcm1796_params(struct oxygen
*chip
,
625 struct snd_pcm_hw_params
*params
)
627 struct xonar_pcm179x
*data
= chip
->model_data
;
630 data
->current_rate
= params_rate(params
);
631 update_pcm1796_oversampling(chip
);
634 static void update_pcm1796_volume(struct oxygen
*chip
)
636 struct xonar_pcm179x
*data
= chip
->model_data
;
640 gain_offset
= data
->hp_active
? data
->hp_gain_offset
: 0;
641 for (i
= 0; i
< data
->dacs
; ++i
) {
642 pcm1796_write_cached(chip
, i
, 16, chip
->dac_volume
[i
* 2]
644 pcm1796_write_cached(chip
, i
, 17, chip
->dac_volume
[i
* 2 + 1]
650 static void update_pcm1796_mute(struct oxygen
*chip
)
652 struct xonar_pcm179x
*data
= chip
->model_data
;
656 value
= PCM1796_DMF_DISABLED
| PCM1796_FMT_24_I2S
| PCM1796_ATLD
;
658 value
|= PCM1796_MUTE
;
659 for (i
= 0; i
< data
->dacs
; ++i
)
660 pcm1796_write_cached(chip
, i
, 18, value
);
663 static void update_cs2000_rate(struct oxygen
*chip
, unsigned int rate
)
665 struct xonar_pcm179x
*data
= chip
->model_data
;
671 rate_mclk
= OXYGEN_RATE_32000
;
676 rate_mclk
= OXYGEN_RATE_44100
;
682 rate_mclk
= OXYGEN_RATE_48000
;
686 if (rate
<= 96000 && (rate
> 48000 || data
->h6
)) {
687 rate_mclk
|= OXYGEN_I2S_MCLK(MCLK_256
);
688 reg
= CS2000_REF_CLK_DIV_1
;
690 rate_mclk
|= OXYGEN_I2S_MCLK(MCLK_512
);
691 reg
= CS2000_REF_CLK_DIV_2
;
694 oxygen_write16_masked(chip
, OXYGEN_I2S_A_FORMAT
, rate_mclk
,
695 OXYGEN_I2S_RATE_MASK
| OXYGEN_I2S_MCLK_MASK
);
696 cs2000_write_cached(chip
, CS2000_FUN_CFG_1
, reg
);
697 msleep(3); /* PLL lock delay */
700 static void set_st_params(struct oxygen
*chip
,
701 struct snd_pcm_hw_params
*params
)
703 update_cs2000_rate(chip
, params_rate(params
));
704 set_pcm1796_params(chip
, params
);
707 static void set_hdav_params(struct oxygen
*chip
,
708 struct snd_pcm_hw_params
*params
)
710 struct xonar_hdav
*data
= chip
->model_data
;
712 set_pcm1796_params(chip
, params
);
713 xonar_set_hdmi_params(chip
, &data
->hdmi
, params
);
716 static const struct snd_kcontrol_new alt_switch
= {
717 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
718 .name
= "Analog Loopback Switch",
719 .info
= snd_ctl_boolean_mono_info
,
720 .get
= xonar_gpio_bit_switch_get
,
721 .put
= xonar_gpio_bit_switch_put
,
722 .private_value
= GPIO_D2_ALT
,
725 static int rolloff_info(struct snd_kcontrol
*ctl
,
726 struct snd_ctl_elem_info
*info
)
728 static const char *const names
[2] = {
729 "Sharp Roll-off", "Slow Roll-off"
732 return snd_ctl_enum_info(info
, 1, 2, names
);
735 static int rolloff_get(struct snd_kcontrol
*ctl
,
736 struct snd_ctl_elem_value
*value
)
738 struct oxygen
*chip
= ctl
->private_data
;
739 struct xonar_pcm179x
*data
= chip
->model_data
;
741 value
->value
.enumerated
.item
[0] =
742 (data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
] &
743 PCM1796_FLT_MASK
) != PCM1796_FLT_SHARP
;
747 static int rolloff_put(struct snd_kcontrol
*ctl
,
748 struct snd_ctl_elem_value
*value
)
750 struct oxygen
*chip
= ctl
->private_data
;
751 struct xonar_pcm179x
*data
= chip
->model_data
;
756 mutex_lock(&chip
->mutex
);
757 reg
= data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
];
758 reg
&= ~PCM1796_FLT_MASK
;
759 if (!value
->value
.enumerated
.item
[0])
760 reg
|= PCM1796_FLT_SHARP
;
762 reg
|= PCM1796_FLT_SLOW
;
763 changed
= reg
!= data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
];
765 for (i
= 0; i
< data
->dacs
; ++i
)
766 pcm1796_write(chip
, i
, 19, reg
);
768 mutex_unlock(&chip
->mutex
);
772 static const struct snd_kcontrol_new rolloff_control
= {
773 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
774 .name
= "DAC Filter Playback Enum",
775 .info
= rolloff_info
,
780 static const struct snd_kcontrol_new hdav_hdmi_control
= {
781 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
782 .name
= "HDMI Playback Switch",
783 .info
= snd_ctl_boolean_mono_info
,
784 .get
= xonar_gpio_bit_switch_get
,
785 .put
= xonar_gpio_bit_switch_put
,
786 .private_value
= GPIO_HDAV_OUTPUT_ENABLE
| XONAR_GPIO_BIT_INVERT
,
789 static int st_output_switch_info(struct snd_kcontrol
*ctl
,
790 struct snd_ctl_elem_info
*info
)
792 static const char *const names
[3] = {
793 "Speakers", "Headphones", "FP Headphones"
796 return snd_ctl_enum_info(info
, 1, 3, names
);
799 static int st_output_switch_get(struct snd_kcontrol
*ctl
,
800 struct snd_ctl_elem_value
*value
)
802 struct oxygen
*chip
= ctl
->private_data
;
805 gpio
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
806 if (!(gpio
& GPIO_ST_HP
))
807 value
->value
.enumerated
.item
[0] = 0;
808 else if (gpio
& GPIO_ST_HP_REAR
)
809 value
->value
.enumerated
.item
[0] = 1;
811 value
->value
.enumerated
.item
[0] = 2;
816 static int st_output_switch_put(struct snd_kcontrol
*ctl
,
817 struct snd_ctl_elem_value
*value
)
819 struct oxygen
*chip
= ctl
->private_data
;
820 struct xonar_pcm179x
*data
= chip
->model_data
;
823 mutex_lock(&chip
->mutex
);
824 gpio_old
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
826 switch (value
->value
.enumerated
.item
[0]) {
828 gpio
&= ~(GPIO_ST_HP
| GPIO_ST_HP_REAR
);
831 gpio
|= GPIO_ST_HP
| GPIO_ST_HP_REAR
;
834 gpio
= (gpio
| GPIO_ST_HP
) & ~GPIO_ST_HP_REAR
;
837 oxygen_write16(chip
, OXYGEN_GPIO_DATA
, gpio
);
838 data
->hp_active
= gpio
& GPIO_ST_HP
;
839 update_pcm1796_volume(chip
);
840 mutex_unlock(&chip
->mutex
);
841 return gpio
!= gpio_old
;
844 static int st_hp_volume_offset_info(struct snd_kcontrol
*ctl
,
845 struct snd_ctl_elem_info
*info
)
847 static const char *const names
[4] = {
848 "< 32 ohms", "32-64 ohms", "64-300 ohms", "300-600 ohms"
851 return snd_ctl_enum_info(info
, 1, 4, names
);
854 static int st_hp_volume_offset_get(struct snd_kcontrol
*ctl
,
855 struct snd_ctl_elem_value
*value
)
857 struct oxygen
*chip
= ctl
->private_data
;
858 struct xonar_pcm179x
*data
= chip
->model_data
;
860 mutex_lock(&chip
->mutex
);
861 if (data
->hp_gain_offset
< 2*-12)
862 value
->value
.enumerated
.item
[0] = 0;
863 else if (data
->hp_gain_offset
< 2*-6)
864 value
->value
.enumerated
.item
[0] = 1;
865 else if (data
->hp_gain_offset
< 0)
866 value
->value
.enumerated
.item
[0] = 2;
868 value
->value
.enumerated
.item
[0] = 3;
869 mutex_unlock(&chip
->mutex
);
874 static int st_hp_volume_offset_put(struct snd_kcontrol
*ctl
,
875 struct snd_ctl_elem_value
*value
)
877 static const s8 offsets
[] = { 2*-18, 2*-12, 2*-6, 0 };
878 struct oxygen
*chip
= ctl
->private_data
;
879 struct xonar_pcm179x
*data
= chip
->model_data
;
883 if (value
->value
.enumerated
.item
[0] > 3)
885 offset
= offsets
[value
->value
.enumerated
.item
[0]];
886 mutex_lock(&chip
->mutex
);
887 changed
= offset
!= data
->hp_gain_offset
;
889 data
->hp_gain_offset
= offset
;
890 update_pcm1796_volume(chip
);
892 mutex_unlock(&chip
->mutex
);
896 static const struct snd_kcontrol_new st_controls
[] = {
898 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
899 .name
= "Analog Output",
900 .info
= st_output_switch_info
,
901 .get
= st_output_switch_get
,
902 .put
= st_output_switch_put
,
905 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
906 .name
= "Headphones Impedance Playback Enum",
907 .info
= st_hp_volume_offset_info
,
908 .get
= st_hp_volume_offset_get
,
909 .put
= st_hp_volume_offset_put
,
913 static int xense_output_switch_get(struct snd_kcontrol
*ctl
,
914 struct snd_ctl_elem_value
*value
)
916 struct oxygen
*chip
= ctl
->private_data
;
919 gpio
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
920 if (gpio
& GPIO_XENSE_SPEAKERS
)
921 value
->value
.enumerated
.item
[0] = 0;
922 else if (!(gpio
& GPIO_XENSE_SPEAKERS
) && (gpio
& GPIO_ST_HP_REAR
))
923 value
->value
.enumerated
.item
[0] = 1;
925 value
->value
.enumerated
.item
[0] = 2;
929 static int xense_output_switch_put(struct snd_kcontrol
*ctl
,
930 struct snd_ctl_elem_value
*value
)
932 struct oxygen
*chip
= ctl
->private_data
;
933 struct xonar_pcm179x
*data
= chip
->model_data
;
936 mutex_lock(&chip
->mutex
);
937 gpio_old
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
939 switch (value
->value
.enumerated
.item
[0]) {
941 gpio
|= GPIO_XENSE_SPEAKERS
| GPIO_ST_HP_REAR
;
944 gpio
= (gpio
| GPIO_ST_HP_REAR
) & ~GPIO_XENSE_SPEAKERS
;
947 gpio
&= ~(GPIO_XENSE_SPEAKERS
| GPIO_ST_HP_REAR
);
950 oxygen_write16(chip
, OXYGEN_GPIO_DATA
, gpio
);
951 data
->hp_active
= !(gpio
& GPIO_XENSE_SPEAKERS
);
952 update_pcm1796_volume(chip
);
953 mutex_unlock(&chip
->mutex
);
954 return gpio
!= gpio_old
;
957 static const struct snd_kcontrol_new xense_controls
[] = {
959 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
960 .name
= "Analog Output",
961 .info
= st_output_switch_info
,
962 .get
= xense_output_switch_get
,
963 .put
= xense_output_switch_put
,
966 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
967 .name
= "Headphones Impedance Playback Enum",
968 .info
= st_hp_volume_offset_info
,
969 .get
= st_hp_volume_offset_get
,
970 .put
= st_hp_volume_offset_put
,
974 static void xonar_line_mic_ac97_switch(struct oxygen
*chip
,
975 unsigned int reg
, unsigned int mute
)
977 if (reg
== AC97_LINE
) {
978 spin_lock_irq(&chip
->reg_lock
);
979 oxygen_write16_masked(chip
, OXYGEN_GPIO_DATA
,
980 mute
? GPIO_INPUT_ROUTE
: 0,
982 spin_unlock_irq(&chip
->reg_lock
);
986 static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale
, -6000, 50, 0);
988 static int xonar_d2_control_filter(struct snd_kcontrol_new
*template)
990 if (!strncmp(template->name
, "CD Capture ", 11))
991 /* CD in is actually connected to the video in pin */
992 template->private_value
^= AC97_CD
^ AC97_VIDEO
;
996 static int xonar_st_h6_control_filter(struct snd_kcontrol_new
*template)
998 if (!strncmp(template->name
, "Master Playback ", 16))
999 /* no volume/mute, as I²C to the third DAC does not work */
1004 static int add_pcm1796_controls(struct oxygen
*chip
)
1006 struct xonar_pcm179x
*data
= chip
->model_data
;
1009 if (!data
->broken_i2c
) {
1010 err
= snd_ctl_add(chip
->card
,
1011 snd_ctl_new1(&rolloff_control
, chip
));
1018 static int xonar_d2_mixer_init(struct oxygen
*chip
)
1022 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&alt_switch
, chip
));
1025 err
= add_pcm1796_controls(chip
);
1031 static int xonar_hdav_mixer_init(struct oxygen
*chip
)
1035 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&hdav_hdmi_control
, chip
));
1038 err
= add_pcm1796_controls(chip
);
1044 static int xonar_st_mixer_init(struct oxygen
*chip
)
1049 for (i
= 0; i
< ARRAY_SIZE(st_controls
); ++i
) {
1050 err
= snd_ctl_add(chip
->card
,
1051 snd_ctl_new1(&st_controls
[i
], chip
));
1055 err
= add_pcm1796_controls(chip
);
1061 static int xonar_xense_mixer_init(struct oxygen
*chip
)
1066 for (i
= 0; i
< ARRAY_SIZE(xense_controls
); ++i
) {
1067 err
= snd_ctl_add(chip
->card
,
1068 snd_ctl_new1(&xense_controls
[i
], chip
));
1072 err
= add_pcm1796_controls(chip
);
1078 static void dump_pcm1796_registers(struct oxygen
*chip
,
1079 struct snd_info_buffer
*buffer
)
1081 struct xonar_pcm179x
*data
= chip
->model_data
;
1082 unsigned int dac
, i
;
1084 for (dac
= 0; dac
< data
->dacs
; ++dac
) {
1085 snd_iprintf(buffer
, "\nPCM1796 %u:", dac
+ 1);
1086 for (i
= 0; i
< 5; ++i
)
1087 snd_iprintf(buffer
, " %02x",
1088 data
->pcm1796_regs
[dac
][i
]);
1090 snd_iprintf(buffer
, "\n");
1093 static void dump_cs2000_registers(struct oxygen
*chip
,
1094 struct snd_info_buffer
*buffer
)
1096 struct xonar_pcm179x
*data
= chip
->model_data
;
1099 if (data
->has_cs2000
) {
1100 snd_iprintf(buffer
, "\nCS2000:\n00: ");
1101 for (i
= 1; i
< 0x10; ++i
)
1102 snd_iprintf(buffer
, " %02x", data
->cs2000_regs
[i
]);
1103 snd_iprintf(buffer
, "\n10:");
1104 for (i
= 0x10; i
< 0x1f; ++i
)
1105 snd_iprintf(buffer
, " %02x", data
->cs2000_regs
[i
]);
1106 snd_iprintf(buffer
, "\n");
1110 static void dump_st_registers(struct oxygen
*chip
,
1111 struct snd_info_buffer
*buffer
)
1113 dump_pcm1796_registers(chip
, buffer
);
1114 dump_cs2000_registers(chip
, buffer
);
1117 static const struct oxygen_model model_xonar_d2
= {
1118 .longname
= "Asus Virtuoso 200",
1120 .init
= xonar_d2_init
,
1121 .control_filter
= xonar_d2_control_filter
,
1122 .mixer_init
= xonar_d2_mixer_init
,
1123 .cleanup
= xonar_d2_cleanup
,
1124 .suspend
= xonar_d2_suspend
,
1125 .resume
= xonar_d2_resume
,
1126 .set_dac_params
= set_pcm1796_params
,
1127 .set_adc_params
= xonar_set_cs53x1_params
,
1128 .update_dac_volume
= update_pcm1796_volume
,
1129 .update_dac_mute
= update_pcm1796_mute
,
1130 .dump_registers
= dump_pcm1796_registers
,
1131 .dac_tlv
= pcm1796_db_scale
,
1132 .model_data_size
= sizeof(struct xonar_pcm179x
),
1133 .device_config
= PLAYBACK_0_TO_I2S
|
1134 PLAYBACK_1_TO_SPDIF
|
1135 CAPTURE_0_FROM_I2S_2
|
1136 CAPTURE_1_FROM_SPDIF
|
1140 .dac_channels_pcm
= 8,
1141 .dac_channels_mixer
= 8,
1142 .dac_volume_min
= 255 - 2*60,
1143 .dac_volume_max
= 255,
1144 .misc_flags
= OXYGEN_MISC_MIDI
,
1145 .function_flags
= OXYGEN_FUNCTION_SPI
|
1146 OXYGEN_FUNCTION_ENABLE_SPI_4_5
,
1147 .dac_mclks
= OXYGEN_MCLKS(512, 128, 128),
1148 .adc_mclks
= OXYGEN_MCLKS(256, 128, 128),
1149 .dac_i2s_format
= OXYGEN_I2S_FORMAT_I2S
,
1150 .adc_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
1153 static const struct oxygen_model model_xonar_hdav
= {
1154 .longname
= "Asus Virtuoso 200",
1156 .init
= xonar_hdav_init
,
1157 .mixer_init
= xonar_hdav_mixer_init
,
1158 .cleanup
= xonar_hdav_cleanup
,
1159 .suspend
= xonar_hdav_suspend
,
1160 .resume
= xonar_hdav_resume
,
1161 .pcm_hardware_filter
= xonar_hdmi_pcm_hardware_filter
,
1162 .set_dac_params
= set_hdav_params
,
1163 .set_adc_params
= xonar_set_cs53x1_params
,
1164 .update_dac_volume
= update_pcm1796_volume
,
1165 .update_dac_mute
= update_pcm1796_mute
,
1166 .uart_input
= xonar_hdmi_uart_input
,
1167 .ac97_switch
= xonar_line_mic_ac97_switch
,
1168 .dump_registers
= dump_pcm1796_registers
,
1169 .dac_tlv
= pcm1796_db_scale
,
1170 .model_data_size
= sizeof(struct xonar_hdav
),
1171 .device_config
= PLAYBACK_0_TO_I2S
|
1172 PLAYBACK_1_TO_SPDIF
|
1173 CAPTURE_0_FROM_I2S_2
|
1174 CAPTURE_1_FROM_SPDIF
,
1175 .dac_channels_pcm
= 8,
1176 .dac_channels_mixer
= 2,
1177 .dac_volume_min
= 255 - 2*60,
1178 .dac_volume_max
= 255,
1179 .misc_flags
= OXYGEN_MISC_MIDI
,
1180 .function_flags
= OXYGEN_FUNCTION_2WIRE
,
1181 .dac_mclks
= OXYGEN_MCLKS(512, 128, 128),
1182 .adc_mclks
= OXYGEN_MCLKS(256, 128, 128),
1183 .dac_i2s_format
= OXYGEN_I2S_FORMAT_I2S
,
1184 .adc_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
1187 static const struct oxygen_model model_xonar_st
= {
1188 .longname
= "Asus Virtuoso 100",
1190 .init
= xonar_st_init
,
1191 .mixer_init
= xonar_st_mixer_init
,
1192 .cleanup
= xonar_st_cleanup
,
1193 .suspend
= xonar_st_suspend
,
1194 .resume
= xonar_st_resume
,
1195 .set_dac_params
= set_st_params
,
1196 .set_adc_params
= xonar_set_cs53x1_params
,
1197 .update_dac_volume
= update_pcm1796_volume
,
1198 .update_dac_mute
= update_pcm1796_mute
,
1199 .ac97_switch
= xonar_line_mic_ac97_switch
,
1200 .dump_registers
= dump_st_registers
,
1201 .dac_tlv
= pcm1796_db_scale
,
1202 .model_data_size
= sizeof(struct xonar_pcm179x
),
1203 .device_config
= PLAYBACK_0_TO_I2S
|
1204 PLAYBACK_1_TO_SPDIF
|
1205 CAPTURE_0_FROM_I2S_2
|
1206 CAPTURE_1_FROM_SPDIF
|
1208 .dac_channels_pcm
= 2,
1209 .dac_channels_mixer
= 2,
1210 .dac_volume_min
= 255 - 2*60,
1211 .dac_volume_max
= 255,
1212 .function_flags
= OXYGEN_FUNCTION_2WIRE
,
1213 .dac_mclks
= OXYGEN_MCLKS(512, 128, 128),
1214 .adc_mclks
= OXYGEN_MCLKS(256, 128, 128),
1215 .dac_i2s_format
= OXYGEN_I2S_FORMAT_I2S
,
1216 .adc_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
1219 int get_xonar_pcm179x_model(struct oxygen
*chip
,
1220 const struct pci_device_id
*id
)
1222 switch (id
->subdevice
) {
1224 chip
->model
= model_xonar_d2
;
1225 chip
->model
.shortname
= "Xonar D2";
1228 chip
->model
= model_xonar_d2
;
1229 chip
->model
.shortname
= "Xonar D2X";
1230 chip
->model
.init
= xonar_d2x_init
;
1233 chip
->model
= model_xonar_hdav
;
1234 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_DB_MASK
);
1235 switch (oxygen_read16(chip
, OXYGEN_GPIO_DATA
) & GPIO_DB_MASK
) {
1237 chip
->model
.shortname
= "Xonar HDAV1.3";
1240 chip
->model
.shortname
= "Xonar HDAV1.3+H6";
1241 chip
->model
.dac_channels_mixer
= 8;
1242 chip
->model
.dac_mclks
= OXYGEN_MCLKS(256, 128, 128);
1247 chip
->model
= model_xonar_st
;
1248 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_DB_MASK
);
1249 switch (oxygen_read16(chip
, OXYGEN_GPIO_DATA
) & GPIO_DB_MASK
) {
1251 chip
->model
.shortname
= "Xonar ST";
1254 chip
->model
.shortname
= "Xonar ST+H6";
1255 chip
->model
.control_filter
= xonar_st_h6_control_filter
;
1256 chip
->model
.dac_channels_pcm
= 8;
1257 chip
->model
.dac_channels_mixer
= 8;
1258 chip
->model
.dac_volume_min
= 255;
1259 chip
->model
.dac_mclks
= OXYGEN_MCLKS(256, 128, 128);
1264 chip
->model
= model_xonar_st
;
1265 chip
->model
.shortname
= "Xonar STX";
1266 chip
->model
.init
= xonar_stx_init
;
1267 chip
->model
.resume
= xonar_stx_resume
;
1268 chip
->model
.set_dac_params
= set_pcm1796_params
;
1271 chip
->model
= model_xonar_st
;
1272 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_DB_MASK
);
1273 switch (oxygen_read16(chip
, OXYGEN_GPIO_DATA
) & GPIO_DB_MASK
) {
1275 chip
->model
.shortname
= "Xonar STX II";
1278 chip
->model
.shortname
= "Xonar STX II+H6";
1279 chip
->model
.dac_channels_pcm
= 8;
1280 chip
->model
.dac_channels_mixer
= 8;
1281 chip
->model
.dac_mclks
= OXYGEN_MCLKS(256, 128, 128);
1284 chip
->model
.init
= xonar_stx_init
;
1285 chip
->model
.resume
= xonar_stx_resume
;
1286 chip
->model
.set_dac_params
= set_pcm1796_params
;
1289 chip
->model
= model_xonar_st
;
1290 chip
->model
.shortname
= "Xonar Xense";
1291 chip
->model
.chip
= "AV100";
1292 chip
->model
.init
= xonar_xense_init
;
1293 chip
->model
.mixer_init
= xonar_xense_mixer_init
;