blob: c8c7f2c9b355ae8f4dde5d8deb4b68a11a64f296 [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 *
Clemens Ladischde664932010-12-02 11:42:48 +010025 * SPI 0 -> 1st PCM1796 (front)
26 * SPI 1 -> 2nd PCM1796 (surround)
27 * SPI 2 -> 3rd PCM1796 (center/LFE)
28 * SPI 4 -> 4th PCM1796 (back)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020029 *
Clemens Ladischde664932010-12-02 11:42:48 +010030 * 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 *
Clemens Ladischde664932010-12-02 11:42:48 +010038 * 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
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020045 */
46
47/*
48 * Xonar HDAV1.3 (Deluxe)
49 * ----------------------
50 *
51 * CMI8788:
52 *
Clemens Ladischde664932010-12-02 11:42:48 +010053 * I²C <-> PCM1796 (addr 1001100) (front)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020054 *
Clemens Ladischde664932010-12-02 11:42:48 +010055 * GPI 0 <- external power present
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020056 *
Clemens Ladischde664932010-12-02 11:42:48 +010057 * 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)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020065 *
Clemens Ladischde664932010-12-02 11:42:48 +010066 * UART <-> HDMI controller
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020067 *
Clemens Ladischdc0adf42009-09-28 11:17:36 +020068 * CM9780:
69 *
Clemens Ladischde664932010-12-02 11:42:48 +010070 * 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
Clemens Ladischdc0adf42009-09-28 11:17:36 +020077 *
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020078 * no daughterboard
79 * ----------------
80 *
Clemens Ladischde664932010-12-02 11:42:48 +010081 * GPIO 4 <- 1
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020082 *
83 * H6 daughterboard
84 * ----------------
85 *
Clemens Ladischde664932010-12-02 11:42:48 +010086 * GPIO 4 <- 0
87 * GPIO 5 <- 0
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020088 *
Clemens Ladischde664932010-12-02 11:42:48 +010089 * I²C <-> PCM1796 (addr 1001101) (surround)
90 * <-> PCM1796 (addr 1001110) (center/LFE)
91 * <-> PCM1796 (addr 1001111) (back)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020092 *
93 * unknown daughterboard
94 * ---------------------
95 *
Clemens Ladischde664932010-12-02 11:42:48 +010096 * GPIO 4 <- 0
97 * GPIO 5 <- 1
Clemens Ladisch65c3ac82009-09-28 11:11:27 +020098 *
Clemens Ladischde664932010-12-02 11:42:48 +010099 * I²C <-> CS4362A (addr 0011000) (surround, center/LFE, back)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200100 */
101
102/*
103 * Xonar Essence ST (Deluxe)/STX
104 * -----------------------------
105 *
106 * CMI8788:
107 *
Clemens Ladischde664932010-12-02 11:42:48 +0100108 * I²C <-> PCM1792A (addr 1001100)
109 * <-> CS2000 (addr 1001110) (ST only)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200110 *
Clemens Ladischde664932010-12-02 11:42:48 +0100111 * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200112 *
Clemens Ladischde664932010-12-02 11:42:48 +0100113 * GPI 0 <- external power present (STX only)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200114 *
Clemens Ladischde664932010-12-02 11:42:48 +0100115 * 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)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200124 *
125 * PCM1792A:
126 *
Clemens Ladischde664932010-12-02 11:42:48 +0100127 * SCK <- CLK_OUT of CS2000 (ST only)
Clemens Ladischdc0adf42009-09-28 11:17:36 +0200128 *
129 * CM9780:
130 *
Clemens Ladischde664932010-12-02 11:42:48 +0100131 * 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
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200137 *
138 * H6 daughterboard
139 * ----------------
140 *
141 * GPIO 4 <- 0
142 * GPIO 5 <- 0
143 */
144
Clemens Ladisch2b830ba2010-10-04 13:22:51 +0200145/*
Clemens Ladischde664932010-12-02 11:42:48 +0100146 * Xonar Xense
147 * -----------
Clemens Ladisch2b830ba2010-10-04 13:22:51 +0200148 *
149 * CMI8788:
150 *
Clemens Ladischde664932010-12-02 11:42:48 +0100151 * I²C <-> PCM1796 (addr 1001100) (front)
152 * <-> CS4362A (addr 0011000) (surround, center/LFE, back)
153 * <-> CS2000 (addr 1001110)
Clemens Ladisch2b830ba2010-10-04 13:22:51 +0200154 *
Clemens Ladischde664932010-12-02 11:42:48 +0100155 * 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)
Clemens Ladisch2b830ba2010-10-04 13:22:51 +0200179 */
180
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200181#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>
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100187#include <sound/info.h>
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200188#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"
Clemens Ladisch268304f2009-09-28 11:15:01 +0200194#include "cs2000.h"
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200195
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
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100205#define GPIO_HDAV_MAGIC 0x00c0
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200206
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
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100212#define GPIO_ST_MAGIC 0x0040
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200213#define GPIO_ST_HP 0x0080
214
215#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200216#define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200217
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200218#define PCM1796_REG_BASE 16
219
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200220
221struct xonar_pcm179x {
222 struct xonar_generic generic;
223 unsigned int dacs;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200224 u8 pcm1796_regs[4][5];
Clemens Ladisch973dca92009-09-28 11:20:47 +0200225 unsigned int current_rate;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100226 bool h6;
Clemens Ladischa361e242009-09-28 11:19:19 +0200227 bool hp_active;
228 s8 hp_gain_offset;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200229 bool has_cs2000;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100230 u8 cs2000_regs[0x1f];
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100231 bool broken_i2c;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200232};
233
234struct xonar_hdav {
235 struct xonar_pcm179x pcm179x;
236 struct xonar_hdmi hdmi;
237};
238
239
240static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
241 u8 reg, u8 value)
242{
243 /* maps ALSA channel pair number to SPI output */
244 static const u8 codec_map[4] = {
245 0, 1, 2, 4
246 };
247 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
248 OXYGEN_SPI_DATA_LENGTH_2 |
249 OXYGEN_SPI_CLOCK_160 |
250 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
251 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
252 (reg << 8) | value);
253}
254
255static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
256 u8 reg, u8 value)
257{
258 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
259}
260
261static void pcm1796_write(struct oxygen *chip, unsigned int codec,
262 u8 reg, u8 value)
263{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200264 struct xonar_pcm179x *data = chip->model_data;
265
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200266 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
267 OXYGEN_FUNCTION_SPI)
268 pcm1796_write_spi(chip, codec, reg, value);
269 else
270 pcm1796_write_i2c(chip, codec, reg, value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200271 if ((unsigned int)(reg - PCM1796_REG_BASE)
272 < ARRAY_SIZE(data->pcm1796_regs[codec]))
273 data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
274}
275
276static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
277 u8 reg, u8 value)
278{
279 struct xonar_pcm179x *data = chip->model_data;
280
281 if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
282 pcm1796_write(chip, codec, reg, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200283}
284
Clemens Ladisch268304f2009-09-28 11:15:01 +0200285static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
286{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200287 struct xonar_pcm179x *data = chip->model_data;
288
Clemens Ladisch268304f2009-09-28 11:15:01 +0200289 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100290 data->cs2000_regs[reg] = value;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200291}
292
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200293static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
294{
295 struct xonar_pcm179x *data = chip->model_data;
296
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100297 if (value != data->cs2000_regs[reg])
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200298 cs2000_write(chip, reg, value);
299}
300
301static void pcm1796_registers_init(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200302{
303 struct xonar_pcm179x *data = chip->model_data;
304 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200305 s8 gain_offset;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200306
Clemens Ladisch79815e02011-01-10 16:02:32 +0100307 msleep(1);
Clemens Ladischa361e242009-09-28 11:19:19 +0200308 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200309 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200310 /* set ATLD before ATL/ATR */
311 pcm1796_write(chip, i, 18,
312 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
Clemens Ladischa361e242009-09-28 11:19:19 +0200313 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
314 + gain_offset);
315 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
316 + gain_offset);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200317 pcm1796_write(chip, i, 19,
318 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200319 pcm1796_write(chip, i, 20,
320 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
321 pcm1796_write(chip, i, 21, 0);
Clemens Ladischbc29e262011-01-10 16:11:32 +0100322 gain_offset = 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200323 }
324}
325
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200326static void pcm1796_init(struct oxygen *chip)
327{
328 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200329
Clemens Ladischc81c6b32011-07-17 22:18:05 +0200330 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] =
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100331 PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladischc81c6b32011-07-17 22:18:05 +0200332 if (!data->broken_i2c)
333 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] |= PCM1796_MUTE;
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200334 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
335 PCM1796_FLT_SHARP | PCM1796_ATS_1;
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100336 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] =
337 data->h6 ? PCM1796_OS_64 : PCM1796_OS_128;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200338 pcm1796_registers_init(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200339 data->current_rate = 48000;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200340}
341
342static void xonar_d2_init(struct oxygen *chip)
343{
344 struct xonar_pcm179x *data = chip->model_data;
345
346 data->generic.anti_pop_delay = 300;
347 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
348 data->dacs = 4;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200349
350 pcm1796_init(chip);
351
352 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
353 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
354
355 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
356
357 xonar_init_cs53x1(chip);
358 xonar_enable_output(chip);
359
360 snd_component_add(chip->card, "PCM1796");
361 snd_component_add(chip->card, "CS5381");
362}
363
364static void xonar_d2x_init(struct oxygen *chip)
365{
366 struct xonar_pcm179x *data = chip->model_data;
367
368 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
369 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
370 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
371 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
372 xonar_init_ext_power(chip);
373 xonar_d2_init(chip);
374}
375
376static void xonar_hdav_init(struct oxygen *chip)
377{
378 struct xonar_hdav *data = chip->model_data;
379
380 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
381 OXYGEN_2WIRE_LENGTH_8 |
382 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100383 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200384
385 data->pcm179x.generic.anti_pop_delay = 100;
386 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
387 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
388 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
389 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100390 data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100391 data->pcm179x.h6 = chip->model.dac_channels_mixer > 2;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200392
393 pcm1796_init(chip);
394
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100395 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
396 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200397 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
398
399 xonar_init_cs53x1(chip);
400 xonar_init_ext_power(chip);
401 xonar_hdmi_init(chip, &data->hdmi);
402 xonar_enable_output(chip);
403
404 snd_component_add(chip->card, "PCM1796");
405 snd_component_add(chip->card, "CS5381");
406}
407
Clemens Ladisch268304f2009-09-28 11:15:01 +0200408static void xonar_st_init_i2c(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200409{
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200410 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
411 OXYGEN_2WIRE_LENGTH_8 |
412 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100413 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200414}
415
416static void xonar_st_init_common(struct oxygen *chip)
417{
418 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200419
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200420 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100421 data->dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladischa361e242009-09-28 11:19:19 +0200422 data->hp_gain_offset = 2*-18;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200423
424 pcm1796_init(chip);
425
426 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100427 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
428 GPIO_ST_MAGIC | GPIO_ST_HP);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200429 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
430 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
431
432 xonar_init_cs53x1(chip);
433 xonar_enable_output(chip);
434
435 snd_component_add(chip->card, "PCM1792A");
436 snd_component_add(chip->card, "CS5381");
437}
438
Clemens Ladisch268304f2009-09-28 11:15:01 +0200439static void cs2000_registers_init(struct oxygen *chip)
440{
441 struct xonar_pcm179x *data = chip->model_data;
442
443 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
444 cs2000_write(chip, CS2000_DEV_CTRL, 0);
445 cs2000_write(chip, CS2000_DEV_CFG_1,
446 CS2000_R_MOD_SEL_1 |
447 (0 << CS2000_R_SEL_SHIFT) |
448 CS2000_AUX_OUT_SRC_REF_CLK |
449 CS2000_EN_DEV_CFG_1);
450 cs2000_write(chip, CS2000_DEV_CFG_2,
451 (0 << CS2000_LOCK_CLK_SHIFT) |
452 CS2000_FRAC_N_SRC_STATIC);
453 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
454 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
455 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
456 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100457 cs2000_write(chip, CS2000_FUN_CFG_1,
458 data->cs2000_regs[CS2000_FUN_CFG_1]);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200459 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
460 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100461 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200462}
463
464static void xonar_st_init(struct oxygen *chip)
465{
466 struct xonar_pcm179x *data = chip->model_data;
467
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200468 data->generic.anti_pop_delay = 100;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100469 data->h6 = chip->model.dac_channels_mixer > 2;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200470 data->has_cs2000 = 1;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100471 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100472 data->broken_i2c = true;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200473
474 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100475 OXYGEN_RATE_48000 |
476 OXYGEN_I2S_FORMAT_I2S |
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100477 OXYGEN_I2S_MCLK(data->h6 ? MCLK_256 : MCLK_512) |
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100478 OXYGEN_I2S_BITS_16 |
479 OXYGEN_I2S_MASTER |
480 OXYGEN_I2S_BCLK_64);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200481
482 xonar_st_init_i2c(chip);
483 cs2000_registers_init(chip);
484 xonar_st_init_common(chip);
485
486 snd_component_add(chip->card, "CS2000");
487}
488
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200489static void xonar_stx_init(struct oxygen *chip)
490{
491 struct xonar_pcm179x *data = chip->model_data;
492
Clemens Ladisch268304f2009-09-28 11:15:01 +0200493 xonar_st_init_i2c(chip);
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200494 data->generic.anti_pop_delay = 800;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200495 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
496 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
497 data->generic.ext_power_bit = GPI_EXT_POWER;
498 xonar_init_ext_power(chip);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200499 xonar_st_init_common(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200500}
501
502static void xonar_d2_cleanup(struct oxygen *chip)
503{
504 xonar_disable_output(chip);
505}
506
507static void xonar_hdav_cleanup(struct oxygen *chip)
508{
509 xonar_hdmi_cleanup(chip);
510 xonar_disable_output(chip);
511 msleep(2);
512}
513
514static void xonar_st_cleanup(struct oxygen *chip)
515{
516 xonar_disable_output(chip);
517}
518
519static void xonar_d2_suspend(struct oxygen *chip)
520{
521 xonar_d2_cleanup(chip);
522}
523
524static void xonar_hdav_suspend(struct oxygen *chip)
525{
526 xonar_hdav_cleanup(chip);
527}
528
529static void xonar_st_suspend(struct oxygen *chip)
530{
531 xonar_st_cleanup(chip);
532}
533
534static void xonar_d2_resume(struct oxygen *chip)
535{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200536 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200537 xonar_enable_output(chip);
538}
539
540static void xonar_hdav_resume(struct oxygen *chip)
541{
542 struct xonar_hdav *data = chip->model_data;
543
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200544 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200545 xonar_hdmi_resume(chip, &data->hdmi);
546 xonar_enable_output(chip);
547}
548
Clemens Ladisch268304f2009-09-28 11:15:01 +0200549static void xonar_stx_resume(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200550{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200551 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200552 xonar_enable_output(chip);
553}
554
Clemens Ladisch268304f2009-09-28 11:15:01 +0200555static void xonar_st_resume(struct oxygen *chip)
556{
557 cs2000_registers_init(chip);
558 xonar_stx_resume(chip);
559}
560
Clemens Ladisch973dca92009-09-28 11:20:47 +0200561static void update_pcm1796_oversampling(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200562{
563 struct xonar_pcm179x *data = chip->model_data;
564 unsigned int i;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200565 u8 reg;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200566
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100567 if (data->current_rate <= 48000 && !data->h6)
Clemens Ladisch973dca92009-09-28 11:20:47 +0200568 reg = PCM1796_OS_128;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200569 else
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100570 reg = PCM1796_OS_64;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200571 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200572 pcm1796_write_cached(chip, i, 20, reg);
573}
574
Clemens Ladisch973dca92009-09-28 11:20:47 +0200575static void set_pcm1796_params(struct oxygen *chip,
576 struct snd_pcm_hw_params *params)
577{
578 struct xonar_pcm179x *data = chip->model_data;
579
Clemens Ladisch79815e02011-01-10 16:02:32 +0100580 msleep(1);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200581 data->current_rate = params_rate(params);
582 update_pcm1796_oversampling(chip);
583}
584
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200585static void update_pcm1796_volume(struct oxygen *chip)
586{
587 struct xonar_pcm179x *data = chip->model_data;
588 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200589 s8 gain_offset;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200590
Clemens Ladischa361e242009-09-28 11:19:19 +0200591 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200592 for (i = 0; i < data->dacs; ++i) {
Clemens Ladischa361e242009-09-28 11:19:19 +0200593 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
594 + gain_offset);
595 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
596 + gain_offset);
Clemens Ladischbc29e262011-01-10 16:11:32 +0100597 gain_offset = 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200598 }
599}
600
601static void update_pcm1796_mute(struct oxygen *chip)
602{
603 struct xonar_pcm179x *data = chip->model_data;
604 unsigned int i;
605 u8 value;
606
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100607 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200608 if (chip->dac_mute)
609 value |= PCM1796_MUTE;
610 for (i = 0; i < data->dacs; ++i)
611 pcm1796_write_cached(chip, i, 18, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200612}
613
Clemens Ladisch973dca92009-09-28 11:20:47 +0200614static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200615{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200616 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200617 u8 rate_mclk, reg;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200618
Clemens Ladisch973dca92009-09-28 11:20:47 +0200619 switch (rate) {
Clemens Ladisch973dca92009-09-28 11:20:47 +0200620 case 32000:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100621 case 64000:
622 rate_mclk = OXYGEN_RATE_32000;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200623 break;
624 case 44100:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200625 case 88200:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200626 case 176400:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100627 rate_mclk = OXYGEN_RATE_44100;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200628 break;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100629 default:
630 case 48000:
631 case 96000:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200632 case 192000:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100633 rate_mclk = OXYGEN_RATE_48000;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200634 break;
635 }
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100636
637 if (rate <= 96000 && (rate > 48000 || data->h6)) {
638 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_256);
639 reg = CS2000_REF_CLK_DIV_1;
640 } else {
641 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_512);
642 reg = CS2000_REF_CLK_DIV_2;
643 }
644
Clemens Ladisch268304f2009-09-28 11:15:01 +0200645 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
646 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200647 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100648 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200649}
650
651static void set_st_params(struct oxygen *chip,
652 struct snd_pcm_hw_params *params)
653{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200654 update_cs2000_rate(chip, params_rate(params));
Clemens Ladisch268304f2009-09-28 11:15:01 +0200655 set_pcm1796_params(chip, params);
656}
657
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200658static void set_hdav_params(struct oxygen *chip,
659 struct snd_pcm_hw_params *params)
660{
661 struct xonar_hdav *data = chip->model_data;
662
663 set_pcm1796_params(chip, params);
664 xonar_set_hdmi_params(chip, &data->hdmi, params);
665}
666
667static const struct snd_kcontrol_new alt_switch = {
668 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
669 .name = "Analog Loopback Switch",
670 .info = snd_ctl_boolean_mono_info,
671 .get = xonar_gpio_bit_switch_get,
672 .put = xonar_gpio_bit_switch_put,
673 .private_value = GPIO_D2_ALT,
674};
675
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200676static int rolloff_info(struct snd_kcontrol *ctl,
677 struct snd_ctl_elem_info *info)
678{
679 static const char *const names[2] = {
680 "Sharp Roll-off", "Slow Roll-off"
681 };
682
Clemens Ladisch96007322011-01-10 16:25:44 +0100683 return snd_ctl_enum_info(info, 1, 2, names);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200684}
685
686static int rolloff_get(struct snd_kcontrol *ctl,
687 struct snd_ctl_elem_value *value)
688{
689 struct oxygen *chip = ctl->private_data;
690 struct xonar_pcm179x *data = chip->model_data;
691
692 value->value.enumerated.item[0] =
693 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
694 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
695 return 0;
696}
697
698static int rolloff_put(struct snd_kcontrol *ctl,
699 struct snd_ctl_elem_value *value)
700{
701 struct oxygen *chip = ctl->private_data;
702 struct xonar_pcm179x *data = chip->model_data;
703 unsigned int i;
704 int changed;
705 u8 reg;
706
707 mutex_lock(&chip->mutex);
708 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
709 reg &= ~PCM1796_FLT_MASK;
710 if (!value->value.enumerated.item[0])
711 reg |= PCM1796_FLT_SHARP;
712 else
713 reg |= PCM1796_FLT_SLOW;
714 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
715 if (changed) {
716 for (i = 0; i < data->dacs; ++i)
717 pcm1796_write(chip, i, 19, reg);
718 }
719 mutex_unlock(&chip->mutex);
720 return changed;
721}
722
723static const struct snd_kcontrol_new rolloff_control = {
724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
725 .name = "DAC Filter Playback Enum",
726 .info = rolloff_info,
727 .get = rolloff_get,
728 .put = rolloff_put,
729};
730
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100731static const struct snd_kcontrol_new hdav_hdmi_control = {
732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
733 .name = "HDMI Playback Switch",
734 .info = snd_ctl_boolean_mono_info,
735 .get = xonar_gpio_bit_switch_get,
736 .put = xonar_gpio_bit_switch_put,
737 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
738};
739
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200740static int st_output_switch_info(struct snd_kcontrol *ctl,
741 struct snd_ctl_elem_info *info)
742{
743 static const char *const names[3] = {
744 "Speakers", "Headphones", "FP Headphones"
745 };
746
Clemens Ladisch96007322011-01-10 16:25:44 +0100747 return snd_ctl_enum_info(info, 1, 3, names);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200748}
749
750static int st_output_switch_get(struct snd_kcontrol *ctl,
751 struct snd_ctl_elem_value *value)
752{
753 struct oxygen *chip = ctl->private_data;
754 u16 gpio;
755
756 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
757 if (!(gpio & GPIO_ST_HP))
758 value->value.enumerated.item[0] = 0;
759 else if (gpio & GPIO_ST_HP_REAR)
760 value->value.enumerated.item[0] = 1;
761 else
762 value->value.enumerated.item[0] = 2;
763 return 0;
764}
765
766
767static int st_output_switch_put(struct snd_kcontrol *ctl,
768 struct snd_ctl_elem_value *value)
769{
770 struct oxygen *chip = ctl->private_data;
Clemens Ladischa361e242009-09-28 11:19:19 +0200771 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200772 u16 gpio_old, gpio;
773
774 mutex_lock(&chip->mutex);
775 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
776 gpio = gpio_old;
777 switch (value->value.enumerated.item[0]) {
778 case 0:
779 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
780 break;
781 case 1:
782 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
783 break;
784 case 2:
785 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
786 break;
787 }
788 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
Clemens Ladischa361e242009-09-28 11:19:19 +0200789 data->hp_active = gpio & GPIO_ST_HP;
790 update_pcm1796_volume(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200791 mutex_unlock(&chip->mutex);
792 return gpio != gpio_old;
793}
794
Clemens Ladischa361e242009-09-28 11:19:19 +0200795static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
796 struct snd_ctl_elem_info *info)
797{
798 static const char *const names[3] = {
799 "< 64 ohms", "64-300 ohms", "300-600 ohms"
800 };
801
Clemens Ladisch96007322011-01-10 16:25:44 +0100802 return snd_ctl_enum_info(info, 1, 3, names);
Clemens Ladischa361e242009-09-28 11:19:19 +0200803}
804
805static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
806 struct snd_ctl_elem_value *value)
807{
808 struct oxygen *chip = ctl->private_data;
809 struct xonar_pcm179x *data = chip->model_data;
810
811 mutex_lock(&chip->mutex);
812 if (data->hp_gain_offset < 2*-6)
813 value->value.enumerated.item[0] = 0;
814 else if (data->hp_gain_offset < 0)
815 value->value.enumerated.item[0] = 1;
816 else
817 value->value.enumerated.item[0] = 2;
818 mutex_unlock(&chip->mutex);
819 return 0;
820}
821
822
823static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
824 struct snd_ctl_elem_value *value)
825{
826 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
827 struct oxygen *chip = ctl->private_data;
828 struct xonar_pcm179x *data = chip->model_data;
829 s8 offset;
830 int changed;
831
832 if (value->value.enumerated.item[0] > 2)
833 return -EINVAL;
834 offset = offsets[value->value.enumerated.item[0]];
835 mutex_lock(&chip->mutex);
836 changed = offset != data->hp_gain_offset;
837 if (changed) {
838 data->hp_gain_offset = offset;
839 update_pcm1796_volume(chip);
840 }
841 mutex_unlock(&chip->mutex);
842 return changed;
843}
844
845static const struct snd_kcontrol_new st_controls[] = {
846 {
847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
848 .name = "Analog Output",
849 .info = st_output_switch_info,
850 .get = st_output_switch_get,
851 .put = st_output_switch_put,
852 },
853 {
854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
855 .name = "Headphones Impedance Playback Enum",
856 .info = st_hp_volume_offset_info,
857 .get = st_hp_volume_offset_get,
858 .put = st_hp_volume_offset_put,
859 },
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200860};
861
862static void xonar_line_mic_ac97_switch(struct oxygen *chip,
863 unsigned int reg, unsigned int mute)
864{
865 if (reg == AC97_LINE) {
866 spin_lock_irq(&chip->reg_lock);
867 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
868 mute ? GPIO_INPUT_ROUTE : 0,
869 GPIO_INPUT_ROUTE);
870 spin_unlock_irq(&chip->reg_lock);
871 }
872}
873
874static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
875
876static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
877{
878 if (!strncmp(template->name, "CD Capture ", 11))
879 /* CD in is actually connected to the video in pin */
880 template->private_value ^= AC97_CD ^ AC97_VIDEO;
881 return 0;
882}
883
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100884static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
885{
886 if (!strncmp(template->name, "Master Playback ", 16))
887 /* no volume/mute, as I²C to the third DAC does not work */
888 return 1;
889 return 0;
890}
891
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200892static int add_pcm1796_controls(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200893{
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100894 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200895 int err;
896
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100897 if (!data->broken_i2c) {
898 err = snd_ctl_add(chip->card,
899 snd_ctl_new1(&rolloff_control, chip));
900 if (err < 0)
901 return err;
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100902 }
Clemens Ladisch973dca92009-09-28 11:20:47 +0200903 return 0;
904}
905
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200906static int xonar_d2_mixer_init(struct oxygen *chip)
907{
908 int err;
909
910 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
911 if (err < 0)
912 return err;
913 err = add_pcm1796_controls(chip);
914 if (err < 0)
915 return err;
916 return 0;
917}
918
Clemens Ladisch973dca92009-09-28 11:20:47 +0200919static int xonar_hdav_mixer_init(struct oxygen *chip)
920{
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100921 int err;
922
923 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
924 if (err < 0)
925 return err;
926 err = add_pcm1796_controls(chip);
927 if (err < 0)
928 return err;
929 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200930}
931
932static int xonar_st_mixer_init(struct oxygen *chip)
933{
Clemens Ladischa361e242009-09-28 11:19:19 +0200934 unsigned int i;
935 int err;
936
937 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
938 err = snd_ctl_add(chip->card,
939 snd_ctl_new1(&st_controls[i], chip));
940 if (err < 0)
941 return err;
942 }
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200943 err = add_pcm1796_controls(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200944 if (err < 0)
945 return err;
Clemens Ladischa361e242009-09-28 11:19:19 +0200946 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200947}
948
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100949static void dump_pcm1796_registers(struct oxygen *chip,
950 struct snd_info_buffer *buffer)
951{
952 struct xonar_pcm179x *data = chip->model_data;
953 unsigned int dac, i;
954
955 for (dac = 0; dac < data->dacs; ++dac) {
956 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
957 for (i = 0; i < 5; ++i)
958 snd_iprintf(buffer, " %02x",
959 data->pcm1796_regs[dac][i]);
960 }
961 snd_iprintf(buffer, "\n");
962}
963
964static void dump_cs2000_registers(struct oxygen *chip,
965 struct snd_info_buffer *buffer)
966{
967 struct xonar_pcm179x *data = chip->model_data;
968 unsigned int i;
969
970 if (data->has_cs2000) {
971 snd_iprintf(buffer, "\nCS2000:\n00: ");
972 for (i = 1; i < 0x10; ++i)
973 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
974 snd_iprintf(buffer, "\n10:");
975 for (i = 0x10; i < 0x1f; ++i)
976 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
977 snd_iprintf(buffer, "\n");
978 }
979}
980
981static void dump_st_registers(struct oxygen *chip,
982 struct snd_info_buffer *buffer)
983{
984 dump_pcm1796_registers(chip, buffer);
985 dump_cs2000_registers(chip, buffer);
986}
987
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200988static const struct oxygen_model model_xonar_d2 = {
989 .longname = "Asus Virtuoso 200",
990 .chip = "AV200",
991 .init = xonar_d2_init,
992 .control_filter = xonar_d2_control_filter,
993 .mixer_init = xonar_d2_mixer_init,
994 .cleanup = xonar_d2_cleanup,
995 .suspend = xonar_d2_suspend,
996 .resume = xonar_d2_resume,
997 .set_dac_params = set_pcm1796_params,
998 .set_adc_params = xonar_set_cs53x1_params,
999 .update_dac_volume = update_pcm1796_volume,
1000 .update_dac_mute = update_pcm1796_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001001 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001002 .dac_tlv = pcm1796_db_scale,
1003 .model_data_size = sizeof(struct xonar_pcm179x),
1004 .device_config = PLAYBACK_0_TO_I2S |
1005 PLAYBACK_1_TO_SPDIF |
1006 CAPTURE_0_FROM_I2S_2 |
1007 CAPTURE_1_FROM_SPDIF |
1008 MIDI_OUTPUT |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +02001009 MIDI_INPUT |
1010 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001011 .dac_channels_pcm = 8,
1012 .dac_channels_mixer = 8,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001013 .dac_volume_min = 255 - 2*60,
1014 .dac_volume_max = 255,
1015 .misc_flags = OXYGEN_MISC_MIDI,
1016 .function_flags = OXYGEN_FUNCTION_SPI |
1017 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001018 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
Clemens Ladischce2c4922011-01-10 16:16:08 +01001019 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001020 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001021 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1022};
1023
1024static const struct oxygen_model model_xonar_hdav = {
1025 .longname = "Asus Virtuoso 200",
1026 .chip = "AV200",
1027 .init = xonar_hdav_init,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001028 .mixer_init = xonar_hdav_mixer_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001029 .cleanup = xonar_hdav_cleanup,
1030 .suspend = xonar_hdav_suspend,
1031 .resume = xonar_hdav_resume,
1032 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1033 .set_dac_params = set_hdav_params,
1034 .set_adc_params = xonar_set_cs53x1_params,
1035 .update_dac_volume = update_pcm1796_volume,
1036 .update_dac_mute = update_pcm1796_mute,
1037 .uart_input = xonar_hdmi_uart_input,
1038 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001039 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001040 .dac_tlv = pcm1796_db_scale,
1041 .model_data_size = sizeof(struct xonar_hdav),
1042 .device_config = PLAYBACK_0_TO_I2S |
1043 PLAYBACK_1_TO_SPDIF |
1044 CAPTURE_0_FROM_I2S_2 |
1045 CAPTURE_1_FROM_SPDIF,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001046 .dac_channels_pcm = 8,
1047 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001048 .dac_volume_min = 255 - 2*60,
1049 .dac_volume_max = 255,
1050 .misc_flags = OXYGEN_MISC_MIDI,
1051 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001052 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
Clemens Ladischce2c4922011-01-10 16:16:08 +01001053 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001054 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001055 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1056};
1057
1058static const struct oxygen_model model_xonar_st = {
1059 .longname = "Asus Virtuoso 100",
1060 .chip = "AV200",
1061 .init = xonar_st_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001062 .mixer_init = xonar_st_mixer_init,
1063 .cleanup = xonar_st_cleanup,
1064 .suspend = xonar_st_suspend,
1065 .resume = xonar_st_resume,
Clemens Ladisch268304f2009-09-28 11:15:01 +02001066 .set_dac_params = set_st_params,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001067 .set_adc_params = xonar_set_cs53x1_params,
1068 .update_dac_volume = update_pcm1796_volume,
1069 .update_dac_mute = update_pcm1796_mute,
1070 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001071 .dump_registers = dump_st_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001072 .dac_tlv = pcm1796_db_scale,
1073 .model_data_size = sizeof(struct xonar_pcm179x),
1074 .device_config = PLAYBACK_0_TO_I2S |
1075 PLAYBACK_1_TO_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001076 CAPTURE_0_FROM_I2S_2 |
Clemens Ladischdc3fcd12011-06-18 23:05:00 +02001077 CAPTURE_1_FROM_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001078 AC97_FMIC_SWITCH,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001079 .dac_channels_pcm = 2,
1080 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001081 .dac_volume_min = 255 - 2*60,
1082 .dac_volume_max = 255,
1083 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001084 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
Clemens Ladischce2c4922011-01-10 16:16:08 +01001085 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001086 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001087 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1088};
1089
Bill Pembertonf120a6f2012-12-06 12:35:20 -05001090int get_xonar_pcm179x_model(struct oxygen *chip,
1091 const struct pci_device_id *id)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001092{
1093 switch (id->subdevice) {
1094 case 0x8269:
1095 chip->model = model_xonar_d2;
1096 chip->model.shortname = "Xonar D2";
1097 break;
1098 case 0x82b7:
1099 chip->model = model_xonar_d2;
1100 chip->model.shortname = "Xonar D2X";
1101 chip->model.init = xonar_d2x_init;
1102 break;
1103 case 0x8314:
1104 chip->model = model_xonar_hdav;
1105 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1106 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1107 default:
1108 chip->model.shortname = "Xonar HDAV1.3";
1109 break;
1110 case GPIO_DB_H6:
1111 chip->model.shortname = "Xonar HDAV1.3+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001112 chip->model.dac_channels_mixer = 8;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001113 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001114 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";
Clemens Ladischdd203fa2011-01-10 16:05:38 +01001126 chip->model.control_filter = xonar_st_h6_control_filter;
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001127 chip->model.dac_channels_pcm = 8;
1128 chip->model.dac_channels_mixer = 8;
Clemens Ladischc81c6b32011-07-17 22:18:05 +02001129 chip->model.dac_volume_min = 255;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001130 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001131 break;
1132 }
1133 break;
1134 case 0x835c:
1135 chip->model = model_xonar_st;
1136 chip->model.shortname = "Xonar STX";
1137 chip->model.init = xonar_stx_init;
Clemens Ladisch268304f2009-09-28 11:15:01 +02001138 chip->model.resume = xonar_stx_resume;
1139 chip->model.set_dac_params = set_pcm1796_params;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001140 break;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001141 default:
1142 return -EINVAL;
1143 }
1144 return 0;
1145}