STRUCT CLK_OPS(9)
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 theclk_*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 callclk_enable. This callback is intended to allow clock implementations to do any initialisation that may sleep. Called withprepare_lockheld. π΄πunprepareβ Release the clock from its prepared state. This will typically undo any work done in thepreparecallback. Called withprepare_lockheld.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 fromclk_disable_unusedfor 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 withenable_lockheld. This function must not sleep. ππ₯disableβ Disable the clock atomically. Called withenable_lockheld. 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 fromclk_disable_unusedfor gate clocks with special needs. Called withenable_lockheld. 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 theprepare_mutexis held across this call. If the driver cannot figure out a rate for this clock, it must return0. Returns the calculated rate. Optional, but recommended β if this op is not set then clock rate will be initialized to0.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 au8corresponding to the parent in either the.parent_namesor.parentsarrays. This function in effect translates an array index into the value programmed into the hardware. Returns0on success,-EERRORotherwise.get_parentβ Queries the hardware to determine the parent of a clock. The return value is au8which specifies the index corresponding to the parent clock. This index can be applied to either the.parent_namesor.parentsarrays. 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 with0or1parents.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_ratecall. The third argument gives the parent rate which is likely helpful for most.set_rateimplementation. Returns0on success,-EERRORotherwise.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 ofclk_round_ratecall. The third argument gives the parent rate which is likely helpful for most.set_rate_and_parentimplementation. The fourth argument gives the parent index. This callback is optional (and unnecessary) for clocks with0or1parents as well as for clocks that can tolerate switching the rate and the parent separately via calls to.set_parentand.set_rate. Returns0on success,-EERRORotherwise.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. Returns0on success,-EERRORotherwise. π‘β¨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 or0(perfect clock) if clock has no parent.get_phaseβ Queries the hardware to get the current phase of a clock. Returned values are0-359degrees 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 are0-359. Return0on success, otherwise-EERROR.get_duty_cycleβ Queries the hardware to get the current duty cycle ratio of a clock. The returned values' denominator cannot be0and 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 > 0and>= numerator). Return0on 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. Returns0on success,-EERRORotherwise. πͺterminateβ Free any resource allocated byinit.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 withprepare_lockheld. Returns0on success,-EERRORotherwise.
πΈ 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 thatclk_prepareMUST have been called beforeclk_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:
Kernel file ./include/linux/clk-provider.hβ the actual header this whole page is describing, the mothership πΈclk framework flags(9)β the flags situation for the clk frameworkstruct clk_rate_request(9)β the struct for a rate requeststruct clk_duty(9)β the duty-cycle struct, yes it's a whole vibestruct clk_spread_spectrum(9)β the spread-spectrum struct, she's spreading β¨struct clk_parent_data(9)β parent data, the family tree infostruct clk_init_data(9)β init data, the setup bagstruct clk_hw(9)β the hardware-side clock struct, main character energy πstruct clk_fixed_rate(9)β fixed-rate clock structclk_hw_register_fixed_rate(9)β registers a fixed-rate clockdevm_clk_hw_register_fixed_rate(9)β same thing but devm-managed, so cleanup is automatic π§Ήdevm_clk_hw_register_fixed_rate_parent_data(9)β devm-managed, with parent dataclk_hw_register_fixed_rate_parent_hw(9)β fixed-rate, parent given as a hw pointerclk_hw_register_fixed_rate_parent_data(9)β fixed-rate, parent given as parent dataclk_hw_register_fixed_rate_with_accuracy(9)β fixed-rate, but with accuracy on top π―clk_hw_register_fixed_rate_with_accuracy_parent_hw(9)β accuracy + parent hwclk_hw_register_fixed_rate_with_accuracy_parent_data(9)β accuracy + parent dataclk_hw_register_fixed_rate_parent_accuracy(9)β fixed-rate, parent accuracy flavorstruct clk_gate(9)β the gate struct, she gates, she slays πclk_hw_register_gate(9)β registers a gate clockclk_hw_register_gate_parent_hw(9)β gate registration, parent as hwclk_hw_register_gate_parent_data(9)β gate registration, parent as parent datadevm_clk_hw_register_gate(9)β devm gate registrationdevm_clk_hw_register_gate_parent_hw(9)β devm gate, parent hwdevm_clk_hw_register_gate_parent_data(9)β devm gate, parent datastruct clk_divider(9)β divider struct, she divides (math, not drama) βclk_register_divider(9)β the divider register callclk_hw_register_divider(9)β hw-side divider registrationclk_hw_register_divider_parent_hw(9)β divider registration, parent hwclk_hw_register_divider_parent_data(9)β divider registration, parent dataclk_hw_register_divider_table(9)β divider registration with a tableclk_hw_register_divider_table_parent_hw(9)β table + parent hwclk_hw_register_divider_table_parent_data(9)β table + parent datadevm_clk_hw_register_divider(9)β devm divider registrationdevm_clk_hw_register_divider_parent_hw(9)β devm divider, parent hwdevm_clk_hw_register_divider_parent_data(9)β devm divider, parent datadevm_clk_hw_register_divider_table(9)β devm divider with a tablestruct clk_mux(9)β mux struct, she picks one of many πstruct clk_fixed_factor(9)β fixed-factor structdevm_clk_hw_register_fixed_factor_parent_hw(9)β devm fixed-factor registration, parent hwstruct clk_fractional_divider(9)β fractional divider struct, fractions but make it fashionstruct clk_multiplier(9)β multiplier struct, she multiplies βοΈclk_hw_get_dev(9)β grabs the device for a clk_hwclk_hw_get_of_node(9)β grabs theof_nodefor a clk_hw π³
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms