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 <mytbk920423@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34357
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Iru Cai 2019-06-29 14:06:30 +08:00 committed by Felix Held
parent ab5cac2c79
commit 112e9baddf
2 changed files with 67 additions and 32 deletions

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"bytes"
) )
func TryRunAndSave(output string, name string, arg []string) error { func TryRunAndSave(output string, name string, arg []string) error {
@ -74,6 +75,44 @@ func PromptUser(prompt string, opts []string) (match string, err error) {
return return
} }
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() {
in, err := os.Open(SysDir + f.Name() + "/init_pin_configs")
defer in.Close()
if err != nil {
log.Fatal(err)
}
out, err := os.Create(outDir + "/pin_" + strings.Replace(f.Name(), "hdaudio", "hw", -1))
if err != nil {
log.Fatal(err)
}
defer out.Close()
io.Copy(out, in)
}
}
ProcDir := "/proc/asound/" + cardName + "/"
files, _ = ioutil.ReadDir(ProcDir)
for _, f := range files {
if strings.HasPrefix(f.Name(), "codec#") && !f.IsDir() {
in, err := os.Open(ProcDir + f.Name())
defer in.Close()
if err != nil {
log.Fatal(err)
}
out, err := os.Create(outDir + "/" + f.Name())
if err != nil {
log.Fatal(err)
}
defer out.Close()
io.Copy(out, in)
}
}
}
func MakeLogs(outDir string) { func MakeLogs(outDir string) {
os.MkdirAll(outDir, 0700) os.MkdirAll(outDir, 0700)
RunAndSave(outDir+"/lspci.log", "lspci", "-nnvvvxxxx") RunAndSave(outDir+"/lspci.log", "lspci", "-nnvvvxxxx")
@ -97,40 +136,23 @@ func MakeLogs(outDir string) {
RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-pd") RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-pd")
RunAndSave(outDir+"/superiotool.log", "../superiotool/superiotool", "-ade") RunAndSave(outDir+"/superiotool.log", "../superiotool/superiotool", "-ade")
SysDir := "/sys/class/sound/card0/" SysSound := "/sys/class/sound/"
files, _ := ioutil.ReadDir(SysDir) card := ""
for _, f := range files { cards, _ := ioutil.ReadDir(SysSound)
if (strings.HasPrefix(f.Name(), "hw") || strings.HasPrefix(f.Name(), "hdaudio")) && f.IsDir() { for _, f := range cards {
in, err := os.Open(SysDir + f.Name() + "/init_pin_configs") if strings.HasPrefix(f.Name(), "card") {
defer in.Close() cid, err := ioutil.ReadFile(SysSound + f.Name() + "/id")
if err != nil { if err == nil && bytes.Equal(cid, []byte("PCH\n")) {
log.Fatal(err) fmt.Fprintln(os.Stderr, "PCH sound card is", f.Name())
card = f.Name()
} }
out, err := os.Create(outDir + "/pin_" + strings.Replace(f.Name(), "hdaudio", "hw", -1))
if err != nil {
log.Fatal(err)
}
defer out.Close()
io.Copy(out, in)
} }
} }
ProcDir := "/proc/asound/card0/" if card != "" {
files, _ = ioutil.ReadDir(ProcDir) MakeHDALogs(outDir, card)
for _, f := range files { } else {
if strings.HasPrefix(f.Name(), "codec#") && !f.IsDir() { fmt.Fprintln(os.Stderr, "HDAudio not found on PCH.")
in, err := os.Open(ProcDir + f.Name())
defer in.Close()
if err != nil {
log.Fatal(err)
}
out, err := os.Create(outDir + "/" + f.Name())
if err != nil {
log.Fatal(err)
}
defer out.Close()
io.Copy(out, in)
}
} }
for _, fname := range []string{"cpuinfo", "ioports"} { for _, fname := range []string{"cpuinfo", "ioports"} {
@ -154,7 +176,7 @@ func MakeLogs(outDir string) {
defer out.Close() defer out.Close()
ClassInputDir := "/sys/class/input/" ClassInputDir := "/sys/class/input/"
files, _ = ioutil.ReadDir(ClassInputDir) files, _ := ioutil.ReadDir(ClassInputDir)
for _, f := range files { for _, f := range files {
if strings.HasPrefix(f.Name(), "input") && !f.Mode().IsRegular() { /* Allow both dirs and symlinks. */ if strings.HasPrefix(f.Name(), "input") && !f.Mode().IsRegular() { /* Allow both dirs and symlinks. */
in, err := os.Open(ClassInputDir + f.Name() + "/id/bustype") in, err := os.Open(ClassInputDir + f.Name() + "/id/bustype")

View File

@ -251,6 +251,18 @@ func (l *LogDevReader) GetDMI() (ret DMIData) {
} }
func (l *LogDevReader) GetAzaliaCodecs() (ret []AzaliaCodec) { 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++ { for codecno := 0; codecno < 10; codecno++ {
cur := AzaliaCodec{CodecNo: codecno, PinConfig: map[int]uint32{}} cur := AzaliaCodec{CodecNo: codecno, PinConfig: map[int]uint32{}}
codec, err := os.Open(l.InputDirectory + "/codec#" + strconv.Itoa(codecno)) codec, err := os.Open(l.InputDirectory + "/codec#" + strconv.Itoa(codecno))
@ -258,7 +270,8 @@ func (l *LogDevReader) GetAzaliaCodecs() (ret []AzaliaCodec) {
continue continue
} }
defer codec.Close() 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 { if err != nil {
continue continue
} }