1266fa4dfSPatrick DelaunaySTMicroelectronics STM32MP1 clock tree initialization
2266fa4dfSPatrick Delaunay=====================================================
3266fa4dfSPatrick Delaunay
4266fa4dfSPatrick DelaunayThe STM32MP clock tree initialization is based on device tree information
5266fa4dfSPatrick Delaunayfor RCC IP and on fixed clocks.
6266fa4dfSPatrick Delaunay
7266fa4dfSPatrick Delaunay-------------------------------
8266fa4dfSPatrick DelaunayRCC CLOCK = st,stm32mp1-rcc-clk
9266fa4dfSPatrick Delaunay-------------------------------
10266fa4dfSPatrick Delaunay
11266fa4dfSPatrick DelaunayThe RCC IP is both a reset and a clock controller but this documentation only
12266fa4dfSPatrick Delaunaydescribes the fields added for clock tree initialization which are not present
13266fa4dfSPatrick Delaunayin Linux binding.
14266fa4dfSPatrick Delaunay
15266fa4dfSPatrick DelaunayPlease refer to ../mfd/st,stm32-rcc.txt for all the other properties common
16266fa4dfSPatrick Delaunaywith Linux.
17266fa4dfSPatrick Delaunay
18266fa4dfSPatrick DelaunayRequired properties:
19266fa4dfSPatrick Delaunay
20266fa4dfSPatrick Delaunay- compatible: Should be "st,stm32mp1-rcc-clk"
21266fa4dfSPatrick Delaunay
22266fa4dfSPatrick Delaunay- st,clksrc : The clock source in this order
23266fa4dfSPatrick Delaunay
24266fa4dfSPatrick Delaunay	for STM32MP15x: 9 clock sources are requested
25266fa4dfSPatrick Delaunay		MPU AXI MCU PLL12 PLL3 PLL4 RTC MCO1 MCO2
26266fa4dfSPatrick Delaunay
27266fa4dfSPatrick Delaunay	with value equals to RCC clock specifier as defined in
28266fa4dfSPatrick Delaunay	dt-bindings/clock/stm32mp1-clksrc.h: CLK_<NAME>_<SOURCE>
29266fa4dfSPatrick Delaunay
30266fa4dfSPatrick Delaunay- st,clkdiv : The div parameters in this order
31266fa4dfSPatrick Delaunay	for STM32MP15x: 11 dividers value are requested
32266fa4dfSPatrick Delaunay		MPU AXI MCU APB1 APB2 APB3 APB4 APB5 RTC MCO1 MCO2
33266fa4dfSPatrick Delaunay
34266fa4dfSPatrick Delaunay	with DIV coding defined in RCC associated register RCC_xxxDIVR
35266fa4dfSPatrick Delaunay
36266fa4dfSPatrick Delaunay	most the case, it is:
37266fa4dfSPatrick Delaunay		0x0: not divided
38266fa4dfSPatrick Delaunay		0x1: division by 2
39266fa4dfSPatrick Delaunay		0x2: division by 4
40266fa4dfSPatrick Delaunay		0x3: division by 8
41266fa4dfSPatrick Delaunay		...
42266fa4dfSPatrick Delaunay
43266fa4dfSPatrick Delaunay	but for RTC MCO1 MCO2, the coding is different:
44266fa4dfSPatrick Delaunay		0x0: not divided
45266fa4dfSPatrick Delaunay		0x1: division by 2
46266fa4dfSPatrick Delaunay		0x2: division by 3
47266fa4dfSPatrick Delaunay		0x3: division by 4
48266fa4dfSPatrick Delaunay		...
49266fa4dfSPatrick Delaunay
50266fa4dfSPatrick DelaunayOptional Properties:
51266fa4dfSPatrick Delaunay- st,pll
52266fa4dfSPatrick Delaunay    PLL children node for PLL1 to PLL4 : (see ref manual for details)
53266fa4dfSPatrick Delaunay    with associated index 0 to 3 (st,pll@0 to st,pll@4)
54266fa4dfSPatrick Delaunay    PLLx is off when the associated node is absent
55266fa4dfSPatrick Delaunay
56266fa4dfSPatrick Delaunay    - Sub-nodes:
57266fa4dfSPatrick Delaunay
58266fa4dfSPatrick Delaunay	- cfg:	The parameters for PLL configuration in this order:
59266fa4dfSPatrick Delaunay		DIVM DIVN DIVP DIVQ DIVR Output
60266fa4dfSPatrick Delaunay
61266fa4dfSPatrick Delaunay		with DIV value as defined in RCC spec:
62266fa4dfSPatrick Delaunay			0x0: bypass (division by 1)
63266fa4dfSPatrick Delaunay			0x1: division by 2
64266fa4dfSPatrick Delaunay			0x2: division by 3
65266fa4dfSPatrick Delaunay			0x3: division by 4
66266fa4dfSPatrick Delaunay			...
67266fa4dfSPatrick Delaunay
68266fa4dfSPatrick Delaunay		and Output = bitfield for each output value = 1:ON/0:OFF
69266fa4dfSPatrick Delaunay			BIT(0) => output P : DIVPEN
70266fa4dfSPatrick Delaunay			BIT(1) => output Q : DIVQEN
71266fa4dfSPatrick Delaunay			BIT(2) => output R : DIVREN
72266fa4dfSPatrick Delaunay		  NB : macro PQR(p,q,r) can be used to build this value
73266fa4dfSPatrick Delaunay		       with p,p,r = 0 or 1
74266fa4dfSPatrick Delaunay
75266fa4dfSPatrick Delaunay	- frac : Fractional part of the multiplication factor
76266fa4dfSPatrick Delaunay		(optional, PLL is in integer mode when absent)
77266fa4dfSPatrick Delaunay
78266fa4dfSPatrick Delaunay	- csg : Clock Spreading Generator (optional)
79266fa4dfSPatrick Delaunay	        with parameters in this order:
80266fa4dfSPatrick Delaunay		MOD_PER INC_STEP SSCG_MODE
81266fa4dfSPatrick Delaunay
82266fa4dfSPatrick Delaunay		* MOD_PER: Modulation Period Adjustment
83266fa4dfSPatrick Delaunay		* INC_STEP: Modulation Depth Adjustment
84266fa4dfSPatrick Delaunay		* SSCG_MODE: Spread spectrum clock generator mode
85266fa4dfSPatrick Delaunay		  you can use associated defines from stm32mp1-clksrc.h
86266fa4dfSPatrick Delaunay		  * SSCG_MODE_CENTER_SPREAD = 0
87266fa4dfSPatrick Delaunay		  * SSCG_MODE_DOWN_SPREAD = 1
88266fa4dfSPatrick Delaunay
89266fa4dfSPatrick Delaunay
90266fa4dfSPatrick Delaunay- st,pkcs : used to configure the peripherals kernel clock selection
91266fa4dfSPatrick Delaunay  containing a list of peripheral kernel clock source identifier as defined
92266fa4dfSPatrick Delaunay  in the file dt-bindings/clock/stm32mp1-clksrc.h
93266fa4dfSPatrick Delaunay
94266fa4dfSPatrick Delaunay  Example:
95266fa4dfSPatrick Delaunay
96266fa4dfSPatrick Delaunay	rcc: rcc@50000000 {
97266fa4dfSPatrick Delaunay		compatible = "syscon", "simple-mfd";
98266fa4dfSPatrick Delaunay
99266fa4dfSPatrick Delaunay		reg = <0x50000000 0x1000>;
100266fa4dfSPatrick Delaunay
101266fa4dfSPatrick Delaunay		rcc_clk: rcc-clk@50000000 {
102266fa4dfSPatrick Delaunay			#clock-cells = <1>;
103266fa4dfSPatrick Delaunay			compatible = "st,stm32mp1-rcc-clk";
104266fa4dfSPatrick Delaunay
105266fa4dfSPatrick Delaunay			st,clksrc = <	CLK_MPU_PLL1P
106266fa4dfSPatrick Delaunay					CLK_AXI_PLL2P
107266fa4dfSPatrick Delaunay					CLK_MCU_HSI
108266fa4dfSPatrick Delaunay					CLK_PLL12_HSE
109266fa4dfSPatrick Delaunay					CLK_PLL3_HSE
110266fa4dfSPatrick Delaunay					CLK_PLL4_HSE
111266fa4dfSPatrick Delaunay					CLK_RTC_HSE
112266fa4dfSPatrick Delaunay					CLK_MCO1_DISABLED
113266fa4dfSPatrick Delaunay					CLK_MCO2_DISABLED
114266fa4dfSPatrick Delaunay			>;
115266fa4dfSPatrick Delaunay
116266fa4dfSPatrick Delaunay			st,clkdiv = <
117266fa4dfSPatrick Delaunay				1 /*MPU*/
118266fa4dfSPatrick Delaunay				0 /*AXI*/
119266fa4dfSPatrick Delaunay				0 /*MCU*/
120266fa4dfSPatrick Delaunay				1 /*APB1*/
121266fa4dfSPatrick Delaunay				1 /*APB2*/
122266fa4dfSPatrick Delaunay				1 /*APB3*/
123266fa4dfSPatrick Delaunay				1 /*APB4*/
124266fa4dfSPatrick Delaunay				5 /*APB5*/
125266fa4dfSPatrick Delaunay				23 /*RTC*/
126266fa4dfSPatrick Delaunay				0 /*MCO1*/
127266fa4dfSPatrick Delaunay				0 /*MCO2*/
128266fa4dfSPatrick Delaunay			>;
129266fa4dfSPatrick Delaunay
130266fa4dfSPatrick Delaunay			st,pll@0 {
131266fa4dfSPatrick Delaunay				cfg = < 1 53 0 0 0 1 >;
132266fa4dfSPatrick Delaunay				frac = < 0x810 >;
133266fa4dfSPatrick Delaunay			};
134266fa4dfSPatrick Delaunay			st,pll@1 {
135266fa4dfSPatrick Delaunay				cfg = < 1 43 1 0 0 PQR(0,1,1) >;
136266fa4dfSPatrick Delaunay				csg = < 10 20 1 >;
137266fa4dfSPatrick Delaunay			};
138266fa4dfSPatrick Delaunay			st,pll@2 {
139266fa4dfSPatrick Delaunay				cfg = < 2 85 3 13 3 0 >;
140266fa4dfSPatrick Delaunay				csg = < 10 20 SSCG_MODE_CENTER_SPREAD >;
141266fa4dfSPatrick Delaunay			};
142266fa4dfSPatrick Delaunay			st,pll@3 {
143266fa4dfSPatrick Delaunay				cfg = < 2 78 4 7 9 3 >;
144266fa4dfSPatrick Delaunay			};
145266fa4dfSPatrick Delaunay			st,pkcs = <
146266fa4dfSPatrick Delaunay					CLK_STGEN_HSE
147266fa4dfSPatrick Delaunay					CLK_CKPER_HSI
148266fa4dfSPatrick Delaunay					CLK_USBPHY_PLL2P
149266fa4dfSPatrick Delaunay					CLK_DSI_PLL2Q
150266fa4dfSPatrick Delaunay				  >;
151266fa4dfSPatrick Delaunay		};
152266fa4dfSPatrick Delaunay	};
153266fa4dfSPatrick Delaunay
154266fa4dfSPatrick Delaunay--------------------------
155266fa4dfSPatrick Delaunayother clocks = fixed-clock
156266fa4dfSPatrick Delaunay--------------------------
157266fa4dfSPatrick DelaunayThe clock tree is also based on 5 fixed-clock in clocks node
158266fa4dfSPatrick Delaunayused to define the state of associated ST32MP1 oscillators:
159266fa4dfSPatrick Delaunay- clk-lsi
160266fa4dfSPatrick Delaunay- clk-lse
161266fa4dfSPatrick Delaunay- clk-hsi
162266fa4dfSPatrick Delaunay- clk-hse
163266fa4dfSPatrick Delaunay- clk-csi
164266fa4dfSPatrick Delaunay
165266fa4dfSPatrick DelaunayAt boot the clock tree initialization will
166266fa4dfSPatrick Delaunay- enable the oscillator present in device tree
167266fa4dfSPatrick Delaunay- disable HSI oscillator if the node is absent (always activated by bootrom)
168266fa4dfSPatrick Delaunay
169266fa4dfSPatrick DelaunayOptional properties :
170266fa4dfSPatrick Delaunay
171266fa4dfSPatrick Delaunaya) for external oscillator: "clk-lse", "clk-hse"
172266fa4dfSPatrick Delaunay
173*d2194155SPatrick Delaunay	4 optional fields are managed
174266fa4dfSPatrick Delaunay	- "st,bypass" Configure the oscillator bypass mode (HSEBYP, LSEBYP)
175*d2194155SPatrick Delaunay	- "st,digbypass" Configure the bypass mode as full-swing digital signal
176*d2194155SPatrick Delaunay	  (DIGBYP)
177266fa4dfSPatrick Delaunay	- "st,css" Activate the clock security system (HSECSSON, LSECSSON)
178266fa4dfSPatrick Delaunay	- "st,drive" (only for LSE) value of the drive for the oscillator
179266fa4dfSPatrick Delaunay	   (see LSEDRV_ define in the file dt-bindings/clock/stm32mp1-clksrc.h)
180266fa4dfSPatrick Delaunay
181266fa4dfSPatrick Delaunay	Example board file:
182266fa4dfSPatrick Delaunay
183266fa4dfSPatrick Delaunay	/ {
184266fa4dfSPatrick Delaunay		clocks {
185266fa4dfSPatrick Delaunay			clk_hse: clk-hse {
186266fa4dfSPatrick Delaunay				#clock-cells = <0>;
187266fa4dfSPatrick Delaunay				compatible = "fixed-clock";
188266fa4dfSPatrick Delaunay				clock-frequency = <64000000>;
189266fa4dfSPatrick Delaunay				st,bypass;
190266fa4dfSPatrick Delaunay			};
191266fa4dfSPatrick Delaunay
192266fa4dfSPatrick Delaunay			clk_lse: clk-lse {
193266fa4dfSPatrick Delaunay				#clock-cells = <0>;
194266fa4dfSPatrick Delaunay				compatible = "fixed-clock";
195266fa4dfSPatrick Delaunay				clock-frequency = <32768>;
196266fa4dfSPatrick Delaunay				st,css;
197266fa4dfSPatrick Delaunay				st,drive = <LSEDRV_LOWEST>;
198266fa4dfSPatrick Delaunay			};
199266fa4dfSPatrick Delaunay	};
200266fa4dfSPatrick Delaunay
201266fa4dfSPatrick Delaunayb) for internal oscillator: "clk-hsi"
202266fa4dfSPatrick Delaunay
203266fa4dfSPatrick Delaunay	internally HSI clock is fixed to 64MHz for STM32MP157 soc
204266fa4dfSPatrick Delaunay	in device tree clk-hsi is the clock after HSIDIV (ck_hsi in RCC doc)
205266fa4dfSPatrick Delaunay	So this clock frequency is used to compute the expected HSI_DIV
206266fa4dfSPatrick Delaunay	for the clock tree initialisation
207266fa4dfSPatrick Delaunay
208266fa4dfSPatrick Delaunay	ex: for HSIDIV = /1
209266fa4dfSPatrick Delaunay
210266fa4dfSPatrick Delaunay	/ {
211266fa4dfSPatrick Delaunay		clocks {
212266fa4dfSPatrick Delaunay			clk_hsi: clk-hsi {
213266fa4dfSPatrick Delaunay				#clock-cells = <0>;
214266fa4dfSPatrick Delaunay				compatible = "fixed-clock";
215266fa4dfSPatrick Delaunay				clock-frequency = <64000000>;
216266fa4dfSPatrick Delaunay			};
217266fa4dfSPatrick Delaunay	};
218266fa4dfSPatrick Delaunay
219266fa4dfSPatrick Delaunay	ex: for HSIDIV = /2
220266fa4dfSPatrick Delaunay
221266fa4dfSPatrick Delaunay	/ {
222266fa4dfSPatrick Delaunay		clocks {
223266fa4dfSPatrick Delaunay			clk_hsi: clk-hsi {
224266fa4dfSPatrick Delaunay				#clock-cells = <0>;
225266fa4dfSPatrick Delaunay				compatible = "fixed-clock";
226266fa4dfSPatrick Delaunay				clock-frequency = <32000000>;
227266fa4dfSPatrick Delaunay			};
228266fa4dfSPatrick Delaunay	};
229