[PATCH v6 7/9] Bluetooth: hci_sync: Add NVMEM-backed BD address retrieval

Kwapulinski, Piotr piotr.kwapulinski at intel.com
Mon Jun 29 02:23:07 PDT 2026


>-----Original Message-----
>From: Loic Poulain <loic.poulain at oss.qualcomm.com> 
>Sent: Monday, June 29, 2026 10:55 AM
>To: Ulf Hansson <ulfh at kernel.org>; Rob Herring <robh at kernel.org>; Krzysztof Kozlowski <krzk+dt at kernel.org>; Conor Dooley <conor+dt at kernel.org>; Bjorn Andersson <andersson at kernel.org>; Konrad Dybcio <konradybcio at kernel.org>; Jens Axboe <axboe at kernel.dk>; Johannes Berg <johannes at sipsolutions.net>; Jeff Johnson <jjohnson at kernel.org>; Bartosz Golaszewski <brgl at kernel.org>; Marcel Holtmann <marcel at holtmann.org>; Luiz Augusto von Dentz <luiz.dentz at gmail.com>; Balakrishna Godavarthi <quic_bgodavar at quicinc.com>; Rocky Liao <quic_rjliao at quicinc.com>; David S. Miller <davem at davemloft.net>; Eric Dumazet <edumazet at google.com>; Jakub Kicinski <kuba at kernel.org>; Paolo Abeni <pabeni at redhat.com>; Simon Horman <horms at kernel.org>; Srinivas Kandagatla <srini at kernel.org>; Andrew Lunn <andrew at lunn.ch>; Heiner Kallweit <hkallweit1 at gmail.com>; Russell King <linux at armlinux.org.uk>; Saravana Kannan <saravanak at kernel.org>; Christian Marangi <ansuelsmth at gmail.com>
>Cc: linux-mmc at vger.kernel.org; devicetree at vger.kernel.org; linux-kernel at vger.kernel.org; linux-arm-msm at vger.kernel.org; linux-block at vger.kernel.org; linux-wireless at vger.kernel.org; ath10k at lists.infradead.org; linux-bluetooth at vger.kernel.org; netdev at vger.kernel.org; daniel at makrotopia.org; Loic Poulain <loic.poulain at oss.qualcomm.com>; Bartosz Golaszewski <bartosz.golaszewski at oss.qualcomm.com>
>Subject: [PATCH v6 7/9] Bluetooth: hci_sync: Add NVMEM-backed BD address retrieval
>
>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.
>
>Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski at oss.qualcomm.com>
>Signed-off-by: Loic Poulain <loic.poulain at oss.qualcomm.com>
>---
> include/net/bluetooth/hci.h | 18 ++++++++++++++++++
> net/bluetooth/hci_sync.c    | 39 ++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 56 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..589ccdfa26c1281d6eb979370523fff0d7920302 100644
>--- a/net/bluetooth/hci_sync.c
>+++ b/net/bluetooth/hci_sync.c
>@@ -7,6 +7,7 @@
>  */
> 
> #include <linux/property.h>
>+#include <linux/of_net.h>
> 
> #include <net/bluetooth/bluetooth.h>
> #include <net/bluetooth/hci_core.h>
>@@ -3588,6 +3589,37 @@ 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 in the device firmware node.
>+ *
>+ * All-zero BD addresses are rejected (unprovisioned).
Please add return value description and
Reviewed-by: Piotr Kwapulinski <piotr.kwapulinski at intel.com>
Thank you.
Piotr

>+ */
>+static int hci_dev_get_bd_addr_from_nvmem(struct hci_dev *hdev) {
>+	struct device_node *np = dev_of_node(hdev->dev.parent);
>+	u8 ba[sizeof(bdaddr_t)];
>+	int err;
>+
>+	if (!np)
>+		return -ENODEV;
>+
>+	err = of_get_nvmem_eui48(np, "local-bd-address", ba);
>+	if (err)
>+		return err;
>+
>+	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);
>+
>+	return 0;
>+}
>+
> /**
>  * hci_dev_get_bd_addr_from_property - Get the Bluetooth Device Address
>  *				       (BD_ADDR) for a HCI device from
>@@ -5042,12 +5074,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
>


More information about the ath10k mailing list