From patchwork Mon Dec 5 05:23:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 9460287 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3D06560236 for ; Mon, 5 Dec 2016 05:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30A111FEC1 for ; Mon, 5 Dec 2016 05:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21BAB2621D; Mon, 5 Dec 2016 05:23:58 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 6FFA21FEC1 for ; Mon, 5 Dec 2016 05:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750772AbcLEFX4 (ORCPT ); Mon, 5 Dec 2016 00:23:56 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:29956 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750752AbcLEFXz (ORCPT ); Mon, 5 Dec 2016 00:23:55 -0500 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie1.idc.renesas.com with ESMTP; 05 Dec 2016 14:23:23 +0900 Received: from relmlac1.idc.renesas.com (relmlac1.idc.renesas.com [10.200.69.21]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id 19B72500F4; Mon, 5 Dec 2016 14:23:23 +0900 (JST) Received: by relmlac1.idc.renesas.com (Postfix, from userid 0) id 0B5DA80030; Mon, 5 Dec 2016 14:23:23 +0900 (JST) Received: from relmlac1.idc.renesas.com (localhost [127.0.0.1]) by relmlac1.idc.renesas.com (Postfix) with ESMTP id 05C088002F; Mon, 5 Dec 2016 14:23:23 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac1.idc.renesas.com with ESMTP id QAQ12669; Mon, 5 Dec 2016 14:23:22 +0900 X-IronPort-AV: E=Sophos;i="5.33,302,1477926000"; d="scan'208";a="227061702" Received: from mail-hk2apc01lp0209.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.209]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 05 Dec 2016 14:23:21 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=GhAYBxBq2N8MBBpy1RhvgeL4OITgMbWdSilgG1cxoO0=; b=pEYLSuJVJZ1UiuEs0TU+mhP7TdOyFaIM4WTtBHQJVhiALqG7oZBhYNxl8JeSCg5Yzxv2d4yeCPSOXdHN2xqqBa9PLoB7s2GxqmKs1v5OpFciBlIkHZEAcq2A2g/5nqLGgnekc/wkiVs7MAcVgQTUl5rsbKg36cRpBzemzrBxfuA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=kuninori.morimoto.gx@renesas.com; Received: from morimoto-PC.renesas.com (211.11.155.144) by HK2PR0601MB1441.apcprd06.prod.outlook.com (10.165.182.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Mon, 5 Dec 2016 05:23:20 +0000 Message-ID: <8737i3vtl7.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 1/3] clkdev: add devm_get_clk_from_child() User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 To: Russell King - ARM Linux , Stephen Boyd , Rob Herring , Linux-ALSA , Linux-DT , Michael Turquette , Linux-Kernel , Mark Brown , , Linux-ARM In-Reply-To: <874m2jvtmw.wl%kuninori.morimoto.gx@renesas.com> References: <874m2jvtmw.wl%kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Mon, 5 Dec 2016 05:23:20 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TYXPR0101CA0013.jpnprd01.prod.outlook.com (10.168.40.151) To HK2PR0601MB1441.apcprd06.prod.outlook.com (10.165.182.147) X-MS-Office365-Filtering-Correlation-Id: 91714182-5e79-49be-1e06-08d41cced3d5 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:HK2PR0601MB1441; X-Microsoft-Exchange-Diagnostics: 1; HK2PR0601MB1441; 3:aiufhqe7BPh82ZK8YXbABU2COC+/08R3HTcFealqy/eadG/oHIWwKIws+LUKQQeaoNPAnfTfnTb2Vuflf1cneqIOBTbnmHmmn8aPQ/bvXYt7H4us7H0nY+jAh1eoVGjHLH/2tEtsEmX0T6ockDHOVq8+kWf8YWIPrj+KVuiEivoa1uyRj407F+UOtInpEtaHZm2t+zO59l3i4FUT8P4z6sNbLJJWuk11kGl44rVbZoSnE91yJhtbIwxveYCJF3shu1PxBgnoywedr/8lwFJd1w==; 25:RRw0SCAQNmmYI7rJTAEzC2CKqwZ4mqokKzFmIoDiWgMVZWm64KnMGfXIEDxXqssKx0aUib5GK3YNj4sJCWZjvOYPOGwO63AIq+++/8dSTj3jP7D+EQ6PX1SLZDpGErKoxR92PnLCV760J1xvWiaXwPJbsQo3/GcWrj9+EvkwDCeEYtA5cA0KloeTsUKt8IUNMoThl0Cdb73tGoclTw9geMhgFunosUSR5bQuSEo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PNJhxucPy X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123562025)(20161123564025)(20161123555025)(6072148); SRVR:HK2PR0601MB1441; BCL:0; PCL:0; RULEID:; SRVR:HK2PR0601MB1441; X-Microsoft-Exchange-Diagnostics: 1; HK2PR0601MB1441; 4:75UZWqQHtDRYOK8AGHfmbfQtP5Ea4qO5mhD5BtzC6D3Tpu/koNMczzo2raL4vcnbIc5PGwXNSoIYhUpFX1in6wDBTQzPXV00SFhx8nH8U1xz1ARRLoIPyyRHso2BmTtvRSzl2Ci73ewajVB4hTiQpkmNp4EGMYT3gVGZVebx4Qoh+r4MjjBKE4cFdmzfze2Xw6LQ4on1/ZHyLapP0bWrpJ2ZpIw+OEkKehrx8hix+zQNztqyX6OrAH41o8w4V55ecrSdKMqkxGVlxHawk/5SnossZfV1W2wtguLfXWlUnEBD/VaXskassW9zGMFMIZRgh1M+Z9lGU/PV0ttsGRfpsyG76gFJkTEWZmed3Uha54TMLDZL/q3dERoe0OUkP+3ahWePdbcbNDBDjTo/vxUz2/AKIIwe2FFdSf2scKzmERa84jA/nhm2IRBaD/BJ0o9sVludIEtRJanaU4C4G37omcEx8ANGZI+w0x3ROS8ZjniiRCmkZCSuQyS/mzUnFiMAPr1avxM+IJdP0qFkDaSeGfwZLN7pZ6Qbv1MQfejH5hVn5kBL9RzsdhIYf2yiNiYxnJFmPeyHlizxM5a2B5dT9Q== X-Forefront-PRVS: 0147E151B5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(107886002)(83506001)(92566002)(38730400001)(50986999)(39410400001)(69596002)(81166006)(105586002)(81156014)(54356999)(76176999)(3846002)(7416002)(42186005)(39840400001)(39860400001)(23726003)(305945005)(53416004)(8676002)(106356001)(7846002)(6116002)(101416001)(7736002)(2950100002)(50466002)(47776003)(66066001)(97736004)(68736007)(5001770100001)(2906002)(36756003)(5660300001)(4001350100001)(46406003)(39850400001)(733004)(86362001)(39450400002)(33646002)(6486002)(189998001)(921003)(21314002)(16060500001)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:HK2PR0601MB1441; H:morimoto-PC.renesas.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: renesas.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HK2PR0601MB1441; 23:WX2miubwvTnErd34Er5U0+mzuqM9aL5X4roqUdE?= =?us-ascii?Q?hcq1l139ZXyshyYICx1l/Fj+kpYuwfQKXp1eHuVIz+TvmcTqq7ZJCbWF/ZiG?= =?us-ascii?Q?yDBUPwCfoFIi4CpYqyrbI/9X5RN26cJ1j7XGBrZcju+kIQcmvVTDPR6uI0FG?= =?us-ascii?Q?/thdqwqsUKMk3OGlTl3lb0UmpMZhwx6QyU4dr9LJs0oqJCS9uvtfToGlsyfj?= =?us-ascii?Q?kxLSaQgB8vlrnEw1iRZ1WFmh4UqkzO1jWvykg/+13nLIKoRqu+Bv984nxfLL?= =?us-ascii?Q?9vqcGhgxe5mPSNtyD08oLZPCRrClS9E19PF9lY5a2sM0Q2oXG5B/ngr8Jn2y?= =?us-ascii?Q?yoqeOMbzcDczOmHBvE5F00NDtZiJYy+V6vWPoy+gR6kFCYOm1Qfo5gCbuaL+?= =?us-ascii?Q?751pVaIC8V62kNbgpXHEKVCGVtJ3QbLjawghlq9/EZXLbabj/vDjFM7KWEUh?= =?us-ascii?Q?EGldBdy6dceg4BoUwIWgxVvDFCDqGCD9wkffkGED+jVfJdWyrOgiYh9BqHvP?= =?us-ascii?Q?qN2Dh4jr64atm3PH5i19utfiPdhrWrg6+W20PqXHMCJUlWHvDN3VeufR5NYd?= =?us-ascii?Q?NnxVnqWlfvVNYltVVtx+dUsxux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lWD7B8i814bdlSnb98DSFSWhmSKXsJg+uTpqEMPWfnJz2bYKcC1JEumV0l5gujwCTAuzOEBg1x3bPLIJIFha8GVfp50JbZQrVAtUhw==; 20:dDzGLyTFWzXGw5SvhEKcxXUWpiLmkrhleN0kHS9oCABNROCY5asBD33ZdmFl4Rk7TdRioE2lEdefMog8gBQIoASQNgb5KnDMbxh5wCdACDvOWQauO6PKdp4L7N3kHD4RKjGTjhvJS5cjT6Lk8SRBrZS4fyILtzpzXiZ0tBOE05k= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2016 05:23:20.1266 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2PR0601MB1441 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 From: Kuninori Morimoto Some driver is using this type of DT bindings for clock (more detail, see ${LINUX}/Documentation/devicetree/bindings/sound/simple-card.txt). sound_soc { ... cpu { clocks = <&xxx>; ... }; codec { clocks = <&xxx>; ... }; }; Current driver in this case uses of_clk_get() for each node, but there is no devm_of_clk_get() today. OTOH, the problem of having devm_of_clk_get() is that it encourages the use of of_clk_get() when clk_get() is more desirable. Thus, this patch adds new devm_get_clk_from_chile() which explicitly reads as get a clock from a child node of this device. By this function, we can also use this type of DT bindings sound_soc { clocks = <&xxx>, <&xxx>; clock-names = "cpu", "codec"; ... cpu { ... }; codec { ... }; }; Signed-off-by: Kuninori Morimoto Acked-by: Russell King --- drivers/clk/clk-devres.c | 21 +++++++++++++++++++++ include/linux/clk.h | 29 +++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index 8f57154..3a218c3 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -53,3 +53,24 @@ void devm_clk_put(struct device *dev, struct clk *clk) WARN_ON(ret); } EXPORT_SYMBOL(devm_clk_put); + +struct clk *devm_get_clk_from_child(struct device *dev, + struct device_node *np, const char *con_id) +{ + struct clk **ptr, *clk; + + ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + clk = of_clk_get_by_name(np, con_id); + if (!IS_ERR(clk)) { + *ptr = clk; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return clk; +} +EXPORT_SYMBOL(devm_get_clk_from_child); diff --git a/include/linux/clk.h b/include/linux/clk.h index 123c027..e9d36b3 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -17,8 +17,9 @@ #include struct device; - struct clk; +struct device_node; +struct of_phandle_args; /** * DOC: clk notifier callback types @@ -249,6 +250,23 @@ static inline void clk_unprepare(struct clk *clk) struct clk *devm_clk_get(struct device *dev, const char *id); /** + * devm_get_clk_from_child - lookup and obtain a managed reference to a + * clock producer from child node. + * @dev: device for clock "consumer" + * @np: pointer to clock consumer node + * @con_id: clock consumer ID + * + * This function parses the clocks, and uses them to look up the + * struct clk from the registered list of clock providers by using + * @np and @con_id + * + * The clock will automatically be freed when the device is unbound + * from the bus. + */ +struct clk *devm_get_clk_from_child(struct device *dev, + struct device_node *np, const char *con_id); + +/** * clk_enable - inform the system when the clock source should be running. * @clk: clock source * @@ -432,6 +450,12 @@ static inline struct clk *devm_clk_get(struct device *dev, const char *id) return NULL; } +static inline struct clk *devm_get_clk_from_child(struct device *dev, + struct device_node *np, const char *con_id) +{ + return NULL; +} + static inline void clk_put(struct clk *clk) {} static inline void devm_clk_put(struct device *dev, struct clk *clk) {} @@ -501,9 +525,6 @@ static inline void clk_disable_unprepare(struct clk *clk) clk_unprepare(clk); } -struct device_node; -struct of_phandle_args; - #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) struct clk *of_clk_get(struct device_node *np, int index); struct clk *of_clk_get_by_name(struct device_node *np, const char *name);