of_pwm_get(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’« of_pwm_get(9) β€” like, the whole tea πŸ’«

Okay bestie, sit down, grab your matcha πŸ“ β€” this is of_pwm_get(9) straight out of the Kernel API Manual, and honestly? It's giving "small function, big responsibilities." Let's get into it πŸ’…


✨ NAME ✨

of_pwm_get β€” request a PWM via the PWM framework πŸŽ€

No cap, that's the whole pitch. You want a PWM? This is the door you knock on.


✨ SYNOPSIS ✨

struct pwm_device * of_pwm_get (struct device *dev , struct device_node
*np , const char *con_id );

Three arguments, one pointer out. Iconic signature honestly 🫢


✨ ARGUMENTS ✨

  • dev β€” the device for the PWM consumer. Like, who's asking for the PWM πŸ‘€
  • np β€” the device node to get the PWM from. This is the tree branch you're pulling from 🌳
  • con_id β€” the consumer name. Your little name tag at the PWM party πŸŽ€

✨ DESCRIPTION ✨

So here's the vibe: it returns the PWM device parsed from the phandle and index specified in the "pwms" property of a device tree node β€” or a negative error-code on failure 😭. Everything parsed from the device tree gets stored in the returned PWM device object, so it's not just handing you a pointer, it's handing you a fully loaded one ✨

Now, the con_id tea β˜• β€” and this part matters, so pay attention:

If con_id is NULL, the first PWM device listed in the "pwms" property will be requested. Easy, default behavior, slay πŸ’…

Otherwise, the "pwm-names" property is used to do a reverse lookup of the PWM index. Which also means β€” and this is the part people forget and then cry about β€” the "pwm-names" property becomes mandatory for devices that look up the PWM device via the con_id parameter. Mandatory. Like, required required. Not optional, bestie 🚨

Lowkey the biggest gotcha on this whole page: pass a con_id, and you must have "pwm-names" in your device tree. No exceptions, no "but it worked on my machine" 🫠

✨ RETURN ✨

A pointer to the requested PWM device πŸ’– β€” or, if things went sideways, an ERR_PTR-encoded error code. So like, always check it with IS_ERR() before you go dereferencing it, iykyk πŸ‘‘


✨ SEE ALSO ✨

The kernel file lives at ./drivers/pwm/core.c, and here's the whole friend group 🫢:

pwm_round_waveform_might_sleep(9), 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), 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)

That's a lot of PWMs. Go read them. Or don't. But like, you should 🌈


Alright bestie, that's the whole page β€” from ./drivers/pwm, October 2026, in the Kernel API Manual. Go forth and request your PWMs responsibly πŸ’œβœ¨

πŸ“¦ where this page comes from