1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016, Linaro Limited
4 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
7 #include <linux/clk-provider.h>
9 #include <linux/export.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/mutex.h>
14 #include <linux/mfd/qcom_rpm.h>
16 #include <linux/of_device.h>
17 #include <linux/platform_device.h>
19 #include <dt-bindings/mfd/qcom-rpm.h>
20 #include <dt-bindings/clock/qcom,rpmcc.h>
22 #define QCOM_RPM_MISC_CLK_TYPE 0x306b6c63
23 #define QCOM_RPM_SCALING_ENABLE_ID 0x2
24 #define QCOM_RPM_XO_MODE_ON 0x2
26 #define DEFINE_CLK_RPM(_platform, _name, _active, r_id) \
27 static struct clk_rpm _platform##_##_active; \
28 static struct clk_rpm _platform##_##_name = { \
29 .rpm_clk_id = (r_id), \
30 .peer = &_platform##_##_active, \
32 .hw.init = &(struct clk_init_data){ \
33 .ops = &clk_rpm_ops, \
35 .parent_names = (const char *[]){ "pxo_board" }, \
39 static struct clk_rpm _platform##_##_active = { \
40 .rpm_clk_id = (r_id), \
41 .peer = &_platform##_##_name, \
42 .active_only = true, \
44 .hw.init = &(struct clk_init_data){ \
45 .ops = &clk_rpm_ops, \
47 .parent_names = (const char *[]){ "pxo_board" }, \
52 #define DEFINE_CLK_RPM_XO_BUFFER(_platform, _name, _active, offset) \
53 static struct clk_rpm _platform##_##_name = { \
54 .rpm_clk_id = QCOM_RPM_CXO_BUFFERS, \
55 .xo_offset = (offset), \
56 .hw.init = &(struct clk_init_data){ \
57 .ops = &clk_rpm_xo_ops, \
59 .parent_names = (const char *[]){ "cxo_board" }, \
64 #define DEFINE_CLK_RPM_FIXED(_platform, _name, _active, r_id, r) \
65 static struct clk_rpm _platform##_##_name = { \
66 .rpm_clk_id = (r_id), \
68 .hw.init = &(struct clk_init_data){ \
69 .ops = &clk_rpm_fixed_ops, \
71 .parent_names = (const char *[]){ "pxo" }, \
76 #define DEFINE_CLK_RPM_PXO_BRANCH(_platform, _name, _active, r_id, r) \
77 static struct clk_rpm _platform##_##_active; \
78 static struct clk_rpm _platform##_##_name = { \
79 .rpm_clk_id = (r_id), \
80 .active_only = true, \
81 .peer = &_platform##_##_active, \
84 .hw.init = &(struct clk_init_data){ \
85 .ops = &clk_rpm_branch_ops, \
87 .parent_names = (const char *[]){ "pxo_board" }, \
91 static struct clk_rpm _platform##_##_active = { \
92 .rpm_clk_id = (r_id), \
93 .peer = &_platform##_##_name, \
96 .hw.init = &(struct clk_init_data){ \
97 .ops = &clk_rpm_branch_ops, \
99 .parent_names = (const char *[]){ "pxo_board" }, \
104 #define DEFINE_CLK_RPM_CXO_BRANCH(_platform, _name, _active, r_id, r) \
105 static struct clk_rpm _platform##_##_active; \
106 static struct clk_rpm _platform##_##_name = { \
107 .rpm_clk_id = (r_id), \
108 .peer = &_platform##_##_active, \
111 .hw.init = &(struct clk_init_data){ \
112 .ops = &clk_rpm_branch_ops, \
114 .parent_names = (const char *[]){ "cxo_board" }, \
118 static struct clk_rpm _platform##_##_active = { \
119 .rpm_clk_id = (r_id), \
120 .active_only = true, \
121 .peer = &_platform##_##_name, \
124 .hw.init = &(struct clk_init_data){ \
125 .ops = &clk_rpm_branch_ops, \
127 .parent_names = (const char *[]){ "cxo_board" }, \
132 #define to_clk_rpm(_hw) container_of(_hw, struct clk_rpm, hw)
137 const int rpm_clk_id
;
139 const bool active_only
;
143 struct clk_rpm
*peer
;
145 struct qcom_rpm
*rpm
;
146 struct rpm_cc
*rpm_cc
;
150 struct qcom_rpm
*rpm
;
151 struct clk_rpm
**clks
;
154 struct mutex xo_lock
;
157 struct rpm_clk_desc
{
158 struct clk_rpm
**clks
;
162 static DEFINE_MUTEX(rpm_clk_lock
);
164 static int clk_rpm_handoff(struct clk_rpm
*r
)
170 * The vendor tree simply reads the status for this
173 if (r
->rpm_clk_id
== QCOM_RPM_PLL_4
||
174 r
->rpm_clk_id
== QCOM_RPM_CXO_BUFFERS
)
177 ret
= qcom_rpm_write(r
->rpm
, QCOM_RPM_ACTIVE_STATE
,
178 r
->rpm_clk_id
, &value
, 1);
181 ret
= qcom_rpm_write(r
->rpm
, QCOM_RPM_SLEEP_STATE
,
182 r
->rpm_clk_id
, &value
, 1);
189 static int clk_rpm_set_rate_active(struct clk_rpm
*r
, unsigned long rate
)
191 u32 value
= DIV_ROUND_UP(rate
, 1000); /* to kHz */
193 return qcom_rpm_write(r
->rpm
, QCOM_RPM_ACTIVE_STATE
,
194 r
->rpm_clk_id
, &value
, 1);
197 static int clk_rpm_set_rate_sleep(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_SLEEP_STATE
,
202 r
->rpm_clk_id
, &value
, 1);
205 static void to_active_sleep(struct clk_rpm
*r
, unsigned long rate
,
206 unsigned long *active
, unsigned long *sleep
)
211 * Active-only clocks don't care what the rate is during sleep. So,
212 * they vote for zero.
220 static int clk_rpm_prepare(struct clk_hw
*hw
)
222 struct clk_rpm
*r
= to_clk_rpm(hw
);
223 struct clk_rpm
*peer
= r
->peer
;
224 unsigned long this_rate
= 0, this_sleep_rate
= 0;
225 unsigned long peer_rate
= 0, peer_sleep_rate
= 0;
226 unsigned long active_rate
, sleep_rate
;
229 mutex_lock(&rpm_clk_lock
);
231 /* Don't send requests to the RPM if the rate has not been set. */
235 to_active_sleep(r
, r
->rate
, &this_rate
, &this_sleep_rate
);
237 /* Take peer clock's rate into account only if it's enabled. */
239 to_active_sleep(peer
, peer
->rate
,
240 &peer_rate
, &peer_sleep_rate
);
242 active_rate
= max(this_rate
, peer_rate
);
245 active_rate
= !!active_rate
;
247 ret
= clk_rpm_set_rate_active(r
, active_rate
);
251 sleep_rate
= max(this_sleep_rate
, peer_sleep_rate
);
253 sleep_rate
= !!sleep_rate
;
255 ret
= clk_rpm_set_rate_sleep(r
, sleep_rate
);
257 /* Undo the active set vote and restore it */
258 ret
= clk_rpm_set_rate_active(r
, peer_rate
);
264 mutex_unlock(&rpm_clk_lock
);
269 static void clk_rpm_unprepare(struct clk_hw
*hw
)
271 struct clk_rpm
*r
= to_clk_rpm(hw
);
272 struct clk_rpm
*peer
= r
->peer
;
273 unsigned long peer_rate
= 0, peer_sleep_rate
= 0;
274 unsigned long active_rate
, sleep_rate
;
277 mutex_lock(&rpm_clk_lock
);
282 /* Take peer clock's rate into account only if it's enabled. */
284 to_active_sleep(peer
, peer
->rate
, &peer_rate
,
287 active_rate
= r
->branch
? !!peer_rate
: peer_rate
;
288 ret
= clk_rpm_set_rate_active(r
, active_rate
);
292 sleep_rate
= r
->branch
? !!peer_sleep_rate
: peer_sleep_rate
;
293 ret
= clk_rpm_set_rate_sleep(r
, sleep_rate
);
300 mutex_unlock(&rpm_clk_lock
);
303 static int clk_rpm_xo_prepare(struct clk_hw
*hw
)
305 struct clk_rpm
*r
= to_clk_rpm(hw
);
306 struct rpm_cc
*rcc
= r
->rpm_cc
;
307 int ret
, clk_id
= r
->rpm_clk_id
;
310 mutex_lock(&rcc
->xo_lock
);
312 value
= rcc
->xo_buffer_value
| (QCOM_RPM_XO_MODE_ON
<< r
->xo_offset
);
313 ret
= qcom_rpm_write(r
->rpm
, QCOM_RPM_ACTIVE_STATE
, clk_id
, &value
, 1);
316 rcc
->xo_buffer_value
= value
;
319 mutex_unlock(&rcc
->xo_lock
);
324 static void clk_rpm_xo_unprepare(struct clk_hw
*hw
)
326 struct clk_rpm
*r
= to_clk_rpm(hw
);
327 struct rpm_cc
*rcc
= r
->rpm_cc
;
328 int ret
, clk_id
= r
->rpm_clk_id
;
331 mutex_lock(&rcc
->xo_lock
);
333 value
= rcc
->xo_buffer_value
& ~(QCOM_RPM_XO_MODE_ON
<< r
->xo_offset
);
334 ret
= qcom_rpm_write(r
->rpm
, QCOM_RPM_ACTIVE_STATE
, clk_id
, &value
, 1);
337 rcc
->xo_buffer_value
= value
;
340 mutex_unlock(&rcc
->xo_lock
);
343 static int clk_rpm_fixed_prepare(struct clk_hw
*hw
)
345 struct clk_rpm
*r
= to_clk_rpm(hw
);
349 ret
= qcom_rpm_write(r
->rpm
, QCOM_RPM_ACTIVE_STATE
,
350 r
->rpm_clk_id
, &value
, 1);
357 static void clk_rpm_fixed_unprepare(struct clk_hw
*hw
)
359 struct clk_rpm
*r
= to_clk_rpm(hw
);
363 ret
= qcom_rpm_write(r
->rpm
, QCOM_RPM_ACTIVE_STATE
,
364 r
->rpm_clk_id
, &value
, 1);
369 static int clk_rpm_set_rate(struct clk_hw
*hw
,
370 unsigned long rate
, unsigned long parent_rate
)
372 struct clk_rpm
*r
= to_clk_rpm(hw
);
373 struct clk_rpm
*peer
= r
->peer
;
374 unsigned long active_rate
, sleep_rate
;
375 unsigned long this_rate
= 0, this_sleep_rate
= 0;
376 unsigned long peer_rate
= 0, peer_sleep_rate
= 0;
379 mutex_lock(&rpm_clk_lock
);
384 to_active_sleep(r
, rate
, &this_rate
, &this_sleep_rate
);
386 /* Take peer clock's rate into account only if it's enabled. */
388 to_active_sleep(peer
, peer
->rate
,
389 &peer_rate
, &peer_sleep_rate
);
391 active_rate
= max(this_rate
, peer_rate
);
392 ret
= clk_rpm_set_rate_active(r
, active_rate
);
396 sleep_rate
= max(this_sleep_rate
, peer_sleep_rate
);
397 ret
= clk_rpm_set_rate_sleep(r
, sleep_rate
);
404 mutex_unlock(&rpm_clk_lock
);
409 static long clk_rpm_round_rate(struct clk_hw
*hw
, unsigned long rate
,
410 unsigned long *parent_rate
)
413 * RPM handles rate rounding and we don't have a way to
414 * know what the rate will be, so just return whatever
420 static unsigned long clk_rpm_recalc_rate(struct clk_hw
*hw
,
421 unsigned long parent_rate
)
423 struct clk_rpm
*r
= to_clk_rpm(hw
);
426 * RPM handles rate rounding and we don't have a way to
427 * know what the rate will be, so just return whatever
433 static const struct clk_ops clk_rpm_xo_ops
= {
434 .prepare
= clk_rpm_xo_prepare
,
435 .unprepare
= clk_rpm_xo_unprepare
,
438 static const struct clk_ops clk_rpm_fixed_ops
= {
439 .prepare
= clk_rpm_fixed_prepare
,
440 .unprepare
= clk_rpm_fixed_unprepare
,
441 .round_rate
= clk_rpm_round_rate
,
442 .recalc_rate
= clk_rpm_recalc_rate
,
445 static const struct clk_ops clk_rpm_ops
= {
446 .prepare
= clk_rpm_prepare
,
447 .unprepare
= clk_rpm_unprepare
,
448 .set_rate
= clk_rpm_set_rate
,
449 .round_rate
= clk_rpm_round_rate
,
450 .recalc_rate
= clk_rpm_recalc_rate
,
453 static const struct clk_ops clk_rpm_branch_ops
= {
454 .prepare
= clk_rpm_prepare
,
455 .unprepare
= clk_rpm_unprepare
,
456 .round_rate
= clk_rpm_round_rate
,
457 .recalc_rate
= clk_rpm_recalc_rate
,
460 /* MSM8660/APQ8060 */
461 DEFINE_CLK_RPM(msm8660
, afab_clk
, afab_a_clk
, QCOM_RPM_APPS_FABRIC_CLK
);
462 DEFINE_CLK_RPM(msm8660
, sfab_clk
, sfab_a_clk
, QCOM_RPM_SYS_FABRIC_CLK
);
463 DEFINE_CLK_RPM(msm8660
, mmfab_clk
, mmfab_a_clk
, QCOM_RPM_MM_FABRIC_CLK
);
464 DEFINE_CLK_RPM(msm8660
, daytona_clk
, daytona_a_clk
, QCOM_RPM_DAYTONA_FABRIC_CLK
);
465 DEFINE_CLK_RPM(msm8660
, sfpb_clk
, sfpb_a_clk
, QCOM_RPM_SFPB_CLK
);
466 DEFINE_CLK_RPM(msm8660
, cfpb_clk
, cfpb_a_clk
, QCOM_RPM_CFPB_CLK
);
467 DEFINE_CLK_RPM(msm8660
, mmfpb_clk
, mmfpb_a_clk
, QCOM_RPM_MMFPB_CLK
);
468 DEFINE_CLK_RPM(msm8660
, smi_clk
, smi_a_clk
, QCOM_RPM_SMI_CLK
);
469 DEFINE_CLK_RPM(msm8660
, ebi1_clk
, ebi1_a_clk
, QCOM_RPM_EBI1_CLK
);
470 DEFINE_CLK_RPM_FIXED(msm8660
, pll4_clk
, pll4_a_clk
, QCOM_RPM_PLL_4
, 540672000);
472 static struct clk_rpm
*msm8660_clks
[] = {
473 [RPM_APPS_FABRIC_CLK
] = &msm8660_afab_clk
,
474 [RPM_APPS_FABRIC_A_CLK
] = &msm8660_afab_a_clk
,
475 [RPM_SYS_FABRIC_CLK
] = &msm8660_sfab_clk
,
476 [RPM_SYS_FABRIC_A_CLK
] = &msm8660_sfab_a_clk
,
477 [RPM_MM_FABRIC_CLK
] = &msm8660_mmfab_clk
,
478 [RPM_MM_FABRIC_A_CLK
] = &msm8660_mmfab_a_clk
,
479 [RPM_DAYTONA_FABRIC_CLK
] = &msm8660_daytona_clk
,
480 [RPM_DAYTONA_FABRIC_A_CLK
] = &msm8660_daytona_a_clk
,
481 [RPM_SFPB_CLK
] = &msm8660_sfpb_clk
,
482 [RPM_SFPB_A_CLK
] = &msm8660_sfpb_a_clk
,
483 [RPM_CFPB_CLK
] = &msm8660_cfpb_clk
,
484 [RPM_CFPB_A_CLK
] = &msm8660_cfpb_a_clk
,
485 [RPM_MMFPB_CLK
] = &msm8660_mmfpb_clk
,
486 [RPM_MMFPB_A_CLK
] = &msm8660_mmfpb_a_clk
,
487 [RPM_SMI_CLK
] = &msm8660_smi_clk
,
488 [RPM_SMI_A_CLK
] = &msm8660_smi_a_clk
,
489 [RPM_EBI1_CLK
] = &msm8660_ebi1_clk
,
490 [RPM_EBI1_A_CLK
] = &msm8660_ebi1_a_clk
,
491 [RPM_PLL4_CLK
] = &msm8660_pll4_clk
,
494 static const struct rpm_clk_desc rpm_clk_msm8660
= {
495 .clks
= msm8660_clks
,
496 .num_clks
= ARRAY_SIZE(msm8660_clks
),
500 DEFINE_CLK_RPM(apq8064
, afab_clk
, afab_a_clk
, QCOM_RPM_APPS_FABRIC_CLK
);
501 DEFINE_CLK_RPM(apq8064
, cfpb_clk
, cfpb_a_clk
, QCOM_RPM_CFPB_CLK
);
502 DEFINE_CLK_RPM(apq8064
, daytona_clk
, daytona_a_clk
, QCOM_RPM_DAYTONA_FABRIC_CLK
);
503 DEFINE_CLK_RPM(apq8064
, ebi1_clk
, ebi1_a_clk
, QCOM_RPM_EBI1_CLK
);
504 DEFINE_CLK_RPM(apq8064
, mmfab_clk
, mmfab_a_clk
, QCOM_RPM_MM_FABRIC_CLK
);
505 DEFINE_CLK_RPM(apq8064
, mmfpb_clk
, mmfpb_a_clk
, QCOM_RPM_MMFPB_CLK
);
506 DEFINE_CLK_RPM(apq8064
, sfab_clk
, sfab_a_clk
, QCOM_RPM_SYS_FABRIC_CLK
);
507 DEFINE_CLK_RPM(apq8064
, sfpb_clk
, sfpb_a_clk
, QCOM_RPM_SFPB_CLK
);
508 DEFINE_CLK_RPM(apq8064
, qdss_clk
, qdss_a_clk
, QCOM_RPM_QDSS_CLK
);
509 DEFINE_CLK_RPM_XO_BUFFER(apq8064
, xo_d0_clk
, xo_d0_a_clk
, 0);
510 DEFINE_CLK_RPM_XO_BUFFER(apq8064
, xo_d1_clk
, xo_d1_a_clk
, 8);
511 DEFINE_CLK_RPM_XO_BUFFER(apq8064
, xo_a0_clk
, xo_a0_a_clk
, 16);
512 DEFINE_CLK_RPM_XO_BUFFER(apq8064
, xo_a1_clk
, xo_a1_a_clk
, 24);
513 DEFINE_CLK_RPM_XO_BUFFER(apq8064
, xo_a2_clk
, xo_a2_a_clk
, 28);
515 static struct clk_rpm
*apq8064_clks
[] = {
516 [RPM_APPS_FABRIC_CLK
] = &apq8064_afab_clk
,
517 [RPM_APPS_FABRIC_A_CLK
] = &apq8064_afab_a_clk
,
518 [RPM_CFPB_CLK
] = &apq8064_cfpb_clk
,
519 [RPM_CFPB_A_CLK
] = &apq8064_cfpb_a_clk
,
520 [RPM_DAYTONA_FABRIC_CLK
] = &apq8064_daytona_clk
,
521 [RPM_DAYTONA_FABRIC_A_CLK
] = &apq8064_daytona_a_clk
,
522 [RPM_EBI1_CLK
] = &apq8064_ebi1_clk
,
523 [RPM_EBI1_A_CLK
] = &apq8064_ebi1_a_clk
,
524 [RPM_MM_FABRIC_CLK
] = &apq8064_mmfab_clk
,
525 [RPM_MM_FABRIC_A_CLK
] = &apq8064_mmfab_a_clk
,
526 [RPM_MMFPB_CLK
] = &apq8064_mmfpb_clk
,
527 [RPM_MMFPB_A_CLK
] = &apq8064_mmfpb_a_clk
,
528 [RPM_SYS_FABRIC_CLK
] = &apq8064_sfab_clk
,
529 [RPM_SYS_FABRIC_A_CLK
] = &apq8064_sfab_a_clk
,
530 [RPM_SFPB_CLK
] = &apq8064_sfpb_clk
,
531 [RPM_SFPB_A_CLK
] = &apq8064_sfpb_a_clk
,
532 [RPM_QDSS_CLK
] = &apq8064_qdss_clk
,
533 [RPM_QDSS_A_CLK
] = &apq8064_qdss_a_clk
,
534 [RPM_XO_D0
] = &apq8064_xo_d0_clk
,
535 [RPM_XO_D1
] = &apq8064_xo_d1_clk
,
536 [RPM_XO_A0
] = &apq8064_xo_a0_clk
,
537 [RPM_XO_A1
] = &apq8064_xo_a1_clk
,
538 [RPM_XO_A2
] = &apq8064_xo_a2_clk
,
541 static const struct rpm_clk_desc rpm_clk_apq8064
= {
542 .clks
= apq8064_clks
,
543 .num_clks
= ARRAY_SIZE(apq8064_clks
),
547 DEFINE_CLK_RPM(ipq806x
, afab_clk
, afab_a_clk
, QCOM_RPM_APPS_FABRIC_CLK
);
548 DEFINE_CLK_RPM(ipq806x
, cfpb_clk
, cfpb_a_clk
, QCOM_RPM_CFPB_CLK
);
549 DEFINE_CLK_RPM(ipq806x
, daytona_clk
, daytona_a_clk
, QCOM_RPM_DAYTONA_FABRIC_CLK
);
550 DEFINE_CLK_RPM(ipq806x
, ebi1_clk
, ebi1_a_clk
, QCOM_RPM_EBI1_CLK
);
551 DEFINE_CLK_RPM(ipq806x
, sfab_clk
, sfab_a_clk
, QCOM_RPM_SYS_FABRIC_CLK
);
552 DEFINE_CLK_RPM(ipq806x
, sfpb_clk
, sfpb_a_clk
, QCOM_RPM_SFPB_CLK
);
553 DEFINE_CLK_RPM(ipq806x
, nss_fabric_0_clk
, nss_fabric_0_a_clk
, QCOM_RPM_NSS_FABRIC_0_CLK
);
554 DEFINE_CLK_RPM(ipq806x
, nss_fabric_1_clk
, nss_fabric_1_a_clk
, QCOM_RPM_NSS_FABRIC_1_CLK
);
556 static struct clk_rpm
*ipq806x_clks
[] = {
557 [RPM_APPS_FABRIC_CLK
] = &ipq806x_afab_clk
,
558 [RPM_APPS_FABRIC_A_CLK
] = &ipq806x_afab_a_clk
,
559 [RPM_CFPB_CLK
] = &ipq806x_cfpb_clk
,
560 [RPM_CFPB_A_CLK
] = &ipq806x_cfpb_a_clk
,
561 [RPM_DAYTONA_FABRIC_CLK
] = &ipq806x_daytona_clk
,
562 [RPM_DAYTONA_FABRIC_A_CLK
] = &ipq806x_daytona_a_clk
,
563 [RPM_EBI1_CLK
] = &ipq806x_ebi1_clk
,
564 [RPM_EBI1_A_CLK
] = &ipq806x_ebi1_a_clk
,
565 [RPM_SYS_FABRIC_CLK
] = &ipq806x_sfab_clk
,
566 [RPM_SYS_FABRIC_A_CLK
] = &ipq806x_sfab_a_clk
,
567 [RPM_SFPB_CLK
] = &ipq806x_sfpb_clk
,
568 [RPM_SFPB_A_CLK
] = &ipq806x_sfpb_a_clk
,
569 [RPM_NSS_FABRIC_0_CLK
] = &ipq806x_nss_fabric_0_clk
,
570 [RPM_NSS_FABRIC_0_A_CLK
] = &ipq806x_nss_fabric_0_a_clk
,
571 [RPM_NSS_FABRIC_1_CLK
] = &ipq806x_nss_fabric_1_clk
,
572 [RPM_NSS_FABRIC_1_A_CLK
] = &ipq806x_nss_fabric_1_a_clk
,
575 static const struct rpm_clk_desc rpm_clk_ipq806x
= {
576 .clks
= ipq806x_clks
,
577 .num_clks
= ARRAY_SIZE(ipq806x_clks
),
580 static const struct of_device_id rpm_clk_match_table
[] = {
581 { .compatible
= "qcom,rpmcc-msm8660", .data
= &rpm_clk_msm8660
},
582 { .compatible
= "qcom,rpmcc-apq8060", .data
= &rpm_clk_msm8660
},
583 { .compatible
= "qcom,rpmcc-apq8064", .data
= &rpm_clk_apq8064
},
584 { .compatible
= "qcom,rpmcc-ipq806x", .data
= &rpm_clk_ipq806x
},
587 MODULE_DEVICE_TABLE(of
, rpm_clk_match_table
);
589 static struct clk_hw
*qcom_rpm_clk_hw_get(struct of_phandle_args
*clkspec
,
592 struct rpm_cc
*rcc
= data
;
593 unsigned int idx
= clkspec
->args
[0];
595 if (idx
>= rcc
->num_clks
) {
596 pr_err("%s: invalid index %u\n", __func__
, idx
);
597 return ERR_PTR(-EINVAL
);
600 return rcc
->clks
[idx
] ? &rcc
->clks
[idx
]->hw
: ERR_PTR(-ENOENT
);
603 static int rpm_clk_probe(struct platform_device
*pdev
)
608 struct qcom_rpm
*rpm
;
609 struct clk_rpm
**rpm_clks
;
610 const struct rpm_clk_desc
*desc
;
612 rpm
= dev_get_drvdata(pdev
->dev
.parent
);
614 dev_err(&pdev
->dev
, "Unable to retrieve handle to RPM\n");
618 desc
= of_device_get_match_data(&pdev
->dev
);
622 rpm_clks
= desc
->clks
;
623 num_clks
= desc
->num_clks
;
625 rcc
= devm_kzalloc(&pdev
->dev
, sizeof(*rcc
), GFP_KERNEL
);
629 rcc
->clks
= rpm_clks
;
630 rcc
->num_clks
= num_clks
;
631 mutex_init(&rcc
->xo_lock
);
633 for (i
= 0; i
< num_clks
; i
++) {
637 rpm_clks
[i
]->rpm
= rpm
;
638 rpm_clks
[i
]->rpm_cc
= rcc
;
640 ret
= clk_rpm_handoff(rpm_clks
[i
]);
645 for (i
= 0; i
< num_clks
; i
++) {
649 ret
= devm_clk_hw_register(&pdev
->dev
, &rpm_clks
[i
]->hw
);
654 ret
= of_clk_add_hw_provider(pdev
->dev
.of_node
, qcom_rpm_clk_hw_get
,
661 dev_err(&pdev
->dev
, "Error registering RPM Clock driver (%d)\n", ret
);
665 static int rpm_clk_remove(struct platform_device
*pdev
)
667 of_clk_del_provider(pdev
->dev
.of_node
);
671 static struct platform_driver rpm_clk_driver
= {
673 .name
= "qcom-clk-rpm",
674 .of_match_table
= rpm_clk_match_table
,
676 .probe
= rpm_clk_probe
,
677 .remove
= rpm_clk_remove
,
680 static int __init
rpm_clk_init(void)
682 return platform_driver_register(&rpm_clk_driver
);
684 core_initcall(rpm_clk_init
);
686 static void __exit
rpm_clk_exit(void)
688 platform_driver_unregister(&rpm_clk_driver
);
690 module_exit(rpm_clk_exit
);
692 MODULE_DESCRIPTION("Qualcomm RPM Clock Controller Driver");
693 MODULE_LICENSE("GPL v2");
694 MODULE_ALIAS("platform:qcom-clk-rpm");