alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* hda-jack-sense-test
@ 2011-05-16 15:40 David Henningsson
  0 siblings, 0 replies; only message in thread
From: David Henningsson @ 2011-05-16 15:40 UTC (permalink / raw)
  To: ALSA Development Mailing List, ubuntu-audio-dev

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]

Just a little something I wrote on the train back home yesterday. I hope 
someone finds it a nice way to figure out if your BIOS is lying to you 
about what pin is used for what. It (re)uses some of the classes in 
hda-analyzer.

For Ubuntu 11.04 users, this small tool is now packaged together with 
codecgraph, hda-verb, hda-emu and hda-analyzer in my snd-hda-tools 
package, which is available in ppa:diwic/ppa.


-- 
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic

[-- Attachment #2: hda-jack-sense-test.py --]
[-- Type: text/x-python, Size: 1968 bytes --]

#!/usr/bin/env python
#
# Written by David Henningsson, Copyright 2011 Canonical Ltd. 
# Licensed under GPLv2+

# the hda_codec.py file comes from Jaroslav Kysela's hda_analyzer program.
from hda_codec import *


def parseoptions():
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-c", "--card", dest="cardindex", default=0, metavar="CARD",
        help="card index (as can be seen in /proc/asound/cards)")
    parser.add_option("-d", "--codec", dest="codecindex", default=0, metavar="CODEC",
        help="codec device index (as can be seen in /proc/asound/cardX/codecY)")
    parser.add_option("-a", "--allpins", dest="tryallpins", default=False,
        action="store_true",
        help="also check pins which (probably) are not physical jacks")
    (options, args) = parser.parse_args()
    return int(options.cardindex), int(options.codecindex), options.tryallpins
    
def should_check_presence(node, tryallpins):
    if WIDGET_TYPE_IDS[node.wtype] != 'PIN':
        return False
    if tryallpins:
        return True
    conn_type = (node.defcfg_pincaps >> 30) & 0x03
    if conn_type != 0: # Not a Jack
        return False
    if node.defcfg_pincaps & (1 << 8): # Jack has NO_PRESENCE set
        return False     
    return True

def get_simplecaps(node):
    conn_type = (node.defcfg_pincaps >> 30) & 0x03
    if conn_type == 1: # N/A
        return 'Not connected'
    if conn_type == 0: # Jack
        return "%s %s" % (node.jack_color_name, node.jack_type_name)
    return "Internal %s" % node.jack_type_name

cardindex, codecindex, tryallpins = parseoptions()
codec = HDACodec(cardindex, codecindex)
codec.analyze()
for nid in codec.nodes:
    node = codec.get_node(nid)
    if not should_check_presence(node, tryallpins):
        continue
    present = codec.rw(nid, VERBS['GET_PIN_SENSE'], 0) & 0x80000000
    print "Pin 0x%.2x (%s): present = %s" % (nid, get_simplecaps(node), "Yes" if present else "No")


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-16 15:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-16 15:40 hda-jack-sense-test David Henningsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).