From patchwork Wed Aug 29 12:51:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 10580305 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BFFA14BD for ; Wed, 29 Aug 2018 12:55:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D1CF28737 for ; Wed, 29 Aug 2018 12:55:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00D112B03F; Wed, 29 Aug 2018 12:55:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5640A28737 for ; Wed, 29 Aug 2018 12:55:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727651AbeH2QwQ (ORCPT ); Wed, 29 Aug 2018 12:52:16 -0400 Received: from mail-eopbgr80074.outbound.protection.outlook.com ([40.107.8.74]:31904 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728483AbeH2QwP (ORCPT ); Wed, 29 Aug 2018 12:52:15 -0400 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=Rw9+YfSA6MDu1qVOhtAIGv4iDtfo3XsUT5Y+EGVeicw=; b=TmIPBc2bPoHKbcoy6sJmZHOQDu84A3VaetRQbAlH0JrnXHrBsyv6F+ryfW9HinupzgnG9W7H/cPPdnDdi8frCkEL+UtbeaYsr4pWqnt+1F9pHnNIpXKeLBs172zJplXFk1TtWP/YHce6SCHIlSkzr7nfVaic3Rza6mTkVInLPHM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aisheng.dong@nxp.com; Received: from b29396-OptiPlex-7040.ap.freescale.net (119.31.174.66) by AM0PR04MB4211.eurprd04.prod.outlook.com (2603:10a6:208:66::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.17; Wed, 29 Aug 2018 12:55:18 +0000 From: Dong Aisheng To: linux-clk@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, sboyd@kernel.org, mturquette@baylibre.com, shawnguo@kernel.org, thor.thayer@linux.intel.com, linux-imx@nxp.com, Dong Aisheng , Stephen Boyd , Masahiro Yamada Subject: [PATCH V4 2/4] clk: add new APIs to operate on all available clocks Date: Wed, 29 Aug 2018 20:51:38 +0800 Message-Id: <1535547100-25634-3-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535547100-25634-1-git-send-email-aisheng.dong@nxp.com> References: <1535547100-25634-1-git-send-email-aisheng.dong@nxp.com> MIME-Version: 1.0 X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: HK0PR04CA0003.apcprd04.prod.outlook.com (2603:1096:203:36::15) To AM0PR04MB4211.eurprd04.prod.outlook.com (2603:10a6:208:66::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab10b721-72c6-4342-a1e8-08d60daeaed1 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM0PR04MB4211; X-Microsoft-Exchange-Diagnostics: 1;AM0PR04MB4211;3:2LgdQXUXe5shLAuLu7mbjH5IZGkvNAjG7ZWHsxfsY3twE9mb9Q4hlcY9fbqLJ+UY9uMZZgFADgAFQccnbImpA2YAF9eOyvmml2OQL75yANZA6OnI6DtXqeyJQfCPxXqLdBHSTfPFz6iCt6xy6H1HuJLoOgIulMPKhu+IyR7WPhdlAxO2U+7/rQWNSugzF1rnoZ1nzD9iEru0QOKkDKgRpfM4ejxXMT8vG9Up/U2UxRnM3lalYWal+ThgUIAHRdfw;25:r9+SWCQccEPH9S9akoIh4meunP2p4pHJTOGyllvqY92GlsBC1YEaCb/E5eJ/Bs5vWr7Pe2ezkwENQEXDFSFz6NcqnsTYgdpFgt2L5WRTCAsv4rS/pRGBI8RaxVb7UskG/ZAuUyrZ//AE0m/9NSR5EWtI2Jx8rdDdnNMWD9q862nMAEM8b6RpVTp9TRyCJwQcrKN5+zm30ck7scdn+gHjD1j6T47ZeB7KxvFZYemvqxyHhx3lAZ0KJRryKQrBtQY9QSTKwMTIaOKA+nqf+zwMyQ4kPErDBXr8Njc8r6P7d6KfzFTYf3lGbvlZkH0JzkKq8uLlZtjLBxBl2Xmo7UXgqQ==;31:Xy2UsvEgiXXGDnLpe7/N3RsTew3NyHd6/ThMyHS+TTY2DbrnK7x344l4mtWLi19XBYyNMypnsN4YYnoIC0q/W7XoVcVmUAc1EHCEblBi13TbTWpGGDYzESwumE8957SNJwiFYTLunlEiBMaMyEDW2TXtCR6Jo4hY2mv+QlmL92mvjmo0yQ2O72mKelhm1NaM15gmBFPbyBpNL1CjTq/jPK2ff1xCddqkcVqABqUzHH8= X-MS-TrafficTypeDiagnostic: AM0PR04MB4211: X-Microsoft-Exchange-Diagnostics: 1;AM0PR04MB4211;20:jCb/4hI+V44j0iPd3q4HMKHOu6zb0Ymk7Abi6nv8be/PL7ellkHY33+yI2HSGxImN9FLKS9N6YIBBXzCz4Vhe7uli4DlnwQISDz9eWcTuX2+bcTiJxZWZPs7vuqQV0aptezN3l2r+hf4YfLwbvFR6BrYcLs8KlU1mhsYLgM7WGl9AQm7ddyNtMYgyhKQ60MuWChQo1AOrZXar2u01HSUUo33TLoqWC7tCIaKq9QI0bFGX87MGTFdO8n7DHwIyM3nZLOPkQBiLjamqIBM3T4Yrt0V16wG85Fz5cBmMboE4SKEe7k+7cqUhZx5Gv5dTSBzx1S5yvDdDZxJ9N2JAc+AckRv+wN+jbsvXKoEonosFs/RB5QG1MN4zIr76/iojeD9w8/rEMHgn0bZvkNd7gjBpMBPgA0dDq/zx8iy3hHzXprrbbU4z3mvRvxgc/GngWwulchLIqvP+pdOFqVu5gAOtP2sp7Rs06q5Ke/F5Fjlc6ao5CwM7+STwlzEj+PV654T;4:9FrIO+s26S/nCvJ/BCEPLxUn4CAoHVkOw5YzYipEN8q/9X9Dx5rx/bE+BrKllkge0wokJibKvI83URGQcFAHBCrazusQQbtBTWl2RuuIG80evPKxu/zItzJax2WrGO8Q6F9FLKdf9QP+1zZeRYgw28KjqBsPCsl3FTC7sLlSnuvMhV0noPp6dDNJDFRDkNI/RzfFoMUq0p3TtvJ51ObKAZ/IXkNhgosozdtGsgMKmXPuSNFi2kE3cQ4ii/QaALdOyvmjI+Jh1RUi0bpTlNsc9gldeD0YR8gZjUZdWlX8NzhYjDvVPoP32y3jrj9Rz8somZKJKmGQs/kOvgZb118/x3oFvFd298KbCTCT04UB4i8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(228905959029699); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823301075)(3231311)(944501410)(52105095)(10201501046)(93006095)(93001095)(3002001)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(201708071742011)(7699016);SRVR:AM0PR04MB4211;BCL:0;PCL:0;RULEID:;SRVR:AM0PR04MB4211; X-Forefront-PRVS: 077929D941 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(396003)(366004)(376002)(346002)(39860400002)(136003)(189003)(199004)(51416003)(50226002)(3846002)(6116002)(68736007)(2361001)(8676002)(50466002)(48376002)(2351001)(2906002)(97736004)(106356001)(105586002)(36756003)(8936002)(7736002)(305945005)(53936002)(6512007)(386003)(47776003)(81166006)(6506007)(14444005)(6916009)(2616005)(4326008)(26005)(446003)(16526019)(66066001)(25786009)(956004)(81156014)(476003)(86362001)(186003)(76176011)(486006)(5660300001)(16586007)(316002)(478600001)(52116002)(54906003)(6486002)(11346002)(6666003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB4211;H:b29396-OptiPlex-7040.ap.freescale.net;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;AM0PR04MB4211;23:WwbTkwrYDXLBOknbnhwprHj3BC/I1YOisZ5g1YFLMXO3wE0TTZJDUCzOSjMAI2tPmyLAdTW5igzInK9i0CrzOVfIyuftIdcKEjwiXfwhzyIMsypXc+pnEb0cSBoQdDrDks6NFAUWACqQIvSHMe1tsPcSkHwm83ohu+a4efG9q0SrfsXnlXyNyH05pHsd+JLJW57xSNFIjAycNjSVklHZRRvvgWXPcKLsS8JACd4MjmYBQ08Dq3elRtkC7Geoh/iE18JDu/Y5EfaULuJekzvoGu5eukpCfhZM7QUnwOISYw68Wbol+YRvGB8QIrAzE400TKQLsEiS6ClVC32+ssCGcRW8V0RlvsNZOQK3zZlMb/4O+pofA0PGMKAX4cdIL4HLFtiTU5ZldyxBB3XLjpqwV3NJ3bRplRnmXmrDEJocVKoHPR5ysyfJccE/e9dsiXC18tgTWflJ2cjBsHk73QaXGU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: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2018 12:55:18.9198 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab10b721-72c6-4342-a1e8-08d60daeaed1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4211 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces of_clk_bulk_get_all and clk_bulk_x_all APIs to users who just want to handle all available clocks from device tree without need to know the detailed clock information likes clock numbers and names. This is useful in writing some generic drivers to handle clock part. Cc: Stephen Boyd Cc: Masahiro Yamada Tested-by: Thor Thayer Signed-off-by: Dong Aisheng --- v3->v4: * no changes v2->v3: * remove #if define condition * use kmalloc_array v1->v2: * make of_clk_bulk_get_all private * add clk_bulk_get/put_all --- drivers/clk/clk-bulk.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 42 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-bulk.c b/drivers/clk/clk-bulk.c index 4460ac5..6a7118d 100644 --- a/drivers/clk/clk-bulk.c +++ b/drivers/clk/clk-bulk.c @@ -17,9 +17,11 @@ */ #include +#include #include #include #include +#include static int __must_check of_clk_bulk_get(struct device_node *np, int num_clks, struct clk_bulk_data *clks) @@ -49,6 +51,32 @@ static int __must_check of_clk_bulk_get(struct device_node *np, int num_clks, return ret; } +static int __must_check of_clk_bulk_get_all(struct device_node *np, + struct clk_bulk_data **clks) +{ + struct clk_bulk_data *clk_bulk; + int num_clks; + int ret; + + num_clks = of_clk_get_parent_count(np); + if (!num_clks) + return 0; + + clk_bulk = kmalloc_array(num_clks, sizeof(*clk_bulk), GFP_KERNEL); + if (!clk_bulk) + return -ENOMEM; + + ret = of_clk_bulk_get(np, num_clks, clk_bulk); + if (ret) { + kfree(clk_bulk); + return ret; + } + + *clks = clk_bulk; + + return num_clks; +} + void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) { while (--num_clks >= 0) { @@ -88,6 +116,29 @@ int __must_check clk_bulk_get(struct device *dev, int num_clks, } EXPORT_SYMBOL(clk_bulk_get); +void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) +{ + if (IS_ERR_OR_NULL(clks)) + return; + + clk_bulk_put(num_clks, clks); + + kfree(clks); +} +EXPORT_SYMBOL(clk_bulk_put_all); + +int __must_check clk_bulk_get_all(struct device *dev, + struct clk_bulk_data **clks) +{ + struct device_node *np = dev_of_node(dev); + + if (!np) + return 0; + + return of_clk_bulk_get_all(np, clks); +} +EXPORT_SYMBOL(clk_bulk_get_all); + #ifdef CONFIG_HAVE_CLK_PREPARE /** diff --git a/include/linux/clk.h b/include/linux/clk.h index 4f750c4..e9433c7 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -312,7 +312,26 @@ struct clk *clk_get(struct device *dev, const char *id); */ int __must_check clk_bulk_get(struct device *dev, int num_clks, struct clk_bulk_data *clks); - +/** + * clk_bulk_get_all - lookup and obtain all available references to clock + * producer. + * @dev: device for clock "consumer" + * @clks: pointer to the clk_bulk_data table of consumer + * + * This helper function allows drivers to get all clk consumers in one + * operation. If any of the clk cannot be acquired then any clks + * that were obtained will be freed before returning to the caller. + * + * Returns a positive value for the number of clocks obtained while the + * clock references are stored in the clk_bulk_data table in @clks field. + * Returns 0 if there're none and a negative value if something failed. + * + * Drivers must assume that the clock source is not enabled. + * + * clk_bulk_get should not be called from within interrupt context. + */ +int __must_check clk_bulk_get_all(struct device *dev, + struct clk_bulk_data **clks); /** * devm_clk_bulk_get - managed get multiple clk consumers * @dev: device for clock "consumer" @@ -488,6 +507,19 @@ void clk_put(struct clk *clk); void clk_bulk_put(int num_clks, struct clk_bulk_data *clks); /** + * clk_bulk_put_all - "free" all the clock source + * @num_clks: the number of clk_bulk_data + * @clks: the clk_bulk_data table of consumer + * + * Note: drivers must ensure that all clk_bulk_enable calls made on this + * clock source are balanced by clk_bulk_disable calls prior to calling + * this function. + * + * clk_bulk_put_all should not be called from within interrupt context. + */ +void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks); + +/** * devm_clk_put - "free" a managed clock source * @dev: device used to acquire the clock * @clk: clock source acquired with devm_clk_get() @@ -642,6 +674,12 @@ static inline int __must_check clk_bulk_get(struct device *dev, int num_clks, return 0; } +static inline int __must_check clk_bulk_get_all(struct device *dev, + struct clk_bulk_data **clks) +{ + return 0; +} + static inline struct clk *devm_clk_get(struct device *dev, const char *id) { return NULL; @@ -663,6 +701,8 @@ static inline void clk_put(struct clk *clk) {} static inline void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) {} +static inline void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks) {} + static inline void devm_clk_put(struct device *dev, struct clk *clk) {}