Lines Matching +full:divider +full:- +full:clock
1 // SPDX-License-Identifier: GPL-2.0
3 * Zynq UltraScale+ MPSoC Divider support
5 * Copyright (C) 2016-2019 Xilinx
7 * Adjustable divider clock implementation
11 #include <linux/clk-provider.h>
13 #include "clk-zynqmp.h"
16 * DOC: basic adjustable divider clock that cannot gate
18 * Traits of this clock:
19 * prepare - clk_prepare only ensures that parents are prepared
20 * enable - clk_enable only ensures that parents are enabled
21 * rate - rate is adjustable. clk->rate = ceiling(parent->rate / divisor)
22 * parent - fixed parent. No clk_set_parent support
32 * struct zynqmp_clk_divider - adjustable divider clock
33 * @hw: handle between common and hardware-specific interfaces
35 * @is_frac: The divider is a fractional divider
36 * @clk_id: Id of clock
65 return (rate - up_rate) <= (down_rate - rate) ? up : down; in zynqmp_divider_get_val()
73 * zynqmp_clk_divider_recalc_rate() - Recalc rate of divider clock
74 * @hw: handle between common and hardware-specific interfaces
75 * @parent_rate: rate of parent clock
82 struct zynqmp_clk_divider *divider = to_zynqmp_clk_divider(hw); in zynqmp_clk_divider_recalc_rate() local
84 u32 clk_id = divider->clk_id; in zynqmp_clk_divider_recalc_rate()
85 u32 div_type = divider->div_type; in zynqmp_clk_divider_recalc_rate()
92 pr_debug("%s() get divider failed for %s, ret = %d\n", in zynqmp_clk_divider_recalc_rate()
100 if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) in zynqmp_clk_divider_recalc_rate()
104 WARN(!(divider->flags & CLK_DIVIDER_ALLOW_ZERO), in zynqmp_clk_divider_recalc_rate()
114 * zynqmp_clk_divider_round_rate() - Round rate of divider clock
115 * @hw: handle between common and hardware-specific interfaces
116 * @rate: rate of clock to be set
117 * @prate: rate of parent clock
125 struct zynqmp_clk_divider *divider = to_zynqmp_clk_divider(hw); in zynqmp_clk_divider_round_rate() local
127 u32 clk_id = divider->clk_id; in zynqmp_clk_divider_round_rate()
128 u32 div_type = divider->div_type; in zynqmp_clk_divider_round_rate()
134 if (divider->flags & CLK_DIVIDER_READ_ONLY) { in zynqmp_clk_divider_round_rate()
138 pr_debug("%s() get divider failed for %s, ret = %d\n", in zynqmp_clk_divider_round_rate()
145 if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) in zynqmp_clk_divider_round_rate()
151 width = fls(divider->max_div); in zynqmp_clk_divider_round_rate()
153 rate = divider_round_rate(hw, rate, prate, NULL, width, divider->flags); in zynqmp_clk_divider_round_rate()
155 if (divider->is_frac && (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) && (rate % *prate)) in zynqmp_clk_divider_round_rate()
162 * zynqmp_clk_divider_set_rate() - Set rate of divider clock
163 * @hw: handle between common and hardware-specific interfaces
164 * @rate: rate of clock to be set
165 * @parent_rate: rate of parent clock
172 struct zynqmp_clk_divider *divider = to_zynqmp_clk_divider(hw); in zynqmp_clk_divider_set_rate() local
174 u32 clk_id = divider->clk_id; in zynqmp_clk_divider_set_rate()
175 u32 div_type = divider->div_type; in zynqmp_clk_divider_set_rate()
179 value = zynqmp_divider_get_val(parent_rate, rate, divider->flags); in zynqmp_clk_divider_set_rate()
188 if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) in zynqmp_clk_divider_set_rate()
194 pr_debug("%s() set divider failed for %s, ret = %d\n", in zynqmp_clk_divider_set_rate()
212 * zynqmp_clk_get_max_divisor() - Get maximum supported divisor from firmware.
213 * @clk_id: Id of clock
214 * @type: Divider type
216 * Return: Maximum divisor of a clock if query data is successful
263 * zynqmp_clk_register_divider() - Register a divider clock
264 * @name: Name of this clock
265 * @clk_id: Id of clock
266 * @parents: Name of this clock's parents
268 * @nodes: Clock topology node
270 * Return: clock hardware to registered clock divider
283 /* allocate the divider */ in zynqmp_clk_register_divider()
286 return ERR_PTR(-ENOMEM); in zynqmp_clk_register_divider()
289 if (nodes->type_flag & CLK_DIVIDER_READ_ONLY) in zynqmp_clk_register_divider()
294 init.flags = zynqmp_clk_map_common_ccf_flags(nodes->flag); in zynqmp_clk_register_divider()
300 div->is_frac = !!((nodes->flag & CLK_FRAC) | in zynqmp_clk_register_divider()
301 (nodes->custom_type_flag & CUSTOM_FLAG_CLK_FRAC)); in zynqmp_clk_register_divider()
302 div->flags = zynqmp_clk_map_divider_ccf_flags(nodes->type_flag); in zynqmp_clk_register_divider()
303 div->hw.init = &init; in zynqmp_clk_register_divider()
304 div->clk_id = clk_id; in zynqmp_clk_register_divider()
305 div->div_type = nodes->type; in zynqmp_clk_register_divider()
308 * To achieve best possible rate, maximum limit of divider is required in zynqmp_clk_register_divider()
311 div->max_div = zynqmp_clk_get_max_divisor(clk_id, nodes->type); in zynqmp_clk_register_divider()
313 hw = &div->hw; in zynqmp_clk_register_divider()