drivers/pwm/pwm-clps711x.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-clps711x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-clps711x.c- Extension
.c- Size
- 2584 bytes
- Lines
- 111
- 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/module.hlinux/of.hlinux/platform_device.hlinux/pwm.h
Detected Declarations
struct clps711x_chipfunction clps711x_pwm_requestfunction clps711x_pwm_applyfunction clps711x_pwm_probe
Annotated Snippet
struct clps711x_chip {
void __iomem *pmpcon;
struct clk *clk;
};
static inline struct clps711x_chip *to_clps711x_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct clps711x_chip *priv = to_clps711x_chip(chip);
unsigned int freq = clk_get_rate(priv->clk);
if (!freq)
return -EINVAL;
/* Store constant period value */
pwm->args.period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq);
return 0;
}
static int clps711x_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
struct clps711x_chip *priv = to_clps711x_chip(chip);
/* PWM0 - bits 4..7, PWM1 - bits 8..11 */
u32 shift = (pwm->hwpwm + 1) * 4;
u32 pmpcon, val;
if (state->polarity != PWM_POLARITY_NORMAL)
return -EINVAL;
if (state->period != pwm->args.period)
return -EINVAL;
if (state->enabled)
val = mul_u64_u64_div_u64(state->duty_cycle, 0xf, state->period);
else
val = 0;
pmpcon = readl(priv->pmpcon);
pmpcon &= ~(0xf << shift);
pmpcon |= val << shift;
writel(pmpcon, priv->pmpcon);
return 0;
}
static const struct pwm_ops clps711x_pwm_ops = {
.request = clps711x_pwm_request,
.apply = clps711x_pwm_apply,
};
static int clps711x_pwm_probe(struct platform_device *pdev)
{
struct pwm_chip *chip;
struct clps711x_chip *priv;
chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*priv));
if (IS_ERR(chip))
return PTR_ERR(chip);
priv = to_clps711x_chip(chip);
priv->pmpcon = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(priv->pmpcon))
return PTR_ERR(priv->pmpcon);
priv->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(priv->clk))
return PTR_ERR(priv->clk);
chip->ops = &clps711x_pwm_ops;
return devm_pwmchip_add(&pdev->dev, chip);
}
static const struct of_device_id clps711x_pwm_dt_ids[] = {
{ .compatible = "cirrus,ep7209-pwm", },
{ }
};
MODULE_DEVICE_TABLE(of, clps711x_pwm_dt_ids);
static struct platform_driver clps711x_pwm_driver = {
.driver = {
.name = "clps711x-pwm",
.of_match_table = clps711x_pwm_dt_ids,
},
Annotation
- Immediate include surface: `linux/clk.h`, `linux/io.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pwm.h`.
- Detected declarations: `struct clps711x_chip`, `function clps711x_pwm_request`, `function clps711x_pwm_apply`, `function clps711x_pwm_probe`.
- 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.