meta-digi-dey: bluez5: Adapt bluetooth-init to mainline use
The Digi vendor kernel uses a dedicated HCI UART driver with support for In-Band Sleep (IBS). This driver, when used with a QCA vendor ROME plugin for hciattach, is able to upload a new firmware version to the Bluetooth chipset, as well as set the MAC address directly on the firmware. Mainline BSP uses the HCI H4 driver instead and the "qualcomm" hciattach plugin which is not able to upload firmware to the QCA6564 chipset. As such, when using mainline the chipset uses the ROM firmware and the bluetooth init script has been adapted accordingly. Signed-off-by: Alex Gonzalez <alex.gonzalez@digi.com>
This commit is contained in:
parent
30fde4487b
commit
569c95511f
|
|
@ -0,0 +1,102 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#===============================================================================
|
||||||
|
#
|
||||||
|
# Copyright (C) 2012-2018 by Digi International Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License version 2 as published by
|
||||||
|
# the Free Software Foundation.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# !Description: Initialize bluetooth hardware
|
||||||
|
#
|
||||||
|
#===============================================================================
|
||||||
|
|
||||||
|
# Bluetooth power GPIO
|
||||||
|
BT_EN_QCA_GPIO_NR="137"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
set_mac_address() {
|
||||||
|
# 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')"
|
||||||
|
if [ -z "${BT_MACADDR}" ] || [ "${BT_MACADDR}" = "00:00:00:00:00:00" ]; then
|
||||||
|
BT_MACADDR="00:04:F3:FF:FF:BB"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Convert the BT address to the hcitool command format.
|
||||||
|
# Example: "00:04:F3:11:22:33" coverted to "33 22 11 F3 04 00"
|
||||||
|
HCI_BT_ADDR="$(echo ${BT_MACADDR} | sed -e 's,^\(..\):\(..\):\(..\):\(..\):\(..\):\(..\)$,\6 \5 \4 \3 \2 \1,g')"
|
||||||
|
|
||||||
|
# Up the interface to be able to send hci commands
|
||||||
|
hciconfig hci0 up || echo "Cannot bring up bluetooth interface after initial attach" || exit 1
|
||||||
|
|
||||||
|
# Set the MAC address
|
||||||
|
hcitool -i hci0 cmd 3F 000B 01 02 06 ${HCI_BT_ADDR} > /dev/null || echo "Unable to set BT MAC Address" || exit 1
|
||||||
|
|
||||||
|
# Set the hci interface down so bluetooth main.conf will apply
|
||||||
|
hciconfig hci0 down || echo "Cannot down the hci interface" || exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
bluetooth_init() {
|
||||||
|
# Start the Bluetooth driver and bring up the interface
|
||||||
|
HCIATTACH_LOG="/var/log/hciattach.log"
|
||||||
|
|
||||||
|
killproc hciattach
|
||||||
|
powercycle_gpio "${BT_EN_QCA_GPIO_NR}"
|
||||||
|
hciattach ttyBt qualcomm 115200 -t3 flow unused > ${HCIATTACH_LOG} 2>&1 || BT_ERROR="FAIL (hciattach)"
|
||||||
|
set_mac_address || BT_ERROR="Unable to set MAC address"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Source function library
|
||||||
|
. /etc/init.d/functions
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if [ -d "/proc/device-tree/bluetooth" ]; then
|
||||||
|
echo -n "Starting bluetooth hardware: "
|
||||||
|
bluetooth_init
|
||||||
|
echo "${BT_ERROR:-done.}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
if [ -d "/sys/class/bluetooth/hci0" ]; then
|
||||||
|
echo -n "Stopping bluetooth hardware: "
|
||||||
|
killproc hciattach
|
||||||
|
# Power down bluetooth
|
||||||
|
set_gpio_value "${BT_EN_QCA_GPIO_NR}" 0
|
||||||
|
echo "done."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
$0 stop
|
||||||
|
sleep 1
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Loading…
Reference in New Issue