blob: 24109d37ca09783e09b243044506c852d4cee94d [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/*
Clemens Ladischf42bb222014-08-04 15:17:55 +0200103 * Xonar Essence ST (Deluxe)/STX (II)
104 * ----------------------------------
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200105 *
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
Harley Griggs5ae00952014-09-10 19:58:25 +0100215#define GPIO_XENSE_OUTPUT_ENABLE (0x0001 | 0x0010 | 0x0020)
216#define GPIO_XENSE_SPEAKERS 0x0080
217
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200218#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200219#define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200220
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200221#define PCM1796_REG_BASE 16
222
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200223
224struct xonar_pcm179x {
225 struct xonar_generic generic;
226 unsigned int dacs;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200227 u8 pcm1796_regs[4][5];
Clemens Ladisch973dca92009-09-28 11:20:47 +0200228 unsigned int current_rate;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100229 bool h6;
Clemens Ladischa361e242009-09-28 11:19:19 +0200230 bool hp_active;
231 s8 hp_gain_offset;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200232 bool has_cs2000;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100233 u8 cs2000_regs[0x1f];
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100234 bool broken_i2c;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200235};
236
237struct xonar_hdav {
238 struct xonar_pcm179x pcm179x;
239 struct xonar_hdmi hdmi;
240};
241
242
243static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
244 u8 reg, u8 value)
245{
246 /* maps ALSA channel pair number to SPI output */
247 static const u8 codec_map[4] = {
248 0, 1, 2, 4
249 };
250 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
251 OXYGEN_SPI_DATA_LENGTH_2 |
252 OXYGEN_SPI_CLOCK_160 |
253 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
254 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
255 (reg << 8) | value);
256}
257
258static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
259 u8 reg, u8 value)
260{
261 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
262}
263
264static void pcm1796_write(struct oxygen *chip, unsigned int codec,
265 u8 reg, u8 value)
266{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200267 struct xonar_pcm179x *data = chip->model_data;
268
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200269 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
270 OXYGEN_FUNCTION_SPI)
271 pcm1796_write_spi(chip, codec, reg, value);
272 else
273 pcm1796_write_i2c(chip, codec, reg, value);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200274 if ((unsigned int)(reg - PCM1796_REG_BASE)
275 < ARRAY_SIZE(data->pcm1796_regs[codec]))
276 data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
277}
278
279static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
280 u8 reg, u8 value)
281{
282 struct xonar_pcm179x *data = chip->model_data;
283
284 if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
285 pcm1796_write(chip, codec, reg, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200286}
287
Clemens Ladisch268304f2009-09-28 11:15:01 +0200288static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
289{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200290 struct xonar_pcm179x *data = chip->model_data;
291
Clemens Ladisch268304f2009-09-28 11:15:01 +0200292 oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100293 data->cs2000_regs[reg] = value;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200294}
295
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200296static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
297{
298 struct xonar_pcm179x *data = chip->model_data;
299
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100300 if (value != data->cs2000_regs[reg])
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200301 cs2000_write(chip, reg, value);
302}
303
304static void pcm1796_registers_init(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200305{
306 struct xonar_pcm179x *data = chip->model_data;
307 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200308 s8 gain_offset;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200309
Clemens Ladisch79815e02011-01-10 16:02:32 +0100310 msleep(1);
Clemens Ladischa361e242009-09-28 11:19:19 +0200311 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200312 for (i = 0; i < data->dacs; ++i) {
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200313 /* set ATLD before ATL/ATR */
314 pcm1796_write(chip, i, 18,
315 data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
Clemens Ladischa361e242009-09-28 11:19:19 +0200316 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
317 + gain_offset);
318 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
319 + gain_offset);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200320 pcm1796_write(chip, i, 19,
321 data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200322 pcm1796_write(chip, i, 20,
323 data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
324 pcm1796_write(chip, i, 21, 0);
Clemens Ladischbc29e262011-01-10 16:11:32 +0100325 gain_offset = 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200326 }
327}
328
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200329static void pcm1796_init(struct oxygen *chip)
330{
331 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200332
Clemens Ladischc81c6b32011-07-17 22:18:05 +0200333 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] =
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100334 PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladischc81c6b32011-07-17 22:18:05 +0200335 if (!data->broken_i2c)
336 data->pcm1796_regs[0][18 - PCM1796_REG_BASE] |= PCM1796_MUTE;
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200337 data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
338 PCM1796_FLT_SHARP | PCM1796_ATS_1;
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100339 data->pcm1796_regs[0][20 - PCM1796_REG_BASE] =
340 data->h6 ? PCM1796_OS_64 : PCM1796_OS_128;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200341 pcm1796_registers_init(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200342 data->current_rate = 48000;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200343}
344
345static void xonar_d2_init(struct oxygen *chip)
346{
347 struct xonar_pcm179x *data = chip->model_data;
348
349 data->generic.anti_pop_delay = 300;
350 data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
351 data->dacs = 4;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200352
353 pcm1796_init(chip);
354
355 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
356 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
357
358 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
359
360 xonar_init_cs53x1(chip);
361 xonar_enable_output(chip);
362
363 snd_component_add(chip->card, "PCM1796");
364 snd_component_add(chip->card, "CS5381");
365}
366
367static void xonar_d2x_init(struct oxygen *chip)
368{
369 struct xonar_pcm179x *data = chip->model_data;
370
371 data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
372 data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
373 data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
374 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
375 xonar_init_ext_power(chip);
376 xonar_d2_init(chip);
377}
378
379static void xonar_hdav_init(struct oxygen *chip)
380{
381 struct xonar_hdav *data = chip->model_data;
382
383 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
384 OXYGEN_2WIRE_LENGTH_8 |
385 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100386 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200387
388 data->pcm179x.generic.anti_pop_delay = 100;
389 data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
390 data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
391 data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
392 data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100393 data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100394 data->pcm179x.h6 = chip->model.dac_channels_mixer > 2;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200395
396 pcm1796_init(chip);
397
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100398 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
399 GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200400 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
401
402 xonar_init_cs53x1(chip);
403 xonar_init_ext_power(chip);
404 xonar_hdmi_init(chip, &data->hdmi);
405 xonar_enable_output(chip);
406
407 snd_component_add(chip->card, "PCM1796");
408 snd_component_add(chip->card, "CS5381");
409}
410
Clemens Ladisch268304f2009-09-28 11:15:01 +0200411static void xonar_st_init_i2c(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200412{
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200413 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
414 OXYGEN_2WIRE_LENGTH_8 |
415 OXYGEN_2WIRE_INTERRUPT_MASK |
Clemens Ladisch41060552011-01-10 16:01:57 +0100416 OXYGEN_2WIRE_SPEED_STANDARD);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200417}
418
419static void xonar_st_init_common(struct oxygen *chip)
420{
421 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200422
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200423 data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
Clemens Ladischd2119c02011-01-10 16:00:34 +0100424 data->dacs = chip->model.dac_channels_mixer / 2;
Clemens Ladischd6cc58e2014-09-07 21:47:33 +0200425 data->h6 = chip->model.dac_channels_mixer > 2;
Clemens Ladischa361e242009-09-28 11:19:19 +0200426 data->hp_gain_offset = 2*-18;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200427
428 pcm1796_init(chip);
429
430 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
Clemens Ladischf7e4bad2010-12-02 11:36:51 +0100431 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
432 GPIO_ST_MAGIC | GPIO_ST_HP);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200433 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
434 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
435
436 xonar_init_cs53x1(chip);
437 xonar_enable_output(chip);
438
439 snd_component_add(chip->card, "PCM1792A");
440 snd_component_add(chip->card, "CS5381");
441}
442
Clemens Ladisch268304f2009-09-28 11:15:01 +0200443static void cs2000_registers_init(struct oxygen *chip)
444{
445 struct xonar_pcm179x *data = chip->model_data;
446
447 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
448 cs2000_write(chip, CS2000_DEV_CTRL, 0);
449 cs2000_write(chip, CS2000_DEV_CFG_1,
450 CS2000_R_MOD_SEL_1 |
451 (0 << CS2000_R_SEL_SHIFT) |
452 CS2000_AUX_OUT_SRC_REF_CLK |
453 CS2000_EN_DEV_CFG_1);
454 cs2000_write(chip, CS2000_DEV_CFG_2,
455 (0 << CS2000_LOCK_CLK_SHIFT) |
456 CS2000_FRAC_N_SRC_STATIC);
457 cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
458 cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
459 cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
460 cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100461 cs2000_write(chip, CS2000_FUN_CFG_1,
462 data->cs2000_regs[CS2000_FUN_CFG_1]);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200463 cs2000_write(chip, CS2000_FUN_CFG_2, 0);
464 cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100465 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200466}
467
468static void xonar_st_init(struct oxygen *chip)
469{
470 struct xonar_pcm179x *data = chip->model_data;
471
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200472 data->generic.anti_pop_delay = 100;
Clemens Ladisch00b8dd72011-01-10 16:09:23 +0100473 data->h6 = chip->model.dac_channels_mixer > 2;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200474 data->has_cs2000 = 1;
Clemens Ladisch9719fca2010-12-02 11:41:10 +0100475 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100476 data->broken_i2c = true;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200477
478 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100479 OXYGEN_RATE_48000 |
480 OXYGEN_I2S_FORMAT_I2S |
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100481 OXYGEN_I2S_MCLK(data->h6 ? MCLK_256 : MCLK_512) |
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100482 OXYGEN_I2S_BITS_16 |
483 OXYGEN_I2S_MASTER |
484 OXYGEN_I2S_BCLK_64);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200485
486 xonar_st_init_i2c(chip);
487 cs2000_registers_init(chip);
488 xonar_st_init_common(chip);
489
490 snd_component_add(chip->card, "CS2000");
491}
492
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200493static void xonar_stx_init(struct oxygen *chip)
494{
495 struct xonar_pcm179x *data = chip->model_data;
496
Clemens Ladisch268304f2009-09-28 11:15:01 +0200497 xonar_st_init_i2c(chip);
Clemens Ladischd737f3e2010-10-04 13:23:26 +0200498 data->generic.anti_pop_delay = 800;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200499 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
500 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
501 data->generic.ext_power_bit = GPI_EXT_POWER;
502 xonar_init_ext_power(chip);
Clemens Ladisch268304f2009-09-28 11:15:01 +0200503 xonar_st_init_common(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200504}
505
Harley Griggs5ae00952014-09-10 19:58:25 +0100506static void xonar_xense_init(struct oxygen *chip)
507{
508 struct xonar_pcm179x *data = chip->model_data;
509
510 data->generic.ext_power_reg = OXYGEN_GPI_DATA;
511 data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
512 data->generic.ext_power_bit = GPI_EXT_POWER;
513 xonar_init_ext_power(chip);
514
515 data->generic.anti_pop_delay = 100;
516 data->has_cs2000 = 1;
517 data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
518
519 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
520 OXYGEN_RATE_48000 |
521 OXYGEN_I2S_FORMAT_I2S |
522 OXYGEN_I2S_MCLK(MCLK_512) |
523 OXYGEN_I2S_BITS_16 |
524 OXYGEN_I2S_MASTER |
525 OXYGEN_I2S_BCLK_64);
526
527 xonar_st_init_i2c(chip);
528 cs2000_registers_init(chip);
529
530 data->generic.output_enable_bit = GPIO_XENSE_OUTPUT_ENABLE;
531 data->dacs = 1;
532 data->hp_gain_offset = 2*-18;
533
534 pcm1796_init(chip);
535
536 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
537 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
538 GPIO_ST_MAGIC | GPIO_XENSE_SPEAKERS);
539 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
540 GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
541 GPIO_XENSE_SPEAKERS);
542
543 xonar_init_cs53x1(chip);
544 xonar_enable_output(chip);
545
546 snd_component_add(chip->card, "PCM1796");
547 snd_component_add(chip->card, "CS5381");
548 snd_component_add(chip->card, "CS2000");
549}
550
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200551static void xonar_d2_cleanup(struct oxygen *chip)
552{
553 xonar_disable_output(chip);
554}
555
556static void xonar_hdav_cleanup(struct oxygen *chip)
557{
558 xonar_hdmi_cleanup(chip);
559 xonar_disable_output(chip);
560 msleep(2);
561}
562
563static void xonar_st_cleanup(struct oxygen *chip)
564{
565 xonar_disable_output(chip);
566}
567
568static void xonar_d2_suspend(struct oxygen *chip)
569{
570 xonar_d2_cleanup(chip);
571}
572
573static void xonar_hdav_suspend(struct oxygen *chip)
574{
575 xonar_hdav_cleanup(chip);
576}
577
578static void xonar_st_suspend(struct oxygen *chip)
579{
580 xonar_st_cleanup(chip);
581}
582
583static void xonar_d2_resume(struct oxygen *chip)
584{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200585 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200586 xonar_enable_output(chip);
587}
588
589static void xonar_hdav_resume(struct oxygen *chip)
590{
591 struct xonar_hdav *data = chip->model_data;
592
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200593 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200594 xonar_hdmi_resume(chip, &data->hdmi);
595 xonar_enable_output(chip);
596}
597
Clemens Ladisch268304f2009-09-28 11:15:01 +0200598static void xonar_stx_resume(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200599{
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200600 pcm1796_registers_init(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200601 xonar_enable_output(chip);
602}
603
Clemens Ladisch268304f2009-09-28 11:15:01 +0200604static void xonar_st_resume(struct oxygen *chip)
605{
606 cs2000_registers_init(chip);
607 xonar_stx_resume(chip);
608}
609
Clemens Ladisch973dca92009-09-28 11:20:47 +0200610static void update_pcm1796_oversampling(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200611{
612 struct xonar_pcm179x *data = chip->model_data;
613 unsigned int i;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200614 u8 reg;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200615
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100616 if (data->current_rate <= 48000 && !data->h6)
Clemens Ladisch973dca92009-09-28 11:20:47 +0200617 reg = PCM1796_OS_128;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200618 else
Clemens Ladischc97e2dc2011-01-10 16:11:05 +0100619 reg = PCM1796_OS_64;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200620 for (i = 0; i < data->dacs; ++i)
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200621 pcm1796_write_cached(chip, i, 20, reg);
622}
623
Clemens Ladisch973dca92009-09-28 11:20:47 +0200624static void set_pcm1796_params(struct oxygen *chip,
625 struct snd_pcm_hw_params *params)
626{
627 struct xonar_pcm179x *data = chip->model_data;
628
Clemens Ladisch79815e02011-01-10 16:02:32 +0100629 msleep(1);
Clemens Ladisch973dca92009-09-28 11:20:47 +0200630 data->current_rate = params_rate(params);
631 update_pcm1796_oversampling(chip);
632}
633
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200634static void update_pcm1796_volume(struct oxygen *chip)
635{
636 struct xonar_pcm179x *data = chip->model_data;
637 unsigned int i;
Clemens Ladischa361e242009-09-28 11:19:19 +0200638 s8 gain_offset;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200639
Clemens Ladischa361e242009-09-28 11:19:19 +0200640 gain_offset = data->hp_active ? data->hp_gain_offset : 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200641 for (i = 0; i < data->dacs; ++i) {
Clemens Ladischa361e242009-09-28 11:19:19 +0200642 pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
643 + gain_offset);
644 pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
645 + gain_offset);
Clemens Ladischbc29e262011-01-10 16:11:32 +0100646 gain_offset = 0;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200647 }
648}
649
650static void update_pcm1796_mute(struct oxygen *chip)
651{
652 struct xonar_pcm179x *data = chip->model_data;
653 unsigned int i;
654 u8 value;
655
Clemens Ladisch03ff9592011-01-10 16:03:17 +0100656 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200657 if (chip->dac_mute)
658 value |= PCM1796_MUTE;
659 for (i = 0; i < data->dacs; ++i)
660 pcm1796_write_cached(chip, i, 18, value);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200661}
662
Clemens Ladisch973dca92009-09-28 11:20:47 +0200663static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
Clemens Ladisch268304f2009-09-28 11:15:01 +0200664{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200665 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200666 u8 rate_mclk, reg;
Clemens Ladisch268304f2009-09-28 11:15:01 +0200667
Clemens Ladisch973dca92009-09-28 11:20:47 +0200668 switch (rate) {
Clemens Ladisch973dca92009-09-28 11:20:47 +0200669 case 32000:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100670 case 64000:
671 rate_mclk = OXYGEN_RATE_32000;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200672 break;
673 case 44100:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200674 case 88200:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200675 case 176400:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100676 rate_mclk = OXYGEN_RATE_44100;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200677 break;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100678 default:
679 case 48000:
680 case 96000:
Clemens Ladisch973dca92009-09-28 11:20:47 +0200681 case 192000:
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100682 rate_mclk = OXYGEN_RATE_48000;
Clemens Ladisch973dca92009-09-28 11:20:47 +0200683 break;
684 }
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +0100685
686 if (rate <= 96000 && (rate > 48000 || data->h6)) {
687 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_256);
688 reg = CS2000_REF_CLK_DIV_1;
689 } else {
690 rate_mclk |= OXYGEN_I2S_MCLK(MCLK_512);
691 reg = CS2000_REF_CLK_DIV_2;
692 }
693
Clemens Ladisch268304f2009-09-28 11:15:01 +0200694 oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
695 OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
Clemens Ladisch6f0de3c2009-09-28 11:18:45 +0200696 cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
Clemens Ladisch79815e02011-01-10 16:02:32 +0100697 msleep(3); /* PLL lock delay */
Clemens Ladisch268304f2009-09-28 11:15:01 +0200698}
699
700static void set_st_params(struct oxygen *chip,
701 struct snd_pcm_hw_params *params)
702{
Clemens Ladisch973dca92009-09-28 11:20:47 +0200703 update_cs2000_rate(chip, params_rate(params));
Clemens Ladisch268304f2009-09-28 11:15:01 +0200704 set_pcm1796_params(chip, params);
705}
706
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200707static void set_hdav_params(struct oxygen *chip,
708 struct snd_pcm_hw_params *params)
709{
710 struct xonar_hdav *data = chip->model_data;
711
712 set_pcm1796_params(chip, params);
713 xonar_set_hdmi_params(chip, &data->hdmi, params);
714}
715
716static const struct snd_kcontrol_new alt_switch = {
717 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
718 .name = "Analog Loopback Switch",
719 .info = snd_ctl_boolean_mono_info,
720 .get = xonar_gpio_bit_switch_get,
721 .put = xonar_gpio_bit_switch_put,
722 .private_value = GPIO_D2_ALT,
723};
724
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200725static int rolloff_info(struct snd_kcontrol *ctl,
726 struct snd_ctl_elem_info *info)
727{
728 static const char *const names[2] = {
729 "Sharp Roll-off", "Slow Roll-off"
730 };
731
Clemens Ladisch96007322011-01-10 16:25:44 +0100732 return snd_ctl_enum_info(info, 1, 2, names);
Clemens Ladisch4852ad02009-09-28 11:21:21 +0200733}
734
735static int rolloff_get(struct snd_kcontrol *ctl,
736 struct snd_ctl_elem_value *value)
737{
738 struct oxygen *chip = ctl->private_data;
739 struct xonar_pcm179x *data = chip->model_data;
740
741 value->value.enumerated.item[0] =
742 (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
743 PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
744 return 0;
745}
746
747static int rolloff_put(struct snd_kcontrol *ctl,
748 struct snd_ctl_elem_value *value)
749{
750 struct oxygen *chip = ctl->private_data;
751 struct xonar_pcm179x *data = chip->model_data;
752 unsigned int i;
753 int changed;
754 u8 reg;
755
756 mutex_lock(&chip->mutex);
757 reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
758 reg &= ~PCM1796_FLT_MASK;
759 if (!value->value.enumerated.item[0])
760 reg |= PCM1796_FLT_SHARP;
761 else
762 reg |= PCM1796_FLT_SLOW;
763 changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
764 if (changed) {
765 for (i = 0; i < data->dacs; ++i)
766 pcm1796_write(chip, i, 19, reg);
767 }
768 mutex_unlock(&chip->mutex);
769 return changed;
770}
771
772static const struct snd_kcontrol_new rolloff_control = {
773 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
774 .name = "DAC Filter Playback Enum",
775 .info = rolloff_info,
776 .get = rolloff_get,
777 .put = rolloff_put,
778};
779
Clemens Ladisch2509ec62010-12-02 11:38:06 +0100780static const struct snd_kcontrol_new hdav_hdmi_control = {
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "HDMI Playback Switch",
783 .info = snd_ctl_boolean_mono_info,
784 .get = xonar_gpio_bit_switch_get,
785 .put = xonar_gpio_bit_switch_put,
786 .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
787};
788
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200789static int st_output_switch_info(struct snd_kcontrol *ctl,
790 struct snd_ctl_elem_info *info)
791{
792 static const char *const names[3] = {
793 "Speakers", "Headphones", "FP Headphones"
794 };
795
Clemens Ladisch96007322011-01-10 16:25:44 +0100796 return snd_ctl_enum_info(info, 1, 3, names);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200797}
798
799static int st_output_switch_get(struct snd_kcontrol *ctl,
800 struct snd_ctl_elem_value *value)
801{
802 struct oxygen *chip = ctl->private_data;
803 u16 gpio;
804
805 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
806 if (!(gpio & GPIO_ST_HP))
807 value->value.enumerated.item[0] = 0;
808 else if (gpio & GPIO_ST_HP_REAR)
809 value->value.enumerated.item[0] = 1;
810 else
811 value->value.enumerated.item[0] = 2;
812 return 0;
813}
814
815
816static int st_output_switch_put(struct snd_kcontrol *ctl,
817 struct snd_ctl_elem_value *value)
818{
819 struct oxygen *chip = ctl->private_data;
Clemens Ladischa361e242009-09-28 11:19:19 +0200820 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200821 u16 gpio_old, gpio;
822
823 mutex_lock(&chip->mutex);
824 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
825 gpio = gpio_old;
826 switch (value->value.enumerated.item[0]) {
827 case 0:
828 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
829 break;
830 case 1:
831 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
832 break;
833 case 2:
834 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
835 break;
836 }
837 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
Clemens Ladischa361e242009-09-28 11:19:19 +0200838 data->hp_active = gpio & GPIO_ST_HP;
839 update_pcm1796_volume(chip);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200840 mutex_unlock(&chip->mutex);
841 return gpio != gpio_old;
842}
843
Clemens Ladischa361e242009-09-28 11:19:19 +0200844static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
845 struct snd_ctl_elem_info *info)
846{
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200847 static const char *const names[4] = {
848 "< 32 ohms", "32-64 ohms", "64-300 ohms", "300-600 ohms"
Clemens Ladischa361e242009-09-28 11:19:19 +0200849 };
850
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200851 return snd_ctl_enum_info(info, 1, 4, names);
Clemens Ladischa361e242009-09-28 11:19:19 +0200852}
853
854static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
855 struct snd_ctl_elem_value *value)
856{
857 struct oxygen *chip = ctl->private_data;
858 struct xonar_pcm179x *data = chip->model_data;
859
860 mutex_lock(&chip->mutex);
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200861 if (data->hp_gain_offset < 2*-12)
Clemens Ladischa361e242009-09-28 11:19:19 +0200862 value->value.enumerated.item[0] = 0;
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200863 else if (data->hp_gain_offset < 2*-6)
Clemens Ladischa361e242009-09-28 11:19:19 +0200864 value->value.enumerated.item[0] = 1;
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200865 else if (data->hp_gain_offset < 0)
Clemens Ladischa361e242009-09-28 11:19:19 +0200866 value->value.enumerated.item[0] = 2;
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200867 else
868 value->value.enumerated.item[0] = 3;
Clemens Ladischa361e242009-09-28 11:19:19 +0200869 mutex_unlock(&chip->mutex);
870 return 0;
871}
872
873
874static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
875 struct snd_ctl_elem_value *value)
876{
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200877 static const s8 offsets[] = { 2*-18, 2*-12, 2*-6, 0 };
Clemens Ladischa361e242009-09-28 11:19:19 +0200878 struct oxygen *chip = ctl->private_data;
879 struct xonar_pcm179x *data = chip->model_data;
880 s8 offset;
881 int changed;
882
Clemens Ladischdd38dc12014-09-07 21:45:59 +0200883 if (value->value.enumerated.item[0] > 3)
Clemens Ladischa361e242009-09-28 11:19:19 +0200884 return -EINVAL;
885 offset = offsets[value->value.enumerated.item[0]];
886 mutex_lock(&chip->mutex);
887 changed = offset != data->hp_gain_offset;
888 if (changed) {
889 data->hp_gain_offset = offset;
890 update_pcm1796_volume(chip);
891 }
892 mutex_unlock(&chip->mutex);
893 return changed;
894}
895
896static const struct snd_kcontrol_new st_controls[] = {
897 {
898 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
899 .name = "Analog Output",
900 .info = st_output_switch_info,
901 .get = st_output_switch_get,
902 .put = st_output_switch_put,
903 },
904 {
905 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
906 .name = "Headphones Impedance Playback Enum",
907 .info = st_hp_volume_offset_info,
908 .get = st_hp_volume_offset_get,
909 .put = st_hp_volume_offset_put,
910 },
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200911};
912
Harley Griggs5ae00952014-09-10 19:58:25 +0100913static int xense_output_switch_get(struct snd_kcontrol *ctl,
914 struct snd_ctl_elem_value *value)
915{
916 struct oxygen *chip = ctl->private_data;
917 u16 gpio;
918
919 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
920 if (gpio & GPIO_XENSE_SPEAKERS)
921 value->value.enumerated.item[0] = 0;
922 else if (!(gpio & GPIO_XENSE_SPEAKERS) && (gpio & GPIO_ST_HP_REAR))
923 value->value.enumerated.item[0] = 1;
924 else
925 value->value.enumerated.item[0] = 2;
926 return 0;
927}
928
929static int xense_output_switch_put(struct snd_kcontrol *ctl,
930 struct snd_ctl_elem_value *value)
931{
932 struct oxygen *chip = ctl->private_data;
933 struct xonar_pcm179x *data = chip->model_data;
934 u16 gpio_old, gpio;
935
936 mutex_lock(&chip->mutex);
937 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
938 gpio = gpio_old;
939 switch (value->value.enumerated.item[0]) {
940 case 0:
941 gpio |= GPIO_XENSE_SPEAKERS | GPIO_ST_HP_REAR;
942 break;
943 case 1:
944 gpio = (gpio | GPIO_ST_HP_REAR) & ~GPIO_XENSE_SPEAKERS;
945 break;
946 case 2:
947 gpio &= ~(GPIO_XENSE_SPEAKERS | GPIO_ST_HP_REAR);
948 break;
949 }
950 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
951 data->hp_active = !(gpio & GPIO_XENSE_SPEAKERS);
952 update_pcm1796_volume(chip);
953 mutex_unlock(&chip->mutex);
954 return gpio != gpio_old;
955}
956
957static const struct snd_kcontrol_new xense_controls[] = {
958 {
959 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
960 .name = "Analog Output",
961 .info = st_output_switch_info,
962 .get = xense_output_switch_get,
963 .put = xense_output_switch_put,
964 },
965 {
966 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
967 .name = "Headphones Impedance Playback Enum",
968 .info = st_hp_volume_offset_info,
969 .get = st_hp_volume_offset_get,
970 .put = st_hp_volume_offset_put,
971 },
972};
973
Clemens Ladisch65c3ac82009-09-28 11:11:27 +0200974static void xonar_line_mic_ac97_switch(struct oxygen *chip,
975 unsigned int reg, unsigned int mute)
976{
977 if (reg == AC97_LINE) {
978 spin_lock_irq(&chip->reg_lock);
979 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
980 mute ? GPIO_INPUT_ROUTE : 0,
981 GPIO_INPUT_ROUTE);
982 spin_unlock_irq(&chip->reg_lock);
983 }
984}
985
986static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
987
988static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
989{
990 if (!strncmp(template->name, "CD Capture ", 11))
991 /* CD in is actually connected to the video in pin */
992 template->private_value ^= AC97_CD ^ AC97_VIDEO;
993 return 0;
994}
995
Clemens Ladischdd203fa2011-01-10 16:05:38 +0100996static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
997{
998 if (!strncmp(template->name, "Master Playback ", 16))
999 /* no volume/mute, as I²C to the third DAC does not work */
1000 return 1;
1001 return 0;
1002}
1003
Clemens Ladisch4852ad02009-09-28 11:21:21 +02001004static int add_pcm1796_controls(struct oxygen *chip)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001005{
Clemens Ladischdd203fa2011-01-10 16:05:38 +01001006 struct xonar_pcm179x *data = chip->model_data;
Clemens Ladisch973dca92009-09-28 11:20:47 +02001007 int err;
1008
Clemens Ladischdd203fa2011-01-10 16:05:38 +01001009 if (!data->broken_i2c) {
1010 err = snd_ctl_add(chip->card,
1011 snd_ctl_new1(&rolloff_control, chip));
1012 if (err < 0)
1013 return err;
Clemens Ladischdd203fa2011-01-10 16:05:38 +01001014 }
Clemens Ladisch973dca92009-09-28 11:20:47 +02001015 return 0;
1016}
1017
Clemens Ladisch4852ad02009-09-28 11:21:21 +02001018static int xonar_d2_mixer_init(struct oxygen *chip)
1019{
1020 int err;
1021
1022 err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
1023 if (err < 0)
1024 return err;
1025 err = add_pcm1796_controls(chip);
1026 if (err < 0)
1027 return err;
1028 return 0;
1029}
1030
Clemens Ladisch973dca92009-09-28 11:20:47 +02001031static int xonar_hdav_mixer_init(struct oxygen *chip)
1032{
Clemens Ladisch2509ec62010-12-02 11:38:06 +01001033 int err;
1034
1035 err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
1036 if (err < 0)
1037 return err;
1038 err = add_pcm1796_controls(chip);
1039 if (err < 0)
1040 return err;
1041 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001042}
1043
1044static int xonar_st_mixer_init(struct oxygen *chip)
1045{
Clemens Ladischa361e242009-09-28 11:19:19 +02001046 unsigned int i;
1047 int err;
1048
1049 for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
1050 err = snd_ctl_add(chip->card,
1051 snd_ctl_new1(&st_controls[i], chip));
1052 if (err < 0)
1053 return err;
1054 }
Clemens Ladisch4852ad02009-09-28 11:21:21 +02001055 err = add_pcm1796_controls(chip);
Clemens Ladisch973dca92009-09-28 11:20:47 +02001056 if (err < 0)
1057 return err;
Clemens Ladischa361e242009-09-28 11:19:19 +02001058 return 0;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001059}
1060
Harley Griggs5ae00952014-09-10 19:58:25 +01001061static int xonar_xense_mixer_init(struct oxygen *chip)
1062{
1063 unsigned int i;
1064 int err;
1065
1066 for (i = 0; i < ARRAY_SIZE(xense_controls); ++i) {
1067 err = snd_ctl_add(chip->card,
1068 snd_ctl_new1(&xense_controls[i], chip));
1069 if (err < 0)
1070 return err;
1071 }
1072 err = add_pcm1796_controls(chip);
1073 if (err < 0)
1074 return err;
1075 return 0;
1076}
1077
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001078static void dump_pcm1796_registers(struct oxygen *chip,
1079 struct snd_info_buffer *buffer)
1080{
1081 struct xonar_pcm179x *data = chip->model_data;
1082 unsigned int dac, i;
1083
1084 for (dac = 0; dac < data->dacs; ++dac) {
1085 snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
1086 for (i = 0; i < 5; ++i)
1087 snd_iprintf(buffer, " %02x",
1088 data->pcm1796_regs[dac][i]);
1089 }
1090 snd_iprintf(buffer, "\n");
1091}
1092
1093static void dump_cs2000_registers(struct oxygen *chip,
1094 struct snd_info_buffer *buffer)
1095{
1096 struct xonar_pcm179x *data = chip->model_data;
1097 unsigned int i;
1098
1099 if (data->has_cs2000) {
1100 snd_iprintf(buffer, "\nCS2000:\n00: ");
1101 for (i = 1; i < 0x10; ++i)
1102 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1103 snd_iprintf(buffer, "\n10:");
1104 for (i = 0x10; i < 0x1f; ++i)
1105 snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
1106 snd_iprintf(buffer, "\n");
1107 }
1108}
1109
1110static void dump_st_registers(struct oxygen *chip,
1111 struct snd_info_buffer *buffer)
1112{
1113 dump_pcm1796_registers(chip, buffer);
1114 dump_cs2000_registers(chip, buffer);
1115}
1116
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001117static const struct oxygen_model model_xonar_d2 = {
1118 .longname = "Asus Virtuoso 200",
1119 .chip = "AV200",
1120 .init = xonar_d2_init,
1121 .control_filter = xonar_d2_control_filter,
1122 .mixer_init = xonar_d2_mixer_init,
1123 .cleanup = xonar_d2_cleanup,
1124 .suspend = xonar_d2_suspend,
1125 .resume = xonar_d2_resume,
1126 .set_dac_params = set_pcm1796_params,
1127 .set_adc_params = xonar_set_cs53x1_params,
1128 .update_dac_volume = update_pcm1796_volume,
1129 .update_dac_mute = update_pcm1796_mute,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001130 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001131 .dac_tlv = pcm1796_db_scale,
1132 .model_data_size = sizeof(struct xonar_pcm179x),
1133 .device_config = PLAYBACK_0_TO_I2S |
1134 PLAYBACK_1_TO_SPDIF |
1135 CAPTURE_0_FROM_I2S_2 |
1136 CAPTURE_1_FROM_SPDIF |
1137 MIDI_OUTPUT |
Clemens Ladischb6ca8ab2010-10-04 13:21:52 +02001138 MIDI_INPUT |
1139 AC97_CD_INPUT,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001140 .dac_channels_pcm = 8,
1141 .dac_channels_mixer = 8,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001142 .dac_volume_min = 255 - 2*60,
1143 .dac_volume_max = 255,
1144 .misc_flags = OXYGEN_MISC_MIDI,
1145 .function_flags = OXYGEN_FUNCTION_SPI |
1146 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001147 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
Clemens Ladischce2c4922011-01-10 16:16:08 +01001148 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001149 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001150 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1151};
1152
1153static const struct oxygen_model model_xonar_hdav = {
1154 .longname = "Asus Virtuoso 200",
1155 .chip = "AV200",
1156 .init = xonar_hdav_init,
Clemens Ladisch973dca92009-09-28 11:20:47 +02001157 .mixer_init = xonar_hdav_mixer_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001158 .cleanup = xonar_hdav_cleanup,
1159 .suspend = xonar_hdav_suspend,
1160 .resume = xonar_hdav_resume,
1161 .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
1162 .set_dac_params = set_hdav_params,
1163 .set_adc_params = xonar_set_cs53x1_params,
1164 .update_dac_volume = update_pcm1796_volume,
1165 .update_dac_mute = update_pcm1796_mute,
1166 .uart_input = xonar_hdmi_uart_input,
1167 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001168 .dump_registers = dump_pcm1796_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001169 .dac_tlv = pcm1796_db_scale,
1170 .model_data_size = sizeof(struct xonar_hdav),
1171 .device_config = PLAYBACK_0_TO_I2S |
1172 PLAYBACK_1_TO_SPDIF |
1173 CAPTURE_0_FROM_I2S_2 |
1174 CAPTURE_1_FROM_SPDIF,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001175 .dac_channels_pcm = 8,
1176 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001177 .dac_volume_min = 255 - 2*60,
1178 .dac_volume_max = 255,
1179 .misc_flags = OXYGEN_MISC_MIDI,
1180 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001181 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
Clemens Ladischce2c4922011-01-10 16:16:08 +01001182 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001183 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001184 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1185};
1186
1187static const struct oxygen_model model_xonar_st = {
1188 .longname = "Asus Virtuoso 100",
1189 .chip = "AV200",
1190 .init = xonar_st_init,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001191 .mixer_init = xonar_st_mixer_init,
1192 .cleanup = xonar_st_cleanup,
1193 .suspend = xonar_st_suspend,
1194 .resume = xonar_st_resume,
Clemens Ladisch268304f2009-09-28 11:15:01 +02001195 .set_dac_params = set_st_params,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001196 .set_adc_params = xonar_set_cs53x1_params,
1197 .update_dac_volume = update_pcm1796_volume,
1198 .update_dac_mute = update_pcm1796_mute,
1199 .ac97_switch = xonar_line_mic_ac97_switch,
Clemens Ladisch9719fca2010-12-02 11:41:10 +01001200 .dump_registers = dump_st_registers,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001201 .dac_tlv = pcm1796_db_scale,
1202 .model_data_size = sizeof(struct xonar_pcm179x),
1203 .device_config = PLAYBACK_0_TO_I2S |
1204 PLAYBACK_1_TO_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001205 CAPTURE_0_FROM_I2S_2 |
Clemens Ladischdc3fcd12011-06-18 23:05:00 +02001206 CAPTURE_1_FROM_SPDIF |
Clemens Ladische96f38f2010-12-02 11:39:34 +01001207 AC97_FMIC_SWITCH,
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001208 .dac_channels_pcm = 2,
1209 .dac_channels_mixer = 2,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001210 .dac_volume_min = 255 - 2*60,
1211 .dac_volume_max = 255,
1212 .function_flags = OXYGEN_FUNCTION_2WIRE,
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001213 .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
Clemens Ladischce2c4922011-01-10 16:16:08 +01001214 .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
Clemens Ladisch03ff9592011-01-10 16:03:17 +01001215 .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001216 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1217};
1218
Bill Pembertonf120a6f2012-12-06 12:35:20 -05001219int get_xonar_pcm179x_model(struct oxygen *chip,
1220 const struct pci_device_id *id)
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001221{
1222 switch (id->subdevice) {
1223 case 0x8269:
1224 chip->model = model_xonar_d2;
1225 chip->model.shortname = "Xonar D2";
1226 break;
1227 case 0x82b7:
1228 chip->model = model_xonar_d2;
1229 chip->model.shortname = "Xonar D2X";
1230 chip->model.init = xonar_d2x_init;
1231 break;
1232 case 0x8314:
1233 chip->model = model_xonar_hdav;
1234 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1235 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1236 default:
1237 chip->model.shortname = "Xonar HDAV1.3";
1238 break;
1239 case GPIO_DB_H6:
1240 chip->model.shortname = "Xonar HDAV1.3+H6";
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001241 chip->model.dac_channels_mixer = 8;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001242 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001243 break;
1244 }
1245 break;
1246 case 0x835d:
1247 chip->model = model_xonar_st;
1248 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1249 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1250 default:
1251 chip->model.shortname = "Xonar ST";
1252 break;
1253 case GPIO_DB_H6:
1254 chip->model.shortname = "Xonar ST+H6";
Clemens Ladischdd203fa2011-01-10 16:05:38 +01001255 chip->model.control_filter = xonar_st_h6_control_filter;
Clemens Ladisch1f4d7be2011-01-10 15:59:38 +01001256 chip->model.dac_channels_pcm = 8;
1257 chip->model.dac_channels_mixer = 8;
Clemens Ladischc81c6b32011-07-17 22:18:05 +02001258 chip->model.dac_volume_min = 255;
Clemens Ladisch5b8bf2a2011-01-10 16:14:52 +01001259 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001260 break;
1261 }
1262 break;
1263 case 0x835c:
1264 chip->model = model_xonar_st;
1265 chip->model.shortname = "Xonar STX";
1266 chip->model.init = xonar_stx_init;
Clemens Ladisch268304f2009-09-28 11:15:01 +02001267 chip->model.resume = xonar_stx_resume;
1268 chip->model.set_dac_params = set_pcm1796_params;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001269 break;
Clemens Ladischf42bb222014-08-04 15:17:55 +02001270 case 0x85f4:
1271 chip->model = model_xonar_st;
Clemens Ladischd6cc58e2014-09-07 21:47:33 +02001272 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1273 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1274 default:
1275 chip->model.shortname = "Xonar STX II";
1276 break;
1277 case GPIO_DB_H6:
1278 chip->model.shortname = "Xonar STX II+H6";
1279 chip->model.dac_channels_pcm = 8;
1280 chip->model.dac_channels_mixer = 8;
1281 chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
1282 break;
1283 }
Clemens Ladischf42bb222014-08-04 15:17:55 +02001284 chip->model.init = xonar_stx_init;
1285 chip->model.resume = xonar_stx_resume;
1286 chip->model.set_dac_params = set_pcm1796_params;
1287 break;
Harley Griggs5ae00952014-09-10 19:58:25 +01001288 case 0x8428:
1289 chip->model = model_xonar_st;
1290 chip->model.shortname = "Xonar Xense";
1291 chip->model.chip = "AV100";
1292 chip->model.init = xonar_xense_init;
1293 chip->model.mixer_init = xonar_xense_mixer_init;
1294 break;
Clemens Ladisch65c3ac82009-09-28 11:11:27 +02001295 default:
1296 return -EINVAL;
1297 }
1298 return 0;
1299}