bluez5: ccimx8: use kernel module for bluetooth power management

Modify bluetooth init script to use kernel module to power on/off
the bluetooth chip instead of managing it directly from sysfs.

https://jira.digi.com/browse/DEL-6615

Signed-off-by: Arturo Buzarra <arturo.buzarra@digi.com>
This commit is contained in:
Arturo Buzarra 2019-06-19 12:13:51 +02:00
parent 6491b5b00a
commit ccc6f9c960
1 changed files with 4 additions and 30 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
#=============================================================================== #===============================================================================
# #
# Copyright (C) 2018 by Digi International Inc. # Copyright (C) 2018,2019 by Digi International Inc.
# All rights reserved. # All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify it # This program is free software; you can redistribute it and/or modify it
@ -13,32 +13,6 @@
# #
#=============================================================================== #===============================================================================
# Bluetooth power GPIO
BT_EN_QCA_GPIO_NR="394"
# set_gpio_value <gpio_nr> <value>
set_gpio_value() {
local SG_GPIONR="${1}"
local SG_GPIOVAL="${2}"
local SG_GPIOPATH="/sys/class/gpio/gpio${SG_GPIONR}"
[ -d "${SG_GPIOPATH}" ] || printf "%s" "${SG_GPIONR}" > /sys/class/gpio/export
printf out > "${SG_GPIOPATH}/direction" && sleep .2
printf "${SG_GPIOVAL}" > "${SG_GPIOPATH}/value" && sleep .2
[ -d "${SG_GPIOPATH}" ] && printf "%s" "${SG_GPIONR}" > /sys/class/gpio/unexport
}
# powercycle_gpio <gpio_nr>
powercycle_gpio() {
set_gpio_value "${1}" 0
set_gpio_value "${1}" 1
}
error() {
echo ${1}
exit 1
}
bluetooth_init() { bluetooth_init() {
# Get MAC address from the device tree. Use a default value if it has not been set. # Get MAC address from the device tree. Use a default value if it has not been set.
BT_MACADDR="$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/bluetooth/mac-address 2>/dev/null | sed 's/:$//g')" BT_MACADDR="$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/bluetooth/mac-address 2>/dev/null | sed 's/:$//g')"
@ -52,10 +26,11 @@ bluetooth_init() {
for RETRY in $(seq 1 5) for RETRY in $(seq 1 5)
do do
killproc hciattach killproc hciattach
powercycle_gpio "${BT_EN_QCA_GPIO_NR}" modprobe btdigi
if hciattach ttyBt qca ${BT_RATE:-3000000} -t30 ${BT_FLOW:-flow} unused ${BT_MACADDR} >${HCIATTACH_LOG} 2>&1; then if hciattach ttyBt qca ${BT_RATE:-3000000} -t30 ${BT_FLOW:-flow} unused ${BT_MACADDR} >${HCIATTACH_LOG} 2>&1; then
return return
fi fi
rmmod btdigi
sleep 1 sleep 1
done done
BT_ERROR="FAIL (hciattach)" BT_ERROR="FAIL (hciattach)"
@ -76,8 +51,7 @@ case "$1" in
if [ -d "/sys/class/bluetooth/hci0" ]; then if [ -d "/sys/class/bluetooth/hci0" ]; then
echo -n "Stopping bluetooth hardware: " echo -n "Stopping bluetooth hardware: "
killproc hciattach killproc hciattach
# Power down bluetooth rmmod btdigi
set_gpio_value "${BT_EN_QCA_GPIO_NR}" 0
echo "done." echo "done."
fi fi
;; ;;