From: Loic Poulain <loic.poulain@oss.qualcomm.com>
To: Ulf Hansson <ulfh@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Jens Axboe <axboe@kernel.dk>,
Johannes Berg <johannes@sipsolutions.net>,
Jeff Johnson <jjohnson@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Balakrishna Godavarthi <quic_bgodavar@quicinc.com>,
Rocky Liao <quic_rjliao@quicinc.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-block@vger.kernel.org, linux-wireless@vger.kernel.org,
ath10k@lists.infradead.org, linux-bluetooth@vger.kernel.org,
netdev@vger.kernel.org, daniel@makrotopia.org,
Loic Poulain <loic.poulain@oss.qualcomm.com>
Subject: [PATCH 7/9] Bluetooth: hci_sync: Add NVMEM-backed BD address retrieval
Date: Tue, 28 Apr 2026 16:23:12 +0200 [thread overview]
Message-ID: <20260428-block-as-nvmem-v1-7-6ad23e75190a@oss.qualcomm.com> (raw)
In-Reply-To: <20260428-block-as-nvmem-v1-0-6ad23e75190a@oss.qualcomm.com>
Some devices store the Bluetooth BD address in non-volatile
memory, which can be accessed through the NVMEM framework.
Similar to Ethernet or WiFi MAC addresses, add support for
reading the BD address from a 'local-bd-address' NVMEM cell.
As with the device-tree provided BD address, add a quirk to
indicate whether a device or platform should attempt to read
the address from NVMEM when no valid in-chip address is present.
Also add a quirk to indicate if the address is stored in
big-endian byte order.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
include/net/bluetooth/hci.h | 18 +++++++++++++++
net/bluetooth/hci_sync.c | 56 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 572b1c620c5d653a1fe10b26c1b0ba33e8f4968f..7686466d1109253b0d75edeb5f6a99fb98ce4cc6 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -164,6 +164,24 @@ enum {
*/
HCI_QUIRK_BDADDR_PROPERTY_BROKEN,
+ /* When this quirk is set, the public Bluetooth address
+ * initially reported by HCI Read BD Address command
+ * is considered invalid. The public BD Address can be
+ * retrieved via a 'local-bd-address' NVMEM cell.
+ *
+ * This quirk can be set before hci_register_dev is called or
+ * during the hdev->setup vendor callback.
+ */
+ HCI_QUIRK_USE_BDADDR_NVMEM,
+
+ /* When this quirk is set, the Bluetooth Device Address provided by
+ * the 'local-bd-address' NVMEM is stored in big-endian order.
+ *
+ * This quirk can be set before hci_register_dev is called or
+ * during the hdev->setup vendor callback.
+ */
+ HCI_QUIRK_BDADDR_NVMEM_BE,
+
/* When this quirk is set, the duplicate filtering during
* scanning is based on Bluetooth devices addresses. To allow
* RSSI based updates, restart scanning if needed.
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index fd3aacdea512a37c22b9a2be90c89ddca4b4d99f..f87cb6ae85c3a5754fe79f415ba05dd177f75fad 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -6,6 +6,7 @@
* Copyright 2023 NXP
*/
+#include <linux/nvmem-consumer.h>
#include <linux/property.h>
#include <net/bluetooth/bluetooth.h>
@@ -3588,6 +3589,54 @@ int hci_powered_update_sync(struct hci_dev *hdev)
return 0;
}
+/**
+ * hci_dev_get_bd_addr_from_nvmem - Get the Bluetooth Device Address
+ * (BD_ADDR) for a HCI device from
+ * an NVMEM cell.
+ * @hdev: The HCI device
+ *
+ * Search for 'local-bd-address' NVMEM cell.
+ *
+ * All-zero BD addresses are rejected (unprovisioned).
+ */
+static int hci_dev_get_bd_addr_from_nvmem(struct hci_dev *hdev)
+{
+ struct device *dev = hdev->dev.parent;
+ struct nvmem_cell *cell;
+ const void *ba;
+ int err = 0;
+ size_t len;
+
+ cell = nvmem_cell_get(dev, "local-bd-address");
+ if (IS_ERR(cell))
+ return PTR_ERR(cell);
+
+ ba = nvmem_cell_read(cell, &len);
+ nvmem_cell_put(cell);
+
+ if (IS_ERR(ba)) {
+ bt_dev_warn(hdev, "Error reading BD address from NVMEM (%ld)\n",
+ PTR_ERR(ba));
+ err = PTR_ERR(ba);
+ goto done;
+ }
+
+ if (len != sizeof(bdaddr_t) || !bacmp(ba, BDADDR_ANY)) {
+ bt_dev_warn(hdev, "NVMEM BD address has incorrect format\n");
+ err = -EINVAL;
+ goto done;
+ }
+
+ if (hci_test_quirk(hdev, HCI_QUIRK_BDADDR_NVMEM_BE))
+ baswap(&hdev->public_addr, (bdaddr_t *)ba);
+ else
+ bacpy(&hdev->public_addr, (bdaddr_t *)ba);
+
+done:
+ kfree(ba);
+ return err;
+}
+
/**
* hci_dev_get_bd_addr_from_property - Get the Bluetooth Device Address
* (BD_ADDR) for a HCI device from
@@ -5042,12 +5091,17 @@ static int hci_dev_setup_sync(struct hci_dev *hdev)
* its setup callback.
*/
invalid_bdaddr = hci_test_quirk(hdev, HCI_QUIRK_INVALID_BDADDR) ||
- hci_test_quirk(hdev, HCI_QUIRK_USE_BDADDR_PROPERTY);
+ hci_test_quirk(hdev, HCI_QUIRK_USE_BDADDR_PROPERTY) ||
+ hci_test_quirk(hdev, HCI_QUIRK_USE_BDADDR_NVMEM);
if (!ret) {
if (hci_test_quirk(hdev, HCI_QUIRK_USE_BDADDR_PROPERTY) &&
!bacmp(&hdev->public_addr, BDADDR_ANY))
hci_dev_get_bd_addr_from_property(hdev);
+ if (hci_test_quirk(hdev, HCI_QUIRK_USE_BDADDR_NVMEM) &&
+ !bacmp(&hdev->public_addr, BDADDR_ANY))
+ hci_dev_get_bd_addr_from_nvmem(hdev);
+
if (invalid_bdaddr && bacmp(&hdev->public_addr, BDADDR_ANY) &&
hdev->set_bdaddr) {
ret = hdev->set_bdaddr(hdev, &hdev->public_addr);
--
2.34.1
next prev parent reply other threads:[~2026-04-28 14:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 14:23 [PATCH 0/9] Support for block device NVMEM providers Loic Poulain
2026-04-28 14:23 ` [PATCH 1/9] dt-bindings: mmc: Document support for nvmem-layout Loic Poulain
2026-04-30 9:59 ` Krzysztof Kozlowski
2026-04-30 13:13 ` Loic Poulain
2026-04-28 14:23 ` [PATCH 2/9] arm64: dts: qcom: arduino-imola: Describe boot1 NVMEM layout Loic Poulain
2026-04-30 9:43 ` Krzysztof Kozlowski
2026-04-28 14:23 ` [PATCH 3/9] block: implement NVMEM provider Loic Poulain
2026-04-28 14:23 ` [PATCH 4/9] dt-bindings: net: wireless: qcom,ath10k: Add NVMEM MAC address cell Loic Poulain
2026-04-29 9:31 ` Konrad Dybcio
2026-04-28 14:23 ` [PATCH 5/9] arm64: dts: qcom: arduino-imola: Get WiFi MAC from NVMEM Loic Poulain
2026-04-29 9:30 ` Konrad Dybcio
2026-04-28 14:23 ` [PATCH 6/9] dt-bindings: bluetooth: qcom: Add NVMEM BD address cell Loic Poulain
2026-04-28 14:23 ` Loic Poulain [this message]
2026-04-29 8:53 ` [PATCH 7/9] Bluetooth: hci_sync: Add NVMEM-backed BD address retrieval Bartosz Golaszewski
2026-04-29 13:15 ` Andrew Lunn
2026-04-29 16:22 ` Loic Poulain
2026-04-28 14:23 ` [PATCH 8/9] Bluetooth: qca: Set NVMEM BD address quirks when address is invalid Loic Poulain
2026-04-28 14:23 ` [PATCH 9/9] arm64: dts: qcom: arduino-imola: Get Bluetooth BD address from NVMEM Loic Poulain
2026-04-29 9:32 ` Konrad Dybcio
2026-04-29 1:05 ` [PATCH 0/9] Support for block device NVMEM providers Andrew Lunn
2026-04-29 20:20 ` Loic Poulain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260428-block-as-nvmem-v1-7-6ad23e75190a@oss.qualcomm.com \
--to=loic.poulain@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=ath10k@lists.infradead.org \
--cc=axboe@kernel.dk \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jjohnson@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_bgodavar@quicinc.com \
--cc=quic_rjliao@quicinc.com \
--cc=robh@kernel.org \
--cc=ulfh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox