pwm_round_wa..._might_sleep(9)
β¨ pwm_round_wa..._might_sleep(9) β¨
okay so real quick β this is a page straight out of the Kernel API Manual, and the star of the show is pwm_round_waveform_might_sleep. yes the title has an ellipsis in it, no that's not me being dramatic for once, that's just how it's abbreviated. π
π NAME π
pwm_round_waveform_might_sleep β query hardware capabilities. Cannot be used in atomic context. periodt.
π¦ SYNOPSIS π¦
int pwm_round_waveform_might_sleep (struct pwm_device *pwm , struct
pwm_waveform *wf );
πΈ ARGUMENTS πΈ
pwmβ the PWM device, bestie. that's your gadget.wfβ the waveform that gets rounded, and also the output parameter. she does both jobs, we stan a multitasker. π
π DESCRIPTION π
so like, typically a given waveform cannot be implemented exactly by the hardware β think about it, sometimes the hardware only supports coarse period resolution, or it straight up has no duty_offset. it's giving limited, honestly. π
this function returns the waveform that's actually implemented if you pass wf to pwm_set_waveform_might_sleep right now.
but β and this is the important part, don't skip it β the world doesn't stop turning when you call it. so when you do:
pwm_round_waveform_might_sleep(mypwm, wf);
pwm_set_waveform_might_sleep(mypwm, wf, true);
that latter call might fail, lowkey. why? because an input clock could've changed its rate between these two calls, and then the waveform that pwm_round_waveform_might_sleep determined can't be implemented anymore. so close yet so far π
usually all values passed in wf are rounded down to the nearest possible value β in this order: period_length_ns, then duty_length_ns, then duty_offset_ns. order matters, iykyk. only if that isn't possible might a value grow. for a more formal description, go check the documentation for pwm_set_waveform_might_sleep. she explains it properly. π
β RETURN β
0on success π«Ά1if at least one value had to be rounded up (she had to grow, let her)- or a negative
errnoπ
π§ CONTEXT π§
May sleep. that's it, that's the context. so like, don't be weird about it.
π₯ SEE ALSO π₯
Kernel file ./drivers/pwm/core.c, plus the whole friend group:
pwm_get_waveform_might_sleep(9)pwm_set_waveform_might_sleep(9)pwm_apply_might_sleep(9)pwm_apply_atomic(9)pwm_get_state_hw(9)pwm_adjust_config(9)pwm_capture(9)pwm_request_from_chip(9)of_pwm_get(9)acpi_pwm_get(9)pwm_get(9)pwm_put(9)devm_pwm_get(9)devm_fwnode_pwm_get(9)__pwmchip_add(9)pwmchip_remove(9)pwm_add_table(9)pwm_remove_table(9)
and that's the whole page bestie π this lil cutie lives in ./drivers/pwm and the version vibes are dated October 2026 β so yeah, she's from the future, main character energy fr fr. πβ¨π¦
π¦ 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