Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1335530rwb; Sun, 14 Aug 2022 01:04:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR403pVMr6t5wnNtOh7z55WAfS9lWB5/GS5FEkkgnfujkn2k9VYItXRzx94Jpi6eA2d/L8qq X-Received: by 2002:a17:90a:f002:b0:1f3:251:c48 with SMTP id bt2-20020a17090af00200b001f302510c48mr21746741pjb.22.1660464282628; Sun, 14 Aug 2022 01:04:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1660464282; cv=pass; d=google.com; s=arc-20160816; b=lDE1qcZnIH40i9GTig1UhRsruzoLouAQSLl++X9wp0ht4xyetGMjY53fXDf6+axBN+ 1lXhKg3dLWDsopMDk2wYWp2ztfRXqGRTHKNiPuRaTYr6nKB/LwOxvv9kW4aKevDcAswD fowengfIHsdYj57b9q8EXl1t/aR0nUpDFQ1uu2j1uXcVRELkOB8kBwJ5Hugr9vbSuqI0 oY0O/O2uEszGMplh1kxYqRypdeSkm9I/4ApRh/IUEowGGl0Y+MveKa7Z85sfI2IDVf7T ZXKJQ/Z6H7VdrtLVLmftUx/sQ12RIGIN2fcztTA6mWsH9K2MRS1pxbDIOYdsjHB33gmf ZdPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lAxYOfz3sZc+r6ojdxKXSBJrhK0IXn6bj0q+c+eoq+I=; b=NhLyMjh6Brw1HoKh9Pha/j9jBwQvIPBjCztretYIM1EBD7UVo5+LMinJB0GbT34G45 sGlCnkQ6/qnQVpujQ+FNaiN8Z37+kPlE4cJACMODAngGgXUVfi3QcP11PNM7ViCK9YGs FLTY1WKv9ED6iFDZkspYB72wznRE8P9IY8CjkjIZiyxEkO2EE7XugW1aqDaO61Q0XNQ3 0B0fEY5p8BT0hjKp9JTIcWk+kzWGhXO2LtrLPep5oi/CeP5/38h2PNsLnmLkcAnLBtRe FRUrOAbnI6RE2RBXCW/yKjBiEK/ZtAt/W8ISpBf1B7Jn9qFVUFPH6zIRDx2VH/H2zLAh iI2A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=kE4OOZf9; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020aa78f29000000b00528c39ccb81si6894997pfr.277.2022.08.14.01.04.24; Sun, 14 Aug 2022 01:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=kE4OOZf9; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239574AbiHNHmP (ORCPT + 99 others); Sun, 14 Aug 2022 03:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230519AbiHNHmN (ORCPT ); Sun, 14 Aug 2022 03:42:13 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2060.outbound.protection.outlook.com [40.107.22.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B77FF1F2EA; Sun, 14 Aug 2022 00:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jd3hT+mFwsAdDwMwJmWYqVkxImaBsrH+43Ec9PF+rCZa09/n7tyWPPfR4EwTaKWItDRSE3tV83ehkOhhTArGyWKrmFt6RbjMh9XADh224/ij46fAd0RMCppz4UaNmVq9TABcrpxHIEeQCAARreB3TWuorIsprONXu6NpegiqIYxdDVUbUMsjuRHEeWiaZIErpFif/oglfva3pCK6A/vQFDieELhSlUj1yOFCFapi1KtDl2VUDzzc6PquvcbWNmRkLjZfZivxW2lWPvgWiD2uBuYl+dc6RHSyRuknmiCNXEkLZgtsMrlUnl9EzlHvSi43O4dlH9SrdmWFkZhI1LbN/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=lAxYOfz3sZc+r6ojdxKXSBJrhK0IXn6bj0q+c+eoq+I=; b=BC2TSYiODoOC+9JiEVuRYu0IC45LOCakXiUVdjnsGojUFNnn3BV+dS19UZrzGqIZ5TIxlSsWkOFrrix+eN5udmwuzOJJmigNGcPJHR1kO3zEOW2Y9/CPCAT/LkiU/JfSya3UVW5uDjTJvJsE2znhxBeANWW1VTDY8Sx/4y3IOPjNf8jZp6nOrxVTVa3DcrT8Jqpv8RrK5kTejwmZR9O/DNuy8xAyMLLEEfDtevyWLoCP2rxtRQ49LwBkZLOR/htaLRunKUWUwZYXstjHsnIkGkQXHPSaRbLhO7+mm+HyqMfOXSDjuY+PYPQzLLLDFHnfBLm57H9rgeNR5TGonmRCTw== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lAxYOfz3sZc+r6ojdxKXSBJrhK0IXn6bj0q+c+eoq+I=; b=kE4OOZf9qPZWb+uRD/PEzA+4BximkAIGI1165TXenNpluhid0DtwSUYLNXmH7jZLxyuyfFGSUQ/G/yTM+mpIRWByVFPYBEe3y3qq0iIjU6MnvSavTeUgCxvNzQ9L5xKES9imf6k/9+cIUpF+R8732BKWz7CRY5QxCsF3y+uZIBc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7046.eurprd04.prod.outlook.com (2603:10a6:20b:113::22) by VI1PR04MB4016.eurprd04.prod.outlook.com (2603:10a6:803:4a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Sun, 14 Aug 2022 07:42:09 +0000 Received: from AM7PR04MB7046.eurprd04.prod.outlook.com ([fe80::2549:869e:d80b:3a1b]) by AM7PR04MB7046.eurprd04.prod.outlook.com ([fe80::2549:869e:d80b:3a1b%6]) with mapi id 15.20.5504.027; Sun, 14 Aug 2022 07:42:09 +0000 From: Liu Ying To: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, saravanak@google.com, gregkh@linuxfoundation.org, geert+renesas@glider.be, krzysztof.kozlowski@linaro.org, robh@kernel.org Subject: [PATCH v4 1/2] drivers: bus: simple-pm-bus: Use clocks Date: Sun, 14 Aug 2022 15:43:37 +0800 Message-Id: <20220814074338.453608-2-victor.liu@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220814074338.453608-1-victor.liu@nxp.com> References: <20220814074338.453608-1-victor.liu@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2PR06CA0197.apcprd06.prod.outlook.com (2603:1096:4:1::29) To AM7PR04MB7046.eurprd04.prod.outlook.com (2603:10a6:20b:113::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ae50fe96-9fa2-4c8c-d91f-08da7dc87e4c X-MS-TrafficTypeDiagnostic: VI1PR04MB4016:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: un7011cOUPtux8mtFftZ4W/n/rIN9IiRvjhU/tWLJYtlJzwGK25+/kqV7d4GExv1JXQlJZeYy/RBkswggqICB8brz54F1dcccrD0YYmm8IHn0diD31I6UWjaBNaJIA8Jw4/718qamNtgK53up6Hfe8cSWCMMFifVeg85k3WxqG4DVdTJlaGaB+n3a+8M/w1ZhZ3wu+khxqkMrlKj3QSjCubzVZbVI8oXy2hGo3wOc4gmsKXh9zRCgArVJUBAKmtgjqkCphX8BH0RHaco2sXN9uObCapHNsCYJHNCVtI6belchP4POtnD7KBRN164UumdSYe3UDwWvj3eDGnP1inlCcqnr0LXMFohsKNrrVR1LFP3mUbuLURAH/cit6+bskAvPS6fXuriv0dV5JGOOBU7YHfBXOtOC+cfZND0/oP6IrdbMNib7qLNcrqeBsU96fGh6PwiPzJ5Aj4lzrSdVZwEOygCYoD0aI5iEMMkCfV0siMMQseGwi0zW5zGCWbzcRi5yq2LKEd5QeoCI3/voDWsNL2+TryI/ViMcPoahiC1/y2JQlb75MSNC0K+M1VNCMFJlafX+AYXtaeem+qLLnb9EZxbUQFnvIEAb8avslxkZ2XxTzFeQRn7HK+Jqz8uvsurJp/7CXfwioj56AMTxJatmmfT6ol8mTNgTTk5RDW7ghryG0jkrUkGvMRSeNCkXnNJL9U1vjEWNQ4GVI/0SEOaY3yzGlEi/tIg/vqjqjuDnLMat3ET4GGsnDQmIJfy/aJiSGcPm8Tmi5KkYvp7/19msqu7QBJdaU2rW7wJoEWL1VBN5+Hkph1zAdJTlsfh2SOR X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7046.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(39850400004)(396003)(346002)(136003)(376002)(366004)(36756003)(86362001)(26005)(6666004)(83380400001)(6506007)(6512007)(2616005)(1076003)(52116002)(186003)(6486002)(38350700002)(4326008)(41300700001)(316002)(478600001)(66946007)(5660300002)(8676002)(66556008)(8936002)(7416002)(38100700002)(66476007)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Nf+pk8mmTczOmjWd02Lzg2brsk5ISgvmELy3xZ3y6WA7g+11ZCd8HMsWYG1Z?= =?us-ascii?Q?KaUo9/pS8LNcvixiEtnXX1XfymBEWUdQA0QmsSr9g4gUiHElAsDNZbgE3BnZ?= =?us-ascii?Q?qeudj+8sKid6o66LFV6+2XjY88jtXITh/stc7g7760npwHZGhbAov9VaU8CH?= =?us-ascii?Q?nJytfyaKqP1PsblJHZcGjZJRsll0Vm50Q8eAhPO7wC2mEArEvKs6rPOtH2tN?= =?us-ascii?Q?2KZ3jnRLkwkKQcwzIe5j+Ylx/fmLx3KqWYdQ8JLyRREY+04eHVbm80F69TG7?= =?us-ascii?Q?9vn8i/fjyHfEQzorOrhU5kzy8pc3YlHV/777e1N/NYl49re9WlVRohBsjIIQ?= =?us-ascii?Q?dxeWf9V59eVZEtLKDW9ZcrzjmdExX3W3aJvGA8w+hWy0Wl+2AXffx1apsWZL?= =?us-ascii?Q?b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/POn?= =?us-ascii?Q?p6OKjoghm3znQa4YTH3eIhxLjZ4yxrn8ILsYC0JqkXsiQ9fMb70vUBIlt8a3?= =?us-ascii?Q?qHlo428CJi0zLGvSYzX7YozOH1iL+b0G42FSQIDcSBP9uKuUGf4CzHNMQQE+?= =?us-ascii?Q?SvArs7cF/iP1cis/igT9bYcDs4PlFzy9J0RypHB0WwN7vVsTQsRm2zrsXdhW?= =?us-ascii?Q?pr9fEsQZOnei7Utveqhm7W7X90p3Szwa3hARCXiorNwIb+jkyu2B8SEKphvB?= =?us-ascii?Q?+b1goSCMk83qPtyVb16wZs6i8OHRcKp2cIVlj6JS?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae50fe96-9fa2-4c8c-d91f-08da7dc87e4c X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7046.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2022 07:42:09.4756 (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: j1VbPwK4oLXLo7hHNT9KYPuo3rJJBZI3hFV4h6GMHHCxzasC1CypGsZ8lqD6pSdlHG5+1qpGdm2ZeS9zbn/Vqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4016 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simple Power-Managed bus controller may need functional clock(s) to be enabled before child devices connected to the bus can be accessed. Get the clock(s) as a bulk and enable/disable the clock(s) when the bus is being power managed. One example is that Freescale i.MX8qxp pixel link MSI bus controller needs MSI clock and AHB clock to be enabled before accessing child devices. Reviewed-by: Geert Uytterhoeven Signed-off-by: Liu Ying --- v3->v4: * Drop unnecessary 'bus == NULL' check from simple_pm_bus_runtime_{suspend,resume}. (Geert) * Add Geert's R-b tag. v1->v3: * No change. drivers/bus/simple-pm-bus.c | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/bus/simple-pm-bus.c b/drivers/bus/simple-pm-bus.c index 6b8d6257ed8a..d7b043fefde9 100644 --- a/drivers/bus/simple-pm-bus.c +++ b/drivers/bus/simple-pm-bus.c @@ -8,17 +8,24 @@ * for more details. */ +#include #include #include #include #include +struct simple_pm_bus { + struct clk_bulk_data *clks; + int num_clks; +}; + static int simple_pm_bus_probe(struct platform_device *pdev) { const struct device *dev = &pdev->dev; const struct of_dev_auxdata *lookup = dev_get_platdata(dev); struct device_node *np = dev->of_node; const struct of_device_id *match; + struct simple_pm_bus *bus; /* * Allow user to use driver_override to bind this driver to a @@ -44,6 +51,16 @@ static int simple_pm_bus_probe(struct platform_device *pdev) return -ENODEV; } + bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); + if (!bus) + return -ENOMEM; + + bus->num_clks = devm_clk_bulk_get_all(&pdev->dev, &bus->clks); + if (bus->num_clks < 0) + return dev_err_probe(&pdev->dev, bus->num_clks, "failed to get clocks\n"); + + dev_set_drvdata(&pdev->dev, bus); + dev_dbg(&pdev->dev, "%s\n", __func__); pm_runtime_enable(&pdev->dev); @@ -67,6 +84,36 @@ static int simple_pm_bus_remove(struct platform_device *pdev) return 0; } +static int simple_pm_bus_runtime_suspend(struct device *dev) +{ + struct simple_pm_bus *bus = dev_get_drvdata(dev); + + clk_bulk_disable_unprepare(bus->num_clks, bus->clks); + + return 0; +} + +static int simple_pm_bus_runtime_resume(struct device *dev) +{ + struct simple_pm_bus *bus = dev_get_drvdata(dev); + int ret; + + ret = clk_bulk_prepare_enable(bus->num_clks, bus->clks); + if (ret) { + dev_err(dev, "failed to enable clocks: %d\n", ret); + return ret; + } + + return 0; +} + +static const struct dev_pm_ops simple_pm_bus_pm_ops = { + SET_RUNTIME_PM_OPS(simple_pm_bus_runtime_suspend, + simple_pm_bus_runtime_resume, NULL) + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) +}; + #define ONLY_BUS ((void *) 1) /* Match if the device is only a bus. */ static const struct of_device_id simple_pm_bus_of_match[] = { @@ -85,6 +132,7 @@ static struct platform_driver simple_pm_bus_driver = { .driver = { .name = "simple-pm-bus", .of_match_table = simple_pm_bus_of_match, + .pm = &simple_pm_bus_pm_ops, }, }; -- 2.37.1