Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5405508imu; Wed, 19 Dec 2018 10:31:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/VENqPmcWKDVIyHLf1VaykzbYlJQK3QCgk0reBwXq8m2wZgWDxJ0lQkHeCk0gGU6gkFH1l/ X-Received: by 2002:a62:42d4:: with SMTP id h81mr21403816pfd.259.1545244268581; Wed, 19 Dec 2018 10:31:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545244268; cv=none; d=google.com; s=arc-20160816; b=ixusONE+FY6d2VT4jXLxDTqCDW2l/En0O4t2S+ov4WfPUVAWmw3cLjEGiJYiqNheam RUsVQNOqpWh8O5T0Dow7l8LXBi9eX7g/g/4VbI7/2UE5JuKFetbi7wO1q3K4U8lOCDJw 9Wq082a4sb3WzHTczXOnRDgGQd1+K00yJZQ+BtSWKHQMlDrp5geC1wx8nti4+ypwJ8rq 9cIqn4+2IqxRVgOxy4UfKD7GcXpRaMfgQypiuOt+svoJXxlgJ+PFczMOuYgR12xF4wkC 4BZQRIZVt9/GlfNDpwA1DK4EJ+YubbU7OClakoUyljNe8oJPaqYZRcoiKDF1c43wIkqc 22yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=TTKaZenJWEQTumRYXujOelLGpFFGavzmScU4seznP68=; b=Uu3MhyxpFfyyR7zJ+IySwAl+MQWjub1Q/z2DkokX9ryH0gtld2ibb3HhRtpz7mwGvi 86eGiMK4TTIoxYgu0UbTml7mH8nzPeEPYAGLBkTxxRPCmZuBaxoV2mdwBAIwMug5ZCHZ pYCpOtTakdG63uLgYROPv6k1FoX44MZL1TggGehh/2IfgcPXMrXXwlOk4XMd5IczZujU hh/XXtF1+/y3klUj0oAxilXTTnqy3itpu7iWK++BKEWf/4EU7NzzShElMXK8g6eVDvUr uXmm7yBfaAngbNS67iQk23K6V1QZ+PILYkNaFdlYFn+fmJhcsZ75vXLs4pO1TqeiW/kd xd9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c12si16635734pgh.257.2018.12.19.10.30.52; Wed, 19 Dec 2018 10:31:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730004AbeLSQsj (ORCPT + 99 others); Wed, 19 Dec 2018 11:48:39 -0500 Received: from sauhun.de ([88.99.104.3]:55846 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729703AbeLSQsg (ORCPT ); Wed, 19 Dec 2018 11:48:36 -0500 Received: from localhost (p54B333DA.dip0.t-ipconnect.de [84.179.51.218]) by pokefinder.org (Postfix) with ESMTPSA id 55BAD2E3560; Wed, 19 Dec 2018 17:48:34 +0100 (CET) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Hans de Goede , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Wolfram Sang , Wolfram Sang , linux-kernel@vger.kernel.org Subject: [PATCH 01/10] i2c: add suspended flag and accessors for i2c adapters Date: Wed, 19 Dec 2018 17:48:17 +0100 Message-Id: <20181219164827.20985-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181219164827.20985-1-wsa+renesas@sang-engineering.com> References: <20181219164827.20985-1-wsa+renesas@sang-engineering.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A few drivers open code handling of suspended adapters. It could be handled by the core, though, to ensure generic handling. This patch adds the flag and accessor functions. The usage of these helpers is optional, though. See the kerneldoc in this patch. Signed-off-by: Wolfram Sang --- drivers/i2c/i2c-core-base.c | 1 + include/linux/i2c.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 28460f6a60cc..2c465455b2f6 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1232,6 +1232,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) if (!adap->lock_ops) adap->lock_ops = &i2c_adapter_lock_ops; + adap->locked_flags = 0; rt_mutex_init(&adap->bus_lock); rt_mutex_init(&adap->mux_lock); mutex_init(&adap->userspace_clients_lock); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 65b4eaed1d96..b7401c55dc83 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -680,6 +680,8 @@ struct i2c_adapter { int timeout; /* in jiffies */ int retries; struct device dev; /* the adapter device */ + unsigned long locked_flags; /* owned by the I2C core */ +#define I2C_ALF_IS_SUSPENDED 0 int nr; char name[48]; @@ -762,6 +764,38 @@ i2c_unlock_bus(struct i2c_adapter *adapter, unsigned int flags) adapter->lock_ops->unlock_bus(adapter, flags); } +/** + * i2c_mark_adapter_suspended - Report suspended state of the adapter to the core + * @adap: Adapter to mark as suspended + * + * When using this helper to mark an adapter as suspended, the core will reject + * further transfers to this adapter. The usage of this helper is optional but + * recommended for devices having distinct handlers for systems suspend and + * runtime suspend. More complex devices are free to implement custom solutions + * to reject transfers when suspended. + */ +static inline void i2c_mark_adapter_suspended(struct i2c_adapter *adap) +{ + i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER); + set_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags); + i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); +} + +/** + * i2c_mark_adapter_resumed - Report resumed state of the adapter to the core + * @adap: Adapter to mark as resumed + * + * When using this helper to mark an adapter as resumed, the core will allow + * further transfers to this adapter. See also further notes to + * @i2c_mark_adapter_suspended(). + */ +static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap) +{ + i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER); + clear_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags); + i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); +} + /*flags for the client struct: */ #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ #define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ -- 2.11.0