Skip to content

Commit

Permalink
clk: Add clk_get_first_to_set_rate
Browse files Browse the repository at this point in the history
The purpose of this function is to be used along with the notifier
mechanism.

When a parent clock can see its rate externally changed at any moment,
and a driver needs a specific clock rate to function, it can register a
notifier on the parent clock, and call clk_set_rate() on the base clock
to adjust its frequency according to the new parent clock.

This works fine, until the base clock has the CLK_SET_RATE_PARENT flag
set. In that case, calling clk_set_rate() on the base clock will call
clk_set_rate() on the parent clock, which will trigger the notifier
again, and we're in a loop.

For that reason, we need to register the notifier on the parent clock of
the first ancestor of the base clock that will effectively modify its
rate when clk_set_rate() is called, which we can now obtain with
clk_get_first_to_set_rate().

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei authored and intel-lab-lkp committed Mar 7, 2021
1 parent 4d5c4ae commit 009ca1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,15 @@ struct clk *clk_get_parent(struct clk *clk)
}
EXPORT_SYMBOL_GPL(clk_get_parent);

struct clk *clk_get_first_to_set_rate(struct clk *clk)
{
while (clk && (clk->core->flags & CLK_SET_RATE_PARENT))
clk = clk_get_parent(clk);

return clk;
}


static struct clk_core *__clk_init_parent(struct clk_core *core)
{
u8 index = 0;
Expand Down
16 changes: 16 additions & 0 deletions include/linux/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,17 @@ struct clk *clk_get_parent(struct clk *clk);
*/
struct clk *clk_get_sys(const char *dev_id, const char *con_id);

/**
* clk_get_first_to_set_rate - get a pointer to the clock that will
* effectively modify its rate when clk_set_rate(clk) is called
* (might be clk itself, or any ancestor)
* @clk: clock source
*
* Returns struct clk corresponding to the matched clock source, or
* NULL on error.
*/
struct clk *clk_get_first_to_set_rate(struct clk *clk);

/**
* clk_save_context - save clock context for poweroff
*
Expand Down Expand Up @@ -906,6 +917,11 @@ static inline struct clk *clk_get_parent(struct clk *clk)
return NULL;
}

static inline struct clk *clk_get_first_to_set_rate(struct clk *clk)
{
return NULL;
}

static inline struct clk *clk_get_sys(const char *dev_id, const char *con_id)
{
return NULL;
Expand Down

0 comments on commit 009ca1a

Please sign in to comment.