1 // SPDX-License-Identifier: GPL-2.0-only
3 * card driver for models with PCM1796 DACs (Xonar D2/D2X/HDAV1.3/ST/STX)
5 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
14 * SPI 0 -> 1st PCM1796 (front)
15 * SPI 1 -> 2nd PCM1796 (surround)
16 * SPI 2 -> 3rd PCM1796 (center/LFE)
17 * SPI 4 -> 4th PCM1796 (back)
19 * GPIO 2 -> M0 of CS5381
20 * GPIO 3 -> M1 of CS5381
21 * GPIO 5 <- external power present (D2X only)
23 * GPIO 8 -> enable output to speakers
27 * LINE_OUT -> input of ADC
33 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
37 * Xonar HDAV1.3 (Deluxe)
38 * ----------------------
42 * I²C <-> PCM1796 (addr 1001100) (front)
44 * GPI 0 <- external power present
46 * GPIO 0 -> enable HDMI (0) or speaker (1) output
47 * GPIO 2 -> M0 of CS5381
48 * GPIO 3 -> M1 of CS5381
49 * GPIO 4 <- daughterboard detection
50 * GPIO 5 <- daughterboard detection
53 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
55 * UART <-> HDMI controller
59 * LINE_OUT -> input of ADC
65 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
78 * I²C <-> PCM1796 (addr 1001101) (surround)
79 * <-> PCM1796 (addr 1001110) (center/LFE)
80 * <-> PCM1796 (addr 1001111) (back)
82 * unknown daughterboard
83 * ---------------------
88 * I²C <-> CS4362A (addr 0011000) (surround, center/LFE, back)
92 * Xonar Essence ST (Deluxe)/STX (II)
93 * ----------------------------------
97 * I²C <-> PCM1792A (addr 1001100)
98 * <-> CS2000 (addr 1001110) (ST only)
100 * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
102 * GPI 0 <- external power present (STX only)
104 * GPIO 0 -> enable output to speakers
105 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
106 * GPIO 2 -> M0 of CS5381
107 * GPIO 3 -> M1 of CS5381
108 * GPIO 4 <- daughterboard detection
109 * GPIO 5 <- daughterboard detection
111 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
112 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
116 * SCK <- CLK_OUT of CS2000 (ST only)
120 * LINE_OUT -> input of ADC
125 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
140 * I²C <-> PCM1796 (addr 1001100) (front)
141 * <-> CS4362A (addr 0011000) (surround, center/LFE, back)
142 * <-> CS2000 (addr 1001110)
144 * ADC1 MCLK -> REF_CLK of CS2000
146 * GPI 0 <- external power present
148 * GPIO 0 -> enable output
149 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
150 * GPIO 2 -> M0 of CS5381
151 * GPIO 3 -> M1 of CS5381
152 * GPIO 4 -> enable output
153 * GPIO 5 -> enable output
155 * GPIO 7 -> route output to HP (0) or speaker (1)
156 * GPIO 8 -> route input jack to mic-in (0) or line-in (1)
160 * LINE_OUT -> input of ADC
166 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
167 * GPO 1 -> route mic-in from input jack (0) or front panel header (1)
170 #include <linux/pci.h>
171 #include <linux/delay.h>
172 #include <linux/mutex.h>
173 #include <sound/ac97_codec.h>
174 #include <sound/control.h>
175 #include <sound/core.h>
176 #include <sound/info.h>
177 #include <sound/pcm.h>
178 #include <sound/pcm_params.h>
179 #include <sound/tlv.h>
186 #define GPIO_D2X_EXT_POWER 0x0020
187 #define GPIO_D2_ALT 0x0080
188 #define GPIO_D2_OUTPUT_ENABLE 0x0100
190 #define GPI_EXT_POWER 0x01
191 #define GPIO_INPUT_ROUTE 0x0100
193 #define GPIO_HDAV_OUTPUT_ENABLE 0x0001
194 #define GPIO_HDAV_MAGIC 0x00c0
196 #define GPIO_DB_MASK 0x0030
197 #define GPIO_DB_H6 0x0000
199 #define GPIO_ST_OUTPUT_ENABLE 0x0001
200 #define GPIO_ST_HP_REAR 0x0002
201 #define GPIO_ST_MAGIC 0x0040
202 #define GPIO_ST_HP 0x0080
204 #define GPIO_XENSE_OUTPUT_ENABLE (0x0001 | 0x0010 | 0x0020)
205 #define GPIO_XENSE_SPEAKERS 0x0080
207 #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
208 #define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
210 #define PCM1796_REG_BASE 16
213 struct xonar_pcm179x
{
214 struct xonar_generic generic
;
216 u8 pcm1796_regs
[4][5];
217 unsigned int current_rate
;
222 u8 cs2000_regs
[0x1f];
227 struct xonar_pcm179x pcm179x
;
228 struct xonar_hdmi hdmi
;
232 static inline void pcm1796_write_spi(struct oxygen
*chip
, unsigned int codec
,
235 /* maps ALSA channel pair number to SPI output */
236 static const u8 codec_map
[4] = {
239 oxygen_write_spi(chip
, OXYGEN_SPI_TRIGGER
|
240 OXYGEN_SPI_DATA_LENGTH_2
|
241 OXYGEN_SPI_CLOCK_160
|
242 (codec_map
[codec
] << OXYGEN_SPI_CODEC_SHIFT
) |
243 OXYGEN_SPI_CEN_LATCH_CLOCK_HI
,
247 static inline void pcm1796_write_i2c(struct oxygen
*chip
, unsigned int codec
,
250 oxygen_write_i2c(chip
, I2C_DEVICE_PCM1796(codec
), reg
, value
);
253 static void pcm1796_write(struct oxygen
*chip
, unsigned int codec
,
256 struct xonar_pcm179x
*data
= chip
->model_data
;
258 if ((chip
->model
.function_flags
& OXYGEN_FUNCTION_2WIRE_SPI_MASK
) ==
260 pcm1796_write_spi(chip
, codec
, reg
, value
);
262 pcm1796_write_i2c(chip
, codec
, reg
, value
);
263 if ((unsigned int)(reg
- PCM1796_REG_BASE
)
264 < ARRAY_SIZE(data
->pcm1796_regs
[codec
]))
265 data
->pcm1796_regs
[codec
][reg
- PCM1796_REG_BASE
] = value
;
268 static void pcm1796_write_cached(struct oxygen
*chip
, unsigned int codec
,
271 struct xonar_pcm179x
*data
= chip
->model_data
;
273 if (value
!= data
->pcm1796_regs
[codec
][reg
- PCM1796_REG_BASE
])
274 pcm1796_write(chip
, codec
, reg
, value
);
277 static void cs2000_write(struct oxygen
*chip
, u8 reg
, u8 value
)
279 struct xonar_pcm179x
*data
= chip
->model_data
;
281 oxygen_write_i2c(chip
, I2C_DEVICE_CS2000
, reg
, value
);
282 data
->cs2000_regs
[reg
] = value
;
285 static void cs2000_write_cached(struct oxygen
*chip
, u8 reg
, u8 value
)
287 struct xonar_pcm179x
*data
= chip
->model_data
;
289 if (value
!= data
->cs2000_regs
[reg
])
290 cs2000_write(chip
, reg
, value
);
293 static void pcm1796_registers_init(struct oxygen
*chip
)
295 struct xonar_pcm179x
*data
= chip
->model_data
;
300 gain_offset
= data
->hp_active
? data
->hp_gain_offset
: 0;
301 for (i
= 0; i
< data
->dacs
; ++i
) {
302 /* set ATLD before ATL/ATR */
303 pcm1796_write(chip
, i
, 18,
304 data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
]);
305 pcm1796_write(chip
, i
, 16, chip
->dac_volume
[i
* 2]
307 pcm1796_write(chip
, i
, 17, chip
->dac_volume
[i
* 2 + 1]
309 pcm1796_write(chip
, i
, 19,
310 data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
]);
311 pcm1796_write(chip
, i
, 20,
312 data
->pcm1796_regs
[0][20 - PCM1796_REG_BASE
]);
313 pcm1796_write(chip
, i
, 21, 0);
318 static void pcm1796_init(struct oxygen
*chip
)
320 struct xonar_pcm179x
*data
= chip
->model_data
;
322 data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
] =
323 PCM1796_FMT_24_I2S
| PCM1796_ATLD
;
324 if (!data
->broken_i2c
)
325 data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
] |= PCM1796_MUTE
;
326 data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
] =
327 PCM1796_FLT_SHARP
| PCM1796_ATS_1
;
328 data
->pcm1796_regs
[0][20 - PCM1796_REG_BASE
] =
329 data
->h6
? PCM1796_OS_64
: PCM1796_OS_128
;
330 pcm1796_registers_init(chip
);
331 data
->current_rate
= 48000;
334 static void xonar_d2_init(struct oxygen
*chip
)
336 struct xonar_pcm179x
*data
= chip
->model_data
;
338 data
->generic
.anti_pop_delay
= 300;
339 data
->generic
.output_enable_bit
= GPIO_D2_OUTPUT_ENABLE
;
344 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_D2_ALT
);
345 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_D2_ALT
);
347 oxygen_ac97_set_bits(chip
, 0, CM9780_JACK
, CM9780_FMIC2MIC
);
349 xonar_init_cs53x1(chip
);
350 xonar_enable_output(chip
);
352 snd_component_add(chip
->card
, "PCM1796");
353 snd_component_add(chip
->card
, "CS5381");
356 static void xonar_d2x_init(struct oxygen
*chip
)
358 struct xonar_pcm179x
*data
= chip
->model_data
;
360 data
->generic
.ext_power_reg
= OXYGEN_GPIO_DATA
;
361 data
->generic
.ext_power_int_reg
= OXYGEN_GPIO_INTERRUPT_MASK
;
362 data
->generic
.ext_power_bit
= GPIO_D2X_EXT_POWER
;
363 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_D2X_EXT_POWER
);
364 xonar_init_ext_power(chip
);
368 static void xonar_hdav_init(struct oxygen
*chip
)
370 struct xonar_hdav
*data
= chip
->model_data
;
372 oxygen_write16(chip
, OXYGEN_2WIRE_BUS_STATUS
,
373 OXYGEN_2WIRE_LENGTH_8
|
374 OXYGEN_2WIRE_INTERRUPT_MASK
|
375 OXYGEN_2WIRE_SPEED_STANDARD
);
377 data
->pcm179x
.generic
.anti_pop_delay
= 100;
378 data
->pcm179x
.generic
.output_enable_bit
= GPIO_HDAV_OUTPUT_ENABLE
;
379 data
->pcm179x
.generic
.ext_power_reg
= OXYGEN_GPI_DATA
;
380 data
->pcm179x
.generic
.ext_power_int_reg
= OXYGEN_GPI_INTERRUPT_MASK
;
381 data
->pcm179x
.generic
.ext_power_bit
= GPI_EXT_POWER
;
382 data
->pcm179x
.dacs
= chip
->model
.dac_channels_mixer
/ 2;
383 data
->pcm179x
.h6
= chip
->model
.dac_channels_mixer
> 2;
387 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
,
388 GPIO_HDAV_MAGIC
| GPIO_INPUT_ROUTE
);
389 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_INPUT_ROUTE
);
391 xonar_init_cs53x1(chip
);
392 xonar_init_ext_power(chip
);
393 xonar_hdmi_init(chip
, &data
->hdmi
);
394 xonar_enable_output(chip
);
396 snd_component_add(chip
->card
, "PCM1796");
397 snd_component_add(chip
->card
, "CS5381");
400 static void xonar_st_init_i2c(struct oxygen
*chip
)
402 oxygen_write16(chip
, OXYGEN_2WIRE_BUS_STATUS
,
403 OXYGEN_2WIRE_LENGTH_8
|
404 OXYGEN_2WIRE_INTERRUPT_MASK
|
405 OXYGEN_2WIRE_SPEED_STANDARD
);
408 static void xonar_st_init_common(struct oxygen
*chip
)
410 struct xonar_pcm179x
*data
= chip
->model_data
;
412 data
->generic
.output_enable_bit
= GPIO_ST_OUTPUT_ENABLE
;
413 data
->dacs
= chip
->model
.dac_channels_mixer
/ 2;
414 data
->h6
= chip
->model
.dac_channels_mixer
> 2;
415 data
->hp_gain_offset
= 2*-18;
419 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
,
420 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
|
421 GPIO_ST_MAGIC
| GPIO_ST_HP
);
422 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
,
423 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
| GPIO_ST_HP
);
425 xonar_init_cs53x1(chip
);
426 xonar_enable_output(chip
);
428 snd_component_add(chip
->card
, "PCM1792A");
429 snd_component_add(chip
->card
, "CS5381");
432 static void cs2000_registers_init(struct oxygen
*chip
)
434 struct xonar_pcm179x
*data
= chip
->model_data
;
436 cs2000_write(chip
, CS2000_GLOBAL_CFG
, CS2000_FREEZE
);
437 cs2000_write(chip
, CS2000_DEV_CTRL
, 0);
438 cs2000_write(chip
, CS2000_DEV_CFG_1
,
440 (0 << CS2000_R_SEL_SHIFT
) |
441 CS2000_AUX_OUT_SRC_REF_CLK
|
442 CS2000_EN_DEV_CFG_1
);
443 cs2000_write(chip
, CS2000_DEV_CFG_2
,
444 (0 << CS2000_LOCK_CLK_SHIFT
) |
445 CS2000_FRAC_N_SRC_STATIC
);
446 cs2000_write(chip
, CS2000_RATIO_0
+ 0, 0x00); /* 1.0 */
447 cs2000_write(chip
, CS2000_RATIO_0
+ 1, 0x10);
448 cs2000_write(chip
, CS2000_RATIO_0
+ 2, 0x00);
449 cs2000_write(chip
, CS2000_RATIO_0
+ 3, 0x00);
450 cs2000_write(chip
, CS2000_FUN_CFG_1
,
451 data
->cs2000_regs
[CS2000_FUN_CFG_1
]);
452 cs2000_write(chip
, CS2000_FUN_CFG_2
, 0);
453 cs2000_write(chip
, CS2000_GLOBAL_CFG
, CS2000_EN_DEV_CFG_2
);
454 msleep(3); /* PLL lock delay */
457 static void xonar_st_init(struct oxygen
*chip
)
459 struct xonar_pcm179x
*data
= chip
->model_data
;
461 data
->generic
.anti_pop_delay
= 100;
462 data
->h6
= chip
->model
.dac_channels_mixer
> 2;
463 data
->has_cs2000
= true;
464 data
->cs2000_regs
[CS2000_FUN_CFG_1
] = CS2000_REF_CLK_DIV_1
;
465 data
->broken_i2c
= true;
467 oxygen_write16(chip
, OXYGEN_I2S_A_FORMAT
,
469 OXYGEN_I2S_FORMAT_I2S
|
470 OXYGEN_I2S_MCLK(data
->h6
? MCLK_256
: MCLK_512
) |
475 xonar_st_init_i2c(chip
);
476 cs2000_registers_init(chip
);
477 xonar_st_init_common(chip
);
479 snd_component_add(chip
->card
, "CS2000");
482 static void xonar_stx_init(struct oxygen
*chip
)
484 struct xonar_pcm179x
*data
= chip
->model_data
;
486 xonar_st_init_i2c(chip
);
487 data
->generic
.anti_pop_delay
= 800;
488 data
->generic
.ext_power_reg
= OXYGEN_GPI_DATA
;
489 data
->generic
.ext_power_int_reg
= OXYGEN_GPI_INTERRUPT_MASK
;
490 data
->generic
.ext_power_bit
= GPI_EXT_POWER
;
491 xonar_init_ext_power(chip
);
492 xonar_st_init_common(chip
);
495 static void xonar_xense_init(struct oxygen
*chip
)
497 struct xonar_pcm179x
*data
= chip
->model_data
;
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
);
504 data
->generic
.anti_pop_delay
= 100;
505 data
->has_cs2000
= true;
506 data
->cs2000_regs
[CS2000_FUN_CFG_1
] = CS2000_REF_CLK_DIV_1
;
508 oxygen_write16(chip
, OXYGEN_I2S_A_FORMAT
,
510 OXYGEN_I2S_FORMAT_I2S
|
511 OXYGEN_I2S_MCLK(MCLK_512
) |
516 xonar_st_init_i2c(chip
);
517 cs2000_registers_init(chip
);
519 data
->generic
.output_enable_bit
= GPIO_XENSE_OUTPUT_ENABLE
;
521 data
->hp_gain_offset
= 2*-18;
525 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
,
526 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
|
527 GPIO_ST_MAGIC
| GPIO_XENSE_SPEAKERS
);
528 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
,
529 GPIO_INPUT_ROUTE
| GPIO_ST_HP_REAR
|
530 GPIO_XENSE_SPEAKERS
);
532 xonar_init_cs53x1(chip
);
533 xonar_enable_output(chip
);
535 snd_component_add(chip
->card
, "PCM1796");
536 snd_component_add(chip
->card
, "CS5381");
537 snd_component_add(chip
->card
, "CS2000");
540 static void xonar_d2_cleanup(struct oxygen
*chip
)
542 xonar_disable_output(chip
);
545 static void xonar_hdav_cleanup(struct oxygen
*chip
)
547 xonar_hdmi_cleanup(chip
);
548 xonar_disable_output(chip
);
552 static void xonar_st_cleanup(struct oxygen
*chip
)
554 xonar_disable_output(chip
);
557 static void xonar_d2_suspend(struct oxygen
*chip
)
559 xonar_d2_cleanup(chip
);
562 static void xonar_hdav_suspend(struct oxygen
*chip
)
564 xonar_hdav_cleanup(chip
);
567 static void xonar_st_suspend(struct oxygen
*chip
)
569 xonar_st_cleanup(chip
);
572 static void xonar_d2_resume(struct oxygen
*chip
)
574 pcm1796_registers_init(chip
);
575 xonar_enable_output(chip
);
578 static void xonar_hdav_resume(struct oxygen
*chip
)
580 struct xonar_hdav
*data
= chip
->model_data
;
582 pcm1796_registers_init(chip
);
583 xonar_hdmi_resume(chip
, &data
->hdmi
);
584 xonar_enable_output(chip
);
587 static void xonar_stx_resume(struct oxygen
*chip
)
589 pcm1796_registers_init(chip
);
590 xonar_enable_output(chip
);
593 static void xonar_st_resume(struct oxygen
*chip
)
595 cs2000_registers_init(chip
);
596 xonar_stx_resume(chip
);
599 static void update_pcm1796_oversampling(struct oxygen
*chip
)
601 struct xonar_pcm179x
*data
= chip
->model_data
;
605 if (data
->current_rate
<= 48000 && !data
->h6
)
606 reg
= PCM1796_OS_128
;
609 for (i
= 0; i
< data
->dacs
; ++i
)
610 pcm1796_write_cached(chip
, i
, 20, reg
);
613 static void update_pcm1796_deemph(struct oxygen
*chip
)
615 struct xonar_pcm179x
*data
= chip
->model_data
;
619 reg
= data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
] & ~PCM1796_DMF_MASK
;
620 if (data
->current_rate
== 48000)
621 reg
|= PCM1796_DMF_48
;
622 else if (data
->current_rate
== 44100)
623 reg
|= PCM1796_DMF_441
;
624 else if (data
->current_rate
== 32000)
625 reg
|= PCM1796_DMF_32
;
626 for (i
= 0; i
< data
->dacs
; ++i
)
627 pcm1796_write_cached(chip
, i
, 18, reg
);
630 static void set_pcm1796_params(struct oxygen
*chip
,
631 struct snd_pcm_hw_params
*params
)
633 struct xonar_pcm179x
*data
= chip
->model_data
;
636 data
->current_rate
= params_rate(params
);
637 update_pcm1796_oversampling(chip
);
638 update_pcm1796_deemph(chip
);
641 static void update_pcm1796_volume(struct oxygen
*chip
)
643 struct xonar_pcm179x
*data
= chip
->model_data
;
647 gain_offset
= data
->hp_active
? data
->hp_gain_offset
: 0;
648 for (i
= 0; i
< data
->dacs
; ++i
) {
649 pcm1796_write_cached(chip
, i
, 16, chip
->dac_volume
[i
* 2]
651 pcm1796_write_cached(chip
, i
, 17, chip
->dac_volume
[i
* 2 + 1]
657 static void update_pcm1796_mute(struct oxygen
*chip
)
659 struct xonar_pcm179x
*data
= chip
->model_data
;
663 value
= data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
];
665 value
|= PCM1796_MUTE
;
667 value
&= ~PCM1796_MUTE
;
668 for (i
= 0; i
< data
->dacs
; ++i
)
669 pcm1796_write_cached(chip
, i
, 18, value
);
672 static void update_cs2000_rate(struct oxygen
*chip
, unsigned int rate
)
674 struct xonar_pcm179x
*data
= chip
->model_data
;
680 rate_mclk
= OXYGEN_RATE_32000
;
685 rate_mclk
= OXYGEN_RATE_44100
;
691 rate_mclk
= OXYGEN_RATE_48000
;
695 if (rate
<= 96000 && (rate
> 48000 || data
->h6
)) {
696 rate_mclk
|= OXYGEN_I2S_MCLK(MCLK_256
);
697 reg
= CS2000_REF_CLK_DIV_1
;
699 rate_mclk
|= OXYGEN_I2S_MCLK(MCLK_512
);
700 reg
= CS2000_REF_CLK_DIV_2
;
703 oxygen_write16_masked(chip
, OXYGEN_I2S_A_FORMAT
, rate_mclk
,
704 OXYGEN_I2S_RATE_MASK
| OXYGEN_I2S_MCLK_MASK
);
705 cs2000_write_cached(chip
, CS2000_FUN_CFG_1
, reg
);
706 msleep(3); /* PLL lock delay */
709 static void set_st_params(struct oxygen
*chip
,
710 struct snd_pcm_hw_params
*params
)
712 update_cs2000_rate(chip
, params_rate(params
));
713 set_pcm1796_params(chip
, params
);
716 static void set_hdav_params(struct oxygen
*chip
,
717 struct snd_pcm_hw_params
*params
)
719 struct xonar_hdav
*data
= chip
->model_data
;
721 set_pcm1796_params(chip
, params
);
722 xonar_set_hdmi_params(chip
, &data
->hdmi
, params
);
725 static const struct snd_kcontrol_new alt_switch
= {
726 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
727 .name
= "Analog Loopback Switch",
728 .info
= snd_ctl_boolean_mono_info
,
729 .get
= xonar_gpio_bit_switch_get
,
730 .put
= xonar_gpio_bit_switch_put
,
731 .private_value
= GPIO_D2_ALT
,
734 static int rolloff_info(struct snd_kcontrol
*ctl
,
735 struct snd_ctl_elem_info
*info
)
737 static const char *const names
[2] = {
738 "Sharp Roll-off", "Slow Roll-off"
741 return snd_ctl_enum_info(info
, 1, 2, names
);
744 static int rolloff_get(struct snd_kcontrol
*ctl
,
745 struct snd_ctl_elem_value
*value
)
747 struct oxygen
*chip
= ctl
->private_data
;
748 struct xonar_pcm179x
*data
= chip
->model_data
;
750 value
->value
.enumerated
.item
[0] =
751 (data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
] &
752 PCM1796_FLT_MASK
) != PCM1796_FLT_SHARP
;
756 static int rolloff_put(struct snd_kcontrol
*ctl
,
757 struct snd_ctl_elem_value
*value
)
759 struct oxygen
*chip
= ctl
->private_data
;
760 struct xonar_pcm179x
*data
= chip
->model_data
;
765 mutex_lock(&chip
->mutex
);
766 reg
= data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
];
767 reg
&= ~PCM1796_FLT_MASK
;
768 if (!value
->value
.enumerated
.item
[0])
769 reg
|= PCM1796_FLT_SHARP
;
771 reg
|= PCM1796_FLT_SLOW
;
772 changed
= reg
!= data
->pcm1796_regs
[0][19 - PCM1796_REG_BASE
];
774 for (i
= 0; i
< data
->dacs
; ++i
)
775 pcm1796_write(chip
, i
, 19, reg
);
777 mutex_unlock(&chip
->mutex
);
781 static const struct snd_kcontrol_new rolloff_control
= {
782 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
783 .name
= "DAC Filter Playback Enum",
784 .info
= rolloff_info
,
789 static int deemph_get(struct snd_kcontrol
*ctl
,
790 struct snd_ctl_elem_value
*value
)
792 struct oxygen
*chip
= ctl
->private_data
;
793 struct xonar_pcm179x
*data
= chip
->model_data
;
795 value
->value
.integer
.value
[0] =
796 !!(data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
] & PCM1796_DME
);
800 static int deemph_put(struct snd_kcontrol
*ctl
,
801 struct snd_ctl_elem_value
*value
)
803 struct oxygen
*chip
= ctl
->private_data
;
804 struct xonar_pcm179x
*data
= chip
->model_data
;
809 mutex_lock(&chip
->mutex
);
810 reg
= data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
];
811 if (!value
->value
.integer
.value
[0])
815 changed
= reg
!= data
->pcm1796_regs
[0][18 - PCM1796_REG_BASE
];
817 for (i
= 0; i
< data
->dacs
; ++i
)
818 pcm1796_write(chip
, i
, 18, reg
);
820 mutex_unlock(&chip
->mutex
);
824 static const struct snd_kcontrol_new deemph_control
= {
825 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
826 .name
= "De-emphasis Playback Switch",
827 .info
= snd_ctl_boolean_mono_info
,
832 static const struct snd_kcontrol_new hdav_hdmi_control
= {
833 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
834 .name
= "HDMI Playback Switch",
835 .info
= snd_ctl_boolean_mono_info
,
836 .get
= xonar_gpio_bit_switch_get
,
837 .put
= xonar_gpio_bit_switch_put
,
838 .private_value
= GPIO_HDAV_OUTPUT_ENABLE
| XONAR_GPIO_BIT_INVERT
,
841 static int st_output_switch_info(struct snd_kcontrol
*ctl
,
842 struct snd_ctl_elem_info
*info
)
844 static const char *const names
[3] = {
845 "Speakers", "Headphones", "FP Headphones"
848 return snd_ctl_enum_info(info
, 1, 3, names
);
851 static int st_output_switch_get(struct snd_kcontrol
*ctl
,
852 struct snd_ctl_elem_value
*value
)
854 struct oxygen
*chip
= ctl
->private_data
;
857 gpio
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
858 if (!(gpio
& GPIO_ST_HP
))
859 value
->value
.enumerated
.item
[0] = 0;
860 else if (gpio
& GPIO_ST_HP_REAR
)
861 value
->value
.enumerated
.item
[0] = 1;
863 value
->value
.enumerated
.item
[0] = 2;
868 static int st_output_switch_put(struct snd_kcontrol
*ctl
,
869 struct snd_ctl_elem_value
*value
)
871 struct oxygen
*chip
= ctl
->private_data
;
872 struct xonar_pcm179x
*data
= chip
->model_data
;
875 mutex_lock(&chip
->mutex
);
876 gpio_old
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
878 switch (value
->value
.enumerated
.item
[0]) {
880 gpio
&= ~(GPIO_ST_HP
| GPIO_ST_HP_REAR
);
883 gpio
|= GPIO_ST_HP
| GPIO_ST_HP_REAR
;
886 gpio
= (gpio
| GPIO_ST_HP
) & ~GPIO_ST_HP_REAR
;
889 oxygen_write16(chip
, OXYGEN_GPIO_DATA
, gpio
);
890 data
->hp_active
= gpio
& GPIO_ST_HP
;
891 update_pcm1796_volume(chip
);
892 mutex_unlock(&chip
->mutex
);
893 return gpio
!= gpio_old
;
896 static int st_hp_volume_offset_info(struct snd_kcontrol
*ctl
,
897 struct snd_ctl_elem_info
*info
)
899 static const char *const names
[4] = {
900 "< 32 ohms", "32-64 ohms", "64-300 ohms", "300-600 ohms"
903 return snd_ctl_enum_info(info
, 1, 4, names
);
906 static int st_hp_volume_offset_get(struct snd_kcontrol
*ctl
,
907 struct snd_ctl_elem_value
*value
)
909 struct oxygen
*chip
= ctl
->private_data
;
910 struct xonar_pcm179x
*data
= chip
->model_data
;
912 mutex_lock(&chip
->mutex
);
913 if (data
->hp_gain_offset
< 2*-12)
914 value
->value
.enumerated
.item
[0] = 0;
915 else if (data
->hp_gain_offset
< 2*-6)
916 value
->value
.enumerated
.item
[0] = 1;
917 else if (data
->hp_gain_offset
< 0)
918 value
->value
.enumerated
.item
[0] = 2;
920 value
->value
.enumerated
.item
[0] = 3;
921 mutex_unlock(&chip
->mutex
);
926 static int st_hp_volume_offset_put(struct snd_kcontrol
*ctl
,
927 struct snd_ctl_elem_value
*value
)
929 static const s8 offsets
[] = { 2*-18, 2*-12, 2*-6, 0 };
930 struct oxygen
*chip
= ctl
->private_data
;
931 struct xonar_pcm179x
*data
= chip
->model_data
;
935 if (value
->value
.enumerated
.item
[0] > 3)
937 offset
= offsets
[value
->value
.enumerated
.item
[0]];
938 mutex_lock(&chip
->mutex
);
939 changed
= offset
!= data
->hp_gain_offset
;
941 data
->hp_gain_offset
= offset
;
942 update_pcm1796_volume(chip
);
944 mutex_unlock(&chip
->mutex
);
948 static const struct snd_kcontrol_new st_controls
[] = {
950 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
951 .name
= "Analog Output",
952 .info
= st_output_switch_info
,
953 .get
= st_output_switch_get
,
954 .put
= st_output_switch_put
,
957 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
958 .name
= "Headphones Impedance Playback Enum",
959 .info
= st_hp_volume_offset_info
,
960 .get
= st_hp_volume_offset_get
,
961 .put
= st_hp_volume_offset_put
,
965 static int xense_output_switch_get(struct snd_kcontrol
*ctl
,
966 struct snd_ctl_elem_value
*value
)
968 struct oxygen
*chip
= ctl
->private_data
;
971 gpio
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
972 if (gpio
& GPIO_XENSE_SPEAKERS
)
973 value
->value
.enumerated
.item
[0] = 0;
974 else if (!(gpio
& GPIO_XENSE_SPEAKERS
) && (gpio
& GPIO_ST_HP_REAR
))
975 value
->value
.enumerated
.item
[0] = 1;
977 value
->value
.enumerated
.item
[0] = 2;
981 static int xense_output_switch_put(struct snd_kcontrol
*ctl
,
982 struct snd_ctl_elem_value
*value
)
984 struct oxygen
*chip
= ctl
->private_data
;
985 struct xonar_pcm179x
*data
= chip
->model_data
;
988 mutex_lock(&chip
->mutex
);
989 gpio_old
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
991 switch (value
->value
.enumerated
.item
[0]) {
993 gpio
|= GPIO_XENSE_SPEAKERS
| GPIO_ST_HP_REAR
;
996 gpio
= (gpio
| GPIO_ST_HP_REAR
) & ~GPIO_XENSE_SPEAKERS
;
999 gpio
&= ~(GPIO_XENSE_SPEAKERS
| GPIO_ST_HP_REAR
);
1002 oxygen_write16(chip
, OXYGEN_GPIO_DATA
, gpio
);
1003 data
->hp_active
= !(gpio
& GPIO_XENSE_SPEAKERS
);
1004 update_pcm1796_volume(chip
);
1005 mutex_unlock(&chip
->mutex
);
1006 return gpio
!= gpio_old
;
1009 static const struct snd_kcontrol_new xense_controls
[] = {
1011 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1012 .name
= "Analog Output",
1013 .info
= st_output_switch_info
,
1014 .get
= xense_output_switch_get
,
1015 .put
= xense_output_switch_put
,
1018 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1019 .name
= "Headphones Impedance Playback Enum",
1020 .info
= st_hp_volume_offset_info
,
1021 .get
= st_hp_volume_offset_get
,
1022 .put
= st_hp_volume_offset_put
,
1026 static void xonar_line_mic_ac97_switch(struct oxygen
*chip
,
1027 unsigned int reg
, unsigned int mute
)
1029 if (reg
== AC97_LINE
) {
1030 spin_lock_irq(&chip
->reg_lock
);
1031 oxygen_write16_masked(chip
, OXYGEN_GPIO_DATA
,
1032 mute
? GPIO_INPUT_ROUTE
: 0,
1034 spin_unlock_irq(&chip
->reg_lock
);
1038 static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale
, -6000, 50, 0);
1040 static int xonar_d2_control_filter(struct snd_kcontrol_new
*template)
1042 if (!strncmp(template->name
, "CD Capture ", 11))
1043 /* CD in is actually connected to the video in pin */
1044 template->private_value
^= AC97_CD
^ AC97_VIDEO
;
1048 static int xonar_st_h6_control_filter(struct snd_kcontrol_new
*template)
1050 if (!strncmp(template->name
, "Master Playback ", 16))
1051 /* no volume/mute, as I²C to the third DAC does not work */
1056 static int add_pcm1796_controls(struct oxygen
*chip
)
1058 struct xonar_pcm179x
*data
= chip
->model_data
;
1061 if (!data
->broken_i2c
) {
1062 err
= snd_ctl_add(chip
->card
,
1063 snd_ctl_new1(&rolloff_control
, chip
));
1066 err
= snd_ctl_add(chip
->card
,
1067 snd_ctl_new1(&deemph_control
, chip
));
1074 static int xonar_d2_mixer_init(struct oxygen
*chip
)
1078 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&alt_switch
, chip
));
1081 err
= add_pcm1796_controls(chip
);
1087 static int xonar_hdav_mixer_init(struct oxygen
*chip
)
1091 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&hdav_hdmi_control
, chip
));
1094 err
= add_pcm1796_controls(chip
);
1100 static int xonar_st_mixer_init(struct oxygen
*chip
)
1105 for (i
= 0; i
< ARRAY_SIZE(st_controls
); ++i
) {
1106 err
= snd_ctl_add(chip
->card
,
1107 snd_ctl_new1(&st_controls
[i
], chip
));
1111 err
= add_pcm1796_controls(chip
);
1117 static int xonar_xense_mixer_init(struct oxygen
*chip
)
1122 for (i
= 0; i
< ARRAY_SIZE(xense_controls
); ++i
) {
1123 err
= snd_ctl_add(chip
->card
,
1124 snd_ctl_new1(&xense_controls
[i
], chip
));
1128 err
= add_pcm1796_controls(chip
);
1134 static void dump_pcm1796_registers(struct oxygen
*chip
,
1135 struct snd_info_buffer
*buffer
)
1137 struct xonar_pcm179x
*data
= chip
->model_data
;
1138 unsigned int dac
, i
;
1140 for (dac
= 0; dac
< data
->dacs
; ++dac
) {
1141 snd_iprintf(buffer
, "\nPCM1796 %u:", dac
+ 1);
1142 for (i
= 0; i
< 5; ++i
)
1143 snd_iprintf(buffer
, " %02x",
1144 data
->pcm1796_regs
[dac
][i
]);
1146 snd_iprintf(buffer
, "\n");
1149 static void dump_cs2000_registers(struct oxygen
*chip
,
1150 struct snd_info_buffer
*buffer
)
1152 struct xonar_pcm179x
*data
= chip
->model_data
;
1155 if (data
->has_cs2000
) {
1156 snd_iprintf(buffer
, "\nCS2000:\n00: ");
1157 for (i
= 1; i
< 0x10; ++i
)
1158 snd_iprintf(buffer
, " %02x", data
->cs2000_regs
[i
]);
1159 snd_iprintf(buffer
, "\n10:");
1160 for (i
= 0x10; i
< 0x1f; ++i
)
1161 snd_iprintf(buffer
, " %02x", data
->cs2000_regs
[i
]);
1162 snd_iprintf(buffer
, "\n");
1166 static void dump_st_registers(struct oxygen
*chip
,
1167 struct snd_info_buffer
*buffer
)
1169 dump_pcm1796_registers(chip
, buffer
);
1170 dump_cs2000_registers(chip
, buffer
);
1173 static const struct oxygen_model model_xonar_d2
= {
1174 .longname
= "Asus Virtuoso 200",
1176 .init
= xonar_d2_init
,
1177 .control_filter
= xonar_d2_control_filter
,
1178 .mixer_init
= xonar_d2_mixer_init
,
1179 .cleanup
= xonar_d2_cleanup
,
1180 .suspend
= xonar_d2_suspend
,
1181 .resume
= xonar_d2_resume
,
1182 .set_dac_params
= set_pcm1796_params
,
1183 .set_adc_params
= xonar_set_cs53x1_params
,
1184 .update_dac_volume
= update_pcm1796_volume
,
1185 .update_dac_mute
= update_pcm1796_mute
,
1186 .dump_registers
= dump_pcm1796_registers
,
1187 .dac_tlv
= pcm1796_db_scale
,
1188 .model_data_size
= sizeof(struct xonar_pcm179x
),
1189 .device_config
= PLAYBACK_0_TO_I2S
|
1190 PLAYBACK_1_TO_SPDIF
|
1191 CAPTURE_0_FROM_I2S_2
|
1192 CAPTURE_1_FROM_SPDIF
|
1196 .dac_channels_pcm
= 8,
1197 .dac_channels_mixer
= 8,
1198 .dac_volume_min
= 255 - 2*60,
1199 .dac_volume_max
= 255,
1200 .misc_flags
= OXYGEN_MISC_MIDI
,
1201 .function_flags
= OXYGEN_FUNCTION_SPI
|
1202 OXYGEN_FUNCTION_ENABLE_SPI_4_5
,
1203 .dac_mclks
= OXYGEN_MCLKS(512, 128, 128),
1204 .adc_mclks
= OXYGEN_MCLKS(256, 128, 128),
1205 .dac_i2s_format
= OXYGEN_I2S_FORMAT_I2S
,
1206 .adc_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
1209 static const struct oxygen_model model_xonar_hdav
= {
1210 .longname
= "Asus Virtuoso 200",
1212 .init
= xonar_hdav_init
,
1213 .mixer_init
= xonar_hdav_mixer_init
,
1214 .cleanup
= xonar_hdav_cleanup
,
1215 .suspend
= xonar_hdav_suspend
,
1216 .resume
= xonar_hdav_resume
,
1217 .pcm_hardware_filter
= xonar_hdmi_pcm_hardware_filter
,
1218 .set_dac_params
= set_hdav_params
,
1219 .set_adc_params
= xonar_set_cs53x1_params
,
1220 .update_dac_volume
= update_pcm1796_volume
,
1221 .update_dac_mute
= update_pcm1796_mute
,
1222 .uart_input
= xonar_hdmi_uart_input
,
1223 .ac97_switch
= xonar_line_mic_ac97_switch
,
1224 .dump_registers
= dump_pcm1796_registers
,
1225 .dac_tlv
= pcm1796_db_scale
,
1226 .model_data_size
= sizeof(struct xonar_hdav
),
1227 .device_config
= PLAYBACK_0_TO_I2S
|
1228 PLAYBACK_1_TO_SPDIF
|
1229 CAPTURE_0_FROM_I2S_2
|
1230 CAPTURE_1_FROM_SPDIF
,
1231 .dac_channels_pcm
= 8,
1232 .dac_channels_mixer
= 2,
1233 .dac_volume_min
= 255 - 2*60,
1234 .dac_volume_max
= 255,
1235 .misc_flags
= OXYGEN_MISC_MIDI
,
1236 .function_flags
= OXYGEN_FUNCTION_2WIRE
,
1237 .dac_mclks
= OXYGEN_MCLKS(512, 128, 128),
1238 .adc_mclks
= OXYGEN_MCLKS(256, 128, 128),
1239 .dac_i2s_format
= OXYGEN_I2S_FORMAT_I2S
,
1240 .adc_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
1243 static const struct oxygen_model model_xonar_st
= {
1244 .longname
= "Asus Virtuoso 100",
1246 .init
= xonar_st_init
,
1247 .mixer_init
= xonar_st_mixer_init
,
1248 .cleanup
= xonar_st_cleanup
,
1249 .suspend
= xonar_st_suspend
,
1250 .resume
= xonar_st_resume
,
1251 .set_dac_params
= set_st_params
,
1252 .set_adc_params
= xonar_set_cs53x1_params
,
1253 .update_dac_volume
= update_pcm1796_volume
,
1254 .update_dac_mute
= update_pcm1796_mute
,
1255 .ac97_switch
= xonar_line_mic_ac97_switch
,
1256 .dump_registers
= dump_st_registers
,
1257 .dac_tlv
= pcm1796_db_scale
,
1258 .model_data_size
= sizeof(struct xonar_pcm179x
),
1259 .device_config
= PLAYBACK_0_TO_I2S
|
1260 PLAYBACK_1_TO_SPDIF
|
1261 CAPTURE_0_FROM_I2S_2
|
1262 CAPTURE_1_FROM_SPDIF
|
1264 .dac_channels_pcm
= 2,
1265 .dac_channels_mixer
= 2,
1266 .dac_volume_min
= 255 - 2*60,
1267 .dac_volume_max
= 255,
1268 .function_flags
= OXYGEN_FUNCTION_2WIRE
,
1269 .dac_mclks
= OXYGEN_MCLKS(512, 128, 128),
1270 .adc_mclks
= OXYGEN_MCLKS(256, 128, 128),
1271 .dac_i2s_format
= OXYGEN_I2S_FORMAT_I2S
,
1272 .adc_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
1275 int get_xonar_pcm179x_model(struct oxygen
*chip
,
1276 const struct pci_device_id
*id
)
1278 switch (id
->subdevice
) {
1280 chip
->model
= model_xonar_d2
;
1281 chip
->model
.shortname
= "Xonar D2";
1284 chip
->model
= model_xonar_d2
;
1285 chip
->model
.shortname
= "Xonar D2X";
1286 chip
->model
.init
= xonar_d2x_init
;
1289 chip
->model
= model_xonar_hdav
;
1290 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_DB_MASK
);
1291 switch (oxygen_read16(chip
, OXYGEN_GPIO_DATA
) & GPIO_DB_MASK
) {
1293 chip
->model
.shortname
= "Xonar HDAV1.3";
1296 chip
->model
.shortname
= "Xonar HDAV1.3+H6";
1297 chip
->model
.dac_channels_mixer
= 8;
1298 chip
->model
.dac_mclks
= OXYGEN_MCLKS(256, 128, 128);
1303 chip
->model
= model_xonar_st
;
1304 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_DB_MASK
);
1305 switch (oxygen_read16(chip
, OXYGEN_GPIO_DATA
) & GPIO_DB_MASK
) {
1307 chip
->model
.shortname
= "Xonar ST";
1310 chip
->model
.shortname
= "Xonar ST+H6";
1311 chip
->model
.control_filter
= xonar_st_h6_control_filter
;
1312 chip
->model
.dac_channels_pcm
= 8;
1313 chip
->model
.dac_channels_mixer
= 8;
1314 chip
->model
.dac_volume_min
= 255;
1315 chip
->model
.dac_mclks
= OXYGEN_MCLKS(256, 128, 128);
1320 chip
->model
= model_xonar_st
;
1321 chip
->model
.shortname
= "Xonar STX";
1322 chip
->model
.init
= xonar_stx_init
;
1323 chip
->model
.resume
= xonar_stx_resume
;
1324 chip
->model
.set_dac_params
= set_pcm1796_params
;
1327 chip
->model
= model_xonar_st
;
1328 oxygen_clear_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_DB_MASK
);
1329 switch (oxygen_read16(chip
, OXYGEN_GPIO_DATA
) & GPIO_DB_MASK
) {
1331 chip
->model
.shortname
= "Xonar STX II";
1334 chip
->model
.shortname
= "Xonar STX II+H6";
1335 chip
->model
.dac_channels_pcm
= 8;
1336 chip
->model
.dac_channels_mixer
= 8;
1337 chip
->model
.dac_mclks
= OXYGEN_MCLKS(256, 128, 128);
1340 chip
->model
.init
= xonar_stx_init
;
1341 chip
->model
.resume
= xonar_stx_resume
;
1342 chip
->model
.set_dac_params
= set_pcm1796_params
;
1345 chip
->model
= model_xonar_st
;
1346 chip
->model
.shortname
= "Xonar Xense";
1347 chip
->model
.chip
= "AV100";
1348 chip
->model
.init
= xonar_xense_init
;
1349 chip
->model
.mixer_init
= xonar_xense_mixer_init
;