Clock device tree configuration

Revision as of 16:36, 24 May 2022 by Registered User (→‎DT configuration (board level))
Applicable for STM32MP13x lines, STM32MP15x lines

1. Article purpose[edit source]

The purpose of this article is to explain how to configure the RCC internal peripheral clocks using the device tree mechanism, relying on the bindings documentation, that is the description of the required and optional device-tree properties.

The peripheral can be assigned to different contexts/software components, depending on the final product needs. Refer to How to assign an internal peripheral to a runtime context article for guidelines on this configuration .

2. DT bindings documentation[edit source]

The device tree binding documents are stored either in the given applicable components listed below, or in the Linux kernel repository:

3. DT configuration[edit source]

This hardware description is a combination of the STM32 microprocessor device tree files (.dtsi extension) and board device tree files (.dts extension). See the Device tree for an explanation of the device-tree file organization.

STM32CubeMX can be used to generate the board device tree. Refer to How to configure the DT using STM32CubeMX for more details.

3.1. DT configuration (STM32/SoC level)[edit source]

The STM32MP1 RCC node is located

  • for STM32MP13x lines More info.png in stm32mp131.dtsi [1]
  • for STM32MP15x lines More info.png in stm32mp151.dtsi [2]

See the example of STM32MP1 RCC clock DT node above in this article, with compatible = "st,stm32mp1-rcc-secure". The node specifies its dependency on the input clock using SCMI clock phandles scmi_clk.

	rcc: rcc@50000000 {
		compatible = "st,stm32mp1-rcc-secure", "st,stm32mp1-rcc", "syscon";
		reg = <0x50000000 0x1000>;
		#clock-cells = <1>;
		#reset-cells = <1>;

		clock-names = "hse", "hsi", "csi", "lse", "lsi";
		clocks = <&scmi_clk CK_SCMI_HSE>,
			 <&scmi_clk CK_SCMI_HSI>,
			 <&scmi_clk CK_SCMI_CSI>,
			 <&scmi_clk CK_SCMI_LSE>,
			 <&scmi_clk CK_SCMI_LSI>;
	};
Warning white.png Warning
This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.

3.2. DT configuration (board level)[edit source]

The objective of this chapter is to explain how to configure a clock tree related to the board.
Using this chapter, the end-user can configure any parameters via the DT to adapt to a new board.

At the first time the clock tree is configured in TF-A BL2 (a minimal configuration) and at the next stage OP-TEE will configure the completed clock tree.

This an example a clock configuration tree:

&rcc {
	compatible = "st,stm32mp13-rcc", "syscon", "st,stm32mp13-rcc-mco";
	pinctrl-0 = <&rcc_mco_pins_a>;
	pinctrl-names = "default";

	st,clksrc = <
		CLK_MPU_PLL1P
		CLK_AXI_PLL2P
		CLK_MLAHBS_PLL3
		CLK_RTC_LSE
		CLK_MCO1_HSE
		...
	>;

	st,clkdiv = <
		DIV(DIV_MPU, 1)
		DIV(DIV_AXI, 0)
		DIV(DIV_MLAHB, 0)
                ...
	>;

	st,pll_vco {
		pll3_vco_417_8Mhz: pll3-vco-417_8Mhz {
			src = < CLK_PLL3_HSE >;
			divmn = < 1 33 >;
			frac = < 0x1a04 >;
		};

		pll4_vco_600Mhz: pll4-vco-600Mhz {
			src = < CLK_PLL4_HSE >;
			divmn = < 1 49 >;
		};
	};




	/* VCO = 417.8 MHz => P = 209, Q = 24, R = 11 */
	pll3:st,pll@2 {
		compatible = "st,stm32mp1-pll";
		reg = <2>;

		st,pll = < &pll3_cfg1 >;

		pll3_cfg1: pll3_cfg1 {
			st,pll_vco = < &pll3_vco_417_8Mhz >;
			st,pll_div_pqr = < 1 16 36 >;
		};
	};

	/* VCO = 600.0 MHz => P = 50, Q = 10, R = 50 */
	pll4:st,pll@3 {
		compatible = "st,stm32mp1-pll";
		reg = <3>;
		st,pll = < &pll4_cfg1 >;

		pll4_cfg1: pll4_cfg1 {
			st,pll_vco = < &pll4_vco_600Mhz >;
			st,pll_div_pqr = < 11 59 11 >;
		};
	};
};

You can find a full example of the boar configuration here stm32mp135f-dk.dts

3.3. DT configuration examples[edit source]

This OPTIONAL chapter must provide an example of how to configure the DT to adapt it to a new board.

4. Clock device providers[edit source]

There are 3 clock providers in the STM32MP1. Each are represented by node(s) in the device tree description.

  • Fixed clocks, as input clocks with a fixed frequency.
  • STM32MP1 RCC clocks, most of the system clocks.
  • SCMI clocks, clocks that only the secure world can manipulate, and that the secure world exposes to non-secure world using the SCMI clock protocol and a client/server communication.

The node defines #clock-cells = <1>;.
In the device tree bindings, all clock providers must define a specific specifier for the number cells used with the clock device phandle, when referring to the clock.

  • When #clock-cells = 0, the clock provider phandle does not need an extra argument..
  • When #clock-cells = 1, the clock provider phandle is used with an argument..

The STM32MP1 RCC clock and SCMI clock drivers both use stm32mp1 clock DT binding IDs defined

  • for STM32MP13x lines More info.png in stm32mp13-clks.h [3]
  • for STM32MP15x lines More info.png in stm32mp1-clks.h [4]

