drivers/pmdomain/sunxi/sun20i-ppu.c
Source file repositories/reference/linux-study-clean/drivers/pmdomain/sunxi/sun20i-ppu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pmdomain/sunxi/sun20i-ppu.c- Extension
.c- Size
- 5747 bytes
- Lines
- 240
- Domain
- Driver Families
- Bucket
- drivers/pmdomain
- 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/bitfield.hlinux/clk.hlinux/io.hlinux/iopoll.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm_domain.hlinux/reset.h
Detected Declarations
struct sun20i_ppu_descstruct sun20i_ppu_pdfunction sun20i_ppu_pd_is_onfunction sun20i_ppu_pd_set_powerfunction sun20i_ppu_pd_power_onfunction sun20i_ppu_pd_power_offfunction sun20i_ppu_probe
Annotated Snippet
struct sun20i_ppu_desc {
const char *const *names;
unsigned int num_domains;
};
struct sun20i_ppu_pd {
struct generic_pm_domain genpd;
void __iomem *base;
};
#define to_sun20i_ppu_pd(_genpd) \
container_of(_genpd, struct sun20i_ppu_pd, genpd)
static bool sun20i_ppu_pd_is_on(const struct sun20i_ppu_pd *pd)
{
u32 status = readl(pd->base + PD_STATUS_REG);
return FIELD_GET(PD_STATUS_STATE, status) == PD_STATE_ON;
}
static int sun20i_ppu_pd_set_power(const struct sun20i_ppu_pd *pd, bool power_on)
{
u32 state, status;
int ret;
if (sun20i_ppu_pd_is_on(pd) == power_on)
return 0;
/* Wait for the power controller to be idle. */
ret = readl_poll_timeout(pd->base + PD_STATUS_REG, status,
!(status & PD_STATUS_BUSY), 100, 1000);
if (ret)
return ret;
state = power_on ? PD_STATE_ON : PD_STATE_OFF;
writel(state, pd->base + PD_COMMAND_REG);
/* Wait for the state transition to complete. */
ret = readl_poll_timeout(pd->base + PD_STATUS_REG, status,
FIELD_GET(PD_STATUS_STATE, status) == state &&
(status & PD_STATUS_COMPLETE), 100, 1000);
if (ret)
return ret;
/* Clear the completion flag. */
writel(status, pd->base + PD_STATUS_REG);
return 0;
}
static int sun20i_ppu_pd_power_on(struct generic_pm_domain *genpd)
{
const struct sun20i_ppu_pd *pd = to_sun20i_ppu_pd(genpd);
return sun20i_ppu_pd_set_power(pd, true);
}
static int sun20i_ppu_pd_power_off(struct generic_pm_domain *genpd)
{
const struct sun20i_ppu_pd *pd = to_sun20i_ppu_pd(genpd);
return sun20i_ppu_pd_set_power(pd, false);
}
static int sun20i_ppu_probe(struct platform_device *pdev)
{
const struct sun20i_ppu_desc *desc;
struct device *dev = &pdev->dev;
struct genpd_onecell_data *ppu;
struct sun20i_ppu_pd *pds;
struct reset_control *rst;
void __iomem *base;
struct clk *clk;
int ret;
desc = of_device_get_match_data(dev);
if (!desc)
return -EINVAL;
pds = devm_kcalloc(dev, desc->num_domains, sizeof(*pds), GFP_KERNEL);
if (!pds)
return -ENOMEM;
ppu = devm_kzalloc(dev, sizeof(*ppu), GFP_KERNEL);
if (!ppu)
return -ENOMEM;
ppu->domains = devm_kcalloc(dev, desc->num_domains,
sizeof(*ppu->domains), GFP_KERNEL);
if (!ppu->domains)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/io.h`, `linux/iopoll.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pm_domain.h`.
- Detected declarations: `struct sun20i_ppu_desc`, `struct sun20i_ppu_pd`, `function sun20i_ppu_pd_is_on`, `function sun20i_ppu_pd_set_power`, `function sun20i_ppu_pd_power_on`, `function sun20i_ppu_pd_power_off`, `function sun20i_ppu_probe`.
- Atlas domain: Driver Families / drivers/pmdomain.
- 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.