From patchwork Fri Aug 23 21:41:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13776050 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 0B2A1C5321E for ; Fri, 23 Aug 2024 21:43:44 +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=AjvArJdA06PbNXPgnOry3Qq7eKu1y9KpKSsxjlMv9Wc=; b=hXAC+McM1bGqoEpU3MM6Be5njP tN2ASktmNPK4qqqHoT2AxQUCKjqiIFPSakSjKHbfRuOjXNaKpZl7ICU2FJfGCrRndn4K6RA/ppv4q DnmNLs7lO9QrgweUr7aKJTIE6N1hfo5LrT1lWu2i5jqgUQZUn3gAWNYptHWZMw8KHw/tJPiJ7Rqy5 qGzp3LMFuIBv3IV1wyQaUq31wcJdUCOvrFNpKbCwZRa7PyuuTzKoM2RMsX0DK851YnV9XVIY4gTOQ WofQZnDCbeRyLxrY7Q6qayvjcHVR6GnthmELLnv5ejx+85VcYR+K5M24yeYmWqUwbGGmTHGtWcp4S kVsWD3Pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1shc4C-00000000kMq-05EX; Fri, 23 Aug 2024 21:43:32 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1shc3Q-00000000kHC-0LGN for linux-arm-kernel@lists.infradead.org; Fri, 23 Aug 2024 21:42:45 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2021aeee5e4so17808965ad.0 for ; Fri, 23 Aug 2024 14:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724449363; x=1725054163; 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=AjvArJdA06PbNXPgnOry3Qq7eKu1y9KpKSsxjlMv9Wc=; b=CVl4vu0iro62x8cvlhPUrvtTS+xSegd3RbF+Tp8KbttEi2eonMWigfcMA/dHOh1byY 4TLgRT25iNZrqWcCu88Q0DWR70yamz5mOlPUmD5m147NORfIDaKmOead9cVoig+EUsvb 7v2QGT9Fik4aNvvJhJ6fwctfklxOSD+0rTf68= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724449363; x=1725054163; 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=AjvArJdA06PbNXPgnOry3Qq7eKu1y9KpKSsxjlMv9Wc=; b=Buwe/8gm/STdJfkNupK2oQ/wmx/F1moAyU5c45U+4PRQXhUeV8O+y5uWu3uKErt62A ciHVORczcDRyeRIx9bdFPqkXbSjc6zwPtWnHfSF2PA/WVvWDocRVotI9kIG0PVMyF9xl c22S8xHTqriGyA2Z6BO7WDe18TbcsZKC4XiDEdLZedqYKDDq8SqrQk+p5+XpxksC0XZX W2EtdVbDFxZTtVjpcDHbRwcBeVq4sYOCfxVjJLdkEOPrVRSUTsSENw9PGEJSdIhTwpCI h1nW5bPYxepRhwBJiKPWXY676/ReMHwYYzOoOX9GcsRmvYlBgIYjpsUAY/jndMpPS7aJ 7V5w== X-Forwarded-Encrypted: i=1; AJvYcCVqPJsTUoDmksX4E7WpaTmj5GwFbyKKcxeSplUc1Jf2P6uGj2gF475VLcaH1hg3LgWrc+wetjloArtxO00D3yMD@lists.infradead.org X-Gm-Message-State: AOJu0YwlpHmc3as0H9orGlQER86UbW5qwLKeOzBSwLvpF4CfyLZYWFzf Z6VIL6CKyQ1ymHuElPnydampiaQ0NMQOYu7DO5LiWUCzgS0FexhquvKFCIGh/Q== X-Google-Smtp-Source: AGHT+IGx6tc8HURRUBmfNKOOVhPbKyAJLPo58Lxm+iRK79rRI6Fo2cVzD+Gs5a92IWu63jXL+kWA/Q== X-Received: by 2002:a17:903:22c1:b0:1fb:7c7f:6458 with SMTP id d9443c01a7336-2039e4b4bcemr38350745ad.32.1724449363238; Fri, 23 Aug 2024 14:42:43 -0700 (PDT) Received: from localhost ([2a00:79e0:2e14:7:9d43:7af7:9970:8219]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2038560975csm32500335ad.194.2024.08.23.14.42.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Aug 2024 14:42:42 -0700 (PDT) From: Brian Norris To: Mark Brown Cc: =?utf-8?q?Ond=C5=99ej_Jirman?= , Brian Norris , stable@vger.kernel.org, Heiko Stuebner , Jon Lin , 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] spi: rockchip: Resolve unbalanced runtime PM / system PM handling Date: Fri, 23 Aug 2024 14:41:56 -0700 Message-ID: <20240823214235.1718769-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-20240823_144244_164730_39CB1F94 X-CRM114-Status: GOOD ( 17.82 ) 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 --- drivers/spi/spi-rockchip.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index e1ecd96c7858..f30af4316b8b 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -951,8 +951,11 @@ static int rockchip_spi_suspend(struct device *dev) 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); @@ -967,21 +970,11 @@ static int rockchip_spi_resume(struct device *dev) 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 */