1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/clk.h>
20#include <linux/device.h>
21#include <linux/export.h>
22
23void clk_bulk_put(int num_clks, struct clk_bulk_data *clks)
24{
25 while (--num_clks >= 0) {
26 clk_put(clks[num_clks].clk);
27 clks[num_clks].clk = NULL;
28 }
29}
30EXPORT_SYMBOL_GPL(clk_bulk_put);
31
32int __must_check clk_bulk_get(struct device *dev, int num_clks,
33 struct clk_bulk_data *clks)
34{
35 int ret;
36 int i;
37
38 for (i = 0; i < num_clks; i++)
39 clks[i].clk = NULL;
40
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;
49 }
50 }
51
52 return 0;
53
54err:
55 clk_bulk_put(i, clks);
56
57 return ret;
58}
59EXPORT_SYMBOL(clk_bulk_get);
60
61#ifdef CONFIG_HAVE_CLK_PREPARE
62
63
64
65
66
67
68
69
70
71void clk_bulk_unprepare(int num_clks, const struct clk_bulk_data *clks)
72{
73 while (--num_clks >= 0)
74 clk_unprepare(clks[num_clks].clk);
75}
76EXPORT_SYMBOL_GPL(clk_bulk_unprepare);
77
78
79
80
81
82
83
84
85
86int __must_check clk_bulk_prepare(int num_clks,
87 const struct clk_bulk_data *clks)
88{
89 int ret;
90 int i;
91
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;
98 }
99 }
100
101 return 0;
102
103err:
104 clk_bulk_unprepare(i, clks);
105
106 return ret;
107}
108EXPORT_SYMBOL_GPL(clk_bulk_prepare);
109
110#endif
111
112
113
114
115
116
117
118
119
120
121void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks)
122{
123
124 while (--num_clks >= 0)
125 clk_disable(clks[num_clks].clk);
126}
127EXPORT_SYMBOL_GPL(clk_bulk_disable);
128
129
130
131
132
133
134
135
136
137int __must_check clk_bulk_enable(int num_clks, const struct clk_bulk_data *clks)
138{
139 int ret;
140 int i;
141
142 for (i = 0; i < num_clks; i++) {
143 ret = clk_enable(clks[i].clk);
144 if (ret) {
145 pr_err("Failed to enable clk '%s': %d\n",
146 clks[i].id, ret);
147 goto err;
148 }
149 }
150
151 return 0;
152
153err:
154 clk_bulk_disable(i, clks);
155
156 return ret;
157}
158EXPORT_SYMBOL_GPL(clk_bulk_enable);
159