From patchwork Fri Oct 7 00:42:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arminder Singh X-Patchwork-Id: 13000832 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 76B54C433FE for ; Fri, 7 Oct 2022 00:44:45 +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: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:In-Reply-To:References: List-Owner; bh=0CcuH3ZiI2ayCoOenuYTBQ9SVnSCxDBcOfQk1GUUxsc=; b=Z7f768m018ZFwL HGaCoLM23C6PzwLrVqS9KkdxkiFJoWkZKTYf/7rZQt2+o6URr4HiYtlDE0dhuwSrxNCVUlfCow1BT bppxjsPTPWFQ6Ybmt5f/vPIdK/3C3amoKozmWndqJc8UYvdh2WRDKAPwe6RqIQ9pRHkaLrlF544mk upgehO1AQrtu+W8dp2YcargC6KSIA/s3DddNLymzggBtSkg2bwRDBqMfVi4v0Xz1mGLicMFbalfLL Vz6br1GfXPWy8xkjbAnFMUceMD51fAuCZ4so+ZEwpvgloEhSJYBr/t9Kaq5jEAS1HxcEcG5xAhgqX Oqe3YG2n3iSxu9b6tkmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogbSP-006G4P-NJ; Fri, 07 Oct 2022 00:43:17 +0000 Received: from mail-bn7nam10olkn2041.outbound.protection.outlook.com ([40.92.40.41] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogbSL-006G3N-Vl for linux-arm-kernel@lists.infradead.org; Fri, 07 Oct 2022 00:43:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffOnQ0V7XQxGm/Z+K90iHYhl9euDCobfW16V3FAsrNW2ZvwaOrnjx50ni/uPTcpoagygmyhhu6MakRA49VviSetMMizpPjt/m0vx0Y7NeDni/1xQJ+ERX7wTr8x5nzWbbmuuVEdRUVSI/apIgz8YTV2eb3GjTJm8XJvWvs8pFT+UbSYjuA7xz8feDWqLJD1SFwjFE/hyDM0A3/sQFf3TPAxCSUmuVRfAuKTUmrMwusnONLzDLGTfArzvDuzb7JrVbXeQTcIaEzH1fGb/+t5NxXYlgoxyVb1K7mJYMEolXfkZlWPy5BgeLejyvaU/srYgG11k4Ir5fAumdxfhgbkqmQ== 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=pqukOOrvRDIhkBG1itTCkuejnMLMzhVBDjnmBgzOZ5Y=; b=WIGspF+KKj8g48TzFuktfg7Z0JmHN4VQZkwiRneKgX7ehbmeW7OOKyROQNn0dNVemzxnJg/3GknB5g2v2MWTxx7LmylStjDVRc8rKXdD0qDIG+LCOlFg1WKqU3fNHskhoEDUyffVqMzwqpOyFNmMdYVKi3m4sSCNUg6dwj9a+AHA7+O2KT1uGo5FxD0Rd0BvQ5AFW+X69xRuKY3heq+6EV2vnw0cKISS9ocgOmZSSk1O4EzgAAU7AeMJC/eLqYgZ7OZ1LeIM+JH1ihpSQzrAeM4NP/4U98f+CGmtsQ3WiFqxsIBfKiP9fmUVqo2YQHdDWMohDJ1eVbN52J/8QQhnqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pqukOOrvRDIhkBG1itTCkuejnMLMzhVBDjnmBgzOZ5Y=; b=kcn2AwBR5GXp5b977KH2miBiJve1EqiErw3hJ+s5/5AAeu2MejuaHlD7zZNpKnK3S18d5HvIuTmfi/+OrcSqpoa6gk5RUnSRNzdwP63GLbQAJx/RCNxPVT8AXrRDNuyuUFXhg4x7lQm8pTDGokic4Yt7X8Q6P3ehB/euppMcVJ5tGuJNp7PzA6unfCfUDsLitolxlBJSfs2+nd0rAi13PN/JFg8NWOm4b2lu83uMU1IrYVmhXsDIx0eiosNo9/w1koAYURhVg4tcfAXHtLv1TO4+oZkqID9bTRMyIfvJJWG/IMdDaqlpSeMspzVnHCkZ5fPVXXGupAHkGih3pUngtg== Received: from MN2PR01MB5358.prod.exchangelabs.com (2603:10b6:208:117::26) by SJ0PR01MB6221.prod.exchangelabs.com (2603:10b6:a03:295::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.20; Fri, 7 Oct 2022 00:43:05 +0000 Received: from MN2PR01MB5358.prod.exchangelabs.com ([fe80::3c11:1e6d:4c2b:c8c7]) by MN2PR01MB5358.prod.exchangelabs.com ([fe80::3c11:1e6d:4c2b:c8c7%6]) with mapi id 15.20.5676.034; Fri, 7 Oct 2022 00:43:05 +0000 From: Arminder Singh To: linux-kernel@vger.kernel.org Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, asahi@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, Alyssa Rosenzweig , Sven Peter , Hector Martin , Christophe Leroy , Nicholas Piggin , Michael Ellerman , Arminder Singh Subject: [PATCH v3] i2c/pasemi: PASemi I2C controller IRQ enablement Date: Thu, 6 Oct 2022 20:42:03 -0400 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [wI8Vag+iqIejAVU6v720xiuzB+MDRhCoOK5FgCeod/5NcFcomaqQ9XIWD6BRe3mf] X-ClientProxiedBy: BLAPR03CA0047.namprd03.prod.outlook.com (2603:10b6:208:32d::22) To MN2PR01MB5358.prod.exchangelabs.com (2603:10b6:208:117::26) X-Microsoft-Original-Message-ID: <20221007004202.2662001-1-arminders208@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR01MB5358:EE_|SJ0PR01MB6221:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c67f286-26c3-4b08-b8d5-08daa7fce50a X-MS-Exchange-SLBlob-MailProps: ZpxNddEKiWz9xWgIDw6EsgO2Ibru/UT1cZ7XV10NTqMVi6rxHosuiqEw0YtFBVR/OMiGlhALjdxZc/ohAYz4GCASMc7q6VA3lPUCe5teuSOf1thQmHuN5WGhAXP7YThY2Bc2WlXITjqWIHnL/pwsPd/wGrlqSx9im70ez3PnETAdXzyV+DdXoQODc/78yivKJxVOPUVr+TcaMTq6VMo6LcHJYuwp4n6R6kEBUzpl9uk2SsLmTsYKoFd7O1K3/MYsFQI7Uq0K0f0uJJDCpOMgnU6JT97H5UdBwdR3eI0sMQhBudl+qU65KCrQM3dw1X3EKOnkXYf1DKV7br010TBqZjE00Tfl/62D3m5PfcW5DXZ1nSzWgHuRXzn8DeOEE8cKL7/vB0O8X/i1NJU6AAdB/NJ/Bvvl7XauE/xppn3Hvvl9lSSfMgDu27RgQj3vmzm4wgWRt6S1nWWLkrWL7zPFqMh9yWJsSVJDFRovTtzKI4FeOO0LaqcjQpVskEGP8bw5u5wL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BcW5c/ARCn5UzDpNRWZ6hbfh/W7ENvhXO03gmQN1K1prnpr+OgFfoASVoz0MjIQh2B56hpLeuhK5ypJ76MqvIj7mROClZO1vj1Nzh9nHPDAV0vCe3ay5DRsgJgeVwgyanmBiKvvK8u6CX+wDCGrvnW3wwFHkJ/rb+iafXDP9XCdypCQX8nrrhhTIX6VFRq2s6N3prpEVeY6lR76ucFVbOTCK8+A5o/3PY3gMAovLsC801rJ91deKPLIUZ3snPufJU2bn0pQoPqP989UYd1pHcwobhRA2p3OzbNfxzsOV5rh4s9qw6xTeRLesd0huGAb3lmj986UYZT8PD9aOGfxZifUMFxP3wcEzpjQfWe0oLCoA8KKdJGOVaTLcWeSA8GrYSDnrxH3L/nJGmkI8lT4HO2oHKA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c67f286-26c3-4b08-b8d5-08daa7fce50a X-MS-Exchange-CrossTenant-AuthSource: MN2PR01MB5358.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 00:43:05.1690 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB6221 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221006_174314_051385_4D18E10B X-CRM114-Status: GOOD ( 26.50 ) 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 This patch adds IRQ support to the PASemi I2C controller driver to increase the performace of I2C transactions on platforms with PASemi I2C controllers. While primarily intended for Apple silicon platforms, this patch should also help in enabling IRQ support for older PASemi hardware as well should the need arise. Signed-off-by: Arminder Singh --- This version of the patch has been tested on an M1 Ultra Mac Studio, as well as an M1 MacBook Pro, and userspace launches successfully while using the IRQ path for I2C transactions. This version of the patch only contains fixes to the whitespace and alignment issues found in v2 of the patch, and as such the testing that Christian Zigotsky did on PASemi hardware for v2 of the patch also applies to this version of the patch as well. (See v2 patch email thread for the "Tested-by" tag) v2 to v3 changes: - Fixed some whitespace and alignment issues found in v2 of the patch v1 to v2 changes: - moved completion setup from pasemi_platform_i2c_probe to pasemi_i2c_common_probe to allow PASemi and Apple platforms to share common completion setup code in case PASemi hardware gets IRQ support added - initialized the status variable in pasemi_smb_waitready when going down the non-IRQ path - removed an unnecessary cast of dev_id in the IRQ handler - fixed alignment of struct member names in i2c-pasemi-core.h (addresses Christophe's feedback in the original submission) - IRQs are now disabled after the wait_for_completion_timeout call instead of inside the IRQ handler (prevents the IRQ from going off after the completion times out) - changed the request_irq call to a devm_request_irq call to obviate the need for a remove function and a free_irq call (thanks to Sven for pointing this out in the original submission) - added a reinit_completion call to pasemi_reset as a failsafe to prevent missed interrupts from causing the completion to never complete (thanks to Arnd Bergmann for pointing this out) - removed the bitmask variable in favor of just using the value directly (it wasn't used anywhere else) v2 linked here: https://lore.kernel.org/linux-i2c/MN2PR01MB535821C8058C7814B2F8EEDF9F599@MN2PR01MB5358.prod.exchangelabs.com/ v1 linked here: https://lore.kernel.org/linux-i2c/MN2PR01MB535838492432C910F2381F929F6F9@MN2PR01MB5358.prod.exchangelabs.com/T/#m11b3504c2667517aad7521514c99ca0e07a9381f Hopefully the patch is good to go this time around! drivers/i2c/busses/i2c-pasemi-core.c | 29 ++++++++++++++++++++---- drivers/i2c/busses/i2c-pasemi-core.h | 5 ++++ drivers/i2c/busses/i2c-pasemi-platform.c | 6 +++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c index 9028ffb58cc0..4855144b370e 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -21,6 +21,7 @@ #define REG_MTXFIFO 0x00 #define REG_MRXFIFO 0x04 #define REG_SMSTA 0x14 +#define REG_IMASK 0x18 #define REG_CTL 0x1c #define REG_REV 0x28 @@ -66,6 +67,7 @@ static void pasemi_reset(struct pasemi_smbus *smbus) val |= CTL_EN; reg_write(smbus, REG_CTL, val); + reinit_completion(&smbus->irq_completion); } static void pasemi_smb_clear(struct pasemi_smbus *smbus) @@ -81,11 +83,18 @@ static int pasemi_smb_waitready(struct pasemi_smbus *smbus) int timeout = 10; unsigned int status; - status = reg_read(smbus, REG_SMSTA); - - while (!(status & SMSTA_XEN) && timeout--) { - msleep(1); + if (smbus->use_irq) { + reinit_completion(&smbus->irq_completion); + reg_write(smbus, REG_IMASK, SMSTA_XEN | SMSTA_MTN); + wait_for_completion_timeout(&smbus->irq_completion, msecs_to_jiffies(10)); + reg_write(smbus, REG_IMASK, 0); status = reg_read(smbus, REG_SMSTA); + } else { + status = reg_read(smbus, REG_SMSTA); + while (!(status & SMSTA_XEN) && timeout--) { + msleep(1); + status = reg_read(smbus, REG_SMSTA); + } } /* Got NACK? */ @@ -344,10 +353,14 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) /* set up the sysfs linkage to our parent device */ smbus->adapter.dev.parent = smbus->dev; + smbus->use_irq = 0; + init_completion(&smbus->irq_completion); if (smbus->hw_rev != PASEMI_HW_REV_PCI) smbus->hw_rev = reg_read(smbus, REG_REV); + reg_write(smbus, REG_IMASK, 0); + pasemi_reset(smbus); error = devm_i2c_add_adapter(smbus->dev, &smbus->adapter); @@ -356,3 +369,11 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) return 0; } + +irqreturn_t pasemi_irq_handler(int irq, void *dev_id) +{ + struct pasemi_smbus *smbus = dev_id; + + complete(&smbus->irq_completion); + return IRQ_HANDLED; +} diff --git a/drivers/i2c/busses/i2c-pasemi-core.h b/drivers/i2c/busses/i2c-pasemi-core.h index 4655124a37f3..88821f4e8a9f 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.h +++ b/drivers/i2c/busses/i2c-pasemi-core.h @@ -7,6 +7,7 @@ #include #include #include +#include #define PASEMI_HW_REV_PCI -1 @@ -16,6 +17,10 @@ struct pasemi_smbus { void __iomem *ioaddr; unsigned int clk_div; int hw_rev; + int use_irq; + struct completion irq_completion; }; int pasemi_i2c_common_probe(struct pasemi_smbus *smbus); + +irqreturn_t pasemi_irq_handler(int irq, void *dev_id); diff --git a/drivers/i2c/busses/i2c-pasemi-platform.c b/drivers/i2c/busses/i2c-pasemi-platform.c index 88a54aaf7e3c..e35945a91dbe 100644 --- a/drivers/i2c/busses/i2c-pasemi-platform.c +++ b/drivers/i2c/busses/i2c-pasemi-platform.c @@ -49,6 +49,7 @@ static int pasemi_platform_i2c_probe(struct platform_device *pdev) struct pasemi_smbus *smbus; u32 frequency; int error; + int irq_num; data = devm_kzalloc(dev, sizeof(struct pasemi_platform_i2c_data), GFP_KERNEL); @@ -82,6 +83,11 @@ static int pasemi_platform_i2c_probe(struct platform_device *pdev) if (error) goto out_clk_disable; + irq_num = platform_get_irq(pdev, 0); + error = devm_request_irq(smbus->dev, irq_num, pasemi_irq_handler, 0, "pasemi_apple_i2c", (void *)smbus); + + if (!error) + smbus->use_irq = 1; platform_set_drvdata(pdev, data); return 0;