4.1. STM32MP1 RCC clock device[edit source]

The device tree defines the RCC clock controller device as a node with compatible = "st,stm32mp1-rcc" or "st,stm32mp1-rcc-secure" node.

  • "st,stm32mp1-rcc-secure" complies with configuration where RCC TZEN secure hardening is enabled.
  • "st,stm32mp1-rcc" complies with configuration where RCC TZEN secure hardening is disabled.

For example, below is an extract from the Linux kernel and U-Boot device tree representation.

	rcc: rcc@50000000 {
		compatible = "st,stm32mp1-rcc-secure", "st,stm32mp1-rcc", "syscon";
		reg = <0x50000000 0x1000>;
		#clock-cells = <1>;
		#reset-cells = <1>;

		clock-names = "hse", "hsi", "csi", "lse", "lsi";
		clocks = <&scmi_clk CK_SCMI_HSE>,
			 <&scmi_clk CK_SCMI_HSI>,
			 <&scmi_clk CK_SCMI_CSI>,
			 <&scmi_clk CK_SCMI_LSE>,
			 <&scmi_clk CK_SCMI_LSI>;
	};

Note in the file snipped above the STM32MP1 RCC clocks depend on system clocks registered by the SCMI device using the phandles &scmi_clk. Declaring this dependency helps the Linux kernel and U-Boot boot loader to proprely handle the platform clocks.

4.2. SCMI clock device[edit source]

The device tree defines SCMI clocks using compatible = "arm,scmi" nodes with subnodes specifying protocol@14 (reg = <0x14>).
The node defines #clock-cells = 1.
The node phandle (label scmi_clk in example below) is used together with a clock ID, using macros CK_SCMI_* defined

  • for STM32MP13x lines More info.png in stm32mp13-clks.h [3]
  • for STM32MP15x lines More info.png in stm32mp1-clks.h [4]

One can refer to the article SCMI overview, chapter STM32MP1 SCMI clock and reset for more details.


  	scmi {
  		compatible = "linaro,scmi-optee";
  		#address-cells = <1>;
  		#size-cells = <0>;
		(...)

  		scmi_clk: protocol@14 {
  			reg = <0x14>;
  			#clock-cells = <1>;
  		};
  	};

The Linux driver handles all STM32MP clocks with the Linux common clock framework. As does U-Boot with its generic clock udevice framework.

The configuration is performed using the device tree mechanism that provides a description of the fixed clocks if any, RCC peripheral clocks and SCMI clocks used.

5. DT bindings documentation[edit source]

The RCC is a multi function device.

Each function is represented by a separate binding document:

  • generic DT bindings[5] used by the Common Clock framework.
  • vendor clock DT bindings[6] used by the clk-stm32mp1 driver: this binding document explains how to write device tree files for clocks.
  • generic SCMI DT bindings[7] for the clock protocol support.

6. DT configuration[edit source]

6.1. DT configuration (STM32 level)[edit source]

The STM32MP1 RCC node is located

  • for STM32MP13x lines More info.png in stm32mp131.dtsi [1]
  • for STM32MP15x lines More info.png in stm32mp151.dtsi [2]

See Device tree for more explanations.

See the example of STM32MP1 RCC clock DT node above in this article, with compatible = "st,stm32mp1-rcc-secure". The node specifies its dependency on the input clock using SCMI clock phandles scmi_clk.

	rcc: rcc@50000000 {
		compatible = "st,stm32mp1-rcc-secure", "st,stm32mp1-rcc", "syscon";
		reg = <0x50000000 0x1000>;
		#clock-cells = <1>;
		#reset-cells = <1>;

		clock-names = "hse", "hsi", "csi", "lse", "lsi";
		clocks = <&scmi_clk CK_SCMI_HSE>,
			 <&scmi_clk CK_SCMI_HSI>,
			 <&scmi_clk CK_SCMI_CSI>,
			 <&scmi_clk CK_SCMI_LSE>,
			 <&scmi_clk CK_SCMI_LSI>;
	};

6.2. DT configuration (board level)[edit source]

If a Linux driver needs a clock, it has to be added in its DT node:

clocks = <handle> It is the list of the handles to use in the device tree to refer to the target clock instance. The can be several clocks listed, separated with coma character ',', i.e. clocks = <handle>, <handle>, <handle>;

In the clock provider node, property #clock-cells defines how many 32-bit IDs are to be used with the device phandle to identify the clock.
When the clock provider defines #clock-cells = 0, <handle> is the single device tree node phandle reference <&phandle>.
When the clock provider defines #clock-cells = 1, <handle> is a pair <&phandel id>'

  • Example:
    usart3: serial@4000f000 {
        compatible = "st,stm32h7-usart";
        reg = <0x4000f000 0x400>;
        interrupts-extended = <&intc GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>,
                              <&exti 28 1>;
        clocks = <&rcc USART3_K>;
        power-domains = <&pd_core>;
    };

    usart1: serial@5c000000 {
        compatible = "st,stm32h7-usart";
        reg = <0x5c000000 0x400>;
        interrupts-extended = <&intc GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>,
                              <&exti 28 1>;
        clocks = <&scmi_clk CK_SCMI_USART1>;
        power-domains = <&pd_core>;
    };

7. How to configure the DT using STM32CubeMX[edit source]

The STM32CubeMX tool can be used to configure the STM32MP1 device and get the corresponding platform configuration device tree files.
The STM32CubeMX may not support all the properties described in the above DT bindings documentation paragraph. If so, the tool inserts user sections in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to STM32CubeMX user manual for further information.

8. References[edit source]

Please refer to the following links for additional information: