drivers/pwm/pwm-dwc-core.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-dwc-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-dwc-core.c- Extension
.c- Size
- 4673 bytes
- Lines
- 184
- Domain
- Driver Families
- Bucket
- drivers/pwm
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/export.hlinux/kernel.hlinux/module.hlinux/pci.hlinux/pm_runtime.hlinux/pwm.hpwm-dwc.h
Detected Declarations
function Copyrightfunction __dwc_pwm_configure_timerfunction dwc_pwm_applyfunction dwc_pwm_get_stateexport dwc_pwm_alloc
Annotated Snippet
if (pwm->state.enabled) {
__dwc_pwm_set_enable(dwc, pwm->hwpwm, false);
pm_runtime_put_sync(pwmchip_parent(chip));
}
}
return 0;
}
static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_state *state)
{
struct dwc_pwm *dwc = to_dwc_pwm(chip);
u64 duty, period;
u32 ctrl, ld, ld2;
pm_runtime_get_sync(pwmchip_parent(chip));
ctrl = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm->hwpwm));
ld = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm));
ld2 = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(pwm->hwpwm));
state->enabled = !!(ctrl & DWC_TIM_CTRL_EN);
/*
* If we're not in PWM, technically the output is a 50-50
* based on the timer load-count only.
*/
if (ctrl & DWC_TIM_CTRL_PWM) {
duty = (ld + 1) * dwc->clk_ns;
period = (ld2 + 1) * dwc->clk_ns;
period += duty;
} else {
duty = (ld + 1) * dwc->clk_ns;
period = duty * 2;
}
state->polarity = PWM_POLARITY_INVERSED;
state->period = period;
state->duty_cycle = duty;
pm_runtime_put_sync(pwmchip_parent(chip));
return 0;
}
static const struct pwm_ops dwc_pwm_ops = {
.apply = dwc_pwm_apply,
.get_state = dwc_pwm_get_state,
};
struct pwm_chip *dwc_pwm_alloc(struct device *dev)
{
struct pwm_chip *chip;
struct dwc_pwm *dwc;
chip = devm_pwmchip_alloc(dev, DWC_TIMERS_TOTAL, sizeof(*dwc));
if (IS_ERR(chip))
return chip;
dwc = to_dwc_pwm(chip);
dwc->clk_ns = 10;
chip->ops = &dwc_pwm_ops;
return chip;
}
EXPORT_SYMBOL_GPL(dwc_pwm_alloc);
MODULE_AUTHOR("Felipe Balbi (Intel)");
MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@linux.intel.com>");
MODULE_AUTHOR("Raymond Tan <raymond.tan@intel.com>");
MODULE_DESCRIPTION("DesignWare PWM Controller");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/export.h`, `linux/kernel.h`, `linux/module.h`, `linux/pci.h`, `linux/pm_runtime.h`, `linux/pwm.h`, `pwm-dwc.h`.
- Detected declarations: `function Copyright`, `function __dwc_pwm_configure_timer`, `function dwc_pwm_apply`, `function dwc_pwm_get_state`, `export dwc_pwm_alloc`.
- Atlas domain: Driver Families / drivers/pwm.
- Implementation status: integration 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.