blob: 3850834f989c64558d99ba4e70a5f8ab4a423544 [file] [log] [blame]
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001/*
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
Clemens Ladischdc0adf42009-09-28 11:17:36 +020035 *
36 * CM9780:
37 *
38 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020039 */
40
41/*
42 * Xonar HDAV1.3 (Deluxe)
43 * ----------------------
44 *
45 * CMI8788:
46 *
47 * I²C <-> PCM1796 (front)
48 *
49 * GPI 0 <- external power present
50 *
51 * GPIO 0 -> enable output to speakers
52 * GPIO 2 -> M0 of CS5381
53 * GPIO 3 -> M1 of CS5381
54 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
55 *
56 * TXD -> HDMI controller
57 * RXD <- HDMI controller
58 *
59 * PCM1796 front: AD1,0 <- 0,0
60 *
Clemens Ladischdc0adf42009-09-28 11:17:36 +020061 * CM9780:
62 *
63 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
64 *
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020065 * no daughterboard
66 * ----------------
67 *
68 * GPIO 4 <- 1
69 *
70 * H6 daughterboard
71 * ----------------
72 *
73 * GPIO 4 <- 0
74 * GPIO 5 <- 0
75 *
76 * I²C <-> PCM1796 (surround)
77 * <-> PCM1796 (center/LFE)
78 * <-> PCM1796 (back)
79 *
80 * PCM1796 surround: AD1,0 <- 0,1
81 * PCM1796 center/LFE: AD1,0 <- 1,0
82 * PCM1796 back: AD1,0 <- 1,1
83 *
84 * unknown daughterboard
85 * ---------------------
86 *
87 * GPIO 4 <- 0
88 * GPIO 5 <- 1
89 *
90 * I²C <-> CS4362A (surround, center/LFE, back)
91 *
92 * CS4362A: AD0 <- 0
93 */
94
95/*
96 * Xonar Essence ST (Deluxe)/STX
97 * -----------------------------
98 *
99 * CMI8788:
100 *
101 * I²C <-> PCM1792A
Clemens Ladisch268304f2009-09-28 11:15:01 +0200102 * <-> CS2000 (ST only)
103 *
104 * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200105 *
106 * GPI 0 <- external power present (STX only)
107 *
108 * GPIO 0 -> enable output to speakers
109 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
110 * GPIO 2 -> M0 of CS5381
111 * GPIO 3 -> M1 of CS5381
112 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
113 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
114 *
115 * PCM1792A:
116 *
117 * AD1,0 <- 0,0
Clemens Ladischdc0adf42009-09-28 11:17:36 +0200118 * SCK <- CLK_OUT of CS2000 (ST only)
119 *
120 * CS2000:
121 *
122 * AD0 <- 0
123 *
124 * CM9780:
125 *
126 * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200127 *
128 * H6 daughterboard
129 * ----------------
130 *
131 * GPIO 4 <- 0
132 * GPIO 5 <- 0
133 */
134
Clemens Ladisch2b830ba2010-10-04 13:22:51 +0200135/*
136 * Xonar HDAV1.3 Slim
137 * ------------------
138 *
139 * CMI8788:
140 *
141 * GPIO 1 -> enable output
142 *
143 * TXD -> HDMI controller
144 * RXD <- HDMI controller
145 */
146
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200147#include <linux/pci.h>
148#include <linux/delay.h>
149#include <linux/mutex.h>
150#include <sound/ac97_codec.h>
151#include <sound/control.h>
152#include <sound/core.h>
153#include <sound/pcm.h>
154#include <sound/pcm_params.h>
155#include <sound/tlv.h>
156#include "xonar.h"
157#include "cm9780.h"
158#include "pcm1796.h"
Clemens Ladisch268304f2009-09-28 11:15:01 +0200159#include "cs2000.h"
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200160
161
162#define GPIO_D2X_EXT_POWER 0x0020
163#define GPIO_D2_ALT 0x0080
164#define GPIO_D2_OUTPUT_ENABLE 0x0100
165
166#define GPI_EXT_POWER 0x01
167#define GPIO_INPUT_ROUTE 0x0100
168
169#define GPIO_HDAV_OUTPUT_ENABLE 0x0001
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100170#define GPIO_HDAV_MAGIC 0x00c0
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200171
172#define GPIO_DB_MASK 0x0030
173#define GPIO_DB_H6 0x0000
174
175#define GPIO_ST_OUTPUT_ENABLE 0x0001
176#define GPIO_ST_HP_REAR 0x0002
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100177#define GPIO_ST_MAGIC 0x0040
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200178#define GPIO_ST_HP 0x0080
179
180#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200181#define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200182
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200183#define PCM1796_REG_BASE 16
184
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200185
186struct xonar_pcm179x {
187 struct xonar_generic generic;
188 unsigned int dacs;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200189 u8 pcm1796_regs[4][5];
Clemens Ladisch973dca92009-09-28 11:20:47 +0200190 unsigned int current_rate;
191 bool os_128;
Clemens Ladischa361e242009-09-28 11:19:19 +0200192 bool hp_active;
193 s8 hp_gain_offset;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200194 bool has_cs2000;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200195 u8 cs2000_fun_cfg_1;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200196};
197
198struct xonar_hdav {
199 struct xonar_pcm179x pcm179x;
200 struct xonar_hdmi hdmi;
201};
202
203
204static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
205 u8 reg, u8 value)
206{
207 /* maps ALSA channel pair number to SPI output */
208 static const u8 codec_map[4] = {
209 0, 1, 2, 4
210 };
211 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
212 OXYGEN_SPI_DATA_LENGTH_2 |
213 OXYGEN_SPI_CLOCK_160 |
214 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
215 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
216 (reg << 8) | value);
217}
218
219static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
220 u8 reg, u8 value)
221{
222 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
223}
224
225static void pcm1796_write(struct oxygen *chip, unsigned int codec,
226 u8 reg, u8 value)
227{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200228 struct xonar_pcm179x *data = chip->model_data;
229
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200230 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
231 OXYGEN_FUNCTION_SPI)
232 pcm1796_write_spi(chip, codec, reg, value);
233 else
234 pcm1796_write_i2c(chip, codec, reg, value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200235 if ((unsigned int)(reg - PCM1796_REG_BASE)
236 < ARRAY_SIZE(data->pcm1796_regs[codec]))
237 data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
238}
239
240static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
241 u8 reg, u8 value)
242{
243 struct xonar_pcm179x *data = chip->model_data;
244
245 if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
246 pcm1796_write(chip, codec, reg, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200247}
248
Clemens Ladisch268304f2009-09-28 11:15:01 +0200249static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
250{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200251 struct xonar_pcm179x *data = chip->model_data;
252
Clemens Ladisch268304f2009-09-28 11:15:01 +0200253 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200254 if (reg == CS2000_FUN_CFG_1)
255 data->cs2000_fun_cfg_1 = value;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200256}
257
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200258static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
259{
260 struct xonar_pcm179x *data = chip->model_data;
261
262 if (reg != CS2000_FUN_CFG_1 ||
263 value != data->cs2000_fun_cfg_1)
264 cs2000_write(chip, reg, value);
265}
266
267static void pcm1796_registers_init(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200268{
269 struct xonar_pcm179x *data = chip->model_data;
270 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200271 s8 gain_offset;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200272
Clemens Ladischa361e242009-09-28 11:19:19 +0200273 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200274 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200275 /* set ATLD before ATL/ATR */
276 pcm1796_write(chip, i, 18,
277 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
Clemens Ladischa361e242009-09-28 11:19:19 +0200278 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
279 + gain_offset);
280 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
281 + gain_offset);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200282 pcm1796_write(chip, i, 19,
283 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200284 pcm1796_write(chip, i, 20,
285 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
286 pcm1796_write(chip, i, 21, 0);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200287 }
288}
289
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200290static void pcm1796_init(struct oxygen *chip)
291{
292 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200293
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200294 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
295 PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200296 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
297 PCM1796_FLT_SHARP | PCM1796_ATS_1;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200298 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
299 pcm1796_registers_init(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200300 data->current_rate = 48000;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200301}
302
303static void xonar_d2_init(struct oxygen *chip)
304{
305 struct xonar_pcm179x *data = chip->model_data;
306
307 data->generic.anti_pop_delay = 300;
308 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
309 data->dacs = 4;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200310
311 pcm1796_init(chip);
312
313 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
314 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
315
316 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
317
318 xonar_init_cs53x1(chip);
319 xonar_enable_output(chip);
320
321 snd_component_add(chip->card, "PCM1796");
322 snd_component_add(chip->card, "CS5381");
323}
324
325static void xonar_d2x_init(struct oxygen *chip)
326{
327 struct xonar_pcm179x *data = chip->model_data;
328
329 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
330 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
331 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
332 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
333 xonar_init_ext_power(chip);
334 xonar_d2_init(chip);
335}
336
337static void xonar_hdav_init(struct oxygen *chip)
338{
339 struct xonar_hdav *data = chip->model_data;
340
341 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
342 OXYGEN_2WIRE_LENGTH_8 |
343 OXYGEN_2WIRE_INTERRUPT_MASK |
344 OXYGEN_2WIRE_SPEED_FAST);
345
346 data->pcm179x.generic.anti_pop_delay = 100;
347 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
348 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
349 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
350 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
351 data->pcm179x.dacs = chip->model.private_data ? 4 : 1;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200352
353 pcm1796_init(chip);
354
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100355 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
356 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200357 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
358
359 xonar_init_cs53x1(chip);
360 xonar_init_ext_power(chip);
361 xonar_hdmi_init(chip, &data->hdmi);
362 xonar_enable_output(chip);
363
364 snd_component_add(chip->card, "PCM1796");
365 snd_component_add(chip->card, "CS5381");
366}
367
Clemens Ladisch268304f2009-09-28 11:15:01 +0200368static void xonar_st_init_i2c(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200369{
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200370 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
371 OXYGEN_2WIRE_LENGTH_8 |
372 OXYGEN_2WIRE_INTERRUPT_MASK |
373 OXYGEN_2WIRE_SPEED_FAST);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200374}
375
376static void xonar_st_init_common(struct oxygen *chip)
377{
378 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200379
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200380 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
381 data->dacs = chip->model.private_data ? 4 : 1;
Clemens Ladischa361e242009-09-28 11:19:19 +0200382 data->hp_gain_offset = 2*-18;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200383
384 pcm1796_init(chip);
385
386 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100387 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
388 GPIO_ST_MAGIC | GPIO_ST_HP);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200389 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
390 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
391
392 xonar_init_cs53x1(chip);
393 xonar_enable_output(chip);
394
395 snd_component_add(chip->card, "PCM1792A");
396 snd_component_add(chip->card, "CS5381");
397}
398
Clemens Ladisch268304f2009-09-28 11:15:01 +0200399static void cs2000_registers_init(struct oxygen *chip)
400{
401 struct xonar_pcm179x *data = chip->model_data;
402
403 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
404 cs2000_write(chip, CS2000_DEV_CTRL, 0);
405 cs2000_write(chip, CS2000_DEV_CFG_1,
406 CS2000_R_MOD_SEL_1 |
407 (0 << CS2000_R_SEL_SHIFT) |
408 CS2000_AUX_OUT_SRC_REF_CLK |
409 CS2000_EN_DEV_CFG_1);
410 cs2000_write(chip, CS2000_DEV_CFG_2,
411 (0 << CS2000_LOCK_CLK_SHIFT) |
412 CS2000_FRAC_N_SRC_STATIC);
413 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
414 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
415 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
416 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
417 cs2000_write(chip, CS2000_FUN_CFG_1, data->cs2000_fun_cfg_1);
418 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
419 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
420}
421
422static void xonar_st_init(struct oxygen *chip)
423{
424 struct xonar_pcm179x *data = chip->model_data;
425
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200426 data->generic.anti_pop_delay = 100;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200427 data->has_cs2000 = 1;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200428 data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_1;
429
430 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
431 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
432 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
433 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
434
435 xonar_st_init_i2c(chip);
436 cs2000_registers_init(chip);
437 xonar_st_init_common(chip);
438
439 snd_component_add(chip->card, "CS2000");
440}
441
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200442static void xonar_stx_init(struct oxygen *chip)
443{
444 struct xonar_pcm179x *data = chip->model_data;
445
Clemens Ladisch268304f2009-09-28 11:15:01 +0200446 xonar_st_init_i2c(chip);
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200447 data->generic.anti_pop_delay = 800;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200448 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
449 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
450 data->generic.ext_power_bit = GPI_EXT_POWER;
451 xonar_init_ext_power(chip);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200452 xonar_st_init_common(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200453}
454
455static void xonar_d2_cleanup(struct oxygen *chip)
456{
457 xonar_disable_output(chip);
458}
459
460static void xonar_hdav_cleanup(struct oxygen *chip)
461{
462 xonar_hdmi_cleanup(chip);
463 xonar_disable_output(chip);
464 msleep(2);
465}
466
467static void xonar_st_cleanup(struct oxygen *chip)
468{
469 xonar_disable_output(chip);
470}
471
472static void xonar_d2_suspend(struct oxygen *chip)
473{
474 xonar_d2_cleanup(chip);
475}
476
477static void xonar_hdav_suspend(struct oxygen *chip)
478{
479 xonar_hdav_cleanup(chip);
480}
481
482static void xonar_st_suspend(struct oxygen *chip)
483{
484 xonar_st_cleanup(chip);
485}
486
487static void xonar_d2_resume(struct oxygen *chip)
488{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200489 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200490 xonar_enable_output(chip);
491}
492
493static void xonar_hdav_resume(struct oxygen *chip)
494{
495 struct xonar_hdav *data = chip->model_data;
496
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200497 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200498 xonar_hdmi_resume(chip, &data->hdmi);
499 xonar_enable_output(chip);
500}
501
Clemens Ladisch268304f2009-09-28 11:15:01 +0200502static void xonar_stx_resume(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200503{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200504 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200505 xonar_enable_output(chip);
506}
507
Clemens Ladisch268304f2009-09-28 11:15:01 +0200508static void xonar_st_resume(struct oxygen *chip)
509{
510 cs2000_registers_init(chip);
511 xonar_stx_resume(chip);
512}
513
Clemens Ladisch973dca92009-09-28 11:20:47 +0200514static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
515{
516 struct xonar_pcm179x *data = chip->model_data;
517
518 if (rate <= 32000)
519 return OXYGEN_I2S_MCLK_512;
520 else if (rate <= 48000 && data->os_128)
521 return OXYGEN_I2S_MCLK_512;
522 else if (rate <= 96000)
523 return OXYGEN_I2S_MCLK_256;
524 else
525 return OXYGEN_I2S_MCLK_128;
526}
527
528static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
529 unsigned int channel,
530 struct snd_pcm_hw_params *params)
531{
532 if (channel == PCM_MULTICH)
533 return mclk_from_rate(chip, params_rate(params));
534 else
535 return oxygen_default_i2s_mclk(chip, channel, params);
536}
537
538static void update_pcm1796_oversampling(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200539{
540 struct xonar_pcm179x *data = chip->model_data;
541 unsigned int i;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200542 u8 reg;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200543
Clemens Ladisch973dca92009-09-28 11:20:47 +0200544 if (data->current_rate <= 32000)
545 reg = PCM1796_OS_128;
546 else if (data->current_rate <= 48000 && data->os_128)
547 reg = PCM1796_OS_128;
548 else if (data->current_rate <= 96000 || data->os_128)
549 reg = PCM1796_OS_64;
550 else
551 reg = PCM1796_OS_32;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200552 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200553 pcm1796_write_cached(chip, i, 20, reg);
554}
555
Clemens Ladisch973dca92009-09-28 11:20:47 +0200556static void set_pcm1796_params(struct oxygen *chip,
557 struct snd_pcm_hw_params *params)
558{
559 struct xonar_pcm179x *data = chip->model_data;
560
561 data->current_rate = params_rate(params);
562 update_pcm1796_oversampling(chip);
563}
564
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200565static void update_pcm1796_volume(struct oxygen *chip)
566{
567 struct xonar_pcm179x *data = chip->model_data;
568 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200569 s8 gain_offset;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200570
Clemens Ladischa361e242009-09-28 11:19:19 +0200571 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200572 for (i = 0; i < data->dacs; ++i) {
Clemens Ladischa361e242009-09-28 11:19:19 +0200573 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
574 + gain_offset);
575 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
576 + gain_offset);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200577 }
578}
579
580static void update_pcm1796_mute(struct oxygen *chip)
581{
582 struct xonar_pcm179x *data = chip->model_data;
583 unsigned int i;
584 u8 value;
585
586 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
587 if (chip->dac_mute)
588 value |= PCM1796_MUTE;
589 for (i = 0; i < data->dacs; ++i)
590 pcm1796_write_cached(chip, i, 18, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200591}
592
Clemens Ladisch973dca92009-09-28 11:20:47 +0200593static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200594{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200595 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200596 u8 rate_mclk, reg;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200597
Clemens Ladisch973dca92009-09-28 11:20:47 +0200598 switch (rate) {
599 /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */
600 case 32000:
601 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
602 break;
603 case 44100:
604 if (data->os_128)
605 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
606 else
607 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128;
608 break;
609 default: /* 48000 */
610 if (data->os_128)
611 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
612 else
613 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128;
614 break;
615 case 64000:
616 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
617 break;
618 case 88200:
619 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
620 break;
621 case 96000:
622 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
623 break;
624 case 176400:
625 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
626 break;
627 case 192000:
628 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
629 break;
630 }
Clemens Ladisch268304f2009-09-28 11:15:01 +0200631 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
632 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
633 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200634 reg = CS2000_REF_CLK_DIV_1;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200635 else
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200636 reg = CS2000_REF_CLK_DIV_2;
637 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200638}
639
640static void set_st_params(struct oxygen *chip,
641 struct snd_pcm_hw_params *params)
642{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200643 update_cs2000_rate(chip, params_rate(params));
Clemens Ladisch268304f2009-09-28 11:15:01 +0200644 set_pcm1796_params(chip, params);
645}
646
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200647static void set_hdav_params(struct oxygen *chip,
648 struct snd_pcm_hw_params *params)
649{
650 struct xonar_hdav *data = chip->model_data;
651
652 set_pcm1796_params(chip, params);
653 xonar_set_hdmi_params(chip, &data->hdmi, params);
654}
655
656static const struct snd_kcontrol_new alt_switch = {
657 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
658 .name = "Analog Loopback Switch",
659 .info = snd_ctl_boolean_mono_info,
660 .get = xonar_gpio_bit_switch_get,
661 .put = xonar_gpio_bit_switch_put,
662 .private_value = GPIO_D2_ALT,
663};
664
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200665static int rolloff_info(struct snd_kcontrol *ctl,
666 struct snd_ctl_elem_info *info)
667{
668 static const char *const names[2] = {
669 "Sharp Roll-off", "Slow Roll-off"
670 };
671
672 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
673 info->count = 1;
674 info->value.enumerated.items = 2;
675 if (info->value.enumerated.item >= 2)
676 info->value.enumerated.item = 1;
677 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
678 return 0;
679}
680
681static int rolloff_get(struct snd_kcontrol *ctl,
682 struct snd_ctl_elem_value *value)
683{
684 struct oxygen *chip = ctl->private_data;
685 struct xonar_pcm179x *data = chip->model_data;
686
687 value->value.enumerated.item[0] =
688 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
689 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
690 return 0;
691}
692
693static int rolloff_put(struct snd_kcontrol *ctl,
694 struct snd_ctl_elem_value *value)
695{
696 struct oxygen *chip = ctl->private_data;
697 struct xonar_pcm179x *data = chip->model_data;
698 unsigned int i;
699 int changed;
700 u8 reg;
701
702 mutex_lock(&chip->mutex);
703 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
704 reg &= ~PCM1796_FLT_MASK;
705 if (!value->value.enumerated.item[0])
706 reg |= PCM1796_FLT_SHARP;
707 else
708 reg |= PCM1796_FLT_SLOW;
709 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
710 if (changed) {
711 for (i = 0; i < data->dacs; ++i)
712 pcm1796_write(chip, i, 19, reg);
713 }
714 mutex_unlock(&chip->mutex);
715 return changed;
716}
717
718static const struct snd_kcontrol_new rolloff_control = {
719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
720 .name = "DAC Filter Playback Enum",
721 .info = rolloff_info,
722 .get = rolloff_get,
723 .put = rolloff_put,
724};
725
Clemens Ladisch973dca92009-09-28 11:20:47 +0200726static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
727{
728 static const char *const names[2] = { "64x", "128x" };
729
730 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
731 info->count = 1;
732 info->value.enumerated.items = 2;
733 if (info->value.enumerated.item >= 2)
734 info->value.enumerated.item = 1;
735 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
736 return 0;
737}
738
739static int os_128_get(struct snd_kcontrol *ctl,
740 struct snd_ctl_elem_value *value)
741{
742 struct oxygen *chip = ctl->private_data;
743 struct xonar_pcm179x *data = chip->model_data;
744
745 value->value.enumerated.item[0] = data->os_128;
746 return 0;
747}
748
749static int os_128_put(struct snd_kcontrol *ctl,
750 struct snd_ctl_elem_value *value)
751{
752 struct oxygen *chip = ctl->private_data;
753 struct xonar_pcm179x *data = chip->model_data;
754 int changed;
755
756 mutex_lock(&chip->mutex);
757 changed = value->value.enumerated.item[0] != data->os_128;
758 if (changed) {
759 data->os_128 = value->value.enumerated.item[0];
760 if (data->has_cs2000)
761 update_cs2000_rate(chip, data->current_rate);
762 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
763 mclk_from_rate(chip, data->current_rate),
764 OXYGEN_I2S_MCLK_MASK);
765 update_pcm1796_oversampling(chip);
766 }
767 mutex_unlock(&chip->mutex);
768 return changed;
769}
770
771static const struct snd_kcontrol_new os_128_control = {
772 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
773 .name = "DAC Oversampling Playback Enum",
774 .info = os_128_info,
775 .get = os_128_get,
776 .put = os_128_put,
777};
778
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100779static const struct snd_kcontrol_new hdav_hdmi_control = {
780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
781 .name = "HDMI Playback Switch",
782 .info = snd_ctl_boolean_mono_info,
783 .get = xonar_gpio_bit_switch_get,
784 .put = xonar_gpio_bit_switch_put,
785 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
786};
787
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200788static int st_output_switch_info(struct snd_kcontrol *ctl,
789 struct snd_ctl_elem_info *info)
790{
791 static const char *const names[3] = {
792 "Speakers", "Headphones", "FP Headphones"
793 };
794
795 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
796 info->count = 1;
797 info->value.enumerated.items = 3;
798 if (info->value.enumerated.item >= 3)
799 info->value.enumerated.item = 2;
800 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
801 return 0;
802}
803
804static int st_output_switch_get(struct snd_kcontrol *ctl,
805 struct snd_ctl_elem_value *value)
806{
807 struct oxygen *chip = ctl->private_data;
808 u16 gpio;
809
810 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
811 if (!(gpio & GPIO_ST_HP))
812 value->value.enumerated.item[0] = 0;
813 else if (gpio & GPIO_ST_HP_REAR)
814 value->value.enumerated.item[0] = 1;
815 else
816 value->value.enumerated.item[0] = 2;
817 return 0;
818}
819
820
821static int st_output_switch_put(struct snd_kcontrol *ctl,
822 struct snd_ctl_elem_value *value)
823{
824 struct oxygen *chip = ctl->private_data;
Clemens Ladischa361e242009-09-28 11:19:19 +0200825 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200826 u16 gpio_old, gpio;
827
828 mutex_lock(&chip->mutex);
829 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
830 gpio = gpio_old;
831 switch (value->value.enumerated.item[0]) {
832 case 0:
833 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
834 break;
835 case 1:
836 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
837 break;
838 case 2:
839 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
840 break;
841 }
842 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
Clemens Ladischa361e242009-09-28 11:19:19 +0200843 data->hp_active = gpio & GPIO_ST_HP;
844 update_pcm1796_volume(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200845 mutex_unlock(&chip->mutex);
846 return gpio != gpio_old;
847}
848
Clemens Ladischa361e242009-09-28 11:19:19 +0200849static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
850 struct snd_ctl_elem_info *info)
851{
852 static const char *const names[3] = {
853 "< 64 ohms", "64-300 ohms", "300-600 ohms"
854 };
855
856 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
857 info->count = 1;
858 info->value.enumerated.items = 3;
859 if (info->value.enumerated.item > 2)
860 info->value.enumerated.item = 2;
861 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
862 return 0;
863}
864
865static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
866 struct snd_ctl_elem_value *value)
867{
868 struct oxygen *chip = ctl->private_data;
869 struct xonar_pcm179x *data = chip->model_data;
870
871 mutex_lock(&chip->mutex);
872 if (data->hp_gain_offset < 2*-6)
873 value->value.enumerated.item[0] = 0;
874 else if (data->hp_gain_offset < 0)
875 value->value.enumerated.item[0] = 1;
876 else
877 value->value.enumerated.item[0] = 2;
878 mutex_unlock(&chip->mutex);
879 return 0;
880}
881
882
883static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
884 struct snd_ctl_elem_value *value)
885{
886 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
887 struct oxygen *chip = ctl->private_data;
888 struct xonar_pcm179x *data = chip->model_data;
889 s8 offset;
890 int changed;
891
892 if (value->value.enumerated.item[0] > 2)
893 return -EINVAL;
894 offset = offsets[value->value.enumerated.item[0]];
895 mutex_lock(&chip->mutex);
896 changed = offset != data->hp_gain_offset;
897 if (changed) {
898 data->hp_gain_offset = offset;
899 update_pcm1796_volume(chip);
900 }
901 mutex_unlock(&chip->mutex);
902 return changed;
903}
904
905static const struct snd_kcontrol_new st_controls[] = {
906 {
907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
908 .name = "Analog Output",
909 .info = st_output_switch_info,
910 .get = st_output_switch_get,
911 .put = st_output_switch_put,
912 },
913 {
914 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
915 .name = "Headphones Impedance Playback Enum",
916 .info = st_hp_volume_offset_info,
917 .get = st_hp_volume_offset_get,
918 .put = st_hp_volume_offset_put,
919 },
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200920};
921
922static void xonar_line_mic_ac97_switch(struct oxygen *chip,
923 unsigned int reg, unsigned int mute)
924{
925 if (reg == AC97_LINE) {
926 spin_lock_irq(&chip->reg_lock);
927 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
928 mute ? GPIO_INPUT_ROUTE : 0,
929 GPIO_INPUT_ROUTE);
930 spin_unlock_irq(&chip->reg_lock);
931 }
932}
933
934static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
935
936static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
937{
938 if (!strncmp(template->name, "CD Capture ", 11))
939 /* CD in is actually connected to the video in pin */
940 template->private_value ^= AC97_CD ^ AC97_VIDEO;
941 return 0;
942}
943
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200944static int add_pcm1796_controls(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200945{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200946 int err;
947
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200948 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
Clemens Ladisch973dca92009-09-28 11:20:47 +0200949 if (err < 0)
950 return err;
951 err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip));
952 if (err < 0)
953 return err;
954 return 0;
955}
956
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200957static int xonar_d2_mixer_init(struct oxygen *chip)
958{
959 int err;
960
961 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
962 if (err < 0)
963 return err;
964 err = add_pcm1796_controls(chip);
965 if (err < 0)
966 return err;
967 return 0;
968}
969
Clemens Ladisch973dca92009-09-28 11:20:47 +0200970static int xonar_hdav_mixer_init(struct oxygen *chip)
971{
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100972 int err;
973
974 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
975 if (err < 0)
976 return err;
977 err = add_pcm1796_controls(chip);
978 if (err < 0)
979 return err;
980 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200981}
982
983static int xonar_st_mixer_init(struct oxygen *chip)
984{
Clemens Ladischa361e242009-09-28 11:19:19 +0200985 unsigned int i;
986 int err;
987
988 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
989 err = snd_ctl_add(chip->card,
990 snd_ctl_new1(&st_controls[i], chip));
991 if (err < 0)
992 return err;
993 }
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200994 err = add_pcm1796_controls(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200995 if (err < 0)
996 return err;
Clemens Ladischa361e242009-09-28 11:19:19 +0200997 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200998}
999
1000static const struct oxygen_model model_xonar_d2 = {
1001 .longname = "Asus Virtuoso 200",
1002 .chip = "AV200",
1003 .init = xonar_d2_init,
1004 .control_filter = xonar_d2_control_filter,
1005 .mixer_init = xonar_d2_mixer_init,
1006 .cleanup = xonar_d2_cleanup,
1007 .suspend = xonar_d2_suspend,
1008 .resume = xonar_d2_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001009 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001010 .set_dac_params = set_pcm1796_params,
1011 .set_adc_params = xonar_set_cs53x1_params,
1012 .update_dac_volume = update_pcm1796_volume,
1013 .update_dac_mute = update_pcm1796_mute,
1014 .dac_tlv = pcm1796_db_scale,
1015 .model_data_size = sizeof(struct xonar_pcm179x),
1016 .device_config = PLAYBACK_0_TO_I2S |
1017 PLAYBACK_1_TO_SPDIF |
1018 CAPTURE_0_FROM_I2S_2 |
1019 CAPTURE_1_FROM_SPDIF |
1020 MIDI_OUTPUT |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +02001021 MIDI_INPUT |
1022 AC97_CD_INPUT,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001023 .dac_channels = 8,
1024 .dac_volume_min = 255 - 2*60,
1025 .dac_volume_max = 255,
1026 .misc_flags = OXYGEN_MISC_MIDI,
1027 .function_flags = OXYGEN_FUNCTION_SPI |
1028 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1029 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1030 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1031};
1032
1033static const struct oxygen_model model_xonar_hdav = {
1034 .longname = "Asus Virtuoso 200",
1035 .chip = "AV200",
1036 .init = xonar_hdav_init,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001037 .mixer_init = xonar_hdav_mixer_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001038 .cleanup = xonar_hdav_cleanup,
1039 .suspend = xonar_hdav_suspend,
1040 .resume = xonar_hdav_resume,
1041 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001042 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001043 .set_dac_params = set_hdav_params,
1044 .set_adc_params = xonar_set_cs53x1_params,
1045 .update_dac_volume = update_pcm1796_volume,
1046 .update_dac_mute = update_pcm1796_mute,
1047 .uart_input = xonar_hdmi_uart_input,
1048 .ac97_switch = xonar_line_mic_ac97_switch,
1049 .dac_tlv = pcm1796_db_scale,
1050 .model_data_size = sizeof(struct xonar_hdav),
1051 .device_config = PLAYBACK_0_TO_I2S |
1052 PLAYBACK_1_TO_SPDIF |
1053 CAPTURE_0_FROM_I2S_2 |
1054 CAPTURE_1_FROM_SPDIF,
1055 .dac_channels = 8,
1056 .dac_volume_min = 255 - 2*60,
1057 .dac_volume_max = 255,
1058 .misc_flags = OXYGEN_MISC_MIDI,
1059 .function_flags = OXYGEN_FUNCTION_2WIRE,
1060 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1061 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1062};
1063
1064static const struct oxygen_model model_xonar_st = {
1065 .longname = "Asus Virtuoso 100",
1066 .chip = "AV200",
1067 .init = xonar_st_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001068 .mixer_init = xonar_st_mixer_init,
1069 .cleanup = xonar_st_cleanup,
1070 .suspend = xonar_st_suspend,
1071 .resume = xonar_st_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001072 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch268304f2009-09-28 11:15:01 +02001073 .set_dac_params = set_st_params,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001074 .set_adc_params = xonar_set_cs53x1_params,
1075 .update_dac_volume = update_pcm1796_volume,
1076 .update_dac_mute = update_pcm1796_mute,
1077 .ac97_switch = xonar_line_mic_ac97_switch,
1078 .dac_tlv = pcm1796_db_scale,
1079 .model_data_size = sizeof(struct xonar_pcm179x),
1080 .device_config = PLAYBACK_0_TO_I2S |
1081 PLAYBACK_1_TO_SPDIF |
1082 CAPTURE_0_FROM_I2S_2,
1083 .dac_channels = 2,
1084 .dac_volume_min = 255 - 2*60,
1085 .dac_volume_max = 255,
1086 .function_flags = OXYGEN_FUNCTION_2WIRE,
1087 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1088 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1089};
1090
1091int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1092 const struct pci_device_id *id)
1093{
1094 switch (id->subdevice) {
1095 case 0x8269:
1096 chip->model = model_xonar_d2;
1097 chip->model.shortname = "Xonar D2";
1098 break;
1099 case 0x82b7:
1100 chip->model = model_xonar_d2;
1101 chip->model.shortname = "Xonar D2X";
1102 chip->model.init = xonar_d2x_init;
1103 break;
1104 case 0x8314:
1105 chip->model = model_xonar_hdav;
1106 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1107 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1108 default:
1109 chip->model.shortname = "Xonar HDAV1.3";
1110 break;
1111 case GPIO_DB_H6:
1112 chip->model.shortname = "Xonar HDAV1.3+H6";
1113 chip->model.private_data = 1;
1114 break;
1115 }
1116 break;
1117 case 0x835d:
1118 chip->model = model_xonar_st;
1119 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1120 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1121 default:
1122 chip->model.shortname = "Xonar ST";
1123 break;
1124 case GPIO_DB_H6:
1125 chip->model.shortname = "Xonar ST+H6";
1126 chip->model.dac_channels = 8;
1127 chip->model.private_data = 1;
1128 break;
1129 }
1130 break;
1131 case 0x835c:
1132 chip->model = model_xonar_st;
1133 chip->model.shortname = "Xonar STX";
1134 chip->model.init = xonar_stx_init;
Clemens Ladisch268304f2009-09-28 11:15:01 +02001135 chip->model.resume = xonar_stx_resume;
1136 chip->model.set_dac_params = set_pcm1796_params;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001137 break;
Clemens Ladisch2b830ba2010-10-04 13:22:51 +02001138 case 0x835e:
1139 snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");
1140 return -ENODEV;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001141 default:
1142 return -EINVAL;
1143 }
1144 return 0;
1145}