Commit graph

93 commits

Author SHA1 Message Date
Gabriel Fernandez
615f31fe40 feat(st-clock): add STM32MP2 clock driver
This driver manages the clocks on STM32MP2 platforms.
It uses a dedicated RCC (Reset and Clock Control) peripheral.

Change-Id: I6ba2173e73222269a2dfca4c6897229276a150c0
Signed-off-by: Yann Gautier <yann.gautier@st.com>
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com>
2024-06-27 18:27:17 +02:00
Yann Gautier
1a25db196d feat(st-clock): use early traces
Replace trace macros with their corresponding EARLY_* macros.

Change-Id: I39b163964fa3129be38e58352b5dee9b4081675b
Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
2024-06-11 14:02:10 +02:00
Christoph Fritz
eca510346d fix(st-clock): adapt order of CSS on LSE and HSE
Fix the activation order of the CSS to prevent a faulty halt, according
to the reference manual (RM0442 Rev 6, Chapter: 10.4.3 Clock security
system CSS) it must be done after selecting the LSE clock via the RTCSRC
field.
For the HSE clock, this can be activated even when HSEON is '0'.

Signed-off-by: Christoph Fritz <chf@fritzc.com>
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Change-Id: Ied01baac1ccc63dcef78bf5f9180bb8628cce2d0
2024-06-11 14:02:10 +02:00
Yann Gautier
3201497ebb refactor(st-clock): remove unused struct
The struct clk_fixed_rate is used nowhere in the code, remove its
definition.

Change-Id: I139ad05a249357da96a996feabd4b1f53e290f2a
Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
2024-06-11 14:02:10 +02:00
Yann Gautier
1be399b813 refactor(st-clock): move stm32mp1_clk_rcc_regs_*lock
Those functions are only used on MP1, they should not be in STM32 clock
core. Move them to MP13 driver (they are already in MP15 driver).
Redefine new clk_stm32_rcc_regs_*lock() functions in clock core. This
change avoid sparse warning:
drivers/st/clk/clk-stm32-core.c:46:6: warning: symbol
 'stm32mp1_clk_rcc_regs_lock' was not declared. Should it be static?
drivers/st/clk/clk-stm32-core.c:51:6: warning: symbol
 'stm32mp1_clk_rcc_regs_unlock' was not declared. Should it be static?

Change-Id: I9f255acaa843e41fc14267c1a8091f93bd029796
Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
2024-06-11 14:02:10 +02:00
Gabriel Fernandez
d9a7ddeb25 refactor(st-clock): driver size optimization
Re-ordering structures to avoid gaps and minimize data.
Reduce type of gate_refcounts[], uint8_t is enough.
Re-ordering structures to avoid gaps and minimize data.
Use an unsigned char to define a clock ops type.

Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Change-Id: I6b793dc34abdd6ef013609fc0f122da5d1824a34
2024-06-11 14:02:10 +02:00
Yann Gautier
698bba5e74 refactor(st-clock): remove BL32 support on STM32MP13
TF-A BL32 (SP_MIN) is not supported on STM32MP13. Only OP-TEE is used
as BL32. Remove the code under IMAGE_BL32 flag in STM32MP13 driver.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I6cc9f230782c44129b205e66a44cdb4bcb5f95c3
2024-06-11 14:02:10 +02:00
Gabriel Fernandez
f2aebab859 feat(st-clock): don't gate/ungate an oscillator if it is not wired
If the oscillator is not present, the gating will fail.

