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)
158 clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
160 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
161 u32 cfg, hid_div, m = 0, n = 0, mode = 0, mask;
163 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
165 if (rcg->mnd_width) {
166 mask = BIT(rcg->mnd_width) - 1;
167 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + M_REG, &m);
169 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + N_REG, &n);
173 mode = cfg & CFG_MODE_MASK;
174 mode >>= CFG_MODE_SHIFT;
177 mask = BIT(rcg->hid_width) - 1;
178 hid_div = cfg >> CFG_SRC_DIV_SHIFT;
181 return calc_rate(parent_rate, m, n, mode, hid_div);
184 static int _freq_tbl_determine_rate(struct clk_hw *hw, const struct freq_tbl *f,
185 struct clk_rate_request *req,
186 enum freq_policy policy)
188 unsigned long clk_flags, rate = req->rate;
190 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
195 f = qcom_find_freq_floor(f, rate);
198 f = qcom_find_freq(f, rate);
207 index = qcom_find_src_index(hw, rcg->parent_map, f->src);
211 clk_flags = clk_hw_get_flags(hw);
212 p = clk_hw_get_parent_by_index(hw, index);
216 if (clk_flags & CLK_SET_RATE_PARENT) {
221 rate *= f->pre_div + 1;
231 rate = clk_hw_get_rate(p);
233 req->best_parent_hw = p;
234 req->best_parent_rate = rate;
240 static int clk_rcg2_determine_rate(struct clk_hw *hw,
241 struct clk_rate_request *req)
243 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
245 return _freq_tbl_determine_rate(hw, rcg->freq_tbl, req, CEIL);
248 static int clk_rcg2_determine_floor_rate(struct clk_hw *hw,
249 struct clk_rate_request *req)
251 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
253 return _freq_tbl_determine_rate(hw, rcg->freq_tbl, req, FLOOR);
256 static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
259 struct clk_hw *hw = &rcg->clkr.hw;
260 int ret, index = qcom_find_src_index(hw, rcg->parent_map, f->src);
265 if (rcg->mnd_width && f->n) {
266 mask = BIT(rcg->mnd_width) - 1;
267 ret = regmap_update_bits(rcg->clkr.regmap,
268 rcg->cmd_rcgr + M_REG, mask, f->m);
272 ret = regmap_update_bits(rcg->clkr.regmap,
273 rcg->cmd_rcgr + N_REG, mask, ~(f->n - f->m));
277 ret = regmap_update_bits(rcg->clkr.regmap,
278 rcg->cmd_rcgr + D_REG, mask, ~f->n);
283 mask = BIT(rcg->hid_width) - 1;
284 mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK;
285 cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
286 cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
287 if (rcg->mnd_width && f->n && (f->m != f->n))
288 cfg |= CFG_MODE_DUAL_EDGE;
289 ret = regmap_update_bits(rcg->clkr.regmap,
290 rcg->cmd_rcgr + CFG_REG, mask, cfg);
294 return update_config(rcg);
297 static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
298 enum freq_policy policy)
300 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
301 const struct freq_tbl *f;
305 f = qcom_find_freq_floor(rcg->freq_tbl, rate);
308 f = qcom_find_freq(rcg->freq_tbl, rate);
317 return clk_rcg2_configure(rcg, f);
320 static int clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
321 unsigned long parent_rate)
323 return __clk_rcg2_set_rate(hw, rate, CEIL);
326 static int clk_rcg2_set_floor_rate(struct clk_hw *hw, unsigned long rate,
327 unsigned long parent_rate)
329 return __clk_rcg2_set_rate(hw, rate, FLOOR);
332 static int clk_rcg2_set_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, CEIL);
338 static int clk_rcg2_set_floor_rate_and_parent(struct clk_hw *hw,
339 unsigned long rate, unsigned long parent_rate, u8 index)
341 return __clk_rcg2_set_rate(hw, rate, FLOOR);
344 const struct clk_ops clk_rcg2_ops = {
345 .is_enabled = clk_rcg2_is_enabled,
346 .get_parent = clk_rcg2_get_parent,
347 .set_parent = clk_rcg2_set_parent,
348 .recalc_rate = clk_rcg2_recalc_rate,
349 .determine_rate = clk_rcg2_determine_rate,
350 .set_rate = clk_rcg2_set_rate,
351 .set_rate_and_parent = clk_rcg2_set_rate_and_parent,
353 EXPORT_SYMBOL_GPL(clk_rcg2_ops);
355 const struct clk_ops clk_rcg2_floor_ops = {
356 .is_enabled = clk_rcg2_is_enabled,
357 .get_parent = clk_rcg2_get_parent,
358 .set_parent = clk_rcg2_set_parent,
359 .recalc_rate = clk_rcg2_recalc_rate,
360 .determine_rate = clk_rcg2_determine_floor_rate,
361 .set_rate = clk_rcg2_set_floor_rate,
362 .set_rate_and_parent = clk_rcg2_set_floor_rate_and_parent,
364 EXPORT_SYMBOL_GPL(clk_rcg2_floor_ops);
366 static int clk_rcg2_shared_force_enable(struct clk_hw *hw, unsigned long rate)
368 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
369 const char *name = clk_hw_get_name(hw);
372 /* force enable RCG */
373 ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
374 CMD_ROOT_EN, CMD_ROOT_EN);
378 /* wait for RCG to turn ON */
379 for (count = 500; count > 0; count--) {
380 ret = clk_rcg2_is_enabled(hw);
386 pr_err("%s: RCG did not turn on\n", name);
389 ret = __clk_rcg2_set_rate(hw, rate, CEIL);
393 /* clear force enable RCG */
394 return regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
398 static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate,
399 unsigned long parent_rate)
401 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
404 rcg->current_freq = rate;
406 if (!__clk_is_enabled(hw->clk))
409 return clk_rcg2_shared_force_enable(hw, rcg->current_freq);
413 clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
415 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
417 return rcg->current_freq = clk_rcg2_recalc_rate(hw, parent_rate);
420 static int clk_rcg2_shared_enable(struct clk_hw *hw)
422 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
424 return clk_rcg2_shared_force_enable(hw, rcg->current_freq);
427 static void clk_rcg2_shared_disable(struct clk_hw *hw)
429 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
431 /* switch to XO, which is the lowest entry in the freq table */
432 clk_rcg2_shared_set_rate(hw, rcg->freq_tbl[0].freq, 0);
435 const struct clk_ops clk_rcg2_shared_ops = {
436 .enable = clk_rcg2_shared_enable,
437 .disable = clk_rcg2_shared_disable,
438 .get_parent = clk_rcg2_get_parent,
439 .recalc_rate = clk_rcg2_shared_recalc_rate,
440 .determine_rate = clk_rcg2_determine_rate,
441 .set_rate = clk_rcg2_shared_set_rate,
443 EXPORT_SYMBOL_GPL(clk_rcg2_shared_ops);
450 static const struct frac_entry frac_table_675m[] = { /* link rate of 270M */
451 { 52, 295 }, /* 119 M */
452 { 11, 57 }, /* 130.25 M */
453 { 63, 307 }, /* 138.50 M */
454 { 11, 50 }, /* 148.50 M */
455 { 47, 206 }, /* 154 M */
456 { 31, 100 }, /* 205.25 M */
457 { 107, 269 }, /* 268.50 M */
461 static struct frac_entry frac_table_810m[] = { /* Link rate of 162M */
462 { 31, 211 }, /* 119 M */
463 { 32, 199 }, /* 130.25 M */
464 { 63, 307 }, /* 138.50 M */
465 { 11, 60 }, /* 148.50 M */
466 { 50, 263 }, /* 154 M */
467 { 31, 120 }, /* 205.25 M */
468 { 119, 359 }, /* 268.50 M */
472 static int clk_edp_pixel_set_rate(struct clk_hw *hw, unsigned long rate,
473 unsigned long parent_rate)
475 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
476 struct freq_tbl f = *rcg->freq_tbl;
477 const struct frac_entry *frac;
479 s64 src_rate = parent_rate;
481 u32 mask = BIT(rcg->hid_width) - 1;
484 if (src_rate == 810000000)
485 frac = frac_table_810m;
487 frac = frac_table_675m;
489 for (; frac->num; frac++) {
491 request *= frac->den;
492 request = div_s64(request, frac->num);
493 if ((src_rate < (request - delta)) ||
494 (src_rate > (request + delta)))
497 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
500 f.pre_div >>= CFG_SRC_DIV_SHIFT;
505 return clk_rcg2_configure(rcg, &f);
511 static int clk_edp_pixel_set_rate_and_parent(struct clk_hw *hw,
512 unsigned long rate, unsigned long parent_rate, u8 index)
514 /* Parent index is set statically in frequency table */
515 return clk_edp_pixel_set_rate(hw, rate, parent_rate);
518 static int clk_edp_pixel_determine_rate(struct clk_hw *hw,
519 struct clk_rate_request *req)
521 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
522 const struct freq_tbl *f = rcg->freq_tbl;
523 const struct frac_entry *frac;
526 u32 mask = BIT(rcg->hid_width) - 1;
528 int index = qcom_find_src_index(hw, rcg->parent_map, f->src);
530 /* Force the correct parent */
531 req->best_parent_hw = clk_hw_get_parent_by_index(hw, index);
532 req->best_parent_rate = clk_hw_get_rate(req->best_parent_hw);
534 if (req->best_parent_rate == 810000000)
535 frac = frac_table_810m;
537 frac = frac_table_675m;
539 for (; frac->num; frac++) {
541 request *= frac->den;
542 request = div_s64(request, frac->num);
543 if ((req->best_parent_rate < (request - delta)) ||
544 (req->best_parent_rate > (request + delta)))
547 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
549 hid_div >>= CFG_SRC_DIV_SHIFT;
552 req->rate = calc_rate(req->best_parent_rate,
553 frac->num, frac->den,
554 !!frac->den, hid_div);
561 const struct clk_ops clk_edp_pixel_ops = {
562 .is_enabled = clk_rcg2_is_enabled,
563 .get_parent = clk_rcg2_get_parent,
564 .set_parent = clk_rcg2_set_parent,
565 .recalc_rate = clk_rcg2_recalc_rate,
566 .set_rate = clk_edp_pixel_set_rate,
567 .set_rate_and_parent = clk_edp_pixel_set_rate_and_parent,
568 .determine_rate = clk_edp_pixel_determine_rate,
570 EXPORT_SYMBOL_GPL(clk_edp_pixel_ops);
572 static int clk_byte_determine_rate(struct clk_hw *hw,
573 struct clk_rate_request *req)
575 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
576 const struct freq_tbl *f = rcg->freq_tbl;
577 int index = qcom_find_src_index(hw, rcg->parent_map, f->src);
578 unsigned long parent_rate, div;
579 u32 mask = BIT(rcg->hid_width) - 1;
585 req->best_parent_hw = p = clk_hw_get_parent_by_index(hw, index);
586 req->best_parent_rate = parent_rate = clk_hw_round_rate(p, req->rate);
588 div = DIV_ROUND_UP((2 * parent_rate), req->rate) - 1;
589 div = min_t(u32, div, mask);
591 req->rate = calc_rate(parent_rate, 0, 0, 0, div);
596 static int clk_byte_set_rate(struct clk_hw *hw, unsigned long rate,
597 unsigned long parent_rate)
599 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
600 struct freq_tbl f = *rcg->freq_tbl;
602 u32 mask = BIT(rcg->hid_width) - 1;
604 div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
605 div = min_t(u32, div, mask);
609 return clk_rcg2_configure(rcg, &f);
612 static int clk_byte_set_rate_and_parent(struct clk_hw *hw,
613 unsigned long rate, unsigned long parent_rate, u8 index)
615 /* Parent index is set statically in frequency table */
616 return clk_byte_set_rate(hw, rate, parent_rate);
619 const struct clk_ops clk_byte_ops = {
620 .is_enabled = clk_rcg2_is_enabled,
621 .get_parent = clk_rcg2_get_parent,
622 .set_parent = clk_rcg2_set_parent,
623 .recalc_rate = clk_rcg2_recalc_rate,
624 .set_rate = clk_byte_set_rate,
625 .set_rate_and_parent = clk_byte_set_rate_and_parent,
626 .determine_rate = clk_byte_determine_rate,
628 EXPORT_SYMBOL_GPL(clk_byte_ops);
630 static int clk_byte2_determine_rate(struct clk_hw *hw,
631 struct clk_rate_request *req)
633 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
634 unsigned long parent_rate, div;
635 u32 mask = BIT(rcg->hid_width) - 1;
637 unsigned long rate = req->rate;
642 p = req->best_parent_hw;
643 req->best_parent_rate = parent_rate = clk_hw_round_rate(p, rate);
645 div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
646 div = min_t(u32, div, mask);
648 req->rate = calc_rate(parent_rate, 0, 0, 0, div);
653 static int clk_byte2_set_rate(struct clk_hw *hw, unsigned long rate,
654 unsigned long parent_rate)
656 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
657 struct freq_tbl f = { 0 };
659 int i, num_parents = clk_hw_get_num_parents(hw);
660 u32 mask = BIT(rcg->hid_width) - 1;
663 div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
664 div = min_t(u32, div, mask);
668 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
669 cfg &= CFG_SRC_SEL_MASK;
670 cfg >>= CFG_SRC_SEL_SHIFT;
672 for (i = 0; i < num_parents; i++) {
673 if (cfg == rcg->parent_map[i].cfg) {
674 f.src = rcg->parent_map[i].src;
675 return clk_rcg2_configure(rcg, &f);
682 static int clk_byte2_set_rate_and_parent(struct clk_hw *hw,
683 unsigned long rate, unsigned long parent_rate, u8 index)
685 /* Read the hardware to determine parent during set_rate */
686 return clk_byte2_set_rate(hw, rate, parent_rate);
689 const struct clk_ops clk_byte2_ops = {
690 .is_enabled = clk_rcg2_is_enabled,
691 .get_parent = clk_rcg2_get_parent,
692 .set_parent = clk_rcg2_set_parent,
693 .recalc_rate = clk_rcg2_recalc_rate,
694 .set_rate = clk_byte2_set_rate,
695 .set_rate_and_parent = clk_byte2_set_rate_and_parent,
696 .determine_rate = clk_byte2_determine_rate,
698 EXPORT_SYMBOL_GPL(clk_byte2_ops);
700 static const struct frac_entry frac_table_pixel[] = {
708 static int clk_pixel_determine_rate(struct clk_hw *hw,
709 struct clk_rate_request *req)
711 unsigned long request, src_rate;
713 const struct frac_entry *frac = frac_table_pixel;
715 for (; frac->num; frac++) {
716 request = (req->rate * frac->den) / frac->num;
718 src_rate = clk_hw_round_rate(req->best_parent_hw, request);
719 if ((src_rate < (request - delta)) ||
720 (src_rate > (request + delta)))
723 req->best_parent_rate = src_rate;
724 req->rate = (src_rate * frac->num) / frac->den;
731 static int clk_pixel_set_rate(struct clk_hw *hw, unsigned long rate,
732 unsigned long parent_rate)
734 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
735 struct freq_tbl f = { 0 };
736 const struct frac_entry *frac = frac_table_pixel;
737 unsigned long request;
739 u32 mask = BIT(rcg->hid_width) - 1;
741 int i, num_parents = clk_hw_get_num_parents(hw);
743 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
744 cfg &= CFG_SRC_SEL_MASK;
745 cfg >>= CFG_SRC_SEL_SHIFT;
747 for (i = 0; i < num_parents; i++)
748 if (cfg == rcg->parent_map[i].cfg) {
749 f.src = rcg->parent_map[i].src;
753 for (; frac->num; frac++) {
754 request = (rate * frac->den) / frac->num;
756 if ((parent_rate < (request - delta)) ||
757 (parent_rate > (request + delta)))
760 regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
763 f.pre_div >>= CFG_SRC_DIV_SHIFT;
768 return clk_rcg2_configure(rcg, &f);
773 static int clk_pixel_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
774 unsigned long parent_rate, u8 index)
776 return clk_pixel_set_rate(hw, rate, parent_rate);
779 const struct clk_ops clk_pixel_ops = {
780 .is_enabled = clk_rcg2_is_enabled,
781 .get_parent = clk_rcg2_get_parent,
782 .set_parent = clk_rcg2_set_parent,
783 .recalc_rate = clk_rcg2_recalc_rate,
784 .set_rate = clk_pixel_set_rate,
785 .set_rate_and_parent = clk_pixel_set_rate_and_parent,
786 .determine_rate = clk_pixel_determine_rate,
788 EXPORT_SYMBOL_GPL(clk_pixel_ops);
790 static int clk_gfx3d_determine_rate(struct clk_hw *hw,
791 struct clk_rate_request *req)
793 struct clk_rate_request parent_req = { };
794 struct clk_hw *p2, *p8, *p9, *xo;
795 unsigned long p9_rate;
798 xo = clk_hw_get_parent_by_index(hw, 0);
799 if (req->rate == clk_hw_get_rate(xo)) {
800 req->best_parent_hw = xo;
804 p9 = clk_hw_get_parent_by_index(hw, 2);
805 p2 = clk_hw_get_parent_by_index(hw, 3);
806 p8 = clk_hw_get_parent_by_index(hw, 4);
808 /* PLL9 is a fixed rate PLL */
809 p9_rate = clk_hw_get_rate(p9);
811 parent_req.rate = req->rate = min(req->rate, p9_rate);
812 if (req->rate == p9_rate) {
813 req->rate = req->best_parent_rate = p9_rate;
814 req->best_parent_hw = p9;
818 if (req->best_parent_hw == p9) {
819 /* Are we going back to a previously used rate? */
820 if (clk_hw_get_rate(p8) == req->rate)
821 req->best_parent_hw = p8;
823 req->best_parent_hw = p2;
824 } else if (req->best_parent_hw == p8) {
825 req->best_parent_hw = p2;
827 req->best_parent_hw = p8;
830 ret = __clk_determine_rate(req->best_parent_hw, &parent_req);
834 req->rate = req->best_parent_rate = parent_req.rate;
839 static int clk_gfx3d_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
840 unsigned long parent_rate, u8 index)
842 struct clk_rcg2 *rcg = to_clk_rcg2(hw);
846 /* Just mux it, we don't use the division or m/n hardware */
847 cfg = rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
848 ret = regmap_write(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, cfg);
852 return update_config(rcg);
855 static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate,
856 unsigned long parent_rate)
859 * We should never get here; clk_gfx3d_determine_rate() should always
860 * make us use a different parent than what we're currently using, so
861 * clk_gfx3d_set_rate_and_parent() should always be called.
866 const struct clk_ops clk_gfx3d_ops = {
867 .is_enabled = clk_rcg2_is_enabled,
868 .get_parent = clk_rcg2_get_parent,
869 .set_parent = clk_rcg2_set_parent,
870 .recalc_rate = clk_rcg2_recalc_rate,
871 .set_rate = clk_gfx3d_set_rate,
872 .set_rate_and_parent = clk_gfx3d_set_rate_and_parent,
873 .determine_rate = clk_gfx3d_determine_rate,
875 EXPORT_SYMBOL_GPL(clk_gfx3d_ops);