bluetooth-init: bluetooth-init_btbcm_hciuart: optimize script

Optimize the script to remove unneeded code.
As the BT_REG_ON is managed by the driver, the REG_POWER_ON is not
needed at all.
Loading the hci_uart pulls btbcm, so no need to load it explicitly.

https://onedigi.atlassian.net/browse/DEL-9949

Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
This commit is contained in:
Isaac Hermida 2026-01-23 12:22:38 +01:00
parent 3408f8c4ed
commit 865ca174c9
1 changed files with 10 additions and 31 deletions

View File

@ -18,20 +18,6 @@ RETRIES=3
HCI_IFACE="hci0"
MODULE_NAME="hci_uart"
if grep -qs '\<digi,ccmp13\>' /proc/device-tree/compatible; then
# CCMP13 - BT_REG_EN - GPIO PD13
GPIO_CHIP="GPIOD"
GPIO_NUMBER="13"
elif grep -qs '\<digi,ccmp15\>' /proc/device-tree/compatible; then
# CCMP15 - BT_REG_EN - GPIO PZ6
GPIO_CHIP="GPIOZ"
GPIO_NUMBER="6"
elif grep -qs '\<digi,ccimx95\>' /proc/device-tree/compatible; then
# CCIMX95
GPIO_CHIP="1"
GPIO_NUMBER="18"
fi
log() {
if type "systemd-cat" >/dev/null 2>/dev/null; then
systemd-cat -p "${1}" -t "${SCRIPTNAME}" printf "%s" "${2}"
@ -40,20 +26,16 @@ log() {
fi
}
bt_power() {
gpioset "${GPIO_CHIP}" "${GPIO_NUMBER}"="${1}"
}
set_btaddr() {
hciconfig hci0 up
hciconfig ${HCI_IFACE} up
sleep 0.2
bt_addr=$(hexdump -v -e '1/1 "%02X "' /proc/device-tree/bluetooth/mac-address \
| awk '{ for(i=NF; i>0; i--) printf "0x%s ", $i }' \
| sed 's/ $//')
hcitool -i hci0 cmd 0x3f 0x0001 ${bt_addr}
hciconfig hci0 down
hcitool -i ${HCI_IFACE} cmd 0x3f 0x0001 ${bt_addr}
hciconfig ${HCI_IFACE} down
sleep 0.2
hciconfig hci0 up
hciconfig ${HCI_IFACE} up
}
is_kernel_module_loaded() {
@ -65,18 +47,16 @@ bt_init() {
is_kernel_module_loaded && log info "kernel module already present, skipping" && return 1
for i in $(seq ${RETRIES}); do
# Perform a power cycle
bt_power 0
sleep 0.5
bt_power 1
# Load manually the kernel module
modprobe "${MODULE_NAME}"
sleep 1
# Reconfigure the HCI interface with the expected MAC address
is_kernel_module_loaded && set_btaddr && log info "Bluetooth activated" && return 0
bt_stop
log err "Cannot initialize Bluetooth, retrying..."
if [ "$i" -lt "$RETRIES" ]; then
log err "Cannot initialize Bluetooth, retrying..."
fi
done
log err "Failed to initialize Bluetooth interface"
@ -86,10 +66,9 @@ bt_init() {
bt_stop() {
hciconfig ${HCI_IFACE} down
# Unload HCI driver instance
rmmod hci_uart
rmmod "${MODULE_NAME}"
rmmod btbcm
# Disable Bluetooth chip
bt_power 0 && log info "Bluetooth disabled" && return 0
log info "Bluetooth disabled"
}
case "$1" in