blob: fce55fa5b0b00c3e8cd6acd1b2936e42dd646602 [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 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 Ladisch65c3ac82009-09-28 11:11:27 +0200322 }
323}
324
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200325static void pcm1796_init(struct oxygen *chip)
326{
327 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200328
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200329 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100330 PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200331 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
332 PCM1796_FLT_SHARP | PCM1796_ATS_1;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200333 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
334 pcm1796_registers_init(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200335 data->current_rate = 48000;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200336}
337
338static void xonar_d2_init(struct oxygen *chip)
339{
340 struct xonar_pcm179x *data = chip->model_data;
341
342 data->generic.anti_pop_delay = 300;
343 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
344 data->dacs = 4;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200345
346 pcm1796_init(chip);
347
348 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
349 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
350
351 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
352
353 xonar_init_cs53x1(chip);
354 xonar_enable_output(chip);
355
356 snd_component_add(chip->card, "PCM1796");
357 snd_component_add(chip->card, "CS5381");
358}
359
360static void xonar_d2x_init(struct oxygen *chip)
361{
362 struct xonar_pcm179x *data = chip->model_data;
363
364 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
365 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
366 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
367 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
368 xonar_init_ext_power(chip);
369 xonar_d2_init(chip);
370}
371
372static void xonar_hdav_init(struct oxygen *chip)
373{
374 struct xonar_hdav *data = chip->model_data;
375
376 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
377 OXYGEN_2WIRE_LENGTH_8 |
378 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100379 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200380
381 data->pcm179x.generic.anti_pop_delay = 100;
382 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
383 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
384 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
385 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100386 data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200387
388 pcm1796_init(chip);
389
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100390 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
391 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200392 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
393
394 xonar_init_cs53x1(chip);
395 xonar_init_ext_power(chip);
396 xonar_hdmi_init(chip, &data->hdmi);
397 xonar_enable_output(chip);
398
399 snd_component_add(chip->card, "PCM1796");
400 snd_component_add(chip->card, "CS5381");
401}
402
Clemens Ladisch268304f2009-09-28 11:15:01 +0200403static void xonar_st_init_i2c(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200404{
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200405 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
406 OXYGEN_2WIRE_LENGTH_8 |
407 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100408 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200409}
410
411static void xonar_st_init_common(struct oxygen *chip)
412{
413 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200414
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200415 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100416 data->dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladischa361e242009-09-28 11:19:19 +0200417 data->hp_gain_offset = 2*-18;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200418
419 pcm1796_init(chip);
420
421 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100422 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
423 GPIO_ST_MAGIC | GPIO_ST_HP);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200424 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
425 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
426
427 xonar_init_cs53x1(chip);
428 xonar_enable_output(chip);
429
430 snd_component_add(chip->card, "PCM1792A");
431 snd_component_add(chip->card, "CS5381");
432}
433
Clemens Ladisch268304f2009-09-28 11:15:01 +0200434static void cs2000_registers_init(struct oxygen *chip)
435{
436 struct xonar_pcm179x *data = chip->model_data;
437
438 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
439 cs2000_write(chip, CS2000_DEV_CTRL, 0);
440 cs2000_write(chip, CS2000_DEV_CFG_1,
441 CS2000_R_MOD_SEL_1 |
442 (0 << CS2000_R_SEL_SHIFT) |
443 CS2000_AUX_OUT_SRC_REF_CLK |
444 CS2000_EN_DEV_CFG_1);
445 cs2000_write(chip, CS2000_DEV_CFG_2,
446 (0 << CS2000_LOCK_CLK_SHIFT) |
447 CS2000_FRAC_N_SRC_STATIC);
448 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
449 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
450 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
451 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100452 cs2000_write(chip, CS2000_FUN_CFG_1,
453 data->cs2000_regs[CS2000_FUN_CFG_1]);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200454 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
455 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100456 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200457}
458
459static void xonar_st_init(struct oxygen *chip)
460{
461 struct xonar_pcm179x *data = chip->model_data;
462
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200463 data->generic.anti_pop_delay = 100;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200464 data->has_cs2000 = 1;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100465 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100466 data->broken_i2c = true;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200467
468 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
469 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100470 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
Clemens Ladisch268304f2009-09-28 11:15:01 +0200471 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
472
473 xonar_st_init_i2c(chip);
474 cs2000_registers_init(chip);
475 xonar_st_init_common(chip);
476
477 snd_component_add(chip->card, "CS2000");
478}
479
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200480static void xonar_stx_init(struct oxygen *chip)
481{
482 struct xonar_pcm179x *data = chip->model_data;
483
Clemens Ladisch268304f2009-09-28 11:15:01 +0200484 xonar_st_init_i2c(chip);
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200485 data->generic.anti_pop_delay = 800;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200486 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
487 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
488 data->generic.ext_power_bit = GPI_EXT_POWER;
489 xonar_init_ext_power(chip);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200490 xonar_st_init_common(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200491}
492
493static void xonar_d2_cleanup(struct oxygen *chip)
494{
495 xonar_disable_output(chip);
496}
497
498static void xonar_hdav_cleanup(struct oxygen *chip)
499{
500 xonar_hdmi_cleanup(chip);
501 xonar_disable_output(chip);
502 msleep(2);
503}
504
505static void xonar_st_cleanup(struct oxygen *chip)
506{
507 xonar_disable_output(chip);
508}
509
510static void xonar_d2_suspend(struct oxygen *chip)
511{
512 xonar_d2_cleanup(chip);
513}
514
515static void xonar_hdav_suspend(struct oxygen *chip)
516{
517 xonar_hdav_cleanup(chip);
518}
519
520static void xonar_st_suspend(struct oxygen *chip)
521{
522 xonar_st_cleanup(chip);
523}
524
525static void xonar_d2_resume(struct oxygen *chip)
526{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200527 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200528 xonar_enable_output(chip);
529}
530
531static void xonar_hdav_resume(struct oxygen *chip)
532{
533 struct xonar_hdav *data = chip->model_data;
534
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200535 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200536 xonar_hdmi_resume(chip, &data->hdmi);
537 xonar_enable_output(chip);
538}
539
Clemens Ladisch268304f2009-09-28 11:15:01 +0200540static void xonar_stx_resume(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200541{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200542 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200543 xonar_enable_output(chip);
544}
545
Clemens Ladisch268304f2009-09-28 11:15:01 +0200546static void xonar_st_resume(struct oxygen *chip)
547{
548 cs2000_registers_init(chip);
549 xonar_stx_resume(chip);
550}
551
Clemens Ladisch973dca92009-09-28 11:20:47 +0200552static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
553{
554 struct xonar_pcm179x *data = chip->model_data;
555
556 if (rate <= 32000)
557 return OXYGEN_I2S_MCLK_512;
558 else if (rate <= 48000 && data->os_128)
559 return OXYGEN_I2S_MCLK_512;
560 else if (rate <= 96000)
561 return OXYGEN_I2S_MCLK_256;
562 else
563 return OXYGEN_I2S_MCLK_128;
564}
565
566static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
567 unsigned int channel,
568 struct snd_pcm_hw_params *params)
569{
570 if (channel == PCM_MULTICH)
571 return mclk_from_rate(chip, params_rate(params));
572 else
573 return oxygen_default_i2s_mclk(chip, channel, params);
574}
575
576static void update_pcm1796_oversampling(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200577{
578 struct xonar_pcm179x *data = chip->model_data;
579 unsigned int i;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200580 u8 reg;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200581
Clemens Ladisch973dca92009-09-28 11:20:47 +0200582 if (data->current_rate <= 32000)
583 reg = PCM1796_OS_128;
584 else if (data->current_rate <= 48000 && data->os_128)
585 reg = PCM1796_OS_128;
586 else if (data->current_rate <= 96000 || data->os_128)
587 reg = PCM1796_OS_64;
588 else
589 reg = PCM1796_OS_32;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200590 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200591 pcm1796_write_cached(chip, i, 20, reg);
592}
593
Clemens Ladisch973dca92009-09-28 11:20:47 +0200594static void set_pcm1796_params(struct oxygen *chip,
595 struct snd_pcm_hw_params *params)
596{
597 struct xonar_pcm179x *data = chip->model_data;
598
Clemens Ladisch79815e02011-01-10 16:02:32 +0100599 msleep(1);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200600 data->current_rate = params_rate(params);
601 update_pcm1796_oversampling(chip);
602}
603
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200604static void update_pcm1796_volume(struct oxygen *chip)
605{
606 struct xonar_pcm179x *data = chip->model_data;
607 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200608 s8 gain_offset;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200609
Clemens Ladischa361e242009-09-28 11:19:19 +0200610 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200611 for (i = 0; i < data->dacs; ++i) {
Clemens Ladischa361e242009-09-28 11:19:19 +0200612 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
613 + gain_offset);
614 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
615 + gain_offset);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200616 }
617}
618
619static void update_pcm1796_mute(struct oxygen *chip)
620{
621 struct xonar_pcm179x *data = chip->model_data;
622 unsigned int i;
623 u8 value;
624
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100625 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200626 if (chip->dac_mute)
627 value |= PCM1796_MUTE;
628 for (i = 0; i < data->dacs; ++i)
629 pcm1796_write_cached(chip, i, 18, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200630}
631
Clemens Ladisch973dca92009-09-28 11:20:47 +0200632static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200633{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200634 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200635 u8 rate_mclk, reg;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200636
Clemens Ladisch973dca92009-09-28 11:20:47 +0200637 switch (rate) {
Clemens Ladisch973dca92009-09-28 11:20:47 +0200638 case 32000:
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100639 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200640 break;
641 case 44100:
642 if (data->os_128)
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100643 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200644 else
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100645 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200646 break;
647 default: /* 48000 */
648 if (data->os_128)
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100649 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200650 else
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100651 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200652 break;
653 case 64000:
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100654 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200655 break;
656 case 88200:
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100657 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200658 break;
659 case 96000:
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100660 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200661 break;
662 case 176400:
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100663 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200664 break;
665 case 192000:
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100666 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_512;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200667 break;
668 }
Clemens Ladisch268304f2009-09-28 11:15:01 +0200669 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
670 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
Clemens Ladischd353eaa2011-01-10 16:07:11 +0100671 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_256)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200672 reg = CS2000_REF_CLK_DIV_1;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200673 else
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200674 reg = CS2000_REF_CLK_DIV_2;
675 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100676 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200677}
678
679static void set_st_params(struct oxygen *chip,
680 struct snd_pcm_hw_params *params)
681{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200682 update_cs2000_rate(chip, params_rate(params));
Clemens Ladisch268304f2009-09-28 11:15:01 +0200683 set_pcm1796_params(chip, params);
684}
685
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200686static void set_hdav_params(struct oxygen *chip,
687 struct snd_pcm_hw_params *params)
688{
689 struct xonar_hdav *data = chip->model_data;
690
691 set_pcm1796_params(chip, params);
692 xonar_set_hdmi_params(chip, &data->hdmi, params);
693}
694
695static const struct snd_kcontrol_new alt_switch = {
696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
697 .name = "Analog Loopback Switch",
698 .info = snd_ctl_boolean_mono_info,
699 .get = xonar_gpio_bit_switch_get,
700 .put = xonar_gpio_bit_switch_put,
701 .private_value = GPIO_D2_ALT,
702};
703
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200704static int rolloff_info(struct snd_kcontrol *ctl,
705 struct snd_ctl_elem_info *info)
706{
707 static const char *const names[2] = {
708 "Sharp Roll-off", "Slow Roll-off"
709 };
710
711 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
712 info->count = 1;
713 info->value.enumerated.items = 2;
714 if (info->value.enumerated.item >= 2)
715 info->value.enumerated.item = 1;
716 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
717 return 0;
718}
719
720static int rolloff_get(struct snd_kcontrol *ctl,
721 struct snd_ctl_elem_value *value)
722{
723 struct oxygen *chip = ctl->private_data;
724 struct xonar_pcm179x *data = chip->model_data;
725
726 value->value.enumerated.item[0] =
727 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
728 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
729 return 0;
730}
731
732static int rolloff_put(struct snd_kcontrol *ctl,
733 struct snd_ctl_elem_value *value)
734{
735 struct oxygen *chip = ctl->private_data;
736 struct xonar_pcm179x *data = chip->model_data;
737 unsigned int i;
738 int changed;
739 u8 reg;
740
741 mutex_lock(&chip->mutex);
742 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
743 reg &= ~PCM1796_FLT_MASK;
744 if (!value->value.enumerated.item[0])
745 reg |= PCM1796_FLT_SHARP;
746 else
747 reg |= PCM1796_FLT_SLOW;
748 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
749 if (changed) {
750 for (i = 0; i < data->dacs; ++i)
751 pcm1796_write(chip, i, 19, reg);
752 }
753 mutex_unlock(&chip->mutex);
754 return changed;
755}
756
757static const struct snd_kcontrol_new rolloff_control = {
758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
759 .name = "DAC Filter Playback Enum",
760 .info = rolloff_info,
761 .get = rolloff_get,
762 .put = rolloff_put,
763};
764
Clemens Ladisch973dca92009-09-28 11:20:47 +0200765static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
766{
767 static const char *const names[2] = { "64x", "128x" };
768
769 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
770 info->count = 1;
771 info->value.enumerated.items = 2;
772 if (info->value.enumerated.item >= 2)
773 info->value.enumerated.item = 1;
774 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
775 return 0;
776}
777
778static int os_128_get(struct snd_kcontrol *ctl,
779 struct snd_ctl_elem_value *value)
780{
781 struct oxygen *chip = ctl->private_data;
782 struct xonar_pcm179x *data = chip->model_data;
783
784 value->value.enumerated.item[0] = data->os_128;
785 return 0;
786}
787
788static int os_128_put(struct snd_kcontrol *ctl,
789 struct snd_ctl_elem_value *value)
790{
791 struct oxygen *chip = ctl->private_data;
792 struct xonar_pcm179x *data = chip->model_data;
793 int changed;
794
795 mutex_lock(&chip->mutex);
796 changed = value->value.enumerated.item[0] != data->os_128;
797 if (changed) {
798 data->os_128 = value->value.enumerated.item[0];
799 if (data->has_cs2000)
800 update_cs2000_rate(chip, data->current_rate);
801 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
802 mclk_from_rate(chip, data->current_rate),
803 OXYGEN_I2S_MCLK_MASK);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100804 msleep(1);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200805 update_pcm1796_oversampling(chip);
806 }
807 mutex_unlock(&chip->mutex);
808 return changed;
809}
810
811static const struct snd_kcontrol_new os_128_control = {
812 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
813 .name = "DAC Oversampling Playback Enum",
814 .info = os_128_info,
815 .get = os_128_get,
816 .put = os_128_put,
817};
818
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100819static const struct snd_kcontrol_new hdav_hdmi_control = {
820 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
821 .name = "HDMI Playback Switch",
822 .info = snd_ctl_boolean_mono_info,
823 .get = xonar_gpio_bit_switch_get,
824 .put = xonar_gpio_bit_switch_put,
825 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
826};
827
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200828static int st_output_switch_info(struct snd_kcontrol *ctl,
829 struct snd_ctl_elem_info *info)
830{
831 static const char *const names[3] = {
832 "Speakers", "Headphones", "FP Headphones"
833 };
834
835 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
836 info->count = 1;
837 info->value.enumerated.items = 3;
838 if (info->value.enumerated.item >= 3)
839 info->value.enumerated.item = 2;
840 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
841 return 0;
842}
843
844static int st_output_switch_get(struct snd_kcontrol *ctl,
845 struct snd_ctl_elem_value *value)
846{
847 struct oxygen *chip = ctl->private_data;
848 u16 gpio;
849
850 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
851 if (!(gpio & GPIO_ST_HP))
852 value->value.enumerated.item[0] = 0;
853 else if (gpio & GPIO_ST_HP_REAR)
854 value->value.enumerated.item[0] = 1;
855 else
856 value->value.enumerated.item[0] = 2;
857 return 0;
858}
859
860
861static int st_output_switch_put(struct snd_kcontrol *ctl,
862 struct snd_ctl_elem_value *value)
863{
864 struct oxygen *chip = ctl->private_data;
Clemens Ladischa361e242009-09-28 11:19:19 +0200865 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200866 u16 gpio_old, gpio;
867
868 mutex_lock(&chip->mutex);
869 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
870 gpio = gpio_old;
871 switch (value->value.enumerated.item[0]) {
872 case 0:
873 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
874 break;
875 case 1:
876 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
877 break;
878 case 2:
879 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
880 break;
881 }
882 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
Clemens Ladischa361e242009-09-28 11:19:19 +0200883 data->hp_active = gpio & GPIO_ST_HP;
884 update_pcm1796_volume(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200885 mutex_unlock(&chip->mutex);
886 return gpio != gpio_old;
887}
888
Clemens Ladischa361e242009-09-28 11:19:19 +0200889static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
890 struct snd_ctl_elem_info *info)
891{
892 static const char *const names[3] = {
893 "< 64 ohms", "64-300 ohms", "300-600 ohms"
894 };
895
896 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
897 info->count = 1;
898 info->value.enumerated.items = 3;
899 if (info->value.enumerated.item > 2)
900 info->value.enumerated.item = 2;
901 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
902 return 0;
903}
904
905static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
906 struct snd_ctl_elem_value *value)
907{
908 struct oxygen *chip = ctl->private_data;
909 struct xonar_pcm179x *data = chip->model_data;
910
911 mutex_lock(&chip->mutex);
912 if (data->hp_gain_offset < 2*-6)
913 value->value.enumerated.item[0] = 0;
914 else if (data->hp_gain_offset < 0)
915 value->value.enumerated.item[0] = 1;
916 else
917 value->value.enumerated.item[0] = 2;
918 mutex_unlock(&chip->mutex);
919 return 0;
920}
921
922
923static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
924 struct snd_ctl_elem_value *value)
925{
926 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
927 struct oxygen *chip = ctl->private_data;
928 struct xonar_pcm179x *data = chip->model_data;
929 s8 offset;
930 int changed;
931
932 if (value->value.enumerated.item[0] > 2)
933 return -EINVAL;
934 offset = offsets[value->value.enumerated.item[0]];
935 mutex_lock(&chip->mutex);
936 changed = offset != data->hp_gain_offset;
937 if (changed) {
938 data->hp_gain_offset = offset;
939 update_pcm1796_volume(chip);
940 }
941 mutex_unlock(&chip->mutex);
942 return changed;
943}
944
945static const struct snd_kcontrol_new st_controls[] = {
946 {
947 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
948 .name = "Analog Output",
949 .info = st_output_switch_info,
950 .get = st_output_switch_get,
951 .put = st_output_switch_put,
952 },
953 {
954 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
955 .name = "Headphones Impedance Playback Enum",
956 .info = st_hp_volume_offset_info,
957 .get = st_hp_volume_offset_get,
958 .put = st_hp_volume_offset_put,
959 },
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200960};
961
962static void xonar_line_mic_ac97_switch(struct oxygen *chip,
963 unsigned int reg, unsigned int mute)
964{
965 if (reg == AC97_LINE) {
966 spin_lock_irq(&chip->reg_lock);
967 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
968 mute ? GPIO_INPUT_ROUTE : 0,
969 GPIO_INPUT_ROUTE);
970 spin_unlock_irq(&chip->reg_lock);
971 }
972}
973
974static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
975
976static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
977{
978 if (!strncmp(template->name, "CD Capture ", 11))
979 /* CD in is actually connected to the video in pin */
980 template->private_value ^= AC97_CD ^ AC97_VIDEO;
981 return 0;
982}
983
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100984static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
985{
986 if (!strncmp(template->name, "Master Playback ", 16))
987 /* no volume/mute, as I²C to the third DAC does not work */
988 return 1;
989 return 0;
990}
991
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200992static int add_pcm1796_controls(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200993{
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100994 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200995 int err;
996
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100997 if (!data->broken_i2c) {
998 err = snd_ctl_add(chip->card,
999 snd_ctl_new1(&rolloff_control, chip));
1000 if (err < 0)
1001 return err;
1002 err = snd_ctl_add(chip->card,
1003 snd_ctl_new1(&os_128_control, chip));
1004 if (err < 0)
1005 return err;
1006 }
Clemens Ladisch973dca92009-09-28 11:20:47 +02001007 return 0;
1008}
1009
Clemens Ladisch4852ad02009-09-28 11:21:21 +02001010static int xonar_d2_mixer_init(struct oxygen *chip)
1011{
1012 int err;
1013
1014 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
1015 if (err < 0)
1016 return err;
1017 err = add_pcm1796_controls(chip);
1018 if (err < 0)
1019 return err;
1020 return 0;
1021}
1022
Clemens Ladisch973dca92009-09-28 11:20:47 +02001023static int xonar_hdav_mixer_init(struct oxygen *chip)
1024{
Clemens Ladisch2509ec62010-12-02 11:38:06 +01001025 int err;
1026
1027 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
1028 if (err < 0)
1029 return err;
1030 err = add_pcm1796_controls(chip);
1031 if (err < 0)
1032 return err;
1033 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001034}
1035
1036static int xonar_st_mixer_init(struct oxygen *chip)
1037{
Clemens Ladischa361e242009-09-28 11:19:19 +02001038 unsigned int i;
1039 int err;
1040
1041 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
1042 err = snd_ctl_add(chip->card,
1043 snd_ctl_new1(&st_controls[i], chip));
1044 if (err < 0)
1045 return err;
1046 }
Clemens Ladisch4852ad02009-09-28 11:21:21 +02001047 err = add_pcm1796_controls(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +02001048 if (err < 0)
1049 return err;
Clemens Ladischa361e242009-09-28 11:19:19 +02001050 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001051}
1052
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001053static void dump_pcm1796_registers(struct oxygen *chip,
1054 struct snd_info_buffer *buffer)
1055{
1056 struct xonar_pcm179x *data = chip->model_data;
1057 unsigned int dac, i;
1058
1059 for (dac = 0; dac < data->dacs; ++dac) {
1060 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
1061 for (i = 0; i < 5; ++i)
1062 snd_iprintf(buffer, " %02x",
1063 data->pcm1796_regs[dac][i]);
1064 }
1065 snd_iprintf(buffer, "\n");
1066}
1067
1068static void dump_cs2000_registers(struct oxygen *chip,
1069 struct snd_info_buffer *buffer)
1070{
1071 struct xonar_pcm179x *data = chip->model_data;
1072 unsigned int i;
1073
1074 if (data->has_cs2000) {
1075 snd_iprintf(buffer, "\nCS2000:\n00: ");
1076 for (i = 1; i < 0x10; ++i)
1077 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1078 snd_iprintf(buffer, "\n10:");
1079 for (i = 0x10; i < 0x1f; ++i)
1080 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1081 snd_iprintf(buffer, "\n");
1082 }
1083}
1084
1085static void dump_st_registers(struct oxygen *chip,
1086 struct snd_info_buffer *buffer)
1087{
1088 dump_pcm1796_registers(chip, buffer);
1089 dump_cs2000_registers(chip, buffer);
1090}
1091
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001092static const struct oxygen_model model_xonar_d2 = {
1093 .longname = "Asus Virtuoso 200",
1094 .chip = "AV200",
1095 .init = xonar_d2_init,
1096 .control_filter = xonar_d2_control_filter,
1097 .mixer_init = xonar_d2_mixer_init,
1098 .cleanup = xonar_d2_cleanup,
1099 .suspend = xonar_d2_suspend,
1100 .resume = xonar_d2_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001101 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001102 .set_dac_params = set_pcm1796_params,
1103 .set_adc_params = xonar_set_cs53x1_params,
1104 .update_dac_volume = update_pcm1796_volume,
1105 .update_dac_mute = update_pcm1796_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001106 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001107 .dac_tlv = pcm1796_db_scale,
1108 .model_data_size = sizeof(struct xonar_pcm179x),
1109 .device_config = PLAYBACK_0_TO_I2S |
1110 PLAYBACK_1_TO_SPDIF |
1111 CAPTURE_0_FROM_I2S_2 |
1112 CAPTURE_1_FROM_SPDIF |
1113 MIDI_OUTPUT |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +02001114 MIDI_INPUT |
1115 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001116 .dac_channels_pcm = 8,
1117 .dac_channels_mixer = 8,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001118 .dac_volume_min = 255 - 2*60,
1119 .dac_volume_max = 255,
1120 .misc_flags = OXYGEN_MISC_MIDI,
1121 .function_flags = OXYGEN_FUNCTION_SPI |
1122 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001123 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001124 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1125};
1126
1127static const struct oxygen_model model_xonar_hdav = {
1128 .longname = "Asus Virtuoso 200",
1129 .chip = "AV200",
1130 .init = xonar_hdav_init,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001131 .mixer_init = xonar_hdav_mixer_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001132 .cleanup = xonar_hdav_cleanup,
1133 .suspend = xonar_hdav_suspend,
1134 .resume = xonar_hdav_resume,
1135 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001136 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001137 .set_dac_params = set_hdav_params,
1138 .set_adc_params = xonar_set_cs53x1_params,
1139 .update_dac_volume = update_pcm1796_volume,
1140 .update_dac_mute = update_pcm1796_mute,
1141 .uart_input = xonar_hdmi_uart_input,
1142 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001143 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001144 .dac_tlv = pcm1796_db_scale,
1145 .model_data_size = sizeof(struct xonar_hdav),
1146 .device_config = PLAYBACK_0_TO_I2S |
1147 PLAYBACK_1_TO_SPDIF |
1148 CAPTURE_0_FROM_I2S_2 |
1149 CAPTURE_1_FROM_SPDIF,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001150 .dac_channels_pcm = 8,
1151 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001152 .dac_volume_min = 255 - 2*60,
1153 .dac_volume_max = 255,
1154 .misc_flags = OXYGEN_MISC_MIDI,
1155 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001156 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001157 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1158};
1159
1160static const struct oxygen_model model_xonar_st = {
1161 .longname = "Asus Virtuoso 100",
1162 .chip = "AV200",
1163 .init = xonar_st_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001164 .mixer_init = xonar_st_mixer_init,
1165 .cleanup = xonar_st_cleanup,
1166 .suspend = xonar_st_suspend,
1167 .resume = xonar_st_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001168 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch268304f2009-09-28 11:15:01 +02001169 .set_dac_params = set_st_params,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001170 .set_adc_params = xonar_set_cs53x1_params,
1171 .update_dac_volume = update_pcm1796_volume,
1172 .update_dac_mute = update_pcm1796_mute,
1173 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001174 .dump_registers = dump_st_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001175 .dac_tlv = pcm1796_db_scale,
1176 .model_data_size = sizeof(struct xonar_pcm179x),
1177 .device_config = PLAYBACK_0_TO_I2S |
1178 PLAYBACK_1_TO_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001179 CAPTURE_0_FROM_I2S_2 |
1180 AC97_FMIC_SWITCH,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001181 .dac_channels_pcm = 2,
1182 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001183 .dac_volume_min = 255 - 2*60,
1184 .dac_volume_max = 255,
1185 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001186 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001187 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1188};
1189
1190int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1191 const struct pci_device_id *id)
1192{
1193 switch (id->subdevice) {
1194 case 0x8269:
1195 chip->model = model_xonar_d2;
1196 chip->model.shortname = "Xonar D2";
1197 break;
1198 case 0x82b7:
1199 chip->model = model_xonar_d2;
1200 chip->model.shortname = "Xonar D2X";
1201 chip->model.init = xonar_d2x_init;
1202 break;
1203 case 0x8314:
1204 chip->model = model_xonar_hdav;
1205 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1206 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1207 default:
1208 chip->model.shortname = "Xonar HDAV1.3";
1209 break;
1210 case GPIO_DB_H6:
1211 chip->model.shortname = "Xonar HDAV1.3+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001212 chip->model.dac_channels_mixer = 8;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001213 break;
1214 }
1215 break;
1216 case 0x835d:
1217 chip->model = model_xonar_st;
1218 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1219 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1220 default:
1221 chip->model.shortname = "Xonar ST";
1222 break;
1223 case GPIO_DB_H6:
1224 chip->model.shortname = "Xonar ST+H6";
Clemens Ladischdd203fa2011-01-10 16:05:38 +01001225 chip->model.control_filter = xonar_st_h6_control_filter;
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001226 chip->model.dac_channels_pcm = 8;
1227 chip->model.dac_channels_mixer = 8;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001228 break;
1229 }
1230 break;
1231 case 0x835c:
1232 chip->model = model_xonar_st;
1233 chip->model.shortname = "Xonar STX";
1234 chip->model.init = xonar_stx_init;
Clemens Ladisch268304f2009-09-28 11:15:01 +02001235 chip->model.resume = xonar_stx_resume;
1236 chip->model.set_dac_params = set_pcm1796_params;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001237 break;
Clemens Ladisch2b830ba2010-10-04 13:22:51 +02001238 case 0x835e:
1239 snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");
1240 return -ENODEV;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001241 default:
1242 return -EINVAL;
1243 }
1244 return 0;
1245}