From patchwork Tue Nov 29 01:21:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 9450827 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 02C2B6074E for ; Tue, 29 Nov 2016 01:21:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED98F27D64 for ; Tue, 29 Nov 2016 01:21:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E14A127FE4; Tue, 29 Nov 2016 01:21: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=unavailable 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 7265827D64 for ; Tue, 29 Nov 2016 01:21:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754607AbcK2BVl (ORCPT ); Mon, 28 Nov 2016 20:21:41 -0500 Received: from relmlor3.renesas.com ([210.160.252.173]:14820 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751479AbcK2BVj (ORCPT ); Mon, 28 Nov 2016 20:21:39 -0500 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie2.idc.renesas.com with ESMTP; 29 Nov 2016 10:21:36 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 0F98A4DB77; Tue, 29 Nov 2016 10:21:36 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id E9FC5480A6; Tue, 29 Nov 2016 10:21:35 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id D9EB0480A5; Tue, 29 Nov 2016 10:21:35 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac4.idc.renesas.com with ESMTP id LAK19369; Tue, 29 Nov 2016 10:21:35 +0900 X-IronPort-AV: E=Sophos;i="5.31,565,1473087600"; d="scan'";a="227189247" Received: from mail-hk2apc01lp0212.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.212]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 29 Nov 2016 10:21:34 +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=/CWl0k+sfUf8jJoN1X8ym7RyTmXaX1f2R392V/ykPW8=; b=FrGVGJB1qBySs7kXj80KT6MF2ujv+aajWqOJggD4edGGsKRSvJEQ8ecI+bQSZuN0h9favqhUG54ZZe1vHjKNMJVZxmaNiarUNDUBfBXlEzdyrv/qG1SCwb8JgW7AaNP8sKa/3uWZtDJ088B176nE8/jgr8nZoNHMudcN8Ew6iLI= 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 KL1PR0601MB1446.apcprd06.prod.outlook.com (10.169.69.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.734.8; Tue, 29 Nov 2016 01:21:30 +0000 Message-ID: <87zikjw08i.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v4] clkdev: add devm_of_clk_get() 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 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Tue, 29 Nov 2016 01:21:30 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS2PR0101CA0035.jpnprd01.prod.outlook.com (10.167.173.173) To KL1PR0601MB1446.apcprd06.prod.outlook.com (10.169.69.24) X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1446; 2:moq7ITX0cHyhL5BFCDATYn1vjmcKyom/K4KS4+FIC+S8v+1MxXI3mdd2Orsq2S4P1V4Q8mLLRknJNbKcpKpRGWjmox9X4+1TXN+zMaTp++NQHqAvu4muQv+C7cnlRCSJBppwj010S9AGTWPhxKJcvhccv4DTfBu3sAQN76XHVzM=; 3:8sfxa+sV50c37XGgGUzXTQCvNCMLYC70sXay1YiLFC6ruuLwYUfQz20/Qem7nu6ox2C3RvlAq14qeOCGdQdaGFyrwd3Qf9u7R2zs7/UyuEqDGHmrf7Pa3PiacjcqFJhMCehbwlImu/2Yb4G/GSBW7ddbQGtrSF0ogO1fD7s0gx4= X-MS-Office365-Filtering-Correlation-Id: 71c072f5-7c88-43df-b4df-08d417f60d6d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:KL1PR0601MB1446; X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1446; 25:JYFiRyyrBj7yplYOFezZS+0lZY8Z5ClIxX5SExvGY7s7rx6EIzz1O8lsoZhKcbsd59b2jYyRrrj/Yc9Tx2d4DLrmtmwicSQlAGfkq76MImX0AHFBF92RFeKMDzMzwhoex0kQ/IsxToF3a84KhIvhtrlHI9adoCjZBkidb+5TkngHMnLpckWLBBZzdXi/wYNL1EEcn3bLBZpjLzb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ZNl28utBQc5CsJPj/eHVPzNfRQKlf7Y90VrNiwayitfwgt+oISznJJ1QwYo7FSJ7X86lC8F3O3BxHb5PG2GZpEh09n9ZtUmMAWLnqmRygGku0pRh6WhGf4uaVsSNCv2W1O8R6nfj44MpZwWuQUzOEh4GN7SiUrE0o8PMYGkrgW21PntEMJQiJwcXSIWUZCoSUo2bybeJF3SuEj0mv3qtR1j+wICyJjx7TSmomwSbbs8VjoGCgN/sD9hCh5oXQZs645Nic9F2cGAl8uLe8AAG1MQXmtAjZy/NCj+Nzno2FT/w383qeQ3+z7TDwbrkBAecV8fRScUTiwYn92+/3Ne X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6045199)(6060326)(6040361)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(6061324)(20161123560025)(20161123558021)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:KL1PR0601MB1446; BCL:0; PCL:0; RULEID:; SRVR:KL1PR0601MB1446; X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1446; 4:VBzuEqFYxI/Vr6GO2WHOmOH7WTbIWhYYSQ+aXOSCROkpEmJnuNSJwJWEiWSjAvGo2Uhmcg33nqwb5CiPsucL+kst32MZIOlILf+v0dx8jChBFBxYMcV/lFM4lVYIi6oGv1JfNXJnAY98f9jMtBhTuGicsaTwowEt2rC6TkM2XXqVqal7hPwc+0owKk814crQfYcBugIuZ88exw7Y0Mfd/w3v/4XSdTWzZPrp+FzOe64/UkOZedigJwcgBK3WoPDvG1Y2epr2Jl/gk/1nwV37zU25SmYkEldtRnrYfGs0GNn8uuEbbjLHBbMI5KhZlHLhSeeRkW/w2LmAeY+fosMZN90npBevFCECc4Lj813ll82gKYk1kNRJcwxSIYFRBI8ZpTX77ToJc+UpC/F/kz5CrqvPKPXU6mBgvr6FLjPlRFA7L3aJMKG7YtPO8R0YNaGPKjz3QyrzBltN7gUlNk9qxkiDbwuts7h7U6uwTcG7onw2Spw015MYhN+IXPpJRlg1/3CLgWQ2WOUT5PLNESjzDOTpQxoGNR8Adyl5H5idL3nCmG6xHPMiVNs/7zPt9FZHbG5cuHsMPqqmEF9bJAgs803aQxS/B83GaCgQG4pmpE9Bgu/XO8MmY3ne5kB0O1l6SgVJijRZq93loWkw4eFSajr9i6Vz55ode94HrpWaLKqFtwyydaXXvSWndy6308Nd X-Forefront-PRVS: 01415BB535 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(81166006)(68736007)(92566002)(7416002)(36756003)(39410400001)(50466002)(81156014)(8676002)(46406003)(39450400002)(83506001)(38730400001)(39400400001)(66066001)(69596002)(47776003)(42186005)(2906002)(53416004)(105586002)(50986999)(54356999)(106356001)(97736004)(4001350100001)(5001770100001)(101416001)(189998001)(33646002)(305945005)(7846002)(3846002)(6116002)(23726003)(107886002)(733004)(39380400001)(6486002)(5660300001)(7736002)(86362001)(921003)(16060500001)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:KL1PR0601MB1446; H:morimoto-PC.renesas.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; KL1PR0601MB1446; 23:JqnqcqweaenpmEzjSbp/k+Vcz7UwCgFAuwRzSSI?= =?us-ascii?Q?zntOWK3m81D6vg/AAx7TVnRQlKon+uZmPDDG/ympSRP6XB6zQ4kkeXxGYJqp?= =?us-ascii?Q?y6zD6P+6GZk8CJ11jrzfH4j4wYkpAIa2VTCz+XjL3Qlbded8zfJKqsyEASkv?= =?us-ascii?Q?HCP1K9y0Io4MTLjuQ84UsbdI7iiikHftubLA1vj6VeuIeMadyk9UQERmM+nY?= =?us-ascii?Q?AsylTloxVvfkjjUpTNitbuVDyph/Gb8TTm+H7T2N9LNs9tHp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VGKyZPjmpSidhDUlcjJx6NzcWbvkELrviEQAlW?= =?us-ascii?Q?pDP4jVqxPieEErh3a2veOlFMI4yYw4ocjtm8uGGCJKe9ERq+D71C8v+97Qi/?= =?us-ascii?Q?QLoNFmZrN1yeAP9PjHF95+Tn5M166rm1HBRchxLp0?= X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1446; 6:+NwqLsJFYiRn/NSCGZiFyHxzDqjHiUq69YR+nLyAVe+Qg7Cc+VwoKEheKMqCke9fj0x39eAzcWk9DE2fDeXdDT+C7aHQSidUb27WxtxdCGjcJyDnJFoE+YZxP7Kt2Bc1zs5VlEQ8YO+qUO+ZooLuRELtO94wnpmZ6JlZ93eXA5GZgJ0uOJdbSHCmLNwUrQQF2oJ497mzodZeAi2gs+anQFlp/4LdQhO/mLmHmyE/m45frYb2MDS0tftIHXJ4l/RsXxR8Rm+V/vxnDsh43zBgHTYWtC1j5WfpmMMvVpcgxT18DKaSqRMNIUSFOO2ssWd8XJLdmJYBO58P96X3ZLQ5XJVsPEp1hub4loIBBIYkymEe6//78aNF4IrM5xFB5CFw; 5:yCcqcRWBZiFFzR+FIcQry3kVxDOE5ElgnEL4jZr6L4wMuJSqOVfvL5xReyAMO6t64taMdVGSR+LQ8yOAKbEAx9YD5M+Ew1KflxuJsw7Inh3ZVntlzgwAg9xbwB5cKRVjUlbuAelJNH468Ggm+2Z87A==; 24:Cksj+sKjgJIjQr4JssBgRc31rHJNUfzbhKlx8cgeD17vZGchFOzK6QWadpkm4qwByntVJpHNYdi0IdtNMP36RYKjz35BhWiLdFw08F7eTzE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1446; 7:Hlfya1kurRZvRFBpf2Vk1I5Vg/NUkHv3uAjwnZA2nJSoG+m5okzf31TY1bICiPv+TD/muO9hmTXTWuK8id09U8zFZcWg5BM01SX245CmIzas8Wau7Ak/0i7UwtLTmYsI7HDxZ6IiZAaB+AZn9OtQl5FQ72v16u6v8CTQNmgPA4cp7rRhSGrwtq3tQNR16Kyr0Ndn3H+xSR6+aKrI2vzT6YijBsBJRZX69DdQWkYUG/pmH48yuWGJeTW0NYptBfumDGOfLHUgGNmUVZXkMVN/FWiEVb54dC8JTiRoroeKcGN35RyVxHYT6ML7vc0808Tne+IYcfTiR0yMHIPEtTyuL94c2682zTiTaNIF1PJ/8M8=; 20:xLSRu4RUcx2B1YsjCiD9EA+piKiNTG25AZDXC7ybeYBrD226kHStcWGXKQV+GgQ5TWIwfGKHEFlt85JSNT++RkZUJmscSejE+NTaXLmPC8BvQiF9l0LQxyhJZYzYjUcOfWZ677DoutpCCgXazdvrz92rnLrNF/meXdwIdwW/W5M= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2016 01:21:30.8748 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB1446 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 Current Linux has of_clk_get(), but doesn't have devm_of_clk_get(). This patch adds it. It is implemeted in clk-devres.c to share devm_clk_release(). Signed-off-by: Kuninori Morimoto --- v3 -> v4 - git log explain why it is implemeted in clk-devres - it is related to CONFIG_HAVE_CLK drivers/clk/clk-devres.c | 21 +++++++++++++++++++++ include/linux/clk.h | 27 +++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index 8f57154..2449b25 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_of_clk_get(struct device *dev, + struct device_node *np, int index) +{ + struct clk **ptr, *clk; + + ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + clk = of_clk_get(np, index); + if (!IS_ERR(clk)) { + *ptr = clk; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return clk; +} +EXPORT_SYMBOL(devm_of_clk_get); diff --git a/include/linux/clk.h b/include/linux/clk.h index 123c027..7f50c5f 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,21 @@ static inline void clk_unprepare(struct clk *clk) struct clk *devm_clk_get(struct device *dev, const char *id); /** + * devm_clk_get - lookup and obtain a managed reference to a clock producer. + * @dev: device for clock "consumer" + * @np: pointer to clock consumer node + * @index: clock index + * + * 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 @index. + * + * The clock will automatically be freed when the device is unbound + * from the bus. + */ +struct clk *devm_of_clk_get(struct device *dev, struct device_node *np, int index); + +/** * clk_enable - inform the system when the clock source should be running. * @clk: clock source * @@ -432,6 +448,12 @@ static inline struct clk *devm_clk_get(struct device *dev, const char *id) return NULL; } +static inline struct clk *devm_of_clk_get(struct device *dev, + struct device_node *np, int index) +{ + return NULL; +} + static inline void clk_put(struct clk *clk) {} static inline void devm_clk_put(struct device *dev, struct clk *clk) {} @@ -501,9 +523,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);