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