From 9698c64aca80e0045db7e1d13cab2bffb7930255 Mon Sep 17 00:00:00 2001 From: Romuald JEANNE Date: Wed, 17 Jun 2020 16:44:02 +0200 Subject: [PATCH] BLUETOOTH-SUSPEND: add bluetooth suspend as wifi suspend Change-Id: I44123165c65308a1e076a1ac4a62b1fbd4c14f0a --- .../bluetooth/bluetooth-suspend.bb | 28 ++++++++++++ .../bluetooth-brcmfmac-sleep.service | 13 ++++++ .../bluetooth_brcmfmac_driver.sh | 44 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 recipes-connectivity/bluetooth/bluetooth-suspend.bb create mode 100644 recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth-brcmfmac-sleep.service create mode 100755 recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth_brcmfmac_driver.sh diff --git a/recipes-connectivity/bluetooth/bluetooth-suspend.bb b/recipes-connectivity/bluetooth/bluetooth-suspend.bb new file mode 100644 index 0000000..12f50df --- /dev/null +++ b/recipes-connectivity/bluetooth/bluetooth-suspend.bb @@ -0,0 +1,28 @@ +# Copyright (C) 2020, STMicroelectronics - All Rights Reserved + +DESCRIPTION = "Systemd service to suspend/resume correctly bluetooth" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" + +SRC_URI = " \ + file://bluetooth_brcmfmac_driver.sh \ + file://bluetooth-brcmfmac-sleep.service \ + " + +inherit systemd +SYSTEMD_PACKAGES += "${PN}" +SYSTEMD_SERVICE_${PN} = "bluetooth-brcmfmac-sleep.service" + +do_install() { + install -d ${D}${bindir} + install -m 0755 ${WORKDIR}/bluetooth_brcmfmac_driver.sh ${D}${bindir}/ + + if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then + install -d ${D}${systemd_unitdir}/system/ + + install -m 0644 ${WORKDIR}/bluetooth-brcmfmac-sleep.service ${D}${systemd_unitdir}/system/ + fi +} + +ALLOW_EMPTY_${PN} = "1" + diff --git a/recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth-brcmfmac-sleep.service b/recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth-brcmfmac-sleep.service new file mode 100644 index 0000000..4a2a2d3 --- /dev/null +++ b/recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth-brcmfmac-sleep.service @@ -0,0 +1,13 @@ +[Unit] +Description=Bluetooth brcmfmac sleep hook +Before=sleep.target +StopWhenUnneeded=yes + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=-/usr/bin/bluetooth_brcmfmac_driver.sh unbind +ExecStop=-/usr/bin/bluetooth_brcmfmac_driver.sh bind + +[Install] +WantedBy=sleep.target diff --git a/recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth_brcmfmac_driver.sh b/recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth_brcmfmac_driver.sh new file mode 100755 index 0000000..5c68aed --- /dev/null +++ b/recipes-connectivity/bluetooth/bluetooth-suspend/bluetooth_brcmfmac_driver.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +COMPATIBLE_BOARD=$(cat /proc/device-tree/compatible | sed "s|st,|,|g" | cut -d ',' -f2) + +case $COMPATIBLE_BOARD in +stm32mp151a-dk2*) + # supported + ;; +stm32mp151f-dk2*) + # supported + ;; +stm32mp153a-dk2*) + # supported + ;; +stm32mp153f-dk2*) + # supported + ;; +stm32mp157c-dk2*) + # supported + ;; +stm32mp157f-dk2*) + # supported + ;; + *) + exit 1; +esac + +case $1 in +bind) + echo "bind driver hci_uart"; + echo "bind driver hci_uart" > /dev/kmsg + modprobe -r hci_uart + modprobe hci_uart + ;; +unbind) + echo "unbind driver hci_uart"; + echo "unbind driver hci_uart" > /dev/kmsg + modprobe -r hci_uart + ;; +*) + echo "$0 [bind|unbind]" + echo "Bind/Unbind bluetooth driver brcmfmac." + ;; +esac