drivers/pwm/pwm-lpss.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-lpss.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-lpss.c- Extension
.c- Size
- 7595 bytes
- Lines
- 294
- 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/bits.hlinux/delay.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/module.hlinux/pm_runtime.hlinux/pwm.hlinux/time.hpwm-lpss.h
Detected Declarations
function pwm_lpss_readfunction pwm_lpss_writefunction pwm_lpss_wait_for_updatefunction pwm_lpss_is_updatingfunction pwm_lpss_preparefunction pwm_lpss_cond_enablefunction pwm_lpss_prepare_enablefunction pwm_lpss_applyfunction pwm_lpss_get_stateexport pwm_lpss_byt_infoexport pwm_lpss_bsw_infoexport pwm_lpss_bxt_infoexport pwm_lpss_tng_infoexport devm_pwm_lpss_probe
Annotated Snippet
if (!pwm_is_enabled(pwm)) {
pm_runtime_get_sync(pwmchip_parent(chip));
ret = pwm_lpss_prepare_enable(lpwm, pwm, state);
if (ret)
pm_runtime_put(pwmchip_parent(chip));
} else {
ret = pwm_lpss_prepare_enable(lpwm, pwm, state);
}
} else if (pwm_is_enabled(pwm)) {
pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE);
pm_runtime_put(pwmchip_parent(chip));
}
return ret;
}
static int pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_state *state)
{
struct pwm_lpss_chip *lpwm = to_lpwm(chip);
unsigned long base_unit_range;
unsigned long long base_unit, freq, on_time_div;
u32 ctrl;
pm_runtime_get_sync(pwmchip_parent(chip));
base_unit_range = BIT(lpwm->info->base_unit_bits);
ctrl = pwm_lpss_read(pwm);
on_time_div = 255 - (ctrl & PWM_ON_TIME_DIV_MASK);
base_unit = (ctrl >> PWM_BASE_UNIT_SHIFT) & (base_unit_range - 1);
freq = base_unit * lpwm->info->clk_rate;
do_div(freq, base_unit_range);
if (freq == 0)
state->period = NSEC_PER_SEC;
else
state->period = NSEC_PER_SEC / (unsigned long)freq;
on_time_div *= state->period;
do_div(on_time_div, 255);
state->duty_cycle = on_time_div;
state->polarity = PWM_POLARITY_NORMAL;
state->enabled = !!(ctrl & PWM_ENABLE);
pm_runtime_put(pwmchip_parent(chip));
return 0;
}
static const struct pwm_ops pwm_lpss_ops = {
.apply = pwm_lpss_apply,
.get_state = pwm_lpss_get_state,
};
struct pwm_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base,
const struct pwm_lpss_boardinfo *info)
{
struct pwm_lpss_chip *lpwm;
struct pwm_chip *chip;
unsigned long c;
int i, ret;
u32 ctrl;
if (WARN_ON(info->npwm > LPSS_MAX_PWMS))
return ERR_PTR(-ENODEV);
chip = devm_pwmchip_alloc(dev, info->npwm, sizeof(*lpwm));
if (IS_ERR(chip))
return chip;
lpwm = to_lpwm(chip);
lpwm->regs = base;
lpwm->info = info;
c = lpwm->info->clk_rate;
if (!c)
return ERR_PTR(-EINVAL);
chip->ops = &pwm_lpss_ops;
ret = devm_pwmchip_add(dev, chip);
if (ret) {
dev_err(dev, "failed to add PWM chip: %d\n", ret);
return ERR_PTR(ret);
}
for (i = 0; i < lpwm->info->npwm; i++) {
ctrl = pwm_lpss_read(&chip->pwms[i]);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/delay.h`, `linux/io.h`, `linux/iopoll.h`, `linux/kernel.h`, `linux/module.h`, `linux/pm_runtime.h`, `linux/pwm.h`.
- Detected declarations: `function pwm_lpss_read`, `function pwm_lpss_write`, `function pwm_lpss_wait_for_update`, `function pwm_lpss_is_updating`, `function pwm_lpss_prepare`, `function pwm_lpss_cond_enable`, `function pwm_lpss_prepare_enable`, `function pwm_lpss_apply`, `function pwm_lpss_get_state`, `export pwm_lpss_byt_info`.
- 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.