From patchwork Mon Feb 5 14:57:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13545664 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 952DE2D057; Mon, 5 Feb 2024 14:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145060; cv=none; b=qXJUT26VLg0UB3YW/CSJ+2hQVDdOZz/wVurkB93XLCe+oFrTYpA48+P+f0RRycM/KIp03dKrMHyiMo57SGTIVyiqPE+PjOL7w3lo0olMZpFt0Up3tLEE7czt7kg8WzANdXAhegem1JuhPImC17MIDhKcvVN/DXSTe9AtAKxfmxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145060; c=relaxed/simple; bh=m2XZhlLpN5aSeXbQFhpV8z4QLndJRWw0770SYgQStq8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=vFx/QnHJ7TjFZ/2YDCfUkBFsh5QrTgJLH72+n+xfUXgwjr8kf57Ldtg7Kh2ecQTe9bLR69KfNByMBwPIarMQGsLYh2kdo7ZzowbIeabwu62vgulkGe6raWudhVTN5NB/44f2sxO1FFWKTSxPL7O/UkPHpss+Usx1PkPfs6nH/6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=IhfWuC8q; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="IhfWuC8q" Received: by mail.gandi.net (Postfix) with ESMTPSA id 94ED420009; Mon, 5 Feb 2024 14:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707145051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ntIK1ht2V349W+UW4Kgf9LtLhGBVrs1jWnKGiUHScxQ=; b=IhfWuC8q4u6WUe40Tu3HdIb9eC+23NaBw2fa8E8ZkR95N4i6/92BYQnv16mbFY+POXRE7a HM9r2xsQYeyZtgcWioLVLSKdTXGVqsz6nhffaj3k4ASSg19LH6R0QqqP8CE8/d0nxXfCai rsnhsoL0Jlm8O/odgSbs4SgTLdr9FrjqYo2KlIIFsElR9fo73b/Q3kuR6cNXkacj4enVut 2cVxm8P/5hkg6iBxM+G6Q0EdpKd8L6VQRR8/OtyeUgjQEwpqRyxH47TdmYgXke8+1QMD+6 cXelRmn2HOHknzS3GkbUT3Il/uOOCFaWL1mLYNpXuw3w3bgndfgRmB57ENbr8w== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 05 Feb 2024 15:57:29 +0100 Subject: [PATCH v2 1/4] spi: cadence-qspi: put runtime in runtime PM hooks names Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240205-cdns-qspi-pm-fix-v2-1-2e7bbad49a46@bootlin.com> References: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> In-Reply-To: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> To: Mark Brown , Apurva Nandan , Dhruva Gole Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Gregory CLEMENT , Vladimir Kondratiev , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.12.4 X-GND-Sasl: theo.lebrun@bootlin.com Follow kernel naming convention with regards to power-management callback function names. The convention in the kernel is: - prefix_suspend means the system-wide suspend callback; - prefix_runtime_suspend means the runtime PM suspend callback. The same applies to resume callbacks. Fixes: 0578a6dbfe75 ("spi: spi-cadence-quadspi: add runtime pm support") Signed-off-by: Théo Lebrun Reviewed-by: Dhruva Gole --- drivers/spi/spi-cadence-quadspi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c index 74647dfcb86c..720b28d2980c 100644 --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c @@ -1927,7 +1927,7 @@ static void cqspi_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); } -static int cqspi_suspend(struct device *dev) +static int cqspi_runtime_suspend(struct device *dev) { struct cqspi_st *cqspi = dev_get_drvdata(dev); struct spi_controller *host = dev_get_drvdata(dev); @@ -1941,7 +1941,7 @@ static int cqspi_suspend(struct device *dev) return ret; } -static int cqspi_resume(struct device *dev) +static int cqspi_runtime_resume(struct device *dev) { struct cqspi_st *cqspi = dev_get_drvdata(dev); struct spi_controller *host = dev_get_drvdata(dev); @@ -1956,8 +1956,8 @@ static int cqspi_resume(struct device *dev) return spi_controller_resume(host); } -static DEFINE_RUNTIME_DEV_PM_OPS(cqspi_dev_pm_ops, cqspi_suspend, - cqspi_resume, NULL); +static DEFINE_RUNTIME_DEV_PM_OPS(cqspi_dev_pm_ops, cqspi_runtime_suspend, + cqspi_runtime_resume, NULL); static const struct cqspi_driver_platdata cdns_qspi = { .quirks = CQSPI_DISABLE_DAC_MODE, From patchwork Mon Feb 5 14:57:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13545663 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 952B62D054; Mon, 5 Feb 2024 14:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145060; cv=none; b=Zv2iQPlV8PLLWiFmoRFe57m9Crc+/qV8o1t0WwYB2O+L8FF93u0UQFORuTh2vg6Ox0rT8zOsizJj4bVRpRsJnVWYb5Ql+qItMFS7I96UAKHEo2oLsAisQ/b46BZkRT4NtdCEMVgLnYI+Ns9LVaIeQAgJ6t+KOEYDA8j9G55Xhao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145060; c=relaxed/simple; bh=0TIv8do25e/uL4lq4tvg5O/ua8nIaVhna6ZlQbpAaHs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uGV6t7EhyxX+9lMe5pJXlahf3UFHb91EMBbZc2gdFbGUe517ppWH27/JEEqEFU9Ie2Jlk1y3RTmZ7hd6VYbju1hk1rVi7xnYzZ5B19P+Ey+rQqecslkhbR9d13GvbXe3B7UCQvHJKcf7l8ZdgPv1BP9gXxvntVeF3962P9w/VEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=kzvfDQtO; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="kzvfDQtO" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1A9F520010; Mon, 5 Feb 2024 14:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707145051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2dW3YRsN3P/j/sY75FzxRXD8f2o0gC9+4GEJkf/Bos8=; b=kzvfDQtOo6/Vma01SnlkXEt4R6RXIKcub5Z85ty5eZbHB0g6f9mzimhgyVoHvWrCDc7zbM YItcz0fwfImmnCPXLr0oIDtX/U6+IA2c0kHG7LsSQKVlWbnPJvWQXGBuuduTmS2CK5Myb5 ZIBf0iK0vFyzq5qLqDEBOpyQPaUk8PJYytpQcruA+ZZ93JhCakpb6Ufq6p9WpJ9CQprqBC w4uUCIkS2JH0TwJBYOV/+pMiNlH8dqvn1zyef/m3MTMtTLazqch+oX3U7IfzerLYp4YnaZ vArJcemC99BrioYouxkSHzLR6JJzYHflxI4/0bDdUNRc4TbS4FSu1P6tTCtV4Q== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 05 Feb 2024 15:57:30 +0100 Subject: [PATCH v2 2/4] spi: cadence-qspi: fix pointer reference in runtime PM hooks Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240205-cdns-qspi-pm-fix-v2-2-2e7bbad49a46@bootlin.com> References: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> In-Reply-To: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> To: Mark Brown , Apurva Nandan , Dhruva Gole Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Gregory CLEMENT , Vladimir Kondratiev , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.12.4 X-GND-Sasl: theo.lebrun@bootlin.com dev_get_drvdata() gets used to acquire the pointer to cqspi and the SPI controller. Neither embed the other; this lead to memory corruption. On a given platform (Mobileye EyeQ5) the memory corruption is hidden inside cqspi->f_pdata. Also, this uninitialised memory is used as a mutex (ctlr->bus_lock_mutex) by spi_controller_suspend(). Fixes: 2087e85bb66e ("spi: cadence-quadspi: fix suspend-resume implementations") Signed-off-by: Théo Lebrun --- drivers/spi/spi-cadence-quadspi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c index 720b28d2980c..1a27987638f0 100644 --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c @@ -1930,10 +1930,9 @@ static void cqspi_remove(struct platform_device *pdev) static int cqspi_runtime_suspend(struct device *dev) { struct cqspi_st *cqspi = dev_get_drvdata(dev); - struct spi_controller *host = dev_get_drvdata(dev); int ret; - ret = spi_controller_suspend(host); + ret = spi_controller_suspend(cqspi->host); cqspi_controller_enable(cqspi, 0); clk_disable_unprepare(cqspi->clk); @@ -1944,7 +1943,6 @@ static int cqspi_runtime_suspend(struct device *dev) static int cqspi_runtime_resume(struct device *dev) { struct cqspi_st *cqspi = dev_get_drvdata(dev); - struct spi_controller *host = dev_get_drvdata(dev); clk_prepare_enable(cqspi->clk); cqspi_wait_idle(cqspi); @@ -1953,7 +1951,7 @@ static int cqspi_runtime_resume(struct device *dev) cqspi->current_cs = -1; cqspi->sclk = 0; - return spi_controller_resume(host); + return spi_controller_resume(cqspi->host); } static DEFINE_RUNTIME_DEV_PM_OPS(cqspi_dev_pm_ops, cqspi_runtime_suspend, From patchwork Mon Feb 5 14:57:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13545666 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 709552D608; Mon, 5 Feb 2024 14:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145061; cv=none; b=dVtv4UONLpqyAZVvIO21LQ6OW2yZvjAwiYAL2V38+ASlx47wbkZ379eftmHJGVczM9d/hJjvXUsvo1Oto9+r0p09MLX/0lp2Y/yqnDWbYjaWm3TrLPnoSp/nCFr2juUo098cgGFwmpjUnWnlv/UiqZstpEMzXujo6NGvZyyhIuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145061; c=relaxed/simple; bh=JMbhlud7refefepc6cbZbO1h9xgdtvzBjl+BpdUwOjs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H5K2+kq6D4IKTt/A0hIY8UMPK2S+Ur/fsDSPU4RQzIAH3SF8wXDik13jQDMaK4Jr8Utri4UUekUi1oHeaWEM+fDUC352g7uia9gCRE1D8h1rpwJvFVjBQBiyimZFTDRODzfjGcedPJl6FIcDL2mi+VU79t051ob4etetrjNUlG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=g9KSmxUv; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="g9KSmxUv" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8DA612000A; Mon, 5 Feb 2024 14:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707145051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r4OQzcLAofPBxtpl+SThQ0jsbUehiX/Q8NETsj1jEIk=; b=g9KSmxUvJv9MIFtkvV5a5uGHLifTWOtHoD5jHFbj0uYp57gcoPoA8Rfw1g4ZOYbyWCf/pD 7ItfRjRHVhnprJEGxW/xwMaEG0FWRvcC8SkncfeIyHkd5pnaZh+T9opoXpPddLG3uoxEm1 YsB8MWInPq4QoZVsguPKdxLZlfBB+xmKhDJjPUr5AmnN3/79YQp/auCJuAiWqpePyuR39P INmIDdIoC3udR989OppJNOZtNeEbZZEkhusai3+8rWW10zI1f2UqH7L/AN2JX5iB414jGC U3NjgoD3tfI13G+NWwoAB95DwDseaOgxavQLFoTSzoUsyYjRpOopqFbweL4kjA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 05 Feb 2024 15:57:31 +0100 Subject: [PATCH v2 3/4] spi: cadence-qspi: remove system-wide suspend helper calls from runtime PM hooks Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240205-cdns-qspi-pm-fix-v2-3-2e7bbad49a46@bootlin.com> References: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> In-Reply-To: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> To: Mark Brown , Apurva Nandan , Dhruva Gole Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Gregory CLEMENT , Vladimir Kondratiev , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.12.4 X-GND-Sasl: theo.lebrun@bootlin.com The ->runtime_suspend() and ->runtime_resume() callbacks are not expected to call spi_controller_suspend() and spi_controller_resume(). Remove calls to those in the cadence-qspi driver. Those helpers have two roles currently: - They stop/start the queue, including dealing with the kworker. - They toggle the SPI controller SPI_CONTROLLER_SUSPENDED flag. It requires acquiring ctlr->bus_lock_mutex. Step one is irrelevant because cadence-qspi is not queued. Step two however has two implications: - A deadlock occurs, because ->runtime_resume() is called in a context where the lock is already taken (in the ->exec_op() callback, where the usage count is incremented). - It would disallow all operations once the device is auto-suspended. Here is a brief call tree highlighting the mutex deadlock: spi_mem_exec_op() ... spi_mem_access_start() mutex_lock(&ctlr->bus_lock_mutex) cqspi_exec_mem_op() pm_runtime_resume_and_get() cqspi_resume() spi_controller_resume() mutex_lock(&ctlr->bus_lock_mutex) ... spi_mem_access_end() mutex_unlock(&ctlr->bus_lock_mutex) ... Fixes: 0578a6dbfe75 ("spi: spi-cadence-quadspi: add runtime pm support") Signed-off-by: Théo Lebrun --- drivers/spi/spi-cadence-quadspi.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c index 1a27987638f0..ee14965142ba 100644 --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c @@ -1930,14 +1930,10 @@ static void cqspi_remove(struct platform_device *pdev) static int cqspi_runtime_suspend(struct device *dev) { struct cqspi_st *cqspi = dev_get_drvdata(dev); - int ret; - ret = spi_controller_suspend(cqspi->host); cqspi_controller_enable(cqspi, 0); - clk_disable_unprepare(cqspi->clk); - - return ret; + return 0; } static int cqspi_runtime_resume(struct device *dev) @@ -1950,8 +1946,7 @@ static int cqspi_runtime_resume(struct device *dev) cqspi->current_cs = -1; cqspi->sclk = 0; - - return spi_controller_resume(cqspi->host); + return 0; } static DEFINE_RUNTIME_DEV_PM_OPS(cqspi_dev_pm_ops, cqspi_runtime_suspend, From patchwork Mon Feb 5 14:57:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 13545665 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 709272D607; Mon, 5 Feb 2024 14:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145061; cv=none; b=MOQUHSwYrjIolx3XX5c/JIGCW5ppOpYkqarnWXyScVGhfwASwJ5ozjlmfh4eNz5xeTa+Z+vWDJ6IwjLCjJLnqIBSMs6jXtwDQdK6b7/koH5G3PaRI17mT4ttMzJtR4ThttT8YvcRhcz0aY48a7ywlTRjOTE3/+HkYNXzuXh1lNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707145061; c=relaxed/simple; bh=cstpzce+J+7b1urmkwA3P0JVejglpP3nSE1z8JR3RxA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f8WCThDIq0gTT3P5uHFg8ufBbtZjt5YPv/x57Y3erBAxEC7dm3H9IjxIm/vomTba1/+tRQHxayHm1dsRewJp8x7w+rxhsJkPcPYooZD/k3phMoXq2JB1FpZ4lUC0+RYGnWN/G7x88V8WECwlW43EPlNYKryGVt2FeDvRkdleUIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=bqC4KiMd; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="bqC4KiMd" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0E51A2000F; Mon, 5 Feb 2024 14:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707145052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RqketI7LTDXTpTwWPnxjrx3WSm2BtW9HamRjcUb4AQk=; b=bqC4KiMdfymIvbi/PG+BDj33Q8eJ4s2v+BfhsI02Q9bYVMCXh9FLDiiwjqSHzOkR+c2uti YlTQqD4JuqvOUOJszNbmBRwmztc0joTBsXatNC43dal/y/HrVLjDAccxh2gI6j42H1QK9V iWYhdYrJl4cKxv2ZFo7my4osnMVK1WJcWbkDhOi2gPs7e+i6h9hSgIVvzn+LN6jxtl+5wT xkZQKhaz4cFGThnNCetNQT2EZJDDyGaDYNzYWLibM2o0DolK0SosnE45Blfd0JRcRqMd0y HyOE5JaMQMVsNZQ7qNqQojBTDJmvnyz21aGaay4TzXBBUWqhbIqmvPFKXe0ATg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Mon, 05 Feb 2024 15:57:32 +0100 Subject: [PATCH v2 4/4] spi: cadence-qspi: add system-wide suspend and resume callbacks Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240205-cdns-qspi-pm-fix-v2-4-2e7bbad49a46@bootlin.com> References: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> In-Reply-To: <20240205-cdns-qspi-pm-fix-v2-0-2e7bbad49a46@bootlin.com> To: Mark Brown , Apurva Nandan , Dhruva Gole Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Gregory CLEMENT , Vladimir Kondratiev , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.12.4 X-GND-Sasl: theo.lebrun@bootlin.com Each SPI controller is expected to call the spi_controller_suspend() and spi_controller_resume() callbacks at system-wide suspend and resume. It (1) handles the kthread worker for queued controllers and (2) marks the controller as suspended to have spi_sync() fail while the controller is unavailable. Those two operations do not require the controller to be active, we do not need to increment the runtime PM usage counter. Signed-off-by: Théo Lebrun --- drivers/spi/spi-cadence-quadspi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c index ee14965142ba..f976681187b0 100644 --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c @@ -1949,8 +1949,24 @@ static int cqspi_runtime_resume(struct device *dev) return 0; } -static DEFINE_RUNTIME_DEV_PM_OPS(cqspi_dev_pm_ops, cqspi_runtime_suspend, - cqspi_runtime_resume, NULL); +static int cqspi_suspend(struct device *dev) +{ + struct cqspi_st *cqspi = dev_get_drvdata(dev); + + return spi_controller_suspend(cqspi->host); +} + +static int cqspi_resume(struct device *dev) +{ + struct cqspi_st *cqspi = dev_get_drvdata(dev); + + return spi_controller_resume(cqspi->host); +} + +static const struct dev_pm_ops cqspi_dev_pm_ops = { + SET_RUNTIME_PM_OPS(cqspi_runtime_suspend, cqspi_runtime_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(cqspi_suspend, cqspi_resume) +}; static const struct cqspi_driver_platdata cdns_qspi = { .quirks = CQSPI_DISABLE_DAC_MODE,