STRUCT CLK_OPS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

okay bestie, this is the struct clk_ops(9) page from the Kernel API Manual β€” clock callback ops, and yes we're making it cute. It's giving "hardware clock homework but make it make sense" energy. πŸ•°οΈβœ¨


πŸ’– NAME πŸ’–

  • struct clk_ops β€” Callback operations for hardware clocks; these are to be provided by the clock implementation, and will be called by drivers through the clk_* api. πŸ’…

✨ SYNOPSIS ✨

       struct clk_ops {
           int (*prepare)(struct clk_hw *hw);
           void (*unprepare)(struct clk_hw *hw);
           int (*is_prepared)(struct clk_hw *hw);
           void (*unprepare_unused)(struct clk_hw *hw);
           int (*enable)(struct clk_hw *hw);
           void (*disable)(struct clk_hw *hw);
           int (*is_enabled)(struct clk_hw *hw);
           void (*disable_unused)(struct clk_hw *hw);
           int (*save_context)(struct clk_hw *hw);
           void (*restore_context)(struct clk_hw *hw);
           unsigned long   (*recalc_rate)(struct clk_hw *hw, unsigned long
       parent_rate);
           int (*determine_rate)(struct clk_hw *hw, struct clk_rate_request
       *req);
           int (*set_parent)(struct clk_hw *hw, u8 index);
           u8 (*get_parent)(struct clk_hw *hw);
           int (*set_rate)(struct clk_hw *hw, unsigned long rate, unsigned long
       parent_rate);
           int (*set_rate_and_parent)(struct clk_hw *hw, unsigned long rate,
       unsigned long parent_rate, u8 index);
           int (*set_spread_spectrum)(struct clk_hw *hw, const struct
       clk_spread_spectrum *ss_conf);
           unsigned long   (*recalc_accuracy)(struct clk_hw *hw, unsigned long
       parent_accuracy);
           int (*get_phase)(struct clk_hw *hw);
           int (*set_phase)(struct clk_hw *hw, int degrees);
           int (*get_duty_cycle)(struct clk_hw *hw, struct clk_duty *duty);
           int (*set_duty_cycle)(struct clk_hw *hw, struct clk_duty *duty);
           int (*init)(struct clk_hw *hw);
           void (*terminate)(struct clk_hw *hw);
           void (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
        };

πŸŽ€ Members πŸŽ€

  • prepare β€” Prepare the clock for enabling. This must not return until the clock is fully prepared, and it's safe to call clk_enable. This callback is intended to allow clock implementations to do any initialisation that may sleep. Called with prepare_lock held. πŸ˜΄πŸ’–
  • unprepare β€” Release the clock from its prepared state. This will typically undo any work done in the prepare callback. Called with prepare_lock held.
  • is_prepared β€” Queries the hardware to determine if the clock is prepared. This function is allowed to sleep. Optional, if this op is not set then the prepare count will be used.
  • unprepare_unused β€” Unprepare the clock atomically. Only called from clk_disable_unused for prepare clocks with special needs. Called with prepare mutex held. This function may sleep.
  • enable β€” Enable the clock atomically. This must not return until the clock is generating a valid clock signal, usable by consumer devices. Called with enable_lock held. This function must not sleep. πŸ’€πŸ”₯
  • disable β€” Disable the clock atomically. Called with enable_lock held. This function must not sleep.
  • is_enabled β€” Queries the hardware to determine if the clock is enabled. This function must not sleep. Optional, if this op is not set then the enable count will be used.
  • disable_unused β€” Disable the clock atomically. Only called from clk_disable_unused for gate clocks with special needs. Called with enable_lock held. This function must not sleep.
  • save_context β€” Save the context of the clock in preparation for poweroff. πŸ”‹
  • restore_context β€” Restore the context of the clock after a restoration of power. ⚑
  • recalc_rate β€” Recalculate the rate of this clock, by querying hardware. The parent rate is an input parameter. It is up to the caller to ensure that the prepare_mutex is held across this call. If the driver cannot figure out a rate for this clock, it must return 0. Returns the calculated rate. Optional, but recommended β€” if this op is not set then clock rate will be initialized to 0.
  • determine_rate β€” Given a target rate as input, returns the closest rate actually supported by the clock, and optionally the parent clock that should be used to provide the clock rate. 🎯
  • set_parent β€” Change the input source of this clock; for clocks with multiple possible parents specify a new parent by passing in the index as a u8 corresponding to the parent in either the .parent_names or .parents arrays. This function in effect translates an array index into the value programmed into the hardware. Returns 0 on success, -EERROR otherwise.
  • get_parent β€” Queries the hardware to determine the parent of a clock. The return value is a u8 which specifies the index corresponding to the parent clock. This index can be applied to either the .parent_names or .parents arrays. In short, this function translates the parent value read from hardware into an array index. Currently only called when the clock is initialized by __clk_init. This callback is mandatory for clocks with multiple parents. It is optional (and unnecessary) for clocks with 0 or 1 parents.
  • set_rate β€” Change the rate of this clock. The requested rate is specified by the second argument, which should typically be the return of .determine_rate call. The third argument gives the parent rate which is likely helpful for most .set_rate implementation. Returns 0 on success, -EERROR otherwise.
  • set_rate_and_parent β€” Change the rate and the parent of this clock. The requested rate is specified by the second argument, which should typically be the return of clk_round_rate call. The third argument gives the parent rate which is likely helpful for most .set_rate_and_parent implementation. The fourth argument gives the parent index. This callback is optional (and unnecessary) for clocks with 0 or 1 parents as well as for clocks that can tolerate switching the rate and the parent separately via calls to .set_parent and .set_rate. Returns 0 on success, -EERROR otherwise.
  • set_spread_spectrum β€” Optional callback used to configure the spread spectrum modulation frequency, percentage, and method to reduce EMI by spreading the clock frequency over a wider range. Returns 0 on success, -EERROR otherwise. πŸ“‘βœ¨
  • recalc_accuracy β€” Recalculate the accuracy of this clock. The clock accuracy is expressed in ppb (parts per billion). The parent accuracy is an input parameter. Returns the calculated accuracy. Optional β€” if this op is not set then clock accuracy will be initialized to parent accuracy or 0 (perfect clock) if clock has no parent.
  • get_phase β€” Queries the hardware to get the current phase of a clock. Returned values are 0-359 degrees on success, negative error codes on failure.
  • set_phase β€” Shift the phase of this clock signal in degrees specified by the second argument. Valid values for degrees are 0-359. Return 0 on success, otherwise -EERROR.
  • get_duty_cycle β€” Queries the hardware to get the current duty cycle ratio of a clock. The returned values' denominator cannot be 0 and must be superior or equal to the numerator.
  • set_duty_cycle β€” Apply the duty cycle ratio to this clock signal specified by the numerator (2nd argument) and denominator (3rd argument). Argument must be a valid ratio (denominator > 0 and >= numerator). Return 0 on success, otherwise -EERROR.
  • init β€” Perform platform-specific initialization magic. This is not used by any of the basic clock types. This callback exists for HW which needs to perform some initialisation magic for CCF to get an accurate view of the clock. It may also be used when dynamic resource allocation is required. It shall not be used to deal with clock parameters, such as rate or parents. Returns 0 on success, -EERROR otherwise. πŸͺ„
  • terminate β€” Free any resource allocated by init.
  • debug_init β€” Set up type-specific debugfs entries for this clock. This is called once, after the debugfs directory entry for this clock has been created. The dentry pointer representing that directory is provided as an argument. Called with prepare_lock held. Returns 0 on success, -EERROR otherwise.

🌸 Description 🌸

The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow implementations to split any work between atomic (enable) and sleepable (prepare) contexts. If enabling a clock requires code that might sleep, this must be done in clk_prepare. Clock enable code that will never be called in a sleepable context may be implemented in clk_enable.

Typically, drivers will call clk_prepare when a clock may be needed later (eg. when a device is opened), and clk_enable when the clock is actually required (eg. from an interrupt).

🚨 Note that clk_prepare MUST have been called before clk_enable. periodt. πŸ’…

🌈 SEE ALSO 🌈

okay bestie, this is the part where we hand you the whole friend group πŸ’– every single one of these is a real page you can pull up with man 9 <name>, so go be nosy:


and that's the whole page, bestie, you made it to the end 🫢 go forth and register your clocks responsibly, ily πŸ˜­πŸ’–

source: <green>./include/linux</green> β€’ October 2026 β€’ this whole lovely mess is struct clk_ops(9) βœ¨πŸŽ€

πŸ“¦ where this page comes from