snd-oxygen: Fixes for the Xonar DG card
Subsystems (2)
PATCH 2/2 snd-oxygen: Fixes for the Xonar DG card
Fixes for the Xonar DG model of the Oxygen driver:
CS4245 CODEC now fully supported with the headphone amplifier. Both front panel and rear jacks work.
Full support of capturing: from the microphone, line in, and aux input. Multichannel playback routing corrected for 2.0/4.0/5.1 speakers New mixer controls, hardware volume control supported for headphones only.
---
Depends on: [PATCH 1/2] snd-oxygen: Changes for oxygen driver to fix the Xonar DG card
sound/pci/oxygen/Makefile +1 -1
@@ -1,5 +1,5 @@ snd-oxygen-lib-objs := oxygen_io.o oxygen_lib.o oxygen_mixer.o oxygen_pcm.o -snd-oxygen-objs := oxygen.o xonar_dg.o +snd-oxygen-objs := oxygen.o xonar_dg.o xonar_dg_mixer.o snd-virtuoso-objs := virtuoso.o xonar_lib.o \ xonar_pcm179x.o xonar_cs43xx.o xonar_wm87x6.o xonar_hdmi.o
sound/pci/oxygen/xonar_dg.c +211 -468
797 lines not on this page · raw message
sound/pci/oxygen/xonar_dg.h +42 -0
48 lines not on this page · raw message
sound/pci/oxygen/xonar_dg_mixer.c +536 -0
536 lines not on this page · raw message
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Clemens Ladisch
maintainerQuoted 1 line · Roman Volkov
Fixes for the Xonar DG model of the Oxygen driver:
Each of the following sentences describes a separate logical change.
Quoted 4 lines
+++
linux-3.12-my/sound/pci/oxygen/xonar_dg.c2013-11-19 01:01:07.000000000 +0400+ * DGX card: not tested.
+ * Suspend/resume: not tested
This does not belong in the source code; if some tests succeeds, we do not want to update the driver.
Quoted 1 line
+ * SPDIF: not tested
SPDIF is handled completely by the CMI8788 itself.
Quoted 1 line
+ * 128kHz doesn't work for CS4361 (multichannel playback)
Why do you expect 128 kHz to work?
Quoted 2 lines
+ * CS4245 Auxiliary Output is connected to the front panel headphones jack
+ * through amplifier.
The comment below already says this.
Quoted 2 lines
- * GPIO 3 <- ?
+ * GPIO 3 <- unused (?)
Why this change?
Quoted 4 lines
- * GPIO 5 -> route input jack to line-in (0) or mic-in (1) - * GPIO 6 -> route input jack to line-in (0) or mic-in (1) + * GPIO 5 -> ADC analog circuit power supply control for left channel (?) + * GPIO 6 -> ADC analog circuit power supply control for right channel (?)
The Xonar cards often use mechanical relays for these routing things; you should be able to hear them when switching.
Quoted 3 lines
- * GPIO 7 -> enable rear headphone amp
+ * GPIO 7 -> switches green rear output jack between CS4245 / CS4361 first
+ * channel
0 or 1?
Quoted 2 lines
- * GPIO 8 -> enable output to speakers
+ * GPIO 8 -> DAC analog circuit power supply control (?)
This relay is intended to prevent popping when powering on.
Quoted 1 line
+static int
cs4245_dump_regs(struct oxygen *chip, bool bRead)
Why "dump" for writing? This should be two functions.
sound/pci/oxygen/xonar_dg.c line 122
Quoted 4 lines
sound/pci/oxygen/xonar_dg.c +4
-0+for (address =0 ; address <=0x10 ; address++) { +return bRead ?cs4245_read_spi (chip, address) : +cs4245_write_spi (chip, address); + }
Why return from the loop?
sound/pci/oxygen/xonar_dg.c
Quoted 7 lines
sound/pci/oxygen/xonar_dg.c +5
-0+static void dg_init(struct oxygen *chip) + * Recommended sequence from the datasheet: reset the codec and then + * initialize it. + oxygen_write8_masked(chip, OXYGEN_FUNCTION, 0, + OXYGEN_FUNCTION_RESET_CODEC);
This is what the _set/clear_bits functions are for.
Is the reset pin actually connected? Does the Windows driver do this?
Review
Quoted 1 line
(quoted diff) +1
-0+ mdelay(1);
Use mdelay() only when sleeping is not possible; use msleep() instead.
Review
Quoted 1 line
(quoted diff) +1
-0+ msleep_interruptible(1000);
When you use _interruptible, you should also check for the interrupt.
sound/pci/oxygen/xonar_dg.c line 216
Quoted 5 lines
static void set_cs4245_dac_params(struct oxygen *chip,
sound/pci/oxygen/xonar_dg.c +2
-0struct snd_pcm_hw_params *params) +unsigned char tmp; +unsigned char tmp2;
These variable names are not very descriptive.
sound/pci/oxygen/xonar_dg.c line 267
Quoted 3 lines
sound/pci/oxygen/xonar_dg.c +3
-0+case PLAYBACK_DST_20_CH : +case PLAYBACK_DST_40_CH : +case PLAYBACK_DST_51_CH :
Why is it necessary to differentiate between those? There should be no mixer control; the driver can automatically detect what format is used. And this should not make any difference because the unused channels will be silent anyway.
Quoted 1 line
+/* Put the codec into low power mode, disable audio output, save registers */
Does the Windows driver implement this?
sound/pci/oxygen/xonar_dg.c line 299
Quoted 7 lines
sound/pci/oxygen/xonar_dg.c +5
-0+static void dg_suspend (struct oxygen *chip) {struct dg *data = chip->model_data; + data->cs4245_shadow[CS4245_POWER_CTRL ] =CS4245_PDN_MIC | +CS4245_PDN_ADC |CS4245_PDN_DAC |CS4245_PDN ; +cs4245_write_spi (chip,CS4245_POWER_CTRL ); +cs4245_dump_regs (chip, true);
Why reading the registers? The cs4245_shadow values should already be valid.
sound/pci/oxygen/xonar_dg.c struct oxygen_model model_xonar_dg = { · line 346
Quoted 2 lines
sound/pci/oxygen/xonar_dg.c +1
-1- .function_flags = OXYGEN_FUNCTION_SPI, + .function_flags = OXYGEN_FUNCTION_SPI | OXYGEN_FUNCTION_ENABLE_SPI_4_5,
Why?
Quoted 1 line
+++
linux-3.12-my/sound/pci/oxygen/xonar_dg.h2013-11-19 01:06:12.000000000 +0400
This file was intended as the interface between xonar_dg.c and the generic oxygen.c driver.
That you have to add so much stuff indicates that xonar_dg.c and xonar_dg_mixer.c are not very independent and maybe should have stayed a single file.
sound/pci/oxygen/xonar_dg.h line 41
Quoted 10 lines
sound/pci/oxygen/xonar_dg.h +10
-0+/* Independend capture volumes */ +char mic_vol_l; +char mic_vol_r; +bool mic_m; +char line_vol_l; +char line_vol_r; +bool line_m; +char aux_vol_l; +char aux_vol_r; +bool aux_m;
The old driver had a separate volume for front mic.
Quoted 5 lines
+ * It is not good that we do not have software volume control
+ * as the Windows driver does. CS4361 cannot attenuate the volume.
+ * When we are switching from headphones to the speakers,
+ * which are controlled by the simple DAC CS4361, our headphones
+ * in the rear jack can stun us.
This is why I did not implement a volume control in the first place.
sound/pci/oxygen/xonar_dg_mixer.c line 132
Quoted 3 lines
sound/pci/oxygen/xonar_dg_mixer.c +2
-0+static int xonar_dg_pcm_route_apply(struct oxygen *chip) + oxygen_write8_masked(chip, OXYGEN_GPIO_DATA, 0x00, 0x80);
Use _set_bits and the GPIO_ symbol.
sound/pci/oxygen/xonar_dg_mixer.c line 328
Quoted 6 lines
sound/pci/oxygen/xonar_dg_mixer.c +6
-0+static int xonar_dg_pga_volume_get (struct snd_kcontrol *ctl, +struct snd_ctl_elem_value *val) + switch (ctl->private_value) { +case CAPTURE_SRC_MIC : +case CAPTURE_SRC_LINE : +case CAPTURE_SRC_AUX :
And FP_MIC? (Also elsewhere.)
Regards,
Clemens
В Tue, 19 Nov 2013 23:23:54 +0100
Clemens Ladisch <[email protected]> пишет:
Quoted 4 lines
Quoted 1 line · Roman Volkov
Fixes for the Xonar DG model of the Oxygen driver:
Each of the following sentences describes a separate logical change.
Yea, have some problems with naming :). Will try.
Quoted 8 lines
Quoted 5 lines
+++
linux-3.12-my/sound/pci/oxygen/xonar_dg.c2013-11-19
01:01:07.000000000 +0400+ * DGX card: not tested.
+ * Suspend/resume: not testedThis does not belong in the source code; if some tests succeeds, we do not want to update the driver.
Will move that to the patch notes.
Quoted 7 lines
Quoted 1 line
+ * SPDIF: not tested
SPDIF is handled completely by the CMI8788 itself.
Quoted 1 line
+ * 128kHz doesn't work for CS4361 (multichannel playback)
Why do you expect 128 kHz to work?
128kHz will not work because CS4361 can't detect clocks for the following mode:
LRCK = 128khz
MCLK = 128x
I tried to use MCLKs sequence 512,256,128, but unfortunately, then 32kHz does not work for CS4361.
Is the frequency 128kHz valid for ALSA?
Quoted 10 lines
Quoted 3 lines
+ * CS4245 Auxiliary Output is connected to the front panel headphones jack
+ * through amplifier.The comment below already says this.
Quoted 2 lines
- * GPIO 3 <- ?
+ * GPIO 3 <- unused (?)Why this change?
Will remove overcommenting and reduce changes.
Quoted 10 lines
Quoted 7 lines
- * GPIO 5 -> route input jack to line-in (0) or mic-in (1) - * GPIO 6 -> route input jack to line-in (0) or mic-in (1) + * GPIO 5 -> ADC analog circuit power supply control for leftchannel (?)
+ * GPIO 6 -> ADC analog circuit power supply control for right
channel (?)The Xonar cards often use mechanical relays for these routing things; you should be able to hear them when switching.
Yes, GPIO 7 swiches that relay.
Quoted 11 lines
Quoted 4 lines
- * GPIO 7 -> enable rear headphone amp
+ * GPIO 7 -> switches green rear output jack between CS4245 /
CS4361 first
+ * channel0 or 1?
Quoted 2 lines
- * GPIO 8 -> enable output to speakers
+ * GPIO 8 -> DAC analog circuit power supply control (?)This relay is intended to prevent popping when powering on.
GPIO 8 "powers up" or I don't know what it exactly does, but it doesn't switch the relay. It "enables" the audio output, headphone amp becomes connected to the DACs output, probably the same for multichannel outputs. During initialization of the windows driver, this GPIO becomes active at the last step. And perhaps my anti-pop delay of 1 second is too long. Maybe, I'll find better way to prevent pops.
Quoted 10 lines
Quoted 1 line
+static int
cs4245_dump_regs(struct oxygen *chip, bool bRead)Why "dump" for writing? This should be two functions.
sound/pci/oxygen/xonar_dg.c line 122
Quoted 4 lines
sound/pci/oxygen/xonar_dg.c +4
-0+for (address =0 ; address <=0x10 ; address++) { +return bRead ?cs4245_read_spi (chip, address) : +cs4245_write_spi (chip, address); + }Why return from the loop?
Oh, my mistake. Too quickly performed optimizations :). This only affects suspend\resume logic, so I missed out this after testing.
Quoted 10 lines
sound/pci/oxygen/xonar_dg.c line 170
Quoted 8 lines
sound/pci/oxygen/xonar_dg.c +2
-0+static void dg_init(struct oxygen *chip) + * Recommended sequence from the datasheet: reset thecodec and then
sound/pci/oxygen/xonar_dg.c +3
-0+ * initialize it. +oxygen_write8_masked (chip,OXYGEN_FUNCTION ,0 , +OXYGEN_FUNCTION_RESET_CODEC );This is what the _set/clear_bits functions are for.
Thanks for the hint.
Quoted 1 line
Is the reset pin actually connected? Does the Windows driver do this?
Should be, otherwise this is bad design. Windows driver probably not does that, but honestly, this driver is slightly buggy: sometimes (rarely) I get completely distorted sound when I power up the Windows machine. In the Linux driver I do not have this issue.
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ mdelay(1);Use
mdelay()only when sleeping is not possible; usemsleep()instead.
msleep() is not recommended for small delays (1ms-20ms). Using mdelay() here is okay. Don't use mdelay for long delays (more than 20ms).
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ msleep_interruptible(1000);When you use
_interruptible, you should also check for the interrupt.
Will use just msleep().
Quoted 7 lines
sound/pci/oxygen/xonar_dg.c line 216
Quoted 5 lines
static void set_cs4245_dac_params(struct oxygen *chip,
sound/pci/oxygen/xonar_dg.c +2
-0struct snd_pcm_hw_params *params) +unsigned char tmp; +unsigned char tmp2;These variable names are not very descriptive.
Ok
Quoted 8 lines
sound/pci/oxygen/xonar_dg.c line 267
Quoted 3 lines
sound/pci/oxygen/xonar_dg.c +3
-0+case PLAYBACK_DST_20_CH : +case PLAYBACK_DST_40_CH : +case PLAYBACK_DST_51_CH :Why is it necessary to differentiate between those? There should be no mixer control; the driver can automatically detect what format is used. And this should not make any difference because the unused channels will be silent anyway.
Just as in the windows driver. Should I change this to "HP\HP FP\Speakers"?
Quoted 4 lines
Quoted 2 lines
+/* Put the codec into low power mode, disable audio output, save registers */
Does the Windows driver implement this?
I don't know. Linux docs says I should put my hardware into low power mode and I do that. However I can't test this on my machine - my display remains black after resume (VGA driver) and computer freezes at all when I use NVIDIA proprietary driver... Maybe will test this on another machine later.
Quoted 10 lines
sound/pci/oxygen/xonar_dg.c line 299
Quoted 7 lines
sound/pci/oxygen/xonar_dg.c +5
-0+static void dg_suspend (struct oxygen *chip) {struct dg *data = chip->model_data; + data->cs4245_shadow[CS4245_POWER_CTRL ] =CS4245_PDN_MIC | +CS4245_PDN_ADC |CS4245_PDN_DAC |CS4245_PDN ; +cs4245_write_spi (chip,CS4245_POWER_CTRL ); +cs4245_dump_regs (chip, true);Why reading the registers? The
cs4245_shadowvalues should already be valid.
Just to validate again :)
Quoted 5 lines
Quoted 3 lines
(quoted diff) +1
-1- .function_flags = OXYGEN_FUNCTION_SPI, + .function_flags = OXYGEN_FUNCTION_SPI |
OXYGEN_FUNCTION_ENABLE_SPI_4_5,Why?
Because this just works and as in the Windows driver. IFAIK, this sets bit 7 at register 50h in the CMI chip (1: select SPI chip 4, 5 enable function).
Quoted 9 lines
Quoted 2 lines
+++
linux-3.12-my/sound/pci/oxygen/xonar_dg.h2013-11-19
01:06:12.000000000 +0400This file was intended as the interface between
xonar_dg.cand the genericoxygen.cdriver.That you have to add so much stuff indicates that
xonar_dg.candxonar_dg_mixer.care not very independent and maybe should have stayed a single file.
But moving mixer to another file so simplifies things... Currently, xonar_dg.c is at upper level of hierarchy, probably I should change that? (The mixer controls the driver, not otherwise)
Quoted 4 lines
Quoted 4 lines
sound/pci/oxygen/xonar_dg.h +4
-0+/* Independend capture volumes */ +char mic_vol_l; +char mic_vol_r; +bool mic_m;
Quoted 8 lines
sound/pci/oxygen/xonar_dg.h line 41
Quoted 6 lines
sound/pci/oxygen/xonar_dg.h +6
-0+char line_vol_l; +char line_vol_r; +bool line_m; +char aux_vol_l; +char aux_vol_r; +bool aux_m;The old driver had a separate volume for front mic.
Will add this one.
Quoted 8 lines
Quoted 6 lines
+ * It is not good that we do not have software volume control
+ * as the Windows driver does. CS4361 cannot attenuate the volume.
+ * When we are switching from headphones to the speakers,
+ * which are controlled by the simple DAC CS4361, our headphones
+ * in the rear jack can stun us.This is why I did not implement a volume control in the first place.
Honestly, this is a common problem with ALSA, headphones without volume regulator, and flat_volumes = yes.
It's better to have this regulator I think...
Quoted 6 lines
Quoted 4 lines
(quoted diff) +2
-0+static int xonar_dg_pcm_route_apply(struct oxygen *chip) + oxygen_write8_masked(chip, OXYGEN_GPIO_DATA, 0x00,
0x80);Use
_set_bitsand theGPIO_symbol.
Ok
Quoted 8 lines
sound/pci/oxygen/xonar_dg_mixer.c line 328
Quoted 6 lines
sound/pci/oxygen/xonar_dg_mixer.c +6
-0+static int xonar_dg_pga_volume_get (struct snd_kcontrol *ctl, +struct snd_ctl_elem_value *val) + switch (ctl->private_value) { +case CAPTURE_SRC_MIC : +case CAPTURE_SRC_LINE : +case CAPTURE_SRC_AUX :And
FP_MIC? (Also elsewhere.)
CAPTURE_SRC_MIC private_value is common for both FP and rear, see snd_kcontrol_new array.
Quoted 4 lines
Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
В Wed, 20 Nov 2013 13:29:18 +0100
Clemens Ladisch <[email protected]> пишет:
Quoted 95 lines
Quoted 7 lines · Roman Volkov
Clemens Ladisch <[email protected]> пишет:
Quoted 4 lines
Quoted 1 line · Roman Volkov
+ * 128kHz doesn't work for CS4361 (multichannel playback)
Why do you expect 128 kHz to work?
128kHz will not work because ...
... the CMI8788 does not support 128 kHz in the first place.
Quoted 1 line
And perhaps my anti-pop delay of 1 second is too long.
The Windows driver uses 2.5 seconds.
Quoted 4 lines
Quoted 2 lines
Is the reset pin actually connected? Does the Windows driver do this?
Should be, otherwise this is bad design.
This driver is not for a theoretical, optimally designed card; it is for the actual card that Asus builds. If the Windows driver does not touch the reset pin, we should not do this either (because it might be connected to the self-destruct trigger).
Quoted 2 lines
sometimes (rarely) I get completely distorted sound when I power up the Windows machine.
After a cold boot?
This also happened for some other Xonar card when the Linux driver did things differently and did not reset these settings when shutting down.
Quoted 4 lines
Quoted 2 lines
Use
mdelay()only when sleeping is not possible; usemsleep()instead.
msleep()is not recommended for small delays (1ms-20ms).Only because it isn't very accurate. But using
mdelay()is even worse because it busy-loops.Quoted 10 lines
Quoted 8 lines
sound/pci/oxygen/xonar_dg.c line 267
Quoted 3 lines
sound/pci/oxygen/xonar_dg.c +3
-0+case PLAYBACK_DST_20_CH : +case PLAYBACK_DST_40_CH : +case PLAYBACK_DST_51_CH :Why is it necessary to differentiate between those? There should be no mixer control; the driver can automatically detect what format is used. And this should not make any difference because the unused channels will be silent anyway.
Just as in the windows driver.
This is not necessarily a reason to implement the same in the Linux driver, especially if it's not required by the actual hardware, and reduces usability.
Quoted 1 line
Should I change this to "HP\HP FP\Speakers"?
Yes.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
+/* Put the codec into low power mode, disable audio output, save registers */
Does the Windows driver implement this?
I don't know. Linux docs says I should put my hardware into low power mode and I do that.
As far as I know, none of the Xonar cards have any real power-saving functionality; they rely on the entire PCI slot being powered down.
For practical purposes, suspend/resume just means that you have to restore the registers.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
(quoted diff) +1
-1- .function_flags = OXYGEN_FUNCTION_SPI, + .function_flags = OXYGEN_FUNCTION_SPI |
OXYGEN_FUNCTION_ENABLE_SPI_4_5,Why?
Because this just works and as in the Windows driver.
If nothing is connected to those pins, it doesn't matter. This code in the Windows driver probably was just copy/pasted from the D2 code.
Quoted 9 lines
Quoted 8 lines
Quoted 1 line
+++
linux-3.12-my/sound/pci/oxygen/xonar_dg.hThis file was intended as the interface between
xonar_dg.cand the genericoxygen.cdriver.That you have to add so much stuff indicates that
xonar_dg.candxonar_dg_mixer.care not very independent and maybe should have stayed a single file.
Quoted 9 lines
Quoted 1 line
But moving mixer to another file so simplifies things...
Your choice. But it makes it hard to review changes when you move the code around in the same patch.
Regards,
Clemens
Okay, I won't argue. If the driver will work with the changes, I don't care. How should I name the subject? Should I mark this with "RESEND" or "UPDATE" or leave the subject named like "[PATCH 2/2]
snd-oxygen: Fixes for the Xonar DG card"?
Signature · 7 lines
Kind regards, Roman Volkov, [email protected] _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel