2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/kernel.h>
15 #include <linux/bitops.h>
16 #include <linux/err.h>
17 #include <linux/bug.h>
18 #include <linux/export.h>
19 #include <linux/clk-provider.h>
20 #include <linux/delay.h>
21 #include <linux/regmap.h>
22 #include <linux/math64.h>
24 #include <asm/div64.h>
30 #define CMD_UPDATE BIT(0)
31 #define CMD_ROOT_EN BIT(1)
32 #define CMD_DIRTY_CFG BIT(4)
33 #define CMD_DIRTY_N BIT(5)
34 #define CMD_DIRTY_M BIT(6)
35 #define CMD_DIRTY_D BIT(7)
36 #define CMD_ROOT_OFF BIT(31)
39 #define CFG_SRC_DIV_SHIFT 0
40 #define CFG_SRC_SEL_SHIFT 8
41 #define CFG_SRC_SEL_MASK (0x7 << CFG_SRC_SEL_SHIFT)
42 #define CFG_MODE_SHIFT 12
43 #define CFG_MODE_MASK (0x3 << CFG_MODE_SHIFT)
44 #define CFG_MODE_DUAL_EDGE (0x2 << CFG_MODE_SHIFT)
55 static int clk_rcg2_is_enabled(struct clk_hw *hw)
57 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
61 ret = regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, &cmd);
65 return (cmd & CMD_ROOT_OFF) == 0;
68 static u8 clk_rcg2_get_parent(struct clk_hw *hw)
70 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
71 int num_parents = clk_hw_get_num_parents(hw);
75 ret = regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
79 cfg &= CFG_SRC_SEL_MASK;
80 cfg >>= CFG_SRC_SEL_SHIFT;
82 for (i = 0; i < num_parents; i++)
83 if (cfg == rcg->parent_map[i].cfg)
87 pr_debug("%s: Clock %s has invalid parent, using default.\n",
88 __func__, clk_hw_get_name(hw));
92 static int update_config(struct clk_rcg2 *rcg)
96 struct clk_hw *hw = &rcg->clkr.hw;
97 const char *name = clk_hw_get_name(hw);
99 ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
100 CMD_UPDATE, CMD_UPDATE);
104 /* Wait for update to take effect */
105 for (count = 500; count > 0; count--) {
106 ret = regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, &cmd);
109 if (!(cmd & CMD_UPDATE))
114 WARN(1, "%s: rcg didn't update its configuration.", name);
118 static int clk_rcg2_set_parent(struct clk_hw *hw, u8 index)
120 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
122 u32 cfg = rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
124 ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
125 CFG_SRC_SEL_MASK, cfg);
129 return update_config(rcg);
133 * Calculate m/n:d rate
136 * rate = ----------- x ---
140 calc_rate(unsigned long rate, u32 m, u32 n, u32 mode, u32 hid_div)
143 rate = mult_frac(rate, 2, hid_div + 1);
146 rate = mult_frac(rate, m, n);
152 clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
154 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
155 u32 cfg, hid_div, m = 0, n = 0, mode = 0, mask;
157 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
159 if (rcg->mnd_width) {
160 mask = BIT(rcg->mnd_width) - 1;
161 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + M_REG, &m);
163 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + N_REG, &n);
167 mode = cfg & CFG_MODE_MASK;
168 mode >>= CFG_MODE_SHIFT;
171 mask = BIT(rcg->hid_width) - 1;
172 hid_div = cfg >> CFG_SRC_DIV_SHIFT;
175 return calc_rate(parent_rate, m, n, mode, hid_div);
178 static int _freq_tbl_determine_rate(struct clk_hw *hw, const struct freq_tbl *f,
179 struct clk_rate_request *req,
180 enum freq_policy policy)
182 unsigned long clk_flags, rate = req->rate;
184 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
189 f = qcom_find_freq_floor(f, rate);
192 f = qcom_find_freq(f, rate);
201 index = qcom_find_src_index(hw, rcg->parent_map, f->src);
205 clk_flags = clk_hw_get_flags(hw);
206 p = clk_hw_get_parent_by_index(hw, index);
210 if (clk_flags & CLK_SET_RATE_PARENT) {
215 rate *= f->pre_div + 1;
225 rate = clk_hw_get_rate(p);
227 req->best_parent_hw = p;
228 req->best_parent_rate = rate;
234 static int clk_rcg2_determine_rate(struct clk_hw *hw,
235 struct clk_rate_request *req)
237 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
239 return _freq_tbl_determine_rate(hw, rcg->freq_tbl, req, CEIL);
242 static int clk_rcg2_determine_floor_rate(struct clk_hw *hw,
243 struct clk_rate_request *req)
245 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
247 return _freq_tbl_determine_rate(hw, rcg->freq_tbl, req, FLOOR);
250 static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
253 struct clk_hw *hw = &rcg->clkr.hw;
254 int ret, index = qcom_find_src_index(hw, rcg->parent_map, f->src);
259 if (rcg->mnd_width && f->n) {
260 mask = BIT(rcg->mnd_width) - 1;
261 ret = regmap_update_bits(rcg->clkr.regmap,
262 rcg->cmd_rcgr + M_REG, mask, f->m);
266 ret = regmap_update_bits(rcg->clkr.regmap,
267 rcg->cmd_rcgr + N_REG, mask, ~(f->n - f->m));
271 ret = regmap_update_bits(rcg->clkr.regmap,
272 rcg->cmd_rcgr + D_REG, mask, ~f->n);
277 mask = BIT(rcg->hid_width) - 1;
278 mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK;
279 cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
280 cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
281 if (rcg->mnd_width && f->n && (f->m != f->n))
282 cfg |= CFG_MODE_DUAL_EDGE;
283 ret = regmap_update_bits(rcg->clkr.regmap,
284 rcg->cmd_rcgr + CFG_REG, mask, cfg);
288 return update_config(rcg);
291 static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
292 enum freq_policy policy)
294 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
295 const struct freq_tbl *f;
299 f = qcom_find_freq_floor(rcg->freq_tbl, rate);
302 f = qcom_find_freq(rcg->freq_tbl, rate);
311 return clk_rcg2_configure(rcg, f);
314 static int clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
315 unsigned long parent_rate)
317 return __clk_rcg2_set_rate(hw, rate, CEIL);
320 static int clk_rcg2_set_floor_rate(struct clk_hw *hw, unsigned long rate,
321 unsigned long parent_rate)
323 return __clk_rcg2_set_rate(hw, rate, FLOOR);
326 static int clk_rcg2_set_rate_and_parent(struct clk_hw *hw,
327 unsigned long rate, unsigned long parent_rate, u8 index)
329 return __clk_rcg2_set_rate(hw, rate, CEIL);
332 static int clk_rcg2_set_floor_rate_and_parent(struct clk_hw *hw,
333 unsigned long rate, unsigned long parent_rate, u8 index)
335 return __clk_rcg2_set_rate(hw, rate, FLOOR);
338 const struct clk_ops clk_rcg2_ops = {
339 .is_enabled = clk_rcg2_is_enabled,
340 .get_parent = clk_rcg2_get_parent,
341 .set_parent = clk_rcg2_set_parent,
342 .recalc_rate = clk_rcg2_recalc_rate,
343 .determine_rate = clk_rcg2_determine_rate,
344 .set_rate = clk_rcg2_set_rate,
345 .set_rate_and_parent = clk_rcg2_set_rate_and_parent,
347 EXPORT_SYMBOL_GPL(clk_rcg2_ops);
349 const struct clk_ops clk_rcg2_floor_ops = {
350 .is_enabled = clk_rcg2_is_enabled,
351 .get_parent = clk_rcg2_get_parent,
352 .set_parent = clk_rcg2_set_parent,
353 .recalc_rate = clk_rcg2_recalc_rate,
354 .determine_rate = clk_rcg2_determine_floor_rate,
355 .set_rate = clk_rcg2_set_floor_rate,
356 .set_rate_and_parent = clk_rcg2_set_floor_rate_and_parent,
358 EXPORT_SYMBOL_GPL(clk_rcg2_floor_ops);
360 static int clk_rcg2_shared_force_enable(struct clk_hw *hw, unsigned long rate)
362 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
363 const char *name = clk_hw_get_name(hw);
366 /* force enable RCG */
367 ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
368 CMD_ROOT_EN, CMD_ROOT_EN);
372 /* wait for RCG to turn ON */
373 for (count = 500; count > 0; count--) {
374 ret = clk_rcg2_is_enabled(hw);
380 pr_err("%s: RCG did not turn on\n", name);
383 ret = __clk_rcg2_set_rate(hw, rate, CEIL);
387 /* clear force enable RCG */
388 return regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
392 static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate,
393 unsigned long parent_rate)
395 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
398 rcg->current_freq = rate;
400 if (!__clk_is_enabled(hw->clk))
403 return clk_rcg2_shared_force_enable(hw, rcg->current_freq);
407 clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
409 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
411 return rcg->current_freq = clk_rcg2_recalc_rate(hw, parent_rate);
414 static int clk_rcg2_shared_enable(struct clk_hw *hw)
416 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
418 return clk_rcg2_shared_force_enable(hw, rcg->current_freq);
421 static void clk_rcg2_shared_disable(struct clk_hw *hw)
423 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
425 /* switch to XO, which is the lowest entry in the freq table */
426 clk_rcg2_shared_set_rate(hw, rcg->freq_tbl[0].freq, 0);
429 const struct clk_ops clk_rcg2_shared_ops = {
430 .enable = clk_rcg2_shared_enable,
431 .disable = clk_rcg2_shared_disable,
432 .get_parent = clk_rcg2_get_parent,
433 .recalc_rate = clk_rcg2_shared_recalc_rate,
434 .determine_rate = clk_rcg2_determine_rate,
435 .set_rate = clk_rcg2_shared_set_rate,
437 EXPORT_SYMBOL_GPL(clk_rcg2_shared_ops);
444 static const struct frac_entry frac_table_675m[] = { /* link rate of 270M */
445 { 52, 295 }, /* 119 M */
446 { 11, 57 }, /* 130.25 M */
447 { 63, 307 }, /* 138.50 M */
448 { 11, 50 }, /* 148.50 M */
449 { 47, 206 }, /* 154 M */
450 { 31, 100 }, /* 205.25 M */
451 { 107, 269 }, /* 268.50 M */
455 static struct frac_entry frac_table_810m[] = { /* Link rate of 162M */
456 { 31, 211 }, /* 119 M */
457 { 32, 199 }, /* 130.25 M */
458 { 63, 307 }, /* 138.50 M */
459 { 11, 60 }, /* 148.50 M */
460 { 50, 263 }, /* 154 M */
461 { 31, 120 }, /* 205.25 M */
462 { 119, 359 }, /* 268.50 M */
466 static int clk_edp_pixel_set_rate(struct clk_hw *hw, unsigned long rate,
467 unsigned long parent_rate)
469 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
470 struct freq_tbl f = *rcg->freq_tbl;
471 const struct frac_entry *frac;
473 s64 src_rate = parent_rate;
475 u32 mask = BIT(rcg->hid_width) - 1;
478 if (src_rate == 810000000)
479 frac = frac_table_810m;
481 frac = frac_table_675m;
483 for (; frac->num; frac++) {
485 request *= frac->den;
486 request = div_s64(request, frac->num);
487 if ((src_rate < (request - delta)) ||
488 (src_rate > (request + delta)))
491 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
494 f.pre_div >>= CFG_SRC_DIV_SHIFT;
499 return clk_rcg2_configure(rcg, &f);
505 static int clk_edp_pixel_set_rate_and_parent(struct clk_hw *hw,
506 unsigned long rate, unsigned long parent_rate, u8 index)
508 /* Parent index is set statically in frequency table */
509 return clk_edp_pixel_set_rate(hw, rate, parent_rate);
512 static int clk_edp_pixel_determine_rate(struct clk_hw *hw,
513 struct clk_rate_request *req)
515 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
516 const struct freq_tbl *f = rcg->freq_tbl;
517 const struct frac_entry *frac;
520 u32 mask = BIT(rcg->hid_width) - 1;
522 int index = qcom_find_src_index(hw, rcg->parent_map, f->src);
524 /* Force the correct parent */
525 req->best_parent_hw = clk_hw_get_parent_by_index(hw, index);
526 req->best_parent_rate = clk_hw_get_rate(req->best_parent_hw);
528 if (req->best_parent_rate == 810000000)
529 frac = frac_table_810m;
531 frac = frac_table_675m;
533 for (; frac->num; frac++) {
535 request *= frac->den;
536 request = div_s64(request, frac->num);
537 if ((req->best_parent_rate < (request - delta)) ||
538 (req->best_parent_rate > (request + delta)))
541 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
543 hid_div >>= CFG_SRC_DIV_SHIFT;
546 req->rate = calc_rate(req->best_parent_rate,
547 frac->num, frac->den,
548 !!frac->den, hid_div);
555 const struct clk_ops clk_edp_pixel_ops = {
556 .is_enabled = clk_rcg2_is_enabled,
557 .get_parent = clk_rcg2_get_parent,
558 .set_parent = clk_rcg2_set_parent,
559 .recalc_rate = clk_rcg2_recalc_rate,
560 .set_rate = clk_edp_pixel_set_rate,
561 .set_rate_and_parent = clk_edp_pixel_set_rate_and_parent,
562 .determine_rate = clk_edp_pixel_determine_rate,
564 EXPORT_SYMBOL_GPL(clk_edp_pixel_ops);
566 static int clk_byte_determine_rate(struct clk_hw *hw,
567 struct clk_rate_request *req)
569 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
570 const struct freq_tbl *f = rcg->freq_tbl;
571 int index = qcom_find_src_index(hw, rcg->parent_map, f->src);
572 unsigned long parent_rate, div;
573 u32 mask = BIT(rcg->hid_width) - 1;
579 req->best_parent_hw = p = clk_hw_get_parent_by_index(hw, index);
580 req->best_parent_rate = parent_rate = clk_hw_round_rate(p, req->rate);
582 div = DIV_ROUND_UP((2 * parent_rate), req->rate) - 1;
583 div = min_t(u32, div, mask);
585 req->rate = calc_rate(parent_rate, 0, 0, 0, div);
590 static int clk_byte_set_rate(struct clk_hw *hw, unsigned long rate,
591 unsigned long parent_rate)
593 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
594 struct freq_tbl f = *rcg->freq_tbl;
596 u32 mask = BIT(rcg->hid_width) - 1;
598 div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
599 div = min_t(u32, div, mask);
603 return clk_rcg2_configure(rcg, &f);
606 static int clk_byte_set_rate_and_parent(struct clk_hw *hw,
607 unsigned long rate, unsigned long parent_rate, u8 index)
609 /* Parent index is set statically in frequency table */
610 return clk_byte_set_rate(hw, rate, parent_rate);
613 const struct clk_ops clk_byte_ops = {
614 .is_enabled = clk_rcg2_is_enabled,
615 .get_parent = clk_rcg2_get_parent,
616 .set_parent = clk_rcg2_set_parent,
617 .recalc_rate = clk_rcg2_recalc_rate,
618 .set_rate = clk_byte_set_rate,
619 .set_rate_and_parent = clk_byte_set_rate_and_parent,
620 .determine_rate = clk_byte_determine_rate,
622 EXPORT_SYMBOL_GPL(clk_byte_ops);
624 static int clk_byte2_determine_rate(struct clk_hw *hw,
625 struct clk_rate_request *req)
627 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
628 unsigned long parent_rate, div;
629 u32 mask = BIT(rcg->hid_width) - 1;
631 unsigned long rate = req->rate;
636 p = req->best_parent_hw;
637 req->best_parent_rate = parent_rate = clk_hw_round_rate(p, rate);
639 div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
640 div = min_t(u32, div, mask);
642 req->rate = calc_rate(parent_rate, 0, 0, 0, div);
647 static int clk_byte2_set_rate(struct clk_hw *hw, unsigned long rate,
648 unsigned long parent_rate)
650 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
651 struct freq_tbl f = { 0 };
653 int i, num_parents = clk_hw_get_num_parents(hw);
654 u32 mask = BIT(rcg->hid_width) - 1;
657 div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
658 div = min_t(u32, div, mask);
662 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
663 cfg &= CFG_SRC_SEL_MASK;
664 cfg >>= CFG_SRC_SEL_SHIFT;
666 for (i = 0; i < num_parents; i++) {
667 if (cfg == rcg->parent_map[i].cfg) {
668 f.src = rcg->parent_map[i].src;
669 return clk_rcg2_configure(rcg, &f);
676 static int clk_byte2_set_rate_and_parent(struct clk_hw *hw,
677 unsigned long rate, unsigned long parent_rate, u8 index)
679 /* Read the hardware to determine parent during set_rate */
680 return clk_byte2_set_rate(hw, rate, parent_rate);
683 const struct clk_ops clk_byte2_ops = {
684 .is_enabled = clk_rcg2_is_enabled,
685 .get_parent = clk_rcg2_get_parent,
686 .set_parent = clk_rcg2_set_parent,
687 .recalc_rate = clk_rcg2_recalc_rate,
688 .set_rate = clk_byte2_set_rate,
689 .set_rate_and_parent = clk_byte2_set_rate_and_parent,
690 .determine_rate = clk_byte2_determine_rate,
692 EXPORT_SYMBOL_GPL(clk_byte2_ops);
694 static const struct frac_entry frac_table_pixel[] = {
703 static int clk_pixel_determine_rate(struct clk_hw *hw,
704 struct clk_rate_request *req)
706 unsigned long request, src_rate;
708 const struct frac_entry *frac = frac_table_pixel;
710 for (; frac->num; frac++) {
711 request = (req->rate * frac->den) / frac->num;
713 src_rate = clk_hw_round_rate(req->best_parent_hw, request);
714 if ((src_rate < (request - delta)) ||
715 (src_rate > (request + delta)))
718 req->best_parent_rate = src_rate;
719 req->rate = (src_rate * frac->num) / frac->den;
726 static int clk_pixel_set_rate(struct clk_hw *hw, unsigned long rate,
727 unsigned long parent_rate)
729 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
730 struct freq_tbl f = { 0 };
731 const struct frac_entry *frac = frac_table_pixel;
732 unsigned long request;
734 u32 mask = BIT(rcg->hid_width) - 1;
736 int i, num_parents = clk_hw_get_num_parents(hw);
738 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
739 cfg &= CFG_SRC_SEL_MASK;
740 cfg >>= CFG_SRC_SEL_SHIFT;
742 for (i = 0; i < num_parents; i++)
743 if (cfg == rcg->parent_map[i].cfg) {
744 f.src = rcg->parent_map[i].src;
748 for (; frac->num; frac++) {
749 request = (rate * frac->den) / frac->num;
751 if ((parent_rate < (request - delta)) ||
752 (parent_rate > (request + delta)))
755 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
758 f.pre_div >>= CFG_SRC_DIV_SHIFT;
763 return clk_rcg2_configure(rcg, &f);
768 static int clk_pixel_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
769 unsigned long parent_rate, u8 index)
771 return clk_pixel_set_rate(hw, rate, parent_rate);
774 const struct clk_ops clk_pixel_ops = {
775 .is_enabled = clk_rcg2_is_enabled,
776 .get_parent = clk_rcg2_get_parent,
777 .set_parent = clk_rcg2_set_parent,
778 .recalc_rate = clk_rcg2_recalc_rate,
779 .set_rate = clk_pixel_set_rate,
780 .set_rate_and_parent = clk_pixel_set_rate_and_parent,
781 .determine_rate = clk_pixel_determine_rate,
783 EXPORT_SYMBOL_GPL(clk_pixel_ops);
785 static int clk_gfx3d_determine_rate(struct clk_hw *hw,
786 struct clk_rate_request *req)
788 struct clk_rate_request parent_req = { };
789 struct clk_hw *p2, *p8, *p9, *xo;
790 unsigned long p9_rate;
793 xo = clk_hw_get_parent_by_index(hw, 0);
794 if (req->rate == clk_hw_get_rate(xo)) {
795 req->best_parent_hw = xo;
799 p9 = clk_hw_get_parent_by_index(hw, 2);
800 p2 = clk_hw_get_parent_by_index(hw, 3);
801 p8 = clk_hw_get_parent_by_index(hw, 4);
803 /* PLL9 is a fixed rate PLL */
804 p9_rate = clk_hw_get_rate(p9);
806 parent_req.rate = req->rate = min(req->rate, p9_rate);
807 if (req->rate == p9_rate) {
808 req->rate = req->best_parent_rate = p9_rate;
809 req->best_parent_hw = p9;
813 if (req->best_parent_hw == p9) {
814 /* Are we going back to a previously used rate? */
815 if (clk_hw_get_rate(p8) == req->rate)
816 req->best_parent_hw = p8;
818 req->best_parent_hw = p2;
819 } else if (req->best_parent_hw == p8) {
820 req->best_parent_hw = p2;
822 req->best_parent_hw = p8;
825 ret = __clk_determine_rate(req->best_parent_hw, &parent_req);
829 req->rate = req->best_parent_rate = parent_req.rate;
834 static int clk_gfx3d_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
835 unsigned long parent_rate, u8 index)
837 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
841 /* Just mux it, we don't use the division or m/n hardware */
842 cfg = rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
843 ret = regmap_write(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, cfg);
847 return update_config(rcg);
850 static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate,
851 unsigned long parent_rate)
854 * We should never get here; clk_gfx3d_determine_rate() should always
855 * make us use a different parent than what we're currently using, so
856 * clk_gfx3d_set_rate_and_parent() should always be called.
861 const struct clk_ops clk_gfx3d_ops = {
862 .is_enabled = clk_rcg2_is_enabled,
863 .get_parent = clk_rcg2_get_parent,
864 .set_parent = clk_rcg2_set_parent,
865 .recalc_rate = clk_rcg2_recalc_rate,
866 .set_rate = clk_gfx3d_set_rate,
867 .set_rate_and_parent = clk_gfx3d_set_rate_and_parent,
868 .determine_rate = clk_gfx3d_determine_rate,
870 EXPORT_SYMBOL_GPL(clk_gfx3d_ops);