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: 13776049 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 E7472C5321E for ; Fri, 23 Aug 2024 21:43:36 +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=v9/J9xKhFFZ8yKlwpdhc7w5LvSkj/QxJebVL2cqIwO4=; b=UCSTDi6nc2LFau f+BV0krhaMzwckPFwszD6tA4DVLQH5A0d2k1Q4NeqGN+OLSvi/ihf+wXCje1usljHRqB9wif47jvl BChiYJGF2/Q0mZPl9NJso0sODJDW9Szb8zYoPMhyrdIDOVijc9/wIUlP5/edUnYV6cititzdqb11u AVCnmAJZ4JcmQlLUmpoMQSKfkivuZLc/zwQinFxJZTCzY9jB3Ff8IjC6shtbYp5pljfl6eT1cmwgq Aha/98Q4fFl2wmnYAw9SD9YHhnARjh4o+zNVOGYMcb9q8Fw+VfRCMOOIzDTG8sYqQcs81x2pBL+NT aqY75YNaDCYMHPp9i+wQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1shc4C-00000000kMx-2TKH; Fri, 23 Aug 2024 21:43:32 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1shc3Q-00000000kHB-0LOU for linux-rockchip@lists.infradead.org; Fri, 23 Aug 2024 21:42:46 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1fec34f94abso24238095ad.2 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=PiJE7Wg5gHxpF4KzKnP05nQyoxzTFAKWujvv7azVXA6Upy+NFXx+JeNpFDVNdI7ylc bpI5k20AgxBp2poOygVS5QSS1yybHACIY8fuoXh0LIq9mSDhYzikJhSXywOcL+S9+XNu wuHL/HwRo8MxflLl6URWQwOgd59dk5usRFmL3cL2Byg1lUL837xH5Yx1VUZmjD9f//Ux //4MHKH2VduKDQnXJ/ONd732ifw8kjKBs2nWcLV/hLkIjlrP/rA4aBrLLsRSbu7kxlrm MF6/0Xrx0e0aU0IEQvE3V/MTTLWS9z3eFScr90+vLVf9jfSmHx9FrI5iWadUKGM90mMX xYUg== X-Forwarded-Encrypted: i=1; AJvYcCXbFl4nCzv38z8iTmB5aA4A7dpxgmXsYu6W8xUCVDuTSZdG+r6okPH+hPcqqtBAySKruGyB5i2YnFEZasoN7g==@lists.infradead.org X-Gm-Message-State: AOJu0Ywe+OyfEkSf43BlE+1K7lENYj6Ot5XTK3pOfHtYS23XJQhKbfpk GaiTgFWb3ATH/OLt/q4nGeuK3j2gFqP5fZvUuS9tZPx4wslxfIoGiqqgrjrGnoNqE8/tPm0o6Nw = 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_162949_C94DBA08 X-CRM114-Status: GOOD ( 16.51 ) 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 --- 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 */