From f0045eb373c5376510d111c5e1091134c186884e Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Sat, 29 Jun 2019 14:06:30 +0800 Subject: autoport: search for the HDA device on PCH Haswell has its Mini-HD device and is at card0, so we need to search for the PCH HD Audio device instead of using card0. Change-Id: I2bc420fdbe9731ae835f63add85db79f04201da4 Signed-off-by: Iru Cai --- util/autoport/log_maker.go | 74 +++++++++++++++++++++++++++++---------------- util/autoport/log_reader.go | 15 ++++++++- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/util/autoport/log_maker.go b/util/autoport/log_maker.go index 08b35d2195..2a524d387a 100644 --- a/util/autoport/log_maker.go +++ b/util/autoport/log_maker.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "strings" + "bytes" ) func TryRunAndSave(output string, name string, arg []string) error { @@ -74,30 +75,8 @@ func PromptUser(prompt string, opts []string) (match string, err error) { return } -func MakeLogs(outDir string) { - os.MkdirAll(outDir, 0700) - RunAndSave(outDir+"/lspci.log", "lspci", "-nnvvvxxxx") - RunAndSave(outDir+"/dmidecode.log", "dmidecode") - RunAndSave(outDir+"/acpidump.log", "acpidump") - - inteltoolArgs := "-a" - opt, err := PromptUser("WARNING: The following tool MAY cause your system to hang when it attempts "+ - "to probe for graphics registers. Having the graphics registers will help create a better port. "+ - "Should autoport probe these registers?", - []string{"y", "yes", "n", "no"}) - - // Continue even if there is an error - - switch opt { - case "y", "yes": - inteltoolArgs += "f" - } - - RunAndSave(outDir+"/inteltool.log", "../inteltool/inteltool", inteltoolArgs) - RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-pd") - RunAndSave(outDir+"/superiotool.log", "../superiotool/superiotool", "-ade") - - SysDir := "/sys/class/sound/card0/" +func MakeHDALogs(outDir string, cardName string) { + SysDir := "/sys/class/sound/" + cardName + "/" files, _ := ioutil.ReadDir(SysDir) for _, f := range files { if (strings.HasPrefix(f.Name(), "hw") || strings.HasPrefix(f.Name(), "hdaudio")) && f.IsDir() { @@ -115,7 +94,7 @@ func MakeLogs(outDir string) { } } - ProcDir := "/proc/asound/card0/" + ProcDir := "/proc/asound/" + cardName + "/" files, _ = ioutil.ReadDir(ProcDir) for _, f := range files { if strings.HasPrefix(f.Name(), "codec#") && !f.IsDir() { @@ -132,6 +111,49 @@ func MakeLogs(outDir string) { io.Copy(out, in) } } +} + +func MakeLogs(outDir string) { + os.MkdirAll(outDir, 0700) + RunAndSave(outDir+"/lspci.log", "lspci", "-nnvvvxxxx") + RunAndSave(outDir+"/dmidecode.log", "dmidecode") + RunAndSave(outDir+"/acpidump.log", "acpidump") + + inteltoolArgs := "-a" + opt, err := PromptUser("WARNING: The following tool MAY cause your system to hang when it attempts "+ + "to probe for graphics registers. Having the graphics registers will help create a better port. "+ + "Should autoport probe these registers?", + []string{"y", "yes", "n", "no"}) + + // Continue even if there is an error + + switch opt { + case "y", "yes": + inteltoolArgs += "f" + } + + RunAndSave(outDir+"/inteltool.log", "../inteltool/inteltool", inteltoolArgs) + RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-pd") + RunAndSave(outDir+"/superiotool.log", "../superiotool/superiotool", "-ade") + + SysSound := "/sys/class/sound/" + card := "" + cards, _ := ioutil.ReadDir(SysSound) + for _, f := range cards { + if strings.HasPrefix(f.Name(), "card") { + cid, err := ioutil.ReadFile(SysSound + f.Name() + "/id") + if err == nil && bytes.Equal(cid, []byte("PCH\n")) { + fmt.Fprintln(os.Stderr, "PCH sound card is", f.Name()) + card = f.Name() + } + } + } + + if card != "" { + MakeHDALogs(outDir, card) + } else { + fmt.Fprintln(os.Stderr, "HDAudio not found on PCH.") + } for _, fname := range []string{"cpuinfo", "ioports"} { in, err := os.Open("/proc/" + fname) @@ -154,7 +176,7 @@ func MakeLogs(outDir string) { defer out.Close() ClassInputDir := "/sys/class/input/" - files, _ = ioutil.ReadDir(ClassInputDir) + files, _ := ioutil.ReadDir(ClassInputDir) for _, f := range files { if strings.HasPrefix(f.Name(), "input") && !f.Mode().IsRegular() { /* Allow both dirs and symlinks. */ in, err := os.Open(ClassInputDir + f.Name() + "/id/bustype") diff --git a/util/autoport/log_reader.go b/util/autoport/log_reader.go index 0aaf6a9db3..b144804c28 100644 --- a/util/autoport/log_reader.go +++ b/util/autoport/log_reader.go @@ -251,6 +251,18 @@ func (l *LogDevReader) GetDMI() (ret DMIData) { } func (l *LogDevReader) GetAzaliaCodecs() (ret []AzaliaCodec) { + cardno := -1 + for i := 0; i < 10; i++ { + pin, err := os.Open(l.InputDirectory + "/pin_hwC" + strconv.Itoa(i) + "D0") + if err == nil { + pin.Close() + cardno = i + break + } + } + if cardno == -1 { + return + } for codecno := 0; codecno < 10; codecno++ { cur := AzaliaCodec{CodecNo: codecno, PinConfig: map[int]uint32{}} codec, err := os.Open(l.InputDirectory + "/codec#" + strconv.Itoa(codecno)) @@ -258,7 +270,8 @@ func (l *LogDevReader) GetAzaliaCodecs() (ret []AzaliaCodec) { continue } defer codec.Close() - pin, err := os.Open(l.InputDirectory + "/pin_hwC0D" + strconv.Itoa(codecno)) + pin, err := os.Open(l.InputDirectory + "/pin_hwC" + strconv.Itoa(cardno) + + "D" + strconv.Itoa(codecno)) if err != nil { continue } -- cgit v1.2.3