From patchwork Mon Aug 22 06:03:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ying Liu X-Patchwork-Id: 12950202 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 B33B9C28D13 for ; Mon, 22 Aug 2022 06:03:29 +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=DRnJaXqYllX4+4 Z0ZkLEN+2dYl3H7rzeegiNeRavfV5o5XSqmiQWJEYyoeIPcDyvq8l5ocGt05YJk7pHYlDT+sxjsaZ ocC1VBhA1FPzZ6NG0E8jDqLxT0TEzO9qO9kaemLmTDVwiEn6M5G/ADArrc0ayA1xuqNgGoWlbjCUF F8ajT0q9HoOmXqm7WWGcoPFA9uo5f5C42vYe0yK7LpmyWrLXNuC2AjpN9kKnQHrmLRrCeavGWBuFd oWQM6tAx4aG0dX3hadSG4HdFxXxghjp40/MbUSf3aL4nor/CIXD/6UT+/2dEQChRZtGAkAByg5PBH ntQK96sPg3K22DM3PX7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQ0Vy-005GeK-Pu; Mon, 22 Aug 2022 06:02:22 +0000 Received: from mail-am7eur03on2087.outbound.protection.outlook.com ([40.107.105.87] helo=EUR03-AM7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQ0Vj-005GVn-El for linux-arm-kernel@lists.infradead.org; Mon, 22 Aug 2022 06:02:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Whdgn5CG25N0VQ4CUcxYuJyCq9iE/0Mfg8GF8PJlk8ewxjrhf77OSOJ/cl9PmYE+lvcO6f0fLowrZ+jMwwwjTODf0psdMRMcofO9ohYnSRr5LpWknxR8DT0Y9XEQlnIehSWhzr+Jcx/HP5oymhTINDs3Kegl62G86PmKB5TLw47mh4MsmF6kAY08yDKsittkas/hP8f7ZLbME8bvLikoGRdRTpSfaUv0g6JR2KiCux8naO8bN36v90Fo80g56XSeOEOGjs4Hf+Wc8hr4ruEOmlBrJTBLn8bNebHyjC12MLv3BrHWqTIQSd6aBif4QTFUT7MkeFzEOznIZ8SBnpVPpQ== 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=nNABbCiEb0cttG/H2Uh06ht+hPInjwHX6hHzpn/NTZqoVGeML6ZImInA84k/FC7wMLs1PjGa47i7Ew5Sccz+BD1KSE8vEzj8nmJf2Xs3XFsHgP5Z+cjfZ7lmrguC+0iDsWCP+S4KM0TY1ZAabJfYJZ9qNiJLJJL0uzdPIOzfhliHBtdbggUScr9RzE0ePohmtiTxz4rc8uDvEzuGE8p2yftxvt++DAbD3bsrSOzdnDqwcerfiQR6LISdO71wXkqKuqVnSDHnJFCfCtMAU+jkWq7BaZ8m8M3T9louPObuQs8D3fbIyOaPnDA9Ha0Vdc/Q08B4g08oewAmc+BCCNpfOg== 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=XTZOzy33Lbz2JOvmKsRPhXSiBNroI+NI6Ymx9jE7WoD2Tpt8ohOYEul1+E3EajkMeskBVQhVXX042Czp/vJlrmZIcxIlnemca1QVjLPg6gUubCIOX8Em26DyWXqB0Aa/cxUqflvYY+H55UPIaMrocA/2ud6ybR6ifNdwQED4+P0= 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 DB7PR04MB4604.eurprd04.prod.outlook.com (2603:10a6:5:35::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.22; Mon, 22 Aug 2022 06:02:03 +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; Mon, 22 Aug 2022 06:02:03 +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 RESEND v4 1/2] drivers: bus: simple-pm-bus: Use clocks Date: Mon, 22 Aug 2022 14:03:22 +0800 Message-Id: <20220822060323.3481384-2-victor.liu@nxp.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220822060323.3481384-1-victor.liu@nxp.com> References: <20220822060323.3481384-1-victor.liu@nxp.com> X-ClientProxiedBy: SG2PR06CA0224.apcprd06.prod.outlook.com (2603:1096:4:68::32) 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: abfe2cd4-7d7b-49e5-250b-08da8403d5d9 X-MS-TrafficTypeDiagnostic: DB7PR04MB4604:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DWxkYL5N/2rQvjN3dXwsbfF2CrxTe3nrjujZS1G8It+OafXHGv69b1d5jpV/nb5j2uazzzwMJbJ9okkWlaytxzE0rLJqmZd5swiY/H9Q6UACLfUempxo+U1dRQ09u2QlSPJVsrVxqy9/PRcfmBnuAS6fz0qeJT1zhMhCXH9Y0TbdJ6eYeBCfAe/nbZcLlOwCQdqu/uGI/kfpmXl+ZuvVJOvagUZUwRR4Vx32vWFkIijy+8WxX1N8RUtifOxFBIsQMOHIfF2n1Gq/GXMecp7VSmHIDHxrwRzHbQHDTpeJo7Iv4Sfyzpz3Wc3yJiosUnkyMqfyp7ss16MyIGLCRMFV/0LqHQ2YRpD2EGH0UlnzSCGSoxNcYZ/i7sQGR2HKq0tp9lp7iCETPkgjQupa04gXA/V60VFybTussBZFqXwOQIDgZariqFjAbWRvEVwx8eKhulTqdXNZ681KINZiCRSyzr2nUMur0Yx7aPQJJKHnKJ97u9u4jogNgXLh2l7LK8JX/iCtVZbrDcuP4Pbq3lzlqueC9u1v3dsv/6sZt6kyLfpQdKa8L8VE7M0XRJ46EmLcOSBXQ0CWmqVd9hNkcvA68zKySBrJzrF9jsFjn+y5DvfsCRTnbescdWk2LrGh1nQA7sn1eVbWVf/ug7c7axTD6zQIega4TbAn+5uhdsuPW9ZkH9EbQthfSLaEPqH4f78QpQN40SZXdIvDqo7kHLFdGOgy0Ao+pPvAijAb2OhPIljlwmTfDR/vHlAwV2OMJFjMLWDtt5hMxIZPpOp68mXbfg== 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)(366004)(39860400002)(376002)(136003)(396003)(346002)(86362001)(83380400001)(38100700002)(38350700002)(316002)(8936002)(66556008)(5660300002)(7416002)(66946007)(66476007)(8676002)(2906002)(4326008)(1076003)(2616005)(186003)(41300700001)(478600001)(6486002)(52116002)(6506007)(6512007)(26005)(6666004)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iKIOIiWACpzUG09mPPXQQ3UyD7RXidpIDhTCOt/nSwYI9DbXoo+QcEf63Lvc4DT9LN3Dgy7PI0XdhBcny50cg9ngoZqRclMKcbSer/KQja3RDpE9z71eR8UVvgbmNgmnDXy2j3dIPQaAEL9ZhfqwWS63Fq77/bPftmHddv8+rW1+iiBlLROHKNBo+PNBwRedKWWYLdu0X0hVhE63CTYISZs2Bl5l97kZ2Ljf0RPOY5ebaLR6mdz/1LQGUsnIv9nWIqDX0xlzHq4INyPIId0TgS2XqCQELTWaYdbEhRAlo+Mgp/xJTDVTlp2vZLbdsBpqg4gdJXl3hlcVOplthwx4mGNj63bzCeDuL3Ey1T8GD5cizS6CoWLmWYpwKD+ZUPvQy7OaJAv0UNYfGjUl8ryFJNxNjkQKDvv3QC2U493IgtUYGTLigGDNWC1bR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sw4JUcEXHy3KlQLmHujebxicL8H46JUXTfbo/RLV/V+uFbDo94YTbKJV4i6MEnfw4aWLDi+M6ZZQmWyS9W7nNCkfhenqmi X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: abfe2cd4-7d7b-49e5-250b-08da8403d5d9 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7046.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 06:02:03.6392 (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: J7QIRSFBRNG+TMWo3Glhy2l2oSbpy7TIoNB7210tRGryuUmyIqoyFoibtkKUDLz9fmS9MEVbkI3nGmkh8mNrPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4604 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220821_230207_568907_C5E27315 X-CRM114-Status: GOOD ( 19.44 ) 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, }, };