drivers/pwm/pwm-atmel-hlcdc.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-atmel-hlcdc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-atmel-hlcdc.c- Extension
.c- Size
- 7666 bytes
- Lines
- 310
- 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/delay.hlinux/mfd/atmel-hlcdc.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pwm.hlinux/regmap.h
Detected Declarations
struct atmel_hlcdc_pwm_erratastruct atmel_hlcdc_pwmfunction atmel_hlcdc_pwm_applyfunction atmel_hlcdc_pwm_suspendfunction atmel_hlcdc_pwm_resumefunction atmel_hlcdc_pwm_probefunction atmel_hlcdc_pwm_remove
Annotated Snippet
struct atmel_hlcdc_pwm_errata {
bool slow_clk_erratum;
bool div1_clk_erratum;
};
struct atmel_hlcdc_pwm {
struct atmel_hlcdc *hlcdc;
struct clk *cur_clk;
const struct atmel_hlcdc_pwm_errata *errata;
};
static inline struct atmel_hlcdc_pwm *to_atmel_hlcdc_pwm(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int atmel_hlcdc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
struct atmel_hlcdc *hlcdc = atmel->hlcdc;
unsigned int status;
int ret;
if (state->enabled) {
struct clk *new_clk = hlcdc->slow_clk;
u64 pwmcval = state->duty_cycle * 256;
unsigned long clk_freq;
u64 clk_period_ns;
u32 pwmcfg;
int pres;
if (!atmel->errata || !atmel->errata->slow_clk_erratum) {
clk_freq = clk_get_rate(new_clk);
if (!clk_freq)
return -EINVAL;
clk_period_ns = (u64)NSEC_PER_SEC * 256;
do_div(clk_period_ns, clk_freq);
}
/* Errata: cannot use slow clk on some IP revisions */
if ((atmel->errata && atmel->errata->slow_clk_erratum) ||
clk_period_ns > state->period) {
new_clk = hlcdc->sys_clk;
clk_freq = clk_get_rate(new_clk);
if (!clk_freq)
return -EINVAL;
clk_period_ns = (u64)NSEC_PER_SEC * 256;
do_div(clk_period_ns, clk_freq);
}
for (pres = 0; pres <= ATMEL_HLCDC_PWMPS_MAX; pres++) {
/* Errata: cannot divide by 1 on some IP revisions */
if (!pres && atmel->errata &&
atmel->errata->div1_clk_erratum)
continue;
if ((clk_period_ns << pres) >= state->period)
break;
}
if (pres > ATMEL_HLCDC_PWMPS_MAX)
return -EINVAL;
pwmcfg = ATMEL_HLCDC_PWMPS(pres);
if (new_clk != atmel->cur_clk) {
u32 gencfg = 0;
int ret;
ret = clk_prepare_enable(new_clk);
if (ret)
return ret;
clk_disable_unprepare(atmel->cur_clk);
atmel->cur_clk = new_clk;
if (new_clk == hlcdc->sys_clk)
gencfg = ATMEL_HLCDC_CLKPWMSEL;
ret = regmap_update_bits(hlcdc->regmap,
ATMEL_HLCDC_CFG(0),
ATMEL_HLCDC_CLKPWMSEL,
gencfg);
if (ret)
return ret;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/mfd/atmel-hlcdc.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pwm.h`, `linux/regmap.h`.
- Detected declarations: `struct atmel_hlcdc_pwm_errata`, `struct atmel_hlcdc_pwm`, `function atmel_hlcdc_pwm_apply`, `function atmel_hlcdc_pwm_suspend`, `function atmel_hlcdc_pwm_resume`, `function atmel_hlcdc_pwm_probe`, `function atmel_hlcdc_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.