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