From patchwork Thu Mar 16 17:22:11 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: 665025 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 0D968C761A6 for ; Thu, 16 Mar 2023 17:23:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229530AbjCPRX3 (ORCPT ); Thu, 16 Mar 2023 13:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjCPRWz (ORCPT ); Thu, 16 Mar 2023 13:22:55 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2083.outbound.protection.outlook.com [40.107.21.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63096B856E; Thu, 16 Mar 2023 10:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TnOGuC4c44MX9aaUwl02Ji+wY0C0LEEgaKQddIcKn+MEh4NIcit9j3ophB3ub0Y7RD/oJsR0WHNiXXu7ralorcw9AROxlu4pqai4z8NCuPb5NGUFctafhwJXdI3ywn4wBUGy+f7jurIPNfljIbn2GgQDAhc6BdUSSRKIPuV/kCaY7ERbtDQ8tKyqjPMLLnSI03w0s0oNG4Jsu0M0P8wbAq+Mii0QuyJH1eXMytaQIZsJ0NI4X/xJUZzm1m8Z+6Lm99hzqkzS/tgKrLX/3TCK3bhHKC24IYqfRKzAxoyOlYA/OqMcNg0HWyAw1aAOni6pPwDrijW5MTnkrXJ3+YmC7w== 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=TaPSKGt9hUBQ0i7lstGETu/vw3C1OXKaJa9nti1zass=; b=fD4sF0lJ0TySgbrEHFIz/UmHIQ+AmNeiMulAn/eDhF2Y0gSRSzJXuU2qsLsjXhNGCmD1iO60crkBwNuYvUWKkagE+pfKmkeyuMlAPGu+fBvGVj0vRWWRcZmWinAXmoHiBHuwmqY1xB8qKGgefIQFULI7hGsFuxVIIOhBit3H3sbJyN+swpeFvisyLjltGLRmgR8vyjB7Gibc5L0E0E/MIkeZuM4J3/EQlbIvjuBD4+3i9U6jVCcaVZ6LBP6BVEXVVOFsv7lbrFn37e7Au2zg0e0mgbLjkfXHfe69Op0trU7n1ifrShThL/P+a+oJMOk4sIdODGSzPvfwSLKMH/uhGg== 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=TaPSKGt9hUBQ0i7lstGETu/vw3C1OXKaJa9nti1zass=; b=HF4Ko6SZcmy0aYjWCJZDWm2b/AKlxAI2PxzZBWh/ei47y1A97Qww2Nlph+tW7cGaXnhx+538iUWS44/W1xXjIZ0xg0UnoXmoc+H/ab8sWfVENKjE/AUOJEExmR21fUnXiqjPutM8fvwTvYZGkY8z5W+toVAoSfRtZQUvfc37pFI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) by PA4PR04MB9293.eurprd04.prod.outlook.com (2603:10a6:102:2a4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Thu, 16 Mar 2023 17:22:49 +0000 Received: from DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9]) by DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9%8]) with mapi id 15.20.6178.031; Thu, 16 Mar 2023 17:22:49 +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, simon.horman@corigine.com 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 v13 1/4] serdev: Replace all instances of ENOTSUPP with EOPNOTSUPP Date: Thu, 16 Mar 2023 22:52:11 +0530 Message-Id: <20230316172214.3899786-2-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> References: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG3P274CA0007.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::19) To DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8600:EE_|PA4PR04MB9293:EE_ X-MS-Office365-Filtering-Correlation-Id: 520ed011-a2e1-4caf-82c2-08db264310f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PktzsulSS1/fUtWVtxy37mocmB0foHx8H2cOPfvdYGzZ3keEYDWvuwIOXoSEMdPFd6azeUhQNf2rjSDx6Y9ojp8cN0GCOul1jE1hNE8s+1zrJHQsHrK6OWTmphJjzEvU/yNzOGssHO9jrf474l/rnnWlfD/R38aFXmVpziLtoN0QMt6jq01innY+kUXqrRftGgthLztO24EQDMzLTAq9/EDnv3gwdIo5zObbZeOG0727j0MyAswQZo5+ptfpz7tMNiP4HfdUnjVcWU9t7Rkn0/ebiaH02xv/YG4ptS/1JF/olp/ETtkCHUqvXRv3P2HI1ba+RAwQ7bcFbJyH2unZ53eheZ9L2S0D5APnUCjnz9Ej2bCq6D0/AqL+kXxe1NWxNNn3IWJBJpaEC13N8UzW5P7oQwqtkGuwhhwOdm5rlnt8/Mxual8IDnvs1nI6W/daaxIkwPnzcnsRX2sDZgiZCQdlvUgwUV6CvoL0zecSSFRFBDxjPZT5s8SF01C5qtJl+WoTQDqdwh4nmZydSL+NeR+Mm6ddNz88sOnme3ylIdUbveW5PvbiZM3kRoVDeFhNmi9PPxn3gd8BtR3ppX2q5xaw52I+9fKpPxgZKaLhsduYmCKGaUQQr1KEYaAsnXqotdYibQND34zrgpoOvl7t0QvuS/VBxcEYFP1H5+NJQtiHp951t5hTxlH4us/ZKI9roWms0K1QNT7kds0JVEVZ9cxD1of9AQdpW0JfHCJI9Io= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8600.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(396003)(346002)(39860400002)(366004)(376002)(136003)(451199018)(6486002)(52116002)(6512007)(6506007)(1076003)(478600001)(26005)(83380400001)(2616005)(6666004)(66476007)(66946007)(316002)(186003)(66556008)(2906002)(41300700001)(4326008)(8936002)(5660300002)(8676002)(7416002)(38350700002)(38100700002)(921005)(36756003)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oNdupXC/Dq295GFhMnIlPVKjRYxjyLdUcSXE1dGXZrDTvEPKQW5hWbKiY+JbTqpcw7basO0Wges8Jo8sytKMQV8AC8+pWtdn1ITNKzvJmIhrYQrvwkm1Xx/GrcwQ5QYKQM4Wxi0ZHMAkWIP2Q2InZ41V/svnMQa4t58xd7Oh7MhVgnrnmJgifmm5ElrW+II/X7AOGPQeiqC6BgmMEGh62UG/cKrmgasUujTuxZs6o8958XS1DfzTg2BdI0wXNsyopfpHoyWGPa65gWqDXCTLZE8q728nnXv+i1nD3nFvmKziWvBbNraYg387cRv1xySdG3vwWI8WsB5jfKMjUbuKq3DPKJKgiL2npuARcMrW1SvbGhzDe4nKcD0tryxktjU0XN19qeCr03kq2VwIhj72h/7O8y6Uk8qEB+3+HzyZuQlEb5IGGxXCdIImTK42EyuyGPi0lQbRQ8Y7TGPdU+OXWFUUE9wH64loxX+H/7KMpAwT6LdtnT9uil7mPDqcy9JVgmpFFWQy5jsW3sCjq5OeI7KOz2YY9qKd84Lw+vCqYR+xyNL/eZ7+jShbUk1wwNFdka7KuNJY31hv/Ms1WL1gEpbtwT4hLE6yuZ0T3DsgLQZ+yJDahd/95FGSAeWeZKNKpgttOrLvPunFLabIfVG7dFr4eT61DgQKa9QVMGr3FCbyiHSwZYzwhw4hhZYPwBs+/XQlecHkjhG9CStqdUckwDfK7r1fltU6m3Aw7+R8jQeNwY/o3lMIQyrVm59g1eQamNSKJjpVI+k1w30kna5knxQRHNisfc+ed4vsPiBSpjD7HhHcKVV2VzwZF2KVKO/DVI/WRjscr2clncnW9daSHwlyD+UaHb3esmFPY+HOZGV0FjR9MmmBk7DytN/BmTif4qq7Ma5p9+O1AA6Rr9Nvj8noOlRDGetE1DFywvP8eGKnUYJYb33sRWfvqh5egDTnc+hIahVgFWRs5A+DRB9TOpkARRR0v6M+QJddwk8P01cRK2RhME/qz8fCnuWLY5p6+c22gjK0HtXeQkdhq541RvV7abhjG/hpXAv1S4e/VLnvPvbsbl/5bdKJfTKE485OxfArVmKA/JCFULFNcQKgxFanJhZmoSqm7dfr6jD/O7isPsnjH5nV88KVry9Pq2Sd65MbBgujx424XnPT4BoXiOFd+aLOcgCYV8bXbXbdO9QzSAv6VC3Bqd6zOLPfpnYGvMhwhGOw97dpfbE8ZWh6szkjyMrdndSy7DunR742rKmPb/XYSYJzFE1g7BusNMrQ764iBpSKlkUSz/G1eRhJ/Wvc0BlFqS3m0sa4NvIw1OuXTAxrOcEBx3s+QG0dcZiNhYgw5NVV+GSq03SdfZ+V2QU/He9XVBBQBbtdyDy7Ul2ZzuO/+F/0LkQ6b3f7OW/IMhtbD0LgMhH79Ufa7jzb/3tqakcZNFXYLxd0F2hZg0eFaAhES3UI6gBoVSdD7YRon6jFmj2d4OprILfzQllRqncdFwkCsV0S5h2urGF2XS58ahW7dETaF0IN0c40EecNpajND0w0a5dVg1nFMEgmnzBVr1rxF/g/flZszrGZlRVRfF10JZrbE48IGb86SVXD8wTQpo6AzJ1+SvifhytNbA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 520ed011-a2e1-4caf-82c2-08db264310f9 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2023 17:22:49.5789 (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: ksvMqyCSIrujsNOQe4FwGlDceck7356z9cWugch2A0C38pVK7V+i2zTv9vf9ftd4nkP7MOxpoUeiKBTVdIQpjM176P5BPCB1MtJ9p3Blk3c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9293 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This replaces all instances of ENOTSUPP with EOPNOTSUPP since ENOTSUPP is not a standard error code. This will help maintain consistency in error codes when new serdev API's are added. Signed-off-by: Neeraj Sanjay Kale Reviewed-by: Simon Horman --- v11: Replace all instances of ENOTSUPP with EOPNOTSUPP. (Simon Horman) --- drivers/tty/serdev/core.c | 6 +++--- drivers/tty/serdev/serdev-ttyport.c | 4 ++-- include/linux/serdev.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 0180e1e4e75d..d43aabd0cb76 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -366,7 +366,7 @@ int serdev_device_set_parity(struct serdev_device *serdev, struct serdev_controller *ctrl = serdev->ctrl; if (!ctrl || !ctrl->ops->set_parity) - return -ENOTSUPP; + return -EOPNOTSUPP; return ctrl->ops->set_parity(ctrl, parity); } @@ -388,7 +388,7 @@ int serdev_device_get_tiocm(struct serdev_device *serdev) struct serdev_controller *ctrl = serdev->ctrl; if (!ctrl || !ctrl->ops->get_tiocm) - return -ENOTSUPP; + return -EOPNOTSUPP; return ctrl->ops->get_tiocm(ctrl); } @@ -399,7 +399,7 @@ int serdev_device_set_tiocm(struct serdev_device *serdev, int set, int clear) struct serdev_controller *ctrl = serdev->ctrl; if (!ctrl || !ctrl->ops->set_tiocm) - return -ENOTSUPP; + return -EOPNOTSUPP; return ctrl->ops->set_tiocm(ctrl, set, clear); } diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index d367803e2044..f26ff82723f1 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -231,7 +231,7 @@ static int ttyport_get_tiocm(struct serdev_controller *ctrl) struct tty_struct *tty = serport->tty; if (!tty->ops->tiocmget) - return -ENOTSUPP; + return -EOPNOTSUPP; return tty->ops->tiocmget(tty); } @@ -242,7 +242,7 @@ static int ttyport_set_tiocm(struct serdev_controller *ctrl, unsigned int set, u struct tty_struct *tty = serport->tty; if (!tty->ops->tiocmset) - return -ENOTSUPP; + return -EOPNOTSUPP; return tty->ops->tiocmset(tty, set, clear); } diff --git a/include/linux/serdev.h b/include/linux/serdev.h index 66f624fc618c..89b0a5af9be2 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -249,11 +249,11 @@ static inline int serdev_device_write_buf(struct serdev_device *serdev, static inline void serdev_device_wait_until_sent(struct serdev_device *sdev, long timeout) {} static inline int serdev_device_get_tiocm(struct serdev_device *serdev) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int serdev_device_set_tiocm(struct serdev_device *serdev, int set, int clear) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int serdev_device_write(struct serdev_device *sdev, const unsigned char *buf, size_t count, unsigned long timeout) From patchwork Thu Mar 16 17:22:12 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: 665026 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 D7091C76195 for ; Thu, 16 Mar 2023 17:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229778AbjCPRXZ (ORCPT ); Thu, 16 Mar 2023 13:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbjCPRXE (ORCPT ); Thu, 16 Mar 2023 13:23:04 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2054.outbound.protection.outlook.com [40.107.21.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A07DB863D; Thu, 16 Mar 2023 10:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VnO4jogeYEDM2eXWNhucEqDUa1wdVVn5Rj/bhzufEQJVIBruzYhnETpOH/iKzE4ypTARv/qbfKrkIXItsiqs/miXaD301G4APOQRj/QhJZkB/nNoURjI/bQm/Gtl3njXDBC/flcOfUYQNQaceMOqaeMiDdreVJQkRfy5RGUkf+5KEct7rDdVrw9BoDiDyzIxSkknsIvsK1XpFrd3A1KYeMexIs8c20pfE+uoq1B/54BlFpo+r9zLFy5ZABSA4xMA8AGERxRYNvUfralwRl60Cx613UztxnX/s7H+dUlsE725QndrY+uBUn9vRJ8xArOge98OwYSZ0y4QCYvDOMkxGg== 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=XEUux4oIC4z4fMGUhCjhIyOb8tcBYNB4Ks+ILiH/W0w=; b=PDWpDipfnDgf7owRT1RbY3ZwOB4isPrv9WCRPc2jTptZN6uVkShUbcCCjkDtfTvatkY11k43X3NaR8FpU34EZmlnI9YboDIFHdnfacvoblpliNVYYvk9XB1VUvrrTqCYr/+nq1VXOdokzjjqHfvQ5q/6vA4Hp2z4dmVJHIQU8g6OkSQOtkEGFivdEKWAA0c5ZQ0a5ErVn63VzmdKxBlssgrs7GOV7bjmyW4oYgy3dNJtXmrj34O0iwgGMea4VxtbOjVII0Dwz2MSbFPty4cmwFzXEb3/cZyux5D+IB2hHOgSOIXVMDzm/j8cB5pWabtTl1ZGP639RgMdu/yhqcmqzA== 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=XEUux4oIC4z4fMGUhCjhIyOb8tcBYNB4Ks+ILiH/W0w=; b=mBIC81hmuExfQxFxF3ssK4oNzZ9jwTimn/F87BAn53ok3pGi9FSx31cqGIDJHPxQ6yUhX5mXvvnQzlcWWOhsjCYzQO4FqxHffLKXYp2YD9SHBkQ5fbeY3916Io2CNe+PtzSkokxMWYHjN2ceKejTe+57150KrfG6Wet1/G3wFqQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) by PA4PR04MB9293.eurprd04.prod.outlook.com (2603:10a6:102:2a4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Thu, 16 Mar 2023 17:22:56 +0000 Received: from DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9]) by DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9%8]) with mapi id 15.20.6178.031; Thu, 16 Mar 2023 17:22:56 +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, simon.horman@corigine.com 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 v13 2/4] serdev: Add method to assert break signal over tty UART port Date: Thu, 16 Mar 2023 22:52:12 +0530 Message-Id: <20230316172214.3899786-3-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> References: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG3P274CA0007.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::19) To DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8600:EE_|PA4PR04MB9293:EE_ X-MS-Office365-Filtering-Correlation-Id: bf6dd7d6-42a7-443d-963d-08db26431536 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RrDkB1mN2/dbUT3TethJzM091bojc8K7iBHRGW3tbnjc9k40HEAAO9nOP9CpCF68jGGG62gakM9s4SExaRmHEwXLktbq0skVG/4YihAMqKvG3nuzEGyhDPqre8iawyfiUNYhPOqoOU8tXv3fHLddTcDEWpN1lebOqYRXiXSn7SXZCLo5fRVJra52kAv4/7MoBOJXtSYY05UP6lupA4qSN0Fu/nZZKFqUmJlJfOEPAHmVps5z/0Lx/swt4Iyv+KbM1cl20HtdAlgMMoguAIPOjRVrWF/RKS4kRXJPgZH9AmocbCf59NkFcWUKGsC/BQPQF5OaAaYVSJ15MMyTN/25EIV7k/5ejywsWg6Ml3U3kDEoXZVq0DOmaM0kwfO9ikzi+LZAy972TtI/jQTIDLNEBvOJcjTxAkAXzS104ShGFJREIKmBXgDmTeNGtpkEhoD2kjBz74w0TmbZGffaVFGAqThTIxv1N4on0N38yKP7aVBqWXhk7pAGtufOWOfkyhp8vzCWChQZKF3Be2S+6HUByqF/znZX9t0EQeEyuUnWzgRN0s64MO3UVQf3BlOvk16ZAo08EdX5R/zcJE62JX+s9VIHqvxY4BfEKzCZVyrYCyC4laYgq9dseLylprx7Q6FhfA1fMvoGCXjXShThJV8l10P+oXTpDMpa43LOYdzkcQylPEi+mRvo8kbNvPlBJyz+VANC8WqbdY14FAnIz7L8shdswhzOMh44eHdHcBhY2cM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8600.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(396003)(346002)(39860400002)(366004)(376002)(136003)(451199018)(6486002)(52116002)(6512007)(6506007)(1076003)(478600001)(26005)(83380400001)(2616005)(6666004)(66476007)(66946007)(316002)(186003)(66556008)(2906002)(41300700001)(4326008)(8936002)(5660300002)(8676002)(7416002)(38350700002)(38100700002)(921005)(36756003)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UpVxV6oUKpz/+1WwElTFQIYbB+8B9Rdg831/HfhgJpcFGo5AdokWAOi8ZgNg5YIm5HA9qJ/9OTy7cC+w1YphY5kl6XHo75ZFxPMY0G+Hhlte+Y0yCRPYX59ePdpVoHG8Fea8XbQXx//qLuUL98kVRN3RIjeaQB+B3BmGhd9Rgk43WPDFz2V8/PXKbvay5UFxA86hiQCYIWWrhzZ+dMiwR97ZWu5v7BHKGWnlXwT3ARNGLRHKMoeU/mFBnVrgL4EzdX4HONChaaBv4zqkaKqxYpcnscXiNOmcrRvKb9WOQZhTdZy7ULch+31Cn4hisyfqdywEMo8SPV+FTJF4lAzRegjj5XDoaXGbuP/eqpwdn8rpjgZDnzpBxMRNzqsd5nLkcmHwV2d9ewObryNlvWSkWc3gTtgeeq1AKsub3GelQAWy8zN0pA0Jzo1YJ+SwdSaRdkWoQaKBPmObI5puV7hv5HRjH9rVWBTh1cRWVpc3gDt9jafGF5dcSJMkNnz/egFdfl6GOBlKX8Gxtcg/TdeFIGrR34JKsoJ6iw/R/gKi+jZ+nGe/k1S6LYWPyka3GmkSXhlmpuob+1Mc2g6JDC2NsAqnET17hO0ev65mSNW5M4JeP/36NKJJG7mgu3/JOoMEqe/nPuxvcgOeRxGupAmGVLPlWJWUr+7vI7+nGlpOLQBPOc1JBCfhuv8tFMcUvZBgJuospStWtGSCUEC5LVWXMpMcyGLyKTo2vtY8cqZPUaFbXiwFExS4VIrhBWHAGc3Zu1zjaQWE2jaCnbz/JDSOLppFKl1RrF5RMRHWGV92K7s6KLUoVNyiRB8NCDx+KxuP54NYq2gWLqHD6jr+mt4XLtwIx96UmaUAihGhW9Q3/hTKqVtqNsiVhh1cUc3ZXLPyuf/OgD95J9+tuJM3ogU9wEO/yG71Zxtovs6xve4UlJ/Bv6PfRi5uNNItvwBf5DQr97xncVyrtg7BVdKi8LAFSwgqGD3v6jnGCa6MtN0K62QPwImiKrLm8Hvac1FrQrJ3j7b/mt4vlScIj07ngICF+U8cfjDyu+NZWO5JKj5drfqrzO0C5AbY/zJ+tqWC2kZOZO6R5JKlrYNz4GeK3mOyewiyBW/Qbw8zI83yTXv8zVVBamsPGnqYWmIzBLf8V1rytlbgcMBE3o8iaLAP9n5eEDGi5/ukj3SgttH4e3Ez+yVCL6d5+NyTJom+vBW9iLE3T/veNMf91d+dvTbcqts0UH7RqJ+dsOFIjj0E5BkMhqboeeiPFrJjRJQ49SAIxGNYpE8BfYRRha+C8siqZqSBW1sY9DO+80If1KODjTSvlEuJ1odpErJu4nKsxj64ioZDFvkFL7dowicY8k2rMvnEkmJpybW1yVQK65b29B/P0KTgSdIjDKbuY616D7NiFvXJIxGOIREjjNdaewgAug2Yw412ZDYa7KSeG6e94atQJXR/aWo2Kdg69iXQcnEMUZnlrvQVsPW84xN8/JAaLiJKp7nE2jfQzwYUVEBPD5VNDgw91nDScbA6tf6/3P9jLjiI1wwb9jxFS4jac8uPJTqZKyDwIdr3LkAidZ2L0E1Uq75YADi02ENX4UcnYrQLFf5P3sY0EBtgeKkL16VFk6yKgA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf6dd7d6-42a7-443d-963d-08db26431536 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2023 17:22:56.6276 (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: ucAe7wL98F5Bk6mh5vgzvCHegJyh1pEUH0D5cGVJ4VHdEVas6Y3NNRPRpcY2sOBdQwB0v6rY2t6tA+wyZx97clUcdf6Nrci+h8QpNVVXgWs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9293 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 Reviewed-by: Simon Horman --- v3: Add details to the commit message. Replace ENOTSUPP with EOPNOTSUPP. (Greg KH, Leon Romanovsky) v9: Replace all instances of ENOTSUPP with EOPNOTSUPP. (Simon Horman) v11: Create a separate patch for replacing ENOTSUPP with EOPNOTSUPP. (Simon Horman) --- 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 d43aabd0cb76..dc540e74c64d 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 f26ff82723f1..8033ef19669c 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 89b0a5af9be2..d123d7f43e85 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 -EOPNOTSUPP; } +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 Thu Mar 16 17:22:13 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: 664120 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 88470C6FD19 for ; Thu, 16 Mar 2023 17:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbjCPRX2 (ORCPT ); Thu, 16 Mar 2023 13:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbjCPRXR (ORCPT ); Thu, 16 Mar 2023 13:23:17 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2054.outbound.protection.outlook.com [40.107.21.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768B54233; Thu, 16 Mar 2023 10:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f1ghbZ4gfvpIt01d70RPguuCdbeE07ddC9WfUL2GaMLgHGZ1C/eOVap9cG0JnsZNksQvkJbpL8WpbyZOHU3hn8n31TUMdpJSmRYxQVYHjRBrzJVvO2X01mSgGjvaoKgAcT0TYIPu6dtpofULo83KL9CDSHY8TI4LuoI9VZVe8zvC4+PoGXjCrmehfKK/6weP8bVmVmVK7aGxAF+AUdB9VOePpoXVms/9YJcRSf6FwRwZs4zDqAGkhEFS9j7p0FdEP8VrC9xRkAPkLUAqRpKtGOYF5E7qOhjOiyCFzS8OPUVtHXOIJNHcSzwEZtR+RoFi9mycD3BhKJsJlmfDCDJiog== 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=pE/kksZ9/izowAg1GSlXNRb2ouOGLUVelluEjwyW+P4=; b=Ftb1aoVc5Yvk/LOZp936VUX4wrsdKdAxEy0MdG/iCQFwbrlc2ep/D0RcgV5ZPPhMcG0YNtHnQiKU5Tvy4Q4oFkUyqWfnmi1sm4ymRJH5dt8ldwlY/+anjVyX+zIP0TbagoTrAjgYKQg9uI/EOLfzoB2b2NydkO7gprQZPHw+bHkkTeyOlrGYfxXSJuKCZhdkfaKa/xscgnEJoYuG24Uy9j1isAom/8mTh5dO2GDLpzH65NKW12zyFpVE6S/WxlEY85F0UvdDzRL6euBw1Vr4McDHY/oEt4yGjp8t3IxnmTZyXt+5MzqDH5SrY64cbqRosyIR5lX5IW48Sam+pjcxaQ== 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=pE/kksZ9/izowAg1GSlXNRb2ouOGLUVelluEjwyW+P4=; b=m9nkFHL5u/RFkgweiAdHwz9fbP7J0eMe3YpFQ+xjMbdVgAKVvGwVPi4m+d1AGylT6d6dkNPNCulvRZ158fUlXFLS8aFwCuVS7UhNJ3y5mYGsMI8jhHE8vV5PW2hUPO9zgZPhTLAw0iExEoZJyR9w0D4zD5vwq4SuC1ZWPVXjjlw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) by PA4PR04MB9293.eurprd04.prod.outlook.com (2603:10a6:102:2a4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Thu, 16 Mar 2023 17:23:03 +0000 Received: from DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9]) by DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9%8]) with mapi id 15.20.6178.031; Thu, 16 Mar 2023 17:23:03 +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, simon.horman@corigine.com 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 v13 3/4] dt-bindings: net: bluetooth: Add NXP bluetooth support Date: Thu, 16 Mar 2023 22:52:13 +0530 Message-Id: <20230316172214.3899786-4-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> References: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG3P274CA0007.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::19) To DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8600:EE_|PA4PR04MB9293:EE_ X-MS-Office365-Filtering-Correlation-Id: 39359446-c541-439a-2fae-08db26431919 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pRBauS8SU9hPQlP9lmdqOKLQsWZSzcTeIxInr8eBPjfxCmzanxDCDYL8horUlVUACsGLS3yGHf/hZ6EYW+wRHbwl5ulOdjqPQoFnyN3XBN0CtJOAYAwDEWd2KGI0yzWFw2dOVbwRAi6K85DYBbbGEnugBYfhutJkTe2iN9z97NzAl/XylC3dglCO4uKw83E4KwhV4EbsbPxepMuCa8zUwdF7e6ePR4D6+IlLfJRX9djXtKFk2STgIZuO3jskzQJyn3oJnC8Rv+DRqZb8TG7TsI9qddFz4rVl1TNalthyC9lchACaag3/VS6NxliXi7cCYmz9sVo9w/VmDviZOR6wC3EEeohaOyR2U1r6cB05cgisyYjTytbNETwi8sYGlr4nfHxwGBXOHqvFOZklH5N1bN4qNHWRCg/dkKpDDj71t7KQAu7XSBnJU3MY9z8o0glRhxCREPNXtkUEYYAyBKkUkzsztNLnmQ0H4cLkFCl36asgz+hwdwDw+S0u6tDW2jYubrbpDadp7hoBUqI+2yhnYo/52EhQBAb01aRo0ueZ6q/nkj+5dQhQ9rwXzTGq4RNmUZjGS5ehdtYxiXn32/LW3vIRw7iqoZk/eTMFZmtTVzVit8CLf5IqrKLhbPKUoJoWLiGhLQvtmN5Z0pLwNsnWBmK+0FcY7m/PqjhDKYJBzoB+s/jtkmcrbKp5wWIiLeNLlX+RG7Sk/QimKZsXO6lZJ9C2VG8+6zCBWudRs1Lb3fCIaLs9EN09hIJ+VNv3RcIn X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8600.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(396003)(346002)(39860400002)(366004)(376002)(136003)(451199018)(6486002)(52116002)(966005)(6512007)(6506007)(1076003)(478600001)(26005)(83380400001)(2616005)(6666004)(66476007)(66946007)(316002)(186003)(66556008)(2906002)(41300700001)(4326008)(8936002)(5660300002)(8676002)(7416002)(38350700002)(38100700002)(921005)(36756003)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0NOcqTV61Ew74lYtN5Rnw16ajUGbqcNh96L6S5M6f0DCAAKO2hRDLQB/hP3ZBhzI+QLDFZZEULO2+Oy67HEMolnTNd7HCJw7YXbWXqlQto1fDgQJPR3/6bghCk7afg0bQKBxvso9HA/bXFMC9IkqoKkVwIyI0nud/oyLA9CdOXPBgY9W0kokc+wKk6hu/nhTz8hrQV4LBeoSp15vpKJCfREvbB+1PvBWQH4IxZ+NR9LdmhBShwFn1t5cEJnTUSiyCDivYJ0euttT5oK/ddVmjFIMkS29LKF/ow+mCYKagGBn3T9WfiIODSLuyrHo/0aKCFnNS+jtX6Gg/4cWdp2Ti6wEOZdc+cSsSlze4FpISjG/MucVCR4FUQqMTqCyJv0gWOKJOBjMk7BV/p2o5MsQcFbrqNzf/AFasQQTfqsgI4GtZqbvgYpZSS6/oFhXADPlVf+N5hD5jEkCEvK55n/Ocno4e/o2y056NGFo8UwUJoa15oTrrfV0uR09+c7WEwoqLqsCEiMFj/BgT+iGzf9otgXxwyp7w9YjyT2nDRpFuKF8DkFeACRBM/KjGt5/g13GISuJwhL3UQ/W4idM31fXkSA6yWouhp2gQ0sa2A+vCmCVniNSAqmUVv7TwpGoij0GBQf7PvR7vcl8eJBcID/j3pHkQe42SsKjn7ZlO2ZBMW4Fa0OWPKZ9I2ojTR4QYE+UMHhXvWD9HzFVwXv7gZDggrBqwd1P1APMuDFkZqqlQ7/EyrOie4LJleJSRs8fz0LGreL4vl1tsybjA6rKAXQifVbEYfYbKOD8SXPPfG5H2tv3CQA7kHttqLms9IokyCovJ7fSKl22iy3aJvlcKeX2NkZVv6/sTc3U5yR/CZl7gmLrTW3ehUCHLRgnF2QTz7es9zkVRQ6qDPcy5AB9qdOjaYFTxh4lGn2pbb6Mz8vDX42xg0RYQ63I+nbW8h0dfqEuCM8l9auP6y1ebJfD0DrIttF7RkFMB0uTxFOEszJUtHXCQaNFumCG+MJ3eISxHLUhNhXScpOrgwXGQ6Wkeez+f7Stm5BKvpql/qVuuCd9kaSCzs8Rd35v+HCe9OjRY38VKAaSt2Tas6vI7m6K4kWopJZU/9IXSMl+BXYUVbL1un/PtkQy55n0t+BCfVHiEVuRC05/uSCyoybYUfqpo2Omb41M1dBjellu/rpFT61OquZmQFezjuB3SrjnaIsvIxVVQj//g4PVQZYKk+WVT66/dIJWImUB2qW1hUbue6FnHA3Y3S4E1Tq0ek7QSLOwMcVCqhuBZA/M/ZbMi70jZmTaC6EfhNZkCE510rkNUbkovNmkuZ0A4yNQhnSuC7/8SPNwu+EfC3319xHuE9po+XQOMXZmCF++rzTZQClLUIv7nZQUbTPN2MOLg0Gk1PJLgdfI+8H9RJuIVeotbukafVlqJJggnlKdhJOvO9LeR5lpkgsAVhSTodJK78qGMA08/kS4lbF1Fn6LZAIqSgy2C4fkFKB21WA9kMf70Na+LnZjDnPcJMPnQWE84P4FPmZoB6IN7+XQPoFWtplhYs5P44+Y5YitJrKQhM4A7PTH/ZDDw8kawvDOjZ0PvdHzwqnAH9loXLougNi+Bzo+XPeTU5Q8Cg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39359446-c541-439a-2fae-08db26431919 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2023 17:23:03.0520 (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: Im+zVKXyvmg92ajkysKkJiJwVj8g7ccP7YmHvn0dkMpBMRx564KfKVfT7ArO7E7HY6hAAoCsv2jQjWyBtPBWWI0aXt8tXwttlLqRBILPtvY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9293 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) v11: Corrected grammatical errors in description. (Paul Menzel) --- .../net/bluetooth/nxp,88w8987-bt.yaml | 45 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 51 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..57e4c87cb00b --- /dev/null +++ b/Documentation/devicetree/bindings/net/bluetooth/nxp,88w8987-bt.yaml @@ -0,0 +1,45 @@ +# 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 Thu Mar 16 17:22:14 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: 664119 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 5D492C7618B for ; Thu, 16 Mar 2023 17:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbjCPRXk (ORCPT ); Thu, 16 Mar 2023 13:23:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbjCPRXf (ORCPT ); Thu, 16 Mar 2023 13:23:35 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2054.outbound.protection.outlook.com [40.107.21.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0E2DB9524; Thu, 16 Mar 2023 10:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=neE/MqI1jpz/jTZ9FKzJIe1bVyqYEghITFk9BKN6KrWmL3RxNu0xmRuQsTA6ZarAFOz18kXo/WYE/l3AgEqX77wLaXz21or0xwRv7vf5SNiAFeKUpM3Jbsz1BWSsU1ws4Od+PYNNDIjJwdLfN66NUgqEJK5JxynuVXiNUOkLWd7jjxIMw/JGtMM0HOYngDhZ7pTDcnX362D0D7e5hDxyqXFhiHR4z7v0Y9alZn+VVMcM2UXTsY9KfoubqF4UrXWdUWVvh7Dcn98wdENL/bOJM3Dptic1IgartmAgZY2//leN8h9gkVxEP9xMHr3vZWD4TVNoB3U7+1KR/YWqRO6aEw== 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=8vy1jgx2tTVHb3Nk7rwmZ/9G7MOG2iGoosTYxfH431Q=; b=liAKleUHJ+nuhI53oY9AyaRyzo0umH6K7EVEPZvS5DaBbbwvrTKDd87An97P+2Om8yZefYul07xvoUuCTlHm4aHp/VghOzc33+Nc9GMJrtyLSLlxF+0Ugd2HpEoqI0fxCCaf7aW/d/Jm+GQQdw1c9mwStMonkQGP9KmSglvTj9t9iwJ9X+OiMKQQQN5XeGeUWWAgxLWJa9CDT3P5l4tpYlirMdCBJT9n6Shi2AYa3iBrxUT77N3D/9yzF+bzpvoby6/POyO+WgYOCG63piJN9+UdQcrFwWAU+XEiL+qm/IlB/OmSVuTlXkjgF+vbTp4/c4DdfFGhMXbjLh3TE6jwlA== 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=8vy1jgx2tTVHb3Nk7rwmZ/9G7MOG2iGoosTYxfH431Q=; b=iPEsaSLGRi6U0X2YgEVE7Fak6RCUraMW3KR/vCH5RGcE/A2bsqw4JbtYNlxymmYTwtW7qEY+6kKJzJTAtW2PSMrVzFTPukNeVxqZ0Zy9gkJ7sII3aod5qdxSi/NhuddRpsmkOyb0LhHyI2CwEBn9gfapNNefnHVNqsVrQl6WNgA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) by PA4PR04MB9293.eurprd04.prod.outlook.com (2603:10a6:102:2a4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Thu, 16 Mar 2023 17:23:09 +0000 Received: from DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9]) by DU2PR04MB8600.eurprd04.prod.outlook.com ([fe80::d590:6d9a:9f14:95b9%8]) with mapi id 15.20.6178.031; Thu, 16 Mar 2023 17:23:09 +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, simon.horman@corigine.com 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 v13 4/4] Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets Date: Thu, 16 Mar 2023 22:52:14 +0530 Message-Id: <20230316172214.3899786-5-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> References: <20230316172214.3899786-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG3P274CA0007.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::19) To DU2PR04MB8600.eurprd04.prod.outlook.com (2603:10a6:10:2db::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8600:EE_|PA4PR04MB9293:EE_ X-MS-Office365-Filtering-Correlation-Id: f748856d-5f57-4160-765e-08db26431d16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iGA1YV4qrCMkK0u9jM4JKxFq/0m7bW4RraY17qQ414pxyB7Y3LUY4X8kxwICEY4dSBaEPKTpYeW0OOwKYQ82CN30TFYFrRSkyjaph62yhiEwp/TL4PH5DToesZVIsKMFZFKcxj+4PbivRCa1AzdvxlvsO512qEQhqPGJp1HAUkJSKPzYA/7e9wU9aYdnOqlEjB3Ps+V9sX5IyVrhAAFt/WZmCqOpeOxkvCJHmgrLyXOrK8tOiT1bRg4/33LLzCudsgbtDWfLSV6/MRmfz1tlbRWdlbS7qCC9xgw9yiao98x/Hbh0IxJR7Eb3QZZej587JyVNI/Oe35RhACKFoG0nbGDBNUGzEpriN8OmxAFhpedobokBJthAKJr9ypYtY8Fp8TqJUAAajroBbLyPiYWGiipJXJlgn4nxCJqtNbxpdTBUPvYWZixq7e6ni326PEI5UTme7CGPuYLWmGjHByk1mEcZoOb8vOhu5EJihDCjA8Pij2iB6c4GlfYFldGPnBxS2lqwO9XFpcWO739APQ6uhbPwDMd//YtCPGY/G+6xcF4HjSMWJt3TifDM/VFI/3MKOHwuw9FP6pwMQ/HVy5b6AZcWm7KQguns0tF4+070Vdvb5g++2sgP/qbxi2oNvX7BLRga/n5VAYRchp5mM/YEMX2EjRAbRR2zIO8+2LNf1GT86cQ+zYLNiujIgyJ11ofHWxVdkFS5ODRD5NKyIeYQZg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8600.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(396003)(346002)(39860400002)(366004)(376002)(136003)(451199018)(66574015)(6486002)(52116002)(6512007)(6506007)(1076003)(478600001)(26005)(83380400001)(2616005)(6666004)(66476007)(66946007)(316002)(186003)(66899018)(66556008)(2906002)(41300700001)(4326008)(8936002)(30864003)(5660300002)(8676002)(7416002)(38350700002)(38100700002)(921005)(36756003)(86362001)(579004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?255lQKPAWcbVSSAySTKAeWkna5/8?= =?utf-8?q?MwO0NB0qr1VU5PDPxTdZYO8f4M1i/uK10d6m6fNziRikP9P727p8d/9lMQ9O3nstf?= =?utf-8?q?ZZ+iskT2hyHuB1TzcDpEYhAVRVnPCb3ftFCRvWMBD/pdXXOYt8ZIw0Wo3sKCsuamb?= =?utf-8?q?jffy3wRzKmNrmbWqbopfCAs+tIA+y8T/HC/GtoHaRMrf6jbvEqUE7DAB7HwIkjetP?= =?utf-8?q?eEZD/mxGdrjD5vNpXi0ORB+IRFbMNnHXi9KkULi+wYHcGLj48EjOttPNZx+Zk6e/z?= =?utf-8?q?wolyrl1YXYoSA56iZNo6FgEnmisxOK68hgiRNbQviL7cNZRLDyn05AwrMiT29CL/i?= =?utf-8?q?VkdDLFwpMrb0TqqT4liuyz+lK0ZDo4Y1hZ/MoiHnIOzGH7MBXVXFtrZYRvK2NeWt5?= =?utf-8?q?anMQ0HWci1X5Fl88cs2+2x1x2Jfz9zswf3bhYzbxzB3Y2+w1+NG2pF/HGps+GwnMz?= =?utf-8?q?I38HSqKGFP2mAVvEtldS6zvGNgjvTIq/utpwwoO6bnIiSC+M5AEUxiMzYZrCqj4uT?= =?utf-8?q?TMhfpNbWujs5SO0+nWndZHtAi2XhGZE0gxFRXfKB3yGhliKy11gfBou/evlz+saN2?= =?utf-8?q?ETqv/XQG1LPcOGLXZOeelTSbVFdAHHsDFfRg54nAux17iamucNzAfGF6TVcDNQ/Sc?= =?utf-8?q?eb0YYj+0g+bCNSzyX8xGgf8tSukafRztwpvh726r5vYjAxTlPw1vrkf3QURQUJXHn?= =?utf-8?q?PKHx/finXq0xo7fUl5BL43lUtKZaBkUb4+BixOIAfPiyVtzx8M1Edc2+gt9s6fOzE?= =?utf-8?q?55KE2FsahHzaujK5hKEBHI/cxpbO+OdWXy0ywIaHhn57HDoDsqUtrPVjh2i1tMj5x?= =?utf-8?q?yzLzEl/CvDBGvS5BCskh0xmRDvV1Il7ae6+jl8X+1rfmQmJr31I86e2nC6KrroSBX?= =?utf-8?q?qX94GCbuGI24jYpYTC1/j/7ylSQhNB9Gt3Cwrj6SgQFd9usuccBmARDaez4PrF1JO?= =?utf-8?q?PFGUwlfgcUZ/URYengFsGtuQwSeIBNzLK0GEOIVpoe7/iNiGsG2yj7Y31dMkGHqaA?= =?utf-8?q?8FfcTefv8lD1sei7j3cZMH+k6Xtad9T0SmVFnGhpeCDJ4WdYUxAVdHmOkteI3pf2Q?= =?utf-8?q?pUZKCCyAxs4mbm2n/TDe9YorFDSuVH34EZbwYyUi8EfvYUGomt1D6mh2DvSdMsYX0?= =?utf-8?q?AP7uXgtH2SXsutKxNxsXK7QsBUITcyaj7MB4jeZ6mymkNnBERz9/rJny/lcyoK5iP?= =?utf-8?q?6+UJAKd3wQel0AMPQehMzwiM1Qz1fT3WLAVnZkN3L1Fr/xpTCO4O7/Iq7oxVuLaoI?= =?utf-8?q?JBiKy/pks1tvGn/Q7UzYPszbVR9X3FnF4sM8MYUW8fOosKyab8i/zg7H1t2vQUflC?= =?utf-8?q?kh8vYeAbn+mUN78OpS3WxsbX/gfVn4HgqwjnorsbGEXdB2r1w3WuyogBK1CAXz+mM?= =?utf-8?q?Dx8snHCg+XWw+8ay0TKZCW4OL3i0cdIHhaNB75gmhGneSI2GYQQLNT6bgx1A3nyqz?= =?utf-8?q?TlfXxgAB6l4XKUdJ5TXCZB38ps9+mzIP7roUBMY1Df9Q6d7xTQqEI1RVy4bnCzm48?= =?utf-8?q?BJCSE/PqstGKJQxgh8ZrL404mH6ztdRC1g=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f748856d-5f57-4160-765e-08db26431d16 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2023 17:23:09.7742 (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: 0eipV17aTgL6yFPfTGf7d/nahaZ4lfckKjA2GuC/zEk0p8HJOqiT0NEOgLE9bf5VgSgOqD6vp6vbWZPGoui51Pfnp+0WuigVYjyPGUgr09c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9293 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 Reviewed-by: Ilpo Järvinen --- 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) v9: Change datatype of FW download command CRC to __be32. (Ilpo Järvinen) v10: Remove version string from MODULE_DESCRIPTION() (Ilpo Järvinen) v11: Renamed goto labels, fix potential memory leak. (Simon Horman) v12: Create new function btnxpuart_queue_skb(). (Simon Horman, Luiz Augusto von Dentz) v13: Cosmetic changes. (Simon Horman, Paul Menzel) --- MAINTAINERS | 1 + drivers/bluetooth/Kconfig | 12 + drivers/bluetooth/Makefile | 1 + drivers/bluetooth/btnxpuart.c | 1297 +++++++++++++++++++++++++++++++++ 4 files changed, 1311 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..0703bdd44140 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -465,4 +465,16 @@ 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 + select CRC32 + 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..5f641466d695 --- /dev/null +++ b/drivers/bluetooth/btnxpuart.c @@ -0,0 +1,1297 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * NXP Bluetooth driver + * Copyright 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 milliseconds */ +#define PS_DEFAULT_TIMEOUT_PERIOD_MS 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_download_3M_baudrate; + const char *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; + __be32 crc; +} __packed; + +struct nxp_bootloader_cmd { + __le32 header; + __le32 arg; + __le32 payload_len; + __be32 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_MS; + 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)); + /* FW expects swapped CRC bytes */ + nxp_cmd5.crc = __cpu_to_be32(crc32_be(0UL, (char *)&nxp_cmd5, + sizeof(nxp_cmd5) - 4)); + + 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); + /* FW expects swapped CRC bytes */ + uart_config.crc = __cpu_to_be32(crc32_be(0UL, (char *)&uart_config, + sizeof(uart_config) - 4)); + + 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; + /* FW expects swapped CRC bytes */ + nxp_cmd7.crc = __cpu_to_be32(crc32_be(0UL, (char *)&nxp_cmd7, + sizeof(nxp_cmd7) - 4)); + 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 char *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 free_skb; + + req = (struct v1_data_req *)skb_pull_data(skb, sizeof(struct v1_data_req)); + if (!req) + goto free_skb; + + if ((req->len ^ req->len_comp) != 0xffff) { + bt_dev_dbg(hdev, "ERR: Send NAK"); + nxp_send_ack(NXP_NAK_V1, hdev); + goto free_skb; + } + nxp_send_ack(NXP_ACK_V1, hdev); + + if (nxp_data->fw_download_3M_baudrate) { + if (!nxpdev->timeout_changed) { + nxpdev->timeout_changed = nxp_fw_change_timeout(hdev, req->len); + goto free_skb; + } + 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 free_skb; + } + } + + if (nxp_request_firmware(hdev, nxp_data->fw_name)) + goto free_skb; + + 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 free_skb; + } + 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; + +free_skb: + kfree_skb(skb); + return 0; +} + +static char *nxp_get_fw_name_from_chipid(struct hci_dev *hdev, u16 chipid) +{ + char *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 free_skb; + + if (!nxp_request_firmware(hdev, nxp_get_fw_name_from_chipid(hdev, req->chip_id))) + nxp_send_ack(NXP_ACK_V3, hdev); + +free_skb: + 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 free_skb; + + req = (struct v3_data_req *)skb_pull_data(skb, sizeof(struct v3_data_req)); + if (!req || !nxpdev->fw) + goto free_skb; + + nxp_send_ack(NXP_ACK_V3, hdev); + + if (!nxpdev->timeout_changed) { + nxpdev->timeout_changed = nxp_fw_change_timeout(hdev, req->len); + goto free_skb; + } + + 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 free_skb; + } + + 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 free_skb; + } + 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 free_skb; + } + + serdev_device_write_buf(nxpdev->serdev, + nxpdev->fw->data + req->offset - nxpdev->fw_v3_offset_correction, + req->len); + +free_skb: + 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 = 0; + + 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 || *status) + goto free_skb; + + set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + err = nxp_download_firmware(hdev); + if (err < 0) + goto free_skb; + 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); + +free_skb: + kfree_skb(skb); + return err; +} + +/* 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 btnxpuart_queue_skb(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + /* 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); + 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)) + return btnxpuart_queue_skb(hdev, 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; + } + } + + return btnxpuart_queue_skb(hdev, skb); + +free_skb: + kfree_skb(skb); + return 0; +} + +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_download_3M_baudrate = true, + .fw_name = FIRMWARE_W8987, +}; + +static struct btnxpuart_data w8997_data = { + .fw_download_3M_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"); +MODULE_LICENSE("GPL");