RT-Thread RTOS
An open source embedded real-time operating system
+ Collaboration diagram for Clock:

Data Structures

struct  rt_clk_node
 
struct  rt_clk_cell
 
struct  rt_clk_fixed_rate
 
struct  rt_clk
 
struct  rt_clk_array
 
struct  rt_clk_notifier
 

Macros

#define RT_CLK_F_SET_RATE_GATE   RT_BIT(0)
 
#define RT_CLK_F_SET_PARENT_GATE   RT_BIT(1)
 
#define RT_CLK_F_SET_RATE_PARENT   RT_BIT(2)
 
#define RT_CLK_F_IGNORE_UNUSED   RT_BIT(3)
 
#define RT_CLK_F_SET_RATE_UNGATE   RT_BIT(4)
 
#define RT_CLK_F_IS_CRITICAL   RT_BIT(5)
 
#define RT_CLK_F_GET_RATE_NOCACHE   RT_BIT(6)
 

Functions

rt_err_t rt_clk_register (struct rt_clk_node *clk_np)
 
rt_err_t rt_clk_unregister (struct rt_clk_node *clk_np)
 
rt_err_t rt_clk_notifier_register (struct rt_clk *clk, struct rt_clk_notifier *notifier)
 
rt_err_t rt_clk_notifier_unregister (struct rt_clk *clk, struct rt_clk_notifier *notifier)
 
rt_err_t rt_clk_prepare (struct rt_clk *clk)
 
void rt_clk_unprepare (struct rt_clk *clk)
 
rt_err_t rt_clk_enable (struct rt_clk *clk)
 
void rt_clk_disable (struct rt_clk *clk)
 
rt_err_t rt_clk_prepare_enable (struct rt_clk *clk)
 
void rt_clk_disable_unprepare (struct rt_clk *clk)
 
rt_err_t rt_clk_array_prepare (struct rt_clk_array *clk_arr)
 
void rt_clk_array_unprepare (struct rt_clk_array *clk_arr)
 
rt_err_t rt_clk_array_enable (struct rt_clk_array *clk_arr)
 
void rt_clk_array_disable (struct rt_clk_array *clk_arr)
 
rt_err_t rt_clk_array_prepare_enable (struct rt_clk_array *clk_arr)
 
void rt_clk_array_disable_unprepare (struct rt_clk_array *clk_arr)
 
rt_err_t rt_clk_set_rate_range (struct rt_clk *clk, rt_ubase_t min, rt_ubase_t max)
 
rt_err_t rt_clk_set_min_rate (struct rt_clk *clk, rt_ubase_t rate)
 
rt_err_t rt_clk_set_max_rate (struct rt_clk *clk, rt_ubase_t rate)
 
rt_err_t rt_clk_set_rate (struct rt_clk *clk, rt_ubase_t rate)
 
rt_ubase_t rt_clk_get_rate (struct rt_clk *clk)
 
rt_base_t rt_clk_round_rate (struct rt_clk *clk, rt_ubase_t rate)
 
rt_err_t rt_clk_set_parent (struct rt_clk *clk, struct rt_clk *clk_parent)
 
struct rt_clkrt_clk_get_parent (struct rt_clk *clk)
 
rt_err_t rt_clk_set_phase (struct rt_clk *clk, int degrees)
 
rt_base_t rt_clk_get_phase (struct rt_clk *clk)
 
struct rt_clkrt_clk_cell_get_clk (const struct rt_clk_cell *cell, const char *con_id)
 
rt_bool_t rt_clk_cell_is_prepared (const struct rt_clk_cell *cell)
 
rt_bool_t rt_clk_cell_is_enabled (const struct rt_clk_cell *cell)
 
rt_ubase_t rt_clk_cell_get_rate (const struct rt_clk_cell *cell)
 
rt_ubase_t rt_clk_cell_round_rate (struct rt_clk_cell *cell, rt_ubase_t rate)
 
struct rt_clk_cellrt_clk_cell_get_parent (const struct rt_clk_cell *cell)
 
struct rt_clk_cellrt_clk_cell_get_parent_by_index (const struct rt_clk_cell *cell, rt_uint8_t idx)
 
rt_uint8_t rt_clk_cell_get_parent_index (struct rt_clk_cell *cell)
 
rt_err_t rt_clk_cell_set_parent (struct rt_clk_cell *cell, struct rt_clk_cell *parent)
 
struct rt_clk_arrayrt_clk_get_array (struct rt_device *dev)
 
struct rt_clkrt_clk_get_by_index (struct rt_device *dev, int index)
 
