@@ -71,6 +71,58 @@ static const char *ice_tspll_clk_freq_str(enum ice_tspll_freq clk_freq)
7171 }
7272}
7373
74+ /**
75+ * ice_tspll_default_freq - Return default frequency for a MAC type
76+ * @mac_type: MAC type
77+ *
78+ * Return: default TSPLL frequency for a correct MAC type, -ERANGE otherwise.
79+ */
80+ static enum ice_tspll_freq ice_tspll_default_freq (enum ice_mac_type mac_type )
81+ {
82+ switch (mac_type ) {
83+ case ICE_MAC_GENERIC :
84+ return ICE_TSPLL_FREQ_25_000 ;
85+ case ICE_MAC_GENERIC_3K_E825 :
86+ return ICE_TSPLL_FREQ_156_250 ;
87+ default :
88+ return - ERANGE ;
89+ }
90+ }
91+
92+ /**
93+ * ice_tspll_check_params - Check if TSPLL params are correct
94+ * @hw: Pointer to the HW struct
95+ * @clk_freq: Clock frequency to program
96+ * @clk_src: Clock source to select (TIME_REF or TCXO)
97+ *
98+ * Return: true if TSPLL params are correct, false otherwise.
99+ */
100+ static bool ice_tspll_check_params (struct ice_hw * hw ,
101+ enum ice_tspll_freq clk_freq ,
102+ enum ice_clk_src clk_src )
103+ {
104+ if (clk_freq >= NUM_ICE_TSPLL_FREQ ) {
105+ dev_warn (ice_hw_to_dev (hw ), "Invalid TSPLL frequency %u\n" ,
106+ clk_freq );
107+ return false;
108+ }
109+
110+ if (clk_src >= NUM_ICE_CLK_SRC ) {
111+ dev_warn (ice_hw_to_dev (hw ), "Invalid clock source %u\n" ,
112+ clk_src );
113+ return false;
114+ }
115+
116+ if ((hw -> mac_type == ICE_MAC_GENERIC_3K_E825 ||
117+ clk_src == ICE_CLK_SRC_TCXO ) &&
118+ clk_freq != ice_tspll_default_freq (hw -> mac_type )) {
119+ dev_warn (ice_hw_to_dev (hw ), "Unsupported frequency for this clock source\n" );
120+ return false;
121+ }
122+
123+ return true;
124+ }
125+
74126/**
75127 * ice_tspll_clk_src_str - Convert time_ref_src to string
76128 * @clk_src: Clock source
@@ -130,24 +182,6 @@ static int ice_tspll_cfg_e82x(struct ice_hw *hw, enum ice_tspll_freq clk_freq,
130182 u32 val , r9 , r24 ;
131183 int err ;
132184
133- if (clk_freq >= NUM_ICE_TSPLL_FREQ ) {
134- dev_warn (ice_hw_to_dev (hw ), "Invalid TIME_REF frequency %u\n" ,
135- clk_freq );
136- return - EINVAL ;
137- }
138-
139- if (clk_src >= NUM_ICE_CLK_SRC ) {
140- dev_warn (ice_hw_to_dev (hw ), "Invalid clock source %u\n" ,
141- clk_src );
142- return - EINVAL ;
143- }
144-
145- if (clk_src == ICE_CLK_SRC_TCXO && clk_freq != ICE_TSPLL_FREQ_25_000 ) {
146- dev_warn (ice_hw_to_dev (hw ),
147- "TCXO only supports 25 MHz frequency\n" );
148- return - EINVAL ;
149- }
150-
151185 err = ice_read_cgu_reg (hw , ICE_CGU_R9 , & r9 );
152186 if (err )
153187 return err ;
@@ -306,23 +340,6 @@ static int ice_tspll_cfg_e825c(struct ice_hw *hw, enum ice_tspll_freq clk_freq,
306340 u32 val , r9 , r23 ;
307341 int err ;
308342
309- if (clk_freq >= NUM_ICE_TSPLL_FREQ ) {
310- dev_warn (ice_hw_to_dev (hw ), "Invalid TIME_REF frequency %u\n" ,
311- clk_freq );
312- return - EINVAL ;
313- }
314-
315- if (clk_src >= NUM_ICE_CLK_SRC ) {
316- dev_warn (ice_hw_to_dev (hw ), "Invalid clock source %u\n" ,
317- clk_src );
318- return - EINVAL ;
319- }
320-
321- if (clk_freq != ICE_TSPLL_FREQ_156_250 ) {
322- dev_warn (ice_hw_to_dev (hw ), "Adapter only supports 156.25 MHz frequency\n" );
323- return - EINVAL ;
324- }
325-
326343 err = ice_read_cgu_reg (hw , ICE_CGU_R9 , & r9 );
327344 if (err )
328345 return err ;
@@ -508,6 +525,52 @@ int ice_tspll_cfg_pps_out_e825c(struct ice_hw *hw, bool enable)
508525 return ice_write_cgu_reg (hw , ICE_CGU_R9 , val );
509526}
510527
528+ /**
529+ * ice_tspll_cfg - Configure the Clock Generation Unit TSPLL
530+ * @hw: Pointer to the HW struct
531+ * @clk_freq: Clock frequency to program
532+ * @clk_src: Clock source to select (TIME_REF, or TCXO)
533+ *
534+ * Configure the Clock Generation Unit with the desired clock frequency and
535+ * time reference, enabling the TSPLL which drives the PTP hardware clock.
536+ *
537+ * Return: 0 on success, -ERANGE on unsupported MAC type, other negative error
538+ * codes when failed to configure CGU.
539+ */
540+ static int ice_tspll_cfg (struct ice_hw * hw , enum ice_tspll_freq clk_freq ,
541+ enum ice_clk_src clk_src )
542+ {
543+ switch (hw -> mac_type ) {
544+ case ICE_MAC_GENERIC :
545+ return ice_tspll_cfg_e82x (hw , clk_freq , clk_src );
546+ case ICE_MAC_GENERIC_3K_E825 :
547+ return ice_tspll_cfg_e825c (hw , clk_freq , clk_src );
548+ default :
549+ return - ERANGE ;
550+ }
551+ }
552+
553+ /**
554+ * ice_tspll_dis_sticky_bits - disable TSPLL sticky bits
555+ * @hw: Pointer to the HW struct
556+ *
557+ * Configure the Clock Generation Unit TSPLL sticky bits so they don't latch on
558+ * losing TSPLL lock, but always show current state.
559+ *
560+ * Return: 0 on success, -ERANGE on unsupported MAC type.
561+ */
562+ static int ice_tspll_dis_sticky_bits (struct ice_hw * hw )
563+ {
564+ switch (hw -> mac_type ) {
565+ case ICE_MAC_GENERIC :
566+ return ice_tspll_dis_sticky_bits_e82x (hw );
567+ case ICE_MAC_GENERIC_3K_E825 :
568+ return ice_tspll_dis_sticky_bits_e825c (hw );
569+ default :
570+ return - ERANGE ;
571+ }
572+ }
573+
511574/**
512575 * ice_tspll_init - Initialize TSPLL with settings from firmware
513576 * @hw: Pointer to the HW structure
@@ -519,25 +582,22 @@ int ice_tspll_cfg_pps_out_e825c(struct ice_hw *hw, bool enable)
519582int ice_tspll_init (struct ice_hw * hw )
520583{
521584 struct ice_ts_func_info * ts_info = & hw -> func_caps .ts_func_info ;
585+ enum ice_tspll_freq tspll_freq ;
586+ enum ice_clk_src clk_src ;
522587 int err ;
523588
524- /* Disable sticky lock detection so lock err reported is accurate. */
525- if (hw -> mac_type == ICE_MAC_GENERIC_3K_E825 )
526- err = ice_tspll_dis_sticky_bits_e825c (hw );
527- else
528- err = ice_tspll_dis_sticky_bits_e82x (hw );
589+ tspll_freq = (enum ice_tspll_freq )ts_info -> time_ref ;
590+ clk_src = (enum ice_clk_src )ts_info -> clk_src ;
591+ if (!ice_tspll_check_params (hw , tspll_freq , clk_src ))
592+ return - EINVAL ;
593+
594+ /* Disable sticky lock detection so lock status reported is accurate */
595+ err = ice_tspll_dis_sticky_bits (hw );
529596 if (err )
530597 return err ;
531598
532599 /* Configure the TSPLL using the parameters from the function
533600 * capabilities.
534601 */
535- if (hw -> mac_type == ICE_MAC_GENERIC_3K_E825 )
536- err = ice_tspll_cfg_e825c (hw , ts_info -> time_ref ,
537- (enum ice_clk_src )ts_info -> clk_src );
538- else
539- err = ice_tspll_cfg_e82x (hw , ts_info -> time_ref ,
540- (enum ice_clk_src )ts_info -> clk_src );
541-
542- return err ;
602+ return ice_tspll_cfg (hw , tspll_freq , clk_src );
543603}
0 commit comments