PebbleOS
Loading...
Searching...
No Matches
Clock

Clock controller class. More...

Modules

 SF32LB RCC clocks
 Clock controller of the SF32LB52 HPSYS RCC.
 

Data Structures

struct  pbl_clk_controller_ops
 Clock controller driver operations, called with interrupts locked. More...
 
struct  pbl_clk_controller
 A clock controller. More...
 
struct  pbl_clk
 A clock, as used by a consumer. More...
 

Macros

#define PBL_CLK_CONTROLLER_STATE_DEFINE(sym, _num_clks)
 Define the class state of clock controller sym, for the driver's define macro.
 
#define PBL_CLK_CONTROLLER_INIT(sym, _name, _init, _parent, _ops)
 Initializer for the struct pbl_clk_controller of controller sym.
 
#define PBL_CLK(_ctrl, _id)   {.ctrl = (_ctrl), .id = (_id)}
 Initializer for a struct pbl_clk.
 

Functions

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.
 

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:22
#define SF32LB52_HPSYS_CLK_TRNG
Definition sf32lb.h:39
A clock, as used by a consumer.
Definition clk.h:83
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:96

Data Structure Documentation

◆ pbl_clk_controller

struct pbl_clk_controller

A clock controller.

Data Fields
struct pbl_device dev Device.
uint16_t num_clks Number of clocks.
const struct pbl_clk_controller_ops * ops Driver operations.
uint8_t * use_counts Enable count of each clock.

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

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_CONTROLLER_INIT

#define PBL_CLK_CONTROLLER_INIT (   sym,
  _name,
  _init,
  _parent,
  _ops 
)
Value:
{ \
.dev = PBL_DEVICE_INIT(sym, _name, _init, _parent, nullptr), \
.ops = (_ops), \
.use_counts = sym##_clk_use_counts, \
.num_clks = sizeof(sym##_clk_use_counts), \
}
#define PBL_DEVICE_INIT(sym, _name, _init, _parent, _deps)
Initializer for the struct pbl_device of device instance sym.
Definition device.h:142

Initializer for the struct pbl_clk_controller of controller sym.

Parameters
symSymbol of the controller instance, with its state defined by PBL_CLK_CONTROLLER_STATE_DEFINE().
_nameName.
_initDevice init function, or NULL.
_parentParent device, or NULL.
_opsDriver operations.

◆ PBL_CLK_CONTROLLER_STATE_DEFINE

#define PBL_CLK_CONTROLLER_STATE_DEFINE (   sym,
  _num_clks 
)
Value:
static uint8_t sym##_clk_use_counts[_num_clks]
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:109

Define the class state of clock controller sym, for the driver's define macro.

Parameters
symSymbol of the controller instance.
_num_clksNumber of clocks.

Function Documentation

◆ 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_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.