From 66fb6e55c181fc0ae9a2c450f6bd45f8bb0c74f0 Mon Sep 17 00:00:00 2001 From: Isaac Hermida Date: Fri, 17 Feb 2023 12:48:18 +0100 Subject: [PATCH] ccimx93: iw612: add bluetooth support The bluetooth FW for the IW612 is loaded together with WiFi FW, so there is not BT FW file as in our other products. In order to use the BT, it is a requirement to load the WiFi FW, so ensure that the service is started after the load of the system modules. https://onedigi.atlassian.net/browse/DEL-8346 Signed-off-by: Isaac Hermida --- .../recipes-connectivity/bluez/bluez5-init.bb | 7 +- .../bluez/bluez5-init/ccimx93/bluetooth-init | 70 +++++++++++++++++++ .../ccimx93/bluetooth-init.service | 13 ++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init create mode 100644 meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init.service diff --git a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init.bb b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init.bb index a6cd7ee41..f5df5aa02 100644 --- a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init.bb +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init.bb @@ -1,4 +1,4 @@ -# Copyright (C) 2022, Digi International Inc. +# Copyright (C) 2022-2023, Digi International Inc. SUMMARY = "Bluetooth init scripts" LICENSE = "GPL-2.0-only" @@ -58,5 +58,8 @@ SYSTEMD_SERVICE:${PN} = "bluetooth-init.service" # 'bluetooth-init' script uses '/etc/init.d/functions' RDEPENDS:${PN} = "initscripts-functions" +# IW61x Bluetooth support requires the WiFi FW support +RDEPENDS:${PN}:append:ccimx93 = " firmware-nxp-wifi-nxpiw612" + PACKAGE_ARCH = "${MACHINE_ARCH}" -COMPATIBLE_MACHINE = "(ccimx6$|ccimx6ul|ccimx8x|ccimx8mn|ccimx8mm)" +COMPATIBLE_MACHINE = "(ccimx6$|ccimx6ul|ccimx8x|ccimx8mn|ccimx8mm|ccimx93)" 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 new file mode 100644 index 000000000..6ceda69b4 --- /dev/null +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init @@ -0,0 +1,70 @@ +#!/bin/sh +#=============================================================================== +# +# Copyright (C) 2023 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 +# +#=============================================================================== + +HCI_IFACE="hci0" + +log() { + printf "<3>iw612-bluetooth: %s\n" "${1}" >/dev/kmsg +} + +bluetooth_start() { + if ! [ -e "/proc/device-tree/bluetooth/mac-address" ]; then + log "[ERROR] Bluetooth mac-address not found" + return + fi + + BTADDR=$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/bluetooth/mac-address 2>/dev/null | sed 's/:$//g') + hciattach -t5 /dev/ttyBt any 115200 flow nosleep "${BTADDR}" && \ + hciconfig ${HCI_IFACE} up && \ + sleep 0.2 && \ + hcitool -i ${HCI_IFACE} cmd 0x3f 0x0009 0xc0 0xc6 0x2d 0x00 && \ + sleep 0.2 && \ + killall hciattach && \ + sleep 0.2 && \ + hciattach -t5 /dev/ttyBt any -s 3000000 3000000 flow && \ + log "Bluetooth activated" && return + + log "[ERROR] Cannot initialize Bluetooth" + return 1 +} + +bluetooth_stop() { + if [ -e "/sys/class/bluetooth/${HCI_IFACE}" ]; then + # hci reset command + hcitool -i ${HCI_IFACE} cmd 0x03 0x0003 + sleep 0.2 + # set baudrate to 115200 + hcitool -i ${HCI_IFACE} cmd 0x3f 0x0009 0x00 0xc2 0x01 0x00 + killall hciattach + fi +} + +case "$1" in + start) + bluetooth_start + ;; + stop) + bluetooth_stop + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 + ;; +esac 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 new file mode 100644 index 000000000..9fbfc8b1e --- /dev/null +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx93/bluetooth-init.service @@ -0,0 +1,13 @@ +[Unit] +Description=Initialization of the IW612 bluetooth chip +ConditionPathIsDirectory=/proc/device-tree/bluetooth +Before=bluetooth.service +After=systemd-modules-load.service + +[Service] +Type=forking +ExecStart=/etc/bluetooth-init start +ExecStop=/etc/bluetooth-init stop + +[Install] +WantedBy=bluetooth.service