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: 13779893 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 A4772C54731 for ; Tue, 27 Aug 2024 17:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=2ixBPZmAKONV9bJpTFofc/6fvQaTqPTkhkrYgBMRipo=; b=JiEksXrKxgwj8O WC6XjN42s8K+l4KEiG0dCulatTru8B1zEhfttD6LZrpHuzZZoquJX2XCre/TWW2TqmaBD4aYjfP/W FynDMZyjxFsFCujlharbbUM1pphFIQdpcKnC3x1WmoofcFfYMkpfByfhmlLI4ArI7N4Wgoe6EPcb2 +m6Pge2ZykgIK03mh/Rvxc89PTIFQiBErmbGV35YBYBLbrgvru9hXOQ9DfH9eeJMdFD5Tx44Im93+ dUAnOrg/0Dt/JSpXXH6ixWESLr3aZYPJIey63pl0w91u5jNNsZgIovseSW5yNv2HwHD+w2dcSsZkr mMm/vf0agFs2anshiq/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sj028-0000000CIdI-1HPW; Tue, 27 Aug 2024 17:31:08 +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-0000000CF5F-1egW for linux-rockchip@lists.infradead.org; Tue, 27 Aug 2024 17:11:44 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-714302e7285so4707264b3a.2 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=ZNJbRlFM3SKXVfqDbtLSABy5EECCCqTFZgnMptdLXmNNmPXEy5KyiILA8DXSahVG2N TA5Rx0FVbv89FLoW63AF1cklbTVuYDCVOE5/kYIDBmhmt7Yq1gsQbE17o5plhvFKwL7W 8P9dsnjNpUSe4uAOZNvxvqELHaAsCf40PyMoYR135cB3My8VORy2EmbsEIx8cDtDgq/V KTnry8rj5hdq9+z6NpyP0TCZgir8EjPU5Ep4T9CCKmD6Nebnm1OhB6xhFYztk4FowFp7 LO3O8yrgM3VWmdfK6puGFDU/DM7f8btrfZA35UK+U2t5BWrAWEF8bS4J/ywWBHZnjzVR prvQ== X-Forwarded-Encrypted: i=1; AJvYcCVaruiUf4j6ZoEgZdaAwMgLrRfpQbNvqqyR9qoHXzratS1bxt/piLsKgIdvp7eYGFro7wO+uwtiRrHd5kX7YA==@lists.infradead.org X-Gm-Message-State: AOJu0YzegMv/p+vI8jNs7sG+P+Vowt4Qy4vxWZikG54hYMEIi8cOcfPj xUOsKtcgPpFIOeygk/WkVgPL6MUDQagqjSGS3q+BdywvA+XunMuBFnQDau+iVg== 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_485294_2B9FC4C4 X-CRM114-Status: GOOD ( 17.42 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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 */