xref: /rk3399_ARM-atf/include/dt-bindings/clock/stm32mp21-clksrc.h (revision 4f6c787ef3f156e477a00e5857a39d0972ece3e0)
1*dcb00b10SNicolas Le Bayon /* SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause */
2*dcb00b10SNicolas Le Bayon /*
3*dcb00b10SNicolas Le Bayon  * Copyright (C) 2025, STMicroelectronics - All Rights Reserved
4*dcb00b10SNicolas Le Bayon  */
5*dcb00b10SNicolas Le Bayon 
6*dcb00b10SNicolas Le Bayon #ifndef _DT_BINDINGS_CLOCK_STM32MP21_CLKSRC_H_
7*dcb00b10SNicolas Le Bayon #define _DT_BINDINGS_CLOCK_STM32MP21_CLKSRC_H_
8*dcb00b10SNicolas Le Bayon 
9*dcb00b10SNicolas Le Bayon #define CMD_DIV		0
10*dcb00b10SNicolas Le Bayon #define CMD_MUX		1
11*dcb00b10SNicolas Le Bayon #define CMD_CLK		2
12*dcb00b10SNicolas Le Bayon #define CMD_FLEXGEN	3
13*dcb00b10SNicolas Le Bayon 
14*dcb00b10SNicolas Le Bayon #define CMD_ADDR_BIT	0x80000000
15*dcb00b10SNicolas Le Bayon 
16*dcb00b10SNicolas Le Bayon #define CMD_SHIFT	26
17*dcb00b10SNicolas Le Bayon #define CMD_MASK	0xFC000000
18*dcb00b10SNicolas Le Bayon #define CMD_DATA_MASK	0x03FFFFFF
19*dcb00b10SNicolas Le Bayon 
20*dcb00b10SNicolas Le Bayon #define DIV_ID_SHIFT	8
21*dcb00b10SNicolas Le Bayon #define DIV_ID_MASK	0x0000FF00
22*dcb00b10SNicolas Le Bayon 
23*dcb00b10SNicolas Le Bayon #define DIV_DIVN_SHIFT	0
24*dcb00b10SNicolas Le Bayon #define DIV_DIVN_MASK	0x000000FF
25*dcb00b10SNicolas Le Bayon 
26*dcb00b10SNicolas Le Bayon #define MUX_ID_SHIFT	4
27*dcb00b10SNicolas Le Bayon #define MUX_ID_MASK	0x00000FF0
28*dcb00b10SNicolas Le Bayon 
29*dcb00b10SNicolas Le Bayon #define MUX_SEL_SHIFT	0
30*dcb00b10SNicolas Le Bayon #define MUX_SEL_MASK	0x0000000F
31*dcb00b10SNicolas Le Bayon 
32*dcb00b10SNicolas Le Bayon /* CLK define */
33*dcb00b10SNicolas Le Bayon #define CLK_ON_MASK	BIT(21)
34*dcb00b10SNicolas Le Bayon #define CLK_ON_SHIFT	21
35*dcb00b10SNicolas Le Bayon 
36*dcb00b10SNicolas Le Bayon #define CLK_ID_MASK	GENMASK_32(20, 12)
37*dcb00b10SNicolas Le Bayon #define CLK_ID_SHIFT	12
38*dcb00b10SNicolas Le Bayon 
39*dcb00b10SNicolas Le Bayon #define CLK_NO_DIV_MASK	0x0000080
40*dcb00b10SNicolas Le Bayon #define CLK_DIV_MASK	GENMASK_32(10, 5)
41*dcb00b10SNicolas Le Bayon #define CLK_DIV_SHIFT	5
42*dcb00b10SNicolas Le Bayon 
43*dcb00b10SNicolas Le Bayon #define CLK_NO_SEL_MASK	0x00000010
44*dcb00b10SNicolas Le Bayon #define CLK_SEL_MASK	GENMASK_32(3, 0)
45*dcb00b10SNicolas Le Bayon #define CLK_SEL_SHIFT	0
46*dcb00b10SNicolas Le Bayon 
47*dcb00b10SNicolas Le Bayon #define CLK_CFG(clk_id, sel, div, state)	((CMD_CLK << CMD_SHIFT) |\
48*dcb00b10SNicolas Le Bayon 						 ((state) << CLK_ON_SHIFT) |\
49*dcb00b10SNicolas Le Bayon 						 ((clk_id) << CLK_ID_SHIFT) |\
50*dcb00b10SNicolas Le Bayon 						 ((div) << CLK_DIV_SHIFT) |\
51*dcb00b10SNicolas Le Bayon 						 ((sel) << CLK_SEL_SHIFT))
52*dcb00b10SNicolas Le Bayon 
53*dcb00b10SNicolas Le Bayon #define CLK_OFF		0
54*dcb00b10SNicolas Le Bayon #define CLK_ON		1
55*dcb00b10SNicolas Le Bayon #define CLK_NODIV	0x00000040
56*dcb00b10SNicolas Le Bayon #define CLK_NOMUX	0x00000010
57*dcb00b10SNicolas Le Bayon 
58*dcb00b10SNicolas Le Bayon /* Flexgen define */
59*dcb00b10SNicolas Le Bayon #define FLEX_ID_SHIFT	20
60*dcb00b10SNicolas Le Bayon #define FLEX_SEL_SHIFT	16
61*dcb00b10SNicolas Le Bayon #define FLEX_PDIV_SHIFT	6
62*dcb00b10SNicolas Le Bayon #define FLEX_FDIV_SHIFT	0
63*dcb00b10SNicolas Le Bayon 
64*dcb00b10SNicolas Le Bayon #define FLEX_ID_MASK	GENMASK_32(25, 20)
65*dcb00b10SNicolas Le Bayon #define FLEX_SEL_MASK	GENMASK_32(19, 16)
66*dcb00b10SNicolas Le Bayon #define FLEX_PDIV_MASK	GENMASK_32(15, 6)
67*dcb00b10SNicolas Le Bayon #define FLEX_FDIV_MASK	GENMASK_32(5, 0)
68*dcb00b10SNicolas Le Bayon 
69*dcb00b10SNicolas Le Bayon #define DIV_CFG(div_id, div)	((CMD_DIV << CMD_SHIFT) |\
70*dcb00b10SNicolas Le Bayon 				 ((div_id) << DIV_ID_SHIFT |\
71*dcb00b10SNicolas Le Bayon 				 (div)))
72*dcb00b10SNicolas Le Bayon 
73*dcb00b10SNicolas Le Bayon #define MUX_CFG(mux_id, sel)	((CMD_MUX << CMD_SHIFT) |\
74*dcb00b10SNicolas Le Bayon 				 ((mux_id) << MUX_ID_SHIFT |\
75*dcb00b10SNicolas Le Bayon 				 (sel)))
76*dcb00b10SNicolas Le Bayon 
77*dcb00b10SNicolas Le Bayon #define CLK_ADDR_SHIFT		16
78*dcb00b10SNicolas Le Bayon #define CLK_ADDR_MASK		0x7FFF0000
79*dcb00b10SNicolas Le Bayon #define CLK_ADDR_VAL_MASK	0xFFFF
80*dcb00b10SNicolas Le Bayon 
81*dcb00b10SNicolas Le Bayon #define DIV_LSMCU	0
82*dcb00b10SNicolas Le Bayon #define DIV_APB1	1
83*dcb00b10SNicolas Le Bayon #define DIV_APB2	2
84*dcb00b10SNicolas Le Bayon #define DIV_APB3	3
85*dcb00b10SNicolas Le Bayon #define DIV_APB4	4
86*dcb00b10SNicolas Le Bayon #define DIV_APB5	5
87*dcb00b10SNicolas Le Bayon #define DIV_APBDBG	6
88*dcb00b10SNicolas Le Bayon #define DIV_RTC		7
89*dcb00b10SNicolas Le Bayon #define DIV_NB		8
90*dcb00b10SNicolas Le Bayon 
91*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL0	0
92*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL1	1
93*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL2	2
94*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL3	3
95*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL4	4
96*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL5	5
97*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL6	6
98*dcb00b10SNicolas Le Bayon #define MUX_MUXSEL7	7
99*dcb00b10SNicolas Le Bayon #define MUX_XBARSEL	8
100*dcb00b10SNicolas Le Bayon #define MUX_RTC		9
101*dcb00b10SNicolas Le Bayon #define MUX_MCO1	10
102*dcb00b10SNicolas Le Bayon #define MUX_MCO2	11
103*dcb00b10SNicolas Le Bayon #define MUX_ADC1	12
104*dcb00b10SNicolas Le Bayon #define MUX_ADC2	13
105*dcb00b10SNicolas Le Bayon #define MUX_USB2PHY1	14
106*dcb00b10SNicolas Le Bayon #define MUX_USB2PHY2	15
107*dcb00b10SNicolas Le Bayon #define MUX_DTS		16
108*dcb00b10SNicolas Le Bayon #define MUX_CPU1	17
109*dcb00b10SNicolas Le Bayon #define MUX_NB		18
110*dcb00b10SNicolas Le Bayon 
111*dcb00b10SNicolas Le Bayon #define MUXSEL_HSI		0
112*dcb00b10SNicolas Le Bayon #define MUXSEL_HSE		1
113*dcb00b10SNicolas Le Bayon #define MUXSEL_MSI		2
114*dcb00b10SNicolas Le Bayon 
115*dcb00b10SNicolas Le Bayon /* KERNEL source clocks */
116*dcb00b10SNicolas Le Bayon #define MUX_RTC_DISABLED	0x0
117*dcb00b10SNicolas Le Bayon #define MUX_RTC_LSE		0x1
118*dcb00b10SNicolas Le Bayon #define MUX_RTC_LSI		0x2
119*dcb00b10SNicolas Le Bayon #define MUX_RTC_HSE		0x3
120*dcb00b10SNicolas Le Bayon 
121*dcb00b10SNicolas Le Bayon #define MUX_MCO1_FLEX61		0x0
122*dcb00b10SNicolas Le Bayon #define MUX_MCO1_OBSER0		0x1
123*dcb00b10SNicolas Le Bayon 
124*dcb00b10SNicolas Le Bayon #define MUX_MCO2_FLEX62		0x0
125*dcb00b10SNicolas Le Bayon #define MUX_MCO2_OBSER1		0x1
126*dcb00b10SNicolas Le Bayon 
127*dcb00b10SNicolas Le Bayon #define MUX_ADC1_FLEX46		0x0
128*dcb00b10SNicolas Le Bayon #define MUX_ADC1_LSMCU		0x1
129*dcb00b10SNicolas Le Bayon 
130*dcb00b10SNicolas Le Bayon #define MUX_ADC2_FLEX47		0x0
131*dcb00b10SNicolas Le Bayon #define MUX_ADC2_LSMCU		0x1
132*dcb00b10SNicolas Le Bayon #define MUX_ADC2_FLEX46		0x2
133*dcb00b10SNicolas Le Bayon 
134*dcb00b10SNicolas Le Bayon #define MUX_USB2PHY1_FLEX57	0x0
135*dcb00b10SNicolas Le Bayon #define MUX_USB2PHY1_HSE	0x1
136*dcb00b10SNicolas Le Bayon 
137*dcb00b10SNicolas Le Bayon #define MUX_USB2PHY2_FLEX58	0x0
138*dcb00b10SNicolas Le Bayon #define MUX_USB2PHY2_HSE	0x1
139*dcb00b10SNicolas Le Bayon 
140*dcb00b10SNicolas Le Bayon #define MUX_DTS_HSI		0x0
141*dcb00b10SNicolas Le Bayon #define MUX_DTS_HSE		0x1
142*dcb00b10SNicolas Le Bayon #define MUX_DTS_MSI		0x2
143*dcb00b10SNicolas Le Bayon 
144*dcb00b10SNicolas Le Bayon /* PLLs source clocks */
145*dcb00b10SNicolas Le Bayon #define PLL_SRC_HSI		0x0
146*dcb00b10SNicolas Le Bayon #define PLL_SRC_HSE		0x1
147*dcb00b10SNicolas Le Bayon #define PLL_SRC_MSI		0x2
148*dcb00b10SNicolas Le Bayon #define PLL_SRC_DISABLED	0x3
149*dcb00b10SNicolas Le Bayon 
150*dcb00b10SNicolas Le Bayon /* XBAR source clocks */
151*dcb00b10SNicolas Le Bayon #define XBAR_SRC_PLL4		0x0
152*dcb00b10SNicolas Le Bayon #define XBAR_SRC_PLL5		0x1
153*dcb00b10SNicolas Le Bayon #define XBAR_SRC_PLL6		0x2
154*dcb00b10SNicolas Le Bayon #define XBAR_SRC_PLL7		0x3
155*dcb00b10SNicolas Le Bayon #define XBAR_SRC_PLL8		0x4
156*dcb00b10SNicolas Le Bayon #define XBAR_SRC_HSI		0x5
157*dcb00b10SNicolas Le Bayon #define XBAR_SRC_HSE		0x6
158*dcb00b10SNicolas Le Bayon #define XBAR_SRC_MSI		0x7
159*dcb00b10SNicolas Le Bayon #define XBAR_SRC_HSI_KER	0x8
160*dcb00b10SNicolas Le Bayon #define XBAR_SRC_HSE_KER	0x9
161*dcb00b10SNicolas Le Bayon #define XBAR_SRC_MSI_KER	0xA
162*dcb00b10SNicolas Le Bayon #define XBAR_SRC_SPDIF_SYMB	0xB
163*dcb00b10SNicolas Le Bayon #define XBAR_SRC_I2S		0xC
164*dcb00b10SNicolas Le Bayon #define XBAR_SRC_LSI		0xD
165*dcb00b10SNicolas Le Bayon #define XBAR_SRC_LSE		0xE
166*dcb00b10SNicolas Le Bayon 
167*dcb00b10SNicolas Le Bayon /*
168*dcb00b10SNicolas Le Bayon  * Configure a XBAR channel with its clock source
169*dcb00b10SNicolas Le Bayon  * channel_nb: XBAR channel number from 0 to 63
170*dcb00b10SNicolas Le Bayon  * channel_src: one of the 15 previous XBAR source clocks defines
171*dcb00b10SNicolas Le Bayon  * channel_prediv: value of the PREDIV in channel RCC_PREDIVxCFGR register
172*dcb00b10SNicolas Le Bayon  *		   can be either 1, 2, 4 or 1024
173*dcb00b10SNicolas Le Bayon  * channel_findiv: value of the FINDIV in channel RCC_FINDIVxCFGR register
174*dcb00b10SNicolas Le Bayon  *		   from 1 to 64
175*dcb00b10SNicolas Le Bayon  */
176*dcb00b10SNicolas Le Bayon 
177*dcb00b10SNicolas Le Bayon #define FLEXGEN_CFG(ch, sel, pdiv, fdiv)	((CMD_FLEXGEN << CMD_SHIFT) |\
178*dcb00b10SNicolas Le Bayon 						((ch) << FLEX_ID_SHIFT) |\
179*dcb00b10SNicolas Le Bayon 						((sel) << FLEX_SEL_SHIFT) |\
180*dcb00b10SNicolas Le Bayon 						((pdiv) << FLEX_PDIV_SHIFT) |\
181*dcb00b10SNicolas Le Bayon 						((fdiv) << FLEX_FDIV_SHIFT))
182*dcb00b10SNicolas Le Bayon 
183*dcb00b10SNicolas Le Bayon /* Register addresses of MCO1 & MCO2 */
184*dcb00b10SNicolas Le Bayon #define MCO1			0x488
185*dcb00b10SNicolas Le Bayon #define MCO2			0x48C
186*dcb00b10SNicolas Le Bayon 
187*dcb00b10SNicolas Le Bayon #define MCO_OFF			0
188*dcb00b10SNicolas Le Bayon #define MCO_ON			1
189*dcb00b10SNicolas Le Bayon #define MCO_STATUS_SHIFT	8
190*dcb00b10SNicolas Le Bayon 
191*dcb00b10SNicolas Le Bayon #define MCO_CFG(addr, sel, status)	(CMD_ADDR_BIT |\
192*dcb00b10SNicolas Le Bayon 					((addr) << CLK_ADDR_SHIFT) |\
193*dcb00b10SNicolas Le Bayon 					((status) << MCO_STATUS_SHIFT) |\
194*dcb00b10SNicolas Le Bayon 					(sel))
195*dcb00b10SNicolas Le Bayon 
196*dcb00b10SNicolas Le Bayon /* define for st,pll /csg */
197*dcb00b10SNicolas Le Bayon #define SSCG_MODE_CENTER_SPREAD	0
198*dcb00b10SNicolas Le Bayon #define SSCG_MODE_DOWN_SPREAD	1
199*dcb00b10SNicolas Le Bayon 
200*dcb00b10SNicolas Le Bayon /* define for st,drive */
201*dcb00b10SNicolas Le Bayon #define LSEDRV_LOWEST		0
202*dcb00b10SNicolas Le Bayon #define LSEDRV_MEDIUM_LOW	2
203*dcb00b10SNicolas Le Bayon #define LSEDRV_MEDIUM_HIGH	1
204*dcb00b10SNicolas Le Bayon #define LSEDRV_HIGHEST		3
205*dcb00b10SNicolas Le Bayon 
206*dcb00b10SNicolas Le Bayon #endif /* _DT_BINDINGS_CLOCK_STM32MP21_CLKSRC_H_ */
207