• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7# Collect information about the audio system from top to bottom.
8
9dump_cards() {
10    # shellcheck disable=SC2068
11    for card in ${@}
12    do
13        echo "=== amixer -c ${card} scontents ==="
14        amixer -c "${card}" scontents
15        echo "=== amixer -c ${card} contents ==="
16        amixer -c "${card}" contents
17    done
18}
19
20# Helper function: in_the_list $1 $2
21# Returns 0 if str $1 is included in delimited str $2; otherwise 1
22in_the_list() {
23    for item in $2
24    do
25        if [ "$1" = "${item}" ]; then
26            return 0
27        fi
28    done
29    return 1
30}
31
32echo '=== cras_test_client --dump_server_info ==='
33cras_test_client --dump_server_info
34
35echo '=== cras_test_client --dump_audio_thread ==='
36cras_test_client --dump_audio_thread
37
38echo '=== cras_test_client --dump_main ==='
39cras_test_client --dump_main
40
41echo '=== cras_test_client --dump_bt ==='
42cras_test_client --dump_bt
43
44echo '=== cras_test_client --dump_events ==='
45cras_test_client --dump_events
46
47echo '=== aplay -l ==='
48aplay -l
49echo '=== arecord -l ==='
50arecord -l
51
52output_cards=$(
53    aplay -l | grep -E ^card | sed 's/card \([0-9]\+\).*/\1/' | sort -u)
54dump_cards "${output_cards}"
55
56input_cards=$(
57    arecord -l | grep -E ^card | sed 's/card \([0-9]\+\).*/\1/' | sort -u)
58dump_cards "${input_cards}"
59
60# HDA codec for codecs on x86.
61codecs=$(find /proc/asound -mindepth 2 -maxdepth 2 -path '*card*/codec#*')
62for codec in ${codecs}
63do
64    echo "=== codec: ${codec} ==="
65    cat "${codec}"
66done
67
68# I2C dump for codecs on arm.
69# Find lines like "max98088.7-0010" and extract "7 0x0010" from it.
70if [ -e /sys/kernel/debug/asoc/codecs ]; then
71    sed_expr='s/^\([^.-]\+\)\.\([0-9]\+\)-\([0-9]\+\)$/\2 0x\3/p'
72    sed -n "${sed_expr}" /sys/kernel/debug/asoc/codecs |
73    while read -r i2c_addr
74    do
75        echo "=== i2cdump -f -y ${i2c_addr} ==="
76        i2cdump -f -y "${i2c_addr}"
77    done
78fi
79
80# Dump registers from regmaps
81
82# List of audio components
83# For kernel>=4.14, it is in /sys/kernel/debug/asoc/components
84# For kernel<4.14, it is in /sys/kernel/debug/asoc/codecs
85if [ -f /sys/kernel/debug/asoc/components ]; then
86    audio_comps=$(cat /sys/kernel/debug/asoc/components)
87else
88    audio_comps=$(cat /sys/kernel/debug/asoc/codecs)
89fi
90
91# Blocklist regmap name of dumping registers (tracked by b/154177454)
92# Use the blank space as delimiter, e.g. 'name_a name_b name_c'
93name_blocklist='snd_hda_codec_hdmi'
94
95for file_path in /sys/kernel/debug/regmap/*
96do
97    [ -e "${file_path}" ] || break  # handle the case of no files
98    component=$(basename "${file_path}")
99
100    # Skip dumping registers if component is not listed in audio_comps
101    if ! in_the_list "${component}" "${audio_comps}"; then
102        continue
103    fi
104
105    if [ ! -f "${file_path}/name" ]; then
106        echo "Failed at dump registers: ${file_path}"
107        continue
108    fi
109
110    name=$(cat "${file_path}/name")
111    echo "=== dump registers component: ${component} name: ${name} ==="
112
113    # Skip dumping registers if regmap's name is in name_blocklist
114    if in_the_list "${name}" "${name_blocklist}"; then
115        echo 'skipped dumping due to b/154177454'
116        continue
117    fi
118
119    # Store back the original value
120    # Note: $(cat cache_bypass) returns 'Y' if flag is on; otherwise 'N'
121    cache_bypass=$(cat "${file_path}/cache_bypass")
122    if [ "${cache_bypass}" = "N" ]; then
123        echo 1 > "${file_path}/cache_bypass"
124    fi
125    cat "${file_path}/registers"
126    if [ "${cache_bypass}" = "N" ]; then
127        echo 0 > "${file_path}/cache_bypass"
128    fi
129done
130