From patchwork Wed Jan 15 16:38:46 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: 13940646 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2068.outbound.protection.outlook.com [40.107.104.68]) (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 B7BD6194A54; Wed, 15 Jan 2025 16:37:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736959064; cv=fail; b=bXiGLSxSyZ5TyyHqmbaVf6FXc2cvjrNbmZjzNL34WPQf3oS5OPF1TYh0vj3y0Zj+IC+BtqIMS5bxfTdS6FAk98FmprUtygbtrmeGM1X/fXjBc10ips6jQWG3Y8aRgtHA7NvnImMaXnwBGGEEkwEM7D7HRMRCXaXM51hqxN3flEE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736959064; c=relaxed/simple; bh=wtpNaREMXoeKvZyK2KJIhERJ8JA2vNi/7MLQlh7aSvE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=f3heXlp8rDLNT2aLbEUL9/LQKUqeXfeKacu92XmraR6ctJ5IbL1ksB2bnjQcx3B/n42wm35/CVoK/bM4AaVkD6vgVtlNLbu11asBh4tFWx3S1noqIhyC4QaK1xGraiANvFBaov9GQvISJeV8Dmw1tIeO2k6P8P43tikR8XAhSfc= 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=n2AXkztY; arc=fail smtp.client-ip=40.107.104.68 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="n2AXkztY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DIWW8d99U8MCY5xFWjol2N8p4Md1b4pYanS4tmtkiCrdhibNcf582NJz5HwJFO7+mSjc48TGxovNGhhPjizxOr5RIUJ2Hw4lFEwTI5+lkBUvRw1J69RRzvTztyLccgKjlixPKEDjOWC+BS0NNO6SG/t1o8xUff5DHJ0Xzs+C34ojK0zszApYcqlqCIgUFlqOwAGWU82DhBDF0iCL0vM/sykDlO8ZDdqYYjxbKEOZqswQOMypt9Aq5QF2pdvc+/fEASjwwKEZlMNWKHGiIuTIvzYSezvtjjyTfUzhGfFNdmFwi9YM7n7aITM/1D/2wtN++69VJAfLzW2Paosu3H6VXw== 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=jRe9+lZM2I1aLDz7V8EYgNMomijvzqACZ8+BxPNAUmg=; b=LXrQw2gFpkHOMBpHeSbkrj3d9UzGgO7uIZ0UE/Ki7lkoteqBHJDRx63L+y2+tFXuyIqPL0eP/VOPo5ZRn2NuGBBiuOaOPN3cisGtmu+vL1F9OWEOUye2N5ouIbT4VEkM+1mgFer1WDi0E4EiVkczlX6iACs+gW71Wzp5UH5ySfGFU+OSR0+7Soco157tKwr+mhh+pxC9v6XQxNsv2+OTXkuStNhfSH2TqatfKqkV5pwikomC5cPQq3XVSQK5pB89QzyO4QFnyxYjGcH2sRTqbEmyg+Otjgw4H9Zv81r/NnHqwjUrJEK60oTV+fnFKkr0fE8Sioxj39G9wq8+/SZb9g== 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=jRe9+lZM2I1aLDz7V8EYgNMomijvzqACZ8+BxPNAUmg=; b=n2AXkztYa8CO87imZm09bH3Qmu/P+RabmZbRbgwpVfPNGdCGlbZTK9Lw/CpEawO+yIUtUP/QdBR0h0PTMXzqTfCwWvXqCB80pzODrgcfTX5Z4GeztsNVonjmJJut999GBin33PCAu3oKJP8G8gx7UiS1WjMrgWXRMBhCn3WEumk+IDPEn9Rpw4rjqyytGAy0Qw1QGb9vcDHBni6EzwHd1esvYJX0CmRIR1sIHFKzpM4PgyHED8qlrINaAXwnRB/5JGn6ARscWSgNlYzNkg+pCVdIW0a5TppLHu2OHo7L3HVtKrvTLJPZLUXYUJFAm7yBIDu7qhDLYgLpFzY5Hh5cgg== 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 AS8PR04MB9079.eurprd04.prod.outlook.com (2603:10a6:20b:446::12) 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 16:37:40 +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 16:37:38 +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 v5 2/2] Bluetooth: btnxpuart: Add support for set BD address Date: Wed, 15 Jan 2025 22:08:46 +0530 Message-Id: <20250115163846.2385345-2-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250115163846.2385345-1-neeraj.sanjaykale@nxp.com> References: <20250115163846.2385345-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SI2P153CA0010.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::13) 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_|AS8PR04MB9079:EE_ X-MS-Office365-Filtering-Correlation-Id: cb67833b-8e1d-4717-448a-08dd3582ec24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Ceq9djp/3BRedg4AI5BTp92cuAB2rIW?= =?utf-8?q?bV0F5pskuZBT+QiPnhBGBzu/xdjkhaOpYCckEVdNpK+b4e9xIuup/muF+WW5TXvAp?= =?utf-8?q?ILas8zX6Imejnd6bIihdsX7Ukb+O8xzcTeQOXc4hO7DlbIm8uMWSLTG0tK0SL/KpH?= =?utf-8?q?wPnjy9Q0UogORCxHGI43Qgz1dId3cA/xA+7MQNxtXp14/jOD8QiitplWjCSlw3LOF?= =?utf-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UlemM1MgfC7Rin9JNUzzA7CnSVv4ze/4rb9F8/z8rsZwwdeHUPgy8cnoDw?= =?utf-8?q?JEO4E7pexrIxy7qapKjshTyLSc02FDS3/xNEsg7DLB4D7zfthLiAJKSv5l61q/4Xk?= =?utf-8?q?pHgaffDmpvkPcLgKNELaGps1gRWMx154FFamnFhvkDacnhuOMEQIbMt/JdDGV8F90?= =?utf-8?q?2NAFdPXVe/5MslW1VgFcG4Nq8B4JPBezz6WO9qqxp2Mu0eXaqMNVi+eSvMr0/yiOg?= =?utf-8?q?E5fpr/ObYvvvKq6vZPaxuixZDy1wV8eMOZTcraRUBCDxEQ+++6qCEf3kivNo6ZK97?= =?utf-8?q?VH0e/o5NMlH?= 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)(1800799024)(7416014)(376014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?85NHF3ewYOndctW3JZTJEaZ39Pmh?= =?utf-8?q?+Rq37w7MziPfDAMl+AHnKw9O6KZAQ+Ea/iZjcHhP1NtGxYFTiSk9YGzPNjJHVpEm2?= =?utf-8?q?Ofr5ydkwLMelKfPvMCIpc1Dv08kqbc+lPUiz7sxgcUtRtEeUfdNdsn2IMDQLP/d1z?= =?utf-8?q?BwdFdHzpmwImR02C5S5sSP/9NxpNBNV1nsN2NJnUGdrJb7aSOXh4PTzWBIW1E5d/o?= =?utf-8?q?MNrT+EYthTUTVvlw1Jeg5cmdX8wCt1RIVI15sJfOLLbacrUnymIIvlMQ8YwZHDg2D?= =?utf-8?q?1jk4OuNiZr8WGPVnZL5EdSERshwbrEK6fUBDcidXNmSfW2PfDKwCz5Z19HP9R1jxo?= =?utf-8?q?kUzoD8+GBXbPwLiIR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wWjF+5+YKvauaegHfYK5X3OG0gAqL/GN8OylpYuCz+?= =?utf-8?q?M4qH9ISBtWV5Zxs4pu5OBljSS3IukN5Zvgs13cqRiikvGbRqyEoAILscqRbwFoZ/Y?= =?utf-8?q?d3kn3LFIbJtuQQOET30Id98gpqB6HMteMGQ/Yd4iHTS4FV9Y868Quy5Y3L4KqLIge?= =?utf-8?q?YiUwrA4g1eILWMwZKoVWTM4GwR13631u8FCCBOVTHqT4WOgwFUxTd2NzD5pw5b6oj?= =?utf-8?q?zKol7VpDbN/5WoEnKgZB1zZRlQkP7ezKfV3gjdEDs9xZTJHK0L4UeGJxgwimlFT97?= =?utf-8?q?XxGVW3appLxyDweECmk+eix4B7n3DE40WA=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb67833b-8e1d-4717-448a-08dd3582ec24 X-MS-Exchange-CrossTenant-AuthSource: AS4PR04MB9692.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2025 16:37:38.1924 (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: EBrllZDiVRiebvS13w4LasYLwQMX08w6H/ZvTpkn+u7NP5FbenUzNItI9NdYBGsqJq2JLiS1uf6fD1bxgvoju5pqe8lLgegM4zkDc4IzbqM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9079 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) v5: Initialize local variable ba, update Copywrite year. (Kristian) --- drivers/bluetooth/btnxpuart.c | 39 ++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c index 1230045d78a5..dd9161bfd52c 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 @@ -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 = {0}; 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;