Skip to content

Commit 659eccf

Browse files
FelixWang47831jhedberg
authored andcommitted
drivers: clock_control: Configure STM clock
1.Add "mux-1-dc-0-div" and "mux-2-dc-0-div" property in mc_cgm device tree for STM clock divider setting and set these properties in frdm_mcxe31b.dts 2.Enable STM peripheral clock in mc_cgm_clock_control_on function 3.Support to get STM frequency from mc_cgm_get_subsys_rate function 4.Configure STM clock in mc_cgm_init function Signed-off-by: Felix Wang <[email protected]>
1 parent f305443 commit 659eccf

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

boards/nxp/frdm_mcxe31b/frdm_mcxe31b.dts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@
164164
mux-0-dc-4-div = <4>;
165165
mux-0-dc-5-div = <4>;
166166
mux-0-dc-6-div = <1>;
167+
mux-1-dc-0-div = <1>;
168+
mux-2-dc-0-div = <1>;
167169
};
168170

169171
&stm_0 {

drivers/clock_control/clock_control_nxp_mc_cgm.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ static int mc_cgm_clock_control_on(const struct device *dev, clock_control_subsy
160160
}
161161
#endif /* defined(CONFIG_I2C_MCUX_LPI2C) */
162162

163+
#if defined(CONFIG_COUNTER_MCUX_STM)
164+
switch ((uint32_t)sub_system) {
165+
case MCUX_STM0_CLK:
166+
CLOCK_EnableClock(kCLOCK_Stm0);
167+
break;
168+
case MCUX_STM1_CLK:
169+
CLOCK_EnableClock(kCLOCK_Stm1);
170+
break;
171+
default:
172+
break;
173+
}
174+
#endif /* defined(CONFIG_COUNTER_MCUX_STM) */
175+
163176
return 0;
164177
}
165178

@@ -237,6 +250,15 @@ static int mc_cgm_get_subsys_rate(const struct device *dev, clock_control_subsys
237250
*rate = CLOCK_GetFlexcanPeClkFreq(5);
238251
break;
239252
#endif /* defined(CONFIG_CAN_MCUX_FLEXCAN) */
253+
254+
#if defined(CONFIG_COUNTER_MCUX_STM)
255+
case MCUX_STM0_CLK:
256+
*rate = CLOCK_GetStmClkFreq(0);
257+
break;
258+
case MCUX_STM1_CLK:
259+
*rate = CLOCK_GetStmClkFreq(1);
260+
break;
261+
#endif /* defined(CONFIG_COUNTER_MCUX_STM) */
240262
}
241263
return 0;
242264
}
@@ -297,6 +319,14 @@ static int mc_cgm_init(const struct device *dev)
297319
#endif
298320
CLOCK_CommonTriggerClkMux0DivUpdate();
299321
CLOCK_ProgressiveClockFrequencySwitch(kPLL_PHI0_CLK_to_MUX0, &pcfs_config);
322+
#if defined(CONFIG_COUNTER_MCUX_STM)
323+
CLOCK_SetClkDiv(kCLOCK_DivStm0Clk, NXP_PLL_MUX_1_DC_0_DIV);
324+
CLOCK_AttachClk(kAIPS_PLAT_CLK_to_STM0);
325+
#if defined(FSL_FEATURE_SOC_STM_COUNT) && (FSL_FEATURE_SOC_STM_COUNT == 2U)
326+
CLOCK_SetClkDiv(kCLOCK_DivStm1Clk, NXP_PLL_MUX_2_DC_0_DIV);
327+
CLOCK_AttachClk(kAIPS_PLAT_CLK_to_STM1);
328+
#endif /* FSL_FEATURE_SOC_STM_COUNT == 2U */
329+
#endif /* defined(CONFIG_COUNTER_MCUX_STM) */
300330
#endif
301331

302332
/* Set SystemCoreClock variable. */

dts/bindings/clock/nxp,mc-cgm.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ properties:
5757
type: int
5858
description: MUX_0_DC_6 divider setting
5959

60+
mux-1-dc-0-div:
61+
type: int
62+
description: MUX_1_DC_0 divider setting
63+
64+
mux-2-dc-0-div:
65+
type: int
66+
description: MUX_2_DC_0 divider setting
67+
6068
"#clock-cells":
6169
type: int
6270
const: 1

include/zephyr/dt-bindings/clock/nxp_mc_cgm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define NXP_PLL_MUX_0_DC_4_DIV DT_PROP(DT_NODELABEL(mc_cgm), mux_0_dc_4_div)
1919
#define NXP_PLL_MUX_0_DC_5_DIV DT_PROP(DT_NODELABEL(mc_cgm), mux_0_dc_5_div)
2020
#define NXP_PLL_MUX_0_DC_6_DIV DT_PROP(DT_NODELABEL(mc_cgm), mux_0_dc_6_div)
21+
#define NXP_PLL_MUX_1_DC_0_DIV DT_PROP(DT_NODELABEL(mc_cgm), mux_1_dc_0_div)
22+
#define NXP_PLL_MUX_2_DC_0_DIV DT_PROP(DT_NODELABEL(mc_cgm), mux_2_dc_0_div)
2123

2224
/* Note- clock identifiers in this file must be unique,
2325
* as the driver uses them in a switch case

0 commit comments

Comments
 (0)