Lines Matching +full:clk +full:- +full:div
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Author: Xing Zheng <zhengxing@rock-chips.com>
11 * samsung/clk.c
18 #include <linux/clk.h>
19 #include <linux/clk-provider.h>
25 #include "../clk-fractional-divider.h"
26 #include "clk.h"
32 * src1 --|--\
33 * |M |--[GATE]-[DIV]-
34 * src2 --|--/
38 static struct clk *rockchip_clk_register_branch(const char *name, in rockchip_clk_register_branch()
51 struct clk_divider *div = NULL; in rockchip_clk_register_branch() local
59 return ERR_PTR(-ENOMEM); in rockchip_clk_register_branch()
61 mux->reg = base + muxdiv_offset; in rockchip_clk_register_branch()
62 mux->shift = mux_shift; in rockchip_clk_register_branch()
63 mux->mask = BIT(mux_width) - 1; in rockchip_clk_register_branch()
64 mux->flags = mux_flags; in rockchip_clk_register_branch()
65 mux->table = mux_table; in rockchip_clk_register_branch()
66 mux->lock = lock; in rockchip_clk_register_branch()
74 ret = -ENOMEM; in rockchip_clk_register_branch()
78 gate->flags = gate_flags; in rockchip_clk_register_branch()
79 gate->reg = base + gate_offset; in rockchip_clk_register_branch()
80 gate->bit_idx = gate_shift; in rockchip_clk_register_branch()
81 gate->lock = lock; in rockchip_clk_register_branch()
86 div = kzalloc(sizeof(*div), GFP_KERNEL); in rockchip_clk_register_branch()
87 if (!div) { in rockchip_clk_register_branch()
88 ret = -ENOMEM; in rockchip_clk_register_branch()
92 div->flags = div_flags; in rockchip_clk_register_branch()
94 div->reg = base + div_offset; in rockchip_clk_register_branch()
96 div->reg = base + muxdiv_offset; in rockchip_clk_register_branch()
97 div->shift = div_shift; in rockchip_clk_register_branch()
98 div->width = div_width; in rockchip_clk_register_branch()
99 div->lock = lock; in rockchip_clk_register_branch()
100 div->table = div_table; in rockchip_clk_register_branch()
107 mux ? &mux->hw : NULL, mux_ops, in rockchip_clk_register_branch()
108 div ? &div->hw : NULL, div_ops, in rockchip_clk_register_branch()
109 gate ? &gate->hw : NULL, gate_ops, in rockchip_clk_register_branch()
112 kfree(div); in rockchip_clk_register_branch()
117 return hw->clk; in rockchip_clk_register_branch()
127 struct clk_fractional_divider div; member
146 struct clk_mux *frac_mux = &frac->mux; in rockchip_clk_frac_notifier_cb()
150 __func__, event, ndata->old_rate, ndata->new_rate); in rockchip_clk_frac_notifier_cb()
152 frac->rate_change_idx = in rockchip_clk_frac_notifier_cb()
153 frac->mux_ops->get_parent(&frac_mux->hw); in rockchip_clk_frac_notifier_cb()
154 if (frac->rate_change_idx != frac->mux_frac_idx) { in rockchip_clk_frac_notifier_cb()
155 frac->mux_ops->set_parent(&frac_mux->hw, in rockchip_clk_frac_notifier_cb()
156 frac->mux_frac_idx); in rockchip_clk_frac_notifier_cb()
157 frac->rate_change_remuxed = 1; in rockchip_clk_frac_notifier_cb()
166 if (frac->rate_change_remuxed) { in rockchip_clk_frac_notifier_cb()
167 frac->mux_ops->set_parent(&frac_mux->hw, in rockchip_clk_frac_notifier_cb()
168 frac->rate_change_idx); in rockchip_clk_frac_notifier_cb()
169 frac->rate_change_remuxed = 0; in rockchip_clk_frac_notifier_cb()
195 fd->flags |= CLK_FRAC_DIVIDER_POWER_OF_TWO_PS; in rockchip_fractional_approximation()
201 struct clk *clk, unsigned int id) in rockchip_clk_add_lookup() argument
203 ctx->clk_data.clks[id] = clk; in rockchip_clk_add_lookup()
206 static struct clk *rockchip_clk_register_frac_branch( in rockchip_clk_register_frac_branch()
217 struct clk_fractional_divider *div = NULL; in rockchip_clk_register_frac_branch() local
221 return ERR_PTR(-EINVAL); in rockchip_clk_register_frac_branch()
223 if (child && child->branch_type != branch_mux) { in rockchip_clk_register_frac_branch()
226 return ERR_PTR(-EINVAL); in rockchip_clk_register_frac_branch()
231 return ERR_PTR(-ENOMEM); in rockchip_clk_register_frac_branch()
234 gate = &frac->gate; in rockchip_clk_register_frac_branch()
235 gate->flags = gate_flags; in rockchip_clk_register_frac_branch()
236 gate->reg = base + gate_offset; in rockchip_clk_register_frac_branch()
237 gate->bit_idx = gate_shift; in rockchip_clk_register_frac_branch()
238 gate->lock = lock; in rockchip_clk_register_frac_branch()
242 div = &frac->div; in rockchip_clk_register_frac_branch()
243 div->flags = div_flags; in rockchip_clk_register_frac_branch()
244 div->reg = base + muxdiv_offset; in rockchip_clk_register_frac_branch()
245 div->mshift = 16; in rockchip_clk_register_frac_branch()
246 div->mwidth = 16; in rockchip_clk_register_frac_branch()
247 div->nshift = 0; in rockchip_clk_register_frac_branch()
248 div->nwidth = 16; in rockchip_clk_register_frac_branch()
249 div->lock = lock; in rockchip_clk_register_frac_branch()
250 div->approximation = rockchip_fractional_approximation; in rockchip_clk_register_frac_branch()
255 &div->hw, div_ops, in rockchip_clk_register_frac_branch()
256 gate ? &gate->hw : NULL, gate_ops, in rockchip_clk_register_frac_branch()
264 struct clk_mux *frac_mux = &frac->mux; in rockchip_clk_register_frac_branch()
266 struct clk *mux_clk; in rockchip_clk_register_frac_branch()
269 frac->mux_frac_idx = match_string(child->parent_names, in rockchip_clk_register_frac_branch()
270 child->num_parents, name); in rockchip_clk_register_frac_branch()
271 frac->mux_ops = &clk_mux_ops; in rockchip_clk_register_frac_branch()
272 frac->clk_nb.notifier_call = rockchip_clk_frac_notifier_cb; in rockchip_clk_register_frac_branch()
274 frac_mux->reg = base + child->muxdiv_offset; in rockchip_clk_register_frac_branch()
275 frac_mux->shift = child->mux_shift; in rockchip_clk_register_frac_branch()
276 frac_mux->mask = BIT(child->mux_width) - 1; in rockchip_clk_register_frac_branch()
277 frac_mux->flags = child->mux_flags; in rockchip_clk_register_frac_branch()
278 if (child->mux_table) in rockchip_clk_register_frac_branch()
279 frac_mux->table = child->mux_table; in rockchip_clk_register_frac_branch()
280 frac_mux->lock = lock; in rockchip_clk_register_frac_branch()
281 frac_mux->hw.init = &init; in rockchip_clk_register_frac_branch()
283 init.name = child->name; in rockchip_clk_register_frac_branch()
284 init.flags = child->flags | CLK_SET_RATE_PARENT; in rockchip_clk_register_frac_branch()
285 init.ops = frac->mux_ops; in rockchip_clk_register_frac_branch()
286 init.parent_names = child->parent_names; in rockchip_clk_register_frac_branch()
287 init.num_parents = child->num_parents; in rockchip_clk_register_frac_branch()
289 mux_clk = clk_register(NULL, &frac_mux->hw); in rockchip_clk_register_frac_branch()
295 rockchip_clk_add_lookup(ctx, mux_clk, child->id); in rockchip_clk_register_frac_branch()
298 if (frac->mux_frac_idx >= 0) { in rockchip_clk_register_frac_branch()
300 __func__, frac->mux_frac_idx); in rockchip_clk_register_frac_branch()
301 ret = clk_notifier_register(hw->clk, &frac->clk_nb); in rockchip_clk_register_frac_branch()
307 __func__, name, child->name); in rockchip_clk_register_frac_branch()
311 return hw->clk; in rockchip_clk_register_frac_branch()
314 static struct clk *rockchip_clk_register_factor_branch(const char *name, in rockchip_clk_register_factor_branch()
316 void __iomem *base, unsigned int mult, unsigned int div, in rockchip_clk_register_factor_branch() argument
328 div); in rockchip_clk_register_factor_branch()
333 return ERR_PTR(-ENOMEM); in rockchip_clk_register_factor_branch()
335 gate->flags = gate_flags; in rockchip_clk_register_factor_branch()
336 gate->reg = base + gate_offset; in rockchip_clk_register_factor_branch()
337 gate->bit_idx = gate_shift; in rockchip_clk_register_factor_branch()
338 gate->lock = lock; in rockchip_clk_register_factor_branch()
343 return ERR_PTR(-ENOMEM); in rockchip_clk_register_factor_branch()
346 fix->mult = mult; in rockchip_clk_register_factor_branch()
347 fix->div = div; in rockchip_clk_register_factor_branch()
351 &fix->hw, &clk_fixed_factor_ops, in rockchip_clk_register_factor_branch()
352 &gate->hw, &clk_gate_ops, flags); in rockchip_clk_register_factor_branch()
359 return hw->clk; in rockchip_clk_register_factor_branch()
367 struct clk **clk_table; in rockchip_clk_init()
372 return ERR_PTR(-ENOMEM); in rockchip_clk_init()
374 clk_table = kcalloc(nr_clks, sizeof(struct clk *), GFP_KERNEL); in rockchip_clk_init()
379 clk_table[i] = ERR_PTR(-ENOENT); in rockchip_clk_init()
381 ctx->reg_base = base; in rockchip_clk_init()
382 ctx->clk_data.clks = clk_table; in rockchip_clk_init()
383 ctx->clk_data.clk_num = nr_clks; in rockchip_clk_init()
384 ctx->cru_node = np; in rockchip_clk_init()
385 spin_lock_init(&ctx->lock); in rockchip_clk_init()
387 ctx->grf = syscon_regmap_lookup_by_phandle(ctx->cru_node, in rockchip_clk_init()
394 return ERR_PTR(-ENOMEM); in rockchip_clk_init()
402 &ctx->clk_data)) in rockchip_clk_of_add_provider()
403 pr_err("%s: could not register clk provider\n", __func__); in rockchip_clk_of_add_provider()
411 struct clk *clk; in rockchip_clk_register_plls() local
415 clk = rockchip_clk_register_pll(ctx, list->type, list->name, in rockchip_clk_register_plls()
416 list->parent_names, list->num_parents, in rockchip_clk_register_plls()
417 list->con_offset, grf_lock_offset, in rockchip_clk_register_plls()
418 list->lock_shift, list->mode_offset, in rockchip_clk_register_plls()
419 list->mode_shift, list->rate_table, in rockchip_clk_register_plls()
420 list->flags, list->pll_flags); in rockchip_clk_register_plls()
421 if (IS_ERR(clk)) { in rockchip_clk_register_plls()
423 list->name); in rockchip_clk_register_plls()
427 rockchip_clk_add_lookup(ctx, clk, list->id); in rockchip_clk_register_plls()
439 if (list->id > max) in rockchip_clk_find_max_clk_id()
440 max = list->id; in rockchip_clk_find_max_clk_id()
441 if (list->child && list->child->id > max) in rockchip_clk_find_max_clk_id()
442 max = list->child->id; in rockchip_clk_find_max_clk_id()
453 struct clk *clk; in rockchip_clk_register_branches() local
458 flags = list->flags; in rockchip_clk_register_branches()
459 clk = NULL; in rockchip_clk_register_branches()
462 switch (list->branch_type) { in rockchip_clk_register_branches()
464 if (list->mux_table) in rockchip_clk_register_branches()
465 clk = clk_register_mux_table(NULL, list->name, in rockchip_clk_register_branches()
466 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
468 ctx->reg_base + list->muxdiv_offset, in rockchip_clk_register_branches()
469 list->mux_shift, list->mux_width, in rockchip_clk_register_branches()
470 list->mux_flags, list->mux_table, in rockchip_clk_register_branches()
471 &ctx->lock); in rockchip_clk_register_branches()
473 clk = clk_register_mux(NULL, list->name, in rockchip_clk_register_branches()
474 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
476 ctx->reg_base + list->muxdiv_offset, in rockchip_clk_register_branches()
477 list->mux_shift, list->mux_width, in rockchip_clk_register_branches()
478 list->mux_flags, &ctx->lock); in rockchip_clk_register_branches()
481 clk = rockchip_clk_register_muxgrf(list->name, in rockchip_clk_register_branches()
482 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
483 flags, ctx->grf, list->muxdiv_offset, in rockchip_clk_register_branches()
484 list->mux_shift, list->mux_width, in rockchip_clk_register_branches()
485 list->mux_flags); in rockchip_clk_register_branches()
488 if (list->div_table) in rockchip_clk_register_branches()
489 clk = clk_register_divider_table(NULL, in rockchip_clk_register_branches()
490 list->name, list->parent_names[0], in rockchip_clk_register_branches()
492 ctx->reg_base + list->muxdiv_offset, in rockchip_clk_register_branches()
493 list->div_shift, list->div_width, in rockchip_clk_register_branches()
494 list->div_flags, list->div_table, in rockchip_clk_register_branches()
495 &ctx->lock); in rockchip_clk_register_branches()
497 clk = clk_register_divider(NULL, list->name, in rockchip_clk_register_branches()
498 list->parent_names[0], flags, in rockchip_clk_register_branches()
499 ctx->reg_base + list->muxdiv_offset, in rockchip_clk_register_branches()
500 list->div_shift, list->div_width, in rockchip_clk_register_branches()
501 list->div_flags, &ctx->lock); in rockchip_clk_register_branches()
504 clk = rockchip_clk_register_frac_branch(ctx, list->name, in rockchip_clk_register_branches()
505 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
506 ctx->reg_base, list->muxdiv_offset, in rockchip_clk_register_branches()
507 list->div_flags, in rockchip_clk_register_branches()
508 list->gate_offset, list->gate_shift, in rockchip_clk_register_branches()
509 list->gate_flags, flags, list->child, in rockchip_clk_register_branches()
510 &ctx->lock); in rockchip_clk_register_branches()
513 clk = rockchip_clk_register_halfdiv(list->name, in rockchip_clk_register_branches()
514 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
515 ctx->reg_base, list->muxdiv_offset, in rockchip_clk_register_branches()
516 list->mux_shift, list->mux_width, in rockchip_clk_register_branches()
517 list->mux_flags, list->div_shift, in rockchip_clk_register_branches()
518 list->div_width, list->div_flags, in rockchip_clk_register_branches()
519 list->gate_offset, list->gate_shift, in rockchip_clk_register_branches()
520 list->gate_flags, flags, &ctx->lock); in rockchip_clk_register_branches()
525 clk = clk_register_gate(NULL, list->name, in rockchip_clk_register_branches()
526 list->parent_names[0], flags, in rockchip_clk_register_branches()
527 ctx->reg_base + list->gate_offset, in rockchip_clk_register_branches()
528 list->gate_shift, list->gate_flags, &ctx->lock); in rockchip_clk_register_branches()
531 clk = rockchip_clk_register_branch(list->name, in rockchip_clk_register_branches()
532 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
533 ctx->reg_base, list->muxdiv_offset, in rockchip_clk_register_branches()
534 list->mux_shift, in rockchip_clk_register_branches()
535 list->mux_width, list->mux_flags, in rockchip_clk_register_branches()
536 list->mux_table, list->div_offset, in rockchip_clk_register_branches()
537 list->div_shift, list->div_width, in rockchip_clk_register_branches()
538 list->div_flags, list->div_table, in rockchip_clk_register_branches()
539 list->gate_offset, list->gate_shift, in rockchip_clk_register_branches()
540 list->gate_flags, flags, &ctx->lock); in rockchip_clk_register_branches()
543 clk = rockchip_clk_register_mmc( in rockchip_clk_register_branches()
544 list->name, in rockchip_clk_register_branches()
545 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
546 ctx->reg_base + list->muxdiv_offset, in rockchip_clk_register_branches()
547 list->div_shift in rockchip_clk_register_branches()
551 clk = rockchip_clk_register_inverter( in rockchip_clk_register_branches()
552 list->name, list->parent_names, in rockchip_clk_register_branches()
553 list->num_parents, in rockchip_clk_register_branches()
554 ctx->reg_base + list->muxdiv_offset, in rockchip_clk_register_branches()
555 list->div_shift, list->div_flags, &ctx->lock); in rockchip_clk_register_branches()
558 clk = rockchip_clk_register_factor_branch( in rockchip_clk_register_branches()
559 list->name, list->parent_names, in rockchip_clk_register_branches()
560 list->num_parents, ctx->reg_base, in rockchip_clk_register_branches()
561 list->div_shift, list->div_width, in rockchip_clk_register_branches()
562 list->gate_offset, list->gate_shift, in rockchip_clk_register_branches()
563 list->gate_flags, flags, &ctx->lock); in rockchip_clk_register_branches()
566 clk = rockchip_clk_register_ddrclk( in rockchip_clk_register_branches()
567 list->name, list->flags, in rockchip_clk_register_branches()
568 list->parent_names, list->num_parents, in rockchip_clk_register_branches()
569 list->muxdiv_offset, list->mux_shift, in rockchip_clk_register_branches()
570 list->mux_width, list->div_shift, in rockchip_clk_register_branches()
571 list->div_width, list->div_flags, in rockchip_clk_register_branches()
572 ctx->reg_base, &ctx->lock); in rockchip_clk_register_branches()
577 if (!clk) { in rockchip_clk_register_branches()
579 __func__, list->branch_type); in rockchip_clk_register_branches()
583 if (IS_ERR(clk)) { in rockchip_clk_register_branches()
585 __func__, list->name, PTR_ERR(clk)); in rockchip_clk_register_branches()
589 rockchip_clk_add_lookup(ctx, clk, list->id); in rockchip_clk_register_branches()
602 struct clk *clk; in rockchip_clk_register_armclk() local
604 clk = rockchip_clk_register_cpuclk(name, parent_names, num_parents, in rockchip_clk_register_armclk()
606 ctx->reg_base, &ctx->lock); in rockchip_clk_register_armclk()
607 if (IS_ERR(clk)) { in rockchip_clk_register_armclk()
609 __func__, name, PTR_ERR(clk)); in rockchip_clk_register_armclk()
613 rockchip_clk_add_lookup(ctx, clk, lookup_id); in rockchip_clk_register_armclk()
624 struct clk *clk = __clk_lookup(clocks[i]); in rockchip_clk_protect_critical() local
626 clk_prepare_enable(clk); in rockchip_clk_protect_critical()
656 rst_base = ctx->reg_base; in rockchip_register_restart_notifier()