clk: fixed-factor: add optional accuracy support
Fixed factor clock reports the parent clock accuracy. Add flags and acc fields to `struct clk_fixed_factor` to support setting a fixed accuracy. The default if no flag is set is not changed: use the parent clock accuracy. Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> Link: https://lore.kernel.org/r/20240221-mbly-clk-v7-1-31d4ce3630c3@bootlin.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
6613476e22
commit
ff773fd219
|
@ -57,10 +57,22 @@ static int clk_factor_set_rate(struct clk_hw *hw, unsigned long rate,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned long clk_factor_recalc_accuracy(struct clk_hw *hw,
|
||||||
|
unsigned long parent_accuracy)
|
||||||
|
{
|
||||||
|
struct clk_fixed_factor *fix = to_clk_fixed_factor(hw);
|
||||||
|
|
||||||
|
if (fix->flags & CLK_FIXED_FACTOR_FIXED_ACCURACY)
|
||||||
|
return fix->acc;
|
||||||
|
|
||||||
|
return parent_accuracy;
|
||||||
|
}
|
||||||
|
|
||||||
const struct clk_ops clk_fixed_factor_ops = {
|
const struct clk_ops clk_fixed_factor_ops = {
|
||||||
.round_rate = clk_factor_round_rate,
|
.round_rate = clk_factor_round_rate,
|
||||||
.set_rate = clk_factor_set_rate,
|
.set_rate = clk_factor_set_rate,
|
||||||
.recalc_rate = clk_factor_recalc_rate,
|
.recalc_rate = clk_factor_recalc_rate,
|
||||||
|
.recalc_accuracy = clk_factor_recalc_accuracy,
|
||||||
};
|
};
|
||||||
EXPORT_SYMBOL_GPL(clk_fixed_factor_ops);
|
EXPORT_SYMBOL_GPL(clk_fixed_factor_ops);
|
||||||
|
|
||||||
|
@ -81,7 +93,7 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
|
||||||
const char *name, const char *parent_name,
|
const char *name, const char *parent_name,
|
||||||
const struct clk_hw *parent_hw, int index,
|
const struct clk_hw *parent_hw, int index,
|
||||||
unsigned long flags, unsigned int mult, unsigned int div,
|
unsigned long flags, unsigned int mult, unsigned int div,
|
||||||
bool devm)
|
unsigned long acc, unsigned int fixflags, bool devm)
|
||||||
{
|
{
|
||||||
struct clk_fixed_factor *fix;
|
struct clk_fixed_factor *fix;
|
||||||
struct clk_init_data init = { };
|
struct clk_init_data init = { };
|
||||||
|
@ -105,6 +117,8 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
|
||||||
fix->mult = mult;
|
fix->mult = mult;
|
||||||
fix->div = div;
|
fix->div = div;
|
||||||
fix->hw.init = &init;
|
fix->hw.init = &init;
|
||||||
|
fix->acc = acc;
|
||||||
|
fix->flags = fixflags;
|
||||||
|
|
||||||
init.name = name;
|
init.name = name;
|
||||||
init.ops = &clk_fixed_factor_ops;
|
init.ops = &clk_fixed_factor_ops;
|
||||||
|
@ -152,7 +166,7 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
|
||||||
unsigned int mult, unsigned int div)
|
unsigned int mult, unsigned int div)
|
||||||
{
|
{
|
||||||
return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL, index,
|
return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL, index,
|
||||||
flags, mult, div, true);
|
flags, mult, div, 0, 0, true);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_index);
|
EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_index);
|
||||||
|
|
||||||
|
@ -174,7 +188,7 @@ struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
|
||||||
unsigned long flags, unsigned int mult, unsigned int div)
|
unsigned long flags, unsigned int mult, unsigned int div)
|
||||||
{
|
{
|
||||||
return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw,
|
return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw,
|
||||||
-1, flags, mult, div, true);
|
-1, flags, mult, div, 0, 0, true);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_parent_hw);
|
EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_parent_hw);
|
||||||
|
|
||||||
|
@ -184,7 +198,7 @@ struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
|
||||||
{
|
{
|
||||||
return __clk_hw_register_fixed_factor(dev, NULL, name, NULL,
|
return __clk_hw_register_fixed_factor(dev, NULL, name, NULL,
|
||||||
parent_hw, -1, flags, mult, div,
|
parent_hw, -1, flags, mult, div,
|
||||||
false);
|
0, 0, false);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_parent_hw);
|
EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_parent_hw);
|
||||||
|
|
||||||
|
@ -193,7 +207,7 @@ struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
|
||||||
unsigned int mult, unsigned int div)
|
unsigned int mult, unsigned int div)
|
||||||
{
|
{
|
||||||
return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1,
|
return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1,
|
||||||
flags, mult, div, false);
|
flags, mult, div, 0, 0, false);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor);
|
EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor);
|
||||||
|
|
||||||
|
@ -240,7 +254,7 @@ struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
|
||||||
unsigned int mult, unsigned int div)
|
unsigned int mult, unsigned int div)
|
||||||
{
|
{
|
||||||
return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1,
|
return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1,
|
||||||
flags, mult, div, true);
|
flags, mult, div, 0, 0, true);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor);
|
EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor);
|
||||||
|
|
||||||
|
@ -267,7 +281,7 @@ static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node)
|
||||||
of_property_read_string(node, "clock-output-names", &clk_name);
|
of_property_read_string(node, "clock-output-names", &clk_name);
|
||||||
|
|
||||||
hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL, 0,
|
hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL, 0,
|
||||||
0, mult, div, false);
|
0, mult, div, 0, 0, false);
|
||||||
if (IS_ERR(hw)) {
|
if (IS_ERR(hw)) {
|
||||||
/*
|
/*
|
||||||
* Clear OF_POPULATED flag so that clock registration can be
|
* Clear OF_POPULATED flag so that clock registration can be
|
||||||
|
|
|
@ -1084,18 +1084,28 @@ void of_fixed_factor_clk_setup(struct device_node *node);
|
||||||
* @hw: handle between common and hardware-specific interfaces
|
* @hw: handle between common and hardware-specific interfaces
|
||||||
* @mult: multiplier
|
* @mult: multiplier
|
||||||
* @div: divider
|
* @div: divider
|
||||||
|
* @acc: fixed accuracy in ppb
|
||||||
|
* @flags: behavior modifying flags
|
||||||
*
|
*
|
||||||
* Clock with a fixed multiplier and divider. The output frequency is the
|
* Clock with a fixed multiplier and divider. The output frequency is the
|
||||||
* parent clock rate divided by div and multiplied by mult.
|
* parent clock rate divided by div and multiplied by mult.
|
||||||
* Implements .recalc_rate, .set_rate and .round_rate
|
* Implements .recalc_rate, .set_rate, .round_rate and .recalc_accuracy
|
||||||
|
*
|
||||||
|
* Flags:
|
||||||
|
* * CLK_FIXED_FACTOR_FIXED_ACCURACY - Use the value in @acc instead of the
|
||||||
|
* parent clk accuracy.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct clk_fixed_factor {
|
struct clk_fixed_factor {
|
||||||
struct clk_hw hw;
|
struct clk_hw hw;
|
||||||
unsigned int mult;
|
unsigned int mult;
|
||||||
unsigned int div;
|
unsigned int div;
|
||||||
|
unsigned long acc;
|
||||||
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define CLK_FIXED_FACTOR_FIXED_ACCURACY BIT(0)
|
||||||
|
|
||||||
#define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
|
#define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
|
||||||
|
|
||||||
extern const struct clk_ops clk_fixed_factor_ops;
|
extern const struct clk_ops clk_fixed_factor_ops;
|
||||||
|
|
Loading…
Reference in New Issue