blob: b55149e9be818b96724a569b21871ce4626cfc54 [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;
226 bool os_128;
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 Ladisch65c3ac82009-09-28 11:11:27 +0200231};
232
233struct xonar_hdav {
234 struct xonar_pcm179x pcm179x;
235 struct xonar_hdmi hdmi;
236};
237
238
239static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
240 u8 reg, u8 value)
241{
242 /* maps ALSA channel pair number to SPI output */
243 static const u8 codec_map[4] = {
244 0, 1, 2, 4
245 };
246 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
247 OXYGEN_SPI_DATA_LENGTH_2 |
248 OXYGEN_SPI_CLOCK_160 |
249 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
250 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
251 (reg << 8) | value);
252}
253
254static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
255 u8 reg, u8 value)
256{
257 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
258}
259
260static void pcm1796_write(struct oxygen *chip, unsigned int codec,
261 u8 reg, u8 value)
262{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200263 struct xonar_pcm179x *data = chip->model_data;
264
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200265 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
266 OXYGEN_FUNCTION_SPI)
267 pcm1796_write_spi(chip, codec, reg, value);
268 else
269 pcm1796_write_i2c(chip, codec, reg, value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200270 if ((unsigned int)(reg - PCM1796_REG_BASE)
271 < ARRAY_SIZE(data->pcm1796_regs[codec]))
272 data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
273}
274
275static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
276 u8 reg, u8 value)
277{
278 struct xonar_pcm179x *data = chip->model_data;
279
280 if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
281 pcm1796_write(chip, codec, reg, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200282}
283
Clemens Ladisch268304f2009-09-28 11:15:01 +0200284static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
285{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200286 struct xonar_pcm179x *data = chip->model_data;
287
Clemens Ladisch268304f2009-09-28 11:15:01 +0200288 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100289 data->cs2000_regs[reg] = value;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200290}
291
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200292static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
293{
294 struct xonar_pcm179x *data = chip->model_data;
295
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100296 if (value != data->cs2000_regs[reg])
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200297 cs2000_write(chip, reg, value);
298}
299
300static void pcm1796_registers_init(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200301{
302 struct xonar_pcm179x *data = chip->model_data;
303 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200304 s8 gain_offset;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200305
Clemens Ladischa361e242009-09-28 11:19:19 +0200306 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200307 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200308 /* set ATLD before ATL/ATR */
309 pcm1796_write(chip, i, 18,
310 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
Clemens Ladischa361e242009-09-28 11:19:19 +0200311 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
312 + gain_offset);
313 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
314 + gain_offset);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200315 pcm1796_write(chip, i, 19,
316 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200317 pcm1796_write(chip, i, 20,
318 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
319 pcm1796_write(chip, i, 21, 0);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200320 }
321}
322
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200323static void pcm1796_init(struct oxygen *chip)
324{
325 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200326
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200327 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
328 PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200329 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
330 PCM1796_FLT_SHARP | PCM1796_ATS_1;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200331 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
332 pcm1796_registers_init(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200333 data->current_rate = 48000;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200334}
335
336static void xonar_d2_init(struct oxygen *chip)
337{
338 struct xonar_pcm179x *data = chip->model_data;
339
340 data->generic.anti_pop_delay = 300;
341 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
342 data->dacs = 4;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200343
344 pcm1796_init(chip);
345
346 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
347 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
348
349 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
350
351 xonar_init_cs53x1(chip);
352 xonar_enable_output(chip);
353
354 snd_component_add(chip->card, "PCM1796");
355 snd_component_add(chip->card, "CS5381");
356}
357
358static void xonar_d2x_init(struct oxygen *chip)
359{
360 struct xonar_pcm179x *data = chip->model_data;
361
362 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
363 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
364 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
365 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
366 xonar_init_ext_power(chip);
367 xonar_d2_init(chip);
368}
369
370static void xonar_hdav_init(struct oxygen *chip)
371{
372 struct xonar_hdav *data = chip->model_data;
373
374 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
375 OXYGEN_2WIRE_LENGTH_8 |
376 OXYGEN_2WIRE_INTERRUPT_MASK |
377 OXYGEN_2WIRE_SPEED_FAST);
378
379 data->pcm179x.generic.anti_pop_delay = 100;
380 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
381 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
382 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
383 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
384 data->pcm179x.dacs = chip->model.private_data ? 4 : 1;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200385
386 pcm1796_init(chip);
387
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100388 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
389 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200390 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
391
392 xonar_init_cs53x1(chip);
393 xonar_init_ext_power(chip);
394 xonar_hdmi_init(chip, &data->hdmi);
395 xonar_enable_output(chip);
396
397 snd_component_add(chip->card, "PCM1796");
398 snd_component_add(chip->card, "CS5381");
399}
400
Clemens Ladisch268304f2009-09-28 11:15:01 +0200401static void xonar_st_init_i2c(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200402{
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200403 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
404 OXYGEN_2WIRE_LENGTH_8 |
405 OXYGEN_2WIRE_INTERRUPT_MASK |
406 OXYGEN_2WIRE_SPEED_FAST);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200407}
408
409static void xonar_st_init_common(struct oxygen *chip)
410{
411 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200412
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200413 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
414 data->dacs = chip->model.private_data ? 4 : 1;
Clemens Ladischa361e242009-09-28 11:19:19 +0200415 data->hp_gain_offset = 2*-18;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200416
417 pcm1796_init(chip);
418
419 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100420 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
421 GPIO_ST_MAGIC | GPIO_ST_HP);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200422 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
423 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
424
425 xonar_init_cs53x1(chip);
426 xonar_enable_output(chip);
427
428 snd_component_add(chip->card, "PCM1792A");
429 snd_component_add(chip->card, "CS5381");
430}
431
Clemens Ladisch268304f2009-09-28 11:15:01 +0200432static void cs2000_registers_init(struct oxygen *chip)
433{
434 struct xonar_pcm179x *data = chip->model_data;
435
436 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
437 cs2000_write(chip, CS2000_DEV_CTRL, 0);
438 cs2000_write(chip, CS2000_DEV_CFG_1,
439 CS2000_R_MOD_SEL_1 |
440 (0 << CS2000_R_SEL_SHIFT) |
441 CS2000_AUX_OUT_SRC_REF_CLK |
442 CS2000_EN_DEV_CFG_1);
443 cs2000_write(chip, CS2000_DEV_CFG_2,
444 (0 << CS2000_LOCK_CLK_SHIFT) |
445 CS2000_FRAC_N_SRC_STATIC);
446 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
447 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
448 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
449 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100450 cs2000_write(chip, CS2000_FUN_CFG_1,
451 data->cs2000_regs[CS2000_FUN_CFG_1]);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200452 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
453 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
454}
455
456static void xonar_st_init(struct oxygen *chip)
457{
458 struct xonar_pcm179x *data = chip->model_data;
459
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200460 data->generic.anti_pop_delay = 100;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200461 data->has_cs2000 = 1;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100462 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200463
464 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
465 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
466 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
467 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
468
469 xonar_st_init_i2c(chip);
470 cs2000_registers_init(chip);
471 xonar_st_init_common(chip);
472
473 snd_component_add(chip->card, "CS2000");
474}
475
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200476static void xonar_stx_init(struct oxygen *chip)
477{
478 struct xonar_pcm179x *data = chip->model_data;
479
Clemens Ladisch268304f2009-09-28 11:15:01 +0200480 xonar_st_init_i2c(chip);
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200481 data->generic.anti_pop_delay = 800;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200482 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
483 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
484 data->generic.ext_power_bit = GPI_EXT_POWER;
485 xonar_init_ext_power(chip);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200486 xonar_st_init_common(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200487}
488
489static void xonar_d2_cleanup(struct oxygen *chip)
490{
491 xonar_disable_output(chip);
492}
493
494static void xonar_hdav_cleanup(struct oxygen *chip)
495{
496 xonar_hdmi_cleanup(chip);
497 xonar_disable_output(chip);
498 msleep(2);
499}
500
501static void xonar_st_cleanup(struct oxygen *chip)
502{
503 xonar_disable_output(chip);
504}
505
506static void xonar_d2_suspend(struct oxygen *chip)
507{
508 xonar_d2_cleanup(chip);
509}
510
511static void xonar_hdav_suspend(struct oxygen *chip)
512{
513 xonar_hdav_cleanup(chip);
514}
515
516static void xonar_st_suspend(struct oxygen *chip)
517{
518 xonar_st_cleanup(chip);
519}
520
521static void xonar_d2_resume(struct oxygen *chip)
522{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200523 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200524 xonar_enable_output(chip);
525}
526
527static void xonar_hdav_resume(struct oxygen *chip)
528{
529 struct xonar_hdav *data = chip->model_data;
530
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200531 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200532 xonar_hdmi_resume(chip, &data->hdmi);
533 xonar_enable_output(chip);
534}
535
Clemens Ladisch268304f2009-09-28 11:15:01 +0200536static void xonar_stx_resume(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200537{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200538 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200539 xonar_enable_output(chip);
540}
541
Clemens Ladisch268304f2009-09-28 11:15:01 +0200542static void xonar_st_resume(struct oxygen *chip)
543{
544 cs2000_registers_init(chip);
545 xonar_stx_resume(chip);
546}
547
Clemens Ladisch973dca92009-09-28 11:20:47 +0200548static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
549{
550 struct xonar_pcm179x *data = chip->model_data;
551
552 if (rate <= 32000)
553 return OXYGEN_I2S_MCLK_512;
554 else if (rate <= 48000 && data->os_128)
555 return OXYGEN_I2S_MCLK_512;
556 else if (rate <= 96000)
557 return OXYGEN_I2S_MCLK_256;
558 else
559 return OXYGEN_I2S_MCLK_128;
560}
561
562static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
563 unsigned int channel,
564 struct snd_pcm_hw_params *params)
565{
566 if (channel == PCM_MULTICH)
567 return mclk_from_rate(chip, params_rate(params));
568 else
569 return oxygen_default_i2s_mclk(chip, channel, params);
570}
571
572static void update_pcm1796_oversampling(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200573{
574 struct xonar_pcm179x *data = chip->model_data;
575 unsigned int i;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200576 u8 reg;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200577
Clemens Ladisch973dca92009-09-28 11:20:47 +0200578 if (data->current_rate <= 32000)
579 reg = PCM1796_OS_128;
580 else if (data->current_rate <= 48000 && data->os_128)
581 reg = PCM1796_OS_128;
582 else if (data->current_rate <= 96000 || data->os_128)
583 reg = PCM1796_OS_64;
584 else
585 reg = PCM1796_OS_32;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200586 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200587 pcm1796_write_cached(chip, i, 20, reg);
588}
589
Clemens Ladisch973dca92009-09-28 11:20:47 +0200590static void set_pcm1796_params(struct oxygen *chip,
591 struct snd_pcm_hw_params *params)
592{
593 struct xonar_pcm179x *data = chip->model_data;
594
595 data->current_rate = params_rate(params);
596 update_pcm1796_oversampling(chip);
597}
598
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200599static void update_pcm1796_volume(struct oxygen *chip)
600{
601 struct xonar_pcm179x *data = chip->model_data;
602 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200603 s8 gain_offset;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200604
Clemens Ladischa361e242009-09-28 11:19:19 +0200605 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200606 for (i = 0; i < data->dacs; ++i) {
Clemens Ladischa361e242009-09-28 11:19:19 +0200607 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
608 + gain_offset);
609 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
610 + gain_offset);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200611 }
612}
613
614static void update_pcm1796_mute(struct oxygen *chip)
615{
616 struct xonar_pcm179x *data = chip->model_data;
617 unsigned int i;
618 u8 value;
619
620 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
621 if (chip->dac_mute)
622 value |= PCM1796_MUTE;
623 for (i = 0; i < data->dacs; ++i)
624 pcm1796_write_cached(chip, i, 18, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200625}
626
Clemens Ladisch973dca92009-09-28 11:20:47 +0200627static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200628{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200629 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200630 u8 rate_mclk, reg;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200631
Clemens Ladisch973dca92009-09-28 11:20:47 +0200632 switch (rate) {
633 /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */
634 case 32000:
635 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
636 break;
637 case 44100:
638 if (data->os_128)
639 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
640 else
641 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128;
642 break;
643 default: /* 48000 */
644 if (data->os_128)
645 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
646 else
647 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128;
648 break;
649 case 64000:
650 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
651 break;
652 case 88200:
653 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
654 break;
655 case 96000:
656 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
657 break;
658 case 176400:
659 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
660 break;
661 case 192000:
662 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
663 break;
664 }
Clemens Ladisch268304f2009-09-28 11:15:01 +0200665 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
666 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
667 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200668 reg = CS2000_REF_CLK_DIV_1;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200669 else
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200670 reg = CS2000_REF_CLK_DIV_2;
671 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200672}
673
674static void set_st_params(struct oxygen *chip,
675 struct snd_pcm_hw_params *params)
676{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200677 update_cs2000_rate(chip, params_rate(params));
Clemens Ladisch268304f2009-09-28 11:15:01 +0200678 set_pcm1796_params(chip, params);
679}
680
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200681static void set_hdav_params(struct oxygen *chip,
682 struct snd_pcm_hw_params *params)
683{
684 struct xonar_hdav *data = chip->model_data;
685
686 set_pcm1796_params(chip, params);
687 xonar_set_hdmi_params(chip, &data->hdmi, params);
688}
689
690static const struct snd_kcontrol_new alt_switch = {
691 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
692 .name = "Analog Loopback Switch",
693 .info = snd_ctl_boolean_mono_info,
694 .get = xonar_gpio_bit_switch_get,
695 .put = xonar_gpio_bit_switch_put,
696 .private_value = GPIO_D2_ALT,
697};
698
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200699static int rolloff_info(struct snd_kcontrol *ctl,
700 struct snd_ctl_elem_info *info)
701{
702 static const char *const names[2] = {
703 "Sharp Roll-off", "Slow Roll-off"
704 };
705
706 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
707 info->count = 1;
708 info->value.enumerated.items = 2;
709 if (info->value.enumerated.item >= 2)
710 info->value.enumerated.item = 1;
711 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
712 return 0;
713}
714
715static int rolloff_get(struct snd_kcontrol *ctl,
716 struct snd_ctl_elem_value *value)
717{
718 struct oxygen *chip = ctl->private_data;
719 struct xonar_pcm179x *data = chip->model_data;
720
721 value->value.enumerated.item[0] =
722 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
723 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
724 return 0;
725}
726
727static int rolloff_put(struct snd_kcontrol *ctl,
728 struct snd_ctl_elem_value *value)
729{
730 struct oxygen *chip = ctl->private_data;
731 struct xonar_pcm179x *data = chip->model_data;
732 unsigned int i;
733 int changed;
734 u8 reg;
735
736 mutex_lock(&chip->mutex);
737 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
738 reg &= ~PCM1796_FLT_MASK;
739 if (!value->value.enumerated.item[0])
740 reg |= PCM1796_FLT_SHARP;
741 else
742 reg |= PCM1796_FLT_SLOW;
743 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
744 if (changed) {
745 for (i = 0; i < data->dacs; ++i)
746 pcm1796_write(chip, i, 19, reg);
747 }
748 mutex_unlock(&chip->mutex);
749 return changed;
750}
751
752static const struct snd_kcontrol_new rolloff_control = {
753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
754 .name = "DAC Filter Playback Enum",
755 .info = rolloff_info,
756 .get = rolloff_get,
757 .put = rolloff_put,
758};
759
Clemens Ladisch973dca92009-09-28 11:20:47 +0200760static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
761{
762 static const char *const names[2] = { "64x", "128x" };
763
764 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
765 info->count = 1;
766 info->value.enumerated.items = 2;
767 if (info->value.enumerated.item >= 2)
768 info->value.enumerated.item = 1;
769 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
770 return 0;
771}
772
773static int os_128_get(struct snd_kcontrol *ctl,
774 struct snd_ctl_elem_value *value)
775{
776 struct oxygen *chip = ctl->private_data;
777 struct xonar_pcm179x *data = chip->model_data;
778
779 value->value.enumerated.item[0] = data->os_128;
780 return 0;
781}
782
783static int os_128_put(struct snd_kcontrol *ctl,
784 struct snd_ctl_elem_value *value)
785{
786 struct oxygen *chip = ctl->private_data;
787 struct xonar_pcm179x *data = chip->model_data;
788 int changed;
789
790 mutex_lock(&chip->mutex);
791 changed = value->value.enumerated.item[0] != data->os_128;
792 if (changed) {
793 data->os_128 = value->value.enumerated.item[0];
794 if (data->has_cs2000)
795 update_cs2000_rate(chip, data->current_rate);
796 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
797 mclk_from_rate(chip, data->current_rate),
798 OXYGEN_I2S_MCLK_MASK);
799 update_pcm1796_oversampling(chip);
800 }
801 mutex_unlock(&chip->mutex);
802 return changed;
803}
804
805static const struct snd_kcontrol_new os_128_control = {
806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
807 .name = "DAC Oversampling Playback Enum",
808 .info = os_128_info,
809 .get = os_128_get,
810 .put = os_128_put,
811};
812
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100813static const struct snd_kcontrol_new hdav_hdmi_control = {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "HDMI Playback Switch",
816 .info = snd_ctl_boolean_mono_info,
817 .get = xonar_gpio_bit_switch_get,
818 .put = xonar_gpio_bit_switch_put,
819 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
820};
821
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200822static int st_output_switch_info(struct snd_kcontrol *ctl,
823 struct snd_ctl_elem_info *info)
824{
825 static const char *const names[3] = {
826 "Speakers", "Headphones", "FP Headphones"
827 };
828
829 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
830 info->count = 1;
831 info->value.enumerated.items = 3;
832 if (info->value.enumerated.item >= 3)
833 info->value.enumerated.item = 2;
834 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
835 return 0;
836}
837
838static int st_output_switch_get(struct snd_kcontrol *ctl,
839 struct snd_ctl_elem_value *value)
840{
841 struct oxygen *chip = ctl->private_data;
842 u16 gpio;
843
844 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
845 if (!(gpio & GPIO_ST_HP))
846 value->value.enumerated.item[0] = 0;
847 else if (gpio & GPIO_ST_HP_REAR)
848 value->value.enumerated.item[0] = 1;
849 else
850 value->value.enumerated.item[0] = 2;
851 return 0;
852}
853
854
855static int st_output_switch_put(struct snd_kcontrol *ctl,
856 struct snd_ctl_elem_value *value)
857{
858 struct oxygen *chip = ctl->private_data;
Clemens Ladischa361e242009-09-28 11:19:19 +0200859 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200860 u16 gpio_old, gpio;
861
862 mutex_lock(&chip->mutex);
863 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
864 gpio = gpio_old;
865 switch (value->value.enumerated.item[0]) {
866 case 0:
867 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
868 break;
869 case 1:
870 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
871 break;
872 case 2:
873 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
874 break;
875 }
876 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
Clemens Ladischa361e242009-09-28 11:19:19 +0200877 data->hp_active = gpio & GPIO_ST_HP;
878 update_pcm1796_volume(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200879 mutex_unlock(&chip->mutex);
880 return gpio != gpio_old;
881}
882
Clemens Ladischa361e242009-09-28 11:19:19 +0200883static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
884 struct snd_ctl_elem_info *info)
885{
886 static const char *const names[3] = {
887 "< 64 ohms", "64-300 ohms", "300-600 ohms"
888 };
889
890 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
891 info->count = 1;
892 info->value.enumerated.items = 3;
893 if (info->value.enumerated.item > 2)
894 info->value.enumerated.item = 2;
895 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
896 return 0;
897}
898
899static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
900 struct snd_ctl_elem_value *value)
901{
902 struct oxygen *chip = ctl->private_data;
903 struct xonar_pcm179x *data = chip->model_data;
904
905 mutex_lock(&chip->mutex);
906 if (data->hp_gain_offset < 2*-6)
907 value->value.enumerated.item[0] = 0;
908 else if (data->hp_gain_offset < 0)
909 value->value.enumerated.item[0] = 1;
910 else
911 value->value.enumerated.item[0] = 2;
912 mutex_unlock(&chip->mutex);
913 return 0;
914}
915
916
917static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
918 struct snd_ctl_elem_value *value)
919{
920 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
921 struct oxygen *chip = ctl->private_data;
922 struct xonar_pcm179x *data = chip->model_data;
923 s8 offset;
924 int changed;
925
926 if (value->value.enumerated.item[0] > 2)
927 return -EINVAL;
928 offset = offsets[value->value.enumerated.item[0]];
929 mutex_lock(&chip->mutex);
930 changed = offset != data->hp_gain_offset;
931 if (changed) {
932 data->hp_gain_offset = offset;
933 update_pcm1796_volume(chip);
934 }
935 mutex_unlock(&chip->mutex);
936 return changed;
937}
938
939static const struct snd_kcontrol_new st_controls[] = {
940 {
941 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
942 .name = "Analog Output",
943 .info = st_output_switch_info,
944 .get = st_output_switch_get,
945 .put = st_output_switch_put,
946 },
947 {
948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
949 .name = "Headphones Impedance Playback Enum",
950 .info = st_hp_volume_offset_info,
951 .get = st_hp_volume_offset_get,
952 .put = st_hp_volume_offset_put,
953 },
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200954};
955
956static void xonar_line_mic_ac97_switch(struct oxygen *chip,
957 unsigned int reg, unsigned int mute)
958{
959 if (reg == AC97_LINE) {
960 spin_lock_irq(&chip->reg_lock);
961 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
962 mute ? GPIO_INPUT_ROUTE : 0,
963 GPIO_INPUT_ROUTE);
964 spin_unlock_irq(&chip->reg_lock);
965 }
966}
967
968static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
969
970static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
971{
972 if (!strncmp(template->name, "CD Capture ", 11))
973 /* CD in is actually connected to the video in pin */
974 template->private_value ^= AC97_CD ^ AC97_VIDEO;
975 return 0;
976}
977
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200978static int add_pcm1796_controls(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200979{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200980 int err;
981
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200982 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
Clemens Ladisch973dca92009-09-28 11:20:47 +0200983 if (err < 0)
984 return err;
985 err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip));
986 if (err < 0)
987 return err;
988 return 0;
989}
990
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200991static int xonar_d2_mixer_init(struct oxygen *chip)
992{
993 int err;
994
995 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
996 if (err < 0)
997 return err;
998 err = add_pcm1796_controls(chip);
999 if (err < 0)
1000 return err;
1001 return 0;
1002}
1003
Clemens Ladisch973dca92009-09-28 11:20:47 +02001004static int xonar_hdav_mixer_init(struct oxygen *chip)
1005{
Clemens Ladisch2509ec62010-12-02 11:38:06 +01001006 int err;
1007
1008 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
1009 if (err < 0)
1010 return err;
1011 err = add_pcm1796_controls(chip);
1012 if (err < 0)
1013 return err;
1014 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001015}
1016
1017static int xonar_st_mixer_init(struct oxygen *chip)
1018{
Clemens Ladischa361e242009-09-28 11:19:19 +02001019 unsigned int i;
1020 int err;
1021
1022 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
1023 err = snd_ctl_add(chip->card,
1024 snd_ctl_new1(&st_controls[i], chip));
1025 if (err < 0)
1026 return err;
1027 }
Clemens Ladisch4852ad02009-09-28 11:21:21 +02001028 err = add_pcm1796_controls(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +02001029 if (err < 0)
1030 return err;
Clemens Ladischa361e242009-09-28 11:19:19 +02001031 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001032}
1033
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001034static void dump_pcm1796_registers(struct oxygen *chip,
1035 struct snd_info_buffer *buffer)
1036{
1037 struct xonar_pcm179x *data = chip->model_data;
1038 unsigned int dac, i;
1039
1040 for (dac = 0; dac < data->dacs; ++dac) {
1041 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
1042 for (i = 0; i < 5; ++i)
1043 snd_iprintf(buffer, " %02x",
1044 data->pcm1796_regs[dac][i]);
1045 }
1046 snd_iprintf(buffer, "\n");
1047}
1048
1049static void dump_cs2000_registers(struct oxygen *chip,
1050 struct snd_info_buffer *buffer)
1051{
1052 struct xonar_pcm179x *data = chip->model_data;
1053 unsigned int i;
1054
1055 if (data->has_cs2000) {
1056 snd_iprintf(buffer, "\nCS2000:\n00: ");
1057 for (i = 1; i < 0x10; ++i)
1058 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1059 snd_iprintf(buffer, "\n10:");
1060 for (i = 0x10; i < 0x1f; ++i)
1061 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1062 snd_iprintf(buffer, "\n");
1063 }
1064}
1065
1066static void dump_st_registers(struct oxygen *chip,
1067 struct snd_info_buffer *buffer)
1068{
1069 dump_pcm1796_registers(chip, buffer);
1070 dump_cs2000_registers(chip, buffer);
1071}
1072
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001073static const struct oxygen_model model_xonar_d2 = {
1074 .longname = "Asus Virtuoso 200",
1075 .chip = "AV200",
1076 .init = xonar_d2_init,
1077 .control_filter = xonar_d2_control_filter,
1078 .mixer_init = xonar_d2_mixer_init,
1079 .cleanup = xonar_d2_cleanup,
1080 .suspend = xonar_d2_suspend,
1081 .resume = xonar_d2_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001082 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001083 .set_dac_params = set_pcm1796_params,
1084 .set_adc_params = xonar_set_cs53x1_params,
1085 .update_dac_volume = update_pcm1796_volume,
1086 .update_dac_mute = update_pcm1796_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001087 .dump_registers = dump_pcm1796_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 |
1092 CAPTURE_0_FROM_I2S_2 |
1093 CAPTURE_1_FROM_SPDIF |
1094 MIDI_OUTPUT |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +02001095 MIDI_INPUT |
1096 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001097 .dac_channels_pcm = 8,
1098 .dac_channels_mixer = 8,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001099 .dac_volume_min = 255 - 2*60,
1100 .dac_volume_max = 255,
1101 .misc_flags = OXYGEN_MISC_MIDI,
1102 .function_flags = OXYGEN_FUNCTION_SPI |
1103 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1104 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1105 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1106};
1107
1108static const struct oxygen_model model_xonar_hdav = {
1109 .longname = "Asus Virtuoso 200",
1110 .chip = "AV200",
1111 .init = xonar_hdav_init,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001112 .mixer_init = xonar_hdav_mixer_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001113 .cleanup = xonar_hdav_cleanup,
1114 .suspend = xonar_hdav_suspend,
1115 .resume = xonar_hdav_resume,
1116 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001117 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001118 .set_dac_params = set_hdav_params,
1119 .set_adc_params = xonar_set_cs53x1_params,
1120 .update_dac_volume = update_pcm1796_volume,
1121 .update_dac_mute = update_pcm1796_mute,
1122 .uart_input = xonar_hdmi_uart_input,
1123 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001124 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001125 .dac_tlv = pcm1796_db_scale,
1126 .model_data_size = sizeof(struct xonar_hdav),
1127 .device_config = PLAYBACK_0_TO_I2S |
1128 PLAYBACK_1_TO_SPDIF |
1129 CAPTURE_0_FROM_I2S_2 |
1130 CAPTURE_1_FROM_SPDIF,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001131 .dac_channels_pcm = 8,
1132 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001133 .dac_volume_min = 255 - 2*60,
1134 .dac_volume_max = 255,
1135 .misc_flags = OXYGEN_MISC_MIDI,
1136 .function_flags = OXYGEN_FUNCTION_2WIRE,
1137 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1138 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1139};
1140
1141static const struct oxygen_model model_xonar_st = {
1142 .longname = "Asus Virtuoso 100",
1143 .chip = "AV200",
1144 .init = xonar_st_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001145 .mixer_init = xonar_st_mixer_init,
1146 .cleanup = xonar_st_cleanup,
1147 .suspend = xonar_st_suspend,
1148 .resume = xonar_st_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001149 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch268304f2009-09-28 11:15:01 +02001150 .set_dac_params = set_st_params,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001151 .set_adc_params = xonar_set_cs53x1_params,
1152 .update_dac_volume = update_pcm1796_volume,
1153 .update_dac_mute = update_pcm1796_mute,
1154 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001155 .dump_registers = dump_st_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001156 .dac_tlv = pcm1796_db_scale,
1157 .model_data_size = sizeof(struct xonar_pcm179x),
1158 .device_config = PLAYBACK_0_TO_I2S |
1159 PLAYBACK_1_TO_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001160 CAPTURE_0_FROM_I2S_2 |
1161 AC97_FMIC_SWITCH,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001162 .dac_channels_pcm = 2,
1163 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001164 .dac_volume_min = 255 - 2*60,
1165 .dac_volume_max = 255,
1166 .function_flags = OXYGEN_FUNCTION_2WIRE,
1167 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1168 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1169};
1170
1171int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1172 const struct pci_device_id *id)
1173{
1174 switch (id->subdevice) {
1175 case 0x8269:
1176 chip->model = model_xonar_d2;
1177 chip->model.shortname = "Xonar D2";
1178 break;
1179 case 0x82b7:
1180 chip->model = model_xonar_d2;
1181 chip->model.shortname = "Xonar D2X";
1182 chip->model.init = xonar_d2x_init;
1183 break;
1184 case 0x8314:
1185 chip->model = model_xonar_hdav;
1186 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1187 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1188 default:
1189 chip->model.shortname = "Xonar HDAV1.3";
1190 break;
1191 case GPIO_DB_H6:
1192 chip->model.shortname = "Xonar HDAV1.3+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001193 chip->model.dac_channels_mixer = 8;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001194 chip->model.private_data = 1;
1195 break;
1196 }
1197 break;
1198 case 0x835d:
1199 chip->model = model_xonar_st;
1200 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1201 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1202 default:
1203 chip->model.shortname = "Xonar ST";
1204 break;
1205 case GPIO_DB_H6:
1206 chip->model.shortname = "Xonar ST+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001207 chip->model.dac_channels_pcm = 8;
1208 chip->model.dac_channels_mixer = 8;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001209 chip->model.private_data = 1;
1210 break;
1211 }
1212 break;
1213 case 0x835c:
1214 chip->model = model_xonar_st;
1215 chip->model.shortname = "Xonar STX";
1216 chip->model.init = xonar_stx_init;
Clemens Ladisch268304f2009-09-28 11:15:01 +02001217 chip->model.resume = xonar_stx_resume;
1218 chip->model.set_dac_params = set_pcm1796_params;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001219 break;
Clemens Ladisch2b830ba2010-10-04 13:22:51 +02001220 case 0x835e:
1221 snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");
1222 return -ENODEV;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001223 default:
1224 return -EINVAL;
1225 }
1226 return 0;
1227}