Skip to content
Snippets Groups Projects
Commit 233b3d58 authored by Lucas Sinn's avatar Lucas Sinn Committed by Tomeu Vizoso
Browse files

HACK: drivers: clk: add rockchip clock scaling

This adds the adaptive frequency scaling feature for the npu
provided by the devicetree to increase the inference performance.
parent f10f5112
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ struct rockchip_clk_pll {
u8 flags;
const struct rockchip_pll_rate_table *rate_table;
unsigned int rate_count;
int sel;
spinlock_t *lock;
struct rockchip_clk_provider *ctx;
......@@ -61,6 +62,72 @@ static const struct rockchip_pll_rate_table *rockchip_get_pll_settings(
return NULL;
}
int rockchip_pll_clk_adaptive_scaling(struct clk *clk, int sel)
{
struct clk *parent = clk_get_parent(clk);
struct rockchip_clk_pll *pll;
if (IS_ERR_OR_NULL(parent))
return -EINVAL;
pll = to_rockchip_clk_pll(__clk_get_hw(parent));
if (!pll)
return -EINVAL;
pll->sel = sel;
return 0;
}
EXPORT_SYMBOL(rockchip_pll_clk_adaptive_scaling);
int rockchip_pll_clk_rate_to_scale(struct clk *clk, unsigned long rate)
{
const struct rockchip_pll_rate_table *rate_table;
struct clk *parent = clk_get_parent(clk);
struct rockchip_clk_pll *pll;
unsigned int i;
if (IS_ERR_OR_NULL(parent))
return -EINVAL;
pll = to_rockchip_clk_pll(__clk_get_hw(parent));
if (!pll)
return -EINVAL;
rate_table = pll->rate_table;
for (i = 0; i < pll->rate_count; i++) {
if (rate >= rate_table[i].rate)
return i;
}
return -EINVAL;
}
EXPORT_SYMBOL(rockchip_pll_clk_rate_to_scale);
int rockchip_pll_clk_scale_to_rate(struct clk *clk, unsigned int scale)
{
const struct rockchip_pll_rate_table *rate_table;
struct clk *parent = clk_get_parent(clk);
struct rockchip_clk_pll *pll;
unsigned int i;
if (IS_ERR_OR_NULL(parent))
return -EINVAL;
pll = to_rockchip_clk_pll(__clk_get_hw(parent));
if (!pll)
return -EINVAL;
rate_table = pll->rate_table;
for (i = 0; i < pll->rate_count; i++) {
if (i == scale)
return rate_table[i].rate;
}
return -EINVAL;
}
EXPORT_SYMBOL(rockchip_pll_clk_scale_to_rate);
static long rockchip_pll_round_rate(struct clk_hw *hw,
unsigned long drate, unsigned long *prate)
{
......
......@@ -987,6 +987,9 @@ void rockchip_clk_register_armclk(struct rockchip_clk_provider *ctx,
const struct rockchip_cpuclk_reg_data *reg_data,
const struct rockchip_cpuclk_rate_table *rates,
int nrates);
int rockchip_pll_clk_rate_to_scale(struct clk *clk, unsigned long rate);
int rockchip_pll_clk_scale_to_rate(struct clk *clk, unsigned int scale);
int rockchip_pll_clk_adaptive_scaling(struct clk *clk, int sel);
void rockchip_clk_protect_critical(const char *const clocks[], int nclocks);
void rockchip_register_restart_notifier(struct rockchip_clk_provider *ctx,
unsigned int reg, void (*cb)(void));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment