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 |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Xonar HDAV1.3 (Deluxe) |
| 39 | * ---------------------- |
| 40 | * |
| 41 | * CMI8788: |
| 42 | * |
| 43 | * I²C <-> PCM1796 (front) |
| 44 | * |
| 45 | * GPI 0 <- external power present |
| 46 | * |
| 47 | * GPIO 0 -> enable output to speakers |
| 48 | * GPIO 2 -> M0 of CS5381 |
| 49 | * GPIO 3 -> M1 of CS5381 |
| 50 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) |
| 51 | * |
| 52 | * TXD -> HDMI controller |
| 53 | * RXD <- HDMI controller |
| 54 | * |
| 55 | * PCM1796 front: AD1,0 <- 0,0 |
| 56 | * |
| 57 | * no daughterboard |
| 58 | * ---------------- |
| 59 | * |
| 60 | * GPIO 4 <- 1 |
| 61 | * |
| 62 | * H6 daughterboard |
| 63 | * ---------------- |
| 64 | * |
| 65 | * GPIO 4 <- 0 |
| 66 | * GPIO 5 <- 0 |
| 67 | * |
| 68 | * I²C <-> PCM1796 (surround) |
| 69 | * <-> PCM1796 (center/LFE) |
| 70 | * <-> PCM1796 (back) |
| 71 | * |
| 72 | * PCM1796 surround: AD1,0 <- 0,1 |
| 73 | * PCM1796 center/LFE: AD1,0 <- 1,0 |
| 74 | * PCM1796 back: AD1,0 <- 1,1 |
| 75 | * |
| 76 | * unknown daughterboard |
| 77 | * --------------------- |
| 78 | * |
| 79 | * GPIO 4 <- 0 |
| 80 | * GPIO 5 <- 1 |
| 81 | * |
| 82 | * I²C <-> CS4362A (surround, center/LFE, back) |
| 83 | * |
| 84 | * CS4362A: AD0 <- 0 |
| 85 | */ |
| 86 | |
| 87 | /* |
| 88 | * Xonar Essence ST (Deluxe)/STX |
| 89 | * ----------------------------- |
| 90 | * |
| 91 | * CMI8788: |
| 92 | * |
| 93 | * I²C <-> PCM1792A |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 94 | * <-> CS2000 (ST only) |
| 95 | * |
| 96 | * ADC1 MCLK -> REF_CLK of CS2000 (ST only) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 97 | * |
| 98 | * GPI 0 <- external power present (STX only) |
| 99 | * |
| 100 | * GPIO 0 -> enable output to speakers |
| 101 | * GPIO 1 -> route HP to front panel (0) or rear jack (1) |
| 102 | * GPIO 2 -> M0 of CS5381 |
| 103 | * GPIO 3 -> M1 of CS5381 |
| 104 | * GPIO 7 -> route output to speaker jacks (0) or HP (1) |
| 105 | * GPIO 8 -> route input jack to line-in (0) or mic-in (1) |
| 106 | * |
| 107 | * PCM1792A: |
| 108 | * |
| 109 | * AD1,0 <- 0,0 |
| 110 | * |
| 111 | * H6 daughterboard |
| 112 | * ---------------- |
| 113 | * |
| 114 | * GPIO 4 <- 0 |
| 115 | * GPIO 5 <- 0 |
| 116 | */ |
| 117 | |
| 118 | #include <linux/pci.h> |
| 119 | #include <linux/delay.h> |
| 120 | #include <linux/mutex.h> |
| 121 | #include <sound/ac97_codec.h> |
| 122 | #include <sound/control.h> |
| 123 | #include <sound/core.h> |
| 124 | #include <sound/pcm.h> |
| 125 | #include <sound/pcm_params.h> |
| 126 | #include <sound/tlv.h> |
| 127 | #include "xonar.h" |
| 128 | #include "cm9780.h" |
| 129 | #include "pcm1796.h" |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 130 | #include "cs2000.h" |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 131 | |
| 132 | |
| 133 | #define GPIO_D2X_EXT_POWER 0x0020 |
| 134 | #define GPIO_D2_ALT 0x0080 |
| 135 | #define GPIO_D2_OUTPUT_ENABLE 0x0100 |
| 136 | |
| 137 | #define GPI_EXT_POWER 0x01 |
| 138 | #define GPIO_INPUT_ROUTE 0x0100 |
| 139 | |
| 140 | #define GPIO_HDAV_OUTPUT_ENABLE 0x0001 |
| 141 | |
| 142 | #define GPIO_DB_MASK 0x0030 |
| 143 | #define GPIO_DB_H6 0x0000 |
| 144 | |
| 145 | #define GPIO_ST_OUTPUT_ENABLE 0x0001 |
| 146 | #define GPIO_ST_HP_REAR 0x0002 |
| 147 | #define GPIO_ST_HP 0x0080 |
| 148 | |
| 149 | #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */ |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 150 | #define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */ |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 151 | |
| 152 | |
| 153 | struct xonar_pcm179x { |
| 154 | struct xonar_generic generic; |
| 155 | unsigned int dacs; |
| 156 | u8 oversampling; |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 157 | u8 cs2000_fun_cfg_1; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct xonar_hdav { |
| 161 | struct xonar_pcm179x pcm179x; |
| 162 | struct xonar_hdmi hdmi; |
| 163 | }; |
| 164 | |
| 165 | |
| 166 | static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec, |
| 167 | u8 reg, u8 value) |
| 168 | { |
| 169 | /* maps ALSA channel pair number to SPI output */ |
| 170 | static const u8 codec_map[4] = { |
| 171 | 0, 1, 2, 4 |
| 172 | }; |
| 173 | oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER | |
| 174 | OXYGEN_SPI_DATA_LENGTH_2 | |
| 175 | OXYGEN_SPI_CLOCK_160 | |
| 176 | (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) | |
| 177 | OXYGEN_SPI_CEN_LATCH_CLOCK_HI, |
| 178 | (reg << 8) | value); |
| 179 | } |
| 180 | |
| 181 | static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec, |
| 182 | u8 reg, u8 value) |
| 183 | { |
| 184 | oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value); |
| 185 | } |
| 186 | |
| 187 | static void pcm1796_write(struct oxygen *chip, unsigned int codec, |
| 188 | u8 reg, u8 value) |
| 189 | { |
| 190 | if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) == |
| 191 | OXYGEN_FUNCTION_SPI) |
| 192 | pcm1796_write_spi(chip, codec, reg, value); |
| 193 | else |
| 194 | pcm1796_write_i2c(chip, codec, reg, value); |
| 195 | } |
| 196 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 197 | static void cs2000_write(struct oxygen *chip, u8 reg, u8 value) |
| 198 | { |
| 199 | oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value); |
| 200 | } |
| 201 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 202 | static void update_pcm1796_volume(struct oxygen *chip) |
| 203 | { |
| 204 | struct xonar_pcm179x *data = chip->model_data; |
| 205 | unsigned int i; |
| 206 | |
| 207 | for (i = 0; i < data->dacs; ++i) { |
| 208 | pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]); |
| 209 | pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | static void update_pcm1796_mute(struct oxygen *chip) |
| 214 | { |
| 215 | struct xonar_pcm179x *data = chip->model_data; |
| 216 | unsigned int i; |
| 217 | u8 value; |
| 218 | |
| 219 | value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; |
| 220 | if (chip->dac_mute) |
| 221 | value |= PCM1796_MUTE; |
| 222 | for (i = 0; i < data->dacs; ++i) |
| 223 | pcm1796_write(chip, i, 18, value); |
| 224 | } |
| 225 | |
| 226 | static void pcm1796_init(struct oxygen *chip) |
| 227 | { |
| 228 | struct xonar_pcm179x *data = chip->model_data; |
| 229 | unsigned int i; |
| 230 | |
| 231 | for (i = 0; i < data->dacs; ++i) { |
| 232 | pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); |
| 233 | pcm1796_write(chip, i, 20, data->oversampling); |
| 234 | pcm1796_write(chip, i, 21, 0); |
| 235 | } |
| 236 | update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */ |
| 237 | update_pcm1796_volume(chip); |
| 238 | } |
| 239 | |
| 240 | static void xonar_d2_init(struct oxygen *chip) |
| 241 | { |
| 242 | struct xonar_pcm179x *data = chip->model_data; |
| 243 | |
| 244 | data->generic.anti_pop_delay = 300; |
| 245 | data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE; |
| 246 | data->dacs = 4; |
| 247 | data->oversampling = PCM1796_OS_64; |
| 248 | |
| 249 | pcm1796_init(chip); |
| 250 | |
| 251 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT); |
| 252 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT); |
| 253 | |
| 254 | oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC); |
| 255 | |
| 256 | xonar_init_cs53x1(chip); |
| 257 | xonar_enable_output(chip); |
| 258 | |
| 259 | snd_component_add(chip->card, "PCM1796"); |
| 260 | snd_component_add(chip->card, "CS5381"); |
| 261 | } |
| 262 | |
| 263 | static void xonar_d2x_init(struct oxygen *chip) |
| 264 | { |
| 265 | struct xonar_pcm179x *data = chip->model_data; |
| 266 | |
| 267 | data->generic.ext_power_reg = OXYGEN_GPIO_DATA; |
| 268 | data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK; |
| 269 | data->generic.ext_power_bit = GPIO_D2X_EXT_POWER; |
| 270 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER); |
| 271 | xonar_init_ext_power(chip); |
| 272 | xonar_d2_init(chip); |
| 273 | } |
| 274 | |
| 275 | static void xonar_hdav_init(struct oxygen *chip) |
| 276 | { |
| 277 | struct xonar_hdav *data = chip->model_data; |
| 278 | |
| 279 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, |
| 280 | OXYGEN_2WIRE_LENGTH_8 | |
| 281 | OXYGEN_2WIRE_INTERRUPT_MASK | |
| 282 | OXYGEN_2WIRE_SPEED_FAST); |
| 283 | |
| 284 | data->pcm179x.generic.anti_pop_delay = 100; |
| 285 | data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE; |
| 286 | data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA; |
| 287 | data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; |
| 288 | data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER; |
| 289 | data->pcm179x.dacs = chip->model.private_data ? 4 : 1; |
| 290 | data->pcm179x.oversampling = PCM1796_OS_64; |
| 291 | |
| 292 | pcm1796_init(chip); |
| 293 | |
| 294 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_INPUT_ROUTE); |
| 295 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE); |
| 296 | |
| 297 | xonar_init_cs53x1(chip); |
| 298 | xonar_init_ext_power(chip); |
| 299 | xonar_hdmi_init(chip, &data->hdmi); |
| 300 | xonar_enable_output(chip); |
| 301 | |
| 302 | snd_component_add(chip->card, "PCM1796"); |
| 303 | snd_component_add(chip->card, "CS5381"); |
| 304 | } |
| 305 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 306 | static void xonar_st_init_i2c(struct oxygen *chip) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 307 | { |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 308 | oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, |
| 309 | OXYGEN_2WIRE_LENGTH_8 | |
| 310 | OXYGEN_2WIRE_INTERRUPT_MASK | |
| 311 | OXYGEN_2WIRE_SPEED_FAST); |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 312 | } |
| 313 | |
| 314 | static void xonar_st_init_common(struct oxygen *chip) |
| 315 | { |
| 316 | struct xonar_pcm179x *data = chip->model_data; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 317 | |
| 318 | data->generic.anti_pop_delay = 100; |
| 319 | data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE; |
| 320 | data->dacs = chip->model.private_data ? 4 : 1; |
| 321 | data->oversampling = PCM1796_OS_64; |
| 322 | |
| 323 | pcm1796_init(chip); |
| 324 | |
| 325 | oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, |
| 326 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); |
| 327 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, |
| 328 | GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP); |
| 329 | |
| 330 | xonar_init_cs53x1(chip); |
| 331 | xonar_enable_output(chip); |
| 332 | |
| 333 | snd_component_add(chip->card, "PCM1792A"); |
| 334 | snd_component_add(chip->card, "CS5381"); |
| 335 | } |
| 336 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 337 | static void cs2000_registers_init(struct oxygen *chip) |
| 338 | { |
| 339 | struct xonar_pcm179x *data = chip->model_data; |
| 340 | |
| 341 | cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE); |
| 342 | cs2000_write(chip, CS2000_DEV_CTRL, 0); |
| 343 | cs2000_write(chip, CS2000_DEV_CFG_1, |
| 344 | CS2000_R_MOD_SEL_1 | |
| 345 | (0 << CS2000_R_SEL_SHIFT) | |
| 346 | CS2000_AUX_OUT_SRC_REF_CLK | |
| 347 | CS2000_EN_DEV_CFG_1); |
| 348 | cs2000_write(chip, CS2000_DEV_CFG_2, |
| 349 | (0 << CS2000_LOCK_CLK_SHIFT) | |
| 350 | CS2000_FRAC_N_SRC_STATIC); |
| 351 | cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */ |
| 352 | cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10); |
| 353 | cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00); |
| 354 | cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00); |
| 355 | cs2000_write(chip, CS2000_FUN_CFG_1, data->cs2000_fun_cfg_1); |
| 356 | cs2000_write(chip, CS2000_FUN_CFG_2, 0); |
| 357 | cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2); |
| 358 | } |
| 359 | |
| 360 | static void xonar_st_init(struct oxygen *chip) |
| 361 | { |
| 362 | struct xonar_pcm179x *data = chip->model_data; |
| 363 | |
| 364 | data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_1; |
| 365 | |
| 366 | oxygen_write16(chip, OXYGEN_I2S_A_FORMAT, |
| 367 | OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_I2S | |
| 368 | OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | |
| 369 | OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); |
| 370 | |
| 371 | xonar_st_init_i2c(chip); |
| 372 | cs2000_registers_init(chip); |
| 373 | xonar_st_init_common(chip); |
| 374 | |
| 375 | snd_component_add(chip->card, "CS2000"); |
| 376 | } |
| 377 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 378 | static void xonar_stx_init(struct oxygen *chip) |
| 379 | { |
| 380 | struct xonar_pcm179x *data = chip->model_data; |
| 381 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 382 | xonar_st_init_i2c(chip); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 383 | data->generic.ext_power_reg = OXYGEN_GPI_DATA; |
| 384 | data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; |
| 385 | data->generic.ext_power_bit = GPI_EXT_POWER; |
| 386 | xonar_init_ext_power(chip); |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 387 | xonar_st_init_common(chip); |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | static void xonar_d2_cleanup(struct oxygen *chip) |
| 391 | { |
| 392 | xonar_disable_output(chip); |
| 393 | } |
| 394 | |
| 395 | static void xonar_hdav_cleanup(struct oxygen *chip) |
| 396 | { |
| 397 | xonar_hdmi_cleanup(chip); |
| 398 | xonar_disable_output(chip); |
| 399 | msleep(2); |
| 400 | } |
| 401 | |
| 402 | static void xonar_st_cleanup(struct oxygen *chip) |
| 403 | { |
| 404 | xonar_disable_output(chip); |
| 405 | } |
| 406 | |
| 407 | static void xonar_d2_suspend(struct oxygen *chip) |
| 408 | { |
| 409 | xonar_d2_cleanup(chip); |
| 410 | } |
| 411 | |
| 412 | static void xonar_hdav_suspend(struct oxygen *chip) |
| 413 | { |
| 414 | xonar_hdav_cleanup(chip); |
| 415 | } |
| 416 | |
| 417 | static void xonar_st_suspend(struct oxygen *chip) |
| 418 | { |
| 419 | xonar_st_cleanup(chip); |
| 420 | } |
| 421 | |
| 422 | static void xonar_d2_resume(struct oxygen *chip) |
| 423 | { |
| 424 | pcm1796_init(chip); |
| 425 | xonar_enable_output(chip); |
| 426 | } |
| 427 | |
| 428 | static void xonar_hdav_resume(struct oxygen *chip) |
| 429 | { |
| 430 | struct xonar_hdav *data = chip->model_data; |
| 431 | |
| 432 | pcm1796_init(chip); |
| 433 | xonar_hdmi_resume(chip, &data->hdmi); |
| 434 | xonar_enable_output(chip); |
| 435 | } |
| 436 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 437 | static void xonar_stx_resume(struct oxygen *chip) |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 438 | { |
| 439 | pcm1796_init(chip); |
| 440 | xonar_enable_output(chip); |
| 441 | } |
| 442 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 443 | static void xonar_st_resume(struct oxygen *chip) |
| 444 | { |
| 445 | cs2000_registers_init(chip); |
| 446 | xonar_stx_resume(chip); |
| 447 | } |
| 448 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 449 | static void set_pcm1796_params(struct oxygen *chip, |
| 450 | struct snd_pcm_hw_params *params) |
| 451 | { |
| 452 | struct xonar_pcm179x *data = chip->model_data; |
| 453 | unsigned int i; |
| 454 | |
| 455 | data->oversampling = |
| 456 | params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; |
| 457 | for (i = 0; i < data->dacs; ++i) |
| 458 | pcm1796_write(chip, i, 20, data->oversampling); |
| 459 | } |
| 460 | |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 461 | static void set_cs2000_params(struct oxygen *chip, |
| 462 | struct snd_pcm_hw_params *params) |
| 463 | { |
| 464 | /* XXX Why is the I2S A MCLK half the actual I2S multich MCLK? */ |
| 465 | static const u8 rate_mclks[] = { |
| 466 | [OXYGEN_RATE_32000] = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_128, |
| 467 | [OXYGEN_RATE_44100] = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_128, |
| 468 | [OXYGEN_RATE_48000] = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_128, |
| 469 | [OXYGEN_RATE_64000] = OXYGEN_RATE_32000 | OXYGEN_I2S_MCLK_256, |
| 470 | [OXYGEN_RATE_88200] = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256, |
| 471 | [OXYGEN_RATE_96000] = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256, |
| 472 | [OXYGEN_RATE_176400] = OXYGEN_RATE_44100 | OXYGEN_I2S_MCLK_256, |
| 473 | [OXYGEN_RATE_192000] = OXYGEN_RATE_48000 | OXYGEN_I2S_MCLK_256, |
| 474 | }; |
| 475 | struct xonar_pcm179x *data = chip->model_data; |
| 476 | unsigned int rate_index; |
| 477 | u8 rate_mclk; |
| 478 | |
| 479 | rate_index = oxygen_read16(chip, OXYGEN_I2S_MULTICH_FORMAT) |
| 480 | & OXYGEN_I2S_RATE_MASK; |
| 481 | rate_mclk = rate_mclks[rate_index]; |
| 482 | oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk, |
| 483 | OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK); |
| 484 | if ((rate_mclk & OXYGEN_I2S_MCLK_MASK) <= OXYGEN_I2S_MCLK_128) |
| 485 | data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_1; |
| 486 | else |
| 487 | data->cs2000_fun_cfg_1 = CS2000_REF_CLK_DIV_2; |
| 488 | cs2000_write(chip, CS2000_FUN_CFG_1, data->cs2000_fun_cfg_1); |
| 489 | } |
| 490 | |
| 491 | static void set_st_params(struct oxygen *chip, |
| 492 | struct snd_pcm_hw_params *params) |
| 493 | { |
| 494 | set_cs2000_params(chip, params); |
| 495 | set_pcm1796_params(chip, params); |
| 496 | } |
| 497 | |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 498 | static void set_hdav_params(struct oxygen *chip, |
| 499 | struct snd_pcm_hw_params *params) |
| 500 | { |
| 501 | struct xonar_hdav *data = chip->model_data; |
| 502 | |
| 503 | set_pcm1796_params(chip, params); |
| 504 | xonar_set_hdmi_params(chip, &data->hdmi, params); |
| 505 | } |
| 506 | |
| 507 | static const struct snd_kcontrol_new alt_switch = { |
| 508 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 509 | .name = "Analog Loopback Switch", |
| 510 | .info = snd_ctl_boolean_mono_info, |
| 511 | .get = xonar_gpio_bit_switch_get, |
| 512 | .put = xonar_gpio_bit_switch_put, |
| 513 | .private_value = GPIO_D2_ALT, |
| 514 | }; |
| 515 | |
| 516 | static int st_output_switch_info(struct snd_kcontrol *ctl, |
| 517 | struct snd_ctl_elem_info *info) |
| 518 | { |
| 519 | static const char *const names[3] = { |
| 520 | "Speakers", "Headphones", "FP Headphones" |
| 521 | }; |
| 522 | |
| 523 | info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 524 | info->count = 1; |
| 525 | info->value.enumerated.items = 3; |
| 526 | if (info->value.enumerated.item >= 3) |
| 527 | info->value.enumerated.item = 2; |
| 528 | strcpy(info->value.enumerated.name, names[info->value.enumerated.item]); |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static int st_output_switch_get(struct snd_kcontrol *ctl, |
| 533 | struct snd_ctl_elem_value *value) |
| 534 | { |
| 535 | struct oxygen *chip = ctl->private_data; |
| 536 | u16 gpio; |
| 537 | |
| 538 | gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA); |
| 539 | if (!(gpio & GPIO_ST_HP)) |
| 540 | value->value.enumerated.item[0] = 0; |
| 541 | else if (gpio & GPIO_ST_HP_REAR) |
| 542 | value->value.enumerated.item[0] = 1; |
| 543 | else |
| 544 | value->value.enumerated.item[0] = 2; |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | |
| 549 | static int st_output_switch_put(struct snd_kcontrol *ctl, |
| 550 | struct snd_ctl_elem_value *value) |
| 551 | { |
| 552 | struct oxygen *chip = ctl->private_data; |
| 553 | u16 gpio_old, gpio; |
| 554 | |
| 555 | mutex_lock(&chip->mutex); |
| 556 | gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA); |
| 557 | gpio = gpio_old; |
| 558 | switch (value->value.enumerated.item[0]) { |
| 559 | case 0: |
| 560 | gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR); |
| 561 | break; |
| 562 | case 1: |
| 563 | gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR; |
| 564 | break; |
| 565 | case 2: |
| 566 | gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR; |
| 567 | break; |
| 568 | } |
| 569 | oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio); |
| 570 | mutex_unlock(&chip->mutex); |
| 571 | return gpio != gpio_old; |
| 572 | } |
| 573 | |
| 574 | static const struct snd_kcontrol_new st_output_switch = { |
| 575 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 576 | .name = "Analog Output", |
| 577 | .info = st_output_switch_info, |
| 578 | .get = st_output_switch_get, |
| 579 | .put = st_output_switch_put, |
| 580 | }; |
| 581 | |
| 582 | static void xonar_line_mic_ac97_switch(struct oxygen *chip, |
| 583 | unsigned int reg, unsigned int mute) |
| 584 | { |
| 585 | if (reg == AC97_LINE) { |
| 586 | spin_lock_irq(&chip->reg_lock); |
| 587 | oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, |
| 588 | mute ? GPIO_INPUT_ROUTE : 0, |
| 589 | GPIO_INPUT_ROUTE); |
| 590 | spin_unlock_irq(&chip->reg_lock); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0); |
| 595 | |
| 596 | static int xonar_d2_control_filter(struct snd_kcontrol_new *template) |
| 597 | { |
| 598 | if (!strncmp(template->name, "CD Capture ", 11)) |
| 599 | /* CD in is actually connected to the video in pin */ |
| 600 | template->private_value ^= AC97_CD ^ AC97_VIDEO; |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | static int xonar_st_control_filter(struct snd_kcontrol_new *template) |
| 605 | { |
| 606 | if (!strncmp(template->name, "CD Capture ", 11)) |
| 607 | return 1; /* no CD input */ |
| 608 | if (!strcmp(template->name, "Stereo Upmixing")) |
| 609 | return 1; /* stereo only - we don't need upmixing */ |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | static int xonar_d2_mixer_init(struct oxygen *chip) |
| 614 | { |
| 615 | return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); |
| 616 | } |
| 617 | |
| 618 | static int xonar_st_mixer_init(struct oxygen *chip) |
| 619 | { |
| 620 | return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip)); |
| 621 | } |
| 622 | |
| 623 | static const struct oxygen_model model_xonar_d2 = { |
| 624 | .longname = "Asus Virtuoso 200", |
| 625 | .chip = "AV200", |
| 626 | .init = xonar_d2_init, |
| 627 | .control_filter = xonar_d2_control_filter, |
| 628 | .mixer_init = xonar_d2_mixer_init, |
| 629 | .cleanup = xonar_d2_cleanup, |
| 630 | .suspend = xonar_d2_suspend, |
| 631 | .resume = xonar_d2_resume, |
| 632 | .set_dac_params = set_pcm1796_params, |
| 633 | .set_adc_params = xonar_set_cs53x1_params, |
| 634 | .update_dac_volume = update_pcm1796_volume, |
| 635 | .update_dac_mute = update_pcm1796_mute, |
| 636 | .dac_tlv = pcm1796_db_scale, |
| 637 | .model_data_size = sizeof(struct xonar_pcm179x), |
| 638 | .device_config = PLAYBACK_0_TO_I2S | |
| 639 | PLAYBACK_1_TO_SPDIF | |
| 640 | CAPTURE_0_FROM_I2S_2 | |
| 641 | CAPTURE_1_FROM_SPDIF | |
| 642 | MIDI_OUTPUT | |
| 643 | MIDI_INPUT, |
| 644 | .dac_channels = 8, |
| 645 | .dac_volume_min = 255 - 2*60, |
| 646 | .dac_volume_max = 255, |
| 647 | .misc_flags = OXYGEN_MISC_MIDI, |
| 648 | .function_flags = OXYGEN_FUNCTION_SPI | |
| 649 | OXYGEN_FUNCTION_ENABLE_SPI_4_5, |
| 650 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 651 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 652 | }; |
| 653 | |
| 654 | static const struct oxygen_model model_xonar_hdav = { |
| 655 | .longname = "Asus Virtuoso 200", |
| 656 | .chip = "AV200", |
| 657 | .init = xonar_hdav_init, |
| 658 | .cleanup = xonar_hdav_cleanup, |
| 659 | .suspend = xonar_hdav_suspend, |
| 660 | .resume = xonar_hdav_resume, |
| 661 | .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter, |
| 662 | .set_dac_params = set_hdav_params, |
| 663 | .set_adc_params = xonar_set_cs53x1_params, |
| 664 | .update_dac_volume = update_pcm1796_volume, |
| 665 | .update_dac_mute = update_pcm1796_mute, |
| 666 | .uart_input = xonar_hdmi_uart_input, |
| 667 | .ac97_switch = xonar_line_mic_ac97_switch, |
| 668 | .dac_tlv = pcm1796_db_scale, |
| 669 | .model_data_size = sizeof(struct xonar_hdav), |
| 670 | .device_config = PLAYBACK_0_TO_I2S | |
| 671 | PLAYBACK_1_TO_SPDIF | |
| 672 | CAPTURE_0_FROM_I2S_2 | |
| 673 | CAPTURE_1_FROM_SPDIF, |
| 674 | .dac_channels = 8, |
| 675 | .dac_volume_min = 255 - 2*60, |
| 676 | .dac_volume_max = 255, |
| 677 | .misc_flags = OXYGEN_MISC_MIDI, |
| 678 | .function_flags = OXYGEN_FUNCTION_2WIRE, |
| 679 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 680 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 681 | }; |
| 682 | |
| 683 | static const struct oxygen_model model_xonar_st = { |
| 684 | .longname = "Asus Virtuoso 100", |
| 685 | .chip = "AV200", |
| 686 | .init = xonar_st_init, |
| 687 | .control_filter = xonar_st_control_filter, |
| 688 | .mixer_init = xonar_st_mixer_init, |
| 689 | .cleanup = xonar_st_cleanup, |
| 690 | .suspend = xonar_st_suspend, |
| 691 | .resume = xonar_st_resume, |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 692 | .set_dac_params = set_st_params, |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 693 | .set_adc_params = xonar_set_cs53x1_params, |
| 694 | .update_dac_volume = update_pcm1796_volume, |
| 695 | .update_dac_mute = update_pcm1796_mute, |
| 696 | .ac97_switch = xonar_line_mic_ac97_switch, |
| 697 | .dac_tlv = pcm1796_db_scale, |
| 698 | .model_data_size = sizeof(struct xonar_pcm179x), |
| 699 | .device_config = PLAYBACK_0_TO_I2S | |
| 700 | PLAYBACK_1_TO_SPDIF | |
| 701 | CAPTURE_0_FROM_I2S_2, |
| 702 | .dac_channels = 2, |
| 703 | .dac_volume_min = 255 - 2*60, |
| 704 | .dac_volume_max = 255, |
| 705 | .function_flags = OXYGEN_FUNCTION_2WIRE, |
| 706 | .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 707 | .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, |
| 708 | }; |
| 709 | |
| 710 | int __devinit get_xonar_pcm179x_model(struct oxygen *chip, |
| 711 | const struct pci_device_id *id) |
| 712 | { |
| 713 | switch (id->subdevice) { |
| 714 | case 0x8269: |
| 715 | chip->model = model_xonar_d2; |
| 716 | chip->model.shortname = "Xonar D2"; |
| 717 | break; |
| 718 | case 0x82b7: |
| 719 | chip->model = model_xonar_d2; |
| 720 | chip->model.shortname = "Xonar D2X"; |
| 721 | chip->model.init = xonar_d2x_init; |
| 722 | break; |
| 723 | case 0x8314: |
| 724 | chip->model = model_xonar_hdav; |
| 725 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); |
| 726 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { |
| 727 | default: |
| 728 | chip->model.shortname = "Xonar HDAV1.3"; |
| 729 | break; |
| 730 | case GPIO_DB_H6: |
| 731 | chip->model.shortname = "Xonar HDAV1.3+H6"; |
| 732 | chip->model.private_data = 1; |
| 733 | break; |
| 734 | } |
| 735 | break; |
| 736 | case 0x835d: |
| 737 | chip->model = model_xonar_st; |
| 738 | oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK); |
| 739 | switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) { |
| 740 | default: |
| 741 | chip->model.shortname = "Xonar ST"; |
| 742 | break; |
| 743 | case GPIO_DB_H6: |
| 744 | chip->model.shortname = "Xonar ST+H6"; |
| 745 | chip->model.dac_channels = 8; |
| 746 | chip->model.private_data = 1; |
| 747 | break; |
| 748 | } |
| 749 | break; |
| 750 | case 0x835c: |
| 751 | chip->model = model_xonar_st; |
| 752 | chip->model.shortname = "Xonar STX"; |
| 753 | chip->model.init = xonar_stx_init; |
Clemens Ladisch | 268304f | 2009-09-28 11:15:01 +0200 | [diff] [blame^] | 754 | chip->model.resume = xonar_stx_resume; |
| 755 | chip->model.set_dac_params = set_pcm1796_params; |
Clemens Ladisch | 65c3ac8 | 2009-09-28 11:11:27 +0200 | [diff] [blame] | 756 | break; |
| 757 | default: |
| 758 | return -EINVAL; |
| 759 | } |
| 760 | return 0; |
| 761 | } |