drivers/pwm/pwm-rockchip.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-rockchip.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-rockchip.c- Extension
.c- Size
- 9646 bytes
- Lines
- 403
- Domain
- Driver Families
- Bucket
- drivers/pwm
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/io.hlinux/limits.hlinux/math64.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/property.hlinux/pwm.hlinux/time.h
Detected Declarations
struct rockchip_pwm_chipstruct rockchip_pwm_regsstruct rockchip_pwm_datafunction rockchip_pwm_get_statefunction rockchip_pwm_configfunction rockchip_pwm_enablefunction rockchip_pwm_applyfunction rockchip_pwm_probefunction rockchip_pwm_remove
Annotated Snippet
struct rockchip_pwm_chip {
struct clk *clk;
struct clk *pclk;
const struct rockchip_pwm_data *data;
void __iomem *base;
};
struct rockchip_pwm_regs {
unsigned long duty;
unsigned long period;
unsigned long cntr;
unsigned long ctrl;
};
struct rockchip_pwm_data {
struct rockchip_pwm_regs regs;
unsigned int prescaler;
bool supports_polarity;
bool supports_lock;
u32 enable_conf;
};
static inline struct rockchip_pwm_chip *to_rockchip_pwm_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int rockchip_pwm_get_state(struct pwm_chip *chip,
struct pwm_device *pwm,
struct pwm_state *state)
{
struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
u64 prescaled_ns = (u64)pc->data->prescaler * NSEC_PER_SEC;
u32 enable_conf = pc->data->enable_conf;
unsigned long clk_rate;
u64 tmp;
u32 val;
int ret;
ret = clk_enable(pc->pclk);
if (ret)
return ret;
ret = clk_enable(pc->clk);
if (ret)
return ret;
clk_rate = clk_get_rate(pc->clk);
tmp = readl_relaxed(pc->base + pc->data->regs.period);
tmp *= prescaled_ns;
state->period = DIV_U64_ROUND_UP(tmp, clk_rate);
tmp = readl_relaxed(pc->base + pc->data->regs.duty);
tmp *= prescaled_ns;
state->duty_cycle = DIV_U64_ROUND_UP(tmp, clk_rate);
val = readl_relaxed(pc->base + pc->data->regs.ctrl);
state->enabled = (val & enable_conf) == enable_conf;
if (pc->data->supports_polarity && !(val & PWM_DUTY_POSITIVE))
state->polarity = PWM_POLARITY_INVERSED;
else
state->polarity = PWM_POLARITY_NORMAL;
clk_disable(pc->clk);
clk_disable(pc->pclk);
return 0;
}
static void rockchip_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
u64 prescaled_ns = (u64)pc->data->prescaler * NSEC_PER_SEC;
u64 clk_rate, tmp;
u32 period_ticks, duty_ticks;
u32 ctrl;
clk_rate = clk_get_rate(pc->clk);
/*
* Since period and duty cycle registers have a width of 32
* bits, every possible input period can be obtained using the
* default prescaler value for all practical clock rate values.
*/
tmp = mul_u64_u64_div_u64(clk_rate, state->period, prescaled_ns);
if (tmp > U32_MAX)
tmp = U32_MAX;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/io.h`, `linux/limits.h`, `linux/math64.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct rockchip_pwm_chip`, `struct rockchip_pwm_regs`, `struct rockchip_pwm_data`, `function rockchip_pwm_get_state`, `function rockchip_pwm_config`, `function rockchip_pwm_enable`, `function rockchip_pwm_apply`, `function rockchip_pwm_probe`, `function rockchip_pwm_remove`.
- Atlas domain: Driver Families / drivers/pwm.
- 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.