PebbleOS v4.48.0-75-g7416f78a1
Loading...
Searching...
No Matches
Clock

Clock controller class. More...

Modules

 Calibrated clocks
 Track the rate of an imprecise oscillator by measuring it against a reference.
 
 Clock controller drivers
 Interface for clock controller drivers.
 
 Fixed-rate clocks
 Clock controller of one clock that always runs at the same rate, as a crystal.
 
 nRF52
 Clock controller of the nRF52 clock control block.
 
 nRF54L
 Clock controller of the nRF54L clock control block.
 
 SF32LB RCC clocks
 Clock controllers of the SF32LB52: the HPSYS RCC, the PMUC oscillators and the RTC clock.
 
 SF32LB52 crystal trim
 Load capacitance trim of the 48 MHz crystal, from the SoC factory configuration in the flash OTP area.
 
 SF32LB52 PMUC clocks
 Clock controller for the oscillators of the SF32LB52 PMUC.
 
 SF32LB57 PMUC clocks
 Clock controller for the oscillators of the SF32LB57 PMUC.
 
 SF32LB LPSYS RCC clocks
 Clock controller for the LPSYS RCC of the SF32LB SoCs.
 
 STM32H7
 Clock controller of the STM32H7 RCC.
 

Data Structures

struct  pbl_clk
 A clock, as used by a consumer. More...
 
struct  pbl_clk_assigned
 Parent and rate a clock is set to when its controller comes up. More...
 
struct  pbl_clk_notifier
 A rate change subscription. More...
 

Macros

#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.
 

Typedefs

typedef void(* pbl_clk_notifier_fn_t) (struct pbl_clk_notifier *nb, uint64_t rate_mhz)
 Rate change callback.
 

Functions

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.
 

Detailed Description

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:

// use the peripheral
#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.


Data Structure Documentation

◆ pbl_clk

struct 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

struct 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

struct pbl_clk_notifier

A rate change subscription.

Data Fields
struct pbl_clk clk Clock.
pbl_clk_notifier_fn_t fn Callback.

Macro Definition Documentation

◆ PBL_CLK

#define PBL_CLK (   _ctrl,
  _id 
)    {.ctrl = (_ctrl), .id = (_id)}

Initializer for a struct pbl_clk.

Parameters
_ctrlClock controller.
_idClock 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
_clkClock, a PBL_CLK() initializer.
_parentParent, a PBL_CLK() initializer, or {} to keep the current one.
_rate_hzRate 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
symSymbol 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.

Typedef Documentation

◆ 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
nbNotifier.
rate_mhzNew rate in mHz.

Function Documentation

◆ pbl_clk_assign()

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.

Parameters
assignedList from PBL_CLK_ASSIGNED_DEFINE().
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
clkClock.
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
clkClock.
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
aClock.
bClock.
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
clkClock.
[out]parentParent.
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
clkClock.
[out]rate_mhzRate 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
clkClock.
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

Check whether a clock reference has a clock.

Parameters
clkClock.
Returns
false for PBL_CLK_NONE.

References pbl_clk::ctrl.

◆ pbl_clk_is_enabled()

bool pbl_clk_is_enabled ( const struct pbl_clk *  clk)

Check whether a clock has users.

Parameters
clkClock.
Returns
True if the clock is enabled.

◆ pbl_clk_notifier_register()

void pbl_clk_notifier_register ( struct pbl_clk_notifier *  nb)

Call a function whenever the rate of a clock changes.

Parameters
nbNotifier, 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
clkClock.
parentNew 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
clkClock.
rate_mhzRate 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.