public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address
@ 2025-03-03 11:27 Neeraj Sanjay Kale
  2025-03-03 11:27 ` [PATCH v7 2/2] Bluetooth: btnxpuart: " Neeraj Sanjay Kale
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Neeraj Sanjay Kale @ 2025-03-03 11:27 UTC (permalink / raw)
  To: marcel, luiz.dentz, robh, krzk+dt, conor+dt
  Cc: linux-bluetooth, linux-kernel, devicetree, amitkumar.karwar,
	neeraj.sanjaykale, sherry.sun, ziniu.wang_1, johan.korsnes,
	kristian.krohn, manjeet.gupta

Allow user to set custom BD address for NXP chipsets.

Signed-off-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
v2: Add allOf and unevaluatedProperties: false (Krzysztof)
v3: Drop local-bd-address: true (Krzysztof)
---
 .../devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml   | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml b/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml
index 04f55fac42ce..d02e9dd847ef 100644
--- a/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml
+++ b/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml
@@ -17,6 +17,9 @@ description:
 maintainers:
   - Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
 
+allOf:
+  - $ref: bluetooth-controller.yaml#
+
 properties:
   compatible:
     enum:
@@ -53,7 +56,7 @@ properties:
 required:
   - compatible
 
-additionalProperties: false
+unevaluatedProperties: false
 
 examples:
   - |
@@ -66,5 +69,6 @@ examples:
             device-wakeup-gpios = <&gpio 11 GPIO_ACTIVE_HIGH>;
             nxp,wakein-pin = /bits/ 8 <18>;
             nxp,wakeout-pin = /bits/ 8 <19>;
+            local-bd-address = [66 55 44 33 22 11];
         };
     };
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v7 2/2] Bluetooth: btnxpuart: Add support to set BD address
  2025-03-03 11:27 [PATCH v7 1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address Neeraj Sanjay Kale
@ 2025-03-03 11:27 ` Neeraj Sanjay Kale
  2025-03-03 11:54 ` [v7,1/2] dt-bindings: net: bluetooth: nxp: " bluez.test.bot
  2025-03-06 21:00 ` [PATCH v7 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: Neeraj Sanjay Kale @ 2025-03-03 11:27 UTC (permalink / raw)
  To: marcel, luiz.dentz, robh, krzk+dt, conor+dt
  Cc: linux-bluetooth, linux-kernel, devicetree, amitkumar.karwar,
	neeraj.sanjaykale, sherry.sun, ziniu.wang_1, johan.korsnes,
	kristian.krohn, manjeet.gupta

This adds support for setting BD address during hci registration. NXP
FW does not allow vendor commands unless it receives a reset command
after FW download and initialization done.

As a workaround, the .set_bdaddr callback function will first send the
HCI reset command, followed by the actual vendor command to set BD
address.

The driver checks for the local-bd-address property in device tree, and
if preset, it sets the HCI_QUIRK_USE_BDADDR_PROPERTY quirk.

With this quirk set, the driver's set_bdaddr callback function is called
after FW download is complete and before HCI initialization, which sends
the hci reset and 3f 22 commands. During initialization, kernel reads
the newly set BD address from the controller.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Signed-off-by: Johan Korsnes <johan.korsnes@remarkable.no>
Signed-off-by: Kristian Krohn <kristian.krohn@remarkable.no>
Tested-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
Signed-off-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
---
v4: hci0 interface shows RAW mode if 'local-bd-address' not defined and
    HCI_QUIRK_USE_BDADDR_PROPERTY is set. Add Quirk only if device tree
    property 'local-bd-address' found. (Neeraj)
v5: Initialize local variable ba, update Copywrite year. (Kristian)
v6: Elaborate commit message, add User Manual reference. (Paul Menzel)
v7: Use __hci_cmd_sync_status(). (Luiz)
---
 drivers/bluetooth/btnxpuart.c | 58 ++++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c
index 4f2f429c9800..21b07684dd68 100644
--- a/drivers/bluetooth/btnxpuart.c
+++ b/drivers/bluetooth/btnxpuart.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  *  NXP Bluetooth driver
- *  Copyright 2023 NXP
+ *  Copyright 2023-2025 NXP
  */
 
 #include <linux/module.h>
@@ -98,13 +98,16 @@
 #define PS_STATE_AWAKE          0
 #define PS_STATE_SLEEP          1
 
-/* Bluetooth vendor command : Sleep mode */
+/* NXP Vendor Commands. Refer user manual UM11628 on nxp.com */
+/* Set custom BD Address */
+#define HCI_NXP_SET_BD_ADDR	0xfc22
+/* Set Auto-Sleep mode */
 #define HCI_NXP_AUTO_SLEEP_MODE	0xfc23
-/* Bluetooth vendor command : Wakeup method */
+/* Set Wakeup method */
 #define HCI_NXP_WAKEUP_METHOD	0xfc53
-/* Bluetooth vendor command : Set operational baudrate */
+/* Set operational baudrate */
 #define HCI_NXP_SET_OPER_SPEED	0xfc09
-/* Bluetooth vendor command: Independent Reset */
+/* Independent Reset (Soft Reset) */
 #define HCI_NXP_IND_RESET	0xfcfc
 
 /* Bluetooth Power State : Vendor cmd params */
@@ -310,6 +313,15 @@ union nxp_v3_rx_timeout_nak_u {
 	u8 buf[6];
 };
 
+union nxp_set_bd_addr_payload {
+	struct {
+		u8 param_id;
+		u8 param_len;
+		u8 param[6];
+	} __packed data;
+	u8 buf[8];
+};
+
 static u8 crc8_table[CRC8_TABLE_SIZE];
 
 /* Default configurations */
@@ -1209,6 +1221,33 @@ static int nxp_set_ind_reset(struct hci_dev *hdev, void *data)
 	return hci_recv_frame(hdev, skb);
 }
 
