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