Skip to content

Commit 152efe5

Browse files
Gabriel-Fernandzbebarino
authored andcommitted
clk: stm32mp1: merge 'ck_hse_rtc' and 'ck_rtc' into one clock
'ck_rtc' has multiple clocks as input (ck_hsi, ck_lsi, and ck_hse). A divider is available only on the specific rtc input for ck_hse. This Merge will facilitate to have a more coherent clock tree in no trusted / trusted world. Signed-off-by: Gabriel Fernandez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 47c671d commit 152efe5

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

drivers/clk/clk-stm32mp1.c

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static const char * const dsi_src[] = {
245245
};
246246

247247
static const char * const rtc_src[] = {
248-
"off", "ck_lse", "ck_lsi", "ck_hse_rtc"
248+
"off", "ck_lse", "ck_lsi", "ck_hse"
249249
};
250250

251251
static const char * const mco1_src[] = {
@@ -1031,6 +1031,47 @@ static struct clk_hw *clk_register_cktim(struct device *dev, const char *name,
10311031
return hw;
10321032
}
10331033

1034+
/* The divider of RTC clock concerns only ck_hse clock */
1035+
#define HSE_RTC 3
1036+
1037+
static unsigned long clk_divider_rtc_recalc_rate(struct clk_hw *hw,
1038+
unsigned long parent_rate)
1039+
{
1040+
if (clk_hw_get_parent(hw) == clk_hw_get_parent_by_index(hw, HSE_RTC))
1041+
return clk_divider_ops.recalc_rate(hw, parent_rate);
1042+
1043+
return parent_rate;
1044+
}
1045+
1046+
static int clk_divider_rtc_set_rate(struct clk_hw *hw, unsigned long rate,
1047+
unsigned long parent_rate)
1048+
{
1049+
if (clk_hw_get_parent(hw) == clk_hw_get_parent_by_index(hw, HSE_RTC))
1050+
return clk_divider_ops.set_rate(hw, rate, parent_rate);
1051+
1052+
return parent_rate;
1053+
}
1054+
1055+
static int clk_divider_rtc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req)
1056+
{
1057+
unsigned long best_parent_rate = req->best_parent_rate;
1058+
1059+
if (req->best_parent_hw == clk_hw_get_parent_by_index(hw, HSE_RTC)) {
1060+
req->rate = clk_divider_ops.round_rate(hw, req->rate, &best_parent_rate);
1061+
req->best_parent_rate = best_parent_rate;
1062+
} else {
1063+
req->rate = best_parent_rate;
1064+
}
1065+
1066+
return 0;
1067+
}
1068+
1069+
static const struct clk_ops rtc_div_clk_ops = {
1070+
.recalc_rate = clk_divider_rtc_recalc_rate,
1071+
.set_rate = clk_divider_rtc_set_rate,
1072+
.determine_rate = clk_divider_rtc_determine_rate
1073+
};
1074+
10341075
struct stm32_pll_cfg {
10351076
u32 offset;
10361077
};
@@ -1243,6 +1284,10 @@ _clk_stm32_register_composite(struct device *dev,
12431284
_STM32_DIV(_div_offset, _div_shift, _div_width,\
12441285
_div_flags, _div_table, NULL)\
12451286

1287+
#define _DIV_RTC(_div_offset, _div_shift, _div_width, _div_flags, _div_table)\
1288+
_STM32_DIV(_div_offset, _div_shift, _div_width,\
1289+
_div_flags, _div_table, &rtc_div_clk_ops)
1290+
12461291
#define _STM32_MUX(_offset, _shift, _width, _mux_flags, _mmux, _ops)\
12471292
.mux = &(struct stm32_mux_cfg) {\
12481293
&(struct mux_cfg) {\
@@ -1965,13 +2010,10 @@ static const struct clock_config stm32mp1_clock_cfg[] = {
19652010
_DIV(RCC_ETHCKSELR, 4, 4, 0, NULL)),
19662011

19672012
/* RTC clock */
1968-
DIV(NO_ID, "ck_hse_rtc", "ck_hse", 0, RCC_RTCDIVR, 0, 6, 0),
1969-
1970-
COMPOSITE(RTC, "ck_rtc", rtc_src, CLK_OPS_PARENT_ENABLE |
1971-
CLK_SET_RATE_PARENT,
2013+
COMPOSITE(RTC, "ck_rtc", rtc_src, CLK_OPS_PARENT_ENABLE,
19722014
_GATE(RCC_BDCR, 20, 0),
19732015
_MUX(RCC_BDCR, 16, 2, 0),
1974-
_NO_DIV),
2016+
_DIV_RTC(RCC_RTCDIVR, 0, 6, 0, NULL)),
19752017

19762018
/* MCO clocks */
19772019
COMPOSITE(CK_MCO1, "ck_mco1", mco1_src, CLK_OPS_PARENT_ENABLE |

0 commit comments

Comments
 (0)