Clock device tree configuration

Revision as of 15:19, 16 June 2020 by Registered User ([review] →‎DT configuration (board level): address comment)

1. Article purpose[edit source]

This article explains how to configure the clocks in STMP32MP.

This article focuses on the non-secure world configuration with the device tree technology. Specific articles describe the bootlader stage clock configuration or the alternate ways when when disabling RCC TZEN hardening in non-secure RCC configuration article.

2. Clock device providers[edit source]

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

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

The node defines #clock-cells = <1>;.
In device tree bindings, all clock providers shall define a specific specifier for the number cells used with clock device phandle, when referring to the clock. When #clock-cells = 0, the clock provider phandle does not need extra argument. When #clock-cells = 1, the clock provider phandle is used with an argument. STM32MP1 RCC clock and SCMI clock drivers both uses stm32mp1 clock DT binding IDs defined in the STM32MP1 Clock DT bindings[1].

2.1. STM32MP1 RCC clock device[edit source]

Device tree defines the RCC clock controllers 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 = <&scmi0_clk CK_SCMI0_HSE>,
			 <&scmi0_clk CK_SCMI0_HSI>,
			 <&scmi0_clk CK_SCMI0_CSI>,
			 <&scmi0_clk CK_SCMI0_LSE>,
			 <&scmi0_clk CK_SCMI0_LSI>;
	};

Note in file snipped above the STM32MP1 RCC clocks depends on system clocks registered by SCMI device since the phandles &scmi0_clk used. Declaring this dependency help Linux kernel and U-Boot boot loader to proprely handle the platform clocks.

2.2. SCMI clock device[edit source]

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 scmi1_clk in exmaple below) is used together with a clock ID, using macros CK_SCMI1_* defined in the DT bindings[2]. One can refer to article STM32MP15 SCMI clock and reset devices for more details.

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

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

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.

3. DT bindings documentation[edit source]

The RCC is a multi function device.

Each function is represented by a separate binding document:

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

4. DT configuration[edit source]

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

The STM32MP1 Clock node is located in the stm32mp151.dtsi[6]. 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 input clock using SCMI clock phandles scmi0_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 = <&scmi0_clk CK_SCMI0_HSE>,
			 <&scmi0_clk CK_SCMI0_HSI>,
			 <&scmi0_clk CK_SCMI0_CSI>,
			 <&scmi0_clk CK_SCMI0_LSE>,
			 <&scmi0_clk CK_SCMI0_LSI>;
	};

4.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 clock provider node, property #clock-cells defines how many 32 bit IDs are to be used with device phandle to identify the clock.
When clock provider defines #clock-cells = 0, <handle> is the single device tree node phandle reference <&phandle>.
When 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 = <&scmi0_clk CK_SCMI0_USART1>;
        power-domains = <&pd_core>;
    };

   

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

The STM32CubeMX tool can be used to configure the STM32MPU 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.

6. References[edit source]

Please refer to the following links for additional information:

  1. include/dt-bindings/clock/stm32mp1-clks.h STM32MP1 Clock DT bindings header file
  2. include/dt-bindings/clock/stm32mp1-clks.h STM32MP1 Reset DT bindings header file
  3. Documentation/devicetree/bindings/clock/clock-bindings.txt , Clock device tree bindings
  4. Documentation/devicetree/bindings/clock/st,stm32mp1-rcc.txt , STM32MP1 clock device tree bindings
  5. >Documentation/devicetree/bindings/arm/arm,scmi.txt SCMI DT bindings
  6. stm32mp151.dtsi STM32MP157C device tree file