From patchwork Thu Feb 22 10:12: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: 13567018 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 ADA8A39864; Thu, 22 Feb 2024 10:12:34 +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=1708596759; cv=none; b=tATfKLumMEmykV4X8GNmo82jpVup/qIjG2osBe18wncspJoLWVycbxDT9ENVW4kkT4U70qq1BOFCpQ6+j9uN5CRXJQYaFy2rAqDHDbVcb4GOV7yOBfwMc3AVrx4vqway/9J0vcv0JJo7TQV2/aa5YpxytT39a0BxP4v8DDMumv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596759; c=relaxed/simple; bh=pM5LYZyHZMUxJj8CsXE8e5NI/BUXEphnfuI4iyKBZ3I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MEWqwmOO+CcbX9N4TRwdS4GBD2VVRm/in+yc63gtHBjzxyq7bH+p+Grg4uVZP/kP0gbzwYym3yezMsQ1k55rmQSm0+HFWuP6+Cji/6CtCwjc6MHNTb+I8irOvt1f/rzzH8RE9tVcdaILQGhZXiVjN61pdMQR0ChbkzmOE8X7NkM= 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=C12geg+A; 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="C12geg+A" Received: by mail.gandi.net (Postfix) with ESMTPSA id CC85B20004; Thu, 22 Feb 2024 10:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708596751; 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=PYyfGG5F+SG8R9R5MyMBf2L1QHcp8qaW343NfMmdTxo=; b=C12geg+ATDXZAWApHIm+FM8jNWV2pVTmU59v+gb3sVRSDhDlvErRLgwTh0Uv8UIkhVzs+4 YnDYb5yCVWElbCaz7tP4LNhgwfa6O9ppsCMqWnUeC0qzFiLGe5GeclDxvWjnUtXKHFe9Gl dmG5QRnAoXHR1Z1vShl8oobqr5esxgh4PL2vEdTigvUqGbM58T7eZL0SptBIYTPZ87qQMJ 5fukdbCBjFHL3amwiG2kEZ/AZ2zb29hi8EEfwJMKvvqfcQy7sV81sGECuUB9LJRKR9IbuK Rj5Bsvn2QVdXVG6mcnO2EMKOAgdxhs15vkdxAQ1z/DtH0wGrGkkIZbXkfDESLg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Thu, 22 Feb 2024 11:12:29 +0100 Subject: [PATCH v4 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: <20240222-cdns-qspi-pm-fix-v4-1-6b6af8bcbf59@bootlin.com> References: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@bootlin.com> In-Reply-To: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@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.13.0 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") Reviewed-by: Dhruva Gole 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 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 Thu Feb 22 10:12: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: 13567017 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 ADB343987A; Thu, 22 Feb 2024 10:12:34 +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=1708596758; cv=none; b=CPbwKFM/GgQGFsiuOXCPdVpNtiB9SpJTetLd+qdguv5qF1tduXq6C3rYMXUlII2RbNOBNB9BHJ+bnTGNlZBb5T3sjen9KbVdV1FxmLUrXAGcXOzu1PHkAIdnltHFQj9i3bqNKy+D+snMZHVMy/trSRYU/8lyR6FJvxtWMP1toIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596758; c=relaxed/simple; bh=U+gzS1ckVJjVA+ftOBxZZr+oCPKKnY2akQ+FTUE4Vlo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JimIglmSvNhdVYyTGbFWrp98VTI8397ueBQi9hXVABdFLl8F/mqyqIrRymuhGwtd7urMrXbmw3BxT+bF+lAkVY5rUw86EHautfhaapToPBYZwMnndauHdY+FwJcWV5qtoTFugSo7gzHAA3KRmz8pZGOPddlp2Hllfd1THCNfJa0= 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=dsw6aMVe; 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="dsw6aMVe" Received: by mail.gandi.net (Postfix) with ESMTPSA id 538872000D; Thu, 22 Feb 2024 10:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708596751; 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=Kr+jGKZ7wa4euSb09lk+qCqBrZfe1hy6OrbVIm5KELU=; b=dsw6aMVe503SzQB89/ddzyuJ08+ZL7xstYhTijpcje0Wv9Zr92DVNUljvFTlOHNMCg0TFY NSDq8XEDWEvjkbsXHhxTXNBHcGwmwLH9CRFP17TfJVWJZ12xX/oyKLs3NwcFgu0Gnvlwpm ft6uzCM7UCQ96ffobAChRCH1vFNm6YyukGTRAZZ/TRnXboUVmFN38QcZ6CWVvVK0FcF+0h fFtlhR14w0ApR5fUA58MefDhqH5oeFxBkGhZ8XAs5VdPLEpYU57EGuwTZiZsft+4mEVvyT ZvsFuIk4OQ4FsvaOWA4Tlu7lQaU38ZKCUbrV8RNoQhFHL5ev2LL6ZuWqvDX7BQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Thu, 22 Feb 2024 11:12:30 +0100 Subject: [PATCH v4 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: <20240222-cdns-qspi-pm-fix-v4-2-6b6af8bcbf59@bootlin.com> References: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@bootlin.com> In-Reply-To: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@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.13.0 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 Thu Feb 22 10:12: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: 13567015 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 A2D7339860; Thu, 22 Feb 2024 10:12:34 +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=1708596757; cv=none; b=h8XEHn9H9La0mCP44P+yPVIinV6ZAZpHnME0kTPWHKq5t4vEctw2X4lrdwYI8VTdt6EevBStqf/pNZNVBZjeC897SNDLkVn2mi6zFgjT4UxSERX93fqv+A9IZhxnj7ejCVU4CmxyrYUTbfVYXD/wuiWoZuCY78GGTKXjctHyIpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596757; c=relaxed/simple; bh=8k//nV4PgtS77JaVQHMDyRcyJk3UctPeuulRegs63Dc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ddiEmeT+Sknx5JCsSrCB/zCna/jkTL0wV5E+LJH79pjjTQxBu5QfcIS0x9MnVGFvfVHjrNkF2hRKGQIUKr5MH5Xlcfh8Grzrz043KYJ1k32YJdXUNHWpAHhvUiFPiLiitUrViSH6ZRtyUrV1k3kn0H+TaCSyM1wzcGeUYw6taqw= 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=dfvMuerq; 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="dfvMuerq" Received: by mail.gandi.net (Postfix) with ESMTPSA id CA9D820003; Thu, 22 Feb 2024 10:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708596752; 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=mvoigvJmPhizIcq2GVnu6+m2ifoXHPhDFh2hNqMqK4E=; b=dfvMuerqqH9Msxa66Jb04Loi05gLrfXlH4U7nG19LWMspJ5RZrc+/RIIDj84N+4ipp5HxA SvbJjT+cIwSjxXVEmKiWLUwUrxwMG0QCa97fPqjItYJ1NiD00/5QzrXPy4VXuADVvyyjKa KBwIFDs9m7ih7V5mGBnnHmSdtIyto1jWVesTlXtCwPKtwN6kLVS8CYD7OeSWpZ6ctVBbkA dUAOinAR2lXOA4OL7ZswXSsYKV3EY8784LKdMjCmC9e51kFNJonrI0JNyu8t5B+mMcT4op tfFYOpMHrIEpM9h2Y5861K/Qrm3s8KtsrF0oiiJ0RjqsiYOLNRr1zDezYq6fAA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Thu, 22 Feb 2024 11:12:31 +0100 Subject: [PATCH v4 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: <20240222-cdns-qspi-pm-fix-v4-3-6b6af8bcbf59@bootlin.com> References: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@bootlin.com> In-Reply-To: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@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.13.0 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 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 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 Thu Feb 22 10:12: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: 13567014 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 ADB0239876; Thu, 22 Feb 2024 10:12:34 +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=1708596757; cv=none; b=o9ubogkRHDnhyXDaoSRaFVTQmBX7FcFF9pJY8xRo9xnmFrrNOzU8TQpc3o4DGegSAp2zeF9V/pxzguRhWjJuAb/f9jAkvEtPHNRzPgydEgtEvvs4mPpT4f/YymjHixi3sO821RUI0tZUSDBO/IN2UZi5RhO6zEqaAWUP8eJWhgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596757; c=relaxed/simple; bh=phqB6EsMKmMZCxST51NEKAHp04XCYXDRfwNdDc4qp3c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DYnaqOZOAvLvuUlitX1JKj3TiYcL4RQHyBaiRc52+BK8ocvg9RTFLAfo2VP5if7M++RVNAb9NdHfeVxws6m6hf8P9EOMMxYa/P0hwKaJVzoSCINFVu2KjjN66SZ1O/9LX3qPHc6p/z6XjbDQtoOMEmXFALNPkTiTGByr2ePlOeg= 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=SqGH+qEE; 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="SqGH+qEE" Received: by mail.gandi.net (Postfix) with ESMTPSA id 5239320013; Thu, 22 Feb 2024 10:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708596752; 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=Eg97yjO7KdqvwAZXBVokHmZiB+7Ptk8zlKT2d8Y1vCs=; b=SqGH+qEEI2ulAOG8ee55jdUpIZiKanKdcg3SxLMP34ZEIL0BtCd4sBiOQU0Tra3JQhnFbD PjaMzsqcC5FdcQLbQ1pRoYgt1dX9lmG3fW1z3HZA6RCI7cdsAyKv34zCRGJyygK7L7bHDU wHeAzwYBq7D5Ai1cGs2XeLRjFA3KNFQpdfTAwozXeWoVAKiiXwRFT8DruAPifaj8DnSaWH kIZtV8CZtGFTG6rdP35efOOTIaSsysvUDaze0bdkXfkk+/TdBUzlksUi4/nPjECEpa0sMu +y18tn4dI5IPHVHkGrJYbNgXrhEXrCb6SJBVN7L3O6jcrVk/x5Pd5EUs3gCYeg== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Thu, 22 Feb 2024 11:12:32 +0100 Subject: [PATCH v4 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: <20240222-cdns-qspi-pm-fix-v4-4-6b6af8bcbf59@bootlin.com> References: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@bootlin.com> In-Reply-To: <20240222-cdns-qspi-pm-fix-v4-0-6b6af8bcbf59@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.13.0 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..8bcbab90cb75 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 = { + RUNTIME_PM_OPS(cqspi_runtime_suspend, cqspi_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(cqspi_suspend, cqspi_resume) +}; static const struct cqspi_driver_platdata cdns_qspi = { .quirks = CQSPI_DISABLE_DAC_MODE,