REGULATOR(9)
Hey bestie! π Welcome to REGULATOR(9) β that's the Kernel Developer's Manual page for the regulator framework. It's giving power management main character energy, and honestly? You're gonna slay this. Let me walk you through it. π
β¨ NAME β¨
Okay so this page covers the whole regulator squad: regulator, regulator_get_by_name, regulator_get_by_id, regulator_release, regulator_get_name, regulator_enable, regulator_disable, regulator_stop, regulator_status, regulator_get_voltage, regulator_set_voltage, regulator_check_voltage, regulator_get_by_ofw_property β and these are literally the regulator methods. The whole crew. No cap. π
π« SYNOPSIS π«
Bestie, here's the receipts. You need device regulator and this include:
device regulator
#include <dev/extres/regulator/regulator.h>
And here are all the function signatures, exactly as they appear:
int
regulator_get_by_name(device_t cdev, const char *name,
regulator_t *regulator);
int
regulator_get_by_id(device_t cdev, device_t pdev, intptr_t id,
regulator_t *regulator);
int
regulator_release(regulator_t regulator);
int
regulator_get_name(regulator_t regulator);
int
regulator_enable(regulator_t reg);
int
regulator_disable(regulator_t reg);
int
regulator_stop(regulator_t reg);
int
regulator_status(regulator_t reg, int *status);
int
regulator_get_voltage(regulator_t reg, int *uvolt);
int
regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt);
int
regulator_check_voltage(regulator_t reg, int uvolt);
int
regulator_get_by_ofw_property(device_t dev, phandle_t node, char *name,
regulator_t *reg);
πΈ DESCRIPTION πΈ
The regulator framework is lowkey the GOAT: it lets drivers enable, disable, and change regulator voltage. It's the whole vibe for power management. β‘β¨
π«Ά RETURN VALUES π«Ά
Okay so here's the tea: all these functions return 0 on success β or ENODEV if the regulator (or one of its parents) was not found. That's the standard return drama. Don't forget it. π
β¨ INTERFACE β¨
Alright bestie, let's go function by function. Every detail is about to be served, periodt.
regulator_get_by_name(device_t cdev, const char *name, regulator_t *regulator)β Resolve a regulator based on its name. All regulator names are unique (slay for no duplicates π). This will also increment the refcount on the regulator β so heads up, you're holding a reference. πregulator_get_by_id(device_t cdev, device_t pdev, intptr_t id, regulator_t *regulator)β Resolve a regulator based on its id. All regulator ids are unique, too. This will also increment the refcount on the regulator. Same energy as above. π₯regulator_get_by_ofw_property(device_t dev, phandle_t node, char *name, regulator_t *reg)β Resolve a regulator based on the fdt property named name. If node is0, then the function will get the ofw node itself. This will also increment the refcount on the regulator. It returns0on success orENOENTif the ofw property does not exist. So if it's missing, that's aENOENTmoment. πregulator_release(regulator_t regulator)β This disables the regulator, decrements the refcount on it, and frees the regulator variable passed. So like, it's the cleanup era. You're done with it, and it's done with you. π¦regulator_get_name(regulator_t regulator)β Returns the name of the regulator. All regulator names are unique. Literally every single one. πregulator_enable(regulator_t reg)β Enable the regulator. If the regulator supports a voltage range, the one configured in the hardware will be the output voltage. If the regulator was already enabled by another driver, this simply increments the enable counter. So no drama β just counting vibes. βregulator_disable(regulator_t reg)β Disable the regulator. If the regulator was also enabled by another driver, this simply decrements the enable counter. But bestie, listen: if the regulator was not previously enabled, we willkassert. And a kassert is not a vibe β it's a kernel assertion failure. So don't do that. ππregulator_stop(regulator_t reg)β Disable the regulator in hardware. This ensures the regulator is disabled even if it was enabled by the bootloader. This should not be called on a regulator that has previously been enabled by a driver. So pay attention. π Returns0on success orEBUSYif another consumer enabled it.regulator_status(regulator_t reg, int *status)β Get the hardware status of the regulator. status will contain a bit mask with these possible values:REGULATOR_STATUS_ENABLEDβ The regulator is enabled. βREGULATOR_STATUS_OVERCURRENTβ The hardware reports that too much current is being drawn. π¨
regulator_get_voltage(regulator_t reg, int *uvolt)β Get the current voltage set for the regulator in microvolts. Microvolts, bestie. Tiny units. π§regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt)β Change the voltage for the regulator. If a range is acceptable by the hardware or driver, different values can be provided as min and max. Returns0on success orERANGEif the regulator doesn't support this voltage range. So if it's out of range, that's anERANGEsituation. πregulator_check_voltage(regulator_t reg, int uvolt)β Checks if the regulator supports the given voltage. Returns0on success orERANGEif the regulator doesn't support this voltage range. Just a little vibe check before you commit. β¨
π HISTORY π
The regulator framework first appeared in FreeBSD 12.0. The regulator framework was written by Michal Meloun <mmel@FreeBSD.org>. The regulator manual page was written by Emmanuel Vadot <manu@FreeBSD.org>. Shoutout to them for the lore. π
This page was brought to you by the Debian squad, dated June 14, 2021. REGULATOR(9) out! ππ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2021 Emmanuel Vadot <manu@freebsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms