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 <isaac.hermida@digi.com>
This commit is contained in:
parent
57048f9177
commit
bc4aaf2237
|
|
@ -14,14 +14,34 @@
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
HCI_IFACE="hci0"
|
HCI_IFACE="hci0"
|
||||||
|
MODULE_NAME="btnxpuart"
|
||||||
|
|
||||||
log() {
|
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() {
|
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}
|
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() {
|
bluetooth_start() {
|
||||||
|
|
@ -30,38 +50,21 @@ bluetooth_start() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If there is a hciattach process running, just do nothing
|
# If module is already loaded, skip
|
||||||
pidof hciattach > /dev/null && log "Bluetooth already activated" && return
|
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
|
power 0 && sleep 0.2 && power 1
|
||||||
if [ "$(stty -F /dev/ttyBt speed)" != "3000000" ]; then
|
# Load manually the kernel module
|
||||||
hciattach -t5 /dev/ttyBt any 115200 flow nosleep && \
|
modprobe "${MODULE_NAME}"
|
||||||
hciconfig ${HCI_IFACE} up && \
|
# Reconfigure the HCI interface with the expected MAC address
|
||||||
sleep 0.2 && \
|
is_kernel_module_loaded && set_btaddr && log "Bluetooth activated" && return 0
|
||||||
set_btaddr && \
|
log "[ERROR] Cannot initialize Bluetooth correctly" && return 1
|
||||||
# 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bluetooth_stop() {
|
bluetooth_stop() {
|
||||||
if [ -e "/sys/class/bluetooth/${HCI_IFACE}" ]; then
|
# Remove the kernel module
|
||||||
killall hciattach > /dev/null
|
rmmod "${MODULE_NAME}"
|
||||||
sleep 1
|
power 0
|
||||||
# send a raw hci reset to set the chip in a good state
|
|
||||||
echo -e -n \\x01\\x03\\x0c\\x00 > /dev/ttyBt
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
@ -73,7 +76,6 @@ case "$1" in
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
$0 stop
|
$0 stop
|
||||||
sleep 1
|
|
||||||
$0 start
|
$0 start
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ Before=bluetooth.service
|
||||||
After=systemd-modules-load.service
|
After=systemd-modules-load.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=forking
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
ExecStart=/etc/bluetooth-init start
|
ExecStart=/etc/bluetooth-init start
|
||||||
ExecStop=/etc/bluetooth-init stop
|
ExecStop=/etc/bluetooth-init stop
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,11 @@ if [ "${1}" = "pre" ]; then
|
||||||
rmmod mlan
|
rmmod mlan
|
||||||
|
|
||||||
if systemctl is-active bluetooth-init; then
|
if systemctl is-active bluetooth-init; then
|
||||||
#
|
|
||||||
# bluetooth service relies on bluetooth-init service, so stop/start it unconditionally
|
# bluetooth service relies on bluetooth-init service, so stop/start it unconditionally
|
||||||
echo "systemctl start bluetooth-init" >> "${RESUME_ACTIONS}"
|
echo "systemctl start bluetooth-init" >> "${RESUME_ACTIONS}"
|
||||||
echo "systemctl start bluetooth" >> "${RESUME_ACTIONS}"
|
echo "systemctl start bluetooth" >> "${RESUME_ACTIONS}"
|
||||||
systemctl stop bluetooth-init
|
systemctl stop bluetooth-init
|
||||||
systemctl stop bluetooth
|
systemctl stop bluetooth
|
||||||
stty -F /dev/ttyBt 115200
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ "${1}" = "post" ]; then
|
elif [ "${1}" = "post" ]; then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue