From bc4aaf2237438242a8dc52ff1dfd545cf887e012 Mon Sep 17 00:00:00 2001 From: Isaac Hermida Date: Wed, 12 Jul 2023 10:24:45 +0200 Subject: [PATCH] ccimx93: bluetooth-init: adjust recipes to btnxpuart driver The btnxpuart driver uses internally the serial port to manage the chip, and loads the BT FW independently of the WiFi subsystem. While on it, add support in the bluetooth-init script to be able to power the chip when the WiFi support is not present. https://onedigi.atlassian.net/browse/DEL-8632 Signed-off-by: Isaac Hermida --- .../bluez/bluez5-init/ccimx93/bluetooth-init | 64 ++++++++++--------- .../ccimx93/bluetooth-init.service | 3 +- .../busybox/busybox/ccimx93/standby-actions | 2 - 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init index d45c45cf2..ec2361970 100644 --- a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init @@ -14,14 +14,34 @@ #=============================================================================== HCI_IFACE="hci0" +MODULE_NAME="btnxpuart" log() { - printf "<3>iw612-bluetooth: %s\n" "${1}" >/dev/kmsg + printf "<3>iw61x-bluetooth: %s\n" "${1}" >/dev/kmsg +} + +# The power of the IW61x chip is managed by the WiFi DT entry. +# If WiFi is disabled, is needed to manage the power manually. +is_not_wifi() { + ! [ -e "/proc/device-tree/wireless/mac-address" ] +} + +power() { + is_not_wifi && gpioset 1 7="${1}" } set_btaddr() { - bt_addr=$(echo $(fw_printenv -n btaddr) | awk -F ":" '{ for(i=NF;i>=1;i--) printf "0x%s ", $i }') + hciconfig ${HCI_IFACE} up + sleep 0.2 + bt_addr=$(echo "$(fw_printenv -n btaddr)" | awk -F ":" '{ for(i=NF;i>=1;i--) printf "0x%s ", $i }') hcitool -i ${HCI_IFACE} cmd 0x3f 0x0022 0xfe 0x06 ${bt_addr} + hciconfig ${HCI_IFACE} down + sleep 0.2 + hciconfig ${HCI_IFACE} up +} + +is_kernel_module_loaded() { + lsmod | grep -qs -w "^${MODULE_NAME}" } bluetooth_start() { @@ -30,38 +50,21 @@ bluetooth_start() { return fi - # If there is a hciattach process running, just do nothing - pidof hciattach > /dev/null && log "Bluetooth already activated" && return + # If module is already loaded, skip + is_kernel_module_loaded && log "[ERROR] kernel module already present, skipping" && return 1 - # If port speed is 3M, assume that FW has been modified to run at that speed - if [ "$(stty -F /dev/ttyBt speed)" != "3000000" ]; then - hciattach -t5 /dev/ttyBt any 115200 flow nosleep && \ - hciconfig ${HCI_IFACE} up && \ - sleep 0.2 && \ - set_btaddr && \ - # Change rate to 3M using a custom vendor command - hcitool -i ${HCI_IFACE} cmd 0x3f 0x0009 0xc0 0xc6 0x2d 0x00 && \ - sleep 0.2 && \ - killall hciattach && \ - sleep 0.2 - fi - - hciattach -t5 /dev/ttyBt any -s 3000000 3000000 flow && \ - hciconfig ${HCI_IFACE} up && \ - sleep 0.2 && \ - log "Bluetooth activated" && return - - log "[ERROR] Cannot initialize Bluetooth" - return 1 + power 0 && sleep 0.2 && power 1 + # Load manually the kernel module + modprobe "${MODULE_NAME}" + # Reconfigure the HCI interface with the expected MAC address + is_kernel_module_loaded && set_btaddr && log "Bluetooth activated" && return 0 + log "[ERROR] Cannot initialize Bluetooth correctly" && return 1 } bluetooth_stop() { - if [ -e "/sys/class/bluetooth/${HCI_IFACE}" ]; then - killall hciattach > /dev/null - sleep 1 - # send a raw hci reset to set the chip in a good state - echo -e -n \\x01\\x03\\x0c\\x00 > /dev/ttyBt - fi + # Remove the kernel module + rmmod "${MODULE_NAME}" + power 0 } case "$1" in @@ -73,7 +76,6 @@ case "$1" in ;; restart) $0 stop - sleep 1 $0 start ;; *) diff --git a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init.service b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init.service index 9fbfc8b1e..7766720e2 100644 --- a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init.service +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init.service @@ -5,7 +5,8 @@ Before=bluetooth.service After=systemd-modules-load.service [Service] -Type=forking +Type=oneshot +RemainAfterExit=yes ExecStart=/etc/bluetooth-init start ExecStop=/etc/bluetooth-init stop diff --git a/meta-digi-dey/recipes-core/busybox/busybox/ccimx93/standby-actions b/meta-digi-dey/recipes-core/busybox/busybox/ccimx93/standby-actions index 154b40520..b200c71a7 100644 --- a/meta-digi-dey/recipes-core/busybox/busybox/ccimx93/standby-actions +++ b/meta-digi-dey/recipes-core/busybox/busybox/ccimx93/standby-actions @@ -38,13 +38,11 @@ if [ "${1}" = "pre" ]; then rmmod mlan if systemctl is-active bluetooth-init; then - # # bluetooth service relies on bluetooth-init service, so stop/start it unconditionally echo "systemctl start bluetooth-init" >> "${RESUME_ACTIONS}" echo "systemctl start bluetooth" >> "${RESUME_ACTIONS}" systemctl stop bluetooth-init systemctl stop bluetooth - stty -F /dev/ttyBt 115200 fi fi elif [ "${1}" = "post" ]; then