PWMC(4)
π PWMC π
okay bestie, gather round, because we're talking about pwmc β the PWM (Pulse Width Modulation) control device driver β¨ It lives in the Kernel Interfaces Manual (section 4, for the uninitiated π) and it's literally the thing that lets you talk to your PWM hardware from userspace. no cap.
β¨ SYNOPSIS β¨
so like, you got two ways to get this driver into your life, and both are valid π
Option A: bake it into the kernel. drop these lines in your kernel config file:
device pwmbus
device pwmc
Option B: load it as a module at boot. put this line in loader.conf(5):
pwmc_load="YES"
pick your fighter, both slay π«Ά
πΈ DESCRIPTION πΈ
okay so here's the tea β The pwmc driver gives you device-control access to a channel of PWM hardware. And the way it works? Each individual instance of a pwmc device is tied to exactly one single PWM output channel. one instance, one channel, very monogamous of it π
now, some PWM hardware is set up all communal-style, with multiple channels sharing a common clock or other resources π― In those cases you'll still get a separate pwmc instance for each channel, BUT β and this is the important part, bestie β changing the period or duty cycle of any one channel may affect other channels within the hardware that share the same resources π so like, be careful, your backlight might start beefing with your fan. Consult the documentation for the underlying PWM hardware device driver for the deets on which channels share resources. iykyk.
an instance of pwmc creates a character device named /dev/pwm/pwmcX.Y where:
Xis a sequential number assigned to each PWM hardware controller as it is discovered by the system π’Yis the channel number within that hardware controller π―
and here's the cute part: the driver can be configured to create aliases that point to the pwmcX.Y entries, which is basically giving your channels β¨namesβ¨. named channels. main character energy fr fr.
π The ioctls π
pwmc gives you control of a PWM channel with these ioctl(2) calls and data structures, all defined in <dev/pwm/pwmc.h>:
PWMGETSTATE(struct pwm_state) β Retrieve the current state of the channel. it's giving "let me see what you're up to" πPWMSETSTATE(struct pwm_state) β Set the current state of the channel. β οΈ All parameters are updated on every call. so like, every single one. To change just one of the values, usePWMGETSTATEto get the current state and then submit the same data back with just the appropriate value changed. classic get-modify-set, you got this πͺ
π¦ The pwm_state structure π¦
it's defined as follows, and honestly? iconic:
struct pwm_state {
u_int period;
u_int duty;
uint32_t flags;
bool enable;
};
let's break it down, bestie:
periodβ The duration, in nanoseconds, of one complete on-off cycle. β±οΈdutyβ The duration, in nanoseconds, of the on portion of one cycle. π‘flagsβ Flags that affect the output signal, and they can be bitwise-ORed together. The following flags are currently defined:PWM_POLARITY_INVERTEDβ Invert the signal polarity. π flip it, reverse it
enableβfalseto disable the output signal, ortrueto enable it. the on/off switch, the moment of truth π¬
π HINTS CONFIGURATION π
on a device.hints(5) based system (think MIPS, bestie), these values are configurable for pwmc:
hint.pwmc.%d.atβ Thepwmbusinstance thepwmcinstance is attached to. πhint.pwmc.%d.channelβ The hardware channel number the instance is attached to. Channel numbers count up from zero. 0οΈβ£1οΈβ£2οΈβ£hint.pwmc.%d.labelβ If this optional hint is set, the driver creates an alias in/dev/pwmwith the given name, which points to the instance. π·οΈ cute nickname moment
π§ FDT CONFIGURATION π§
on an fdt(4) based system, a pwmc device is described with a child node of the pwm hardware controller node. and here's a lil shortcut: when the hardware supports multiple channels within the controller, you do not need to include a pwmc child node for every channel the hardware supports. Define only the channels you need to control. efficiency queen π
the following properties are required for a pwmc device node:
compatibleβ Must be the string"freebsd,pwmc". no typos, bestie, it's exact πregβ The hardware channel number.
the following properties are optional for the pwmc device node:
labelβ A string containing only characters legal in a file name. The driver creates an alias with the given name in/dev/pwmwhich points to the instance's/dev/pwm/pwmcX.Ydevice entry. πΈ
β Example of a PWM hardware node containing one pwmc child node β
here's what it looks like in the wild, so you can copy the vibe:
&ehrpwm0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&ehrpwm0_AB_pins>;
pwmcontrol@0 {
compatible = "freebsd,pwmc";
reg = <0>;
label = "backlight";
};
};
see how the label is "backlight"? that's the named-channel glow-up in action β¨
π FILES π
/dev/pwm/pwmc*β where all the magic happens πͺ
π SEE ALSO π
go read these next, they're the whole friend group:
π HISTORY π
The pwmc driver appeared in FreeBSD 13.0. a legend was born π
π reminder bestie: shared resources mean shared consequences. if you're on multi-channel hardware with a common clock, changing one channel can mess with the others. that's not a vibe, that's a warning. check your hardware driver docs.
and that's the whole page, you're officially pwmc-pilled π§ β¨ this beauty came to us from the Debian corner of the world, dated June 17, 2019, and it's the PWMC(4) page, periodt π
π«Ά mwah, go modulate some pulses responsibly ππ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2019 Ian Lepore <ian@freebsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms