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>
This commit is contained in:
Yann Gautier 2019-12-06 09:38:43 +01:00
parent dad7181698
commit b1718c6382

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022, STMicroelectronics - All Rights Reserved
* Copyright (c) 2017-2023, STMicroelectronics - All Rights Reserved
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -319,6 +319,19 @@ unsigned long fdt_get_uart_clock_freq(uintptr_t instance)
return clk_get_rate((unsigned long)clk_id);
}
/*******************************************************************************
* This function sets the STGEN counter value.
******************************************************************************/
static void stgen_set_counter(unsigned long long counter)
{
#ifdef __aarch64__
mmio_write_64(STGEN_BASE + CNTCV_OFF, counter);
#else
mmio_write_32(STGEN_BASE + CNTCVL_OFF, (uint32_t)counter);
mmio_write_32(STGEN_BASE + CNTCVU_OFF, (uint32_t)(counter >> 32));
#endif
}
/*******************************************************************************
* This function configures and restores the STGEN counter depending on the
* connected clock.
@ -337,8 +350,7 @@ void stm32mp_stgen_config(unsigned long rate)
mmio_clrbits_32(STGEN_BASE + CNTCR_OFF, CNTCR_EN);
counter = stm32mp_stgen_get_counter() * rate / cntfid0;
mmio_write_32(STGEN_BASE + CNTCVL_OFF, (uint32_t)counter);
mmio_write_32(STGEN_BASE + CNTCVU_OFF, (uint32_t)(counter >> 32));
stgen_set_counter(counter);
mmio_write_32(STGEN_BASE + CNTFID_OFF, rate);
mmio_setbits_32(STGEN_BASE + CNTCR_OFF, CNTCR_EN);
@ -353,8 +365,12 @@ void stm32mp_stgen_config(unsigned long rate)
******************************************************************************/
unsigned long long stm32mp_stgen_get_counter(void)
{
#ifdef __aarch64__
return mmio_read_64(STGEN_BASE + CNTCV_OFF);
#else
return (((unsigned long long)mmio_read_32(STGEN_BASE + CNTCVU_OFF) << 32) |
mmio_read_32(STGEN_BASE + CNTCVL_OFF));
#endif
}
/*******************************************************************************
@ -371,7 +387,6 @@ void stm32mp_stgen_restore_counter(unsigned long long value,
mmio_read_32(STGEN_BASE + CNTFID_OFF)) / 1000U);
mmio_clrbits_32(STGEN_BASE + CNTCR_OFF, CNTCR_EN);
mmio_write_32(STGEN_BASE + CNTCVL_OFF, (uint32_t)cnt);
mmio_write_32(STGEN_BASE + CNTCVU_OFF, (uint32_t)(cnt >> 32));
stgen_set_counter(cnt);
mmio_setbits_32(STGEN_BASE + CNTCR_OFF, CNTCR_EN);
}