Change-Id: If9119460a4bcd42053537f1975afe5fe1df05752
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
2024-06-11 14:02:10 +02:00
Gabriel Fernandez
ae1e503763 feat(st-clock): update with new bindings
Code alignment with MP13 driver.

Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Change-Id: Ifb0597721a865f463cf41c5cd7be3ca75a1da80c
2024-06-11 14:02:10 +02:00
Yann Gautier
f655922788 feat(stm32mp1): always boot at 650MHz
Switching to higher CPU frequencies requires a dedicated chip version
(STM32MP1xxD or STM32MP1xxF), and increase CPU voltage. To avoid
re-configuring I2C and PMIC before and after applying clock tree,
always boot at 650MHz, which is the frequency for nominal voltage.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Change-Id: Id05a3ee17e7dd57e2d64dc06f8f1e7f9cb21e110
2024-06-11 14:02:10 +02:00
Gabriel Fernandez
6583da67d6 refactor(st-clock): remove LSEDRV_MEDIUM_HIGH for STM32MP13
Remove useless LSEDRV_MEDIUM_HIGH definition in clk-stm32mp13.c.
It's already defined in include/dt-bindings/clock/stm32mp13-clksrc.h.

Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Change-Id: Ie3fa4711930f922fa0733ba7c76d72ec9639e9a5
2024-06-11 14:01:34 +02:00
Patrick Delaunay
039b7d4673 fix(st-clock): display proper PLL number for STM32MP13
The PLL clk_id does not start at 0, but it is in the enum listing all
clocks. To have a better display of the PLL number, start at PLL1,
by changing pll->clk_id in messages with pll->clk_id - _CK_PLL1 + 1.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Change-Id: Ic09195ae6fe5f8d3a87e69962425f7c826f3670b
2024-06-11 11:45:38 +02:00
Yann Gautier
f4a2bb986b fix(st-clock): do not reconfigure LSE
If LSE oscillator is already ON, which is the case when returning from
low-power state or if we are on VBAT, it mustn't be reconfigured.

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: Ie75f2b0b42aeb3d95e2266e1fca811a2f2b3e29f
2024-06-11 11:45:38 +02:00
Patrick Delaunay
caa1295779 refactor(st-clock): remove unused clk function in API
Remove the unused functions in stm32mp clk API:
- stm32mp_stgen_get_counter (change to static, no more exported)
- stm32mp_stgen_restore_counter

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Change-Id: Ib6ca72723eac3e133f1ca0dee504ef344c72e0bf
2024-06-11 11:45:38 +02:00
Patrick Delaunay
3b3a9afdeb refactor(st-clock): support deactivated STGEN in stm32mp_stgen_config
Update function stm32mp_stgen_config() to support deactivated STGEN
when frequency is 0, for example on STOP2 exit for STM32MP25.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Change-Id: Id371c4602a614bbfa0ecc7ce2d2e0ac5261e1d52
2024-06-11 11:45:38 +02:00
Pascal Paillet
bfe8a12eea feat(st-clock): add function to restore generic timer rate
Add a function to restore the CPU generic timer rate from STGEN content.
After wake-up from LPLV-Stop2, STGEN content is not lost, but generic timer
has been reset.

Signed-off-by: Pascal Paillet <p.paillet@st.com>
Change-Id: I6f91dbd051f76383e9ff1d6bb86225d373dbf33a
2024-06-11 11:45:38 +02:00
Lionel Debieve
77b4ca0b2f feat(st-clock): add function to control MCU subsystem
Add a new function to control the MCU subsystem
security state.

Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Change-Id: I070eec06fc93a1214227f25a6a4f1c40c66c86b0
2024-03-19 15:49:14 +01:00
Yann Gautier
19c38081d3 feat(st-clock): stub fdt_get_rcc_secure_state
The function fdt_get_rcc_secure_state() is only used in BL32.
Put it under flag to avoid compilation errors.

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: If57c65bef0b1a3f7349527720f94fde26edbb73c
2023-09-08 10:56:49 +02:00
Yann Gautier
b1718c6382 feat(st-clock): allow aarch64 compilation of STGEN functions
A new local function is created to set STGEN counter value,
that will deal with __aarch64__ flag. And the function
stm32mp_stgen_get_counter is adapted for __aarch64__.

Change-Id: I53c21ad11ba5085611a028790e1decbe5994ae50
Signed-off-by: Yann Gautier <yann.gautier@st.com>
2023-09-08 10:56:49 +02:00
Gabriel Fernandez
1bbcb58a69 fix(st-clock): disabling CKPER clock is not functional on stm32mp13
The mask used to configure the CKPER MUX was wrong and unnecessary.

