Bug 50781 - internal mic not working properly
internal mic not working properly
Status: RESOLVED CODE_FIX
Product: Drivers
Classification: Unclassified
Component: Sound(ALSA)
All Linux
: P1 normal
Assigned To: Takashi Iwai
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-20 13:54 UTC by kite
Modified: 2012-12-22 09:26 UTC (History)
3 users (show)

See Also:
Kernel Version: 3.2.29
Tree: Mainline
Regression: No


Attachments
alsa-info.txt (32.04 KB, text/plain)
2012-11-20 13:55 UTC, kite
Details
patch1 (1.42 KB, patch)
2012-11-23 07:43 UTC, Takashi Iwai
Details | Diff
patch2 (1.95 KB, patch)
2012-11-23 07:43 UTC, Takashi Iwai
Details | Diff
patch3 (2.06 KB, patch)
2012-11-23 07:44 UTC, Takashi Iwai
Details | Diff
linux kernel 3.7.0-rc6, without hda-verb tweaks, without your above patches (34.91 KB, text/plain)
2012-11-23 12:06 UTC, kite
Details
linux kernel 3.7.0-rc6, with hda-verb tweaks, without your above patches (34.91 KB, text/plain)
2012-11-23 12:10 UTC, kite
Details

Description kite 2012-11-20 13:54:19 UTC
The mic is only working in mono mode, the other channel sends only background static noise. It seems that Skype only uses the the channel with static noise, as a result, it is a problem for Skype.
Comment 1 kite 2012-11-20 13:55:43 UTC
Created attachment 86691 [details]
alsa-info.txt
Comment 2 Takashi Iwai 2012-11-20 14:59:14 UTC
Try the latest 3.7-rc6.  Some bugs regarding Cirrus codec have been fixed.
Comment 3 kite 2012-11-20 16:17:55 UTC
Thanks for your comment. I compiled 3.7-rc6, no help at all. Do I need to do anything else?
Comment 4 Takashi Iwai 2012-11-20 16:49:42 UTC
Then it's possibly a hardware feature.  Some devices are known to send a phase-inverted signal in one channel (likely for the noise cancellation).

What does it show with the command sequence below?
    hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
    hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0

(Install hda-verb described in Documentation/sound/alsa/HD-Audio.txt.)

Which channel is working and which channel doesn't work?  I suppose only the right channel is working?

If it's the right channel, try to run the following via hda-verb program (as root) after loading the driver:
   hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
   hda-verb /dev/snd/hwC0D0 0x11 SET_PROC_COEF 0x100a
Comment 5 kite 2012-11-20 17:07:57 UTC
The left channel is not working here.

bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
nid = 0x11, verb = 0x500, param = 0x2
value = 0x0
bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0
nid = 0x11, verb = 0xc00, param = 0x0
value = 0xa

=============

bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
nid = 0x11, verb = 0x500, param = 0x2
value = 0x0
bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_PROC_COEF 0x100a
nid = 0x11, verb = 0x400, param = 0x100a
value = 0x0

