Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3444566pxb; Sun, 26 Sep 2021 15:45:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZ97A8vKvGCHFf2aaGW2zPLUkA9GzcO5Z4oc+34Voi15ae2OJPTncLKze++mH3BpZMtjNO X-Received: by 2002:a17:90a:5a07:: with SMTP id b7mr8469684pjd.196.1632696305726; Sun, 26 Sep 2021 15:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632696305; cv=none; d=google.com; s=arc-20160816; b=DcNFj9aPYJ2SiWLWWzPyapi418bO+FtAwbadjh+mzupAkAZyLYAc/NQ1c1QgUGC8V9 n3/WEfyPiDWvYqM3pPqlU4gJj2tjClelkk2ZvsvQOnN4hWNNtgLiMbPNekVw7glKH5md SRdYoZ71d6T5vdk3rHemPoqrQdh3RqNJgCQiprJPUwv+19IGc1Gjf3byHZNH6PhCXqgC V527vUA+QdsYVdchiHoCB8ZOecupm1Bp0OzQeJTwZAzSOg9J9grm1tg3rd0TPWe6IP3y S/muPnwp/k69sRZz7nz7Nj872/8SMc1C5Niq55vQCs7lY6BSeKJ06kMKxtRE2XqBgLER YWpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sOB+CC4oKPUtnAgAVkVlulPbe4zQ1YRgefv90mYIpNk=; b=Z23X6KrtFfaesIqInI01icqvdM8+A9O2C9YUKZVWtqMHG73LtLaotHHvXLO9X8Eeop kgcKosgZcAnUm0XOCxJsuS6oPSrBXg0Mmm+oxzPYRt/p+BJ3DZeeVs6xPs+edyBB8m5X +u65RRP5zQ2a4Gbw6iHiR4ZVoekKMI08VZTrVpbkdDBXKDJMsxS2WCTBtkWtk/4yyC2V M+H45CYzR8o8ZWOH9QiuUbkqsrv9ItU0dKkcVcoB2JhvEHiMg4knlDycvrGWqEzZanR1 jE5+9uRVNTSDwLPidCNePbypKr9CaTQPOUdkWlN/8rxmOq7XzQbxmTK+fLP3gShF8DhH s5jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iGoHMkqD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h26si19107316pfq.355.2021.09.26.15.44.53; Sun, 26 Sep 2021 15:45:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iGoHMkqD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230423AbhIZWpC (ORCPT + 99 others); Sun, 26 Sep 2021 18:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232090AbhIZWo2 (ORCPT ); Sun, 26 Sep 2021 18:44:28 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0740FC061570; Sun, 26 Sep 2021 15:42:51 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id y26so29088804lfa.11; Sun, 26 Sep 2021 15:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sOB+CC4oKPUtnAgAVkVlulPbe4zQ1YRgefv90mYIpNk=; b=iGoHMkqDer+IUBfR/bgRrz+jeKIMNsmuhWevyrWar8vyZ4ifaG+5gq5Wps+fwEJ3yV DlLdtKAupURsnA1tOm6n1V60owrMvYFXEePQ9T5+tjSh8Pd5jrCVIfKjmq8q+HtjcB8K 7lz6fnZFGMtalSY62wT7bgFeqUSyfbJv0jqxRfa3/0jKRAXrweLfa4PUcGGW567GqPVR upDg4noq5AHZjEW6xka3N+/+mJvYzCfinhRgO+X2BSM1fc/aS40eUiU/DEglgRI/Zij2 y+0CETDbYVbj2PdJ5oyQ6DSucoaeyqGg/VoKO8+GMz920vrjtNy2cySRtoYW/9IubR8m Rt7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sOB+CC4oKPUtnAgAVkVlulPbe4zQ1YRgefv90mYIpNk=; b=RVrjHHzX4q2tyC/qIbZijaAyLkBmPP9hg1XzpNXWjOWFdCAnqyuE6RKRHFUR/qs9y/ 1GIKKHEablZdnT1PzlZu0M7g2TP+jl1zxlNIvJnPQFX16w16m2I/XfrFnIozUv8Ov0s/ 0JvI46pnGAa6OSfvgKx+hYdelXn8gs85V0k/Z0+TOELy0GMuOCw7FKOE+cCz6WvpHjTt ymRcZXaC4d10Yw/uHweyEiRpegmDHCdZdtuR4QMcvBSrtr+UCmPHVzTEEdozV1pKUr70 IDfOwbWljJf8fmFRfz3hdBqaLO/yWGXPjabjDiVImNNcE+NZgRnsW2hD8tFQ4jyIhx4m Ufcw== X-Gm-Message-State: AOAM533Kqwvxjx+pV8RXD+VdvVVND6+dojQ5PBjE2mD//59oe917Bq/x 8166pdpcqndmUtKDuxKIdRY= X-Received: by 2002:a2e:9b98:: with SMTP id z24mr8364213lji.339.1632696169455; Sun, 26 Sep 2021 15:42:49 -0700 (PDT) Received: from localhost.localdomain (46-138-80-108.dynamic.spd-mgts.ru. [46.138.80.108]) by smtp.gmail.com with ESMTPSA id m10sm1408899lfr.272.2021.09.26.15.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 15:42:49 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Ulf Hansson , Viresh Kumar , Stephen Boyd , Peter De Schrijver , Mikko Perttunen , Peter Chen , Lee Jones , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Nishanth Menon , Adrian Hunter , Michael Turquette Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-staging@lists.linux.dev, linux-pwm@vger.kernel.org, linux-mmc@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, Mark Brown , Vignesh Raghavendra , Richard Weinberger , Miquel Raynal , Lucas Stach , Stefan Agner , Mauro Carvalho Chehab , David Heidelberg Subject: [PATCH v13 20/35] mtd: rawnand: tegra: Add runtime PM and OPP support Date: Mon, 27 Sep 2021 01:40:43 +0300 Message-Id: <20210926224058.1252-21-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210926224058.1252-1-digetx@gmail.com> References: <20210926224058.1252-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The NAND on Tegra belongs to the core power domain and we're going to enable GENPD support for the core domain. Now NAND must be resumed using runtime PM API in order to initialize the NAND power state. Add runtime PM and OPP support to the NAND driver. Acked-by: Miquel Raynal Signed-off-by: Dmitry Osipenko --- drivers/mtd/nand/raw/tegra_nand.c | 55 ++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c index 32431bbe69b8..098fcc9cb9df 100644 --- a/drivers/mtd/nand/raw/tegra_nand.c +++ b/drivers/mtd/nand/raw/tegra_nand.c @@ -17,8 +17,11 @@ #include #include #include +#include #include +#include + #define COMMAND 0x00 #define COMMAND_GO BIT(31) #define COMMAND_CLE BIT(30) @@ -1151,6 +1154,7 @@ static int tegra_nand_probe(struct platform_device *pdev) return -ENOMEM; ctrl->dev = &pdev->dev; + platform_set_drvdata(pdev, ctrl); nand_controller_init(&ctrl->controller); ctrl->controller.ops = &tegra_nand_controller_ops; @@ -1166,14 +1170,22 @@ static int tegra_nand_probe(struct platform_device *pdev) if (IS_ERR(ctrl->clk)) return PTR_ERR(ctrl->clk); - err = clk_prepare_enable(ctrl->clk); + err = devm_pm_runtime_enable(&pdev->dev); + if (err) + return err; + + err = devm_tegra_core_dev_init_opp_table_common(&pdev->dev); + if (err) + return err; + + err = pm_runtime_resume_and_get(&pdev->dev); if (err) return err; err = reset_control_reset(rst); if (err) { dev_err(ctrl->dev, "Failed to reset HW: %d\n", err); - goto err_disable_clk; + goto err_put_pm; } writel_relaxed(HWSTATUS_CMD_DEFAULT, ctrl->regs + HWSTATUS_CMD); @@ -1188,21 +1200,19 @@ static int tegra_nand_probe(struct platform_device *pdev) dev_name(&pdev->dev), ctrl); if (err) { dev_err(ctrl->dev, "Failed to get IRQ: %d\n", err); - goto err_disable_clk; + goto err_put_pm; } writel_relaxed(DMA_MST_CTRL_IS_DONE, ctrl->regs + DMA_MST_CTRL); err = tegra_nand_chips_init(ctrl->dev, ctrl); if (err) - goto err_disable_clk; - - platform_set_drvdata(pdev, ctrl); + goto err_put_pm; return 0; -err_disable_clk: - clk_disable_unprepare(ctrl->clk); +err_put_pm: + pm_runtime_put(ctrl->dev); return err; } @@ -1219,11 +1229,39 @@ static int tegra_nand_remove(struct platform_device *pdev) nand_cleanup(chip); + pm_runtime_put(ctrl->dev); + + return 0; +} + +static int __maybe_unused tegra_nand_runtime_resume(struct device *dev) +{ + struct tegra_nand_controller *ctrl = dev_get_drvdata(dev); + int err; + + err = clk_prepare_enable(ctrl->clk); + if (err) { + dev_err(dev, "Failed to enable clock: %d\n", err); + return err; + } + + return 0; +} + +static int __maybe_unused tegra_nand_runtime_suspend(struct device *dev) +{ + struct tegra_nand_controller *ctrl = dev_get_drvdata(dev); + clk_disable_unprepare(ctrl->clk); return 0; } +static const struct dev_pm_ops tegra_nand_pm = { + SET_RUNTIME_PM_OPS(tegra_nand_runtime_suspend, tegra_nand_runtime_resume, + NULL) +}; + static const struct of_device_id tegra_nand_of_match[] = { { .compatible = "nvidia,tegra20-nand" }, { /* sentinel */ } @@ -1234,6 +1272,7 @@ static struct platform_driver tegra_nand_driver = { .driver = { .name = "tegra-nand", .of_match_table = tegra_nand_of_match, + .pm = &tegra_nand_pm, }, .probe = tegra_nand_probe, .remove = tegra_nand_remove, -- 2.32.0