[PATCH v1 12/22] clk: starfive: Introduce inverter and divider

Changhuang Liang
2026-04-02T11:12:02Z

Introduce inverter and divider for starfive clocks.

Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
drivers/clk/starfive/clk-starfive-common.c | 12 ++++++++++++
drivers/clk/starfive/clk-starfive-common.h | 8 ++++++++
2 files changed, 20 insertions(+)

diff --git a/drivers/clk/starfive/clk-starfive-common.c b/drivers/clk/starfive/clk-starfive-common.c
index 9c0eb7a50d1e..d84b326c9aed 100644
--- a/drivers/clk/starfive/clk-starfive-common.c
+++ b/drivers/clk/starfive/clk-starfive-common.c
@@ -298,6 +298,15 @@ static const struct clk_ops starfive_clk_inv_ops = {
.debug_init = starfive_clk_debug_init,
};

+static const struct clk_ops starfive_clk_idiv_ops = {
+ .get_phase = starfive_clk_get_phase,
+ .set_phase = starfive_clk_set_phase,
+ .recalc_rate = starfive_clk_recalc_rate,
+ .determine_rate = starfive_clk_determine_rate,
+ .set_rate = starfive_clk_set_rate,
+ .debug_init = starfive_clk_debug_init,
+};
+
const struct clk_ops *starfive_clk_ops(u32 max)
{
if (max & STARFIVE_CLK_DIV_MASK) {
@@ -308,6 +317,9 @@ const struct clk_ops *starfive_clk_ops(u32 max)
}
if (max & STARFIVE_CLK_ENABLE)
return &starfive_clk_gdiv_ops;
+ else if (max & STARFIVE_CLK_INVERT)
+ return &starfive_clk_idiv_ops;
+
if (max == STARFIVE_CLK_FRAC_MAX)
return &starfive_clk_fdiv_ops;
return &starfive_clk_div_ops;
diff --git a/drivers/clk/starfive/clk-starfive-common.h b/drivers/clk/starfive/clk-starfive-common.h
index a03824e9e75f..fd9bf6f20152 100644
--- a/drivers/clk/starfive/clk-starfive-common.h
+++ b/drivers/clk/starfive/clk-starfive-common.h
@@ -103,6 +103,14 @@ struct starfive_clk_data {
.parents = { [0] = _parent }, \
}

+#define STARFIVE_IDIV(_idx, _name, _flags, _max, _parent) \
+[_idx] = { \
+ .name = _name, \
+ .flags = _flags, \
+ .max = STARFIVE_CLK_INVERT | (_max), \
+ .parents = { [0] = _parent }, \
+}
+
struct starfive_clk {
struct clk_hw hw;
unsigned int idx;
--
2.25.1