Change-Id: I40098f2a27b9e5ba8706ab5377d23f578c09838b
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
2023-05-30 15:39:50 +02:00
Elyes Haouas
1b491eead5 fix(tree): correct some typos
found using codespell (https://github.com/codespell-project/codespell).

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Change-Id: I1bfa797e3460adddeefa916bb68e22beddaf6373
2023-05-09 15:57:12 +01:00
Yann Gautier
4198fa1db7 fix(st-clock): avoid arithmetics on pointers
This corrects MISRA C2012-18.4:
The +, -, += and -= operators should not be applied to an expression
of pointer type.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I9128f567a7c83d8e3381428b07e6bd785be2703b
2022-12-07 14:18:31 +01:00
Yann Gautier
ee21709e98 fix(st-clock): give the size for parent_mp13 and dividers_mp13 tables
This corrects MISRA C2012-9.5:
Where designated initializers are used to initialize an array object
the size of the array shall be specified explicitly.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I4c331b0225af975fd022ffe9e5fd1d536ed59879
2022-12-07 14:18:31 +01:00
Yann Gautier
69a2e320b6 fix(st-clock): remove useless switch
This corrects MISRA C2012-16.6:
Every switch statement shall have at least two switch-clauses.
While at it, remove useless rate variable.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I123784e7184dbf4146fd0d7faeffd6a0382fc6a1
2022-12-07 14:18:31 +01:00
Yann Gautier
c3ae7da02d fix(st-clock): use Boolean type for tests
This corrects MISRA C2012-14.4
The controlling expression of an if statement and the controlling
expression of an iteration-statement shall have essentially Boolean type.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: Id217d3da223caf75cd0439d7ce11c9efab87b4d2
2022-12-07 14:18:31 +01:00
Patrick Delaunay
7d197d6281 refactor(stm32mp1): move DT_UART_COMPAT in include file
Move the definition of DT_UART_COMPAT in stm32mp1_def.h to be used
in several files.

Change-Id: I74d0350bcd971df9b15697f2b9ec04061d6a7656
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
2022-09-23 15:17:43 +02:00
Gabriel Fernandez
3ff1ff4047 refactor(st-clock): code size optimization
Clock name is not used and can be removed for code size optimization.

Change-Id: I75f6a1828e4374004e31a7ce13fa6885c52bbac3
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
2022-08-10 09:56:32 +02:00
Gabriel Fernandez
b44f5acf5d refactor(st-clock): remove unused PLL field
The divn_max field is unused, remove it.

Change-Id: I971912bcc035f16963d98dfa88782c8aed4415f2
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
2022-08-10 09:56:32 +02:00
Yann Gautier
56f895ede3 fix(st-clock): correct MISRA C2012 15.6
Add braces to correct MISRA C2012 15.6 warning:
The body of an iteration-statement or a selection-statement shall be a
compound-statement.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: If26f3732d31df11bf389a16298ec9e9d8a4a2279
2022-06-21 16:01:10 +02:00
Yann Gautier
3b06a53044 fix(st-clock): correctly check ready bit
The function clk_oscillator_wait_ready() was wrongly checking the set
bit and not the ready bit. Correct that by using osc_data->gate_rdy_id
when calling _clk_stm32_gate_wait_ready().

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: Ida58f14d7f0f326b580ae24b98d6b9f592d2d711
2022-06-21 16:01:06 +02:00
Yann Gautier
7417cda6ae fix(st-clock): correct stm32_clk_parse_fdt_by_name
The fdt_getprop() function sets the length to -1 if the property is not
found. We should then not use it later in stm32_clk_parse_fdt_by_name()
in that case. Directly set *nb to 0U and return 0 if the property is not
found.

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: I19c5c953f392cdc768e0b1f3f240fc99a73a049c
2022-04-05 17:05:55 +02:00
Yann Gautier
b8eab512bf fix(st-clock): check _clk_stm32_get_parent return
This issue was found by Coverity (CID 376885). The _clk_stm32_get_parent()
return shouldn't be negative. Return the error in this case.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I91eff7e99fcdac9a258100b163fd9b040a9bd2c0
2022-04-05 17:05:40 +02:00
Gabriel Fernandez
9be88e75c1 feat(st-clock): add clock driver for STM32MP13
Add new clock driver for STM32MP13. Split the include file to manage
either STM32MP13 or STM32MP15.

Change-Id: Ia568cd12b1d5538809204f0fd2224d51e5d1e985
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com>
2022-03-22 09:09:23 +01:00
Yann Gautier
175758b277 fix(st-clock): initialize pllcfg table
The issue was found by Coverity:
CID 376582:    (UNINIT)
    Using uninitialized value "*pllcfg[_PLL4]" when calling
    "stm32mp1_check_pll_conf".
CID 376582:    (UNINIT)
    Using uninitialized value "*pllcfg[_PLL3]" when calling
    "stm32mp1_check_pll_conf".

Check PLL configs are valid before using pllcfg.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I49de849eaf451d0c165a8eb8555112a0a4140bbc
2022-03-04 13:48:53 +01:00
Yann Gautier
9fa9a0c55c fix(st-clock): print enums as unsigned
With gcc-11, the -Wformat-signedness warning complains about enum values
that should be printed as unsigned values. Change %d to %u for several
lines in the clock driver.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: Ia2d24e6feef5e852e0a6bfaa1286fe605f9a16b7
2022-02-28 11:36:00 +01:00
Lionel Debieve
812daf916c feat(st): update the security based on new compatible
From the new binding, the RCC become secured based on the new
compatible. This must be done only from the secure OS initialisation.

Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Change-Id: I7f0a62f22bfcca638ddaefc9563df00f89f01653
2022-02-03 09:20:49 +01:00
Lionel Debieve
591d80c8b1 refactor(st-clock): update STGEN management
Rework STGEN config function, and move it to stm32mp_clkfunc.c file.

Change-Id: I7784a79c486d1b8811f6f8d123e49ea34899e9b6
Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Signed-off-by: Yann Gautier <yann.gautier@st.com>
2022-01-27 18:06:36 +01:00
Yann Gautier
7418cf3979 feat(st-clock): assign clocks to the correct BL
Some clocks are only required in BL2, like boot devices clocks:
FMC, QSPI.
Some clocks are only used in BL32: Timers, devices that need special
care for independent reset.

Change-Id: Id4ba99afeea5095f419a86f7dc6423192c628d82
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Yann Gautier <yann.gautier@st.com>
2022-01-27 18:06:36 +01:00
Yann Gautier
3d69149a7e feat(st-clock): do not refcount on non-secure clocks in bl32
This change removes reference counting support in clock gating
implementation for clocks that rely on non-secure only RCC resources.
As RCC registers are accessed straight by non-secure world for these
clocks, secure world cannot safely store the clock state and even
disabling such clock from secure world can jeopardize the non-secure
world clock management framework and drivers.

As a consequence, for such clocks, stm32_clock_enable() forces the clock
ON without any increment of a refcount and stm32_clock_disable() does
not disable the clock.

Change-Id: I0cc159b36a25dbc8676f05edf2668ae63c640537
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2022-01-27 18:06:36 +01:00
Yann Gautier
aaa09b713c feat(st-clock): define secure and non-secure gate clocks
Array stm32mp1_clk_gate[] defines the clock resources. This change
add a secure attribute to the clock: secure upon RCC[TZEN] (SEC),
secure upon RCC[TZEN] and RCC[MCKPROT] (MKP) or always accessible
from non-secure (N_S).

At init, lookup clock tree to check if any of the secure clocks
is derived from PLL3 in which case PLL3 shall be secure.

Note that this change does not grow byte size of stm32mp1_clk_gate[].

Change-Id: I933d8a30007f3c72f755aa1ef6d7e6bcfabbfa9e
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Yann Gautier <yann.gautier@st.com>
2022-01-27 18:06:36 +01:00
Yann Gautier
2444d2314c refactor(st-clock): use refcnt instead of secure status
Rework the internal functions __stm32mp1_clk_enable/disable to check for
reference count instead of secure status for a clock.
Some functions now unused can be removed.

Change-Id: Ie4359110d7144229f85c961dcd5a019222c3fd25
Signed-off-by: Yann Gautier <yann.gautier@st.com>
2022-01-27 18:06:07 +01:00
Yann Gautier
44fb470b7f fix(st-clock): correct types in error messages
Replace wrong %d with the correct types.
This issue was found with the compilation flag:
-Wformat-signedness

Change-Id: Iec3817a245f964ce444b59561b777ce06c51a60a
Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
2022-01-18 18:39:52 +01:00
Gabriel Fernandez
b208e3da04 refactor(st-clock): directly use oscillator name
Instead of transmitting an 'enum stm32mp_osc_id', just send
directly the clock name with a 'const char *'

Change-Id: I866b05cbb1685a9b9f80e63dcd5ba7b1d35fc932
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com>
2022-01-18 18:39:52 +01:00
Lionel Debieve
31e9750bc1 feat(st-clock): check HSE configuration in serial boot
In case of programmer mode, the bootrom manages to auto-detect
HSE clock configuration. In order to detect a bad device tree
setting in BL2, it will crash during programming if the configuration
is not aligned with the auto-detection.

Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Change-Id: I230697695745d6282d14b1ebfa6e4c4caa0cd8e2
2022-01-18 17:07:41 +01:00
Patrick Delaunay
bcccdacc7e feat(st-clock): manage disabled oscillator
Support "disabled" status for oscillator in device tree.

At boot time, the clock tree initialization performs the following
tasks:
- enabling of the oscillators present in the device tree and not
  disabled,
- disabling of the HSI oscillator if the node is absent or disabled
  (always activated by bootROM).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Change-Id: I176276022334f3d97ba0250b54062f0ae970e239
2022-01-18 17:06:13 +01:00
Nicolas Le Bayon
964e5ff184 refactor(st-clock): improve DT parsing for PLL nodes
Add a function to get PLL settings from DT:
"cfg" property is mandatory, an error is generated if not found.
"frac" is optional, default value is returned if not found.
"csg" is optional too, a boolean value indicates if it has been
found, and its value is updated.

Store each PLL node validity information, this avoids parsing DT
several times.

Change-Id: I039466fbe1e67d160f7112814e7bb63b661804d0
Signed-off-by: Nicolas Le Bayon <nicolas.le.bayon@st.com>
2022-01-18 17:03:45 +01:00
Yann Gautier
33667d299b feat(st): use newly introduced clock framework
Replace calls to stm32mp_clk_enable() / stm32mp_clk_disable() /
stm32mp_clk_get_rate() with clk_enable() / clk_disable() /
clk_get_rate().

Change-Id: I15d2ce57b9499211fa522a1b53eeee9cf584c111
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com>
2021-12-22 13:08:09 +01:00
Manish Pandey
be1d8b24f5 Merge "feat(stm32mp1): preserve the PLL4 settings for USB boot" into integration 2021-12-10 14:19:15 +01:00
Nicolas Le Bayon
165ad5561e feat(drivers/st/uart): add uart driver for STM32MP1
Add a UART/USART driver for STM32 with complete a hardware support;
it used for STM32CubeProgrammer support with even parity.

This driver is not used for console, which is already handle
by a simple driver (drivers/st/uart/aarch32/stm32_console.S).

Change-Id: Ia9266e5d177fe7fd09c8a15b81da1a05b1bc8b2d
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Nicolas Le Bayon <nicolas.le.bayon@st.com>
2021-12-03 09:26:11 +01:00
Patrick Delaunay
bf1af154db feat(stm32mp1): preserve the PLL4 settings for USB boot
The PLL4 can be used by ROM code as the source clock of USB PHYC and,
in this case, the PLL4 configuration must be preserved
with pll4_preserve to avoid USB disturbance.

This patch also adds an error when the clock tree PLL4 configuration
is not the PLL4 configuration used by ROM code; this error allows to
detect a invalid clock tree.

This commit corrects the coverity issue 343023.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Change-Id: I4bae9312a2db8dd342a38e649513d689b13976bb
2021-12-03 09:19:53 +01:00