Lines Matching +full:clk +full:- +full:out +full:- +full:frequency

1 // SPDX-License-Identifier: GPL-2.0
3 // Helper routines for R-Car sound ADG.
6 #include <linux/clk-provider.h>
33 struct clk *clkin[CLKINMAX];
34 struct clk *clkout[CLKOUTMAX];
35 struct clk *null_clk;
50 (i < adg->clkin_size) && \
51 ((pos) = adg->clkin[i]); \
55 (i < adg->clkout_size) && \
56 ((pos) = adg->clkout[i]); \
58 #define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
85 for (i = 3; i >= 0; i--) { in rsnd_adg_calculate_brgx()
88 return (u32)((i << 8) | ((div / ratio) - 1)); in rsnd_adg_calculate_brgx()
131 adg->clkin_rate[CLKA], /* 0000: CLKA */ in __rsnd_adg_get_timesel_ratio()
132 adg->clkin_rate[CLKB], /* 0001: CLKB */ in __rsnd_adg_get_timesel_ratio()
133 adg->clkin_rate[CLKC], /* 0010: CLKC */ in __rsnd_adg_get_timesel_ratio()
134 adg->brg_rate[ADG_HZ_441], /* 0011: BRGA */ in __rsnd_adg_get_timesel_ratio()
135 adg->brg_rate[ADG_HZ_48], /* 0100: BRGB */ in __rsnd_adg_get_timesel_ratio()
150 diff = abs(target_rate - sel_rate[sel] / div); in __rsnd_adg_get_timesel_ratio()
159 * are out of order in __rsnd_adg_get_timesel_ratio()
185 u32 *in, u32 *out, u32 *en) in rsnd_adg_get_timesel_ratio() argument
201 if (runtime->rate != in_rate) { in rsnd_adg_get_timesel_ratio()
204 } else if (runtime->rate != out_rate) { in rsnd_adg_get_timesel_ratio()
216 if (out) in rsnd_adg_get_timesel_ratio()
217 *out = _out; in rsnd_adg_get_timesel_ratio()
253 u32 in, out; in rsnd_adg_set_src_timesel_gen2() local
262 &in, &out, &en); in rsnd_adg_set_src_timesel_gen2()
265 out = out << shift; in rsnd_adg_set_src_timesel_gen2()
269 rsnd_mod_bset(adg_mod, SRCOUT_TIMSEL(id / 2), mask, out); in rsnd_adg_set_src_timesel_gen2()
306 struct clk *clk; in rsnd_adg_clk_query() local
319 for_each_rsnd_clkin(clk, adg, i) in rsnd_adg_clk_query()
320 if (rate == adg->clkin_rate[i]) in rsnd_adg_clk_query()
326 if (rate == adg->brg_rate[ADG_HZ_441]) in rsnd_adg_clk_query()
329 if (rate == adg->brg_rate[ADG_HZ_48]) in rsnd_adg_clk_query()
332 return -EIO; in rsnd_adg_clk_query()
360 rsnd_mod_bset(adg_mod, BRGCKR, 0x80770000, adg->ckr | ckr); in rsnd_adg_ssi_clk_try_start()
364 (ckr) ? adg->brg_rate[ADG_HZ_48] : in rsnd_adg_ssi_clk_try_start()
365 adg->brg_rate[ADG_HZ_441]); in rsnd_adg_ssi_clk_try_start()
374 struct clk *clk; in rsnd_adg_clk_control() local
378 rsnd_mod_bset(adg_mod, BRGCKR, 0x80770000, adg->ckr); in rsnd_adg_clk_control()
379 rsnd_mod_write(adg_mod, BRRA, adg->brga); in rsnd_adg_clk_control()
380 rsnd_mod_write(adg_mod, BRRB, adg->brgb); in rsnd_adg_clk_control()
383 for_each_rsnd_clkin(clk, adg, i) { in rsnd_adg_clk_control()
385 clk_prepare_enable(clk); in rsnd_adg_clk_control()
392 adg->clkin_rate[i] = clk_get_rate(clk); in rsnd_adg_clk_control()
394 clk_disable_unprepare(clk); in rsnd_adg_clk_control()
399 static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv, in rsnd_adg_create_null_clk()
404 struct clk *clk; in rsnd_adg_create_null_clk() local
406 clk = clk_register_fixed_rate(dev, name, parent, 0, 0); in rsnd_adg_create_null_clk()
407 if (IS_ERR_OR_NULL(clk)) { in rsnd_adg_create_null_clk()
408 dev_err(dev, "create null clk error\n"); in rsnd_adg_create_null_clk()
409 return ERR_CAST(clk); in rsnd_adg_create_null_clk()
412 return clk; in rsnd_adg_create_null_clk()
415 static struct clk *rsnd_adg_null_clk_get(struct rsnd_priv *priv) in rsnd_adg_null_clk_get()
417 struct rsnd_adg *adg = priv->adg; in rsnd_adg_null_clk_get()
419 if (!adg->null_clk) { in rsnd_adg_null_clk_get()
422 adg->null_clk = rsnd_adg_create_null_clk(priv, name, NULL); in rsnd_adg_null_clk_get()
425 return adg->null_clk; in rsnd_adg_null_clk_get()
430 struct rsnd_adg *adg = priv->adg; in rsnd_adg_null_clk_clean()
432 if (adg->null_clk) in rsnd_adg_null_clk_clean()
433 clk_unregister_fixed_rate(adg->null_clk); in rsnd_adg_null_clk_clean()
438 struct rsnd_adg *adg = priv->adg; in rsnd_adg_get_clkin()
440 struct clk *clk; in rsnd_adg_get_clkin() local
453 clk = devm_clk_get(dev, clkin_name[i]); in rsnd_adg_get_clkin()
455 if (IS_ERR_OR_NULL(clk)) in rsnd_adg_get_clkin()
456 clk = rsnd_adg_null_clk_get(priv); in rsnd_adg_get_clkin()
457 if (IS_ERR_OR_NULL(clk)) in rsnd_adg_get_clkin()
460 adg->clkin[i] = clk; in rsnd_adg_get_clkin()
463 adg->clkin_size = clkin_size; in rsnd_adg_get_clkin()
472 return -EIO; in rsnd_adg_get_clkin()
477 struct rsnd_adg *adg = priv->adg; in rsnd_adg_unregister_clkout()
478 struct clk *clk; in rsnd_adg_unregister_clkout() local
481 for_each_rsnd_clkout(clk, adg, i) in rsnd_adg_unregister_clkout()
482 clk_unregister_fixed_rate(clk); in rsnd_adg_unregister_clkout()
487 struct rsnd_adg *adg = priv->adg; in rsnd_adg_get_clkout()
488 struct clk *clk; in rsnd_adg_get_clkout() local
490 struct device_node *np = dev->of_node; in rsnd_adg_get_clkout()
516 prop = of_find_property(np, "clock-frequency", NULL); in rsnd_adg_get_clkout()
520 req_size = prop->length / sizeof(u32); in rsnd_adg_get_clkout()
522 dev_err(dev, "too many clock-frequency\n"); in rsnd_adg_get_clkout()
523 return -EINVAL; in rsnd_adg_get_clkout()
526 of_property_read_u32_array(np, "clock-frequency", req_rate, req_size); in rsnd_adg_get_clkout()
540 * SSI itself can divide parent clock by 1/1 - 1/16 in rsnd_adg_get_clkout()
555 * - Minimum division of BRRA/BRRB in rsnd_adg_get_clkout()
556 * - rsnd_ssi_clk_query() in rsnd_adg_get_clkout()
563 * clock-frequency = <22579200 24576000>; in rsnd_adg_get_clkout()
565 for_each_rsnd_clkin(clk, adg, i) { in rsnd_adg_get_clkout()
568 rate = clk_get_rate(clk); in rsnd_adg_get_clkout()
577 rate = (clk_get_rate(clk) / req_Hz[ADG_HZ_441]) * req_Hz[ADG_HZ_441]; in rsnd_adg_get_clkout()
578 if (!adg->brg_rate[ADG_HZ_441] && req_Hz[ADG_HZ_441] && (0 == rate % 44100)) { in rsnd_adg_get_clkout()
583 adg->brg_rate[ADG_HZ_441] = rate / div; in rsnd_adg_get_clkout()
586 parent_clk_name = __clk_get_name(clk); in rsnd_adg_get_clkout()
596 rate = (clk_get_rate(clk) / req_Hz[ADG_HZ_48]) * req_Hz[ADG_HZ_48]; in rsnd_adg_get_clkout()
597 if (!adg->brg_rate[ADG_HZ_48] && req_Hz[ADG_HZ_48] && (0 == rate % 48000)) { in rsnd_adg_get_clkout()
602 adg->brg_rate[ADG_HZ_48] = rate / div; in rsnd_adg_get_clkout()
605 parent_clk_name = __clk_get_name(clk); in rsnd_adg_get_clkout()
612 if (!(adg->brg_rate[ADG_HZ_48] && req_Hz[ADG_HZ_48]) && in rsnd_adg_get_clkout()
613 !(adg->brg_rate[ADG_HZ_441] && req_Hz[ADG_HZ_441])) in rsnd_adg_get_clkout()
629 of_property_read_u32(np, "#clock-cells", &count); in rsnd_adg_get_clkout()
634 clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT], in rsnd_adg_get_clkout()
636 if (IS_ERR_OR_NULL(clk)) in rsnd_adg_get_clkout()
639 adg->clkout[CLKOUT] = clk; in rsnd_adg_get_clkout()
640 adg->clkout_size = 1; in rsnd_adg_get_clkout()
641 of_clk_add_provider(np, of_clk_src_simple_get, clk); in rsnd_adg_get_clkout()
648 clk = clk_register_fixed_rate(dev, clkout_name[i], in rsnd_adg_get_clkout()
651 if (IS_ERR_OR_NULL(clk)) in rsnd_adg_get_clkout()
654 adg->clkout[i] = clk; in rsnd_adg_get_clkout()
656 adg->onecell.clks = adg->clkout; in rsnd_adg_get_clkout()
657 adg->onecell.clk_num = clkout_size; in rsnd_adg_get_clkout()
658 adg->clkout_size = clkout_size; in rsnd_adg_get_clkout()
660 &adg->onecell); in rsnd_adg_get_clkout()
664 adg->ckr = ckr; in rsnd_adg_get_clkout()
665 adg->brga = brga; in rsnd_adg_get_clkout()
666 adg->brgb = brgb; in rsnd_adg_get_clkout()
671 dev_err(dev, "adg clock OUT get failed\n"); in rsnd_adg_get_clkout()
675 return -EIO; in rsnd_adg_get_clkout()
700 struct clk *clk; in rsnd_adg_clk_dbg_info() local
703 for_each_rsnd_clkin(clk, adg, i) in rsnd_adg_clk_dbg_info()
704 dbg_msg(dev, m, "%-18s : %pa : %ld\n", in rsnd_adg_clk_dbg_info()
705 __clk_get_name(clk), clk, clk_get_rate(clk)); in rsnd_adg_clk_dbg_info()
708 adg->ckr, adg->brga, adg->brgb); in rsnd_adg_clk_dbg_info()
709 dbg_msg(dev, m, "BRGA (for 44100 base) = %d\n", adg->brg_rate[ADG_HZ_441]); in rsnd_adg_clk_dbg_info()
710 dbg_msg(dev, m, "BRGB (for 48000 base) = %d\n", adg->brg_rate[ADG_HZ_48]); in rsnd_adg_clk_dbg_info()
716 for_each_rsnd_clkout(clk, adg, i) in rsnd_adg_clk_dbg_info()
717 dbg_msg(dev, m, "%-18s : %pa : %ld\n", in rsnd_adg_clk_dbg_info()
718 __clk_get_name(clk), clk, clk_get_rate(clk)); in rsnd_adg_clk_dbg_info()
732 return -ENOMEM; in rsnd_adg_probe()
734 ret = rsnd_mod_init(priv, &adg->mod, &adg_ops, in rsnd_adg_probe()
739 priv->adg = adg; in rsnd_adg_probe()
758 struct device_node *np = dev->of_node; in rsnd_adg_remove()