Skip to content

Commit 9008fdd

Browse files
Gabriel-Fernandzbebarino
authored andcommitted
clk: stm32mp1: remove intermediate pll clocks
This patch is to prepare STM32MP1 clocks in trusted mode. Integrate the mux clock into pll clock will facilitate to have a more coherent clock tree in no trusted / trusted mode. Signed-off-by: Gabriel Fernandez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 152efe5 commit 9008fdd

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

drivers/clk/clk-stm32mp1.c

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ struct stm32_pll_obj {
731731
spinlock_t *lock;
732732
void __iomem *reg;
733733
struct clk_hw hw;
734+
struct clk_mux mux;
734735
};
735736

736737
#define to_pll(_hw) container_of(_hw, struct stm32_pll_obj, hw)
@@ -745,6 +746,8 @@ struct stm32_pll_obj {
745746
#define FRAC_MASK 0x1FFF
746747
#define FRAC_SHIFT 3
747748
#define FRACLE BIT(16)
749+
#define PLL_MUX_SHIFT 0
750+
#define PLL_MUX_MASK 3
748751

749752
static int __pll_is_enabled(struct clk_hw *hw)
750753
{
@@ -856,16 +859,29 @@ static int pll_is_enabled(struct clk_hw *hw)
856859
return ret;
857860
}
858861

862+
static u8 pll_get_parent(struct clk_hw *hw)
863+
{
864+
struct stm32_pll_obj *clk_elem = to_pll(hw);
865+
struct clk_hw *mux_hw = &clk_elem->mux.hw;
866+
867+
__clk_hw_set_clk(mux_hw, hw);
868+
869+
return clk_mux_ops.get_parent(mux_hw);
870+
}
871+
859872
static const struct clk_ops pll_ops = {
860873
.enable = pll_enable,
861874
.disable = pll_disable,
862875
.recalc_rate = pll_recalc_rate,
863876
.is_enabled = pll_is_enabled,
877+
.get_parent = pll_get_parent,
864878
};
865879

866880
static struct clk_hw *clk_register_pll(struct device *dev, const char *name,
867-
const char *parent_name,
881+
const char * const *parent_names,
882+
int num_parents,
868883
void __iomem *reg,
884+
void __iomem *mux_reg,
869885
unsigned long flags,
870886
spinlock_t *lock)
871887
{
@@ -881,8 +897,15 @@ static struct clk_hw *clk_register_pll(struct device *dev, const char *name,
881897
init.name = name;
882898
init.ops = &pll_ops;
883899
init.flags = flags;
884-
init.parent_names = &parent_name;
885-
init.num_parents = 1;
900+
init.parent_names = parent_names;
901+
init.num_parents = num_parents;
902+
903+
element->mux.lock = lock;
904+
element->mux.reg = mux_reg;
905+
element->mux.shift = PLL_MUX_SHIFT;
906+
element->mux.mask = PLL_MUX_MASK;
907+
element->mux.flags = CLK_MUX_READ_ONLY;
908+
element->mux.reg = mux_reg;
886909

887910
element->hw.init = &init;
888911
element->reg = reg;
@@ -1074,6 +1097,7 @@ static const struct clk_ops rtc_div_clk_ops = {
10741097

10751098
struct stm32_pll_cfg {
10761099
u32 offset;
1100+
u32 muxoff;
10771101
};
10781102

10791103
static struct clk_hw *_clk_register_pll(struct device *dev,
@@ -1083,8 +1107,11 @@ static struct clk_hw *_clk_register_pll(struct device *dev,
10831107
{
10841108
struct stm32_pll_cfg *stm_pll_cfg = cfg->cfg;
10851109

1086-
return clk_register_pll(dev, cfg->name, cfg->parent_name,
1087-
base + stm_pll_cfg->offset, cfg->flags, lock);
1110+
return clk_register_pll(dev, cfg->name, cfg->parent_names,
1111+
cfg->num_parents,
1112+
base + stm_pll_cfg->offset,
1113+
base + stm_pll_cfg->muxoff,
1114+
cfg->flags, lock);
10881115
}
10891116

10901117
struct stm32_cktim_cfg {
@@ -1194,14 +1221,16 @@ _clk_stm32_register_composite(struct device *dev,
11941221
.func = _clk_hw_register_mux,\
11951222
}
11961223

1197-
#define PLL(_id, _name, _parent, _flags, _offset)\
1224+
#define PLL(_id, _name, _parents, _flags, _offset_p, _offset_mux)\
11981225
{\
11991226
.id = _id,\
12001227
.name = _name,\
1201-
.parent_name = _parent,\
1202-
.flags = _flags,\
1228+
.parent_names = _parents,\
1229+
.num_parents = ARRAY_SIZE(_parents),\
1230+
.flags = CLK_IGNORE_UNUSED | (_flags),\
12031231
.cfg = &(struct stm32_pll_cfg) {\
1204-
.offset = _offset,\
1232+
.offset = _offset_p,\
1233+
.muxoff = _offset_mux,\
12051234
},\
12061235
.func = _clk_register_pll,\
12071236
}
@@ -1717,21 +1746,11 @@ static const struct clock_config stm32mp1_clock_cfg[] = {
17171746

17181747
FIXED_FACTOR(CK_HSE_DIV2, "clk-hse-div2", "ck_hse", 0, 1, 2),
17191748

1720-
/* ref clock pll */
1721-
MUX(NO_ID, "ref1", ref12_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK12SELR,
1722-
0, 2, CLK_MUX_READ_ONLY),
1723-
1724-
MUX(NO_ID, "ref3", ref3_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK3SELR,
1725-
0, 2, CLK_MUX_READ_ONLY),
1726-
1727-
MUX(NO_ID, "ref4", ref4_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK4SELR,
1728-
0, 2, CLK_MUX_READ_ONLY),
1729-
17301749
/* PLLs */
1731-
PLL(PLL1, "pll1", "ref1", CLK_IGNORE_UNUSED, RCC_PLL1CR),
1732-
PLL(PLL2, "pll2", "ref1", CLK_IGNORE_UNUSED, RCC_PLL2CR),
1733-
PLL(PLL3, "pll3", "ref3", CLK_IGNORE_UNUSED, RCC_PLL3CR),
1734-
PLL(PLL4, "pll4", "ref4", CLK_IGNORE_UNUSED, RCC_PLL4CR),
1750+
PLL(PLL1, "pll1", ref12_parents, 0, RCC_PLL1CR, RCC_RCK12SELR),
1751+
PLL(PLL2, "pll2", ref12_parents, 0, RCC_PLL2CR, RCC_RCK12SELR),
1752+
PLL(PLL3, "pll3", ref3_parents, 0, RCC_PLL3CR, RCC_RCK3SELR),
1753+
PLL(PLL4, "pll4", ref4_parents, 0, RCC_PLL4CR, RCC_RCK4SELR),
17351754

17361755
/* ODF */
17371756
COMPOSITE(PLL1_P, "pll1_p", PARENT("pll1"), 0,

0 commit comments

Comments
 (0)