Skip to content

Commit a6adc30

Browse files
Dong Aishengbebarino
authored andcommitted
clk: introduce clk_core_enable_lock and clk_core_disable_lock functions
This can be useful when clock core wants to enable/disable clocks. Then we don't have to convert the struct clk_core to struct clk to call clk_enable/clk_disable which is a bit un-align with exist using. And after introduce clk_core_{enable|disable}_lock, we can refine clk_enable and clk_disable a bit. As well as clk_core_{enable|disable}_lock, we also added clk_core_{prepare|unprepare}_lock and clk_core_prepare_enable/ clk_core_unprepare_disable for clock core to easily use. Cc: Michael Turquette <[email protected]> Cc: Stephen Boyd <[email protected]> Cc: Shawn Guo <[email protected]> Signed-off-by: Dong Aisheng <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 582e240 commit a6adc30

File tree

1 file changed

+63
-22
lines changed

1 file changed

+63
-22
lines changed

drivers/clk/clk.c

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ static void clk_core_unprepare(struct clk_core *core)
591591
clk_core_unprepare(core->parent);
592592
}
593593

594+
static void clk_core_unprepare_lock(struct clk_core *core)
595+
{
596+
clk_prepare_lock();
597+
clk_core_unprepare(core);
598+
clk_prepare_unlock();
599+
}
600+
594601
/**
595602
* clk_unprepare - undo preparation of a clock source
596603
* @clk: the clk being unprepared
@@ -607,9 +614,7 @@ void clk_unprepare(struct clk *clk)
607614
if (IS_ERR_OR_NULL(clk))
608615
return;
609616

610-
clk_prepare_lock();
611-
clk_core_unprepare(clk->core);
612-
clk_prepare_unlock();
617+
clk_core_unprepare_lock(clk->core);
613618
}
614619
EXPORT_SYMBOL_GPL(clk_unprepare);
615620

@@ -645,6 +650,17 @@ static int clk_core_prepare(struct clk_core *core)
645650
return 0;
646651
}
647652

653+
static int clk_core_prepare_lock(struct clk_core *core)
654+
{
655+
int ret;
656+
657+
clk_prepare_lock();
658+
ret = clk_core_prepare(core);
659+
clk_prepare_unlock();
660+
661+
return ret;
662+
}
663+
648664
/**
649665
* clk_prepare - prepare a clock source
650666
* @clk: the clk being prepared
@@ -659,16 +675,10 @@ static int clk_core_prepare(struct clk_core *core)
659675
*/
660676
int clk_prepare(struct clk *clk)
661677
{
662-
int ret;
663-
664678
if (!clk)
665679
return 0;
666680

667-
clk_prepare_lock();
668-
ret = clk_core_prepare(clk->core);
669-
clk_prepare_unlock();
670-
671-
return ret;
681+
return clk_core_prepare_lock(clk->core);
672682
}
673683
EXPORT_SYMBOL_GPL(clk_prepare);
674684

@@ -698,6 +708,15 @@ static void clk_core_disable(struct clk_core *core)
698708
clk_core_disable(core->parent);
699709
}
700710

711+
static void clk_core_disable_lock(struct clk_core *core)
712+
{
713+
unsigned long flags;
714+
715+
flags = clk_enable_lock();
716+
clk_core_disable(core);
717+
clk_enable_unlock(flags);
718+
}
719+
701720
/**
702721
* clk_disable - gate a clock
703722
* @clk: the clk being gated
@@ -712,14 +731,10 @@ static void clk_core_disable(struct clk_core *core)
712731
*/
713732
void clk_disable(struct clk *clk)
714733
{
715-
unsigned long flags;
716-
717734
if (IS_ERR_OR_NULL(clk))
718735
return;
719736

720-
flags = clk_enable_lock();
721-
clk_core_disable(clk->core);
722-
clk_enable_unlock(flags);
737+
clk_core_disable_lock(clk->core);
723738
}
724739
EXPORT_SYMBOL_GPL(clk_disable);
725740

@@ -758,6 +773,18 @@ static int clk_core_enable(struct clk_core *core)
758773
return 0;
759774
}
760775

776+
static int clk_core_enable_lock(struct clk_core *core)
777+
{
778+
unsigned long flags;
779+
int ret;
780+
781+
flags = clk_enable_lock();
782+
ret = clk_core_enable(core);
783+
clk_enable_unlock(flags);
784+
785+
return ret;
786+
}
787+
761788
/**
762789
* clk_enable - ungate a clock
763790
* @clk: the clk being ungated
@@ -773,19 +800,33 @@ static int clk_core_enable(struct clk_core *core)
773800
*/
774801
int clk_enable(struct clk *clk)
775802
{
776-
unsigned long flags;
777-
int ret;
778-
779803
if (!clk)
780804
return 0;
781805

782-
flags = clk_enable_lock();
783-
ret = clk_core_enable(clk->core);
784-
clk_enable_unlock(flags);
806+
return clk_core_enable_lock(clk->core);
807+
}
808+
EXPORT_SYMBOL_GPL(clk_enable);
809+
810+
static int clk_core_prepare_enable(struct clk_core *core)
811+
{
812+
int ret;
813+
814+
ret = clk_core_prepare_lock(core);
815+
if (ret)
816+
return ret;
817+
818+
ret = clk_core_enable_lock(core);
819+
if (ret)
820+
clk_core_unprepare_lock(core);
785821

786822
return ret;
787823
}
788-
EXPORT_SYMBOL_GPL(clk_enable);
824+
825+
static void clk_core_disable_unprepare(struct clk_core *core)
826+
{
827+
clk_core_disable_lock(core);
828+
clk_core_unprepare_lock(core);
829+
}
789830

790831
static int clk_core_round_rate_nolock(struct clk_core *core,
791832
struct clk_rate_request *req)

0 commit comments

Comments
 (0)