From patchwork Mon Sep 13 17:38:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 12490299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25CB3C433F5 for ; Mon, 13 Sep 2021 17:41:20 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E4E11610CC for ; Mon, 13 Sep 2021 17:41:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E4E11610CC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: 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: List-Owner; bh=GSfEp5qyrREs5TKKQMvlYILGL3VlCS5a5OzCc9kbuAc=; b=yLZgaw5gFk86aE xhHZ0AoLt/2bJBeNFuLuY2jHUEEBmZfqblFH+VRc8LVyRLDHJZg+J1avg25OPL4jdhehWUoJWSSXn FVBLRLzOBj5NrmuGQm/6gGXJmaJPMYyqsenB6TLKwS+EHTiiUkJCJtoLj0C6OIFRyvw3fszGaSbys bRdE8smJQionfdNMxCXCRFVleHEHxEVEokiHqPgWwrYEydyuvMvr1jA4zyBTkgwrWzg/CnQKXex03 JagokEAL0z9rQgSH8oKMUTCraxM3kH2pqvzj08AQnE8MQukn1Vg/C+LX9CNJgw0m9iA8X6evg8Yiu hPpTOx/8PVWWTpH62eDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPpvl-002kEA-Kh; Mon, 13 Sep 2021 17:39:45 +0000 Received: from inva021.nxp.com ([92.121.34.21]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPpuW-002jla-Vi for linux-arm-kernel@lists.infradead.org; Mon, 13 Sep 2021 17:38:30 +0000 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id B49E02005E2; Mon, 13 Sep 2021 19:38:27 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 9CD002005DD; Mon, 13 Sep 2021 19:38:27 +0200 (CEST) Received: from fsr-ub1664-175.ea.freescale.net (fsr-ub1664-175.ea.freescale.net [10.171.82.40]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id CF2F020363; Mon, 13 Sep 2021 19:38:26 +0200 (CEST) From: Abel Vesa To: Rob Herring , Dong Aisheng , Shawn Guo , Sascha Hauer , Fabio Estevam , "catalin.marinas@arm.com" , Will Deacon , MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Georgi Djakov , Adrian Hunter , Ulf Hansson , Ahmad Fatoum Cc: Pengutronix Kernel Team , linux-serial@vger.kernel.org, NXP Linux Team , Linux Kernel Mailing List , devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Abel Vesa Subject: [RFC 06/19] devfreq: imx8m-ddrc: Add late system sleep PM ops Date: Mon, 13 Sep 2021 20:38:01 +0300 Message-Id: <1631554694-9599-7-git-send-email-abel.vesa@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1631554694-9599-1-git-send-email-abel.vesa@nxp.com> References: <1631554694-9599-1-git-send-email-abel.vesa@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210913_103829_340211_A3E75D16 X-CRM114-Status: GOOD ( 16.53 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Seems that, in order to be able to resume from suspend, the dram rate needs to be the highest one available. Therefore, add the late system suspend/resume PM ops which set the highest rate on suspend and the latest one used before suspending on resume. Signed-off-by: Abel Vesa --- drivers/devfreq/imx8m-ddrc.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/devfreq/imx8m-ddrc.c b/drivers/devfreq/imx8m-ddrc.c index f18a5c3c1c03..f39741b4a0b0 100644 --- a/drivers/devfreq/imx8m-ddrc.c +++ b/drivers/devfreq/imx8m-ddrc.c @@ -72,6 +72,8 @@ struct imx8m_ddrc { struct clk *dram_alt; struct clk *dram_apb; + unsigned long suspend_rate; + unsigned long resume_rate; int freq_count; struct imx8m_ddrc_freq freq_table[IMX8M_DDRC_MAX_FREQ_COUNT]; }; @@ -271,6 +273,22 @@ static int imx8m_ddrc_target(struct device *dev, unsigned long *freq, u32 flags) return ret; } +static int imx8m_ddrc_suspend(struct device *dev) +{ + struct imx8m_ddrc *priv = dev_get_drvdata(dev); + + priv->resume_rate = clk_get_rate(priv->dram_core); + + return imx8m_ddrc_target(dev, &priv->suspend_rate, 0); +} + +static int imx8m_ddrc_resume(struct device *dev) +{ + struct imx8m_ddrc *priv = dev_get_drvdata(dev); + + return imx8m_ddrc_target(dev, &priv->resume_rate, 0); +} + static int imx8m_ddrc_get_cur_freq(struct device *dev, unsigned long *freq) { struct imx8m_ddrc *priv = dev_get_drvdata(dev); @@ -324,6 +342,9 @@ static int imx8m_ddrc_init_freq_info(struct device *dev) if (dev_pm_opp_add(dev, freq->rate * 250000, 0)) return -ENODEV; + + if (index == 0) + priv->suspend_rate = freq->rate * 250000; } return 0; @@ -399,11 +420,16 @@ static const struct of_device_id imx8m_ddrc_of_match[] = { }; MODULE_DEVICE_TABLE(of, imx8m_ddrc_of_match); +static const struct dev_pm_ops imx8m_ddrc_pm_ops = { + SET_LATE_SYSTEM_SLEEP_PM_OPS(imx8m_ddrc_suspend, imx8m_ddrc_resume) +}; + static struct platform_driver imx8m_ddrc_platdrv = { .probe = imx8m_ddrc_probe, .driver = { .name = "imx8m-ddrc-devfreq", - .of_match_table = imx8m_ddrc_of_match, + .pm = &imx8m_ddrc_pm_ops, + .of_match_table = of_match_ptr(imx8m_ddrc_of_match), }, }; module_platform_driver(imx8m_ddrc_platdrv);