struct rt_clkrt_clk_get_by_name (struct rt_device *dev, const char *name)
 
void rt_clk_array_put (struct rt_clk_array *clk_arr)
 
void rt_clk_put (struct rt_clk *clk)
 

Detailed Description

Clock driver API.

Macro Definition Documentation

◆ RT_CLK_F_SET_RATE_GATE

#define RT_CLK_F_SET_RATE_GATE   RT_BIT(0)

Must be gated across rate change

◆ RT_CLK_F_SET_PARENT_GATE

#define RT_CLK_F_SET_PARENT_GATE   RT_BIT(1)

Must be gated across re-parent

◆ RT_CLK_F_SET_RATE_PARENT

#define RT_CLK_F_SET_RATE_PARENT   RT_BIT(2)

Propagate rate change up one level

◆ RT_CLK_F_IGNORE_UNUSED

#define RT_CLK_F_IGNORE_UNUSED   RT_BIT(3)

Do not gate even if unused

◆ RT_CLK_F_SET_RATE_UNGATE

#define RT_CLK_F_SET_RATE_UNGATE   RT_BIT(4)

Clock needs to run to set rate

◆ RT_CLK_F_IS_CRITICAL

#define RT_CLK_F_IS_CRITICAL   RT_BIT(5)

Do not gate, ever

◆ RT_CLK_F_GET_RATE_NOCACHE

#define RT_CLK_F_GET_RATE_NOCACHE   RT_BIT(6)

Do not get rate by cache

Function Documentation

◆ rt_clk_register()

rt_err_t rt_clk_register ( struct rt_clk_node clk_np)

Register a clock node into the global clock framework.

This function initializes an rt_clk_node structure and inserts it into the global clock node list. Each node may contain multiple rt_clk_cell instances, which represent the individual output clocks provided by the node.

If the node is associated with a device (clk_np->dev is not NULL), the framework will automatically try to obtain its parent clocks by calling rt_clk_get_array(clk_np->dev). Otherwise, the node will be treated as a root-level provider (e.g., fixed clock).

The caller must ensure that all rt_clk_cell entries are allocated and linked to the node before calling this function.

Parameters
clk_npPointer to the clock node to be registered.
Return values
RT_EOKSuccessfully registered.
-RT_EINVALInvalid argument or missing cell list.
-RT_ENOMEMFailed to allocate parent clock array.

◆ rt_clk_unregister()

rt_err_t rt_clk_unregister ( struct rt_clk_node clk_np)

Unregister a clock node from global clock list.

This API is intended for rollback use only, typically called when a clock provider fails after registration but before any consumer starts using its clocks.

It removes the specified clock node from the global list and releases its parent clock array if present. The function does not free memory of rt_clk_cell instances or the node itself.

Parameters
clk_npPointer to the clock node to be unregistered.
Return values
RT_EOKSuccessfully unregistered.
-RT_EINVALInvalid parameter.
-RT_EBUSYOne or more cells are active and cannot be removed.

◆ rt_clk_notifier_register()

rt_err_t rt_clk_notifier_register ( struct rt_clk clk,
struct rt_clk_notifier notifier 
)

Register clock notifier into notifier list.

Parameters
clkpoint to clock
notifierpoint to notifier for register
Return values
RT_EOK
-RT_EINVAL

◆ rt_clk_notifier_unregister()

rt_err_t rt_clk_notifier_unregister ( struct rt_clk clk,
struct rt_clk_notifier notifier 
)

Unregister clock notifier into notifier list.

Parameters
clkpoint to clock
notifierpoint to notifier for unregister
Return values
RT_EOK
-RT_EINVAL

◆ rt_clk_prepare()

rt_err_t rt_clk_prepare ( struct rt_clk clk)

Prepare clock.

Parameters
clk
Returns
rt_err_t RT_EOK on prepare clock sucessfully, and other value is failed.

◆ rt_clk_unprepare()

void rt_clk_unprepare ( struct rt_clk clk)

Unprepare clock.

Parameters
clkPonit to clock that will be unprepared

◆ rt_clk_enable()

rt_err_t rt_clk_enable ( struct rt_clk clk)

Enable clock.

Parameters
clkpoint to clock
Returns
rt_err_t RT_EOK on enable clock sucessfully, and other value is failed.

◆ rt_clk_disable()

void rt_clk_disable ( struct rt_clk clk)

Disable clock.

Parameters
clkpoint to clock

◆ rt_clk_prepare_enable()

rt_err_t rt_clk_prepare_enable ( struct rt_clk clk)

Prepare and enable clock.

