From patchwork Wed Mar 15 12:03:23 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: 13175745 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 271C2C76195 for ; Wed, 15 Mar 2023 12:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231848AbjCOMEZ (ORCPT ); Wed, 15 Mar 2023 08:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231713AbjCOMEU (ORCPT ); Wed, 15 Mar 2023 08:04:20 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2071.outbound.protection.outlook.com [40.107.241.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EF4E17156; Wed, 15 Mar 2023 05:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SJfzLj1Dk4NkeuihVoahU+1EZCSKKghkeV/262tbONKEMENqHT95HDIlaBdfo9GL3JluVePbVTLc72eRuW5IxpOkRDeoC1E9//61MNe2uTxi2w2anXdNYBGufYqaS19wIIKhYCthfD2lTeOnTvv90BPRmIoR8Xih2VZTD5lVvCYcvEDPWapVkaPmVhaR/tN2Hz51+I0W2KN+yvgmv215DjiBI7HTM0JlV8v3EnSM5uUM7jFSMWhg7kskgD0f2k7Yi4g19XshHck2+bqSi6Mp7JO1u9BNFztloBFBGOiPZbN/yqzqKJKBIbFkjcdP0clPR49uFScb4D+aXGpd+Wkghw== 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=9h6VVthgpah7G60qrDKCw7o0qLugUfnyM87b908ubwo=; b=Q++5/l0yJ1DPYdv4Mq6dalWAyJBdT1+EQvZDLQBunwFrFj2ykVRYCCefE/mbStI0MC1oD3iQBGfgLOFkcjrx2Ypmk8sniLI3iirHCMRb9wSRqS7OJeGvT/Hify9eDbk/BqUJHmPbFWSqNqeICj+OuYi8+x6S28r3C/7rGLc6yuk6xV8bPuvTk23dnNqGz4EbopP85CvSuPmHG4s5pyD3fbKufY1/Yz6GQ6hh6OUeI6yRkc+GwaR08tgFSTSDgZG2VuYXdCcAaRa+ZQLZM+JATiKH7P1DaUCF144NlZ5sL4TaEqkEyQed+m9T7gLficG3ron5HFfwC4Mg76DaVRzxmw== 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=9h6VVthgpah7G60qrDKCw7o0qLugUfnyM87b908ubwo=; b=HbdKD/JIRdehgE7o14hGzJod2IrLw/IZq/rh5iF9xPNTHURlp3STE22uVaih+kzLGdleaE/oQLKjVC1eQqfkXlI0UmT/KU9DLeIP4C1mdIaRIwDuuJT+A+Idv8BH/lCp75uTaF6DClmP76av9WetSowyG0DF5MEaomNAtrnEneY= 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 DU2PR04MB8629.eurprd04.prod.outlook.com (2603:10a6:10:2dc::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.29; Wed, 15 Mar 2023 12:04:04 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762%7]) with mapi id 15.20.6178.029; Wed, 15 Mar 2023 12:04:04 +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 v12 1/4] serdev: Replace all instances of ENOTSUPP with EOPNOTSUPP Date: Wed, 15 Mar 2023 17:33:23 +0530 Message-Id: <20230315120327.958413-2-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> References: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG2PR02CA0096.apcprd02.prod.outlook.com (2603:1096:4:90::36) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|DU2PR04MB8629:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b606c6b-6896-4e16-2532-08db254d5f02 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9sl8Q+w4YkPWh1ZQw4XzGc5TLfRlOJAZaDrd+p1KVWCUrizpNPRZmq7vIGtZaxjH4eHGq1ojg4fT/YAETG6IjuenvR6Ta2y1Px7O6dejXlyhWGB6jN1pFtNdkI6txyqiNJB9zwL1fIOMKjPViw1lbhjfcrys5cZNuV2cq2QLvoqxpVPqlTvYsnZ6X1ZUjlF6lMw4n7H+p7w5y+WxA3yBe/dSN8JWy3pfVI1O2V/bDGdE+8JC2w7DrZ2FBrcHzxVgS0HcHnkUNq6DxxZK+WUG2ycaYy4H4DvLIwFMuiogvYOFbAvh5Uf8PL6oOjEFdVls7kCR485fr+ewbET7nUJGYSIGB0XfgdErdyskLLZ/XY4zcMUWZEoge1Va09EOcace2ZoSkdrTi0RPZ3bp76UzuOr6bd7nhOvZOciL2qOPbjxwQuP8nNX9XUS40/OkHvBwMC2U9+dPSskFzEx3O7Haf/8lYYSXCeVpTrlO3Ssioy1p4l4toJvwCSjLCmzboFDumnSjHhp0eqNyxQdXeIc8lshxW2SP64BqRypYkXucyw+j8QNOz3Nop41FedPnw5uaLrxjbNGIphW+p7/3rnn3r0CYGCLlARq05C/Nl/7frg5NZoIhdy/59hLApzZESZyg87meLPj+PoGfFfSgtkQVyb3CPz9wcEp/AZPxc7Y0fx/QWyCGdeTYLJ2iPm4r+5vKA4RPEDbBV8Byp5bxBYLm+V7HTW5XqiqrVwcP7Q3FSkA= 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)(376002)(396003)(366004)(39860400002)(136003)(346002)(451199018)(66946007)(41300700001)(38100700002)(2906002)(316002)(38350700002)(66476007)(66556008)(8676002)(4326008)(8936002)(478600001)(5660300002)(7416002)(186003)(52116002)(6486002)(921005)(36756003)(6666004)(6506007)(1076003)(2616005)(26005)(83380400001)(6512007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fw0RFDsOfQ5kxKJyBHKVW6mJl/aAshaak1T4PekkN0o82uzA7nRA2SF/+kb7IJnhb2EwnigD8LQyZwBkdAseu/GCjuFeWygwRmcoiljo+XST5TeTEWqlr4kBoYvpt1yvCrv8/cG8pf+KXurB8hxYzghuvGkbFvePZfhtRyP5+efb8DxQP+fPAjemsBB0SyNPDeXdiAInBwcTIV66roR3iLW7Sf4HhaVGLdzDbjpKUZd4K6HJbGAsQNptOVT2b0GzTSMkpLtIMEImqL5Wy5c7CFoZe0blZtI8O21Rmr/HzqEUdY+Db/xe/K0bdKypovuD7ilqm8zNn4zxTCP0cujboU1Ah4I19deioJ8VHlMRmkstlHLxTxZ7+5zHzImqXJ0IaSUkR3CLfL3AI/rDMyX2kzsfQHxTDtmdAYgxTRaz4cL1kYqIwyrmDtmurfGBPRhnPqAn2Y8I37byKivADLH0CjNkXa4lkXoYStT9R8ZJJZJyUyseDq9BjBjvgAW0weJbzfjTp1zqCRi7GbDd72CxVh+ym3iVSGSyunD65bzXSRUnUsK36KjzufISFIjDGJg8AaIwjPi03bNgynSD/1vhBox5njbfv4mp4whUpoLL1LhChYwbzVaM2xyjLTen8aIY4FMJxMiwTysCCfN8Hthp422NH14zK/JTLhN7gjUPCkaYZIP2i8jZ2gAOU7BCJE5r4a/Tww1szj0hmYKE0v1BNrofGM8ZEr2IkzKWvljvKfcko6FjTUa7/Q3gcAm+VsMhbzXF2Dut9fc39XjHpEHOnYjS8vrzYrNSN0JfH4Eg5MRTA+kJF195XUVCjaK5geGDGjkZNsb0O9PgT1/jt7HNHGKW+qnQ3lqbaBO3qHL14atY6Ezjma9Im8SawyrfX7rsglonF2hD+hfhQBUJuCfj5oV4HDyyKks/atKhgZ8Ux2DlfNKliddX3fhnqHxjjwtwNngPoPJKH+byfzbbPXCYXQHpBTEftKMVx7WrZFOiGAlwI8DpUwLdKGpIlPWl9AKUmQ5U6/VwKwgHbbz+ZLFLi1nlez56T9A1TIpcZ+uwQENo6Kp2t7ib493Y9JqCSKumuu6p52zz+C5m7YW1K+yzgNUwUGB5WskH9s7J9lbKw6wYvX8VocHdCy0PeyrIYIHofH5iHR1Co8mULBF9BsjBSUNdEpMHsVsetDGmAfGfqQhrnvOvAqyPN7BCoHcx8I2RU1pD2aLJDQauoAhkkdGelXRUlW/CqACdIVAsL2wcKLEnfY6wJsVm0X7rucFiD2I6EHqzbmBs+A2KXG7/GPCtCAVekHlYm7+fdsJWQ78o9ozBwOzAl+5NFPWbGFpRjBBLrFzUiDHtgoxLdNL0KJnY6IkjkB1qWfC7zEDlDK9W/qBOXGqL1r/T72tTC7kmxp4YYdeHW0y+muAospql0s521BG6oMUKlwTre+h30iq3yv59PUQcfIH2FdONorkrjEH7HKoWY/u2212CkPoVl9vV7HusmaJ1sNmWh4n3SCPTrT1kqaUuBVqOf10Qos1vDIecrvEjpJIzefmwhFGLeN/lHkeNZd3fGI3qbe+V03Ypy67RzGVrcLMbUUcTdTT6fmdkq/XZBT/NBKdYhG1VdbJpGA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b606c6b-6896-4e16-2532-08db254d5f02 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2023 12:04:04.1863 (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: ATzy78OEBYXLJo+jlmw/08SgnQMPGboWB2CrmoWTUKBbgjGKvZxbpjrznkAzPM8bh/IX73zkaYLIiTMBzG1/dxa2gEB2ZgC5ieKmpinApNo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8629 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Wed Mar 15 12:03:24 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: 13175746 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 DBDF7C6FD1D for ; Wed, 15 Mar 2023 12:04:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231862AbjCOMEo (ORCPT ); Wed, 15 Mar 2023 08:04:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231673AbjCOMEe (ORCPT ); Wed, 15 Mar 2023 08:04:34 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2071.outbound.protection.outlook.com [40.107.241.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D22A62BEE0; Wed, 15 Mar 2023 05:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G3E08Viq4KESPXH+aBjdDDUwb/7uD72FPOOVoGkWFlIgXszPADaQYQoOUHYoCs4LS5oxu3AhUQYzWkzXoCH2sFZeETC71/rhvv8qegp3b3OupHtxFQ8nG5PiTFD0UoSTrc/3WZx5eU7D5bwDEBem2sDYOfbijrqc1iKnLDopl+Q6/bUDWu6Q8NWYtvxaKJHlD9I+oD0SqtVAE9rJLpaM1r3lcHg5zVHHdeLD1/J/XCUKnCQe21/bbqEIT3FKAQjejCGAVQvHZ75NEx+9iFmmA4LiBoHDpme+EY63vftdFUC+j3OYn8/RH905rjIwWlIz/xmM/PswenpkZo5PrSIEkA== 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=8nBPLnQZTmbjcXxRT01WcUGU4Offe4k8SEV+HxYAerM=; b=WmaDi9HHl1Fwg3VEAnrs6Er6pNiX0FU0qPghNNbsONiWr5WuF70qu6iuB7pwmWvfXAm3Xc91bWieh0FGVKuDl3pP338brBxg81bttAZTUDn+uZ0U5Ny1eTnDxUL79qiSZ0COhipYGjDxQFIXhV2m2b61sEnUn+FTIaXYeopeywaz/5uX6CPpy3/YowRwrpeL7Sp2bD7xIZUIE0vrBgaSBdxtYOMxhqv3kxfFsEYg7WSJ4Bl75kDmMk/5U6qNWP+b/vqO/pfMjzsma4Lxtb7TLxbDGumzTzZjdpPS10pnYEkiXB73UlSFutFn+vJy/QHHPKHeflnFRpMDjYLJUAwlDg== 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=8nBPLnQZTmbjcXxRT01WcUGU4Offe4k8SEV+HxYAerM=; b=AVfic7gEmGfaXUlnT1ieGBSYUqyyDLEhTA12phZRbdpQyOll8K4tZ9tlyBJWglYfIDsjvgLRGqMzjSPnuk9IHSuAfkB+DjiIJFT6sufPYAdZ0DzThUHohkB5YO+A+8opLZzReGHCmqHefu12Lkut9M/DAZSc5QwYrr4V4rdq76E= 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 DU2PR04MB8629.eurprd04.prod.outlook.com (2603:10a6:10:2dc::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.29; Wed, 15 Mar 2023 12:04:10 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762%7]) with mapi id 15.20.6178.029; Wed, 15 Mar 2023 12:04:10 +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 v12 2/4] serdev: Add method to assert break signal over tty UART port Date: Wed, 15 Mar 2023 17:33:24 +0530 Message-Id: <20230315120327.958413-3-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> References: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG2PR02CA0096.apcprd02.prod.outlook.com (2603:1096:4:90::36) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|DU2PR04MB8629:EE_ X-MS-Office365-Filtering-Correlation-Id: f431bd0c-1935-4355-f2b2-08db254d62c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F6XzxAjn7YmXYZLptZwHCiFUt4hjL3bSR52bBLG55YoO6eOCxvNUYHHrUmkkhVZ4j7pQzb2tRQ8TXnu/BrJJZxVNXJzlXO8viEihWnhsmpU0dj0LgDgn3WV3Q0T22/Ef/w3gGPDKcBI4hPc5PaogvVGNyBbT76CerPcfdKj6m2doU6jsHJmQ2SpKcWpboVztbBJANf8JkFYOdZB9PhXBr718rhDnI9UuJzQGMCfujF3XTnYnm7Ych8ZycINb0M3lv4K6ZZm4Ni+6IEWi10lOzbdnOTyPY9z3k7XiB0f18Tt+LKSs6H84DLJYzexON9CgyZOt2Pg5EvEoqC+kWSyjo0kPlDcSmkHZgz/B6O4+fs6FOdPlj+h1mbtBgLZH4r42DsCxbuGsqvuNrQ7FoeCZARdNMW1mYIiWeHsoCNDz4xITHkccVON4QexXUaDi0oQwGcZ1hJ3iF8HYOoTRjgnEgL9sdacAoIzUu1AO8q5JRKYDzbe7I0ffv1o/LkfAPu6qT/dwo5MEeFg0FbjzN/egYbqOVzIEjRBwny1/gOI3yw/QuDwIgWUSOeaiQMSDzfaLtgS+0Wp2qELctQQC3EOolEoEHYE9AFAt047PKt8PVWKtGEk9JeAtTfDWGRhU909YKQ5M1FuvwLiwuDRJhz5iAOIgutMSJflUYxUpJ4uF/bxwiAck5wrorpdBNYNHdKgX/LJsm9ez4yYCxe7zZbPIZt2XuXq6Olyz3BBIkCvy5Kg= 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)(376002)(396003)(366004)(39860400002)(136003)(346002)(451199018)(66946007)(41300700001)(38100700002)(2906002)(316002)(38350700002)(66476007)(66556008)(8676002)(4326008)(8936002)(478600001)(5660300002)(7416002)(186003)(52116002)(6486002)(921005)(36756003)(6666004)(6506007)(1076003)(2616005)(26005)(83380400001)(6512007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mx6GWTq+71PFomIdccDE+xZ07URYDMQf9k9xpld0xgNm77NHM4cgUiiSy2cuibXPcn3VulA7Pkh3mM77jcuHYRa0B6bWXzjLlbrEqViAPl3iHML76Ampf+FV3fIPaGqVsLvLEp7Xl53lKhtwgdpmh0rHxerKIy2qaoTyex/cSdxvwpP6nQobBokZwLYF03uyu9jzUGuCU2SoJP06wpU8GW6dSyeLku4u83HN+3Hpp73YdFlCl8uhAc6k3upBog9i+hEtbINnjlA8KPVRC6uJTVjSgSNfOYlU66C0EsiI6yol3snyPw5q0pkwFB6I7IxPJ0adjjTPHgnzE20xK3K9T7PzVIU4aSHHtOQuaPslvD+QAzACJoyIEmZtVaiyvm88E/JNqyGZcqxqrbRRqodpgSp/TWg24qbO3UuOQG2UN5c/y7un0aDqsRJ1rEiBzeH4RnzH7UVD7/J2WbkyvutioHuxfaPY0H/lIWD/Egwwtr1Nad9FPa8DRXE127FKtubetN0F/v31YhqBFyNM0W5J+YIF76/yG7bKt+86WO7lj068J9kHmVCo0PF1J11hR9tVOsyo8Yf8s/6VAv+9i4ps+WH5U76a2bzt4Eh8UKCHywd8hzv9gw8bbPSB2WPNAknwRja0/vE3fWi0aGk/YpOmVObcTJ+QhmVpuUWzVOkpxBWY306oQfGMvrhhgHYEY2q12p39B1HQLPHGdCyPVoB4hVwg6Z0IkgfTeJwUonhtfYlw7kLpIxwUO/1+Ja0jIEwfOWZVEFF1d0vt8x8pdOiHatIsJwMMoQ9eyPzMX5knWKTFT7npuHN25g1SnuNEvIT3KBYdhSPHbKyomsK/ANTS3Jxvf+H11IZl9slBF4yQFh3WK/qjXwLKPWZmXHCi9PL7M9Tr1Ukr8SkKf3+RAh9U6we19Z8Rv5cITJA2QByF5Y/1nmaVy4kTWM/sauCeAB79JvZqEGtDx1O0/4Dk0RCFp42ro5oVrdbIHQDzo/vVC6NA09e7kHq4OkQgs+cUM8wKOx4KthOI+zRRoSUuonc9kROeNYfwIF0UFaViLOTaIznPq2/uCJ+7PrrYvD+0T7QcPYRvy0re1k0/GxRVb+lDHZgXXDv4GMURPETDtwfnXrC+0d4Y9f8tYXsHJVTpaGORMy3TsCjQ2WLeUDydeE1S/SCJOlHBONJ3Qsd39ThiiF951fMwgXfJKlgPguIBd4e/U9l8xas6+Vj7kGS/71ygglaY5wtC67IHAyDL0He26pH+dOR+PYXKmUqYDiwUBb7XD0o7v1KV7DAULDWm03kteDI3W3ZAZnPwtAqxNg84dl5P5Wu2/+vpjCVRqUtaOkyB5nPdx8WQfmpCyOKsI5EbcPrZFxeLB63gJJ9oLd+aXFC3qnUQjSgOjDGAMBjT1tdecwT+yQHRy7TrD/fcl45wJJO7LyP77fLzTEi3I/IutfxZ6LE4pT8sAhdSSAtN2PJOrG64nLQ3qDdbxLka84rG8h2VpAJC8YCG6qMXsBj5Mm3cJ5nDh9RICjcBXyPcJzAO8+J3/KxJqJMjBnT+W8tJ0DAIAO1UuRQCHiHfy35mHmefahqP9zlfUfXjZBvDj6lK8wTUbgLsS43QocKyZPQH5Q== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f431bd0c-1935-4355-f2b2-08db254d62c3 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2023 12:04:10.4962 (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: hiG1FLuaQYQ0VZ2nOALqnEyj2ajS0mYo7U/3T4fzsYeLxIHBKiyLOeVp4UD2glvP9Kiu8ZaXvjprA2F1LbNG8/9NU9CKC8ft1prtEYCyqhA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8629 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Wed Mar 15 12:03:25 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: 13175747 X-Patchwork-Delegate: kuba@kernel.org 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 5C22EC761A6 for ; Wed, 15 Mar 2023 12:05:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231955AbjCOMFM (ORCPT ); Wed, 15 Mar 2023 08:05:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbjCOMEv (ORCPT ); Wed, 15 Mar 2023 08:04:51 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2071.outbound.protection.outlook.com [40.107.241.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B31E430B1D; Wed, 15 Mar 2023 05:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OVYQPJtm6I1+4uH6UU934mNF0GuZ8NXHVB5jI19TjTOfqPQ8TWUhbCE6Xiwi5jUt2oZw1ookSr/1OsqCf6FxtvtoMZmgHv/L2ndNlijlf/1QC/G6wqXnnv0gM5EF60C1ymQZ9bmgjWkYGNGrDC2wMU3HrZBbS2qdHLHIfBH1ZDHHf2XZuxRCigNYTRkqdVfoCc+dSgp5ImiB7nf6oKLCB9JFc+y59VlssZMojiCrxFC0a3JxuKZOjHyJvZ7Ay+x1KoijaG1WeixAfdF+ZvyQGqEknafyGpwC7WbfmSCbyPtJHejRYYmKdEs44IxK+uGQALHNSPDR8Y6bFEHPn2nyMQ== 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=CianlRU+8+MkBrvNb0mXtCR/E6Bk6poHRi2neFYREiYnecJ1Ru0coZf8mLYHm7I6t57eutVmf7IZ/9nIUkUvMdTEL+qGltpllyBLCG2iINK4M6s/qjqQ48K0aU9IMQLIOH4ES5xo7pziaPPq7A820x4Ib6+Cri/Gb+HhObA4gccVPZQQkeONbpewF1odsIYtBSOYPD2mmTJ9QQYmtNF2b0olWvCgkrCpCAbsqkL8jiZyiX20RHDVaYuLHGPDlwLGCMJ8dQMN9Fcr1hZWWI7nhA9Zh9bPVfyVK/nCJxw+G2i+SrgysdgscPC9/k+3kNj7yYEV6ix8upUDZFwLQjvieA== 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=Ch/FRqZ5sg4tVF3+oesVBHavw8h73yl5kIXaS8a5J1HYbg8RaG/q+zzgoIFdXqI2s6ZGTFld2K7JVgqeP3Igav0VpoJ3gjJtylFsiO6qbuNkkueAu3ShI76NxK87DqDkAw2t2yKBfS/RVMlq7i5t0YEe6g5otdQM1zDvoaHIJWg= 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 DU2PR04MB8629.eurprd04.prod.outlook.com (2603:10a6:10:2dc::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.29; Wed, 15 Mar 2023 12:04:16 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762%7]) with mapi id 15.20.6178.029; Wed, 15 Mar 2023 12:04:16 +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 v12 3/4] dt-bindings: net: bluetooth: Add NXP bluetooth support Date: Wed, 15 Mar 2023 17:33:25 +0530 Message-Id: <20230315120327.958413-4-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> References: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG2PR02CA0096.apcprd02.prod.outlook.com (2603:1096:4:90::36) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|DU2PR04MB8629:EE_ X-MS-Office365-Filtering-Correlation-Id: f918d3c2-b8a3-4a07-c7b7-08db254d665e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: db/HAgn6pZSg6KZJrD+uRrG4CceXKl2Z3eDHeDHAMwQWZtTUchfNPnxdK+bqjGk6GjxCQK45r3CHJhkVuqRb3ckpwgF4o1rdcmWMZwhJq4Kc1y+cOwknflPgwL2XoM48qEyeoYPJky0tkvPh83ENmzYrJcJhvyr1/l293ubGkQ5+b7gJ6yxKMKrLpQ5N3YtCu633mzeRpQu2zZ7VrEXa2MzKnTpZFkJgTmRWif4OvDTe6ekGMHrSIhThML6r4KLQfG2bmyuEuENj6tE/9eYkDl42n7H7TljdbKPsJ3DKBT/VDLFJSbiCpJM4+ov0dA4qbvKMTkgT1FrIN33VBSSXGX5fXRtzAzp/qJVd/SN+YlQKtJmxHw+hIAJPDg4WewWr3eWSfLnKNN+gLrkByMQpHn3yddj6193otj/Ktcwndp0CGbv3wXqg8DGdutvOeLnVEAWUqNd4l3ris9UFElmyAqQktXDLrz1ME7tGdM5wG2RHqpfuNI/OUBxRT08tdR3GASSHtpK/yb6RSvRvXmwMpOtf4NS0p3kvqppdbnyqpmXJKEKL4Bq1OAbypGqlZvp4v8grz4kb4BrHJstYryTDNlPbdIC9fBIUwAWyVDppdNjjYIKn4qs6C0ABYKFSG0TcR+GdtjcpR2fP7AtjnlZG9f/IS1vM+68rYNP6dsLUei6LwLQbPn/Zxrg3C4yd92SkqmB1YfzdHMrIp07z6ZuB4AAbbUkd1RYTB0mND02+40G4997fB1tf3cKb+DF/2REj 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)(376002)(396003)(366004)(39860400002)(136003)(346002)(451199018)(66946007)(41300700001)(38100700002)(2906002)(316002)(38350700002)(66476007)(66556008)(8676002)(4326008)(8936002)(478600001)(5660300002)(7416002)(186003)(52116002)(966005)(6486002)(921005)(36756003)(6666004)(6506007)(1076003)(2616005)(26005)(83380400001)(6512007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kd4uH6ekfn5E9BQlEaLotherFXFxWR+AadcF4ktHL5p70F2PkKBYFy7k/f23nJnsZfZRDdmVbaAII8+yZM//jsdeGN0IaY+hFJ9RzkpCohkElyM5RrbBLeCwQ961MnjyLkZM/hiG13faOZAd89wRWUQDOjtAT1fo8ChQQfCFVM727q7m3vG0wInNZpLKvoVbEcMSHRmcvSYDIxX0iTy10/XMoNgK3si4vIlZz6gpqNXkDKdzC37r16H8VmKkI6e/f4lw7gdYuT+lFubrXod+Mu/lvhHowxv4Xbz+1ioNBilinTIw7x/TV5PmXG5+uTTe/8M2j+5AsOXG2gluLVF6Va7Bjj0brLSGyrv1PozGxCtjqSWgH4KWjJfNAZ99RCy62FIo9erDwxreutsvR3v4L5e/1iW1imF5bW4i8QIWIS64nAJdSp1qz18BTRXa6fv2hmKqn+m+/qpkRrtlsLv8zbBm1qbS9NihORCriWjEFdLeSmxUucCPTTAx6E4HTeRvg94sFjrUdqP3eusMMK2vOjT+JeyvWpyFfudoR9y4Ct65BUMz10FDsSXM6YajOgh+Wgs6B2nbaxttL7gaxStcFjO0gW+YKOBs0fw584kl2dL0l2j1aJfW0kqT1CgWk6t5mv08rUFbka/1zEex8j3rpEmeu21XIaG7vlzVu1gyH30xBWB7LN8U9ivqyDdhEKF8vaXs1oY4cgXv0gUH+RJ+oIvtck/HpV0QDwY1+dUPvdy0xzCgInitsHrID0KTXpbu2ed9FummBWOlNqbrjzUoAgloGmm/tin6DFLiMY569esBAEl4dbjwgPXJGO6f9ZvcJJsQ2jH4iEsVtJOyg22shib25AJjkC8kLGuayH0Kh70X7x4PkKir4ngefAaIg/qm3s4Ucr3TGggnTPiEnDfnPxXAasIfvH3K/CSpe4x9IFkC4qqmv0Q6mn3ckX4AH3hjlpQyGemR60ZMoBa0JZMfd+wWM8zyuvAerrOwvwGLMRctK+UX8gaA2wUXi/hCnJAmkprhWScpbPUCBnkIlAQ5TrWqKiCU7SUiKO3bK3DmQdYtJzzPLFXsFJwM1vOCTnkglcA5yD4Z20O6djCY+0g9faUGPIuWqjFM/4BRiNVvvscPVtKnMm4sWLeMQQMKKH+3nbElzZaOWkQ9ZNT3wOl7of6/2qoDKaBpqWU0W+PvIDKrVErgACF9GmkdoBYLsugigoUKieFau0V2VnnrIW4sSvDSugdIgm+LcrSRjVS5g9a/u3qew2SLTQ5zJRnyUJbjdPbeySiSgoVFAbLWgvbNnZk1H27lzvsJJq7Jt8W+G/stPjBzjtcYBeusUKr2uZBFXAiKZ7N28VJo18+dQT5q4z8arjkoaVFyEU3zEnbD9rLA0g5X344AsCIn7ypNxG1cU2/s1Q+mSu307z7IUJvY3gshuyiip5DVi/qqGUVsgjd+mdV76pXjZcW5z6hAeb2lblfq/7wx47s+8BGicjVgj+ade5pK1AUo9sNXr3Usgihg31QzyBi6uqDyHmNDFC6MyhtBj/5sY5ewjJGRQ0gFFm+xs3S9uUOLdKZ7VK8kc957rU2/xE4hyA5WEk+Uu6ZgwMrE9UDiqKCjLeW4lgahTg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f918d3c2-b8a3-4a07-c7b7-08db254d665e X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2023 12:04:16.5282 (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: eBwt7CgTut5FUJQAaNQjDTBMD68vG+LslFpTlwS2SONT1dtFM+ctRezU42KcdFoh61XfREK2etWOPqGDgNyiPPrv55rXLmBh5XlFhbNOA3U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8629 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 Wed Mar 15 12:03:26 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: 13175748 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 A7B87C7618A for ; Wed, 15 Mar 2023 12:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231896AbjCOMFK (ORCPT ); Wed, 15 Mar 2023 08:05:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbjCOMEv (ORCPT ); Wed, 15 Mar 2023 08:04:51 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2051.outbound.protection.outlook.com [40.107.22.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63FC81C322; Wed, 15 Mar 2023 05:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HqUTYaG1u4MH9VWis28dUoVksfeEhaB2oMbYrBsRtMbihus9W7Q8m88k8zxfmtjD5xFkSYrA+/OUijSKKPvcQppJ80/F3iMrrowDa53EVd6WUaz8gfow19K+JSmOFdhJNHBf7arF5mgjDwNqT/qPr242/cYs0k9DeRkkPhoR2AJhOCCrBCS7tGghH/UYlgbuI0G9U2r+fpp1DSQRo8aUeoiQRB9ZOewrdQD9Wo7nANORGbU2H9aJw3+e+dBBX8Wk9JisZ4vfdZYJjcy+Lifu/senjyFRe3k2qrQqsyGFy7S5AT8cdk8Ed+HGAe79VWxDo7BJYPS2Brb8r9ymeKbqpw== 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=Qbze+b8BQzBbKAV9WUF5oqQ5NMlHzIH+ppXtun9ZvLM=; b=FY1qWf73CTfN041YQuaUqdG3P0oV/FJQ6IMfQ1GEShOdoOft4jST8qEA231zrbzdeaykWuRebMp+78cD0cLPd04/TO8Gp/FZm3y04hMvUZ3ogH0Q3w306Da8jRZ/GHCGKplEV0e3yDDalMU8S9lcJfNpmK70wnvrFCFyTNPhJgYELymUxIPqUZyoCv9+NecZokNnZNLU9zXgwPVAwiKcLXX0MbH3DQu427O/RQ/MwuEwVlmUFZD1TgFlI1N8HKYow5Dqf3J/PZuOJWZ8prw2LwtBGg1IaV8cyiP0kFbqmYpq/+flNIkWfzDUubmyipXGFWxciJoOcXDmoYmNUT6tCQ== 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=Qbze+b8BQzBbKAV9WUF5oqQ5NMlHzIH+ppXtun9ZvLM=; b=I7364GnsUAZ0/orW78jxJXzDnbZM4yr+JFA92lfGl/Fw9xM2GfwzihD+Zzy78yRubUa7qcA0Z3+cR3RXbx08g1N1jIGO8TtV/CXVkaroQ7dbGC10BCsVlcOo82ld95KQ5EHqJvLTXi0Hk3XHhtlBLF+ul2VMd7he8QzinQRW5Fs= 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 AM9PR04MB7524.eurprd04.prod.outlook.com (2603:10a6:20b:286::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.29; Wed, 15 Mar 2023 12:04:22 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::45d2:ce51:a1c4:8762%7]) with mapi id 15.20.6178.029; Wed, 15 Mar 2023 12:04:22 +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 v12 4/4] Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets Date: Wed, 15 Mar 2023 17:33:26 +0530 Message-Id: <20230315120327.958413-5-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> References: <20230315120327.958413-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: SG2PR02CA0096.apcprd02.prod.outlook.com (2603:1096:4:90::36) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|AM9PR04MB7524:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f42b286-210e-4780-0657-08db254d69f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5IZJ4w/ljXui4GIAt0G3bSyiF+3Pcc1pcf28AMeyKu3JTF56L4inVrB9eGiOlP8svkpAR8OhtdHnnh4Of91VVSYI3SCxkMw+sR8/7dpSFHI0uLXlh6JvRY/fMPI+BReV6fc2t72Tl98oVVNQkGTjkTxMHYSpSeJnJJzmonmoeqLtweaU+4f96JUkM255tS6J2foFq4IBU7+SW5IC+AJWSCuV4qrc1jfid4Q5av4Ij1V4QwJupvoxtviyIZTfkxQGbMg+5gFM2nun0bLBpGtVfJ1Qr725+K5h1c1RzR1nWRy4RBseC+jQSwVoANhsTunh8PxoXTHuRpdpikayUMJ91Ngr/hP27wgfQS/kPefEgYon+f5S9TU0blQGKwI4T/yNsNLyXaKKT5YIFJzi5tMOySgiQ7oQlTL9T5aZf+SWGAA/FbJVSlvYNtTVfsVuetCSnW4Pjo+ZmCN8SV6EtzyE8JCCVVkrQ3TiUve9vTfsvIPiN5hw5HwLCDnm8TpeUaglNYoN71eDcS3pH7OYZw0mGjtoV/OYklqQOhgeGOWne2ieABs7bhOQPvBry2eOWLZ+z4tpbJLfaxDuSHbY21oPWLYBTGQePBjs3D6bgx1nG3V5WYCfpNn7lWsdBWU2RST1Zsu7UQssUMcCDD6KvS6BITYArWp8nzaDUskoUY3HXW0Z274eSpfW5/re9pu/1cXQf4WWDTkQTZ98JYbOGexU/A== 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)(376002)(366004)(39860400002)(396003)(346002)(136003)(451199018)(26005)(52116002)(6512007)(66574015)(478600001)(83380400001)(186003)(2616005)(316002)(6486002)(66476007)(66556008)(66946007)(66899018)(1076003)(6506007)(8676002)(4326008)(41300700001)(8936002)(5660300002)(30864003)(7416002)(38350700002)(38100700002)(2906002)(921005)(36756003)(86362001)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?WQ9K5ZYJR7ka6EpKuoAnrpxAwbF6?= =?utf-8?q?ud/FOLL0902zathfDq0O0ZZrknPBhkNc7Q8Uocq0ap2VVmRUDkcAacBNrWlYVOT78?= =?utf-8?q?1x+wWKfsI6gqj2K9MNncKeOKQJDGZqZWFCYqsdnmXhwMEUgyxcwZiQLzxsicVEFxq?= =?utf-8?q?Hn03W5kabM/u59KhqAPpeOSTij4dIzERaDmPdykIdsPMruY9xQ7ct5/RwxMVM1l1L?= =?utf-8?q?Trwe6f2UG9Dl58H7N3byTPSsqgEpWwm9nUyNQC9VRFbFvQAb30/NThKxsPZZmhspS?= =?utf-8?q?jXpxK8kj8uKwsilv38dThzOmMZR3s39vodOaxtiFLkwJVIS5c3qCCeVZ+2Ax+mDmK?= =?utf-8?q?GSohoCoN+Z2daoIlnPGtR56jxJ01dYQpwWcl+GJj/F3mi2SUoMLPXKnM7XTBExTU0?= =?utf-8?q?SBKgy74sdzc77pV2zuVR/Po1hP/+HjS2Tcywk+6DKA//Lvmpmw86NOvIQWpN14hm0?= =?utf-8?q?mIpND1Q5SVhBtu2IwjMefJK4FL/a2sFdsrQyJ7KQ8WNcHYSbiWw4bikqsBVvvTBCV?= =?utf-8?q?v3O91sGfmOXvw7BfrZO2WsNfN0vHJI4gatyR0J9D0L/sFomvkNHgdjPgMpY/QaOKo?= =?utf-8?q?ePxXxpsfeDT5hmHr+YXhI6JSAJeFSAIyA2xQouHG2AZ0htY7pzlPreEFS1wI9Xezd?= =?utf-8?q?nOuL8o1tMmVCXf7ryenAyW3eIOWga7o0xwjyU3TwevfjaqS71LaLETh8+rm4jICwi?= =?utf-8?q?Bp78PMrnGT/MpqlL965JSM3+BO8fxU/YrfBnBK7z2b6OnqU0G4KFoAlY41+H4Nxha?= =?utf-8?q?t7jbHfWWpYquj+vVs35x/aCDHRl1JzrpXxPlcfIBkvzTJq6KMFk3CHpjC+m0K7KER?= =?utf-8?q?4DrDpFY5+Usl8kTWmv0uprTMg4zzoxoazYGZAnelami5pk5mr777x7T8Wvd3DorZF?= =?utf-8?q?ynHW0FUW6n9sR7VbKJ5UzbBpWiDHVk7u8xnwUw4Au8XnpZOBln7/h27j6A7p21maP?= =?utf-8?q?Ei+isAOECHum9mVmJqfsH1yoo7a6oA0uYSOmQnAU6zXA7SkKah2jWjwFaC7eHoKZh?= =?utf-8?q?r3s36D07g8nzijh+r82mfqLvPMWa/wkmnhO8fbm96cOUZ9RWdsl1wmhBroURj2USc?= =?utf-8?q?RsptbQ3V+GabFOmmTzYUaufI4xO/klXJHt9r/SxH99q6HR5QhHZLXobw2O6FKlbxy?= =?utf-8?q?0GXkR6DGNO/0SzFCTWIzOGYv16R4hk6m5mtJ0q/aDp1A+R+rTGRcRxvioMQNZFC16?= =?utf-8?q?NKuvthcO45C1mnDj4nTQkTaqCA9szqakX9pZfpxnO6AeCBtMszdjBT6UkVuzb2w2K?= =?utf-8?q?bbVB0ZJWG/oS9CeNHYbQqwVU+t7PnZgl9ONO/4vubAFC70Ln8FNToVmamjvuWfeIT?= =?utf-8?q?6J8djZZIFn0Is2UxuZ+HzbKG4TuuA/4xWJ63pWym/j1gVnv7HU2a74dnAmCXdsqRD?= =?utf-8?q?RNMGcb3zr88ubpiFPzMtbYkyw4K6hl1cnon6Kq/0g9+DxOzEp4l/x9jkBT7AMPQ+O?= =?utf-8?q?KMt3oE5Amswv2e15mp1k8r9IFcVNosC497goEHxsdI8Tw1eaKrhRxCOmo46rK3+s0?= =?utf-8?q?itXfuDyPlFdjK7a6e88WmQFW73jpQP3N/Q=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f42b286-210e-4780-0657-08db254d69f9 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2023 12:04:22.7287 (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: EnnwXKnsRAKywxg0bwa3BVfqjyaSEHahvf8LT4vuHM1hfk7lRHXEOptxFk+YPpejiADMT0ULoP0bC4egILkkBvQvaF3pRuNa0+hoYXgAbP4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7524 Precedence: bulk List-ID: X-Mailing-List: netdev@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) --- MAINTAINERS | 1 + drivers/bluetooth/Kconfig | 12 + drivers/bluetooth/Makefile | 1 + drivers/bluetooth/btnxpuart.c | 1289 +++++++++++++++++++++++++++++++++ 4 files changed, 1303 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..1483481f7cb0 --- /dev/null +++ b/drivers/bluetooth/btnxpuart.c @@ -0,0 +1,1289 @@ +// 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; + __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; + 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 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 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_dnld_use_high_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 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 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) { + if (*status == 0) { + 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; + 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; + + 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_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"); +MODULE_LICENSE("GPL");