From patchwork Mon Apr 9 06:40:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 133002 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp884606ljb; Sun, 8 Apr 2018 23:41:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx49ZCkeMEKZNQ7ACUWsy4hTKeXF33JBVZ+TXFmGEktSmCLgXzuAl0zdyWYfiG+OpTbZ+6iYz X-Received: by 2002:a17:902:900a:: with SMTP id a10-v6mr38350155plp.142.1523256083719; Sun, 08 Apr 2018 23:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523256083; cv=none; d=google.com; s=arc-20160816; b=f6IviFgivpZqCXP25PUW1GCetIDOXIOV3WNo2lJccW0+1CtkjiSGpkSbPzhMAeOzyx Grvaasx+PvDtwO3bgMuAJgz/akUE33IwcLHZiHoSjkTxcBYLfyom1qVud3BbEHlmPesa bADDMhn18/d19LlWMc9jOjMOGZMfXnGdCIqXBprG5npYiaUlVJQUAMUlci/D1VeAcucA R7x7yXfyUWaUR4B/yFWUl37Hsk6xelAyoIMnJQyXY1G0lCD66luvBgCvDIV/ZNBn7dTV EVJcGtaRsMjDNxG8bpJxaOjvkCb7wSp/AEGvweGKMyiNhK87C2wrhF5WJn1zW4SIlaTy AyeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=JBBwsfTSI0VTeJSEuslPmwhSfc9UA4S9CDUxSrhg5ZE=; b=NJI/ruAMeo6fQd7nTvGPSQ34rJhi0q2DMnlN51uUPn4zZBvTwpzpLkWHVE4jK/iAJD tMBYkhI2SoUENMMgvhzrzE5f2sA9qG+rSFuuQBUFBQcD6bpf+6hDVT+bHA6jLFQH8MfN zAGtVAmPvtWu0liawWciq+txwgVth3QOe3mju3yGlSS6uqgJcMH1NJAgZDOi1aNQbFnu XzwwxdQFQ4jjeCWqHPXOfDJv5s6D8mScwa9Uvo4tLBkCdkvBXGPmsShv2Ayinzg9GKko q//JkDjGn3W4ppK0086PujfplvczX8YQkv+GUV2TYvf7OebIdg4P4gy6mzVhZpa2J5oQ ophQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PRjUxzTN; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z19si10884185pgn.46.2018.04.08.23.41.23; Sun, 08 Apr 2018 23:41:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PRjUxzTN; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751917AbeDIGlW (ORCPT + 3 others); Mon, 9 Apr 2018 02:41:22 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:42074 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751877AbeDIGlV (ORCPT ); Mon, 9 Apr 2018 02:41:21 -0400 Received: by mail-pl0-f68.google.com with SMTP id t20-v6so1713585ply.9 for ; Sun, 08 Apr 2018 23:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=JBBwsfTSI0VTeJSEuslPmwhSfc9UA4S9CDUxSrhg5ZE=; b=PRjUxzTNnsDlMnxmx8R4pAZnh5vp1gd6CbQjRsqsCp20GLzBm8U1x2GC+3vKxf326W YuDHwBk9tJQoLaIaHCDDgheVMUyPjl+GrSMKwu27nq5HOHQRUdPguKvsOFbtDbnkS2qZ uvTqPgGXwRDMDozoCD3ZJGd6YmyEzMgXzcbiQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JBBwsfTSI0VTeJSEuslPmwhSfc9UA4S9CDUxSrhg5ZE=; b=eRo1nnKBqHDK69fqs6tY77VWiGXrtt45Q7tI1XoZY3pWPn4I+VHrhzsK/7ZkYVNU3V GwvB4lSiuS1dQ9GhfWdXoSOpqn9ZcTKMewtqBjWXI5fVB9PoGDhYIPug8RXhQ6tZBboJ 7DwQfVaXFaUeLnaMcKs5PTcZadqn8wKXdRZ7bSzfC92SK3h7itIYS8u4v0ohjg2sX7ai tf+HK7bnX1EHfjF9YpwMdH55WFZdhcSKEzi1KE1mZ/DFc8VduNS1hwEXQo9O9tug9Cm3 iDzGqFpajVSzYlvB4iM5cBbL8rgm9e/g32JQio7UjXj39Ey6BEPREiMEW2O6I8rR+31u UC0A== X-Gm-Message-State: ALQs6tBwF9lz4vWFDeBESd6o5GA5l+gq3xS56Ug9Vpbf31JodLQQ28gz 3lUGg5s3iEc6WiPbtAzYo0O2vA== X-Received: by 2002:a17:902:8505:: with SMTP id bj5-v6mr18802185plb.231.1523256081093; Sun, 08 Apr 2018 23:41:21 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id y14sm32517490pff.81.2018.04.08.23.41.18 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Apr 2018 23:41:20 -0700 (PDT) From: Baolin Wang To: wsa@the-dreams.de Cc: broonie@kernel.org, baolin.wang@linaro.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] i2c: sprd: Prevent i2c accesses after suspend is called Date: Mon, 9 Apr 2018 14:40:54 +0800 Message-Id: <99031524fa147e72451d26f54b24f36093c0d3fa.1523255712.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add one flag to indicate if the i2c controller has been in suspend state, which can prevent i2c accesses after i2c controller is suspended following system suspend. Signed-off-by: Baolin Wang --- drivers/i2c/busses/i2c-sprd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 1.7.9.5 diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c index 25fcc3c..2fdad63 100644 --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -86,6 +86,7 @@ struct sprd_i2c { u32 count; int irq; int err; + bool is_suspended; }; static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count) @@ -283,6 +284,9 @@ static int sprd_i2c_master_xfer(struct i2c_adapter *i2c_adap, struct sprd_i2c *i2c_dev = i2c_adap->algo_data; int im, ret; + if (i2c_dev->is_suspended) + return -EBUSY; + ret = pm_runtime_get_sync(i2c_dev->dev); if (ret < 0) return ret; @@ -586,11 +590,23 @@ static int sprd_i2c_remove(struct platform_device *pdev) static int __maybe_unused sprd_i2c_suspend_noirq(struct device *pdev) { + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); + + i2c_lock_adapter(&i2c_dev->adap); + i2c_dev->is_suspended = true; + i2c_unlock_adapter(&i2c_dev->adap); + return pm_runtime_force_suspend(pdev); } static int __maybe_unused sprd_i2c_resume_noirq(struct device *pdev) { + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); + + i2c_lock_adapter(&i2c_dev->adap); + i2c_dev->is_suspended = false; + i2c_unlock_adapter(&i2c_dev->adap); + return pm_runtime_force_resume(pdev); }