@@ -245,7 +245,7 @@ static const char * const dsi_src[] = {
245
245
};
246
246
247
247
static const char * const rtc_src [] = {
248
- "off" , "ck_lse" , "ck_lsi" , "ck_hse_rtc "
248
+ "off" , "ck_lse" , "ck_lsi" , "ck_hse "
249
249
};
250
250
251
251
static const char * const mco1_src [] = {
@@ -1031,6 +1031,47 @@ static struct clk_hw *clk_register_cktim(struct device *dev, const char *name,
1031
1031
return hw ;
1032
1032
}
1033
1033
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
+
1034
1075
struct stm32_pll_cfg {
1035
1076
u32 offset ;
1036
1077
};
@@ -1243,6 +1284,10 @@ _clk_stm32_register_composite(struct device *dev,
1243
1284
_STM32_DIV(_div_offset, _div_shift, _div_width,\
1244
1285
_div_flags, _div_table, NULL)\
1245
1286
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
+
1246
1291
#define _STM32_MUX (_offset , _shift , _width , _mux_flags , _mmux , _ops )\
1247
1292
.mux = &(struct stm32_mux_cfg) {\
1248
1293
&(struct mux_cfg) {\
@@ -1965,13 +2010,10 @@ static const struct clock_config stm32mp1_clock_cfg[] = {
1965
2010
_DIV (RCC_ETHCKSELR , 4 , 4 , 0 , NULL )),
1966
2011
1967
2012
/* 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 ,
1972
2014
_GATE (RCC_BDCR , 20 , 0 ),
1973
2015
_MUX (RCC_BDCR , 16 , 2 , 0 ),
1974
- _NO_DIV ),
2016
+ _DIV_RTC ( RCC_RTCDIVR , 0 , 6 , 0 , NULL ) ),
1975
2017
1976
2018
/* MCO clocks */
1977
2019
COMPOSITE (CK_MCO1 , "ck_mco1" , mco1_src , CLK_OPS_PARENT_ENABLE |
0 commit comments