+static int nxp_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
+{
+	union nxp_set_bd_addr_payload pcmd;
+	int err;
+
+	pcmd.data.param_id = 0xfe;
+	pcmd.data.param_len = 6;
+	memcpy(pcmd.data.param, bdaddr, 6);
+
+	/* BD address can be assigned only after first reset command. */
+	err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
+	if (err) {
+		bt_dev_err(hdev, "Reset before setting local-bd-addr failed (%ld)",
+			   PTR_ERR(skb));
+		return err;
+	}
+
+	err = __hci_cmd_sync_status(hdev, HCI_NXP_SET_BD_ADDR, sizeof(pcmd),
+			     pcmd.buf, HCI_CMD_TIMEOUT);
+	if (err) {
+		bt_dev_err(hdev, "Changing device address failed (%d)", err);
+		return err;
+	}
+
+	return 0;
+}
+
 /* NXP protocol */
 static int nxp_setup(struct hci_dev *hdev)
 {
@@ -1522,6 +1561,7 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
 {
 	struct hci_dev *hdev;
 	struct btnxpuart_dev *nxpdev;
+	bdaddr_t ba = {0};
 
 	nxpdev = devm_kzalloc(&serdev->dev, sizeof(*nxpdev), GFP_KERNEL);
 	if (!nxpdev)
@@ -1570,8 +1610,16 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
 	hdev->hw_error = nxp_hw_err;
 	hdev->shutdown = nxp_shutdown;
 	hdev->wakeup = nxp_wakeup;
+	hdev->set_bdaddr = nxp_set_bdaddr;
+
 	SET_HCIDEV_DEV(hdev, &serdev->dev);
 
+	device_property_read_u8_array(&nxpdev->serdev->dev,
+				      "local-bd-address",
+				      (u8 *)&ba, sizeof(ba));
+	if (bacmp(&ba, BDADDR_ANY))
+		set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
+
 	if (hci_register_dev(hdev) < 0) {
 		dev_err(&serdev->dev, "Can't register HCI device\n");
 		goto probe_fail;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [v7,1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address
  2025-03-03 11:27 [PATCH v7 1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address Neeraj Sanjay Kale
  2025-03-03 11:27 ` [PATCH v7 2/2] Bluetooth: btnxpuart: " Neeraj Sanjay Kale
@ 2025-03-03 11:54 ` bluez.test.bot
  2025-03-06 21:00 ` [PATCH v7 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2025-03-03 11:54 UTC (permalink / raw)
  To: linux-bluetooth, neeraj.sanjaykale

[-- Attachment #1: Type: text/plain, Size: 2116 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=939557

---Test result---

Test Summary:
CheckPatch                    PENDING   0.43 seconds
GitLint                       PENDING   0.22 seconds
SubjectPrefix                 FAIL      0.38 seconds
BuildKernel                   PASS      24.20 seconds
CheckAllWarning               PASS      27.21 seconds
CheckSparse                   PASS      30.89 seconds
BuildKernel32                 PASS      24.14 seconds
TestRunnerSetup               PASS      431.75 seconds
TestRunner_l2cap-tester       PASS      21.07 seconds
TestRunner_iso-tester         PASS      31.95 seconds
TestRunner_bnep-tester        PASS      4.65 seconds
TestRunner_mgmt-tester        FAIL      120.99 seconds
TestRunner_rfcomm-tester      PASS      7.84 seconds
TestRunner_sco-tester         PASS      11.77 seconds
TestRunner_ioctl-tester       PASS      8.19 seconds
TestRunner_mesh-tester        PASS      6.06 seconds
TestRunner_smp-tester         PASS      7.09 seconds
TestRunner_userchan-tester    PASS      5.02 seconds
IncrementalBuild              PENDING   0.84 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: SubjectPrefix - FAIL
Desc: Check subject contains "Bluetooth" prefix
Output:
"Bluetooth: " prefix is not specified in the subject
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 490, Passed: 485 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
LL Privacy - Set Flags 1 (Add to RL)                 Failed       0.147 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v7 1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address
  2025-03-03 11:27 [PATCH v7 1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address Neeraj Sanjay Kale
  2025-03-03 11:27 ` [PATCH v7 2/2] Bluetooth: btnxpuart: " Neeraj Sanjay Kale
  2025-03-03 11:54 ` [v7,1/2] dt-bindings: net: bluetooth: nxp: " bluez.test.bot
@ 2025-03-06 21:00 ` patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2025-03-06 21:00 UTC (permalink / raw)
  To: Neeraj Sanjay Kale
  Cc: marcel, luiz.dentz, robh, krzk+dt, conor+dt, linux-bluetooth,
	linux-kernel, devicetree, amitkumar.karwar, sherry.sun,
	ziniu.wang_1, johan.korsnes, kristian.krohn, manjeet.gupta

Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon,  3 Mar 2025 16:57:51 +0530 you wrote:
> Allow user to set custom BD address for NXP chipsets.
> 
> Signed-off-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> v2: Add allOf and unevaluatedProperties: false (Krzysztof)
> v3: Drop local-bd-address: true (Krzysztof)
> 
> [...]

Here is the summary with links:
  - [v7,1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address
    https://git.kernel.org/bluetooth/bluetooth-next/c/cd4886af1930
  - [v7,2/2] Bluetooth: btnxpuart: Add support to set BD address
    (no matching commit)

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-06 21:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-03 11:27 [PATCH v7 1/2] dt-bindings: net: bluetooth: nxp: Add support to set BD address Neeraj Sanjay Kale
2025-03-03 11:27 ` [PATCH v7 2/2] Bluetooth: btnxpuart: " Neeraj Sanjay Kale
2025-03-03 11:54 ` [v7,1/2] dt-bindings: net: bluetooth: nxp: " bluez.test.bot
2025-03-06 21:00 ` [PATCH v7 1/2] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox