From patchwork Thu Feb 8 17:01:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550108 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45FCDC4828F for ; Thu, 8 Feb 2024 17:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=53q97w8qMgZiB+onVRh9Az4Pj27dcCoeQCr2yaoGhxY=; b=iZhepVU6NIWxEJ xTzko2iPsoV4N60CY4eLAu1rS5+KPz16P/cbNPBD6S+7bQ2vk0GEMzXgysoLATsrnEwoIlqAV8na+ ZkIwafgE8FaMa/VhhNtjy+KwE6wQt3VObBWBiU0cTCF31Iignt2aHQ5/TNUaBl7s2bIEVDzH+p3U9 M5rGGqoGQktfyZh31ZwTY2knX2pPsAbHbiGEsA/cjnRboZtTtZrZf9llnU2E/DlPZp5DdUPfB2p+x n5+xWj/zRd5N3GPH29l++0vWDRfIUnvZlVSQNqg4U7tOn/UKV+kj6vbVcpE2yUCHv6PAIh9fKDWxC I1pEzgCoXRpWUI8ccTZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7n5-0000000EO7M-3P5G; Thu, 08 Feb 2024 17:02:27 +0000 Received: from mail-vi1eur05on20601.outbound.protection.outlook.com ([2a01:111:f403:2613::601] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7mg-0000000ENy9-0EM2 for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:02:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=crtWjEljUoRDHR1pqV3eZUwuEQdBLxC8ItFXWlsSQC4YOvGcru/qEBi357UrBg3w4yiNqgs3cr6cmQ4WavtvmrWZ0SYZlBHoi7IDUWbygrGkuFdkpXsFVfEg5/SPYWJLHlsA9fZef2SO6WjlFpeAELDBnn6BfFQuhqDGI5TW5gqcJKBLCXybYLOozDhLp8GLC7bqP1XOVBKyF0D5+1RgMG9RdHvSV8edaNS/86VQ7FqDnAap2TWj5EjxKIczx7yehcf9gmVhF3Q63zWjV6t8r3sF7tQJsO6K01Ek0LT0oXhf1UucX1Ib697l+OmJQz73A9ZIa+/KKHkGb/9+TMep9w== 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=KoNHQWoIdVvvBsmZsruIoyAVUoQ+OOMnefNma7ikd20=; b=NPL6g2ntb9RQr8XW6Jl61sIqnZCZlX55fjYAbNVtWrOZC8+6Ai4syoJYz1Q/b7oFAxQHQzyofg2zLTd+JFXXct26W9+iRX2cZuRo4QhW04ogR7krUtVqQCFWQtMzD5i5W22E/q12xBpD8403PfVQvZ5PqdgX0BpRVACJpjWCbQ59JqLNQMBeErksvTJim1uMisgtfCzAAIph06bwcuDEQ/6bfIKL1bcx/oGqBMWTN169hCjZVB+XfhFrCZthK3MKcsE7nswVc7tlaJefoW2VJZZl1inJ2Q8vCH266/oI9jo2n0WlulNg9d79jL/M5rRtfFJbXmZLp1P1SdEkAHaexw== 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=KoNHQWoIdVvvBsmZsruIoyAVUoQ+OOMnefNma7ikd20=; b=o/Kx3GGGFh7aTEy7lE3pnhq7lS7aO8g0wMTV1480w0QKV7DgaxJzku6bkpVUfa+Xkpg6wlml3GNrgrJjRcsImnQxbVAvZAoxMmhVSioTSRpulr1bvgMjZJp64PzDh9pRuHKny/kxXIR0UOL5BUQmr7p/wmlSxw7Q+lC9PgzvrNA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA4PR04MB9248.eurprd04.prod.outlook.com (2603:10a6:102:2a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Thu, 8 Feb 2024 17:01:40 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:01:40 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 1/8] i3c: add target mode support Date: Thu, 8 Feb 2024 12:01:10 -0500 Message-Id: <20240208170117.798357-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9248:EE_ X-MS-Office365-Filtering-Correlation-Id: 580d6ef8-fd05-4e3c-3ae1-08dc28c79e05 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +1Oxh7NqeAi0pU+UsP2cLGmnbalZ6rIm0QPdO9CLHT9nn7CfL05YTnHUQYE1GXKWt78rD4WNImLcrXmrTVJk46+LwTVeb0UJxDydq3DEh1acoyFHfmZIl8FMuzT46878g/ENlb1BwiGvtcOq4Lr7DlGwChRfnL3GKDlL0XKUJtG6TWpstzi1baGlc6W5e0keiQFwsovvY6iRKP733yULGEGzolfxHRkym/t2bpXFaGE3HEmx3igwLtgXHnUOmopFOwQ2lZhwv3LywTqYH5YDJWQq2Jjw2Btb76C+nJoCCoK9NgrslKQ7wm7ZOrBo2NASh/zxN21Cy9epb8p4feQGuIRQ7Xcma81xRGYlexbiUowDTM8ZyxWO1N91/pk9Ikl8yHyu3xKq2/rQkx2T5nJknqdN2UlzFyIM6UVQ3xk6uNZNbdMtvUZARHtaqV8HLn1MX3hqgnUbC/LbhOSBcEwrGK944W/oA755Cit4wSmmSKwar23s29XjaTv3y9YZkXRNepjf02KuGKOUY441Rnp/tJ5cqboc74e8LE5/H9UhLxJfba+iNcOyl5I9Js/veXep9w5i8tf6AN7LnesSWNr18LqyqpttGU9nFCLd6FaKDwo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(38100700002)(6666004)(52116002)(6506007)(83380400001)(37006003)(86362001)(7416002)(41300700001)(1076003)(2616005)(26005)(34206002)(6512007)(36756003)(8676002)(8936002)(4326008)(6486002)(478600001)(2906002)(30864003)(5660300002)(966005)(66476007)(66946007)(316002)(66556008)(38350700005)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0kQrhnsiKou9UDOqMSgSUHX19EMK7XfjXGTaeQDaW6ej1YvaYI9WcIti3BG2Xr0xugzS/9kDS0FWOslgcCBK2SazC8D1m0K7MgWf98R96X4T8V1N2T6hJUeh+cgiHmlQI4G95jYZvoXDkDBVnBWJ9tZ4Jc8A0ZBAaaozx40FcLXlKSvIkRY4BnHje0C3lx5j+CAMkpcOzbHJIbgj8iDOSpTpooFNxnJecf2IlYFhx4yZHLtvMhGkytM97hwNg+MxYnrMBgdi9bj6emRbGW6kUCr9D2ys+zE2SxBnvBRg9BOyKnG1CH21o9HmWBeYv2ENehGJky3vG6GIdYc4llsipD+HYWfIkhsq0+2r2dOsSsoweZRFYhwVoWRYpF/nKth/OOo3pVVNzeeiLxMKIz/l/SD/Iemz3i3BvcOnz8vZyXVDcLQVsEeTI2MmBEni8k1aGwZvn/2Tsf4iVQd9X6s2XrRpfL57hajs0at7pL8lOxBKr8dc6FtE0+xniUQDxvpiN10Biq+Uab/jsAMJ0P0+RmuxE3rJg6/dOeU9k7gGuIL2NYMxLTQnoDKcuWqhAuiD5cu39jwiT++2n3aJ3RHdZsI4UYqi+ffvF2EYSEfLj1gZ+1dkyfuBRBO7n+orWeucUYgoaKrrUnGRnRv4yR0cQNsKt+bGotpPHstbFP3zkHRclfYrsJ4tL3Wu6i0tOQAGmekhbV43cJwxIFDlqWnxqURGADTIx3SLRVvpf0DgysVlgbTa5wMOnlp7zmvfwoPq7IBtl3jnfdnD1xLuhQIyEOSKNYTwCYWGxujkx4HTzeQGH2YUB7jXtqC5DNSNRZwrLs3gNCWoRNpmA2h8uQMihTdsQlMPDmshI3PZh0xXy/3NbiAV5uCWUx2OPW0GJ3bA+y67OhEoXv77SaPp5sFQ2GjM4yFSwqxj8Wg2dM5WHPXnEp6KqBHRNJJsp6qnJWOH1AGI4acLP+KcmgFu72GXJ0IZD3weI3g5gQnbThU6Y2NawZ1j21joEkwz+Tg+XBSvn3NocRMIZnCLrV0HIVG3spjW1Zj0M8GhYjpBTAYmKN54KsFhPi4FVkqsOUTVhdS4ucNqqmWqhJIS04++7tgQ7ZVqXrIuU6izp47b/8TMjdrhhuYa+zKU8dfXOTdmpg62h9Yzt09icj12rGnZjPp8x0JqOMh4rxfcu+21iGv7SJ5S0v1cvfh5VMLVJP7kWp2dvPvjCcKAxiomxInJzPdmrjRVcIGSTsoocAja3NSBmMS3QCPlCnWdKskURrFEMkSc+2kenlJj7eaJJucLl8JXRDebZr9MzaJITs7pX56+A9ut6z452zlRiSWSLc/8JFB23z686ZOJ+Z6I9X6R259XSEdVqQn8+jIEsgdWFew0NTHiHwr0jQr8DpIRRNIM0izU7Wv3v7v84PPlwnnAkFWANBuyxT9rI1lcC1Xg3ERFoC2nh9y8nnXiBE0xwWvHRISMEMvvoHbQi5bGALfoBji6EYH694yLIWc+U/pcc4/LzqxoCUdm7ie3bxLRe/sjIe16XB2o8eZtKmiWoINhAuOpShewkyIOgqVTTAgMaBnnMBY= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 580d6ef8-fd05-4e3c-3ae1-08dc28c79e05 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:01:39.9827 (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: Fj85AlR19AdSFZkKWIlP1WODkmF10Y8z8W4fku6HqYiEdjuHtl1t6qdtZ2uKqhr6tSDOUVa0CHI1LgXAl9WdgA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_090158_642597_85912CB8 X-CRM114-Status: GOOD ( 23.96 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Introduce a new target core layer in order to support target functions in linux kernel. This comprises the controller library and function library. Controller library implements functions specific to an target controller and function library implements functions specific to an target function. Introduce a new configfs entry to configure the target function configuring and bind the target function with target controller. Signed-off-by: Frank Li --- Notes: Change from v7 to v8 Added missed head files Change from v5 to v6 - fixed build error when have not CONFIG_TARGET_CONFIGFS | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202402030437.GdGCrKeK-lkp@intel.com/ Chagne from v4 to v5 - add include to fix build error | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202401270838.wdxHPaAT-lkp@intel.com/ Chagne from v4 to v8 - add include to fix build error | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202401270838.wdxHPaAT-lkp@intel.com/ drivers/i3c/Kconfig | 28 +- drivers/i3c/Makefile | 2 + drivers/i3c/i3c-cfs.c | 389 ++++++++++++++++++++++++++ drivers/i3c/target.c | 453 ++++++++++++++++++++++++++++++ include/linux/i3c/target.h | 548 +++++++++++++++++++++++++++++++++++++ 5 files changed, 1419 insertions(+), 1 deletion(-) create mode 100644 drivers/i3c/i3c-cfs.c create mode 100644 drivers/i3c/target.c create mode 100644 include/linux/i3c/target.h diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 30a441506f61c..d59a7eb83d13a 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -10,7 +10,7 @@ menuconfig I3C support for high speed transfers and native interrupt support without the need for extra pins. - The I3C protocol also standardizes the slave device types and is + The I3C protocol also standardizes the target device types and is mainly designed to communicate with sensors. If you want I3C support, you should say Y here and also to the @@ -22,3 +22,29 @@ menuconfig I3C if I3C source "drivers/i3c/master/Kconfig" endif # I3C + +config I3C_TARGET + bool "I3C Target Support" + help + Support I3C Target Mode. + + Enable this configuration option to support configurable I3C target. + This should be enabled if the platform has a I3C controller that can + operate in target mode. + + Enabling this option will build the I3C target library, which includes + target controller library and target function library. + + If in doubt, say "N" to disable target support. + +config I3C_TARGET_CONFIGFS + bool "I3C Target Configfs Support" + depends on I3C_TARGET + select CONFIGFS_FS + help + Configfs entry for target function and controller. + + This will enable the configfs entry that can be used to configure + the target function and used to bind the function with a target + controller. + diff --git a/drivers/i3c/Makefile b/drivers/i3c/Makefile index 11982efbc6d91..c275aeae8970c 100644 --- a/drivers/i3c/Makefile +++ b/drivers/i3c/Makefile @@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 i3c-y := device.o master.o obj-$(CONFIG_I3C) += i3c.o +obj-$(CONFIG_I3C_TARGET) += target.o +obj-$(CONFIG_I3C_TARGET_CONFIGFS) += i3c-cfs.o obj-$(CONFIG_I3C) += master/ diff --git a/drivers/i3c/i3c-cfs.c b/drivers/i3c/i3c-cfs.c new file mode 100644 index 0000000000000..5178b978ebca7 --- /dev/null +++ b/drivers/i3c/i3c-cfs.c @@ -0,0 +1,389 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Configfs to configure the I3C Slave + * + * Copyright (C) 2023 NXP + * Author: Frank Li + */ + +#include +#include +#include +#include +#include + +static DEFINE_MUTEX(functions_mutex); +static struct config_group *functions_group; +static struct config_group *controllers_group; + +struct i3c_target_func_group { + struct config_group group; + struct i3c_target_func *func; +}; + +struct i3c_target_ctrl_group { + struct config_group group; + struct i3c_target_ctrl *ctrl; +}; + +static inline struct i3c_target_func_group *to_i3c_target_func_group(struct config_item *item) +{ + return container_of(to_config_group(item), struct i3c_target_func_group, group); +} + +static inline struct i3c_target_ctrl_group *to_i3c_target_ctrl_group(struct config_item *item) +{ + return container_of(to_config_group(item), struct i3c_target_ctrl_group, group); +} + +static int i3c_target_ctrl_func_link(struct config_item *ctrl_cfg, struct config_item *func_cfg) +{ + struct i3c_target_func_group *func_group = to_i3c_target_func_group(func_cfg); + struct i3c_target_ctrl_group *ctrl_group = to_i3c_target_ctrl_group(ctrl_cfg); + struct i3c_target_ctrl *ctrl = ctrl_group->ctrl; + struct i3c_target_func *func = func_group->func; + int ret; + + ret = i3c_target_ctrl_add_func(ctrl, func); + if (ret) + return ret; + + ret = i3c_target_func_bind(func); + if (ret) { + i3c_target_ctrl_remove_func(ctrl, func); + return ret; + } + + return 0; +} + +static void i3c_target_ctrl_func_unlink(struct config_item *ctrl_cfg, struct config_item *func_cfg) +{ + struct i3c_target_func_group *func_group = to_i3c_target_func_group(func_cfg->ci_parent); + struct i3c_target_ctrl_group *ctrl_group = to_i3c_target_ctrl_group(ctrl_cfg); + struct i3c_target_ctrl *ctrl = ctrl_group->ctrl; + struct i3c_target_func *func = func_group->func; + + i3c_target_func_unbind(func); + i3c_target_ctrl_remove_func(ctrl, func); +} + +static ssize_t i3c_target_ctrl_hotjoin_store(struct config_item *item, const char *page, size_t len) +{ + struct i3c_target_ctrl_group *ctrl_group = to_i3c_target_ctrl_group(item); + struct i3c_target_ctrl *ctrl; + int ret; + + ctrl = ctrl_group->ctrl; + + ret = i3c_target_ctrl_hotjoin(ctrl); + if (ret) { + dev_err(&ctrl->dev, "failed to hotjoin i3c target controller\n"); + return -EINVAL; + } + + return len; +} + +static ssize_t i3c_target_ctrl_hotjoin_show(struct config_item *item, char *page) +{ + return sysfs_emit(page, "%d\n", 0); +} + +CONFIGFS_ATTR(i3c_target_ctrl_, hotjoin); + +static struct configfs_item_operations i3c_target_ctrl_item_ops = { + .allow_link = i3c_target_ctrl_func_link, + .drop_link = i3c_target_ctrl_func_unlink, +}; + +static struct configfs_attribute *i3c_target_ctrl_attrs[] = { + &i3c_target_ctrl_attr_hotjoin, + NULL, +}; + +static const struct config_item_type i3c_target_ctrl_type = { + .ct_item_ops = &i3c_target_ctrl_item_ops, + .ct_attrs = i3c_target_ctrl_attrs, + .ct_owner = THIS_MODULE, +}; + +/** + * i3c_target_cfs_add_ctrl_group() - add I3C target controller group + * @ctrl: I3C target controller device + * + * Return: Pointer to struct config_group + */ +struct config_group *i3c_target_cfs_add_ctrl_group(struct i3c_target_ctrl *ctrl) +{ + struct i3c_target_ctrl_group *ctrl_group; + struct config_group *group; + int ret; + + ctrl_group = kzalloc(sizeof(*ctrl_group), GFP_KERNEL); + if (!ctrl_group) { + ret = -ENOMEM; + goto err; + } + + group = &ctrl_group->group; + + config_group_init_type_name(group, dev_name(&ctrl->dev), &i3c_target_ctrl_type); + ret = configfs_register_group(controllers_group, group); + if (ret) { + pr_err("failed to register configfs group for %s\n", dev_name(&ctrl->dev)); + goto err_register_group; + } + + ctrl_group->ctrl = ctrl; + + return group; + +err_register_group: + kfree(ctrl_group); + +err: + return ERR_PTR(ret); +} +EXPORT_SYMBOL(i3c_target_cfs_add_ctrl_group); + +/** + * i3c_target_cfs_remove_ctrl_group() - remove I3C target controller group + * @group: the group to be removed + */ +void i3c_target_cfs_remove_ctrl_group(struct config_group *group) +{ + struct i3c_target_ctrl_group *ctrl_group; + + if (!group) + return; + + ctrl_group = container_of(group, struct i3c_target_ctrl_group, group); + i3c_target_ctrl_put(ctrl_group->ctrl); + configfs_unregister_group(&ctrl_group->group); + kfree(ctrl_group); +} +EXPORT_SYMBOL(i3c_target_cfs_remove_ctrl_group); + +#define I3C_SLAVE_ATTR_R(_name) \ +static ssize_t i3c_target_func_##_name##_show(struct config_item *item, char *page) \ +{ \ + struct i3c_target_func *func = to_i3c_target_func_group(item)->func; \ + return sysfs_emit(page, "0x%04x\n", func->_name); \ +} + +#define I3C_SLAVE_ATTR_W(_name, _u) \ +static ssize_t i3c_target_func_##_name##_store(struct config_item *item, \ + const char *page, size_t len) \ +{ \ + _u val; \ + struct i3c_target_func *func = to_i3c_target_func_group(item)->func; \ + if (kstrto##_u(page, 0, &val) < 0) \ + return -EINVAL; \ + func->_name = val; \ + return len; \ +} + +I3C_SLAVE_ATTR_R(vendor_id); +I3C_SLAVE_ATTR_W(vendor_id, u16); +CONFIGFS_ATTR(i3c_target_func_, vendor_id); + +I3C_SLAVE_ATTR_R(vendor_info); +I3C_SLAVE_ATTR_W(vendor_info, u16); +CONFIGFS_ATTR(i3c_target_func_, vendor_info); + +I3C_SLAVE_ATTR_R(part_id); +I3C_SLAVE_ATTR_W(part_id, u16); +CONFIGFS_ATTR(i3c_target_func_, part_id); + +I3C_SLAVE_ATTR_R(instance_id); +I3C_SLAVE_ATTR_W(instance_id, u8); +CONFIGFS_ATTR(i3c_target_func_, instance_id); + +I3C_SLAVE_ATTR_R(ext_id); +I3C_SLAVE_ATTR_W(ext_id, u16); +CONFIGFS_ATTR(i3c_target_func_, ext_id); + +I3C_SLAVE_ATTR_R(max_write_len); +I3C_SLAVE_ATTR_W(max_write_len, u16); +CONFIGFS_ATTR(i3c_target_func_, max_write_len); + +I3C_SLAVE_ATTR_R(max_read_len); +I3C_SLAVE_ATTR_W(max_read_len, u16); +CONFIGFS_ATTR(i3c_target_func_, max_read_len); + +I3C_SLAVE_ATTR_R(bcr); +I3C_SLAVE_ATTR_W(bcr, u8); +CONFIGFS_ATTR(i3c_target_func_, bcr); + +I3C_SLAVE_ATTR_R(dcr); +I3C_SLAVE_ATTR_W(dcr, u8); +CONFIGFS_ATTR(i3c_target_func_, dcr); + +static struct configfs_attribute *i3c_target_func_attrs[] = { + &i3c_target_func_attr_vendor_id, + &i3c_target_func_attr_vendor_info, + &i3c_target_func_attr_part_id, + &i3c_target_func_attr_instance_id, + &i3c_target_func_attr_ext_id, + &i3c_target_func_attr_max_write_len, + &i3c_target_func_attr_max_read_len, + &i3c_target_func_attr_bcr, + &i3c_target_func_attr_dcr, + NULL, +}; + +static const struct config_item_type i3c_target_func_type = { + .ct_attrs = i3c_target_func_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct config_group *i3c_target_func_make(struct config_group *group, const char *name) +{ + struct i3c_target_func_group *func_group; + struct i3c_target_func *func; + int err; + + func_group = kzalloc(sizeof(*func_group), GFP_KERNEL); + if (!func_group) + return ERR_PTR(-ENOMEM); + + config_group_init_type_name(&func_group->group, name, &i3c_target_func_type); + + func = i3c_target_func_create(group->cg_item.ci_name, name); + if (IS_ERR(func)) { + pr_err("failed to create i3c target function device\n"); + err = -EINVAL; + goto free_group; + } + + func->group = &func_group->group; + + func_group->func = func; + + return &func_group->group; + +free_group: + kfree(func_group); + + return ERR_PTR(err); +} + +static void i3c_target_func_drop(struct config_group *group, struct config_item *item) +{ + config_item_put(item); +} + +static struct configfs_group_operations i3c_target_func_group_ops = { + .make_group = &i3c_target_func_make, + .drop_item = &i3c_target_func_drop, +}; + +static const struct config_item_type i3c_target_func_group_type = { + .ct_group_ops = &i3c_target_func_group_ops, + .ct_owner = THIS_MODULE, +}; + +/** + * i3c_target_cfs_add_func_group() - add I3C target function group + * @name: group name + * + * Return: Pointer to struct config_group + */ +struct config_group *i3c_target_cfs_add_func_group(const char *name) +{ + struct config_group *group; + + group = configfs_register_default_group(functions_group, name, + &i3c_target_func_group_type); + if (IS_ERR(group)) + pr_err("failed to register configfs group for %s function\n", + name); + + return group; +} +EXPORT_SYMBOL(i3c_target_cfs_add_func_group); + +/** + * i3c_target_cfs_remove_func_group() - add I3C target function group + * @group: group to be removed + */ +void i3c_target_cfs_remove_func_group(struct config_group *group) +{ + if (IS_ERR_OR_NULL(group)) + return; + + configfs_unregister_default_group(group); +} +EXPORT_SYMBOL(i3c_target_cfs_remove_func_group); + +static const struct config_item_type i3c_target_controllers_type = { + .ct_owner = THIS_MODULE, +}; + +static const struct config_item_type i3c_target_functions_type = { + .ct_owner = THIS_MODULE, +}; + +static const struct config_item_type i3c_target_type = { + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem i3c_target_cfs_subsys = { + .su_group = { + .cg_item = { + .ci_namebuf = "i3c_target", + .ci_type = &i3c_target_type, + }, + }, + .su_mutex = __MUTEX_INITIALIZER(i3c_target_cfs_subsys.su_mutex), +}; + +static int __init i3c_target_cfs_init(void) +{ + int ret; + struct config_group *root = &i3c_target_cfs_subsys.su_group; + + config_group_init(root); + + ret = configfs_register_subsystem(&i3c_target_cfs_subsys); + if (ret) { + pr_err("Error %d while registering subsystem %s\n", + ret, root->cg_item.ci_namebuf); + goto err; + } + + functions_group = configfs_register_default_group(root, "functions", + &i3c_target_functions_type); + if (IS_ERR(functions_group)) { + ret = PTR_ERR(functions_group); + pr_err("Error %d while registering functions group\n", + ret); + goto err_functions_group; + } + + controllers_group = + configfs_register_default_group(root, "controllers", + &i3c_target_controllers_type); + if (IS_ERR(controllers_group)) { + ret = PTR_ERR(controllers_group); + pr_err("Error %d while registering controllers group\n", + ret); + goto err_controllers_group; + } + + return 0; + +err_controllers_group: + configfs_unregister_default_group(functions_group); + +err_functions_group: + configfs_unregister_subsystem(&i3c_target_cfs_subsys); + +err: + return ret; +} +module_init(i3c_target_cfs_init); + +MODULE_DESCRIPTION("I3C FUNC CONFIGFS"); +MODULE_AUTHOR("Frank Li "); diff --git a/drivers/i3c/target.c b/drivers/i3c/target.c new file mode 100644 index 0000000000000..a2738b8341f7a --- /dev/null +++ b/drivers/i3c/target.c @@ -0,0 +1,453 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * configfs to configure the I3C Slave + * + * Copyright (C) 2023 NXP + * Author: Frank Li + */ + +#include +#include +#include +#include +#include + +static DEFINE_MUTEX(func_lock); +static struct class *i3c_target_ctrl_class; + +static void i3c_target_func_dev_release(struct device *dev) +{ + struct i3c_target_func *func = to_i3c_target_func(dev); + + kfree(func->name); + kfree(func); +} + +static const struct device_type i3c_target_func_type = { + .release = i3c_target_func_dev_release, +}; + +static int i3c_target_func_match_driver(struct device *dev, struct device_driver *drv) +{ + return !strncmp(dev_name(dev), drv->name, strlen(drv->name)); +} + +static int i3c_target_func_device_probe(struct device *dev) +{ + struct i3c_target_func *func = to_i3c_target_func(dev); + struct i3c_target_func_driver *driver = to_i3c_target_func_driver(dev->driver); + + if (!driver->probe) + return -ENODEV; + + func->driver = driver; + + return driver->probe(func); +} + +static void i3c_target_func_device_remove(struct device *dev) +{ + struct i3c_target_func *func = to_i3c_target_func(dev); + struct i3c_target_func_driver *driver = to_i3c_target_func_driver(dev->driver); + + if (driver->remove) + driver->remove(func); + func->driver = NULL; +} + +static const struct bus_type i3c_target_func_bus_type = { + .name = "i3c_target_func", + .probe = i3c_target_func_device_probe, + .remove = i3c_target_func_device_remove, + .match = i3c_target_func_match_driver, +}; + +static void i3c_target_ctrl_release(struct device *dev) +{ + kfree(to_i3c_target_ctrl(dev)); +} + +static void devm_i3c_target_ctrl_release(struct device *dev, void *res) +{ + struct i3c_target_ctrl *ctrl = *(struct i3c_target_ctrl **)res; + + i3c_target_ctrl_destroy(ctrl); +} + +struct i3c_target_ctrl * +__devm_i3c_target_ctrl_create(struct device *dev, const struct i3c_target_ctrl_ops *ops, + struct module *owner) +{ + struct i3c_target_ctrl **ptr, *ctrl; + + ptr = devres_alloc(devm_i3c_target_ctrl_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + ctrl = __i3c_target_ctrl_create(dev, ops, owner); + if (!IS_ERR(ctrl)) { + *ptr = ctrl; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return ctrl; +} + +static int devm_i3c_target_ctrl_match(struct device *dev, void *res, void *match_data) +{ + struct i3c_target_ctrl **ptr = res; + + return *ptr == match_data; +} + +/** + * __i3c_target_ctrl_create() - create a new target controller device + * @dev: device that is creating the new target controller + * @ops: function pointers for performing target controller operations + * @owner: the owner of the module that creates the target controller device + * + * Return: Pointer to struct i3c_target_ctrl + */ +struct i3c_target_ctrl * +__i3c_target_ctrl_create(struct device *dev, const struct i3c_target_ctrl_ops *ops, + struct module *owner) +{ + struct i3c_target_ctrl *ctrl; + int ret; + + if (WARN_ON(!dev)) + return ERR_PTR(-EINVAL); + + ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); + if (!ctrl) + return ERR_PTR(-ENOMEM); + + device_initialize(&ctrl->dev); + ctrl->dev.class = i3c_target_ctrl_class; + ctrl->dev.parent = dev; + ctrl->dev.release = i3c_target_ctrl_release; + ctrl->ops = ops; + + ret = dev_set_name(&ctrl->dev, "%s", dev_name(dev)); + if (ret) + goto put_dev; + + ret = device_add(&ctrl->dev); + if (ret) + goto put_dev; + + ctrl->group = i3c_target_cfs_add_ctrl_group(ctrl); + if (!ctrl->group) + goto put_dev; + + return ctrl; + +put_dev: + put_device(&ctrl->dev); + kfree(ctrl); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(__i3c_target_ctrl_create); + +/** + * devm_i3c_target_ctrl_destroy() - destroy the target controller device + * @dev: device that hat has to be destroy + * @ctrl: the target controller device that has to be destroy + * + * Invoke to create a new target controller device and add it to i3c_target class. While at that, it + * also associates the device with the i3c_target using devres. On driver detach, release function + * is invoked on the devres data, then devres data is freed. + */ +void devm_i3c_target_ctrl_destroy(struct device *dev, struct i3c_target_ctrl *ctrl) +{ + int r; + + r = devres_destroy(dev, devm_i3c_target_ctrl_release, devm_i3c_target_ctrl_match, + ctrl); + dev_WARN_ONCE(dev, r, "couldn't find I3C controller resource\n"); +} +EXPORT_SYMBOL_GPL(devm_i3c_target_ctrl_destroy); + +/** + * i3c_target_ctrl_destroy() - destroy the target controller device + * @ctrl: the target controller device that has to be destroyed + * + * Invoke to destroy the I3C target device + */ +void i3c_target_ctrl_destroy(struct i3c_target_ctrl *ctrl) +{ + i3c_target_cfs_remove_ctrl_group(ctrl->group); + device_unregister(&ctrl->dev); +} +EXPORT_SYMBOL_GPL(i3c_target_ctrl_destroy); + +/** + * i3c_target_ctrl_add_func() - bind I3C target function to an target controller + * @ctrl: the controller device to which the target function should be added + * @func: the target function to be added + * + * An I3C target device can have only one functions. + */ +int i3c_target_ctrl_add_func(struct i3c_target_ctrl *ctrl, struct i3c_target_func *func) +{ + if (ctrl->func) + return -EBUSY; + + ctrl->func = func; + func->ctrl = ctrl; + + return 0; +} +EXPORT_SYMBOL_GPL(i3c_target_ctrl_add_func); + +/** + * i3c_target_ctrl_remove_func() - unbind I3C target function to an target controller + * @ctrl: the controller device to which the target function should be removed + * @func: the target function to be removed + * + * An I3C target device can have only one functions. + */ +void i3c_target_ctrl_remove_func(struct i3c_target_ctrl *ctrl, struct i3c_target_func *func) +{ + ctrl->func = NULL; +} +EXPORT_SYMBOL_GPL(i3c_target_ctrl_remove_func); + +/** + * i3c_target_ctrl_get() - get the I3C target controller + * @name: device name of the target controller + * + * Invoke to get struct i3c_target_ctrl * corresponding to the device name of the + * target controller + */ +struct i3c_target_ctrl *i3c_target_ctrl_get(const char *name) +{ + int ret = -EINVAL; + struct i3c_target_ctrl *ctrl; + struct device *dev; + struct class_dev_iter iter; + + class_dev_iter_init(&iter, i3c_target_ctrl_class, NULL, NULL); + while ((dev = class_dev_iter_next(&iter))) { + if (strcmp(name, dev_name(dev))) + continue; + + ctrl = to_i3c_target_ctrl(dev); + if (!try_module_get(ctrl->ops->owner)) { + ret = -EINVAL; + goto err; + } + + class_dev_iter_exit(&iter); + get_device(&ctrl->dev); + return ctrl; + } + +err: + class_dev_iter_exit(&iter); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(i3c_target_ctrl_get); + +/** + * i3c_target_ctrl_put() - release the I3C endpoint controller + * @ctrl: target controller returned by pci_target_get() + * + * release the refcount the caller obtained by invoking i3c_target_ctrl_get() + */ +void i3c_target_ctrl_put(struct i3c_target_ctrl *ctrl) +{ + if (!ctrl || IS_ERR(ctrl)) + return; + + module_put(ctrl->ops->owner); + put_device(&ctrl->dev); +} +EXPORT_SYMBOL_GPL(i3c_target_ctrl_put); + +/** + * i3c_target_ctrl_hotjoin() - trigger device hotjoin + * @ctrl: target controller + * + * return: 0: success, others failure + */ +int i3c_target_ctrl_hotjoin(struct i3c_target_ctrl *ctrl) +{ + if (!ctrl || IS_ERR(ctrl)) + return -EINVAL; + + if (!ctrl->ops->hotjoin) + return -EINVAL; + + return ctrl->ops->hotjoin(ctrl); +} +EXPORT_SYMBOL_GPL(i3c_target_ctrl_hotjoin); + +/** + * i3c_target_func_bind() - Notify the function driver that the function device has been bound to a + * controller device + * @func: the function device which has been bound to the controller device + * + * Invoke to notify the function driver that it has been bound to a controller device + */ +int i3c_target_func_bind(struct i3c_target_func *func) +{ + struct device *dev = &func->dev; + int ret; + + if (!func->driver) { + dev_WARN(dev, "func device not bound to driver\n"); + return -EINVAL; + } + + if (!try_module_get(func->driver->owner)) + return -EAGAIN; + + mutex_lock(&func->lock); + ret = func->driver->ops->bind(func); + if (!ret) + func->is_bound = true; + mutex_unlock(&func->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(i3c_target_func_bind); + +/** + * i3c_target_func_unbind() - Notify the function driver that the binding between the function + * device and controller device has been lost. + * @func: the function device which has lost the binding with the controller device. + * + * Invoke to notify the function driver that the binding between the function device and controller + * device has been lost. + */ +void i3c_target_func_unbind(struct i3c_target_func *func) +{ + if (!func->driver) { + dev_WARN(&func->dev, "func device not bound to driver\n"); + return; + } + + mutex_lock(&func->lock); + if (func->is_bound) + func->driver->ops->unbind(func); + mutex_unlock(&func->lock); + + module_put(func->driver->owner); +} +EXPORT_SYMBOL_GPL(i3c_target_func_unbind); + +/** + * i3c_target_func_create() - create a new I3C function device + * @drv_name: the driver name of the I3C function device. + * @name: the name of the function device. + * + * Invoke to create a new I3C function device by providing the name of the function device. + */ +struct i3c_target_func *i3c_target_func_create(const char *drv_name, const char *name) +{ + struct i3c_target_func *func; + struct device *dev; + int ret; + + func = kzalloc(sizeof(*func), GFP_KERNEL); + if (!func) + return ERR_PTR(-ENOMEM); + + dev = &func->dev; + device_initialize(dev); + dev->bus = &i3c_target_func_bus_type; + dev->type = &i3c_target_func_type; + mutex_init(&func->lock); + + ret = dev_set_name(dev, "%s.%s", drv_name, name); + if (ret) { + put_device(dev); + return ERR_PTR(ret); + } + + ret = device_add(dev); + if (ret) { + put_device(dev); + return ERR_PTR(ret); + } + + return func; +} +EXPORT_SYMBOL_GPL(i3c_target_func_create); + +/** + * __i3c_target_func_register_driver() - register a new I3C function driver + * @driver: structure representing I3C function driver + * @owner: the owner of the module that registers the I3C function driver + * + * Invoke to register a new I3C function driver. + */ +int __i3c_target_func_register_driver(struct i3c_target_func_driver *driver, struct module *owner) +{ + int ret = -EEXIST; + + if (!driver->ops) + return -EINVAL; + + if (!driver->ops->bind || !driver->ops->unbind) + return -EINVAL; + + driver->driver.bus = &i3c_target_func_bus_type; + driver->driver.owner = owner; + + ret = driver_register(&driver->driver); + if (ret) + return ret; + + i3c_target_cfs_add_func_group(driver->driver.name); + + return 0; +} +EXPORT_SYMBOL_GPL(__i3c_target_func_register_driver); + +/** + * i3c_target_func_unregister_driver() - unregister the I3C function driver + * @fd: the I3C function driver that has to be unregistered + * + * Invoke to unregister the I3C function driver. + */ +void i3c_target_func_unregister_driver(struct i3c_target_func_driver *fd) +{ + mutex_lock(&func_lock); + mutex_unlock(&func_lock); +} +EXPORT_SYMBOL_GPL(i3c_target_func_unregister_driver); + +static int __init i3c_target_init(void) +{ + int ret; + + i3c_target_ctrl_class = class_create("i3c_target"); + if (IS_ERR(i3c_target_ctrl_class)) { + pr_err("failed to create i3c target class --> %ld\n", + PTR_ERR(i3c_target_ctrl_class)); + return PTR_ERR(i3c_target_ctrl_class); + } + + ret = bus_register(&i3c_target_func_bus_type); + if (ret) { + class_destroy(i3c_target_ctrl_class); + pr_err("failed to register i3c target func bus --> %d\n", ret); + return ret; + } + + return 0; +} +module_init(i3c_target_init); + +static void __exit i3c_target_exit(void) +{ + class_destroy(i3c_target_ctrl_class); + bus_unregister(&i3c_target_func_bus_type); +} +module_exit(i3c_target_exit); + diff --git a/include/linux/i3c/target.h b/include/linux/i3c/target.h new file mode 100644 index 0000000000000..b0bf06685834c --- /dev/null +++ b/include/linux/i3c/target.h @@ -0,0 +1,548 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2023 NXP. + * + * Author: Frank Li + */ + +#ifndef I3C_TARGET_H +#define I3C_TARGET_H + +#include +#include + +struct i3c_target_func; +struct i3c_target_ctrl; + +/** + * struct i3c_target_func_ops - set of function pointers for performing i3c target function + * operations + * @bind: ops to perform when a controller device has been bound to function device + * @unbind: ops to perform when a binding has been lost between a controller device and function + * device + */ +struct i3c_target_func_ops { + int (*bind)(struct i3c_target_func *func); + void (*unbind)(struct i3c_target_func *func); +}; + +/** + * struct i3c_target_func_driver - represents the I3C function driver + * @probe: ops to perform when a new function device has been bound to the function driver + * @remove: ops to perform when the binding between the function device and function driver is + * broken + * @name: I3C Function driver name + * @driver: I3C Function driver + * @ops: set of function pointers for performing function operations + * @owner: the owner of the module that registers the I3C function driver + * @epf_group: list of configfs group corresponding to the I3C function driver + */ +struct i3c_target_func_driver { + int (*probe)(struct i3c_target_func *func); + void (*remove)(struct i3c_target_func *func); + + char *name; + struct device_driver driver; + struct i3c_target_func_ops *ops; + struct module *owner; +}; + +/** + * struct i3c_target_func - represents the I3C function device + * @dev: the I3C function device + * @name: the name of the I3C function device + * @driver: the function driver to which this function device is bound + * @group: configfs group associated with the EPF device + * @lock: mutex to protect i3c_target_func_ops + * @ctrl: binded I3C controller device + * @is_bound: indicates if bind notification to function driver has been invoked + * @vendor_id: vendor id + * @part_id: part id + * @instance_id: instance id + * @ext_id: ext id + * @vendor_info: vendor info + * @static_addr: static address for I2C. It is 0 for I3C. + * @max_write_len: maximum write length + * @max_read_len: maximum read length + * @bcr: bus characteristics register (BCR) + * @dcr: device characteristics register (DCR) + */ +struct i3c_target_func { + struct device dev; + char *name; + struct i3c_target_func_driver *driver; + struct config_group *group; + /* mutex to protect against concurrent access of i3c_target_func_ops */ + struct mutex lock; + struct i3c_target_ctrl *ctrl; + bool is_bound; + + u16 vendor_id; + u16 part_id; + u8 instance_id; + u16 ext_id; + u8 vendor_info; + u16 static_addr; + u16 max_write_len; //0 is hardware default max value + u16 max_read_len; //0 is hardware default max value + u8 bcr; + u8 dcr; +}; + +enum i3c_request_stat { + I3C_REQUEST_OKAY, + I3C_REQUEST_PARTIAL, + I3C_REQUEST_ERR, + I3C_REQUEST_CANCEL, +}; + +/** + * struct i3c_request - represents the an I3C transfer request + * @buf: data buffer + * @length: data length + * @complete: call back function when request finished or cancelled + * @context: general data for complete callback function + * @list: link list + * @status: transfer status + * @actual: how much actually transferred + * @ctrl: I3C target controller associate with this request + * @tx: transfer direction, 1: target to master, 0: master to target + */ +struct i3c_request { + void *buf; + unsigned int length; + + void (*complete)(struct i3c_request *req); + void *context; + struct list_head list; + + enum i3c_request_stat status; + unsigned int actual; + struct i3c_target_ctrl *ctrl; + bool tx; +}; + +/** + * struct i3c_target_ctrl_features - represents I3C target controller features. + * @tx_fifo_sz: tx hardware fifo size + * @rx_fifo_sz: rx hardware fifo size + */ +struct i3c_target_ctrl_features { + u32 tx_fifo_sz; + u32 rx_fifo_sz; +}; + +/** + * struct i3c_target_ctrl_ops - set of function pointers for performing controller operations + * @set_config: set I3C controller configuration + * @enable: enable I3C controller + * @disable: disable I3C controller + * @raise_ibi: raise IBI interrupt to master + * @alloc_request: allocate a i3c_request, optional, default use kmalloc + * @free_request: free a i3c_request, default use kfree + * @queue: queue an I3C transfer + * @dequeue: dequeue an I3C transfer + * @cancel_all_reqs: call all pending requests + * @fifo_status: current FIFO status + * @fifo_flush: flush hardware FIFO + * @hotjoin: raise hotjoin request to master + * @set_status_format1: set i3c status format1 + * @get_status_format1: get i3c status format1 + * @get_addr: get i3c dynmatic address + * @get_features: ops to get the features supported by the I3C target controller + * @owner: the module owner containing the ops + */ +struct i3c_target_ctrl_ops { + int (*set_config)(struct i3c_target_ctrl *ctrl, struct i3c_target_func *func); + int (*enable)(struct i3c_target_ctrl *ctrl); + int (*disable)(struct i3c_target_ctrl *ctrl); + int (*raise_ibi)(struct i3c_target_ctrl *ctrl, void *p, u8 size); + + struct i3c_request *(*alloc_request)(struct i3c_target_ctrl *ctrl, gfp_t gfp_flags); + void (*free_request)(struct i3c_request *req); + + int (*queue)(struct i3c_request *req, gfp_t gfp_flags); + int (*dequeue)(struct i3c_request *req); + + void (*cancel_all_reqs)(struct i3c_target_ctrl *ctrl, bool tx); + + int (*fifo_status)(struct i3c_target_ctrl *ctrl, bool tx); + void (*fifo_flush)(struct i3c_target_ctrl *ctrl, bool tx); + int (*hotjoin)(struct i3c_target_ctrl *ctrl); + int (*set_status_format1)(struct i3c_target_ctrl *ctrl, u16 status); + u16 (*get_status_format1)(struct i3c_target_ctrl *ctrl); + u8 (*get_addr)(struct i3c_target_ctrl *ctrl); + const struct i3c_target_ctrl_features *(*get_features)(struct i3c_target_ctrl *ctrl); + struct module *owner; +}; + +/** + * struct i3c_target_ctrl - represents the I3C target device + * @dev: I3C target device + * @ops: function pointers for performing endpoint operations + * @func: target functions present in this controller device + * @group: configfs group representing the I3C controller device + */ +struct i3c_target_ctrl { + struct device dev; + const struct i3c_target_ctrl_ops *ops; + struct i3c_target_func *func; + struct config_group *group; +}; + +/** + * i3c_target_ctrl_raise_ibi() - Raise IBI to master + * @ctrl: I3C target controller + * @p: optional data for IBI + * @size: size of optional data + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline int i3c_target_ctrl_raise_ibi(struct i3c_target_ctrl *ctrl, void *p, u8 size) +{ + if (ctrl && ctrl->ops && ctrl->ops->raise_ibi) + return ctrl->ops->raise_ibi(ctrl, p, size); + + return -EINVAL; +} + +/** + * i3c_target_ctrl_cancel_all_reqs() - Cancel all pending request + * @ctrl: I3C target controller + * @tx: Transfer diretion queue + */ +static inline void i3c_target_ctrl_cancel_all_reqs(struct i3c_target_ctrl *ctrl, bool tx) +{ + if (ctrl && ctrl->ops && ctrl->ops->cancel_all_reqs) + ctrl->ops->cancel_all_reqs(ctrl, tx); +} + +/** + * i3c_target_ctrl_set_config() - Set controller configuration + * @ctrl: I3C target controller device + * @func: Function device + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline int +i3c_target_ctrl_set_config(struct i3c_target_ctrl *ctrl, struct i3c_target_func *func) +{ + if (ctrl && ctrl->ops && ctrl->ops->set_config) + return ctrl->ops->set_config(ctrl, func); + + return -EINVAL; +} + +/** + * i3c_target_ctrl_enable() - Enable I3C controller + * @ctrl: I3C target controller device + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline int +i3c_target_ctrl_enable(struct i3c_target_ctrl *ctrl) +{ + if (ctrl && ctrl->ops && ctrl->ops->enable) + return ctrl->ops->enable(ctrl); + + return -EINVAL; +} + +/** + * i3c_target_ctrl_disable() - Disable I3C controller + * @ctrl: I3C target controller device + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline int +i3c_target_ctrl_disable(struct i3c_target_ctrl *ctrl) +{ + if (ctrl && ctrl->ops && ctrl->ops->disable) + return ctrl->ops->disable(ctrl); + + return -EINVAL; +} + +/** + * i3c_target_ctrl_alloc_request() - Alloc an I3C transfer + * @ctrl: I3C target controller device + * @gfp_flags: additional gfp flags used when allocating the buffers + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline struct i3c_request * +i3c_target_ctrl_alloc_request(struct i3c_target_ctrl *ctrl, gfp_t gfp_flags) +{ + struct i3c_request *req = NULL; + + if (ctrl && ctrl->ops && ctrl->ops->alloc_request) + req = ctrl->ops->alloc_request(ctrl, gfp_flags); + else + req = kzalloc(sizeof(*req), gfp_flags); + + if (req) + req->ctrl = ctrl; + + return req; +} + +/** + * i3c_target_ctrl_free_request() - Free an I3C transfer + * @req: I3C transfer request + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline void +i3c_target_ctrl_free_request(struct i3c_request *req) +{ + struct i3c_target_ctrl *ctrl; + + if (!req) + return; + + ctrl = req->ctrl; + if (ctrl && ctrl->ops && ctrl->ops->free_request) + ctrl->ops->free_request(req); + else + kfree(req); +} + +/** + * i3c_target_ctrl_queue() - Queue an I3C transfer + * @req: I3C transfer request + * @gfp_flags: additional gfp flags used when allocating the buffers + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline int +i3c_target_ctrl_queue(struct i3c_request *req, gfp_t gfp_flags) +{ + struct i3c_target_ctrl *ctrl; + int ret = -EINVAL; + + if (!req) + return -EINVAL; + + ctrl = req->ctrl; + + req->actual = 0; + req->status = 0; + if (ctrl && ctrl->ops && ctrl->ops->queue) + ret = ctrl->ops->queue(req, gfp_flags); + + return ret; +} + +/** + * i3c_target_ctrl_dequeue() - Dequeue an I3C transfer + * @req: I3C transfer request + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline int +i3c_target_ctrl_dequeue(struct i3c_request *req) +{ + struct i3c_target_ctrl *ctrl; + int ret = -EINVAL; + + if (!req) + return -EINVAL; + + ctrl = req->ctrl; + if (ctrl && ctrl->ops && ctrl->ops->dequeue) + ret = ctrl->ops->dequeue(req); + + return ret; +} + +/** + * i3c_target_ctrl_fifo_status() - Get controller FIFO status + * @ctrl: I3C target controller device + * @tx: 1: Target to master, 0: master to target + * + * Returns: How much data in FIFO + */ +static inline int +i3c_target_ctrl_fifo_status(struct i3c_target_ctrl *ctrl, bool tx) +{ + if (ctrl && ctrl->ops && ctrl->ops->fifo_status) + return ctrl->ops->fifo_status(ctrl, tx); + + return 0; +} + +/** + * i3c_target_ctrl_fifo_flush() - Flush controller FIFO + * @ctrl: I3C target controller device + * @tx: 1: Target to master, 0: master to target + * + */ +static inline void +i3c_target_ctrl_fifo_flush(struct i3c_target_ctrl *ctrl, bool tx) +{ + if (ctrl && ctrl->ops && ctrl->ops->fifo_flush) + return ctrl->ops->fifo_flush(ctrl, tx); +} + +/** + * i3c_target_ctrl_get_features() - Get controller supported features + * @ctrl: I3C target controller device + * + * Returns: The pointer to struct i3c_target_ctrl_features + */ +static inline const struct i3c_target_ctrl_features* +i3c_target_ctrl_get_features(struct i3c_target_ctrl *ctrl) +{ + if (ctrl && ctrl->ops && ctrl->ops->get_features) + return ctrl->ops->get_features(ctrl); + + return NULL; +} + +/** + * i3c_target_ctrl_set_status_format1() - Set controller supported features + * @ctrl: I3C target controller device + * @status: I3C GETSTATUS format1 + * + * Returns: Zero for success, or an error code in case of failure + */ +static inline int +i3c_target_ctrl_set_status_format1(struct i3c_target_ctrl *ctrl, u16 status) +{ + if (ctrl && ctrl->ops && ctrl->ops->set_status_format1) + return ctrl->ops->set_status_format1(ctrl, status); + + return -EINVAL; +} + +/** + * i3c_target_ctrl_get_status_format1() - Get controller supported features + * @ctrl: I3C target controller device + * + * Return: I3C GETSTATUS format1 + */ +static inline u16 +i3c_target_ctrl_get_status_format1(struct i3c_target_ctrl *ctrl) +{ + if (ctrl && ctrl->ops && ctrl->ops->get_status_format1) + return ctrl->ops->get_status_format1(ctrl); + + return 0; +} + +/** + * i3c_target_ctrl_get_addr() - Get controller address + * @ctrl: I3C target controller device + * + * Return: address + */ +static inline u8 i3c_target_ctrl_get_addr(struct i3c_target_ctrl *ctrl) +{ + if (ctrl && ctrl->ops && ctrl->ops->get_addr) + return ctrl->ops->get_addr(ctrl); + + return 0; +} + +#define to_i3c_target_ctrl(device) container_of((device), struct i3c_target_ctrl, dev) + +#define to_i3c_target_func(func_dev) container_of((func_dev), struct i3c_target_func, dev) +#define to_i3c_target_func_driver(drv) (container_of((drv), struct i3c_target_func_driver, driver)) + +#define i3c_target_ctrl_create(dev, ops) \ + __i3c_target_ctrl_create((dev), (ops), THIS_MODULE) +#define devm_i3c_target_ctrl_create(dev, ops) \ + __devm_i3c_target_ctrl_create((dev), (ops), THIS_MODULE) + +#ifdef CONFIG_I3C_TARGET +struct i3c_target_ctrl * +__devm_i3c_target_ctrl_create(struct device *dev, const struct i3c_target_ctrl_ops *ops, + struct module *owner); +struct i3c_target_ctrl * +__i3c_target_ctrl_create(struct device *dev, const struct i3c_target_ctrl_ops *ops, + struct module *owner); + +void devm_i3c_target_ctrl_destroy(struct device *dev, struct i3c_target_ctrl *epc); +void i3c_target_ctrl_destroy(struct i3c_target_ctrl *epc); + +int i3c_target_ctrl_add_func(struct i3c_target_ctrl *ctrl, struct i3c_target_func *func); +void i3c_target_ctrl_remove_func(struct i3c_target_ctrl *ctrl, struct i3c_target_func *func); +int i3c_target_ctrl_hotjoin(struct i3c_target_ctrl *ctrl); + +struct i3c_target_ctrl *i3c_target_ctrl_get(const char *name); +void i3c_target_ctrl_put(struct i3c_target_ctrl *ctrl); + +int i3c_target_func_bind(struct i3c_target_func *func); +void i3c_target_func_unbind(struct i3c_target_func *func); +struct i3c_target_func *i3c_target_func_create(const char *drv_name, const char *name); + +#define i3c_target_func_register_driver(drv) \ + __i3c_target_func_register_driver(drv, THIS_MODULE) + +int __i3c_target_func_register_driver(struct i3c_target_func_driver *drv, struct module *owner); +void i3c_target_func_unregister_driver(struct i3c_target_func_driver *drv); +#else +static inline struct i3c_target_ctrl * +__devm_i3c_target_ctrl_create(struct device *dev, const struct i3c_target_ctrl_ops *ops, + struct module *owner) +{ + return NULL; +} + +static inline struct i3c_target_ctrl * +__i3c_target_ctrl_create(struct device *dev, const struct i3c_target_ctrl_ops *ops, + struct module *owner) +{ + return NULL; +} +#endif + +#ifdef CONFIG_I3C_TARGET_CONFIGFS +struct config_group *i3c_target_cfs_add_ctrl_group(struct i3c_target_ctrl *ctrl); +void i3c_target_cfs_remove_ctrl_group(struct config_group *group); +struct config_group *i3c_target_cfs_add_func_group(const char *name); +void i3c_target_cfs_remove_func_group(struct config_group *group); +#else +static inline struct config_group *i3c_target_cfs_add_ctrl_group(struct i3c_target_ctrl *ctrl) +{ + return NULL; +} + +static inline void i3c_target_cfs_remove_ctrl_group(struct config_group *group) +{ +} + +static inline struct config_group *i3c_target_cfs_add_func_group(const char *name) +{ + return NULL; +} + +static inline void i3c_target_cfs_remove_func_group(struct config_group *group) +{ +} +#endif + +#define DECLARE_I3C_TARGET_FUNC(_name, _probe, _remove, _ops) \ + static struct i3c_target_func_driver _name ## i3c_func = { \ + .driver.name = __stringify(_name), \ + .owner = THIS_MODULE, \ + .probe = _probe, \ + .remove = _remove, \ + .ops = _ops \ + }; \ + MODULE_ALIAS("i3cfunc:" __stringify(_name)) + +#define DECLARE_I3C_TARGET_INIT(_name, _probe, _remove, _ops) \ + DECLARE_I3C_TARGET_FUNC(_name, _probe, _remove, _ops); \ + static int __init _name ## mod_init(void) \ + { \ + return i3c_target_func_register_driver(&_name ## i3c_func); \ + } \ + static void __exit _name ## mod_exit(void) \ + { \ + i3c_target_func_unregister_driver(&_name ## i3c_func); \ + } \ + module_init(_name ## mod_init); \ + module_exit(_name ## mod_exit) + +#endif From patchwork Thu Feb 8 17:01:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550109 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2814C48260 for ; Thu, 8 Feb 2024 17:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WfFwaiRVhFdRpswGxCKtxlCPdT0hgtUbuhjPu1sUo4c=; b=OHlMIR1FHJRj5t YAwEvh4zsypxE8vPf+zF8tuTfvTf/jI3z/7+uBLQWBzf5KkbXbvttifCnEY6Zv9+fFj3I9jRYaXBX fon97C7cnAC6K9aBG7Tpw9fUpcuxaCqgP+f7wVeO/aqmBb4w276GqUx7InubBBIqo1BAv/SfV2r1b RJFHVbo0/BXWekEVUAJ84Oebi5ctWcuQEtreZH5rHSg8Et+8wrxnNWkNSqBrY9+3f+/5lXFfALMkZ hJo5Ou5/BXtthlqFNbgcqvNWlAVTqxE7Hr9O9DAmgUy+5PrLQJykSpEEb7EaxpthDBw+fDcmRWvq6 XsmOsmgxm9FU8UxXIUcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7ni-0000000EOFk-2N4X; Thu, 08 Feb 2024 17:03:03 +0000 Received: from mail-vi1eur05on20600.outbound.protection.outlook.com ([2a01:111:f403:2613::600] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7n5-0000000EO5n-1r2l for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:02:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yfom76iaAAn9jQRXerFbyG7+5Ft01e3LkQODOx5DdkljqaZpQqIRD83lk9+mewczLGhIFEwc52Sq3iYpujvFzHjWdNGirjIafgrRfzw1aCEJGZjufUD4alxd3HuYe9h1A40WZkrTQhgCQaHwnnYff3UqrMPc0pGnjUY+d0c8l9MQZHRKgcCrfCuZ+WelQWmUJJ+izUvDCHxlSdjnxQuOHxVE8otRxijpKsG2p8vcbo2TcVhgQFducaX0FFhATY1tYKTyorbiS/fsZWC7wATI1+3u0GOxNh2xV8gfA3fOQ90U8anUnqa77x8uSkjF4V5oL34XlF6jcOQ3m1Q24gMoqw== 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=xDK4qrtnr5XVTe+ocNEiDTpD8I6wdwaixxJbj5SM/h4=; b=RnQXix5lv52EyjYDghW6BcNelq48lAq6Y9cjMAbclXxXC745FUyXoMaC6gHEIxdGQ/jrenVswtdaISUD9a2b6uBnpgLlTwES+yWhZbFBIcnS1Sks1uQlKdXGVsLdopqEAtM66ydChQdpyivP2ZLXTJ0M53D8+Rh9wOU+EnnNvH+LtVfzAwBCZMbiTZsi218Rfjyt3rWK6/qx+r4Ham3pBvYAOY0pN7jCUTM6ssXLKQMuKhNUQzfj8rVjLJf18U5lAqncrtX5+zdA0znAlkKKmzoPCkor1tOKonpyoMivi2DAeNDl8MhzZqcDqCPL9U1w9B7GiIq+z5ho+MTdYeE5YQ== 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=xDK4qrtnr5XVTe+ocNEiDTpD8I6wdwaixxJbj5SM/h4=; b=OI5GbzEOac6apg9AxhSyzI7gL0orfRfMaa2GigN33GPel304V8Cr3nnWvD7HN9uJ4yliU5ckeBWG+7unF7PzXyYpwIRp18nXvV4iImMwfdTFKjAEYrK2ZBgbddRjQgUjljSCk5HvsMm2L2779pV5GsIzL7sBpLiFrtzPwogiNG4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA4PR04MB9248.eurprd04.prod.outlook.com (2603:10a6:102:2a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Thu, 8 Feb 2024 17:01:44 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:01:44 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 2/8] dt-bindings: i3c: svc: add proptery mode Date: Thu, 8 Feb 2024 12:01:11 -0500 Message-Id: <20240208170117.798357-3-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9248:EE_ X-MS-Office365-Filtering-Correlation-Id: 79b15eeb-d6f5-4845-ee33-08dc28c7a0b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t2RR4z4LncOnBh7EfPqRVfcTDT/SuJXDy3odGvA8ggvsImN5+1aXMUitRDareKUUe1smkRX0vaXx+XfnyofYTIqqZeUwmr0dWpWchjEfXGJYxDgDfnNVKJS6hSvCv+zvPVeFIevVSRwegRA+RgBR1mUnY/ktMojJt+TF4zAZefkQLCyQOL8SlCoepSnMhm0lpXA6K3SFRgJr92ytPBxMoKYFJHoJicE6kQQjNUhvS6u9vj4SEVZ4PNcCA1NXpJiTq6+IL8GA+BZfwKWfFCF3G1I1EY2OGIDIdnW1UmDnyZCV0tAy+sDmbbOYnRd+yO/+L8/yqTOtaraPaKonZA7IlnArs1Ll4iErwR47RoeuHZQ1GtgZvmz3+VXp15EItiGInlME8bpPqZMUYhDRpnt6hdaM4VhLMihRqRiukkW2H8yePvWrYjbbnHJyLEqQ3/3/UdomoshUWZp/7zRjk7h20rczeWpBeGPald574f1ExjE+Gjc50iGzk0NhRHnRrnln4pElQkhmWDiRz7Pjxjg+MzfcwIkQ2h+9pkvHIlQoxPdd7EWqIC8VMb0SxnDJCk1Zj+dGHaeI1YGY3LuOlYcIBWTglrTiiCIRyrLvHVyMK3w= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(38100700002)(6666004)(52116002)(6506007)(83380400001)(37006003)(86362001)(7416002)(41300700001)(1076003)(2616005)(26005)(34206002)(6512007)(36756003)(8676002)(8936002)(4326008)(6486002)(478600001)(2906002)(5660300002)(966005)(66476007)(66946007)(316002)(66556008)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PhYQmYYlRZKYGtpRchv2uzgRg2kBtSKST4veaALJUA3GE6HTR0peByMBuEatMVbhOeUnxHFxGsb6r3SVXZxirJejJlXeVggH1T1yz2hqGqiq+GtY70fBmh4gf3CCVDNJRHeBrGtbwo3JaxwTtIidOaDTvLzofgnUe+BEEbL2M+qgTQwfOk40wDK81kIg13wEWkVPT5rIuxH0STWVh+EpmRuxC8CNm5C/AtdUlQQNno9tiJRkejNjIRLwl/td4McRHfTbDLHeal/Wx47BjXPS3bmHefiDT5fEPkyN7MghCspzgcIi47iTpnL5cHSEMgX2Ti0DcY0dZrbiTyBGobfUuKH5Qm0x5EU2stRjx+nm2X/CcnRwF3YtZ+Jo0HPNUyz6er67j2dfhjfxwp+NHfUYGKkJBJ5SR1qGq4k2KCVckVI73afgVAHwrdPfzFp7D9+UdpaBx6ZupVVPzoOcnTHW6j8JF0iQhdPKheWc0DsuUF8V5m5l9gmmwLfOjZ4fqTNuLjEzHypZa1FdvlXjL6zrnAbJyMjbcf6Ga92zmKjpl3P4RBbqpaCiQxoyyRAjqoCPy7qagZLkCZo9a1OBZNzkT9xjIwSoY6aA4ZOQbhfROMQXLC5VXYlhbpo7xLwNw+AMk6yVuYgNcSVhn3I9xROmOcmZsAqW7TT8Spw5MBV888l0WJ6c8qzreCwmjoeewrQ9QODPX4AjUDMrTSc0Fyxop+qiFAmpPUAjQM0Rh5gcQX11F9U+zcGZEZpyvyIk5oQIKw7SGHEyyM+fNny9vN0Pj7CuMmdHVOF83ak0hJrtU2KigvvJwRCQuUqcvFzxmdKMg4DhFptErGJxv/ia/loww0F0Yy7kz7t4Jf4mb18HKvEbJGOCFFpD66yprp6geZRP68FmE3pDDu9WZDpKoOg5FoOeG/yG1yMEpiYzkk8gSu/3WC4LImZvxfoFEKcPKCT1jJlBc6ruAJNGDm2pZCkdCx9tKKlWcc0/FDyd6U6EMxDwhFbvam/m7DOotUZPGPpei2rFfl1j8VLF7Vxgr9wB680y3fsrtZoOESYmN9Sdk0QkWYNOBQ8143sD53wCX1jJ2/d+dE9AMv4UXplEl5WbZMRc67584rpQJBBZ6kUlrXBYgmQe6g4fY6L9imlrSm2/pdkCSi7b45jA/vDhq8zLiCzAJgQ/oAvtjFopzm9daV7efgMfrcVvEQuVK3WWEfB2gUUrrD39QIVchUaKrQNdzpPsP0vwJXWYB41jFwbpKBWwSEpSJkLfd4/8pGIWHKx2Zz00Jtb8J8cjKKLwqMRRAR2S17SlETfBfOtOyithHlOUKYSiKhPwG+RVejBKBpaYFP80uWekGvBWmX2dh3dG/ZAsX03Ho7Ew/XDye34hgvTlQIKy/aOnBY3TnLrp1Oo6pVcRiBcas2pC/jARN5n23o/EhOj4FKIsoY2aCEhOuHXc+nieC++iuVdT4CZJ7INV5AAXNnQS6D8XJ9LWuTIzFAOaSG07uTTOR0rYzI9TDldH1msnKacWpvQYAi3UoBzKkQKpVbMG3WP6zm/czAJf4+QAu4L7ec2Xy5RASLpJlR6Ojb1CIKh2R6F0u96ttDgq X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 79b15eeb-d6f5-4845-ee33-08dc28c7a0b1 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:01:44.1091 (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: Yjm9NSL8oYO0uv+nehDIpNaTH+SL+2nGzWirMLUs5gBjiwu8IFoOahuTu6+f7HL9LWzC3J0c5xtEPJMFmwLCJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_090228_015535_7135725C X-CRM114-Status: UNSURE ( 9.88 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Add 'mode' property to distinguish between 'controller' and 'target' modes. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Frank Li --- Notes: Change from v4 to v5 - add Krzysztof Kozlowski's review tag Change from v3 to v4 -fix dtb check error Change from v2 to v3 - using 'mode' distringuish master and target mode .../devicetree/bindings/i3c/silvaco,i3c-master.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml b/Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml index 133855f11b4f5..3af77d143f018 100644 --- a/Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml +++ b/Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/i3c/silvaco,i3c-master.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Silvaco I3C master +title: Silvaco I3C master/target maintainers: - Conor Culhane @@ -22,6 +22,15 @@ properties: interrupts: maxItems: 1 + mode: + description: + Tells Dual-Role I3C controllers that we want to work on a particular + mode. In case this attribute isn't passed via DT, I3C controllers + should default to 'controller'. + $ref: /schemas/types.yaml#/definitions/string + enum: [controller, target] + default: controller + clocks: items: - description: system clock From patchwork Thu Feb 8 17:01:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550260 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 829AAC4828F for ; Thu, 8 Feb 2024 18:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=K4VuZJqGGkLJxiZkuAU1rnYFmZ9Ex0tkKle+teKuXDg=; b=23CYdxvW2gCG/h MhleFbq38RJqfR/eSxdaXWCRcj+A2tGRv8p6u3HefRIKX2TxUpGakyERkJsGaayCIRcjao1XceXjT e1WwcfswHXUxeacF3xT/2wnZixsBBcTVwV13WVi/0WsJeqhsaYUAKd56k+MYPtJp+lQitxr5D0uel 2TJvCwLLGY1Z2rLcdB2Y787hTP5REEiLyhXwNbNw79aSkKiNcOUbboDT14Fi9Gx/Z+4t74pw3sLUq CJaG/ytmjAs3Sdy4+J7dcz6DsTOVNW/cW7na7naZXY60Wur4+mysPDXWOHMV1Vaxai4PbWpX/eRT6 dECQvwYdmDH6m/9kPRZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY8x4-0000000EaoP-30BU; Thu, 08 Feb 2024 18:16:46 +0000 Received: from mail-vi1eur05on20601.outbound.protection.outlook.com ([2a01:111:f403:2613::601] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7mm-0000000ENy9-2Lin for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:02:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SjsO17CvkYwM/Za8jTuYYqniMP1opXDUfF/LbLbpc4jyiW8AEV3lcRD1rvyzteWcci16dD8TDHrDRMzbm64MWtiGZS7Ylv1bBmLCQwxrxl1tTLLe2OSd0/3IAb6c7+qpOsWTr2kTL8qb3eMNn+nFdnoL8Vr/TDLi6iw2uGEIZpyKWB8E/Z7bPzupRcfww1T9QIhukwfvU6n2X8oIkW7YSMtyBIR5jPrIN4FsQF8rQnP6DRHhfOVby5wPc434SzD97QoDe9Cuu9jeNY8c2KsnohyDGgSDUp/0wcN6LGEB/4X/if239PwZXP3GRnUV6zumz8qhkN5XmdhLAyFEhhi7Mg== 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=NcAD7n5DFC8zY5SMsqG6DN1S/Q3hAt3IaNHuvXjxowM=; b=oFlg0oquYR+rgfF80tHZz/eANY7IUwITq1c5alIlnIR9iFDLWEOsKrNX4K09frIsWgSoCVeuEOoAy2c/JuyAgOaRVQys9EKM6+ShK6ct5qiBfsVUNiHpP6UfDhjPC8AaYkBMx+TnWPmzxmaqVTZBLWGhGs+G+kUcNm86a9Hn+HfGlaSiOuaYxUIVuLiyw0MtQC3hFuc6YpyGmHuY4PYP1R1+Yh3VXh1z8BJIiYXbc/60J+oPWdsgpvgSCm/vl5GAUawt+5tw2dX5MDY215JfYlfH+9/gchn3rlQsWJTTzR4XeNEAPg2yfPqGUK9/1vbPWdPF/rQZ1/MIdhtZBSXx7Q== 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=NcAD7n5DFC8zY5SMsqG6DN1S/Q3hAt3IaNHuvXjxowM=; b=pF27gAZKXB7efb5prm8LDkEIdhN0NQL1ROTaw4urWxM9Y03z9eLlkaqtjV4qNOlHobmRO942+7LgoN7y3DyM8INHXkhfBKGNuNuaaMRvsF7lJLLcaiyMkfqeEr4m/+7RW/Uq4s9AaGJ8b3qcmMvTpekVua5NfbjDEL5mGWZ60fk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA4PR04MB9248.eurprd04.prod.outlook.com (2603:10a6:102:2a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Thu, 8 Feb 2024 17:01:48 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:01:48 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 3/8] Documentation: i3c: Add I3C target mode controller and function Date: Thu, 8 Feb 2024 12:01:12 -0500 Message-Id: <20240208170117.798357-4-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9248:EE_ X-MS-Office365-Filtering-Correlation-Id: bc82f11f-df49-4a2c-c170-08dc28c7a334 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EW1Uu2wA5+cUMV+Vpot9boM12mJKpRwLvOE0rRNKP5ENagTri+SHeXXpfG0NOADTnAN1oZnTLq9T22c8CSHc0+7V9hc/VMScTfpY2ELbYdTvn03wOGaWGyqGMY7YY4tRDJKJ8AjX3hH3i5m0Ia0XCR++1WGLwbc6kyrTBYCRjbF6p0yLFrW6YgW0WdmpRtCwfPpkfbzI8ZA98K/SM3qbw5ezCEy7C/NuLMvRswa59Pw7iF+Eq+5B08PoAVK0hI4uoaaWlY+FheraO0BYVA6VO5Ugx5siPYx5WrDfMbeiGQh/lOZng30eXid3/dN4wK3hFiDNnOBUwTF/NLWLbclkITjSHdUoI/18HbDGxpsaThoOSGyMZmUGApgdrwSL7O0cJuXjmjMME48RB1StcVf1Gt770DKEtUrWsPSgPebshJtRiQLVs5HnVmEY9kkD7sC36ISvupSLzzSB1C0TGZAwtDvGtlQE2Hl+GKDRaBhgAQl25VAXtU3iQ3ht/Qaj811Fn0Q5WvmWcJFmX9pfpq1rooxzSSCJcOQVsEslR7VuNwUQu/cs2f3cvvxdaDXsZfohKnC2Sqx9DLw8xTeRBle0tyO1qg7ljRMlU0KYVP01q3p/Ki4LDAMYNDVgN/eT26GH X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(38100700002)(6666004)(52116002)(6506007)(83380400001)(37006003)(86362001)(7416002)(41300700001)(1076003)(2616005)(26005)(34206002)(6512007)(36756003)(8676002)(8936002)(4326008)(6486002)(478600001)(2906002)(30864003)(5660300002)(66476007)(66946007)(316002)(66556008)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Jrk/jb30LEsA4Wc3yTNpXLwa7IPIdkE1sUKkUe8ohyU/mVVUCB60l7fBkRsoo4rLShmRzsmrGnnG7ID4Bg3aD7iyid/KY98KStepSYVoCut3yv22BvxMVgQTRS2AV7dikHjJKpx7AdKgVUpXwtevpCSAdKOls50sNsrozUFnTElTaIO7uqM9OIv3bEUmeGWO2JHiClwLK+iIR3GdXly0rZCT9/uQ+p1f7fH5eBntUKr9m7+QHrbMfJotVzD00DSdUwAyOYUH3pXLghs4RlM9IJfc09lS68Gsy+VcRljDENkOieXxay5+UTMpZdUvXkLSqigswtRuAsvQSf9PYrjVczvmtGPV1rjHFpRa17MhAvHD6o7Zao4F+sdhQoW5EKgO50EZdXOY01Yu4iHqMrBwHw5HI+JvHJcnmGoLNIm1ZlSWxvL1crA3VkYB8xDoTpw9evF3AWr6MO450/hOc3ukYE0d5ZI/vLQ6ZU/55EM2SWARY2Jn1wRtLgnqiLkSmV0CxniJP8V/8Nq2I0z/rlP7rlncniRRcGDSqT9cMexv11Ji7afhk7kF+KSkGL8RBD3+jKU1jblMaWDQEOntKYxUhz+fvHCVieRhMd620P3BfE7SkDtTBgDjxucLTct5/1w/OOl/6lRcCQieRQs0OKz7N7s+deM2JRZ4yKJEWbRmuiXEZrKcN0pprQ/nUNX0ul9PJ/zENuQHk1ZHrACgJmUod/8WU7mgLAOZjafqe96wWbKcwGxGAzRV1yeePEbkg9NsToWsfdrrNbjyEtiift7VkTbdXFPzKwBHD2cm5060F2w5quKphv9NhsIcSx5Lx4JDxO9TA8xFb33bo0ZC1SBWm1SoHKDHPZylmyr592AT/SK9mSNkKZVos1Ip2P1CeNx3gRidTuXE6VAZoqju9eoAM7wCuOBSqk4wvD3gfL7DULT6gG1Z0t2oUfXBYFndsTIB4xEa80hCTWoB3bcFpb6eNJk+zWOGC04elwNd/gzi4aRNn1w8XmvTGKrKoTlAjK2uxkLIVvyJ4QaSr7aB2qmHSVuR8cO9ymxYmsZp4lmPa/5zVvPwevWYI8ucirym7lbw942nYTh8AzpWb4a+FX09FDzSCpSLjJa/aw8HYVXX8EsaQtux5HQJ+rZfTU+gjvNPLOCu0fEYmDusuVIablnA/EEgHn5gUzXDx1w13SgHBvlSLJZdWHXjW5FaNokul8TMbzN+K3AtDPt43EUQeP1gCcpTcVoVptiHI4/kk4sx1f/o2mCjgQWBb9hqR/HOr6E9hlepBBLxa1l4gZ9Zkw8wjpZUIfk4zt8zbRHBxk+YF1CQhvxIgO79+/aUcGlpbUwr7jmtdC8qe0qRp0NyPuhboKQKfkZVEMPNOkxkLbVowX9SV/GbMnxOqq3R7ZQYe5rdJdNeMmzLkFZjCBsfUIYNBUnpRSujNWp+0tQky7Im8DaX5A86yB4qANrttyakKNi0jbaVbnmxMxUAEc2/L2phX5KyCUBrQxso0roJRpQBEovbWrWQTOuJnALBtpLlBf5jcMGXr5VCCtfr4ZJLjgreZjZC4KBTazuSxM4d+obaaLgVR85kpRHb37EcZIoAea5i X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc82f11f-df49-4a2c-c170-08dc28c7a334 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:01:48.4316 (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: ioORrWEEYLF8nG+iqKIz3nvSRqkv06ALY1xfgZp7RGih/HfAfFoggBfysk4xrTKUks/i6OvrJX9rqq3wNc/yKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_090208_029748_C4E5765B X-CRM114-Status: GOOD ( 22.07 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Add I3C target mode and tty over i3c func driver document. Signed-off-by: Frank Li --- Documentation/driver-api/i3c/index.rst | 1 + .../driver-api/i3c/target/i3c-target-cfs.rst | 109 ++++++++++ .../driver-api/i3c/target/i3c-target.rst | 189 ++++++++++++++++++ .../driver-api/i3c/target/i3c-tty-howto.rst | 109 ++++++++++ Documentation/driver-api/i3c/target/index.rst | 13 ++ 5 files changed, 421 insertions(+) create mode 100644 Documentation/driver-api/i3c/target/i3c-target-cfs.rst create mode 100644 Documentation/driver-api/i3c/target/i3c-target.rst create mode 100644 Documentation/driver-api/i3c/target/i3c-tty-howto.rst create mode 100644 Documentation/driver-api/i3c/target/index.rst diff --git a/Documentation/driver-api/i3c/index.rst b/Documentation/driver-api/i3c/index.rst index 783d6dad054b6..345a43c9f61b0 100644 --- a/Documentation/driver-api/i3c/index.rst +++ b/Documentation/driver-api/i3c/index.rst @@ -9,3 +9,4 @@ I3C subsystem protocol device-driver-api master-driver-api + target/index diff --git a/Documentation/driver-api/i3c/target/i3c-target-cfs.rst b/Documentation/driver-api/i3c/target/i3c-target-cfs.rst new file mode 100644 index 0000000000000..1fcf829dc4ae2 --- /dev/null +++ b/Documentation/driver-api/i3c/target/i3c-target-cfs.rst @@ -0,0 +1,109 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================================= +Configuring I3C Target Using CONFIGFS +======================================= + +:Author: Frank Li + +The I3C Target Core exposes configfs entry (i3c_target) to configure the I3C +target function and to bind the target function with the target controller. +(For introducing other mechanisms to configure the I3C Target Function refer to +[1]). + +Mounting configfs +================= + +The I3C Target Core layer creates i3c_target directory in the mounted configfs +directory. configfs can be mounted using the following command:: + + mount -t configfs none /sys/kernel/config + +Directory Structure +=================== + +The i3c_target configfs has two directories at its root: controllers and +functions. Every Controller device present in the system will have an entry in +the *controllers* directory and every Function driver present in the system will +have an entry in the *functions* directory. +:: + + /sys/kernel/config/i3c_target/ + .. controllers/ + .. functions/ + +Creating Function Device +=================== + +Every registered Function driver will be listed in controllers directory. The +entries corresponding to Function driver will be created by the Function core. +:: + + /sys/kernel/config/i3c_target/functions/ + .. / + ... / + ... / + ... / + .. / + ... / + ... / + +In order to create a of the type probed by , +the user has to create a directory inside . + +Every directory consists of the following entries that can be +used to configure the standard configuration header of the target function. +(These entries are created by the framework when any new is +created) +:: + + .. / + ... / + ... vendor_id + ... part_id + ... bcr + ... dcr + ... ext_id + ... instance_id + ... max_read_len + ... max_write_len + ... vendor_info + +Controller Device +========== + +Every registered Controller device will be listed in controllers directory. The +entries corresponding to Controller device will be created by the Controller +core. +:: + + /sys/kernel/config/i3c_target/controllers/ + .. / + ... / + .. / + ... / + +The directory will have a list of symbolic links to +. These symbolic links should be created by the user to +represent the functions present in the target device. Only +that represents a physical function can be linked to a Controller device. + +:: + + | controllers/ + | / + | + | functions/ + | / + | / + | vendor_id + | part_id + | bcr + | dcr + | ext_id + | instance_id + | max_read_len + | max_write_len + | vendor_info + +[1] Documentation/I3C/target/pci-target.rst diff --git a/Documentation/driver-api/i3c/target/i3c-target.rst b/Documentation/driver-api/i3c/target/i3c-target.rst new file mode 100644 index 0000000000000..09ae26b1f311a --- /dev/null +++ b/Documentation/driver-api/i3c/target/i3c-target.rst @@ -0,0 +1,189 @@ +.. SPDX-License-Identifier: GPL-2.0 + +:Author: Frank Li + +This document is a guide to use the I3C Target Framework in order to create +target controller driver, target function driver, and using configfs interface +to bind the function driver to the controller driver. + +Introduction +============ + +Linux has a comprehensive I3C subsystem to support I3C controllers that +operates in master mode. The subsystem has capability to scan I3C bus,assign +i3c device address, load I3C driver (based on Manufacturer ID, part ID), +support other services like hot-join, In-Band Interrupt(IBI). + +However the I3C controller IP integrated in some SoCs is capable of operating +either in Master mode or Target mode. I3C Target Framework will add target mode +support in Linux. This will help to run Linux in an target system which can +have a wide variety of use cases from testing or validation, co-processor +accelerator, etc. + +I3C Target Core +================= + +The I3C Target Core layer comprises 3 components: the Target Controller +library, the Target Function library, and the configfs layer to bind the target +function with the target controller. + +I3C Target Controller Library +------------------------------------ + +The Controller library provides APIs to be used by the controller that can +operate in target mode. It also provides APIs to be used by function +driver/library in order to implement a particular target function. + +APIs for the I3C Target controller Driver +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This section lists the APIs that the I3C Target core provides to be used by the +I3C controller driver. + +* devm_i3c_target_ctrl_create()/i3c_target_ctrl_create() + + The I3C controller driver should implement the following ops: + + * set_config: ops to set i3c configuration + * enable: ops to enable controller + * disable: ops to disable controller + * raise_ibi: ops to raise IBI to master controller + * alloc_request: ops to alloc a transfer request + * free_request: ops to free a transfer request + * queue: ops to queue a request to transfer queue + * dequeue: ops to dequeue a request from transfer queue + * cancel_all_reqs: ops to cancel all request from transfer queue + * fifo_status: ops to get fifo status + * fifo_flush: ops to flush hardware fifo + * get_features: ops to get controller supported features + + The I3C controller driver can then create a new Controller device by + invoking devm_i3c_target_ctrl_create()/i3c_target_ctrl_create(). + +* devm_i3c_target_ctrl_destroy()/i3c_target_ctrl_destroy() + + The I3C controller driver can destroy the Controller device created by + either devm_i3c_target_ctrl_create() or i3c_target_ctrl_create() using + devm_i3c_target_ctrl_destroy() or i3c_target_ctrl_destroy(). + +I3C Target Controller APIs for the I3C Target Function Driver +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This section lists the APIs that the I3C Target core provides to be used by the +I3C target function driver. + +* i3c_target_ctrl_set_config() + + The I3C target function driver should use i3c_target_ctrl_set_config() to + write i3c configuration to the target controller. + +* i3c_target_ctrl_enable()/i3c_target_ctrl_disable() + + The I3C target function driver should use i3c_target_ctrl_enable()/ + i3c_target_ctrl_disable() to enable/disable i3c target controller. + +* i3c_target_ctrl_alloc_request()/i3c_target_ctrl_free_request() + + The I3C target function driver should usei3c_target_ctrl_alloc_request() / + i3c_target_ctrl_free_request() to alloc/free a i3c request. + +* i3c_target_ctrl_raise_ibi() + + The I3C target function driver should use i3c_target_ctrl_raise_ibi() to + raise IBI. + +* i3c_target_ctrl_queue()/i3c_target_ctrl_dequeue() + + The I3C target function driver should use i3c_target_ctrl_queue()/ + i3c_target_ctrl_dequeue(), to queue/dequeue I3C transfer to/from transfer + queue. + +* i3c_target_ctrl_get_features() + + The I3C target function driver should use i3c_target_ctrl_get_features() to + get I3C target controller supported features. + +Other I3C Target Controller APIs +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +There are other APIs provided by the Controller library. These are used for +binding the I3C Target Function device with Controlller device. i3c-cfs.c can +be used as reference for using these APIs. + +* i3c_target_ctrl_get() + + Get a reference to the I3C target controller based on the device name of + the controller. + +* i3c_target_ctrl_put() + + Release the reference to the I3C target controller obtained using + i3c_target_ctrl_get() + +* i3c_target_ctrl_add_func() + + Add a I3C target function to a I3C target controller. + +* i3c_target_ctrl_remove_func() + + Remove the I3C target function from I3C target controller. + +I3C Target Function Library +---------------------------------- + +The I3C Target Function library provides APIs to be used by the function driver +and the Controller library to provide target mode functionality. + +I3C Target Function APIs for the I3C Target Function Driver +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This section lists the APIs that the I3C Target core provides to be used +by the I3C target function driver. + +* i3c_target_func_register_driver() + + The I3C Target Function driver should implement the following ops: + * bind: ops to perform when a Controller device has been bound to + Function device + * unbind: ops to perform when a binding has been lost between a + Controller device and Function device + + The I3C Function driver can then register the I3C Function driver by using + i3c_target_func_register_driver(). + +* i3c_target_func_unregister_driver() + + The I3C Function driver can unregister the I3C Function driver by using + i3c_epf_unregister_driver(). + +APIs for the I3C Target Controller Library +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This section lists the APIs that the I3C Target core provides to be used by the +I3C target controller library. + +Other I3C Target APIs +~~~~~~~~~~~~~~~~~~~~ + +There are other APIs provided by the Function library. These are used to notify +the function driver when the Function device is bound to the EPC device. +i3c-cfs.c can be used as reference for using these APIs. + +* i3c_target_func_create() + + Create a new I3C Function device by passing the name of the I3C EPF device. + This name will be used to bind the Function device to a Function driver. + +* i3c_target_func_destroy() + + Destroy the created I3C Function device. + +* i3c_target_func_bind() + + i3c_target_func_bind() should be invoked when the EPF device has been bound + to a Controller device. + +* i3c_target_func_unbind() + + i3c_target_func_unbind() should be invoked when the binding between EPC + device and function device is lost. diff --git a/Documentation/driver-api/i3c/target/i3c-tty-howto.rst b/Documentation/driver-api/i3c/target/i3c-tty-howto.rst new file mode 100644 index 0000000000000..43a129b18e938 --- /dev/null +++ b/Documentation/driver-api/i3c/target/i3c-tty-howto.rst @@ -0,0 +1,109 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================== +I3C TTY User Guide +=================== + +:Author: Frank Li + +This document is a guide to help users use i3c-target-tty function driver and +i3ctty master driver for testing I3C. The list of steps to be followed in the +master side and target side is given below. + +Endpoint Device +=============== + +Endpoint Controller Devices +--------------------------- + +To find the list of target controller devices in the system:: + + # ls /sys/class/i3c_target/ + 44330000.i3c-target + +If CONFIG_I3C_SLAVE_CONFIGFS is enabled:: + + # ls /sys/kernel/config/i3c_target/controllers/ + 44330000.i3c-target + + +Endpoint Function Drivers +------------------------- + +To find the list of target function drivers in the system:: + + # ls /sys/bus/i3c_target_func/drivers + tty + +If CONFIG_I3C_SLAVE_CONFIGFS is enabled:: + + # ls /sys/kernel/config/i3c_target/functions + tty + + +Creating i3c-target-tty Device +---------------------------- + +I3C target function device can be created using the configfs. To create +i3c-target-tty device, the following commands can be used:: + + # mount -t configfs none /sys/kernel/config + # cd /sys/kernel/config/i3c_target/ + # mkdir functions/tty/func1 + +The "mkdir func1" above creates the i3c-target-tty function device that will +be probed by i3c tty driver. + +The I3C target framework populates the directory with the following +configurable fields:: + + # ls functions/tty/func1 + bcr dcr ext_id instance_id max_read_len max_write_len + part_id vendor_id vendor_info + +The I3C target function driver populates these entries with default values when +the device is bound to the driver. The i3c-target-tty driver populates vendorid +with 0xffff and interrupt_pin with 0x0001:: + + # cat functions/tty/func1/vendor_id + 0x0 + +Configuring i3c-target-tty Device +------------------------------- + +The user can configure the i3c-target-tty device using configfs entry. In order +to change the vendorid, the following commands can be used:: + + # echo 0x011b > functions/tty/func1/vendor_id + # echo 0x1000 > functions/tty/func1/part_id + # echo 0x6 > functions/tty/t/bcr + +Binding i3c-target-tty Device to target Controller +------------------------------------------------ + +In order for the target function device to be useful, it has to be bound to a +I3C target controller driver. Use the configfs to bind the function device to +one of the controller driver present in the system:: + + # ln -s functions/tty/func1 controllers/44330000.i3c-target/ + +I3C Master Device +================ + +Check I3C tty device is probed + + # ls /sys/bus/i3c/devices/0-23610000000 + 0-23610000000:0 bcr dcr driver dynamic_address hdrcap + modalias pid power subsystem tty uevent + +Using Target TTY function Device +----------------------------------- + +Host side: + cat /dev/ttyI3C0 +Target side + echo abc >/dev/ttyI3C0 + +You will see "abc" show at console. + +You can use other tty tool to test I3C target tty device. diff --git a/Documentation/driver-api/i3c/target/index.rst b/Documentation/driver-api/i3c/target/index.rst new file mode 100644 index 0000000000000..56eabfae83aa4 --- /dev/null +++ b/Documentation/driver-api/i3c/target/index.rst @@ -0,0 +1,13 @@ +.. SPDX-License-Identifier: GPL-2.0 + +====================== +I3C Target Framework +====================== + +.. toctree:: + :maxdepth: 2 + + i3c-target + i3c-target-cfs + i3c-tty-howto + From patchwork Thu Feb 8 17:01:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550111 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84AEDC48260 for ; Thu, 8 Feb 2024 17:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3UfbXmZRct5DiM77z3OMRdKJnQPbiecuhGgnio76jgw=; b=Kze9R/qAOBBBY0 uQynzK95GFJheuR4pscGALVqhwbU8rkxcejeFnM3uW3cvRHX8f+vIfF9WwxQOLHyD+yaR53Jad6Ae DtbKM0/CgUgUX9GHGv7c3+vmFOTprhVM1txvmdKVwlGVBawq0t7mpEkHp0A8H/9gBuslMsZTnRp9q hmZAc6mDi6Av/8VQTWDfgiSxxq5bixc+pTw2JGir+B2N4fShZ3TD8c8oMFsWv0wzdVZaqtI4WS9EJ nY2a0+m61Q4JKxyVQ0UsGRIqDZc8t3WCrkK/oFW5WzheIZXL1s84KVyOCLxtN+G52+VW51TM7mini fHiVExbeqcyTQF67mCSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7nw-0000000EOKo-4BQg; Thu, 08 Feb 2024 17:03:17 +0000 Received: from mail-vi1eur05on20601.outbound.protection.outlook.com ([2a01:111:f403:2613::601] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7nD-0000000ENy9-1Zxb for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:02:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PkLOQ3LhKX9GTlANxd6YojrLhXyMsYiiTfFmwTu9JQE4Q+oQ/DSuIc6HcEjD7RidrqiiyLuYymmjCIgv8q+AA87dJI8teRv4vf/iHTYAsKvHcmxdT7NPGebVeqi5inkt+bEXvs9DwwapRJW5p4Sn4HRRLFT1WUFscHzHJHqbNEpJ/WCHQgpNThjOBfExHpN0kp3VyIO2pGnTpLpMckSoS2f4xBdITdg3ZNXvwh6CbpQ/DopFb9gsURprLMfIDSzq3nJh2vA+ISoOA3ivsPmhuN0frEoDIbk3HdZwnt4c3dDkF3sgxGza7Sk4aX3NVFs2UKpWImBn/+JK4d5UArQjDQ== 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=weZJEbDsJ4Sl/mO/kzAmO46dRq4XMRwLtJczW+bxKko=; b=Tv5OJrIghW6UbG+wdUKOC/REUanFrK6JfrK87QaP1ZTH0XdTFI1ILwlX2t6iazEgF8+Ohc0b0yV58IcDuELWYwufZb17F4b6sBWqGWz3T3M51wUExiWGVBtDGOz8pvgKMRc6e1Odck6/oI14BdUWspEDf0StZAXbLL/yBU4+COm8Nv21tVo9ZDz7lGhr9lkY5x5yQ/x0z8tlNzWBRoX1i8lbDjHBhmBkCoV6pEMGsx2yBmaVjjOzzOBp9ReNwC9mmcfmL8Gc0d8Ll6toOOm/BCYD/dCgRlfwAuAOqQn6Muj8Or+QcqeLU8aDq4gNxOErMAZImaQ/YwbHTaD+aLLdPg== 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=weZJEbDsJ4Sl/mO/kzAmO46dRq4XMRwLtJczW+bxKko=; b=ORXgumF6gxvP9lbYp9xAL9DyZ0to+X/rd1r9v/xApYSuqMioJVBgJWsWXIQPl5vAIJGiOHf6vBPNUt5VXBOcKpU6E1Q1wgZ668gCkxCtqf4yMfS07PxiP81bSLmerAhNZ5AFlnmJq4/EMRBjNVwFTR32DqqOL/3WvyVnQQSUReM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA4PR04MB9248.eurprd04.prod.outlook.com (2603:10a6:102:2a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Thu, 8 Feb 2024 17:01:52 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:01:52 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 4/8] i3c: svc: Add svc-i3c-main.c and svc-i3c.h Date: Thu, 8 Feb 2024 12:01:13 -0500 Message-Id: <20240208170117.798357-5-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9248:EE_ X-MS-Office365-Filtering-Correlation-Id: 8de0a646-10fe-469c-176d-08dc28c7a5e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d47qnVLFT+ezrse3EdrfG9LPl0m7PomFCF2eJDm/JGvlkKq553Cs6znSv68rCDZRdfcOabJHBlhYQGI59aefnodrXLs83io3NX8wi0HdKGrGYdC5k4v0OFXvK39o73g9+18/wkvX/SiXnXfOhS5XIbyMsDD7Avxx3cBjeG7maVG8+eVfO6RAxa3oeI7EWg+QXN5ZF2t8rin6Gc/4I97qAdWcXEW46N4BglXXBJWE0kuS2FBeaa3+EwGm+ODvQcVkqmfXuI4jLWtwBHgh/gRJxWz/nDUFk0aU+PWbuTw4TVfD93XTX2NZOXvNCEnm6ykmAt/tyrqtiJg+VTzJ27SpM8B3Y6+uBOxU/n8uiXu0R4GTPF+uoCEjIXG7BcaUih11A6NVT4AkzpbT//+rXK5w+8dWTkNZ9pROsD90XvlB2T0yMm7ZBP4X91i3fSc/lSafx653eQ6kpr+6VEIDfCuhpuGAnPB9fRGjhhm57GSu6QaQpBRtrUxsKuC6+TbzHbEYy4eOm5NSq0QxUux+0KTCMuKgXFWkc+xjpr8xS62DpL2TEpsn7WcKLSo73BdSX7v8Tvddb0kBeHH7N+PZ8z5JlgJAobqWO19VE7erbH/aJnU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(38100700002)(6666004)(52116002)(6506007)(83380400001)(37006003)(86362001)(7416002)(41300700001)(1076003)(2616005)(26005)(34206002)(6512007)(36756003)(8676002)(8936002)(4326008)(6486002)(478600001)(2906002)(5660300002)(66476007)(66946007)(316002)(66556008)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fvt3sECGJbnpDWdmlWV8OCsoa8CfAD2996ZT7VgKA7dcV27DNRl5b2JnJhGivxHX4u046ISo4pxHxNFc+3CRn7Y7XMJidLmwQg7HkPS75xFzwjVEN7024McP6AJ2B5Quz83EMnOQH4Y1VrTpZZchlN7CynPKBAxOntXH9IEle+tOkRWmIt1gDHQhhT0v98/mjkC/fCaMykEkTY5W95HEcfXhtEbvpUIOh4DRk9SVFtsaxa96ObMNvMALfCVM62P2LrJLMROkDk57oZaZZCuD8Pl7qokeXQUHee1BhbA5dMGy/M73gq7iceX+rkhokZfrv7WR5itYaJfHkcz1BqdMdU2HVbBttlj5YmKO2KVUHajdWtr5d52kJDDEl8V/J5XpqS6R2fiP4u/O0J3Nsa67Fb9UHiRhgj7UQ88cfGO9+TetdkfeQlZjgN3j+7H0TLPA32yAWJ2EQWwjHVH6E5bSPp51y8wmkdJM29g8ztOVlCT7QSYbUC/dN5UcqXLWFos53GTsI/wtu8hpI0SAQiK34PAYqic+9BFT1zZDdI89Cv4g7srn7/faSHJ5nkAhT+LX6xX+uCzTlChv9YVX0bwoRy446N2Kj2n1H7vER8Wv+7v+Txxy2b9dpGGMzo78Fh6lpU5zss9d+gv9M5a7Wc5gcy5qDTjRnRvISIpRmA4rqo4hhL7Y8tHpQfxF/s8jMnJKgSpCIJzMaS4gj0fyK9dKgoXYGsCuP3w7ZW4gP9gEj0K8kmy4pbJYzwUuE1K1iOcnIWlObqfHWpMzkLN8mjEI0sNlzv4I8wM0+giICxCXhR3sgqpQoj+ON3DPgfvWxQHbVHGTQU57T4br7VE+2MQkbS4vKwTK42I6pW1Qi7XZSC3NYZxfeUolp1ePwO1CjpbdsjDOtmDwQIYEFflEA2n2yv8p4Uvlqe8sidCtO9T5W922hwQ/jRcv7mivl6udyZ9Y2riCb6kcnXaqwTGZFIFelUbGg/OyyqAy5uRFjMkOR3gnPxJpXlUqbF9OjmnOGBbpxQC9Xm6ykMb9LcJ3SsclaHslCNvku1DS+Oo5pBdzDHh+maIBtazCxts+3Gqarx+blRqBYqShxSyQB34ZB4zplqhaE1A+8l0GCxYb/H/MeD4BPw7C1Bg+EJUk9SNq5EXnTgqdMXC6GwE/HxsQvrXFCya0YoKohz0GCuh1qxMUYNDpBtjfVwdt5RTSfQ8ZZhtGCOeqtE4Ycpuy+9aZevjMUeYlfNCkfba3DvxkqK9UBlGgXn4A/7BA41mVVXOsAU4dfk49S1/uCXXpNQTwYaby0Y0oegW9p68+QvQLyCaYWwtQs/AcD6NXagh4UNbm87v2swMtENCahGKLnq5t8b+jMF8jD2u/SRcLDQwJye7gtgEpRvnhxeR+gOZoNdeZp3NZio4jeturBCv7GYtyAOgBJWkK8AhoQosoWSSB8hSDZuZllqnGyun2hwo1n7czvN4t2Vmm3nAWEljK0f/3UYfpwN0FpliNL4BwUSl7GTasgmwU4FXrZw+b0Sd25u7OZSY88H+ozC+iDQbcpt+lNwxiGDTOdaxYL2Dd7wvHqao43ywrkvtbD5AXgp4OevSljSGV X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8de0a646-10fe-469c-176d-08dc28c7a5e6 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:01:52.8191 (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: 7Nlrp1tg2JIMHeWIlneKjixz/DW6H/tYJ0iQVcSW8Uo4qLMKfVvDQfCYZD/Y3izBetmK0elUeO4bYAMD0/21aw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_090231_781997_CCF42BDB X-CRM114-Status: GOOD ( 18.50 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org SVC i3c is a dual role controller. Move probe() into svc-i3c-main.c. This prepares to support target probe depending on dts "mode" settings. Signed-off-by: Frank Li --- Notes: Change from v6 to v7 - using /* SPDX-License-Identifier */ for svc-i3c.h Change from v5 to v6 - none Change from v4 to v5 - add new line at end of file New file from v4 drivers/i3c/master/Makefile | 3 +- drivers/i3c/master/svc-i3c-main.c | 53 +++++++++++++++++++++++++++++ drivers/i3c/master/svc-i3c-master.c | 34 ++++-------------- drivers/i3c/master/svc-i3c.h | 12 +++++++ 4 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 drivers/i3c/master/svc-i3c-main.c create mode 100644 drivers/i3c/master/svc-i3c.h diff --git a/drivers/i3c/master/Makefile b/drivers/i3c/master/Makefile index 3e97960160bc8..484cb81f45821 100644 --- a/drivers/i3c/master/Makefile +++ b/drivers/i3c/master/Makefile @@ -2,5 +2,6 @@ obj-$(CONFIG_CDNS_I3C_MASTER) += i3c-master-cdns.o obj-$(CONFIG_DW_I3C_MASTER) += dw-i3c-master.o obj-$(CONFIG_AST2600_I3C_MASTER) += ast2600-i3c-master.o -obj-$(CONFIG_SVC_I3C_MASTER) += svc-i3c-master.o +svc-i3c-objs += svc-i3c-main.o svc-i3c-master.o +obj-$(CONFIG_SVC_I3C_MASTER) += svc-i3c.o obj-$(CONFIG_MIPI_I3C_HCI) += mipi-i3c-hci/ diff --git a/drivers/i3c/master/svc-i3c-main.c b/drivers/i3c/master/svc-i3c-main.c new file mode 100644 index 0000000000000..6be6a576cdf7a --- /dev/null +++ b/drivers/i3c/master/svc-i3c-main.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include + +#include "svc-i3c.h" + +static int svc_i3c_probe(struct platform_device *pdev) +{ + return svc_i3c_master_probe(pdev); +} + +static void svc_i3c_remove(struct platform_device *pdev) +{ + svc_i3c_master_remove(pdev); +} + +static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev) +{ + return svc_i3c_master_runtime_suspend(dev); +} + +static int __maybe_unused svc_i3c_runtime_resume(struct device *dev) +{ + return svc_i3c_master_runtime_resume(dev); +} + +static const struct dev_pm_ops svc_i3c_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(svc_i3c_runtime_suspend, + svc_i3c_runtime_resume, NULL) +}; + +static const struct of_device_id svc_i3c_master_of_match_tbl[] = { + { .compatible = "silvaco,i3c-master-v1"}, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, svc_i3c_master_of_match_tbl); + +static struct platform_driver svc_i3c_master = { + .probe = svc_i3c_probe, + .remove_new = svc_i3c_remove, + .driver = { + .name = "silvaco-i3c-master", + .of_match_table = svc_i3c_master_of_match_tbl, + .pm = &svc_i3c_pm_ops, + }, +}; +module_platform_driver(svc_i3c_master); + diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 5ee4db68988e2..4dfe85ab17fd2 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -21,6 +21,8 @@ #include #include +#include "svc-i3c.h" + /* Master Mode Registers */ #define SVC_I3C_MCONFIG 0x000 #define SVC_I3C_MCONFIG_MASTER_EN BIT(0) @@ -1613,7 +1615,7 @@ static void svc_i3c_master_unprepare_clks(struct svc_i3c_master *master) clk_disable_unprepare(master->sclk); } -static int svc_i3c_master_probe(struct platform_device *pdev) +int svc_i3c_master_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct svc_i3c_master *master; @@ -1706,7 +1708,7 @@ static int svc_i3c_master_probe(struct platform_device *pdev) return ret; } -static void svc_i3c_master_remove(struct platform_device *pdev) +void svc_i3c_master_remove(struct platform_device *pdev) { struct svc_i3c_master *master = platform_get_drvdata(pdev); @@ -1733,7 +1735,7 @@ static void svc_i3c_restore_regs(struct svc_i3c_master *master) } } -static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev) +int svc_i3c_master_runtime_suspend(struct device *dev) { struct svc_i3c_master *master = dev_get_drvdata(dev); @@ -1744,7 +1746,7 @@ static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev) return 0; } -static int __maybe_unused svc_i3c_runtime_resume(struct device *dev) +int svc_i3c_master_runtime_resume(struct device *dev) { struct svc_i3c_master *master = dev_get_drvdata(dev); @@ -1756,30 +1758,6 @@ static int __maybe_unused svc_i3c_runtime_resume(struct device *dev) return 0; } -static const struct dev_pm_ops svc_i3c_pm_ops = { - SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, - pm_runtime_force_resume) - SET_RUNTIME_PM_OPS(svc_i3c_runtime_suspend, - svc_i3c_runtime_resume, NULL) -}; - -static const struct of_device_id svc_i3c_master_of_match_tbl[] = { - { .compatible = "silvaco,i3c-master-v1"}, - { /* sentinel */ }, -}; -MODULE_DEVICE_TABLE(of, svc_i3c_master_of_match_tbl); - -static struct platform_driver svc_i3c_master = { - .probe = svc_i3c_master_probe, - .remove_new = svc_i3c_master_remove, - .driver = { - .name = "silvaco-i3c-master", - .of_match_table = svc_i3c_master_of_match_tbl, - .pm = &svc_i3c_pm_ops, - }, -}; -module_platform_driver(svc_i3c_master); - MODULE_AUTHOR("Conor Culhane "); MODULE_AUTHOR("Miquel Raynal "); MODULE_DESCRIPTION("Silvaco dual-role I3C master driver"); diff --git a/drivers/i3c/master/svc-i3c.h b/drivers/i3c/master/svc-i3c.h new file mode 100644 index 0000000000000..b9e1dce4b2109 --- /dev/null +++ b/drivers/i3c/master/svc-i3c.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef SVC_I3C_H +#define SVC_I3C_H + +int svc_i3c_master_probe(struct platform_device *pdev); +void svc_i3c_master_remove(struct platform_device *pdev); +int svc_i3c_master_runtime_suspend(struct device *dev); +int svc_i3c_master_runtime_resume(struct device *dev); + +#endif + From patchwork Thu Feb 8 17:01:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550112 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F259C4828F for ; Thu, 8 Feb 2024 17:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5dr25y6ZB3pzqiIp5yLpZgyjoJVQDmemL7l864Q+Cnc=; b=BmFCnw0GFp4m6X fKp0lrxUckq0GXF07wzs8uaqZgp22RYT8T0kvzikbX8FFABAAIVXOPa6TizdF4QlmIQ2y+zNBjLs2 HuMMGLVdwYJmFXR/QbckcGA9/pfVxNXTh7IFwVEXH25gBqigX+qM7oWEXDQi703ZBF+IiBn9vqJZz i0ExSyVboWs9G2SlkBYtWJ1YHf9ZiBbWS0ITSxThMbdLzG+J2X871/OyvmOkQQyy8ZV91t323ARrt L5DJ+//HpBT3ZLCfd47PVXlYcqRHNtzXNDLS3cwnGUyz1J4X+rrt+tuMc8ZpiOjpjgpAsc5BysU6I bI/OgvS/jiHJkSXsqBEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7o5-0000000EOMN-1jTx; Thu, 08 Feb 2024 17:03:25 +0000 Received: from mail-vi1eur05on20600.outbound.protection.outlook.com ([2a01:111:f403:2613::600] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7nE-0000000EO5n-0X5o for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:03:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g2NZC+ey4r4FuKSkVxxA9QSViMJ1Qh1lL8PHxt2vGyKlyYiPEjrcPpTjFs455TmJV4KapyNqiAhx+1LfeUf1kq04mG2qHFo2mL1UEA1pbgG2crL9kmdq50lVZyEO3SEo9ak59ZOUPFj9K8dU9HZykOfYb/Z9WF4DN45sLVH2q7G8h+mADzLWhh7AakhB8TctQswYtyldk/xrsSIS5od5vrMK4YRaH8iinN9ry1oJ0hRgAMnN2z1TOUXv98brY8gxQv0TgbGGIlRL1oafnQYVlnPrBSDk+BqrIZUpxhPgwgNc8rSpqxo1+w+QmYpq5SrFsho2UDXkmL0XaVzqTGjBBA== 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=4wtUtSryywJ1UKhaoUA04wIFITeeEegGorPJgscFx0U=; b=CAvyGtcr8HpyyzggWWmXOIa4C4kVf5U78v1n/TZlPkrPS1V7HJi/9PMESAkP1rZ1RPZME03ebjmiZHAR86B8eYxVz5M/LffjHsXvqJn3Qo9dnaBD3vyJ6eWwvURU5RZCVelFpCDufRptprsJ8C/dV/Uvf5qvH9YpmdyqSOWXwmlv1my/osGFg0TvuS0Co5bSZAg1MYB+BdswyvF9WDZUKRn8x3LGPyajGQHGIqg6/FyWfaLQKeeHvEnoAtyG46XXfY2lirNH8QXAkEGQuDsbrSRlyUkq88heA91bU7BqTE8lcUo4CzLYrf/iIm3rz2B/BNC7AkVhO/tLKdSFQmkZnw== 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=4wtUtSryywJ1UKhaoUA04wIFITeeEegGorPJgscFx0U=; b=cZECVwl/LbWT4Noi+JeYSnZCfGMMDhaBSFl3pswsBrnzml+YYyLlQSAMIEAh2+qt5PDtdMA1rCNF9eFq06L06iPqfq1fknv9BHarVtdH1SpCxT+PkZuZEFWS6qjxo/BQsk1Xnds1DqKfsOO/MDAmR8W66iYpdabz79px9pdDBN8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA4PR04MB9248.eurprd04.prod.outlook.com (2603:10a6:102:2a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Thu, 8 Feb 2024 17:01:57 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:01:57 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 5/8] i3c: target: add svc target controller support Date: Thu, 8 Feb 2024 12:01:14 -0500 Message-Id: <20240208170117.798357-6-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9248:EE_ X-MS-Office365-Filtering-Correlation-Id: ffcfbbc3-0ac0-46c0-eaaf-08dc28c7a8a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hYUHbAAyFar8BrTjQmhUknujnliFNLEH0VsHj/W5MvFNHYKZHaFnRG0zmwjKIpO2B60DKixnjglvvGJM8+QUheSAdGp1/pGNchQcfPW78Z6S5b0FwgeXqkCZV5NvRkZ0b0fjHw/kyBQ18Q7q8MoXu2MpaWblVul/ntjYDZj0uEafUL9zMYiJmTHtY2mcW7LDQ/qg3OOjB2F2xGoPo1O40TB1gd6Q81dmpKDLiHrnhd4cMwZrszvpTDDYyKrnz0jK8Y7a559jihHblrp14fmm5L9y1Xz5vQlj92maWhh56lJRnG+sbCueefmAabHtsB2QRgNqbmAErLbzSb7+Ts0ETuoMnAskJbh2hWg4mAB41RKcW74t818pko9qgXksBoTGa2FOArQbvoPaOkRYxB2Ys1+785xUygssANvAyHuC+4exi+zf2ss+kbKcuOHafiMB2iX/OQG5/i1IJC5G4WQnqF9TwnuAlom9D4szOZ0SsR+pLyQPyGbIUVePHicqBtTcgJI+DlArWxyHaZf9jobVsXRtgcBPmkK9JS9Ln+Hs9wV3okIvhTL+2mO6tXc2Vm83KuFVX5rnZqRikeZQHlS556J+OPRxuFRIfmdAY9b5K5D9QFSjG4oEP8IyzUt6YSQb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(230273577357003)(186009)(64100799003)(1800799012)(451199024)(38100700002)(6666004)(52116002)(6506007)(83380400001)(37006003)(86362001)(7416002)(41300700001)(1076003)(2616005)(26005)(34206002)(6512007)(36756003)(8676002)(8936002)(4326008)(6486002)(478600001)(2906002)(30864003)(5660300002)(66476007)(66946007)(316002)(66556008)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: co+E7o+wGKCs50yRCUEGPnWUTaJ5b3FwQOWsecp0qzHSYhX/05iQ/RGmIcUraSe3ViAKCoV7gDP0d9aRntIRQCllA95TjuUhCsQ00fpsoezzdYCoI6D5YyiZN7c4yIZPNBloC2ctSl8o3eRJuwM9Wub2/11K4ZjcsAdWI050lgSF7TMNvCSBXYKZiKC2e/BeQqgHjsaItILWWTPB80NyGVrpAZSF/Y2bOwUrMm351BgFYC+pVZ63l8WEkCRWipOA6s8qsAP+XeYAdue4+9NLO4iyewi+Qgy1d+48FSd3jImepRdY2I7ra98JGa3UmJq1jd+Ewkt5aNcL5KzHBL4T7PNA+jhb1Uw2m/PXAtBb+rQTYyxKdVaaw3dZ1pFbu7lBzGrimlcF7LH6hl7qoKqHuLstWBObIgGLiftRhileJ4+umva4OnqVxUW6B9aWEckLQ2fwJ2U/7929TqyjcSt1EwckqNMbTv0FV1u8GRJDKk8h+ks+wdAlMC1BTxHKtWTGz0b9PZFLAHN5p3/Tw6KcMKgL7cspbJRH1paAc3qdtYaI/cPfQrPPaElG2v3UpTy6Alh1iLS7Zm/B0RWSo8pXbdRMJnrgrdTJ9EhziKRSKfpEgJKTDSz8hMFFNeVB5qpGQ3sN2C6PrQ1F3TPIWXrdTR+2j4+RMtFqC1mWTbTTvClItEcyXD2/xYQ172WcSPCSYE/g741gHDsT6/v2/TMFFr2/YVfxlKzIUjQsIYaz0I6fZ/tlmz73gTNWlbHzi5bkiZacgHyqgF6aeS9jnX2xTNgfRwVw5zHrmyAOOM0/++Rb1iAoMPd30Us462ewXQpOjVFCNNWw9AuKB6szaf7F9VbOiMXOYUFUWDfba89Us6MkgT59I63oII+vrAyAoiSLPJ6m6VexZuUcSE+NCgA3FgJsnWSnfmadx6gTVE56oDHz1J9kdTS9ItDuS6oqcjrbh/LpqDi7JSulouBveNArP6hjrqFaruEIroO03VMe5QwtGzNvBBuFPwDMmJ2IgSahJUygj0vTJlq8FpURUHU/6Gb4CRwSy+Ky43m/3CWycgdjfgIOZt1li3MyhqySyMTkpMbijW7pcQrDKT46BC35CRJrCembRMSOuo0c6BHHuSSc+zvftGUEmZOc55kjXsFVvihiiYANJDm5KLJgb+aPD4VGzOS4lhIV5TYpN+NB4N588YuHvZw/RGRhcanZxhMqkks+5Tky+EJ7aLB23VQvWddETvhcuKo0bQ5A+lyWarxqeMUQIwVw8zM6K8JpDbO3590RlyNX7eezKaWxvnF4uzv9RDtPbaRfaAzL24a96Q9g+JLLJ6M+f/q5CrWtdK7tjCdz2IExBqJHdylMcE8oCBBFK1t81ZK2vabrRLTtIDFrY/LUawBuVknSW27gI3n0yEcIIlllS+WbAbpmbhd7YI41c981G45HuCQT7plA3L80VEChnlJFAr9ItbAWoHNulqa4XILg/9sRAbTGI7eT1J2UPP20QbDpwgso4sONscPSvoU5d7SoG9A8zxqz3+AYMl306MgldrUEUAJrYxPSPjnrda5jg59jHrwlUNEzLL3ocnUCqS0Xxt6FgbkOTbHx X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ffcfbbc3-0ac0-46c0-eaaf-08dc28c7a8a1 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:01:57.5050 (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: nNcOTnbt8YyY8sFR5aMsZGnz5IgKzn/aK91HGJGT/NkcGQQ4jB0cQaFPERArNonaoQw6TYCRneOKqDGu3SgH6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_090235_054990_FAAA9A61 X-CRM114-Status: GOOD ( 18.25 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Add Silvaco I3C target controller support Signed-off-by: Frank Li --- Notes: Chagne from v7 to v8 -reorder header files - add missed header files Change from v3 to v7 - none Change from v2 to v3 - fix build warning drivers/i3c/master/Makefile | 2 +- drivers/i3c/master/svc-i3c-main.c | 35 +- drivers/i3c/master/svc-i3c-target.c | 776 ++++++++++++++++++++++++++++ drivers/i3c/master/svc-i3c.h | 3 + 4 files changed, 811 insertions(+), 5 deletions(-) create mode 100644 drivers/i3c/master/svc-i3c-target.c diff --git a/drivers/i3c/master/Makefile b/drivers/i3c/master/Makefile index 484cb81f45821..b9ed6c9e7be13 100644 --- a/drivers/i3c/master/Makefile +++ b/drivers/i3c/master/Makefile @@ -2,6 +2,6 @@ obj-$(CONFIG_CDNS_I3C_MASTER) += i3c-master-cdns.o obj-$(CONFIG_DW_I3C_MASTER) += dw-i3c-master.o obj-$(CONFIG_AST2600_I3C_MASTER) += ast2600-i3c-master.o -svc-i3c-objs += svc-i3c-main.o svc-i3c-master.o +svc-i3c-objs += svc-i3c-main.o svc-i3c-master.o svc-i3c-target.o obj-$(CONFIG_SVC_I3C_MASTER) += svc-i3c.o obj-$(CONFIG_MIPI_I3C_HCI) += mipi-i3c-hci/ diff --git a/drivers/i3c/master/svc-i3c-main.c b/drivers/i3c/master/svc-i3c-main.c index 6be6a576cdf7a..e34b128ab274a 100644 --- a/drivers/i3c/master/svc-i3c-main.c +++ b/drivers/i3c/master/svc-i3c-main.c @@ -7,24 +7,51 @@ #include "svc-i3c.h" +static bool svc_i3c_is_master(struct device *dev) +{ + const char *mode = NULL; + + device_property_read_string(dev, "mode", &mode); + + if (!mode) + return true; + + if (strncmp(mode, "target", 6) == 0) + return false; + + return true; +} + static int svc_i3c_probe(struct platform_device *pdev) { - return svc_i3c_master_probe(pdev); + if (svc_i3c_is_master(&pdev->dev)) + return svc_i3c_master_probe(pdev); + + return svc_i3c_target_probe(pdev); } static void svc_i3c_remove(struct platform_device *pdev) { - svc_i3c_master_remove(pdev); + if (svc_i3c_is_master(&pdev->dev)) + return svc_i3c_master_remove(pdev); + + svc_i3c_target_remove(pdev); } static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev) { - return svc_i3c_master_runtime_suspend(dev); + if (svc_i3c_is_master(dev)) + return svc_i3c_master_runtime_suspend(dev); + + return -EINVAL; } static int __maybe_unused svc_i3c_runtime_resume(struct device *dev) { - return svc_i3c_master_runtime_resume(dev); + if (svc_i3c_is_master(dev)) + return svc_i3c_master_runtime_resume(dev); + + return -EINVAL; } static const struct dev_pm_ops svc_i3c_pm_ops = { diff --git a/drivers/i3c/master/svc-i3c-target.c b/drivers/i3c/master/svc-i3c-target.c new file mode 100644 index 0000000000000..06210ed0c3219 --- /dev/null +++ b/drivers/i3c/master/svc-i3c-target.c @@ -0,0 +1,776 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 NXP. + * + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "svc-i3c.h" + +enum i3c_clks { + PCLK, + FCLK, + SCLK, + MAXCLK, +}; + +struct svc_i3c_target { + struct device *dev; + void __iomem *regs; + int irq; + struct clk_bulk_data clks[MAXCLK]; + + struct list_head txq; + spinlock_t txq_lock; /* protect tx queue */ + struct list_head rxq; + spinlock_t rxq_lock; /* protect rx queue */ + struct list_head cq; + spinlock_t cq_lock; /* protect complete queue */ + + struct work_struct work; + struct workqueue_struct *workqueue; + + struct completion dacomplete; + struct i3c_target_ctrl_features features; + + spinlock_t ctrl_lock; /* protext access SCTRL register */ +}; + +#define I3C_SCONFIG 0x4 +#define I3C_SCONFIG_SLVENA_MASK BIT(0) +#define I3C_SCONFIG_OFFLINE_MASK BIT(9) +#define I3C_SCONFIG_SADDR_MASK GENMASK(31, 25) + +#define I3C_SSTATUS 0x8 +#define I3C_SSTATUS_STNOTSTOP_MASK BIT(0) +#define I3C_SSTATUS_STOP_MASK BIT(10) +#define I3C_SSTATUS_RX_PEND_MASK BIT(11) +#define I3C_SSTATUS_TXNOTFULL_MASK BIT(12) +#define I3C_SSTATUS_DACHG_MASK BIT(13) +#define I3C_SSTATUS_EVDET_MASK GENMASK(21, 20) +#define I3C_SSTATUS_EVDET_ACKED 0x3 +#define I3C_SSTATUS_IBIDIS_MASK BIT(24) +#define I3C_SSTATUS_HJDIS_MASK BIT(27) + +#define I3C_SCTRL 0xc +#define I3C_SCTRL_EVENT_MASK GENMASK(1, 0) +#define I3C_SCTRL_EVENT_IBI 0x1 +#define I3C_SCTRL_EVENT_HOTJOIN 0x3 +#define I3C_SCTRL_EXTDATA_MASK BIT(3) +#define I3C_SCTRL_IBIDATA_MASK GENMASK(15, 8) + +#define I3C_SINTSET 0x10 +#define I3C_SINTCLR 0x14 +#define I3C_SINT_START BIT(8) +#define I3C_SINT_MATCHED BIT(9) +#define I3C_SINT_STOP BIT(10) +#define I3C_SINT_RXPEND BIT(11) +#define I3C_SINT_TXSEND BIT(12) +#define I3C_SINT_DACHG BIT(13) +#define I3C_SINT_CCC BIT(14) +#define I3C_SINT_ERRWARN BIT(15) +#define I3C_SINT_DDRMAATCHED BIT(16) +#define I3C_SINT_CHANDLED BIT(17) +#define I3C_SINT_EVENT BIT(18) +#define I3C_SINT_SLVRST BIT(19) + +#define I3C_SDATACTRL 0x2c +#define I3C_SDATACTRL_RXEMPTY_MASK BIT(31) +#define I3C_SDATACTRL_TXFULL_MASK BIT(30) +#define I3C_SDATACTRL_RXCOUNT_MASK GENMASK(28, 24) +#define I3C_SDATACTRL_TXCOUNT_MASK GENMASK(20, 16) +#define I3C_SDATACTRL_FLUSHFB_MASK BIT(1) +#define I3C_SDATACTRL_FLUSHTB_MASK BIT(0) + +#define I3C_SWDATAB 0x30 +#define I3C_SWDATAB_END_ALSO_MASK BIT(16) +#define I3C_SWDATAB_END_MASK BIT(8) + +#define I3C_SWDATAE 0x34 +#define I3C_SRDATAB 0x40 + +#define I3C_SCAPABILITIES 0x60 +#define I3C_SCAPABILITIES_FIFOTX_MASK GENMASK(27, 26) +#define I3C_SCAPABILITIES_FIFORX_MASK GENMASK(29, 28) + +#define I3C_SMAXLIMITS 0x68 +#define I3C_SMAXLIMITS_MAXRD_MASK GENMASK(11, 0) +#define I3C_SMAXLIMITS_MAXWR_MASK GENMASK(27, 16) + +#define I3C_SIDPARTNO 0x6c + +#define I3C_SIDEXT 0x70 +#define I3C_SIDEXT_BCR_MASK GENMASK(23, 16) +#define I3C_SIDEXT_DCR_MASK GENMASK(15, 8) +#define I3C_SVENDORID 0x74 + +#define I3C_SMAPCTRL0 0x11c +#define I3C_SMAPCTRL0_ENA_MASK BIT(0) +#define I3C_SMAPCTRL0_DA_MASK GENMASK(7, 1) + +#define I3C_IBIEXT1 0x140 +#define I3C_IBIEXT1_CNT_MASK GEN_MASK(2, 0) +#define I3C_IBIEXT1_MAX_MASK GEN_MASK(4, 6) +#define I3C_IBIEXT1_EXT1_SHIFT 8 +#define I3C_IBIEXT1_EXT2_SHIFT 16 +#define I3C_IBIEXT1_EXT3_SHIFT 24 + +#define I3C_IBIEXT2 0x144 +#define I3C_IBIEXT2_EXT4_SHIFT 0 +#define I3C_IBIEXT2_EXT5_SHIFT 8 +#define I3C_IBIEXT2_EXT6_SHIFT 16 +#define I3C_IBIEXT2_EXT7_SHIFT 24 + +static int svc_i3c_target_enable(struct i3c_target_ctrl *ctrl) +{ + struct svc_i3c_target *svc; + u32 val; + + svc = dev_get_drvdata(&ctrl->dev); + + val = readl_relaxed(svc->regs + I3C_SCONFIG); + val |= I3C_SCONFIG_SLVENA_MASK; + writel_relaxed(val, svc->regs + I3C_SCONFIG); + + return 0; +} + +static int svc_i3c_target_disable(struct i3c_target_ctrl *ctrl) +{ + struct svc_i3c_target *svc; + u32 val; + + svc = dev_get_drvdata(&ctrl->dev); + + val = readl_relaxed(svc->regs + I3C_SCONFIG); + val &= ~I3C_SCONFIG_SLVENA_MASK; + writel_relaxed(val, svc->regs + I3C_SCONFIG); + + return 0; +} + +static int svc_i3c_target_set_config(struct i3c_target_ctrl *ctrl, struct i3c_target_func *func) +{ + struct svc_i3c_target *svc; + u32 val; + u32 wm, rm; + + svc = dev_get_drvdata(&ctrl->dev); + + if (func->static_addr > 0x7F) + return -EINVAL; + + val = readl_relaxed(svc->regs + I3C_SCONFIG); + val &= ~I3C_SCONFIG_SLVENA_MASK; + val |= FIELD_PREP(I3C_SCONFIG_SADDR_MASK, func->static_addr); + writel_relaxed(val, svc->regs + I3C_SCONFIG); + + if (func->part_id) + writel_relaxed((func->part_id << 16) | + ((func->instance_id << 12) & GENMASK(15, 12)) | + (func->ext_id & GENMASK(11, 0)), svc->regs + I3C_SIDPARTNO); + + writel_relaxed(FIELD_PREP(I3C_SIDEXT_BCR_MASK, func->bcr) | + FIELD_PREP(I3C_SIDEXT_DCR_MASK, func->dcr), + svc->regs + I3C_SIDEXT); + + wm = func->max_write_len == 0 ? + FIELD_GET(I3C_SMAXLIMITS_MAXWR_MASK, I3C_SMAXLIMITS_MAXWR_MASK) : func->max_write_len; + + wm = max_t(u32, val, 8); + + rm = func->max_read_len == 0 ? + FIELD_GET(I3C_SMAXLIMITS_MAXRD_MASK, I3C_SMAXLIMITS_MAXRD_MASK) : func->max_read_len; + rm = max_t(u32, val, 16); + + val = FIELD_PREP(I3C_SMAXLIMITS_MAXRD_MASK, rm) | FIELD_PREP(I3C_SMAXLIMITS_MAXWR_MASK, wm); + writel_relaxed(val, svc->regs + I3C_SMAXLIMITS); + + writel_relaxed(func->vendor_id, svc->regs + I3C_SVENDORID); + return 0; +} + +static const struct i3c_target_ctrl_features *svc_i3c_get_features(struct i3c_target_ctrl *ctrl) +{ + struct svc_i3c_target *svc; + + svc = dev_get_drvdata(&ctrl->dev); + + if (!svc) + return NULL; + + return &svc->features; +} + +static void svc_i3c_queue_complete(struct svc_i3c_target *svc, struct i3c_request *complete) +{ + unsigned long flags; + + spin_lock_irqsave(&svc->cq_lock, flags); + list_add_tail(&complete->list, &svc->cq); + spin_unlock_irqrestore(&svc->cq_lock, flags); + queue_work(svc->workqueue, &svc->work); +} + +static void svc_i3c_fill_txfifo(struct svc_i3c_target *svc) +{ + struct i3c_request *req, *complete = NULL; + unsigned long flags; + int val; + + spin_lock_irqsave(&svc->txq_lock, flags); + while ((!!(req = list_first_entry_or_null(&svc->txq, struct i3c_request, list))) && + !((readl_relaxed(svc->regs + I3C_SDATACTRL) & I3C_SDATACTRL_TXFULL_MASK))) { + while (!(readl_relaxed(svc->regs + I3C_SDATACTRL) + & I3C_SDATACTRL_TXFULL_MASK)) { + val = *(u8 *)(req->buf + req->actual); + + if (req->actual + 1 == req->length) + writel_relaxed(val, svc->regs + I3C_SWDATAE); + else + writel_relaxed(val, svc->regs + I3C_SWDATAB); + + req->actual++; + + if (req->actual == req->length) { + list_del(&req->list); + complete = req; + spin_unlock_irqrestore(&svc->txq_lock, flags); + + svc_i3c_queue_complete(svc, complete); + return; + + spin_lock_irqsave(&svc->txq_lock, flags); + break; + } + } + } + spin_unlock_irqrestore(&svc->txq_lock, flags); +} + +static int svc_i3c_target_queue(struct i3c_request *req, gfp_t gfp) +{ + struct svc_i3c_target *svc; + struct list_head *q; + unsigned long flags; + spinlock_t *lk; + + svc = dev_get_drvdata(&req->ctrl->dev); + if (!svc) + return -EINVAL; + + if (req->tx) { + q = &svc->txq; + lk = &svc->txq_lock; + } else { + q = &svc->rxq; + lk = &svc->rxq_lock; + } + + spin_lock_irqsave(lk, flags); + list_add_tail(&req->list, q); + spin_unlock_irqrestore(lk, flags); + + if (req->tx) + svc_i3c_fill_txfifo(svc); + + if (req->tx) + writel_relaxed(I3C_SINT_TXSEND, svc->regs + I3C_SINTSET); + else + writel_relaxed(I3C_SINT_RXPEND, svc->regs + I3C_SINTSET); + + return 0; +} + +static int svc_i3c_dequeue(struct i3c_request *req) +{ + struct svc_i3c_target *svc; + unsigned long flags; + spinlock_t *lk; + + svc = dev_get_drvdata(&req->ctrl->dev); + if (!svc) + return -EINVAL; + + if (req->tx) + lk = &svc->txq_lock; + else + lk = &svc->rxq_lock; + + spin_lock_irqsave(lk, flags); + list_del(&req->list); + spin_unlock_irqrestore(lk, flags); + + return 0; +} + +static void svc_i3c_target_fifo_flush(struct i3c_target_ctrl *ctrl, bool tx) +{ + struct svc_i3c_target *svc; + u32 val; + + svc = dev_get_drvdata(&ctrl->dev); + + val = readl_relaxed(svc->regs + I3C_SDATACTRL); + + val |= tx ? I3C_SDATACTRL_FLUSHTB_MASK : I3C_SDATACTRL_FLUSHFB_MASK; + + writel_relaxed(val, svc->regs + I3C_SDATACTRL); +} + +static int +svc_i3c_target_raise_ibi(struct i3c_target_ctrl *ctrl, void *p, u8 size) +{ + struct svc_i3c_target *svc; + unsigned long flags; + u8 *ibidata = p; + u32 ext1 = 0, ext2 = 0; + u32 val; + int ret; + + svc = dev_get_drvdata(&ctrl->dev); + + if (size && !p) + return -EINVAL; + + if (size > 8) + return -EINVAL; + + val = readl_relaxed(svc->regs + I3C_SSTATUS); + if (val & I3C_SSTATUS_IBIDIS_MASK) + return -EINVAL; + + ret = readl_relaxed_poll_timeout(svc->regs + I3C_SCTRL, val, + !(val & I3C_SCTRL_EVENT_MASK), 0, 10000); + if (ret) { + dev_err(&ctrl->dev, "Timeout when polling for NO event pending"); + val &= ~I3C_SCTRL_EVENT_MASK; + writel_relaxed(val, svc->regs + I3C_SCTRL); + return -ENAVAIL; + } + + spin_lock_irqsave(&svc->ctrl_lock, flags); + + val = readl_relaxed(svc->regs + I3C_SCTRL); + + val &= ~I3C_SCTRL_EVENT_MASK | I3C_SCTRL_IBIDATA_MASK; + val |= FIELD_PREP(I3C_SCTRL_EVENT_MASK, I3C_SCTRL_EVENT_IBI); + + if (size) { + val |= FIELD_PREP(I3C_SCTRL_IBIDATA_MASK, *ibidata); + ibidata++; + + if (size > 1) + val |= I3C_SCTRL_EXTDATA_MASK; + + size--; + if (size > 0) { + ext1 |= (size + 2); + ext1 |= (*ibidata++) << I3C_IBIEXT1_EXT1_SHIFT; + size--; + } + + if (size > 0) { + ext1 |= (*ibidata++) << I3C_IBIEXT1_EXT2_SHIFT; + size--; + } + + if (size > 0) { + ext1 |= (*ibidata++) << I3C_IBIEXT1_EXT3_SHIFT; + size--; + } + + writel_relaxed(ext1, svc->regs + I3C_IBIEXT1); + + if (size > 0) { + ext2 |= (*ibidata++) << I3C_IBIEXT2_EXT4_SHIFT; + size--; + } + + if (size > 0) { + ext2 |= (*ibidata++) << I3C_IBIEXT2_EXT5_SHIFT; + size--; + } + + if (size > 0) { + ext2 |= (*ibidata++) << I3C_IBIEXT2_EXT6_SHIFT; + size--; + } + + if (size > 0) { + ext2 |= (*ibidata++) << I3C_IBIEXT2_EXT7_SHIFT; + size--; + } + + writeb_relaxed(ext2, svc->regs + I3C_IBIEXT2); + } + + /* Issue IBI*/ + writel_relaxed(val, svc->regs + I3C_SCTRL); + spin_unlock_irqrestore(&svc->ctrl_lock, flags); + + ret = readl_relaxed_poll_timeout(svc->regs + I3C_SCTRL, val, + !(val & I3C_SCTRL_EVENT_MASK), 0, 1000000); + if (ret) { + dev_err(&ctrl->dev, "Timeout when polling for IBI finish\n"); + + //clear event to above hang bus + spin_lock_irqsave(&svc->ctrl_lock, flags); + val = readl_relaxed(svc->regs + I3C_SCTRL); + val &= ~I3C_SCTRL_EVENT_MASK; + writel_relaxed(val, svc->regs + I3C_SCTRL); + spin_unlock_irqrestore(&svc->ctrl_lock, flags); + + return -ENAVAIL; + } + + return 0; +} + +static void svc_i3c_target_complete(struct work_struct *work) +{ + struct svc_i3c_target *svc = container_of(work, struct svc_i3c_target, work); + struct i3c_request *req; + unsigned long flags; + + spin_lock_irqsave(&svc->cq_lock, flags); + while (!list_empty(&svc->cq)) { + req = list_first_entry(&svc->cq, struct i3c_request, list); + list_del(&req->list); + spin_unlock_irqrestore(&svc->cq_lock, flags); + req->complete(req); + + spin_lock_irqsave(&svc->cq_lock, flags); + } + spin_unlock_irqrestore(&svc->cq_lock, flags); +} + +static irqreturn_t svc_i3c_target_irq_handler(int irq, void *dev_id) +{ + struct i3c_request *req, *complete = NULL; + struct svc_i3c_target *svc = dev_id; + unsigned long flags; + u32 statusFlags; + + statusFlags = readl(svc->regs + I3C_SSTATUS); + writel(statusFlags, svc->regs + I3C_SSTATUS); + + if (statusFlags & I3C_SSTATUS_DACHG_MASK) + complete_all(&svc->dacomplete); + + if (statusFlags & I3C_SSTATUS_RX_PEND_MASK) { + spin_lock_irqsave(&svc->rxq_lock, flags); + req = list_first_entry_or_null(&svc->rxq, struct i3c_request, list); + + if (!req) { + writel_relaxed(I3C_SINT_RXPEND, svc->regs + I3C_SINTCLR); + } else { + while (!(readl_relaxed(svc->regs + I3C_SDATACTRL) & + I3C_SDATACTRL_RXEMPTY_MASK)) { + *(u8 *)(req->buf + req->actual) = + readl_relaxed(svc->regs + I3C_SRDATAB); + req->actual++; + + if (req->actual == req->length) { + complete = req; + list_del(&req->list); + break; + } + } + + if (req->actual != req->length && (statusFlags & I3C_SSTATUS_STOP_MASK)) { + complete = req; + list_del(&req->list); + } + } + spin_unlock_irqrestore(&svc->rxq_lock, flags); + + if (complete) { + spin_lock_irqsave(&svc->cq_lock, flags); + list_add_tail(&complete->list, &svc->cq); + spin_unlock_irqrestore(&svc->cq_lock, flags); + queue_work(svc->workqueue, &svc->work); + complete = NULL; + } + } + + if (statusFlags & I3C_SSTATUS_TXNOTFULL_MASK) { + svc_i3c_fill_txfifo(svc); + spin_lock_irqsave(&svc->txq_lock, flags); + if (list_empty(&svc->txq)) + writel_relaxed(I3C_SINT_TXSEND, svc->regs + I3C_SINTCLR); + spin_unlock_irqrestore(&svc->txq_lock, flags); + } + + return IRQ_HANDLED; +} + +static void svc_i3c_cancel_all_reqs(struct i3c_target_ctrl *ctrl, bool tx) +{ + struct svc_i3c_target *svc; + struct i3c_request *req; + struct list_head *q; + unsigned long flags; + spinlock_t *lk; + + svc = dev_get_drvdata(&ctrl->dev); + if (!svc) + return; + + if (tx) { + q = &svc->txq; + lk = &svc->txq_lock; + } else { + q = &svc->rxq; + lk = &svc->rxq_lock; + } + + spin_lock_irqsave(lk, flags); + while (!list_empty(q)) { + req = list_first_entry(q, struct i3c_request, list); + list_del(&req->list); + spin_unlock_irqrestore(lk, flags); + + req->status = I3C_REQUEST_CANCEL; + req->complete(req); + spin_lock_irqsave(lk, flags); + } + spin_unlock_irqrestore(lk, flags); +} + +static int svc_i3c_hotjoin(struct i3c_target_ctrl *ctrl) +{ + struct svc_i3c_target *svc; + int ret; + u32 val; + u32 cfg; + + svc = dev_get_drvdata(&ctrl->dev); + if (!svc) + return -EINVAL; + + reinit_completion(&svc->dacomplete); + + val = readl_relaxed(svc->regs + I3C_SSTATUS); + if (val & I3C_SSTATUS_HJDIS_MASK) { + dev_err(&ctrl->dev, "Hotjoin disabled by i3c master\n"); + return -EINVAL; + } + + ret = readl_relaxed_poll_timeout(svc->regs + I3C_SCTRL, val, + !(val & I3C_SCTRL_EVENT_MASK), 0, 10000); + if (ret) { + dev_err(&ctrl->dev, "Timeout when polling for none event pending"); + return -ENAVAIL; + } + + cfg = readl_relaxed(svc->regs + I3C_SCONFIG); + cfg |= I3C_SCONFIG_OFFLINE_MASK; + writel_relaxed(cfg, svc->regs + I3C_SCONFIG); + + val &= ~(I3C_SCTRL_EVENT_MASK | I3C_SCTRL_IBIDATA_MASK); + val |= FIELD_PREP(I3C_SCTRL_EVENT_MASK, I3C_SCTRL_EVENT_HOTJOIN); + /* Issue hotjoin*/ + writel_relaxed(val, svc->regs + I3C_SCTRL); + + ret = readl_relaxed_poll_timeout(svc->regs + I3C_SCTRL, val, + !(val & I3C_SCTRL_EVENT_MASK), 0, 100000); + if (ret) { + val &= ~FIELD_PREP(I3C_SCTRL_EVENT_MASK, I3C_SCTRL_EVENT_MASK); + writel_relaxed(val, svc->regs + I3C_SCTRL); + dev_err(&ctrl->dev, "Timeout when polling for HOTJOIN finish\n"); + return -EINVAL; + } + + val = readl_relaxed(svc->regs + I3C_SSTATUS); + val = FIELD_GET(I3C_SSTATUS_EVDET_MASK, val); + if (val != I3C_SSTATUS_EVDET_ACKED) { + dev_err(&ctrl->dev, "Master NACKED hotjoin request\n"); + return -EINVAL; + } + + writel_relaxed(I3C_SINT_DACHG, svc->regs + I3C_SINTSET); + ret = wait_for_completion_timeout(&svc->dacomplete, msecs_to_jiffies(100)); + writel_relaxed(I3C_SINT_DACHG, svc->regs + I3C_SINTCLR); + if (!ret) { + dev_err(&ctrl->dev, "wait for da assignment timeout\n"); + return -EIO; + } + + val = readl_relaxed(svc->regs + I3C_SMAPCTRL0); + val = FIELD_GET(I3C_SMAPCTRL0_DA_MASK, val); + dev_info(&ctrl->dev, "Get dynamtic address 0x%x\n", val); + return 0; +} + +static int svc_i3c_set_status_format1(struct i3c_target_ctrl *ctrl, u16 status) +{ + struct svc_i3c_target *svc; + unsigned long flags; + u32 val; + + svc = dev_get_drvdata(&ctrl->dev); + + spin_lock_irqsave(&svc->ctrl_lock, flags); + val = readl_relaxed(svc->regs + I3C_SCTRL); + val &= 0xFFFF; + val |= status << 16; + writel_relaxed(val, svc->regs + I3C_SCTRL); + spin_unlock_irqrestore(&svc->ctrl_lock, flags); + + return 0; +} + +static u16 svc_i3c_get_status_format1(struct i3c_target_ctrl *ctrl) +{ + struct svc_i3c_target *svc; + + svc = dev_get_drvdata(&ctrl->dev); + + return readl_relaxed(svc->regs + I3C_SCTRL) >> 16; +} + +static u8 svc_i3c_get_addr(struct i3c_target_ctrl *ctrl) +{ + struct svc_i3c_target *svc; + int val; + + svc = dev_get_drvdata(&ctrl->dev); + + val = readl_relaxed(svc->regs + I3C_SMAPCTRL0); + + if (val & I3C_SMAPCTRL0_ENA_MASK) + return FIELD_GET(I3C_SMAPCTRL0_DA_MASK, val); + + return 0; +} + +static int svc_i3c_fifo_status(struct i3c_target_ctrl *ctrl, bool tx) +{ + struct svc_i3c_target *svc; + int val; + + svc = dev_get_drvdata(&ctrl->dev); + + val = readl_relaxed(svc->regs + I3C_SDATACTRL); + + if (tx) + return FIELD_GET(I3C_SDATACTRL_TXCOUNT_MASK, val); + else + return FIELD_GET(I3C_SDATACTRL_RXCOUNT_MASK, val); +} + +static struct i3c_target_ctrl_ops svc_i3c_target_ops = { + .set_config = svc_i3c_target_set_config, + .enable = svc_i3c_target_enable, + .disable = svc_i3c_target_disable, + .queue = svc_i3c_target_queue, + .dequeue = svc_i3c_dequeue, + .raise_ibi = svc_i3c_target_raise_ibi, + .fifo_flush = svc_i3c_target_fifo_flush, + .cancel_all_reqs = svc_i3c_cancel_all_reqs, + .get_features = svc_i3c_get_features, + .hotjoin = svc_i3c_hotjoin, + .fifo_status = svc_i3c_fifo_status, + .set_status_format1 = svc_i3c_set_status_format1, + .get_status_format1 = svc_i3c_get_status_format1, + .get_addr = svc_i3c_get_addr, +}; + +int svc_i3c_target_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct i3c_target_ctrl *target; + struct svc_i3c_target *svc; + int ret; + u32 val; + + svc = devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL); + if (!svc) + return -ENOMEM; + + svc->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(svc->regs)) + return PTR_ERR(svc->regs); + + svc->clks[PCLK].id = "pclk"; + svc->clks[FCLK].id = "fast_clk"; + svc->clks[SCLK].id = "slow_clk"; + + ret = devm_clk_bulk_get(dev, MAXCLK, svc->clks); + if (ret < 0) { + dev_err(dev, "fail get clks: %d\n", ret); + return ret; + } + + ret = clk_bulk_prepare_enable(MAXCLK, svc->clks); + if (ret < 0) { + dev_err(dev, "fail enable clks: %d\n", ret); + return ret; + } + + svc->irq = platform_get_irq(pdev, 0); + if (svc->irq < 0) + return svc->irq; + + INIT_LIST_HEAD(&svc->txq); + INIT_LIST_HEAD(&svc->rxq); + INIT_LIST_HEAD(&svc->cq); + spin_lock_init(&svc->txq_lock); + spin_lock_init(&svc->rxq_lock); + spin_lock_init(&svc->cq_lock); + spin_lock_init(&svc->ctrl_lock); + + init_completion(&svc->dacomplete); + + INIT_WORK(&svc->work, svc_i3c_target_complete); + svc->workqueue = alloc_workqueue("%s-cq", 0, 0, dev_name(dev)); + if (!svc->workqueue) + return -ENOMEM; + + /* Disable all IRQ */ + writel_relaxed(0xFFFFFFFF, svc->regs + I3C_SINTCLR); + + val = readl_relaxed(svc->regs + I3C_SCAPABILITIES); + svc->features.tx_fifo_sz = FIELD_GET(I3C_SCAPABILITIES_FIFOTX_MASK, val); + svc->features.tx_fifo_sz = 2 << svc->features.tx_fifo_sz; + + svc->features.rx_fifo_sz = FIELD_GET(I3C_SCAPABILITIES_FIFORX_MASK, val); + svc->features.rx_fifo_sz = 2 << svc->features.rx_fifo_sz; + + ret = devm_request_irq(dev, svc->irq, svc_i3c_target_irq_handler, 0, "svc-i3c-irq", svc); + if (ret) + return -ENOENT; + + target = devm_i3c_target_ctrl_create(dev, &svc_i3c_target_ops); + if (!target) + return -ENOMEM; + + dev_set_drvdata(&target->dev, svc); + + return 0; +} + +void svc_i3c_target_remove(struct platform_device *pdev) +{ +} diff --git a/drivers/i3c/master/svc-i3c.h b/drivers/i3c/master/svc-i3c.h index b9e1dce4b2109..1bb77474f36eb 100644 --- a/drivers/i3c/master/svc-i3c.h +++ b/drivers/i3c/master/svc-i3c.h @@ -8,5 +8,8 @@ void svc_i3c_master_remove(struct platform_device *pdev); int svc_i3c_master_runtime_suspend(struct device *dev); int svc_i3c_master_runtime_resume(struct device *dev); +int svc_i3c_target_probe(struct platform_device *pdev); +void svc_i3c_target_remove(struct platform_device *pdev); + #endif From patchwork Thu Feb 8 17:01:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550113 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B5EBC48260 for ; Thu, 8 Feb 2024 17:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pc3f82oSwwvYZeTYNiNnf8bGpQT+Ew85tqBCJqpYoFM=; b=g/E3bOJdLwKW6b FxNnIwgxNUwqZcEtUwp3+BBe7heTMv7AI8UO/LRh34puQSToIyqNlf29Bv11iIuaXTWpqPe/djhAC Nw99HfbaBKXctlWMVIkbow0n2/jvQ89fiF6ScDXIcpJE2Zo8jx+wl25kFoqi0m8BOJw9fD/CUPgNE sAWiRSmRuVATSCfhmM/Cd712SGk4HpIoHiFxr6m9QRqHel+Hkpmd00c4Z3wgF4vcutF7OSGZMxlAm NxwRvH56WpRCpJJJ+eMF8JztE1CUbKy1MrTTrnX+2nxKdaOHCW2BWRncKJY5YxTV7DdGfxpfHEX/6 ftfq1bDf4ujcPiDMYHFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7o6-0000000EONV-0HWU; Thu, 08 Feb 2024 17:03:26 +0000 Received: from mail-vi1eur05on20601.outbound.protection.outlook.com ([2a01:111:f403:2613::601] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7nl-0000000ENy9-17mO for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:03:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TDya8lvlR2nvh1VKRsQ+FkbVQtlp36b1flXBwifUMqh4neBzJ94NR5sSKKUt8ACz8Qvf96a4h/3klg7AcsNwd+Xq5rWhI5TswQ0/eRCoagbSTsvOKvAW4jjlWg/xCtLI3ellXJDbRFAikvqw0LzTx/duyLUn02kYu9Qfdx4WHV+ahcjzYux4D/2gHVxBl0gJxhvZoRGYcembkNu+nrfcxgpGPItxnMVoToSDRZIAV+I2a2qkJpGvLMCsebRY598gfB+uMdIPq5a5U6JnnAM8j3MWzML7Q6IqsIGAwDsW3vC3ig+ahc2nXATaKOtZBh+9wzpSfMxSZIa41pmxq7yBZQ== 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=04xqZBjF8Z1MoZTW2zREKB6wmaZdVutdhyYJgIV1Fgc=; b=KaxRbniqv6hsxpWxSWctRX2g4s2bJQsJFOacUcc1NtUFyANPNjAkFJ40oo2r8hJ7sw+6lxWFjC1pCngwvhIKEYDo6nDnkwp8zjz6IbrhjfADBy77YYG8hI4yIMw1yiIxl4wREV3PD5RfTcG/llUngPJ13unyB0lNOmasa8uD/yXEOkSK4hSUdFxQfql4/b2hOo6hRRzT+8YYUqIdCeIBkd/rjQgxFsu2dbBQrA7Hk+KztxizvHxZfEw0kbUI7vSc0a9U0hYasqH62sh23m/oFQU7SXecS1EoJlxdjK1vEwd+GwpXiLYagBErZ5d8AuTkQ2C0andlVne4meJkGuVOPA== 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=04xqZBjF8Z1MoZTW2zREKB6wmaZdVutdhyYJgIV1Fgc=; b=TAV1rP/GtcUeFdu4jayNsgMNGk9OWumBar+oIRNEB7Y8MB/YpRmYiOrYfREY7WspnjK/4goAxY4+3450GdrQEX5dtD9mMSS3l562Bwqxw+JXm+2iW3bFn8iAj3og7/uJSHjf8NEpmCoTaDuA6E+KbrBnBt4d0LLQQ/WL1+4e+eQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA4PR04MB9248.eurprd04.prod.outlook.com (2603:10a6:102:2a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Thu, 8 Feb 2024 17:02:02 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:02:02 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 6/8] i3c: target: func: add tty driver Date: Thu, 8 Feb 2024 12:01:15 -0500 Message-Id: <20240208170117.798357-7-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9248:EE_ X-MS-Office365-Filtering-Correlation-Id: f1103997-bb95-4dfc-3834-08dc28c7ab51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LwhYZm3OmyqoOwqNcCEY4InWdT/3IdEUBzbp8pj7H64nVb9eeRDx9+P8UD6OGRNc46WV/gg23IneVYCD2spetxONF5xAHYw6sUfZrP7V4Xy+Pg5F6BgGkKQKiTUBJxK9CCoajgdORyQAZfntu8jAUOW8Oxqi2R+Nwclooxkf1yrfQuTt1MTX39BMBtXqQwzjXcs3Qy58kEdjsZi5dfTB1L0lGiWOokosvdsybZZIgTja89qloQHJg4K5gp1cHpjWrEhJbvQITws33jx7zSCrasLGrauwiti7YAe6Ym4TGTM2QghaqfJl/HpW85pczcA9j3WT5O8VIDR+xZaNmFTqgox34eAiyMIMJzkwrzDUbRSES6CwPHKm8EaojegezkLHQdwkbjoPakPKFFERfMETjjspUw39v1ZYd4vFV7AokRfGN9tagVpSSBj4o8Bl+GG+qOT4oPZLamr4uIQdNNH9TmFmXL0H1OaLoFQ9nCW0+G3JM4st0WOowMfBmMmaUCOhIar8eFsUxso+4dHFDj5Oq//O67di8vCOVme3hNT782rHjdn8v61gzoNOVi33eu55KDjdSZAdy1tUGpxkYHGbcCmjwX++z46jdwhTR1vOLBZIPAScYjRQap6CbJRRrEQP X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(38100700002)(6666004)(52116002)(6506007)(83380400001)(37006003)(86362001)(7416002)(41300700001)(1076003)(2616005)(26005)(34206002)(6512007)(36756003)(8676002)(8936002)(4326008)(6486002)(478600001)(2906002)(30864003)(5660300002)(66476007)(66946007)(316002)(66556008)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rU4G4oNbSY8F5dCuw0ln4tHw5Cwt2clj5hPGevdJP5e3VQgKKNs2SMMHSu7SvhhKxGgU0fCQGTi4jSmlguZKfvRQkkupRIhUy4pUydejsmPZTdgJ8MesMP7vPt2LuQDPzs+HbpTdAHyOQ4sukgnrFmjQRqHqrsebkmGj214VjpRuof4I7E674hNkWe6vLVxmklTcGZKly6Z72msY1n6HJAt/xqFF8ZOMnh2fJ4XjTplcPgbARL/NQmG6rlQyHi6ogsditDaX5hR2BhTK4Snll3lI+gWPEmoJs/O6EmTgEr+uS9XEfUHQTee1v4vSocmtF6M5OyqPQa/bidXXlvilAq8zEyuncJ8gobULEcelR7pkm/TLTgL/FzFBTnaRgIpMUV3cjYqEIuwBN+tPK/mKGtMgSj4il7W6wn3371oDa/XBGWaDsxAv/cOV+NJ8XxlPgP79oOPz/pDh5yZSyO7Vei9fzmMsf47Zo3IEK+ksm8bMNF7UTY/bm7XVo72XVeA6o5nL8oczT2bluTAbkEK0Kr25+wuwUsWrYc/1Yq5bcSjdqLfFCrIoRD6V7O9gsniqro/OoIX1mQl7/XK+lGXjZuYRq0owGNCyKBmv27d9b0J45Y4x0GBFwQbAf8SjMDrE7zoSRD5DCDkhvaj5X5SdTdVZV7zh4mSOdNfNWDSAjvg2yF3k00eXCf4rQduRHDd88nXmKRx5XI4G6FFxgBTCPkgr4f3LuAvEL9Y0BYPqHMP9e5FVPAZcSpDp01F1u8ysc7oGmxSeLjeSYlM3+35M806G24zXAW6k9vC1upH1AqRn2env5/Fd91eSnUIzuwjlPbf4vdATM0q4RGo7gFj743tNrgDQ5wTrBUV9MPXOrOCda7dphii0o4fCtEwaOxPP7ouM24qSV013mQ2gqSrgGaiOlFB03h+MFzH7eszxxZ+FBQlLLer6gndrLvYhsz6jpgOBn59VQXbIfFFP8dVphzLWE3APp6HEGYC6JwTTrbdYkBVtyzROmPgcWF9QNN2uwa2/UYOjFho1VFl9rgrbh4WZwPh18XdgjN8t14SsAhEgX8Mz1s1rkBeqfYgupGW07OUdw2mp5KoZ/RDwvjXd0N+O5NY3LxVB2THCDYFRYwHLdYblybK1bgQ4LuMfSh3x2bBeRXduiBz/+Jet8EjeMXWZ8FNaNtsK4fc4PfxNL2NMZWIrOGVefwjHfWKQZlEyb7MrpEWhZyR9Mkqo6zKQDW358ibUHDJOzAllaPEqvELLJ7mauOm1nycTNaksY6Yk9mvlWp4iQ6YOSdJ0g+ewrHIBEmWEjUlLdmLQoNzUegx4akVbx4Dn3DMck/gvT9ZocGStGLPQw+r0TDaLECW5f5reAQGTVSmEPxqwSxZS2Tobu4sN9DHd6M/wM6LDcX5idnQ2SLX1NfQ3Rtnb7nXG+OHouZ+GnYqwuH22Db4caETqosawaGNE992W3ZCgYd+CYh6Gh6b29cxKUvJ+TGJOXSiFc9IAq4hRuGfAMmNDXKrmFAPZbIWyCwT7v7t15T1L7m+CMpdl/FQrrGPP1quDdwRQP8ZTHHMB0CUVjZet8osCNwKV63X2gSvdOI9sa5ZQ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1103997-bb95-4dfc-3834-08dc28c7ab51 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:02:01.9296 (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: 2wchm8ERBtZuq9Gmj+cpj52dW7E3E5YGXOGRFcICHEwSO5q/vXA9UDL01j1FvU8SUxtzhUYSRpMq0STLOHgnsg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_090305_636975_310390D7 X-CRM114-Status: GOOD ( 19.85 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Add tty over I3C target function driver. Signed-off-by: Frank Li --- Notes: Change from v7 to v8 - reorder header file - add missed header files Change from v5 to v7 - none Change from v4 to v5 - remove void* - include bitfield.h - remove extra () - oneline for struct ttyi3c_port *sport drivers/i3c/Kconfig | 3 + drivers/i3c/Makefile | 1 + drivers/i3c/func/Kconfig | 9 + drivers/i3c/func/Makefile | 3 + drivers/i3c/func/tty.c | 481 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 497 insertions(+) create mode 100644 drivers/i3c/func/Kconfig create mode 100644 drivers/i3c/func/Makefile create mode 100644 drivers/i3c/func/tty.c diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index d59a7eb83d13a..fca808cda87b3 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -48,3 +48,6 @@ config I3C_TARGET_CONFIGFS the target function and used to bind the function with a target controller. +if I3C_TARGET +source "drivers/i3c/func/Kconfig" +endif # I3C_TARGET diff --git a/drivers/i3c/Makefile b/drivers/i3c/Makefile index c275aeae8970c..11f026d6876fe 100644 --- a/drivers/i3c/Makefile +++ b/drivers/i3c/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_I3C) += i3c.o obj-$(CONFIG_I3C_TARGET) += target.o obj-$(CONFIG_I3C_TARGET_CONFIGFS) += i3c-cfs.o obj-$(CONFIG_I3C) += master/ +obj-$(CONFIG_I3C_TARGET) += func/ diff --git a/drivers/i3c/func/Kconfig b/drivers/i3c/func/Kconfig new file mode 100644 index 0000000000000..7115129eb7d5a --- /dev/null +++ b/drivers/i3c/func/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 + +config I3C_TARGET_FUNC_TTY + tristate "I3C target tty driver" + depends on I3C_TARGET + help + I3C Target TTY Function Driver. + + General TTY over I3C target controller function drivers. diff --git a/drivers/i3c/func/Makefile b/drivers/i3c/func/Makefile new file mode 100644 index 0000000000000..16b3b9301496b --- /dev/null +++ b/drivers/i3c/func/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_I3C_TARGET_FUNC_TTY) += tty.o diff --git a/drivers/i3c/func/tty.c b/drivers/i3c/func/tty.c new file mode 100644 index 0000000000000..2cf25c8d49f2b --- /dev/null +++ b/drivers/i3c/func/tty.c @@ -0,0 +1,481 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 NXP + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_IDR(i3c_tty_minors); + +static struct tty_driver *i3c_tty_driver; + +#define I3C_TTY_MINORS 8 + +#define I3C_TX_NOEMPTY BIT(0) +#define I3C_TTY_TRANS_SIZE 16 +#define I3C_TTY_IBI_TX BIT(0) + +struct ttyi3c_port { + struct tty_port port; + int minor; + struct i3c_target_func *i3cdev; + struct completion txcomplete; + spinlock_t xlock; + void *buffer; + struct work_struct work; + u16 status; + struct i3c_request *req; +}; + +static void i3c_target_tty_rx_complete(struct i3c_request *req) +{ + struct ttyi3c_port *port = req->context; + + if (req->status == I3C_REQUEST_CANCEL) { + i3c_target_ctrl_free_request(req); + return; + } + + tty_insert_flip_string(&port->port, req->buf, req->actual); + tty_flip_buffer_push(&port->port); + + req->actual = 0; + req->status = 0; + i3c_target_ctrl_queue(req, GFP_KERNEL); +} + +static void i3c_target_tty_tx_complete(struct i3c_request *req) +{ + struct ttyi3c_port *sport = req->context; + unsigned long flags; + + if (req->status == I3C_REQUEST_CANCEL) { + i3c_target_ctrl_free_request(req); + return; + } + + spin_lock_irqsave(&sport->xlock, flags); + kfifo_dma_out_finish(&sport->port.xmit_fifo, req->actual); + sport->req = NULL; + + if (kfifo_is_empty(&sport->port.xmit_fifo)) + complete(&sport->txcomplete); + else + queue_work(system_unbound_wq, &sport->work); + + if (kfifo_len(&sport->port.xmit_fifo) < WAKEUP_CHARS) + tty_port_tty_wakeup(&sport->port); + spin_unlock_irqrestore(&sport->xlock, flags); + + i3c_target_ctrl_free_request(req); +} + +static void i3c_target_tty_i3c_work(struct work_struct *work) +{ + struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, work); + struct i3c_request *req = sport->req; + struct scatterlist sg[1]; + unsigned int nents; + u8 ibi; + + if (kfifo_is_empty(&sport->port.xmit_fifo)) + return; + + if (!req) { + req = i3c_target_ctrl_alloc_request(sport->i3cdev->ctrl, GFP_KERNEL); + if (!req) + return; + + sg_init_table(sg, ARRAY_SIZE(sg)); + nents = kfifo_dma_out_prepare(&sport->port.xmit_fifo, sg, ARRAY_SIZE(sg), + UART_XMIT_SIZE); + if (!nents) + goto err; + + req->length = sg->length; + req->buf = sg_virt(sg); + + req->complete = i3c_target_tty_tx_complete; + req->context = sport; + req->tx = true; + + if (i3c_target_ctrl_queue(req, GFP_KERNEL)) + goto err; + + sport->req = req; + } + + ibi = I3C_TTY_IBI_TX; + i3c_target_ctrl_raise_ibi(sport->i3cdev->ctrl, &ibi, 1); + + return; + +err: + i3c_target_ctrl_free_request(req); +} + +static int i3c_port_activate(struct tty_port *port, struct tty_struct *tty) +{ + struct ttyi3c_port *sport = container_of(port, struct ttyi3c_port, port); + const struct i3c_target_ctrl_features *feature; + struct i3c_target_func *func = sport->i3cdev; + struct i3c_request *req; + int rxfifo_size; + int offset = 0; + int ret; + + feature = i3c_target_ctrl_get_features(func->ctrl); + if (!feature) + return -EINVAL; + + ret = tty_port_alloc_xmit_buf(port); + if (ret) + return ret; + + sport->buffer = (void *)get_zeroed_page(GFP_KERNEL); + if (!sport->buffer) + goto err_alloc_rx_buf; + + rxfifo_size = feature->rx_fifo_sz; + + if (!rxfifo_size) + rxfifo_size = I3C_TTY_TRANS_SIZE; + + do { + req = i3c_target_ctrl_alloc_request(func->ctrl, GFP_KERNEL); + if (!req) + goto err_alloc_req; + + req->buf = sport->buffer + offset; + req->length = rxfifo_size; + req->context = sport; + req->complete = i3c_target_tty_rx_complete; + offset += rxfifo_size; + + if (i3c_target_ctrl_queue(req, GFP_KERNEL)) + goto err_alloc_req; + } while (req && offset + rxfifo_size < UART_XMIT_SIZE); + + reinit_completion(&sport->txcomplete); + + return 0; + +err_alloc_req: + i3c_target_ctrl_cancel_all_reqs(func->ctrl, false); + free_page((unsigned long)sport->buffer); +err_alloc_rx_buf: + tty_port_free_xmit_buf(port); + return -ENOMEM; +} + +static void i3c_port_shutdown(struct tty_port *port) +{ + struct ttyi3c_port *sport = container_of(port, struct ttyi3c_port, port); + + cancel_work_sync(&sport->work); + + i3c_target_ctrl_cancel_all_reqs(sport->i3cdev->ctrl, true); + i3c_target_ctrl_cancel_all_reqs(sport->i3cdev->ctrl, false); + + i3c_target_ctrl_fifo_flush(sport->i3cdev->ctrl, true); + i3c_target_ctrl_fifo_flush(sport->i3cdev->ctrl, false); + + tty_port_free_xmit_buf(port); + free_page((unsigned long)sport->buffer); +} + +static void i3c_port_destruct(struct tty_port *port) +{ + struct ttyi3c_port *sport = container_of(port, struct ttyi3c_port, port); + + idr_remove(&i3c_tty_minors, sport->minor); +} + +static const struct tty_port_operations i3c_port_ops = { + .shutdown = i3c_port_shutdown, + .activate = i3c_port_activate, + .destruct = i3c_port_destruct, +}; + +static int i3c_target_tty_bind(struct i3c_target_func *func) +{ + struct ttyi3c_port *sport; + struct device *tty_dev; + int minor; + int ret; + + sport = dev_get_drvdata(&func->dev); + + if (i3c_target_ctrl_set_config(func->ctrl, func)) { + dev_err(&func->dev, "failed to set i3c config\n"); + return -EINVAL; + } + + spin_lock_init(&sport->xlock); + init_completion(&sport->txcomplete); + + ret = minor = idr_alloc(&i3c_tty_minors, sport, 0, I3C_TTY_MINORS, GFP_KERNEL); + + if (minor < 0) + goto err_idr_alloc; + + tty_port_init(&sport->port); + sport->port.ops = &i3c_port_ops; + + tty_dev = tty_port_register_device(&sport->port, i3c_tty_driver, minor, + &func->dev); + if (IS_ERR(tty_dev)) { + ret = PTR_ERR(tty_dev); + goto err_register_port; + } + + sport->minor = minor; + ret = i3c_target_ctrl_enable(func->ctrl); + if (ret) + goto err_ctrl_enable; + + return 0; + +err_ctrl_enable: + tty_port_unregister_device(&sport->port, i3c_tty_driver, sport->minor); +err_register_port: + idr_remove(&i3c_tty_minors, sport->minor); +err_idr_alloc: + i3c_target_ctrl_cancel_all_reqs(func->ctrl, false); + dev_err(&func->dev, "bind failure\n"); + + return ret; +} + +static void i3c_target_tty_unbind(struct i3c_target_func *func) +{ + struct ttyi3c_port *sport; + + sport = dev_get_drvdata(&func->dev); + + cancel_work_sync(&sport->work); + + i3c_target_ctrl_disable(func->ctrl); + i3c_target_ctrl_cancel_all_reqs(func->ctrl, 0); + i3c_target_ctrl_cancel_all_reqs(func->ctrl, 1); + + tty_port_unregister_device(&sport->port, i3c_tty_driver, sport->minor); + + free_page((unsigned long)sport->buffer); +} + +static struct i3c_target_func_ops i3c_func_ops = { + .bind = i3c_target_tty_bind, + .unbind = i3c_target_tty_unbind, +}; + +static int i3c_tty_probe(struct i3c_target_func *func) +{ + struct device *dev = &func->dev; + struct ttyi3c_port *port; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + port->i3cdev = func; + dev_set_drvdata(&func->dev, port); + + INIT_WORK(&port->work, i3c_target_tty_i3c_work); + + return 0; +} + +static ssize_t i3c_write(struct tty_struct *tty, const unsigned char *buf, size_t count) +{ + struct ttyi3c_port *sport = tty->driver_data; + unsigned long flags; + bool is_empty; + int ret = 0; + + spin_lock_irqsave(&sport->xlock, flags); + ret = kfifo_in(&sport->port.xmit_fifo, buf, count); + is_empty = kfifo_is_empty(&sport->port.xmit_fifo); + i3c_target_ctrl_set_status_format1(sport->i3cdev->ctrl, sport->status | I3C_TX_NOEMPTY); + spin_unlock_irqrestore(&sport->xlock, flags); + + if (!is_empty) + queue_work(system_unbound_wq, &sport->work); + + return ret; +} + +static int i3c_put_char(struct tty_struct *tty, unsigned char ch) +{ + struct ttyi3c_port *sport = tty->driver_data; + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&sport->xlock, flags); + ret = kfifo_put(&sport->port.xmit_fifo, ch); + spin_unlock_irqrestore(&sport->xlock, flags); + + return ret; +} + +static void i3c_flush_chars(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + unsigned long flags; + + spin_lock_irqsave(&sport->xlock, flags); + if (!kfifo_is_empty(&sport->port.xmit_fifo)) + queue_work(system_unbound_wq, &sport->work); + spin_unlock_irqrestore(&sport->xlock, flags); +} + +static unsigned int i3c_write_room(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + return kfifo_avail(&sport->port.xmit_fifo); +} + +static void i3c_throttle(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + i3c_target_ctrl_cancel_all_reqs(sport->i3cdev->ctrl, false); +} + +static void i3c_unthrottle(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + i3c_port_activate(&sport->port, tty); +} + +static int i3c_open(struct tty_struct *tty, struct file *filp) +{ + struct ttyi3c_port *sport = container_of(tty->port, struct ttyi3c_port, port); + int ret; + + tty->driver_data = sport; + + if (!i3c_target_ctrl_get_addr(sport->i3cdev->ctrl)) { + dev_dbg(&sport->i3cdev->dev, "No target addr assigned, try hotjoin"); + ret = i3c_target_ctrl_hotjoin(sport->i3cdev->ctrl); + if (ret) { + dev_err(&sport->i3cdev->dev, "Hotjoin failure, check connection"); + return ret; + } + } + + return tty_port_open(&sport->port, tty, filp); +} + +static void i3c_close(struct tty_struct *tty, struct file *filp) +{ + tty_port_close(tty->port, tty, filp); +} + +static void i3c_wait_until_sent(struct tty_struct *tty, int timeout) +{ + struct ttyi3c_port *sport = tty->driver_data; + int val; + int ret; + u8 ibi = I3C_TTY_IBI_TX; + int retry = 100; + + if (!kfifo_is_empty(&sport->port.xmit_fifo)) { + do { + ret = wait_for_completion_timeout(&sport->txcomplete, timeout / 100); + if (ret) + break; + i3c_target_ctrl_raise_ibi(sport->i3cdev->ctrl, &ibi, 1); + } while (retry--); + + reinit_completion(&sport->txcomplete); + } + + read_poll_timeout(i3c_target_ctrl_fifo_status, val, !val, 100, timeout, false, + sport->i3cdev->ctrl, true); + + i3c_target_ctrl_set_status_format1(sport->i3cdev->ctrl, sport->status & ~I3C_TX_NOEMPTY); +} + +static const struct tty_operations i3c_tty_ops = { + .open = i3c_open, + .close = i3c_close, + .write = i3c_write, + .put_char = i3c_put_char, + .flush_chars = i3c_flush_chars, + .write_room = i3c_write_room, + .throttle = i3c_throttle, + .unthrottle = i3c_unthrottle, + .wait_until_sent = i3c_wait_until_sent, +}; + +DECLARE_I3C_TARGET_FUNC(tty, i3c_tty_probe, NULL, &i3c_func_ops); + +static int __init i3c_tty_init(void) +{ + int ret; + + i3c_tty_driver = tty_alloc_driver( + I3C_TTY_MINORS, TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV); + + if (IS_ERR(i3c_tty_driver)) + return PTR_ERR(i3c_tty_driver); + + i3c_tty_driver->driver_name = "ttySI3C", i3c_tty_driver->name = "ttySI3C", + i3c_tty_driver->minor_start = 0, + i3c_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, + i3c_tty_driver->subtype = SERIAL_TYPE_NORMAL, + i3c_tty_driver->init_termios = tty_std_termios; + i3c_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | + CLOCAL; + i3c_tty_driver->init_termios.c_lflag = 0; + + tty_set_operations(i3c_tty_driver, &i3c_tty_ops); + + ret = tty_register_driver(i3c_tty_driver); + if (ret) + goto err_register_tty_driver; + + ret = i3c_target_func_register_driver(&ttyi3c_func); + if (ret) + goto err_register_i3c_driver; + + return 0; + +err_register_i3c_driver: + tty_unregister_driver(i3c_tty_driver); + +err_register_tty_driver: + tty_driver_kref_put(i3c_tty_driver); + + return ret; +} + +static void __exit i3c_tty_exit(void) +{ + i3c_target_func_unregister_driver(&ttyi3c_func); + tty_unregister_driver(i3c_tty_driver); + tty_driver_kref_put(i3c_tty_driver); + idr_destroy(&i3c_tty_minors); +} + +module_init(i3c_tty_init); +module_exit(i3c_tty_exit); + +MODULE_LICENSE("GPL"); + From patchwork Thu Feb 8 17:01:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550110 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8AFCC4829A for ; Thu, 8 Feb 2024 17:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tUdBuPBo+nhI1Jtr6ojtSVPTP652e2lm7MhCTe9+Mj8=; b=IekXR2lZfQBV9j 8Bdhf+fQirsz8tHyMiR5LK0QKoAXAIkt1R8gk9noVF6o70ajqYZIlIi6ZyqnTyJXRQj8lPHZEYYSR +nUg4K3+hv8w5cL+AmiK5WpzaNe8seTgLvIzBU/ULan8pxICX3HUbqshtDVo3PafRsuIbMrFwRPAZ r0fuSp0EPGDFrhzq7r3ut+w0GcGi94myNkOcBKwqOxNen6yBtKuhSJSRfudyzwQ69kIYTxxu/veDz wl+gWse6Br5KsyOV5EaaLi/yXcw8B3a8+sr4DPUzX9NTch2Q9dyu0BGzcp7c2ylH6aU0ArS3hMIx2 RZifNrhh0jyYk/QfZYvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7nl-0000000EOH7-08X3; Thu, 08 Feb 2024 17:03:05 +0000 Received: from mail-vi1eur02on20615.outbound.protection.outlook.com ([2a01:111:f400:fe16::615] helo=EUR02-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7n5-0000000EO67-19lk for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:02:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B1pGIxUs4vWHQteM7sGj2PlT4A7s+tzqwG48AcL9H2q4Ble6V/EWgpLjCVCbkPX7ZMbefa5HjS6GD6EwFTBL4vmdIX0++oKG7peDVw1bNr+U3S9RvN9FbBC9akt+d9mWh0s1tcrD2UcauByHbfMJGY3pj1EUZGeGITHwJonBaAOxHn9/bAbUBg0Svc3CgO+lMwJIjjWpuGluyr7nDhqJqGKQWXloKFCAm8qqAPAfxYVnND4WJbISSRmdIcWVGryTS1YAm1bVWtdzgYoogyvmTI2QMGaVvOeH+SjGhogNUryqYAdEY5aTJVLbH8SuTGTOzDCxtW/OsYgAXnZR2dHkxA== 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=m6ARtUV31Aw0WkrJm4RAXeC+QYXs6+F2YjWwVs9OYOM=; b=DA+9yvaR7gqDIjQuNzuLclYXTIyadZPyYXgNsU3ddZxCBSo3piRyNfJIOR/u0AxdfpJgfZdF4RtoV4D9iSHW71oVsCaJ5h4PUf25MCWeH0wGFKXG68nUFGGIt7WOGRQ5BnuQXRdVJx2altGmUP10D90S4iKVeCNyJKVkMtPeBmfzS29TnwKWzjWOlF8oWcDFeqf08y5r5HBweKEHW6eC2Lx1oFYA8ilOOg1OEFPIhCw0SsY6m3174CvAImukAK+tivyt/pfSJpetqxdacr1VsONZyC76qwhaaTKUtdHe1u9sAVKzcNfVGmv/1/tFnrx+qL3o38FEve7XQVJ6tqXMQw== 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=m6ARtUV31Aw0WkrJm4RAXeC+QYXs6+F2YjWwVs9OYOM=; b=p5Nzwz/wxWpZ+qJVH9lN30usqP90zQuf3wlGKivXwTHEoOVAhxZPLEZJflpscHZW4vIEBxFC1qBDdxtD2PW5V4cg2Zi1d5XVBBFhG64ncBdzi0w2BX0wNBNB9jubED2WaMrRMMGHLPoZLuslPuTceAvv5h3QEuK/juiQxNq/FEM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by VI1PR04MB9931.eurprd04.prod.outlook.com (2603:10a6:800:1d4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.34; Thu, 8 Feb 2024 17:02:06 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:02:06 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 7/8] i3c: add API i3c_dev_gettstatus_format1() to get target device status Date: Thu, 8 Feb 2024 12:01:16 -0500 Message-Id: <20240208170117.798357-8-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|VI1PR04MB9931:EE_ X-MS-Office365-Filtering-Correlation-Id: 3acd3f31-f953-4c79-0c75-08dc28c7adc6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WBfaKCGHc+20t0mlC2aL1/umsqegpRuEd7xUvIHblXUia9GY8kppsirj+9S3YLUeogq23Awnncp1tWfx/qu4778pbRNR0W5WLMpAIlgMm4OO+Ancc7sevXZfLx2mw0Vb2tYJhxBrD1h3D8cQyRATBCETBt5Qqi8NIM3FGVJTiT1atku4IjRsDKfMJUu6OZGVmIRECx10BvMx6N2moogP0KTMnx0uWiZFxmsDQGNug1zk1CCG0eGKnDxTxErnwb0Abb517wGTG03fx/OpBmZrmZ2aIgJHKrEm4lLCtGSSfYCZSHvAfBEpahv4VrGVMTLeuJSS12f9gakg5FRcqK0vnnQFt0umSEyLKi43C86plv3N5psPdmvxKMrl/CWw6BMpSr7OJnLq/soB8UjvJs1oVbHWHekGtkF3201cIc/xCuYKgwwIOFbqLU7702pK5u1Qi+Ud//dYry9Qg7MJFbScPD8lmWwr1gpSzcgRYJvcwZUowwBhIx4rPHeIVNxwQ8ANjVepTSTacxQumLsi3W9WoVei3S2ix2e0/xcQflQAIDSES+YNutYe0NxDs/9kKcpLhdh07tg7xsktKWBVEXpnqtyz5qgnNC+SnbTzgbdXQYhCreXB0+xFtxeb5oldZkSf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(366004)(136003)(376002)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(52116002)(26005)(6512007)(2616005)(41300700001)(37006003)(316002)(1076003)(478600001)(6506007)(66946007)(66476007)(6666004)(83380400001)(6486002)(5660300002)(38100700002)(86362001)(8936002)(7416002)(8676002)(4326008)(2906002)(34206002)(38350700005)(66556008)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WvFXbk2/vy6e/aSWOZZG1DRcK5Hh964W0Tpq7Gkhs82/c4ayegFcjyZxAY7+68BJ8eGVDhhjqZZietJbystgxW4MfNaDKBbuH80rCIGNYbq5QeyvbYo69fj2Qu3rZS6/hwIixvMRRaPFAmZS8VUFWRtPv0cSY1dueeMr3THljnArMDPG6koAX19QTpJahU+q+67x95maPpqhzj37a3HQk34/NHnf1OTgUXO30RsSOrpf1vwVDrQ9A8qHKr1rEeID9HCfCM3536BRfHLnfYhyH3UU5Fj1QvLId1DI858kjuhu0BFjpuTA6slHn2kPz+i2G44p3P55r2lp/2sKJUSGclKqF2VHR7amXEdTkTzRHsQ8mCjW1hEUuZA/q8V0cdZTU1YlD65JRqHYGmt92dvjGM8H/cBf1HxzKyYnJprGe5E9b5HG0khUQutu71BliWtuDyF2yWXK/2YPnxfrnanbvalRA9HNw/JzFJt8cpSKV3M7uwYllhSzJfWWWHk4JNNrSJo9gjzuvRY/gbQYI+KbQ7S0eXD3Uj3KDBxNbS/DPsSeNINtGK581xzBZ69NxXFOtr66mN/PMiyjXMYVsw8XhIlSJTS+QolbRzRBXYuzTsnAFcdU0SAWGozDdu68Q2bJn3dKxLQ6obQ/2x+JNLubvs6ps3Bg19BYmGtTfn7u0qHESMmh1ZIk5DrxuXoo60OAKXSb1egmmrjMvuQPZ2KfaTQjX5uuMNPv+8xUKuvN4FKpfLmzZAb1S13HKiuXXTNVOmd5IQvimUlJAV7ohLisUy+RKmYBjZaE2AHSaogMAkBWI7KNnybl3nbmWLqkLAkdKSZim8iJxtBrxb+pawD3CyWxbXs1EhuKpLRH/lzwPsbsTSgBxuR22Mw5RljPBkhD1mdU43QEgKdfFZI34dZuCex9MzP+McchYds3BW0li82rS6wq0c1X9vKuUz0/USAIK5tefzs2Cx/Zj6rznLPBZXaP8lyjdc3AkXfbgWAvgkuXaAWo/gtho8Wn111RHfUn0HwuWkdyPAsjS07UTzFqQxdWGuTLkOfZvAxrOV7NsVocBGhByd/C/uyfwfCxoW/NWklx2eyhC+9JfxQJ2F5LTEKzC2ImT0iFzuEAvYZBcnpBc7gOAC9SZ6Rg/1kdXhYyINHLI52t001C5xF8fXDpQMmhGLak9hmulK9NIXYrTMbkd3Wczmdx8tz27w8WSQWVL6axCIQ93ztiLPqGoa/WJKb8LNlkaIhqFNyIfjgdgmGvw1pXi5BNnkUJ6TZAN7U6IUWQ6/jS9B3llgDZ3/FaNuDyw2U+QvYCczJcXGAJCDXwwiR0LPlH62vaXPVdQaQAKer+EJ4IK4A7LfYaH0L7QDNKyxcdeyMbzsoFRTOaD+Re5hJC+p2lOD0NQg+ElTMlyvPDxdGvb95FD1mCdDLfj7FaOINMqwGOpJFjR1eplDq7pT+8ntUxxxGxnGcJzdKISlo/tfsY9XUyiQJMcpZaHp/lBJ/afCL0QCmzJEYVtQYb1iCZDnrhR1cNG8kCKVnibyUh7Vd+18Caz+nE8z8ljcBowJQK0/GZZGSgkVRK5NygdBhbVN8C7UmI1yjXJ4y9 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3acd3f31-f953-4c79-0c75-08dc28c7adc6 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:02:06.0241 (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: Wt9EFhDvzkNKtyBFac9bAvexc1kuj6DWD0xK0B5lyQcyhRlZNKLJpK+bWcHgDX+0hoWporwgPpeb1XyKhLXV9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB9931 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_090228_104704_1FFE6529 X-CRM114-Status: GOOD ( 13.05 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org I3C standard 5.1.9.3.15 Get Device Status (GETSTATUS): Get request for one I3C Target Device to return its current status. Add API to fetch it with format1. Signed-off-by: Frank Li --- drivers/i3c/device.c | 24 ++++++++++++++++++++++++ drivers/i3c/internals.h | 1 + drivers/i3c/master.c | 26 ++++++++++++++++++++++++++ include/linux/i3c/device.h | 1 + 4 files changed, 52 insertions(+) diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c index 1a6a8703dbc3a..aa26cf50ab9c6 100644 --- a/drivers/i3c/device.c +++ b/drivers/i3c/device.c @@ -196,6 +196,30 @@ void i3c_device_free_ibi(struct i3c_device *dev) } EXPORT_SYMBOL_GPL(i3c_device_free_ibi); +/** + * i3c_device_getstatus_format1() - Get device status with format 1. + * @dev: device for which you want to get status. + * @status: I3C status format 1 + * + * Return: 0 in case of success, a negative error core otherwise. + */ +int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status) +{ + int ret = -EINVAL; + + if (!status) + return -EINVAL; + + i3c_bus_normaluse_lock(dev->bus); + if (dev->desc) + ret = i3c_dev_getstatus_format1_locked(dev->desc, status); + + i3c_bus_normaluse_unlock(dev->bus); + + return ret; +} +EXPORT_SYMBOL_GPL(i3c_device_getstatus_format1); + /** * i3cdev_to_dev() - Returns the device embedded in @i3cdev * @i3cdev: I3C device diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index 908a807badaf9..976ad26ca79c2 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -24,4 +24,5 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev); int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev, const struct i3c_ibi_setup *req); void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev); +int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status); #endif /* I3C_INTERNAL_H */ diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 3afa530c5e322..ff61a218bcc6d 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2988,6 +2988,32 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev) dev->ibi = NULL; } +int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status) +{ + struct i3c_master_controller *master = i3c_dev_get_master(dev); + struct i3c_ccc_getstatus *format1; + struct i3c_ccc_cmd_dest dest; + struct i3c_ccc_cmd cmd; + int ret; + + format1 = i3c_ccc_cmd_dest_init(&dest, dev->info.dyn_addr, sizeof(*format1)); + if (!format1) + return -ENOMEM; + + i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETSTATUS, &dest, 1); + + ret = i3c_master_send_ccc_cmd_locked(master, &cmd); + if (ret) + goto out; + + *status = be16_to_cpu(format1->status); + +out: + i3c_ccc_cmd_dest_cleanup(&dest); + + return ret; +} + static int __init i3c_init(void) { int res; diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h index e119f11948efe..66920045ff042 100644 --- a/include/linux/i3c/device.h +++ b/include/linux/i3c/device.h @@ -345,4 +345,5 @@ void i3c_device_free_ibi(struct i3c_device *dev); int i3c_device_enable_ibi(struct i3c_device *dev); int i3c_device_disable_ibi(struct i3c_device *dev); +int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status); #endif /* I3C_DEV_H */ From patchwork Thu Feb 8 17:01:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13550224 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E647EC4828F for ; Thu, 8 Feb 2024 17:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PPTeRhWS9vdymX4vAKcAANIjf8jubwOQHGJ4gVTqHnc=; b=rXGf7EjNBUxmkq wxxoUJsGzPWB/HqcpCi1lAi0+Qo2ihIkwBZRw1u0nSmLT1vYcGgP5c9HQyFrwJHPYFDPsBUAozExK uvK2LJGtT9/PzFtaHykQv8Awfrk0xKsG1rSwDB1qe9xfln0q29zWpxAYyoyK0YFS49BshW6qA0Yno 8Mk5M0kJCrF9yawdC+kvD5AL346V04u1yco8U6yXCLmsQ6FOiMiKcjfQ1CpCnRlVCDDWXk39xB1zg b1c5gB8r4qB31XXTv28won1ROZc7rGetM309XuBOPOUnRqqAw21p+iTmU/UdI9IPy9WngELzo2czU 7UjxcaoF2JFxlOcryBHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY82Q-0000000ESSm-40p3; Thu, 08 Feb 2024 17:18:15 +0000 Received: from mail-vi1eur05on20600.outbound.protection.outlook.com ([2a01:111:f403:2613::600] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY820-0000000ESMX-0xiy for linux-i3c@lists.infradead.org; Thu, 08 Feb 2024 17:17:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HZ4kH9RemctFH8XbksraMRpV1jUvMMktqtil8EYjxKQM1c3qx3ZZCWcAb12p5kupYmYVAnlKcn5X7syj/mSUhPHPLW2ul5+TG6rFylv6zh7+o5Ppgvd+/nEk/j+tjqfEmxGhTNTWp/hKVSAkmZhptn/pCcFw+YcS6O9dt8BUZBBEADW5ujCtrieqLXVxgKxvD9qX59P5W/6NhWLvyAUoUEdd39Utd0UQhXAH+ScIkYKl1EswvRpv/OWQgE8hRVjZ4w5tqhNO7F5M0kgSUdiX1Dl7aKqa2OVI+Ey/Nss4cbojj9UjW/E/r6r8MZk0zqHa465gUOVkgzo4QkvF2V4uNw== 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=qpgZbwICckj3ROCqP6QbkMBGI0lLllPHgqPKuswIHVU=; b=kf6BsKc0fRKWYd7duLzPdZJ0PpTdCu994lCvWEzcEitp+MQPKpoR3bMqON4CqAKJjApklyZzj4FjpoQWHXg/+2QYmDA/CpF3FdBOHm924hU1Ccg73VpOrzdx7y4+578Uhb5yFlyOyEc4xpWjkH4mqupvJsBAXTQBLclDGVVURhfvmZsoP0b252BDB1oZVHiLWhSZx833G6+vZ9csjyeKT/CFShonQKqtIo2n4hKd00xgmD56m2zKf3YAlrQCCR4wL/8JlHik8oiighwUwdsNolla+gD9s3YguZFjQnJ2V5uriEQ3od0RhLIae4zCn0LLnzGQNXB9MkB+vbbymUqBwg== 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=qpgZbwICckj3ROCqP6QbkMBGI0lLllPHgqPKuswIHVU=; b=Iq+ozFBYjSiMGlkikk+ycAPgIj/TpQbZCirweJFu538pOTzQkwfzT/FyVe4vA6e9lKI7OFB3/cClr9ZTXIOLgkDcVSxvXyTc/F2vmCKaT2tLt5OKaTvwctw1K62LgNUpTBaVn1cpxhgy5i0GRkbms7ZX546B0G68oEihaikjQOk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB7734.eurprd04.prod.outlook.com (2603:10a6:20b:2a6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Thu, 8 Feb 2024 17:02:10 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::c8b4:5648:8948:e85c%3]) with mapi id 15.20.7249.035; Thu, 8 Feb 2024 17:02:10 +0000 From: Frank Li To: frank.li@nxp.com Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, robh@kernel.org, zbigniew.lukwinski@linux.intel.com Subject: [PATCH v8 8/8] tty: i3c: add TTY over I3C master support Date: Thu, 8 Feb 2024 12:01:17 -0500 Message-Id: <20240208170117.798357-9-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208170117.798357-1-Frank.Li@nxp.com> References: <20240208170117.798357-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0245.namprd03.prod.outlook.com (2603:10b6:a03:3a0::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB7734:EE_ X-MS-Office365-Filtering-Correlation-Id: c8fa3833-52f6-428d-4090-08dc28c7b041 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PkqNFnzsPzD/PJsnJUYhOB+Ee0v6XxaJBfLWRAonNL1Bxo3Yjpy1R9Xcv+CTJoBWbksK3oHHFqFOtA+dZ6msWXiHPPCAQ5hbr9EhGvrWhA4TwQO+nUrffqfkusXWPvNGzfVG4Dywxv1BlPRv6TJbtFY+oKwTY1Ko4cCcn593Cxq7CMM5e4VofWCSxrYYjoOnEgcGRyu+JHTJG4Esdq6vVR1/YdYsL4pE2gDrFw6ObrWPVsEmhlsbbIyMcnCElJwABARIrCApcAWj01BRdvdCtKiKLFHUqHmwc7aVZJ2TNQb1cY7o0Ze6iznLmHXYXcEak9UQPW/M+re84l7dINC8Jt78wKoma668CL8Hv5Og7FLTkBReUhDRhGxtiXeGoE1XOPQ+2KpqbndezNTlL+liFfDfzWnAa16GF1uf8Fgc9JwtsZQvJPyhf2IllPuncs6tj5fX5ZQGAj30jf9rjUzrMUMXUBz9dDANd9rSBNnLl7sDjecUS5l079xLIsp2iyIn+pomm8I+fweNNM8sesp8sDxtihhG+bGSDLICoiKFMfO5r1RnJDTupVOCXG4sh8g25Cbs2Iil5my6sXyHNUGieYGfSZzGn2fsU50YAvB0cIM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(39860400002)(396003)(136003)(376002)(346002)(230922051799003)(230273577357003)(1800799012)(64100799003)(451199024)(186009)(41300700001)(86362001)(30864003)(8676002)(8936002)(34206002)(7416002)(4326008)(6506007)(966005)(36756003)(2616005)(1076003)(6486002)(52116002)(478600001)(6512007)(5660300002)(26005)(37006003)(66556008)(38350700005)(66476007)(66946007)(316002)(83380400001)(2906002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1UGogynTP+83Ilk7zgecr5EY7xyXxVI0kqOYj/uhKjB10ZbMeGRyJXvJhyyyzrOaAEWnP1zFCgbhyLS5kt+IhKkuf/Fk9MG0mKjQojGH1TeQcvZb9F5O5DWDpvdLN/zM6jh7YD3OTrG0Ws8IA9POtngzIrzA1F1lzMfd+HJladq+xfxbCtc8H10SjqxDjBnGnA4OntTTX0WvpOW2uoivVUED38PQdXV7Taec2VKWKBDBSY6tEr+C/Edytotvu0Nfw6VvKjg6g1FoO0fIl4wzmkIWIB3KE/YoQD2tBu6ko7/nuCcyBi/r7W/jFACIfJPbhi7I4kPMS9jT2yAzxIgD09onHSsp2VbPZPulhmU4NSZIxirFRRahMSQOLhQoSnhRSzq6eUjvXXBY1Vte+xtW4mX/Pl99D2SyKvrXnyI6ydAL8B5IdoBOS6ATZfkOX+JY+Wx0eQYWCeMBStPE+Et06VIbdVe93M64hcbEytUd0v7jxeFHvDzar9z80SYLPYgGbA1Ue1SzAz6T5UDfWUD9qy5KmdY3bluD1fMsgI+2khpaxfRrR1pgpDgV5QTi0ungmdcw7X1RR8ISi0vI1FGFMy4Dk/uEOfoB1L4iCMjMFZ9ICosoA9JC212ZiupRafmcxMWF6zAwsMZcWe11IAkJoSdBfscATFVJMderaJWor/fvMGMo0QWycKJ617TDjZK8t0fynRxFnzmm4wrLaqY2Wsi/h8utZZ34okLOqyhjsn7ok/P4gQs5gxU4flYKJqoRffTVm2kU/CFTFo+qtu8/raWOP3RpjalPZkS2ND+JpUl7wDn+F28psvEkbZaLkjvaWWC/3n82wCtsYMjRRfYnCLSK+8YwzFoq5gDBlq2y+6DV1Ex520tDqAJBYmMkWM6IGRtp36jckJANXWdYr/Ke+gAyBrDFb1XFNiGPB+Gl7PqatDXJaRbZWecI3wWTauRMaettERK8fZnolLqJndLgdYo8rs6/f0WrYc9WbMhlody94I8AXvJOOK6kmOUfoGbT676X3wXtROVMnd8JT/q9q9rIlJsJZBQ0Hv6A74NYBNlExdRG4tz0LDU++9eRahKs1SL7B9HMsovQe94EHIiPC1xdNJa6+OabDJ9ZEiaMmrxg6pKYEIc8g8nJk/7W7gVM0hRQaJadhu3Y+/dMGg+/t/rc/BaLc0K1yP4+CfdDo+paByPtRSZcdoS7L0jXbM7fBMKJ3fP7t71S0DXKZ+HYnXxg098RTh4nCrinavFJ3E1Oxsxk0GD8hCC1A0zkupkAvWzP3XMkYallBZ9lBBZKRBg5lsKT+4fd5+9WlMpxnZmZNRjEFKAxdGpQCOPmIyI+wvdpVJHKXGWYDHVgObP7PkxzPkCmnqZriG1BtVHJRGhRMh+LEPSDb8/7EWDwuCToufZvBlsDEDo9ZdRH2qV5yQ9zQNeWRcCQEu4JLcXGmPG5YORuGItd0Ux5eCRfmxyq60L/9mSwZ4mRu8KQd7fSyGdPW0rBc2ukXxHmh+wIuR9sHoY4j5HRuU7PSvTHETEqu9PVN9PcAzKm+3ZSxHj4dWAqCIOM3KOGZqXrfUeZ+d6VB92zKgJRwkI0Mre1Uf7x X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8fa3833-52f6-428d-4090-08dc28c7b041 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 17:02:10.3909 (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: AJ/1Z7yL9My2sU9jTQSWDRxir7iFMcUJb+aAiWlHVrZZkNIPXsa8ufEMrSW8fcF/PIFedMIWNMKui5dvZnzu8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7734 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_091748_867646_DEDF7EDA X-CRM114-Status: GOOD ( 23.57 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org In typical embedded Linux systems, UART consoles require at least two pins, TX and RX. In scenarios where I2C/I3C devices like sensors or PMICs are present, we can save these two pins by using this driver. Pins is crucial resources, especially in small chip packages. This introduces support for using the I3C bus to transfer console tty data, effectively replacing the need for dedicated UART pins. This not only conserves valuable pin resources but also facilitates testing of I3C's advanced features, including early termination, in-band interrupt (IBI) support, and the creation of more complex data patterns. Additionally, it aids in identifying and addressing issues within the I3C controller driver. Signed-off-by: Frank Li --- Notes: Notes: Version number use i3c target patches. Change from v7 to v8 - reorder head files - add missed head files Change from v6 to v7 - try to fixed build warning https://lore.kernel.org/imx/20240202230925.1000659-1-Frank.Li@nxp.com/T/#m4e35da31a4226186b3dc6bc8f2fba28f58be1188 but I can't reproduce this error in my machine with powerpc-linux-gcc (GCC) 13.2.0 kernel test robot have not show reproduce step. But anyway, status may not init if code through continue branch. So Move status = I3C_TTY_TARGET_RX_READY; before continue branch. Change from v5 to v6 -none Change from v4 to v5 - add missed header file - add define for BIT(0) - oneline for struct ttyi3c_port *sport Change from v3 to v4 - add static at i3c_remove() Change v2 - using system_unbound_wq working queue - fixed accoring to Jiri Slaby's comments Change before send with i3c target support Change from v4 to v5 - send in i3c improvememtn patches. Change from v2 to v4 - none Change from v1 to v2 - update commit message. - using goto for err handle - using one working queue for all tty-i3c device - fixed typo found by js - update kconfig help - using kfifo Still below items not be fixed (according to Jiri Slaby's comments) - rxwork thread: need trigger from two position. - common thread queue: need some suggestion Notes: Version number use i3c target patches. Change from v3 to v4 - add static at i3c_remove() Change v2 - using system_unbound_wq working queue - fixed accoring to Jiri Slaby's comments Change before send with i3c target support Change from v4 to v5 - send in i3c improvememtn patches. Change from v2 to v4 - none Change from v1 to v2 - update commit message. - using goto for err handle - using one working queue for all tty-i3c device - fixed typo found by js - update kconfig help - using kfifo Still below items not be fixed (according to Jiri Slaby's comments) - rxwork thread: need trigger from two position. - common thread queue: need some suggestion drivers/tty/Kconfig | 13 ++ drivers/tty/Makefile | 1 + drivers/tty/i3c_tty.c | 432 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 446 insertions(+) create mode 100644 drivers/tty/i3c_tty.c diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index 5646dc6242cd9..9ab4cd480e9f8 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -412,6 +412,19 @@ config RPMSG_TTY To compile this driver as a module, choose M here: the module will be called rpmsg_tty. +config I3C_TTY + tristate "TTY over I3C" + depends on I3C + help + Select this option to use TTY over I3C master controller. + + This makes it possible for user-space programs to send and receive + data as a standard tty protocol. I3C provide relatively higher data + transfer rate and less pin numbers, SDA/SCL are shared with other + devices. + + If unsure, say N + endif # TTY source "drivers/tty/serdev/Kconfig" diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile index 07aca5184a55d..f329f9c7d308a 100644 --- a/drivers/tty/Makefile +++ b/drivers/tty/Makefile @@ -27,5 +27,6 @@ obj-$(CONFIG_GOLDFISH_TTY) += goldfish.o obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o obj-$(CONFIG_VCC) += vcc.o obj-$(CONFIG_RPMSG_TTY) += rpmsg_tty.o +obj-$(CONFIG_I3C_TTY) += i3c_tty.o obj-y += ipwireless/ diff --git a/drivers/tty/i3c_tty.c b/drivers/tty/i3c_tty.c new file mode 100644 index 0000000000000..235cd0524b0b7 --- /dev/null +++ b/drivers/tty/i3c_tty.c @@ -0,0 +1,432 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 NXP. + * + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_IDR(i3c_tty_minors); +static DEFINE_MUTEX(i3c_tty_minors_lock); + +static struct tty_driver *i3c_tty_driver; + +#define I3C_TTY_MINORS 8 +#define I3C_TTY_TRANS_SIZE 16 +#define I3C_TTY_RX_STOP 0 +#define I3C_TTY_RETRY 20 +#define I3C_TTY_YIELD_US 100 +#define I3C_TTY_TARGET_RX_READY BIT(0) + +struct ttyi3c_port { + struct tty_port port; + int minor; + spinlock_t xlock; /* protect xmit */ + u8 tx_buff[I3C_TTY_TRANS_SIZE]; + u8 rx_buff[I3C_TTY_TRANS_SIZE]; + struct i3c_device *i3cdev; + struct work_struct txwork; + struct work_struct rxwork; + struct completion txcomplete; + unsigned long status; + u32 buf_overrun; +}; + +static const struct i3c_device_id i3c_ids[] = { + I3C_DEVICE(0x011B, 0x1000, NULL), + { /* sentinel */ }, +}; + +static int i3c_port_activate(struct tty_port *port, struct tty_struct *tty) +{ + struct ttyi3c_port *sport = container_of(port, struct ttyi3c_port, port); + int ret; + + ret = tty_port_alloc_xmit_buf(port); + if (ret < 0) + return ret; + + sport->status = 0; + + ret = i3c_device_enable_ibi(sport->i3cdev); + if (ret) { + tty_port_free_xmit_buf(port); + return ret; + } + + return 0; +} + +static void i3c_port_shutdown(struct tty_port *port) +{ + struct ttyi3c_port *sport = container_of(port, struct ttyi3c_port, port); + + i3c_device_disable_ibi(sport->i3cdev); + tty_port_free_xmit_buf(port); +} + +static void i3c_port_destruct(struct tty_port *port) +{ + struct ttyi3c_port *sport = container_of(port, struct ttyi3c_port, port); + + mutex_lock(&i3c_tty_minors_lock); + idr_remove(&i3c_tty_minors, sport->minor); + mutex_unlock(&i3c_tty_minors_lock); +} + +static const struct tty_port_operations i3c_port_ops = { + .shutdown = i3c_port_shutdown, + .activate = i3c_port_activate, + .destruct = i3c_port_destruct, +}; + +static ssize_t i3c_write(struct tty_struct *tty, const unsigned char *buf, size_t count) +{ + struct ttyi3c_port *sport = tty->driver_data; + unsigned long flags; + bool is_empty; + int ret; + + spin_lock_irqsave(&sport->xlock, flags); + ret = kfifo_in(&sport->port.xmit_fifo, buf, count); + is_empty = kfifo_is_empty(&sport->port.xmit_fifo); + spin_unlock_irqrestore(&sport->xlock, flags); + + if (!is_empty) + queue_work(system_unbound_wq, &sport->txwork); + + return ret; +} + +static int i3c_put_char(struct tty_struct *tty, unsigned char ch) +{ + struct ttyi3c_port *sport = tty->driver_data; + unsigned long flags; + int ret; + + spin_lock_irqsave(&sport->xlock, flags); + ret = kfifo_put(&sport->port.xmit_fifo, ch); + spin_unlock_irqrestore(&sport->xlock, flags); + + return ret; +} + +static void i3c_flush_chars(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + queue_work(system_unbound_wq, &sport->txwork); +} + +static unsigned int i3c_write_room(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + return kfifo_avail(&sport->port.xmit_fifo); +} + +static void i3c_throttle(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + clear_bit(I3C_TTY_RX_STOP, &sport->status); +} + +static void i3c_unthrottle(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + set_bit(I3C_TTY_RX_STOP, &sport->status); + + queue_work(system_unbound_wq, &sport->rxwork); +} + +static int i3c_open(struct tty_struct *tty, struct file *filp) +{ + struct ttyi3c_port *sport = container_of(tty->port, struct ttyi3c_port, port); + + tty->driver_data = sport; + + return tty_port_open(&sport->port, tty, filp); +} + +static void i3c_close(struct tty_struct *tty, struct file *filp) +{ + tty_port_close(tty->port, tty, filp); +} + +static const struct tty_operations i3c_tty_ops = { + .open = i3c_open, + .close = i3c_close, + .write = i3c_write, + .put_char = i3c_put_char, + .flush_chars = i3c_flush_chars, + .write_room = i3c_write_room, + .throttle = i3c_throttle, + .unthrottle = i3c_unthrottle, +}; + +static void i3c_controller_irq_handler(struct i3c_device *dev, + const struct i3c_ibi_payload *payload) +{ + struct ttyi3c_port *sport = dev_get_drvdata(&dev->dev); + + /* i3c_unthrottle also queue the work to fetch pending data in target side */ + queue_work(system_unbound_wq, &sport->rxwork); +} + +static void tty_i3c_rxwork(struct work_struct *work) +{ + struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, rxwork); + struct i3c_priv_xfer xfers; + u32 retry = I3C_TTY_RETRY; + u16 status; + int ret; + + memset(&xfers, 0, sizeof(xfers)); + xfers.data.in = sport->rx_buff; + xfers.len = I3C_TTY_TRANS_SIZE; + xfers.rnw = 1; + + do { + if (test_bit(I3C_TTY_RX_STOP, &sport->status)) + break; + + i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1); + + status = I3C_TTY_TARGET_RX_READY; + + if (xfers.actual_len) { + ret = tty_insert_flip_string(&sport->port, sport->rx_buff, + xfers.actual_len); + if (ret < xfers.actual_len) + sport->buf_overrun++; + + retry = I3C_TTY_RETRY; + continue; + } + + i3c_device_getstatus_format1(sport->i3cdev, &status); + /* + * Target side needs some time to fill data into fifo. Target side may not + * have hardware update status in real time. Software update status always + * needs some delays. + * + * Generally, target side have circular buffer in memory, it will be moved + * into FIFO by CPU or DMA. 'status' just show if circular buffer empty. But + * there are gap, especially CPU have not response irq to fill FIFO in time. + * So xfers.actual will be zero, wait for little time to avoid flood + * transfer in i3c bus. + */ + usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US); + retry--; + + } while (retry && (status & I3C_TTY_TARGET_RX_READY)); + + tty_flip_buffer_push(&sport->port); +} + +static void tty_i3c_txwork(struct work_struct *work) +{ + struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, txwork); + struct i3c_priv_xfer xfers; + u32 retry = I3C_TTY_RETRY; + unsigned long flags; + int ret; + + xfers.rnw = 0; + xfers.data.out = sport->tx_buff; + + while (!kfifo_is_empty(&sport->port.xmit_fifo)) { + spin_lock_irqsave(&sport->xlock, flags); + xfers.len = kfifo_out_peek(&sport->port.xmit_fifo, sport->tx_buff, + I3C_TTY_TRANS_SIZE); + spin_unlock_irqrestore(&sport->xlock, flags); + ret = i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1); + if (ret) { + /* + * Target side may not move data out of FIFO. delay can't resolve problem, + * just reduce some possiblity. Target can't end I3C SDR mode write + * transfer, discard data is reasonable when FIFO overrun. + */ + usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US); + retry--; + } else { + retry = I3C_TTY_RETRY; + } + + if (ret == 0 || retry == 0) { + /* when retry == 0, means need discard the data */ + spin_lock_irqsave(&sport->xlock, flags); + ret = kfifo_out(&sport->port.xmit_fifo, sport->tx_buff, xfers.len); + spin_unlock_irqrestore(&sport->xlock, flags); + } + } + + spin_lock_irqsave(&sport->xlock, flags); + if (kfifo_len(&sport->port.xmit_fifo) < WAKEUP_CHARS) + tty_port_tty_wakeup(&sport->port); + spin_unlock_irqrestore(&sport->xlock, flags); +} + +static int i3c_probe(struct i3c_device *i3cdev) +{ + struct ttyi3c_port *sport; + struct device *tty_dev; + struct i3c_ibi_setup req; + int minor; + int ret; + + sport = devm_kzalloc(&i3cdev->dev, sizeof(*sport), GFP_KERNEL); + if (!sport) + return -ENOMEM; + + sport->i3cdev = i3cdev; + + dev_set_drvdata(&i3cdev->dev, sport); + + req.max_payload_len = 8; + req.num_slots = 4; + req.handler = &i3c_controller_irq_handler; + + ret = i3c_device_request_ibi(i3cdev, &req); + if (ret) + return -EINVAL; + + mutex_lock(&i3c_tty_minors_lock); + minor = idr_alloc(&i3c_tty_minors, sport, 0, I3C_TTY_MINORS, GFP_KERNEL); + mutex_unlock(&i3c_tty_minors_lock); + + if (minor < 0) { + ret = -EINVAL; + goto err_idr_alloc; + } + + spin_lock_init(&sport->xlock); + INIT_WORK(&sport->txwork, tty_i3c_txwork); + INIT_WORK(&sport->rxwork, tty_i3c_rxwork); + init_completion(&sport->txcomplete); + + tty_port_init(&sport->port); + sport->port.ops = &i3c_port_ops; + + tty_dev = tty_port_register_device(&sport->port, i3c_tty_driver, minor, + &i3cdev->dev); + if (IS_ERR(tty_dev)) { + ret = PTR_ERR(tty_dev); + goto err_tty_port_register; + } + + sport->minor = minor; + + return 0; + +err_tty_port_register: + tty_port_put(&sport->port); + + mutex_lock(&i3c_tty_minors_lock); + idr_remove(&i3c_tty_minors, minor); + mutex_unlock(&i3c_tty_minors_lock); + +err_idr_alloc: + i3c_device_free_ibi(i3cdev); + + return ret; +} + +static void i3c_remove(struct i3c_device *dev) +{ + struct ttyi3c_port *sport = dev_get_drvdata(&dev->dev); + + tty_port_unregister_device(&sport->port, i3c_tty_driver, sport->minor); + cancel_work_sync(&sport->txwork); + + tty_port_put(&sport->port); + + mutex_lock(&i3c_tty_minors_lock); + idr_remove(&i3c_tty_minors, sport->minor); + mutex_unlock(&i3c_tty_minors_lock); + + i3c_device_free_ibi(sport->i3cdev); +} + +static struct i3c_driver i3c_driver = { + .driver = { + .name = "ttyi3c", + }, + .probe = i3c_probe, + .remove = i3c_remove, + .id_table = i3c_ids, +}; + +static int __init i3c_tty_init(void) +{ + int ret; + + i3c_tty_driver = tty_alloc_driver(I3C_TTY_MINORS, + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV); + + if (IS_ERR(i3c_tty_driver)) + return PTR_ERR(i3c_tty_driver); + + i3c_tty_driver->driver_name = "ttyI3C"; + i3c_tty_driver->name = "ttyI3C"; + i3c_tty_driver->minor_start = 0, + i3c_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, + i3c_tty_driver->subtype = SERIAL_TYPE_NORMAL, + i3c_tty_driver->init_termios = tty_std_termios; + i3c_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | + CLOCAL; + i3c_tty_driver->init_termios.c_lflag = 0; + + tty_set_operations(i3c_tty_driver, &i3c_tty_ops); + + ret = tty_register_driver(i3c_tty_driver); + if (ret) + goto err_tty_register_driver; + + ret = i3c_driver_register(&i3c_driver); + if (ret) + goto err_i3c_driver_register; + + return 0; + +err_i3c_driver_register: + tty_unregister_driver(i3c_tty_driver); + +err_tty_register_driver: + tty_driver_kref_put(i3c_tty_driver); + + return ret; +} + +static void __exit i3c_tty_exit(void) +{ + i3c_driver_unregister(&i3c_driver); + tty_unregister_driver(i3c_tty_driver); + tty_driver_kref_put(i3c_tty_driver); + idr_destroy(&i3c_tty_minors); +} + +module_init(i3c_tty_init); +module_exit(i3c_tty_exit); + +MODULE_LICENSE("GPL");