#!/bin/bash # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2022-present JELOS (https://github.com/JustEnoughLinuxOS) . /etc/profile # Check headphone gpio at boot and set the correct output device HP_GPIO=$(cat /sys/class/gpio/gpio${DEVICE_JACK}/value) case ${HP_GPIO} in "1") amixer -c 0 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_HP} amixer -c 0 set 'Headphone' '67%' amixer -c 0 set 'Playback Polarity' Normal set_setting "audio.device" "headphone" ;; *) amixer -c 0 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_SPK} amixer -c 0 set 'Headphone' '100%' amixer -c 0 set 'Playback Polarity' 'R Invert' set_setting "audio.device" "speakers" ;; esac # Headphone sensing DEVICE="${DEVICE_HEADPHONE_DEV}" HP_OFF='*(SW_HEADPHONE_INSERT), value 0*' HP_ON='*(SW_HEADPHONE_INSERT), value 1*' evtest "${DEVICE}" | while read line; do case $line in (${HP_ON}) amixer -c 0 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_HP} amixer -c 0 set 'Headphone' '67%' amixer -c 0 set 'Playback Polarity' Normal set_setting "audio.device" "headphone" ;; (${HP_OFF}) amixer -c 0 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_SPK} amixer -c 0 set 'Headphone' '100%' amixer -c 0 set 'Playback Polarity' 'R Invert' set_setting "audio.device" "speakers" ;; esac done