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    for card in ${@}
11    do
12        echo '=== amixer -c' $card scontents '==='
13        amixer -c $card scontents
14        echo '=== amixer -c' $card contents '==='
15        amixer -c $card contents
16    done
17}
18
19echo '=== cras_test_client --dump_server_info ==='
20cras_test_client --dump_server_info
21
22echo '=== cras_test_client --dump_audio_thread ==='
23cras_test_client --dump_audio_thread
24
25echo '=== aplay -l ==='
26aplay -l
27echo '=== arecord -l ==='
28arecord -l
29
30output_cards=$(aplay -l | egrep ^card | sed 's/card \([0-9]\+\).*/\1/' | sort -u)
31dump_cards $output_cards
32
33input_cards=$(arecord -l | egrep ^card | sed 's/card \([0-9]\+\).*/\1/' | sort -u)
34dump_cards $input_cards
35
36# HDA codec for codecs on x86.
37codecs=$(find /proc/asound -mindepth 2 -maxdepth 2 -path '*card*/codec#*')
38for codec in $codecs
39do
40    echo '=== codec:' $codec '==='
41    cat $codec
42done
43
44# I2C dump for codecs on arm.
45# Find lines like "max98088.7-0010" and extract "7 0x0010" from it.
46if [ -e /sys/kernel/debug/asoc/codecs ]; then
47    sed_expr='s/^\([^.-]\+\)\.\([0-9]\+\)-\([0-9]\+\)$/\2 0x\3/p'
48    sed -n "$sed_expr" /sys/kernel/debug/asoc/codecs |
49    while read i2c_addr
50    do
51        echo '===' i2cdump -f -y $i2c_addr '==='
52        i2cdump -f -y $i2c_addr
53    done
54fi
55