From patchwork Mon Feb 13 14:54:30 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: 13138534 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 F4181C64ED6 for ; Mon, 13 Feb 2023 14:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229704AbjBMOzl (ORCPT ); Mon, 13 Feb 2023 09:55:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230505AbjBMOzd (ORCPT ); Mon, 13 Feb 2023 09:55:33 -0500 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2061.outbound.protection.outlook.com [40.107.6.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBA8B1C7F4; Mon, 13 Feb 2023 06:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=agIah7F/f3Y1Bce+pIp+XxTGSCVMV5gCyqvcARSnATeUUaqfn+Z8FWte+8yhmSu37R7GoJD4EFQBs107npvYqef07kVFx6SvDqHNwwDlSVsWS7pyGFzM8rMbXrmd/FAelJU4NivqcNicNTqSXW20GkvUFmjGEyMdA5vS6OhSWKcz1BPrYw7RVgPTzewAPcwFwzFzhiEIoghM8h4bvMcD89ClFL1Fp4mDH0ZSeRZaxX72cQlT/zLGyVlUVgfhd6Yd3DNDSvLth8GBVUvjI1xmepFC/P7jjb81yKrEFJz9LX6omffVckuWWIEX6Lv+vclY4reVm0pEkZaGT0HJFmGobg== 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=Ta+Ww9o9HktQNwZkbqs6z4pt+Ol2zIBUeLuWY1Huc24=; b=CCR75ae1BXwlJVgFNsmIM8I7qTJWKwzVOpykU60hViYmZFTqPbxMoSZ2ujqc0pL6IyRAVVWwOReUVrSD/63jMidN4m2SOlQke/ZBKJkqO8oiz5FAMO1pn2gcWWmn58B8qj/TzbTa/iF1y5iW+jqVVarbgoI6vmLCSgux+pQ4D53NZ+Y2NZlfPuetKWuIqfqMp15IJIhYXu0ctCD+4TlQHhcQLfJdoYtip9fCJQr3XOAYi9j5mFUES7qqDDFvPKjS8vTlohC0CN5ey1AeHoy364JrYeTTIteNfo29jTGPCxvsSH1tOQ6QJeypvTHr9DiYJC6lT2qesone1A6L6aF9pw== 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=Ta+Ww9o9HktQNwZkbqs6z4pt+Ol2zIBUeLuWY1Huc24=; b=LqV+HBReV+9g3WUR0Ox2KGvyvaufEUuPg3YBQfYhOK/7nmHxmr4/wdY5P5db58uxKHOOzOwGjz34r70Lt0FfLZQRd4FFHw9w99rToSR3c7ggHAR5+cRU345PL4vx0Ac0ZggOpJVAGKm0qS/gXSiU6CHa2Nf25Cy1YYxxgnfUxFY= 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 AM9PR04MB7523.eurprd04.prod.outlook.com (2603:10a6:20b:2d6::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.24; Mon, 13 Feb 2023 14:55:24 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::f8fe:ab7c:ef5d:9189]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::f8fe:ab7c:ef5d:9189%9]) with mapi id 15.20.6086.024; Mon, 13 Feb 2023 14:55:24 +0000 From: Neeraj Sanjay Kale To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, alok.a.tiwari@oracle.com, hdanton@sina.com, ilpo.jarvinen@linux.intel.com, leon@kernel.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org, amitkumar.karwar@nxp.com, rohit.fule@nxp.com, sherry.sun@nxp.com, neeraj.sanjaykale@nxp.com Subject: [PATCH v3 1/3] serdev: Add method to assert break signal over tty UART port Date: Mon, 13 Feb 2023 20:24:30 +0530 Message-Id: <20230213145432.1192911-2-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213145432.1192911-1-neeraj.sanjaykale@nxp.com> References: <20230213145432.1192911-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: AM3PR05CA0156.eurprd05.prod.outlook.com (2603:10a6:207:3::34) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|AM9PR04MB7523:EE_ X-MS-Office365-Filtering-Correlation-Id: 35c3e598-986e-4fe9-e625-08db0dd25610 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PeEFY0qlhz9MpIHcdNYCdEgxSGC92GrvhHAsdqL8dPI2TDAC9cb0b+bc2wROJ1WGca0wHsISc+XQJ4V+ddr/FexBRKn3afN7kToxuoCcKvn5eK5YkWvAddnPrxb8nbsVVzI/6EnATXqZzzPGvr5qA/gSwgfizf9kwIDs4zi2x+tShNVqCBvEOKeUG8I6XX3scx/rpANFFhxJMOQWozB+RmVWIczSbnKNrGtYIRgquKszf0iLT85Ct4PtczYKqHzE07acQWWQTxz6Vxa17orV6OYG3PjxP8JSyckdf6AoA3LqWGE+uMjCTCGCTrBPBe383YFOMxUpC5vASafP0P0NAE0l1X9vPYm7dVEQMvtHl3pOrhrMmMcDHpecE6aaQBc2ceRZ8Laj9rBpmf2HDqbaxrjeoRL63QHQnS+2uqwCr8AEwSb6p4OmcAyPOd7AS6jQGC5LNbLtAZs4olKSy47Hgk+ZC46eSJyDOqEKpCVjhYXMgUDo+ySPsw0rFtdm8zPZ9uhK0XgxdzwFCG6uj0pIZdje6U1NxTJSEVC71sjV/pN7GVfULB017rH9LWwgvVzZJTMlPprjL9dcBTMMxh0GfBLKeRwOq0fWH4uld88/+WYiqLhu0VgZqWGoaDvLeD2F1pqbfE9lf0S5nkx5Apl62O7/bFnVziJWPW6Upup3v2DGRylO/WW69RF5qqaWDE2YFC4vaNAw9CWsDGCpjotUKieWubgbxJZCdTka394ptf8= 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)(136003)(39860400002)(346002)(366004)(376002)(396003)(451199018)(478600001)(2616005)(6666004)(6486002)(52116002)(1076003)(6506007)(186003)(316002)(6512007)(26005)(66556008)(66946007)(83380400001)(66476007)(4326008)(8676002)(41300700001)(7416002)(5660300002)(921005)(8936002)(36756003)(2906002)(38350700002)(38100700002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SfjVkUIfkJ3o3jLGTrmf2fDyMQG0z9xHd80HNeZhCeTHbw1Vj/4L1y9MmG8yEQhyLKtqPI/QHnryNw91jxnMsOyQbIVzieX7HbZpM425bUSAJj9z149+6bMnLpZRSsdel8fx6pVv3lpXAJCMJrt/3E4p/sP7oF+L1bOEpDiNsHxnw5Pgc4c6uTNh0sP+j+SkHVffveKXaqdVzhLU5MWTwO9dIZYbH50MznZp+vUPqHs/fPjIkTHukqcWUTqQBLBg2tkcUK19+vHtSzZiSiR6X52p2+cq0Qb4ZHEB1k59KiY8l886ZjGPqYD+LWiIS8m3/t4+7eaZ6aLuuwAbzFgX+KTH/qziC2NflKbylBJ5utdcOrfAGAf9tB8BLikybK5PAkCKaxR4ppyKkWMRNvBGWHEoorfDFJapPHgqVAL1NBbCj06zwry/VF5q/UWg4M+gQw5NzXWXt2Dd8Q8/GkuH9pnpi9WQL5E0AZ68RVRECw6zFkli+EKLFh8hPSxMpkR9PiMUVg4RLyMSJBq3iXR5Jm2iFVene1syTO9mUbv0XaB1yE5pdb7qbLLx7GxkjxgSmtqgW+KCGNEfuAhVkQ8Dj90Smw4P+jHORhRRM+mMMiGhTZsDGL/xh6QUAiy3h4gOIhddBr//Jb60cqjC1K92s9DhQ0P19bQN5BjJrUtuZz7bE/z7RzAcXsq4Q/cEpPiOGqWHOGF87R3KYcCJsmRJIVKy2x7On97Pvd7N0rEcHAgDNQ/vPGN7/7YpIPEoQSfN57QmVChf9ntQpuFQ/VaYoeuOtE16YN7Rs0rwUloVBoZSXcW3VVn2PbYL0FWNfunvnGYu4a+EbrYb0CsNpnc1t+FbWlBIb+89RSLpr/2lpnhaHzIUwFggwKAUBQx0UBg5XduvNxqQguTwIhjw2pnSkD8kNg6V8rlXMdf7pUV1Fv4yKDip69KLE6LSq/UogBWxBdz4I5p76vO4eJ2el6J2yZ2VcqvzvXkHc0iCLKrENKL8LCWEDkmPhrDGqROXDEp9ulwKF+EhhYFq57RiYNB6RCf454Fb1eTEziSKMi1I6zx8xzux4md3Yxtd7M78CYbKfIGfH+98fcZw/pwjNmhU6OzfAJVXE/Zw77WifKeHQEqs6CruN7KaTk4tLSmCiJPkG1Q8pKvycxk3zLjNKtWEkTTy4nq9IhP+rcjGMY5ZQTKn0/N8jr5F/S9sIoAz6kCZSvGI77NjQh57HPlKR4E0bucD2md1a6wyDIJJ0P9IVmCRX43a2CAa5PeaBw3MrY/Cyfo2pspmhpA4eAD19kTI0JubN4tQrIg3MUqF015kJ4iOz/k8rP4ywrur6ka8uAakV9hvJIVXHygd3STo6MaojADusvFhoCxzknLDZyaOQ6vEMpXF+eysIJFlNaJyVE8ER6DFYqwUlhvtd83PGwxqt2HEpgHmQHpIRS5eXT1kJWKq0f8BeqIXq64eivlTqpdSNlyCvj3P6RY74B3BbnRwgGGZhNp50kqZPCqX3SGHvAYUtcVbuB54ir+WifWzyqDElZOVKY7n5/JGiSE3w9RNxfqq0frJkdzEF1SZHPXWmR8fQMJCnLD1AIco53ms8EIapQaqEFnnlB5J7Ag+C1MTqg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35c3e598-986e-4fe9-e625-08db0dd25610 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2023 14:55:24.3654 (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: tV6R+r95Alpj//Sqn04guwDQ3OMG/YS9urmkBe1n8aaZO7+TrURy9p7g/KQ2zwjdbNQi5qZtDVVpzZNpl/keOuJHLA1UMinKhVgzWc9cw+8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7523 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 --- v3: Add details to the commit message (Greg KH) --- drivers/tty/serdev/core.c | 11 +++++++++++ drivers/tty/serdev/serdev-ttyport.c | 12 ++++++++++++ include/linux/serdev.h | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 0180e1e4e75d..f2fdd6264e5d 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -405,6 +405,17 @@ int serdev_device_set_tiocm(struct serdev_device *serdev, int set, int clear) } EXPORT_SYMBOL_GPL(serdev_device_set_tiocm); +int serdev_device_break_ctl(struct serdev_device *serdev, int break_state) +{ + struct serdev_controller *ctrl = serdev->ctrl; + + if (!ctrl || !ctrl->ops->break_ctl) + return -EOPNOTSUPP; + + return ctrl->ops->break_ctl(ctrl, break_state); +} +EXPORT_SYMBOL_GPL(serdev_device_break_ctl); + static int serdev_drv_probe(struct device *dev) { const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index d367803e2044..9888673744af 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -247,6 +247,17 @@ static int ttyport_set_tiocm(struct serdev_controller *ctrl, unsigned int set, u return tty->ops->tiocmset(tty, set, clear); } +static int ttyport_break_ctl(struct serdev_controller *ctrl, unsigned int break_state) +{ + struct serport *serport = serdev_controller_get_drvdata(ctrl); + struct tty_struct *tty = serport->tty; + + if (!tty->ops->break_ctl) + return -EOPNOTSUPP; + + return tty->ops->break_ctl(tty, break_state); +} + static const struct serdev_controller_ops ctrl_ops = { .write_buf = ttyport_write_buf, .write_flush = ttyport_write_flush, @@ -259,6 +270,7 @@ static const struct serdev_controller_ops ctrl_ops = { .wait_until_sent = ttyport_wait_until_sent, .get_tiocm = ttyport_get_tiocm, .set_tiocm = ttyport_set_tiocm, + .break_ctl = ttyport_break_ctl, }; struct device *serdev_tty_port_register(struct tty_port *port, diff --git a/include/linux/serdev.h b/include/linux/serdev.h index 66f624fc618c..c065ef1c82f1 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -92,6 +92,7 @@ struct serdev_controller_ops { void (*wait_until_sent)(struct serdev_controller *, long); int (*get_tiocm)(struct serdev_controller *); int (*set_tiocm)(struct serdev_controller *, unsigned int, unsigned int); + int (*break_ctl)(struct serdev_controller *ctrl, unsigned int break_state); }; /** @@ -202,6 +203,7 @@ int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_ void serdev_device_wait_until_sent(struct serdev_device *, long); int serdev_device_get_tiocm(struct serdev_device *); int serdev_device_set_tiocm(struct serdev_device *, int, int); +int serdev_device_break_ctl(struct serdev_device *serdev, int break_state); void serdev_device_write_wakeup(struct serdev_device *); int serdev_device_write(struct serdev_device *, const unsigned char *, size_t, long); void serdev_device_write_flush(struct serdev_device *); @@ -255,6 +257,10 @@ static inline int serdev_device_set_tiocm(struct serdev_device *serdev, int set, { return -ENOTSUPP; } +static inline int serdev_device_break_ctl(struct serdev_device *serdev, int break_state) +{ + return -EOPNOTSUPP; +} static inline int serdev_device_write(struct serdev_device *sdev, const unsigned char *buf, size_t count, unsigned long timeout) { From patchwork Mon Feb 13 14:54:31 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: 13138535 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 6566AC6379F for ; Mon, 13 Feb 2023 14:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbjBMO4A (ORCPT ); Mon, 13 Feb 2023 09:56:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230223AbjBMOzq (ORCPT ); Mon, 13 Feb 2023 09:55:46 -0500 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2084.outbound.protection.outlook.com [40.107.6.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 355971C7F8; Mon, 13 Feb 2023 06:55:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VFjA+hSHEjKtfC37KT+dRZi0EYpN4yxAb9gD2ojc/FJbUgmXmExiu4WuD0RQJhCHZcDUupfhFialWjU1ZHaZ6bm7iB/Tm8FZ8AkuP0cEkGIk9yE26/6rpqH/WGqdvrVxdcBgNBU6loO7lV51sj6/stYsmDGQjpMjNweEpxol7m5co+HJPGTctnHiV6WiQska7fFOtYnh9FqEQL+XxwVvjx80vLU8Ke/LFsv8mwTvsYZwEiTLGHewv/r9YBrTuYqG8siX+J/t6W8dhzoxrHF1FDQKooXSvnLVvAwCKo/D/MMMXodBy/VJ4pBZ3xX4TEf4edvNT1E6N7YrThlELiaDDg== 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=tDpQIOargL0QzxHgFfcOPc6+EncnHFtwaAkcgBoyf0s=; b=kfkITJiZqY9M7TFBI/sFcFm798nQWh7XRVRJYCWzJUG+LPXYJ6XovXCRpGlDDkqoLz6O1htAptT0f+tDU81F6jDlAxVa4zkp5+oHa9ltBrplSmgdwEPHl0SkcdNpmsMVuR/sR+Nwj6Qu5WIaiu6f7wdzpJCm1rSJrg+Tikh24RxlxcfBUI4grnpDHHyrKEv+vTqZmTaSQwZ/tA2i10SXnzEj7sdw8/LYktnWNKHn5XAO7IeLuFlD6aHNQ6df+JeSgItufrcazkJ+LmWTUmQXw2C08SBo3WS46kj4qL+5R1+Lfky75mIhoqBZPBNgaPR7yCa8SGiKybwhV6Bzaw47PQ== 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=tDpQIOargL0QzxHgFfcOPc6+EncnHFtwaAkcgBoyf0s=; b=VNceYiqZUAC80a7ZTWiIZlRu1er2tKIYrTazBuFQp8Bnvtsdg1IMNbaekkwZ+C3M6WhwZ1A3w/V/j2dm2/T1RYXiL4YDTq3m/uTU9TJYp4rUmXpu4+WWII68rOx8xe5OnWGMl+J9H7NApexGQCTSsgVAPqFjLSy4fDON+15fn68= 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 PA4PR04MB9390.eurprd04.prod.outlook.com (2603:10a6:102:2a9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.22; Mon, 13 Feb 2023 14:55:33 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::f8fe:ab7c:ef5d:9189]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::f8fe:ab7c:ef5d:9189%9]) with mapi id 15.20.6086.024; Mon, 13 Feb 2023 14:55:33 +0000 From: Neeraj Sanjay Kale To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, alok.a.tiwari@oracle.com, hdanton@sina.com, ilpo.jarvinen@linux.intel.com, leon@kernel.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org, amitkumar.karwar@nxp.com, rohit.fule@nxp.com, sherry.sun@nxp.com, neeraj.sanjaykale@nxp.com Subject: [PATCH v3 2/3] dt-bindings: net: bluetooth: Add NXP bluetooth support Date: Mon, 13 Feb 2023 20:24:31 +0530 Message-Id: <20230213145432.1192911-3-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213145432.1192911-1-neeraj.sanjaykale@nxp.com> References: <20230213145432.1192911-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: AM3PR05CA0156.eurprd05.prod.outlook.com (2603:10a6:207:3::34) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|PA4PR04MB9390:EE_ X-MS-Office365-Filtering-Correlation-Id: c334d28d-09c3-4c6b-dd63-08db0dd25b70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 15lpyjreGgx0f63XyLNNmYCOVBKdbtxQCqsxNant5R3K0du3b+inAP0sPXyxtfsZZGSWRcfxiM2X7qz+c3meB5KwRQlRBdIU0Q0S8HdxHjX4cMiq92unxl5O95iIw3kJzo0s59WPQ7/M12N53qVbdQtR2uz3C+WQY2Q0g1bDSR41iBo5mnrdC3Q7fDXsoL0nnh2vYJNfbsLCic3w86H1QLeXN54TeU73NjkNerOcZymKotmLgchcItsrk3Z6OHW505mAe8oPFTKhYXKHOgMWe0IHoDhqL7+GZ4e7fz4VhEC6cEMWZqybJDhF9j+ySIgwOtTn8wFAmDt1vYDvrxSflnAzx9x1lL13vnYkrGtpA4nBU4QMPttsr3aeFEAt/z/RQ1QTFiNKDTNbqOANGNJo1l0JzF4lYGZXzNWVEWb3Dtba/Qdi+BjlfjrV+VtOdOmAOafYm6WpwPrv2eqoclvkwDPUda8Wi49JhOf0mXInOcL3obF6jZMD1jXVIyHoymJIMRXj5pF5479OU3J+W3KZh/o+nEAMANkPFBbk/O11QB5oIATNHqaJ9c5Alfv7RwGDYf9NRcYBUNXIjAjwnh+OuF6XJIH7UJuHaAZjoSzLzFFAeCe0d2/V1LsAnV6SujOuEMy3HDkWCUcf+pCde56rqvB5rTjrNAgZGn34XR/2mldY5cPmIH1Ro30j2uECMnsI0AJXAsQKE6fwL34DXKJtLuQsT9JTzYE6xJzvMPld595mAniSFtAsdwKqVaaBIw0zlKnTKLWT/LDI753BGdTtA4ow3g3z/T1D5ig9Ml/2UY0= 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)(39860400002)(376002)(396003)(366004)(346002)(136003)(451199018)(26005)(186003)(921005)(6506007)(6512007)(1076003)(86362001)(478600001)(5660300002)(38350700002)(38100700002)(2906002)(2616005)(6486002)(966005)(36756003)(52116002)(7416002)(8936002)(66556008)(66946007)(83380400001)(4326008)(8676002)(41300700001)(316002)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Xdly/qmmUA87pg0MgLF9BwimhQ3Ej4Y+tZfCu0dsY5dSaQ+FMVt+owNnKxKZAvUcQvvKQgyuOrnAQadW+LLZnbCn132qS/9UdM1pHEeQQptA8f9OvZbLW8O6nrN07h8ACY/69dbnawd4cjV/w5AEF4K2+pXXO6CascMa+zsHrH/GQA6vIREzdmSwkQcybc/mewdAWxM+XWMPMmNwZTdbAIC9dfnp6V/rWylhWz+cPYAKSCrdx69edNT8MKFo1wWuD8CexEBePEg5je0yiEo62ZrhoTtsZFEJEL6EwcrgBb2ffSH15IaZJ/i4DVcr12kSvGWOGlj4Yu5u514XR4h/bOhCmHC86YraWEC+ftdZv1KGJJt9Yqnq6kQ9hmWHUYLgxMpBWCLG9bs8zIsRLJBcroJ8Nwvuu5ug4N5k5910FeL2o4za0JlieTJHFfyqU4E4h/yih5goOA0xZtzOApbkwbLDYcDeMIjRCCmkWMm+luwFwEhC4hPlf8zQrytJyWomOp/s3Nj3Md4MEmkQFrAebohEujLZORT9elx9wpG7AhrbqobY+Bmy+QzAeQFXbOXoQtMggm9RHX/eTKIK0lBnFrrRPlARvdUeJkNi+JvOHN5sieNrAuNmNx1SFUKgEXxlU091KRs2ajjVR+H3R7yVjOAOqhZyhzfiCZ5QAOzILo12eLjndWuli2BCj0vMyZshzr5pKoKToK1SK8aFjSIVMf368C1gLjHhVuVt5bHVjaZ7M8lYQPj797FjVwKgS5959jcy35RkSLL6GtCrB4p5bKVh5I6xeasNOFBNj6U4uq2aW7aAqYkihyzWsQ6m8VG+hLJSW5pd+ZHukUQKXeAl5NI9HlUFX0IHIm/nlakBfZLvn7xvMvcap/6BWAG5sIt902/dvw3mYEnygws858ZKDoijSEQFxMBKVTGEHwUPixwH81acaKS9A2pITQFW0GjHHEw0CbiQgKOZY8IQDQVkx/cwinZEwPS29AxehEw921OU/hfQZ+fQGuwQMeBwP71nO63t/W3MOhGPWdW1irpPVWoYFwc7+rcYif7Wp09OHdB6fyY+ISq9aXGS1M0F2sKEVYeoAwyZD2vMVBd/CnP5ni+NIxEu/96Gc4veeVlEPOaYLBLOeUhsT5VOn/Kc19ZjFMAOVVYWnsSGA2v/2brsBaYyd+LLH+i2ny+Feym9+Rt6jiJOBvAie5Ve2hRbWAhMcYt6H6XtxYVBLFvoUST3ZqAj/OSs+f6QieBzKqkerusk9VB9xzQ3RHUcFM9KAhrnZzkNLESPBytZtoDo2JUkd159dLCx5Mr60TwaaE0htyDku6e7KdpsoSs5m5ZauZI4+bYofhMs9ush/6pWKdDk0ljnLRmVVEX+MFly/V0PiOq/lGWzWtlJioRYAVCTvSOjqHPxuqAoaHtAnSR3AWFEgBY7apSFFBdRCqaF4RnD8ROWJFZ63JxFj/naUYZwlMRpoo4Ja5OCMFKPS2niHUawv3pzJwMtasaH47vYpRkl8VOrJ4lZlyqluyUzB7EUul3on6fcVRgTsevfFpdwMLTrFhI37Owo2Ce12ildKStjBlNOM2d0vraZMf/IghZvJPZh1XZdsW/L2wWL+ZrvV59BFA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c334d28d-09c3-4c6b-dd63-08db0dd25b70 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2023 14:55:33.3817 (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: hGzlIMbS4Z4tPsEoDu6gV6qbj/6R1alwhs4bvrslWuGEm1lE+mQMzVFfTDHlskqFr3c2XJL/8H/kM+5flWZRzYZpQRg9u6h1E8ppNTLGonA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9390 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 --- 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) --- .../bindings/net/bluetooth/nxp,w8xxx-bt.yaml | 44 +++++++++++++++++++ MAINTAINERS | 7 +++ 2 files changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/bluetooth/nxp,w8xxx-bt.yaml diff --git a/Documentation/devicetree/bindings/net/bluetooth/nxp,w8xxx-bt.yaml b/Documentation/devicetree/bindings/net/bluetooth/nxp,w8xxx-bt.yaml new file mode 100644 index 000000000000..2685f6d5904f --- /dev/null +++ b/Documentation/devicetree/bindings/net/bluetooth/nxp,w8xxx-bt.yaml @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/bluetooth/nxp-bluetooth.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, + except for iw612, which is a tri-radio chip supporting 15.4 + as well. + 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 + - nxp,88w9098-bt + - nxp,iw416-bt + - nxp,iw612-bt + +required: + - compatible + +additionalProperties: false + +examples: + - | + uart2 { + uart-has-rtscts; + bluetooth { + compatible = "nxp,iw416-bt"; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 32dd41574930..211fc667c0ec 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22835,6 +22835,13 @@ 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-bluetooth.yaml +F: drivers/bluetooth/btnxpuart* + THE REST M: Linus Torvalds L: linux-kernel@vger.kernel.org From patchwork Mon Feb 13 14:54:32 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: 13138536 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 6CC1EC64ED6 for ; Mon, 13 Feb 2023 14:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231153AbjBMO4S (ORCPT ); Mon, 13 Feb 2023 09:56:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbjBMO4C (ORCPT ); Mon, 13 Feb 2023 09:56:02 -0500 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2060.outbound.protection.outlook.com [40.107.6.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8461D1CF66; Mon, 13 Feb 2023 06:55:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OL08CRkzFRNg1agbx7GjgfIFygAbeR4x7bcrpLLniacXnzpECawnQP6xUoxa1dFUgOUze43gVVIyPwxY06tWSRlM4jFyidqJr/5PSL0aZ7yvObqwodVLaXk+oZ+Q5lk/C+DaWwIRKUcqTbxZFO4yfgkC57pTmxOwTQ9yT+tSCS0UUZKnT13CxdkCXAcycP2n0C4S//DXKyspZzcqSKMcSIdmJoTRHWQvCOcinBPM/XO+ARh1zQSqBCLM4KnfFsGhg/h9f+xlJWExj7Y+xWxxcB+iH3ap31KoNy2XssWaFOVER4YwneSfyrd9pCShiF470S6K9P95+MsUtXNTkREkAg== 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=Lk3wLCITnbAvYqEJ9bfQrMzUMUjZWOSqGf2I443/7gY=; b=dHrBXTKjkYgd78wJN3hr/9uXIs62M0azJUUsHiywghfJ+x9uefCBdyZijwKvoZxTmEHxis3X1SlRwP7qij1wOPiqvCadS22WZTO8puKhISCbnhddyxO2BwVYhen5ZpzGkbLnb4axVYH7k5Kn9GEnLBCDVjOqyBymiohCprz/i8qxNWF6qxBaE+X4XZ/pm4CFLLK21GfHXNHPZHnxnw4TGgkQUjyJefBbTV8ct0Fv7uMw8jLCmDNohT5lCF6d0K2HQAI/DJ1NCmBUVzbJ1SR82cbbrZXpJR8CxyiZlnzfsvqBX4cM3fnS9T2asPgpVs6FQwbijZsBw2KdnBNZxLNmNw== 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=Lk3wLCITnbAvYqEJ9bfQrMzUMUjZWOSqGf2I443/7gY=; b=HC/eZ34Op7C5oELlKYNy9TABs46qJFBSr8ACvNSHarEkaf5tf0lKO7CEhxzU6AqYIR2b5wKV5ewX6vOamnN48O3cXLTAdCZG/drsP4BwjvwtALOXueJOWgTnwd3jsVns7oiO/l63z3kqYiERCcZgpz5ntfulVGO0FQHOEowHyDA= 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 AS8PR04MB7591.eurprd04.prod.outlook.com (2603:10a6:20b:297::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.24; Mon, 13 Feb 2023 14:55:42 +0000 Received: from AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::f8fe:ab7c:ef5d:9189]) by AM9PR04MB8603.eurprd04.prod.outlook.com ([fe80::f8fe:ab7c:ef5d:9189%9]) with mapi id 15.20.6086.024; Mon, 13 Feb 2023 14:55:42 +0000 From: Neeraj Sanjay Kale To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, alok.a.tiwari@oracle.com, hdanton@sina.com, ilpo.jarvinen@linux.intel.com, leon@kernel.org Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org, amitkumar.karwar@nxp.com, rohit.fule@nxp.com, sherry.sun@nxp.com, neeraj.sanjaykale@nxp.com Subject: [PATCH v3 3/3] Bluetooth: NXP: Add protocol support for NXP Bluetooth chipsets Date: Mon, 13 Feb 2023 20:24:32 +0530 Message-Id: <20230213145432.1192911-4-neeraj.sanjaykale@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230213145432.1192911-1-neeraj.sanjaykale@nxp.com> References: <20230213145432.1192911-1-neeraj.sanjaykale@nxp.com> X-ClientProxiedBy: AM3PR05CA0156.eurprd05.prod.outlook.com (2603:10a6:207:3::34) To AM9PR04MB8603.eurprd04.prod.outlook.com (2603:10a6:20b:43a::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8603:EE_|AS8PR04MB7591:EE_ X-MS-Office365-Filtering-Correlation-Id: 96e4c3ed-35ca-4180-2c55-08db0dd26082 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fdva/kkxeYn0fjvt7xKuzRREwBMAE/UjPSEz6Zd2yJAFxp++TKSrXbXnb0YLeAMPzsDgt/h2Acu32vMxGbBbLZEOJxsM7iciotXXd2G9RJ60SuclCrHYYIu7UT8uIrtgQffQUqO+sgNRRg8hgM20mGCI1IoPWbn/BMMEe/0VHeWP3Usl1A2SPTDaWV4BD+x+8rFxs8ySFCLmDXyoTkj8n1a5WdNup1ZScMr/Be9XG9Rv++Q+uxhLhorjh53brJMQfpDQHaounZWusa5Jj/FCb1ow7Z5Yzjpoaor84ua5s9duCvzWq8gT4zxsuA6JtI1Uyl5UKW9S99ED5XHanAbPJRasZOrXZNzh14gnvcSeE9gwfyd4EydTqCS7pV5Pf0YPggyduTHTaAbk/i6J1a+PkhgNvm5P/rYfw6XmRH0FVwZDHYbXKxl/6/1KmbP+FrGqC1LhV22bJhxFerfmjuwIx4V0dMHbwTO8TdRM7xM1p9dRhVWmfeen7ma/OPkU+v2Iqp1ZjNHDzwGMNUgJHk07YdEVg0/FZTDKAQU9M0ZKmhDoyoFmSy0wW1JJ+gSVbAkezOxisSGxE95Skpc2fY9FNlfL2iGWyykPU5OlpdIJ4WuhS14D+yxi1KS3/i6d8amJX22PZr6sDJ4rxrl+RD0dtO7EhbWZvMyss5PpLYOcBYnNovO3eR1SIGu3i/mRrgX1vSf26dbgvCx1Qu3bvhZakQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8603.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(346002)(396003)(376002)(366004)(39860400002)(136003)(451199018)(41300700001)(83380400001)(66476007)(4326008)(66556008)(66946007)(8676002)(38100700002)(38350700002)(2906002)(86362001)(921005)(36756003)(5660300002)(7416002)(8936002)(6666004)(2616005)(30864003)(478600001)(66899018)(6486002)(52116002)(6512007)(186003)(26005)(316002)(6506007)(66574015)(1076003)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?wAAZnWq5JCQZLjzK1NImAMAWIPCW?= =?utf-8?q?0SZ3Fqfr9/+uUGsP7rXt4EUIynZNZYECB9h484Ho76W77mYI55G6aVIIeWUxjeKuh?= =?utf-8?q?3wDQnmzHs1tePLz23Cf+l1lE817pWvVwQCM1j3IZ/GhBdqYsgDvmt/nuwfVmlB/GM?= =?utf-8?q?UnsiZV6VU+MKiY/Rq57pdSn42TkTIcC9zIkakaZKGuCVSNBB0sN8+gS47/rg7Lc2F?= =?utf-8?q?IWaucbydlsmoLXaqKwUyNFLDLWMDgb0B3I+CGuutC7VfkMYogAFgjzwNeXI85se4Q?= =?utf-8?q?cbMNJ830EjWBlSz5Pys6oH9UFlEeFfX2X/+XTOHy+sDwUw9tDHXHQYo9ucGUgGFtC?= =?utf-8?q?QiBjU94cpKU8rvDAqU/FPu0ibPQRB3X/j635EYGXdu1QQh72E/V6CxMRWR4qWxFvE?= =?utf-8?q?Io7R4I+7nT1CCh/FKttGSEvBOcxji4MFaDzxfHds+zIjHUzpe2IZQdfM6Yo2o0zmq?= =?utf-8?q?VytUGfF8CpAbEIuzSh4uKfjxk3Pqvbzu1ZMT5IR6vl040CGDQO5lYBHZJ6KLJEMu3?= =?utf-8?q?IlGWrQnQYqnTjDSxFwqODh0skShK048uXnSHUpBhvHXpWT52K1pOH/ks8b/2op1yf?= =?utf-8?q?wFrl597G+xN0BJ0rSQjyLxihgDAS1VCmy+sPhh9FRIbeLTWKCP2SvS8z3XQv+6J/n?= =?utf-8?q?exRnGElDgA/GmOAdAF5qQ0igjoNxvX0SrottMpLTBbnhAfjFiaa7jR6DeVMDAdRJc?= =?utf-8?q?CboOn9xfeGSlTkT5Q6d94qTTkW+4CqWxjWQh6+mj0n1+BGPJ3MdyXb3WWyvrRkx/J?= =?utf-8?q?mRwMHnrgL7AMpaSOKXbIULUjpnwWj0jifhaMyY7hPJQg9+d15UemvFAO0KKLe/ZEu?= =?utf-8?q?tA+5pK+K2hQVe6oQftGHKUNx+ZuUnNvxH+oxitMpWB/dOqltftC08yuNvjH+kuwiK?= =?utf-8?q?R8bKxwewXESsLGa+DudzOrCXBLOlVtmV48X9D523/ouUGkIFxnU6rrKfcct3njDYu?= =?utf-8?q?gEJHX2k91uzbYTpqn1++h8l21kEKfuE4mIVL2ITvN2BBRYBaJk+/s4d/ryB/zilnM?= =?utf-8?q?8voVbxjC24XFNRpFlAUgS5jlbTYSFoKAGYe5eItyWgMFZ2qxDr2EqK3D3qmu1tSDv?= =?utf-8?q?R4OB3Zwmzbvzh6za853/MRyRea3lebtvtNXvDC/jnO+DrbHljv4LkVYRh+4fdp40P?= =?utf-8?q?4a/wUSkOGLlOlt2OvK3HOBJHKBK0yJes82gXi/DBVDFUr3cXiOB8aY6VT907E10UN?= =?utf-8?q?U4wHRw3clHcUuwSxhGsafDF+XzrjLP/rRWR2qwzbRlV6VHNhkfg2Em2pmHWGhyu4x?= =?utf-8?q?oml+SynEeT2Ea1qWzyCPrdLb2rXkPyS1JjgVbIQAJGrI7kSomcoun/9zrBaOwdR5c?= =?utf-8?q?Dx4VDkqPkrvGbzaHg3NC8Yb9oNydrEQ67q9p6cbU+QT/dgI64zI8LpAP8eE875CGc?= =?utf-8?q?Hbp6CDGV/zpLHrx8U/Vq9w/Tok+arU+wY7zQ5ZEx4ov3U8iTd0ZvtIHBgFUghk3Lt?= =?utf-8?q?H92i3pGGaitj7jzXY5zBddrj4bfnLqfjTSJtgc1BOmLG/sOa/O3PcrIQ+mjvS57NC?= =?utf-8?q?TZQtfIisvnA7hh0EL4JyqEEZgCZjlYVnlg=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96e4c3ed-35ca-4180-2c55-08db0dd26082 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8603.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2023 14:55:42.2600 (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: XTQsJqWT0Kqp6t5xry+mE1dJ6mWS7epuM2108jvq6qn4pLB9SF5aP77+N9/nBbF8dVFouMbobZ6mf3h8LcPz0uWMVx+NUxZTMytTq7Q1nmw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7591 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 a generic 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 based on the CTS line, and downloads device specific FW file into the chip over UART. The driver contains certain device specific default parameters related to FW filename, baudrate and timeouts which can be overwritten by an optional user space config file. These parameters may vary from one module vendor to another. Signed-off-by: Neeraj Sanjay Kale --- v2: Removed conf file support and added static data for each chip based on compatibility devices mentioned in DT bindings. Handled potential memory leaks and null pointer dereference issues, simplified FW download feature, handled byte-order and few cosmetic changes. (Ilpo Järvinen, Alok Tiwari, Hillf Danton) v3: Added conf file support necessary to support different vendor modules, moved .h file contents to .c, cosmetic changes. (Luiz Augusto von Dentz, Rob Herring, Leon Romanovsky) --- drivers/bluetooth/Kconfig | 11 + drivers/bluetooth/Makefile | 1 + drivers/bluetooth/btnxpuart.c | 1370 +++++++++++++++++++++++++++++++++ 3 files changed, 1382 insertions(+) create mode 100644 drivers/bluetooth/btnxpuart.c diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 5a1a7bec3c42..773b40d34b7b 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -465,4 +465,15 @@ config BT_VIRTIO Say Y here to compile support for HCI over Virtio into the kernel or say M to compile as a module. +config BT_NXPUART + tristate "NXP protocol support" + depends on SERIAL_DEV_BUS + help + NXP is serial driver required for NXP Bluetooth + devices with UART interface. + + Say Y here to compile support for NXP Bluetooth UART device into + the kernel, or say M here to compile as a module. + + 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..d774564d47ce --- /dev/null +++ b/drivers/bluetooth/btnxpuart.c @@ -0,0 +1,1370 @@ +// 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 "h4_recv.h" + +#define BTNXPUART_TX_STATE_ACTIVE 1 +#define BTNXPUART_FW_DOWNLOADING 2 + +#define MAX_TAG_STR_LEN 20 +#define BT_FW_CONF_FILE "nxp/bt_mod_para.conf" +#define USER_CONFIG_TAG "user_config" +#define FW_NAME_TAG "fw_name" +#define OPER_SPEED_TAG "oper_speed" +#define FW_DL_PRI_BAUDRATE_TAG "fw_dl_pri_speed" +#define FW_DL_SEC_BAUDRATE_TAG "fw_dl_sec_speed" +#define FW_INIT_BAUDRATE "fw_init_speed" +#define PS_INTERVAL_MS "ps_interval_ms" + +#define FIRMWARE_W8987 "nxp/sdiouart8987_combo_v0.bin" +#define FIRMWARE_W8997 "nxp/uartuart8997_bt_v4.bin" +#define FIRMWARE_W9098 "nxp/uartuart9098_bt_v1.bin" +#define FIRMWARE_IW416 "nxp/sdiouartiw416_combo_v0.bin" +#define FIRMWARE_IW612 "nxp/sduart_nw61x_v1.bin.se" + +#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 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 ps_mode; + u8 cur_psmode; + u8 ps_state; + u8 ps_cmd; + u8 wakeupmode; + u8 cur_wakeupmode; + bool driver_sent_cmd; + u8 timer_on; + u32 interval; + struct hci_dev *hdev; + struct work_struct work; + struct timer_list ps_timer; +}; + +struct btnxpuart_data { + u32 fw_dnld_pri_baudrate; + u32 fw_dnld_sec_baudrate; + u32 fw_init_baudrate; + u32 oper_speed; + u32 ps_interval_ms; + 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; + const struct firmware *fw_config; + u8 fw_name[MAX_FW_FILE_NAME_LEN]; + u32 fw_dnld_v1_offset; + u32 fw_v1_sent_bytes; + u32 fw_v3_offset_correction; + wait_queue_head_t suspend_wait_q; + + u32 new_baudrate; + u32 current_baudrate; + + 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 +#define POLYNOMIAL32 0x04c11db7L + +struct uart_reg { + __le32 address; + __le32 value; +} __packed; + +struct uart_config { + struct uart_reg clkdiv; + struct uart_reg uartdiv; + struct uart_reg mcr; + struct uart_reg re_init; + struct uart_reg icr; + struct uart_reg fcr; + __le32 crc; +} __packed; + +struct nxp_bootloader_cmd { + __le32 header; + __le32 arg; + __le32 payload_len; + __le32 crc; +} __packed; + +static u8 crc8_table[CRC8_TABLE_SIZE]; +static unsigned long crc32_table[256]; + +/* Default Power Save configuration */ +int wakeupmode = WAKEUP_METHOD_BREAK; +int ps_mode = PS_MODE_ENABLE; + +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; + + psdata->driver_sent_cmd = true; /* set flag to prevent re-sending command in nxp_enqueue */ + 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) { + psdata->timer_on = 1; + mod_timer(&psdata->ps_timer, jiffies + (psdata->interval * HZ) / 1000); + } +} + +static void ps_cancel_timer(struct btnxpuart_dev *nxpdev) +{ + struct ps_data *psdata = nxpdev->psdata; + + if (!psdata) + return; + + flush_work(&psdata->work); + if (psdata->timer_on) + del_timer_sync(&psdata->ps_timer); + kfree(psdata); +} + +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; + + if (psdata->ps_state == ps_state) + return; + + switch (psdata->cur_wakeupmode) { + case WAKEUP_METHOD_DTR: + if (ps_state == PS_STATE_AWAKE) + serdev_device_set_tiocm(nxpdev->serdev, TIOCM_DTR, 0); + else + serdev_device_set_tiocm(nxpdev->serdev, 0, TIOCM_DTR); + break; + case WAKEUP_METHOD_BREAK: + default: + bt_dev_info(hdev, "Set UART break: %s", ps_state == PS_STATE_AWAKE ? "off" : "on"); + if (ps_state == PS_STATE_AWAKE) + serdev_device_break_ctl(nxpdev->serdev, 0); + else + serdev_device_break_ctl(nxpdev->serdev, -1); + break; + } + 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); + + data->timer_on = 0; + 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 ps_data *psdata = kzalloc(sizeof(*psdata), GFP_KERNEL); + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + + if (!psdata) { + bt_dev_err(hdev, "Can't allocate control structure for Power Save feature"); + return -ENOMEM; + } + nxpdev->psdata = psdata; + + psdata->interval = nxp_data->ps_interval_ms; + psdata->ps_state = PS_STATE_AWAKE; + psdata->ps_mode = ps_mode; + psdata->hdev = hdev; + + switch (wakeupmode) { + case WAKEUP_METHOD_DTR: + psdata->wakeupmode = WAKEUP_METHOD_DTR; + break; + case WAKEUP_METHOD_BREAK: + default: + psdata->wakeupmode = WAKEUP_METHOD_BREAK; + break; + } + psdata->cur_psmode = PS_MODE_DISABLE; + psdata->cur_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; + + psdata->timer_on = 0; + timer_setup(&psdata->ps_timer, ps_timeout_func, 0); +} + +static int ps_wakeup(struct btnxpuart_dev *nxpdev) +{ + struct ps_data *psdata = nxpdev->psdata; + + if (psdata->ps_state == PS_STATE_AWAKE) + return 0; + psdata->ps_cmd = PS_CMD_EXIT_PS; + schedule_work(&psdata->work); + + return 1; +} + +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; + u8 pcmd; + struct sk_buff *skb; + u8 *status; + + if (psdata->ps_mode == PS_MODE_ENABLE) + pcmd = BT_PS_ENABLE; + else + pcmd = BT_PS_DISABLE; + + skb = nxp_drv_send_cmd(hdev, HCI_NXP_AUTO_SLEEP_MODE, 1, &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->ps_mode; + else + psdata->ps_mode = psdata->cur_psmode; + if (psdata->cur_psmode == PS_MODE_ENABLE) + ps_start_timer(nxpdev); + else + ps_wakeup(nxpdev); + bt_dev_info(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; + u8 pcmd[4]; + struct sk_buff *skb; + u8 *status; + + pcmd[0] = BT_HOST_WAKEUP_METHOD_NONE; + pcmd[1] = 0xff; + switch (psdata->wakeupmode) { + case WAKEUP_METHOD_DTR: + pcmd[2] = BT_CTRL_WAKEUP_METHOD_DSR; + break; + case WAKEUP_METHOD_BREAK: + default: + pcmd[2] = BT_CTRL_WAKEUP_METHOD_BREAK; + break; + } + pcmd[3] = 0xff; + + skb = nxp_drv_send_cmd(hdev, HCI_NXP_WAKEUP_METHOD, 4, 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_wakeupmode = psdata->wakeupmode; + else + psdata->wakeupmode = psdata->cur_wakeupmode; + bt_dev_info(hdev, "Set Wakeup Method response: status=%d, wakeupmode=%d", + *status, psdata->cur_wakeupmode); + } + kfree_skb(skb); + + return 0; +} + +static int 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, TIOCM_RTS, 0); + + switch (psdata->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 (!test_bit(HCI_RUNNING, &hdev->flags)) { + bt_dev_err(hdev, "HCI_RUNNING is not set"); + return -EBUSY; + } + if (psdata->cur_wakeupmode != psdata->wakeupmode) + hci_cmd_sync_queue(hdev, send_wakeup_method_cmd, NULL, NULL); + if (psdata->cur_psmode != psdata->ps_mode) + hci_cmd_sync_queue(hdev, send_ps_cmd, NULL, NULL); + + return 0; +} + +/* NXP Firmware Download Feature */ +static void nxp_fw_dnld_gen_crc32_table(void) +{ + int i, j; + unsigned long crc_accum; + + for (i = 0; i < 256; i++) { + crc_accum = ((unsigned long)i << 24); + for (j = 0; j < 8; j++) { + if (crc_accum & 0x80000000L) + crc_accum = (crc_accum << 1) ^ POLYNOMIAL32; + else + crc_accum = (crc_accum << 1); + } + crc32_table[i] = crc_accum; + } +} + +static unsigned long nxp_fw_dnld_update_crc(unsigned long crc_accum, + char *data_blk_ptr, + int data_blk_size) +{ + unsigned long i, j; + + for (j = 0; j < data_blk_size; j++) { + i = ((unsigned long)(crc_accum >> 24) ^ *data_blk_ptr++) & 0xff; + crc_accum = (crc_accum << 8) ^ crc32_table[i]; + } + return crc_accum; +} + +static int nxp_download_firmware(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + int err = 0; + + nxpdev->fw_dnld_v1_offset = 0; + nxpdev->fw_v1_sent_bytes = 0; + + crc8_populate_msb(crc8_table, POLYNOMIAL8); + nxp_fw_dnld_gen_crc32_table(); + + if (!strlen(nxpdev->fw_name)) + snprintf(nxpdev->fw_name, MAX_FW_FILE_NAME_LEN, "%s", + nxp_data->fw_name); + + bt_dev_info(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; + } + + serdev_device_set_baudrate(nxpdev->serdev, nxp_data->fw_dnld_pri_baudrate); + serdev_device_set_flow_control(nxpdev->serdev, 0); + nxpdev->current_baudrate = nxp_data->fw_dnld_pri_baudrate; + nxpdev->fw_v3_offset_correction = 0; + + /* Wait till FW is downloaded and CTS becomes low */ + err = wait_event_interruptible_timeout(nxpdev->suspend_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; + } + bt_dev_info(hdev, "CTS is low"); + release_firmware(nxpdev->fw); + + /* Allow the downloaded FW to initialize */ + usleep_range(1000000, 1200000); + + return 0; +} + +static int nxp_send_ack(u8 ack, struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + u8 ack_nak[2]; + + if (ack == NXP_ACK_V1 || ack == NXP_NAK_V1) { + ack_nak[0] = ack; + serdev_device_write_buf(nxpdev->serdev, ack_nak, 1); + } else if (ack == NXP_ACK_V3) { + ack_nak[0] = ack; + ack_nak[1] = crc8(crc8_table, ack_nak, 1, 0xff); + serdev_device_write_buf(nxpdev->serdev, ack_nak, 2); + } + return 0; +} + +static bool nxp_fw_change_baudrate(struct hci_dev *hdev, u16 req_len) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct nxp_bootloader_cmd nxp_cmd5; + struct uart_config uart_config; + + if (req_len == sizeof(nxp_cmd5)) { + nxp_cmd5.header = __cpu_to_le32(5); + nxp_cmd5.arg = 0; + nxp_cmd5.payload_len = __cpu_to_le32(sizeof(uart_config)); + nxp_cmd5.crc = swab32(nxp_fw_dnld_update_crc(0UL, + (char *)&nxp_cmd5, + sizeof(nxp_cmd5) - 4)); + + serdev_device_write_buf(nxpdev->serdev, (u8 *)&nxp_cmd5, req_len); + nxpdev->fw_v3_offset_correction += req_len; + } else if (req_len == sizeof(uart_config)) { + uart_config.clkdiv.address = __cpu_to_le32(CLKDIVADDR); + uart_config.clkdiv.value = __cpu_to_le32(0x00c00000); + uart_config.uartdiv.address = __cpu_to_le32(UARTDIVADDR); + uart_config.uartdiv.value = __cpu_to_le32(1); + uart_config.mcr.address = __cpu_to_le32(UARTMCRADDR); + uart_config.mcr.value = __cpu_to_le32(MCR); + uart_config.re_init.address = __cpu_to_le32(UARTREINITADDR); + uart_config.re_init.value = __cpu_to_le32(INIT); + uart_config.icr.address = __cpu_to_le32(UARTICRADDR); + uart_config.icr.value = __cpu_to_le32(ICR); + uart_config.fcr.address = __cpu_to_le32(UARTFCRADDR); + uart_config.fcr.value = __cpu_to_le32(FCR); + uart_config.crc = swab32(nxp_fw_dnld_update_crc(0UL, + (char *)&uart_config, + sizeof(uart_config) - 4)); + serdev_device_write_buf(nxpdev->serdev, (u8 *)&uart_config, req_len); + serdev_device_wait_until_sent(nxpdev->serdev, 0); + nxpdev->fw_v3_offset_correction += req_len; + return true; + } + return false; +} + +static bool nxp_fw_change_timeout(struct hci_dev *hdev, u16 req_len) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct nxp_bootloader_cmd nxp_cmd7; + + if (req_len != sizeof(nxp_cmd7)) + return false; + + nxp_cmd7.header = __cpu_to_le32(7); + nxp_cmd7.arg = __cpu_to_le32(0x70); + nxp_cmd7.payload_len = 0; + nxp_cmd7.crc = swab32(nxp_fw_dnld_update_crc(0UL, + (char *)&nxp_cmd7, + sizeof(nxp_cmd7) - 4)); + + serdev_device_write_buf(nxpdev->serdev, (u8 *)&nxp_cmd7, req_len); + 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); +} + +/* for legacy chipsets with V1 bootloader */ +static int nxp_recv_fw_req_v1(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct v1_data_req *req = skb_pull_data(skb, sizeof(struct v1_data_req)); + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + static bool timeout_changed; + static bool baudrate_changed; + u32 requested_len; + static u32 expected_len = HDR_LEN; + + if (!test_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state)) + goto ret; + + if (!nxpdev->fw) + goto ret; + + if (req && (req->len ^ req->len_comp) != 0xffff) { + bt_dev_info(hdev, "ERR: Send NAK"); + nxp_send_ack(NXP_NAK_V1, hdev); + goto ret; + } + nxp_send_ack(NXP_ACK_V1, hdev); + + if (nxp_data->fw_dnld_sec_baudrate != nxpdev->current_baudrate) { + if (!timeout_changed) { + timeout_changed = nxp_fw_change_timeout(hdev, req->len); + goto ret; + } + if (!baudrate_changed) { + baudrate_changed = nxp_fw_change_baudrate(hdev, req->len); + if (baudrate_changed) { + serdev_device_set_baudrate(nxpdev->serdev, + nxp_data->fw_dnld_sec_baudrate); + serdev_device_set_flow_control(nxpdev->serdev, 1); + nxpdev->current_baudrate = nxp_data->fw_dnld_sec_baudrate; + } + goto ret; + } + } + + requested_len = req->len; + if (requested_len == 0) { + bt_dev_info(hdev, "FW Downloaded Successfully: %zu bytes", nxpdev->fw->size); + clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + wake_up_interruptible(&nxpdev->suspend_wait_q); + goto ret; + } + if (requested_len & 0x01) { + /* The CRC did not match at the other end. + * Simply send the same bytes again. + */ + requested_len = nxpdev->fw_v1_sent_bytes; + bt_dev_err(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 == expected_len) { + if (requested_len == HDR_LEN) + expected_len = nxp_get_data_len(nxpdev->fw->data + + nxpdev->fw_dnld_v1_offset); + else + 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; + expected_len = HDR_LEN; + } + } + } + + if (nxpdev->fw_dnld_v1_offset + requested_len <= nxpdev->fw->size) + serdev_device_write_buf(nxpdev->serdev, + nxpdev->fw->data + nxpdev->fw_dnld_v1_offset, + requested_len); + nxpdev->fw_v1_sent_bytes = requested_len; + +ret: + kfree_skb(skb); + return 0; +} + +static int nxp_recv_chip_ver_v3(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + if (test_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state)) + nxp_send_ack(NXP_ACK_V3, hdev); + kfree_skb(skb); + return 0; +} + +static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct v3_data_req *req = skb_pull_data(skb, sizeof(struct v3_data_req)); + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + static bool timeout_changed; + static bool baudrate_changed; + + if (!req || !nxpdev || !nxpdev->fw->data) + goto ret; + + if (!test_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state)) + goto ret; + + nxp_send_ack(NXP_ACK_V3, hdev); + + if (nxpdev->current_baudrate != nxp_data->fw_dnld_sec_baudrate) { + if (!timeout_changed) { + timeout_changed = nxp_fw_change_timeout(hdev, req->len); + goto ret; + } + + if (!baudrate_changed) { + baudrate_changed = nxp_fw_change_baudrate(hdev, req->len); + if (baudrate_changed) { + serdev_device_set_baudrate(nxpdev->serdev, + nxp_data->fw_dnld_sec_baudrate); + serdev_device_set_flow_control(nxpdev->serdev, 1); + nxpdev->current_baudrate = nxp_data->fw_dnld_sec_baudrate; + } + goto ret; + } + } + + if (req->len == 0) { + bt_dev_info(hdev, "FW Downloaded Successfully: %zu bytes", nxpdev->fw->size); + clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + wake_up_interruptible(&nxpdev->suspend_wait_q); + goto ret; + } + if (req->error) + bt_dev_err(hdev, "FW Download received err 0x%02x from chip. Resending FW chunk.", + req->error); + + if (req->offset < nxpdev->fw_v3_offset_correction) { + /* This scenario should ideally never occur. + * But if it ever does, FW is out of sync and + * needs a power cycle. + */ + bt_dev_err(hdev, "Something went wrong during FW download. Please power cycle and try again"); + goto ret; + } + + serdev_device_write_buf(nxpdev->serdev, + nxpdev->fw->data + req->offset - nxpdev->fw_v3_offset_correction, + req->len); + +ret: + kfree_skb(skb); + return 0; +} + +static int nxp_set_baudrate_cmd(struct hci_dev *hdev, void *data) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + u32 new_baudrate = __cpu_to_le32(nxpdev->new_baudrate); + struct ps_data *psdata = nxpdev->psdata; + u8 *pcmd = (u8 *)&new_baudrate; + struct sk_buff *skb; + u8 *status; + + if (!psdata) + return 0; + + skb = nxp_drv_send_cmd(hdev, HCI_NXP_SET_OPER_SPEED, 4, pcmd); + if (IS_ERR(skb)) { + bt_dev_err(hdev, "Setting baudrate failed (%ld)", PTR_ERR(skb)); + return PTR_ERR(skb); + } + + status = 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_info(hdev, "Set baudrate response: status=%d, baudrate=%d", + *status, nxpdev->new_baudrate); + } + kfree_skb(skb); + + return 0; +} + +/* NXP protocol */ +static void nxp_update_device_data(struct hci_dev *hdev, + char *label, char *value) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + int ret = 0; + u32 val; + + if (!strncmp(label, FW_NAME_TAG, MAX_TAG_STR_LEN)) { + snprintf(nxpdev->fw_name, MAX_FW_FILE_NAME_LEN, "%s", + value); + return; + } + + ret = sscanf(value, "%u", &val); + if (ret != 1) { + bt_dev_err(hdev, "Error parsing value for %s", label); + return; + } + + if (!strncmp(label, OPER_SPEED_TAG, MAX_TAG_STR_LEN)) + nxp_data->oper_speed = val; + else if (!strncmp(label, FW_DL_PRI_BAUDRATE_TAG, MAX_TAG_STR_LEN)) + nxp_data->fw_dnld_pri_baudrate = val; + else if (!strncmp(label, FW_DL_SEC_BAUDRATE_TAG, MAX_TAG_STR_LEN)) + nxp_data->fw_dnld_sec_baudrate = val; + else if (!strncmp(label, FW_INIT_BAUDRATE, MAX_TAG_STR_LEN)) + nxp_data->fw_init_baudrate = val; + else if (!strncmp(label, PS_INTERVAL_MS, MAX_TAG_STR_LEN)) + nxp_data->ps_interval_ms = val; +} + +static void nxp_parse_conf_file(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + char *dptr, *label, *value; + bool valid_param = false; + bool skipline = false; + int param_index = 0; + const char *sptr; + int line_num = 1; + char line[100]; + int ret = 0; + int i, j; + + ret = request_firmware(&nxpdev->fw_config, BT_FW_CONF_FILE, &hdev->dev); + if (ret < 0) { + bt_dev_info(hdev, "No NXP config file, using default settings"); + return; + } + + sptr = nxpdev->fw_config->data; + j = 0; + for (i = 0; i < nxpdev->fw_config->size; i++) { + /* if current line is a comment, ignore */ + if (sptr[i] == '#') { + skipline = true; + continue; + } + /* keep ignoring the entire comment line */ + if (sptr[i] != '\n' && skipline) + continue; + /* ignore space, and comma */ + if (sptr[i] == ' ' || sptr[i] == '\r' || sptr[i] == ',') + continue; + /* handle '}' */ + if (sptr[i] == '}') { + if (!valid_param) { + bt_dev_err(hdev, "Unexpected '}' on line %d", line_num); + goto ret; + } + valid_param = false; + param_index++; + continue; + } + /* handle new-line character */ + if (sptr[i] == '\n') { + line_num++; + if (skipline) { + skipline = false; + continue; + } + line[j] = '\0'; + /* ignore empty lines */ + if (strlen(line) == 0) + continue; + + dptr = line; + label = strsep(&dptr, "="); + value = strsep(&dptr, "="); + if (label && value) { + /* handle '{' */ + if (!strncmp(value, "{", MAX_TAG_STR_LEN) && + !strncmp(label, USER_CONFIG_TAG, MAX_TAG_STR_LEN)) { + valid_param = true; + } else if (valid_param) { + nxp_update_device_data(hdev, label, value); + } + } else { + bt_dev_err(hdev, "Invalid \"key\" = \"value\" pair at line: %d", + line_num - 1); + goto ret; + } + j = 0; + } else { + line[j] = sptr[i]; + j++; + if (j >= 100) { + bt_dev_err(hdev, "Line too long: %d", line_num); + goto ret; + } + } + } + +ret: + release_firmware(nxpdev->fw_config); +} + +static int nxp_setup(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + int err = 0; + + if (!nxpdev) + return 0; + + set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + + nxp_parse_conf_file(hdev); + init_waitqueue_head(&nxpdev->suspend_wait_q); + + if (!serdev_device_get_cts(nxpdev->serdev)) { + bt_dev_info(hdev, "CTS high. Need FW Download"); + err = nxp_download_firmware(hdev); + if (err < 0) + return err; + } else { + bt_dev_info(hdev, "CTS low. FW already running."); + clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); + } + + serdev_device_set_flow_control(nxpdev->serdev, 1); + serdev_device_set_baudrate(nxpdev->serdev, nxp_data->fw_init_baudrate); + nxpdev->current_baudrate = nxp_data->fw_init_baudrate; + + if (nxpdev->current_baudrate != nxp_data->oper_speed) { + nxpdev->new_baudrate = nxp_data->oper_speed; + hci_cmd_sync_queue(hdev, nxp_set_baudrate_cmd, NULL, NULL); + } + + if (!ps_init_work(hdev)) + ps_init_timer(hdev); + ps_init(hdev); + + return 0; +} + +static int nxp_enqueue(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + struct ps_data *psdata = nxpdev->psdata; + struct hci_command_hdr *hdr; + u8 *param; + + if (!nxpdev || !psdata) { + kfree_skb(skb); + goto ret; + } + + /* 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. + */ + if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT && !psdata->driver_sent_cmd) { + hdr = (struct hci_command_hdr *)skb->data; + param = skb->data + HCI_COMMAND_HDR_SIZE; + switch (__le16_to_cpu(hdr->opcode)) { + case HCI_NXP_AUTO_SLEEP_MODE: + if (hdr->plen >= 1) { + if (param[0] == BT_PS_ENABLE) + psdata->ps_mode = PS_MODE_ENABLE; + else if (param[0] == BT_PS_DISABLE) + psdata->ps_mode = PS_MODE_DISABLE; + hci_cmd_sync_queue(hdev, send_ps_cmd, NULL, NULL); + kfree_skb(skb); + goto ret; + } + break; + case HCI_NXP_WAKEUP_METHOD: + if (hdr->plen >= 4) { + switch (param[2]) { + case BT_CTRL_WAKEUP_METHOD_DSR: + psdata->wakeupmode = WAKEUP_METHOD_DTR; + break; + case BT_CTRL_WAKEUP_METHOD_BREAK: + default: + psdata->wakeupmode = WAKEUP_METHOD_BREAK; + break; + } + hci_cmd_sync_queue(hdev, send_wakeup_method_cmd, NULL, NULL); + kfree_skb(skb); + goto ret; + } + break; + case HCI_NXP_SET_OPER_SPEED: + if (hdr->plen == 4) { + nxpdev->new_baudrate = *((u32 *)param); + hci_cmd_sync_queue(hdev, nxp_set_baudrate_cmd, NULL, NULL); + kfree_skb(skb); + goto ret; + } + } + } + + /* Prepend skb with frame type */ + memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1); + skb_queue_tail(&nxpdev->txq, skb); + + btnxpuart_tx_wakeup(nxpdev); +ret: + return 0; +} + +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)); + } + + return err; +} + +static int btnxpuart_close(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + if (!nxpdev) + return 0; + + serdev_device_close(nxpdev->serdev); + + return 0; +} + +static int btnxpuart_flush(struct hci_dev *hdev) +{ + struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev); + + if (!nxpdev) + return 0; + + /* 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 int btnxpuart_receive_buf(struct serdev_device *serdev, const u8 *data, + size_t count) +{ + struct btnxpuart_dev *nxpdev = serdev_device_get_drvdata(serdev); + + if (test_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state)) { + if (*data != NXP_V1_FW_REQ_PKT && *data != NXP_V1_CHIP_VER_PKT && + *data != NXP_V3_FW_REQ_PKT && *data != NXP_V3_CHIP_VER_PKT) { + /* 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); + + /* 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 = 37; + 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; + } + + return 0; +} + +static void nxp_serdev_remove(struct serdev_device *serdev) +{ + struct btnxpuart_dev *nxpdev = serdev_device_get_drvdata(serdev); + struct btnxpuart_data *nxp_data = nxpdev->nxp_data; + 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 (nxp_data->fw_init_baudrate != nxpdev->current_baudrate) { + nxpdev->new_baudrate = nxp_data->fw_init_baudrate; + nxp_set_baudrate_cmd(hdev, NULL); + } + + ps_cancel_timer(nxpdev); + hci_unregister_dev(hdev); + hci_free_dev(hdev); +} + +/* Following default values are as per Murata M.2 modules + * For modules from different vendor, if any of the device + * parameters are different, they can be over-written by + * config file /lib/firmware/nxp/bt_mod_para.conf + */ +static struct btnxpuart_data w8987_data = { + .fw_dnld_pri_baudrate = 115200, + .fw_dnld_sec_baudrate = 3000000, + .fw_init_baudrate = 115200, + .oper_speed = 3000000, + .ps_interval_ms = PS_DEFAULT_TIMEOUT_PERIOD, + .fw_name = FIRMWARE_W8987, +}; + +static struct btnxpuart_data w8997_data = { + .fw_dnld_pri_baudrate = 115200, + .fw_dnld_sec_baudrate = 115200, + .fw_init_baudrate = 115200, + .oper_speed = 3000000, + .ps_interval_ms = PS_DEFAULT_TIMEOUT_PERIOD, + .fw_name = FIRMWARE_W8997, +}; + +static struct btnxpuart_data w9098_data = { + .fw_dnld_pri_baudrate = 115200, + .fw_dnld_sec_baudrate = 3000000, + .fw_init_baudrate = 115200, + .oper_speed = 3000000, + .ps_interval_ms = PS_DEFAULT_TIMEOUT_PERIOD, + .fw_name = FIRMWARE_W9098, +}; + +static struct btnxpuart_data iw416_data = { + .fw_dnld_pri_baudrate = 115200, + .fw_dnld_sec_baudrate = 3000000, + .fw_init_baudrate = 115200, + .oper_speed = 3000000, + .ps_interval_ms = PS_DEFAULT_TIMEOUT_PERIOD, + .fw_name = FIRMWARE_IW416, +}; + +static struct btnxpuart_data iw612_data = { + .fw_dnld_pri_baudrate = 115200, + .fw_dnld_sec_baudrate = 3000000, + .fw_init_baudrate = 115200, + .oper_speed = 3000000, + .ps_interval_ms = PS_DEFAULT_TIMEOUT_PERIOD, + .fw_name = FIRMWARE_IW612, +}; + +static const struct of_device_id nxpuart_of_match_table[] = { + { .compatible = "nxp,88w8987-bt", .data = &w8987_data }, + { .compatible = "nxp,88w8997-bt", .data = &w8997_data }, + { .compatible = "nxp,88w9098-bt", .data = &w9098_data }, + { .compatible = "nxp,iw416-bt", .data = &iw416_data }, + { .compatible = "nxp,iw612-bt", .data = &iw612_data }, + { } +}; +MODULE_DEVICE_TABLE(of, nxpuart_of_match_table); + +static struct serdev_device_driver nxp_serdev_driver = { + .probe = nxp_serdev_probe, + .remove = nxp_serdev_remove, + .driver = { + .name = "btnxpuart", + .of_match_table = of_match_ptr(nxpuart_of_match_table), + }, +}; + +module_serdev_device_driver(nxp_serdev_driver); + +MODULE_AUTHOR("Neeraj Sanjay Kale "); +MODULE_DESCRIPTION("NXP Bluetooth Serial driver v1.0 "); +MODULE_LICENSE("GPL");