blob: 9787193f6ed35d453645040ae7b8df2dac2e6179 [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 Ladisch6f0de3c2009-09-28 11:18:45 +0200330 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100331 PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200332 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
333 PCM1796_FLT_SHARP | PCM1796_ATS_1;
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100334 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] =
335 data->h6 ? PCM1796_OS_64 : PCM1796_OS_128;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200336 pcm1796_registers_init(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200337 data->current_rate = 48000;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200338}
339
340static void xonar_d2_init(struct oxygen *chip)
341{
342 struct xonar_pcm179x *data = chip->model_data;
343
344 data->generic.anti_pop_delay = 300;
345 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
346 data->dacs = 4;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200347
348 pcm1796_init(chip);
349
350 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
351 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
352
353 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
354
355 xonar_init_cs53x1(chip);
356 xonar_enable_output(chip);
357
358 snd_component_add(chip->card, "PCM1796");
359 snd_component_add(chip->card, "CS5381");
360}
361
362static void xonar_d2x_init(struct oxygen *chip)
363{
364 struct xonar_pcm179x *data = chip->model_data;
365
366 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
367 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
368 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
369 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
370 xonar_init_ext_power(chip);
371 xonar_d2_init(chip);
372}
373
374static void xonar_hdav_init(struct oxygen *chip)
375{
376 struct xonar_hdav *data = chip->model_data;
377
378 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
379 OXYGEN_2WIRE_LENGTH_8 |
380 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100381 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200382
383 data->pcm179x.generic.anti_pop_delay = 100;
384 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
385 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
386 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
387 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100388 data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100389 data->pcm179x.h6 = chip->model.dac_channels_mixer > 2;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200390
391 pcm1796_init(chip);
392
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100393 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
394 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200395 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
396
397 xonar_init_cs53x1(chip);
398 xonar_init_ext_power(chip);
399 xonar_hdmi_init(chip, &data->hdmi);
400 xonar_enable_output(chip);
401
402 snd_component_add(chip->card, "PCM1796");
403 snd_component_add(chip->card, "CS5381");
404}
405
Clemens Ladisch268304f2009-09-28 11:15:01 +0200406static void xonar_st_init_i2c(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200407{
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200408 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
409 OXYGEN_2WIRE_LENGTH_8 |
410 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100411 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200412}
413
414static void xonar_st_init_common(struct oxygen *chip)
415{
416 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200417
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200418 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100419 data->dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladischa361e242009-09-28 11:19:19 +0200420 data->hp_gain_offset = 2*-18;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200421
422 pcm1796_init(chip);
423
424 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100425 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
426 GPIO_ST_MAGIC | GPIO_ST_HP);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200427 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
428 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
429
430 xonar_init_cs53x1(chip);
431 xonar_enable_output(chip);
432
433 snd_component_add(chip->card, "PCM1792A");
434 snd_component_add(chip->card, "CS5381");
435}
436
Clemens Ladisch268304f2009-09-28 11:15:01 +0200437static void cs2000_registers_init(struct oxygen *chip)
438{
439 struct xonar_pcm179x *data = chip->model_data;
440
441 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
442 cs2000_write(chip, CS2000_DEV_CTRL, 0);
443 cs2000_write(chip, CS2000_DEV_CFG_1,
444 CS2000_R_MOD_SEL_1 |
445 (0 << CS2000_R_SEL_SHIFT) |
446 CS2000_AUX_OUT_SRC_REF_CLK |
447 CS2000_EN_DEV_CFG_1);
448 cs2000_write(chip, CS2000_DEV_CFG_2,
449 (0 << CS2000_LOCK_CLK_SHIFT) |
450 CS2000_FRAC_N_SRC_STATIC);
451 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
452 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
453 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
454 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100455 cs2000_write(chip, CS2000_FUN_CFG_1,
456 data->cs2000_regs[CS2000_FUN_CFG_1]);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200457 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
458 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100459 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200460}
461
462static void xonar_st_init(struct oxygen *chip)
463{
464 struct xonar_pcm179x *data = chip->model_data;
465
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200466 data->generic.anti_pop_delay = 100;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100467 data->h6 = chip->model.dac_channels_mixer > 2;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200468 data->has_cs2000 = 1;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100469 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100470 data->broken_i2c = true;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200471
472 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100473 OXYGEN_RATE_48000 |
474 OXYGEN_I2S_FORMAT_I2S |
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100475 OXYGEN_I2S_MCLK(data->h6 ? MCLK_256 : MCLK_512) |
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100476 OXYGEN_I2S_BITS_16 |
477 OXYGEN_I2S_MASTER |
478 OXYGEN_I2S_BCLK_64);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200479
480 xonar_st_init_i2c(chip);
481 cs2000_registers_init(chip);
482 xonar_st_init_common(chip);
483
484 snd_component_add(chip->card, "CS2000");
485}
486
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200487static void xonar_stx_init(struct oxygen *chip)
488{
489 struct xonar_pcm179x *data = chip->model_data;
490
Clemens Ladisch268304f2009-09-28 11:15:01 +0200491 xonar_st_init_i2c(chip);
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200492 data->generic.anti_pop_delay = 800;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200493 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
494 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
495 data->generic.ext_power_bit = GPI_EXT_POWER;
496 xonar_init_ext_power(chip);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200497 xonar_st_init_common(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200498}
499
500static void xonar_d2_cleanup(struct oxygen *chip)
501{
502 xonar_disable_output(chip);
503}
504
505static void xonar_hdav_cleanup(struct oxygen *chip)
506{
507 xonar_hdmi_cleanup(chip);
508 xonar_disable_output(chip);
509 msleep(2);
510}
511
512static void xonar_st_cleanup(struct oxygen *chip)
513{
514 xonar_disable_output(chip);
515}
516
517static void xonar_d2_suspend(struct oxygen *chip)
518{
519 xonar_d2_cleanup(chip);
520}
521
522static void xonar_hdav_suspend(struct oxygen *chip)
523{
524 xonar_hdav_cleanup(chip);
525}
526
527static void xonar_st_suspend(struct oxygen *chip)
528{
529 xonar_st_cleanup(chip);
530}
531
532static void xonar_d2_resume(struct oxygen *chip)
533{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200534 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200535 xonar_enable_output(chip);
536}
537
538static void xonar_hdav_resume(struct oxygen *chip)
539{
540 struct xonar_hdav *data = chip->model_data;
541
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200542 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200543 xonar_hdmi_resume(chip, &data->hdmi);
544 xonar_enable_output(chip);
545}
546
Clemens Ladisch268304f2009-09-28 11:15:01 +0200547static void xonar_stx_resume(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200548{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200549 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200550 xonar_enable_output(chip);
551}
552
Clemens Ladisch268304f2009-09-28 11:15:01 +0200553static void xonar_st_resume(struct oxygen *chip)
554{
555 cs2000_registers_init(chip);
556 xonar_stx_resume(chip);
557}
558
Clemens Ladisch973dca92009-09-28 11:20:47 +0200559static void update_pcm1796_oversampling(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200560{
561 struct xonar_pcm179x *data = chip->model_data;
562 unsigned int i;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200563 u8 reg;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200564
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100565 if (data->current_rate <= 48000 && !data->h6)
Clemens Ladisch973dca92009-09-28 11:20:47 +0200566 reg = PCM1796_OS_128;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200567 else
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100568 reg = PCM1796_OS_64;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200569 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200570 pcm1796_write_cached(chip, i, 20, reg);
571}
572
Clemens Ladisch973dca92009-09-28 11:20:47 +0200573static void set_pcm1796_params(struct oxygen *chip,
574 struct snd_pcm_hw_params *params)
575{
576 struct xonar_pcm179x *data = chip->model_data;
577
Clemens Ladisch79815e02011-01-10 16:02:32 +0100578 msleep(1);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200579 data->current_rate = params_rate(params);
580 update_pcm1796_oversampling(chip);
581}
582
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200583static void update_pcm1796_volume(struct oxygen *chip)
584{
585 struct xonar_pcm179x *data = chip->model_data;
586 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200587 s8 gain_offset;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200588
Clemens Ladischa361e242009-09-28 11:19:19 +0200589 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200590 for (i = 0; i < data->dacs; ++i) {
Clemens Ladischa361e242009-09-28 11:19:19 +0200591 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
592 + gain_offset);
593 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
594 + gain_offset);
Clemens Ladischbc29e262011-01-10 16:11:32 +0100595 gain_offset = 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200596 }
597}
598
599static void update_pcm1796_mute(struct oxygen *chip)
600{
601 struct xonar_pcm179x *data = chip->model_data;
602 unsigned int i;
603 u8 value;
604
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100605 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200606 if (chip->dac_mute)
607 value |= PCM1796_MUTE;
608 for (i = 0; i < data->dacs; ++i)
609 pcm1796_write_cached(chip, i, 18, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200610}
611
Clemens Ladisch973dca92009-09-28 11:20:47 +0200612static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200613{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200614 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200615 u8 rate_mclk, reg;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200616
Clemens Ladisch973dca92009-09-28 11:20:47 +0200617 switch (rate) {
Clemens Ladisch973dca92009-09-28 11:20:47 +0200618 case 32000:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100619 case 64000:
620 rate_mclk = OXYGEN_RATE_32000;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200621 break;
622 case 44100:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200623 case 88200:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200624 case 176400:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100625 rate_mclk = OXYGEN_RATE_44100;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200626 break;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100627 default:
628 case 48000:
629 case 96000:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200630 case 192000:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100631 rate_mclk = OXYGEN_RATE_48000;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200632 break;
633 }
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100634
635 if (rate <= 96000 && (rate > 48000 || data->h6)) {
636 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_256);
637 reg = CS2000_REF_CLK_DIV_1;
638 } else {
639 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_512);
640 reg = CS2000_REF_CLK_DIV_2;
641 }
642
Clemens Ladisch268304f2009-09-28 11:15:01 +0200643 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
644 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200645 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100646 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200647}
648
649static void set_st_params(struct oxygen *chip,
650 struct snd_pcm_hw_params *params)
651{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200652 update_cs2000_rate(chip, params_rate(params));
Clemens Ladisch268304f2009-09-28 11:15:01 +0200653 set_pcm1796_params(chip, params);
654}
655
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200656static void set_hdav_params(struct oxygen *chip,
657 struct snd_pcm_hw_params *params)
658{
659 struct xonar_hdav *data = chip->model_data;
660
661 set_pcm1796_params(chip, params);
662 xonar_set_hdmi_params(chip, &data->hdmi, params);
663}
664
665static const struct snd_kcontrol_new alt_switch = {
666 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
667 .name = "Analog Loopback Switch",
668 .info = snd_ctl_boolean_mono_info,
669 .get = xonar_gpio_bit_switch_get,
670 .put = xonar_gpio_bit_switch_put,
671 .private_value = GPIO_D2_ALT,
672};
673
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200674static int rolloff_info(struct snd_kcontrol *ctl,
675 struct snd_ctl_elem_info *info)
676{
677 static const char *const names[2] = {
678 "Sharp Roll-off", "Slow Roll-off"
679 };
680
681 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
682 info->count = 1;
683 info->value.enumerated.items = 2;
684 if (info->value.enumerated.item >= 2)
685 info->value.enumerated.item = 1;
686 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
687 return 0;
688}
689
690static int rolloff_get(struct snd_kcontrol *ctl,
691 struct snd_ctl_elem_value *value)
692{
693 struct oxygen *chip = ctl->private_data;
694 struct xonar_pcm179x *data = chip->model_data;
695
696 value->value.enumerated.item[0] =
697 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
698 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
699 return 0;
700}
701
702static int rolloff_put(struct snd_kcontrol *ctl,
703 struct snd_ctl_elem_value *value)
704{
705 struct oxygen *chip = ctl->private_data;
706 struct xonar_pcm179x *data = chip->model_data;
707 unsigned int i;
708 int changed;
709 u8 reg;
710
711 mutex_lock(&chip->mutex);
712 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
713 reg &= ~PCM1796_FLT_MASK;
714 if (!value->value.enumerated.item[0])
715 reg |= PCM1796_FLT_SHARP;
716 else
717 reg |= PCM1796_FLT_SLOW;
718 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
719 if (changed) {
720 for (i = 0; i < data->dacs; ++i)
721 pcm1796_write(chip, i, 19, reg);
722 }
723 mutex_unlock(&chip->mutex);
724 return changed;
725}
726
727static const struct snd_kcontrol_new rolloff_control = {
728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
729 .name = "DAC Filter Playback Enum",
730 .info = rolloff_info,
731 .get = rolloff_get,
732 .put = rolloff_put,
733};
734
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100735static const struct snd_kcontrol_new hdav_hdmi_control = {
736 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
737 .name = "HDMI Playback Switch",
738 .info = snd_ctl_boolean_mono_info,
739 .get = xonar_gpio_bit_switch_get,
740 .put = xonar_gpio_bit_switch_put,
741 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
742};
743
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200744static int st_output_switch_info(struct snd_kcontrol *ctl,
745 struct snd_ctl_elem_info *info)
746{
747 static const char *const names[3] = {
748 "Speakers", "Headphones", "FP Headphones"
749 };
750
751 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
752 info->count = 1;
753 info->value.enumerated.items = 3;
754 if (info->value.enumerated.item >= 3)
755 info->value.enumerated.item = 2;
756 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
757 return 0;
758}
759
760static int st_output_switch_get(struct snd_kcontrol *ctl,
761 struct snd_ctl_elem_value *value)
762{
763 struct oxygen *chip = ctl->private_data;
764 u16 gpio;
765
766 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
767 if (!(gpio & GPIO_ST_HP))
768 value->value.enumerated.item[0] = 0;
769 else if (gpio & GPIO_ST_HP_REAR)
770 value->value.enumerated.item[0] = 1;
771 else
772 value->value.enumerated.item[0] = 2;
773 return 0;
774}
775
776
777static int st_output_switch_put(struct snd_kcontrol *ctl,
778 struct snd_ctl_elem_value *value)
779{
780 struct oxygen *chip = ctl->private_data;
Clemens Ladischa361e242009-09-28 11:19:19 +0200781 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200782 u16 gpio_old, gpio;
783
784 mutex_lock(&chip->mutex);
785 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
786 gpio = gpio_old;
787 switch (value->value.enumerated.item[0]) {
788 case 0:
789 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
790 break;
791 case 1:
792 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
793 break;
794 case 2:
795 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
796 break;
797 }
798 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
Clemens Ladischa361e242009-09-28 11:19:19 +0200799 data->hp_active = gpio & GPIO_ST_HP;
800 update_pcm1796_volume(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200801 mutex_unlock(&chip->mutex);
802 return gpio != gpio_old;
803}
804
Clemens Ladischa361e242009-09-28 11:19:19 +0200805static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
806 struct snd_ctl_elem_info *info)
807{
808 static const char *const names[3] = {
809 "< 64 ohms", "64-300 ohms", "300-600 ohms"
810 };
811
812 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
813 info->count = 1;
814 info->value.enumerated.items = 3;
815 if (info->value.enumerated.item > 2)
816 info->value.enumerated.item = 2;
817 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
818 return 0;
819}
820
821static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
822 struct snd_ctl_elem_value *value)
823{
824 struct oxygen *chip = ctl->private_data;
825 struct xonar_pcm179x *data = chip->model_data;
826
827 mutex_lock(&chip->mutex);
828 if (data->hp_gain_offset < 2*-6)
829 value->value.enumerated.item[0] = 0;
830 else if (data->hp_gain_offset < 0)
831 value->value.enumerated.item[0] = 1;
832 else
833 value->value.enumerated.item[0] = 2;
834 mutex_unlock(&chip->mutex);
835 return 0;
836}
837
838
839static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
840 struct snd_ctl_elem_value *value)
841{
842 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
843 struct oxygen *chip = ctl->private_data;
844 struct xonar_pcm179x *data = chip->model_data;
845 s8 offset;
846 int changed;
847
848 if (value->value.enumerated.item[0] > 2)
849 return -EINVAL;
850 offset = offsets[value->value.enumerated.item[0]];
851 mutex_lock(&chip->mutex);
852 changed = offset != data->hp_gain_offset;
853 if (changed) {
854 data->hp_gain_offset = offset;
855 update_pcm1796_volume(chip);
856 }
857 mutex_unlock(&chip->mutex);
858 return changed;
859}
860
861static const struct snd_kcontrol_new st_controls[] = {
862 {
863 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
864 .name = "Analog Output",
865 .info = st_output_switch_info,
866 .get = st_output_switch_get,
867 .put = st_output_switch_put,
868 },
869 {
870 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
871 .name = "Headphones Impedance Playback Enum",
872 .info = st_hp_volume_offset_info,
873 .get = st_hp_volume_offset_get,
874 .put = st_hp_volume_offset_put,
875 },
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200876};
877
878static void xonar_line_mic_ac97_switch(struct oxygen *chip,
879 unsigned int reg, unsigned int mute)
880{
881 if (reg == AC97_LINE) {
882 spin_lock_irq(&chip->reg_lock);
883 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
884 mute ? GPIO_INPUT_ROUTE : 0,
885 GPIO_INPUT_ROUTE);
886 spin_unlock_irq(&chip->reg_lock);
887 }
888}
889
890static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
891
892static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
893{
894 if (!strncmp(template->name, "CD Capture ", 11))
895 /* CD in is actually connected to the video in pin */
896 template->private_value ^= AC97_CD ^ AC97_VIDEO;
897 return 0;
898}
899
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100900static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
901{
902 if (!strncmp(template->name, "Master Playback ", 16))
903 /* no volume/mute, as I²C to the third DAC does not work */
904 return 1;
905 return 0;
906}
907
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200908static int add_pcm1796_controls(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200909{
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100910 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200911 int err;
912
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100913 if (!data->broken_i2c) {
914 err = snd_ctl_add(chip->card,
915 snd_ctl_new1(&rolloff_control, chip));
916 if (err < 0)
917 return err;
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100918 }
Clemens Ladisch973dca92009-09-28 11:20:47 +0200919 return 0;
920}
921
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200922static int xonar_d2_mixer_init(struct oxygen *chip)
923{
924 int err;
925
926 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
927 if (err < 0)
928 return err;
929 err = add_pcm1796_controls(chip);
930 if (err < 0)
931 return err;
932 return 0;
933}
934
Clemens Ladisch973dca92009-09-28 11:20:47 +0200935static int xonar_hdav_mixer_init(struct oxygen *chip)
936{
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100937 int err;
938
939 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
940 if (err < 0)
941 return err;
942 err = add_pcm1796_controls(chip);
943 if (err < 0)
944 return err;
945 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200946}
947
948static int xonar_st_mixer_init(struct oxygen *chip)
949{
Clemens Ladischa361e242009-09-28 11:19:19 +0200950 unsigned int i;
951 int err;
952
953 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
954 err = snd_ctl_add(chip->card,
955 snd_ctl_new1(&st_controls[i], chip));
956 if (err < 0)
957 return err;
958 }
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200959 err = add_pcm1796_controls(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200960 if (err < 0)
961 return err;
Clemens Ladischa361e242009-09-28 11:19:19 +0200962 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200963}
964
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100965static void dump_pcm1796_registers(struct oxygen *chip,
966 struct snd_info_buffer *buffer)
967{
968 struct xonar_pcm179x *data = chip->model_data;
969 unsigned int dac, i;
970
971 for (dac = 0; dac < data->dacs; ++dac) {
972 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
973 for (i = 0; i < 5; ++i)
974 snd_iprintf(buffer, " %02x",
975 data->pcm1796_regs[dac][i]);
976 }
977 snd_iprintf(buffer, "\n");
978}
979
980static void dump_cs2000_registers(struct oxygen *chip,
981 struct snd_info_buffer *buffer)
982{
983 struct xonar_pcm179x *data = chip->model_data;
984 unsigned int i;
985
986 if (data->has_cs2000) {
987 snd_iprintf(buffer, "\nCS2000:\n00: ");
988 for (i = 1; i < 0x10; ++i)
989 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
990 snd_iprintf(buffer, "\n10:");
991 for (i = 0x10; i < 0x1f; ++i)
992 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
993 snd_iprintf(buffer, "\n");
994 }
995}
996
997static void dump_st_registers(struct oxygen *chip,
998 struct snd_info_buffer *buffer)
999{
1000 dump_pcm1796_registers(chip, buffer);
1001 dump_cs2000_registers(chip, buffer);
1002}
1003
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001004static const struct oxygen_model model_xonar_d2 = {
1005 .longname = "Asus Virtuoso 200",
1006 .chip = "AV200",
1007 .init = xonar_d2_init,
1008 .control_filter = xonar_d2_control_filter,
1009 .mixer_init = xonar_d2_mixer_init,
1010 .cleanup = xonar_d2_cleanup,
1011 .suspend = xonar_d2_suspend,
1012 .resume = xonar_d2_resume,
1013 .set_dac_params = set_pcm1796_params,
1014 .set_adc_params = xonar_set_cs53x1_params,
1015 .update_dac_volume = update_pcm1796_volume,
1016 .update_dac_mute = update_pcm1796_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001017 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001018 .dac_tlv = pcm1796_db_scale,
1019 .model_data_size = sizeof(struct xonar_pcm179x),
1020 .device_config = PLAYBACK_0_TO_I2S |
1021 PLAYBACK_1_TO_SPDIF |
1022 CAPTURE_0_FROM_I2S_2 |
1023 CAPTURE_1_FROM_SPDIF |
1024 MIDI_OUTPUT |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +02001025 MIDI_INPUT |
1026 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001027 .dac_channels_pcm = 8,
1028 .dac_channels_mixer = 8,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001029 .dac_volume_min = 255 - 2*60,
1030 .dac_volume_max = 255,
1031 .misc_flags = OXYGEN_MISC_MIDI,
1032 .function_flags = OXYGEN_FUNCTION_SPI |
1033 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001034 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
1035 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001036 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001037 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1038};
1039
1040static const struct oxygen_model model_xonar_hdav = {
1041 .longname = "Asus Virtuoso 200",
1042 .chip = "AV200",
1043 .init = xonar_hdav_init,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001044 .mixer_init = xonar_hdav_mixer_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001045 .cleanup = xonar_hdav_cleanup,
1046 .suspend = xonar_hdav_suspend,
1047 .resume = xonar_hdav_resume,
1048 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1049 .set_dac_params = set_hdav_params,
1050 .set_adc_params = xonar_set_cs53x1_params,
1051 .update_dac_volume = update_pcm1796_volume,
1052 .update_dac_mute = update_pcm1796_mute,
1053 .uart_input = xonar_hdmi_uart_input,
1054 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001055 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001056 .dac_tlv = pcm1796_db_scale,
1057 .model_data_size = sizeof(struct xonar_hdav),
1058 .device_config = PLAYBACK_0_TO_I2S |
1059 PLAYBACK_1_TO_SPDIF |
1060 CAPTURE_0_FROM_I2S_2 |
1061 CAPTURE_1_FROM_SPDIF,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001062 .dac_channels_pcm = 8,
1063 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001064 .dac_volume_min = 255 - 2*60,
1065 .dac_volume_max = 255,
1066 .misc_flags = OXYGEN_MISC_MIDI,
1067 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001068 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
1069 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001070 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001071 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1072};
1073
1074static const struct oxygen_model model_xonar_st = {
1075 .longname = "Asus Virtuoso 100",
1076 .chip = "AV200",
1077 .init = xonar_st_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001078 .mixer_init = xonar_st_mixer_init,
1079 .cleanup = xonar_st_cleanup,
1080 .suspend = xonar_st_suspend,
1081 .resume = xonar_st_resume,
Clemens Ladisch268304f2009-09-28 11:15:01 +02001082 .set_dac_params = set_st_params,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001083 .set_adc_params = xonar_set_cs53x1_params,
1084 .update_dac_volume = update_pcm1796_volume,
1085 .update_dac_mute = update_pcm1796_mute,
1086 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001087 .dump_registers = dump_st_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001088 .dac_tlv = pcm1796_db_scale,
1089 .model_data_size = sizeof(struct xonar_pcm179x),
1090 .device_config = PLAYBACK_0_TO_I2S |
1091 PLAYBACK_1_TO_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001092 CAPTURE_0_FROM_I2S_2 |
1093 AC97_FMIC_SWITCH,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001094 .dac_channels_pcm = 2,
1095 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001096 .dac_volume_min = 255 - 2*60,
1097 .dac_volume_max = 255,
1098 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001099 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
1100 .adc_mclks = OXYGEN_MCLKS(256, 256, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001101 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001102 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1103};
1104
1105int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1106 const struct pci_device_id *id)
1107{
1108 switch (id->subdevice) {
1109 case 0x8269:
1110 chip->model = model_xonar_d2;
1111 chip->model.shortname = "Xonar D2";
1112 break;
1113 case 0x82b7:
1114 chip->model = model_xonar_d2;
1115 chip->model.shortname = "Xonar D2X";
1116 chip->model.init = xonar_d2x_init;
1117 break;
1118 case 0x8314:
1119 chip->model = model_xonar_hdav;
1120 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1121 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1122 default:
1123 chip->model.shortname = "Xonar HDAV1.3";
1124 break;
1125 case GPIO_DB_H6:
1126 chip->model.shortname = "Xonar HDAV1.3+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001127 chip->model.dac_channels_mixer = 8;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001128 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001129 break;
1130 }
1131 break;
1132 case 0x835d:
1133 chip->model = model_xonar_st;
1134 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1135 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1136 default:
1137 chip->model.shortname = "Xonar ST";
1138 break;
1139 case GPIO_DB_H6:
1140 chip->model.shortname = "Xonar ST+H6";
Clemens Ladischdd203fa2011-01-10 16:05:38 +01001141 chip->model.control_filter = xonar_st_h6_control_filter;
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001142 chip->model.dac_channels_pcm = 8;
1143 chip->model.dac_channels_mixer = 8;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001144 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001145 break;
1146 }
1147 break;
1148 case 0x835c:
1149 chip->model = model_xonar_st;
1150 chip->model.shortname = "Xonar STX";
1151 chip->model.init = xonar_stx_init;
Clemens Ladisch268304f2009-09-28 11:15:01 +02001152 chip->model.resume = xonar_stx_resume;
1153 chip->model.set_dac_params = set_pcm1796_params;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001154 break;
Clemens Ladisch2b830ba2010-10-04 13:22:51 +02001155 case 0x835e:
1156 snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");
1157 return -ENODEV;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001158 default:
1159 return -EINVAL;
1160 }
1161 return 0;
1162}