drivers/pwm/pwm-atmel-tcb.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-atmel-tcb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-atmel-tcb.c- Extension
.c- Size
- 15050 bytes
- Lines
- 567
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/init.hlinux/clocksource.hlinux/clockchips.hlinux/interrupt.hlinux/irq.hlinux/clk.hlinux/err.hlinux/ioport.hlinux/io.hlinux/mfd/syscon.hlinux/platform_device.hlinux/pwm.hlinux/of.hlinux/regmap.hlinux/slab.hsoc/at91/atmel_tcb.h
Detected Declarations
struct atmel_tcb_pwm_devicestruct atmel_tcb_channelstruct atmel_tcb_pwm_chipfunction atmel_tcb_pwm_requestfunction atmel_tcb_pwm_freefunction atmel_tcb_pwm_disablefunction atmel_tcb_pwm_enablefunction atmel_tcb_pwm_configfunction clockfunction atmel_tcb_pwm_applyfunction atmel_tcb_pwm_probefunction atmel_tcb_pwm_removefunction atmel_tcb_pwm_suspendfunction atmel_tcb_pwm_resume
Annotated Snippet
struct atmel_tcb_pwm_device {
unsigned div; /* PWM clock divider */
unsigned duty; /* PWM duty expressed in clk cycles */
unsigned period; /* PWM period expressed in clk cycles */
};
struct atmel_tcb_channel {
u32 enabled;
u32 cmr;
u32 ra;
u32 rb;
u32 rc;
};
struct atmel_tcb_pwm_chip {
spinlock_t lock;
u8 channel;
u8 width;
unsigned long rate;
unsigned long slow_rate;
struct regmap *regmap;
struct clk *clk;
struct clk *gclk;
struct clk *slow_clk;
struct atmel_tcb_pwm_device pwms[NPWM];
struct atmel_tcb_channel bkup;
};
static const u8 atmel_tcb_divisors[] = { 2, 8, 32, 128, 0, };
static inline struct atmel_tcb_pwm_chip *to_tcb_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int atmel_tcb_pwm_request(struct pwm_chip *chip,
struct pwm_device *pwm)
{
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
unsigned cmr;
int ret;
ret = clk_prepare_enable(tcbpwmc->clk);
if (ret)
return ret;
tcbpwm->duty = 0;
tcbpwm->period = 0;
tcbpwm->div = 0;
guard(spinlock)(&tcbpwmc->lock);
regmap_read(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), &cmr);
/*
* Get init config from Timer Counter registers if
* Timer Counter is already configured as a PWM generator.
*/
if (cmr & ATMEL_TC_WAVE) {
if (pwm->hwpwm == 0)
regmap_read(tcbpwmc->regmap,
ATMEL_TC_REG(tcbpwmc->channel, RA),
&tcbpwm->duty);
else
regmap_read(tcbpwmc->regmap,
ATMEL_TC_REG(tcbpwmc->channel, RB),
&tcbpwm->duty);
tcbpwm->div = cmr & ATMEL_TC_TCCLKS;
regmap_read(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, RC),
&tcbpwm->period);
cmr &= (ATMEL_TC_TCCLKS | ATMEL_TC_ACMR_MASK |
ATMEL_TC_BCMR_MASK);
} else
cmr = 0;
cmr |= ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO | ATMEL_TC_EEVT_XC0;
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr);
return 0;
}
static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
clk_disable_unprepare(tcbpwmc->clk);
}
static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm,
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/clocksource.h`, `linux/clockchips.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/clk.h`, `linux/err.h`.
- Detected declarations: `struct atmel_tcb_pwm_device`, `struct atmel_tcb_channel`, `struct atmel_tcb_pwm_chip`, `function atmel_tcb_pwm_request`, `function atmel_tcb_pwm_free`, `function atmel_tcb_pwm_disable`, `function atmel_tcb_pwm_enable`, `function atmel_tcb_pwm_config`, `function clock`, `function atmel_tcb_pwm_apply`.
- Atlas domain: Driver Families / drivers/pwm.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.