guo ecf2d82159
sync branch rt-smart. (#6641)
* Synchronize the code of the rt mart branch to the master branch.
  * TTY device
  * Add lwP code from rt-smart
  * Add vnode in DFS, but DFS will be re-write for rt-smart
  * There are three libcpu for rt-smart:
    * arm/cortex-a, arm/aarch64
    * riscv64

Co-authored-by: Rbb666 <zhangbingru@rt-thread.com>
Co-authored-by: zhkag <zhkag@foxmail.com>
2022-12-03 12:07:44 +08:00

72 lines
1.6 KiB
C

#include <sunxi_hal_common.h>
#include <hal_clk.h>
#include <hal_prcm.h>
void hal_clock_init(void)
{
ccu_init();
}
hal_clk_status_t hal_clk_set_parent(hal_clk_id_t clk, hal_clk_id_t parent)
{
return ccu_set_mclk_src(clk, parent) == OK ?
HAL_CLK_STATUS_OK :
HAL_CLK_STATUS_INVALID_PARAMETER;
}
hal_clk_id_t hal_clk_get_parent(hal_clk_id_t clk)
{
return ccu_get_mclk_src(clk);
}
u32 hal_clk_recalc_rate(hal_clk_id_t clk)
{
return ccu_get_sclk_freq(clk);
}
u32 hal_clk_round_rate(hal_clk_id_t clk, u32 rate)
{
/* TODO */
return HAL_CLK_RATE_UNINITIALIZED;
}
u32 hal_clk_get_rate(hal_clk_id_t clk)
{
return ccu_get_sclk_freq(clk);
}
hal_clk_status_t hal_clk_set_rate(hal_clk_id_t clk, u32 rate)
{
return ccu_set_sclk_freq(clk, rate) == OK ?
HAL_CLK_STATUS_OK :
HAL_CLK_STATUS_INVALID_PARAMETER;
}
hal_clk_status_t hal_clock_is_enabled(hal_clk_id_t clk)
{
/* FIXME: always return disabled */
return HAL_CLK_STATUS_DISABLED;
}
hal_clk_status_t hal_clock_enable(hal_clk_id_t clk)
{
if (ccu_set_mclk_reset(clk, CCU_CLK_NRESET) != OK)
return HAL_CLK_STATUS_ERROR_CLK_ENABLED_FAILED;
if (ccu_set_mclk_onoff(clk, CCU_CLK_ON) != OK)
return HAL_CLK_STATUS_ERROR_CLK_ENABLED_FAILED;
return HAL_CLK_STATUS_OK;
}
hal_clk_status_t hal_clock_disable(hal_clk_id_t clk)
{
if (ccu_set_mclk_onoff(clk, CCU_CLK_OFF) != OK)
return HAL_CLK_STATUS_ERROR_CLK_ENABLED_FAILED;
if (ccu_set_mclk_reset(clk, CCU_CLK_RESET) != OK)
return HAL_CLK_STATUS_ERROR_CLK_ENABLED_FAILED;
return HAL_CLK_STATUS_OK;
}