2 * C-Media CMI8788 driver for C-Media's reference design and similar models
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
23 * SPI 0 -> 1st AK4396 (front)
24 * SPI 1 -> 2nd AK4396 (surround)
25 * SPI 2 -> 3rd AK4396 (center/LFE)
27 * SPI 4 -> 4th AK4396 (back)
29 * GPIO 0 -> DFS0 of AK5385
30 * GPIO 1 -> DFS1 of AK5385
33 * GPIO 4 -> enable extension S/PDIF input
34 * GPIO 6 -> enable on-board S/PDIF input
37 * GPIO 6 -> S/PDIF from optical (0) or coaxial (1) input
38 * GPIO 8 -> enable headphone amplifier
42 * LINE_OUT -> input of ADC
48 * GPO 0 -> route line-in (0) or AC97 output (1) to ADC input
51 #include <linux/delay.h>
52 #include <linux/mutex.h>
53 #include <linux/pci.h>
54 #include <linux/module.h>
55 #include <sound/ac97_codec.h>
56 #include <sound/control.h>
57 #include <sound/core.h>
58 #include <sound/info.h>
59 #include <sound/initval.h>
60 #include <sound/pcm.h>
61 #include <sound/pcm_params.h>
62 #include <sound/tlv.h>
68 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
69 MODULE_DESCRIPTION("C-Media CMI8788 driver");
70 MODULE_LICENSE("GPL v2");
71 MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8786}"
73 ",{C-Media,CMI8788}}");
75 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
76 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
77 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
79 module_param_array(index
, int, NULL
, 0444);
80 MODULE_PARM_DESC(index
, "card index");
81 module_param_array(id
, charp
, NULL
, 0444);
82 MODULE_PARM_DESC(id
, "ID string");
83 module_param_array(enable
, bool, NULL
, 0444);
84 MODULE_PARM_DESC(enable
, "enable card");
100 static const struct pci_device_id oxygen_ids
[] = {
101 /* C-Media's reference design */
102 { OXYGEN_PCI_SUBID(0x10b0, 0x0216), .driver_data
= MODEL_CMEDIA_REF
},
103 { OXYGEN_PCI_SUBID(0x10b0, 0x0217), .driver_data
= MODEL_CMEDIA_REF
},
104 { OXYGEN_PCI_SUBID(0x10b0, 0x0218), .driver_data
= MODEL_CMEDIA_REF
},
105 { OXYGEN_PCI_SUBID(0x10b0, 0x0219), .driver_data
= MODEL_CMEDIA_REF
},
106 { OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data
= MODEL_CMEDIA_REF
},
107 { OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data
= MODEL_CMEDIA_REF
},
108 { OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data
= MODEL_CMEDIA_REF
},
109 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data
= MODEL_CMEDIA_REF
},
110 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data
= MODEL_CMEDIA_REF
},
112 { OXYGEN_PCI_SUBID(0x1043, 0x8467), .driver_data
= MODEL_XONAR_DG
},
114 { OXYGEN_PCI_SUBID(0x1043, 0x8521), .driver_data
= MODEL_XONAR_DGX
},
115 /* PCI 2.0 HD Audio */
116 { OXYGEN_PCI_SUBID(0x13f6, 0x8782), .driver_data
= MODEL_2CH_OUTPUT
},
117 /* Kuroutoshikou CMI8787-HG2PCI */
118 { OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data
= MODEL_HG2PCI
},
119 /* TempoTec HiFier Fantasia */
120 { OXYGEN_PCI_SUBID(0x14c3, 0x1710), .driver_data
= MODEL_FANTASIA
},
121 /* TempoTec HiFier Serenade */
122 { OXYGEN_PCI_SUBID(0x14c3, 0x1711), .driver_data
= MODEL_SERENADE
},
123 /* AuzenTech X-Meridian */
124 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data
= MODEL_MERIDIAN
},
125 /* AuzenTech X-Meridian 2G */
126 { OXYGEN_PCI_SUBID(0x5431, 0x017a), .driver_data
= MODEL_MERIDIAN_2G
},
128 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data
= MODEL_CLARO
},
129 /* HT-Omega Claro halo */
130 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data
= MODEL_CLARO_HALO
},
133 MODULE_DEVICE_TABLE(pci
, oxygen_ids
);
136 #define GPIO_AK5385_DFS_MASK 0x0003
137 #define GPIO_AK5385_DFS_NORMAL 0x0000
138 #define GPIO_AK5385_DFS_DOUBLE 0x0001
139 #define GPIO_AK5385_DFS_QUAD 0x0002
141 #define GPIO_MERIDIAN_DIG_MASK 0x0050
142 #define GPIO_MERIDIAN_DIG_EXT 0x0010
143 #define GPIO_MERIDIAN_DIG_BOARD 0x0040
145 #define GPIO_CLARO_DIG_COAX 0x0040
146 #define GPIO_CLARO_HP 0x0100
148 struct generic_data
{
150 u8 ak4396_regs
[4][5];
154 static void ak4396_write(struct oxygen
*chip
, unsigned int codec
,
157 /* maps ALSA channel pair number to SPI output */
158 static const u8 codec_spi_map
[4] = {
161 struct generic_data
*data
= chip
->model_data
;
163 oxygen_write_spi(chip
, OXYGEN_SPI_TRIGGER
|
164 OXYGEN_SPI_DATA_LENGTH_2
|
165 OXYGEN_SPI_CLOCK_160
|
166 (codec_spi_map
[codec
] << OXYGEN_SPI_CODEC_SHIFT
) |
167 OXYGEN_SPI_CEN_LATCH_CLOCK_HI
,
168 AK4396_WRITE
| (reg
<< 8) | value
);
169 data
->ak4396_regs
[codec
][reg
] = value
;
172 static void ak4396_write_cached(struct oxygen
*chip
, unsigned int codec
,
175 struct generic_data
*data
= chip
->model_data
;
177 if (value
!= data
->ak4396_regs
[codec
][reg
])
178 ak4396_write(chip
, codec
, reg
, value
);
181 static void wm8785_write(struct oxygen
*chip
, u8 reg
, unsigned int value
)
183 struct generic_data
*data
= chip
->model_data
;
185 oxygen_write_spi(chip
, OXYGEN_SPI_TRIGGER
|
186 OXYGEN_SPI_DATA_LENGTH_2
|
187 OXYGEN_SPI_CLOCK_160
|
188 (3 << OXYGEN_SPI_CODEC_SHIFT
) |
189 OXYGEN_SPI_CEN_LATCH_CLOCK_LO
,
191 if (reg
< ARRAY_SIZE(data
->wm8785_regs
))
192 data
->wm8785_regs
[reg
] = value
;
195 static void ak4396_registers_init(struct oxygen
*chip
)
197 struct generic_data
*data
= chip
->model_data
;
200 for (i
= 0; i
< data
->dacs
; ++i
) {
201 ak4396_write(chip
, i
, AK4396_CONTROL_1
,
202 AK4396_DIF_24_MSB
| AK4396_RSTN
);
203 ak4396_write(chip
, i
, AK4396_CONTROL_2
,
204 data
->ak4396_regs
[0][AK4396_CONTROL_2
]);
205 ak4396_write(chip
, i
, AK4396_CONTROL_3
,
207 ak4396_write(chip
, i
, AK4396_LCH_ATT
,
208 chip
->dac_volume
[i
* 2]);
209 ak4396_write(chip
, i
, AK4396_RCH_ATT
,
210 chip
->dac_volume
[i
* 2 + 1]);
214 static void ak4396_init(struct oxygen
*chip
)
216 struct generic_data
*data
= chip
->model_data
;
218 data
->dacs
= chip
->model
.dac_channels_pcm
/ 2;
219 data
->ak4396_regs
[0][AK4396_CONTROL_2
] =
220 AK4396_SMUTE
| AK4396_DEM_OFF
| AK4396_DFS_NORMAL
;
221 ak4396_registers_init(chip
);
222 snd_component_add(chip
->card
, "AK4396");
225 static void ak5385_init(struct oxygen
*chip
)
227 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_AK5385_DFS_MASK
);
228 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_AK5385_DFS_MASK
);
229 snd_component_add(chip
->card
, "AK5385");
232 static void wm8785_registers_init(struct oxygen
*chip
)
234 struct generic_data
*data
= chip
->model_data
;
236 wm8785_write(chip
, WM8785_R7
, 0);
237 wm8785_write(chip
, WM8785_R0
, data
->wm8785_regs
[0]);
238 wm8785_write(chip
, WM8785_R2
, data
->wm8785_regs
[2]);
241 static void wm8785_init(struct oxygen
*chip
)
243 struct generic_data
*data
= chip
->model_data
;
245 data
->wm8785_regs
[0] =
246 WM8785_MCR_SLAVE
| WM8785_OSR_SINGLE
| WM8785_FORMAT_LJUST
;
247 data
->wm8785_regs
[2] = WM8785_HPFR
| WM8785_HPFL
;
248 wm8785_registers_init(chip
);
249 snd_component_add(chip
->card
, "WM8785");
252 static void generic_init(struct oxygen
*chip
)
258 static void meridian_init(struct oxygen
*chip
)
260 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
,
261 GPIO_MERIDIAN_DIG_MASK
);
262 oxygen_write16_masked(chip
, OXYGEN_GPIO_DATA
,
263 GPIO_MERIDIAN_DIG_BOARD
, GPIO_MERIDIAN_DIG_MASK
);
268 static void claro_enable_hp(struct oxygen
*chip
)
271 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_CLARO_HP
);
272 oxygen_set_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_CLARO_HP
);
275 static void claro_init(struct oxygen
*chip
)
277 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_CLARO_DIG_COAX
);
278 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_CLARO_DIG_COAX
);
281 claro_enable_hp(chip
);
284 static void claro_halo_init(struct oxygen
*chip
)
286 oxygen_set_bits16(chip
, OXYGEN_GPIO_CONTROL
, GPIO_CLARO_DIG_COAX
);
287 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_CLARO_DIG_COAX
);
290 claro_enable_hp(chip
);
293 static void fantasia_init(struct oxygen
*chip
)
296 snd_component_add(chip
->card
, "CS5340");
299 static void stereo_output_init(struct oxygen
*chip
)
304 static void generic_cleanup(struct oxygen
*chip
)
308 static void claro_disable_hp(struct oxygen
*chip
)
310 oxygen_clear_bits16(chip
, OXYGEN_GPIO_DATA
, GPIO_CLARO_HP
);
313 static void claro_cleanup(struct oxygen
*chip
)
315 claro_disable_hp(chip
);
318 static void claro_suspend(struct oxygen
*chip
)
320 claro_disable_hp(chip
);
323 static void generic_resume(struct oxygen
*chip
)
325 ak4396_registers_init(chip
);
326 wm8785_registers_init(chip
);
329 static void meridian_resume(struct oxygen
*chip
)
331 ak4396_registers_init(chip
);
334 static void claro_resume(struct oxygen
*chip
)
336 ak4396_registers_init(chip
);
337 claro_enable_hp(chip
);
340 static void stereo_resume(struct oxygen
*chip
)
342 ak4396_registers_init(chip
);
345 static void set_ak4396_params(struct oxygen
*chip
,
346 struct snd_pcm_hw_params
*params
)
348 struct generic_data
*data
= chip
->model_data
;
352 value
= data
->ak4396_regs
[0][AK4396_CONTROL_2
] & ~AK4396_DFS_MASK
;
353 if (params_rate(params
) <= 54000)
354 value
|= AK4396_DFS_NORMAL
;
355 else if (params_rate(params
) <= 108000)
356 value
|= AK4396_DFS_DOUBLE
;
358 value
|= AK4396_DFS_QUAD
;
360 msleep(1); /* wait for the new MCLK to become stable */
362 if (value
!= data
->ak4396_regs
[0][AK4396_CONTROL_2
]) {
363 for (i
= 0; i
< data
->dacs
; ++i
) {
364 ak4396_write(chip
, i
, AK4396_CONTROL_1
,
366 ak4396_write(chip
, i
, AK4396_CONTROL_2
, value
);
367 ak4396_write(chip
, i
, AK4396_CONTROL_1
,
368 AK4396_DIF_24_MSB
| AK4396_RSTN
);
373 static void update_ak4396_volume(struct oxygen
*chip
)
375 struct generic_data
*data
= chip
->model_data
;
378 for (i
= 0; i
< data
->dacs
; ++i
) {
379 ak4396_write_cached(chip
, i
, AK4396_LCH_ATT
,
380 chip
->dac_volume
[i
* 2]);
381 ak4396_write_cached(chip
, i
, AK4396_RCH_ATT
,
382 chip
->dac_volume
[i
* 2 + 1]);
386 static void update_ak4396_mute(struct oxygen
*chip
)
388 struct generic_data
*data
= chip
->model_data
;
392 value
= data
->ak4396_regs
[0][AK4396_CONTROL_2
] & ~AK4396_SMUTE
;
394 value
|= AK4396_SMUTE
;
395 for (i
= 0; i
< data
->dacs
; ++i
)
396 ak4396_write_cached(chip
, i
, AK4396_CONTROL_2
, value
);
399 static void set_wm8785_params(struct oxygen
*chip
,
400 struct snd_pcm_hw_params
*params
)
402 struct generic_data
*data
= chip
->model_data
;
405 value
= WM8785_MCR_SLAVE
| WM8785_FORMAT_LJUST
;
406 if (params_rate(params
) <= 48000)
407 value
|= WM8785_OSR_SINGLE
;
408 else if (params_rate(params
) <= 96000)
409 value
|= WM8785_OSR_DOUBLE
;
411 value
|= WM8785_OSR_QUAD
;
412 if (value
!= data
->wm8785_regs
[0]) {
413 wm8785_write(chip
, WM8785_R7
, 0);
414 wm8785_write(chip
, WM8785_R0
, value
);
415 wm8785_write(chip
, WM8785_R2
, data
->wm8785_regs
[2]);
419 static void set_ak5385_params(struct oxygen
*chip
,
420 struct snd_pcm_hw_params
*params
)
424 if (params_rate(params
) <= 54000)
425 value
= GPIO_AK5385_DFS_NORMAL
;
426 else if (params_rate(params
) <= 108000)
427 value
= GPIO_AK5385_DFS_DOUBLE
;
429 value
= GPIO_AK5385_DFS_QUAD
;
430 oxygen_write16_masked(chip
, OXYGEN_GPIO_DATA
,
431 value
, GPIO_AK5385_DFS_MASK
);
434 static void set_no_params(struct oxygen
*chip
, struct snd_pcm_hw_params
*params
)
438 static int rolloff_info(struct snd_kcontrol
*ctl
,
439 struct snd_ctl_elem_info
*info
)
441 static const char *const names
[2] = {
442 "Sharp Roll-off", "Slow Roll-off"
445 return snd_ctl_enum_info(info
, 1, 2, names
);
448 static int rolloff_get(struct snd_kcontrol
*ctl
,
449 struct snd_ctl_elem_value
*value
)
451 struct oxygen
*chip
= ctl
->private_data
;
452 struct generic_data
*data
= chip
->model_data
;
454 value
->value
.enumerated
.item
[0] =
455 (data
->ak4396_regs
[0][AK4396_CONTROL_2
] & AK4396_SLOW
) != 0;
459 static int rolloff_put(struct snd_kcontrol
*ctl
,
460 struct snd_ctl_elem_value
*value
)
462 struct oxygen
*chip
= ctl
->private_data
;
463 struct generic_data
*data
= chip
->model_data
;
468 mutex_lock(&chip
->mutex
);
469 reg
= data
->ak4396_regs
[0][AK4396_CONTROL_2
];
470 if (value
->value
.enumerated
.item
[0])
474 changed
= reg
!= data
->ak4396_regs
[0][AK4396_CONTROL_2
];
476 for (i
= 0; i
< data
->dacs
; ++i
)
477 ak4396_write(chip
, i
, AK4396_CONTROL_2
, reg
);
479 mutex_unlock(&chip
->mutex
);
483 static const struct snd_kcontrol_new rolloff_control
= {
484 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
485 .name
= "DAC Filter Playback Enum",
486 .info
= rolloff_info
,
491 static int hpf_info(struct snd_kcontrol
*ctl
, struct snd_ctl_elem_info
*info
)
493 static const char *const names
[2] = {
494 "None", "High-pass Filter"
497 return snd_ctl_enum_info(info
, 1, 2, names
);
500 static int hpf_get(struct snd_kcontrol
*ctl
, struct snd_ctl_elem_value
*value
)
502 struct oxygen
*chip
= ctl
->private_data
;
503 struct generic_data
*data
= chip
->model_data
;
505 value
->value
.enumerated
.item
[0] =
506 (data
->wm8785_regs
[WM8785_R2
] & WM8785_HPFR
) != 0;
510 static int hpf_put(struct snd_kcontrol
*ctl
, struct snd_ctl_elem_value
*value
)
512 struct oxygen
*chip
= ctl
->private_data
;
513 struct generic_data
*data
= chip
->model_data
;
517 mutex_lock(&chip
->mutex
);
518 reg
= data
->wm8785_regs
[WM8785_R2
] & ~(WM8785_HPFR
| WM8785_HPFL
);
519 if (value
->value
.enumerated
.item
[0])
520 reg
|= WM8785_HPFR
| WM8785_HPFL
;
521 changed
= reg
!= data
->wm8785_regs
[WM8785_R2
];
523 wm8785_write(chip
, WM8785_R2
, reg
);
524 mutex_unlock(&chip
->mutex
);
528 static const struct snd_kcontrol_new hpf_control
= {
529 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
530 .name
= "ADC Filter Capture Enum",
536 static int meridian_dig_source_info(struct snd_kcontrol
*ctl
,
537 struct snd_ctl_elem_info
*info
)
539 static const char *const names
[2] = { "On-board", "Extension" };
541 return snd_ctl_enum_info(info
, 1, 2, names
);
544 static int claro_dig_source_info(struct snd_kcontrol
*ctl
,
545 struct snd_ctl_elem_info
*info
)
547 static const char *const names
[2] = { "Optical", "Coaxial" };
549 return snd_ctl_enum_info(info
, 1, 2, names
);
552 static int meridian_dig_source_get(struct snd_kcontrol
*ctl
,
553 struct snd_ctl_elem_value
*value
)
555 struct oxygen
*chip
= ctl
->private_data
;
557 value
->value
.enumerated
.item
[0] =
558 !!(oxygen_read16(chip
, OXYGEN_GPIO_DATA
) &
559 GPIO_MERIDIAN_DIG_EXT
);
563 static int claro_dig_source_get(struct snd_kcontrol
*ctl
,
564 struct snd_ctl_elem_value
*value
)
566 struct oxygen
*chip
= ctl
->private_data
;
568 value
->value
.enumerated
.item
[0] =
569 !!(oxygen_read16(chip
, OXYGEN_GPIO_DATA
) &
570 GPIO_CLARO_DIG_COAX
);
574 static int meridian_dig_source_put(struct snd_kcontrol
*ctl
,
575 struct snd_ctl_elem_value
*value
)
577 struct oxygen
*chip
= ctl
->private_data
;
578 u16 old_reg
, new_reg
;
581 mutex_lock(&chip
->mutex
);
582 old_reg
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
583 new_reg
= old_reg
& ~GPIO_MERIDIAN_DIG_MASK
;
584 if (value
->value
.enumerated
.item
[0] == 0)
585 new_reg
|= GPIO_MERIDIAN_DIG_BOARD
;
587 new_reg
|= GPIO_MERIDIAN_DIG_EXT
;
588 changed
= new_reg
!= old_reg
;
590 oxygen_write16(chip
, OXYGEN_GPIO_DATA
, new_reg
);
591 mutex_unlock(&chip
->mutex
);
595 static int claro_dig_source_put(struct snd_kcontrol
*ctl
,
596 struct snd_ctl_elem_value
*value
)
598 struct oxygen
*chip
= ctl
->private_data
;
599 u16 old_reg
, new_reg
;
602 mutex_lock(&chip
->mutex
);
603 old_reg
= oxygen_read16(chip
, OXYGEN_GPIO_DATA
);
604 new_reg
= old_reg
& ~GPIO_CLARO_DIG_COAX
;
605 if (value
->value
.enumerated
.item
[0])
606 new_reg
|= GPIO_CLARO_DIG_COAX
;
607 changed
= new_reg
!= old_reg
;
609 oxygen_write16(chip
, OXYGEN_GPIO_DATA
, new_reg
);
610 mutex_unlock(&chip
->mutex
);
614 static const struct snd_kcontrol_new meridian_dig_source_control
= {
615 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
616 .name
= "IEC958 Source Capture Enum",
617 .info
= meridian_dig_source_info
,
618 .get
= meridian_dig_source_get
,
619 .put
= meridian_dig_source_put
,
622 static const struct snd_kcontrol_new claro_dig_source_control
= {
623 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
624 .name
= "IEC958 Source Capture Enum",
625 .info
= claro_dig_source_info
,
626 .get
= claro_dig_source_get
,
627 .put
= claro_dig_source_put
,
630 static int generic_mixer_init(struct oxygen
*chip
)
632 return snd_ctl_add(chip
->card
, snd_ctl_new1(&rolloff_control
, chip
));
635 static int generic_wm8785_mixer_init(struct oxygen
*chip
)
639 err
= generic_mixer_init(chip
);
642 err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&hpf_control
, chip
));
648 static int meridian_mixer_init(struct oxygen
*chip
)
652 err
= generic_mixer_init(chip
);
655 err
= snd_ctl_add(chip
->card
,
656 snd_ctl_new1(&meridian_dig_source_control
, chip
));
662 static int claro_mixer_init(struct oxygen
*chip
)
666 err
= generic_wm8785_mixer_init(chip
);
669 err
= snd_ctl_add(chip
->card
,
670 snd_ctl_new1(&claro_dig_source_control
, chip
));
676 static int claro_halo_mixer_init(struct oxygen
*chip
)
680 err
= generic_mixer_init(chip
);
683 err
= snd_ctl_add(chip
->card
,
684 snd_ctl_new1(&claro_dig_source_control
, chip
));
690 static void dump_ak4396_registers(struct oxygen
*chip
,
691 struct snd_info_buffer
*buffer
)
693 struct generic_data
*data
= chip
->model_data
;
696 for (dac
= 0; dac
< data
->dacs
; ++dac
) {
697 snd_iprintf(buffer
, "\nAK4396 %u:", dac
+ 1);
698 for (i
= 0; i
< 5; ++i
)
699 snd_iprintf(buffer
, " %02x", data
->ak4396_regs
[dac
][i
]);
701 snd_iprintf(buffer
, "\n");
704 static void dump_wm8785_registers(struct oxygen
*chip
,
705 struct snd_info_buffer
*buffer
)
707 struct generic_data
*data
= chip
->model_data
;
710 snd_iprintf(buffer
, "\nWM8785:");
711 for (i
= 0; i
< 3; ++i
)
712 snd_iprintf(buffer
, " %03x", data
->wm8785_regs
[i
]);
713 snd_iprintf(buffer
, "\n");
716 static void dump_oxygen_registers(struct oxygen
*chip
,
717 struct snd_info_buffer
*buffer
)
719 dump_ak4396_registers(chip
, buffer
);
720 dump_wm8785_registers(chip
, buffer
);
723 static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale
, TLV_DB_GAIN_MUTE
, 0);
725 static const struct oxygen_model model_generic
= {
726 .shortname
= "C-Media CMI8788",
727 .longname
= "C-Media Oxygen HD Audio",
729 .init
= generic_init
,
730 .mixer_init
= generic_wm8785_mixer_init
,
731 .cleanup
= generic_cleanup
,
732 .resume
= generic_resume
,
733 .set_dac_params
= set_ak4396_params
,
734 .set_adc_params
= set_wm8785_params
,
735 .update_dac_volume
= update_ak4396_volume
,
736 .update_dac_mute
= update_ak4396_mute
,
737 .dump_registers
= dump_oxygen_registers
,
738 .dac_tlv
= ak4396_db_scale
,
739 .model_data_size
= sizeof(struct generic_data
),
740 .device_config
= PLAYBACK_0_TO_I2S
|
741 PLAYBACK_1_TO_SPDIF
|
742 PLAYBACK_2_TO_AC97_1
|
743 CAPTURE_0_FROM_I2S_1
|
744 CAPTURE_1_FROM_SPDIF
|
745 CAPTURE_2_FROM_AC97_1
|
747 .dac_channels_pcm
= 8,
748 .dac_channels_mixer
= 8,
750 .dac_volume_max
= 255,
751 .function_flags
= OXYGEN_FUNCTION_SPI
|
752 OXYGEN_FUNCTION_ENABLE_SPI_4_5
,
753 .dac_mclks
= OXYGEN_MCLKS(256, 128, 128),
754 .adc_mclks
= OXYGEN_MCLKS(256, 256, 128),
755 .dac_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
756 .adc_i2s_format
= OXYGEN_I2S_FORMAT_LJUST
,
759 static int get_oxygen_model(struct oxygen
*chip
,
760 const struct pci_device_id
*id
)
762 static const char *const names
[] = {
763 [MODEL_MERIDIAN
] = "AuzenTech X-Meridian",
764 [MODEL_MERIDIAN_2G
] = "AuzenTech X-Meridian 2G",
765 [MODEL_CLARO
] = "HT-Omega Claro",
766 [MODEL_CLARO_HALO
] = "HT-Omega Claro halo",
767 [MODEL_FANTASIA
] = "TempoTec HiFier Fantasia",
768 [MODEL_SERENADE
] = "TempoTec HiFier Serenade",
769 [MODEL_HG2PCI
] = "CMI8787-HG2PCI",
770 [MODEL_XONAR_DG
] = "Xonar DG",
771 [MODEL_XONAR_DGX
] = "Xonar DGX",
774 chip
->model
= model_generic
;
775 switch (id
->driver_data
) {
777 case MODEL_MERIDIAN_2G
:
778 chip
->model
.init
= meridian_init
;
779 chip
->model
.mixer_init
= meridian_mixer_init
;
780 chip
->model
.resume
= meridian_resume
;
781 chip
->model
.set_adc_params
= set_ak5385_params
;
782 chip
->model
.dump_registers
= dump_ak4396_registers
;
783 chip
->model
.device_config
= PLAYBACK_0_TO_I2S
|
784 PLAYBACK_1_TO_SPDIF
|
785 CAPTURE_0_FROM_I2S_2
|
786 CAPTURE_1_FROM_SPDIF
;
787 if (id
->driver_data
== MODEL_MERIDIAN
)
788 chip
->model
.device_config
|= AC97_CD_INPUT
;
791 chip
->model
.init
= claro_init
;
792 chip
->model
.mixer_init
= claro_mixer_init
;
793 chip
->model
.cleanup
= claro_cleanup
;
794 chip
->model
.suspend
= claro_suspend
;
795 chip
->model
.resume
= claro_resume
;
797 case MODEL_CLARO_HALO
:
798 chip
->model
.init
= claro_halo_init
;
799 chip
->model
.mixer_init
= claro_halo_mixer_init
;
800 chip
->model
.cleanup
= claro_cleanup
;
801 chip
->model
.suspend
= claro_suspend
;
802 chip
->model
.resume
= claro_resume
;
803 chip
->model
.set_adc_params
= set_ak5385_params
;
804 chip
->model
.dump_registers
= dump_ak4396_registers
;
805 chip
->model
.device_config
= PLAYBACK_0_TO_I2S
|
806 PLAYBACK_1_TO_SPDIF
|
807 CAPTURE_0_FROM_I2S_2
|
808 CAPTURE_1_FROM_SPDIF
;
812 case MODEL_2CH_OUTPUT
:
814 chip
->model
.shortname
= "C-Media CMI8787";
815 chip
->model
.chip
= "CMI8787";
816 if (id
->driver_data
== MODEL_FANTASIA
)
817 chip
->model
.init
= fantasia_init
;
819 chip
->model
.init
= stereo_output_init
;
820 chip
->model
.resume
= stereo_resume
;
821 chip
->model
.mixer_init
= generic_mixer_init
;
822 chip
->model
.set_adc_params
= set_no_params
;
823 chip
->model
.dump_registers
= dump_ak4396_registers
;
824 chip
->model
.device_config
= PLAYBACK_0_TO_I2S
|
826 if (id
->driver_data
== MODEL_FANTASIA
) {
827 chip
->model
.device_config
|= CAPTURE_0_FROM_I2S_1
;
828 chip
->model
.adc_mclks
= OXYGEN_MCLKS(256, 128, 128);
830 chip
->model
.dac_channels_pcm
= 2;
831 chip
->model
.dac_channels_mixer
= 2;
834 case MODEL_XONAR_DGX
:
835 chip
->model
= model_xonar_dg
;
838 if (id
->driver_data
== MODEL_MERIDIAN
||
839 id
->driver_data
== MODEL_MERIDIAN_2G
||
840 id
->driver_data
== MODEL_CLARO_HALO
) {
841 chip
->model
.misc_flags
= OXYGEN_MISC_MIDI
;
842 chip
->model
.device_config
|= MIDI_OUTPUT
| MIDI_INPUT
;
844 if (id
->driver_data
< ARRAY_SIZE(names
) && names
[id
->driver_data
])
845 chip
->model
.shortname
= names
[id
->driver_data
];
849 static int generic_oxygen_probe(struct pci_dev
*pci
,
850 const struct pci_device_id
*pci_id
)
855 if (dev
>= SNDRV_CARDS
)
861 err
= oxygen_pci_probe(pci
, index
[dev
], id
[dev
], THIS_MODULE
,
862 oxygen_ids
, get_oxygen_model
);
868 static struct pci_driver oxygen_driver
= {
869 .name
= KBUILD_MODNAME
,
870 .id_table
= oxygen_ids
,
871 .probe
= generic_oxygen_probe
,
872 .remove
= oxygen_pci_remove
,
873 #ifdef CONFIG_PM_SLEEP
875 .pm
= &oxygen_pci_pm
,
880 module_pci_driver(oxygen_driver
);