From patchwork Mon Jul 9 23:49:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 10515943 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED434600CA for ; Mon, 9 Jul 2018 23:50:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCBAB28BB9 for ; Mon, 9 Jul 2018 23:50:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D086B28BBD; Mon, 9 Jul 2018 23:50:09 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53FEE28BB9 for ; Mon, 9 Jul 2018 23:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933182AbeGIXuH (ORCPT ); Mon, 9 Jul 2018 19:50:07 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:39069 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933179AbeGIXuD (ORCPT ); Mon, 9 Jul 2018 19:50:03 -0400 Received: by mail-pg1-f193.google.com with SMTP id n2-v6so1582913pgq.6 for ; Mon, 09 Jul 2018 16:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=U+/ail1Y2/zS6EKnjkbyr94CF/SqkicIq6LsMUZ45Go=; b=fOV3hhb23H4sdM2wOdjq2UG4SphvViR7FE/Bo88VQnMTd60MSu9frp6XSmgeuvKvVz PbIRlNQzBfNbbdbXZsB6ZU659cAlKMpP1GxJXsuUC2IPTLC8DI25JuiruzOkRCqm+1WT vNFXs7BdF1HTN3SvD86YN1PAsNNLfIv+AGRW8= 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=U+/ail1Y2/zS6EKnjkbyr94CF/SqkicIq6LsMUZ45Go=; b=mvHVBYRiPOHAjQ6YenxYUHIOy9LrkdUMP+7LcbDI3ubqmq/w3kV9l3OymlsGBdMCwk wes2POTqaf5l2diaZEAqwGHCuioglXgTTzDbpZDwsqOyl+LuW+jAipWaTLIRKlsYDYRQ r4pN+SW+kx2V7IsjVUpOwilFc5dO3RRtfwGZmI92onLag/FwDDPpjGRH7q/ExgLIbrYQ BrT2IewHrc+7S9le9NfIFoy55lMXyyBUemYecfi6FZ2gUqOYFObhb99ACs5IqopfUP1P aLgeo8e1YbmaJD+v5shtR8EefqOwgKDxUnvM5nYAxj7mH55NPQTtAKjAoJ3mCQ0XBR3R HlQw== X-Gm-Message-State: APt69E049FSNBfmeEsiby6+TiYpbvmUKs6PFQC6852RZ1gt8L6PAKVSv Ukqo6jRpf2p76o6BCg2nMDPL3Q== X-Google-Smtp-Source: AAOMgpdG2tA/51MAAt5mZBgdrWLAYYxpWV0+R2q9L9BpYWtDSWLgY92VrLlOWE/wvRoCkEbzFtvRKg== X-Received: by 2002:a62:d94a:: with SMTP id s71-v6mr23100530pfg.164.1531180202823; Mon, 09 Jul 2018 16:50:02 -0700 (PDT) Received: from evgreen2.mtv.corp.google.com ([2620:0:1000:1511:116f:8bf3:133b:f7fd]) by smtp.gmail.com with ESMTPSA id x11-v6sm26361213pge.15.2018.07.09.16.50.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Jul 2018 16:50:01 -0700 (PDT) From: Evan Green To: andy.gross@linaro.org, david.brown@linaro.org, Karthikeyan Ramasubramanian , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, swboyd@chromium.org, dianders@chromium.org, Girish Mahadevan , linux-i2c@vger.kernel.org Cc: Evan Green Subject: [PATCH] i2c: i2c-qcom-geni: Fix suspend clock handling Date: Mon, 9 Jul 2018 16:49:37 -0700 Message-Id: <20180709234937.176154-1-evgreen@chromium.org> X-Mailer: git-send-email 2.16.4 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pm_runtime_suspended can return 0 even if the last runtime power management function called in the device was a suspend call. This trips up the i2c-qcom-geni's suspend_noirq accounting, which was trying to use the function to determine if it should disable clocks or if that had already been done. The fix is to track whether or not clocks have been enabled explicitly in the driver with a new member. While in there, also honor the return value of geni_se_resources_off, which can technically fail. An example of the warning generated during suspend: [ 68.314733] WARNING: CPU: 0 PID: 1990 at drivers/clk/clk.c:595 clk_core_disable+0x28/0x200 [ 68.464576] Call trace: [ 68.554410] [] clk_core_disable+0x28/0x200 [ 68.560244] [] clk_disable+0x38/0x4c [ 68.565541] [] geni_se_resources_off+0x40/0x74 [ 68.571731] [] geni_i2c_runtime_suspend+0x2c/0x3c [ 68.578185] [] geni_i2c_suspend_noirq+0x38/0x68 [ 68.584475] [] dpm_run_callback+0x104/0x210 [ 68.590404] [] __device_suspend_noirq+0x158/0x1a8 [ 68.596859] [] dpm_noirq_suspend_devices+0x180/0x38c [ 68.603594] [] suspend_devices_and_enter+0x49c/0x964 [ 68.610321] [] pm_suspend+0x690/0x6e0 [ 68.615712] [] state_store+0xd4/0xf8 [ 68.621014] [] kobj_attr_store+0x18/0x28 [ 68.626672] [] sysfs_kf_write+0x5c/0x68 [ 68.632240] [] kernfs_fop_write+0x174/0x1b8 [ 68.638177] [] __vfs_write+0x58/0x160 [ 68.643567] [] vfs_write+0xcc/0x184 [ 68.648780] [] SyS_write+0x64/0xb4 Signed-off-by: Evan Green Reviewed-by: Karthikeyan Ramasubramanian --- This change applies atop Karthik's patch [1], which as far as I can tell technically hasn't landed yet, but also hasn't had feedback in awhile either. I opted to submit this as a separate patch, but if the maintainers prefer it's fine with me if this get folded in to another spin of the base series. [1] https://patchwork.kernel.org/patch/10460819/ drivers/i2c/busses/i2c-qcom-geni.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 54bcd1a79cc5..90c4cbfa22d8 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -85,6 +85,7 @@ struct geni_i2c_dev { spinlock_t lock; u32 clk_freq_out; const struct geni_i2c_clk_fld *clk_fld; + int suspended; }; struct geni_i2c_err_log { @@ -567,9 +568,15 @@ static int geni_i2c_probe(struct platform_device *pdev) geni_se_init(&gi2c->se, gi2c->tx_wm, tx_depth); geni_se_config_packing(&gi2c->se, BITS_PER_BYTE, PACKING_BYTES_PW, true, true, true); - geni_se_resources_off(&gi2c->se); + ret = geni_se_resources_off(&gi2c->se); + if (ret) { + dev_err(&pdev->dev, "Error turning off resources %d\n", ret); + return ret; + } + dev_dbg(&pdev->dev, "i2c fifo/se-dma mode. fifo depth:%d\n", tx_depth); + gi2c->suspended = 1; pm_runtime_set_suspended(gi2c->se.dev); pm_runtime_set_autosuspend_delay(gi2c->se.dev, I2C_AUTO_SUSPEND_DELAY); pm_runtime_use_autosuspend(gi2c->se.dev); @@ -590,10 +597,19 @@ static int geni_i2c_remove(struct platform_device *pdev) static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev) { + int ret; struct geni_i2c_dev *gi2c = dev_get_drvdata(dev); disable_irq(gi2c->irq); - geni_se_resources_off(&gi2c->se); + ret = geni_se_resources_off(&gi2c->se); + if (ret) { + enable_irq(gi2c->irq); + return ret; + + } else { + gi2c->suspended = 1; + } + return 0; } @@ -607,12 +623,15 @@ static int __maybe_unused geni_i2c_runtime_resume(struct device *dev) return ret; enable_irq(gi2c->irq); + gi2c->suspended = 0; return 0; } static int __maybe_unused geni_i2c_suspend_noirq(struct device *dev) { - if (!pm_runtime_suspended(dev)) { + struct geni_i2c_dev *gi2c = dev_get_drvdata(dev); + + if (!gi2c->suspended) { geni_i2c_runtime_suspend(dev); pm_runtime_disable(dev); pm_runtime_set_suspended(dev);