You said it is a feature, but when I boot into MacOS, both channels are working there. I think something is wrong under linux.
Comment 6 Takashi Iwai 2012-11-21 07:04:45 UTC
(In reply to comment #5)
> The left channel is not working here.
> 
> bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
> nid = 0x11, verb = 0x500, param = 0x2
> value = 0x0
> bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0
> nid = 0x11, verb = 0xc00, param = 0x0
> value = 0xa

OK, it's the expected value.  Also give the outputs of other values between 0 and 4 for SET_COEF_INDEX?  e.g.
     SET_COEF_INDEX 1
     GET_PROC_COEF 0

> bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
> nid = 0x11, verb = 0x500, param = 0x2
> value = 0x0
> bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_PROC_COEF 0x100a
> nid = 0x11, verb = 0x400, param = 0x100a
> value = 0x0

And no behavior change in the mic recording?
If this doesn't change, make sure that the coef value is properly set by reading it again via SET_COEF_INDEX 2 / GET_PROC_COEF 0.

If 0x100a doesn't help, try 0x40a.  Bit 11:12 and 9:10 should control the channel mapping of ADC2 and ADC1, respectively.  You can play with these bits.

If these still don't change anything, you can play to turn on bit 4 and 5.  These control ADC1 and ADC2 PGA modes.

> You said it is a feature, but when I boot into MacOS, both channels are working
> there.

Check whether the internal mic gives really a stereo input, i.e. the different signals for both left and right channels.

> I think something is wrong under linux.

We had a similar bug for other Macs but it was fixed recently on 3.7.  It was due to the wrong COEF stuff.  This is a vendor-specific setup, thus the generic driver can't work without special handling.
Comment 7 kite 2012-11-22 08:25:59 UTC
./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 0
nid = 0x11, verb = 0x500, param = 0x0
value = 0x0
./hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0
nid = 0x11, verb = 0xc00, param = 0x0
value = 0x1e


./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 1
nid = 0x11, verb = 0x500, param = 0x1
value = 0x0
./hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0
nid = 0x11, verb = 0xc00, param = 0x0
value = 0xa


./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
nid = 0x11, verb = 0x500, param = 0x2
value = 0x0
./hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0
nid = 0x11, verb = 0xc00, param = 0x0
value = 0xa

./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 3
nid = 0x11, verb = 0x500, param = 0x3
value = 0x0
./hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0
nid = 0x11, verb = 0xc00, param = 0x0
value = 0x146a

./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 4
nid = 0x11, verb = 0x500, param = 0x4
value = 0x0
./hda-verb /dev/snd/hwC0D0 0x11 GET_PROC_COEF 0
nid = 0x11, verb = 0xc00, param = 0x0
value = 0x7

===========
After the following setting, mic recording within audacity is working in 2 channels! Also mic is working within Skype now! But with heavy background noise. Not clear enough for general use.

bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_COEF_INDEX 2
nid = 0x11, verb = 0x500, param = 0x2
value = 0x0
bash-4.2# ./hda-verb /dev/snd/hwC0D0 0x11 SET_PROC_COEF 0x100a
nid = 0x11, verb = 0x400, param = 0x100a
value = 0x0
Comment 8 Takashi Iwai 2012-11-22 08:34:16 UTC
Try 0x102a or 0x2a instead of 0x100a, then.
Comment 9 kite 2012-11-22 09:00:07 UTC
0x102a is a little better than 0x100a, more natural sound; 0x2a return to the previous status (left static noise, right ok).
Comment 10 Takashi Iwai 2012-11-22 17:02:46 UTC
OK.  To be sure, could you try model=mbp101 option instead?

If this doesn't work, try without model option, and let me know what doesn't work exactly in this state.  (e.g. no sound from speaker, etc.)

I'm asking it because I saw you set model=mbp55.  It might be wrong for yours.
Comment 11 kite 2012-11-23 01:10:22 UTC
Actually model=mbp55 was not there (deleted) when I did the above test following your previous steps.

After setting model=mbp101, with or without hda-verb tweaks, the mic is silent (audacity test, the signal wave is a vertical line).
Comment 12 kite 2012-11-23 05:38:14 UTC
Horizontal line. Sorry
Comment 13 Takashi Iwai 2012-11-23 07:42:38 UTC
OK, that's good to know.  Could you upload alsa-info.sh output again with the latest kernel?

Anyway, I cooked up patches for testing now.  It became more than I expected, not only adding a new fixup, in the end.

Apply three patches attached below, and you'll have the COEF 2 0x102a automagically for your device.  Give it a try.
Comment 14 Takashi Iwai 2012-11-23 07:43:15 UTC
Created attachment 87081 [details]
patch1
Comment 15 Takashi Iwai 2012-11-23 07:43:39 UTC
Created attachment 87091 [details]
patch2
Comment 16 Takashi Iwai 2012-11-23 07:44:02 UTC
Created attachment 87101 [details]
patch3
Comment 17 kite 2012-11-23 12:01:55 UTC
With kernel 3.7.0-rc6 without your patches above:
Comment 18 kite 2012-11-23 12:06:58 UTC
Created attachment 87121 [details]
linux kernel 3.7.0-rc6, without hda-verb tweaks, without your above patches
Comment 19 kite 2012-11-23 12:10:18 UTC
Created attachment 87131 [details]
linux kernel 3.7.0-rc6, with hda-verb tweaks, without your above patches

linux kernel 3.7.0-rc6, with hda-verb tweaks, without your above patches
Comment 20 kite 2012-11-23 14:33:41 UTC
I applied your patches 1,2,3. Both channels are working quite good now. Thanks a lot for your brilliant work!
Comment 21 kite 2012-11-23 14:39:01 UTC
I just checked dmesg, and found the following log, is this harmless?

[ 6984.464519] hda-intel: Unstable LPIB (131000 >= 8192); disabling LPIB delay counting
Comment 22 Takashi Iwai 2012-11-23 15:27:13 UTC
(In reply to comment #20)
> I applied your patches 1,2,3. Both channels are working quite good now. Thanks
> a lot for your brilliant work!

Good to hear.  The patch is queued for 3.8 kernel (where the merge window will be opened sooner or later in one or two weeks).

(In reply to comment #21)
> I just checked dmesg, and found the following log, is this harmless?
> 
> [ 6984.464519] hda-intel: Unstable LPIB (131000 >= 8192); disabling LPIB delay
> counting

Yes, this is no big thing to worry.  Your hardware doesn't give a stable LPIB register read, so the driver disabled the extra delay calculation, but using only position buffer.  It's still good enough for normal use.
Comment 23 Florian Mickler 2012-12-22 09:26:26 UTC
A patch referencing this bug report has been merged in Linux v3.8-rc1:

commit ffe4d12b151018e831f0ca2e05fe78a55238c517
Author: Takashi Iwai <tiwai@suse.de>
Date:   Fri Nov 23 08:34:13 2012 +0100

    ALSA: hda - Add a fixup for internal mic on MacBook Pro 8,1

Note You need to log in before you can comment on or make changes to this bug.