mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
dectmngr: Determine UART from device tree
Instead of hardcoding it, determine UART device to use for communication with the DCX81 DECT chip using an alias in the device-tree /aliases/dcx81-uart. Also use the existence of the alias as an indicator of whether the device supports DECT instead of checking for hw.board.hasDect in board-db. Signed-off-by: Andreas Gnau <andreas.gnau@iopsys.eu>
This commit is contained in:
parent
fb324be411
commit
77d1d82a89
1 changed files with 39 additions and 5 deletions
|
|
@ -10,6 +10,7 @@ NAME=dectmngr
|
||||||
PROG=/usr/sbin/dectmngr
|
PROG=/usr/sbin/dectmngr
|
||||||
LOG_PATH=/var/log/dectmngr
|
LOG_PATH=/var/log/dectmngr
|
||||||
DB_PATH=/etc/dect
|
DB_PATH=/etc/dect
|
||||||
|
DCX81_UART_DT_ALIAS=/proc/device-tree/aliases/dcx81-uart
|
||||||
|
|
||||||
DECT_GPIO=$(db -q get hw.board.dect_gpio)
|
DECT_GPIO=$(db -q get hw.board.dect_gpio)
|
||||||
|
|
||||||
|
|
@ -24,13 +25,43 @@ stop_and_wait_dectmngr() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has_dect() {
|
||||||
|
[ -f "$DCX81_UART_DT_ALIAS" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
get_dcx81_device() {
|
||||||
|
readonly dcx81_uart_dt_node="/proc/device-tree/$(cat "$DCX81_UART_DT_ALIAS" 2>/dev/null)"
|
||||||
|
[ -e "$dcx81_uart_dt_node" ] || return 1
|
||||||
|
for tty_dt_node in /sys/class/tty/*/device/of_node; do
|
||||||
|
if [ "$tty_dt_node" -ef "$dcx81_uart_dt_node" ]; then
|
||||||
|
readonly uevent_file="${tty_dt_node%%/device/of_node}/uevent"
|
||||||
|
local device_name_line
|
||||||
|
device_name_line="$(grep '^DEVNAME=' "$uevent_file")" || return 1
|
||||||
|
readonly device="/dev/${device_name_line##DEVNAME=}"
|
||||||
|
[ -c "$device" ] || return 1
|
||||||
|
printf "%s" "$device"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
local opt_ext=
|
local opt_ext=
|
||||||
local rfpi=
|
local rfpi=
|
||||||
local model_id=
|
local model_id=
|
||||||
local rxtun=
|
local rxtun=
|
||||||
|
|
||||||
test $(db get hw.board.hasDect) = "0" && return
|
if ! has_dect; then
|
||||||
|
logger -t "$PROG" "Not starting because no DECT hardware is available."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local dcx81_uart_device
|
||||||
|
if ! dcx81_uart_device="$(get_dcx81_device)"; then
|
||||||
|
logger -t "$PROG" -p daemon.error "Could not determine DCX81 UART device. Cannot start $PROG"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
[ -n "$DECT_GPIO" ] && echo 1 > /sys/class/gpio/gpio${DECT_GPIO}/value
|
[ -n "$DECT_GPIO" ] && echo 1 > /sys/class/gpio/gpio${DECT_GPIO}/value
|
||||||
|
|
||||||
|
|
@ -51,19 +82,22 @@ start_service() {
|
||||||
config_get log_dect_cmbs global log_dect_cmbs syslog
|
config_get log_dect_cmbs global log_dect_cmbs syslog
|
||||||
|
|
||||||
procd_open_instance
|
procd_open_instance
|
||||||
|
|
||||||
|
# dectmngr takes expects device without /dev
|
||||||
|
readonly dcx81_uart_device_wo_dev="${dcx81_uart_device##/dev/}"
|
||||||
case "$log_dect_cmbs" in
|
case "$log_dect_cmbs" in
|
||||||
none)
|
none)
|
||||||
echo "Starting dectmngr with cmbs logging disabled"
|
echo "Starting dectmngr with cmbs logging disabled"
|
||||||
procd_set_param command $PROG -comname ttyH0 $opt_ext
|
procd_set_param command "$PROG" -comname "$dcx81_uart_device_wo_dev" $opt_ext
|
||||||
rm -f $LOG_PATH/*
|
rm -f $LOG_PATH/*
|
||||||
;;
|
;;
|
||||||
file)
|
file)
|
||||||
echo "Starting dectmngr with cmbs logging enabled to file"
|
echo "Starting dectmngr with cmbs logging enabled to file"
|
||||||
procd_set_param command $PROG -comname ttyH0 -log $LOG_PATH/dect-cmbs.log $opt_ext
|
procd_set_param command "$PROG" -comname "$dcx81_uart_device_wo_dev" -log $LOG_PATH/dect-cmbs.log $opt_ext
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Starting dectmngr with cmbs logging enabled to syslog"
|
echo "Starting dectmngr with cmbs logging enabled to syslog"
|
||||||
procd_set_param command $PROG -comname ttyH0 -syslog $opt_ext
|
procd_set_param command "$PROG" -comname "$dcx81_uart_device_wo_dev" -syslog $opt_ext
|
||||||
rm -f $LOG_PATH/*
|
rm -f $LOG_PATH/*
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -75,7 +109,7 @@ start_service() {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_service() {
|
stop_service() {
|
||||||
test $(db get hw.board.hasDect) = "0" && return
|
has_dect || return 0
|
||||||
|
|
||||||
[ -n "$DECT_GPIO" ] && echo 0 > /sys/class/gpio/gpio${DECT_GPIO}/value
|
[ -n "$DECT_GPIO" ] && echo 0 > /sys/class/gpio/gpio${DECT_GPIO}/value
|
||||||
stop_and_wait_dectmngr
|
stop_and_wait_dectmngr
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue