Linux 4.18.10
[linux/fpc-iii.git] / drivers / clk / qcom / clk-rpm.c
blobb949814476640fee5b869704e0eb11b63cba060a
1 /*
2 * Copyright (c) 2016, Linaro Limited
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/clk-provider.h>
16 #include <linux/err.h>
17 #include <linux/export.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/mutex.h>
22 #include <linux/mfd/qcom_rpm.h>
23 #include <linux/of.h>
24 #include <linux/of_device.h>
25 #include <linux/platform_device.h>
27 #include <dt-bindings/mfd/qcom-rpm.h>
28 #include <dt-bindings/clock/qcom,rpmcc.h>
30 #define QCOM_RPM_MISC_CLK_TYPE 0x306b6c63
31 #define QCOM_RPM_SCALING_ENABLE_ID 0x2
32 #define QCOM_RPM_XO_MODE_ON 0x2
34 #define DEFINE_CLK_RPM(_platform, _name, _active, r_id) \
35 static struct clk_rpm _platform##_##_active; \
36 static struct clk_rpm _platform##_##_name = { \
37 .rpm_clk_id = (r_id), \
38 .peer = &_platform##_##_active, \
39 .rate = INT_MAX, \
40 .hw.init = &(struct clk_init_data){ \
41 .ops = &clk_rpm_ops, \
42 .name = #_name, \
43 .parent_names = (const char *[]){ "pxo_board" }, \
44 .num_parents = 1, \
45 }, \
46 }; \
47 static struct clk_rpm _platform##_##_active = { \
48 .rpm_clk_id = (r_id), \
49 .peer = &_platform##_##_name, \
50 .active_only = true, \
51 .rate = INT_MAX, \
52 .hw.init = &(struct clk_init_data){ \
53 .ops = &clk_rpm_ops, \
54 .name = #_active, \
55 .parent_names = (const char *[]){ "pxo_board" }, \
56 .num_parents = 1, \
57 }, \
60 #define DEFINE_CLK_RPM_XO_BUFFER(_platform, _name, _active, offset) \
61 static struct clk_rpm _platform##_##_name = { \
62 .rpm_clk_id = QCOM_RPM_CXO_BUFFERS, \
63 .xo_offset = (offset), \
64 .hw.init = &(struct clk_init_data){ \
65 .ops = &clk_rpm_xo_ops, \
66 .name = #_name, \
67 .parent_names = (const char *[]){ "cxo_board" }, \
68 .num_parents = 1, \
69 }, \
72 #define DEFINE_CLK_RPM_FIXED(_platform, _name, _active, r_id, r) \
73 static struct clk_rpm _platform##_##_name = { \
74 .rpm_clk_id = (r_id), \
75 .rate = (r), \
76 .hw.init = &(struct clk_init_data){ \
77 .ops = &clk_rpm_fixed_ops, \
78 .name = #_name, \
79 .parent_names = (const char *[]){ "pxo" }, \
80 .num_parents = 1, \
81 }, \
84 #define DEFINE_CLK_RPM_PXO_BRANCH(_platform, _name, _active, r_id, r) \
85 static struct clk_rpm _platform##_##_active; \
86 static struct clk_rpm _platform##_##_name = { \
87 .rpm_clk_id = (r_id), \
88 .active_only = true, \
89 .peer = &_platform##_##_active, \
90 .rate = (r), \
91 .branch = true, \
92 .hw.init = &(struct clk_init_data){ \
93 .ops = &clk_rpm_branch_ops, \
94 .name = #_name, \
95 .parent_names = (const char *[]){ "pxo_board" }, \
96 .num_parents = 1, \
97 }, \
98 }; \
99 static struct clk_rpm _platform##_##_active = { \
100 .rpm_clk_id = (r_id), \
101 .peer = &_platform##_##_name, \
102 .rate = (r), \
103 .branch = true, \
104 .hw.init = &(struct clk_init_data){ \
105 .ops = &clk_rpm_branch_ops, \
106 .name = #_active, \
107 .parent_names = (const char *[]){ "pxo_board" }, \
108 .num_parents = 1, \
109 }, \
112 #define DEFINE_CLK_RPM_CXO_BRANCH(_platform, _name, _active, r_id, r) \
113 static struct clk_rpm _platform##_##_active; \
114 static struct clk_rpm _platform##_##_name = { \
115 .rpm_clk_id = (r_id), \
116 .peer = &_platform##_##_active, \
117 .rate = (r), \
118 .branch = true, \
119 .hw.init = &(struct clk_init_data){ \
120 .ops = &clk_rpm_branch_ops, \
121 .name = #_name, \
122 .parent_names = (const char *[]){ "cxo_board" }, \
123 .num_parents = 1, \
124 }, \
125 }; \
126 static struct clk_rpm _platform##_##_active = { \
127 .rpm_clk_id = (r_id), \
128 .active_only = true, \
129 .peer = &_platform##_##_name, \
130 .rate = (r), \
131 .branch = true, \
132 .hw.init = &(struct clk_init_data){ \
133 .ops = &clk_rpm_branch_ops, \
134 .name = #_active, \
135 .parent_names = (const char *[]){ "cxo_board" }, \
136 .num_parents = 1, \
137 }, \
140 #define to_clk_rpm(_hw) container_of(_hw, struct clk_rpm, hw)
142 struct rpm_cc;
144 struct clk_rpm {
145 const int rpm_clk_id;
146 const int xo_offset;
147 const bool active_only;
148 unsigned long rate;
149 bool enabled;
150 bool branch;
151 struct clk_rpm *peer;
152 struct clk_hw hw;
153 struct qcom_rpm *rpm;
154 struct rpm_cc *rpm_cc;
157 struct rpm_cc {
158 struct qcom_rpm *rpm;
159 struct clk_rpm **clks;
160 size_t num_clks;
161 u32 xo_buffer_value;
162 struct mutex xo_lock;
165 struct rpm_clk_desc {
166 struct clk_rpm **clks;
167 size_t num_clks;
170 static DEFINE_MUTEX(rpm_clk_lock);
172 static int clk_rpm_handoff(struct clk_rpm *r)
174 int ret;
175 u32 value = INT_MAX;
178 * The vendor tree simply reads the status for this
179 * RPM clock.
181 if (r->rpm_clk_id == QCOM_RPM_PLL_4 ||
182 r->rpm_clk_id == QCOM_RPM_CXO_BUFFERS)
183 return 0;
185 ret = qcom_rpm_write(r->rpm, QCOM_RPM_ACTIVE_STATE,
186 r->rpm_clk_id, &value, 1);
187 if (ret)
188 return ret;
189 ret = qcom_rpm_write(r->rpm, QCOM_RPM_SLEEP_STATE,
190 r->rpm_clk_id, &value, 1);
191 if (ret)
192 return ret;
194 return 0;
197 static int clk_rpm_set_rate_active(struct clk_rpm *r, unsigned long rate)
199 u32 value = DIV_ROUND_UP(rate, 1000); /* to kHz */
201 return qcom_rpm_write(r->rpm, QCOM_RPM_ACTIVE_STATE,
202 r->rpm_clk_id, &value, 1);
205 static int clk_rpm_set_rate_sleep(struct clk_rpm *r, unsigned long rate)
207 u32 value = DIV_ROUND_UP(rate, 1000); /* to kHz */
209 return qcom_rpm_write(r->rpm, QCOM_RPM_SLEEP_STATE,
210 r->rpm_clk_id, &value, 1);
213 static void to_active_sleep(struct clk_rpm *r, unsigned long rate,
214 unsigned long *active, unsigned long *sleep)
216 *active = rate;
219 * Active-only clocks don't care what the rate is during sleep. So,
220 * they vote for zero.
222 if (r->active_only)
223 *sleep = 0;
224 else
225 *sleep = *active;
228 static int clk_rpm_prepare(struct clk_hw *hw)
230 struct clk_rpm *r = to_clk_rpm(hw);
231 struct clk_rpm *peer = r->peer;
232 unsigned long this_rate = 0, this_sleep_rate = 0;
233 unsigned long peer_rate = 0, peer_sleep_rate = 0;
234 unsigned long active_rate, sleep_rate;
235 int ret = 0;
237 mutex_lock(&rpm_clk_lock);
239 /* Don't send requests to the RPM if the rate has not been set. */
240 if (!r->rate)
241 goto out;
243 to_active_sleep(r, r->rate, &this_rate, &this_sleep_rate);
245 /* Take peer clock's rate into account only if it's enabled. */
246 if (peer->enabled)
247 to_active_sleep(peer, peer->rate,
248 &peer_rate, &peer_sleep_rate);
250 active_rate = max(this_rate, peer_rate);
252 if (r->branch)
253 active_rate = !!active_rate;
255 ret = clk_rpm_set_rate_active(r, active_rate);
256 if (ret)
257 goto out;
259 sleep_rate = max(this_sleep_rate, peer_sleep_rate);
260 if (r->branch)
261 sleep_rate = !!sleep_rate;
263 ret = clk_rpm_set_rate_sleep(r, sleep_rate);
264 if (ret)
265 /* Undo the active set vote and restore it */
266 ret = clk_rpm_set_rate_active(r, peer_rate);
268 out:
269 if (!ret)
270 r->enabled = true;
272 mutex_unlock(&rpm_clk_lock);
274 return ret;
277 static void clk_rpm_unprepare(struct clk_hw *hw)
279 struct clk_rpm *r = to_clk_rpm(hw);
280 struct clk_rpm *peer = r->peer;
281 unsigned long peer_rate = 0, peer_sleep_rate = 0;
282 unsigned long active_rate, sleep_rate;
283 int ret;
285 mutex_lock(&rpm_clk_lock);
287 if (!r->rate)
288 goto out;
290 /* Take peer clock's rate into account only if it's enabled. */
291 if (peer->enabled)
292 to_active_sleep(peer, peer->rate, &peer_rate,
293 &peer_sleep_rate);
295 active_rate = r->branch ? !!peer_rate : peer_rate;
296 ret = clk_rpm_set_rate_active(r, active_rate);
297 if (ret)
298 goto out;
300 sleep_rate = r->branch ? !!peer_sleep_rate : peer_sleep_rate;
301 ret = clk_rpm_set_rate_sleep(r, sleep_rate);
302 if (ret)
303 goto out;
305 r->enabled = false;
307 out:
308 mutex_unlock(&rpm_clk_lock);
311 static int clk_rpm_xo_prepare(struct clk_hw *hw)
313 struct clk_rpm *r = to_clk_rpm(hw);
314 struct rpm_cc *rcc = r->rpm_cc;
315 int ret, clk_id = r->rpm_clk_id;
316 u32 value;
318 mutex_lock(&rcc->xo_lock);
320 value = rcc->xo_buffer_value | (QCOM_RPM_XO_MODE_ON << r->xo_offset);
321 ret = qcom_rpm_write(r->rpm, QCOM_RPM_ACTIVE_STATE, clk_id, &value, 1);
322 if (!ret) {
323 r->enabled = true;
324 rcc->xo_buffer_value = value;
327 mutex_unlock(&rcc->xo_lock);
329 return ret;
332 static void clk_rpm_xo_unprepare(struct clk_hw *hw)
334 struct clk_rpm *r = to_clk_rpm(hw);
335 struct rpm_cc *rcc = r->rpm_cc;
336 int ret, clk_id = r->rpm_clk_id;
337 u32 value;
339 mutex_lock(&rcc->xo_lock);
341 value = rcc->xo_buffer_value & ~(QCOM_RPM_XO_MODE_ON << r->xo_offset);
342 ret = qcom_rpm_write(r->rpm, QCOM_RPM_ACTIVE_STATE, clk_id, &value, 1);
343 if (!ret) {
344 r->enabled = false;
345 rcc->xo_buffer_value = value;
348 mutex_unlock(&rcc->xo_lock);
351 static int clk_rpm_fixed_prepare(struct clk_hw *hw)
353 struct clk_rpm *r = to_clk_rpm(hw);
354 u32 value = 1;
355 int ret;
357 ret = qcom_rpm_write(r->rpm, QCOM_RPM_ACTIVE_STATE,
358 r->rpm_clk_id, &value, 1);
359 if (!ret)
360 r->enabled = true;
362 return ret;
365 static void clk_rpm_fixed_unprepare(struct clk_hw *hw)
367 struct clk_rpm *r = to_clk_rpm(hw);
368 u32 value = 0;
369 int ret;
371 ret = qcom_rpm_write(r->rpm, QCOM_RPM_ACTIVE_STATE,
372 r->rpm_clk_id, &value, 1);
373 if (!ret)
374 r->enabled = false;
377 static int clk_rpm_set_rate(struct clk_hw *hw,
378 unsigned long rate, unsigned long parent_rate)
380 struct clk_rpm *r = to_clk_rpm(hw);
381 struct clk_rpm *peer = r->peer;
382 unsigned long active_rate, sleep_rate;
383 unsigned long this_rate = 0, this_sleep_rate = 0;
384 unsigned long peer_rate = 0, peer_sleep_rate = 0;
385 int ret = 0;
387 mutex_lock(&rpm_clk_lock);
389 if (!r->enabled)
390 goto out;
392 to_active_sleep(r, rate, &this_rate, &this_sleep_rate);
394 /* Take peer clock's rate into account only if it's enabled. */
395 if (peer->enabled)
396 to_active_sleep(peer, peer->rate,
397 &peer_rate, &peer_sleep_rate);
399 active_rate = max(this_rate, peer_rate);
400 ret = clk_rpm_set_rate_active(r, active_rate);
401 if (ret)
402 goto out;
404 sleep_rate = max(this_sleep_rate, peer_sleep_rate);
405 ret = clk_rpm_set_rate_sleep(r, sleep_rate);
406 if (ret)
407 goto out;
409 r->rate = rate;
411 out:
412 mutex_unlock(&rpm_clk_lock);
414 return ret;
417 static long clk_rpm_round_rate(struct clk_hw *hw, unsigned long rate,
418 unsigned long *parent_rate)
421 * RPM handles rate rounding and we don't have a way to
422 * know what the rate will be, so just return whatever
423 * rate is requested.
425 return rate;
428 static unsigned long clk_rpm_recalc_rate(struct clk_hw *hw,
429 unsigned long parent_rate)
431 struct clk_rpm *r = to_clk_rpm(hw);
434 * RPM handles rate rounding and we don't have a way to
435 * know what the rate will be, so just return whatever
436 * rate was set.
438 return r->rate;
441 static const struct clk_ops clk_rpm_xo_ops = {
442 .prepare = clk_rpm_xo_prepare,
443 .unprepare = clk_rpm_xo_unprepare,
446 static const struct clk_ops clk_rpm_fixed_ops = {
447 .prepare = clk_rpm_fixed_prepare,
448 .unprepare = clk_rpm_fixed_unprepare,
449 .round_rate = clk_rpm_round_rate,
450 .recalc_rate = clk_rpm_recalc_rate,
453 static const struct clk_ops clk_rpm_ops = {
454 .prepare = clk_rpm_prepare,
455 .unprepare = clk_rpm_unprepare,
456 .set_rate = clk_rpm_set_rate,
457 .round_rate = clk_rpm_round_rate,
458 .recalc_rate = clk_rpm_recalc_rate,
461 static const struct clk_ops clk_rpm_branch_ops = {
462 .prepare = clk_rpm_prepare,
463 .unprepare = clk_rpm_unprepare,
464 .round_rate = clk_rpm_round_rate,
465 .recalc_rate = clk_rpm_recalc_rate,
468 /* MSM8660/APQ8060 */
469 DEFINE_CLK_RPM(msm8660, afab_clk, afab_a_clk, QCOM_RPM_APPS_FABRIC_CLK);
470 DEFINE_CLK_RPM(msm8660, sfab_clk, sfab_a_clk, QCOM_RPM_SYS_FABRIC_CLK);
471 DEFINE_CLK_RPM(msm8660, mmfab_clk, mmfab_a_clk, QCOM_RPM_MM_FABRIC_CLK);
472 DEFINE_CLK_RPM(msm8660, daytona_clk, daytona_a_clk, QCOM_RPM_DAYTONA_FABRIC_CLK);
473 DEFINE_CLK_RPM(msm8660, sfpb_clk, sfpb_a_clk, QCOM_RPM_SFPB_CLK);
474 DEFINE_CLK_RPM(msm8660, cfpb_clk, cfpb_a_clk, QCOM_RPM_CFPB_CLK);
475 DEFINE_CLK_RPM(msm8660, mmfpb_clk, mmfpb_a_clk, QCOM_RPM_MMFPB_CLK);
476 DEFINE_CLK_RPM(msm8660, smi_clk, smi_a_clk, QCOM_RPM_SMI_CLK);
477 DEFINE_CLK_RPM(msm8660, ebi1_clk, ebi1_a_clk, QCOM_RPM_EBI1_CLK);
478 DEFINE_CLK_RPM_FIXED(msm8660, pll4_clk, pll4_a_clk, QCOM_RPM_PLL_4, 540672000);
480 static struct clk_rpm *msm8660_clks[] = {
481 [RPM_APPS_FABRIC_CLK] = &msm8660_afab_clk,
482 [RPM_APPS_FABRIC_A_CLK] = &msm8660_afab_a_clk,
483 [RPM_SYS_FABRIC_CLK] = &msm8660_sfab_clk,
484 [RPM_SYS_FABRIC_A_CLK] = &msm8660_sfab_a_clk,
485 [RPM_MM_FABRIC_CLK] = &msm8660_mmfab_clk,
486 [RPM_MM_FABRIC_A_CLK] = &msm8660_mmfab_a_clk,
487 [RPM_DAYTONA_FABRIC_CLK] = &msm8660_daytona_clk,
488 [RPM_DAYTONA_FABRIC_A_CLK] = &msm8660_daytona_a_clk,
489 [RPM_SFPB_CLK] = &msm8660_sfpb_clk,
490 [RPM_SFPB_A_CLK] = &msm8660_sfpb_a_clk,
491 [RPM_CFPB_CLK] = &msm8660_cfpb_clk,
492 [RPM_CFPB_A_CLK] = &msm8660_cfpb_a_clk,
493 [RPM_MMFPB_CLK] = &msm8660_mmfpb_clk,
494 [RPM_MMFPB_A_CLK] = &msm8660_mmfpb_a_clk,
495 [RPM_SMI_CLK] = &msm8660_smi_clk,
496 [RPM_SMI_A_CLK] = &msm8660_smi_a_clk,
497 [RPM_EBI1_CLK] = &msm8660_ebi1_clk,
498 [RPM_EBI1_A_CLK] = &msm8660_ebi1_a_clk,
499 [RPM_PLL4_CLK] = &msm8660_pll4_clk,
502 static const struct rpm_clk_desc rpm_clk_msm8660 = {
503 .clks = msm8660_clks,
504 .num_clks = ARRAY_SIZE(msm8660_clks),
507 /* apq8064 */
508 DEFINE_CLK_RPM(apq8064, afab_clk, afab_a_clk, QCOM_RPM_APPS_FABRIC_CLK);
509 DEFINE_CLK_RPM(apq8064, cfpb_clk, cfpb_a_clk, QCOM_RPM_CFPB_CLK);
510 DEFINE_CLK_RPM(apq8064, daytona_clk, daytona_a_clk, QCOM_RPM_DAYTONA_FABRIC_CLK);
511 DEFINE_CLK_RPM(apq8064, ebi1_clk, ebi1_a_clk, QCOM_RPM_EBI1_CLK);
512 DEFINE_CLK_RPM(apq8064, mmfab_clk, mmfab_a_clk, QCOM_RPM_MM_FABRIC_CLK);
513 DEFINE_CLK_RPM(apq8064, mmfpb_clk, mmfpb_a_clk, QCOM_RPM_MMFPB_CLK);
514 DEFINE_CLK_RPM(apq8064, sfab_clk, sfab_a_clk, QCOM_RPM_SYS_FABRIC_CLK);
515 DEFINE_CLK_RPM(apq8064, sfpb_clk, sfpb_a_clk, QCOM_RPM_SFPB_CLK);
516 DEFINE_CLK_RPM(apq8064, qdss_clk, qdss_a_clk, QCOM_RPM_QDSS_CLK);
517 DEFINE_CLK_RPM_XO_BUFFER(apq8064, xo_d0_clk, xo_d0_a_clk, 0);
518 DEFINE_CLK_RPM_XO_BUFFER(apq8064, xo_d1_clk, xo_d1_a_clk, 8);
519 DEFINE_CLK_RPM_XO_BUFFER(apq8064, xo_a0_clk, xo_a0_a_clk, 16);
520 DEFINE_CLK_RPM_XO_BUFFER(apq8064, xo_a1_clk, xo_a1_a_clk, 24);
521 DEFINE_CLK_RPM_XO_BUFFER(apq8064, xo_a2_clk, xo_a2_a_clk, 28);
523 static struct clk_rpm *apq8064_clks[] = {
524 [RPM_APPS_FABRIC_CLK] = &apq8064_afab_clk,
525 [RPM_APPS_FABRIC_A_CLK] = &apq8064_afab_a_clk,
526 [RPM_CFPB_CLK] = &apq8064_cfpb_clk,
527 [RPM_CFPB_A_CLK] = &apq8064_cfpb_a_clk,
528 [RPM_DAYTONA_FABRIC_CLK] = &apq8064_daytona_clk,
529 [RPM_DAYTONA_FABRIC_A_CLK] = &apq8064_daytona_a_clk,
530 [RPM_EBI1_CLK] = &apq8064_ebi1_clk,
531 [RPM_EBI1_A_CLK] = &apq8064_ebi1_a_clk,
532 [RPM_MM_FABRIC_CLK] = &apq8064_mmfab_clk,
533 [RPM_MM_FABRIC_A_CLK] = &apq8064_mmfab_a_clk,
534 [RPM_MMFPB_CLK] = &apq8064_mmfpb_clk,
535 [RPM_MMFPB_A_CLK] = &apq8064_mmfpb_a_clk,
536 [RPM_SYS_FABRIC_CLK] = &apq8064_sfab_clk,
537 [RPM_SYS_FABRIC_A_CLK] = &apq8064_sfab_a_clk,
538 [RPM_SFPB_CLK] = &apq8064_sfpb_clk,
539 [RPM_SFPB_A_CLK] = &apq8064_sfpb_a_clk,
540 [RPM_QDSS_CLK] = &apq8064_qdss_clk,
541 [RPM_QDSS_A_CLK] = &apq8064_qdss_a_clk,
542 [RPM_XO_D0] = &apq8064_xo_d0_clk,
543 [RPM_XO_D1] = &apq8064_xo_d1_clk,
544 [RPM_XO_A0] = &apq8064_xo_a0_clk,
545 [RPM_XO_A1] = &apq8064_xo_a1_clk,
546 [RPM_XO_A2] = &apq8064_xo_a2_clk,
549 static const struct rpm_clk_desc rpm_clk_apq8064 = {
550 .clks = apq8064_clks,
551 .num_clks = ARRAY_SIZE(apq8064_clks),
554 static const struct of_device_id rpm_clk_match_table[] = {
555 { .compatible = "qcom,rpmcc-msm8660", .data = &rpm_clk_msm8660 },
556 { .compatible = "qcom,rpmcc-apq8060", .data = &rpm_clk_msm8660 },
557 { .compatible = "qcom,rpmcc-apq8064", .data = &rpm_clk_apq8064 },
560 MODULE_DEVICE_TABLE(of, rpm_clk_match_table);
562 static struct clk_hw *qcom_rpm_clk_hw_get(struct of_phandle_args *clkspec,
563 void *data)
565 struct rpm_cc *rcc = data;
566 unsigned int idx = clkspec->args[0];
568 if (idx >= rcc->num_clks) {
569 pr_err("%s: invalid index %u\n", __func__, idx);
570 return ERR_PTR(-EINVAL);
573 return rcc->clks[idx] ? &rcc->clks[idx]->hw : ERR_PTR(-ENOENT);
576 static int rpm_clk_probe(struct platform_device *pdev)
578 struct rpm_cc *rcc;
579 int ret;
580 size_t num_clks, i;
581 struct qcom_rpm *rpm;
582 struct clk_rpm **rpm_clks;
583 const struct rpm_clk_desc *desc;
585 rpm = dev_get_drvdata(pdev->dev.parent);
586 if (!rpm) {
587 dev_err(&pdev->dev, "Unable to retrieve handle to RPM\n");
588 return -ENODEV;
591 desc = of_device_get_match_data(&pdev->dev);
592 if (!desc)
593 return -EINVAL;
595 rpm_clks = desc->clks;
596 num_clks = desc->num_clks;
598 rcc = devm_kzalloc(&pdev->dev, sizeof(*rcc), GFP_KERNEL);
599 if (!rcc)
600 return -ENOMEM;
602 rcc->clks = rpm_clks;
603 rcc->num_clks = num_clks;
604 mutex_init(&rcc->xo_lock);
606 for (i = 0; i < num_clks; i++) {
607 if (!rpm_clks[i])
608 continue;
610 rpm_clks[i]->rpm = rpm;
611 rpm_clks[i]->rpm_cc = rcc;
613 ret = clk_rpm_handoff(rpm_clks[i]);
614 if (ret)
615 goto err;
618 for (i = 0; i < num_clks; i++) {
619 if (!rpm_clks[i])
620 continue;
622 ret = devm_clk_hw_register(&pdev->dev, &rpm_clks[i]->hw);
623 if (ret)
624 goto err;
627 ret = of_clk_add_hw_provider(pdev->dev.of_node, qcom_rpm_clk_hw_get,
628 rcc);
629 if (ret)
630 goto err;
632 return 0;
633 err:
634 dev_err(&pdev->dev, "Error registering RPM Clock driver (%d)\n", ret);
635 return ret;
638 static int rpm_clk_remove(struct platform_device *pdev)
640 of_clk_del_provider(pdev->dev.of_node);
641 return 0;
644 static struct platform_driver rpm_clk_driver = {
645 .driver = {
646 .name = "qcom-clk-rpm",
647 .of_match_table = rpm_clk_match_table,
649 .probe = rpm_clk_probe,
650 .remove = rpm_clk_remove,
653 static int __init rpm_clk_init(void)
655 return platform_driver_register(&rpm_clk_driver);
657 core_initcall(rpm_clk_init);
659 static void __exit rpm_clk_exit(void)
661 platform_driver_unregister(&rpm_clk_driver);
663 module_exit(rpm_clk_exit);
665 MODULE_DESCRIPTION("Qualcomm RPM Clock Controller Driver");
666 MODULE_LICENSE("GPL v2");
667 MODULE_ALIAS("platform:qcom-clk-rpm");