From patchwork Fri Feb 9 13:55:50 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: 13551244 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 7A45A4D11A; Fri, 9 Feb 2024 13:56:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486974; cv=none; b=RXD7Th3oDXBDmyzya9BSxjnQ9xooR3yDRHDGDh3BmMTdn/K3x5+9HP0zfAqsOvGv0UEWHnEVV+LwwoFs3mbTQlA89Zt/D1T1/cyd+oAtaFr/9uvGr5MoJpu7DbRDbkz9fW+HIPfEwYqvG4nqZNR3w10v4GKY4P0McSFLFbn9Frw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486974; c=relaxed/simple; bh=Y7H7/t7uj8gApP1bpHRilwd85LT3J++X+h8HBhu5qUE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ek8llW/pZ/KSwL83zvF+1TC0Ss3JEnjO+THVMFrOM4qGwRCJEYmhsJIyQTKKtzgijtGXZdIkDexhmyA2DKyvCbtuKOhTp26H1yXkEjYHHowmb9jhTV+OGoaLwbawEi9qqNB7giQgoNUW03fxc4yE/ZReir+SkmbyzfkmMJjAl1U= 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=PVJ6UVBC; arc=none smtp.client-ip=217.70.183.201 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="PVJ6UVBC" Received: by mail.gandi.net (Postfix) with ESMTPSA id 527851BF206; Fri, 9 Feb 2024 13:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707486965; 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=edgfHyClH8frjqdW176guaeqRWtXQmQVgxIX7uID0gk=; b=PVJ6UVBC5ChpcMt8ptcINE+fuPY2TiGagSVF3uJU2+QddUP1LeGL0w4FRb0pFUOhCqjhWt bjTOPdW5gB2RI7SoAMoMMSFemuA+eq9D6Ni8zaFWqMYZv160/NbcUhG/iB+r0tRoEq03RC D2hn4hgqH4ySbdIC16GGjFM4Fhm21rY4sBESzpWBc9HNfTwg1KSzEV1lZ+7qaPXEBTe2tl FO1ODI4CnMP18TPzLgtz6GDqBebIKxwMzzkSaO/YfspkG7U+HrSaTCbJKVYdbD5ksmb2qQ DqxZU2j52LoFPPQFX7IDiVc/Z9XDnYrZuvPmWWZX+u9I6jXZbTe0aEHfdWSNuQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 09 Feb 2024 14:55:50 +0100 Subject: [PATCH v3 1/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: <20240209-cdns-qspi-pm-fix-v3-1-540ac222f26b@bootlin.com> References: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@bootlin.com> In-Reply-To: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@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 Reviewed-by: Dhruva Gole --- 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 74647dfcb86c..d19ba024c80b 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_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_suspend(struct device *dev) static int cqspi_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_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_suspend, From patchwork Fri Feb 9 13:55:51 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: 13551246 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 C561B286AF; Fri, 9 Feb 2024 13:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486976; cv=none; b=oviaPrGKTr92sc4z4+Pxc3/D4HtT5RVvkEmhpuZm/oU24LPbmC/Tnsuiab2VmY9b/7CU6X/awQ4tdDbgK6C3euGqwqfhtn/e2BDyO49CyBdHHFbbVR02fGprV4UL411h6uS4uygc5gly07Jfn1RSxtaTa9GOtcSqmOwI0uCfg8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486976; c=relaxed/simple; bh=MJODknsNdPWKKihYzzcpVIfotVeSxNrGrwbmt2FA684=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y6JwHb3WmsuQbIwmmcD+YIMsboiYxkouMVy7ytm0inFL4e/IlvBbv7aaQ10gCYTE9LwP2gVZ5oKL0WfTwJx0sSzQL1wQANFZvD1zErzGhfpkZ0XqjxUbg5kFQ4IMbH+mCA9xSba931REHO3OOlXEezi/uxXxu/BSE3fsJUv0qas= 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=VOlPNAV+; arc=none smtp.client-ip=217.70.183.201 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="VOlPNAV+" Received: by mail.gandi.net (Postfix) with ESMTPSA id 3393D1BF20A; Fri, 9 Feb 2024 13:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707486965; 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=mHHh5pthlaRvRNGcIbfyZm+1KloZJQv9bQbNMTFQ/6M=; b=VOlPNAV+tLPiurdzfe97v46AUhH37VsDMw1b/jI6cao5J1q0Kp5XtEJtH7jsDKnozdlOg/ DKyakZx3/Y02haNkXr8PaUtg1obtMx81vPp0ZRAb3zbymAod1GTg+fSrAx5gilmbU1vdy2 EWuW14fIZB31iqm31NFrLyIGG0xAgVM5EgrmkYFXYJ4/vNbqvr5aZa0glNeMW6cC63DQPh M3W4gY8wZdQ8mhLVDkRbCvgck34H5fKTyf4eu4iaSzrdk6LAKdk8KlpVekSoHgr42QSQqn V0NKiQWm+uMZbDUFhdcZ8E07HQaSDe7cLVjukk2mR1nTv+aJus4/xIVALJDaIw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 09 Feb 2024 14:55:51 +0100 Subject: [PATCH v3 2/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: <20240209-cdns-qspi-pm-fix-v3-2-540ac222f26b@bootlin.com> References: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@bootlin.com> In-Reply-To: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@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 d19ba024c80b..809bbbb876ad 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_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_resume(struct device *dev) @@ -1950,8 +1946,7 @@ static int cqspi_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_suspend, From patchwork Fri Feb 9 13:55:52 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: 13551247 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 7C63F4D11D; Fri, 9 Feb 2024 13:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486977; cv=none; b=pnyLu75tKcqnQHm5B5njiv4uUYQe4J62u3u7uxaO8W33gCwBdI3kuUX6E0LblPOmaIEbm2wSWmSwWrHZwJC/7Ie8OBYzV5l6STdrMqO+0iIhTFgpX5lcPpvP8XdVm+bNSHCczqDXIf58Q44usx9iEsh+asqw8/wb/AF/hbuMFj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486977; c=relaxed/simple; bh=u9bsxtohU+8O0/ftK0UrMmBKffO0/k0GLIWvh6WyXKQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X9/H3xGSHjEYCYxwSLJNlHk5ZbsO7Bt9RgpswLsrf/ojAlndFdtDuurnEO8UB5QfvCzLtK3LGWc6WdZAFhHrnpNZ02tIlacd2AWF+M3uujDWBBHiCVHqR5WMDj85sXUPio+ls0OYKpQaGQPpzHww/0J4xH8FRrJyFFBtgz2X1XI= 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=nPeFEuvr; arc=none smtp.client-ip=217.70.183.201 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="nPeFEuvr" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0A9A81BF20D; Fri, 9 Feb 2024 13:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707486966; 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=dXmlq/yLijYckXKkeLmVy9L0DG5yOUTwBMD5D252K9Y=; b=nPeFEuvrBc6WFjtuX4Ol3EEl2l2ga5mNYxvBsWEZi9cPKD0z5zCCwAbmfpSzOXgK4UBkYl jXPYBcrI6YMJ2jYWl7KYtGdRREsX36Qxdcsf9oOH09qe1fCfMHnhttCYChAa6QXLAZwjUf dIgprqI5Db+mnbGjYnFsALRLEKvCSNchwEVLkiR+aFAtS5bvUKal0nrSfCZnXmnDIikFZT 8QVx9Yhwwr9AwwrSWnkht7PRLc6tVtzOT0deupkTT0T5juYvfZFjZ3peAyUohMfojWrXXe OHp7lAY7FdqWCLRAVSQRRA+kA3BA3HaNs8QpaDE/akdfbRDl88iG61A0VuT0PQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 09 Feb 2024 14:55:52 +0100 Subject: [PATCH v3 3/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: <20240209-cdns-qspi-pm-fix-v3-3-540ac222f26b@bootlin.com> References: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@bootlin.com> In-Reply-To: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@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. Signed-off-by: Théo Lebrun --- 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 809bbbb876ad..ee14965142ba 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); @@ -1936,7 +1936,7 @@ static int cqspi_suspend(struct device *dev) return 0; } -static int cqspi_resume(struct device *dev) +static int cqspi_runtime_resume(struct device *dev) { struct cqspi_st *cqspi = dev_get_drvdata(dev); @@ -1949,8 +1949,8 @@ static int cqspi_resume(struct device *dev) return 0; } -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 Fri Feb 9 13:55:53 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: 13551245 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 7C67A4D135; Fri, 9 Feb 2024 13:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486976; cv=none; b=T8uHrgxDEbMdQerTVl7NsO6NjHtFlAFnlJFyfj1CcmJwrreZji5yDFFyM8eGkIIj9KnJPt/m4oCoSQpB3WROAivFZ0aDFaZ65aLxUL/J5j0ePZQNzkJEAdU8eZjVDE6E4lni2Gpp7fPTRT3+OWBbTYdnyvEDffaJ0LDb3tWpvZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707486976; c=relaxed/simple; bh=cstpzce+J+7b1urmkwA3P0JVejglpP3nSE1z8JR3RxA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O9rrIz4bzKLEq1Eczh0lDGs4PCkLnnRHWHjJxaczPjXVwvbJJ7rpoAAvLwTjdUZlIwK8HQoTvTf6Klri6WnQ6Lxgwv8c3WNPDrGI3IGiWyt4OENKChcn22RlpDxJas2KgaBysxazBwCAF8KjQjZWVnafgpLe/2g1hudVM2a0KkU= 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=jzWFemig; arc=none smtp.client-ip=217.70.183.201 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="jzWFemig" Received: by mail.gandi.net (Postfix) with ESMTPSA id D3D5F1BF20E; Fri, 9 Feb 2024 13:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707486967; 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=jzWFemigIBN7tkr2IC/YavhPwPGsVSUWlXGPvdXKNdRDGHcLAKcnSS+n7JY+e7eFS0u5bY 89OPpQ9TxcURK7NssrfPQ/TkCsNmqMc5c9hVljDKS9N9upPZFMVLb8sfbo49mMDSuqoDv3 pbYb5civJ76rq2a8LtiSXC5oGPONX2Hity5DSJxBJM/xxARh9+VTqGy86dVwa96xby5KSx VEsJayEtd0xaP4fuH3CktvM8WSKc87UPY2Igo7MHccdW0pCqtK9L3bxQDz4RQoOlPvBg4d nXaDeFPX+frH581MyBvxGxEDza7nKxeDaF2z+rDkTx8NdPgbYGH61BRNx2z94g== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 09 Feb 2024 14:55:53 +0100 Subject: [PATCH v3 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: <20240209-cdns-qspi-pm-fix-v3-4-540ac222f26b@bootlin.com> References: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@bootlin.com> In-Reply-To: <20240209-cdns-qspi-pm-fix-v3-0-540ac222f26b@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,