1c72fcc34Sopenharmony_ci#!/bin/bash
2c72fcc34Sopenharmony_ci
3c72fcc34Sopenharmony_ci#/*
4c72fcc34Sopenharmony_ci# * Copyright (C) 2013-2016 Intel Corporation
5c72fcc34Sopenharmony_ci# *
6c72fcc34Sopenharmony_ci# * This program is free software; you can redistribute it and/or modify
7c72fcc34Sopenharmony_ci# * it under the terms of the GNU General Public License as published by
8c72fcc34Sopenharmony_ci# * the Free Software Foundation; either version 2 of the License, or
9c72fcc34Sopenharmony_ci# * (at your option) any later version.
10c72fcc34Sopenharmony_ci# *
11c72fcc34Sopenharmony_ci# * This program is distributed in the hope that it will be useful,
12c72fcc34Sopenharmony_ci# * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c72fcc34Sopenharmony_ci# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14c72fcc34Sopenharmony_ci# * GNU General Public License for more details.
15c72fcc34Sopenharmony_ci# *
16c72fcc34Sopenharmony_ci# */
17c72fcc34Sopenharmony_ci#set -x
18c72fcc34Sopenharmony_ci
19c72fcc34Sopenharmony_cisubdevice_number=0
20c72fcc34Sopenharmony_ciget_subdevice=0
21c72fcc34Sopenharmony_ci
22c72fcc34Sopenharmony_ci#make sure the HDMI monitor is connected and active ########
23c72fcc34Sopenharmony_ci
24c72fcc34Sopenharmony_ci# To get HDMI audio device number
25c72fcc34Sopenharmony_cicard_number=$(aplay -l | grep "HDMI 0" | cut -b 6)
26c72fcc34Sopenharmony_ciif [ "$card_number" = "" ]; then
27c72fcc34Sopenharmony_ci	echo "Can not get Display audio card."
28c72fcc34Sopenharmony_ci	#failed to get Display audio card.
29c72fcc34Sopenharmony_ci	exit 1
30c72fcc34Sopenharmony_cifi
31c72fcc34Sopenharmony_ci
32c72fcc34Sopenharmony_ciaudio_card_dir="/proc/asound/card$card_number/"
33c72fcc34Sopenharmony_ci
34c72fcc34Sopenharmony_cicd $audio_card_dir
35c72fcc34Sopenharmony_cifor file in `ls`
36c72fcc34Sopenharmony_ci	do
37c72fcc34Sopenharmony_ci		#To get the ELD information according to the connented monitor with HDMI
38c72fcc34Sopenharmony_ci		if [[ $file == eld* ]]; then
39c72fcc34Sopenharmony_ci			let subdevice_number+=1
40c72fcc34Sopenharmony_ci			cat $file | grep connection_type | grep HDMI > /dev/null
41c72fcc34Sopenharmony_ci			if [ $? = 0 ]; then
42c72fcc34Sopenharmony_ci				get_subdevice=1
43c72fcc34Sopenharmony_ci				break
44c72fcc34Sopenharmony_ci			fi
45c72fcc34Sopenharmony_ci		fi
46c72fcc34Sopenharmony_ci	done
47c72fcc34Sopenharmony_ci
48c72fcc34Sopenharmony_ci#failed to get the subdevice number of HDMI audio.
49c72fcc34Sopenharmony_ciif [ $get_subdevice == 0 ]; then
50c72fcc34Sopenharmony_ci	exit 77
51c72fcc34Sopenharmony_cifi
52c72fcc34Sopenharmony_ci
53c72fcc34Sopenharmony_ci#the subdevice number of HDMI audio is 3.
54c72fcc34Sopenharmony_ciif [ $subdevice_number == 1 ]; then
55c72fcc34Sopenharmony_ci	exit 3
56c72fcc34Sopenharmony_ci#the subdevice number of HDMI audio is 7.
57c72fcc34Sopenharmony_cielif [ $subdevice_number == 2 ]; then
58c72fcc34Sopenharmony_ci	exit 7
59c72fcc34Sopenharmony_ci#the subdevice number of HDMI audio is 8.
60c72fcc34Sopenharmony_cielif [ $subdevice_number == 3 ]; then
61c72fcc34Sopenharmony_ci	exit 8
62c72fcc34Sopenharmony_ci#default: failed to get the subdevice number of HDMI audio.
63c72fcc34Sopenharmony_cielse
64c72fcc34Sopenharmony_ci	exit 77
65c72fcc34Sopenharmony_cifi
66