soc: nxp: kwx: move clk divider options to device tree

Use kinetis SIM clock divider options set in device tree
instead of kconfig.

Both the kw40z and kw41z device tree originally used an
undefined "nxp,kw41z-mcg" binding for the MCG node.
This has been replaced with the general "nxp,kinetis-mcg"
binding instead.

Signed-off-by: Mikkel Jakobsen <mikkel.aunsbjerg@prevas.dk>
This commit is contained in:
Mikkel Jakobsen 2021-03-04 18:02:48 +01:00 committed by Maureen Helm
commit 68e8a4870d
6 changed files with 70 additions and 35 deletions

View file

@ -59,8 +59,28 @@
compatible = "nxp,kinetis-sim"; compatible = "nxp,kinetis-sim";
reg = <0x40047000 0x1060>; reg = <0x40047000 0x1060>;
label = "SIM"; label = "SIM";
#clock-cells = <3>; #clock-cells = <3>;
core_clk {
compatible = "fixed-factor-clock";
clocks = <&mcg KINETIS_MCG_OUT_CLK>;
clock-div = <1>;
#clock-cells = <0>;
};
bus_clk {
compatible = "fixed-factor-clock";
clocks = <&mcg KINETIS_MCG_OUT_CLK>;
clock-div = <1>;
#clock-cells = <0>;
};
flash_clk {
compatible = "fixed-factor-clock";
clocks = <&mcg KINETIS_MCG_OUT_CLK>;
clock-div = <2>;
#clock-cells = <0>;
};
}; };
ftfl: flash-controller@40020000 { ftfl: flash-controller@40020000 {

View file

@ -3,6 +3,7 @@
#include <mem.h> #include <mem.h>
#include "armv6-m.dtsi" #include "armv6-m.dtsi"
#include <dt-bindings/clock/kinetis_sim.h> #include <dt-bindings/clock/kinetis_sim.h>
#include <dt-bindings/clock/kinetis_mcg.h>
#include <dt-bindings/gpio/gpio.h> #include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/i2c/i2c.h> #include <dt-bindings/i2c/i2c.h>
@ -29,8 +30,10 @@
soc { soc {
mcg: clock-controller@40064000 { mcg: clock-controller@40064000 {
compatible = "nxp,kw41z-mcg"; compatible = "nxp,kinetis-mcg";
reg = <0x40064000 0x13>; reg = <0x40064000 0x13>;
label = "MCG";
#clock-cells = <1>;
}; };
osc: clock-controller@40065000 { osc: clock-controller@40065000 {
@ -49,8 +52,21 @@
compatible = "nxp,kinetis-sim"; compatible = "nxp,kinetis-sim";
reg = <0x40047000 0x1060>; reg = <0x40047000 0x1060>;
label = "SIM"; label = "SIM";
#clock-cells = <3>; #clock-cells = <3>;
core_clk {
compatible = "fixed-factor-clock";
clocks = <&mcg KINETIS_MCG_OUT_CLK>;
clock-div = <1>;
#clock-cells = <0>;
};
flash_clk {
compatible = "fixed-factor-clock";
clocks = <&mcg KINETIS_MCG_OUT_CLK>;
clock-div = <2>;
#clock-cells = <0>;
};
}; };
ftfa: flash-controller@40020000 { ftfa: flash-controller@40020000 {

View file

@ -35,7 +35,7 @@
soc { soc {
mcg: clock-controller@40064000 { mcg: clock-controller@40064000 {
compatible = "nxp,kw41z-mcg"; compatible = "nxp,kinetis-mcg";
reg = <0x40064000 0x13>; reg = <0x40064000 0x13>;
label = "MCG"; label = "MCG";
#clock-cells = <1>; #clock-cells = <1>;
@ -60,8 +60,21 @@
compatible = "nxp,kinetis-sim"; compatible = "nxp,kinetis-sim";
reg = <0x40047000 0x1060>; reg = <0x40047000 0x1060>;
label = "SIM"; label = "SIM";
#clock-cells = <3>; #clock-cells = <3>;
core_clk {
compatible = "fixed-factor-clock";
clocks = <&mcg KINETIS_MCG_OUT_CLK>;
clock-div = <1>;
#clock-cells = <0>;
};
flash_clk {
compatible = "fixed-factor-clock";
clocks = <&mcg KINETIS_MCG_OUT_CLK>;
clock-div = <2>;
#clock-cells = <0>;
};
}; };
ftfa: flash-controller@40020000 { ftfa: flash-controller@40020000 {

View file

@ -89,29 +89,4 @@ config SOC_PART_NUMBER_KINETIS_KWX
that you should not set directly. The part number selection choice defines that you should not set directly. The part number selection choice defines
the default value for this string. the default value for this string.
if SOC_MKW24D5 || SOC_MKW22D5
config KW2XD_CORE_CLOCK_DIVIDER
int "KW2xD core clock divider"
default 1
help
This option specifies the divide value for the KW2xD processor core
clock from the system clock.
config KW2XD_BUS_CLOCK_DIVIDER
int "KW2xD bus clock divider"
default 1
help
This option specifies the divide value for the KW2xD bus clock from
the system clock.
config KW2XD_FLASH_CLOCK_DIVIDER
int "KW2xD flash clock divider"
default 2
help
This option specifies the divide value for the KW2xD flash clock from
the system clock.
endif # SOC_MKW24D5 || SOC_MKW22D5
endif # SOC_SERIES_KINETIS_KWX endif # SOC_SERIES_KINETIS_KWX

View file

@ -26,6 +26,12 @@
#define TIMESRC_OSCERCLK (2) #define TIMESRC_OSCERCLK (2)
#define CLOCK_NODEID(clk) \
DT_CHILD(DT_INST(0, nxp_kinetis_sim), clk)
#define CLOCK_DIVIDER(clk) \
DT_PROP_OR(CLOCK_NODEID(clk), clock_div, 1) - 1
static const osc_config_t oscConfig = { static const osc_config_t oscConfig = {
.freq = CONFIG_OSC_XTAL0_FREQ, .freq = CONFIG_OSC_XTAL0_FREQ,
.capLoad = 0, .capLoad = 0,
@ -58,9 +64,9 @@ static const mcg_pll_config_t pll0Config = {
static const sim_clock_config_t simConfig = { static const sim_clock_config_t simConfig = {
.pllFllSel = PLLFLLSEL_MCGPLLCLK, /* PLLFLLSEL select PLL. */ .pllFllSel = PLLFLLSEL_MCGPLLCLK, /* PLLFLLSEL select PLL. */
.er32kSrc = ER32KSEL_RTC, /* ERCLK32K selection, use RTC. */ .er32kSrc = ER32KSEL_RTC, /* ERCLK32K selection, use RTC. */
.clkdiv1 = SIM_CLKDIV1_OUTDIV1(CONFIG_KW2XD_CORE_CLOCK_DIVIDER - 1) | .clkdiv1 = SIM_CLKDIV1_OUTDIV1(CLOCK_DIVIDER(core_clk)) |
SIM_CLKDIV1_OUTDIV2(CONFIG_KW2XD_BUS_CLOCK_DIVIDER - 1) | SIM_CLKDIV1_OUTDIV2(CLOCK_DIVIDER(bus_clk)) |
SIM_CLKDIV1_OUTDIV4(CONFIG_KW2XD_FLASH_CLOCK_DIVIDER - 1), SIM_CLKDIV1_OUTDIV4(CLOCK_DIVIDER(flash_clk)),
}; };
/** /**

View file

@ -16,7 +16,11 @@
#define LPUART0SRC_OSCERCLK (1) #define LPUART0SRC_OSCERCLK (1)
#define TPMSRC_MCGPLLCLK (1) #define TPMSRC_MCGPLLCLK (1)
#define CLKDIV1_DIVBY2 (1) #define CLOCK_NODEID(clk) \
DT_CHILD(DT_INST(0, nxp_kinetis_sim), clk)
#define CLOCK_DIVIDER(clk) \
DT_PROP_OR(CLOCK_NODEID(clk), clock_div, 1) - 1
static const osc_config_t oscConfig = { static const osc_config_t oscConfig = {
.freq = CONFIG_OSC_XTAL0_FREQ, .freq = CONFIG_OSC_XTAL0_FREQ,
@ -34,7 +38,8 @@ static const osc_config_t oscConfig = {
static const sim_clock_config_t simConfig = { static const sim_clock_config_t simConfig = {
.er32kSrc = DT_PROP(DT_INST(0, nxp_kinetis_sim), er32k_select), .er32kSrc = DT_PROP(DT_INST(0, nxp_kinetis_sim), er32k_select),
.clkdiv1 = SIM_CLKDIV1_OUTDIV4(CLKDIV1_DIVBY2), .clkdiv1 = SIM_CLKDIV1_OUTDIV1(CLOCK_DIVIDER(core_clk)) |
SIM_CLKDIV1_OUTDIV4(CLOCK_DIVIDER(flash_clk)),
}; };
/* This function comes from the MCUX SDK: /* This function comes from the MCUX SDK: