From patchwork Fri Mar 10 18:19:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neeraj Sanjay Kale X-Patchwork-Id: 662178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D19D5C6FA99 for ; Fri, 10 Mar 2023 18:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231485AbjCJSUN (ORCPT ); Fri, 10 Mar 2023 13:20:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbjCJSUL (ORCPT ); Fri, 10 Mar 2023 13:20:11 -0500 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2075.outbound.protection.outlook.com [40.107.241.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B9510284F; Fri, 10 Mar 2023 10:20:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d+mrvo22InCqcnjThS568Y9yeNfcsQQjuwMZoUtAiyhMYx4vuDlH2iuPamyS3mNGi4owvqBkzKPr14LXCm9rxBegGEI3/m3XkOfnYw6YS303b94s42qoTu0v5g1SM8wRuqYalhdywHSaCXeckXiABPUaDy068k9Q7aRReHqidk0D/7gOYe8svTia0SvmJH5U6cpdH8fdJ+yybtsQeyWaAgHxExtPzlRFTZYBAknsLKE7LDZbcTi5xq/UUjin0B9x+pqZXFLBQcueEhHInCko0IOyYKtbyHuzaVO3nRMEiPuH/HlkqUMpaGy8n/xPy2GjTRyyaUYnzwj30+oKNU/0Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Y8vUV52mlQbn5GtqgDoRGrOJqgeNqnjP4c40QHQo9Wg=; b=LUFvf7rDGf2FSA4xH5sOUrP9ST1qYOzOkP1WOL2lA6qPFbYYrl0sx4U9CobSg57pwfLwJX4yo2MuD2SXI7uI9dxVNnIdaYprsPgO5xFTqiIY4OM41cuNPswnoSVr5k4ErPQeZADQ2tZn6MFWXOFYGBrSRj0ixPeezoGL3L8oycU4NII0TUR1TXL9iC0MDOa2mLhW8LvPG+sU6t5HvYRc3A50mVhGcJ25OJpLHvyYGUNPL7nYB1YiCPOd9L2wKEn8qTWrN09X4FW8Y0EXhnUG1OLTdOePWolaElaYjA/+fSZ+YGpOPM1X2SBmZF6yvWs213qIPpkRnyuSKLVkHG9u5A== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Y8vUV52mlQbn5GtqgDoRGrOJqgeNqnjP4c40QHQo9Wg=; b=ekTH32RI62JHi+fE/4XmNB8fhN+oDz+vrvgpFibrbFjzVdedmiODNZ/63Pz8VlVruQZbYFogG+vZ5kr2ko9gfDMMYqZDEspxip+gjHSdpOZqELaPBj4TlYZqDvakUlug8c470Eiv6G2oOHROrPe8JzDOT/oipkYgIvR28XPGOIo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) by DB9PR04MB9704.eurprd04.prod.outlook.com (2603:10a6:10:303::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.16; Fri, 10 Mar 2023 18:20:07 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762%5]) with mapi id 15.20.6178.019; Fri, 10 Mar 2023 18:20:07 +0000 From: Neeraj Sanjay Kale To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, alok.a.tiwari@oracle.com, hdanton@sina.com, ilpo.jarvinen@linux.intel.com, leon@kernel.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org, amitkumar.karwar@nxp.com, rohit.fule@nxp.com, sherry.sun@nxp.com, neeraj.sanjaykale@nxp.com Subject: [PATCH v8 1/3] serdev: Add method to assert break signal over tty UART port Date: Fri, 10 Mar 2023 23:49:19 +0530 Message-Id: <20230310181921.1437890-2-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230310181921.1437890-1-neeraj.sanjaykale@nxp.com> References: <20230310181921.1437890-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG2PR04CA0195.apcprd04.prod.outlook.com (2603:1096:4:14::33) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|DB9PR04MB9704:EE_ X-MS-Office365-Filtering-Correlation-Id: 302b7648-666f-4580-e05e-08db21941389 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3I6IzM5ASbdSjFoq/dvYlxJvzn1abCYmyatrw+/lw2u1iYHIcBdOpBSl8Nfn6vIUEJdzwPH/u7LJHvuxBlYRslkyTQNP/VU18fRMt4KHAPrfNJDTiCdVopi/LBvjyHx0SUzmgOp8w3N+MpXJpiOi/u+7c9mhQBtuOv/TNK4QCErtFAd6Bl6BGTW6DCb5p6TDg7Lq3y0tz/UlvU3W+uZ9bY0Rd3y+P0ZK8Q2DWJlakOAdT+t8NDAOMA5aMwfWX6/RQVI2M5EsqGaFA8fzDobyY+GZv6iGGQgrCiTGcAnmBNiyP/EouiLVSRHRo2mkDtAR5sBN5Ze3dWYDuhdZZwVsh1jGesMRx4aTmu+/356+HDKI6mRds6BEY0g1bJEs/BxoT2CoPB5eS4YWpd6sygC9kD0MtRiF4tK9H4PTnbhiN/VRuEn6l5U8FwCR3ddN/JT3ZQMerc1iTzhT3/KPHNNnex8dx2WBN05OHhBy6Sxv69TvcYSGIAwm3b6rZ5qtOgqiCYSnVn/whTkbp7xPiyqb/IYK34VRKOQSyNpoiji9og+uq10miByHR8GjGTYwE7/hLo3guob+uRqr1xnHjAQCK9AF13i4DimdEAM7AofxtB10BXQ6T+C9Z7MS008rzc6aoZyMY2EbOXpp9RBGKqyrzQVldrrmNMVCjFajTv1IpdrhheHmG155tJIoEFJLDUN1TmaqXXTJnlUeBWVzFKgXfhVdP6VWz9EOGGtK8YLK744= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8603.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(451199018)(66946007)(66476007)(66556008)(1076003)(6512007)(6506007)(316002)(38100700002)(26005)(8676002)(36756003)(7416002)(478600001)(6666004)(8936002)(2906002)(5660300002)(6486002)(921005)(52116002)(86362001)(83380400001)(4326008)(2616005)(38350700002)(41300700001)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vTFeAV2uz3Qsp67YdsG8bPDHZpATSEGt93YheGDThYLCgpsyZ4PWI1Rp2iSB1vArrgGo1J0BqJTtJAV/d4qO0YhZnJOeKFIWfGbUipGRQgTpgzFjO5q+EhCK8915CZyBOn+JP5+w6gBvRh8EwdhBxwbZqHR0H57s8gNiwwFfGmKJPKcIClENCxpgC5Em7oFWqWT4lr+/UqkRr0sfW9cIGis0OFU1xO+RoI734MFc6mM8LYWy9ar3AkV03elltHri7eBqaq/5yGs+LM3rdKZzJvV2zi0guWqdT5FnggS2r9TeuStzk1zAeYCtko8uUWhDmeJqIsfphUuFVNDWy0na59zYjCrSC4DETIXLGdQJYBcSWkletrKgkeww6qwWXcbqd89U0hbfl2hKVMf+Flrvz/oYKW9TMUe9yUynP+H6wrNQYqCOZFsBnlIvGrqefO2i94oKgG9pQ1FIUqhf4MEqiJbVTTwEyXh+gXKOXuUQXeKEhD8csyRyWIeg16T2U86jn/0wBzjiFzfSoQ/y3zcQTkeR9PKHoPmk3GkFeGp5u14Xh6NfTXiIEnMJZ9vmV5XJqV8HJipLBSLKAYlX7I3hz9FXaCb6TArbZ8A2eqASRuPpZOzgCjFFHhJAWxpjecB9tj1Tj1NvUfROue9ZUTH0+dmOhP3sjWt/hZg4SwNE1LIcHgKuL1uDlo234LtoxzWAMpgGp6xOhFbVeYjl+Gsz7VDTpeXlFPQAAtPU9dRLuFcbawxbu2BSdVAlI2uAeYqb0Fr+haWAkx9W0VgRNXrsMp6ifP2a3SbEsrlb77MH0EJ0dSpEqmzSfjWtBTohOtXa3rqxvxGYLhLnWUCuiRog8QYzTg9htIbbUWbpu8h8Ivv1ztRiTg8shyc72bXkJ9kJ2YxhWaOMLw86uEiYkyN/vac2pQTkUAjEu75JGhSiM4LMYHtbUHl55bXDtZirQN2sXH1z3UpoEP1Na3OOJDmkb/w59GYJ4XbiikXDSACgV/aGAHq9+YfkyF8yE4IlWJVBC0jFCFVIhY4nl+OiDimrrt82wC4Ocihv0m0SZiQwP8MAkKuHm7zfUj4B9TiWMx9/KxkTMo5tu+2tikfgPxK0PYALJ7xrRVAXru4EhdUNihZLEDe+XRPTzPpNuX2cgm9UZMoWN3K1/uqYJ9GTqPpoXqofLfaVCtaxibF/p7ZiQB3GpZnlvAQFU1FMTz2IMWz8bkQQO6A7uhn4g+vlQC/OgObSrqaexPebCYWvcEWYuL0C2RlSAmDz9DX7cf2H2wmFhPPtSR7K186WNFLEqLprAhbHMmJqPVXkXgu331Q9o909bn4h1iE9oiwVOxMaaNzf+F2JZtg/bx0ACke5o3mzNIWARodHHtV+SAYz7e2tmaP3RpxwGrAeZbGjvThjv/cVIL17kD/WJUZeC7Rgi9nppEu++9pI2tfz2g4r3+UwC7hpPjICpZc4f9f/rm4nKkCTGlA1+amRDmMSaXltOamKzPE9VdTPKXzpQDO77VRKRPIhvlNOEg55Dxe/M17/2xdjO1+MLumL1b81NZWMNXAUghrFWBZ2y83HaJbWS3XYmKUHJ6qiBjfNP+HZcd3Q5no+V1ItkCxHVaggfRkUpofbKw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 302b7648-666f-4580-e05e-08db21941389 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 18:20:07.2079 (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: +Igxur1sDovRVuozIQN6cirOtOOQsLfSXNOxlZSyDFRLAOeOD2edqHnkjsJtmNWw6D9pUMWPgmFRFiTi0af6U4A0AoQ5iYgmGZcO/6K4FAw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9704 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Adds serdev_device_break_ctl() and an implementation for ttyport. This function simply calls the break_ctl in tty layer, which can assert a break signal over UART-TX line, if the tty and the underlying platform and UART peripheral supports this operation. Signed-off-by: Neeraj Sanjay Kale --- v3: Add details to the commit message. (Greg KH) --- drivers/tty/serdev/core.c | 11 +++++++++++ drivers/tty/serdev/serdev-ttyport.c | 12 ++++++++++++ include/linux/serdev.h | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 0180e1e4e75d..f2fdd6264e5d 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -405,6 +405,17 @@ int serdev_device_set_tiocm(struct serdev_device *serdev, int set, int clear) } EXPORT_SYMBOL_GPL(serdev_device_set_tiocm); +int serdev_device_break_ctl(struct serdev_device *serdev, int break_state) +{ + struct serdev_controller *ctrl = serdev->ctrl; + + if (!ctrl || !ctrl->ops->break_ctl) + return -EOPNOTSUPP; + + return ctrl->ops->break_ctl(ctrl, break_state); +} +EXPORT_SYMBOL_GPL(serdev_device_break_ctl); + static int serdev_drv_probe(struct device *dev) { const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index d367803e2044..9888673744af 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -247,6 +247,17 @@ static int ttyport_set_tiocm(struct serdev_controller *ctrl, unsigned int set, u return tty->ops->tiocmset(tty, set, clear); } +static int ttyport_break_ctl(struct serdev_controller *ctrl, unsigned int break_state) +{ + struct serport *serport = serdev_controller_get_drvdata(ctrl); + struct tty_struct *tty = serport->tty; + + if (!tty->ops->break_ctl) + return -EOPNOTSUPP; + + return tty->ops->break_ctl(tty, break_state); +} + static const struct serdev_controller_ops ctrl_ops = { .write_buf = ttyport_write_buf, .write_flush = ttyport_write_flush, @@ -259,6 +270,7 @@ static const struct serdev_controller_ops ctrl_ops = { .wait_until_sent = ttyport_wait_until_sent, .get_tiocm = ttyport_get_tiocm, .set_tiocm = ttyport_set_tiocm, + .break_ctl = ttyport_break_ctl, }; struct device *serdev_tty_port_register(struct tty_port *port, diff --git a/include/linux/serdev.h b/include/linux/serdev.h index 66f624fc618c..c065ef1c82f1 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -92,6 +92,7 @@ struct serdev_controller_ops { void (*wait_until_sent)(struct serdev_controller *, long); int (*get_tiocm)(struct serdev_controller *); int (*set_tiocm)(struct serdev_controller *, unsigned int, unsigned int); + int (*break_ctl)(struct serdev_controller *ctrl, unsigned int break_state); }; /** @@ -202,6 +203,7 @@ int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_ void serdev_device_wait_until_sent(struct serdev_device *, long); int serdev_device_get_tiocm(struct serdev_device *); int serdev_device_set_tiocm(struct serdev_device *, int, int); +int serdev_device_break_ctl(struct serdev_device *serdev, int break_state); void serdev_device_write_wakeup(struct serdev_device *); int serdev_device_write(struct serdev_device *, const unsigned char *, size_t, long); void serdev_device_write_flush(struct serdev_device *); @@ -255,6 +257,10 @@ static inline int serdev_device_set_tiocm(struct serdev_device *serdev, int set, { return -ENOTSUPP; } +static inline int serdev_device_break_ctl(struct serdev_device *serdev, int break_state) +{ + return -EOPNOTSUPP; +} static inline int serdev_device_write(struct serdev_device *sdev, const unsigned char *buf, size_t count, unsigned long timeout) { From patchwork Fri Mar 10 18:19:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neeraj Sanjay Kale X-Patchwork-Id: 661876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A021C6FD1C for ; Fri, 10 Mar 2023 18:20:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231731AbjCJSUg (ORCPT ); Fri, 10 Mar 2023 13:20:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231597AbjCJSUR (ORCPT ); Fri, 10 Mar 2023 13:20:17 -0500 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2065.outbound.protection.outlook.com [40.107.241.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0B7A11052B; Fri, 10 Mar 2023 10:20:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nDwq23mJ9GKYZ+x8vOaRFnu2PKcB6uODK7Yo1ubsFQo5tpmlBa+Vmv0JHM2lBCjMOylfr/Nd9mhiNgLm/KHd9HcTi079r0oCAsXb5zELA66ED2NuLzGNHZ0LQ2t1v5JrcWRNMFIalZ2xY29A5MnXUXDciJVdsruD/k4uMCulKx1v2I94ExA8vLC2CwJmN4hd3OdUqjFOmO0B05YnlWfS/GkQTXWLACqm5D+0kM7ETXL5+7+Ls4uxPHLR9JY5uhhBEdX4t1jJjEc77ClcPmyK51McoC/CGNLhD25wWtfTvyj7dyZfIpnGmQIUztUxgC4ZwIAH81yv5ZF/CM2PNJL+FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=3lXvJmWsKiEDF7bGa7efvlLRdaiR9wPwcnWO5lzbjF8=; b=eglYaZv6uHeRnSYmkphM0xo6htJIdWOESfC/D3Wro/LSYLamMW1DkRBpvTgqefq6RQpQv3tXplVwKwJPy5myeB6gk2HfP5dOxu6T/BuU7OG69vWnQ3lQbFdaNTDAO+DnTloVtHdZZGxiR47dZXqv8H5eVphwbvrpCJMUrmHZ+2wDlWB5QGMJGNG/ukRajmwhU33if4RKFi4IS/cAXdnkrbfXVAZ4sgCNu3LRlJCT9KbElcSoTkyE4ezbj+Arfn268oeJlB7KeRWTslco+GfZ6p14KiTEVw1CALBfIbAxzaFR+h64+JuiVJWEVTMuukY35F54eziek2wmlFz/JSPGag== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3lXvJmWsKiEDF7bGa7efvlLRdaiR9wPwcnWO5lzbjF8=; b=k6GYrFry6h5JKlk/nASOvOUPv+km5f7MACzynAUkPxRmbcskbEwNuMOhoHPEjTnKxdWObjSbmhrjpb3Vb9UrEiF8Vw3QPloHBOWHQnDrdRRLGfOXnhdAcuXtu31sUi2sVMD8VZGJre0wFkvDTgIJwZVXCs28yE+LRtFuQVj8saI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) by DB9PR04MB9704.eurprd04.prod.outlook.com (2603:10a6:10:303::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.16; Fri, 10 Mar 2023 18:20:13 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762%5]) with mapi id 15.20.6178.019; Fri, 10 Mar 2023 18:20:13 +0000 From: Neeraj Sanjay Kale To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, alok.a.tiwari@oracle.com, hdanton@sina.com, ilpo.jarvinen@linux.intel.com, leon@kernel.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org, amitkumar.karwar@nxp.com, rohit.fule@nxp.com, sherry.sun@nxp.com, neeraj.sanjaykale@nxp.com Subject: [PATCH v8 2/3] dt-bindings: net: bluetooth: Add NXP bluetooth support Date: Fri, 10 Mar 2023 23:49:20 +0530 Message-Id: <20230310181921.1437890-3-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230310181921.1437890-1-neeraj.sanjaykale@nxp.com> References: <20230310181921.1437890-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG2PR04CA0195.apcprd04.prod.outlook.com (2603:1096:4:14::33) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|DB9PR04MB9704:EE_ X-MS-Office365-Filtering-Correlation-Id: df840646-2387-4ae5-1cb1-08db21941718 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8pnLQMN4TxexaAQNbhPcAYbH1xu2werrqvhKvk/8izlHmpby4xSlE+gsteEeKVd9+qUgwtU8KUG2WkeDyP+GLuqJNhfWaCzFct28McS9U5l1ZgHL/3ZgvAtWnEfGISswq8nkGQRZ9FDgBlgb0NIFkhkHi0yUky3sJCmutGmjEQwREYGAV4lI3ZhIzWFpAqYwcDdbcOBaZHYvq//vsmvhLLJe+AhbrA+RHXRDL+1xGlxh2qt+vWDS+q5aGT1JKEHHLNpwlxikIuSGJVC6DunFz567mVWE8PaR2+0cyYHahmyz3AdDSlHtASyHA/w/A3jUSw+uWXML9zbzgtychiB9V4f7viihdllwaFf16ySFQJeHPUKP7NOvgc0Yms06IDrbJ4VvF7ZQWU+ElSDYVmkLDJMeJbI+sz3C2cDHL6k9OlFzdBRwzts6UND5i2gSQ0a2nwoDWBOwh+HM86cdG1po91bMBU22iLBe82JWRCtk3topGRcQIzhicuhZCk/oyi59khEWOREcYNUxoOYRRu+qAOesslFGpvxxNnMZH0+bET+IOxGAN/RYqRAZ3wdzF6I+z2X7rmW79vwDPeRgtk7wZm3YaM41A3YsqkJoBMVyZo2YPcDMDncWghCjeiAOeLAV/1YRz70xbP92vgE+Oo5cLazvMovdns+BdPWUe9x1ICCEDVAd8V1yDO4P8BNKwV8JxNZHTzaDgntsLE+95d0gRAInC6P4Sg8p0SpZ769ExVL7e1h/mYSVltD9MMmgOsJy X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8603.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(451199018)(66946007)(66476007)(66556008)(1076003)(6512007)(6506007)(316002)(38100700002)(26005)(8676002)(36756003)(7416002)(478600001)(6666004)(8936002)(2906002)(5660300002)(6486002)(921005)(52116002)(86362001)(966005)(83380400001)(4326008)(2616005)(38350700002)(41300700001)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vXBkZDloFn1LJaxg2wvR9Kn4sGxfEtCZq8WIAbwg0YWi9/+vt/vFC7QyiwTaVq4UKkVLnvRz6mxPxxf4mZoXjN7XwQWAlTdWzJHNkHzMr6bqKHDnN8eeqjDon7lddYJYMXnmLiBa7x+8k8Vz7K/Q2JD+q/HD2U7jzBxClBmGWt8eGHzYmzSBGilyCNl9hV82qmQmFTXH4uMmQ2hSQT4TBKuj5A2Idwk/NS5FeD9rpRAKe0MexfmY7VPT5bX4Om0Jv9/bkvEVnp1YjbI3AHe99qF7izdStb0/37yVCZsCDp62+zJ/yBcjAnC2zDGJJoE4f4ITfODWiMSxjPmr0dq2K8cogk4Qg5pH6V55jRWlFr3nTyUKsASlSsxcaXSMWINLwIw2S69Pxks1GRZiww0LxLfDvSY7s/PEwMOxX0YUZZdALGC6lL+Kswhner4sRXpCcUS/lyHGrhwwMXRJm4JGuk6rihHv7YMMVan5ZtSMyd2bhqFbLK/cDaV8aVK/eZZQ3IPhcS4rVu8OtTKh8TLm1q/oO6DJRjIZ4ZYYypskK+Y4pBvFBaySctco1gy/PbKi1bI5DrpAg8YPT+0LDJYq/tOjcUqqb+XZDslwnKbmXbB5r2LuAgdr1ZCB4vx/A4RGQdu7R7aOImlxNmbNGDIziseHgCGXBqQK/Yy/wdQh25hCZ4E130USN0WXC8P00zWb7fJtdcSC435/L5OuxFI2J7BK8EQym1SN6Mmlc61CY6Q1GiWFgCyYHVyh8gWOiV6a17gsmCeShxcX1GUT19j9/jXatl+SGxlb4UKmDXaQ/Hgah/aI0TOpdW3ZI9di7+o9VlayC13llXcEXcr3al86gdT19k5WjLEgQxJeAK4/P6Km4ZkVpONifiHxabTF1QJq6/NzgftyvdL0MtEp4+6ZTXfCPNFWrVq6InVzf3Xw7KkoWtAvlZvcMSh8/ZkOE7EE/pYQOZEjDzSsUyTFCJlqwbEFmJ/jZgJ2yJGt9lbDoxCEcWROztF9ptpWENluuj2MxVNkzx9NzbjUxqHisgGd0czDlvU4B0fEe5vcTyME8Zy5U6yH50BTfP99bvXkKEG7IinniLBad9xV/smcmnoY83TZ495KKo1Rvqnyg21NFQ9FE18xxGFV6El+4oLTIbADedJf3bZg3mknT628ryK1+PLq4xzDkrIAe71PHAepcg2D4i/zBpxIXNsUiRPmUxDB3rJzGC8OqfIfu1dK/HbluPvwaB/1VNXQF15DqqHgUDH9V2Hl0Nlk82MX8CTacFT0SjNfwrwneQkfhHMOU9mJ4pay0duNOFq3EPVRVGT5dWKR9IDmTVLTVptNoW5tpF/0GVTDnjOOpadSA+uf7tiL4prOeC/UpDYsNxcTLejOv5zhJquIns9Q2O4zm2nCYoJtbwr2hAYkligFRYNTEG1aKVXi4Dlbm28P9Y56ZXh3KnHGssyILU1zfBF6GbUCVHJCbSBmmeHY8K+MXGUHi/wxJ22f87NEAHxy5j8vrfqnvjbVO+TlHpV5KoAeXr6i6X0sA0KY8NFYxin9ki31ZLU9/zsmuTue/2ay4781uaDjPyJk35uyBFJVsx598OUZaYcHsnPk7U3WflSLYHEc7NZq7w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: df840646-2387-4ae5-1cb1-08db21941718 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 18:20:13.1420 (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: LoA5z5/x+UBKWdvrMax05ytgy29muHLFBymeni/QTp4aOKArowbsbHWVCAx0lE5bU3nDYWno07Ne3BhnhuXh/bc7cvYJSwDdus4NuanXfuc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9704 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add binding document for NXP bluetooth chipsets attached over UART. Signed-off-by: Neeraj Sanjay Kale Reviewed-by: Krzysztof Kozlowski --- v2: Resolved dt_binding_check errors. (Rob Herring) v2: Modified description, added specific compatibility devices, corrected indentations. (Krzysztof Kozlowski) v3: Modified description, renamed file (Krzysztof Kozlowski) v4: Resolved dt_binding_check errors, corrected indentation. (Rob Herring, Krzysztof Kozlowski) v5: Corrected serial device name in example. (Krzysztof Kozlowski) --- .../net/bluetooth/nxp,88w8987-bt.yaml | 46 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml diff --git a/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml b/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml new file mode 100644 index 000000000000..b913ca59b489 --- /dev/null +++ b/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/bluetooth/nxp,88w8987-bt.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP Bluetooth chips + +description: + This binding describes UART-attached NXP bluetooth chips. + These chips are dual-radio chips supporting WiFi and Bluetooth. + The bluetooth works on standard H4 protocol over 4-wire UART. + The RTS and CTS lines are used during FW download. + To enable power save mode, the host asserts break signal + over UART-TX line to put the chip into power save state. + De-asserting break wakes-up the BT chip. + +maintainers: + - Neeraj Sanjay Kale + +properties: + compatible: + enum: + - nxp,88w8987-bt + - nxp,88w8997-bt + + fw-init-baudrate: + description: + Chip baudrate after FW is downloaded and initialized. + This property depends on the module vendor's + configuration. If this property is not specified, + 115200 is set as default. + +required: + - compatible + +additionalProperties: false + +examples: + - | + serial { + bluetooth { + compatible = "nxp,88w8987-bt"; + fw-init-baudrate = <3000000>; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 32dd41574930..030ec6fe89df 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22835,6 +22835,12 @@ L: linux-mm@kvack.org S: Maintained F: mm/zswap.c +NXP BLUETOOTH WIRELESS DRIVERS +M: Amitkumar Karwar +M: Neeraj Kale +S: Maintained +F: Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml + THE REST M: Linus Torvalds L: linux-kernel@vger.kernel.org From patchwork Fri Mar 10 18:19:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Neeraj Sanjay Kale X-Patchwork-Id: 662177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 055D7C742A7 for ; Fri, 10 Mar 2023 18:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231812AbjCJSU7 (ORCPT ); Fri, 10 Mar 2023 13:20:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231752AbjCJSUi (ORCPT ); Fri, 10 Mar 2023 13:20:38 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2066.outbound.protection.outlook.com [40.107.104.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC5E51378BC; Fri, 10 Mar 2023 10:20:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oRXKURlUSQHjeCFF77W7MXtWrG8QWAcItOYYHh3J2AvHuDrVSW97ePce4SPCm1gRugJOTWRzo8TO3rAPVOH6mE7Ur/fyY6c7G9fevWt5tLAM77Z8l8oOPlmzyNvhnKz0yOH97gXGnvqlmd7Lcxtd3yUMFiHp2zXDiVc8eHn04n8ZCk6jvefbyAAbedBO53ooKzUo8R7AeDVd737dV2xUILCuwWLNLTF8khe9iMleBDJmYWnPGQXO25c+HNk8PUwEQyw7lL7YjgbwMZnO3KA7RZpH4PslteMFmm7zNIuJ7JpBiEgsZCrgAdi8hvhIUTJOxObr9Ou/Ux3ZhrnWvg3m9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=LFWnsGg6UaApo0o8ni/gu/8yZJigacz8/MnXacaK6lI=; b=T10RVfe+1R3pyG6z6xNebziWR2o5fQIgTpBmuxW6566f4NXWQGCnsSHKV+1ZFvv6RyaQ3uA5dgtL6RtRQlgsX5gpZ0NlPuSfItWRsaFrCBsLmmn9RjynR1aZ97dh5B6HXkBY7NOdyM1uMC6ajr9OMlKhsGBoqEMzq9b/mo+Uv41+tu2EPSTDIysO/drItBej0gAViGJ9siKUvkKjg2I3xJAkYSw+yH1jZqJgzctM0XyKngdvnpnGnDAAwi5aG8vqjpddOnIlzwV3H6ldodHNpCY/GRnnwbV42QhovJkV6ap0FO8cLBdE9wVSExSiCFQKgvhSfyuOcIBQgjixkWVEUA== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LFWnsGg6UaApo0o8ni/gu/8yZJigacz8/MnXacaK6lI=; b=isMa3ljkvZpo8VO3WhvgLtCNvnpkg6qyOBuPr7ZugslqXTQdUFzNepyEedDBY3r87chySbtiScAVZyh+swzpH3lLKiMWA3N6sRA0IADjaLDSvz58viUvgMe5f2MRmBXYNDt9+NDU+VKyrlxcSm6TfZSYSK78FXWKzLI+UImF/sg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) by DB9PR04MB9704.eurprd04.prod.outlook.com (2603:10a6:10:303::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.16; Fri, 10 Mar 2023 18:20:19 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762%5]) with mapi id 15.20.6178.019; Fri, 10 Mar 2023 18:20:19 +0000 From: Neeraj Sanjay Kale To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, alok.a.tiwari@oracle.com, hdanton@sina.com, ilpo.jarvinen@linux.intel.com, leon@kernel.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org, amitkumar.karwar@nxp.com, rohit.fule@nxp.com, sherry.sun@nxp.com, neeraj.sanjaykale@nxp.com Subject: [PATCH v8 3/3] Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets Date: Fri, 10 Mar 2023 23:49:21 +0530 Message-Id: <20230310181921.1437890-4-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230310181921.1437890-1-neeraj.sanjaykale@nxp.com> References: <20230310181921.1437890-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG2PR04CA0195.apcprd04.prod.outlook.com (2603:1096:4:14::33) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|DB9PR04MB9704:EE_ X-MS-Office365-Filtering-Correlation-Id: cd1ef3af-6e54-4d4d-d29b-08db21941ad6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5WpedZ449PrgZ+3s1dvHuoMIePoPBCJiOhhcUXKGScEX6FfZ2XNyromD2pFLqCZwJ2EG02QrmjwJ1tDgIzeYFd15R15GwbqxbvZv7QLAwT6HRmOwG5/En5flX1/X0pFpPlAjkYbTCfX6eIAtcreMNVyOtc1U4VRVzPjUNWtewyB8Vt9J3Oehaj5DnlooeYsh1s1Vq18wluWR8iH+viuhYOLhB1QMlkEMCjALYewvyipFgkpiq5uYMHTna9k6g9VkJ7QBln6D1XflQlHO75LdaYiw9VYvqSnFPaIGnFShXybgoIeg2phdCxggRf6lgrtiOb7S3iou9fsYCKqBh+gjYRmuJEf0yY8Mk45UPzg1IF3PeFAA36LDFoRG+faKWqNPeJxhnLD8zHwoIel9ScHsb62sUJDzcRdiZMwIOCQddmKk66ZsFjMmXw3zhFYvkcRSqLWGBNqpZ42ZEIAs3fIorYUuOBTsyO1MghR7+5oyYckuhl5wEST83Yr6/IsO5aIkeXzBUo9xALJgC09btrFrGwMKqC8n+ZEH5SQETOXn6VE/WB+N3JWUqAsmn8lfEorpWFzwCHlRJDYcKVy0dD127k1Y9ZEo+xiWUZNngHLhRm5fcpTvoFOe+iSUZY4CALlEa7bGeAEnghRN/OTkTve4Sy8dlPm9O25tygwF5cPbsyxbSGTYghAFMM3Bj5yPqTXlfQX8vwkusqH0n8Re6h5R2g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8603.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(451199018)(66946007)(66476007)(66556008)(1076003)(6512007)(6506007)(316002)(38100700002)(26005)(8676002)(66574015)(36756003)(7416002)(30864003)(478600001)(6666004)(8936002)(2906002)(5660300002)(6486002)(921005)(52116002)(86362001)(83380400001)(4326008)(2616005)(66899018)(38350700002)(41300700001)(186003)(579004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?QZNKd9p91XEz6bNh4J/ZG5IYSdFB?= =?utf-8?q?YHlPTdKIncFNLlr7sG4O+e2npcsB7MH1+B0FKjYeEB3Gnd1H68Yb3XQRdqWYumn+o?= =?utf-8?q?jyv8aBbogyZqLKJ8FTWJJuCLojhYM8s/ys0akZrFj83w5cB+NL6XA1uatjSWVPXhv?= =?utf-8?q?8vKDJuoIaOmaTT+suUmvp7sjVnNU9huAE292veJHXudCvZ59pDUp5+EuwGmUMOvrF?= =?utf-8?q?V0ilNE97hDk4u8ZYuv3lusUYUjf2VCYelNIJPv679yl/bUW8ATNEjizp7O9UdKyK8?= =?utf-8?q?Ef0pFzGxFj1ypnVsvIxTCsCtUK2cZEA5DycDO3r1yHdg2Gj1EOkTv1Jw1UIbA5Bf4?= =?utf-8?q?C6k0sgDfbMskyomZw01wSs/Y5F3M2t1hfv4SKX1yPNkqMkoDF6IOHgKM3b1siO4h5?= =?utf-8?q?6hA4JOtHlH9kxSeyp5FNXHrN+y5vBi23ExcEQ0lO6AmnFAxMqKXpjfBwlHLoVC3Xl?= =?utf-8?q?VMro/oODJYpeqyBaDWe+4xdtW/a+WAObnDuy9SWBN6BmEF8Qf4OZvUGRkUs6I9HfH?= =?utf-8?q?vJ/NgMn/1anT4WRo9HwZIYEK6zM3Kc/tZ3XYYXvR8Jvn1ZmFnXK7ZUsCYpfiplCi7?= =?utf-8?q?OgYN5AHv3C5wpnlerZHUTjgBdOyvxCATx6mgWdakXqi3pM/CsrAdtnHKoyS6oNcDk?= =?utf-8?q?DIYrmuNjBk+EzgSsw3FQSJ4ZncHX26kDcKE/nJTh0NsOLYVyedW5zjwto8sxNafEA?= =?utf-8?q?Br78zavP2VXiFjw5uWFmdiPdTTpwrPijOSTbzVAY3mop9nvwafNhhsWT8S5uLbsGd?= =?utf-8?q?KVQIkOT8JguC95MNGN+5osU8eh3Lz/r0jcOVZCfAwNh7d/w7EQyUZuWUzo+ttCx1N?= =?utf-8?q?RIXLNcstMAD8K0db5mgRrGj/nsSOLKBrwIfc4gh/y/hu3T8qjYSXOKt5WwTzR6Dtf?= =?utf-8?q?vK2gl8NiCVqX3IfiKTsBdCGCufbQLEdtAZ8+j8oiNRMJyeHSGLt6rDe/CO31oqrrH?= =?utf-8?q?NOdel2VBL2LMToK6/RnrL9u7XrcGypZbWtbcIxwpjD1LLyanhrrktxJ+NimqWj4M1?= =?utf-8?q?j20ecn7kE6qINAnEODy5Gno6F8OyAK7UTydixfE+OZG/IQJ8Y9zFSPBa7X/Xslghd?= =?utf-8?q?6K8pPH1a0kgznVTnmes6cjmZwUo+3lu44G6tJp9O4CK1gQyy2OqHU+9m99E7Rr7cg?= =?utf-8?q?T4fL4WJJ/jqqUIU26XhPxQdCAisaN2SnuV9JZPddb/iyyFwO4JFX9v9qpXyIiHhMt?= =?utf-8?q?w5NRWGmWQ7h02TAr80vZvScC5epo9MHJim8VVUxd54NIGQ1AmgTksp6k3Lt79+FXY?= =?utf-8?q?2nAzyo/MxjL4aUiY6+v9wZXpijva8P+XhmrInEWVqAa9pyBUneKViJi4kjCTJm1Fl?= =?utf-8?q?mF6+VOgdToo4UVo/JyqT+N7b0MwzaeZCkxZfhiupuouQ++xCJ52f2aKq6Mm7Szlxk?= =?utf-8?q?UU15jcHtdwelYZ4rWOAns71JwjwbCmsR2REAGIJ2svwPedMg1EIgeiyTecM0xTCV/?= =?utf-8?q?u5EZZGp13pZyFo2fG80pOw1sSQkEcdI/oLNfNeYUpgT9dK+sKGKDcxy+ytQrqowCJ?= =?utf-8?q?N5bbJIMzzF8p0Mxcx74mSTm1OIf5gTl+kg=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd1ef3af-6e54-4d4d-d29b-08db21941ad6 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 18:20:19.5981 (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: TPh8kDXtO+GRNN3Zf9fDsa57by40PTeqykyk0hz0Agr0MBvxoYEBME56HaW34fw92eQ2Z+RPQjUCfrgX7mGEsGr7ioHvpm5jEeejT/YtXmA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9704 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds a driver based on serdev driver for the NXP BT serial protocol based on running H:4, which can enable the built-in Bluetooth device inside an NXP BT chip. This driver has Power Save feature that will put the chip into sleep state whenever there is no activity for 2000ms, and will be woken up when any activity is to be initiated over UART. This driver enables the power save feature by default by sending the vendor specific commands to the chip during setup. During setup, the driver checks if a FW is already running on the chip by waiting for the bootloader signature, and downloads device specific FW file into the chip over UART if bootloader signature is received.. Signed-off-by: Neeraj Sanjay Kale --- v2: Removed conf file support and added static data for each chip based on compatibility devices mentioned in DT bindings. Handled potential memory leaks and null pointer dereference issues, simplified FW download feature, handled byte-order and few cosmetic changes. (Ilpo Järvinen, Alok Tiwari, Hillf Danton) v3: Added conf file support necessary to support different vendor modules, moved .h file contents to .c, cosmetic changes. (Luiz Augusto von Dentz, Rob Herring, Leon Romanovsky) v4: Removed conf file support, optimized driver data, add logic to select FW name based on chip signature (Greg KH, Ilpo Järvinen, Sherry Sun) v5: Replaced bt_dev_info() with bt_dev_dbg(), handled user-space cmd parsing in nxp_enqueue() in a better way. (Greg KH, Luiz Augusto von Dentz) v6: Add support for fw-init-baudrate parameter from device tree, modified logic to detect FW download is needed or FW is running. (Greg KH, Sherry Sun) v7: Renamed variables, improved FW download functions, include ps_data into btnxpuart_dev. (Ilpo Järvinen) v8: Move bootloader signature handling to a separate function. Add select CRC32 to Kconfig file. (Ilpo Järvinen) --- MAINTAINERS | 1 + drivers/bluetooth/Kconfig | 11 + drivers/bluetooth/Makefile | 1 + drivers/bluetooth/btnxpuart.c | 1293 +++++++++++++++++++++++++++++++++ 4 files changed, 1306 insertions(+) create mode 100644 drivers/bluetooth/btnxpuart.c diff --git a/MAINTAINERS b/MAINTAINERS index 030ec6fe89df..fdb9b0788c89 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22840,6 +22840,7 @@ M: Amitkumar Karwar M: Neeraj Kale S: Maintained F: Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml +F: drivers/bluetooth/btnxpuart.c THE REST M: Linus Torvalds diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 5a1a7bec3c42..359a4833e31f 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -465,4 +465,15 @@ config BT_VIRTIO Say Y here to compile support for HCI over Virtio into the kernel or say M to compile as a module. +config BT_NXPUART + tristate "NXP protocol support" + depends on SERIAL_DEV_BUS + help + NXP is serial driver required for NXP Bluetooth + devices with UART interface. + + Say Y here to compile support for NXP Bluetooth UART device into + the kernel, or say M here to compile as a module (btnxpuart). + + endmenu diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index e0b261f24fc9..7a5967e9ac48 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_BT_QCA) += btqca.o obj-$(CONFIG_BT_MTK) += btmtk.o obj-$(CONFIG_BT_VIRTIO) += virtio_bt.o +obj-$(CONFIG_BT_NXPUART) += btnxpuart.o obj-$(CONFIG_BT_HCIUART_NOKIA) += hci_nokia.o diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c new file mode 100644 index 000000000000..81d89a0ebe32 --- /dev/null +++ b/drivers/bluetooth/btnxpuart.c @@ -0,0 +1,1293 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * NXP Bluetooth driver + * Copyright 2018-2023 NXP + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "h4_recv.h" + +#define MANUFACTURER_NXP 37 + +#define BTNXPUART_TX_STATE_ACTIVE 1 +#define BTNXPUART_FW_DOWNLOADING 2 +#define BTNXPUART_CHECK_BOOT_SIGNATURE 3 +#define BTNXPUART_SERDEV_OPEN 4 + +#define FIRMWARE_W8987 "nxp/uartuart8987_bt.bin" +#define FIRMWARE_W8997 "nxp/uartuart8997_bt_v4.bin" +#define FIRMWARE_W9098 "nxp/uartuart9098_bt_v1.bin" +#define FIRMWARE_IW416 "nxp/uartiw416_bt_v0.bin" +#define FIRMWARE_IW612 "nxp/uartspi_n61x_v1.bin.se" + +#define CHIP_ID_W9098 0x5c03 +#define CHIP_ID_IW416 0x7201 +#define CHIP_ID_IW612 0x7601 + +#define HCI_NXP_PRI_BAUDRATE 115200 +#define HCI_NXP_SEC_BAUDRATE 3000000 + +#define MAX_FW_FILE_NAME_LEN 50 + +/* Default ps timeout period in milli-second */ +#define PS_DEFAULT_TIMEOUT_PERIOD 2000 + +/* wakeup methods */ +#define WAKEUP_METHOD_DTR 0 +#define WAKEUP_METHOD_BREAK 1 +#define WAKEUP_METHOD_EXT_BREAK 2 +#define WAKEUP_METHOD_RTS 3 +#define WAKEUP_METHOD_INVALID 0xff + +/* power save mode status */ +#define PS_MODE_DISABLE 0 +#define PS_MODE_ENABLE 1 + +/* Power Save Commands to ps_work_func */ +#define PS_CMD_EXIT_PS 1 +#define PS_CMD_ENTER_PS 2 + +/* power save state */ +#define PS_STATE_AWAKE 0 +#define PS_STATE_SLEEP 1 + +/* Bluetooth vendor command : Sleep mode */ +#define HCI_NXP_AUTO_SLEEP_MODE 0xfc23 +/* Bluetooth vendor command : Wakeup method */ +#define HCI_NXP_WAKEUP_METHOD 0xfc53 +/* Bluetooth vendor command : Set operational baudrate */ +#define HCI_NXP_SET_OPER_SPEED 0xfc09 +/* Bluetooth vendor command: Independent Reset */ +#define HCI_NXP_IND_RESET 0xfcfc + +/* Bluetooth Power State : Vendor cmd params */ +#define BT_PS_ENABLE 0x02 +#define BT_PS_DISABLE 0x03 + +/* Bluetooth Host Wakeup Methods */ +#define BT_HOST_WAKEUP_METHOD_NONE 0x00 +#define BT_HOST_WAKEUP_METHOD_DTR 0x01 +#define BT_HOST_WAKEUP_METHOD_BREAK 0x02 +#define BT_HOST_WAKEUP_METHOD_GPIO 0x03 + +/* Bluetooth Chip Wakeup Methods */ +#define BT_CTRL_WAKEUP_METHOD_DSR 0x00 +#define BT_CTRL_WAKEUP_METHOD_BREAK 0x01 +#define BT_CTRL_WAKEUP_METHOD_GPIO 0x02 +#define BT_CTRL_WAKEUP_METHOD_EXT_BREAK 0x04 +#define BT_CTRL_WAKEUP_METHOD_RTS 0x05 + +struct ps_data { + u8 target_ps_mode; /* ps mode to be set */ + u8 cur_psmode; /* current ps_mode */ + u8 ps_state; /* controller's power save state */ + u8 ps_cmd; + u8 h2c_wakeupmode; + u8 cur_h2c_wakeupmode; + u8 c2h_wakeupmode; + u8 c2h_wakeup_gpio; + u8 h2c_wakeup_gpio; + bool driver_sent_cmd; + u16 h2c_ps_interval; + u16 c2h_ps_interval; + struct hci_dev *hdev; + struct work_struct work; + struct timer_list ps_timer; +}; + +struct wakeup_cmd_payload { + u8 c2h_wakeupmode; + u8 c2h_wakeup_gpio; + u8 h2c_wakeupmode; + u8 h2c_wakeup_gpio; +} __packed; + +struct psmode_cmd_payload { + u8 ps_cmd; + __le16 c2h_ps_interval; +} __packed; + +struct btnxpuart_data { + bool fw_dnld_use_high_baudrate; + const u8 *fw_name; +}; + +struct btnxpuart_dev { + struct hci_dev *hdev; + struct serdev_device *serdev; + + struct work_struct tx_work; + unsigned long tx_state; + struct sk_buff_head txq; + struct sk_buff *rx_skb; + + const struct firmware *fw; + u8 fw_name[MAX_FW_FILE_NAME_LEN]; + u32 fw_dnld_v1_offset; + u32 fw_v1_sent_bytes; + u32 fw_v3_offset_correction; + u32 fw_v1_expected_len; + wait_queue_head_t fw_dnld_done_wait_q; + wait_queue_head_t check_boot_sign_wait_q; + + u32 new_baudrate; + u32 current_baudrate; + u32 fw_init_baudrate; + bool timeout_changed; + bool baudrate_changed; + + struct ps_data psdata; + struct btnxpuart_data *nxp_data; +}; + +#define NXP_V1_FW_REQ_PKT 0xa5 +#define NXP_V1_CHIP_VER_PKT 0xaa +#define NXP_V3_FW_REQ_PKT 0xa7 +#define NXP_V3_CHIP_VER_PKT 0xab + +#define NXP_ACK_V1 0x5a +#define NXP_NAK_V1 0xbf +#define NXP_ACK_V3 0x7a +#define NXP_NAK_V3 0x7b +#define NXP_CRC_ERROR_V3 0x7c + +#define HDR_LEN 16 + +#define NXP_RECV_FW_REQ_V1 \ + .type = NXP_V1_FW_REQ_PKT, \ + .hlen = 4, \ + .loff = 0, \ + .lsize = 0, \ + .maxlen = 4 + +#define NXP_RECV_CHIP_VER_V3 \ + .type = NXP_V3_CHIP_VER_PKT, \ + .hlen = 4, \ + .loff = 0, \ + .lsize = 0, \ + .maxlen = 4 + +#define NXP_RECV_FW_REQ_V3 \ + .type = NXP_V3_FW_REQ_PKT, \ + .hlen = 9, \ + .loff = 0, \ + .lsize = 0, \ + .maxlen = 9 + +struct v1_data_req { + __le16 len; + __le16 len_comp; +} __packed; + +struct v3_data_req { + __le16 len; + __le32 offset; + __le16 error; + u8 crc; +} __packed; + +struct v3_start_ind { + __le16 chip_id; + u8 loader_ver; + u8 crc; +} __packed; + +/* UART register addresses of BT chip */ +#define CLKDIVADDR 0x7f00008f +#define UARTDIVADDR 0x7f000090 +#define UARTMCRADDR 0x7f000091 +#define UARTREINITADDR 0x7f000092 +#define UARTICRADDR 0x7f000093 +#define UARTFCRADDR 0x7f000094 + +#define MCR 0x00000022 +#define INIT 0x00000001 +#define ICR 0x000000c7 +#define FCR 0x000000c7 + +#define POLYNOMIAL8 0x07 + +struct uart_reg { + __le32 address; + __le32 value; +} __packed; + +struct uart_config { + struct uart_reg clkdiv; + struct uart_reg uartdiv; + struct uart_reg mcr; + struct uart_reg re_init; + struct uart_reg icr; + struct uart_reg fcr; + __le32 crc; +} __packed; + +struct nxp_bootloader_cmd { + __le32 header; + __le32 arg; + __le32 payload_len; + __le32 crc; +} __packed; + +static u8 crc8_table[CRC8_TABLE_SIZE]; + +/* Default configurations */ +#define DEFAULT_H2C_WAKEUP_MODE WAKEUP_METHOD_BREAK +#define DEFAULT_PS_MODE PS_MODE_ENABLE +#define FW_INIT_BAUDRATE HCI_NXP_PRI_BAUDRATE + +static struct sk_buff *nxp_drv_send_cmd(struct hci_dev *hdev, u16 opcode, + u32 plen, + void *param) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + struct sk_buff *skb; + + /* set flag to prevent nxp_enqueue from parsing values from this command and + * calling hci_cmd_sync_queue() again. + */ + psdata->driver_sent_cmd = true; + skb = __hci_cmd_sync(hdev, opcode, plen, param, HCI_CMD_TIMEOUT); + psdata->driver_sent_cmd = false; + + return skb; +} + +static void btnxpuart_tx_wakeup(struct btnxpuart_dev *nxpdev) +{ + if (schedule_work(&nxpdev->tx_work)) + set_bit(BTNXPUART_TX_STATE_ACTIVE, &nxpdev->tx_state); +} + +/* NXP Power Save Feature */ +static void ps_start_timer(struct btnxpuart_dev *nxpdev) +{ + struct ps_data *psdata = &nxpdev->psdata; + + if (!psdata) + return; + + if (psdata->cur_psmode == PS_MODE_ENABLE) + mod_timer(&psdata->ps_timer, jiffies + msecs_to_jiffies(psdata->h2c_ps_interval)); +} + +static void ps_cancel_timer(struct btnxpuart_dev *nxpdev) +{ + struct ps_data *psdata = &nxpdev->psdata; + + flush_work(&psdata->work); + del_timer_sync(&psdata->ps_timer); +} + +static void ps_control(struct hci_dev *hdev, u8 ps_state) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + int status; + + if (psdata->ps_state == ps_state || + !test_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state)) + return; + + switch (psdata->cur_h2c_wakeupmode) { + case WAKEUP_METHOD_DTR: + if (ps_state == PS_STATE_AWAKE) + status = serdev_device_set_tiocm(nxpdev->serdev, TIOCM_DTR, 0); + else + status = serdev_device_set_tiocm(nxpdev->serdev, 0, TIOCM_DTR); + break; + case WAKEUP_METHOD_BREAK: + default: + if (ps_state == PS_STATE_AWAKE) + status = serdev_device_break_ctl(nxpdev->serdev, 0); + else + status = serdev_device_break_ctl(nxpdev->serdev, -1); + bt_dev_dbg(hdev, "Set UART break: %s, status=%d", + str_on_off(ps_state == PS_STATE_SLEEP), status); + break; + } + if (!status) + psdata->ps_state = ps_state; + if (ps_state == PS_STATE_AWAKE) + btnxpuart_tx_wakeup(nxpdev); +} + +static void ps_work_func(struct work_struct *work) +{ + struct ps_data *data = container_of(work, struct ps_data, work); + + if (data->ps_cmd == PS_CMD_ENTER_PS && data->cur_psmode == PS_MODE_ENABLE) + ps_control(data->hdev, PS_STATE_SLEEP); + else if (data->ps_cmd == PS_CMD_EXIT_PS) + ps_control(data->hdev, PS_STATE_AWAKE); +} + +static void ps_timeout_func(struct timer_list *t) +{ + struct ps_data *data = from_timer(data, t, ps_timer); + struct hci_dev *hdev = data->hdev; + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + if (test_bit(BTNXPUART_TX_STATE_ACTIVE, &nxpdev->tx_state)) { + ps_start_timer(nxpdev); + } else { + data->ps_cmd = PS_CMD_ENTER_PS; + schedule_work(&data->work); + } +} + +static int ps_init_work(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + + psdata->h2c_ps_interval = PS_DEFAULT_TIMEOUT_PERIOD; + psdata->ps_state = PS_STATE_AWAKE; + psdata->target_ps_mode = DEFAULT_PS_MODE; + psdata->hdev = hdev; + psdata->c2h_wakeupmode = BT_HOST_WAKEUP_METHOD_NONE; + psdata->c2h_wakeup_gpio = 0xff; + + switch (DEFAULT_H2C_WAKEUP_MODE) { + case WAKEUP_METHOD_DTR: + psdata->h2c_wakeupmode = WAKEUP_METHOD_DTR; + break; + case WAKEUP_METHOD_BREAK: + default: + psdata->h2c_wakeupmode = WAKEUP_METHOD_BREAK; + break; + } + psdata->cur_psmode = PS_MODE_DISABLE; + psdata->cur_h2c_wakeupmode = WAKEUP_METHOD_INVALID; + INIT_WORK(&psdata->work, ps_work_func); + + return 0; +} + +static void ps_init_timer(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + + timer_setup(&psdata->ps_timer, ps_timeout_func, 0); +} + +static void ps_wakeup(struct btnxpuart_dev *nxpdev) +{ + struct ps_data *psdata = &nxpdev->psdata; + + if (psdata->ps_state != PS_STATE_AWAKE) { + psdata->ps_cmd = PS_CMD_EXIT_PS; + schedule_work(&psdata->work); + } +} + +static int send_ps_cmd(struct hci_dev *hdev, void *data) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + struct psmode_cmd_payload pcmd; + struct sk_buff *skb; + u8 *status; + + if (psdata->target_ps_mode == PS_MODE_ENABLE) + pcmd.ps_cmd = BT_PS_ENABLE; + else + pcmd.ps_cmd = BT_PS_DISABLE; + pcmd.c2h_ps_interval = __cpu_to_le16(psdata->c2h_ps_interval); + + skb = nxp_drv_send_cmd(hdev, HCI_NXP_AUTO_SLEEP_MODE, sizeof(pcmd), &pcmd); + if (IS_ERR(skb)) { + bt_dev_err(hdev, "Setting Power Save mode failed (%ld)", PTR_ERR(skb)); + return PTR_ERR(skb); + } + + status = skb_pull_data(skb, 1); + if (status) { + if (!*status) + psdata->cur_psmode = psdata->target_ps_mode; + else + psdata->target_ps_mode = psdata->cur_psmode; + if (psdata->cur_psmode == PS_MODE_ENABLE) + ps_start_timer(nxpdev); + else + ps_wakeup(nxpdev); + bt_dev_dbg(hdev, "Power Save mode response: status=%d, ps_mode=%d", + *status, psdata->cur_psmode); + } + kfree_skb(skb); + + return 0; +} + +static int send_wakeup_method_cmd(struct hci_dev *hdev, void *data) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + struct wakeup_cmd_payload pcmd; + struct sk_buff *skb; + u8 *status; + + pcmd.c2h_wakeupmode = psdata->c2h_wakeupmode; + pcmd.c2h_wakeup_gpio = psdata->c2h_wakeup_gpio; + switch (psdata->h2c_wakeupmode) { + case WAKEUP_METHOD_DTR: + pcmd.h2c_wakeupmode = BT_CTRL_WAKEUP_METHOD_DSR; + break; + case WAKEUP_METHOD_BREAK: + default: + pcmd.h2c_wakeupmode = BT_CTRL_WAKEUP_METHOD_BREAK; + break; + } + pcmd.h2c_wakeup_gpio = 0xff; + + skb = nxp_drv_send_cmd(hdev, HCI_NXP_WAKEUP_METHOD, sizeof(pcmd), &pcmd); + if (IS_ERR(skb)) { + bt_dev_err(hdev, "Setting wake-up method failed (%ld)", PTR_ERR(skb)); + return PTR_ERR(skb); + } + + status = skb_pull_data(skb, 1); + if (status) { + if (*status == 0) + psdata->cur_h2c_wakeupmode = psdata->h2c_wakeupmode; + else + psdata->h2c_wakeupmode = psdata->cur_h2c_wakeupmode; + bt_dev_dbg(hdev, "Set Wakeup Method response: status=%d, h2c_wakeupmode=%d", + *status, psdata->cur_h2c_wakeupmode); + } + kfree_skb(skb); + + return 0; +} + +static void ps_init(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + + serdev_device_set_tiocm(nxpdev->serdev, 0, TIOCM_RTS); + usleep_range(5000, 10000); + serdev_device_set_tiocm(nxpdev->serdev, TIOCM_RTS, 0); + usleep_range(5000, 10000); + + switch (psdata->h2c_wakeupmode) { + case WAKEUP_METHOD_DTR: + serdev_device_set_tiocm(nxpdev->serdev, 0, TIOCM_DTR); + serdev_device_set_tiocm(nxpdev->serdev, TIOCM_DTR, 0); + break; + case WAKEUP_METHOD_BREAK: + default: + serdev_device_break_ctl(nxpdev->serdev, -1); + usleep_range(5000, 10000); + serdev_device_break_ctl(nxpdev->serdev, 0); + usleep_range(5000, 10000); + break; + } + if (psdata->cur_h2c_wakeupmode != psdata->h2c_wakeupmode) + hci_cmd_sync_queue(hdev, send_wakeup_method_cmd, NULL, NULL); + if (psdata->cur_psmode != psdata->target_ps_mode) + hci_cmd_sync_queue(hdev, send_ps_cmd, NULL, NULL); +} + +/* NXP Firmware Download Feature */ +static int nxp_download_firmware(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + int err = 0; + + nxpdev->fw_dnld_v1_offset = 0; + nxpdev->fw_v1_sent_bytes = 0; + nxpdev->fw_v1_expected_len = HDR_LEN; + nxpdev->fw_v3_offset_correction = 0; + nxpdev->baudrate_changed = false; + nxpdev->timeout_changed = false; + + serdev_device_set_baudrate(nxpdev->serdev, HCI_NXP_PRI_BAUDRATE); + serdev_device_set_flow_control(nxpdev->serdev, 0); + nxpdev->current_baudrate = HCI_NXP_PRI_BAUDRATE; + + /* Wait till FW is downloaded and CTS becomes low */ + err = wait_event_interruptible_timeout(nxpdev->fw_dnld_done_wait_q, + !test_bit(BTNXPUART_FW_DOWNLOADING, + &nxpdev->tx_state), + msecs_to_jiffies(60000)); + if (err == 0) { + bt_dev_err(hdev, "FW Download Timeout."); + return -ETIMEDOUT; + } + + serdev_device_set_flow_control(nxpdev->serdev, 1); + err = serdev_device_wait_for_cts(nxpdev->serdev, 1, 60000); + if (err < 0) { + bt_dev_err(hdev, "CTS is still high. FW Download failed."); + return err; + } + release_firmware(nxpdev->fw); + memset(nxpdev->fw_name, 0, sizeof(nxpdev->fw_name)); + + /* Allow the downloaded FW to initialize */ + usleep_range(800 * USEC_PER_MSEC, 1 * USEC_PER_SEC); + + return 0; +} + +static void nxp_send_ack(u8 ack, struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + u8 ack_nak[2]; + int len = 1; + + ack_nak[0] = ack; + if (ack == NXP_ACK_V3) { + ack_nak[1] = crc8(crc8_table, ack_nak, 1, 0xff); + len = 2; + } + serdev_device_write_buf(nxpdev->serdev, ack_nak, len); +} + +static bool nxp_fw_change_baudrate(struct hci_dev *hdev, u16 req_len) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct nxp_bootloader_cmd nxp_cmd5; + struct uart_config uart_config; + + if (req_len == sizeof(nxp_cmd5)) { + nxp_cmd5.header = __cpu_to_le32(5); + nxp_cmd5.arg = 0; + nxp_cmd5.payload_len = __cpu_to_le32(sizeof(uart_config)); + nxp_cmd5.crc = __cpu_to_le32(crc32_be(0UL, (char *)&nxp_cmd5, + sizeof(nxp_cmd5) - 4)); + nxp_cmd5.crc = swab32(nxp_cmd5.crc); /* FW expects swapped CRC bytes */ + + serdev_device_write_buf(nxpdev->serdev, (u8 *)&nxp_cmd5, sizeof(nxp_cmd5)); + nxpdev->fw_v3_offset_correction += req_len; + } else if (req_len == sizeof(uart_config)) { + uart_config.clkdiv.address = __cpu_to_le32(CLKDIVADDR); + uart_config.clkdiv.value = __cpu_to_le32(0x00c00000); + uart_config.uartdiv.address = __cpu_to_le32(UARTDIVADDR); + uart_config.uartdiv.value = __cpu_to_le32(1); + uart_config.mcr.address = __cpu_to_le32(UARTMCRADDR); + uart_config.mcr.value = __cpu_to_le32(MCR); + uart_config.re_init.address = __cpu_to_le32(UARTREINITADDR); + uart_config.re_init.value = __cpu_to_le32(INIT); + uart_config.icr.address = __cpu_to_le32(UARTICRADDR); + uart_config.icr.value = __cpu_to_le32(ICR); + uart_config.fcr.address = __cpu_to_le32(UARTFCRADDR); + uart_config.fcr.value = __cpu_to_le32(FCR); + uart_config.crc = __cpu_to_le32(crc32_be(0UL, (char *)&uart_config, + sizeof(uart_config) - 4)); + uart_config.crc = swab32(uart_config.crc); /* FW expects swapped CRC bytes */ + + serdev_device_write_buf(nxpdev->serdev, (u8 *)&uart_config, sizeof(uart_config)); + serdev_device_wait_until_sent(nxpdev->serdev, 0); + nxpdev->fw_v3_offset_correction += req_len; + return true; + } + return false; +} + +static bool nxp_fw_change_timeout(struct hci_dev *hdev, u16 req_len) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct nxp_bootloader_cmd nxp_cmd7; + + if (req_len != sizeof(nxp_cmd7)) + return false; + + nxp_cmd7.header = __cpu_to_le32(7); + nxp_cmd7.arg = __cpu_to_le32(0x70); + nxp_cmd7.payload_len = 0; + nxp_cmd7.crc = __cpu_to_le32(crc32_be(0UL, (char *)&nxp_cmd7, + sizeof(nxp_cmd7) - 4)); + nxp_cmd7.crc = swab32(nxp_cmd7.crc); /* FW expects swapped CRC bytes */ + serdev_device_write_buf(nxpdev->serdev, (u8 *)&nxp_cmd7, sizeof(nxp_cmd7)); + serdev_device_wait_until_sent(nxpdev->serdev, 0); + nxpdev->fw_v3_offset_correction += req_len; + return true; +} + +static u32 nxp_get_data_len(const u8 *buf) +{ + struct nxp_bootloader_cmd *hdr = (struct nxp_bootloader_cmd *)buf; + + return __le32_to_cpu(hdr->payload_len); +} + +static bool is_fw_downloading(struct btnxpuart_dev *nxpdev) +{ + return test_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); +} + +static bool process_boot_signature(struct btnxpuart_dev *nxpdev) +{ + if (test_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, &nxpdev->tx_state)) { + clear_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, &nxpdev->tx_state); + wake_up_interruptible(&nxpdev->check_boot_sign_wait_q); + return false; + } + return is_fw_downloading(nxpdev); +} + +static int nxp_request_firmware(struct hci_dev *hdev, const u8 *fw_name) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + int err = 0; + + if (!strlen(nxpdev->fw_name)) { + snprintf(nxpdev->fw_name, MAX_FW_FILE_NAME_LEN, "%s", fw_name); + + bt_dev_dbg(hdev, "Request Firmware: %s", nxpdev->fw_name); + err = request_firmware(&nxpdev->fw, nxpdev->fw_name, &hdev->dev); + if (err < 0) { + bt_dev_err(hdev, "Firmware file %s not found", nxpdev->fw_name); + clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + } + } + return err; +} + +/* for legacy chipsets with V1 bootloader */ +static int nxp_recv_fw_req_v1(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + struct v1_data_req *req; + u32 requested_len; + + if (!process_boot_signature(nxpdev)) + goto ret; + + req = (struct v1_data_req *)skb_pull_data(skb, sizeof(struct v1_data_req)); + if (!req) + goto ret; + + if ((req->len ^ req->len_comp) != 0xffff) { + bt_dev_dbg(hdev, "ERR: Send NAK"); + nxp_send_ack(NXP_NAK_V1, hdev); + goto ret; + } + nxp_send_ack(NXP_ACK_V1, hdev); + + if (nxp_data->fw_dnld_use_high_baudrate) { + if (!nxpdev->timeout_changed) { + nxpdev->timeout_changed = nxp_fw_change_timeout(hdev, req->len); + goto ret; + } + if (!nxpdev->baudrate_changed) { + nxpdev->baudrate_changed = nxp_fw_change_baudrate(hdev, req->len); + if (nxpdev->baudrate_changed) { + serdev_device_set_baudrate(nxpdev->serdev, + HCI_NXP_SEC_BAUDRATE); + serdev_device_set_flow_control(nxpdev->serdev, 1); + nxpdev->current_baudrate = HCI_NXP_SEC_BAUDRATE; + } + goto ret; + } + } + + if (nxp_request_firmware(hdev, nxp_data->fw_name)) + goto ret; + + requested_len = req->len; + if (requested_len == 0) { + bt_dev_dbg(hdev, "FW Downloaded Successfully: %zu bytes", nxpdev->fw->size); + clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q); + goto ret; + } + if (requested_len & 0x01) { + /* The CRC did not match at the other end. + * Simply send the same bytes again. + */ + requested_len = nxpdev->fw_v1_sent_bytes; + bt_dev_dbg(hdev, "CRC error. Resend %d bytes of FW.", requested_len); + } else { + nxpdev->fw_dnld_v1_offset += nxpdev->fw_v1_sent_bytes; + + /* The FW bin file is made up of many blocks of + * 16 byte header and payload data chunks. If the + * FW has requested a header, read the payload length + * info from the header, before sending the header. + * In the next iteration, the FW should request the + * payload data chunk, which should be equal to the + * payload length read from header. If there is a + * mismatch, clearly the driver and FW are out of sync, + * and we need to re-send the previous header again. + */ + if (requested_len == nxpdev->fw_v1_expected_len) { + if (requested_len == HDR_LEN) + nxpdev->fw_v1_expected_len = nxp_get_data_len(nxpdev->fw->data + + nxpdev->fw_dnld_v1_offset); + else + nxpdev->fw_v1_expected_len = HDR_LEN; + } else if (requested_len == HDR_LEN) { + /* FW download out of sync. Send previous chunk again */ + nxpdev->fw_dnld_v1_offset -= nxpdev->fw_v1_sent_bytes; + nxpdev->fw_v1_expected_len = HDR_LEN; + } + } + + if (nxpdev->fw_dnld_v1_offset + requested_len <= nxpdev->fw->size) + serdev_device_write_buf(nxpdev->serdev, + nxpdev->fw->data + nxpdev->fw_dnld_v1_offset, + requested_len); + nxpdev->fw_v1_sent_bytes = requested_len; + +ret: + kfree_skb(skb); + return 0; +} + +static u8 *nxp_get_fw_name_from_chipid(struct hci_dev *hdev, u16 chipid) +{ + u8 *fw_name = NULL; + + switch (chipid) { + case CHIP_ID_W9098: + fw_name = FIRMWARE_W9098; + break; + case CHIP_ID_IW416: + fw_name = FIRMWARE_IW416; + break; + case CHIP_ID_IW612: + fw_name = FIRMWARE_IW612; + break; + default: + bt_dev_err(hdev, "Unknown chip signature %04x", chipid); + break; + } + return fw_name; +} + +static int nxp_recv_chip_ver_v3(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct v3_start_ind *req = skb_pull_data(skb, sizeof(struct v3_start_ind)); + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + if (!process_boot_signature(nxpdev)) + goto ret; + + if (!nxp_request_firmware(hdev, nxp_get_fw_name_from_chipid(hdev, req->chip_id))) + nxp_send_ack(NXP_ACK_V3, hdev); + +ret: + kfree_skb(skb); + return 0; +} + +static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct v3_data_req *req; + + if (!process_boot_signature(nxpdev)) + goto ret; + + req = (struct v3_data_req *)skb_pull_data(skb, sizeof(struct v3_data_req)); + if (!req || !nxpdev->fw) + goto ret; + + nxp_send_ack(NXP_ACK_V3, hdev); + + if (!nxpdev->timeout_changed) { + nxpdev->timeout_changed = nxp_fw_change_timeout(hdev, req->len); + goto ret; + } + + if (!nxpdev->baudrate_changed) { + nxpdev->baudrate_changed = nxp_fw_change_baudrate(hdev, req->len); + if (nxpdev->baudrate_changed) { + serdev_device_set_baudrate(nxpdev->serdev, + HCI_NXP_SEC_BAUDRATE); + serdev_device_set_flow_control(nxpdev->serdev, 1); + nxpdev->current_baudrate = HCI_NXP_SEC_BAUDRATE; + } + goto ret; + } + + if (req->len == 0) { + bt_dev_dbg(hdev, "FW Downloaded Successfully: %zu bytes", nxpdev->fw->size); + clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q); + goto ret; + } + if (req->error) + bt_dev_dbg(hdev, "FW Download received err 0x%02x from chip", req->error); + + if (req->offset < nxpdev->fw_v3_offset_correction) { + /* This scenario should ideally never occur. But if it ever does, + * FW is out of sync and needs a power cycle. + */ + bt_dev_err(hdev, "Something went wrong during FW download. Please power cycle and try again"); + goto ret; + } + + serdev_device_write_buf(nxpdev->serdev, + nxpdev->fw->data + req->offset - nxpdev->fw_v3_offset_correction, + req->len); + +ret: + kfree_skb(skb); + return 0; +} + +static int nxp_set_baudrate_cmd(struct hci_dev *hdev, void *data) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + __le32 new_baudrate = __cpu_to_le32(nxpdev->new_baudrate); + struct ps_data *psdata = &nxpdev->psdata; + struct sk_buff *skb; + u8 *status; + + if (!psdata) + return 0; + + skb = nxp_drv_send_cmd(hdev, HCI_NXP_SET_OPER_SPEED, 4, (u8 *)&new_baudrate); + if (IS_ERR(skb)) { + bt_dev_err(hdev, "Setting baudrate failed (%ld)", PTR_ERR(skb)); + return PTR_ERR(skb); + } + + status = (u8 *)skb_pull_data(skb, 1); + if (status) { + if (*status == 0) { + serdev_device_set_baudrate(nxpdev->serdev, nxpdev->new_baudrate); + nxpdev->current_baudrate = nxpdev->new_baudrate; + } + bt_dev_dbg(hdev, "Set baudrate response: status=%d, baudrate=%d", + *status, nxpdev->new_baudrate); + } + kfree_skb(skb); + + return 0; +} + +static int nxp_set_ind_reset(struct hci_dev *hdev, void *data) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct sk_buff *skb; + u8 *status; + u8 pcmd = 0; + int err; + + skb = nxp_drv_send_cmd(hdev, HCI_NXP_IND_RESET, 1, &pcmd); + if (IS_ERR(skb)) + return PTR_ERR(skb); + + status = skb_pull_data(skb, 1); + if (status) { + if (*status == 0) { + set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + err = nxp_download_firmware(hdev); + if (err < 0) + return err; + serdev_device_set_baudrate(nxpdev->serdev, nxpdev->fw_init_baudrate); + nxpdev->current_baudrate = nxpdev->fw_init_baudrate; + if (nxpdev->current_baudrate != HCI_NXP_SEC_BAUDRATE) { + nxpdev->new_baudrate = HCI_NXP_SEC_BAUDRATE; + nxp_set_baudrate_cmd(hdev, NULL); + } + hci_cmd_sync_queue(hdev, send_wakeup_method_cmd, NULL, NULL); + hci_cmd_sync_queue(hdev, send_ps_cmd, NULL, NULL); + } + } + kfree_skb(skb); + + return 0; +} + +/* NXP protocol */ +static int nxp_check_boot_sign(struct btnxpuart_dev *nxpdev) +{ + serdev_device_set_baudrate(nxpdev->serdev, HCI_NXP_PRI_BAUDRATE); + serdev_device_set_flow_control(nxpdev->serdev, 0); + set_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, &nxpdev->tx_state); + + return wait_event_interruptible_timeout(nxpdev->check_boot_sign_wait_q, + !test_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, + &nxpdev->tx_state), + msecs_to_jiffies(1000)); +} + +static int nxp_setup(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + int err = 0; + + set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + init_waitqueue_head(&nxpdev->fw_dnld_done_wait_q); + init_waitqueue_head(&nxpdev->check_boot_sign_wait_q); + + if (nxp_check_boot_sign(nxpdev)) { + bt_dev_dbg(hdev, "Need FW Download."); + err = nxp_download_firmware(hdev); + if (err < 0) + return err; + } else { + bt_dev_dbg(hdev, "FW already running."); + clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + } + + serdev_device_set_flow_control(nxpdev->serdev, 1); + device_property_read_u32(&nxpdev->serdev->dev, "fw-init-baudrate", + &nxpdev->fw_init_baudrate); + if (!nxpdev->fw_init_baudrate) + nxpdev->fw_init_baudrate = FW_INIT_BAUDRATE; + serdev_device_set_baudrate(nxpdev->serdev, nxpdev->fw_init_baudrate); + nxpdev->current_baudrate = nxpdev->fw_init_baudrate; + + if (nxpdev->current_baudrate != HCI_NXP_SEC_BAUDRATE) { + nxpdev->new_baudrate = HCI_NXP_SEC_BAUDRATE; + hci_cmd_sync_queue(hdev, nxp_set_baudrate_cmd, NULL, NULL); + } + + ps_init(hdev); + + return 0; +} + +static int nxp_enqueue(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = &nxpdev->psdata; + struct hci_command_hdr *hdr; + struct psmode_cmd_payload ps_parm; + struct wakeup_cmd_payload wakeup_parm; + __le32 baudrate_parm; + + /* if vendor commands are received from user space (e.g. hcitool), update + * driver flags accordingly and ask driver to re-send the command to FW. + * In case the payload for any command does not match expected payload + * length, let the firmware and user space program handle it, or throw + * an error. + */ + if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT && !psdata->driver_sent_cmd) { + hdr = (struct hci_command_hdr *)skb->data; + if (hdr->plen != (skb->len - HCI_COMMAND_HDR_SIZE)) + goto send_skb; + + switch (__le16_to_cpu(hdr->opcode)) { + case HCI_NXP_AUTO_SLEEP_MODE: + if (hdr->plen == sizeof(ps_parm)) { + memcpy(&ps_parm, skb->data + HCI_COMMAND_HDR_SIZE, hdr->plen); + if (ps_parm.ps_cmd == BT_PS_ENABLE) + psdata->target_ps_mode = PS_MODE_ENABLE; + else if (ps_parm.ps_cmd == BT_PS_DISABLE) + psdata->target_ps_mode = PS_MODE_DISABLE; + psdata->c2h_ps_interval = __le16_to_cpu(ps_parm.c2h_ps_interval); + hci_cmd_sync_queue(hdev, send_ps_cmd, NULL, NULL); + goto free_skb; + } + break; + case HCI_NXP_WAKEUP_METHOD: + if (hdr->plen == sizeof(wakeup_parm)) { + memcpy(&wakeup_parm, skb->data + HCI_COMMAND_HDR_SIZE, hdr->plen); + psdata->c2h_wakeupmode = wakeup_parm.c2h_wakeupmode; + psdata->c2h_wakeup_gpio = wakeup_parm.c2h_wakeup_gpio; + psdata->h2c_wakeup_gpio = wakeup_parm.h2c_wakeup_gpio; + switch (wakeup_parm.h2c_wakeupmode) { + case BT_CTRL_WAKEUP_METHOD_DSR: + psdata->h2c_wakeupmode = WAKEUP_METHOD_DTR; + break; + case BT_CTRL_WAKEUP_METHOD_BREAK: + default: + psdata->h2c_wakeupmode = WAKEUP_METHOD_BREAK; + break; + } + hci_cmd_sync_queue(hdev, send_wakeup_method_cmd, NULL, NULL); + goto free_skb; + } + break; + case HCI_NXP_SET_OPER_SPEED: + if (hdr->plen == sizeof(baudrate_parm)) { + memcpy(&baudrate_parm, skb->data + HCI_COMMAND_HDR_SIZE, hdr->plen); + nxpdev->new_baudrate = __le32_to_cpu(baudrate_parm); + hci_cmd_sync_queue(hdev, nxp_set_baudrate_cmd, NULL, NULL); + goto free_skb; + } + break; + case HCI_NXP_IND_RESET: + if (hdr->plen == 1) { + hci_cmd_sync_queue(hdev, nxp_set_ind_reset, NULL, NULL); + goto free_skb; + } + break; + default: + break; + } + } + +send_skb: + /* Prepend skb with frame type */ + memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1); + skb_queue_tail(&nxpdev->txq, skb); + + btnxpuart_tx_wakeup(nxpdev); +ret: + return 0; + +free_skb: + kfree_skb(skb); + goto ret; +} + +static struct sk_buff *nxp_dequeue(void *data) +{ + struct btnxpuart_dev *nxpdev = (struct btnxpuart_dev *)data; + + ps_wakeup(nxpdev); + ps_start_timer(nxpdev); + return skb_dequeue(&nxpdev->txq); +} + +/* btnxpuart based on serdev */ +static void btnxpuart_tx_work(struct work_struct *work) +{ + struct btnxpuart_dev *nxpdev = container_of(work, struct btnxpuart_dev, + tx_work); + struct serdev_device *serdev = nxpdev->serdev; + struct hci_dev *hdev = nxpdev->hdev; + struct sk_buff *skb; + int len; + + while ((skb = nxp_dequeue(nxpdev))) { + len = serdev_device_write_buf(serdev, skb->data, skb->len); + hdev->stat.byte_tx += len; + + skb_pull(skb, len); + if (skb->len > 0) { + skb_queue_head(&nxpdev->txq, skb); + break; + } + + switch (hci_skb_pkt_type(skb)) { + case HCI_COMMAND_PKT: + hdev->stat.cmd_tx++; + break; + case HCI_ACLDATA_PKT: + hdev->stat.acl_tx++; + break; + case HCI_SCODATA_PKT: + hdev->stat.sco_tx++; + break; + } + + kfree_skb(skb); + } + clear_bit(BTNXPUART_TX_STATE_ACTIVE, &nxpdev->tx_state); +} + +static int btnxpuart_open(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + int err = 0; + + err = serdev_device_open(nxpdev->serdev); + if (err) { + bt_dev_err(hdev, "Unable to open UART device %s", + dev_name(&nxpdev->serdev->dev)); + } else { + set_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state); + } + return err; +} + +static int btnxpuart_close(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + serdev_device_close(nxpdev->serdev); + clear_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state); + return 0; +} + +static int btnxpuart_flush(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + /* Flush any pending characters */ + serdev_device_write_flush(nxpdev->serdev); + skb_queue_purge(&nxpdev->txq); + + cancel_work_sync(&nxpdev->tx_work); + + kfree_skb(nxpdev->rx_skb); + nxpdev->rx_skb = NULL; + + return 0; +} + +static const struct h4_recv_pkt nxp_recv_pkts[] = { + { H4_RECV_ACL, .recv = hci_recv_frame }, + { H4_RECV_SCO, .recv = hci_recv_frame }, + { H4_RECV_EVENT, .recv = hci_recv_frame }, + { NXP_RECV_FW_REQ_V1, .recv = nxp_recv_fw_req_v1 }, + { NXP_RECV_CHIP_VER_V3, .recv = nxp_recv_chip_ver_v3 }, + { NXP_RECV_FW_REQ_V3, .recv = nxp_recv_fw_req_v3 }, +}; + +static bool is_valid_bootloader_signature(const u8 *data, size_t count) +{ + if ((*data == NXP_V1_FW_REQ_PKT && count == sizeof(struct v1_data_req) + 1) || + (*data == NXP_V3_FW_REQ_PKT && count == sizeof(struct v3_data_req) + 1) || + (*data == NXP_V3_CHIP_VER_PKT && count == sizeof(struct v3_start_ind) + 1)) + return true; + else + return false; +} + +static int btnxpuart_receive_buf(struct serdev_device *serdev, const u8 *data, + size_t count) +{ + struct btnxpuart_dev *nxpdev = serdev_device_get_drvdata(serdev); + + if (is_fw_downloading(nxpdev) && !is_valid_bootloader_signature(data, count)) { + /* Unknown bootloader signature, skip without returning error */ + return count; + } + + ps_start_timer(nxpdev); + + nxpdev->rx_skb = h4_recv_buf(nxpdev->hdev, nxpdev->rx_skb, data, count, + nxp_recv_pkts, ARRAY_SIZE(nxp_recv_pkts)); + if (IS_ERR(nxpdev->rx_skb)) { + int err = PTR_ERR(nxpdev->rx_skb); + + bt_dev_err(nxpdev->hdev, "Frame reassembly failed (%d)", err); + nxpdev->rx_skb = NULL; + return err; + } + nxpdev->hdev->stat.byte_rx += count; + return count; +} + +static void btnxpuart_write_wakeup(struct serdev_device *serdev) +{ + serdev_device_write_wakeup(serdev); +} + +static const struct serdev_device_ops btnxpuart_client_ops = { + .receive_buf = btnxpuart_receive_buf, + .write_wakeup = btnxpuart_write_wakeup, +}; + +static int nxp_serdev_probe(struct serdev_device *serdev) +{ + struct hci_dev *hdev; + struct btnxpuart_dev *nxpdev; + + nxpdev = devm_kzalloc(&serdev->dev, sizeof(*nxpdev), GFP_KERNEL); + if (!nxpdev) + return -ENOMEM; + + nxpdev->nxp_data = (struct btnxpuart_data *)device_get_match_data(&serdev->dev); + + nxpdev->serdev = serdev; + serdev_device_set_drvdata(serdev, nxpdev); + + serdev_device_set_client_ops(serdev, &btnxpuart_client_ops); + + INIT_WORK(&nxpdev->tx_work, btnxpuart_tx_work); + skb_queue_head_init(&nxpdev->txq); + + crc8_populate_msb(crc8_table, POLYNOMIAL8); + + /* Initialize and register HCI device */ + hdev = hci_alloc_dev(); + if (!hdev) { + dev_err(&serdev->dev, "Can't allocate HCI device\n"); + return -ENOMEM; + } + + nxpdev->hdev = hdev; + + hdev->bus = HCI_UART; + hci_set_drvdata(hdev, nxpdev); + + hdev->manufacturer = MANUFACTURER_NXP; + hdev->open = btnxpuart_open; + hdev->close = btnxpuart_close; + hdev->flush = btnxpuart_flush; + hdev->setup = nxp_setup; + hdev->send = nxp_enqueue; + SET_HCIDEV_DEV(hdev, &serdev->dev); + + if (hci_register_dev(hdev) < 0) { + dev_err(&serdev->dev, "Can't register HCI device\n"); + hci_free_dev(hdev); + return -ENODEV; + } + + ps_init_work(hdev); + ps_init_timer(hdev); + + return 0; +} + +static void nxp_serdev_remove(struct serdev_device *serdev) +{ + struct btnxpuart_dev *nxpdev = serdev_device_get_drvdata(serdev); + struct hci_dev *hdev = nxpdev->hdev; + + /* Restore FW baudrate to fw_init_baudrate if changed. + * This will ensure FW baudrate is in sync with + * driver baudrate in case this driver is re-inserted. + */ + if (nxpdev->current_baudrate != nxpdev->fw_init_baudrate) { + nxpdev->new_baudrate = nxpdev->fw_init_baudrate; + nxp_set_baudrate_cmd(hdev, NULL); + } + + ps_cancel_timer(nxpdev); + hci_unregister_dev(hdev); + hci_free_dev(hdev); +} + +static struct btnxpuart_data w8987_data = { + .fw_dnld_use_high_baudrate = true, + .fw_name = FIRMWARE_W8987, +}; + +static struct btnxpuart_data w8997_data = { + .fw_dnld_use_high_baudrate = false, + .fw_name = FIRMWARE_W8997, +}; + +static const struct of_device_id nxpuart_of_match_table[] = { + { .compatible = "nxp,88w8987-bt", .data = &w8987_data }, + { .compatible = "nxp,88w8997-bt", .data = &w8997_data }, + { } +}; +MODULE_DEVICE_TABLE(of, nxpuart_of_match_table); + +static struct serdev_device_driver nxp_serdev_driver = { + .probe = nxp_serdev_probe, + .remove = nxp_serdev_remove, + .driver = { + .name = "btnxpuart", + .of_match_table = of_match_ptr(nxpuart_of_match_table), + }, +}; + +module_serdev_device_driver(nxp_serdev_driver); + +MODULE_AUTHOR("Neeraj Sanjay Kale "); +MODULE_DESCRIPTION("NXP Bluetooth Serial driver v1.0 "); +MODULE_LICENSE("GPL");