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