drivers/regulator/stm32-pwr.c
Source file repositories/reference/linux-study-clean/drivers/regulator/stm32-pwr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/stm32-pwr.c- Extension
.c- Size
- 4566 bytes
- Lines
- 186
- Domain
- Driver Families
- Bucket
- drivers/regulator
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/io.hlinux/iopoll.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
struct stm32_pwr_regfunction stm32_pwr_reg_is_readyfunction stm32_pwr_reg_is_enabledfunction stm32_pwr_reg_enablefunction stm32_pwr_reg_disablefunction stm32_pwr_regulator_probe
Annotated Snippet
struct stm32_pwr_reg {
void __iomem *base;
u32 ready_mask;
};
static int stm32_pwr_reg_is_ready(struct regulator_dev *rdev)
{
struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
u32 val;
val = readl_relaxed(priv->base + REG_PWR_CR3);
return (val & priv->ready_mask);
}
static int stm32_pwr_reg_is_enabled(struct regulator_dev *rdev)
{
struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
u32 val;
val = readl_relaxed(priv->base + REG_PWR_CR3);
return (val & rdev->desc->enable_mask);
}
static int stm32_pwr_reg_enable(struct regulator_dev *rdev)
{
struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
int ret;
u32 val;
val = readl_relaxed(priv->base + REG_PWR_CR3);
val |= rdev->desc->enable_mask;
writel_relaxed(val, priv->base + REG_PWR_CR3);
/* use an arbitrary timeout of 20ms */
ret = readx_poll_timeout(stm32_pwr_reg_is_ready, rdev, val, val,
100, 20 * 1000);
if (ret)
dev_err(&rdev->dev, "regulator enable timed out!\n");
return ret;
}
static int stm32_pwr_reg_disable(struct regulator_dev *rdev)
{
struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
int ret;
u32 val;
val = readl_relaxed(priv->base + REG_PWR_CR3);
val &= ~rdev->desc->enable_mask;
writel_relaxed(val, priv->base + REG_PWR_CR3);
/* use an arbitrary timeout of 20ms */
ret = readx_poll_timeout(stm32_pwr_reg_is_enabled, rdev, val, !val,
100, 20 * 1000);
if (ret)
dev_err(&rdev->dev, "regulator disable timed out!\n");
return ret;
}
static const struct regulator_ops stm32_pwr_reg_ops = {
.enable = stm32_pwr_reg_enable,
.disable = stm32_pwr_reg_disable,
.is_enabled = stm32_pwr_reg_is_enabled,
};
#define PWR_REG(_id, _name, _volt, _en, _supply) \
[_id] = { \
.id = _id, \
.name = _name, \
.of_match = of_match_ptr(_name), \
.n_voltages = 1, \
.type = REGULATOR_VOLTAGE, \
.fixed_uV = _volt, \
.ops = &stm32_pwr_reg_ops, \
.enable_mask = _en, \
.owner = THIS_MODULE, \
.supply_name = _supply, \
} \
static const struct regulator_desc stm32_pwr_desc[] = {
PWR_REG(PWR_REG11, "reg11", 1100000, REG_1_1_EN, "vdd"),
PWR_REG(PWR_REG18, "reg18", 1800000, REG_1_8_EN, "vdd"),
PWR_REG(PWR_USB33, "usb33", 3300000, USB_3_3_EN, "vdd_3v3_usbfs"),
};
static int stm32_pwr_regulator_probe(struct platform_device *pdev)
Annotation
- Immediate include surface: `linux/io.h`, `linux/iopoll.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regulator/driver.h`, `linux/regulator/of_regulator.h`.
- Detected declarations: `struct stm32_pwr_reg`, `function stm32_pwr_reg_is_ready`, `function stm32_pwr_reg_is_enabled`, `function stm32_pwr_reg_enable`, `function stm32_pwr_reg_disable`, `function stm32_pwr_regulator_probe`.
- Atlas domain: Driver Families / drivers/regulator.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.