From patchwork Sat Jul 12 11:49:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastian Hecht X-Patchwork-Id: 4539231 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 191CB9F1D6 for ; Sat, 12 Jul 2014 11:49:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C3C6201FA for ; Sat, 12 Jul 2014 11:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43B27201F7 for ; Sat, 12 Jul 2014 11:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752085AbaGLLtl (ORCPT ); Sat, 12 Jul 2014 07:49:41 -0400 Received: from mail-we0-f172.google.com ([74.125.82.172]:52846 "EHLO mail-we0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751720AbaGLLtk (ORCPT ); Sat, 12 Jul 2014 07:49:40 -0400 Received: by mail-we0-f172.google.com with SMTP id x48so402162wes.17 for ; Sat, 12 Jul 2014 04:49:39 -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=5MwwatkL+FBk3HcBTkN5Z7OlcBf3TZFMO+xRuHGj3ZI=; b=W0/bKrWW9bS+KSYl8KcH0ZwUWni2MOft6a3UZLsW1JP10DtpKRtDhw7/7W9uATS6K7 c/ITMVcYlFolsQ8B0ZdGsvpk+0RsQ4fqMq2pl8GPUJXxtQK0ZneP2jyIASes4FtDfKhf Cg7mw5kUHdC+9Gt7S2E95cgxw1bzgGSMzUEVceHy+Q+fgki1wSs9/hkuW0lx81pI2T4N 2NQjTeMEXc30Xzaa1J5S+cC4LF2DxtJrjRXXZjtm9Ahz6U5fI6OUy3jFQ4QleTLIqOCq Fbm7GYcZqX9NauTPXJtxhd6cdbjBG/hWSwVZU/50dlIK1wvd1annlAyUSAIFjznGVRUk aLYQ== X-Received: by 10.180.96.170 with SMTP id dt10mr12096035wib.80.1405165779319; Sat, 12 Jul 2014 04:49:39 -0700 (PDT) Received: from ipanema.Speedport_W723_V_Typ_A_1_01_001 (p4FD2114D.dip0.t-ipconnect.de. [79.210.17.77]) by mx.google.com with ESMTPSA id ey16sm5962198wid.14.2014.07.12.04.49.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 12 Jul 2014 04:49:38 -0700 (PDT) From: Bastian Hecht To: linux-i2c@vger.kernel.org, Wolfram Sang Cc: Linux-SH , Tomoya MORINAGA , Naveen Krishna Chatradhi , Taekgyun Ko , Ben Dooks , Magnus Damm Subject: [PATCH 1/5] i2c: Don't start transfers when suspended Date: Sat, 12 Jul 2014 13:49:27 +0200 Message-Id: <1405165771-8732-1-git-send-email-hechtb@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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. Signed-off-by: Bastian Hecht --- I ended up getting i2c timeouts when suspending and provoking touchscreen IRQs on an Armadillo board with an sh_mobile i2c bus. Instead of copying again the protection mechanism from other bus drivers, we can clean things up and move this into the core. I assume that all bus drivers use kzalloc or equivalent for the struct i2c_adapter. So adap->suspended can't end up uninitialized, right? We could consider using this scheme for freeze/restore too. drivers/i2c/i2c-core.c | 24 +++++++++++++++++++++++- include/linux/i2c.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7c7f4b8..9fe9581 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); @@ -1819,7 +1833,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 = -EIO; + else + ret = __i2c_transfer(adap, msgs, num); i2c_unlock_adapter(adap); return ret; @@ -2577,6 +2594,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 +2611,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];