From patchwork Tue Aug 27 17:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13779897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91EDFC5472F for ; Tue, 27 Aug 2024 17:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=IK8SEiBum8hunhZQDt0oY44SDt3A4Q0KuG3fIX/3rsg=; b=Jyqtg5wd3uN7mXuKTrWYQ1fP/v Qz/NpMUGbeO1Xpzsefv7/krkQGzRCeOLQNRsgi8eV2QWGCE0jXUpMA6FJN+8FUYslrQRZ/Ycn9na/ 37mI6B3qOYl/5PzP4Tt4p01cEXXrGO6ccb/IahPDGqIhtEIfRZX3tCZdAWOc4Jds03QQp4vddRvOB ly/pbDDZDiDEf3g/uOLDYBhB4DuaYNR3BhQMr+Ao+jjWZXpsKf5vDPwWR5AOcN+ZFuPVoiacfJGM1 LLs2N329NI5ZlFXWIpMJZNbVOOO1541mn1He4MzznEKlKa0yk19XFrwdE8fypi8lCdL7EvF9Ag5yI lpYwlgNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sj02v-0000000CIx3-2Abl; Tue, 27 Aug 2024 17:31:57 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sizjB-0000000CF5E-1ecm for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 17:11:48 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-70cec4aa1e4so4006120b3a.1 for ; Tue, 27 Aug 2024 10:11:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724778692; x=1725383492; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IK8SEiBum8hunhZQDt0oY44SDt3A4Q0KuG3fIX/3rsg=; b=Ma5HZJlUwItgOpqsu5riUfOMl+IQ/3kNKfsTi3brhP7xDeAyYF79ou08Ewigk955Qv p+JDBaw04TmsBKuFovMFKyZMeqignlpe9lkwO1shcGoeSYmHigDaT1+s+3yTLtKlMjHm ICcs2tK/INDo5oS8Eq3uDjPO70kIY+XyOZ9B0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724778692; x=1725383492; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IK8SEiBum8hunhZQDt0oY44SDt3A4Q0KuG3fIX/3rsg=; b=VdXv2jthdNvn5DLO5jY7p6QGOQP0ejpQpnR44288mhIpLSq65XzYENRfQ1wlwU4gKt ez/3CPEsSc4CRlmlRqnVll1E78Y+ZLJmEYEOletXWqaVDeo1PMmX8ihBn9WxXC0XpIma XwQgvFqCwTI/qzMYvdpksGm95AEALD0Xe73s/85eX2yvWqYh5FrWPbxWoOp6WJep7bg7 QCD1ZV8+f9qVwYu74lw4XUrn/hO/U0umM8Vr2C58w458XVO/1q1duJHkNs2mOQESI9DZ uwhRqG4j1PUq4+dAY4GGrYGy/vXLgzel+BXzk4nbCexa+cskpjo8M3YgBlr0HrM/MT4V EQ+w== X-Forwarded-Encrypted: i=1; AJvYcCWhaoePYBuNih64ViCQAPCffxRrXDImJy3AAN6jgVXOUEr8Jztaj9Ypydg6iBnOpeoR4Ekp6tIVnoLPojieEzU/@lists.infradead.org X-Gm-Message-State: AOJu0Yyr28dRLhV6zGXBA+99X/TvtsyTMVVLr9ZOGyPXIEQDrExfdW4o FUgvJw+1jq1VYcIMglU3/nzMqh1azHSHlmnlHMqHUHBHs+53nrieL6baG7sV6Q== X-Google-Smtp-Source: AGHT+IG4YPDdFUYtuMPkwkokpmaThrJJFJG1W58Oml09/8xPYFTHvK1DWSTRwqLa9pqAVl8Dy0b24w== X-Received: by 2002:a05:6a00:918b:b0:70d:2b95:d9cd with SMTP id d2e1a72fcca58-714457d35c7mr14736149b3a.16.1724778692187; Tue, 27 Aug 2024 10:11:32 -0700 (PDT) Received: from localhost ([2a00:79e0:2e14:7:9f27:3f59:914a:3d90]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-71434330425sm8813341b3a.190.2024.08.27.10.11.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Aug 2024 10:11:31 -0700 (PDT) From: Brian Norris To: Mark Brown Cc: Jon Lin , =?utf-8?q?Ond=C5=99ej_Jirman?= , Brian Norris , stable@vger.kernel.org, Heiko Stuebner , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-spi@vger.kernel.org, shengfei Xu Subject: [PATCH v3] spi: rockchip: Resolve unbalanced runtime PM / system PM handling Date: Tue, 27 Aug 2024 10:11:16 -0700 Message-ID: <20240827171126.1115748-1-briannorris@chromium.org> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_101133_485100_EB13F789 X-CRM114-Status: GOOD ( 18.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit e882575efc77 ("spi: rockchip: Suspend and resume the bus during NOIRQ_SYSTEM_SLEEP_PM ops") stopped respecting runtime PM status and simply disabled clocks unconditionally when suspending the system. This causes problems when the device is already runtime suspended when we go to sleep -- in which case we double-disable clocks and produce a WARNing. Switch back to pm_runtime_force_{suspend,resume}(), because that still seems like the right thing to do, and the aforementioned commit makes no explanation why it stopped using it. Also, refactor some of the resume() error handling, because it's not actually a good idea to re-disable clocks on failure. Fixes: e882575efc77 ("spi: rockchip: Suspend and resume the bus during NOIRQ_SYSTEM_SLEEP_PM ops") Cc: Reported-by: "Ondřej Jirman" Closes: https://lore.kernel.org/lkml/20220621154218.sau54jeij4bunf56@core/ Signed-off-by: Brian Norris --- Changes in v3: - actually CC the appropriate lists (sorry, I accidentally dropped them on v2) Changes in v2: - fix unused 'rs' warning drivers/spi/spi-rockchip.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index e1ecd96c7858..0bb33c43b1b4 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -945,14 +945,16 @@ static int rockchip_spi_suspend(struct device *dev) { int ret; struct spi_controller *ctlr = dev_get_drvdata(dev); - struct rockchip_spi *rs = spi_controller_get_devdata(ctlr); ret = spi_controller_suspend(ctlr); if (ret < 0) return ret; - clk_disable_unprepare(rs->spiclk); - clk_disable_unprepare(rs->apb_pclk); + ret = pm_runtime_force_suspend(dev); + if (ret < 0) { + spi_controller_resume(ctlr); + return ret; + } pinctrl_pm_select_sleep_state(dev); @@ -963,25 +965,14 @@ static int rockchip_spi_resume(struct device *dev) { int ret; struct spi_controller *ctlr = dev_get_drvdata(dev); - struct rockchip_spi *rs = spi_controller_get_devdata(ctlr); pinctrl_pm_select_default_state(dev); - ret = clk_prepare_enable(rs->apb_pclk); + ret = pm_runtime_force_resume(dev); if (ret < 0) return ret; - ret = clk_prepare_enable(rs->spiclk); - if (ret < 0) - clk_disable_unprepare(rs->apb_pclk); - - ret = spi_controller_resume(ctlr); - if (ret < 0) { - clk_disable_unprepare(rs->spiclk); - clk_disable_unprepare(rs->apb_pclk); - } - - return 0; + return spi_controller_resume(ctlr); } #endif /* CONFIG_PM_SLEEP */