xref: /openbmc/linux/sound/pci/oxygen/xonar_pcm179x.c (revision 00b8dd7d)
1 /*
2  * card driver for models with PCM1796 DACs (Xonar D2/D2X/HDAV1.3/ST/STX)
3  *
4  * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5  *
6  *
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.
9  *
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.
14  *
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/>.
17  */
18 
19 /*
20  * Xonar D2/D2X
21  * ------------
22  *
23  * CMI8788:
24  *
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)
29  *
30  *   GPIO 2 -> M0 of CS5381
31  *   GPIO 3 -> M1 of CS5381
32  *   GPIO 5 <- external power present (D2X only)
33  *   GPIO 7 -> ALT
34  *   GPIO 8 -> enable output to speakers
35  *
36  * CM9780:
37  *
38  *   LINE_OUT -> input of ADC
39  *
40  *   AUX_IN   <- aux
41  *   VIDEO_IN <- CD
42  *   FMIC_IN  <- mic
43  *
44  *   GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
45  */
46 
47 /*
48  * Xonar HDAV1.3 (Deluxe)
49  * ----------------------
50  *
51  * CMI8788:
52  *
53  *   I²C <-> PCM1796 (addr 1001100) (front)
54  *
55  *   GPI 0 <- external power present
56  *
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
62  *   GPIO 6 -> ?
63  *   GPIO 7 -> ?
64  *   GPIO 8 -> route input jack to line-in (0) or mic-in (1)
65  *
66  *   UART <-> HDMI controller
67  *
68  * CM9780:
69  *
70  *   LINE_OUT -> input of ADC
71  *
72  *   AUX_IN <- aux
73  *   CD_IN  <- CD
74  *   MIC_IN <- mic
75  *
76  *   GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
77  *
78  * no daughterboard
79  * ----------------
80  *
81  *   GPIO 4 <- 1
82  *
83  * H6 daughterboard
84  * ----------------
85  *
86  *   GPIO 4 <- 0
87  *   GPIO 5 <- 0
88  *
89  *   I²C <-> PCM1796 (addr 1001101) (surround)
90  *       <-> PCM1796 (addr 1001110) (center/LFE)
91  *       <-> PCM1796 (addr 1001111) (back)
92  *
93  * unknown daughterboard
94  * ---------------------
95  *
96  *   GPIO 4 <- 0
97  *   GPIO 5 <- 1
98  *
99  *   I²C <-> CS4362A (addr 0011000) (surround, center/LFE, back)
100  */
101 
102 /*
103  * Xonar Essence ST (Deluxe)/STX
104  * -----------------------------
105  *
106  * CMI8788:
107  *
108  *   I²C <-> PCM1792A (addr 1001100)
109  *       <-> CS2000 (addr 1001110) (ST only)
110  *
111  *   ADC1 MCLK -> REF_CLK of CS2000 (ST only)
112  *
113  *   GPI 0 <- external power present (STX only)
114  *
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
121  *   GPIO 6 -> ?
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)
124  *
125  * PCM1792A:
126  *
127  *   SCK <- CLK_OUT of CS2000 (ST only)
128  *
129  * CM9780:
130  *
131  *   LINE_OUT -> input of ADC
132  *
133  *   AUX_IN <- aux
134  *   MIC_IN <- mic
135  *
136  *   GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
137  *
138  * H6 daughterboard
139  * ----------------
140  *
141  * GPIO 4 <- 0
142  * GPIO 5 <- 0
143  */
144 
145 /*
146  * Xonar Xense
147  * -----------
148  *
149  * CMI8788:
150  *
151  *   I²C <-> PCM1796 (addr 1001100) (front)
152  *       <-> CS4362A (addr 0011000) (surround, center/LFE, back)
153  *       <-> CS2000 (addr 1001110)
154  *
155  *   ADC1 MCLK -> REF_CLK of CS2000
156  *
157  *   GPI 0 <- external power present
158  *
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
165  *   GPIO 6 -> ?
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)
168  *
169  * CM9780:
170  *
171  *   LINE_OUT -> input of ADC
172  *
173  *   AUX_IN   <- aux
174  *   VIDEO_IN <- ?
175  *   FMIC_IN  <- mic
176  *
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)
179  */
180 
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>
191 #include "xonar.h"
192 #include "cm9780.h"
193 #include "pcm1796.h"
194 #include "cs2000.h"
195 
196 
197 #define GPIO_D2X_EXT_POWER	0x0020
198 #define GPIO_D2_ALT		0x0080
199 #define GPIO_D2_OUTPUT_ENABLE	0x0100
200 
201 #define GPI_EXT_POWER		0x01
202 #define GPIO_INPUT_ROUTE	0x0100
203 
204 #define GPIO_HDAV_OUTPUT_ENABLE	0x0001
205 #define GPIO_HDAV_MAGIC		0x00c0
206 
207 #define GPIO_DB_MASK		0x0030
208 #define GPIO_DB_H6		0x0000
209 
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
214 
215 #define I2C_DEVICE_PCM1796(i)	(0x98 + ((i) << 1))	/* 10011, ii, /W=0 */
216 #define I2C_DEVICE_CS2000	0x9c			/* 100111, 0, /W=0 */
217 
218 #define PCM1796_REG_BASE	16
219 
220 
221 struct xonar_pcm179x {
222 	struct xonar_generic generic;
223 	unsigned int dacs;
224 	u8 pcm1796_regs[4][5];
225 	unsigned int current_rate;
226 	bool os_128;
227 	bool h6;
228 	bool hp_active;
229 	s8 hp_gain_offset;
230 	bool has_cs2000;
231 	u8 cs2000_regs[0x1f];
232 	bool broken_i2c;
233 };
234 
235 struct xonar_hdav {
236 	struct xonar_pcm179x pcm179x;
237 	struct xonar_hdmi hdmi;
238 };
239 
240 
241 static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
242 				     u8 reg, u8 value)
243 {
244 	/* maps ALSA channel pair number to SPI output */
245 	static const u8 codec_map[4] = {
246 		0, 1, 2, 4
247 	};
248 	oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER  |
249 			 OXYGEN_SPI_DATA_LENGTH_2 |
250 			 OXYGEN_SPI_CLOCK_160 |
251 			 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
252 			 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
253 			 (reg << 8) | value);
254 }
255 
256 static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
257 				     u8 reg, u8 value)
258 {
259 	oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
260 }
261 
262 static void pcm1796_write(struct oxygen *chip, unsigned int codec,
263 			  u8 reg, u8 value)
264 {
265 	struct xonar_pcm179x *data = chip->model_data;
266 
267 	if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
268 	    OXYGEN_FUNCTION_SPI)
269 		pcm1796_write_spi(chip, codec, reg, value);
270 	else
271 		pcm1796_write_i2c(chip, codec, reg, value);
272 	if ((unsigned int)(reg - PCM1796_REG_BASE)
273 	    < ARRAY_SIZE(data->pcm1796_regs[codec]))
274 		data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
275 }
276 
277 static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
278 				 u8 reg, u8 value)
279 {
280 	struct xonar_pcm179x *data = chip->model_data;
281 
282 	if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
283 		pcm1796_write(chip, codec, reg, value);
284 }
285 
286 static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
287 {
288 	struct xonar_pcm179x *data = chip->model_data;
289 
290 	oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
291 	data->cs2000_regs[reg] = value;
292 }
293 
294 static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
295 {
296 	struct xonar_pcm179x *data = chip->model_data;
297 
298 	if (value != data->cs2000_regs[reg])
299 		cs2000_write(chip, reg, value);
300 }
301 
302 static void pcm1796_registers_init(struct oxygen *chip)
303 {
304 	struct xonar_pcm179x *data = chip->model_data;
305 	unsigned int i;
306 	s8 gain_offset;
307 
308 	msleep(1);
309 	gain_offset = data->hp_active ? data->hp_gain_offset : 0;
310 	for (i = 0; i < data->dacs; ++i) {
311 		/* set ATLD before ATL/ATR */
312 		pcm1796_write(chip, i, 18,
313 			      data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
314 		pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
315 			      + gain_offset);
316 		pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
317 			      + gain_offset);
318 		pcm1796_write(chip, i, 19,
319 			      data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
320 		pcm1796_write(chip, i, 20,
321 			      data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
322 		pcm1796_write(chip, i, 21, 0);
323 	}
324 }
325 
326 static void pcm1796_init(struct oxygen *chip)
327 {
328 	struct xonar_pcm179x *data = chip->model_data;
329 
330 	data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
331 		PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
332 	data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
333 		PCM1796_FLT_SHARP | PCM1796_ATS_1;
334 	data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
335 	pcm1796_registers_init(chip);
336 	data->current_rate = 48000;
337 }
338 
339 static void xonar_d2_init(struct oxygen *chip)
340 {
341 	struct xonar_pcm179x *data = chip->model_data;
342 
343 	data->generic.anti_pop_delay = 300;
344 	data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
345 	data->dacs = 4;
346 
347 	pcm1796_init(chip);
348 
349 	oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
350 	oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
351 
352 	oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
353 
354 	xonar_init_cs53x1(chip);
355 	xonar_enable_output(chip);
356 
357 	snd_component_add(chip->card, "PCM1796");
358 	snd_component_add(chip->card, "CS5381");
359 }
360 
361 static void xonar_d2x_init(struct oxygen *chip)
362 {
363 	struct xonar_pcm179x *data = chip->model_data;
364 
365 	data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
366 	data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
367 	data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
368 	oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
369 	xonar_init_ext_power(chip);
370 	xonar_d2_init(chip);
371 }
372 
373 static void xonar_hdav_init(struct oxygen *chip)
374 {
375 	struct xonar_hdav *data = chip->model_data;
376 
377 	oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
378 		       OXYGEN_2WIRE_LENGTH_8 |
379 		       OXYGEN_2WIRE_INTERRUPT_MASK |
380 		       OXYGEN_2WIRE_SPEED_STANDARD);
381 
382 	data->pcm179x.generic.anti_pop_delay = 100;
383 	data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
384 	data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
385 	data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
386 	data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
387 	data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
388 	data->pcm179x.h6 = chip->model.dac_channels_mixer > 2;
389 
390 	pcm1796_init(chip);
391 
392 	oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
393 			  GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
394 	oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
395 
396 	xonar_init_cs53x1(chip);
397 	xonar_init_ext_power(chip);
398 	xonar_hdmi_init(chip, &data->hdmi);
399 	xonar_enable_output(chip);
400 
401 	snd_component_add(chip->card, "PCM1796");
402 	snd_component_add(chip->card, "CS5381");
403 }
404 
405 static void xonar_st_init_i2c(struct oxygen *chip)
406 {
407 	oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
408 		       OXYGEN_2WIRE_LENGTH_8 |
409 		       OXYGEN_2WIRE_INTERRUPT_MASK |
410 		       OXYGEN_2WIRE_SPEED_STANDARD);
411 }
412 
413 static void xonar_st_init_common(struct oxygen *chip)
414 {
415 	struct xonar_pcm179x *data = chip->model_data;
416 
417 	data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
418 	data->dacs = chip->model.dac_channels_mixer / 2;
419 	data->hp_gain_offset = 2*-18;
420 
421 	pcm1796_init(chip);
422 
423 	oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
424 			  GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
425 			  GPIO_ST_MAGIC | GPIO_ST_HP);
426 	oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
427 			    GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
428 
429 	xonar_init_cs53x1(chip);
430 	xonar_enable_output(chip);
431 
432 	snd_component_add(chip->card, "PCM1792A");
433 	snd_component_add(chip->card, "CS5381");
434 }
435 
436 static void cs2000_registers_init(struct oxygen *chip)
437 {
438 	struct xonar_pcm179x *data = chip->model_data;
439 
440 	cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
441 	cs2000_write(chip, CS2000_DEV_CTRL, 0);
442 	cs2000_write(chip, CS2000_DEV_CFG_1,
443 		     CS2000_R_MOD_SEL_1 |
444 		     (0 << CS2000_R_SEL_SHIFT) |
445 		     CS2000_AUX_OUT_SRC_REF_CLK |
446 		     CS2000_EN_DEV_CFG_1);
447 	cs2000_write(chip, CS2000_DEV_CFG_2,
448 		     (0 << CS2000_LOCK_CLK_SHIFT) |
449 		     CS2000_FRAC_N_SRC_STATIC);
450 	cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
451 	cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
452 	cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
453 	cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
454 	cs2000_write(chip, CS2000_FUN_CFG_1,
455 		     data->cs2000_regs[CS2000_FUN_CFG_1]);
456 	cs2000_write(chip, CS2000_FUN_CFG_2, 0);
457 	cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
458 	msleep(3); /* PLL lock delay */
459 }
460 
461 static void xonar_st_init(struct oxygen *chip)
462 {
463 	struct xonar_pcm179x *data = chip->model_data;
464 
465 	data->generic.anti_pop_delay = 100;
466 	data->h6 = chip->model.dac_channels_mixer > 2;
467 	data->has_cs2000 = 1;
468 	data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
469 	data->broken_i2c = true;
470 
471 	oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
472 		       OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
473 		       OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
474 		       OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
475 
476 	xonar_st_init_i2c(chip);
477 	cs2000_registers_init(chip);
478 	xonar_st_init_common(chip);
479 
480 	snd_component_add(chip->card, "CS2000");
481 }
482 
483 static void xonar_stx_init(struct oxygen *chip)
484 {
485 	struct xonar_pcm179x *data = chip->model_data;
486 
487 	xonar_st_init_i2c(chip);
488 	data->generic.anti_pop_delay = 800;
489 	data->generic.ext_power_reg = OXYGEN_GPI_DATA;
490 	data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
491 	data->generic.ext_power_bit = GPI_EXT_POWER;
492 	xonar_init_ext_power(chip);
493 	xonar_st_init_common(chip);
494 }
495 
496 static void xonar_d2_cleanup(struct oxygen *chip)
497 {
498 	xonar_disable_output(chip);
499 }
500 
501 static void xonar_hdav_cleanup(struct oxygen *chip)
502 {
503 	xonar_hdmi_cleanup(chip);
504 	xonar_disable_output(chip);
505 	msleep(2);
506 }
507 
508 static void xonar_st_cleanup(struct oxygen *chip)
509 {
510 	xonar_disable_output(chip);
511 }
512 
513 static void xonar_d2_suspend(struct oxygen *chip)
514 {
515 	xonar_d2_cleanup(chip);
516 }
517 
518 static void xonar_hdav_suspend(struct oxygen *chip)
519 {
520 	xonar_hdav_cleanup(chip);
521 }
522 
523 static void xonar_st_suspend(struct oxygen *chip)
524 {
525 	xonar_st_cleanup(chip);
526 }
527 
528 static void xonar_d2_resume(struct oxygen *chip)
529 {
530 	pcm1796_registers_init(chip);
531 	xonar_enable_output(chip);
532 }
533 
534 static void xonar_hdav_resume(struct oxygen *chip)
535 {
536 	struct xonar_hdav *data = chip->model_data;
537 
538 	pcm1796_registers_init(chip);
539 	xonar_hdmi_resume(chip, &data->hdmi);
540 	xonar_enable_output(chip);
541 }
542 
543 static void xonar_stx_resume(struct oxygen *chip)
544 {
545 	pcm1796_registers_init(chip);
546 	xonar_enable_output(chip);
547 }
548 
549 static void xonar_st_resume(struct oxygen *chip)
550 {
551 	cs2000_registers_init(chip);
552 	xonar_stx_resume(chip);
553 }
554 
555 static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
556 {
557 	struct xonar_pcm179x *data = chip->model_data;
558 
559 	if (rate <= 32000)
560 		return data->h6 ? OXYGEN_I2S_MCLK_256 : OXYGEN_I2S_MCLK_512;
561 	else if (rate <= 48000)
562 		return data->os_128 && !data->h6
563 			? OXYGEN_I2S_MCLK_512 : OXYGEN_I2S_MCLK_256;
564 	else
565 		return OXYGEN_I2S_MCLK_128;
566 }
567 
568 static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
569 					 unsigned int channel,
570 					 struct snd_pcm_hw_params *params)
571 {
572 	if (channel == PCM_MULTICH)
573 		return mclk_from_rate(chip, params_rate(params));
574 	else
575 		return oxygen_default_i2s_mclk(chip, channel, params);
576 }
577 
578 static void update_pcm1796_oversampling(struct oxygen *chip)
579 {
580 	struct xonar_pcm179x *data = chip->model_data;
581 	unsigned int i;
582 	u8 reg;
583 
584 	if (data->current_rate <= 32000 && !data->h6)
585 		reg = PCM1796_OS_128;
586 	else if (data->current_rate <= 48000 && data->os_128 && !data->h6)
587 		reg = PCM1796_OS_128;
588 	else if (data->current_rate <= 96000 || data->os_128)
589 		reg = PCM1796_OS_64;
590 	else
591 		reg = PCM1796_OS_32;
592 	for (i = 0; i < data->dacs; ++i)
593 		pcm1796_write_cached(chip, i, 20, reg);
594 }
595 
596 static void set_pcm1796_params(struct oxygen *chip,
597 			       struct snd_pcm_hw_params *params)
598 {
599 	struct xonar_pcm179x *data = chip->model_data;
600 
601 	msleep(1);
602 	data->current_rate = params_rate(params);
603 	update_pcm1796_oversampling(chip);
604 }
605 
606 static void update_pcm1796_volume(struct oxygen *chip)
607 {
608 	struct xonar_pcm179x *data = chip->model_data;
609 	unsigned int i;
610 	s8 gain_offset;
611 
612 	gain_offset = data->hp_active ? data->hp_gain_offset : 0;
613 	for (i = 0; i < data->dacs; ++i) {
614 		pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
615 				     + gain_offset);
616 		pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
617 				     + gain_offset);
618 	}
619 }
620 
621 static void update_pcm1796_mute(struct oxygen *chip)
622 {
623 	struct xonar_pcm179x *data = chip->model_data;
624 	unsigned int i;
625 	u8 value;
626 
627 	value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
628 	if (chip->dac_mute)
629 		value |= PCM1796_MUTE;
630 	for (i = 0; i < data->dacs; ++i)
631 		pcm1796_write_cached(chip, i, 18, value);
632 }
633 
634 static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
635 {
636 	struct xonar_pcm179x *data = chip->model_data;
637 	u8 rate_mclk, reg;
638 
639 	switch (rate) {
640 	case 32000:
641 		if (data->h6)
642 			rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
643 		else
644 			rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_512;
645 		break;
646 	case 44100:
647 		if (data->os_128 && !data->h6)
648 			rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_512;
649 		else
650 			rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
651 		break;
652 	default: /* 48000 */
653 		if (data->os_128 && !data->h6)
654 			rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_512;
655 		else
656 			rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
657 		break;
658 	case 64000:
659 		rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
660 		break;
661 	case 88200:
662 		rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
663 		break;
664 	case 96000:
665 		rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
666 		break;
667 	case 176400:
668 		rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_512;
669 		break;
670 	case 192000:
671 		rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_512;
672 		break;
673 	}
674 	oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
675 			      OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
676 	if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_256)
677 		reg = CS2000_REF_CLK_DIV_1;
678 	else
679 		reg = CS2000_REF_CLK_DIV_2;
680 	cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
681 	msleep(3); /* PLL lock delay */
682 }
683 
684 static void set_st_params(struct oxygen *chip,
685 			  struct snd_pcm_hw_params *params)
686 {
687 	update_cs2000_rate(chip, params_rate(params));
688 	set_pcm1796_params(chip, params);
689 }
690 
691 static void set_hdav_params(struct oxygen *chip,
692 			    struct snd_pcm_hw_params *params)
693 {
694 	struct xonar_hdav *data = chip->model_data;
695 
696 	set_pcm1796_params(chip, params);
697 	xonar_set_hdmi_params(chip, &data->hdmi, params);
698 }
699 
700 static const struct snd_kcontrol_new alt_switch = {
701 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
702 	.name = "Analog Loopback Switch",
703 	.info = snd_ctl_boolean_mono_info,
704 	.get = xonar_gpio_bit_switch_get,
705 	.put = xonar_gpio_bit_switch_put,
706 	.private_value = GPIO_D2_ALT,
707 };
708 
709 static int rolloff_info(struct snd_kcontrol *ctl,
710 			struct snd_ctl_elem_info *info)
711 {
712 	static const char *const names[2] = {
713 		"Sharp Roll-off", "Slow Roll-off"
714 	};
715 
716 	info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
717 	info->count = 1;
718 	info->value.enumerated.items = 2;
719 	if (info->value.enumerated.item >= 2)
720 		info->value.enumerated.item = 1;
721 	strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
722 	return 0;
723 }
724 
725 static int rolloff_get(struct snd_kcontrol *ctl,
726 		       struct snd_ctl_elem_value *value)
727 {
728 	struct oxygen *chip = ctl->private_data;
729 	struct xonar_pcm179x *data = chip->model_data;
730 
731 	value->value.enumerated.item[0] =
732 		(data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
733 		 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
734 	return 0;
735 }
736 
737 static int rolloff_put(struct snd_kcontrol *ctl,
738 		       struct snd_ctl_elem_value *value)
739 {
740 	struct oxygen *chip = ctl->private_data;
741 	struct xonar_pcm179x *data = chip->model_data;
742 	unsigned int i;
743 	int changed;
744 	u8 reg;
745 
746 	mutex_lock(&chip->mutex);
747 	reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
748 	reg &= ~PCM1796_FLT_MASK;
749 	if (!value->value.enumerated.item[0])
750 		reg |= PCM1796_FLT_SHARP;
751 	else
752 		reg |= PCM1796_FLT_SLOW;
753 	changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
754 	if (changed) {
755 		for (i = 0; i < data->dacs; ++i)
756 			pcm1796_write(chip, i, 19, reg);
757 	}
758 	mutex_unlock(&chip->mutex);
759 	return changed;
760 }
761 
762 static const struct snd_kcontrol_new rolloff_control = {
763 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764 	.name = "DAC Filter Playback Enum",
765 	.info = rolloff_info,
766 	.get = rolloff_get,
767 	.put = rolloff_put,
768 };
769 
770 static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
771 {
772 	static const char *const names[2] = { "64x", "128x" };
773 
774 	info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
775 	info->count = 1;
776 	info->value.enumerated.items = 2;
777 	if (info->value.enumerated.item >= 2)
778 		info->value.enumerated.item = 1;
779 	strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
780 	return 0;
781 }
782 
783 static int os_128_get(struct snd_kcontrol *ctl,
784 		      struct snd_ctl_elem_value *value)
785 {
786 	struct oxygen *chip = ctl->private_data;
787 	struct xonar_pcm179x *data = chip->model_data;
788 
789 	value->value.enumerated.item[0] = data->os_128;
790 	return 0;
791 }
792 
793 static int os_128_put(struct snd_kcontrol *ctl,
794 		      struct snd_ctl_elem_value *value)
795 {
796 	struct oxygen *chip = ctl->private_data;
797 	struct xonar_pcm179x *data = chip->model_data;
798 	int changed;
799 
800 	mutex_lock(&chip->mutex);
801 	changed = value->value.enumerated.item[0] != data->os_128;
802 	if (changed) {
803 		data->os_128 = value->value.enumerated.item[0];
804 		if (data->has_cs2000)
805 			update_cs2000_rate(chip, data->current_rate);
806 		oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
807 				      mclk_from_rate(chip, data->current_rate),
808 				      OXYGEN_I2S_MCLK_MASK);
809 		msleep(1);
810 		update_pcm1796_oversampling(chip);
811 	}
812 	mutex_unlock(&chip->mutex);
813 	return changed;
814 }
815 
816 static const struct snd_kcontrol_new os_128_control = {
817 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
818 	.name = "DAC Oversampling Playback Enum",
819 	.info = os_128_info,
820 	.get = os_128_get,
821 	.put = os_128_put,
822 };
823 
824 static const struct snd_kcontrol_new hdav_hdmi_control = {
825 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
826 	.name = "HDMI Playback Switch",
827 	.info = snd_ctl_boolean_mono_info,
828 	.get = xonar_gpio_bit_switch_get,
829 	.put = xonar_gpio_bit_switch_put,
830 	.private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
831 };
832 
833 static int st_output_switch_info(struct snd_kcontrol *ctl,
834 				 struct snd_ctl_elem_info *info)
835 {
836 	static const char *const names[3] = {
837 		"Speakers", "Headphones", "FP Headphones"
838 	};
839 
840 	info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
841 	info->count = 1;
842 	info->value.enumerated.items = 3;
843 	if (info->value.enumerated.item >= 3)
844 		info->value.enumerated.item = 2;
845 	strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
846 	return 0;
847 }
848 
849 static int st_output_switch_get(struct snd_kcontrol *ctl,
850 				struct snd_ctl_elem_value *value)
851 {
852 	struct oxygen *chip = ctl->private_data;
853 	u16 gpio;
854 
855 	gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
856 	if (!(gpio & GPIO_ST_HP))
857 		value->value.enumerated.item[0] = 0;
858 	else if (gpio & GPIO_ST_HP_REAR)
859 		value->value.enumerated.item[0] = 1;
860 	else
861 		value->value.enumerated.item[0] = 2;
862 	return 0;
863 }
864 
865 
866 static int st_output_switch_put(struct snd_kcontrol *ctl,
867 				struct snd_ctl_elem_value *value)
868 {
869 	struct oxygen *chip = ctl->private_data;
870 	struct xonar_pcm179x *data = chip->model_data;
871 	u16 gpio_old, gpio;
872 
873 	mutex_lock(&chip->mutex);
874 	gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
875 	gpio = gpio_old;
876 	switch (value->value.enumerated.item[0]) {
877 	case 0:
878 		gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
879 		break;
880 	case 1:
881 		gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
882 		break;
883 	case 2:
884 		gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
885 		break;
886 	}
887 	oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
888 	data->hp_active = gpio & GPIO_ST_HP;
889 	update_pcm1796_volume(chip);
890 	mutex_unlock(&chip->mutex);
891 	return gpio != gpio_old;
892 }
893 
894 static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
895 				    struct snd_ctl_elem_info *info)
896 {
897 	static const char *const names[3] = {
898 		"< 64 ohms", "64-300 ohms", "300-600 ohms"
899 	};
900 
901 	info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
902 	info->count = 1;
903 	info->value.enumerated.items = 3;
904 	if (info->value.enumerated.item > 2)
905 		info->value.enumerated.item = 2;
906 	strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
907 	return 0;
908 }
909 
910 static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
911 				   struct snd_ctl_elem_value *value)
912 {
913 	struct oxygen *chip = ctl->private_data;
914 	struct xonar_pcm179x *data = chip->model_data;
915 
916 	mutex_lock(&chip->mutex);
917 	if (data->hp_gain_offset < 2*-6)
918 		value->value.enumerated.item[0] = 0;
919 	else if (data->hp_gain_offset < 0)
920 		value->value.enumerated.item[0] = 1;
921 	else
922 		value->value.enumerated.item[0] = 2;
923 	mutex_unlock(&chip->mutex);
924 	return 0;
925 }
926 
927 
928 static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
929 				   struct snd_ctl_elem_value *value)
930 {
931 	static const s8 offsets[] = { 2*-18, 2*-6, 0 };
932 	struct oxygen *chip = ctl->private_data;
933 	struct xonar_pcm179x *data = chip->model_data;
934 	s8 offset;
935 	int changed;
936 
937 	if (value->value.enumerated.item[0] > 2)
938 		return -EINVAL;
939 	offset = offsets[value->value.enumerated.item[0]];
940 	mutex_lock(&chip->mutex);
941 	changed = offset != data->hp_gain_offset;
942 	if (changed) {
943 		data->hp_gain_offset = offset;
944 		update_pcm1796_volume(chip);
945 	}
946 	mutex_unlock(&chip->mutex);
947 	return changed;
948 }
949 
950 static const struct snd_kcontrol_new st_controls[] = {
951 	{
952 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
953 		.name = "Analog Output",
954 		.info = st_output_switch_info,
955 		.get = st_output_switch_get,
956 		.put = st_output_switch_put,
957 	},
958 	{
959 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
960 		.name = "Headphones Impedance Playback Enum",
961 		.info = st_hp_volume_offset_info,
962 		.get = st_hp_volume_offset_get,
963 		.put = st_hp_volume_offset_put,
964 	},
965 };
966 
967 static void xonar_line_mic_ac97_switch(struct oxygen *chip,
968 				       unsigned int reg, unsigned int mute)
969 {
970 	if (reg == AC97_LINE) {
971 		spin_lock_irq(&chip->reg_lock);
972 		oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
973 				      mute ? GPIO_INPUT_ROUTE : 0,
974 				      GPIO_INPUT_ROUTE);
975 		spin_unlock_irq(&chip->reg_lock);
976 	}
977 }
978 
979 static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
980 
981 static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
982 {
983 	if (!strncmp(template->name, "CD Capture ", 11))
984 		/* CD in is actually connected to the video in pin */
985 		template->private_value ^= AC97_CD ^ AC97_VIDEO;
986 	return 0;
987 }
988 
989 static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
990 {
991 	if (!strncmp(template->name, "Master Playback ", 16))
992 		/* no volume/mute, as I²C to the third DAC does not work */
993 		return 1;
994 	return 0;
995 }
996 
997 static int add_pcm1796_controls(struct oxygen *chip)
998 {
999 	struct xonar_pcm179x *data = chip->model_data;
1000 	int err;
1001 
1002 	if (!data->broken_i2c) {
1003 		err = snd_ctl_add(chip->card,
1004 				  snd_ctl_new1(&rolloff_control, chip));
1005 		if (err < 0)
1006 			return err;
1007 		err = snd_ctl_add(chip->card,
1008 				  snd_ctl_new1(&os_128_control, chip));
1009 		if (err < 0)
1010 			return err;
1011 	}
1012 	return 0;
1013 }
1014 
1015 static int xonar_d2_mixer_init(struct oxygen *chip)
1016 {
1017 	int err;
1018 
1019 	err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
1020 	if (err < 0)
1021 		return err;
1022 	err = add_pcm1796_controls(chip);
1023 	if (err < 0)
1024 		return err;
1025 	return 0;
1026 }
1027 
1028 static int xonar_hdav_mixer_init(struct oxygen *chip)
1029 {
1030 	int err;
1031 
1032 	err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
1033 	if (err < 0)
1034 		return err;
1035 	err = add_pcm1796_controls(chip);
1036 	if (err < 0)
1037 		return err;
1038 	return 0;
1039 }
1040 
1041 static int xonar_st_mixer_init(struct oxygen *chip)
1042 {
1043 	unsigned int i;
1044 	int err;
1045 
1046 	for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
1047 		err = snd_ctl_add(chip->card,
1048 				  snd_ctl_new1(&st_controls[i], chip));
1049 		if (err < 0)
1050 			return err;
1051 	}
1052 	err = add_pcm1796_controls(chip);
1053 	if (err < 0)
1054 		return err;
1055 	return 0;
1056 }
1057 
1058 static void dump_pcm1796_registers(struct oxygen *chip,
1059 				   struct snd_info_buffer *buffer)
1060 {
1061 	struct xonar_pcm179x *data = chip->model_data;
1062 	unsigned int dac, i;
1063 
1064 	for (dac = 0; dac < data->dacs; ++dac) {
1065 		snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
1066 		for (i = 0; i < 5; ++i)
1067 			snd_iprintf(buffer, " %02x",
1068 				    data->pcm1796_regs[dac][i]);
1069 	}
1070 	snd_iprintf(buffer, "\n");
1071 }
1072 
1073 static void dump_cs2000_registers(struct oxygen *chip,
1074 				  struct snd_info_buffer *buffer)
1075 {
1076 	struct xonar_pcm179x *data = chip->model_data;
1077 	unsigned int i;
1078 
1079 	if (data->has_cs2000) {
1080 		snd_iprintf(buffer, "\nCS2000:\n00:   ");
1081 		for (i = 1; i < 0x10; ++i)
1082 			snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1083 		snd_iprintf(buffer, "\n10:");
1084 		for (i = 0x10; i < 0x1f; ++i)
1085 			snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1086 		snd_iprintf(buffer, "\n");
1087 	}
1088 }
1089 
1090 static void dump_st_registers(struct oxygen *chip,
1091 			      struct snd_info_buffer *buffer)
1092 {
1093 	dump_pcm1796_registers(chip, buffer);
1094 	dump_cs2000_registers(chip, buffer);
1095 }
1096 
1097 static const struct oxygen_model model_xonar_d2 = {
1098 	.longname = "Asus Virtuoso 200",
1099 	.chip = "AV200",
1100 	.init = xonar_d2_init,
1101 	.control_filter = xonar_d2_control_filter,
1102 	.mixer_init = xonar_d2_mixer_init,
1103 	.cleanup = xonar_d2_cleanup,
1104 	.suspend = xonar_d2_suspend,
1105 	.resume = xonar_d2_resume,
1106 	.get_i2s_mclk = get_pcm1796_i2s_mclk,
1107 	.set_dac_params = set_pcm1796_params,
1108 	.set_adc_params = xonar_set_cs53x1_params,
1109 	.update_dac_volume = update_pcm1796_volume,
1110 	.update_dac_mute = update_pcm1796_mute,
1111 	.dump_registers = dump_pcm1796_registers,
1112 	.dac_tlv = pcm1796_db_scale,
1113 	.model_data_size = sizeof(struct xonar_pcm179x),
1114 	.device_config = PLAYBACK_0_TO_I2S |
1115 			 PLAYBACK_1_TO_SPDIF |
1116 			 CAPTURE_0_FROM_I2S_2 |
1117 			 CAPTURE_1_FROM_SPDIF |
1118 			 MIDI_OUTPUT |
1119 			 MIDI_INPUT |
1120 			 AC97_CD_INPUT,
1121 	.dac_channels_pcm = 8,
1122 	.dac_channels_mixer = 8,
1123 	.dac_volume_min = 255 - 2*60,
1124 	.dac_volume_max = 255,
1125 	.misc_flags = OXYGEN_MISC_MIDI,
1126 	.function_flags = OXYGEN_FUNCTION_SPI |
1127 			  OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1128 	.dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
1129 	.adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1130 };
1131 
1132 static const struct oxygen_model model_xonar_hdav = {
1133 	.longname = "Asus Virtuoso 200",
1134 	.chip = "AV200",
1135 	.init = xonar_hdav_init,
1136 	.mixer_init = xonar_hdav_mixer_init,
1137 	.cleanup = xonar_hdav_cleanup,
1138 	.suspend = xonar_hdav_suspend,
1139 	.resume = xonar_hdav_resume,
1140 	.pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1141 	.get_i2s_mclk = get_pcm1796_i2s_mclk,
1142 	.set_dac_params = set_hdav_params,
1143 	.set_adc_params = xonar_set_cs53x1_params,
1144 	.update_dac_volume = update_pcm1796_volume,
1145 	.update_dac_mute = update_pcm1796_mute,
1146 	.uart_input = xonar_hdmi_uart_input,
1147 	.ac97_switch = xonar_line_mic_ac97_switch,
1148 	.dump_registers = dump_pcm1796_registers,
1149 	.dac_tlv = pcm1796_db_scale,
1150 	.model_data_size = sizeof(struct xonar_hdav),
1151 	.device_config = PLAYBACK_0_TO_I2S |
1152 			 PLAYBACK_1_TO_SPDIF |
1153 			 CAPTURE_0_FROM_I2S_2 |
1154 			 CAPTURE_1_FROM_SPDIF,
1155 	.dac_channels_pcm = 8,
1156 	.dac_channels_mixer = 2,
1157 	.dac_volume_min = 255 - 2*60,
1158 	.dac_volume_max = 255,
1159 	.misc_flags = OXYGEN_MISC_MIDI,
1160 	.function_flags = OXYGEN_FUNCTION_2WIRE,
1161 	.dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
1162 	.adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1163 };
1164 
1165 static const struct oxygen_model model_xonar_st = {
1166 	.longname = "Asus Virtuoso 100",
1167 	.chip = "AV200",
1168 	.init = xonar_st_init,
1169 	.mixer_init = xonar_st_mixer_init,
1170 	.cleanup = xonar_st_cleanup,
1171 	.suspend = xonar_st_suspend,
1172 	.resume = xonar_st_resume,
1173 	.get_i2s_mclk = get_pcm1796_i2s_mclk,
1174 	.set_dac_params = set_st_params,
1175 	.set_adc_params = xonar_set_cs53x1_params,
1176 	.update_dac_volume = update_pcm1796_volume,
1177 	.update_dac_mute = update_pcm1796_mute,
1178 	.ac97_switch = xonar_line_mic_ac97_switch,
1179 	.dump_registers = dump_st_registers,
1180 	.dac_tlv = pcm1796_db_scale,
1181 	.model_data_size = sizeof(struct xonar_pcm179x),
1182 	.device_config = PLAYBACK_0_TO_I2S |
1183 			 PLAYBACK_1_TO_SPDIF |
1184 			 CAPTURE_0_FROM_I2S_2 |
1185 			 AC97_FMIC_SWITCH,
1186 	.dac_channels_pcm = 2,
1187 	.dac_channels_mixer = 2,
1188 	.dac_volume_min = 255 - 2*60,
1189 	.dac_volume_max = 255,
1190 	.function_flags = OXYGEN_FUNCTION_2WIRE,
1191 	.dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
1192 	.adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1193 };
1194 
1195 int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1196 				      const struct pci_device_id *id)
1197 {
1198 	switch (id->subdevice) {
1199 	case 0x8269:
1200 		chip->model = model_xonar_d2;
1201 		chip->model.shortname = "Xonar D2";
1202 		break;
1203 	case 0x82b7:
1204 		chip->model = model_xonar_d2;
1205 		chip->model.shortname = "Xonar D2X";
1206 		chip->model.init = xonar_d2x_init;
1207 		break;
1208 	case 0x8314:
1209 		chip->model = model_xonar_hdav;
1210 		oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1211 		switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1212 		default:
1213 			chip->model.shortname = "Xonar HDAV1.3";
1214 			break;
1215 		case GPIO_DB_H6:
1216 			chip->model.shortname = "Xonar HDAV1.3+H6";
1217 			chip->model.dac_channels_mixer = 8;
1218 			break;
1219 		}
1220 		break;
1221 	case 0x835d:
1222 		chip->model = model_xonar_st;
1223 		oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1224 		switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1225 		default:
1226 			chip->model.shortname = "Xonar ST";
1227 			break;
1228 		case GPIO_DB_H6:
1229 			chip->model.shortname = "Xonar ST+H6";
1230 			chip->model.control_filter = xonar_st_h6_control_filter;
1231 			chip->model.dac_channels_pcm = 8;
1232 			chip->model.dac_channels_mixer = 8;
1233 			break;
1234 		}
1235 		break;
1236 	case 0x835c:
1237 		chip->model = model_xonar_st;
1238 		chip->model.shortname = "Xonar STX";
1239 		chip->model.init = xonar_stx_init;
1240 		chip->model.resume = xonar_stx_resume;
1241 		chip->model.set_dac_params = set_pcm1796_params;
1242 		break;
1243 	case 0x835e:
1244 		snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");
1245 		return -ENODEV;
1246 	default:
1247 		return -EINVAL;
1248 	}
1249 	return 0;
1250 }
1251