pwm_round_wa..._might_sleep(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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 ⭐

  • 0 on success 🫢
  • 1 if 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:


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