From patchwork Thu Jul 17 14:48:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastian Hecht X-Patchwork-Id: 4576091 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E45BC0514 for ; Thu, 17 Jul 2014 14:51:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7A192017D for ; Thu, 17 Jul 2014 14:51:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E01C20160 for ; Thu, 17 Jul 2014 14:51:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X7n07-0000Zp-Gl; Thu, 17 Jul 2014 14:49:39 +0000 Received: from mail-we0-x22b.google.com ([2a00:1450:400c:c03::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X7mzw-0000Qa-Fr for linux-arm-kernel@lists.infradead.org; Thu, 17 Jul 2014 14:49:29 +0000 Received: by mail-we0-f171.google.com with SMTP id p10so3208979wes.30 for ; Thu, 17 Jul 2014 07:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=LgeH+64h+/29WKGIQKODBrRXz7k2tLwQF70AVzISBf4=; b=oZE3kVrpuohINOb4Ch81buG/FKMN+F0NnSly94r8cF2ujLd/49nTGrNi79bq8GN8cS z1Y9jGibmsrs0N4AgOSEq0+M9MLD5mETy5l/Nrx/eZa5KYsY1AvnBGvJ0NmUWA8qfkGR 8uIHrXLWDyKGH2P74Z6ZiYSwsPOFkJdYrnmj4DwAECmKg8+C+XIMwrId9QQCXBErS5OF HeWC37/3WYiBlHxPjjE/CI7GPIG0gPvWCjx6R6rMuqNRI8AeETY5Fdulg3Oh/Ha1s6MV fC2VkTlKeOqg/Oplhg0KB76zjv2pio1JD/tDlukjw401v4cmWsXrg/gCYHjvPERcJ1X7 7/dA== X-Received: by 10.194.158.164 with SMTP id wv4mr4822258wjb.124.1405608542371; Thu, 17 Jul 2014 07:49:02 -0700 (PDT) Received: from ipanema.Speedport_W723_V_Typ_A_1_01_001 (p5B3C7F4A.dip0.t-ipconnect.de. [91.60.127.74]) by mx.google.com with ESMTPSA id di7sm6646044wjb.34.2014.07.17.07.49.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Jul 2014 07:49:01 -0700 (PDT) From: Bastian Hecht To: linux-i2c@vger.kernel.org Subject: [PATCH v2 1/5] i2c: Don't start transfers when suspended Date: Thu, 17 Jul 2014 16:48:36 +0200 Message-Id: <1405608520-5644-1-git-send-email-hechtb@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140717_074928_687268_0ABFB17D X-CRM114-Status: GOOD ( 13.92 ) X-Spam-Score: -0.8 (/) Cc: Wolfram Sang , Linux-SH , Tomoya MORINAGA , open list , Bastian Hecht , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP i2c transfer requests come in very uncontrolled, like from interrupt routines. We might be suspended when this happens. To avoid i2c timeouts caused by powered down busses we check for suspension. Several bus drivers handle this problem on their own. We can clean things up by moving the protection mechanism into the core. Signed-off-by: Bastian Hecht --- changelog v2: - commit message extended. - initialization added for adap->suspended - swapped branch for increased performance drivers/i2c/i2c-core.c | 25 ++++++++++++++++++++++++- include/linux/i2c.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7c7f4b8..b15dc20 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -343,6 +343,13 @@ static int i2c_legacy_resume(struct device *dev) static int i2c_device_pm_suspend(struct device *dev) { const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + struct i2c_adapter *adap = i2c_verify_adapter(dev); + + if (adap) { + i2c_lock_adapter(adap); + adap->suspended = true; + i2c_unlock_adapter(adap); + } if (pm) return pm_generic_suspend(dev); @@ -353,6 +360,13 @@ static int i2c_device_pm_suspend(struct device *dev) static int i2c_device_pm_resume(struct device *dev) { const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; + struct i2c_adapter *adap = i2c_verify_adapter(dev); + + if (adap) { + i2c_lock_adapter(adap); + adap->suspended = false; + i2c_unlock_adapter(adap); + } if (pm) return pm_generic_resume(dev); @@ -1243,6 +1257,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) dev_set_name(&adap->dev, "i2c-%d", adap->nr); adap->dev.bus = &i2c_bus_type; adap->dev.type = &i2c_adapter_type; + adap->suspended = false; res = device_register(&adap->dev); if (res) goto out_list; @@ -1819,7 +1834,10 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) i2c_lock_adapter(adap); } - ret = __i2c_transfer(adap, msgs, num); + if (!adap->suspended) + ret = __i2c_transfer(adap, msgs, num); + else + ret = -EIO; i2c_unlock_adapter(adap); return ret; @@ -2577,6 +2595,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, if (adapter->algo->smbus_xfer) { i2c_lock_adapter(adapter); + if (adapter->suspended) { + res = -EIO; + goto unlock; + } /* Retry automatically on arbitration loss */ orig_jiffies = jiffies; @@ -2590,6 +2612,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, orig_jiffies + adapter->timeout)) break; } +unlock: i2c_unlock_adapter(adapter); if (res != -EOPNOTSUPP || !adapter->algo->master_xfer) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index b556e0a..af08c75 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -434,6 +434,7 @@ struct i2c_adapter { int timeout; /* in jiffies */ int retries; struct device dev; /* the adapter device */ + unsigned int suspended:1; int nr; char name[48];