#!/bin/bash # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2023-present BrooksyTech (https://github.com/brooksytech) . /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 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_HP} amixer set 'Headphone' '67%' amixer set 'Playback Polarity' Normal set_setting "audio.device" "headphone" ;; *) amixer cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_SPK} amixer set 'Headphone' '100%' amixer 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 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_HP} amixer set 'Headphone' '67%' amixer set 'Playback Polarity' Normal set_setting "audio.device" "headphone" ;; (${HP_OFF}) amixer cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_SPK} amixer set 'Headphone' '100%' amixer set 'Playback Polarity' 'R Invert' set_setting "audio.device" "speakers" ;; esac done