Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751494AbcLEFX7 (ORCPT ); Mon, 5 Dec 2016 00:23:59 -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 X-IronPort-AV: E=Sophos;i="5.33,302,1477926000"; d="scan'208";a="227061702" Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=kuninori.morimoto.gx@renesas.com; 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") Content-Type: text/plain; charset="US-ASCII" 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+jAh1eoVGjH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PPwW8qOu66zv55fLun1UfLv0yoMOt0CtObKdVRTtWra39rDNmxBtbuCWO04G3Z5lqAwH69KXTJ6ctmNCFRDxVuSULSxnCJSnnKOU9+kjbvne6evovLPdQxTjeWF2sZdexuRp9bkHxkLMqPS+FQVQ+/r5tS1SwhawHKOCOfTYYDHtLSKpKHtR/S51c0rH5LhAGI861mZ24+LbCGhBr85CIqlHq0Er1pYBfUWAGbub56MRiG7vDZRcxI54AAiWNLX82NgwNAkpB0Y0pwxoJ9TRS32TqXU4o69wMjBbpZ0C/iilQjktlp5v6mKzrJl+UQUPs5ITTx508ZVpbMR2UvoBtRe6mJO8PH2/WV4XmEJhM2s0qGlxl6SQju8y6XPNJhxucPy 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; 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/ngr8J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ZklFN3NfT9JJ1IISlzjFbQdjZEiDdOsrb2eCZDmZ77j?= =?us-ascii?Q?4BF91rVcqAldN0dHDegptP4cfGqPZNMRkx1uFhizIEdKx9V77dSc9b14TjDE?= =?us-ascii?Q?hEit7akjEJB6yc37h89wMLsU=3D?= X-Microsoft-Exchange-Diagnostics: 1;HK2PR0601MB1441;6:VbrN6n1ElLOJdzhnImJ5kqT6p7QTRNKFRFSsPSqUroFUV8Y6h53NM9//NNt7EKAEHwyvHzpaIqnp5erOYw5UtUozKiRCpcFkkqGlbNLAbS4kyazf4o0cZIFhbvg1DmahbcYLh6HBUKOoEaRVYMrSU7Wrur+hTna4HQNNgFd+qAvRhdw5YJli2fRAuZCeqlyo67HmFlNkKtFeKV2ujGndACgiD+Xu/I2RUPpDu2NWW61uBsdSz0N9R/MUsSHOYVzM3qpvoBg9286zPzjBz8zhUdgaIw+ETR8SAguvVgKj2kJY3NZMwR9aMtwBPTYLhLweWR7UuufAt51KQ52qMVhpKi3r22fDB3qNubypbQALnP/LYyGzvri+5fTzRSJjTa4hzUbdLsHfXCAjegfrTdoh7SdA/9PLH16FEY//hCCLJHipJnF9jeHFq2HxMF5MJTRL07+4n4Z2AO5GswfqPWjZq6mwqneyrbNepM6gBoiPeHPH2toG8rLvomZz3bjhnmAa;5:/2lQkG+lPUKs5Y4V9QF1XxX+KD+LEdDjBasYHx6RC1A6fbuOcG9PXrM5lz8GNcYtYQUvJ6jFKJamQA6OuimOzIzmxTvlZi/lxhY0lvcUEeXnasfKkF6NWlttFHOgcyquvtCujz48PaOToM6rWo4ONg==;24:YR+nboRxQ5l9fofRclrpiVGXyBmswnSf9dGBioo8DyLUPyBfzEaaRF12hKhm9X4WJTs2QFqJdzFJDF4ck/QaXhbxfdQYtfesnTEX5JqWjBE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HK2PR0601MB1441;7:Xt2Od5qKa9uBEd86aucDXFMmeemf27ycR87fz75qE0eAlFIgqLsUQ49RxbeuDNo5YB9suNvGLnpRwlRDF8UVI20Hpm1bEcOFeKaTb+Koo6ycFxEvqwSCV0Af6jhEeMw+PCG2NCiQhmcyBhVd2oNxsRytLjaDitz4Z+KCKKaEHsxVSlCcOJc4su46s9OdzZzxMMUlBgfwwf2LJS9RRVnJGq9UPST0oyJ84KqhhU5OEO22iWvVaPtSAePEeAqXIp1HneutKxxGnIqXghJDlt3p5XH0Ht1zF+OawSAQO1MU51wG21tbcR8RvPundDBy4gSLL6XZ/1Ob2r+y70YW6ibc+ll4HFrQRlhBY+qoKRbsaSNavD3BlWD7B8i814bdlSnb98DSFSWhmSKXsJg+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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3696 Lines: 138 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 --- 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); -- 1.9.1