xref: /openbmc/linux/sound/pci/oxygen/xonar_pcm179x.c (revision 6774def6)
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 (II)
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 GPIO_XENSE_OUTPUT_ENABLE	(0x0001 | 0x0010 | 0x0020)
216 #define GPIO_XENSE_SPEAKERS		0x0080
217 
218 #define I2C_DEVICE_PCM1796(i)	(0x98 + ((i) << 1))	/* 10011, ii, /W=0 */
219 #define I2C_DEVICE_CS2000	0x9c			/* 100111, 0, /W=0 */
220 
221 #define PCM1796_REG_BASE	16
222 
223 
224 struct xonar_pcm179x {
225 	struct xonar_generic generic;
226 	unsigned int dacs;
227 	u8 pcm1796_regs[4][5];
228 	unsigned int current_rate;
229 	bool h6;
230 	bool hp_active;
231 	s8 hp_gain_offset;
232 	bool has_cs2000;
233 	u8 cs2000_regs[0x1f];
234 	bool broken_i2c;
235 };
236 
237 struct xonar_hdav {
238 	struct xonar_pcm179x pcm179x;
239 	struct xonar_hdmi hdmi;
240 };
241 
242 
243 static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
244 				     u8 reg, u8 value)
245 {
246 	/* maps ALSA channel pair number to SPI output */
247 	static const u8 codec_map[4] = {
248 		0, 1, 2, 4
249 	};
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,
255 			 (reg << 8) | value);
256 }
257 
258 static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
259 				     u8 reg, u8 value)
260 {
261 	oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
262 }
263 
264 static void pcm1796_write(struct oxygen *chip, unsigned int codec,
265 			  u8 reg, u8 value)
266 {
267 	struct xonar_pcm179x *data = chip->model_data;
268 
269 	if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
270 	    OXYGEN_FUNCTION_SPI)
271 		pcm1796_write_spi(chip, codec, reg, value);
272 	else
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;
277 }
278 
279 static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
280 				 u8 reg, u8 value)
281 {
282 	struct xonar_pcm179x *data = chip->model_data;
283 
284 	if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
285 		pcm1796_write(chip, codec, reg, value);
286 }
287 
288 static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
289 {
290 	struct xonar_pcm179x *data = chip->model_data;
291 
292 	oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
293 	data->cs2000_regs[reg] = value;
294 }
295 
296 static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
297 {
298 	struct xonar_pcm179x *data = chip->model_data;
299 
300 	if (value != data->cs2000_regs[reg])
301 		cs2000_write(chip, reg, value);
302 }
303 
304 static void pcm1796_registers_init(struct oxygen *chip)
305 {
306 	struct xonar_pcm179x *data = chip->model_data;
307 	unsigned int i;
308 	s8 gain_offset;
309 
310 	msleep(1);
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]
317 			      + gain_offset);
318 		pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
319 			      + gain_offset);
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);
325 		gain_offset = 0;
326 	}
327 }
328 
329 static void pcm1796_init(struct oxygen *chip)
330 {
331 	struct xonar_pcm179x *data = chip->model_data;
332 
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;
343 }
344 
345 static void xonar_d2_init(struct oxygen *chip)
346 {
347 	struct xonar_pcm179x *data = chip->model_data;
348 
349 	data->generic.anti_pop_delay = 300;
350 	data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
351 	data->dacs = 4;
352 
353 	pcm1796_init(chip);
354 
355 	oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
356 	oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
357 
358 	oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
359 
360 	xonar_init_cs53x1(chip);
361 	xonar_enable_output(chip);
362 
363 	snd_component_add(chip->card, "PCM1796");
364 	snd_component_add(chip->card, "CS5381");
365 }
366 
367 static void xonar_d2x_init(struct oxygen *chip)
368 {
369 	struct xonar_pcm179x *data = chip->model_data;
370 
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);
376 	xonar_d2_init(chip);
377 }
378 
379 static void xonar_hdav_init(struct oxygen *chip)
380 {
381 	struct xonar_hdav *data = chip->model_data;
382 
383 	oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
384 		       OXYGEN_2WIRE_LENGTH_8 |
385 		       OXYGEN_2WIRE_INTERRUPT_MASK |
386 		       OXYGEN_2WIRE_SPEED_STANDARD);
387 
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;
395 
396 	pcm1796_init(chip);
397 
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);
401 
402 	xonar_init_cs53x1(chip);
403 	xonar_init_ext_power(chip);
404 	xonar_hdmi_init(chip, &data->hdmi);
405 	xonar_enable_output(chip);
406 
407 	snd_component_add(chip->card, "PCM1796");
408 	snd_component_add(chip->card, "CS5381");
409 }
410 
411 static void xonar_st_init_i2c(struct oxygen *chip)
412 {
413 	oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
414 		       OXYGEN_2WIRE_LENGTH_8 |
415 		       OXYGEN_2WIRE_INTERRUPT_MASK |
416 		       OXYGEN_2WIRE_SPEED_STANDARD);
417 }
418 
419 static void xonar_st_init_common(struct oxygen *chip)
420 {
421 	struct xonar_pcm179x *data = chip->model_data;
422 
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;
427 
428 	pcm1796_init(chip);
429 
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);
435 
436 	xonar_init_cs53x1(chip);
437 	xonar_enable_output(chip);
438 
439 	snd_component_add(chip->card, "PCM1792A");
440 	snd_component_add(chip->card, "CS5381");
441 }
442 
443 static void cs2000_registers_init(struct oxygen *chip)
444 {
445 	struct xonar_pcm179x *data = chip->model_data;
446 
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,
450 		     CS2000_R_MOD_SEL_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 */
466 }
467 
468 static void xonar_st_init(struct oxygen *chip)
469 {
470 	struct xonar_pcm179x *data = chip->model_data;
471 
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;
477 
478 	oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
479 		       OXYGEN_RATE_48000 |
480 		       OXYGEN_I2S_FORMAT_I2S |
481 		       OXYGEN_I2S_MCLK(data->h6 ? MCLK_256 : MCLK_512) |
482 		       OXYGEN_I2S_BITS_16 |
483 		       OXYGEN_I2S_MASTER |
484 		       OXYGEN_I2S_BCLK_64);
485 
486 	xonar_st_init_i2c(chip);
487 	cs2000_registers_init(chip);
488 	xonar_st_init_common(chip);
489 
490 	snd_component_add(chip->card, "CS2000");
491 }
492 
493 static void xonar_stx_init(struct oxygen *chip)
494 {
495 	struct xonar_pcm179x *data = chip->model_data;
496 
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);
504 }
505 
506 static void xonar_xense_init(struct oxygen *chip)
507 {
508 	struct xonar_pcm179x *data = chip->model_data;
509 
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);
514 
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;
518 
519 	oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
520 		OXYGEN_RATE_48000 |
521 		OXYGEN_I2S_FORMAT_I2S |
522 		OXYGEN_I2S_MCLK(MCLK_512) |
523 		OXYGEN_I2S_BITS_16 |
524 		OXYGEN_I2S_MASTER |
525 		OXYGEN_I2S_BCLK_64);
526 
527 	xonar_st_init_i2c(chip);
528 	cs2000_registers_init(chip);
529 
530 	data->generic.output_enable_bit = GPIO_XENSE_OUTPUT_ENABLE;
531 	data->dacs = 1;
532 	data->hp_gain_offset = 2*-18;
533 
534 	pcm1796_init(chip);
535 
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);
542 
543 	xonar_init_cs53x1(chip);
544 	xonar_enable_output(chip);
545 
546 	snd_component_add(chip->card, "PCM1796");
547 	snd_component_add(chip->card, "CS5381");
548 	snd_component_add(chip->card, "CS2000");
549 }
550 
551 static void xonar_d2_cleanup(struct oxygen *chip)
552 {
553 	xonar_disable_output(chip);
554 }
555 
556 static void xonar_hdav_cleanup(struct oxygen *chip)
557 {
558 	xonar_hdmi_cleanup(chip);
559 	xonar_disable_output(chip);
560 	msleep(2);
561 }
562 
563 static void xonar_st_cleanup(struct oxygen *chip)
564 {
565 	xonar_disable_output(chip);
566 }
567 
568 static void xonar_d2_suspend(struct oxygen *chip)
569 {
570 	xonar_d2_cleanup(chip);
571 }
572 
573 static void xonar_hdav_suspend(struct oxygen *chip)
574 {
575 	xonar_hdav_cleanup(chip);
576 }
577 
578 static void xonar_st_suspend(struct oxygen *chip)
579 {
580 	xonar_st_cleanup(chip);
581 }
582 
583 static void xonar_d2_resume(struct oxygen *chip)
584 {
585 	pcm1796_registers_init(chip);
586 	xonar_enable_output(chip);
587 }
588 
589 static void xonar_hdav_resume(struct oxygen *chip)
590 {
591 	struct xonar_hdav *data = chip->model_data;
592 
593 	pcm1796_registers_init(chip);
594 	xonar_hdmi_resume(chip, &data->hdmi);
595 	xonar_enable_output(chip);
596 }
597 
598 static void xonar_stx_resume(struct oxygen *chip)
599 {
600 	pcm1796_registers_init(chip);
601 	xonar_enable_output(chip);
602 }
603 
604 static void xonar_st_resume(struct oxygen *chip)
605 {
606 	cs2000_registers_init(chip);
607 	xonar_stx_resume(chip);
608 }
609 
610 static void update_pcm1796_oversampling(struct oxygen *chip)
611 {
612 	struct xonar_pcm179x *data = chip->model_data;
613 	unsigned int i;
614 	u8 reg;
615 
616 	if (data->current_rate <= 48000 && !data->h6)
617 		reg = PCM1796_OS_128;
618 	else
619 		reg = PCM1796_OS_64;
620 	for (i = 0; i < data->dacs; ++i)
621 		pcm1796_write_cached(chip, i, 20, reg);
622 }
623 
624 static void set_pcm1796_params(struct oxygen *chip,
625 			       struct snd_pcm_hw_params *params)
626 {
627 	struct xonar_pcm179x *data = chip->model_data;
628 
629 	msleep(1);
630 	data->current_rate = params_rate(params);
631 	update_pcm1796_oversampling(chip);
632 }
633 
634 static void update_pcm1796_volume(struct oxygen *chip)
635 {
636 	struct xonar_pcm179x *data = chip->model_data;
637 	unsigned int i;
638 	s8 gain_offset;
639 
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]
643 				     + gain_offset);
644 		pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
645 				     + gain_offset);
646 		gain_offset = 0;
647 	}
648 }
649 
650 static void update_pcm1796_mute(struct oxygen *chip)
651 {
652 	struct xonar_pcm179x *data = chip->model_data;
653 	unsigned int i;
654 	u8 value;
655 
656 	value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
657 	if (chip->dac_mute)
658 		value |= PCM1796_MUTE;
659 	for (i = 0; i < data->dacs; ++i)
660 		pcm1796_write_cached(chip, i, 18, value);
661 }
662 
663 static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
664 {
665 	struct xonar_pcm179x *data = chip->model_data;
666 	u8 rate_mclk, reg;
667 
668 	switch (rate) {
669 	case 32000:
670 	case 64000:
671 		rate_mclk = OXYGEN_RATE_32000;
672 		break;
673 	case 44100:
674 	case 88200:
675 	case 176400:
676 		rate_mclk = OXYGEN_RATE_44100;
677 		break;
678 	default:
679 	case 48000:
680 	case 96000:
681 	case 192000:
682 		rate_mclk = OXYGEN_RATE_48000;
683 		break;
684 	}
685 
686 	if (rate <= 96000 && (rate > 48000 || data->h6)) {
687 		rate_mclk |= OXYGEN_I2S_MCLK(MCLK_256);
688 		reg = CS2000_REF_CLK_DIV_1;
689 	} else {
690 		rate_mclk |= OXYGEN_I2S_MCLK(MCLK_512);
691 		reg = CS2000_REF_CLK_DIV_2;
692 	}
693 
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 */
698 }
699 
700 static void set_st_params(struct oxygen *chip,
701 			  struct snd_pcm_hw_params *params)
702 {
703 	update_cs2000_rate(chip, params_rate(params));
704 	set_pcm1796_params(chip, params);
705 }
706 
707 static void set_hdav_params(struct oxygen *chip,
708 			    struct snd_pcm_hw_params *params)
709 {
710 	struct xonar_hdav *data = chip->model_data;
711 
712 	set_pcm1796_params(chip, params);
713 	xonar_set_hdmi_params(chip, &data->hdmi, params);
714 }
715 
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,
723 };
724 
725 static int rolloff_info(struct snd_kcontrol *ctl,
726 			struct snd_ctl_elem_info *info)
727 {
728 	static const char *const names[2] = {
729 		"Sharp Roll-off", "Slow Roll-off"
730 	};
731 
732 	return snd_ctl_enum_info(info, 1, 2, names);
733 }
734 
735 static int rolloff_get(struct snd_kcontrol *ctl,
736 		       struct snd_ctl_elem_value *value)
737 {
738 	struct oxygen *chip = ctl->private_data;
739 	struct xonar_pcm179x *data = chip->model_data;
740 
741 	value->value.enumerated.item[0] =
742 		(data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
743 		 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
744 	return 0;
745 }
746 
747 static int rolloff_put(struct snd_kcontrol *ctl,
748 		       struct snd_ctl_elem_value *value)
749 {
750 	struct oxygen *chip = ctl->private_data;
751 	struct xonar_pcm179x *data = chip->model_data;
752 	unsigned int i;
753 	int changed;
754 	u8 reg;
755 
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;
761 	else
762 		reg |= PCM1796_FLT_SLOW;
763 	changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
764 	if (changed) {
765 		for (i = 0; i < data->dacs; ++i)
766 			pcm1796_write(chip, i, 19, reg);
767 	}
768 	mutex_unlock(&chip->mutex);
769 	return changed;
770 }
771 
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,
776 	.get = rolloff_get,
777 	.put = rolloff_put,
778 };
779 
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,
787 };
788 
789 static int st_output_switch_info(struct snd_kcontrol *ctl,
790 				 struct snd_ctl_elem_info *info)
791 {
792 	static const char *const names[3] = {
793 		"Speakers", "Headphones", "FP Headphones"
794 	};
795 
796 	return snd_ctl_enum_info(info, 1, 3, names);
797 }
798 
799 static int st_output_switch_get(struct snd_kcontrol *ctl,
800 				struct snd_ctl_elem_value *value)
801 {
802 	struct oxygen *chip = ctl->private_data;
803 	u16 gpio;
804 
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;
810 	else
811 		value->value.enumerated.item[0] = 2;
812 	return 0;
813 }
814 
815 
816 static int st_output_switch_put(struct snd_kcontrol *ctl,
817 				struct snd_ctl_elem_value *value)
818 {
819 	struct oxygen *chip = ctl->private_data;
820 	struct xonar_pcm179x *data = chip->model_data;
821 	u16 gpio_old, gpio;
822 
823 	mutex_lock(&chip->mutex);
824 	gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
825 	gpio = gpio_old;
826 	switch (value->value.enumerated.item[0]) {
827 	case 0:
828 		gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
829 		break;
830 	case 1:
831 		gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
832 		break;
833 	case 2:
834 		gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
835 		break;
836 	}
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;
842 }
843 
844 static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
845 				    struct snd_ctl_elem_info *info)
846 {
847 	static const char *const names[4] = {
848 		"< 32 ohms", "32-64 ohms", "64-300 ohms", "300-600 ohms"
849 	};
850 
851 	return snd_ctl_enum_info(info, 1, 4, names);
852 }
853 
854 static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
855 				   struct snd_ctl_elem_value *value)
856 {
857 	struct oxygen *chip = ctl->private_data;
858 	struct xonar_pcm179x *data = chip->model_data;
859 
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;
867 	else
868 		value->value.enumerated.item[0] = 3;
869 	mutex_unlock(&chip->mutex);
870 	return 0;
871 }
872 
873 
874 static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
875 				   struct snd_ctl_elem_value *value)
876 {
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;
880 	s8 offset;
881 	int changed;
882 
883 	if (value->value.enumerated.item[0] > 3)
884 		return -EINVAL;
885 	offset = offsets[value->value.enumerated.item[0]];
886 	mutex_lock(&chip->mutex);
887 	changed = offset != data->hp_gain_offset;
888 	if (changed) {
889 		data->hp_gain_offset = offset;
890 		update_pcm1796_volume(chip);
891 	}
892 	mutex_unlock(&chip->mutex);
893 	return changed;
894 }
895 
896 static const struct snd_kcontrol_new st_controls[] = {
897 	{
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,
903 	},
904 	{
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,
910 	},
911 };
912 
913 static int xense_output_switch_get(struct snd_kcontrol *ctl,
914 				   struct snd_ctl_elem_value *value)
915 {
916 	struct oxygen *chip = ctl->private_data;
917 	u16 gpio;
918 
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;
924 	else
925 		value->value.enumerated.item[0] = 2;
926 	return 0;
927 }
928 
929 static int xense_output_switch_put(struct snd_kcontrol *ctl,
930 				   struct snd_ctl_elem_value *value)
931 {
932 	struct oxygen *chip = ctl->private_data;
933 	struct xonar_pcm179x *data = chip->model_data;
934 	u16 gpio_old, gpio;
935 
936 	mutex_lock(&chip->mutex);
937 	gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
938 	gpio = gpio_old;
939 	switch (value->value.enumerated.item[0]) {
940 	case 0:
941 		gpio |= GPIO_XENSE_SPEAKERS | GPIO_ST_HP_REAR;
942 		break;
943 	case 1:
944 		gpio = (gpio | GPIO_ST_HP_REAR) & ~GPIO_XENSE_SPEAKERS;
945 		break;
946 	case 2:
947 		gpio &= ~(GPIO_XENSE_SPEAKERS | GPIO_ST_HP_REAR);
948 		break;
949 	}
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;
955 }
956 
957 static const struct snd_kcontrol_new xense_controls[] = {
958 	{
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,
964 	},
965 	{
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,
971 	},
972 };
973 
974 static void xonar_line_mic_ac97_switch(struct oxygen *chip,
975 				       unsigned int reg, unsigned int mute)
976 {
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,
981 				      GPIO_INPUT_ROUTE);
982 		spin_unlock_irq(&chip->reg_lock);
983 	}
984 }
985 
986 static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
987 
988 static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
989 {
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;
993 	return 0;
994 }
995 
996 static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
997 {
998 	if (!strncmp(template->name, "Master Playback ", 16))
999 		/* no volume/mute, as I²C to the third DAC does not work */
1000 		return 1;
1001 	return 0;
1002 }
1003 
1004 static int add_pcm1796_controls(struct oxygen *chip)
1005 {
1006 	struct xonar_pcm179x *data = chip->model_data;
1007 	int err;
1008 
1009 	if (!data->broken_i2c) {
1010 		err = snd_ctl_add(chip->card,
1011 				  snd_ctl_new1(&rolloff_control, chip));
1012 		if (err < 0)
1013 			return err;
1014 	}
1015 	return 0;
1016 }
1017 
1018 static int xonar_d2_mixer_init(struct oxygen *chip)
1019 {
1020 	int err;
1021 
1022 	err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
1023 	if (err < 0)
1024 		return err;
1025 	err = add_pcm1796_controls(chip);
1026 	if (err < 0)
1027 		return err;
1028 	return 0;
1029 }
1030 
1031 static int xonar_hdav_mixer_init(struct oxygen *chip)
1032 {
1033 	int err;
1034 
1035 	err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
1036 	if (err < 0)
1037 		return err;
1038 	err = add_pcm1796_controls(chip);
1039 	if (err < 0)
1040 		return err;
1041 	return 0;
1042 }
1043 
1044 static int xonar_st_mixer_init(struct oxygen *chip)
1045 {
1046 	unsigned int i;
1047 	int err;
1048 
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));
1052 		if (err < 0)
1053 			return err;
1054 	}
1055 	err = add_pcm1796_controls(chip);
1056 	if (err < 0)
1057 		return err;
1058 	return 0;
1059 }
1060 
1061 static int xonar_xense_mixer_init(struct oxygen *chip)
1062 {
1063 	unsigned int i;
1064 	int err;
1065 
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));
1069 		if (err < 0)
1070 			return err;
1071 	}
1072 	err = add_pcm1796_controls(chip);
1073 	if (err < 0)
1074 		return err;
1075 	return 0;
1076 }
1077 
1078 static void dump_pcm1796_registers(struct oxygen *chip,
1079 				   struct snd_info_buffer *buffer)
1080 {
1081 	struct xonar_pcm179x *data = chip->model_data;
1082 	unsigned int dac, i;
1083 
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]);
1089 	}
1090 	snd_iprintf(buffer, "\n");
1091 }
1092 
1093 static void dump_cs2000_registers(struct oxygen *chip,
1094 				  struct snd_info_buffer *buffer)
1095 {
1096 	struct xonar_pcm179x *data = chip->model_data;
1097 	unsigned int i;
1098 
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");
1107 	}
1108 }
1109 
1110 static void dump_st_registers(struct oxygen *chip,
1111 			      struct snd_info_buffer *buffer)
1112 {
1113 	dump_pcm1796_registers(chip, buffer);
1114 	dump_cs2000_registers(chip, buffer);
1115 }
1116 
1117 static const struct oxygen_model model_xonar_d2 = {
1118 	.longname = "Asus Virtuoso 200",
1119 	.chip = "AV200",
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 |
1137 			 MIDI_OUTPUT |
1138 			 MIDI_INPUT |
1139 			 AC97_CD_INPUT,
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,
1151 };
1152 
1153 static const struct oxygen_model model_xonar_hdav = {
1154 	.longname = "Asus Virtuoso 200",
1155 	.chip = "AV200",
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,
1185 };
1186 
1187 static const struct oxygen_model model_xonar_st = {
1188 	.longname = "Asus Virtuoso 100",
1189 	.chip = "AV200",
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 |
1207 			 AC97_FMIC_SWITCH,
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,
1217 };
1218 
1219 int get_xonar_pcm179x_model(struct oxygen *chip,
1220 			    const struct pci_device_id *id)
1221 {
1222 	switch (id->subdevice) {
1223 	case 0x8269:
1224 		chip->model = model_xonar_d2;
1225 		chip->model.shortname = "Xonar D2";
1226 		break;
1227 	case 0x82b7:
1228 		chip->model = model_xonar_d2;
1229 		chip->model.shortname = "Xonar D2X";
1230 		chip->model.init = xonar_d2x_init;
1231 		break;
1232 	case 0x8314:
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) {
1236 		default:
1237 			chip->model.shortname = "Xonar HDAV1.3";
1238 			break;
1239 		case GPIO_DB_H6:
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);
1243 			break;
1244 		}
1245 		break;
1246 	case 0x835d:
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) {
1250 		default:
1251 			chip->model.shortname = "Xonar ST";
1252 			break;
1253 		case GPIO_DB_H6:
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);
1260 			break;
1261 		}
1262 		break;
1263 	case 0x835c:
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;
1269 		break;
1270 	case 0x85f4:
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) {
1274 		default:
1275 			chip->model.shortname = "Xonar STX II";
1276 			break;
1277 		case GPIO_DB_H6:
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);
1282 			break;
1283 		}
1284 		chip->model.init = xonar_stx_init;
1285 		chip->model.resume = xonar_stx_resume;
1286 		chip->model.set_dac_params = set_pcm1796_params;
1287 		break;
1288 	case 0x8428:
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;
1294 		break;
1295 	default:
1296 		return -EINVAL;
1297 	}
1298 	return 0;
1299 }
1300