From patchwork Mon Oct 7 19:13:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Xu X-Patchwork-Id: 13825187 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011067.outbound.protection.outlook.com [52.101.65.67]) (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 91AD41DE3A5 for ; Mon, 7 Oct 2024 19:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728328432; cv=fail; b=auT/9Q8TXfrql+9MkHQn8RxsrMIytieTDLEvl+tj4uPRmbOPPhkHoTCL4VLG3ZbvXOiRO4tZhlKypqavIo5HEFK1FBG+OhmP3hs4Db8Kdhk3DzAE0Q796XDZWf0r6++aN/QJMbiUl8j0J2fV7TYcOR/kW2W1tBxyCCCqol115H8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728328432; c=relaxed/simple; bh=RJUixFnlTBvwuwT2fByJ9mucK9vmQNUFTHc5frMn+sE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=HY8tRbMrmww2+OzKejhdshG9asLS1UlLKPxLz8vqEbnmx0GExIIyFoFRv5ADLl1i7EFzFq1NLPOMslYl+xHtP/REkJRZnzeHypsJGDMWGKGjx+uKC8fFW1SSFFLvgBmDvgY2xiKY2QMS9jsmjOhF37WSzlaMBq836ZAfjFfiJ8o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=HAS+Xfvz; arc=fail smtp.client-ip=52.101.65.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="HAS+Xfvz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mc8w0xMisUY2gOxVXizpRabJ79zi198bVBr57pWEkgE/8nGbBCTaq8VUgLH9fOBXGnD9bC84CR6Rx5/Rfpc08FQj8BMlLmjAvVCmYaco9UHzPKvfxylbLqWEcUcoAfhYixyuUSaxjqjt4aa73wMV6gXYQjTAFd2YGM1MLn4v2Dvp8n7lGq3QzqLMifbh5Ff6txhqjL+5BOWBuWfN9+ao+0/GwB1HACe6RbFVnTebmbUO+FVF1GsYFdqXBnFM5TN2XbKaeV5U5HMO/NjhRJFUgp3R3mC/DauWVgMhfqjQJ/S1B9tgtTK0Zg/fcYO/ZUEoRJqL4bqFbtWd4y5eReZ98g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qfksOxHJJl435TBrC1L03dhlO4qDaF9VbPYIqVwSM7o=; b=hrAUYQbYT3MPWKreapvJ37DMg9wt1ozw+lFW3c4RLb/+mcyzHZMUKHh29xpoYggyw7HKNi8Nl7jVHcqYMacy4Ejs9JU8v6uRG4Y+sIkggo3l1Z463mdJo9X6gLq/aarXtJyAtGt6rP/EA9x4w/t33qlylzpTJbmu37CweDWcmRZHAFr9xbDkiMHuEj2pF1n6Mduir/O23bxeVfBV9rslvddjtvVehXK5Kl9NY7xRM1FQ9tSYsh3SdvdY2S2E5PI2SkMdptnXWOFpRAnBJ9TMmz35NJa6zx5XdFVGWIPKYbjsRStaoCrhJJiUxlvmOj9HfR9ni3h5Grg+xH7F7VuA6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qfksOxHJJl435TBrC1L03dhlO4qDaF9VbPYIqVwSM7o=; b=HAS+Xfvz31Fp7/GHMe1PL4oc91Oo9Hmn4DY3nEFNAdJMMmb4bhRM4mw8K4PRpVfxGYCatbqWkLCslR9qMsBcL4SrIYuTo8ktx7Gzz6uDlk8Sj/GWCMbB8NXqcdjkzZQSMCQcU+kuSUH0zg+CatKth5/49cjes6BcY/dpcroArNJz5zsp3ZOg3rARQQZBNOiXxFEwYOr/aoQja1nVo6otbpEb+fAR72tyib3agn8xPBXo9bA3DeZKCJpSdAa/Dxv/vw5mL2V4ok0mEkNoSjHBa/ma1Or39qSJ6G2Y1dw/uivQjtSUu0jIzZ/tYWRvHNCZHvOE2ZnuKeXZidywwoxU/Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from GV1PR04MB9071.eurprd04.prod.outlook.com (2603:10a6:150:22::11) by PA4PR04MB9413.eurprd04.prod.outlook.com (2603:10a6:102:2a8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.22; Mon, 7 Oct 2024 19:13:47 +0000 Received: from GV1PR04MB9071.eurprd04.prod.outlook.com ([fe80::b7f2:1d0:6b6a:ba58]) by GV1PR04MB9071.eurprd04.prod.outlook.com ([fe80::b7f2:1d0:6b6a:ba58%7]) with mapi id 15.20.8026.020; Mon, 7 Oct 2024 19:13:47 +0000 From: Han Xu To: Han Xu , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: imx@lists.linux.dev, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] mtd: nand: raw: gpmi: improve power management handling Date: Mon, 7 Oct 2024 14:13:19 -0500 Message-Id: <20241007191319.220775-2-han.xu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241007191319.220775-1-han.xu@nxp.com> References: <20241007191319.220775-1-han.xu@nxp.com> X-ClientProxiedBy: BYAPR07CA0104.namprd07.prod.outlook.com (2603:10b6:a03:12b::45) To GV1PR04MB9071.eurprd04.prod.outlook.com (2603:10a6:150:22::11) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR04MB9071:EE_|PA4PR04MB9413:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c7c00bb-a71f-4ad5-9d97-08dce7042b92 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: wo/zV45u8hGi7vZst+1CMjYpfPeZqAkgL8MOqNxxL+DyrMg7jli0B71q8/MubMkxRlKQOPKHlt5ed8T1nkQZK5oyShR9IMg5RXWyQeM7Zb8oPhuH2VoRXDW1oo16b3Uwvxt74rDHfCtUq2i0ywDr881uMnZMb0mOxJMvh4SyhPSsXyJ8BRwUP6samkv1B3MUJ6O2O7w+943AYHvPaG9eqRkorXFYfQwpuLssBvNsE9gWdz+/8Jsr6BT9rAgGctsqgb5Glxtc5HmzV/QE8FKUs9bRp1rGCh2em8sSr2DhUXM2iTlMQ/go35bv4IooKV68fD13yLdKZxxtD3X1/Mr35Q7KTPtJMRwr3zKOMkla6YgLF19pM77NpvBmze++BMri6Q2nhJiSJzAwyVvNm16KxH8nlPCHCNSMe+znCEtjkXGUEIbDg21NT101q1Wu2gQM7aeptu1MrBNfaTP+/QS4YYo0eTKE6r7sQhTBylZGsFrYphGmhEiE4s3msTZ0xSyXuXzafeGSyC1G8366o/eFCzlO5m+Ia6BlSYaxCAbmJEfGmLQq9PyyvOi1JNEx0dfxeTUKm5SflGVKXurjV9HkqyBqXmRA23NRwegRZYfNN7CeUKQpzss1eOc+9AyyDZCsq5ACM9n0RuAzId4JVjYaYhnadj1CABVEgz0wynXCfz7nRXwWLwJp0PkEcejUm1PTFi+M4wBP8QheSDqRU6FV+hRYYTiHRGz6OClyyYGnMqwy1DjDq140w5kqfAOM1r4vervAZQ+i8gwxji0YrnLQvHwUzPTCaAznrL530S6G9BeTCS20pZ5iv+NepV0pJKYQXyuBmrPAH/mq08+b+wSCaauNj3N7xdI4BrmC/Wqu2Ck1BeNiX6DP7RBifqf+EGquBUqveqHWtutroB2pv0OGQtejGWZLkx9g8240y4FV+fKemYUIMxwh5l4CfpoUgCS6lhm78WGitZcyMCQrgGVFDj7SaB8n7+VIti2LjAGjqmciAg7CEbTUtMRwIHbi4Z0SBaU9mBX15OS7x1APPN/uA1Pa7QqDffJijxKzuS0pFjyYh73lSDDQvDqehznhbKVFhVIPxMUQDQOdzGWwD5s52IXV38NYKQhIq3SMSh1d6N8mGv1Z2hS7HnGIFdac9sZtMF/RQzdBmblVF3uvBPF0xgsj8cSy2IYw3m7hLrHj/4iGEpTcjalzlEygIq5bmdskxXKMbvnjFTRqEDI/DaU2T5bbBCbfGZGoOX8xvrm8hBFk+bAj/ioibQ+1KiSLhoUi79LjGv9Ejpcn27kjRZBfYQVZuG4tpmTQdXxaHcetq5hIrMFkcSvhusLuI1KDlHjB/QbegQHGNvAnfBvrK+EUqA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:GV1PR04MB9071.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP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2JQQTC0MreCFkyc6uY+38h1Zu0tvFQYEJCS7fwlI2XjDBlOPe5yN2hxHXiz9P9EWtBiGjFjFnFgKG3eHvrMeP4KgK3H25Ig4coo23/APWNWHjnzEoVxGfak7jUALNB9Xk2pK7J7D0j50BGWigP4QNCoe3B1TU6fmeqMmZS6p0JpCUHrJ59P7T0M+8yGKgeLtKtQbsxaclDTaM4Hah7Sf4AqdXXcKutreAEPusRvqEhCZVZzW19NueHFkoHFeJt5MqnOGXnzSlorgejxZJS3Q7Hv2gEMDF0DbAXiwkp2XCPUAamerHNIQ+GgcY2Yw7tOiJbZfcWYnQVbVkVKmdr3HBo0EFZzFYx4HAtwl7v5ZXomaasHaKoJyBXCmbHQ2tEs4HGCJVXo1GkTtqID/HY2W+2n5avDp/J5qmTfv2MtDtWD/R119TlIMo1+E6sZrxwWRb6FjazJ5B/uax3DzAwUr0qaXZ5jP96I8eLo9ru1sWwSSvjx43uZDp7WOZiIllLvGuvYiXqN8uKOcVfUKQSPHp6ClohBcMFbJRhqy4LDzJ7qf6vkklLauEsZ3aqpH6Ig= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c7c00bb-a71f-4ad5-9d97-08dce7042b92 X-MS-Exchange-CrossTenant-AuthSource: GV1PR04MB9071.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2024 19:13:47.8127 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bzvq8HFXTvtWBQy5CYuRP7zLOyX27ppag6l5dBGh5cP1oRBMnV0H+qqwZyrGILI8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9413 Refactor the power management handling in the gpmi nand driver. Remove redundant pm_runtime calls in the driver probe function. Handle the pad control and use the leverage runtime suspend and resume calls to take care of clocks in system suspend and resume functions. Signed-off-by: Han Xu --- Changes in v3: - Delet the DMA channel acquire/release in runtime pm ops. - keep DMA channel acquire in driver probe. - Refine the commit message Changes in v2: - none --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index a7d79679248d..cab6d7b4f4dd 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "gpmi-nand.h" #include "gpmi-regs.h" @@ -737,9 +738,8 @@ static int bch_set_geometry(struct gpmi_nand_data *this) if (ret) return ret; - ret = pm_runtime_get_sync(this->dev); + ret = pm_runtime_resume_and_get(this->dev); if (ret < 0) { - pm_runtime_put_autosuspend(this->dev); return ret; } @@ -2761,15 +2761,9 @@ static int gpmi_nand_probe(struct platform_device *pdev) if (ret) goto exit_acquire_resources; - ret = __gpmi_enable_clk(this, true); - if (ret) - goto exit_acquire_resources; - + pm_runtime_enable(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, 500); pm_runtime_use_autosuspend(&pdev->dev); - pm_runtime_set_active(&pdev->dev); - pm_runtime_enable(&pdev->dev); - pm_runtime_get_sync(&pdev->dev); ret = gpmi_init(this); if (ret) @@ -2779,15 +2773,12 @@ static int gpmi_nand_probe(struct platform_device *pdev) if (ret) goto exit_nfc_init; - pm_runtime_mark_last_busy(&pdev->dev); - pm_runtime_put_autosuspend(&pdev->dev); - dev_info(this->dev, "driver registered.\n"); return 0; exit_nfc_init: - pm_runtime_put(&pdev->dev); + pm_runtime_dont_use_autosuspend(&pdev->dev); pm_runtime_disable(&pdev->dev); release_resources(this); exit_acquire_resources: @@ -2801,22 +2792,23 @@ static void gpmi_nand_remove(struct platform_device *pdev) struct nand_chip *chip = &this->nand; int ret; - pm_runtime_put_sync(&pdev->dev); - pm_runtime_disable(&pdev->dev); - ret = mtd_device_unregister(nand_to_mtd(chip)); WARN_ON(ret); nand_cleanup(chip); gpmi_free_dma_buffer(this); release_resources(this); + pm_runtime_dont_use_autosuspend(&pdev->dev); + pm_runtime_disable(&pdev->dev); } static int gpmi_pm_suspend(struct device *dev) { - struct gpmi_nand_data *this = dev_get_drvdata(dev); + int ret; - release_dma_channels(this); - return 0; + pinctrl_pm_select_sleep_state(dev); + ret = pm_runtime_force_suspend(dev); + + return ret; } static int gpmi_pm_resume(struct device *dev) @@ -2824,9 +2816,13 @@ static int gpmi_pm_resume(struct device *dev) struct gpmi_nand_data *this = dev_get_drvdata(dev); int ret; - ret = acquire_dma_channels(this); - if (ret < 0) + ret = pm_runtime_force_resume(dev); + if (ret) { + dev_err(this->dev, "Error in resume %d\n", ret); return ret; + } + + pinctrl_pm_select_default_state(dev); /* re-init the GPMI registers */ ret = gpmi_init(this); @@ -2849,18 +2845,29 @@ static int gpmi_pm_resume(struct device *dev) return 0; } -static int __maybe_unused gpmi_runtime_suspend(struct device *dev) +#define gpmi_enable_clk(x) __gpmi_enable_clk(x, true) +#define gpmi_disable_clk(x) __gpmi_enable_clk(x, false) + +static int gpmi_runtime_suspend(struct device *dev) { struct gpmi_nand_data *this = dev_get_drvdata(dev); - return __gpmi_enable_clk(this, false); + gpmi_disable_clk(this); + + return 0; } -static int __maybe_unused gpmi_runtime_resume(struct device *dev) +static int gpmi_runtime_resume(struct device *dev) { struct gpmi_nand_data *this = dev_get_drvdata(dev); + int ret; + + ret = gpmi_enable_clk(this); + if (ret) + return ret; + + return 0; - return __gpmi_enable_clk(this, true); } static const struct dev_pm_ops gpmi_pm_ops = {