1# Copyright (c) 2021, Linaro ltd
2# SPDX-License-Identifier: Apache-2.0
3
4description: |
5  STM32 RCC (Reset and Clock controller).
6
7  This node is in charge of system clock ('SYSCLK') source selection and controlling
8  clocks for AHB (Advanced High Performance) and APB (Advanced Peripheral) bus domains.
9
10  Configuring STM32 Reset and Clock controller node:
11
12  System clock source should be selected amongst the clock nodes available in "clocks"
13  node (typically 'clk_hse, clk_hsi', 'pll', ...).
14  Core clock frequency should also be defined, using "clock-frequency" property.
15  Note:
16          Core clock frequency  = SYSCLK / AHB prescaler
17  Last, peripheral bus clocks (typically PCLK1, PCLK2) should be configured using matching
18  prescaler properties.
19  Here is an example of correctly configured rcc node:
20  &rcc {
21           clocks = <&pll>;  /* Select 80MHz pll as SYSCLK source */
22           ahb-prescaler = <2>;
23           clock-frequency = <DT_FREQ_M(40)>; /* = SYSCLK / AHB prescaler */
24           apb1-prescaler = <1>;
25           apb2-prescaler = <1>;
26  }
27
28  Specifying a gated clock:
29
30  To specify a gated clock, a peripheral should define a "clocks" property encoded
31  in the following way:
32  ... {
33           ...
34           clocks = <&rcc STM32_CLOCK_BUS_APB2 0x00000020>;
35           ...
36  }
37  After the phandle referring to rcc node, the first index specifies the registers of
38  the bus controlling the peripheral and the second index specifies the bit used to
39  control the peripheral clock in that bus register.
40  The gated clock is required when accessing to the peripheral controller is needed
41  (generally for configuring the device). If dual clock domain is not used, it is
42  also used for peripheral operation.
43
44  Specifying a domain clock source:
45
46  Specifying a domain source clock could be done by adding a clock specifier to the
47  clock property:
48  ... {
49           ...
50           clocks = <&rcc STM32_CLOCK_BUS_APB2 0x00000020>,
51                        <&rcc STM32_SRC_HSI I2C1_SEL(2)>;
52           ...
53  }
54  In this example, I2C1 device is assigned HSI as domain clock source.
55  Domain clock is independent from the bus/gated clock and allows access to the device's
56  register while the gated clock is off. As it doesn't feed the peripheral's controller, it
57  allows peripheral operation, but can't be used for peripheral configuration.
58  It is peripheral driver's responsibility to query and use clock source information in
59  accordance with clock_control API specifications.
60
61  Since the peripheral subsystem rate is dictated by the clock used for peripheral
62  operation, same clock should be used in calls to `clock_control_get_rate()`
63
64  Note 1: No additional specifier means gating clock is also the clock source (ie
65          'PCLK/PCLK1/PCLK2' depending on the device). There is no need to add a second
66          cell to explicitly set it.
67  Note 2: Default peripheral clock configuration (ie the one provided in *.dsti files)
68          should be the one matching SoC reset state. Confere reference manual to check
69          what is the reset value of the clock source for each peripheral.
70
71  Specifying a divided domain clock source:
72
73  Some peripherals are sourced through fixed clock dividers. For such cases there is
74  STM32_CLOCK_DIV() macro, which allows to specify such divider value. Selecting HSE/2 (HSE
75  frequency divided by 2) is done with following clock property:
76  ... {
77           ...
78           clocks = <&rcc (STM32_SRC_HSE | STM32_CLOCK_DIV(2)) ...>;
79           ...
80  }
81
82compatible: "st,stm32-rcc"
83
84include: [clock-controller.yaml, base.yaml]
85
86properties:
87  reg:
88    required: true
89
90  "#clock-cells":
91    const: 2
92
93  clock-frequency:
94    required: true
95    type: int
96    description: |
97      default frequency in Hz for clock output
98
99  ahb-prescaler:
100    type: int
101    required: true
102    enum:
103      - 1
104      - 2
105      - 4
106      - 8
107      - 16
108      - 64
109      - 128
110      - 256
111      - 512
112    description: |
113        AHB prescaler. Defines actual core clock frequency (HCLK)
114        based on system frequency input.
115        The HCLK clocks CPU, AHB, memories and DMA.
116
117  apb1-prescaler:
118    type: int
119    required: true
120    enum:
121      - 1
122      - 2
123      - 4
124      - 8
125      - 16
126
127  apb2-prescaler:
128    type: int
129    required: true
130    enum:
131      - 1
132      - 2
133      - 4
134      - 8
135      - 16
136
137  undershoot-prevention:
138    type: boolean
139    description: |
140      On some parts, it could be required to set up highest core frequencies
141      (>80MHz) in two steps in order to prevent undershoot.
142      This is done by applying an intermediate AHB prescaler before switching
143      System Clock source to PLL. Once done, prescaler is set back to expected
144      value.
145
146clock-cells:
147  - bus
148  - bits
149