2 * C-Media CMI8788 driver for Asus Xonar cards
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this driver; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * SPI 0 -> 1st PCM1796 (front)
27 * SPI 1 -> 2nd PCM1796 (surround)
28 * SPI 2 -> 3rd PCM1796 (center/LFE)
29 * SPI 4 -> 4th PCM1796 (back)
31 * GPIO 2 -> M0 of CS5381
32 * GPIO 3 -> M1 of CS5381
33 * GPIO 5 <- external power present (D2X only)
35 * GPIO 8 -> enable output to speakers
44 * I²C <-> CS4398 (front)
45 * <-> CS4362A (surround, center/LFE, back)
47 * GPI 0 <- external power present (DX only)
49 * GPIO 0 -> enable output to speakers
50 * GPIO 1 -> enable front panel I/O
51 * GPIO 2 -> M0 of CS5361
52 * GPIO 3 -> M1 of CS5361
53 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
66 * Xonar HDAV1.3 (Deluxe)
67 * ----------------------
71 * I²C <-> PCM1796 (front)
73 * GPI 0 <- external power present
75 * GPIO 0 -> enable output to speakers
76 * GPIO 2 -> M0 of CS5381
77 * GPIO 3 -> M1 of CS5381
78 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
80 * TXD -> HDMI controller
81 * RXD <- HDMI controller
83 * PCM1796 front: AD1,0 <- 0,0
96 * I²C <-> PCM1796 (surround)
97 * <-> PCM1796 (center/LFE)
100 * PCM1796 surround: AD1,0 <- 0,1
101 * PCM1796 center/LFE: AD1,0 <- 1,0
102 * PCM1796 back: AD1,0 <- 1,1
104 * unknown daughterboard
105 * ---------------------
110 * I²C <-> CS4362A (surround, center/LFE, back)
116 * Xonar Essence ST (Deluxe)/STX
117 * -----------------------------
123 * GPI 0 <- external power present
125 * GPIO 0 -> enable output to speakers
126 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
127 * GPIO 2 -> M0 of CS5381
128 * GPIO 3 -> M1 of CS5381
129 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
130 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
143 #include <linux/pci.h>
144 #include <linux/delay.h>
145 #include <linux/mutex.h>
146 #include <sound/ac97_codec.h>
147 #include <sound/asoundef.h>
148 #include <sound/control.h>
149 #include <sound/core.h>
150 #include <sound/initval.h>
151 #include <sound/pcm.h>
152 #include <sound/pcm_params.h>
153 #include <sound/tlv.h>
160 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
161 MODULE_DESCRIPTION("Asus AVx00 driver");
162 MODULE_LICENSE("GPL v2");
163 MODULE_SUPPORTED_DEVICE("{{Asus,AV100},{Asus,AV200}}");
165 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
166 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
167 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
169 module_param_array(index, int, NULL, 0444);
170 MODULE_PARM_DESC(index, "card index");
171 module_param_array(id, charp, NULL, 0444);
172 MODULE_PARM_DESC(id, "ID string");
173 module_param_array(enable, bool, NULL, 0444);
174 MODULE_PARM_DESC(enable, "enable card");
181 MODEL_HDAV, /* without daughterboard */
182 MODEL_HDAV_H6, /* with H6 daughterboard */
188 static struct pci_device_id xonar_ids[] __devinitdata = {
189 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
190 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
191 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
192 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV },
193 { OXYGEN_PCI_SUBID(0x1043, 0x8327), .driver_data = MODEL_DX },
194 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 },
195 { OXYGEN_PCI_SUBID(0x1043, 0x835c), .driver_data = MODEL_STX },
196 { OXYGEN_PCI_SUBID(0x1043, 0x835d), .driver_data = MODEL_ST },
197 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
200 MODULE_DEVICE_TABLE(pci, xonar_ids);
203 #define GPIO_CS53x1_M_MASK 0x000c
204 #define GPIO_CS53x1_M_SINGLE 0x0000
205 #define GPIO_CS53x1_M_DOUBLE 0x0004
206 #define GPIO_CS53x1_M_QUAD 0x0008
208 #define GPIO_D2X_EXT_POWER 0x0020
209 #define GPIO_D2_ALT 0x0080
210 #define GPIO_D2_OUTPUT_ENABLE 0x0100
212 #define GPI_DX_EXT_POWER 0x01
213 #define GPIO_DX_OUTPUT_ENABLE 0x0001
214 #define GPIO_DX_FRONT_PANEL 0x0002
215 #define GPIO_DX_INPUT_ROUTE 0x0100
217 #define GPIO_DB_MASK 0x0030
218 #define GPIO_DB_H6 0x0000
219 #define GPIO_DB_XX 0x0020
221 #define GPIO_ST_HP_REAR 0x0002
222 #define GPIO_ST_HP 0x0080
224 #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */
225 #define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
226 #define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
229 unsigned int anti_pop_delay;
231 u16 output_enable_bit;
233 u8 ext_power_int_reg;
236 u8 pcm1796_oversampling;
242 static void xonar_gpio_changed(struct oxygen *chip);
244 static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
247 /* maps ALSA channel pair number to SPI output */
248 static const u8 codec_map[4] = {
251 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
252 OXYGEN_SPI_DATA_LENGTH_2 |
253 OXYGEN_SPI_CLOCK_160 |
254 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
255 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
259 static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
262 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
265 static void pcm1796_write(struct oxygen *chip, unsigned int codec,
268 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
270 pcm1796_write_spi(chip, codec, reg, value);
272 pcm1796_write_i2c(chip, codec, reg, value);
275 static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
277 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
280 static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
282 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
285 static void hdmi_write_command(struct oxygen *chip, u8 command,
286 unsigned int count, const u8 *params)
291 oxygen_write_uart(chip, 0xfb);
292 oxygen_write_uart(chip, 0xef);
293 oxygen_write_uart(chip, command);
294 oxygen_write_uart(chip, count);
295 for (i = 0; i < count; ++i)
296 oxygen_write_uart(chip, params[i]);
297 checksum = 0xfb + 0xef + command + count;
298 for (i = 0; i < count; ++i)
299 checksum += params[i];
300 oxygen_write_uart(chip, checksum);
303 static void xonar_enable_output(struct oxygen *chip)
305 struct xonar_data *data = chip->model_data;
307 msleep(data->anti_pop_delay);
308 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
311 static void xonar_common_init(struct oxygen *chip)
313 struct xonar_data *data = chip->model_data;
315 if (data->ext_power_reg) {
316 oxygen_set_bits8(chip, data->ext_power_int_reg,
317 data->ext_power_bit);
318 chip->interrupt_mask |= OXYGEN_INT_GPIO;
319 chip->model.gpio_changed = xonar_gpio_changed;
320 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
321 & data->ext_power_bit);
323 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
324 GPIO_CS53x1_M_MASK | data->output_enable_bit);
325 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
326 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
327 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
328 xonar_enable_output(chip);
331 static void update_pcm1796_volume(struct oxygen *chip)
333 struct xonar_data *data = chip->model_data;
336 for (i = 0; i < data->dacs; ++i) {
337 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
338 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
342 static void update_pcm1796_mute(struct oxygen *chip)
344 struct xonar_data *data = chip->model_data;
348 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
350 value |= PCM1796_MUTE;
351 for (i = 0; i < data->dacs; ++i)
352 pcm1796_write(chip, i, 18, value);
355 static void pcm1796_init(struct oxygen *chip)
357 struct xonar_data *data = chip->model_data;
360 for (i = 0; i < data->dacs; ++i) {
361 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
362 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
363 pcm1796_write(chip, i, 21, 0);
365 update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */
366 update_pcm1796_volume(chip);
369 static void xonar_d2_init(struct oxygen *chip)
371 struct xonar_data *data = chip->model_data;
373 data->anti_pop_delay = 300;
375 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
376 data->pcm1796_oversampling = PCM1796_OS_64;
380 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
381 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
383 xonar_common_init(chip);
385 snd_component_add(chip->card, "PCM1796");
386 snd_component_add(chip->card, "CS5381");
389 static void xonar_d2x_init(struct oxygen *chip)
391 struct xonar_data *data = chip->model_data;
393 data->ext_power_reg = OXYGEN_GPIO_DATA;
394 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
395 data->ext_power_bit = GPIO_D2X_EXT_POWER;
396 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
401 static void update_cs4362a_volumes(struct oxygen *chip)
405 mute = chip->dac_mute ? CS4362A_MUTE : 0;
406 cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
407 cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
408 cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
409 cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
410 cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
411 cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
414 static void update_cs43xx_volume(struct oxygen *chip)
416 cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
417 cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
418 update_cs4362a_volumes(chip);
421 static void update_cs43xx_mute(struct oxygen *chip)
425 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
427 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
428 cs4398_write(chip, 4, reg);
429 update_cs4362a_volumes(chip);
432 static void cs43xx_init(struct oxygen *chip)
434 struct xonar_data *data = chip->model_data;
436 /* set CPEN (control port mode) and power down */
437 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
438 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
440 cs4398_write(chip, 2, data->cs4398_fm);
441 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
442 cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
443 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
444 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
445 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
446 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
447 cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
448 cs4362a_write(chip, 0x05, 0);
449 cs4362a_write(chip, 0x06, data->cs4362a_fm);
450 cs4362a_write(chip, 0x09, data->cs4362a_fm);
451 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
452 update_cs43xx_volume(chip);
453 update_cs43xx_mute(chip);
454 /* clear power down */
455 cs4398_write(chip, 8, CS4398_CPEN);
456 cs4362a_write(chip, 0x01, CS4362A_CPEN);
459 static void xonar_d1_init(struct oxygen *chip)
461 struct xonar_data *data = chip->model_data;
463 data->anti_pop_delay = 800;
464 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
465 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
466 data->cs4362a_fm = CS4362A_FM_SINGLE |
467 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
469 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
470 OXYGEN_2WIRE_LENGTH_8 |
471 OXYGEN_2WIRE_INTERRUPT_MASK |
472 OXYGEN_2WIRE_SPEED_FAST);
476 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
477 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
478 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
479 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
481 xonar_common_init(chip);
483 snd_component_add(chip->card, "CS4398");
484 snd_component_add(chip->card, "CS4362A");
485 snd_component_add(chip->card, "CS5361");
488 static void xonar_dx_init(struct oxygen *chip)
490 struct xonar_data *data = chip->model_data;
492 data->ext_power_reg = OXYGEN_GPI_DATA;
493 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
494 data->ext_power_bit = GPI_DX_EXT_POWER;
499 static void xonar_hdav_init(struct oxygen *chip)
501 struct xonar_data *data = chip->model_data;
504 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
505 OXYGEN_2WIRE_LENGTH_8 |
506 OXYGEN_2WIRE_INTERRUPT_MASK |
507 OXYGEN_2WIRE_SPEED_FAST);
509 data->anti_pop_delay = 100;
510 data->dacs = chip->model.private_data == MODEL_HDAV_H6 ? 4 : 1;
511 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
512 data->ext_power_reg = OXYGEN_GPI_DATA;
513 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
514 data->ext_power_bit = GPI_DX_EXT_POWER;
515 data->pcm1796_oversampling = PCM1796_OS_64;
519 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DX_INPUT_ROUTE);
520 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DX_INPUT_ROUTE);
522 oxygen_reset_uart(chip);
524 hdmi_write_command(chip, 0x61, 1, ¶m);
526 hdmi_write_command(chip, 0x74, 1, ¶m);
527 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
528 data->hdmi_params[4] = 1;
529 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
531 xonar_common_init(chip);
533 snd_component_add(chip->card, "PCM1796");
534 snd_component_add(chip->card, "CS5381");
537 static void xonar_st_init(struct oxygen *chip)
539 struct xonar_data *data = chip->model_data;
541 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
542 OXYGEN_2WIRE_LENGTH_8 |
543 OXYGEN_2WIRE_INTERRUPT_MASK |
544 OXYGEN_2WIRE_SPEED_FAST);
546 if (chip->model.private_data == MODEL_ST_H6)
547 chip->model.dac_channels = 8;
548 data->anti_pop_delay = 100;
549 data->dacs = chip->model.private_data == MODEL_ST_H6 ? 4 : 1;
550 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
551 data->pcm1796_oversampling = PCM1796_OS_64;
555 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
556 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
557 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
558 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
560 xonar_common_init(chip);
562 snd_component_add(chip->card, "PCM1792A");
563 snd_component_add(chip->card, "CS5381");
566 static void xonar_stx_init(struct oxygen *chip)
568 struct xonar_data *data = chip->model_data;
570 data->ext_power_reg = OXYGEN_GPI_DATA;
571 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
572 data->ext_power_bit = GPI_DX_EXT_POWER;
577 static void xonar_disable_output(struct oxygen *chip)
579 struct xonar_data *data = chip->model_data;
581 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
584 static void xonar_d2_cleanup(struct oxygen *chip)
586 xonar_disable_output(chip);
589 static void xonar_d1_cleanup(struct oxygen *chip)
591 xonar_disable_output(chip);
592 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
593 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
596 static void xonar_hdav_cleanup(struct oxygen *chip)
600 hdmi_write_command(chip, 0x74, 1, ¶m);
601 xonar_disable_output(chip);
604 static void xonar_st_cleanup(struct oxygen *chip)
606 xonar_disable_output(chip);
609 static void xonar_d2_suspend(struct oxygen *chip)
611 xonar_d2_cleanup(chip);
614 static void xonar_d1_suspend(struct oxygen *chip)
616 xonar_d1_cleanup(chip);
619 static void xonar_hdav_suspend(struct oxygen *chip)
621 xonar_hdav_cleanup(chip);
625 static void xonar_st_suspend(struct oxygen *chip)
627 xonar_st_cleanup(chip);
630 static void xonar_d2_resume(struct oxygen *chip)
633 xonar_enable_output(chip);
636 static void xonar_d1_resume(struct oxygen *chip)
639 xonar_enable_output(chip);
642 static void xonar_hdav_resume(struct oxygen *chip)
644 struct xonar_data *data = chip->model_data;
647 oxygen_reset_uart(chip);
649 hdmi_write_command(chip, 0x61, 1, ¶m);
651 hdmi_write_command(chip, 0x74, 1, ¶m);
652 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
654 xonar_enable_output(chip);
657 static void xonar_st_resume(struct oxygen *chip)
660 xonar_enable_output(chip);
663 static void xonar_hdav_pcm_hardware_filter(unsigned int channel,
664 struct snd_pcm_hardware *hardware)
666 if (channel == PCM_MULTICH) {
667 hardware->rates = SNDRV_PCM_RATE_44100 |
668 SNDRV_PCM_RATE_48000 |
669 SNDRV_PCM_RATE_96000 |
670 SNDRV_PCM_RATE_192000;
671 hardware->rate_min = 44100;
675 static void set_pcm1796_params(struct oxygen *chip,
676 struct snd_pcm_hw_params *params)
678 struct xonar_data *data = chip->model_data;
681 data->pcm1796_oversampling =
682 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
683 for (i = 0; i < data->dacs; ++i)
684 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
687 static void set_cs53x1_params(struct oxygen *chip,
688 struct snd_pcm_hw_params *params)
692 if (params_rate(params) <= 54000)
693 value = GPIO_CS53x1_M_SINGLE;
694 else if (params_rate(params) <= 108000)
695 value = GPIO_CS53x1_M_DOUBLE;
697 value = GPIO_CS53x1_M_QUAD;
698 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
699 value, GPIO_CS53x1_M_MASK);
702 static void set_cs43xx_params(struct oxygen *chip,
703 struct snd_pcm_hw_params *params)
705 struct xonar_data *data = chip->model_data;
707 data->cs4398_fm = CS4398_DEM_NONE | CS4398_DIF_LJUST;
708 data->cs4362a_fm = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
709 if (params_rate(params) <= 50000) {
710 data->cs4398_fm |= CS4398_FM_SINGLE;
711 data->cs4362a_fm |= CS4362A_FM_SINGLE;
712 } else if (params_rate(params) <= 100000) {
713 data->cs4398_fm |= CS4398_FM_DOUBLE;
714 data->cs4362a_fm |= CS4362A_FM_DOUBLE;
716 data->cs4398_fm |= CS4398_FM_QUAD;
717 data->cs4362a_fm |= CS4362A_FM_QUAD;
719 cs4398_write(chip, 2, data->cs4398_fm);
720 cs4362a_write(chip, 0x06, data->cs4362a_fm);
721 cs4362a_write(chip, 0x09, data->cs4362a_fm);
722 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
725 static void set_hdmi_params(struct oxygen *chip,
726 struct snd_pcm_hw_params *params)
728 struct xonar_data *data = chip->model_data;
730 data->hdmi_params[0] = 0; /* 1 = non-audio */
731 switch (params_rate(params)) {
733 data->hdmi_params[1] = IEC958_AES3_CON_FS_44100;
736 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
739 data->hdmi_params[1] = IEC958_AES3_CON_FS_96000;
742 data->hdmi_params[1] = IEC958_AES3_CON_FS_192000;
745 data->hdmi_params[2] = params_channels(params) / 2 - 1;
746 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
747 data->hdmi_params[3] = 0;
749 data->hdmi_params[3] = 0xc0;
750 data->hdmi_params[4] = 1; /* ? */
751 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
754 static void set_hdav_params(struct oxygen *chip,
755 struct snd_pcm_hw_params *params)
757 set_pcm1796_params(chip, params);
758 set_hdmi_params(chip, params);
761 static void xonar_gpio_changed(struct oxygen *chip)
763 struct xonar_data *data = chip->model_data;
766 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
767 & data->ext_power_bit);
768 if (has_power != data->has_power) {
769 data->has_power = has_power;
771 snd_printk(KERN_NOTICE "power restored\n");
774 "Hey! Don't unplug the power cable!\n");
775 /* TODO: stop PCMs */
780 static void xonar_hdav_uart_input(struct oxygen *chip)
782 if (chip->uart_input_count >= 2 &&
783 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
784 chip->uart_input[chip->uart_input_count - 1] == 'K') {
785 printk(KERN_DEBUG "message from Xonar HDAV HDMI chip received:\n");
786 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
787 chip->uart_input, chip->uart_input_count);
788 chip->uart_input_count = 0;
792 static int gpio_bit_switch_get(struct snd_kcontrol *ctl,
793 struct snd_ctl_elem_value *value)
795 struct oxygen *chip = ctl->private_data;
796 u16 bit = ctl->private_value;
798 value->value.integer.value[0] =
799 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
803 static int gpio_bit_switch_put(struct snd_kcontrol *ctl,
804 struct snd_ctl_elem_value *value)
806 struct oxygen *chip = ctl->private_data;
807 u16 bit = ctl->private_value;
808 u16 old_bits, new_bits;
811 spin_lock_irq(&chip->reg_lock);
812 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
813 if (value->value.integer.value[0])
814 new_bits = old_bits | bit;
816 new_bits = old_bits & ~bit;
817 changed = new_bits != old_bits;
819 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
820 spin_unlock_irq(&chip->reg_lock);
824 static const struct snd_kcontrol_new alt_switch = {
825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
826 .name = "Analog Loopback Switch",
827 .info = snd_ctl_boolean_mono_info,
828 .get = gpio_bit_switch_get,
829 .put = gpio_bit_switch_put,
830 .private_value = GPIO_D2_ALT,
833 static const struct snd_kcontrol_new front_panel_switch = {
834 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
835 .name = "Front Panel Switch",
836 .info = snd_ctl_boolean_mono_info,
837 .get = gpio_bit_switch_get,
838 .put = gpio_bit_switch_put,
839 .private_value = GPIO_DX_FRONT_PANEL,
842 static int st_output_switch_info(struct snd_kcontrol *ctl,
843 struct snd_ctl_elem_info *info)
845 static const char *const names[3] = {
846 "Speakers", "Headphones", "FP Headphones"
849 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
851 info->value.enumerated.items = 3;
852 if (info->value.enumerated.item >= 3)
853 info->value.enumerated.item = 2;
854 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
858 static int st_output_switch_get(struct snd_kcontrol *ctl,
859 struct snd_ctl_elem_value *value)
861 struct oxygen *chip = ctl->private_data;
864 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
865 if (!(gpio & GPIO_ST_HP))
866 value->value.enumerated.item[0] = 0;
867 else if (gpio & GPIO_ST_HP_REAR)
868 value->value.enumerated.item[0] = 1;
870 value->value.enumerated.item[0] = 2;
875 static int st_output_switch_put(struct snd_kcontrol *ctl,
876 struct snd_ctl_elem_value *value)
878 struct oxygen *chip = ctl->private_data;
881 mutex_lock(&chip->mutex);
882 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
884 switch (value->value.enumerated.item[0]) {
886 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
889 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
892 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
895 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
896 mutex_unlock(&chip->mutex);
897 return gpio != gpio_old;
900 static const struct snd_kcontrol_new st_output_switch = {
901 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
902 .name = "Analog Output",
903 .info = st_output_switch_info,
904 .get = st_output_switch_get,
905 .put = st_output_switch_put,
908 static void xonar_line_mic_ac97_switch(struct oxygen *chip,
909 unsigned int reg, unsigned int mute)
911 if (reg == AC97_LINE) {
912 spin_lock_irq(&chip->reg_lock);
913 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
914 mute ? GPIO_DX_INPUT_ROUTE : 0,
915 GPIO_DX_INPUT_ROUTE);
916 spin_unlock_irq(&chip->reg_lock);
920 static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
921 static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0);
923 static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
925 if (!strncmp(template->name, "CD Capture ", 11))
926 /* CD in is actually connected to the video in pin */
927 template->private_value ^= AC97_CD ^ AC97_VIDEO;
931 static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
933 if (!strncmp(template->name, "CD Capture ", 11))
934 return 1; /* no CD input */
938 static int xonar_st_control_filter(struct snd_kcontrol_new *template)
940 if (!strncmp(template->name, "CD Capture ", 11))
941 return 1; /* no CD input */
942 if (!strcmp(template->name, "Stereo Upmixing"))
943 return 1; /* stereo only - we don't need upmixing */
947 static int xonar_d2_mixer_init(struct oxygen *chip)
949 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
952 static int xonar_d1_mixer_init(struct oxygen *chip)
954 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
957 static int xonar_st_mixer_init(struct oxygen *chip)
959 return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip));
962 static const struct oxygen_model model_xonar_d2 = {
963 .longname = "Asus Virtuoso 200",
965 .init = xonar_d2_init,
966 .control_filter = xonar_d2_control_filter,
967 .mixer_init = xonar_d2_mixer_init,
968 .cleanup = xonar_d2_cleanup,
969 .suspend = xonar_d2_suspend,
970 .resume = xonar_d2_resume,
971 .set_dac_params = set_pcm1796_params,
972 .set_adc_params = set_cs53x1_params,
973 .update_dac_volume = update_pcm1796_volume,
974 .update_dac_mute = update_pcm1796_mute,
975 .dac_tlv = pcm1796_db_scale,
976 .model_data_size = sizeof(struct xonar_data),
977 .device_config = PLAYBACK_0_TO_I2S |
978 PLAYBACK_1_TO_SPDIF |
979 CAPTURE_0_FROM_I2S_2 |
980 CAPTURE_1_FROM_SPDIF |
984 .dac_volume_min = 255 - 2*60,
985 .dac_volume_max = 255,
986 .misc_flags = OXYGEN_MISC_MIDI,
987 .function_flags = OXYGEN_FUNCTION_SPI |
988 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
989 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
990 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
993 static const struct oxygen_model model_xonar_d1 = {
994 .longname = "Asus Virtuoso 100",
996 .init = xonar_d1_init,
997 .control_filter = xonar_d1_control_filter,
998 .mixer_init = xonar_d1_mixer_init,
999 .cleanup = xonar_d1_cleanup,
1000 .suspend = xonar_d1_suspend,
1001 .resume = xonar_d1_resume,
1002 .set_dac_params = set_cs43xx_params,
1003 .set_adc_params = set_cs53x1_params,
1004 .update_dac_volume = update_cs43xx_volume,
1005 .update_dac_mute = update_cs43xx_mute,
1006 .ac97_switch = xonar_line_mic_ac97_switch,
1007 .dac_tlv = cs4362a_db_scale,
1008 .model_data_size = sizeof(struct xonar_data),
1009 .device_config = PLAYBACK_0_TO_I2S |
1010 PLAYBACK_1_TO_SPDIF |
1011 CAPTURE_0_FROM_I2S_2,
1013 .dac_volume_min = 127 - 60,
1014 .dac_volume_max = 127,
1015 .function_flags = OXYGEN_FUNCTION_2WIRE,
1016 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1017 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1020 static const struct oxygen_model model_xonar_hdav = {
1021 .longname = "Asus Virtuoso 200",
1023 .init = xonar_hdav_init,
1024 .cleanup = xonar_hdav_cleanup,
1025 .suspend = xonar_hdav_suspend,
1026 .resume = xonar_hdav_resume,
1027 .pcm_hardware_filter = xonar_hdav_pcm_hardware_filter,
1028 .set_dac_params = set_hdav_params,
1029 .set_adc_params = set_cs53x1_params,
1030 .update_dac_volume = update_pcm1796_volume,
1031 .update_dac_mute = update_pcm1796_mute,
1032 .uart_input = xonar_hdav_uart_input,
1033 .ac97_switch = xonar_line_mic_ac97_switch,
1034 .dac_tlv = pcm1796_db_scale,
1035 .model_data_size = sizeof(struct xonar_data),
1036 .device_config = PLAYBACK_0_TO_I2S |
1037 PLAYBACK_1_TO_SPDIF |
1038 CAPTURE_0_FROM_I2S_2 |
1039 CAPTURE_1_FROM_SPDIF,
1041 .dac_volume_min = 255 - 2*60,
1042 .dac_volume_max = 255,
1043 .misc_flags = OXYGEN_MISC_MIDI,
1044 .function_flags = OXYGEN_FUNCTION_2WIRE,
1045 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1046 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1049 static const struct oxygen_model model_xonar_st = {
1050 .longname = "Asus Virtuoso 100",
1052 .init = xonar_st_init,
1053 .control_filter = xonar_st_control_filter,
1054 .mixer_init = xonar_st_mixer_init,
1055 .cleanup = xonar_st_cleanup,
1056 .suspend = xonar_st_suspend,
1057 .resume = xonar_st_resume,
1058 .set_dac_params = set_pcm1796_params,
1059 .set_adc_params = set_cs53x1_params,
1060 .update_dac_volume = update_pcm1796_volume,
1061 .update_dac_mute = update_pcm1796_mute,
1062 .ac97_switch = xonar_line_mic_ac97_switch,
1063 .dac_tlv = pcm1796_db_scale,
1064 .model_data_size = sizeof(struct xonar_data),
1065 .device_config = PLAYBACK_0_TO_I2S |
1066 PLAYBACK_1_TO_SPDIF |
1067 CAPTURE_0_FROM_I2S_2,
1069 .dac_volume_min = 255 - 2*60,
1070 .dac_volume_max = 255,
1071 .function_flags = OXYGEN_FUNCTION_2WIRE,
1072 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1073 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1076 static int __devinit get_xonar_model(struct oxygen *chip,
1077 const struct pci_device_id *id)
1079 static const struct oxygen_model *const models[] = {
1080 [MODEL_D1] = &model_xonar_d1,
1081 [MODEL_DX] = &model_xonar_d1,
1082 [MODEL_D2] = &model_xonar_d2,
1083 [MODEL_D2X] = &model_xonar_d2,
1084 [MODEL_HDAV] = &model_xonar_hdav,
1085 [MODEL_ST] = &model_xonar_st,
1086 [MODEL_STX] = &model_xonar_st,
1088 static const char *const names[] = {
1089 [MODEL_D1] = "Xonar D1",
1090 [MODEL_DX] = "Xonar DX",
1091 [MODEL_D2] = "Xonar D2",
1092 [MODEL_D2X] = "Xonar D2X",
1093 [MODEL_HDAV] = "Xonar HDAV1.3",
1094 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
1095 [MODEL_ST] = "Xonar Essence ST",
1096 [MODEL_ST_H6] = "Xonar Essence ST+H6",
1097 [MODEL_STX] = "Xonar Essence STX",
1099 unsigned int model = id->driver_data;
1101 if (model >= ARRAY_SIZE(models) || !models[model])
1103 chip->model = *models[model];
1107 chip->model.init = xonar_d2x_init;
1110 chip->model.init = xonar_dx_init;
1113 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1114 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1116 model = MODEL_HDAV_H6;
1119 snd_printk(KERN_ERR "unknown daughterboard\n");
1124 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1125 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
1127 model = MODEL_ST_H6;
1132 chip->model.init = xonar_stx_init;
1133 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
1137 chip->model.shortname = names[model];
1138 chip->model.private_data = model;
1142 static int __devinit xonar_probe(struct pci_dev *pci,
1143 const struct pci_device_id *pci_id)
1148 if (dev >= SNDRV_CARDS)
1154 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
1155 xonar_ids, get_xonar_model);
1161 static struct pci_driver xonar_driver = {
1163 .id_table = xonar_ids,
1164 .probe = xonar_probe,
1165 .remove = __devexit_p(oxygen_pci_remove),
1167 .suspend = oxygen_pci_suspend,
1168 .resume = oxygen_pci_resume,
1172 static int __init alsa_card_xonar_init(void)
1174 return pci_register_driver(&xonar_driver);
1177 static void __exit alsa_card_xonar_exit(void)
1179 pci_unregister_driver(&xonar_driver);
1182 module_init(alsa_card_xonar_init)
1183 module_exit(alsa_card_xonar_exit)