Clock controller class.
More...
|
| #define | PBL_CLK(_ctrl, _id) {.ctrl = (_ctrl), .id = (_id)} |
| | Initializer for a struct pbl_clk.
|
| |
| #define | PBL_CLK_NONE PBL_CLK(nullptr, 0) |
| | Initializer for a struct pbl_clk without a clock.
|
| |
| #define | PBL_CLK_ASSIGNED(_clk, _parent, _rate_hz) {.clk = _clk, .parent = _parent, .rate_hz = (_rate_hz)} |
| | Initializer for a struct pbl_clk_assigned.
|
| |
| #define | PBL_CLK_ASSIGNED_DEFINE(sym, ...) static const struct pbl_clk_assigned sym[] = {__VA_ARGS__ __VA_OPT__(, ){}} |
| | Define the list of parents and rates a clock controller assigns, for the driver's define macro.
|
| |
|
| static bool | pbl_clk_is_connected (const struct pbl_clk *clk) |
| | Check whether a clock reference has a clock.
|
| |
| int | pbl_clk_init (const struct pbl_clk *clk) |
| | Bring up the controller of a clock, for a user that runs before the devices are initialized.
|
| |
| static bool | pbl_clk_eq (const struct pbl_clk *a, const struct pbl_clk *b) |
| | Check whether two clock references name the same clock.
|
| |
| int | pbl_clk_enable (const struct pbl_clk *clk) |
| | Take a reference on a clock, ungating it for the first user.
|
| |
| int | pbl_clk_disable (const struct pbl_clk *clk) |
| | Drop a reference on a clock, gating it after the last user.
|
| |
| bool | pbl_clk_is_enabled (const struct pbl_clk *clk) |
| | Check whether a clock has users.
|
| |
| int | pbl_clk_get_rate (const struct pbl_clk *clk, uint64_t *rate_mhz) |
| | Get the rate of a clock.
|
| |
| int | pbl_clk_get_parent (const struct pbl_clk *clk, struct pbl_clk *parent) |
| | Get the parent of a clock.
|
| |
| int | pbl_clk_set_parent (const struct pbl_clk *clk, const struct pbl_clk *parent) |
| | Switch a clock to another parent.
|
| |
| int | pbl_clk_set_rate (const struct pbl_clk *clk, uint64_t rate_mhz) |
| | Set the rate of a clock.
|
| |
| int | pbl_clk_assign (const struct pbl_clk_assigned *assigned) |
| | Switch clocks to their assigned parents, then set their assigned rates, as Linux does, for clock controller drivers.
|
| |
| void | pbl_clk_notifier_register (struct pbl_clk_notifier *nb) |
| | Call a function whenever the rate of a clock changes.
|
| |
Clock controller class.
A clock controller is a struct pbl_clk_controller device providing a set of clocks, each identified by a provider-specific number defined in the controller header. A consumer holds a struct pbl_clk naming the controller and clock, lists the controller among its device dependencies, and enables the clock while it uses the peripheral. Enables are counted per clock, so drivers sharing a clock never gate it under each other, and are safe to call from any context:
#define SF32LB_HPSYS_RCC
HPSYS RCC clock controller.
Definition sf32lb.h:29
#define SF32LB52_HPSYS_CLK_TRNG
Definition sf32lb.h:46
A clock, as used by a consumer.
Definition clk.h:43
int pbl_clk_enable(const struct pbl_clk *clk)
Take a reference on a clock, ungating it for the first user.
int pbl_clk_disable(const struct pbl_clk *clk)
Drop a reference on a clock, gating it after the last user.
#define PBL_CLK(_ctrl, _id)
Initializer for a struct pbl_clk.
Definition clk.h:56
Clocks form a tree, across controllers: a clock may have a parent, as the gate of a peripheral has the clock it gates, and its rate follows from the parent's. Enabling a clock enables its parents first.
A consumer that depends on a clock's rate reads it with pbl_clk_get_rate() and, if the rate can change at run time, registers a struct pbl_clk_notifier to follow it.
◆ pbl_clk
A clock, as used by a consumer.
| Data Fields |
|
const struct pbl_clk_controller * |
ctrl |
Controller. |
|
uint32_t |
id |
Clock number on the controller. |
◆ pbl_clk_assigned
Parent and rate a clock is set to when its controller comes up.
| Data Fields |
|
struct pbl_clk |
clk |
Clock. |
|
struct pbl_clk |
parent |
Parent, without a controller to keep the current one. |
|
uint32_t |
rate_hz |
Rate in Hz, or 0 to keep the current one. |
◆ pbl_clk_notifier
A rate change subscription.
◆ PBL_CLK
| #define PBL_CLK |
( |
|
_ctrl, |
|
|
|
_id |
|
) |
| {.ctrl = (_ctrl), .id = (_id)} |
Initializer for a struct pbl_clk.
- Parameters
-
| _ctrl | Clock controller. |
| _id | Clock number, from the controller's binding header. |
◆ PBL_CLK_ASSIGNED
| #define PBL_CLK_ASSIGNED |
( |
|
_clk, |
|
|
|
_parent, |
|
|
|
_rate_hz |
|
) |
| {.clk = _clk, .parent = _parent, .rate_hz = (_rate_hz)} |
Initializer for a struct pbl_clk_assigned.
- Parameters
-
| _clk | Clock, a PBL_CLK() initializer. |
| _parent | Parent, a PBL_CLK() initializer, or {} to keep the current one. |
| _rate_hz | Rate in Hz, or 0 to keep the current one. |
◆ PBL_CLK_ASSIGNED_DEFINE
| #define PBL_CLK_ASSIGNED_DEFINE |
( |
|
sym, |
|
|
|
... |
|
) |
| static const struct pbl_clk_assigned sym[] = {__VA_ARGS__ __VA_OPT__(, ){}} |
Define the list of parents and rates a clock controller assigns, for the driver's define macro.
- Parameters
-
| sym | Symbol of the list. |
| ... | PBL_CLK_ASSIGNED() initializers, from the assigned-clocks, assigned-clock-parents and assigned-clock-rates properties of the controller's node. |
◆ PBL_CLK_NONE
| #define PBL_CLK_NONE PBL_CLK(nullptr, 0) |
Initializer for a struct pbl_clk without a clock.
◆ pbl_clk_notifier_fn_t
| typedef void(* pbl_clk_notifier_fn_t) (struct pbl_clk_notifier *nb, uint64_t rate_mhz) |
Rate change callback.
Called from the context the provider changed the rate in, possibly an interrupt: it must not block.
- Parameters
-
| nb | Notifier. |
| rate_mhz | New rate in mHz. |
◆ pbl_clk_assign()
Switch clocks to their assigned parents, then set their assigned rates, as Linux does, for clock controller drivers.
- Parameters
-
- Returns
- 0 or the first error of pbl_clk_set_parent() or pbl_clk_set_rate().
◆ pbl_clk_disable()
| int pbl_clk_disable |
( |
const struct pbl_clk * |
clk | ) |
|
Drop a reference on a clock, gating it after the last user.
Must balance a successful pbl_clk_enable().
- Parameters
-
- Returns
- 0 or a negative errno.
◆ pbl_clk_enable()
| int pbl_clk_enable |
( |
const struct pbl_clk * |
clk | ) |
|
Take a reference on a clock, ungating it for the first user.
- Parameters
-
- Returns
- 0 or a negative errno.
◆ pbl_clk_eq()
| static bool pbl_clk_eq |
( |
const struct pbl_clk * |
a, |
|
|
const struct pbl_clk * |
b |
|
) |
| |
|
inlinestatic |
Check whether two clock references name the same clock.
- Parameters
-
- Returns
- True if both are the same clock of the same controller.
References pbl_clk::ctrl, and pbl_clk::id.
◆ pbl_clk_get_parent()
| int pbl_clk_get_parent |
( |
const struct pbl_clk * |
clk, |
|
|
struct pbl_clk * |
parent |
|
) |
| |
Get the parent of a clock.
- Parameters
-
| clk | Clock. |
| [out] | parent | Parent. |
- Returns
- 0,
-ENOENT if the clock has no parent, or another negative errno.
◆ pbl_clk_get_rate()
| int pbl_clk_get_rate |
( |
const struct pbl_clk * |
clk, |
|
|
uint64_t * |
rate_mhz |
|
) |
| |
Get the rate of a clock.
Callable from any context.
- Parameters
-
| clk | Clock. |
| [out] | rate_mhz | Rate in mHz. |
- Returns
- 0,
-ENOTSUP if the rate is not known, or another negative errno.
◆ pbl_clk_init()
| int pbl_clk_init |
( |
const struct pbl_clk * |
clk | ) |
|
Bring up the controller of a clock, for a user that runs before the devices are initialized.
- Parameters
-
- Returns
- 0, or
-ENODEV if the controller failed to come up.
◆ pbl_clk_is_connected()
| static bool pbl_clk_is_connected |
( |
const struct pbl_clk * |
clk | ) |
|
|
inlinestatic |
◆ pbl_clk_is_enabled()
| bool pbl_clk_is_enabled |
( |
const struct pbl_clk * |
clk | ) |
|
Check whether a clock has users.
- Parameters
-
- Returns
- True if the clock is enabled.
◆ pbl_clk_notifier_register()
Call a function whenever the rate of a clock changes.
- Parameters
-
| nb | Notifier, with its clock and callback set; must stay valid. |
◆ pbl_clk_set_parent()
| int pbl_clk_set_parent |
( |
const struct pbl_clk * |
clk, |
|
|
const struct pbl_clk * |
parent |
|
) |
| |
Switch a clock to another parent.
The references an enabled clock holds move to the new parent. The notifiers of the clock and of the clocks below it are told the new rates.
- Parameters
-
| clk | Clock. |
| parent | New parent. |
- Returns
- 0,
-ENOTSUP if the clock cannot switch, -EINVAL if it cannot take that parent, or another negative errno.
◆ pbl_clk_set_rate()
| int pbl_clk_set_rate |
( |
const struct pbl_clk * |
clk, |
|
|
uint64_t |
rate_mhz |
|
) |
| |
Set the rate of a clock.
The notifiers of the clock and of the clocks below it are told the new rates.
- Parameters
-
| clk | Clock. |
| rate_mhz | Rate in mHz. |
- Returns
- 0,
-ENOTSUP if the clock cannot change its rate, -EINVAL if it cannot run at that rate exactly, or another negative errno.