From patchwork Wed Jan 15 10:46:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Neeraj Sanjay Kale X-Patchwork-Id: 13940290 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2087.outbound.protection.outlook.com [40.107.241.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31DF1156644; Wed, 15 Jan 2025 10:45:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736937907; cv=fail; b=lN+WG0xm8VAols/c+WEKGkfHlGH2OTzpEJSpI1zuF1QdUDP9FifIAFq6P5GXMT9iPKbmokdUu1atZhDxm+visO3wLp0EuGyHHcgmsqXjan9SoxnodhorpW2KNiHvufD9mKNwPQuBQuJcZ9GFh0XDOGFePYX0jswmp8e83IM9X04= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736937907; c=relaxed/simple; bh=09FLFt7CPRqw0H74Tp5wTNa5H8JujFRAXlRT7R9NEBc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ki1V7ibzV4QMXWrSQ3BBnW4cBdGWjkZ3TbvlgeiSD9BvpXxd6xIUvsHP0dELNqKuuma1EQruNnMQOXhr8FwboMn9QqF1kYlR6q6Cj3/IYZPmyqqQT6XjJ/xesisPupHU1JfPpoJTMwnBXc8Qzyrsa2k2c4p0SRnBvxUYdlb3k88= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=B3nL9mjJ; arc=fail smtp.client-ip=40.107.241.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="B3nL9mjJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OklW3BtU6JiW6UZg09vDE/Tw2N6GCIAd0PSZ5hpf2dfrPzjDpc+mF0xuzQDwzTi/Kqu4P56FgoSmJA6rrGZc8O2TkG6YuJzMs0QU6LFJ7OX3zG3cwwfwN9DSERQgWOd13gzc5iHZ93KH2HEpDX4mckVurYN758zO7r0BoWzEg2fUkhQwDwnF5qw06Tu7SMI/YwZbj3J8VP7EuX1KwQrothPzfzAhYEyYqNl6EOFUrOF9wDvD2+BuogOKtJ7VjZ+Kv4sU7mtYU8RsIqkwqSpkgQKAbzpUzEKUYbFASYdnpnngUCCr2cS8AXSEjobk6/JBwET/5UGHJoIO3rN5XkSL/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=B094ROyfelAXhuEfHOLnG8f0c1McKjS2hRphp+ggeWU=; b=AjPxhAVIXcKHRvgWFr7ODgjC8+r3Fj3pjCfEYdwcMaivPB2JHINy/EyDK4rGg8hDeeU0IZ626DJ0CZ7wfqF/KIuS3jR3/iejsXQELUZuiX4dD3dbdxwjQJ18XS9h0FmMShvUCKJz8m/QFgmyynww2dBnVRMtzETh0Xmox3A8LC83Hx8PmGMT1nOQsS1RAwpFw52Oter/nq+C5Pe7bn3ofwOjrOgSa5YpXXFzODlSbbLvmH3pHjyjvB6iqkZN4DZAsqM++NjUgOHwT1N2D2EIC2Bk54AymfwoMvsT2KWHQVmNSvGjM6TrmPm7txjJpIYqUv6fnz5jkcBT94mMoIUTSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B094ROyfelAXhuEfHOLnG8f0c1McKjS2hRphp+ggeWU=; b=B3nL9mjJ34V+DTm2/SSvYS8dYZQJS8xqrAY43h6lY8pO5Itg+hoG2BxKJrjwAC7BgSJuLLR9xzETzcVe2HhRRdm72stok62LT+kELqwbLS38A+dfNboEgJxnyMZXdiPRxpOwdR0WSOuX7ORG8M4aPt/vs9XE1g6m5nM6WVC0UNe4h1XMZ/IfEtSbZXUQEYYwZHESqE6ETUcaOX6AQ920f8mu+eEMERt4aqFg9/uBK79Sv8FcG66CUpPsbCv1ab9uCLubcasqCwhDZc0MMI3dgt+s85/S6enLQ09OHH4FtRV8CAsyqatb7nW92HA2AcKnh99ebDJkcTokDgTFBnvYmQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS4PR04MB9692.eurprd04.prod.outlook.com (2603:10a6:20b:4fe::20) by DU2PR04MB9180.eurprd04.prod.outlook.com (2603:10a6:10:2f7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Wed, 15 Jan 2025 10:45:03 +0000 Received: from AS4PR04MB9692.eurprd04.prod.outlook.com ([fe80::a2bf:4199:6415:f299]) by AS4PR04MB9692.eurprd04.prod.outlook.com ([fe80::a2bf:4199:6415:f299%3]) with mapi id 15.20.8356.010; Wed, 15 Jan 2025 10:45:03 +0000 From: Neeraj Sanjay Kale To: marcel@holtmann.org, luiz.dentz@gmail.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, amitkumar.karwar@nxp.com, neeraj.sanjaykale@nxp.com, sherry.sun@nxp.com, ziniu.wang_1@nxp.com, johan.korsnes@remarkable.no, kristian.krohn@remarkable.no, manjeet.gupta@nxp.com Subject: [PATCH v4 2/2] Bluetooth: btnxpuart: Add support for set BD address Date: Wed, 15 Jan 2025 16:16:14 +0530 Message-Id: <20250115104614.2381674-2-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250115104614.2381674-1-neeraj.sanjaykale@nxp.com> References: <20250115104614.2381674-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SI2PR02CA0009.apcprd02.prod.outlook.com (2603:1096:4:194::11) To AS4PR04MB9692.eurprd04.prod.outlook.com (2603:10a6:20b:4fe::20) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS4PR04MB9692:EE_|DU2PR04MB9180:EE_ X-MS-Office365-Filtering-Correlation-Id: 1620ffea-f523-43a1-b61b-08dd3551ab26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|7416014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?IfjgGhm055/dr5Cld3aWfTCUZ/BpRMs?= =?utf-8?q?313W/FZHLX9FAVL6WQCqiMyZpRydkPMpSijMKTeOOt8FtRiakKbi2Z/iguQf4Ci3r?= =?utf-8?q?MiczJWIj6Gm5USoObi2iwovlnM+MoVuysYh/KGpssVgh4WCpa3Tq+jkBZ2IEumC2L?= =?utf-8?q?WcP6F2L5kyUDzk5R+RNSVFvsiOeXAQJA/Il4Ct5iZgEje/55DoNxdPC2f9kxg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Dq9q9DRUCocBD9k1fonZxI5V05auHCNrmxffDhWC+hlHi8j7VaACPXwwMYPOpX?= =?utf-8?q?egB59rR2KPy1rOVkd76cmTIfuW/6KQclooIa7L5rvn3XtBhl9wyasB1k8sta0Doq5?= =?utf-8?q?q51kCs0XdxNPrf30HVsjku+1OaVe2QJRtr9WpfzCidu9tNgMZ5X8HtEzKuWxU97yy?= =?utf-8?q?ApUpkx3qfq4Pxa4I0loyalqSomY4GdewdpGDe595XlbB3eWF4g+EMdoFjxioTNCJL?= =?utf-8?q?ANWEiCC06Qhcq91Xz0QcbUm3R4PSn4lIXl3+lRmR6lJiExNntEbA4OJsPQNfsAOBW?= =?utf-8?q?CDhvMHHRchn?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS4PR04MB9692.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(7416014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?DxWXlLtSAaMLSKJ2CJH9ZVyL0ANW?= =?utf-8?q?2+v09onh/D+u/pFUkhkYqTJ1R1C0nnnRscXTQqqbIh49tKLr1MDoaDn9ot/If7vK4?= =?utf-8?q?XyiYnPRT126dMTAy/qqS92DA6mYSEZosnVOjr9GeA3zRWmO95awaEo/p8Jn1bUnjR?= =?utf-8?q?P07mfIa/oZc44kM/5keiDBKiXVjrJeK9kuvFjxx8t8D93jPqg0sUOVYApDw05dSp4?= =?utf-8?q?pO1QvBEvLhayMOsXvICcB8Yl+nscYuATG/R2cTRXbz19ztE062oUUn/OYcJOQjZdv?= =?utf-8?q?vabSgzkfBE7Y+MEr3p9jwlQlLPDrqSN2BKySVvBI1K9936QKj4PxIkQTGSGqjiFci?= =?utf-8?q?SP+sDRtSePl6KnUXt29bxBRMt9c1+gZ6EKe1XI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nj5F8FFTZduqziY?= =?utf-8?q?tM5AGhDyBOEyeA6SWlB5AyU1jmLHIuglDmPfs1Tp+k8UzZYFHII2WfYOYu/b8G0nq?= =?utf-8?q?J5SoDtBiXM7ItozkdxUPG2Wpo0WCwtSnqSmHOeW4FHZed0T4k1xxuiFd/vsib5HGm?= =?utf-8?q?F0pBo5690c7tB5+WdrTH0qoS0Kt/7M1KKz+korYMxJ74EMCgbtMEvItttEko3NVwl?= =?utf-8?q?hvkjwR0As/fdcOgIxoJC8WfUkbNtUYYkKHZ22vs0xWdoEVDh6b74Cg7j4j/JgANt6?= =?utf-8?q?qLh71dz/Ge/bY2j7IMxyU018ZxGPdhDCCA=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1620ffea-f523-43a1-b61b-08dd3551ab26 X-MS-Exchange-CrossTenant-AuthSource: AS4PR04MB9692.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2025 10:45:03.8363 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mwn+xFwaijsrHaB2FOzz0ytKKRlNa5xk4pZmzWJr2QZDcps6dsqVgpP+cvbySFh2TaCCnSRN7HsthIEjLpJQvQLbBY7CwUvNAfzhdOTMZd4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9180 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. Signed-off-by: Loic Poulain Signed-off-by: Johan Korsnes Signed-off-by: Kristian Husevåg Krohn Tested-by: Neeraj Sanjay Kale Signed-off-by: Neeraj Sanjay Kale --- 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) --- drivers/bluetooth/btnxpuart.c | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c index 1230045d78a5..f237c0264e0e 100644 --- a/drivers/bluetooth/btnxpuart.c +++ b/drivers/bluetooth/btnxpuart.c @@ -1197,6 +1197,34 @@ 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) +{ + u8 data[8] = { 0xfe, 0x06, 0, 0, 0, 0, 0, 0 }; + struct sk_buff *skb; + int err; + + memcpy(data + 2, bdaddr, 6); + + skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + err = PTR_ERR(skb); + bt_dev_err(hdev, "Reset before setting local-bd-addr failed (%ld)", + PTR_ERR(skb)); + return err; + } + kfree_skb(skb); + + skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(data), data, HCI_CMD_TIMEOUT); + if (IS_ERR(skb)) { + err = PTR_ERR(skb); + bt_dev_err(hdev, "Changing device address failed (%d)", err); + return err; + } + kfree_skb(skb); + + return 0; +} + /* NXP protocol */ static int nxp_setup(struct hci_dev *hdev) { @@ -1500,6 +1528,7 @@ static int nxp_serdev_probe(struct serdev_device *serdev) { struct hci_dev *hdev; struct btnxpuart_dev *nxpdev; + bdaddr_t ba; nxpdev = devm_kzalloc(&serdev->dev, sizeof(*nxpdev), GFP_KERNEL); if (!nxpdev) @@ -1547,8 +1576,16 @@ static int nxp_serdev_probe(struct serdev_device *serdev) hdev->send = nxp_enqueue; hdev->hw_error = nxp_hw_err; hdev->shutdown = nxp_shutdown; + 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;