From patchwork Sun Aug 14 07:43:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Ying X-Patchwork-Id: 12942870 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4B0F5C25B0E for ; Sun, 14 Aug 2022 07:43:39 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=vasxPEsWvEMukmMtX8Zqdy33CFPWjLL6ZB3tLjRNQWU=; b=GGU61OLc5jJs9Q fGkpgvAupcdBhTnfFzBtW9vmJ3GCPPKKsQwyK5EFwPpd4NmYB9fcdzJR1BQYFKrexEimVxkUuMbHk z9hKJgAQR1TIssfMj8MZRB5sxUDAWLUovKC0gY1EcWLsElx0hYXvrZsI5+2nxb2kBAiOvFKrYEnsk F4xCI16NKPs7H3yWqp62oX+/m5OC9WzDnlwXiTO7mTfPkMkB0Iad2C9kFfb7Ei3w4AaxhPEYh4MIv /q6m0D6lTnW6pvVNJyW9huqEGToB7JGWhU0Zcl9FNSPhiXVvjV3jjAhjiHMiUX3vXtxiR759i+INF l0wMam6MnK7Vvtt/JabA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oN8GP-004Sin-4a; Sun, 14 Aug 2022 07:42:25 +0000 Received: from mail-am6eur05on2053.outbound.protection.outlook.com ([40.107.22.53] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oN8GE-004SZn-GL for linux-arm-kernel@lists.infradead.org; Sun, 14 Aug 2022 07:42:15 +0000 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> 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: Nf+pk8mmTczOmjWd02Lzg2brsk5ISgvmELy3xZ3y6WA7g+11ZCd8HMsWYG1ZKaUo9/pS8LNcvixiEtnXX1XfymBEWUdQA0QmsSr9g4gUiHElAsDNZbgE3BnZqeudj+8sKid6o66LFV6+2XjY88jtXITh/stc7g7760npwHZGhbAov9VaU8CHnJytfyaKqP1PsblJHZcGjZJRsll0Vm50Q8eAhPO7wC2mEArEvKs6rPOtH2tN2KZ3jnRLkwkKQcwzIe5j+Ylx/fmLx3KqWYdQ8JLyRREY+04eHVbm80F69TG79vn8i/fjyHfEQzorOrhU5kzy8pc3YlHV/777e1N/NYl49re9WlVRohBsjIIQdxeWf9V59eVZEtLKDW9ZcrzjmdExX3W3aJvGA8w+hWy0Wl+2AXffx1apsWZLbpvSn+MUHLteab4afYTS9mUdb1ny2EpN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wIb+jkyu2B8SEKphvB+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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220814_004214_566454_607443A1 X-CRM114-Status: GOOD ( 18.39 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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, }, };