#!/bin/sh #=============================================================================== # # Copyright (C) 2012-2017 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="da9063-gpio 4" # set_gpio_value set_gpio_value() { gpioset ${1}=${2} } # powercycle_gpio powercycle_gpio() { gpioset ${1}=0 sleep .2 gpioset ${1}=1 sleep .2 } error() { echo ${1} exit 1 } bluetooth_init() { # 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 # Start the Bluetooth driver and bring up the interface HCIATTACH_LOG="/var/log/hciattach.log" for RETRY in $(seq 1 5) do killproc hciattach powercycle_gpio "${BT_EN_QCA_GPIO_NR}" if hciattach ttyBt qca ${BT_RATE:-3000000} -t30 ${BT_FLOW:-flow} unused ${BT_MACADDR} >${HCIATTACH_LOG} 2>&1; then return fi sleep 1 done BT_ERROR="FAIL (hciattach)" } # Source function library . /etc/init.d/functions case "$1" in start) if [ -d "/proc/device-tree/bluetooth" ]; then if [ "$(tr -d '\0' 2>/dev/null