[03:11]  * shriekout $decode(s60gwKe068fRILDHtOPAzLTZISEhDQpuaWNrILDHtOMNCnF1aXQgOrDHtOMgx9ewocfXsKE=,m)
[22:16] <crimsun> (sorry, waylaid by travel wifi)
[22:17] <crimsun> Welcome to this $timeofday's impromptu session on triaging ALSA bugs in Ubuntu and submitting fixes upstream
[22:17] <crimsun> A couple things to note: you'll need ubuntu-dev-tools, patchutils, git-core installed
[22:18] <crimsun> you'll also need some familiarity with C, though it doesn't need to be deep magic guru stuff
[22:19] <crimsun> Agendum: 1. Low-hanging fruit: bugs with known-working quirks commented in the bug reports
[22:19] <crimsun> 2. Not really fruit: Powerdown bugs
[22:19] <crimsun> 3. Submitting patches upstream
[22:21] <crimsun> Some required reading: https://wiki.ubuntu.com/DebuggingSoundProblems, in particular https://wiki.ubuntu.com/DebuggingSoundProblems/KarmicCaveats
[22:22] <crimsun> Next, free space requirements: you'll need about 300 MB free for git trees
[22:24] <crimsun> We'll be checking out three git trees: upstream linux-2.6 (Linus's tree), sound-2.6 (upstream ALSA kernel tree), ubuntu-lucid
[22:24] <crimsun> After ensuring that you have the prerequisites above installed, you'll do:
[22:24] <crimsun> git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6.git
[22:25] <crimsun> then:
[22:25] <crimsun> git clone --referenc linux-2.6.git/ git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git
[22:25] <crimsun> sorry, that's --reference
[22:26] <crimsun> then: git clone --reference linux-2.6.git/ git://kernel.ubuntu.com/ubuntu/ubuntu-lucid.git
[22:27] <crimsun> Let's look at examples in the meantime (if you're waiting for them to complete)
[22:28] <apparle> crimsun: can I interrupt
[22:28] <crimsun> https://bugs.launchpad.net/bugs/487884
[22:28] <ubot2> Launchpad bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed]
[22:28] <ubot2> Ubuntu bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed] https://launchpad.net/bugs/487884
[22:28] <ubot2> Launchpad bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed] https://launchpad.net/bugs/487884
[22:29] <crimsun> apparle: can it wait for about 10 minutes?
[22:29] <apparle> crimsun: no problem...
[22:30] <crimsun> apparle: thanks
[22:30] <crimsun> So, some background:
[22:30] <crimsun> there are a lot of AC'97 codecs that need some sort of quirk applied
[22:31] <crimsun> About four to five years ago, I spent a good long while getting the most common ones applied
[22:32] <crimsun> Those were mostly binding of 'Master' and 'Headphone' mixer controls and binding 'Headphone' to an indicator LED (for mute status)
[22:32] <crimsun> These days, for AC'97, we'll see a few stragglers that need inverted external amplifier power down (EAPD) applied
[22:33] <crimsun> This symptom most frequently manifests itself in needing 'External Amplifier' to be muted for sound to be audible.
[22:33] <crimsun> There's an existing quirk for this called inv_eapd
[22:34] <crimsun> If you were to pass this option on the command line or in /etc/modprobe.d/alsa-base.conf, it would look similar to:
[22:34] <crimsun> ac97_quirk=inv_eapd
[22:34] <crimsun> e.g., modprobe snd-intel8x0 ac97_quirk=inv_eapd
[22:35] <crimsun> [after which point you could use 'External Amplifier' being unmuted for sound to be audible, which is the accepted norm]
[22:36] <crimsun> most AC'97 quirks live in their respective drivers
[22:37] <crimsun> the three most common ones are sound/pci/intel8x0.c, sound/pci/atiixp.c, and sound/pci/via82xx.c [though there are numerous others in sound/pci/]
[22:37] <crimsun> so, for bug 487884, we're looking specifically at applying this quirk
[22:37] <ubot2> Launchpad bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed] https://launchpad.net/bugs/487884
[22:37] <ubot2> Launchpad bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed] https://launchpad.net/bugs/487884
[22:37] <ubot2> Launchpad bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed]
[22:37] <ubot2> Ubuntu bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed] https://launchpad.net/bugs/487884
[22:38] <crimsun> http://launchpadlibrarian.net/36040747/Card0.Codecs.codec97.0.ac97.0.0.txt has the important information
[22:39] <crimsun> Namely, we need the PCI SSID, which in this case is 0x161f203a
[22:39] <crimsun> we next look at the source file that needs to be modified, which is sound/pci/intel8x0.c
[22:40] <crimsun> at this point, we should change working directories to wherever we cloned ubuntu-lucid.git
[22:40] <crimsun> next, we'll create a separate branch (some people use topic namespace)
[22:40] <crimsun> $ git checkout -b lp487884
[22:41] <crimsun> then, we'll edit the source file
[22:41] <crimsun> $ $EDITOR sound/pci/intel8x0.c
[22:41] <crimsun> AC'97 quirks live in the ac97_quirks[] struct, and they should be ordered by subvendor ID
[22:42] <crimsun> From this point the addition should be fairly straightforward. Add another stanza, fill in the human-friendly model name, add the quirk type
[22:42] <crimsun> $ git commit -a -e -s
[22:43] <crimsun> The first line of your commit message should briefly describe the change
[22:43] <crimsun> ALSA: intel8x0: Mute External Amplifier by default for Gateway 4525GZ
[22:44] <crimsun> the next line (delimited by a blank line) should be the BugLink id, which is something that is Ubuntu syntax-specific for the kernel team
[22:44] <crimsun> BugLink: https://bugs.launchpad.net/bugs/487884
[22:44] <ubot2> Launchpad bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed]
[22:44] <ubot2> Ubuntu bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed] https://launchpad.net/bugs/487884
[22:44] <ubot2> Launchpad bug 487884 in linux "No sound driver for Gateway 4525GZ" [Low,Fix committed] https://launchpad.net/bugs/487884
[22:44] <crimsun> Next, describe the change:
[22:44] <crimsun> This Gateway model needs External Amplifier muted for audible playback,
[22:44] <crimsun> so set the inv_eapd quirk for it.
[22:45] <crimsun> .
[22:45] <crimsun> Make sure that you keep lines wrapped at 80 characters; many maintainers prefer 72 characters.
[22:46] <crimsun> Finally, if the change is very simple (like this one), then you should submit it to the stable tree so that it ends up in Ubuntu
[22:46] <crimsun> Above your Signed-off-by line you should have:
[22:46] <crimsun> CC: stable@kernel.org
[22:47] <crimsun> .
[22:47] <crimsun> After saving your commit message, the change will be committed, and you can generate a patch to send upstream.
[22:47] <crimsun> There are several ways of doing this, but upstream ALSA likes separate patches.
[22:48] <crimsun> So, we'll use:
[22:48] <crimsun> git format-patch -o ~ master
[22:48] <crimsun> You'll end up with ~/0001-ALSA-...
[22:50] <crimsun> This is the patch that you'll attach to your e-mail message. The e-mail should be sent to alsa-devel@alsa-project.org, with Takashi Iwai and myself CCed
[22:50] <crimsun> And that's pretty much the process for bite-sized fixes.
[22:51] <crimsun> apparle: you're up
[22:51] <apparle> got it clear
[22:51] <apparle> but I am having a problem
[22:51] <apparle> what to do abt this
[22:51] <apparle> git.kernel.org[0: 149.20.20.136]: errno=Connection refused git.kernel.org[0: 199.6.1.166]: errno=Connection refused git.kernel.org[0: 204.152.191.40]: errno=Connection refused git.kernel.org[0: 130.239.17.7]: errno=Connection refused fatal: unable to connect a socket (Connection refused)
[22:52] <apparle> I am behing a stringent firewall(university)
[22:52] <crimsun> apparle: you'll need to use another protocol, then, like http
[22:53] <crimsun> (which is unfortunate, because it's less optimized, but it's one of the few ways to continue if you're behind a firewall)
[22:54] <apparle> Initialized empty Git repository in /home/apparle/linux-2.6.git/.git/ fatal: http://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/info/refs download error - Failed connect to git.kernel.org:80; Operation now in progress
[22:54] <apparle> what to do?
[22:55] <crimsun> apparle: firewalls are a bit beyond the scope of this discussion
[22:55] <crimsun> in brief, see git-clone(1)'s "GIT URLS" section for a description
[22:56] <apparle> crimsun: you mean in the man page?
[22:56] <crimsun> apparle: yes
[22:56] <crimsun> Okay, continuing.
[22:57] <crimsun> The next bug we'll consider is no more difficult, but it moves into problematic areas of HDA.
[22:58] <crimsun> In bug 461062, we need to ensure that the reporter's hardware doesn't suffer from distortion when the PCM volume is set to max.
[22:58] <ubot2> Launchpad bug 461062 in linux "0x11d41981 on 0x103c30d8 misreports dB information, needs PCM capped at 0 dB" [Undecided,Fix committed] https://launchpad.net/bugs/461062
[22:58] <ubot2> Launchpad bug 461062 in linux "0x11d41981 on 0x103c30d8 misreports dB information, needs PCM capped at 0 dB" [Undecided,Fix committed]
[22:58] <ubot2> Launchpad bug 461062 in linux "0x11d41981 on 0x103c30d8 misreports dB information, needs PCM capped at 0 dB" [Undecided,Fix committed] https://launchpad.net/bugs/461062
[22:58] <ubot2> Ubuntu bug 461062 in linux "0x11d41981 on 0x103c30d8 misreports dB information, needs PCM capped at 0 dB" [Undecided,Fix committed] https://launchpad.net/bugs/461062
[22:59] <crimsun> To do this, we need to inspect the reporter's HDA codec, which is attached at http://launchpadlibrarian.net/34413094/Card0.Codecs.codec.0.txt
[23:00] <crimsun> So, I'll walk through doing this from the top.
[23:00] <crimsun> Firstly, we need to know which codec patch to modify. That information is given at the beginning of the codec information, so, Analog Devices AD1981
[23:01] <crimsun> When you've triaged enough bugs, you no longer look at the ^Codec line but at the ^Vendor Id line
[23:01] <crimsun> So, knowing that it's an Analog Devices HDA codec, we'll need to look at sound/pci/hda/patch_analog.c
[23:03] <crimsun> Next, we look at the ^Vendor Id line and match it with the entry in the snd_hda_preset_analog[] struct
[23:03] <crimsun> (which is located toward the end of the file)
[23:03] <crimsun> { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
[23:04] <crimsun> so, now we know which function to inspect (patch_ad1981())
[23:04] <crimsun> We need one more piece of information: whether the reporter's hardware is using a specific model quirk.
[23:05] <crimsun> To do that, we look at the ^Subsystem Id in the codec output
[23:05] <crimsun> In this case, it's 0x103c30d8
[23:06] <crimsun> Now, in patch_ad1981(), ad1981_cfg_tbl[] is used to see if any quirks are necessary
[23:07] <crimsun> So we scroll up in the source file to it, and we see that there's a vendor mask already applied:
[23:07] <crimsun> SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
[23:07] <crimsun> This tells us that we need to look at the AD1981_HP model quirk in patch_ad1981()
[23:07] <crimsun> So we return to patch_ad1981() and look at the section for that model.
[23:08] <crimsun> Sure enough, there's no existing cap being set for that model.
[23:08] <crimsun> Next, we verify our finding again by looking at the codec output
[23:10] <crimsun> To do this, we need to look a bit more closely at the pin routing. So, back to the source file, where we look for the mixer setup for the AD1981_HP model quirk
[23:10] <crimsun> mixer setups are of type struct snd_kcontrol_new
[23:11] <crimsun> so we're looking at ad1981_hp_mixers[]
[23:11] <crimsun> Next, find the PCM Playback elements
[23:11] <crimsun> The brief version, without referring to the AD1981 data sheet, is that we're looking at the 0x11 node id
[23:12] <crimsun> So, go back to the codec output and look at Node 0x11
[23:13] <crimsun> The critical piece of information is in:
[23:13] <crimsun> Amp-Out caps: ofs=0x17, nsteps=0x1f,
[23:13] <crimsun> so, we need to override the amp setup by using snd_hda_override_amp_caps()
[23:14] <crimsun> note that 0x1f will give distortion over and beyond 0x17
[23:14] <crimsun> so we need to cap the nsteps at the offset value
[23:14] <crimsun> (the offset value is known as 0 dB)
[23:15] <crimsun> so, this function ends up looking like:
[23:15] <crimsun>                 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
[23:15] <crimsun>                                           (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
[23:15] <crimsun>                                           (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
[23:15] <crimsun>                                           (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
[23:15] <crimsun>                                           (1 << AC_AMPCAP_MUTE_SHIFT));
[23:16] <crimsun> so we take this addition, put it in the AD1981_HP case of patch_ad1981(), commit the change, and so on.
[23:16] <crimsun> (to complicate things, you can also do this from alsactl init, but that's a story for another day)
[23:17] <crimsun> For the sake of time, I'm going to skip the powerdown stuff and just send an e-mail to ubuntu-devel@ .
[23:17] <crimsun> Anyhow, that's it.