Skip to content

Commit

Permalink
clock flags add CLK_OPS_PARENT_ENABLE, parents need enable during gat…
Browse files Browse the repository at this point in the history
…e/ungate, set rate and re-parent

Signed-off-by: zhengshaobo1 <[email protected]>
  • Loading branch information
zhengshaobo1 authored and GUIDINGLI committed Sep 19, 2023
1 parent be767dd commit 6e6ba06
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
43 changes: 42 additions & 1 deletion drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@ static void clk_change_rate(FAR struct clk_s *clk, uint32_t best_parent_rate)

if (clk->new_parent && clk->new_parent != clk->parent)
{
if (clk->flags & CLK_OPS_PARENT_ENABLE)
{
clk_enable(old_parent);
clk_enable(clk->new_parent);
}

if (clk->enable_count)
{
clk_enable(clk->new_parent);
Expand All @@ -519,6 +525,12 @@ static void clk_change_rate(FAR struct clk_s *clk, uint32_t best_parent_rate)
clk_disable(clk);
clk_disable(old_parent);
}

if (clk->flags & CLK_OPS_PARENT_ENABLE)
{
clk_disable(clk->new_parent);
clk_disable(old_parent);
}
}

if (!skip_set_rate && clk->ops->set_rate)
Expand Down Expand Up @@ -789,9 +801,14 @@ static void clk_disable_unused_subtree(FAR struct clk_s *clk)
clk_disable_unused_subtree(child);
}

if (clk->flags & CLK_OPS_PARENT_ENABLE)
{
clk_enable(clk->parent);
}

if (clk->enable_count)
{
return;
goto out;
}

if (clk_is_enabled(clk))
Expand All @@ -805,6 +822,12 @@ static void clk_disable_unused_subtree(FAR struct clk_s *clk)
clk->ops->disable(clk);
}
}

out:
if (clk->flags & CLK_OPS_PARENT_ENABLE)
{
clk_disable(clk->parent);
}
}

/****************************************************************************
Expand Down Expand Up @@ -1062,6 +1085,12 @@ int clk_set_parent(FAR struct clk_s *clk, FAR struct clk_s *parent)

old_parent = clk->parent;

if (clk->flags & CLK_OPS_PARENT_ENABLE)
{
clk_enable(old_parent);
clk_enable(parent);
}

if (clk->enable_count)
{
clk_enable(parent);
Expand All @@ -1085,6 +1114,12 @@ int clk_set_parent(FAR struct clk_s *clk, FAR struct clk_s *parent)
clk_disable(parent);
}

if (clk->flags & CLK_OPS_PARENT_ENABLE)
{
clk_disable(parent);
clk_disable(old_parent);
}

goto out;
}

Expand All @@ -1094,6 +1129,12 @@ int clk_set_parent(FAR struct clk_s *clk, FAR struct clk_s *parent)
clk_disable(old_parent);
}

if (clk->flags & CLK_OPS_PARENT_ENABLE)
{
clk_disable(parent);
clk_disable(old_parent);
}

__clk_recalc_rate(clk);

out:
Expand Down
1 change: 1 addition & 0 deletions include/nuttx/clk/clk_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define CLK_SET_RATE_GATE 0x01
#define CLK_SET_PARENT_GATE 0x02
#define CLK_SET_RATE_PARENT 0x04
#define CLK_OPS_PARENT_ENABLE 0x08
#define CLK_GET_RATE_NOCACHE 0x10
#define CLK_NAME_IS_STATIC 0x20
#define CLK_PARENT_NAME_IS_STATIC 0x40
Expand Down

0 comments on commit 6e6ba06

Please sign in to comment.