Merge tag 'mlx5-fixes-2017-07-09' of https://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6/btrfs-unstable.git] / drivers / clk / clk-bulk.c
blobc834f5abfc497e8ce674de2a736b9c3103bf55fa
1 /*
2 * Copyright 2017 NXP
4 * Dong Aisheng <aisheng.dong@nxp.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <linux/clk.h>
20 #include <linux/device.h>
21 #include <linux/export.h>
23 void clk_bulk_put(int num_clks, struct clk_bulk_data *clks)
25 while (--num_clks >= 0) {
26 clk_put(clks[num_clks].clk);
27 clks[num_clks].clk = NULL;
30 EXPORT_SYMBOL_GPL(clk_bulk_put);
32 int __must_check clk_bulk_get(struct device *dev, int num_clks,
33 struct clk_bulk_data *clks)
35 int ret;
36 int i;
38 for (i = 0; i < num_clks; i++)
39 clks[i].clk = NULL;
41 for (i = 0; i < num_clks; i++) {
42 clks[i].clk = clk_get(dev, clks[i].id);
43 if (IS_ERR(clks[i].clk)) {
44 ret = PTR_ERR(clks[i].clk);
45 dev_err(dev, "Failed to get clk '%s': %d\n",
46 clks[i].id, ret);
47 clks[i].clk = NULL;
48 goto err;
52 return 0;
54 err:
55 clk_bulk_put(i, clks);
57 return ret;
59 EXPORT_SYMBOL(clk_bulk_get);
61 #ifdef CONFIG_HAVE_CLK_PREPARE
63 /**
64 * clk_bulk_unprepare - undo preparation of a set of clock sources
65 * @num_clks: the number of clk_bulk_data
66 * @clks: the clk_bulk_data table being unprepared
68 * clk_bulk_unprepare may sleep, which differentiates it from clk_bulk_disable.
69 * Returns 0 on success, -EERROR otherwise.
71 void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks)
73 while (--num_clks >= 0)
74 clk_unprepare(clks[num_clks].clk);
76 EXPORT_SYMBOL_GPL(clk_bulk_unprepare);
78 /**
79 * clk_bulk_prepare - prepare a set of clocks
80 * @num_clks: the number of clk_bulk_data
81 * @clks: the clk_bulk_data table being prepared
83 * clk_bulk_prepare may sleep, which differentiates it from clk_bulk_enable.
84 * Returns 0 on success, -EERROR otherwise.
86 int __must_check clk_bulk_prepare(int num_clks,
87 const struct clk_bulk_data *clks)
89 int ret;
90 int i;
92 for (i = 0; i < num_clks; i++) {
93 ret = clk_prepare(clks[i].clk);
94 if (ret) {
95 pr_err("Failed to prepare clk '%s': %d\n",
96 clks[i].id, ret);
97 goto err;
101 return 0;
103 err:
104 clk_bulk_unprepare(i, clks);
106 return ret;
109 #endif /* CONFIG_HAVE_CLK_PREPARE */
112 * clk_bulk_disable - gate a set of clocks
113 * @num_clks: the number of clk_bulk_data
114 * @clks: the clk_bulk_data table being gated
116 * clk_bulk_disable must not sleep, which differentiates it from
117 * clk_bulk_unprepare. clk_bulk_disable must be called before
118 * clk_bulk_unprepare.
120 void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks)
123 while (--num_clks >= 0)
124 clk_disable(clks[num_clks].clk);
126 EXPORT_SYMBOL_GPL(clk_bulk_disable);
129 * clk_bulk_enable - ungate a set of clocks
130 * @num_clks: the number of clk_bulk_data
131 * @clks: the clk_bulk_data table being ungated
133 * clk_bulk_enable must not sleep
134 * Returns 0 on success, -EERROR otherwise.
136 int __must_check clk_bulk_enable(int num_clks, const struct clk_bulk_data *clks)
138 int ret;
139 int i;
141 for (i = 0; i < num_clks; i++) {
142 ret = clk_enable(clks[i].clk);
143 if (ret) {
144 pr_err("Failed to enable clk '%s': %d\n",
145 clks[i].id, ret);
146 goto err;
150 return 0;
152 err:
153 clk_bulk_disable(i, clks);
155 return ret;
157 EXPORT_SYMBOL_GPL(clk_bulk_enable);