pwm_set_relative_duty_cycle(9)
π pwm_set_relative_duty_cycle(9) β the Kernel API Manual page, bestie edition
okay so picture this: you're deep in the kernel, you've got a PWM thing, and you want to say "gimme 50%" instead of doing nanosecond math in your head at 2am. That's literally this function. It's called pwm_set_relative_duty_cycle, and it's from the Kernel API Manual, and it's here to save your whole night. π«Ά
β¨ NAME β¨
pwm_set_relative_duty_cycle β sets a relative duty cycle value. that's it, that's the vibe. no absolute, no nanosecond nonsense on your end. π
π¦ SYNOPSIS π¦
int pwm_set_relative_duty_cycle (struct pwm_state *state , unsigned int
duty_cycle , unsigned int scale );
π ARGUMENTS π
stateβ the PWM state you're filling in. she's the canvas, you're the artist β¨duty_cycleβ the relative duty cycle value. yes, the relative one, like a percentage-ish number, not nanoseconds πΈscaleβ the scale yourduty_cycleis expressed in. so if you're thinking in hundredths, this is your100. context is everything, bestie π§
π DESCRIPTION π
okay so what she does: this function converts a relative duty cycle into an absolute one β expressed in nanoseconds β and puts that result straight into state->duty_cycle. no cap. she does the conversion so you don't have to. π
so like, for example, if you want to configure a 50% duty cycle, you call:
pwm_init_state(pwm, state); pwm_set_relative_duty_cycle(state, 50, 100);
pwm_apply_might_sleep(pwm, state);
see how clean that reads? 50 out of 100, and the rest is handled. iconic. ate. π
π₯ RETURN π₯
0β success, we love to see it π-EINVALβ the bad-ending timeline π. you get this ifduty_cycleand/orscaleare inconsistent, which specifically meansscale == 0orduty_cycle > scale. so don't divide by zero and don't go over 100%, bestie, it's giving chaos π
π SEE ALSO π
all the siblings, neighbors, and lore-adjacent icons of the kernel PWM-verse, plus the kernel file they live in: ./include/linux/pwm.h π
enum pwm_polarity(9)struct pwm_args(9)struct pwm_waveform(9)struct pwm_device(9)pwm_get_state(9)pwm_init_state(9)pwm_get_relative_duty_cycle(9)struct pwm_capture(9)struct pwm_ops(9)struct pwm_chip(9)pwmchip_supports_waveform(9)pwm_config(9)pwm_enable(9)pwm_disable(9)pwm_might_sleep(9)
k bye, go set some duty cycles π
β¨ this page lives in ./include/linux and is dated October 2026 β mwah, stay slaying, and remember: relative in, nanoseconds out, no cap ππ
π¦ 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