Parameters
clkpoint to clock
Returns
rt_err_t RT_EOK on prepare and enable clock sucessfully, and other value is failed.

◆ rt_clk_disable_unprepare()

void rt_clk_disable_unprepare ( struct rt_clk clk)

Disable and unprepare clock.

Parameters
clkpoint to clock

◆ rt_clk_array_prepare()

rt_err_t rt_clk_array_prepare ( struct rt_clk_array clk_arr)

Prepare clock array for mutipule out clock.

Parameters
clk_arrpoint to clock array
Returns
rt_err_t RT_EOK on prepare clock array sucessfully, and other value is failed.

◆ rt_clk_array_unprepare()

void rt_clk_array_unprepare ( struct rt_clk_array clk_arr)

Unprepare clock array for mutipule out clock.

Parameters
clk_arrpoint to clock array

◆ rt_clk_array_enable()

rt_err_t rt_clk_array_enable ( struct rt_clk_array clk_arr)

Enable clock array for mutipule out clock.

Parameters
clk_arrpoint to clock array
Returns
rt_err_t RT_EOK on Enable clock array sucessfully, and other value is failed.

◆ rt_clk_array_disable()

void rt_clk_array_disable ( struct rt_clk_array clk_arr)

Enable clock array for mutipule out clock.

Parameters
clk_arrpoint to clock array

◆ rt_clk_array_prepare_enable()

rt_err_t rt_clk_array_prepare_enable ( struct rt_clk_array clk_arr)

Prepare and enable clock array.

Parameters
clk_arrpoint to clock array
Returns
rt_err_t RT_EOK on prepare and enable clock array sucessfully, and other value is failed.

◆ rt_clk_array_disable_unprepare()

void rt_clk_array_disable_unprepare ( struct rt_clk_array clk_arr)

Disable and unprepare clock array.

Parameters
clk_arrpoint to clock array

◆ rt_clk_set_rate_range()

rt_err_t rt_clk_set_rate_range ( struct rt_clk clk,
rt_ubase_t  min,
rt_ubase_t  max 
)

Set clock rate range.

Parameters
clkpoint to clock
minminimum clock rate
maxminimum clock rate
Returns
rt_err_t RT_EOK on set clock rate range sucessfully, and other value is failed.

◆ rt_clk_set_min_rate()

rt_err_t rt_clk_set_min_rate ( struct rt_clk clk,
rt_ubase_t  rate 
)

Set minimum clock rate.

Parameters
clkpoint to clock
ratemiminum clock rate
Returns
rt_err_t RT_EOK on set minimum clock rate sucessfully, and other value is failed.

◆ rt_clk_set_max_rate()

rt_err_t rt_clk_set_max_rate ( struct rt_clk clk,
rt_ubase_t  rate 
)

Set maximum clock rate.

Parameters
clkpoint to clock
ratemaximum clock rate
Returns
rt_err_t RT_EOK on set maximum clock rate sucessfully, and other value is failed.

◆ rt_clk_set_rate()

rt_err_t rt_clk_set_rate ( struct rt_clk clk,
rt_ubase_t  rate 
)

Set clock rate.

Parameters
clkpoint to clock
ratetarget rate
Returns
rt_err_t RT_EOK on set clock rate sucessfully, and other value is failed.

◆ rt_clk_get_rate()

rt_ubase_t rt_clk_get_rate ( struct rt_clk clk)

Get clock rate.

Parameters
clkpoint to clock
Returns
rt_ubase_t clock rate or error code

◆ rt_clk_round_rate()

rt_base_t rt_clk_round_rate ( struct rt_clk clk,
rt_ubase_t  rate 
)

Check if clock rate is in the minimum to maximun and get it.

Parameters
clkpoint to clock
raterate will be checked
Returns
rt_base_t get the correct rate
Note
if parameter rate less than the minimum or more than maximum, the retrun rate will be set to minimum ormaximum value

◆ rt_clk_set_parent()

rt_err_t rt_clk_set_parent ( struct rt_clk clk,
struct rt_clk clk_parent 
)

Set clock parent object.

Parameters
clkpoint to clock
clk_parentpoint to parent clock
Returns
rt_err_t RT_EOK on set clock parent sucessfully, and other value is failed.

◆ rt_clk_get_parent()

struct rt_clk * rt_clk_get_parent ( struct rt_clk clk)

Get parent clock pointer.

Parameters
clkchild clock
Returns
struct rt_clk* parent clock object pointer will be return, unless child clock node havn't parent node instead return RT_NULL

◆ rt_clk_set_phase()

rt_err_t rt_clk_set_phase ( struct rt_clk clk,
int  degrees 
)

