2023-07-06 15:36:07 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2023-07-06 22:59:41 +00:00
|
|
|
# Copyright (C) 2023-present BrooksyTech (https://github.com/brooksytech)
|
2023-07-06 15:36:07 +00:00
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
|
2023-07-09 13:47:11 +00:00
|
|
|
# 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
|
|
|
|
|
2023-07-06 15:36:07 +00:00
|
|
|
# Headphone sensing
|
|
|
|
DEVICE="${DEVICE_HEADPHONE_DEV}"
|
|
|
|
|
2023-07-06 22:59:41 +00:00
|
|
|
HP_OFF='*(SW_HEADPHONE_INSERT), value 0*'
|
|
|
|
HP_ON='*(SW_HEADPHONE_INSERT), value 1*'
|
2023-07-06 15:36:07 +00:00
|
|
|
|
|
|
|
evtest "${DEVICE}" | while read line; do
|
|
|
|
case $line in
|
|
|
|
(${HP_ON})
|
2023-07-09 13:47:11 +00:00
|
|
|
amixer cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_HP}
|
|
|
|
amixer set 'Headphone' '67%'
|
|
|
|
amixer set 'Playback Polarity' Normal
|
|
|
|
set_setting "audio.device" "headphone"
|
2023-07-06 15:36:07 +00:00
|
|
|
;;
|
|
|
|
(${HP_OFF})
|
2023-07-09 13:47:11 +00:00
|
|
|
amixer cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_SPK}
|
|
|
|
amixer set 'Headphone' '100%'
|
|
|
|
amixer set 'Playback Polarity' 'R Invert'
|
|
|
|
set_setting "audio.device" "speakers"
|
2023-07-06 15:36:07 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|