pwm_set_relative_duty_cycle(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 your duty_cycle is expressed in. so if you're thinking in hundredths, this is your 100. 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 if duty_cycle and/or scale are inconsistent, which specifically means scale == 0 or duty_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 πŸ“


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