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)
115 #include <linux/pci.h>
116 #include <linux/delay.h>
117 #include <linux/mutex.h>
118 #include <sound/ac97_codec.h>
119 #include <sound/asoundef.h>
120 #include <sound/control.h>
121 #include <sound/core.h>
122 #include <sound/initval.h>
123 #include <sound/pcm.h>
124 #include <sound/pcm_params.h>
125 #include <sound/tlv.h>
132 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
133 MODULE_DESCRIPTION("Asus AVx00 driver");
134 MODULE_LICENSE("GPL v2");
135 MODULE_SUPPORTED_DEVICE("{{Asus,AV100},{Asus,AV200}}");
137 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
138 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
139 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
141 module_param_array(index, int, NULL, 0444);
142 MODULE_PARM_DESC(index, "card index");
143 module_param_array(id, charp, NULL, 0444);
144 MODULE_PARM_DESC(id, "ID string");
145 module_param_array(enable, bool, NULL, 0444);
146 MODULE_PARM_DESC(enable, "enable card");
153 MODEL_HDAV, /* without daughterboard */
154 MODEL_HDAV_H6, /* with H6 daughterboard */
157 static struct pci_device_id xonar_ids[] __devinitdata = {
158 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
159 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
160 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
161 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV },
162 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 },
165 MODULE_DEVICE_TABLE(pci, xonar_ids);
168 #define GPIO_CS53x1_M_MASK 0x000c
169 #define GPIO_CS53x1_M_SINGLE 0x0000
170 #define GPIO_CS53x1_M_DOUBLE 0x0004
171 #define GPIO_CS53x1_M_QUAD 0x0008
173 #define GPIO_D2X_EXT_POWER 0x0020
174 #define GPIO_D2_ALT 0x0080
175 #define GPIO_D2_OUTPUT_ENABLE 0x0100
177 #define GPI_DX_EXT_POWER 0x01
178 #define GPIO_DX_OUTPUT_ENABLE 0x0001
179 #define GPIO_DX_FRONT_PANEL 0x0002
180 #define GPIO_DX_INPUT_ROUTE 0x0100
182 #define GPIO_HDAV_DB_MASK 0x0030
183 #define GPIO_HDAV_DB_H6 0x0000
184 #define GPIO_HDAV_DB_XX 0x0020
186 #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */
187 #define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
188 #define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
192 unsigned int anti_pop_delay;
194 u16 output_enable_bit;
196 u8 ext_power_int_reg;
199 u8 pcm1796_oversampling;
205 static void xonar_gpio_changed(struct oxygen *chip);
207 static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
210 /* maps ALSA channel pair number to SPI output */
211 static const u8 codec_map[4] = {
214 oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
215 OXYGEN_SPI_DATA_LENGTH_2 |
216 OXYGEN_SPI_CLOCK_160 |
217 (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
218 OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
222 static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
225 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
228 static void pcm1796_write(struct oxygen *chip, unsigned int codec,
231 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
233 pcm1796_write_spi(chip, codec, reg, value);
235 pcm1796_write_i2c(chip, codec, reg, value);
238 static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
240 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
243 static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
245 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
248 static void hdmi_write_command(struct oxygen *chip, u8 command,
249 unsigned int count, const u8 *params)
254 oxygen_write_uart(chip, 0xfb);
255 oxygen_write_uart(chip, 0xef);
256 oxygen_write_uart(chip, command);
257 oxygen_write_uart(chip, count);
258 for (i = 0; i < count; ++i)
259 oxygen_write_uart(chip, params[i]);
260 checksum = 0xfb + 0xef + command + count;
261 for (i = 0; i < count; ++i)
262 checksum += params[i];
263 oxygen_write_uart(chip, checksum);
266 static void xonar_enable_output(struct oxygen *chip)
268 struct xonar_data *data = chip->model_data;
270 msleep(data->anti_pop_delay);
271 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
274 static void xonar_common_init(struct oxygen *chip)
276 struct xonar_data *data = chip->model_data;
278 if (data->ext_power_reg) {
279 oxygen_set_bits8(chip, data->ext_power_int_reg,
280 data->ext_power_bit);
281 chip->interrupt_mask |= OXYGEN_INT_GPIO;
282 chip->model.gpio_changed = xonar_gpio_changed;
283 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
284 & data->ext_power_bit);
286 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
287 GPIO_CS53x1_M_MASK | data->output_enable_bit);
288 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
289 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
290 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
291 xonar_enable_output(chip);
294 static void update_pcm1796_volume(struct oxygen *chip)
296 struct xonar_data *data = chip->model_data;
299 for (i = 0; i < data->dacs; ++i) {
300 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
301 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
305 static void update_pcm1796_mute(struct oxygen *chip)
307 struct xonar_data *data = chip->model_data;
311 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
313 value |= PCM1796_MUTE;
314 for (i = 0; i < data->dacs; ++i)
315 pcm1796_write(chip, i, 18, value);
318 static void pcm1796_init(struct oxygen *chip)
320 struct xonar_data *data = chip->model_data;
323 for (i = 0; i < data->dacs; ++i) {
324 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
325 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
326 pcm1796_write(chip, i, 21, 0);
328 update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */
329 update_pcm1796_volume(chip);
332 static void xonar_d2_init(struct oxygen *chip)
334 struct xonar_data *data = chip->model_data;
336 data->anti_pop_delay = 300;
337 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
338 data->pcm1796_oversampling = PCM1796_OS_64;
339 if (data->model == MODEL_D2X) {
340 data->ext_power_reg = OXYGEN_GPIO_DATA;
341 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
342 data->ext_power_bit = GPIO_D2X_EXT_POWER;
343 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
349 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
350 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
352 xonar_common_init(chip);
354 snd_component_add(chip->card, "PCM1796");
355 snd_component_add(chip->card, "CS5381");
358 static void update_cs4362a_volumes(struct oxygen *chip)
362 mute = chip->dac_mute ? CS4362A_MUTE : 0;
363 cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
364 cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
365 cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
366 cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
367 cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
368 cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
371 static void update_cs43xx_volume(struct oxygen *chip)
373 cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
374 cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
375 update_cs4362a_volumes(chip);
378 static void update_cs43xx_mute(struct oxygen *chip)
382 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
384 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
385 cs4398_write(chip, 4, reg);
386 update_cs4362a_volumes(chip);
389 static void cs43xx_init(struct oxygen *chip)
391 struct xonar_data *data = chip->model_data;
393 /* set CPEN (control port mode) and power down */
394 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
395 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
397 cs4398_write(chip, 2, data->cs4398_fm);
398 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
399 cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
400 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
401 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
402 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
403 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
404 cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
405 cs4362a_write(chip, 0x05, 0);
406 cs4362a_write(chip, 0x06, data->cs4362a_fm);
407 cs4362a_write(chip, 0x09, data->cs4362a_fm);
408 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
409 update_cs43xx_volume(chip);
410 update_cs43xx_mute(chip);
411 /* clear power down */
412 cs4398_write(chip, 8, CS4398_CPEN);
413 cs4362a_write(chip, 0x01, CS4362A_CPEN);
416 static void xonar_d1_init(struct oxygen *chip)
418 struct xonar_data *data = chip->model_data;
420 data->anti_pop_delay = 800;
421 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
422 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
423 data->cs4362a_fm = CS4362A_FM_SINGLE |
424 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
425 if (data->model == MODEL_DX) {
426 data->ext_power_reg = OXYGEN_GPI_DATA;
427 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
428 data->ext_power_bit = GPI_DX_EXT_POWER;
431 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
432 OXYGEN_2WIRE_LENGTH_8 |
433 OXYGEN_2WIRE_INTERRUPT_MASK |
434 OXYGEN_2WIRE_SPEED_FAST);
438 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
439 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
440 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
441 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
443 xonar_common_init(chip);
445 snd_component_add(chip->card, "CS4398");
446 snd_component_add(chip->card, "CS4362A");
447 snd_component_add(chip->card, "CS5361");
450 static void xonar_hdav_init(struct oxygen *chip)
452 struct xonar_data *data = chip->model_data;
455 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
456 OXYGEN_2WIRE_LENGTH_8 |
457 OXYGEN_2WIRE_INTERRUPT_MASK |
458 OXYGEN_2WIRE_SPEED_FAST);
460 data->anti_pop_delay = 100;
461 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
462 data->ext_power_reg = OXYGEN_GPI_DATA;
463 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
464 data->ext_power_bit = GPI_DX_EXT_POWER;
465 data->pcm1796_oversampling = PCM1796_OS_64;
469 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DX_INPUT_ROUTE);
470 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DX_INPUT_ROUTE);
472 oxygen_reset_uart(chip);
474 hdmi_write_command(chip, 0x61, 1, ¶m);
476 hdmi_write_command(chip, 0x74, 1, ¶m);
477 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
478 data->hdmi_params[4] = 1;
479 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
481 xonar_common_init(chip);
483 snd_component_add(chip->card, "PCM1796");
484 snd_component_add(chip->card, "CS5381");
487 static void xonar_disable_output(struct oxygen *chip)
489 struct xonar_data *data = chip->model_data;
491 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
494 static void xonar_d2_cleanup(struct oxygen *chip)
496 xonar_disable_output(chip);
499 static void xonar_d1_cleanup(struct oxygen *chip)
501 xonar_disable_output(chip);
502 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
503 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
506 static void xonar_hdav_cleanup(struct oxygen *chip)
510 hdmi_write_command(chip, 0x74, 1, ¶m);
511 xonar_disable_output(chip);
514 static void xonar_d2_suspend(struct oxygen *chip)
516 xonar_d2_cleanup(chip);
519 static void xonar_d1_suspend(struct oxygen *chip)
521 xonar_d1_cleanup(chip);
524 static void xonar_hdav_suspend(struct oxygen *chip)
526 xonar_hdav_cleanup(chip);
530 static void xonar_d2_resume(struct oxygen *chip)
533 xonar_enable_output(chip);
536 static void xonar_d1_resume(struct oxygen *chip)
539 xonar_enable_output(chip);
542 static void xonar_hdav_resume(struct oxygen *chip)
544 struct xonar_data *data = chip->model_data;
547 oxygen_reset_uart(chip);
549 hdmi_write_command(chip, 0x61, 1, ¶m);
551 hdmi_write_command(chip, 0x74, 1, ¶m);
552 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
554 xonar_enable_output(chip);
557 static void xonar_hdav_pcm_hardware_filter(unsigned int channel,
558 struct snd_pcm_hardware *hardware)
560 if (channel == PCM_MULTICH) {
561 hardware->rates = SNDRV_PCM_RATE_44100 |
562 SNDRV_PCM_RATE_48000 |
563 SNDRV_PCM_RATE_96000 |
564 SNDRV_PCM_RATE_192000;
565 hardware->rate_min = 44100;
569 static void set_pcm1796_params(struct oxygen *chip,
570 struct snd_pcm_hw_params *params)
572 struct xonar_data *data = chip->model_data;
575 data->pcm1796_oversampling =
576 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
577 for (i = 0; i < data->dacs; ++i)
578 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
581 static void set_cs53x1_params(struct oxygen *chip,
582 struct snd_pcm_hw_params *params)
586 if (params_rate(params) <= 54000)
587 value = GPIO_CS53x1_M_SINGLE;
588 else if (params_rate(params) <= 108000)
589 value = GPIO_CS53x1_M_DOUBLE;
591 value = GPIO_CS53x1_M_QUAD;
592 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
593 value, GPIO_CS53x1_M_MASK);
596 static void set_cs43xx_params(struct oxygen *chip,
597 struct snd_pcm_hw_params *params)
599 struct xonar_data *data = chip->model_data;
601 data->cs4398_fm = CS4398_DEM_NONE | CS4398_DIF_LJUST;
602 data->cs4362a_fm = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
603 if (params_rate(params) <= 50000) {
604 data->cs4398_fm |= CS4398_FM_SINGLE;
605 data->cs4362a_fm |= CS4362A_FM_SINGLE;
606 } else if (params_rate(params) <= 100000) {
607 data->cs4398_fm |= CS4398_FM_DOUBLE;
608 data->cs4362a_fm |= CS4362A_FM_DOUBLE;
610 data->cs4398_fm |= CS4398_FM_QUAD;
611 data->cs4362a_fm |= CS4362A_FM_QUAD;
613 cs4398_write(chip, 2, data->cs4398_fm);
614 cs4362a_write(chip, 0x06, data->cs4362a_fm);
615 cs4362a_write(chip, 0x09, data->cs4362a_fm);
616 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
619 static void set_hdmi_params(struct oxygen *chip,
620 struct snd_pcm_hw_params *params)
622 struct xonar_data *data = chip->model_data;
624 data->hdmi_params[0] = 0; /* 1 = non-audio */
625 switch (params_rate(params)) {
627 data->hdmi_params[1] = IEC958_AES3_CON_FS_44100;
630 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
633 data->hdmi_params[1] = IEC958_AES3_CON_FS_96000;
636 data->hdmi_params[1] = IEC958_AES3_CON_FS_192000;
639 data->hdmi_params[2] = params_channels(params) / 2 - 1;
640 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
641 data->hdmi_params[3] = 0;
643 data->hdmi_params[3] = 0xc0;
644 data->hdmi_params[4] = 1; /* ? */
645 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
648 static void set_hdav_params(struct oxygen *chip,
649 struct snd_pcm_hw_params *params)
651 set_pcm1796_params(chip, params);
652 set_hdmi_params(chip, params);
655 static void xonar_gpio_changed(struct oxygen *chip)
657 struct xonar_data *data = chip->model_data;
660 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
661 & data->ext_power_bit);
662 if (has_power != data->has_power) {
663 data->has_power = has_power;
665 snd_printk(KERN_NOTICE "power restored\n");
668 "Hey! Don't unplug the power cable!\n");
669 /* TODO: stop PCMs */
674 static void xonar_hdav_uart_input(struct oxygen *chip)
676 if (chip->uart_input_count >= 2 &&
677 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
678 chip->uart_input[chip->uart_input_count - 1] == 'K') {
679 printk(KERN_DEBUG "message from Xonar HDAV HDMI chip received:");
680 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
681 chip->uart_input, chip->uart_input_count);
682 chip->uart_input_count = 0;
686 static int gpio_bit_switch_get(struct snd_kcontrol *ctl,
687 struct snd_ctl_elem_value *value)
689 struct oxygen *chip = ctl->private_data;
690 u16 bit = ctl->private_value;
692 value->value.integer.value[0] =
693 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
697 static int gpio_bit_switch_put(struct snd_kcontrol *ctl,
698 struct snd_ctl_elem_value *value)
700 struct oxygen *chip = ctl->private_data;
701 u16 bit = ctl->private_value;
702 u16 old_bits, new_bits;
705 spin_lock_irq(&chip->reg_lock);
706 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
707 if (value->value.integer.value[0])
708 new_bits = old_bits | bit;
710 new_bits = old_bits & ~bit;
711 changed = new_bits != old_bits;
713 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
714 spin_unlock_irq(&chip->reg_lock);
718 static const struct snd_kcontrol_new alt_switch = {
719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
720 .name = "Analog Loopback Switch",
721 .info = snd_ctl_boolean_mono_info,
722 .get = gpio_bit_switch_get,
723 .put = gpio_bit_switch_put,
724 .private_value = GPIO_D2_ALT,
727 static const struct snd_kcontrol_new front_panel_switch = {
728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
729 .name = "Front Panel Switch",
730 .info = snd_ctl_boolean_mono_info,
731 .get = gpio_bit_switch_get,
732 .put = gpio_bit_switch_put,
733 .private_value = GPIO_DX_FRONT_PANEL,
736 static void xonar_line_mic_ac97_switch(struct oxygen *chip,
737 unsigned int reg, unsigned int mute)
739 if (reg == AC97_LINE) {
740 spin_lock_irq(&chip->reg_lock);
741 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
742 mute ? GPIO_DX_INPUT_ROUTE : 0,
743 GPIO_DX_INPUT_ROUTE);
744 spin_unlock_irq(&chip->reg_lock);
748 static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0);
749 static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -12700, 100, 0);
751 static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
753 if (!strncmp(template->name, "CD Capture ", 11))
754 /* CD in is actually connected to the video in pin */
755 template->private_value ^= AC97_CD ^ AC97_VIDEO;
759 static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
761 if (!strncmp(template->name, "CD Capture ", 11))
762 return 1; /* no CD input */
766 static int xonar_d2_mixer_init(struct oxygen *chip)
768 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
771 static int xonar_d1_mixer_init(struct oxygen *chip)
773 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
776 static int xonar_model_probe(struct oxygen *chip, unsigned long driver_data)
778 static const char *const names[] = {
779 [MODEL_D1] = "Xonar D1",
780 [MODEL_DX] = "Xonar DX",
781 [MODEL_D2] = "Xonar D2",
782 [MODEL_D2X] = "Xonar D2X",
783 [MODEL_HDAV] = "Xonar HDAV1.3",
784 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
786 static const u8 dacs[] = {
794 struct xonar_data *data = chip->model_data;
796 data->model = driver_data;
797 if (data->model == MODEL_HDAV) {
798 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
800 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) &
802 case GPIO_HDAV_DB_H6:
803 data->model = MODEL_HDAV_H6;
805 case GPIO_HDAV_DB_XX:
806 snd_printk(KERN_ERR "unknown daughterboard\n");
811 data->dacs = dacs[data->model];
812 chip->model.shortname = names[data->model];
816 static const struct oxygen_model model_xonar_d2 = {
817 .longname = "Asus Virtuoso 200",
819 .owner = THIS_MODULE,
820 .probe = xonar_model_probe,
821 .init = xonar_d2_init,
822 .control_filter = xonar_d2_control_filter,
823 .mixer_init = xonar_d2_mixer_init,
824 .cleanup = xonar_d2_cleanup,
825 .suspend = xonar_d2_suspend,
826 .resume = xonar_d2_resume,
827 .set_dac_params = set_pcm1796_params,
828 .set_adc_params = set_cs53x1_params,
829 .update_dac_volume = update_pcm1796_volume,
830 .update_dac_mute = update_pcm1796_mute,
831 .dac_tlv = pcm1796_db_scale,
832 .model_data_size = sizeof(struct xonar_data),
833 .device_config = PLAYBACK_0_TO_I2S |
834 PLAYBACK_1_TO_SPDIF |
835 CAPTURE_0_FROM_I2S_2 |
836 CAPTURE_1_FROM_SPDIF |
840 .dac_volume_min = 0x0f,
841 .dac_volume_max = 0xff,
842 .misc_flags = OXYGEN_MISC_MIDI,
843 .function_flags = OXYGEN_FUNCTION_SPI |
844 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
845 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
846 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
849 static const struct oxygen_model model_xonar_d1 = {
850 .longname = "Asus Virtuoso 100",
852 .owner = THIS_MODULE,
853 .probe = xonar_model_probe,
854 .init = xonar_d1_init,
855 .control_filter = xonar_d1_control_filter,
856 .mixer_init = xonar_d1_mixer_init,
857 .cleanup = xonar_d1_cleanup,
858 .suspend = xonar_d1_suspend,
859 .resume = xonar_d1_resume,
860 .set_dac_params = set_cs43xx_params,
861 .set_adc_params = set_cs53x1_params,
862 .update_dac_volume = update_cs43xx_volume,
863 .update_dac_mute = update_cs43xx_mute,
864 .ac97_switch = xonar_line_mic_ac97_switch,
865 .dac_tlv = cs4362a_db_scale,
866 .model_data_size = sizeof(struct xonar_data),
867 .device_config = PLAYBACK_0_TO_I2S |
868 PLAYBACK_1_TO_SPDIF |
869 CAPTURE_0_FROM_I2S_2,
872 .dac_volume_max = 127,
873 .function_flags = OXYGEN_FUNCTION_2WIRE,
874 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
875 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
878 static const struct oxygen_model model_xonar_hdav = {
879 .longname = "Asus Virtuoso 200",
881 .owner = THIS_MODULE,
882 .probe = xonar_model_probe,
883 .init = xonar_hdav_init,
884 .cleanup = xonar_hdav_cleanup,
885 .suspend = xonar_hdav_suspend,
886 .resume = xonar_hdav_resume,
887 .pcm_hardware_filter = xonar_hdav_pcm_hardware_filter,
888 .set_dac_params = set_hdav_params,
889 .set_adc_params = set_cs53x1_params,
890 .update_dac_volume = update_pcm1796_volume,
891 .update_dac_mute = update_pcm1796_mute,
892 .uart_input = xonar_hdav_uart_input,
893 .ac97_switch = xonar_line_mic_ac97_switch,
894 .dac_tlv = pcm1796_db_scale,
895 .model_data_size = sizeof(struct xonar_data),
896 .device_config = PLAYBACK_0_TO_I2S |
897 PLAYBACK_1_TO_SPDIF |
898 CAPTURE_0_FROM_I2S_2,
900 .dac_volume_min = 0x0f,
901 .dac_volume_max = 0xff,
902 .function_flags = OXYGEN_FUNCTION_2WIRE,
903 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
904 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
907 static int __devinit xonar_probe(struct pci_dev *pci,
908 const struct pci_device_id *pci_id)
910 static const struct oxygen_model *const models[] = {
911 [MODEL_D1] = &model_xonar_d1,
912 [MODEL_DX] = &model_xonar_d1,
913 [MODEL_D2] = &model_xonar_d2,
914 [MODEL_D2X] = &model_xonar_d2,
915 [MODEL_HDAV] = &model_xonar_hdav,
920 if (dev >= SNDRV_CARDS)
926 BUG_ON(pci_id->driver_data >= ARRAY_SIZE(models));
927 err = oxygen_pci_probe(pci, index[dev], id[dev],
928 models[pci_id->driver_data],
929 pci_id->driver_data);
935 static struct pci_driver xonar_driver = {
937 .id_table = xonar_ids,
938 .probe = xonar_probe,
939 .remove = __devexit_p(oxygen_pci_remove),
941 .suspend = oxygen_pci_suspend,
942 .resume = oxygen_pci_resume,
946 static int __init alsa_card_xonar_init(void)
948 return pci_register_driver(&xonar_driver);
951 static void __exit alsa_card_xonar_exit(void)
953 pci_unregister_driver(&xonar_driver);
956 module_init(alsa_card_xonar_init)
957 module_exit(alsa_card_xonar_exit)