Set clock phase.

Parameters
clkpoint to clock
degreestarget phase and the unit of phase is degree
Returns
rt_err_t RT_EOK on set clock phase sucessfully, and other value is failed.

◆ rt_clk_get_phase()

rt_base_t rt_clk_get_phase ( struct rt_clk clk)

Get clock phase.

Parameters
clkpoint to clock
Returns
rt_base_t clock phase or error code

◆ rt_clk_cell_get_clk()

struct rt_clk * rt_clk_cell_get_clk ( const struct rt_clk_cell cell,
const char *  con_id 
)

Get or create clock handle for a clock cell.

Parameters
cellPointer to clock cell
con_idConnection identifier for the clock cell
Returns
Pointer to clock handle, or RT_NULL on failure
Note
If the clock handle does not exist, it will be created automatically.

◆ rt_clk_cell_is_prepared()

rt_bool_t rt_clk_cell_is_prepared ( const struct rt_clk_cell cell)

Check if the clock cell is prepared.

Parameters
cellPointer to clock cell
Returns
RT_TRUE if prepared, otherwise RT_FALSE

◆ rt_clk_cell_is_enabled()

rt_bool_t rt_clk_cell_is_enabled ( const struct rt_clk_cell cell)

Check if the clock cell is enabled.

Parameters
cellPointer to clock cell
Returns
RT_TRUE if enabled, otherwise RT_FALSE

◆ rt_clk_cell_get_rate()

rt_ubase_t rt_clk_cell_get_rate ( const struct rt_clk_cell cell)

Get current rate of the clock cell.

Parameters
cellPointer to clock cell
Returns
Current rate in Hz

◆ rt_clk_cell_round_rate()

rt_ubase_t rt_clk_cell_round_rate ( struct rt_clk_cell cell,
rt_ubase_t  rate 
)

Round a desired rate to the nearest supported rate.

Parameters
cellPointer to clock cell
rateDesired frequency in Hz
Returns
Closest supported frequency in Hz

◆ rt_clk_cell_get_parent()

struct rt_clk_cell * rt_clk_cell_get_parent ( const struct rt_clk_cell cell)

Get parent clock cell.

Parameters
cellPointer to clock cell
Returns
Pointer to parent clock cell, or RT_NULL if none

◆ rt_clk_cell_get_parent_by_index()

struct rt_clk_cell * rt_clk_cell_get_parent_by_index ( const struct rt_clk_cell cell,
rt_uint8_t  idx 
)

Get parent clock cell by index.

Parameters
cellPointer to clock cell
idxParent index
Returns
Pointer to parent clock cell, or RT_NULL if not found

◆ rt_clk_cell_get_parent_index()

rt_uint8_t rt_clk_cell_get_parent_index ( struct rt_clk_cell cell)

Get current parent index.

Parameters
cellPointer to clock cell
Returns
Parent index on success, negative error code on failure

◆ rt_clk_cell_set_parent()

rt_err_t rt_clk_cell_set_parent ( struct rt_clk_cell cell,
struct rt_clk_cell parent 
)

Set new parent clock cell.

Parameters
cellPointer to clock cell
parentPointer to new parent clock cell
Returns
RT_EOK on success, or error code on failure

◆ rt_clk_get_array()

struct rt_clk_array * rt_clk_get_array ( struct rt_device dev)

Get clock array pointer from ofw device node.

Parameters
devpoint to dev
Returns
struct rt_clk_array* if use ofw and under normal circumstance, it will return clock array pointer and other value is RT_NULL

◆ rt_clk_get_by_index()

struct rt_clk * rt_clk_get_by_index ( struct rt_device dev,
int  index 
)

Get clock pointer from ofw device node by index.

Parameters
devpoint to dev
indexindex of clock object
Returns
struct rt_clk* if use ofw and under normal circumstance, it will return clock pointer and other value is RT_NULL

◆ rt_clk_get_by_name()

struct rt_clk * rt_clk_get_by_name ( struct rt_device dev,
const char *  name 
)

Get clock pointer from ofw device node by name.

Parameters
devpoint to dev
namename of clock object
Returns
struct rt_clk* if use ofw and under normal circumstance, it will return clock pointer and other value is RT_NULL

◆ rt_clk_array_put()

void rt_clk_array_put ( struct rt_clk_array clk_arr)

Put reference count of all colock in the clock array.

Parameters
clk_arrpoint to clock array

◆ rt_clk_put()

void rt_clk_put ( struct rt_clk clk)

Put reference count of clock.

Parameters
clkpoint to clock