blob: 5ec164a70cf2bf621f2447ab6876164b1c190096 [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 Ladisch79815e02011-01-10 16:02:32 +0100306 msleep(1);
Clemens Ladischa361e242009-09-28 11:19:19 +0200307 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200308 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200309 /* set ATLD before ATL/ATR */
310 pcm1796_write(chip, i, 18,
311 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
Clemens Ladischa361e242009-09-28 11:19:19 +0200312 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
313 + gain_offset);
314 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
315 + gain_offset);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200316 pcm1796_write(chip, i, 19,
317 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200318 pcm1796_write(chip, i, 20,
319 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
320 pcm1796_write(chip, i, 21, 0);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200321 }
322}
323
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200324static void pcm1796_init(struct oxygen *chip)
325{
326 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200327
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200328 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE |
329 PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200330 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
331 PCM1796_FLT_SHARP | PCM1796_ATS_1;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200332 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64;
333 pcm1796_registers_init(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200334 data->current_rate = 48000;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200335}
336
337static void xonar_d2_init(struct oxygen *chip)
338{
339 struct xonar_pcm179x *data = chip->model_data;
340
341 data->generic.anti_pop_delay = 300;
342 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
343 data->dacs = 4;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200344
345 pcm1796_init(chip);
346
347 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
348 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
349
350 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
351
352 xonar_init_cs53x1(chip);
353 xonar_enable_output(chip);
354
355 snd_component_add(chip->card, "PCM1796");
356 snd_component_add(chip->card, "CS5381");
357}
358
359static void xonar_d2x_init(struct oxygen *chip)
360{
361 struct xonar_pcm179x *data = chip->model_data;
362
363 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
364 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
365 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
366 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
367 xonar_init_ext_power(chip);
368 xonar_d2_init(chip);
369}
370
371static void xonar_hdav_init(struct oxygen *chip)
372{
373 struct xonar_hdav *data = chip->model_data;
374
375 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
376 OXYGEN_2WIRE_LENGTH_8 |
377 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100378 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200379
380 data->pcm179x.generic.anti_pop_delay = 100;
381 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
382 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
383 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
384 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100385 data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200386
387 pcm1796_init(chip);
388
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100389 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
390 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200391 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
392
393 xonar_init_cs53x1(chip);
394 xonar_init_ext_power(chip);
395 xonar_hdmi_init(chip, &data->hdmi);
396 xonar_enable_output(chip);
397
398 snd_component_add(chip->card, "PCM1796");
399 snd_component_add(chip->card, "CS5381");
400}
401
Clemens Ladisch268304f2009-09-28 11:15:01 +0200402static void xonar_st_init_i2c(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200403{
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200404 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
405 OXYGEN_2WIRE_LENGTH_8 |
406 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100407 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200408}
409
410static void xonar_st_init_common(struct oxygen *chip)
411{
412 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200413
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200414 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100415 data->dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladischa361e242009-09-28 11:19:19 +0200416 data->hp_gain_offset = 2*-18;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200417
418 pcm1796_init(chip);
419
420 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100421 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
422 GPIO_ST_MAGIC | GPIO_ST_HP);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200423 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
424 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
425
426 xonar_init_cs53x1(chip);
427 xonar_enable_output(chip);
428
429 snd_component_add(chip->card, "PCM1792A");
430 snd_component_add(chip->card, "CS5381");
431}
432
Clemens Ladisch268304f2009-09-28 11:15:01 +0200433static void cs2000_registers_init(struct oxygen *chip)
434{
435 struct xonar_pcm179x *data = chip->model_data;
436
437 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
438 cs2000_write(chip, CS2000_DEV_CTRL, 0);
439 cs2000_write(chip, CS2000_DEV_CFG_1,
440 CS2000_R_MOD_SEL_1 |
441 (0 << CS2000_R_SEL_SHIFT) |
442 CS2000_AUX_OUT_SRC_REF_CLK |
443 CS2000_EN_DEV_CFG_1);
444 cs2000_write(chip, CS2000_DEV_CFG_2,
445 (0 << CS2000_LOCK_CLK_SHIFT) |
446 CS2000_FRAC_N_SRC_STATIC);
447 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
448 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
449 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
450 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100451 cs2000_write(chip, CS2000_FUN_CFG_1,
452 data->cs2000_regs[CS2000_FUN_CFG_1]);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200453 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
454 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100455 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200456}
457
458static void xonar_st_init(struct oxygen *chip)
459{
460 struct xonar_pcm179x *data = chip->model_data;
461
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200462 data->generic.anti_pop_delay = 100;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200463 data->has_cs2000 = 1;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100464 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200465
466 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
467 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S |
468 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
469 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
470
471 xonar_st_init_i2c(chip);
472 cs2000_registers_init(chip);
473 xonar_st_init_common(chip);
474
475 snd_component_add(chip->card, "CS2000");
476}
477
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200478static void xonar_stx_init(struct oxygen *chip)
479{
480 struct xonar_pcm179x *data = chip->model_data;
481
Clemens Ladisch268304f2009-09-28 11:15:01 +0200482 xonar_st_init_i2c(chip);
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200483 data->generic.anti_pop_delay = 800;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200484 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
485 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
486 data->generic.ext_power_bit = GPI_EXT_POWER;
487 xonar_init_ext_power(chip);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200488 xonar_st_init_common(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200489}
490
491static void xonar_d2_cleanup(struct oxygen *chip)
492{
493 xonar_disable_output(chip);
494}
495
496static void xonar_hdav_cleanup(struct oxygen *chip)
497{
498 xonar_hdmi_cleanup(chip);
499 xonar_disable_output(chip);
500 msleep(2);
501}
502
503static void xonar_st_cleanup(struct oxygen *chip)
504{
505 xonar_disable_output(chip);
506}
507
508static void xonar_d2_suspend(struct oxygen *chip)
509{
510 xonar_d2_cleanup(chip);
511}
512
513static void xonar_hdav_suspend(struct oxygen *chip)
514{
515 xonar_hdav_cleanup(chip);
516}
517
518static void xonar_st_suspend(struct oxygen *chip)
519{
520 xonar_st_cleanup(chip);
521}
522
523static void xonar_d2_resume(struct oxygen *chip)
524{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200525 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200526 xonar_enable_output(chip);
527}
528
529static void xonar_hdav_resume(struct oxygen *chip)
530{
531 struct xonar_hdav *data = chip->model_data;
532
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200533 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200534 xonar_hdmi_resume(chip, &data->hdmi);
535 xonar_enable_output(chip);
536}
537
Clemens Ladisch268304f2009-09-28 11:15:01 +0200538static void xonar_stx_resume(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200539{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200540 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200541 xonar_enable_output(chip);
542}
543
Clemens Ladisch268304f2009-09-28 11:15:01 +0200544static void xonar_st_resume(struct oxygen *chip)
545{
546 cs2000_registers_init(chip);
547 xonar_stx_resume(chip);
548}
549
Clemens Ladisch973dca92009-09-28 11:20:47 +0200550static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate)
551{
552 struct xonar_pcm179x *data = chip->model_data;
553
554 if (rate <= 32000)
555 return OXYGEN_I2S_MCLK_512;
556 else if (rate <= 48000 && data->os_128)
557 return OXYGEN_I2S_MCLK_512;
558 else if (rate <= 96000)
559 return OXYGEN_I2S_MCLK_256;
560 else
561 return OXYGEN_I2S_MCLK_128;
562}
563
564static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip,
565 unsigned int channel,
566 struct snd_pcm_hw_params *params)
567{
568 if (channel == PCM_MULTICH)
569 return mclk_from_rate(chip, params_rate(params));
570 else
571 return oxygen_default_i2s_mclk(chip, channel, params);
572}
573
574static void update_pcm1796_oversampling(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200575{
576 struct xonar_pcm179x *data = chip->model_data;
577 unsigned int i;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200578 u8 reg;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200579
Clemens Ladisch973dca92009-09-28 11:20:47 +0200580 if (data->current_rate <= 32000)
581 reg = PCM1796_OS_128;
582 else if (data->current_rate <= 48000 && data->os_128)
583 reg = PCM1796_OS_128;
584 else if (data->current_rate <= 96000 || data->os_128)
585 reg = PCM1796_OS_64;
586 else
587 reg = PCM1796_OS_32;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200588 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200589 pcm1796_write_cached(chip, i, 20, reg);
590}
591
Clemens Ladisch973dca92009-09-28 11:20:47 +0200592static void set_pcm1796_params(struct oxygen *chip,
593 struct snd_pcm_hw_params *params)
594{
595 struct xonar_pcm179x *data = chip->model_data;
596
Clemens Ladisch79815e02011-01-10 16:02:32 +0100597 msleep(1);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200598 data->current_rate = params_rate(params);
599 update_pcm1796_oversampling(chip);
600}
601
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200602static void update_pcm1796_volume(struct oxygen *chip)
603{
604 struct xonar_pcm179x *data = chip->model_data;
605 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200606 s8 gain_offset;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200607
Clemens Ladischa361e242009-09-28 11:19:19 +0200608 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200609 for (i = 0; i < data->dacs; ++i) {
Clemens Ladischa361e242009-09-28 11:19:19 +0200610 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
611 + gain_offset);
612 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
613 + gain_offset);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200614 }
615}
616
617static void update_pcm1796_mute(struct oxygen *chip)
618{
619 struct xonar_pcm179x *data = chip->model_data;
620 unsigned int i;
621 u8 value;
622
623 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
624 if (chip->dac_mute)
625 value |= PCM1796_MUTE;
626 for (i = 0; i < data->dacs; ++i)
627 pcm1796_write_cached(chip, i, 18, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200628}
629
Clemens Ladisch973dca92009-09-28 11:20:47 +0200630static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200631{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200632 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200633 u8 rate_mclk, reg;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200634
Clemens Ladisch973dca92009-09-28 11:20:47 +0200635 switch (rate) {
636 /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */
637 case 32000:
638 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
639 break;
640 case 44100:
641 if (data->os_128)
642 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
643 else
644 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128;
645 break;
646 default: /* 48000 */
647 if (data->os_128)
648 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
649 else
650 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128;
651 break;
652 case 64000:
653 rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256;
654 break;
655 case 88200:
656 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
657 break;
658 case 96000:
659 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
660 break;
661 case 176400:
662 rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256;
663 break;
664 case 192000:
665 rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256;
666 break;
667 }
Clemens Ladisch268304f2009-09-28 11:15:01 +0200668 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
669 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
670 if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200671 reg = CS2000_REF_CLK_DIV_1;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200672 else
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200673 reg = CS2000_REF_CLK_DIV_2;
674 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100675 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200676}
677
678static void set_st_params(struct oxygen *chip,
679 struct snd_pcm_hw_params *params)
680{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200681 update_cs2000_rate(chip, params_rate(params));
Clemens Ladisch268304f2009-09-28 11:15:01 +0200682 set_pcm1796_params(chip, params);
683}
684
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200685static void set_hdav_params(struct oxygen *chip,
686 struct snd_pcm_hw_params *params)
687{
688 struct xonar_hdav *data = chip->model_data;
689
690 set_pcm1796_params(chip, params);
691 xonar_set_hdmi_params(chip, &data->hdmi, params);
692}
693
694static const struct snd_kcontrol_new alt_switch = {
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "Analog Loopback Switch",
697 .info = snd_ctl_boolean_mono_info,
698 .get = xonar_gpio_bit_switch_get,
699 .put = xonar_gpio_bit_switch_put,
700 .private_value = GPIO_D2_ALT,
701};
702
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200703static int rolloff_info(struct snd_kcontrol *ctl,
704 struct snd_ctl_elem_info *info)
705{
706 static const char *const names[2] = {
707 "Sharp Roll-off", "Slow Roll-off"
708 };
709
710 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
711 info->count = 1;
712 info->value.enumerated.items = 2;
713 if (info->value.enumerated.item >= 2)
714 info->value.enumerated.item = 1;
715 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
716 return 0;
717}
718
719static int rolloff_get(struct snd_kcontrol *ctl,
720 struct snd_ctl_elem_value *value)
721{
722 struct oxygen *chip = ctl->private_data;
723 struct xonar_pcm179x *data = chip->model_data;
724
725 value->value.enumerated.item[0] =
726 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
727 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
728 return 0;
729}
730
731static int rolloff_put(struct snd_kcontrol *ctl,
732 struct snd_ctl_elem_value *value)
733{
734 struct oxygen *chip = ctl->private_data;
735 struct xonar_pcm179x *data = chip->model_data;
736 unsigned int i;
737 int changed;
738 u8 reg;
739
740 mutex_lock(&chip->mutex);
741 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
742 reg &= ~PCM1796_FLT_MASK;
743 if (!value->value.enumerated.item[0])
744 reg |= PCM1796_FLT_SHARP;
745 else
746 reg |= PCM1796_FLT_SLOW;
747 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
748 if (changed) {
749 for (i = 0; i < data->dacs; ++i)
750 pcm1796_write(chip, i, 19, reg);
751 }
752 mutex_unlock(&chip->mutex);
753 return changed;
754}
755
756static const struct snd_kcontrol_new rolloff_control = {
757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
758 .name = "DAC Filter Playback Enum",
759 .info = rolloff_info,
760 .get = rolloff_get,
761 .put = rolloff_put,
762};
763
Clemens Ladisch973dca92009-09-28 11:20:47 +0200764static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
765{
766 static const char *const names[2] = { "64x", "128x" };
767
768 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
769 info->count = 1;
770 info->value.enumerated.items = 2;
771 if (info->value.enumerated.item >= 2)
772 info->value.enumerated.item = 1;
773 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
774 return 0;
775}
776
777static int os_128_get(struct snd_kcontrol *ctl,
778 struct snd_ctl_elem_value *value)
779{
780 struct oxygen *chip = ctl->private_data;
781 struct xonar_pcm179x *data = chip->model_data;
782
783 value->value.enumerated.item[0] = data->os_128;
784 return 0;
785}
786
787static int os_128_put(struct snd_kcontrol *ctl,
788 struct snd_ctl_elem_value *value)
789{
790 struct oxygen *chip = ctl->private_data;
791 struct xonar_pcm179x *data = chip->model_data;
792 int changed;
793
794 mutex_lock(&chip->mutex);
795 changed = value->value.enumerated.item[0] != data->os_128;
796 if (changed) {
797 data->os_128 = value->value.enumerated.item[0];
798 if (data->has_cs2000)
799 update_cs2000_rate(chip, data->current_rate);
800 oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
801 mclk_from_rate(chip, data->current_rate),
802 OXYGEN_I2S_MCLK_MASK);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100803 msleep(1);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200804 update_pcm1796_oversampling(chip);
805 }
806 mutex_unlock(&chip->mutex);
807 return changed;
808}
809
810static const struct snd_kcontrol_new os_128_control = {
811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
812 .name = "DAC Oversampling Playback Enum",
813 .info = os_128_info,
814 .get = os_128_get,
815 .put = os_128_put,
816};
817
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100818static const struct snd_kcontrol_new hdav_hdmi_control = {
819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
820 .name = "HDMI Playback Switch",
821 .info = snd_ctl_boolean_mono_info,
822 .get = xonar_gpio_bit_switch_get,
823 .put = xonar_gpio_bit_switch_put,
824 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
825};
826
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200827static int st_output_switch_info(struct snd_kcontrol *ctl,
828 struct snd_ctl_elem_info *info)
829{
830 static const char *const names[3] = {
831 "Speakers", "Headphones", "FP Headphones"
832 };
833
834 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
835 info->count = 1;
836 info->value.enumerated.items = 3;
837 if (info->value.enumerated.item >= 3)
838 info->value.enumerated.item = 2;
839 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
840 return 0;
841}
842
843static int st_output_switch_get(struct snd_kcontrol *ctl,
844 struct snd_ctl_elem_value *value)
845{
846 struct oxygen *chip = ctl->private_data;
847 u16 gpio;
848
849 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
850 if (!(gpio & GPIO_ST_HP))
851 value->value.enumerated.item[0] = 0;
852 else if (gpio & GPIO_ST_HP_REAR)
853 value->value.enumerated.item[0] = 1;
854 else
855 value->value.enumerated.item[0] = 2;
856 return 0;
857}
858
859
860static int st_output_switch_put(struct snd_kcontrol *ctl,
861 struct snd_ctl_elem_value *value)
862{
863 struct oxygen *chip = ctl->private_data;
Clemens Ladischa361e242009-09-28 11:19:19 +0200864 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200865 u16 gpio_old, gpio;
866
867 mutex_lock(&chip->mutex);
868 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
869 gpio = gpio_old;
870 switch (value->value.enumerated.item[0]) {
871 case 0:
872 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
873 break;
874 case 1:
875 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
876 break;
877 case 2:
878 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
879 break;
880 }
881 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
Clemens Ladischa361e242009-09-28 11:19:19 +0200882 data->hp_active = gpio & GPIO_ST_HP;
883 update_pcm1796_volume(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200884 mutex_unlock(&chip->mutex);
885 return gpio != gpio_old;
886}
887
Clemens Ladischa361e242009-09-28 11:19:19 +0200888static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
889 struct snd_ctl_elem_info *info)
890{
891 static const char *const names[3] = {
892 "< 64 ohms", "64-300 ohms", "300-600 ohms"
893 };
894
895 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
896 info->count = 1;
897 info->value.enumerated.items = 3;
898 if (info->value.enumerated.item > 2)
899 info->value.enumerated.item = 2;
900 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
901 return 0;
902}
903
904static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
905 struct snd_ctl_elem_value *value)
906{
907 struct oxygen *chip = ctl->private_data;
908 struct xonar_pcm179x *data = chip->model_data;
909
910 mutex_lock(&chip->mutex);
911 if (data->hp_gain_offset < 2*-6)
912 value->value.enumerated.item[0] = 0;
913 else if (data->hp_gain_offset < 0)
914 value->value.enumerated.item[0] = 1;
915 else
916 value->value.enumerated.item[0] = 2;
917 mutex_unlock(&chip->mutex);
918 return 0;
919}
920
921
922static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
923 struct snd_ctl_elem_value *value)
924{
925 static const s8 offsets[] = { 2*-18, 2*-6, 0 };
926 struct oxygen *chip = ctl->private_data;
927 struct xonar_pcm179x *data = chip->model_data;
928 s8 offset;
929 int changed;
930
931 if (value->value.enumerated.item[0] > 2)
932 return -EINVAL;
933 offset = offsets[value->value.enumerated.item[0]];
934 mutex_lock(&chip->mutex);
935 changed = offset != data->hp_gain_offset;
936 if (changed) {
937 data->hp_gain_offset = offset;
938 update_pcm1796_volume(chip);
939 }
940 mutex_unlock(&chip->mutex);
941 return changed;
942}
943
944static const struct snd_kcontrol_new st_controls[] = {
945 {
946 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
947 .name = "Analog Output",
948 .info = st_output_switch_info,
949 .get = st_output_switch_get,
950 .put = st_output_switch_put,
951 },
952 {
953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
954 .name = "Headphones Impedance Playback Enum",
955 .info = st_hp_volume_offset_info,
956 .get = st_hp_volume_offset_get,
957 .put = st_hp_volume_offset_put,
958 },
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200959};
960
961static void xonar_line_mic_ac97_switch(struct oxygen *chip,
962 unsigned int reg, unsigned int mute)
963{
964 if (reg == AC97_LINE) {
965 spin_lock_irq(&chip->reg_lock);
966 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
967 mute ? GPIO_INPUT_ROUTE : 0,
968 GPIO_INPUT_ROUTE);
969 spin_unlock_irq(&chip->reg_lock);
970 }
971}
972
973static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
974
975static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
976{
977 if (!strncmp(template->name, "CD Capture ", 11))
978 /* CD in is actually connected to the video in pin */
979 template->private_value ^= AC97_CD ^ AC97_VIDEO;
980 return 0;
981}
982
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200983static int add_pcm1796_controls(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200984{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200985 int err;
986
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200987 err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip));
Clemens Ladisch973dca92009-09-28 11:20:47 +0200988 if (err < 0)
989 return err;
990 err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip));
991 if (err < 0)
992 return err;
993 return 0;
994}
995
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200996static int xonar_d2_mixer_init(struct oxygen *chip)
997{
998 int err;
999
1000 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
1001 if (err < 0)
1002 return err;
1003 err = add_pcm1796_controls(chip);
1004 if (err < 0)
1005 return err;
1006 return 0;
1007}
1008
Clemens Ladisch973dca92009-09-28 11:20:47 +02001009static int xonar_hdav_mixer_init(struct oxygen *chip)
1010{
Clemens Ladisch2509ec62010-12-02 11:38:06 +01001011 int err;
1012
1013 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
1014 if (err < 0)
1015 return err;
1016 err = add_pcm1796_controls(chip);
1017 if (err < 0)
1018 return err;
1019 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001020}
1021
1022static int xonar_st_mixer_init(struct oxygen *chip)
1023{
Clemens Ladischa361e242009-09-28 11:19:19 +02001024 unsigned int i;
1025 int err;
1026
1027 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
1028 err = snd_ctl_add(chip->card,
1029 snd_ctl_new1(&st_controls[i], chip));
1030 if (err < 0)
1031 return err;
1032 }
Clemens Ladisch4852ad02009-09-28 11:21:21 +02001033 err = add_pcm1796_controls(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +02001034 if (err < 0)
1035 return err;
Clemens Ladischa361e242009-09-28 11:19:19 +02001036 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001037}
1038
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001039static void dump_pcm1796_registers(struct oxygen *chip,
1040 struct snd_info_buffer *buffer)
1041{
1042 struct xonar_pcm179x *data = chip->model_data;
1043 unsigned int dac, i;
1044
1045 for (dac = 0; dac < data->dacs; ++dac) {
1046 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
1047 for (i = 0; i < 5; ++i)
1048 snd_iprintf(buffer, " %02x",
1049 data->pcm1796_regs[dac][i]);
1050 }
1051 snd_iprintf(buffer, "\n");
1052}
1053
1054static void dump_cs2000_registers(struct oxygen *chip,
1055 struct snd_info_buffer *buffer)
1056{
1057 struct xonar_pcm179x *data = chip->model_data;
1058 unsigned int i;
1059
1060 if (data->has_cs2000) {
1061 snd_iprintf(buffer, "\nCS2000:\n00: ");
1062 for (i = 1; i < 0x10; ++i)
1063 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1064 snd_iprintf(buffer, "\n10:");
1065 for (i = 0x10; i < 0x1f; ++i)
1066 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1067 snd_iprintf(buffer, "\n");
1068 }
1069}
1070
1071static void dump_st_registers(struct oxygen *chip,
1072 struct snd_info_buffer *buffer)
1073{
1074 dump_pcm1796_registers(chip, buffer);
1075 dump_cs2000_registers(chip, buffer);
1076}
1077
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001078static const struct oxygen_model model_xonar_d2 = {
1079 .longname = "Asus Virtuoso 200",
1080 .chip = "AV200",
1081 .init = xonar_d2_init,
1082 .control_filter = xonar_d2_control_filter,
1083 .mixer_init = xonar_d2_mixer_init,
1084 .cleanup = xonar_d2_cleanup,
1085 .suspend = xonar_d2_suspend,
1086 .resume = xonar_d2_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001087 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001088 .set_dac_params = set_pcm1796_params,
1089 .set_adc_params = xonar_set_cs53x1_params,
1090 .update_dac_volume = update_pcm1796_volume,
1091 .update_dac_mute = update_pcm1796_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001092 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001093 .dac_tlv = pcm1796_db_scale,
1094 .model_data_size = sizeof(struct xonar_pcm179x),
1095 .device_config = PLAYBACK_0_TO_I2S |
1096 PLAYBACK_1_TO_SPDIF |
1097 CAPTURE_0_FROM_I2S_2 |
1098 CAPTURE_1_FROM_SPDIF |
1099 MIDI_OUTPUT |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +02001100 MIDI_INPUT |
1101 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001102 .dac_channels_pcm = 8,
1103 .dac_channels_mixer = 8,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001104 .dac_volume_min = 255 - 2*60,
1105 .dac_volume_max = 255,
1106 .misc_flags = OXYGEN_MISC_MIDI,
1107 .function_flags = OXYGEN_FUNCTION_SPI |
1108 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
1109 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1110 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1111};
1112
1113static const struct oxygen_model model_xonar_hdav = {
1114 .longname = "Asus Virtuoso 200",
1115 .chip = "AV200",
1116 .init = xonar_hdav_init,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001117 .mixer_init = xonar_hdav_mixer_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001118 .cleanup = xonar_hdav_cleanup,
1119 .suspend = xonar_hdav_suspend,
1120 .resume = xonar_hdav_resume,
1121 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001122 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001123 .set_dac_params = set_hdav_params,
1124 .set_adc_params = xonar_set_cs53x1_params,
1125 .update_dac_volume = update_pcm1796_volume,
1126 .update_dac_mute = update_pcm1796_mute,
1127 .uart_input = xonar_hdmi_uart_input,
1128 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001129 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001130 .dac_tlv = pcm1796_db_scale,
1131 .model_data_size = sizeof(struct xonar_hdav),
1132 .device_config = PLAYBACK_0_TO_I2S |
1133 PLAYBACK_1_TO_SPDIF |
1134 CAPTURE_0_FROM_I2S_2 |
1135 CAPTURE_1_FROM_SPDIF,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001136 .dac_channels_pcm = 8,
1137 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001138 .dac_volume_min = 255 - 2*60,
1139 .dac_volume_max = 255,
1140 .misc_flags = OXYGEN_MISC_MIDI,
1141 .function_flags = OXYGEN_FUNCTION_2WIRE,
1142 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1143 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1144};
1145
1146static const struct oxygen_model model_xonar_st = {
1147 .longname = "Asus Virtuoso 100",
1148 .chip = "AV200",
1149 .init = xonar_st_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001150 .mixer_init = xonar_st_mixer_init,
1151 .cleanup = xonar_st_cleanup,
1152 .suspend = xonar_st_suspend,
1153 .resume = xonar_st_resume,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001154 .get_i2s_mclk = get_pcm1796_i2s_mclk,
Clemens Ladisch268304f2009-09-28 11:15:01 +02001155 .set_dac_params = set_st_params,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001156 .set_adc_params = xonar_set_cs53x1_params,
1157 .update_dac_volume = update_pcm1796_volume,
1158 .update_dac_mute = update_pcm1796_mute,
1159 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001160 .dump_registers = dump_st_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001161 .dac_tlv = pcm1796_db_scale,
1162 .model_data_size = sizeof(struct xonar_pcm179x),
1163 .device_config = PLAYBACK_0_TO_I2S |
1164 PLAYBACK_1_TO_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001165 CAPTURE_0_FROM_I2S_2 |
1166 AC97_FMIC_SWITCH,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001167 .dac_channels_pcm = 2,
1168 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001169 .dac_volume_min = 255 - 2*60,
1170 .dac_volume_max = 255,
1171 .function_flags = OXYGEN_FUNCTION_2WIRE,
1172 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1173 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1174};
1175
1176int __devinit get_xonar_pcm179x_model(struct oxygen *chip,
1177 const struct pci_device_id *id)
1178{
1179 switch (id->subdevice) {
1180 case 0x8269:
1181 chip->model = model_xonar_d2;
1182 chip->model.shortname = "Xonar D2";
1183 break;
1184 case 0x82b7:
1185 chip->model = model_xonar_d2;
1186 chip->model.shortname = "Xonar D2X";
1187 chip->model.init = xonar_d2x_init;
1188 break;
1189 case 0x8314:
1190 chip->model = model_xonar_hdav;
1191 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1192 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1193 default:
1194 chip->model.shortname = "Xonar HDAV1.3";
1195 break;
1196 case GPIO_DB_H6:
1197 chip->model.shortname = "Xonar HDAV1.3+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001198 chip->model.dac_channels_mixer = 8;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001199 break;
1200 }
1201 break;
1202 case 0x835d:
1203 chip->model = model_xonar_st;
1204 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1205 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1206 default:
1207 chip->model.shortname = "Xonar ST";
1208 break;
1209 case GPIO_DB_H6:
1210 chip->model.shortname = "Xonar ST+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001211 chip->model.dac_channels_pcm = 8;
1212 chip->model.dac_channels_mixer = 8;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001213 break;
1214 }
1215 break;
1216 case 0x835c:
1217 chip->model = model_xonar_st;
1218 chip->model.shortname = "Xonar STX";
1219 chip->model.init = xonar_stx_init;
Clemens Ladisch268304f2009-09-28 11:15:01 +02001220 chip->model.resume = xonar_stx_resume;
1221 chip->model.set_dac_params = set_pcm1796_params;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001222 break;
Clemens Ladisch2b830ba2010-10-04 13:22:51 +02001223 case 0x835e:
1224 snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n");
1225 return -ENODEV;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001226 default:
1227 return -EINVAL;
1228 }
1229 return 0;
1230}