aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/oxygen/virtuoso.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/oxygen/virtuoso.c')
-rw-r--r--sound/pci/oxygen/virtuoso.c594
1 files changed, 412 insertions, 182 deletions
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index 01d7b75f9182..98c6a8c65d81 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -62,14 +62,66 @@
62 * AD0 <- 0 62 * AD0 <- 0
63 */ 63 */
64 64
65/*
66 * Xonar HDAV1.3 (Deluxe)
67 * ----------------------
68 *
69 * CMI8788:
70 *
71 * I²C <-> PCM1796 (front)
72 *
73 * GPI 0 <- external power present
74 *
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)
79 *
80 * TXD -> HDMI controller
81 * RXD <- HDMI controller
82 *
83 * PCM1796 front: AD1,0 <- 0,0
84 *
85 * no daughterboard
86 * ----------------
87 *
88 * GPIO 4 <- 1
89 *
90 * H6 daughterboard
91 * ----------------
92 *
93 * GPIO 4 <- 0
94 * GPIO 5 <- 0
95 *
96 * I²C <-> PCM1796 (surround)
97 * <-> PCM1796 (center/LFE)
98 * <-> PCM1796 (back)
99 *
100 * PCM1796 surround: AD1,0 <- 0,1
101 * PCM1796 center/LFE: AD1,0 <- 1,0
102 * PCM1796 back: AD1,0 <- 1,1
103 *
104 * unknown daughterboard
105 * ---------------------
106 *
107 * GPIO 4 <- 0
108 * GPIO 5 <- 1
109 *
110 * I²C <-> CS4362A (surround, center/LFE, back)
111 *
112 * CS4362A: AD0 <- 0
113 */
114
65#include <linux/pci.h> 115#include <linux/pci.h>
66#include <linux/delay.h> 116#include <linux/delay.h>
67#include <linux/mutex.h> 117#include <linux/mutex.h>
68#include <sound/ac97_codec.h> 118#include <sound/ac97_codec.h>
119#include <sound/asoundef.h>
69#include <sound/control.h> 120#include <sound/control.h>
70#include <sound/core.h> 121#include <sound/core.h>
71#include <sound/initval.h> 122#include <sound/initval.h>
72#include <sound/pcm.h> 123#include <sound/pcm.h>
124#include <sound/pcm_params.h>
73#include <sound/tlv.h> 125#include <sound/tlv.h>
74#include "oxygen.h" 126#include "oxygen.h"
75#include "cm9780.h" 127#include "cm9780.h"
@@ -98,12 +150,15 @@ enum {
98 MODEL_D2X, 150 MODEL_D2X,
99 MODEL_D1, 151 MODEL_D1,
100 MODEL_DX, 152 MODEL_DX,
153 MODEL_HDAV, /* without daughterboard */
154 MODEL_HDAV_H6, /* with H6 daughterboard */
101}; 155};
102 156
103static struct pci_device_id xonar_ids[] __devinitdata = { 157static struct pci_device_id xonar_ids[] __devinitdata = {
104 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 }, 158 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
105 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX }, 159 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
106 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X }, 160 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
161 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV },
107 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 }, 162 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 },
108 { } 163 { }
109}; 164};
@@ -124,11 +179,18 @@ MODULE_DEVICE_TABLE(pci, xonar_ids);
124#define GPIO_DX_FRONT_PANEL 0x0002 179#define GPIO_DX_FRONT_PANEL 0x0002
125#define GPIO_DX_INPUT_ROUTE 0x0100 180#define GPIO_DX_INPUT_ROUTE 0x0100
126 181
182#define GPIO_HDAV_DB_MASK 0x0030
183#define GPIO_HDAV_DB_H6 0x0000
184#define GPIO_HDAV_DB_XX 0x0020
185
186#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */
127#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ 187#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
128#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */ 188#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
129 189
130struct xonar_data { 190struct xonar_data {
191 unsigned int model;
131 unsigned int anti_pop_delay; 192 unsigned int anti_pop_delay;
193 unsigned int dacs;
132 u16 output_enable_bit; 194 u16 output_enable_bit;
133 u8 ext_power_reg; 195 u8 ext_power_reg;
134 u8 ext_power_int_reg; 196 u8 ext_power_int_reg;
@@ -137,10 +199,13 @@ struct xonar_data {
137 u8 pcm1796_oversampling; 199 u8 pcm1796_oversampling;
138 u8 cs4398_fm; 200 u8 cs4398_fm;
139 u8 cs4362a_fm; 201 u8 cs4362a_fm;
202 u8 hdmi_params[5];
140}; 203};
141 204
142static void pcm1796_write(struct oxygen *chip, unsigned int codec, 205static void xonar_gpio_changed(struct oxygen *chip);
143 u8 reg, u8 value) 206
207static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
208 u8 reg, u8 value)
144{ 209{
145 /* maps ALSA channel pair number to SPI output */ 210 /* maps ALSA channel pair number to SPI output */
146 static const u8 codec_map[4] = { 211 static const u8 codec_map[4] = {
@@ -154,6 +219,22 @@ static void pcm1796_write(struct oxygen *chip, unsigned int codec,
154 (reg << 8) | value); 219 (reg << 8) | value);
155} 220}
156 221
222static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
223 u8 reg, u8 value)
224{
225 oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
226}
227
228static void pcm1796_write(struct oxygen *chip, unsigned int codec,
229 u8 reg, u8 value)
230{
231 if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
232 OXYGEN_FUNCTION_SPI)
233 pcm1796_write_spi(chip, codec, reg, value);
234 else
235 pcm1796_write_i2c(chip, codec, reg, value);
236}
237
157static void cs4398_write(struct oxygen *chip, u8 reg, u8 value) 238static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
158{ 239{
159 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value); 240 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
@@ -164,6 +245,24 @@ static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
164 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value); 245 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
165} 246}
166 247
248static void hdmi_write_command(struct oxygen *chip, u8 command,
249 unsigned int count, const u8 *params)
250{
251 unsigned int i;
252 u8 checksum;
253
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);
264}
265
167static void xonar_enable_output(struct oxygen *chip) 266static void xonar_enable_output(struct oxygen *chip)
168{ 267{
169 struct xonar_data *data = chip->model_data; 268 struct xonar_data *data = chip->model_data;
@@ -180,6 +279,7 @@ static void xonar_common_init(struct oxygen *chip)
180 oxygen_set_bits8(chip, data->ext_power_int_reg, 279 oxygen_set_bits8(chip, data->ext_power_int_reg,
181 data->ext_power_bit); 280 data->ext_power_bit);
182 chip->interrupt_mask |= OXYGEN_INT_GPIO; 281 chip->interrupt_mask |= OXYGEN_INT_GPIO;
282 chip->model.gpio_changed = xonar_gpio_changed;
183 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg) 283 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
184 & data->ext_power_bit); 284 & data->ext_power_bit);
185 } 285 }
@@ -193,9 +293,10 @@ static void xonar_common_init(struct oxygen *chip)
193 293
194static void update_pcm1796_volume(struct oxygen *chip) 294static void update_pcm1796_volume(struct oxygen *chip)
195{ 295{
296 struct xonar_data *data = chip->model_data;
196 unsigned int i; 297 unsigned int i;
197 298
198 for (i = 0; i < 4; ++i) { 299 for (i = 0; i < data->dacs; ++i) {
199 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]); 300 pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
200 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]); 301 pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
201 } 302 }
@@ -203,13 +304,14 @@ static void update_pcm1796_volume(struct oxygen *chip)
203 304
204static void update_pcm1796_mute(struct oxygen *chip) 305static void update_pcm1796_mute(struct oxygen *chip)
205{ 306{
307 struct xonar_data *data = chip->model_data;
206 unsigned int i; 308 unsigned int i;
207 u8 value; 309 u8 value;
208 310
209 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD; 311 value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
210 if (chip->dac_mute) 312 if (chip->dac_mute)
211 value |= PCM1796_MUTE; 313 value |= PCM1796_MUTE;
212 for (i = 0; i < 4; ++i) 314 for (i = 0; i < data->dacs; ++i)
213 pcm1796_write(chip, i, 18, value); 315 pcm1796_write(chip, i, 18, value);
214} 316}
215 317
@@ -218,7 +320,7 @@ static void pcm1796_init(struct oxygen *chip)
218 struct xonar_data *data = chip->model_data; 320 struct xonar_data *data = chip->model_data;
219 unsigned int i; 321 unsigned int i;
220 322
221 for (i = 0; i < 4; ++i) { 323 for (i = 0; i < data->dacs; ++i) {
222 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); 324 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
223 pcm1796_write(chip, i, 20, data->pcm1796_oversampling); 325 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
224 pcm1796_write(chip, i, 21, 0); 326 pcm1796_write(chip, i, 21, 0);
@@ -234,6 +336,13 @@ static void xonar_d2_init(struct oxygen *chip)
234 data->anti_pop_delay = 300; 336 data->anti_pop_delay = 300;
235 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE; 337 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
236 data->pcm1796_oversampling = PCM1796_OS_64; 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,
344 GPIO_D2X_EXT_POWER);
345 }
237 346
238 pcm1796_init(chip); 347 pcm1796_init(chip);
239 348
@@ -246,17 +355,6 @@ static void xonar_d2_init(struct oxygen *chip)
246 snd_component_add(chip->card, "CS5381"); 355 snd_component_add(chip->card, "CS5381");
247} 356}
248 357
249static void xonar_d2x_init(struct oxygen *chip)
250{
251 struct xonar_data *data = chip->model_data;
252
253 data->ext_power_reg = OXYGEN_GPIO_DATA;
254 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
255 data->ext_power_bit = GPIO_D2X_EXT_POWER;
256 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
257 xonar_d2_init(chip);
258}
259
260static void update_cs4362a_volumes(struct oxygen *chip) 358static void update_cs4362a_volumes(struct oxygen *chip)
261{ 359{
262 u8 mute; 360 u8 mute;
@@ -324,6 +422,11 @@ static void xonar_d1_init(struct oxygen *chip)
324 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; 422 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
325 data->cs4362a_fm = CS4362A_FM_SINGLE | 423 data->cs4362a_fm = CS4362A_FM_SINGLE |
326 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; 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;
429 }
327 430
328 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, 431 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
329 OXYGEN_2WIRE_LENGTH_8 | 432 OXYGEN_2WIRE_LENGTH_8 |
@@ -344,30 +447,86 @@ static void xonar_d1_init(struct oxygen *chip)
344 snd_component_add(chip->card, "CS5361"); 447 snd_component_add(chip->card, "CS5361");
345} 448}
346 449
347static void xonar_dx_init(struct oxygen *chip) 450static void xonar_hdav_init(struct oxygen *chip)
348{ 451{
349 struct xonar_data *data = chip->model_data; 452 struct xonar_data *data = chip->model_data;
453 u8 param;
350 454
455 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
456 OXYGEN_2WIRE_LENGTH_8 |
457 OXYGEN_2WIRE_INTERRUPT_MASK |
458 OXYGEN_2WIRE_SPEED_FAST);
459
460 data->anti_pop_delay = 100;
461 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
351 data->ext_power_reg = OXYGEN_GPI_DATA; 462 data->ext_power_reg = OXYGEN_GPI_DATA;
352 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; 463 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
353 data->ext_power_bit = GPI_DX_EXT_POWER; 464 data->ext_power_bit = GPI_DX_EXT_POWER;
354 xonar_d1_init(chip); 465 data->pcm1796_oversampling = PCM1796_OS_64;
466
467 pcm1796_init(chip);
468
469 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DX_INPUT_ROUTE);
470 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_DX_INPUT_ROUTE);
471
472 oxygen_reset_uart(chip);
473 param = 0;
474 hdmi_write_command(chip, 0x61, 1, &param);
475 param = 1;
476 hdmi_write_command(chip, 0x74, 1, &param);
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);
480
481 xonar_common_init(chip);
482
483 snd_component_add(chip->card, "PCM1796");
484 snd_component_add(chip->card, "CS5381");
355} 485}
356 486
357static void xonar_cleanup(struct oxygen *chip) 487static void xonar_disable_output(struct oxygen *chip)
358{ 488{
359 struct xonar_data *data = chip->model_data; 489 struct xonar_data *data = chip->model_data;
360 490
361 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit); 491 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
362} 492}
363 493
494static void xonar_d2_cleanup(struct oxygen *chip)
495{
496 xonar_disable_output(chip);
497}
498
364static void xonar_d1_cleanup(struct oxygen *chip) 499static void xonar_d1_cleanup(struct oxygen *chip)
365{ 500{
366 xonar_cleanup(chip); 501 xonar_disable_output(chip);
367 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); 502 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
368 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC); 503 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
369} 504}
370 505
506static void xonar_hdav_cleanup(struct oxygen *chip)
507{
508 u8 param = 0;
509
510 hdmi_write_command(chip, 0x74, 1, &param);
511 xonar_disable_output(chip);
512}
513
514static void xonar_d2_suspend(struct oxygen *chip)
515{
516 xonar_d2_cleanup(chip);
517}
518
519static void xonar_d1_suspend(struct oxygen *chip)
520{
521 xonar_d1_cleanup(chip);
522}
523
524static void xonar_hdav_suspend(struct oxygen *chip)
525{
526 xonar_hdav_cleanup(chip);
527 msleep(2);
528}
529
371static void xonar_d2_resume(struct oxygen *chip) 530static void xonar_d2_resume(struct oxygen *chip)
372{ 531{
373 pcm1796_init(chip); 532 pcm1796_init(chip);
@@ -380,6 +539,33 @@ static void xonar_d1_resume(struct oxygen *chip)
380 xonar_enable_output(chip); 539 xonar_enable_output(chip);
381} 540}
382 541
542static void xonar_hdav_resume(struct oxygen *chip)
543{
544 struct xonar_data *data = chip->model_data;
545 u8 param;
546
547 oxygen_reset_uart(chip);
548 param = 0;
549 hdmi_write_command(chip, 0x61, 1, &param);
550 param = 1;
551 hdmi_write_command(chip, 0x74, 1, &param);
552 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
553 pcm1796_init(chip);
554 xonar_enable_output(chip);
555}
556
557static void xonar_hdav_pcm_hardware_filter(unsigned int channel,
558 struct snd_pcm_hardware *hardware)
559{
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;
566 }
567}
568
383static void set_pcm1796_params(struct oxygen *chip, 569static void set_pcm1796_params(struct oxygen *chip,
384 struct snd_pcm_hw_params *params) 570 struct snd_pcm_hw_params *params)
385{ 571{
@@ -388,7 +574,7 @@ static void set_pcm1796_params(struct oxygen *chip,
388 574
389 data->pcm1796_oversampling = 575 data->pcm1796_oversampling =
390 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; 576 params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
391 for (i = 0; i < 4; ++i) 577 for (i = 0; i < data->dacs; ++i)
392 pcm1796_write(chip, i, 20, data->pcm1796_oversampling); 578 pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
393} 579}
394 580
@@ -430,6 +616,42 @@ static void set_cs43xx_params(struct oxygen *chip,
430 cs4362a_write(chip, 0x0c, data->cs4362a_fm); 616 cs4362a_write(chip, 0x0c, data->cs4362a_fm);
431} 617}
432 618
619static void set_hdmi_params(struct oxygen *chip,
620 struct snd_pcm_hw_params *params)
621{
622 struct xonar_data *data = chip->model_data;
623
624 data->hdmi_params[0] = 0; /* 1 = non-audio */
625 switch (params_rate(params)) {
626 case 44100:
627 data->hdmi_params[1] = IEC958_AES3_CON_FS_44100;
628 break;
629 case 48000:
630 data->hdmi_params[1] = IEC958_AES3_CON_FS_48000;
631 break;
632 default: /* 96000 */
633 data->hdmi_params[1] = IEC958_AES3_CON_FS_96000;
634 break;
635 case 192000:
636 data->hdmi_params[1] = IEC958_AES3_CON_FS_192000;
637 break;
638 }
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;
642 else
643 data->hdmi_params[3] = 0xc0;
644 data->hdmi_params[4] = 1; /* ? */
645 hdmi_write_command(chip, 0x54, 5, data->hdmi_params);
646}
647
648static void set_hdav_params(struct oxygen *chip,
649 struct snd_pcm_hw_params *params)
650{
651 set_pcm1796_params(chip, params);
652 set_hdmi_params(chip, params);
653}
654
433static void xonar_gpio_changed(struct oxygen *chip) 655static void xonar_gpio_changed(struct oxygen *chip)
434{ 656{
435 struct xonar_data *data = chip->model_data; 657 struct xonar_data *data = chip->model_data;
@@ -449,29 +671,43 @@ static void xonar_gpio_changed(struct oxygen *chip)
449 } 671 }
450} 672}
451 673
452static int alt_switch_get(struct snd_kcontrol *ctl, 674static void xonar_hdav_uart_input(struct oxygen *chip)
453 struct snd_ctl_elem_value *value) 675{
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;
683 }
684}
685
686static int gpio_bit_switch_get(struct snd_kcontrol *ctl,
687 struct snd_ctl_elem_value *value)
454{ 688{
455 struct oxygen *chip = ctl->private_data; 689 struct oxygen *chip = ctl->private_data;
690 u16 bit = ctl->private_value;
456 691
457 value->value.integer.value[0] = 692 value->value.integer.value[0] =
458 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_D2_ALT); 693 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
459 return 0; 694 return 0;
460} 695}
461 696
462static int alt_switch_put(struct snd_kcontrol *ctl, 697static int gpio_bit_switch_put(struct snd_kcontrol *ctl,
463 struct snd_ctl_elem_value *value) 698 struct snd_ctl_elem_value *value)
464{ 699{
465 struct oxygen *chip = ctl->private_data; 700 struct oxygen *chip = ctl->private_data;
701 u16 bit = ctl->private_value;
466 u16 old_bits, new_bits; 702 u16 old_bits, new_bits;
467 int changed; 703 int changed;
468 704
469 spin_lock_irq(&chip->reg_lock); 705 spin_lock_irq(&chip->reg_lock);
470 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); 706 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
471 if (value->value.integer.value[0]) 707 if (value->value.integer.value[0])
472 new_bits = old_bits | GPIO_D2_ALT; 708 new_bits = old_bits | bit;
473 else 709 else
474 new_bits = old_bits & ~GPIO_D2_ALT; 710 new_bits = old_bits & ~bit;
475 changed = new_bits != old_bits; 711 changed = new_bits != old_bits;
476 if (changed) 712 if (changed)
477 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); 713 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
@@ -483,47 +719,22 @@ static const struct snd_kcontrol_new alt_switch = {
483 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
484 .name = "Analog Loopback Switch", 720 .name = "Analog Loopback Switch",
485 .info = snd_ctl_boolean_mono_info, 721 .info = snd_ctl_boolean_mono_info,
486 .get = alt_switch_get, 722 .get = gpio_bit_switch_get,
487 .put = alt_switch_put, 723 .put = gpio_bit_switch_put,
724 .private_value = GPIO_D2_ALT,
488}; 725};
489 726
490static int front_panel_get(struct snd_kcontrol *ctl,
491 struct snd_ctl_elem_value *value)
492{
493 struct oxygen *chip = ctl->private_data;
494
495 value->value.integer.value[0] =
496 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DX_FRONT_PANEL);
497 return 0;
498}
499
500static int front_panel_put(struct snd_kcontrol *ctl,
501 struct snd_ctl_elem_value *value)
502{
503 struct oxygen *chip = ctl->private_data;
504 u16 old_reg, new_reg;
505
506 spin_lock_irq(&chip->reg_lock);
507 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
508 if (value->value.integer.value[0])
509 new_reg = old_reg | GPIO_DX_FRONT_PANEL;
510 else
511 new_reg = old_reg & ~GPIO_DX_FRONT_PANEL;
512 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
513 spin_unlock_irq(&chip->reg_lock);
514 return old_reg != new_reg;
515}
516
517static const struct snd_kcontrol_new front_panel_switch = { 727static const struct snd_kcontrol_new front_panel_switch = {
518 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
519 .name = "Front Panel Switch", 729 .name = "Front Panel Switch",
520 .info = snd_ctl_boolean_mono_info, 730 .info = snd_ctl_boolean_mono_info,
521 .get = front_panel_get, 731 .get = gpio_bit_switch_get,
522 .put = front_panel_put, 732 .put = gpio_bit_switch_put,
733 .private_value = GPIO_DX_FRONT_PANEL,
523}; 734};
524 735
525static void xonar_d1_ac97_switch(struct oxygen *chip, 736static void xonar_line_mic_ac97_switch(struct oxygen *chip,
526 unsigned int reg, unsigned int mute) 737 unsigned int reg, unsigned int mute)
527{ 738{
528 if (reg == AC97_LINE) { 739 if (reg == AC97_LINE) {
529 spin_lock_irq(&chip->reg_lock); 740 spin_lock_irq(&chip->reg_lock);
@@ -552,7 +763,7 @@ static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
552 return 0; 763 return 0;
553} 764}
554 765
555static int xonar_mixer_init(struct oxygen *chip) 766static int xonar_d2_mixer_init(struct oxygen *chip)
556{ 767{
557 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); 768 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
558} 769}
@@ -562,130 +773,147 @@ static int xonar_d1_mixer_init(struct oxygen *chip)
562 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); 773 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
563} 774}
564 775
565static const struct oxygen_model xonar_models[] = { 776static int xonar_model_probe(struct oxygen *chip, unsigned long driver_data)
566 [MODEL_D2] = { 777{
567 .shortname = "Xonar D2", 778 static const char *const names[] = {
568 .longname = "Asus Virtuoso 200", 779 [MODEL_D1] = "Xonar D1",
569 .chip = "AV200", 780 [MODEL_DX] = "Xonar DX",
570 .owner = THIS_MODULE, 781 [MODEL_D2] = "Xonar D2",
571 .init = xonar_d2_init, 782 [MODEL_D2X] = "Xonar D2X",
572 .control_filter = xonar_d2_control_filter, 783 [MODEL_HDAV] = "Xonar HDAV1.3",
573 .mixer_init = xonar_mixer_init, 784 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
574 .cleanup = xonar_cleanup, 785 };
575 .suspend = xonar_cleanup, 786 static const u8 dacs[] = {
576 .resume = xonar_d2_resume, 787 [MODEL_D1] = 2,
577 .set_dac_params = set_pcm1796_params, 788 [MODEL_DX] = 2,
578 .set_adc_params = set_cs53x1_params, 789 [MODEL_D2] = 4,
579 .update_dac_volume = update_pcm1796_volume, 790 [MODEL_D2X] = 4,
580 .update_dac_mute = update_pcm1796_mute, 791 [MODEL_HDAV] = 1,
581 .dac_tlv = pcm1796_db_scale, 792 [MODEL_HDAV_H6] = 4,
582 .model_data_size = sizeof(struct xonar_data), 793 };
583 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 794 struct xonar_data *data = chip->model_data;
584 PLAYBACK_1_TO_SPDIF | 795
585 CAPTURE_0_FROM_I2S_2 | 796 data->model = driver_data;
586 CAPTURE_1_FROM_SPDIF, 797 if (data->model == MODEL_HDAV) {
587 .dac_channels = 8, 798 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
588 .dac_volume_min = 0x0f, 799 GPIO_HDAV_DB_MASK);
589 .dac_volume_max = 0xff, 800 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) &
590 .misc_flags = OXYGEN_MISC_MIDI, 801 GPIO_HDAV_DB_MASK) {
591 .function_flags = OXYGEN_FUNCTION_SPI | 802 case GPIO_HDAV_DB_H6:
592 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 803 data->model = MODEL_HDAV_H6;
593 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 804 break;
594 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 805 case GPIO_HDAV_DB_XX:
595 }, 806 snd_printk(KERN_ERR "unknown daughterboard\n");
596 [MODEL_D2X] = { 807 return -ENODEV;
597 .shortname = "Xonar D2X", 808 }
598 .longname = "Asus Virtuoso 200", 809 }
599 .chip = "AV200", 810
600 .owner = THIS_MODULE, 811 data->dacs = dacs[data->model];
601 .init = xonar_d2x_init, 812 chip->model.shortname = names[data->model];
602 .control_filter = xonar_d2_control_filter, 813 return 0;
603 .mixer_init = xonar_mixer_init, 814}
604 .cleanup = xonar_cleanup, 815
605 .suspend = xonar_cleanup, 816static const struct oxygen_model model_xonar_d2 = {
606 .resume = xonar_d2_resume, 817 .longname = "Asus Virtuoso 200",
607 .set_dac_params = set_pcm1796_params, 818 .chip = "AV200",
608 .set_adc_params = set_cs53x1_params, 819 .owner = THIS_MODULE,
609 .update_dac_volume = update_pcm1796_volume, 820 .probe = xonar_model_probe,
610 .update_dac_mute = update_pcm1796_mute, 821 .init = xonar_d2_init,
611 .gpio_changed = xonar_gpio_changed, 822 .control_filter = xonar_d2_control_filter,
612 .dac_tlv = pcm1796_db_scale, 823 .mixer_init = xonar_d2_mixer_init,
613 .model_data_size = sizeof(struct xonar_data), 824 .cleanup = xonar_d2_cleanup,
614 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 825 .suspend = xonar_d2_suspend,
615 PLAYBACK_1_TO_SPDIF | 826 .resume = xonar_d2_resume,
616 CAPTURE_0_FROM_I2S_2 | 827 .set_dac_params = set_pcm1796_params,
617 CAPTURE_1_FROM_SPDIF, 828 .set_adc_params = set_cs53x1_params,
618 .dac_channels = 8, 829 .update_dac_volume = update_pcm1796_volume,
619 .dac_volume_min = 0x0f, 830 .update_dac_mute = update_pcm1796_mute,
620 .dac_volume_max = 0xff, 831 .dac_tlv = pcm1796_db_scale,
621 .misc_flags = OXYGEN_MISC_MIDI, 832 .model_data_size = sizeof(struct xonar_data),
622 .function_flags = OXYGEN_FUNCTION_SPI | 833 .device_config = PLAYBACK_0_TO_I2S |
623 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 834 PLAYBACK_1_TO_SPDIF |
624 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 835 CAPTURE_0_FROM_I2S_2 |
625 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 836 CAPTURE_1_FROM_SPDIF |
626 }, 837 MIDI_OUTPUT |
627 [MODEL_D1] = { 838 MIDI_INPUT,
628 .shortname = "Xonar D1", 839 .dac_channels = 8,
629 .longname = "Asus Virtuoso 100", 840 .dac_volume_min = 0x0f,
630 .chip = "AV200", 841 .dac_volume_max = 0xff,
631 .owner = THIS_MODULE, 842 .misc_flags = OXYGEN_MISC_MIDI,
632 .init = xonar_d1_init, 843 .function_flags = OXYGEN_FUNCTION_SPI |
633 .control_filter = xonar_d1_control_filter, 844 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
634 .mixer_init = xonar_d1_mixer_init, 845 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
635 .cleanup = xonar_d1_cleanup, 846 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
636 .suspend = xonar_d1_cleanup, 847};
637 .resume = xonar_d1_resume, 848
638 .set_dac_params = set_cs43xx_params, 849static const struct oxygen_model model_xonar_d1 = {
639 .set_adc_params = set_cs53x1_params, 850 .longname = "Asus Virtuoso 100",
640 .update_dac_volume = update_cs43xx_volume, 851 .chip = "AV200",
641 .update_dac_mute = update_cs43xx_mute, 852 .owner = THIS_MODULE,
642 .ac97_switch = xonar_d1_ac97_switch, 853 .probe = xonar_model_probe,
643 .dac_tlv = cs4362a_db_scale, 854 .init = xonar_d1_init,
644 .model_data_size = sizeof(struct xonar_data), 855 .control_filter = xonar_d1_control_filter,
645 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 856 .mixer_init = xonar_d1_mixer_init,
646 PLAYBACK_1_TO_SPDIF | 857 .cleanup = xonar_d1_cleanup,
647 CAPTURE_0_FROM_I2S_2, 858 .suspend = xonar_d1_suspend,
648 .dac_channels = 8, 859 .resume = xonar_d1_resume,
649 .dac_volume_min = 0, 860 .set_dac_params = set_cs43xx_params,
650 .dac_volume_max = 127, 861 .set_adc_params = set_cs53x1_params,
651 .function_flags = OXYGEN_FUNCTION_2WIRE, 862 .update_dac_volume = update_cs43xx_volume,
652 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 863 .update_dac_mute = update_cs43xx_mute,
653 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 864 .ac97_switch = xonar_line_mic_ac97_switch,
654 }, 865 .dac_tlv = cs4362a_db_scale,
655 [MODEL_DX] = { 866 .model_data_size = sizeof(struct xonar_data),
656 .shortname = "Xonar DX", 867 .device_config = PLAYBACK_0_TO_I2S |
657 .longname = "Asus Virtuoso 100", 868 PLAYBACK_1_TO_SPDIF |
658 .chip = "AV200", 869 CAPTURE_0_FROM_I2S_2,
659 .owner = THIS_MODULE, 870 .dac_channels = 8,
660 .init = xonar_dx_init, 871 .dac_volume_min = 0,
661 .control_filter = xonar_d1_control_filter, 872 .dac_volume_max = 127,
662 .mixer_init = xonar_d1_mixer_init, 873 .function_flags = OXYGEN_FUNCTION_2WIRE,
663 .cleanup = xonar_d1_cleanup, 874 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
664 .suspend = xonar_d1_cleanup, 875 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
665 .resume = xonar_d1_resume, 876};
666 .set_dac_params = set_cs43xx_params, 877
667 .set_adc_params = set_cs53x1_params, 878static const struct oxygen_model model_xonar_hdav = {
668 .update_dac_volume = update_cs43xx_volume, 879 .longname = "Asus Virtuoso 200",
669 .update_dac_mute = update_cs43xx_mute, 880 .chip = "AV200",
670 .gpio_changed = xonar_gpio_changed, 881 .owner = THIS_MODULE,
671 .ac97_switch = xonar_d1_ac97_switch, 882 .probe = xonar_model_probe,
672 .dac_tlv = cs4362a_db_scale, 883 .init = xonar_hdav_init,
673 .model_data_size = sizeof(struct xonar_data), 884 .cleanup = xonar_hdav_cleanup,
674 .pcm_dev_cfg = PLAYBACK_0_TO_I2S | 885 .suspend = xonar_hdav_suspend,
675 PLAYBACK_1_TO_SPDIF | 886 .resume = xonar_hdav_resume,
676 CAPTURE_0_FROM_I2S_2, 887 .pcm_hardware_filter = xonar_hdav_pcm_hardware_filter,
677 .dac_channels = 8, 888 .set_dac_params = set_hdav_params,
678 .dac_volume_min = 0, 889 .set_adc_params = set_cs53x1_params,
679 .dac_volume_max = 127, 890 .update_dac_volume = update_pcm1796_volume,
680 .function_flags = OXYGEN_FUNCTION_2WIRE, 891 .update_dac_mute = update_pcm1796_mute,
681 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 892 .uart_input = xonar_hdav_uart_input,
682 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 893 .ac97_switch = xonar_line_mic_ac97_switch,
683 }, 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,
899 .dac_channels = 8,
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,
684}; 905};
685 906
686static int __devinit xonar_probe(struct pci_dev *pci, 907static int __devinit xonar_probe(struct pci_dev *pci,
687 const struct pci_device_id *pci_id) 908 const struct pci_device_id *pci_id)
688{ 909{
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,
916 };
689 static int dev; 917 static int dev;
690 int err; 918 int err;
691 919
@@ -695,8 +923,10 @@ static int __devinit xonar_probe(struct pci_dev *pci,
695 ++dev; 923 ++dev;
696 return -ENOENT; 924 return -ENOENT;
697 } 925 }
926 BUG_ON(pci_id->driver_data >= ARRAY_SIZE(models));
698 err = oxygen_pci_probe(pci, index[dev], id[dev], 927 err = oxygen_pci_probe(pci, index[dev], id[dev],
699 &xonar_models[pci_id->driver_data]); 928 models[pci_id->driver_data],
929 pci_id->driver_data);
700 if (err >= 0) 930 if (err >= 0)
701 ++dev; 931 ++dev;
702 return err; 932 return err;