From patchwork Thu Aug 1 09:44:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manikanta Guntupalli X-Patchwork-Id: 13750099 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 D5D8BC3DA4A for ; Thu, 1 Aug 2024 09:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding: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=GcoAbiRiHj9cBJ0eoyPfj+OdcY/NqCs+SSUFeHG0+wk=; b=GbyBqWnz41m6cuidzOHhdJxf+P h7uJxseWxtd1eHB4fdjxm/DZuLTEqzrw0IwtYXVrin1pnbVRw7synPHoNaBnFmCSc0tsJZ/0/za47 PLAgfnKgvAbmwto+ygBi5goOCa1akyRTOBALic+HdT7egkv7FVP7dhcnPWLpFa7LGb30gkq4c1LoS 8nYs+kMWQpu1aKmIo2wlYjdZJPxfHThTv6d2b6wQ39MNCp9jSKQooCks14DIOesX0TMoxsXoIz0nu JBR1BIByEI+XHL5TlCTpArZMrTMUyjc/KcTfcI62Y5IN92JNBf4LezDrlEMvsteBmrSxHmKttREYw VajryDiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZSNO-00000004dTa-2owO; Thu, 01 Aug 2024 09:45:38 +0000 Received: from mail-bn8nam12on20605.outbound.protection.outlook.com ([2a01:111:f403:2418::605] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZSMS-00000004dAk-0LOY for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 09:44:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YlEExDfp4U/iDDh8OndRjsLppheQmSyDfWzkBeTlecN3Xz0GjM6sCsn11ibQw9tUceaMRTesPq/6H9Zai2qXKndUNZToV5Rq+0EkV1z1895ziMZnG7U46MBuV+F7nQleGOezfXzZOeLYWd8A3K+PjWPyzhGB2CBZS1C8U+eMzGbrxT5YigoTqy3rf6OutnyysqlfR26Xdpg8bvUUgIP73c98hREDsHVXXuAbEAC7n2JVKsFhwupCr+nR+aKLqH1rE2WjtI/TQK2nWdZnSIg4qtiIgZVes3l2gZuby74zOerHRQ9nAvLQukNn952IUO/83xieD/THjnJa4WZPTemOcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=GcoAbiRiHj9cBJ0eoyPfj+OdcY/NqCs+SSUFeHG0+wk=; b=FL9LHpWKW7z1R2uyL2Kr/PEnI4vOjIMgknlQsv/W98qXtd2ayJQqpgVJE9lC3WbubuXdAKG5t9iZPgzG811baxcutEgDB0PFVKKXZbbzLoqueWAYuS+49R6x6Td8WmIYM8WBv6C8IixjMwF7lB1Owp1VZaybXh0BsLTj8N9LP7FS2kkrIwsfWiFmuSl04lADmIjV0NL8Yx4RFjwTXiVVGR3Nt6K+/E2qFCC+JA6/Q7Y/QA5NwjF4OU/7sRgelGM32IUiPUHKv6oToibNpOqLs5HtgYPwFFHjkHkB0237niv90oAp6WaEYuJ9BcBksT7hXLE02eXBUMUspsTsT5p5dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GcoAbiRiHj9cBJ0eoyPfj+OdcY/NqCs+SSUFeHG0+wk=; b=jTrD0Ebq+rHNNHh2QbOKvYuNoVNkllfEDLlnMuobynutBCAF/RzsGT5CcojsYgnV3qYQ+jDJFcV2DZCKCUdShGDtTjdvprSnOfY4+O6qLFCmiR2LK5Nj+6OVqiOwXBCG5pvSg831F8NnYpswOI6YPPRMXkOHUuc8xuWD3iimoCQ= Received: from SJ2PR07CA0018.namprd07.prod.outlook.com (2603:10b6:a03:505::22) by SA1PR12MB7126.namprd12.prod.outlook.com (2603:10b6:806:2b0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Thu, 1 Aug 2024 09:44:30 +0000 Received: from SJ1PEPF00001CDD.namprd05.prod.outlook.com (2603:10b6:a03:505:cafe::13) by SJ2PR07CA0018.outlook.office365.com (2603:10b6:a03:505::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22 via Frontend Transport; Thu, 1 Aug 2024 09:44:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ1PEPF00001CDD.mail.protection.outlook.com (10.167.242.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Thu, 1 Aug 2024 09:44:29 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 1 Aug 2024 04:44:28 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 1 Aug 2024 04:44:28 -0500 Received: from xhdsneeli40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Thu, 1 Aug 2024 04:44:25 -0500 From: Manikanta Guntupalli To: , , , , CC: , , , , , Manikanta Guntupalli Subject: [PATCH 1/3] i2c: cadence: Relocate cdns_i2c_runtime_suspend and cdns_i2c_runtime_resume to facilitate atomic mode Date: Thu, 1 Aug 2024 15:14:06 +0530 Message-ID: <20240801094408.2004460-2-manikanta.guntupalli@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240801094408.2004460-1-manikanta.guntupalli@amd.com> References: <20240801094408.2004460-1-manikanta.guntupalli@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: manikanta.guntupalli@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDD:EE_|SA1PR12MB7126:EE_ X-MS-Office365-Filtering-Correlation-Id: 1eb15c18-b3b0-4b6f-313e-08dcb20e8a2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: +BJRJjUNqVG570U4rP2K4OnoadIPxmk2Z5c47prrzdQKupYQK/lRjyEFHk2iMtgeYBLsu10QijJfSJ9mLltohBR+ap4Cn89fwTeuwpdOuopBTeKnkcTV8qtbPZd99ChOLc8X/GPY56by+vuFeD6UcA0eZ6w20rWpdO4F872xAujJs3qDNOgPEbF1USwepkirQ/xhtvHTwOYeuXHxAhORxu4flJz3muLxPY8kOdb/pZZ/ytTqdIJu/gjTOeFyxbWNKTYLZk2Rbo7zuxn9/WgIqZyuisZ94uX/OO12kyKms1X6d96NDSoVb7GtnobVqzkuwM9dKqo7jvlqDw5Z1nxjqj2ZDSV6J4cNKZWXUstMd8D8ZAWrfmgmg2xAkYwZGMlE3DOm6LNnxtUJC6ayX2U+f7KySR8SgkzYAv6EDqGa1rSd7b9P2q+AJNfjsfVPIeOr22dxc+uORhzfv5CiPTP2aw1ocUyHxObkGiP+oTeAZMqYgijKXq9Vm5o6UGAF6G0P56zdbXotVdhATod0wgtlnI4yAcNqcpzj4K8Y5JFfBp3BbBACLGv3lWAKblkmnt+TOVyq5u4vPnJ/NWJWBduF4uGq9JLXw64fMbUUwt3RnGJ08IaND9pkwigRfB4WW9fN1WQC77ko0n1s3BMOFCaNoXXgH9izShDXfbLOccupn4DpwYpkhrR/62CNxlLxBdPfVjDqp0rim0yn499yTuNAfsBrLvlrM8maa1gkHixt3qRVGa1wPTi+OWpQcCPDN3zsvuV9/V6wEoHyXU7+QkCmlv9ikW7T/MiuIh0zrq4SruElwrmWx5YJSV5NDWJbUSvAIb/VDJxHohArd1ey2SKIf9buLvUWuAX9UgkD1nLHLftHUNdqko1IJYlFKjEoSoQZBJzDZxd7ve0HIpNXf8AaE/SK6DIz/UdRXUfChZLaH9+6XJv51R8gJTyrZRhZztc/Qx+gWPU6JlGaVMmsNkCbz8e4imMNykkEjhcjYZsPkPEbO22/eH1rFTdYBvuftmEt/kcZ2JZQnTQgvPqEkcDe4BzonZXQO0whl/z4Jr/tW5ZSZjQZNYMGCy3Bvq1ld17nrCAZYKB79gdpmGp2m1B1JkRV5KxAMCy0C1F++39Hc95dikJj5uoUk30P8a3Lmnt3RvcF+0I5N/aZRY8i1xd2e7hSBWhMciaweFyAzhma2djIpqWfvK51G1uTUm+CS0LfCcsGJsQ+M5EW5zIeLomman/w1QVOL6LfbjD+KrDYz0ROSJTMG/KtVCoHYCuvHBtgQpaJu6F8zih5g/Qscjf2qHHgHvgOT63CKJgntCYLoJeb37tm3QtfTlQS2CzIBzoUADlyy8p3NHM4TEzmgWaYL6fwcC5KrwAXKtUPOw7pAtIgr2C40igeSUpd+NO5V2StfAI2yDckEANSyCtAIAK3aewAlzjZ1ePk+Jmx6QjMEroF1VJEeVxr+zQ0k53gm1gu X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2024 09:44:29.5930 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1eb15c18-b3b0-4b6f-313e-08dcb20e8a2e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7126 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_024440_152346_82ECEA2E X-CRM114-Status: GOOD ( 20.70 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Relocate cdns_i2c_runtime_suspend, cdns_i2c_runtime_resume and cdns_i2c_init functions to avoid prototype statement in atomic mode changes. Signed-off-by: Manikanta Guntupalli Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-cadence.c | 120 +++++++++++++++---------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index 87b9ba95b2e1..d3f6ca2cb4d7 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -228,6 +228,66 @@ struct cdns_platform_data { #define to_cdns_i2c(_nb) container_of(_nb, struct cdns_i2c, \ clk_rate_change_nb) +/** + * cdns_i2c_init - Controller initialisation + * @id: Device private data structure + * + * Initialise the i2c controller. + * + */ +static void cdns_i2c_init(struct cdns_i2c *id) +{ + cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET); + /* + * Cadence I2C controller has a bug wherein it generates + * invalid read transaction after HW timeout in master receiver mode. + * HW timeout is not used by this driver and the interrupt is disabled. + * But the feature itself cannot be disabled. Hence maximum value + * is written to this register to reduce the chances of error. + */ + cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET); +} + +/** + * cdns_i2c_runtime_suspend - Runtime suspend method for the driver + * @dev: Address of the platform_device structure + * + * Put the driver into low power mode. + * + * Return: 0 always + */ +static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev) +{ + struct cdns_i2c *xi2c = dev_get_drvdata(dev); + + clk_disable(xi2c->clk); + + return 0; +} + +/** + * cdns_i2c_runtime_resume - Runtime resume + * @dev: Address of the platform_device structure + * + * Runtime resume callback. + * + * Return: 0 on success and error value on error + */ +static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev) +{ + struct cdns_i2c *xi2c = dev_get_drvdata(dev); + int ret; + + ret = clk_enable(xi2c->clk); + if (ret) { + dev_err(dev, "Cannot enable clock.\n"); + return ret; + } + cdns_i2c_init(xi2c); + + return 0; +} + /** * cdns_i2c_clear_bus_hold - Clear bus hold bit * @id: Pointer to driver data struct @@ -1158,23 +1218,6 @@ static int cdns_i2c_clk_notifier_cb(struct notifier_block *nb, unsigned long } } -/** - * cdns_i2c_runtime_suspend - Runtime suspend method for the driver - * @dev: Address of the platform_device structure - * - * Put the driver into low power mode. - * - * Return: 0 always - */ -static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev) -{ - struct cdns_i2c *xi2c = dev_get_drvdata(dev); - - clk_disable(xi2c->clk); - - return 0; -} - static int __maybe_unused cdns_i2c_suspend(struct device *dev) { struct cdns_i2c *xi2c = dev_get_drvdata(dev); @@ -1187,49 +1230,6 @@ static int __maybe_unused cdns_i2c_suspend(struct device *dev) return 0; } -/** - * cdns_i2c_init - Controller initialisation - * @id: Device private data structure - * - * Initialise the i2c controller. - * - */ -static void cdns_i2c_init(struct cdns_i2c *id) -{ - cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET); - /* - * Cadence I2C controller has a bug wherein it generates - * invalid read transaction after HW timeout in master receiver mode. - * HW timeout is not used by this driver and the interrupt is disabled. - * But the feature itself cannot be disabled. Hence maximum value - * is written to this register to reduce the chances of error. - */ - cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET); -} - -/** - * cdns_i2c_runtime_resume - Runtime resume - * @dev: Address of the platform_device structure - * - * Runtime resume callback. - * - * Return: 0 on success and error value on error - */ -static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev) -{ - struct cdns_i2c *xi2c = dev_get_drvdata(dev); - int ret; - - ret = clk_enable(xi2c->clk); - if (ret) { - dev_err(dev, "Cannot enable clock.\n"); - return ret; - } - cdns_i2c_init(xi2c); - - return 0; -} - static int __maybe_unused cdns_i2c_resume(struct device *dev) { struct cdns_i2c *xi2c = dev_get_drvdata(dev); From patchwork Thu Aug 1 09:44:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manikanta Guntupalli X-Patchwork-Id: 13750100 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 3C05AC3DA4A for ; Thu, 1 Aug 2024 09:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding: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=jvNWgj4HYDN+r4/iIpSW8c5iCRjU4wr2TN7Dx7RrDj8=; b=lem9/KETJP/6NwK4dR53Cdx+Lx dXrEXHiLKWwMgKihaFR+UR5t/Tb1bG6uU99PeLu79/x1+EZyreliIgvIj2EDqIFR3BTqL1/+d8BZF miavNMR9JHxirvClMJCZHnq1LT5eodJuknr7VsAJe0LRJvT3GmnPQDuIukKToz4NYlLB9ZCrSmfrS IiPaPKYnqZvdJLKBvcttzVa33XwCbwfoQPSi9pWxVJEAmoAid5RQGFVIutsWpTKnRhPATsrEVnZoe 7Mh2BgkEzGfc/ae7gJMZKEHHyrzjKMKwnHojkaQjxxs6pi06izDNkIGHKKxb/aBY34x84kI0sR3tL R94h0f0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZSNq-00000004dc5-1yRV; Thu, 01 Aug 2024 09:46:06 +0000 Received: from mail-bn8nam04on20606.outbound.protection.outlook.com ([2a01:111:f403:2408::606] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZSMS-00000004dAl-0QEL for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 09:44:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xfaRa9Fc7Nvul1NqzU93SmJ2jLBB+Wdo9MGthfx++o6DfthRUt45oPK4WXoFh0EM7K+2RoYodlTvDAG7aNPUlCi8ZbzMsl+gUzkSXN8tbip9cezNJznEgg3tg+JlV6JOFPRg/lk2qr5bgBMLk6TKbhGwy/4w0f1wT/HcwjEKLNsZF1PFf3EnskbND5yu1SGSWMP2qQ9ZAo8mRIw8KKhi8vMob/eHuEeF7NxTC+votv3gbOUrZTOz5SZxsbSF71psYjRAXuOvyqlmGpScysLpC6iRUq5ALFoIsuzwdLGkhWzP31i3iU8tepztMHi+DFFWokILD4n27rTrzGft5qor4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=jvNWgj4HYDN+r4/iIpSW8c5iCRjU4wr2TN7Dx7RrDj8=; b=myZ4/W1dEpS51obrGpZEq00sZM134DcImzifGpW3eV3PRCbgUaMHiCnyI8ulgMD4GkdsLpSpiPHzDjxIVVI12Y9GSSrdUTHuz2UgKwbTsXCtNyk9OxyXoiq+B98+clh0O01muuHa4JSJUHjYnwOpBWJv/wKPRqTnclfe4mMepW1NyGUZ0KNF4Qo1wdt6cbmpewfVPGY8ENf16XxLTrAe2o5lJxZMi+fIk0k/2tMj4dqXawb6IAHE/tWn4kUBYLP51fjFTK2IrD/98Gw8IKEgzPxSPWyig0tm8q0eLzLzpIcglsThO9znoa56JefQblGeB3C9q7k6hF3JxxksLkjdmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jvNWgj4HYDN+r4/iIpSW8c5iCRjU4wr2TN7Dx7RrDj8=; b=cI6yDrIlvojOJDciSEzB84q/MT8SfGUKOw5jHz3VeJgdGDNswgLqtY/uWesDcTSVJFZrX9lX1hp84vup8WVSAHIFQIbpHb9j+EDsCMZLxiTJ3mCTbxR3bXbjGxUoGFQ4ZFlnnxkBWj8feND9D+BeUwUGrkLEqLH6YkqfwWTgUb0= Received: from DM5PR07CA0097.namprd07.prod.outlook.com (2603:10b6:4:ae::26) by CY8PR12MB8363.namprd12.prod.outlook.com (2603:10b6:930:7a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22; Thu, 1 Aug 2024 09:44:35 +0000 Received: from CY4PEPF0000EE3B.namprd03.prod.outlook.com (2603:10b6:4:ae:cafe::2e) by DM5PR07CA0097.outlook.office365.com (2603:10b6:4:ae::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22 via Frontend Transport; Thu, 1 Aug 2024 09:44:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE3B.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Thu, 1 Aug 2024 09:44:35 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 1 Aug 2024 04:44:34 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 1 Aug 2024 04:44:33 -0500 Received: from xhdsneeli40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Thu, 1 Aug 2024 04:44:30 -0500 From: Manikanta Guntupalli To: , , , , CC: , , , , , Manikanta Guntupalli Subject: [PATCH 2/3] i2c: cadence: Split cdns_i2c_master_xfer for Atomic Mode Date: Thu, 1 Aug 2024 15:14:07 +0530 Message-ID: <20240801094408.2004460-3-manikanta.guntupalli@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240801094408.2004460-1-manikanta.guntupalli@amd.com> References: <20240801094408.2004460-1-manikanta.guntupalli@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: manikanta.guntupalli@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3B:EE_|CY8PR12MB8363:EE_ X-MS-Office365-Filtering-Correlation-Id: 6faf14fd-08ad-4ff7-79d6-08dcb20e8d67 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: D1wFvT5ZmMfKvxmYv+YGPOUtXSwYNLgdgHRqeMzw3BPN1Z0Gw/0ocl7RY0g8Q2xPmh6sHPJ5Oiv3fdeg61nDUBv0l9zs3+U19blipKHyfwSG2qb9tjtcn2slMgQfAudothnMKRdm1zk271mtzlmfC9NZrGxuCFuuDOLTrvYiKR4KQai/nB3WSFozZndNimAAjge6DjYR7PAWk+iPI50/ondMF1zNegnkWkkpyf7rL35h9ZMFAabxId9MYc5kMb0J2ArFgPEDZqqZZHRoKcHpqXGS0Bb9v1DMqt3rmfeiSvP4VHhuBIf0aOaEvNSUcrGVgal5xkW0QFQNaSQqjfkZRbMdpXKF/vM4LSQK5pTLBWhJrn1RWROy/JqTLbtahK/TpUA3fMfWpP+mgG+zMOWSbffQz7h/nXsz/6hGwnHHEfz8nqFlZmLEqLayW5+Tf2m4m0JWH0/UixEFTOYBvnxYmPQhyCZJ+hzVimOpnbKvz5At6zJaYbt+WiijIa31zWOCtx3nz1m249GMfD4ryvz+k1VQFCvivmE31/E9Xs9NTvWkcA1k8JBLY7eCpm5VNDRp/bKkAc3qntzzn3BLQvGaorpfN+LlbhqsraMqY1cvw1eWyBLfyrwYZnUkB6WznhtkgYO4MacyvmpmxdKtZZvpMEdnve9J5gZXxdZXHGlLIJO8pXTZ6dswjsEVLvsBOs2BkrYXGfa5jgV0SOKsuIf82nuOTvvGUjc7KoL/+2gbYGriP39hG7xShjtVj9m78AcR0JKqgG7Afio+99r9VjOK1LWkMhOFUxJKpLBnwsspsI5oRv8Ds/gmsuXZG1r8dcqrPuXWE7knkHW4KRFYmcgRwPjG9HycrtBFNfKhaeTmTH0x3n/RE/IB4XkIFNxfWZGgOEYQx+o882odmlg2dhzqUbFL0GiHbPOX9GtlA4MYkvOuS1MiJbJdFG5CwXj/YiQkW/3+3Jl7QgzUcwVCL8moPp03hvYzYxVNgWrE5JjSrw0M4Ujdbok2RQs1vjQYCEcCENrJkc5E1y6zc6umVNXBOJFoqxc37cSubI9KsI/av8QnbuIxCKrGQMHTdlImeQjWGymoRWYS4xGS55Mxu9mQworEU7aQpji8+5XNLvOThw6pW1uMeZ9jnDTXFl7pnmQQYdPwIuIgKx9VJ5u5JG6gJu36cVriZ8f8g0iXd5309mw6Oek+Z3z0Ad4e1rMKYRyUosMJxECkLNJ9Mhz2UjRcL9VMT1rQcRONSxoZjzMuxsyIsH0LSddPHpUbpovbZo9DE4GiZQE1STU0cTqPM+rGdA4ZAn8ePvTBxGlBJXtXLwYGecRfr+McaJgRLkmFLqaThAXjsxkJLmrotveKlf64rDVdoT1/Ghk5GotUc8uVPGjmI2cuLxwkA1/AGHgKXgeg1tlewzTCcW7koCZ79PFwsk9VStRmcgz2qasUlOJyACZ9hMa++Z2Yuc6h+Toxmcuq X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2024 09:44:35.0329 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6faf14fd-08ad-4ff7-79d6-08dcb20e8d67 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8363 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_024440_170243_08BC7AC6 X-CRM114-Status: GOOD ( 19.95 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The cdns_i2c_master_xfer function has been refactored to separate the common code. This change facilitates better support for atomic mode operations by isolating the shared logic. Signed-off-by: Manikanta Guntupalli Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-cadence.c | 100 ++++++++++++++++--------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index d3f6ca2cb4d7..e689448d229f 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -866,46 +866,14 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, return 0; } -/** - * cdns_i2c_master_xfer - The main i2c transfer function - * @adap: pointer to the i2c adapter driver instance - * @msgs: pointer to the i2c message structure - * @num: the number of messages to transfer - * - * Initiates the send/recv activity based on the transfer message received. - * - * Return: number of msgs processed on success, negative error otherwise - */ -static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, - int num) +static int cdns_i2c_master_common_xfer(struct i2c_adapter *adap, + struct i2c_msg *msgs, + int num) { int ret, count; u32 reg; struct cdns_i2c *id = adap->algo_data; bool hold_quirk; -#if IS_ENABLED(CONFIG_I2C_SLAVE) - bool change_role = false; -#endif - - ret = pm_runtime_resume_and_get(id->dev); - if (ret < 0) - return ret; - -#if IS_ENABLED(CONFIG_I2C_SLAVE) - /* Check i2c operating mode and switch if possible */ - if (id->dev_mode == CDNS_I2C_MODE_SLAVE) { - if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) { - ret = -EAGAIN; - goto out; - } - - /* Set mode to master */ - cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); - - /* Mark flag to change role once xfer is completed */ - change_role = true; - } -#endif /* Check if the bus is free */ @@ -917,7 +885,7 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, ret = -EAGAIN; if (id->adap.bus_recovery_info) i2c_recover_bus(adap); - goto out; + return ret; } hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); @@ -937,8 +905,7 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, if (msgs[count].flags & I2C_M_RD) { dev_warn(adap->dev.parent, "Can't do repeated start after a receive message\n"); - ret = -EOPNOTSUPP; - goto out; + return -EOPNOTSUPP; } } id->bus_hold_flag = 1; @@ -956,26 +923,65 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, ret = cdns_i2c_process_msg(id, msgs, adap); if (ret) - goto out; + return ret; /* Report the other error interrupts to application */ if (id->err_status) { cdns_i2c_master_reset(adap); - if (id->err_status & CDNS_I2C_IXR_NACK) { - ret = -ENXIO; - goto out; - } - ret = -EIO; - goto out; + if (id->err_status & CDNS_I2C_IXR_NACK) + return -ENXIO; + + return -EIO; } } + return 0; +} - ret = num; +/** + * cdns_i2c_master_xfer - The main i2c transfer function + * @adap: pointer to the i2c adapter driver instance + * @msgs: pointer to the i2c message structure + * @num: the number of messages to transfer + * + * Initiates the send/recv activity based on the transfer message received. + * + * Return: number of msgs processed on success, negative error otherwise + */ +static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, + int num) +{ + int ret; + struct cdns_i2c *id = adap->algo_data; +#if IS_ENABLED(CONFIG_I2C_SLAVE) + bool change_role = false; +#endif -out: + ret = pm_runtime_resume_and_get(id->dev); + if (ret < 0) + return ret; + +#if IS_ENABLED(CONFIG_I2C_SLAVE) + /* Check i2c operating mode and switch if possible */ + if (id->dev_mode == CDNS_I2C_MODE_SLAVE) { + if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) { + ret = -EAGAIN; + goto out; + } + + /* Set mode to master */ + cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); + + /* Mark flag to change role once xfer is completed */ + change_role = true; + } +#endif + ret = cdns_i2c_master_common_xfer(adap, msgs, num); + if (!ret) + ret = num; #if IS_ENABLED(CONFIG_I2C_SLAVE) +out: /* Switch i2c mode to slave */ if (change_role) cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); From patchwork Thu Aug 1 09:44:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manikanta Guntupalli X-Patchwork-Id: 13750101 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 C17CBC3DA4A for ; Thu, 1 Aug 2024 09:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding: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=giiw7thtg0RWaqNT8pREJ2RKq059p0IDmXwhkxJC2QE=; b=vxKBmYSzMN0DmV3dq0GZXx9d2/ jb5m0qSJP/V7KhWKur5+QMXGIW5WEAe3X0DIzQc+Wstc3l4ra13CHIoYSFh1089PhqP7SYXMqjqjm Dl2lwy77njgk5+NK/ZCY59VqvBzZP4weoUttr/dKsui/ZAb+uhEnjOQNviHAc5zV28q5zSqvScDeS 9ZYSsprRGd5w+nxbxdX7rMsFn/DPyVBpWdfsin7aDhoHTrSYOROPH3V18opNidDO8ZU3df5jVR89j f8uE3XA9QpeE7wWrPJDFCCult4eN46A50HMPgQG6HOBPZyKgalG1HKV3q9SS4mPQlIc7rJvht+/43 rTigQcCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZSOH-00000004dhz-03MH; Thu, 01 Aug 2024 09:46:33 +0000 Received: from mail-bn8nam04on20615.outbound.protection.outlook.com ([2a01:111:f403:2408::615] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZSMg-00000004dEb-0js6 for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 09:44:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Jmur/qC/iLQG+6U2tPjJ6bOSkjW8jVSRPIVq1GSRyo2UBCd0qCDAyVbIcBbKkzB8wGkCDDurBcgMAnZquxfyXkMz5hx4MB6Ii98kSZVeOp8a8W1Jr9f3n7zB1WZqR0B2ohOF3mvPzFHiKWilnEmHRwEI3QFPeLxRKVf9fC1pgFpvtM3hEMWGWz2U+/u2+K75UHRmIwRDw8VTQ32UD4x7mnL+t9NP9CgslRsdP7eFo/ZBm2gnmUKMUGVR+TbzWZCNLNIwjwpJTEoT7Jsvpid3CEN8tecoeP+oEgAM668O1qR/WqrvvP25Tvmd+DU/DwahEshLy4FhXONqh4rR9HNYqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=giiw7thtg0RWaqNT8pREJ2RKq059p0IDmXwhkxJC2QE=; b=MKpK0fmRhduPjpQLzU1Spd42Zp1JXHO7OHd0LPBljzgTJ01bVNJLiGH/qhpn/vlYiH1tBokIixLFabjYR+5HWlzSV+Ha+UxGWRffJaOtItWAeJT+sTRatO0+djY4HFfehmv6D0NoHx4VmVYkklMCNf+pRw7/WWiCipe0SUAgxGn/Gjt+Y7ewJz7RWuh+3LJ45IBtqQM55HeBOCbTTuMJmeVUmIB/QQ0gmxeKcVZkyiFwcYKPC9Ccnzw3YAmhksmb7rQc/tlpzM/n0Nne8qLJpM4lla2xseh2aXRPjkEjqD4clAIt9qLt5jsiNbrIvc3cafm7KT1GFfeY2OGsShTK/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=giiw7thtg0RWaqNT8pREJ2RKq059p0IDmXwhkxJC2QE=; b=laq23D7cy9lrd6+C/GbdTyJdYvaTKV+D+aotrg3zUQ8CIjYtvoAoBN1p/w+YzD4dzVuTNZ5j0DiMM68ktdAg1nnB3LdRBAtWOgfkAqMLx6cX4pYJmRUW//BCq8yNj+q+2L2Yx633ouFEIaz8ogORu0jCFH2Bod2LiAZ4IxvyZSk= Received: from MW4PR04CA0094.namprd04.prod.outlook.com (2603:10b6:303:83::9) by PH7PR12MB5686.namprd12.prod.outlook.com (2603:10b6:510:13d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Thu, 1 Aug 2024 09:44:42 +0000 Received: from SJ1PEPF00001CE0.namprd05.prod.outlook.com (2603:10b6:303:83:cafe::29) by MW4PR04CA0094.outlook.office365.com (2603:10b6:303:83::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.22 via Frontend Transport; Thu, 1 Aug 2024 09:44:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ1PEPF00001CE0.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7828.19 via Frontend Transport; Thu, 1 Aug 2024 09:44:41 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 1 Aug 2024 04:44:40 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 1 Aug 2024 04:44:40 -0500 Received: from xhdsneeli40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Thu, 1 Aug 2024 04:44:37 -0500 From: Manikanta Guntupalli To: , , , , CC: , , , , , Manikanta Guntupalli Subject: [PATCH 3/3] i2c: cadence: Add atomic transfer support for controller version 1.4 Date: Thu, 1 Aug 2024 15:14:08 +0530 Message-ID: <20240801094408.2004460-4-manikanta.guntupalli@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240801094408.2004460-1-manikanta.guntupalli@amd.com> References: <20240801094408.2004460-1-manikanta.guntupalli@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: manikanta.guntupalli@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE0:EE_|PH7PR12MB5686:EE_ X-MS-Office365-Filtering-Correlation-Id: c3c926ec-aac8-443c-ec27-08dcb20e914c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: T0tg3Fc2CVlvC9Dp8M/hF8SdizUbAJQ3vXXBmAQrxppiLRdoTmFHhvlLcyXZX8WsVy0d1qecVoT/QhuSSQnlNtY0awQY7sBVFwyr8Rm2wPMWso+7SWQqpob9JB+t52yCbfXc3PQD/9PLQPb9gLt50gKc0MboijYe+Qb0WvZHqLCkXK0TFSwvN139VFEdlqRhyGYYCTBChcrrrNDF8lzoHKV7uGzj+fLU4XUfCoWsSblM//pT4VNX3kiznE9oxXIMtLjR4St1jnPNSmlPlmwqJkYHcVkimEJf107OlhrgAqIYZm72AWNlN6PowzGPKIIGzutR31VfG8T92ORgJ0fwlDoO40CRXE2ST2ZMs2Bi43SmmJE4UYWMJZSV5/C4QG+kXQm/yAuRbxg18T6Z+GOIeZKodh+4kfqh2mTJ/rJsxBE+fDTMW/TtGmEZ8pxi4AY5bHpIV0vyWa0JLRjFuoyHDjuYsLf3sCJc1ZNXQwNjC+rBTcwYZEBWZyR4aLKDUkKa3kMlbgzcrojFoCMl3puaxaUWISQbVbgBqmWooPTWFyDgAdJE2JKwyUfa5iFk6cqaiLkqhxSNdwNoF/QSVYbxbn5PGirIomY/y38SJ80AtUGxZQKvH8E7mnl/QtWmBObfLkJuqVDB3TpjstG00OsjwWxaY3n36lQZldBWU8UwfobuKsnwco+CVKfMR4ZDxxGv9V0WiojeGmj5lAbM7zHDrX0urAC/uCZVqSkOVb1L2VpYK3Gx9xMxRKNGFTBSdjWR8ysIeJ8LDbmtDb4kx4J+Vv66tsFRXe3c7DZs9N4SwbrjD0dN9Dp01p0lGBNM33sD+quUNTU+KjYXG62gQCa/QNjqssq9DHbQ8STPIzaBfItIqvZStoYtP9XobICycRwFE/HoppvPOnV2FgE9+MFcr+V7ojLKcK3QOjApaSeRRaxg3hc3/6+Bfzr7LCelcoUAaTZpgVEV83RlsWjW40tl7xWL8JwqAddYO5RuwlyBHel48cstPxJMYpM94S2eenEcTONBqdgJNBbENTc7er6oAdeXJ713QVKN/t5yQmgUvM0pmiwwUevXBXIsY0Sf5MOSwRvows1TqKSxFtDp0g74Pktz/v9mRgET1XZJhXOXazL+LZ7f/+VIzEpajmkrFD2YjHUMBbpJil2P1phSXQYE3AN9fN5bP5xhWTIo0ArhIKQB3EY0zjwvA1oVM8RnTRvZjGAy+QVhfv3y1dMM84Ka/Y8JeDHMvZi13L9DljWtCx4vlAetbGrmlFF8tEVYLxx54oYwm5dwb8nN7wov63DHZVjSixpA6n+j5zdn1W3tW5krkZeAQmIwxwjjrJ9/LscrUyAqZJfh7QbdKQ5J51QOOmof7aFfymoUDyVTGL2+6r93VCqDlW8t/2e+BIS4kRcCxXt5nUlv42TshY/G0Aa0b6D0Oay80C5UcTQnEEFzrY1bg0wrfJSPIjGZf3mep7H0 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2024 09:44:41.5385 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3c926ec-aac8-443c-ec27-08dcb20e914c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5686 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240801_024454_754308_82F896CB X-CRM114-Status: GOOD ( 28.74 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rework the read and write code paths in the driver to support operation in atomic contexts in master mode. This change does not apply to slave mode because there is no way to handle interruptions in that context. Adjust the message timeout to include some extra time. For non-atomic contexts, 500 ms is added to the timeout. For atomic contexts, 2000 ms is added because transfers happen in polled mode, requiring more time to account for the polling overhead. Similar changes have been implemented in other drivers, including: commit 3a5ee18d2a32 ("i2c: imx: implement master_xfer_atomic callback") commit 445094c8a9fb ("i2c: exynos5: add support for atomic transfers") commit ede2299f7101 ("i2c: tegra: Support atomic transfers") commit fe402bd09049 ("i2c: meson: implement the master_xfer_atomic callback") Signed-off-by: Manikanta Guntupalli --- drivers/i2c/busses/i2c-cadence.c | 202 ++++++++++++++++++++++++++++--- 1 file changed, 188 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index e689448d229f..8b8433faf959 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -129,6 +129,7 @@ #define CDNS_I2C_BROKEN_HOLD_BIT BIT(0) #define CDNS_I2C_POLL_US 100000 +#define CDNS_I2C_POLL_US_ATOMIC 10 #define CDNS_I2C_TIMEOUT_US 500000 #define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset) @@ -189,6 +190,8 @@ enum cdns_i2c_slave_state { * @slave_state: I2C Slave state(idle/read/write). * @fifo_depth: The depth of the transfer FIFO * @transfer_size: The maximum number of bytes in one transfer + * @atomic: Mode of transfer + * @err_status_atomic: Error status in atomic mode */ struct cdns_i2c { struct device *dev; @@ -219,6 +222,8 @@ struct cdns_i2c { #endif u32 fifo_depth; unsigned int transfer_size; + bool atomic; + int err_status_atomic; }; struct cdns_platform_data { @@ -256,7 +261,7 @@ static void cdns_i2c_init(struct cdns_i2c *id) * * Return: 0 always */ -static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev) +static int cdns_i2c_runtime_suspend(struct device *dev) { struct cdns_i2c *xi2c = dev_get_drvdata(dev); @@ -273,7 +278,7 @@ static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev) * * Return: 0 on success and error value on error */ -static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev) +static int cdns_i2c_runtime_resume(struct device *dev) { struct cdns_i2c *xi2c = dev_get_drvdata(dev); int ret; @@ -621,6 +626,90 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr) return cdns_i2c_master_isr(ptr); } +static bool cdns_i2c_error_check(struct cdns_i2c *id) +{ + unsigned int isr_status; + + id->err_status = 0; + + isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); + cdns_i2c_writereg(isr_status & CDNS_I2C_IXR_ERR_INTR_MASK, CDNS_I2C_ISR_OFFSET); + + id->err_status = isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; + if (id->err_status) + return true; + + return false; +} + +static void cdns_i2c_mrecv_atomic(struct cdns_i2c *id) +{ + bool updatetx; + + while (id->recv_count > 0) { + /* + * Check if transfer size register needs to be updated again for a + * large data receive operation. + */ + updatetx = id->recv_count > id->curr_recv_count; + + while (id->curr_recv_count > 0) { + if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_RXDV) { + *id->p_recv_buf++ = cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET); + id->recv_count--; + id->curr_recv_count--; + + /* + * Clear hold bit that was set for FIFO control + * if RX data left is less than or equal to + * FIFO DEPTH unless repeated start is selected + */ + if (id->recv_count <= id->fifo_depth && !id->bus_hold_flag) + cdns_i2c_clear_bus_hold(id); + } + if (cdns_i2c_error_check(id)) + return; + if (cdns_is_holdquirk(id, updatetx)) + break; + } + + /* + * The controller sends NACK to the slave when transfer size + * register reaches zero without considering the HOLD bit. + * This workaround is implemented for large data transfers to + * maintain transfer size non-zero while performing a large + * receive operation. + */ + if (cdns_is_holdquirk(id, updatetx)) { + /* wait while fifo is full */ + while (cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET) != + (id->curr_recv_count - id->fifo_depth)) + ; + + /* + * Check number of bytes to be received against maximum + * transfer size and update register accordingly. + */ + if (((int)(id->recv_count) - id->fifo_depth) > + id->transfer_size) { + cdns_i2c_writereg(id->transfer_size, + CDNS_I2C_XFER_SIZE_OFFSET); + id->curr_recv_count = id->transfer_size + + id->fifo_depth; + } else { + cdns_i2c_writereg(id->recv_count - + id->fifo_depth, + CDNS_I2C_XFER_SIZE_OFFSET); + id->curr_recv_count = id->recv_count; + } + } + } + + /* Clear hold (if not repeated start) */ + if (!id->recv_count && !id->bus_hold_flag) + cdns_i2c_clear_bus_hold(id); +} + /** * cdns_i2c_mrecv - Prepare and start a master receive operation * @id: pointer to the i2c device structure @@ -715,7 +804,34 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id) cdns_i2c_writereg(addr, CDNS_I2C_ADDR_OFFSET); } - cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); + if (!id->atomic) + cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); + else + cdns_i2c_mrecv_atomic(id); +} + +static void cdns_i2c_msend_rem_atomic(struct cdns_i2c *id) +{ + unsigned int avail_bytes; + unsigned int bytes_to_send; + + while (id->send_count) { + avail_bytes = id->fifo_depth - cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET); + if (id->send_count > avail_bytes) + bytes_to_send = avail_bytes; + else + bytes_to_send = id->send_count; + + while (bytes_to_send--) { + cdns_i2c_writereg((*id->p_send_buf++), CDNS_I2C_DATA_OFFSET); + id->send_count--; + } + if (cdns_i2c_error_check(id)) + return; + } + + if (!id->send_count && !id->bus_hold_flag) + cdns_i2c_clear_bus_hold(id); } /** @@ -778,7 +894,12 @@ static void cdns_i2c_msend(struct cdns_i2c *id) cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, CDNS_I2C_ADDR_OFFSET); - cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); + if (!id->atomic) { + cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); + } else { + if (id->send_count > 0) + cdns_i2c_msend_rem_atomic(id); + } } /** @@ -818,7 +939,8 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, id->p_msg = msg; id->err_status = 0; - reinit_completion(&id->xfer_done); + if (!id->atomic) + reinit_completion(&id->xfer_done); /* Check for the TEN Bit mode on each msg */ reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); @@ -841,13 +963,24 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, /* Minimal time to execute this message */ msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk); /* Plus some wiggle room */ - msg_timeout += msecs_to_jiffies(500); + if (!id->atomic) + msg_timeout += msecs_to_jiffies(500); + else + msg_timeout += msecs_to_jiffies(2000); if (msg_timeout < adap->timeout) msg_timeout = adap->timeout; - /* Wait for the signal of completion */ - time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); + if (!id->atomic) { + /* Wait for the signal of completion */ + time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); + } else { + /* 0 is success, -ETIMEDOUT is error */ + time_left = !readl_poll_timeout_atomic(id->membase + CDNS_I2C_ISR_OFFSET, + reg, (reg & CDNS_I2C_IXR_COMP), + CDNS_I2C_POLL_US_ATOMIC, msg_timeout); + } + if (time_left == 0) { cdns_i2c_master_reset(adap); return -ETIMEDOUT; @@ -876,11 +1009,16 @@ static int cdns_i2c_master_common_xfer(struct i2c_adapter *adap, bool hold_quirk; /* Check if the bus is free */ - - ret = readl_relaxed_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET, - reg, - !(reg & CDNS_I2C_SR_BA), - CDNS_I2C_POLL_US, CDNS_I2C_TIMEOUT_US); + if (!id->atomic) + ret = readl_relaxed_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET, + reg, + !(reg & CDNS_I2C_SR_BA), + CDNS_I2C_POLL_US, CDNS_I2C_TIMEOUT_US); + else + ret = readl_poll_timeout_atomic(id->membase + CDNS_I2C_SR_OFFSET, + reg, + !(reg & CDNS_I2C_SR_BA), + CDNS_I2C_POLL_US_ATOMIC, CDNS_I2C_TIMEOUT_US); if (ret) { ret = -EAGAIN; if (id->adap.bus_recovery_info) @@ -926,7 +1064,7 @@ static int cdns_i2c_master_common_xfer(struct i2c_adapter *adap, return ret; /* Report the other error interrupts to application */ - if (id->err_status) { + if (id->err_status || id->err_status_atomic) { cdns_i2c_master_reset(adap); if (id->err_status & CDNS_I2C_IXR_NACK) @@ -992,6 +1130,41 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, return ret; } +/** + * cdns_i2c_master_xfer_atomic - The i2c transfer function in atomic mode + * @adap: pointer to the i2c adapter driver instance + * @msgs: pointer to the i2c message structure + * @num: the number of messages to transfer + * + * Return: number of msgs processed on success, negative error otherwise + */ +static int cdns_i2c_master_xfer_atomic(struct i2c_adapter *adap, struct i2c_msg *msgs, + int num) +{ + int ret; + struct cdns_i2c *id = adap->algo_data; + + ret = cdns_i2c_runtime_resume(id->dev); + if (ret) + return ret; + + if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) { + dev_warn(id->adap.dev.parent, + "Atomic xfer not supported for version 1.0\n"); + return 0; + } + + id->atomic = true; + ret = cdns_i2c_master_common_xfer(adap, msgs, num); + if (!ret) + ret = num; + + id->atomic = false; + cdns_i2c_runtime_suspend(id->dev); + + return ret; +} + /** * cdns_i2c_func - Returns the supported features of the I2C driver * @adap: pointer to the i2c adapter structure @@ -1056,6 +1229,7 @@ static int cdns_unreg_slave(struct i2c_client *slave) static const struct i2c_algorithm cdns_i2c_algo = { .master_xfer = cdns_i2c_master_xfer, + .master_xfer_atomic = cdns_i2c_master_xfer_atomic, .functionality = cdns_i2c_func, #if IS_ENABLED(CONFIG_I2C_SLAVE) .reg_slave = cdns_reg_slave,