Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1 | /* |
| 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 Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 25 | * 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 Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 29 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 30 | * 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 Ladisch | dc0adf4 | 2009-09-28 11:17:36 +0200 | [diff] [blame] | 35 | * |
| 36 | * CM9780: |
| 37 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 38 | * 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 Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 45 | */ |
| 46 | |
| 47 | /* |
| 48 | * Xonar HDAV1.3 (Deluxe) |
| 49 | * ---------------------- |
| 50 | * |
| 51 | * CMI8788: |
| 52 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 53 | * I²C <-> PCM1796 (addr 1001100) (front) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 54 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 55 | * GPI 0 <- external power present |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 56 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 57 | * 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 Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 65 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 66 | * UART <-> HDMI controller |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 67 | * |
Clemens Ladisch | dc0adf4 | 2009-09-28 11:17:36 +0200 | [diff] [blame] | 68 | * CM9780: |
| 69 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 70 | * 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 Ladisch | dc0adf4 | 2009-09-28 11:17:36 +0200 | [diff] [blame] | 77 | * |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 78 | * no daughterboard |
| 79 | * ---------------- |
| 80 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 81 | * GPIO 4 <- 1 |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 82 | * |
| 83 | * H6 daughterboard |
| 84 | * ---------------- |
| 85 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 86 | * GPIO 4 <- 0 |
| 87 | * GPIO 5 <- 0 |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 88 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 89 | * I²C <-> PCM1796 (addr 1001101) (surround) |
| 90 | * <-> PCM1796 (addr 1001110) (center/LFE) |
| 91 | * <-> PCM1796 (addr 1001111) (back) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 92 | * |
| 93 | * unknown daughterboard |
| 94 | * --------------------- |
| 95 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 96 | * GPIO 4 <- 0 |
| 97 | * GPIO 5 <- 1 |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 98 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 99 | * I²C <-> CS4362A (addr 0011000) (surround, center/LFE, back) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 100 | */ |
| 101 | |
| 102 | /* |
| 103 | * Xonar Essence ST (Deluxe)/STX |
| 104 | * ----------------------------- |
| 105 | * |
| 106 | * CMI8788: |
| 107 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 108 | * I²C <-> PCM1792A (addr 1001100) |
| 109 | * <-> CS2000 (addr 1001110) (ST only) |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 110 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 111 | * ADC1 MCLK -> REF_CLK of CS2000 (ST only) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 112 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 113 | * GPI 0 <- external power present (STX only) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 114 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 115 | * 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 Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 124 | * |
| 125 | * PCM1792A: |
| 126 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 127 | * SCK <- CLK_OUT of CS2000 (ST only) |
Clemens Ladisch | dc0adf4 | 2009-09-28 11:17:36 +0200 | [diff] [blame] | 128 | * |
| 129 | * CM9780: |
| 130 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 131 | * 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 Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 137 | * |
| 138 | * H6 daughterboard |
| 139 | * ---------------- |
| 140 | * |
| 141 | * GPIO 4 <- 0 |
| 142 | * GPIO 5 <- 0 |
| 143 | */ |
| 144 | |
Clemens Ladisch | 2b830ba | 2010-10-04 13:22:51 +0200 | [diff] [blame] | 145 | /* |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 146 | * Xonar Xense |
| 147 | * ----------- |
Clemens Ladisch | 2b830ba | 2010-10-04 13:22:51 +0200 | [diff] [blame] | 148 | * |
| 149 | * CMI8788: |
| 150 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 151 | * I²C <-> PCM1796 (addr 1001100) (front) |
| 152 | * <-> CS4362A (addr 0011000) (surround, center/LFE, back) |
| 153 | * <-> CS2000 (addr 1001110) |
Clemens Ladisch | 2b830ba | 2010-10-04 13:22:51 +0200 | [diff] [blame] | 154 | * |
Clemens Ladisch | de66493 | 2010-12-02 11:42:48 +0100 | [diff] [blame] | 155 | * 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 Ladisch | 2b830ba | 2010-10-04 13:22:51 +0200 | [diff] [blame] | 179 | */ |
| 180 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 181 | #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 Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 187 | #include <sound/info.h> |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 188 | #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 Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 194 | #include "cs2000.h" |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 195 | |
| 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 Ladisch | f7e4bad | 2010-12-02 11:36:51 +0100 | [diff] [blame] | 205 | #define GPIO_HDAV_MAGIC 0x00c0 |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 206 | |
| 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 Ladisch | f7e4bad | 2010-12-02 11:36:51 +0100 | [diff] [blame] | 212 | #define GPIO_ST_MAGIC 0x0040 |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 213 | #define GPIO_ST_HP 0x0080 |
| 214 | |
| 215 | #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */ |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 216 | #define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */ |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 217 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 218 | #define PCM1796_REG_BASE 16 |
| 219 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 220 | |
| 221 | struct xonar_pcm179x { |
| 222 | struct xonar_generic generic; |
| 223 | unsigned int dacs; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 224 | u8 pcm1796_regs[4][5]; |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 225 | unsigned int current_rate; |
| 226 | bool os_128; |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 227 | bool hp_active; |
| 228 | s8 hp_gain_offset; |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 229 | bool has_cs2000; |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 230 | u8 cs2000_regs[0x1f]; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | struct xonar_hdav { |
| 234 | struct xonar_pcm179x pcm179x; |
| 235 | struct xonar_hdmi hdmi; |
| 236 | }; |
| 237 | |
| 238 | |
| 239 | static 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 | |
| 254 | static 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 | |
| 260 | static void pcm1796_write(struct oxygen *chip, unsigned int codec, |
| 261 | u8 reg, u8 value) |
| 262 | { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 263 | struct xonar_pcm179x *data = chip->model_data; |
| 264 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 265 | 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 Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 270 | 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 | |
| 275 | static 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 Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 284 | static void cs2000_write(struct oxygen *chip, u8 reg, u8 value) |
| 285 | { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 286 | struct xonar_pcm179x *data = chip->model_data; |
| 287 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 288 | oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value); |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 289 | data->cs2000_regs[reg] = value; |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 292 | static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value) |
| 293 | { |
| 294 | struct xonar_pcm179x *data = chip->model_data; |
| 295 | |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 296 | if (value != data->cs2000_regs[reg]) |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 297 | cs2000_write(chip, reg, value); |
| 298 | } |
| 299 | |
| 300 | static void pcm1796_registers_init(struct oxygen *chip) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 301 | { |
| 302 | struct xonar_pcm179x *data = chip->model_data; |
| 303 | unsigned int i; |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 304 | s8 gain_offset; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 305 | |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 306 | gain_offset = data->hp_active ? data->hp_gain_offset : 0; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 307 | for (i = 0; i < data->dacs; ++i) { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 308 | /* set ATLD before ATL/ATR */ |
| 309 | pcm1796_write(chip, i, 18, |
| 310 | data->pcm1796_regs[0][18 - PCM1796_REG_BASE]); |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 311 | pcm1796_write(chip, i, 16, chip->dac_volume[i * 2] |
| 312 | + gain_offset); |
| 313 | pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1] |
| 314 | + gain_offset); |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 315 | pcm1796_write(chip, i, 19, |
| 316 | data->pcm1796_regs[0][19 - PCM1796_REG_BASE]); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 317 | pcm1796_write(chip, i, 20, |
| 318 | data->pcm1796_regs[0][20 - PCM1796_REG_BASE]); |
| 319 | pcm1796_write(chip, i, 21, 0); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 323 | static void pcm1796_init(struct oxygen *chip) |
| 324 | { |
| 325 | struct xonar_pcm179x *data = chip->model_data; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 326 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 327 | data->pcm1796_regs[0][18 - PCM1796_REG_BASE] = PCM1796_MUTE | |
| 328 | PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 329 | data->pcm1796_regs[0][19 - PCM1796_REG_BASE] = |
| 330 | PCM1796_FLT_SHARP | PCM1796_ATS_1; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 331 | data->pcm1796_regs[0][20 - PCM1796_REG_BASE] = PCM1796_OS_64; |
| 332 | pcm1796_registers_init(chip); |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 333 | data->current_rate = 48000; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static void xonar_d2_init(struct oxygen *chip) |
| 337 | { |
| 338 | struct xonar_pcm179x *data = chip->model_data; |
| 339 | |
| 340 | data->generic.anti_pop_delay = 300; |
| 341 | data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE; |
| 342 | data->dacs = 4; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 343 | |
| 344 | pcm1796_init(chip); |
| 345 | |
| 346 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT); |
| 347 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT); |
| 348 | |
| 349 | oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC); |
| 350 | |
| 351 | xonar_init_cs53x1(chip); |
| 352 | xonar_enable_output(chip); |
| 353 | |
| 354 | snd_component_add(chip->card, "PCM1796"); |
| 355 | snd_component_add(chip->card, "CS5381"); |
| 356 | } |
| 357 | |
| 358 | static void xonar_d2x_init(struct oxygen *chip) |
| 359 | { |
| 360 | struct xonar_pcm179x *data = chip->model_data; |
| 361 | |
| 362 | data->generic.ext_power_reg = OXYGEN_GPIO_DATA; |
| 363 | data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK; |
| 364 | data->generic.ext_power_bit = GPIO_D2X_EXT_POWER; |
| 365 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER); |
| 366 | xonar_init_ext_power(chip); |
| 367 | xonar_d2_init(chip); |
| 368 | } |
| 369 | |
| 370 | static void xonar_hdav_init(struct oxygen *chip) |
| 371 | { |
| 372 | struct xonar_hdav *data = chip->model_data; |
| 373 | |
| 374 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, |
| 375 | OXYGEN_2WIRE_LENGTH_8 | |
| 376 | OXYGEN_2WIRE_INTERRUPT_MASK | |
| 377 | OXYGEN_2WIRE_SPEED_FAST); |
| 378 | |
| 379 | data->pcm179x.generic.anti_pop_delay = 100; |
| 380 | data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE; |
| 381 | data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA; |
| 382 | data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; |
| 383 | data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER; |
| 384 | data->pcm179x.dacs = chip->model.private_data ? 4 : 1; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 385 | |
| 386 | pcm1796_init(chip); |
| 387 | |
Clemens Ladisch | f7e4bad | 2010-12-02 11:36:51 +0100 | [diff] [blame] | 388 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, |
| 389 | GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 390 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE); |
| 391 | |
| 392 | xonar_init_cs53x1(chip); |
| 393 | xonar_init_ext_power(chip); |
| 394 | xonar_hdmi_init(chip, &data->hdmi); |
| 395 | xonar_enable_output(chip); |
| 396 | |
| 397 | snd_component_add(chip->card, "PCM1796"); |
| 398 | snd_component_add(chip->card, "CS5381"); |
| 399 | } |
| 400 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 401 | static void xonar_st_init_i2c(struct oxygen *chip) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 402 | { |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 403 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, |
| 404 | OXYGEN_2WIRE_LENGTH_8 | |
| 405 | OXYGEN_2WIRE_INTERRUPT_MASK | |
| 406 | OXYGEN_2WIRE_SPEED_FAST); |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static void xonar_st_init_common(struct oxygen *chip) |
| 410 | { |
| 411 | struct xonar_pcm179x *data = chip->model_data; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 412 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 413 | data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE; |
| 414 | data->dacs = chip->model.private_data ? 4 : 1; |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 415 | data->hp_gain_offset = 2*-18; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 416 | |
| 417 | pcm1796_init(chip); |
| 418 | |
| 419 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, |
Clemens Ladisch | f7e4bad | 2010-12-02 11:36:51 +0100 | [diff] [blame] | 420 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | |
| 421 | GPIO_ST_MAGIC | GPIO_ST_HP); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 422 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, |
| 423 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); |
| 424 | |
| 425 | xonar_init_cs53x1(chip); |
| 426 | xonar_enable_output(chip); |
| 427 | |
| 428 | snd_component_add(chip->card, "PCM1792A"); |
| 429 | snd_component_add(chip->card, "CS5381"); |
| 430 | } |
| 431 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 432 | static void cs2000_registers_init(struct oxygen *chip) |
| 433 | { |
| 434 | struct xonar_pcm179x *data = chip->model_data; |
| 435 | |
| 436 | cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE); |
| 437 | cs2000_write(chip, CS2000_DEV_CTRL, 0); |
| 438 | cs2000_write(chip, CS2000_DEV_CFG_1, |
| 439 | CS2000_R_MOD_SEL_1 | |
| 440 | (0 << CS2000_R_SEL_SHIFT) | |
| 441 | CS2000_AUX_OUT_SRC_REF_CLK | |
| 442 | CS2000_EN_DEV_CFG_1); |
| 443 | cs2000_write(chip, CS2000_DEV_CFG_2, |
| 444 | (0 << CS2000_LOCK_CLK_SHIFT) | |
| 445 | CS2000_FRAC_N_SRC_STATIC); |
| 446 | cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */ |
| 447 | cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10); |
| 448 | cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00); |
| 449 | cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00); |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 450 | cs2000_write(chip, CS2000_FUN_CFG_1, |
| 451 | data->cs2000_regs[CS2000_FUN_CFG_1]); |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 452 | cs2000_write(chip, CS2000_FUN_CFG_2, 0); |
| 453 | cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2); |
| 454 | } |
| 455 | |
| 456 | static void xonar_st_init(struct oxygen *chip) |
| 457 | { |
| 458 | struct xonar_pcm179x *data = chip->model_data; |
| 459 | |
Clemens Ladisch | d737f3e | 2010-10-04 13:23:26 +0200 | [diff] [blame] | 460 | data->generic.anti_pop_delay = 100; |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 461 | data->has_cs2000 = 1; |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 462 | data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1; |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 463 | |
| 464 | oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, |
| 465 | OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S | |
| 466 | OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | |
| 467 | OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); |
| 468 | |
| 469 | xonar_st_init_i2c(chip); |
| 470 | cs2000_registers_init(chip); |
| 471 | xonar_st_init_common(chip); |
| 472 | |
| 473 | snd_component_add(chip->card, "CS2000"); |
| 474 | } |
| 475 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 476 | static void xonar_stx_init(struct oxygen *chip) |
| 477 | { |
| 478 | struct xonar_pcm179x *data = chip->model_data; |
| 479 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 480 | xonar_st_init_i2c(chip); |
Clemens Ladisch | d737f3e | 2010-10-04 13:23:26 +0200 | [diff] [blame] | 481 | data->generic.anti_pop_delay = 800; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 482 | data->generic.ext_power_reg = OXYGEN_GPI_DATA; |
| 483 | data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; |
| 484 | data->generic.ext_power_bit = GPI_EXT_POWER; |
| 485 | xonar_init_ext_power(chip); |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 486 | xonar_st_init_common(chip); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | static void xonar_d2_cleanup(struct oxygen *chip) |
| 490 | { |
| 491 | xonar_disable_output(chip); |
| 492 | } |
| 493 | |
| 494 | static void xonar_hdav_cleanup(struct oxygen *chip) |
| 495 | { |
| 496 | xonar_hdmi_cleanup(chip); |
| 497 | xonar_disable_output(chip); |
| 498 | msleep(2); |
| 499 | } |
| 500 | |
| 501 | static void xonar_st_cleanup(struct oxygen *chip) |
| 502 | { |
| 503 | xonar_disable_output(chip); |
| 504 | } |
| 505 | |
| 506 | static void xonar_d2_suspend(struct oxygen *chip) |
| 507 | { |
| 508 | xonar_d2_cleanup(chip); |
| 509 | } |
| 510 | |
| 511 | static void xonar_hdav_suspend(struct oxygen *chip) |
| 512 | { |
| 513 | xonar_hdav_cleanup(chip); |
| 514 | } |
| 515 | |
| 516 | static void xonar_st_suspend(struct oxygen *chip) |
| 517 | { |
| 518 | xonar_st_cleanup(chip); |
| 519 | } |
| 520 | |
| 521 | static void xonar_d2_resume(struct oxygen *chip) |
| 522 | { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 523 | pcm1796_registers_init(chip); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 524 | xonar_enable_output(chip); |
| 525 | } |
| 526 | |
| 527 | static void xonar_hdav_resume(struct oxygen *chip) |
| 528 | { |
| 529 | struct xonar_hdav *data = chip->model_data; |
| 530 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 531 | pcm1796_registers_init(chip); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 532 | xonar_hdmi_resume(chip, &data->hdmi); |
| 533 | xonar_enable_output(chip); |
| 534 | } |
| 535 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 536 | static void xonar_stx_resume(struct oxygen *chip) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 537 | { |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 538 | pcm1796_registers_init(chip); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 539 | xonar_enable_output(chip); |
| 540 | } |
| 541 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 542 | static void xonar_st_resume(struct oxygen *chip) |
| 543 | { |
| 544 | cs2000_registers_init(chip); |
| 545 | xonar_stx_resume(chip); |
| 546 | } |
| 547 | |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 548 | static unsigned int mclk_from_rate(struct oxygen *chip, unsigned int rate) |
| 549 | { |
| 550 | struct xonar_pcm179x *data = chip->model_data; |
| 551 | |
| 552 | if (rate <= 32000) |
| 553 | return OXYGEN_I2S_MCLK_512; |
| 554 | else if (rate <= 48000 && data->os_128) |
| 555 | return OXYGEN_I2S_MCLK_512; |
| 556 | else if (rate <= 96000) |
| 557 | return OXYGEN_I2S_MCLK_256; |
| 558 | else |
| 559 | return OXYGEN_I2S_MCLK_128; |
| 560 | } |
| 561 | |
| 562 | static unsigned int get_pcm1796_i2s_mclk(struct oxygen *chip, |
| 563 | unsigned int channel, |
| 564 | struct snd_pcm_hw_params *params) |
| 565 | { |
| 566 | if (channel == PCM_MULTICH) |
| 567 | return mclk_from_rate(chip, params_rate(params)); |
| 568 | else |
| 569 | return oxygen_default_i2s_mclk(chip, channel, params); |
| 570 | } |
| 571 | |
| 572 | static void update_pcm1796_oversampling(struct oxygen *chip) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 573 | { |
| 574 | struct xonar_pcm179x *data = chip->model_data; |
| 575 | unsigned int i; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 576 | u8 reg; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 577 | |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 578 | if (data->current_rate <= 32000) |
| 579 | reg = PCM1796_OS_128; |
| 580 | else if (data->current_rate <= 48000 && data->os_128) |
| 581 | reg = PCM1796_OS_128; |
| 582 | else if (data->current_rate <= 96000 || data->os_128) |
| 583 | reg = PCM1796_OS_64; |
| 584 | else |
| 585 | reg = PCM1796_OS_32; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 586 | for (i = 0; i < data->dacs; ++i) |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 587 | pcm1796_write_cached(chip, i, 20, reg); |
| 588 | } |
| 589 | |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 590 | static void set_pcm1796_params(struct oxygen *chip, |
| 591 | struct snd_pcm_hw_params *params) |
| 592 | { |
| 593 | struct xonar_pcm179x *data = chip->model_data; |
| 594 | |
| 595 | data->current_rate = params_rate(params); |
| 596 | update_pcm1796_oversampling(chip); |
| 597 | } |
| 598 | |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 599 | static void update_pcm1796_volume(struct oxygen *chip) |
| 600 | { |
| 601 | struct xonar_pcm179x *data = chip->model_data; |
| 602 | unsigned int i; |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 603 | s8 gain_offset; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 604 | |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 605 | gain_offset = data->hp_active ? data->hp_gain_offset : 0; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 606 | for (i = 0; i < data->dacs; ++i) { |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 607 | pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2] |
| 608 | + gain_offset); |
| 609 | pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1] |
| 610 | + gain_offset); |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
| 614 | static void update_pcm1796_mute(struct oxygen *chip) |
| 615 | { |
| 616 | struct xonar_pcm179x *data = chip->model_data; |
| 617 | unsigned int i; |
| 618 | u8 value; |
| 619 | |
| 620 | value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; |
| 621 | if (chip->dac_mute) |
| 622 | value |= PCM1796_MUTE; |
| 623 | for (i = 0; i < data->dacs; ++i) |
| 624 | pcm1796_write_cached(chip, i, 18, value); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 625 | } |
| 626 | |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 627 | static void update_cs2000_rate(struct oxygen *chip, unsigned int rate) |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 628 | { |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 629 | struct xonar_pcm179x *data = chip->model_data; |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 630 | u8 rate_mclk, reg; |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 631 | |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 632 | switch (rate) { |
| 633 | /* XXX Why is the I2S A MCLK half the actual I2S MCLK? */ |
| 634 | case 32000: |
| 635 | rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256; |
| 636 | break; |
| 637 | case 44100: |
| 638 | if (data->os_128) |
| 639 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256; |
| 640 | else |
| 641 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128; |
| 642 | break; |
| 643 | default: /* 48000 */ |
| 644 | if (data->os_128) |
| 645 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256; |
| 646 | else |
| 647 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128; |
| 648 | break; |
| 649 | case 64000: |
| 650 | rate_mclk = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256; |
| 651 | break; |
| 652 | case 88200: |
| 653 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256; |
| 654 | break; |
| 655 | case 96000: |
| 656 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256; |
| 657 | break; |
| 658 | case 176400: |
| 659 | rate_mclk = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256; |
| 660 | break; |
| 661 | case 192000: |
| 662 | rate_mclk = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256; |
| 663 | break; |
| 664 | } |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 665 | oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk, |
| 666 | OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK); |
| 667 | if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128) |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 668 | reg = CS2000_REF_CLK_DIV_1; |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 669 | else |
Clemens Ladisch | 6f0de3c | 2009-09-28 11:18:45 +0200 | [diff] [blame] | 670 | reg = CS2000_REF_CLK_DIV_2; |
| 671 | cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg); |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static void set_st_params(struct oxygen *chip, |
| 675 | struct snd_pcm_hw_params *params) |
| 676 | { |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 677 | update_cs2000_rate(chip, params_rate(params)); |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 678 | set_pcm1796_params(chip, params); |
| 679 | } |
| 680 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 681 | static void set_hdav_params(struct oxygen *chip, |
| 682 | struct snd_pcm_hw_params *params) |
| 683 | { |
| 684 | struct xonar_hdav *data = chip->model_data; |
| 685 | |
| 686 | set_pcm1796_params(chip, params); |
| 687 | xonar_set_hdmi_params(chip, &data->hdmi, params); |
| 688 | } |
| 689 | |
| 690 | static const struct snd_kcontrol_new alt_switch = { |
| 691 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 692 | .name = "Analog Loopback Switch", |
| 693 | .info = snd_ctl_boolean_mono_info, |
| 694 | .get = xonar_gpio_bit_switch_get, |
| 695 | .put = xonar_gpio_bit_switch_put, |
| 696 | .private_value = GPIO_D2_ALT, |
| 697 | }; |
| 698 | |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 699 | static int rolloff_info(struct snd_kcontrol *ctl, |
| 700 | struct snd_ctl_elem_info *info) |
| 701 | { |
| 702 | static const char *const names[2] = { |
| 703 | "Sharp Roll-off", "Slow Roll-off" |
| 704 | }; |
| 705 | |
| 706 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 707 | info->count = 1; |
| 708 | info->value.enumerated.items = 2; |
| 709 | if (info->value.enumerated.item >= 2) |
| 710 | info->value.enumerated.item = 1; |
| 711 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static int rolloff_get(struct snd_kcontrol *ctl, |
| 716 | struct snd_ctl_elem_value *value) |
| 717 | { |
| 718 | struct oxygen *chip = ctl->private_data; |
| 719 | struct xonar_pcm179x *data = chip->model_data; |
| 720 | |
| 721 | value->value.enumerated.item[0] = |
| 722 | (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] & |
| 723 | PCM1796_FLT_MASK) != PCM1796_FLT_SHARP; |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | static int rolloff_put(struct snd_kcontrol *ctl, |
| 728 | struct snd_ctl_elem_value *value) |
| 729 | { |
| 730 | struct oxygen *chip = ctl->private_data; |
| 731 | struct xonar_pcm179x *data = chip->model_data; |
| 732 | unsigned int i; |
| 733 | int changed; |
| 734 | u8 reg; |
| 735 | |
| 736 | mutex_lock(&chip->mutex); |
| 737 | reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE]; |
| 738 | reg &= ~PCM1796_FLT_MASK; |
| 739 | if (!value->value.enumerated.item[0]) |
| 740 | reg |= PCM1796_FLT_SHARP; |
| 741 | else |
| 742 | reg |= PCM1796_FLT_SLOW; |
| 743 | changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE]; |
| 744 | if (changed) { |
| 745 | for (i = 0; i < data->dacs; ++i) |
| 746 | pcm1796_write(chip, i, 19, reg); |
| 747 | } |
| 748 | mutex_unlock(&chip->mutex); |
| 749 | return changed; |
| 750 | } |
| 751 | |
| 752 | static const struct snd_kcontrol_new rolloff_control = { |
| 753 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 754 | .name = "DAC Filter Playback Enum", |
| 755 | .info = rolloff_info, |
| 756 | .get = rolloff_get, |
| 757 | .put = rolloff_put, |
| 758 | }; |
| 759 | |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 760 | static int os_128_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) |
| 761 | { |
| 762 | static const char *const names[2] = { "64x", "128x" }; |
| 763 | |
| 764 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 765 | info->count = 1; |
| 766 | info->value.enumerated.items = 2; |
| 767 | if (info->value.enumerated.item >= 2) |
| 768 | info->value.enumerated.item = 1; |
| 769 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static int os_128_get(struct snd_kcontrol *ctl, |
| 774 | struct snd_ctl_elem_value *value) |
| 775 | { |
| 776 | struct oxygen *chip = ctl->private_data; |
| 777 | struct xonar_pcm179x *data = chip->model_data; |
| 778 | |
| 779 | value->value.enumerated.item[0] = data->os_128; |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | static int os_128_put(struct snd_kcontrol *ctl, |
| 784 | struct snd_ctl_elem_value *value) |
| 785 | { |
| 786 | struct oxygen *chip = ctl->private_data; |
| 787 | struct xonar_pcm179x *data = chip->model_data; |
| 788 | int changed; |
| 789 | |
| 790 | mutex_lock(&chip->mutex); |
| 791 | changed = value->value.enumerated.item[0] != data->os_128; |
| 792 | if (changed) { |
| 793 | data->os_128 = value->value.enumerated.item[0]; |
| 794 | if (data->has_cs2000) |
| 795 | update_cs2000_rate(chip, data->current_rate); |
| 796 | oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, |
| 797 | mclk_from_rate(chip, data->current_rate), |
| 798 | OXYGEN_I2S_MCLK_MASK); |
| 799 | update_pcm1796_oversampling(chip); |
| 800 | } |
| 801 | mutex_unlock(&chip->mutex); |
| 802 | return changed; |
| 803 | } |
| 804 | |
| 805 | static const struct snd_kcontrol_new os_128_control = { |
| 806 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 807 | .name = "DAC Oversampling Playback Enum", |
| 808 | .info = os_128_info, |
| 809 | .get = os_128_get, |
| 810 | .put = os_128_put, |
| 811 | }; |
| 812 | |
Clemens Ladisch | 2509ec6 | 2010-12-02 11:38:06 +0100 | [diff] [blame] | 813 | static const struct snd_kcontrol_new hdav_hdmi_control = { |
| 814 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 815 | .name = "HDMI Playback Switch", |
| 816 | .info = snd_ctl_boolean_mono_info, |
| 817 | .get = xonar_gpio_bit_switch_get, |
| 818 | .put = xonar_gpio_bit_switch_put, |
| 819 | .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT, |
| 820 | }; |
| 821 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 822 | static int st_output_switch_info(struct snd_kcontrol *ctl, |
| 823 | struct snd_ctl_elem_info *info) |
| 824 | { |
| 825 | static const char *const names[3] = { |
| 826 | "Speakers", "Headphones", "FP Headphones" |
| 827 | }; |
| 828 | |
| 829 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 830 | info->count = 1; |
| 831 | info->value.enumerated.items = 3; |
| 832 | if (info->value.enumerated.item >= 3) |
| 833 | info->value.enumerated.item = 2; |
| 834 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static int st_output_switch_get(struct snd_kcontrol *ctl, |
| 839 | struct snd_ctl_elem_value *value) |
| 840 | { |
| 841 | struct oxygen *chip = ctl->private_data; |
| 842 | u16 gpio; |
| 843 | |
| 844 | gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA); |
| 845 | if (!(gpio & GPIO_ST_HP)) |
| 846 | value->value.enumerated.item[0] = 0; |
| 847 | else if (gpio & GPIO_ST_HP_REAR) |
| 848 | value->value.enumerated.item[0] = 1; |
| 849 | else |
| 850 | value->value.enumerated.item[0] = 2; |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | |
| 855 | static int st_output_switch_put(struct snd_kcontrol *ctl, |
| 856 | struct snd_ctl_elem_value *value) |
| 857 | { |
| 858 | struct oxygen *chip = ctl->private_data; |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 859 | struct xonar_pcm179x *data = chip->model_data; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 860 | u16 gpio_old, gpio; |
| 861 | |
| 862 | mutex_lock(&chip->mutex); |
| 863 | gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA); |
| 864 | gpio = gpio_old; |
| 865 | switch (value->value.enumerated.item[0]) { |
| 866 | case 0: |
| 867 | gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR); |
| 868 | break; |
| 869 | case 1: |
| 870 | gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR; |
| 871 | break; |
| 872 | case 2: |
| 873 | gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR; |
| 874 | break; |
| 875 | } |
| 876 | oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio); |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 877 | data->hp_active = gpio & GPIO_ST_HP; |
| 878 | update_pcm1796_volume(chip); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 879 | mutex_unlock(&chip->mutex); |
| 880 | return gpio != gpio_old; |
| 881 | } |
| 882 | |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 883 | static int st_hp_volume_offset_info(struct snd_kcontrol *ctl, |
| 884 | struct snd_ctl_elem_info *info) |
| 885 | { |
| 886 | static const char *const names[3] = { |
| 887 | "< 64 ohms", "64-300 ohms", "300-600 ohms" |
| 888 | }; |
| 889 | |
| 890 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 891 | info->count = 1; |
| 892 | info->value.enumerated.items = 3; |
| 893 | if (info->value.enumerated.item > 2) |
| 894 | info->value.enumerated.item = 2; |
| 895 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | static int st_hp_volume_offset_get(struct snd_kcontrol *ctl, |
| 900 | struct snd_ctl_elem_value *value) |
| 901 | { |
| 902 | struct oxygen *chip = ctl->private_data; |
| 903 | struct xonar_pcm179x *data = chip->model_data; |
| 904 | |
| 905 | mutex_lock(&chip->mutex); |
| 906 | if (data->hp_gain_offset < 2*-6) |
| 907 | value->value.enumerated.item[0] = 0; |
| 908 | else if (data->hp_gain_offset < 0) |
| 909 | value->value.enumerated.item[0] = 1; |
| 910 | else |
| 911 | value->value.enumerated.item[0] = 2; |
| 912 | mutex_unlock(&chip->mutex); |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | |
| 917 | static int st_hp_volume_offset_put(struct snd_kcontrol *ctl, |
| 918 | struct snd_ctl_elem_value *value) |
| 919 | { |
| 920 | static const s8 offsets[] = { 2*-18, 2*-6, 0 }; |
| 921 | struct oxygen *chip = ctl->private_data; |
| 922 | struct xonar_pcm179x *data = chip->model_data; |
| 923 | s8 offset; |
| 924 | int changed; |
| 925 | |
| 926 | if (value->value.enumerated.item[0] > 2) |
| 927 | return -EINVAL; |
| 928 | offset = offsets[value->value.enumerated.item[0]]; |
| 929 | mutex_lock(&chip->mutex); |
| 930 | changed = offset != data->hp_gain_offset; |
| 931 | if (changed) { |
| 932 | data->hp_gain_offset = offset; |
| 933 | update_pcm1796_volume(chip); |
| 934 | } |
| 935 | mutex_unlock(&chip->mutex); |
| 936 | return changed; |
| 937 | } |
| 938 | |
| 939 | static const struct snd_kcontrol_new st_controls[] = { |
| 940 | { |
| 941 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 942 | .name = "Analog Output", |
| 943 | .info = st_output_switch_info, |
| 944 | .get = st_output_switch_get, |
| 945 | .put = st_output_switch_put, |
| 946 | }, |
| 947 | { |
| 948 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 949 | .name = "Headphones Impedance Playback Enum", |
| 950 | .info = st_hp_volume_offset_info, |
| 951 | .get = st_hp_volume_offset_get, |
| 952 | .put = st_hp_volume_offset_put, |
| 953 | }, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 954 | }; |
| 955 | |
| 956 | static void xonar_line_mic_ac97_switch(struct oxygen *chip, |
| 957 | unsigned int reg, unsigned int mute) |
| 958 | { |
| 959 | if (reg == AC97_LINE) { |
| 960 | spin_lock_irq(&chip->reg_lock); |
| 961 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, |
| 962 | mute ? GPIO_INPUT_ROUTE : 0, |
| 963 | GPIO_INPUT_ROUTE); |
| 964 | spin_unlock_irq(&chip->reg_lock); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0); |
| 969 | |
| 970 | static int xonar_d2_control_filter(struct snd_kcontrol_new *template) |
| 971 | { |
| 972 | if (!strncmp(template->name, "CD Capture ", 11)) |
| 973 | /* CD in is actually connected to the video in pin */ |
| 974 | template->private_value ^= AC97_CD ^ AC97_VIDEO; |
| 975 | return 0; |
| 976 | } |
| 977 | |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 978 | static int add_pcm1796_controls(struct oxygen *chip) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 979 | { |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 980 | int err; |
| 981 | |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 982 | err = snd_ctl_add(chip->card, snd_ctl_new1(&rolloff_control, chip)); |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 983 | if (err < 0) |
| 984 | return err; |
| 985 | err = snd_ctl_add(chip->card, snd_ctl_new1(&os_128_control, chip)); |
| 986 | if (err < 0) |
| 987 | return err; |
| 988 | return 0; |
| 989 | } |
| 990 | |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 991 | static int xonar_d2_mixer_init(struct oxygen *chip) |
| 992 | { |
| 993 | int err; |
| 994 | |
| 995 | err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); |
| 996 | if (err < 0) |
| 997 | return err; |
| 998 | err = add_pcm1796_controls(chip); |
| 999 | if (err < 0) |
| 1000 | return err; |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 1004 | static int xonar_hdav_mixer_init(struct oxygen *chip) |
| 1005 | { |
Clemens Ladisch | 2509ec6 | 2010-12-02 11:38:06 +0100 | [diff] [blame] | 1006 | int err; |
| 1007 | |
| 1008 | err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip)); |
| 1009 | if (err < 0) |
| 1010 | return err; |
| 1011 | err = add_pcm1796_controls(chip); |
| 1012 | if (err < 0) |
| 1013 | return err; |
| 1014 | return 0; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static int xonar_st_mixer_init(struct oxygen *chip) |
| 1018 | { |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 1019 | unsigned int i; |
| 1020 | int err; |
| 1021 | |
| 1022 | for (i = 0; i < ARRAY_SIZE(st_controls); ++i) { |
| 1023 | err = snd_ctl_add(chip->card, |
| 1024 | snd_ctl_new1(&st_controls[i], chip)); |
| 1025 | if (err < 0) |
| 1026 | return err; |
| 1027 | } |
Clemens Ladisch | 4852ad0 | 2009-09-28 11:21:21 +0200 | [diff] [blame] | 1028 | err = add_pcm1796_controls(chip); |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 1029 | if (err < 0) |
| 1030 | return err; |
Clemens Ladisch | a361e24 | 2009-09-28 11:19:19 +0200 | [diff] [blame] | 1031 | return 0; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 1034 | static void dump_pcm1796_registers(struct oxygen *chip, |
| 1035 | struct snd_info_buffer *buffer) |
| 1036 | { |
| 1037 | struct xonar_pcm179x *data = chip->model_data; |
| 1038 | unsigned int dac, i; |
| 1039 | |
| 1040 | for (dac = 0; dac < data->dacs; ++dac) { |
| 1041 | snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1); |
| 1042 | for (i = 0; i < 5; ++i) |
| 1043 | snd_iprintf(buffer, " %02x", |
| 1044 | data->pcm1796_regs[dac][i]); |
| 1045 | } |
| 1046 | snd_iprintf(buffer, "\n"); |
| 1047 | } |
| 1048 | |
| 1049 | static void dump_cs2000_registers(struct oxygen *chip, |
| 1050 | struct snd_info_buffer *buffer) |
| 1051 | { |
| 1052 | struct xonar_pcm179x *data = chip->model_data; |
| 1053 | unsigned int i; |
| 1054 | |
| 1055 | if (data->has_cs2000) { |
| 1056 | snd_iprintf(buffer, "\nCS2000:\n00: "); |
| 1057 | for (i = 1; i < 0x10; ++i) |
| 1058 | snd_iprintf(buffer, " %02x", data->cs2000_regs[i]); |
| 1059 | snd_iprintf(buffer, "\n10:"); |
| 1060 | for (i = 0x10; i < 0x1f; ++i) |
| 1061 | snd_iprintf(buffer, " %02x", data->cs2000_regs[i]); |
| 1062 | snd_iprintf(buffer, "\n"); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | static void dump_st_registers(struct oxygen *chip, |
| 1067 | struct snd_info_buffer *buffer) |
| 1068 | { |
| 1069 | dump_pcm1796_registers(chip, buffer); |
| 1070 | dump_cs2000_registers(chip, buffer); |
| 1071 | } |
| 1072 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1073 | static const struct oxygen_model model_xonar_d2 = { |
| 1074 | .longname = "Asus Virtuoso 200", |
| 1075 | .chip = "AV200", |
| 1076 | .init = xonar_d2_init, |
| 1077 | .control_filter = xonar_d2_control_filter, |
| 1078 | .mixer_init = xonar_d2_mixer_init, |
| 1079 | .cleanup = xonar_d2_cleanup, |
| 1080 | .suspend = xonar_d2_suspend, |
| 1081 | .resume = xonar_d2_resume, |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 1082 | .get_i2s_mclk = get_pcm1796_i2s_mclk, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1083 | .set_dac_params = set_pcm1796_params, |
| 1084 | .set_adc_params = xonar_set_cs53x1_params, |
| 1085 | .update_dac_volume = update_pcm1796_volume, |
| 1086 | .update_dac_mute = update_pcm1796_mute, |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 1087 | .dump_registers = dump_pcm1796_registers, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1088 | .dac_tlv = pcm1796_db_scale, |
| 1089 | .model_data_size = sizeof(struct xonar_pcm179x), |
| 1090 | .device_config = PLAYBACK_0_TO_I2S | |
| 1091 | PLAYBACK_1_TO_SPDIF | |
| 1092 | CAPTURE_0_FROM_I2S_2 | |
| 1093 | CAPTURE_1_FROM_SPDIF | |
| 1094 | MIDI_OUTPUT | |
Clemens Ladisch | b6ca8ab | 2010-10-04 13:21:52 +0200 | [diff] [blame] | 1095 | MIDI_INPUT | |
| 1096 | AC97_CD_INPUT, |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame^] | 1097 | .dac_channels_pcm = 8, |
| 1098 | .dac_channels_mixer = 8, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1099 | .dac_volume_min = 255 - 2*60, |
| 1100 | .dac_volume_max = 255, |
| 1101 | .misc_flags = OXYGEN_MISC_MIDI, |
| 1102 | .function_flags = OXYGEN_FUNCTION_SPI | |
| 1103 | OXYGEN_FUNCTION_ENABLE_SPI_4_5, |
| 1104 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 1105 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 1106 | }; |
| 1107 | |
| 1108 | static const struct oxygen_model model_xonar_hdav = { |
| 1109 | .longname = "Asus Virtuoso 200", |
| 1110 | .chip = "AV200", |
| 1111 | .init = xonar_hdav_init, |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 1112 | .mixer_init = xonar_hdav_mixer_init, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1113 | .cleanup = xonar_hdav_cleanup, |
| 1114 | .suspend = xonar_hdav_suspend, |
| 1115 | .resume = xonar_hdav_resume, |
| 1116 | .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter, |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 1117 | .get_i2s_mclk = get_pcm1796_i2s_mclk, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1118 | .set_dac_params = set_hdav_params, |
| 1119 | .set_adc_params = xonar_set_cs53x1_params, |
| 1120 | .update_dac_volume = update_pcm1796_volume, |
| 1121 | .update_dac_mute = update_pcm1796_mute, |
| 1122 | .uart_input = xonar_hdmi_uart_input, |
| 1123 | .ac97_switch = xonar_line_mic_ac97_switch, |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 1124 | .dump_registers = dump_pcm1796_registers, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1125 | .dac_tlv = pcm1796_db_scale, |
| 1126 | .model_data_size = sizeof(struct xonar_hdav), |
| 1127 | .device_config = PLAYBACK_0_TO_I2S | |
| 1128 | PLAYBACK_1_TO_SPDIF | |
| 1129 | CAPTURE_0_FROM_I2S_2 | |
| 1130 | CAPTURE_1_FROM_SPDIF, |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame^] | 1131 | .dac_channels_pcm = 8, |
| 1132 | .dac_channels_mixer = 2, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1133 | .dac_volume_min = 255 - 2*60, |
| 1134 | .dac_volume_max = 255, |
| 1135 | .misc_flags = OXYGEN_MISC_MIDI, |
| 1136 | .function_flags = OXYGEN_FUNCTION_2WIRE, |
| 1137 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 1138 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 1139 | }; |
| 1140 | |
| 1141 | static const struct oxygen_model model_xonar_st = { |
| 1142 | .longname = "Asus Virtuoso 100", |
| 1143 | .chip = "AV200", |
| 1144 | .init = xonar_st_init, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1145 | .mixer_init = xonar_st_mixer_init, |
| 1146 | .cleanup = xonar_st_cleanup, |
| 1147 | .suspend = xonar_st_suspend, |
| 1148 | .resume = xonar_st_resume, |
Clemens Ladisch | 973dca9 | 2009-09-28 11:20:47 +0200 | [diff] [blame] | 1149 | .get_i2s_mclk = get_pcm1796_i2s_mclk, |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 1150 | .set_dac_params = set_st_params, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1151 | .set_adc_params = xonar_set_cs53x1_params, |
| 1152 | .update_dac_volume = update_pcm1796_volume, |
| 1153 | .update_dac_mute = update_pcm1796_mute, |
| 1154 | .ac97_switch = xonar_line_mic_ac97_switch, |
Clemens Ladisch | 9719fca | 2010-12-02 11:41:10 +0100 | [diff] [blame] | 1155 | .dump_registers = dump_st_registers, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1156 | .dac_tlv = pcm1796_db_scale, |
| 1157 | .model_data_size = sizeof(struct xonar_pcm179x), |
| 1158 | .device_config = PLAYBACK_0_TO_I2S | |
| 1159 | PLAYBACK_1_TO_SPDIF | |
Clemens Ladisch | e96f38f | 2010-12-02 11:39:34 +0100 | [diff] [blame] | 1160 | CAPTURE_0_FROM_I2S_2 | |
| 1161 | AC97_FMIC_SWITCH, |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame^] | 1162 | .dac_channels_pcm = 2, |
| 1163 | .dac_channels_mixer = 2, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1164 | .dac_volume_min = 255 - 2*60, |
| 1165 | .dac_volume_max = 255, |
| 1166 | .function_flags = OXYGEN_FUNCTION_2WIRE, |
| 1167 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 1168 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 1169 | }; |
| 1170 | |
| 1171 | int __devinit get_xonar_pcm179x_model(struct oxygen *chip, |
| 1172 | const struct pci_device_id *id) |
| 1173 | { |
| 1174 | switch (id->subdevice) { |
| 1175 | case 0x8269: |
| 1176 | chip->model = model_xonar_d2; |
| 1177 | chip->model.shortname = "Xonar D2"; |
| 1178 | break; |
| 1179 | case 0x82b7: |
| 1180 | chip->model = model_xonar_d2; |
| 1181 | chip->model.shortname = "Xonar D2X"; |
| 1182 | chip->model.init = xonar_d2x_init; |
| 1183 | break; |
| 1184 | case 0x8314: |
| 1185 | chip->model = model_xonar_hdav; |
| 1186 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); |
| 1187 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { |
| 1188 | default: |
| 1189 | chip->model.shortname = "Xonar HDAV1.3"; |
| 1190 | break; |
| 1191 | case GPIO_DB_H6: |
| 1192 | chip->model.shortname = "Xonar HDAV1.3+H6"; |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame^] | 1193 | chip->model.dac_channels_mixer = 8; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1194 | chip->model.private_data = 1; |
| 1195 | break; |
| 1196 | } |
| 1197 | break; |
| 1198 | case 0x835d: |
| 1199 | chip->model = model_xonar_st; |
| 1200 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); |
| 1201 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { |
| 1202 | default: |
| 1203 | chip->model.shortname = "Xonar ST"; |
| 1204 | break; |
| 1205 | case GPIO_DB_H6: |
| 1206 | chip->model.shortname = "Xonar ST+H6"; |
Clemens Ladisch | 1f4d7be | 2011-01-10 15:59:38 +0100 | [diff] [blame^] | 1207 | chip->model.dac_channels_pcm = 8; |
| 1208 | chip->model.dac_channels_mixer = 8; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1209 | chip->model.private_data = 1; |
| 1210 | break; |
| 1211 | } |
| 1212 | break; |
| 1213 | case 0x835c: |
| 1214 | chip->model = model_xonar_st; |
| 1215 | chip->model.shortname = "Xonar STX"; |
| 1216 | chip->model.init = xonar_stx_init; |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame] | 1217 | chip->model.resume = xonar_stx_resume; |
| 1218 | chip->model.set_dac_params = set_pcm1796_params; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1219 | break; |
Clemens Ladisch | 2b830ba | 2010-10-04 13:22:51 +0200 | [diff] [blame] | 1220 | case 0x835e: |
| 1221 | snd_printk(KERN_ERR "the HDAV1.3 Slim is not supported\n"); |
| 1222 | return -ENODEV; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 1223 | default: |
| 1224 | return -EINVAL; |
| 1225 | } |
| 1226 | return 0; |
| 1227 | } |