From patchwork Thu Sep 20 16:14:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10608131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35A54161F for ; Thu, 20 Sep 2018 16:28:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21B9B2DFC1 for ; Thu, 20 Sep 2018 16:28:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15C762DFC4; Thu, 20 Sep 2018 16:28:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A30F12DFC1 for ; Thu, 20 Sep 2018 16:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=QEu6iUQtkcMdKw9yrTnDESoHPikTTTB1ofTcR8MpSs8=; b=NgzVuYqIVJV/nq4/YWowzK5YzE JKhNCv9XqP9nDg0Pd9IC9Ho/IKeJu/FbpgEh7MDa9GsMqsZvAU6L5365VUUOoLFyMkmPidbtzipGk z7ut+X60aMRwA+a2YLQ6pAiUY78KUovWtbgsrZuFAbcPtcoK9YRy3RzODJKsv9hsts7FK4UuSE912 /5i0M9LZsdj19wCgoKGm0pmJD30xpWKudGoMlPHqrkq6AVVLZ0AP0SR8kCsKHLge+gb3yxgSEGa2u 4TPzcs7W+sGh3QBVjCjN6mgYrYEICF5mjWkKjF3QDv5Rn17K28WSYPGKYa3ROwM2GY0fp+y6PxqYp cne7rCtg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31o7-0002ck-TX; Thu, 20 Sep 2018 16:27:59 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31mq-0001jp-F9 for linux-arm-kernel@bombadil.infradead.org; Thu, 20 Sep 2018 16:26:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=h/iSF45IOB5EPeZyffVcKaaJ4le/A39O0acX8f7k8gg=; b=Dw6xXNI3HVJQ1M1DCv9puZ0UA M68NG367Nsjn7hqWPKt2M/zKzAxnUDQHILYySSCFd/xvtMgdNeYzUerlHn3lydjKw03I1QSuWUctB yBNzeZlEFOktNwww2cHdoeWBn3uDbvlHJ0dBQPgGPJt6MPeq3tsBvwMbcdNtmRomEzmV2nfYdiNo7 0gX6brbyGZpS52w/OBeZO3IDcpwbFPqr0r67toYvvh2iTf9ONaMYObc81CXuLuYvkM3YiCEc7iCur hvYP3VuJtowUOyf1svvMiTh2wWp3UOzw1A0U15mj4Zwaz5TP+zXarEKlM44Bc1SoNiTcMArFJDUem b9u/4/s5g==; Received: from sauhun.de ([88.99.104.3] helo=pokefinder.org) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31bI-0003Ch-UU for linux-arm-kernel@lists.infradead.org; Thu, 20 Sep 2018 16:14:46 +0000 Received: from localhost (i577B999D.versanet.de [87.123.153.157]) by pokefinder.org (Postfix) with ESMTPSA id 36AD82E35A1; Thu, 20 Sep 2018 18:14:33 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Subject: [RFC PATCH 1/4] i2c: core: remove outdated DEBUG output Date: Thu, 20 Sep 2018 18:14:20 +0200 Message-Id: <20180920161423.13990-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> References: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180920_171444_994015_CF2214E2 X-CRM114-Status: UNSURE ( 9.14 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tero Kristo , preid@electromag.com.au, Keerthy , Andy Shevchenko , linux-renesas-soc@vger.kernel.org, Wolfram Sang , Grygorii Strashko , Stefan Lengfeld , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The usefulness of this debug output is questionable. It covers only direct i2c_transfer calls and no SMBUS calls, neither direct nor emulated ones. And the latter one is largely used in the kernel, so a lot of stuff is missed. Also, we have a proper tracing mechanism for all these kinds of transfers in place for years now. Remove this old one. Signed-off-by: Wolfram Sang Acked-by: Peter Rosin --- drivers/i2c/i2c-core-base.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 9ee9a15e7134..c2b352c46fae 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1940,16 +1940,6 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) */ if (adap->algo->master_xfer) { -#ifdef DEBUG - for (ret = 0; ret < num; ret++) { - dev_dbg(&adap->dev, - "master_xfer[%d] %c, addr=0x%02x, len=%d%s\n", - ret, (msgs[ret].flags & I2C_M_RD) ? 'R' : 'W', - msgs[ret].addr, msgs[ret].len, - (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : ""); - } -#endif - if (in_atomic() || irqs_disabled()) { ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT); if (!ret) From patchwork Thu Sep 20 16:14:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10608031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DE2714BD for ; Thu, 20 Sep 2018 16:15:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A3AA2DB8B for ; Thu, 20 Sep 2018 16:15:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AC0828786; Thu, 20 Sep 2018 16:15:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A534C28786 for ; Thu, 20 Sep 2018 16:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=s+1jxZNj7rHKCnDEHdRdoIqgNTxx1RD1Bx5Eon2R7G4=; b=WdisLTESaFtBLYXruNxB8TYmlH OdMmwZ8T/dToQhcRcP1hhcIM06S62EuCcfHyxHlgmAWHoA4zaFs56vCEihM8KDJZ1SLieiUza3hop b1ssiL8EK5R0Nw1POGQoVyIt5HWXnZS6MQ0haTFcWK+6cAGNn33yAAeuSek6NMITjVfANxiLx2lKW a45SWieu5nW+RUzZVGE1/YLk2EFJbTBjwYaqUP87nikaFKjHkOASQohMFZlVvNIxmV/8l089qClbV 7ZHCjlAnIFbu6ffqXM8vRWmlnomtwMNYUJsPN5Xe7lKXSjIPnToepzfwKbT5hXszO4JYAvyd8q+qI QY1Endsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31cO-0005GJ-Mk; Thu, 20 Sep 2018 16:15:52 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31bS-0003cZ-SN for linux-arm-kernel@bombadil.infradead.org; Thu, 20 Sep 2018 16:14:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HzZFylXDOizFdFCcTj8IbForOT5wWm8HNwzL7sU5vIs=; b=C5gUKNLuhqiJgr44Pt6hUd7kx vCRzhcP/J1MCI2yCR2FXkO5Q7QYA6YWUW4oC+Y6WieAtWUANTK7Hu5WGxxw2jPFwri9bl+REp5qtK Y+aVqWvotln52sECATclq3vy4ul252FopvMr5ImjhgxaVNKmTSkLBj7rdj/6bzomQ/fqzrwqVHPYm Js7GSvwkyB7oU0bHVYNfpN+0O99c+tLgsB32T9MOJZUPoNzHnJJc8+riegM2tDzcjQN+GWxvwBtWQ Ti7N9PkZMIinafB7qD4lrrjblK4yvAS0NoQtZUlX/ye27KKI0xALmiJxNJ6RAb+fNYpw0T43XcMDq 4q+BtODuQ==; Received: from sauhun.de ([88.99.104.3] helo=pokefinder.org) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31bM-0003jw-T2 for linux-arm-kernel@lists.infradead.org; Thu, 20 Sep 2018 16:14:50 +0000 Received: from localhost (i577B999D.versanet.de [87.123.153.157]) by pokefinder.org (Postfix) with ESMTPSA id AC2962E35A2; Thu, 20 Sep 2018 18:14:33 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Subject: [RFC PATCH 2/4] i2c: core: remove level of indentation in i2c_transfer Date: Thu, 20 Sep 2018 18:14:21 +0200 Message-Id: <20180920161423.13990-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> References: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180920_121449_086283_D97A9595 X-CRM114-Status: GOOD ( 13.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tero Kristo , preid@electromag.com.au, Keerthy , Andy Shevchenko , linux-renesas-soc@vger.kernel.org, Wolfram Sang , Grygorii Strashko , Stefan Lengfeld , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Using the common kernel pattern to bail out at the beginning if some conditions are not met, we can save a level of indentation. No functional change. Signed-off-by: Wolfram Sang Acked-by: Peter Rosin --- drivers/i2c/i2c-core-base.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index c2b352c46fae..799776c6d421 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1922,6 +1922,11 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { int ret; + if (!adap->algo->master_xfer) { + dev_dbg(&adap->dev, "I2C level transfers not supported\n"); + return -EOPNOTSUPP; + } + /* REVISIT the fault reporting model here is weak: * * - When we get an error after receiving N bytes from a slave, @@ -1938,25 +1943,19 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) * one (discarding status on the second message) or errno * (discarding status on the first one). */ - - if (adap->algo->master_xfer) { - if (in_atomic() || irqs_disabled()) { - ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT); - if (!ret) - /* I2C activity is ongoing. */ - return -EAGAIN; - } else { - i2c_lock_bus(adap, I2C_LOCK_SEGMENT); - } - - ret = __i2c_transfer(adap, msgs, num); - i2c_unlock_bus(adap, I2C_LOCK_SEGMENT); - - return ret; + if (in_atomic() || irqs_disabled()) { + ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT); + if (!ret) + /* I2C activity is ongoing. */ + return -EAGAIN; } else { - dev_dbg(&adap->dev, "I2C level transfers not supported\n"); - return -EOPNOTSUPP; + i2c_lock_bus(adap, I2C_LOCK_SEGMENT); } + + ret = __i2c_transfer(adap, msgs, num); + i2c_unlock_bus(adap, I2C_LOCK_SEGMENT); + + return ret; } EXPORT_SYMBOL(i2c_transfer); From patchwork Thu Sep 20 16:14:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10608127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C672161F for ; Thu, 20 Sep 2018 16:27:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04A1A2E156 for ; Thu, 20 Sep 2018 16:27:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC46A2E15D; Thu, 20 Sep 2018 16:27:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D6A02E156 for ; Thu, 20 Sep 2018 16:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=t8o5dYHqO5Fmh2D8RtLLBYlzbMN4kCCpxcVApNE2bvs=; b=ih60+tWNY63kF00R+X+d1rzQMI FA0sxrB84U0eAQ/fH7NA4pS8FhfAN++Yjt2cF66TgN6tVm2vTEC+3OPIX026fS2WZIwkAxDQV431X dRDCv2l/0i1b+LJyTWCrNo3k3Eq7av7NeIhUXAMTy85/2g9OmtfbswagIaiJu+41PoGz+s3Xevdtj oajvpO0aA4W7XMHwzdoZXuxpOyr9qykSBYl4CxrbkAJB3wvI7/mcad4JNptEg8nV38JipsbvtyjKw 8BiJ5wXkmqLibLbaXAtpc0hocx9CwIST4R7I1zTEMks6xv00zC/WQEB/i7XCN0JFdlCdmCRc5uLUq Z+JPFe+w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31nb-0002LN-VT; Thu, 20 Sep 2018 16:27:27 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31mq-0001by-Ft for linux-arm-kernel@bombadil.infradead.org; Thu, 20 Sep 2018 16:26:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Jbp4xJ8CLlwD3ltkLcdDSLwnAaFTbrp++k+mHjvhCZk=; b=FeAX34t0vaIeEsISc5+8gRebk SUq5VDdzj7C148jZI6hsORCF+hGXvTzZQkwu6Cup1oyfTtxHXTD9FOfYm/OzLTJI9zmMF9GOcAJnn z0c3N3gaPdfIDhdNYP4VW9Qx4bH2Z8RXr6WXJimQEsFVXeQ3ihRLT7OBujk23pwLvGnka9T1LUZu7 D3+VifNB3WeCxQNV9Hd+8ff5Gog4FPZKH65P24KPg+lLqneULsdrbVMeY4O9K/oUOA9W5kj2ldDji MuP2KQteEHVoZYdJ3Wp+ji1TTytkSR0t6zTnhPrkWnVSRJVXac7kS05A/WVpHwG84EGPco63bY/kO cqUPSrCkg==; Received: from sauhun.de ([88.99.104.3] helo=pokefinder.org) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31bJ-0003Ci-B1 for linux-arm-kernel@lists.infradead.org; Thu, 20 Sep 2018 16:14:47 +0000 Received: from localhost (i577B999D.versanet.de [87.123.153.157]) by pokefinder.org (Postfix) with ESMTPSA id 1CF462E35A4; Thu, 20 Sep 2018 18:14:34 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Subject: [RFC PATCH 3/4] i2c: core: use I2C locking behaviour also for SMBUS Date: Thu, 20 Sep 2018 18:14:22 +0200 Message-Id: <20180920161423.13990-4-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> References: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180920_171446_223271_888BCFBC X-CRM114-Status: GOOD ( 13.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tero Kristo , preid@electromag.com.au, Keerthy , Andy Shevchenko , linux-renesas-soc@vger.kernel.org, Wolfram Sang , Grygorii Strashko , Stefan Lengfeld , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If I2C transfers are executed in atomic contexts, trylock is used instead of lock. This behaviour was missing for SMBUS, although a lot of transfers are of SMBUS type, either emulated or direct. So, factor out the locking routine into a helper and use it for I2C and SMBUS. Signed-off-by: Wolfram Sang Acked-by: Peter Rosin --- drivers/i2c/i2c-core-base.c | 11 +++-------- drivers/i2c/i2c-core-smbus.c | 7 ++++++- drivers/i2c/i2c-core.h | 12 ++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 799776c6d421..904b4d2ebefa 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1943,14 +1943,9 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) * one (discarding status on the second message) or errno * (discarding status on the first one). */ - if (in_atomic() || irqs_disabled()) { - ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT); - if (!ret) - /* I2C activity is ongoing. */ - return -EAGAIN; - } else { - i2c_lock_bus(adap, I2C_LOCK_SEGMENT); - } + ret = __i2c_lock_bus_helper(adap); + if (ret) + return ret; ret = __i2c_transfer(adap, msgs, num); i2c_unlock_bus(adap, I2C_LOCK_SEGMENT); diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index 9cd66cabb84f..dbb46edb8e02 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -20,6 +20,8 @@ #include #include +#include "i2c-core.h" + #define CREATE_TRACE_POINTS #include @@ -530,7 +532,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, { s32 res; - i2c_lock_bus(adapter, I2C_LOCK_SEGMENT); + res = __i2c_lock_bus_helper(adapter); + if (res) + return res; + res = __i2c_smbus_xfer(adapter, addr, flags, read_write, command, protocol, data); i2c_unlock_bus(adapter, I2C_LOCK_SEGMENT); diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h index 37576f50fe20..6e98aa811980 100644 --- a/drivers/i2c/i2c-core.h +++ b/drivers/i2c/i2c-core.h @@ -29,6 +29,18 @@ extern int __i2c_first_dynamic_bus_num; int i2c_check_7bit_addr_validity_strict(unsigned short addr); +static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap) +{ + int ret = 0; + + if (in_atomic() || irqs_disabled()) + ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT) ? 0 : -EAGAIN; + else + i2c_lock_bus(adap, I2C_LOCK_SEGMENT); + + return ret; +} + #ifdef CONFIG_ACPI const struct acpi_device_id * i2c_acpi_match_device(const struct acpi_device_id *matches, From patchwork Thu Sep 20 16:14:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10608029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E19B76CB for ; Thu, 20 Sep 2018 16:15:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92CE72B6ED for ; Thu, 20 Sep 2018 16:15:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83E0E2DBC5; Thu, 20 Sep 2018 16:15:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 083C02B6ED for ; Thu, 20 Sep 2018 16:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=XSi+8frQEidK5KhY6EvigsaY6XcNu1J4a6bOeRtHMxY=; b=nUUMKF+OL0JD8gKtW05t8577VT 7tVDfZT/fmaGqWFKIHuPJlb9YWlPZkn6yJzn9DW1L0So9k7dOCZsB8ROYNXPn3BMBGfNaIGpkzpbn aK97B2BRHo+t9KGI63l+vjOe/Xy+QZcohAzaVm3CZu8sZ193ZULc/u5jWQA18SxVLZNaKA9Jydu+V agc5OaxldQC5XVREDiATY+5vlIwkB88gOTdzfTSFyvxcMBdPsK4WOysq+fy/3kVncinqUvm6aTMu9 I9NuVsLWCGZ564D8GuvJRz5SvO/Z8GvPnBjU9ocjMubUo7kTE8zpVvaSKHHN9WGgDEC+OXEge4pJt DnVKkVIg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31bg-0003kx-Tp; Thu, 20 Sep 2018 16:15:09 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31bQ-0003cZ-Vv for linux-arm-kernel@bombadil.infradead.org; Thu, 20 Sep 2018 16:14:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=sw7aD1Vz8Q9rSR/28NjgrlKQ0oO9uq1ft+yiGk1zwjE=; b=HVhVSO4oYd6tMF2IRN2cu86Oy JkPqv9BY51BCRBbndvW5dRWxIjd9vkpGgNhJt6vA4OInnZQQbIRY4RKf/qn+N6vhTGZ1Wmg3v1iAX Hb4DlIZY5xaYEoRU75VTjoNsk1aA9ekV+BxS27bH2T+r7BVz46hDUNaeshV/9bhb4LfyoyX6nui2C sZTwvSfXwq1yDOJimFTlD5vvJ0FPvdysvTZXCMCPjHAeAO3/SyPg92ocy2rrUJn/7TktRkT9+HU4c egG7ntoAQbhsheFPtSIhZxaw0082j9s1Pzw6WAkcQoaFSqbqHxYcXJnHWsiAmKs7866vp8EJc29hb KgzbQI1iQ==; Received: from sauhun.de ([88.99.104.3] helo=pokefinder.org) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g31bM-0003jy-H1 for linux-arm-kernel@lists.infradead.org; Thu, 20 Sep 2018 16:14:50 +0000 Received: from localhost (i577B999D.versanet.de [87.123.153.157]) by pokefinder.org (Postfix) with ESMTPSA id 76A4C2E35A8; Thu, 20 Sep 2018 18:14:34 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Subject: [RFC PATCH 4/4] i2c: core: introduce master_xfer_irqless callback Date: Thu, 20 Sep 2018 18:14:23 +0200 Message-Id: <20180920161423.13990-5-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> References: <20180920161423.13990-1-wsa+renesas@sang-engineering.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180920_121448_825239_C5B8C013 X-CRM114-Status: GOOD ( 17.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tero Kristo , preid@electromag.com.au, Keerthy , Andy Shevchenko , linux-renesas-soc@vger.kernel.org, Wolfram Sang , Grygorii Strashko , Stefan Lengfeld , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We had the request to access devices very late when interrupts are not available anymore multiple times now. Mostly to prepare shutdown or reboot. Allow adapters to specify a specific callback for this case. Note that we fall back to the generic master_xfer callback if this new irqless one is not present. This is intentional to preserve the previous behaviour and avoid regressions. Because there are drivers not using interrupts or because it might have worked "accidently" before. Signed-off-by: Wolfram Sang Acked-by: Peter Rosin --- drivers/i2c/i2c-core-base.c | 6 +++++- include/linux/i2c.h | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 904b4d2ebefa..f827446c3089 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1887,7 +1887,11 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) /* Retry automatically on arbitration loss */ orig_jiffies = jiffies; for (ret = 0, try = 0; try <= adap->retries; try++) { - ret = adap->algo->master_xfer(adap, msgs, num); + if ((in_atomic() || irqs_disabled()) && adap->algo->master_xfer_irqless) + ret = adap->algo->master_xfer_irqless(adap, msgs, num); + else + ret = adap->algo->master_xfer(adap, msgs, num); + if (ret != -EAGAIN) break; if (time_after(jiffies, orig_jiffies + adap->timeout)) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 65b4eaed1d96..11e615123bd0 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -498,6 +498,8 @@ i2c_register_board_info(int busnum, struct i2c_board_info const *info, * @master_xfer: Issue a set of i2c transactions to the given I2C adapter * defined by the msgs array, with num messages available to transfer via * the adapter specified by adap. + * @master_xfer_irqless: same as master_xfer. Yet, not using any interrupts + * so e.g. PMICs can be accessed very late before shutdown * @smbus_xfer: Issue smbus transactions to the given I2C adapter. If this * is not present, then the bus layer will try and convert the SMBus calls * into I2C transfers instead. @@ -511,9 +513,9 @@ i2c_register_board_info(int busnum, struct i2c_board_info const *info, * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584 * to name two of the most common. * - * The return codes from the @master_xfer field should indicate the type of - * error code that occurred during the transfer, as documented in the kernel - * Documentation file Documentation/i2c/fault-codes. + * The return codes from the @master_xfer{_irqless} field should indicate the + * type of error code that occurred during the transfer, as documented in the + * Kernel Documentation file Documentation/i2c/fault-codes. */ struct i2c_algorithm { /* If an adapter algorithm can't do I2C-level access, set master_xfer @@ -524,6 +526,8 @@ struct i2c_algorithm { processed, or a negative value on error */ int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); + int (*master_xfer_irqless)(struct i2c_adapter *adap, + struct i2c_msg *msgs, int num); int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data *data);