mirror of
https://github.com/torvalds/linux.git
synced 2024-09-20 06:53:04 +00:00
clk: scmi: Add support for get/set duty_cycle operations
Provide the CLK framework callbacks related to get/set clock duty cycle if the related SCMI clock supports OEM extended configurations. CC: Michael Turquette <mturquette@baylibre.com> CC: Stephen Boyd <sboyd@kernel.org> CC: linux-clk@vger.kernel.org Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Link: https://lore.kernel.org/r/20240415163649.895268-6-cristian.marussi@arm.com Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
fa23e09123
commit
87af9481af
|
@ -22,6 +22,7 @@ enum scmi_clk_feats {
|
|||
SCMI_CLK_STATE_CTRL_SUPPORTED,
|
||||
SCMI_CLK_RATE_CTRL_SUPPORTED,
|
||||
SCMI_CLK_PARENT_CTRL_SUPPORTED,
|
||||
SCMI_CLK_DUTY_CYCLE_SUPPORTED,
|
||||
SCMI_CLK_FEATS_COUNT
|
||||
};
|
||||
|
||||
|
@ -169,6 +170,45 @@ static int scmi_clk_atomic_is_enabled(struct clk_hw *hw)
|
|||
return !!enabled;
|
||||
}
|
||||
|
||||
static int scmi_clk_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
|
||||
{
|
||||
int ret;
|
||||
u32 val;
|
||||
struct scmi_clk *clk = to_scmi_clk(hw);
|
||||
|
||||
ret = scmi_proto_clk_ops->config_oem_get(clk->ph, clk->id,
|
||||
SCMI_CLOCK_CFG_DUTY_CYCLE,
|
||||
&val, NULL, false);
|
||||
if (!ret) {
|
||||
duty->num = val;
|
||||
duty->den = 100;
|
||||
} else {
|
||||
dev_warn(clk->dev,
|
||||
"Failed to get duty cycle for clock ID %d\n", clk->id);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int scmi_clk_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
|
||||
{
|
||||
int ret;
|
||||
u32 val;
|
||||
struct scmi_clk *clk = to_scmi_clk(hw);
|
||||
|
||||
/* SCMI OEM Duty Cycle is expressed as a percentage */
|
||||
val = (duty->num * 100) / duty->den;
|
||||
ret = scmi_proto_clk_ops->config_oem_set(clk->ph, clk->id,
|
||||
SCMI_CLOCK_CFG_DUTY_CYCLE,
|
||||
val, false);
|
||||
if (ret)
|
||||
dev_warn(clk->dev,
|
||||
"Failed to set duty cycle(%u/%u) for clock ID %d\n",
|
||||
duty->num, duty->den, clk->id);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int scmi_clk_ops_init(struct device *dev, struct scmi_clk *sclk,
|
||||
const struct clk_ops *scmi_ops)
|
||||
{
|
||||
|
@ -258,6 +298,12 @@ scmi_clk_ops_alloc(struct device *dev, unsigned long feats_key)
|
|||
if (feats_key & BIT(SCMI_CLK_PARENT_CTRL_SUPPORTED))
|
||||
ops->set_parent = scmi_clk_set_parent;
|
||||
|
||||
/* Duty cycle */
|
||||
if (feats_key & BIT(SCMI_CLK_DUTY_CYCLE_SUPPORTED)) {
|
||||
ops->get_duty_cycle = scmi_clk_get_duty_cycle;
|
||||
ops->set_duty_cycle = scmi_clk_set_duty_cycle;
|
||||
}
|
||||
|
||||
return ops;
|
||||
}
|
||||
|
||||
|
@ -312,6 +358,9 @@ scmi_clk_ops_select(struct scmi_clk *sclk, bool atomic_capable,
|
|||
if (!ci->parent_ctrl_forbidden)
|
||||
feats_key |= BIT(SCMI_CLK_PARENT_CTRL_SUPPORTED);
|
||||
|
||||
if (ci->extended_config)
|
||||
feats_key |= BIT(SCMI_CLK_DUTY_CYCLE_SUPPORTED);
|
||||
|
||||
if (WARN_ON(feats_key >= db_size))
|
||||
return NULL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user