drivers/pwm/pwm-atmel.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-atmel.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-atmel.c- Extension
.c- Size
- 13589 bytes
- Lines
- 544
- 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/err.hlinux/io.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pwm.hlinux/slab.h
Detected Declarations
struct atmel_pwm_registersstruct atmel_pwm_configstruct atmel_pwm_datastruct atmel_pwm_chipfunction atmel_pwm_readlfunction atmel_pwm_writelfunction atmel_pwm_ch_readlfunction atmel_pwm_ch_writelfunction atmel_pwm_update_pendingfunction atmel_pwm_set_pendingfunction atmel_pwm_test_pendingfunction atmel_pwm_wait_nonpendingfunction atmel_pwm_calculate_cprd_and_presfunction atmel_pwm_calculate_cdtyfunction atmel_pwm_update_cdtyfunction atmel_pwm_set_cprd_cdtyfunction atmel_pwm_disablefunction atmel_pwm_applyfunction atmel_pwm_get_statefunction atmel_pwm_enable_clk_if_onfunction atmel_pwm_probe
Annotated Snippet
struct atmel_pwm_registers {
u8 period;
u8 period_upd;
u8 duty;
u8 duty_upd;
};
struct atmel_pwm_config {
u32 period_bits;
};
struct atmel_pwm_data {
struct atmel_pwm_registers regs;
struct atmel_pwm_config cfg;
};
struct atmel_pwm_chip {
struct clk *clk;
void __iomem *base;
const struct atmel_pwm_data *data;
/*
* The hardware supports a mechanism to update a channel's duty cycle at
* the end of the currently running period. When such an update is
* pending we delay disabling the PWM until the new configuration is
* active because otherwise pmw_config(duty_cycle=0); pwm_disable();
* might not result in an inactive output.
* This bitmask tracks for which channels an update is pending in
* hardware.
*/
u32 update_pending;
};
static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static inline u32 atmel_pwm_readl(struct atmel_pwm_chip *chip,
unsigned long offset)
{
return readl_relaxed(chip->base + offset);
}
static inline void atmel_pwm_writel(struct atmel_pwm_chip *chip,
unsigned long offset, unsigned long val)
{
writel_relaxed(val, chip->base + offset);
}
static inline u32 atmel_pwm_ch_readl(struct atmel_pwm_chip *chip,
unsigned int ch, unsigned long offset)
{
unsigned long base = PWM_CH_REG_OFFSET + ch * PWM_CH_REG_SIZE;
return atmel_pwm_readl(chip, base + offset);
}
static inline void atmel_pwm_ch_writel(struct atmel_pwm_chip *chip,
unsigned int ch, unsigned long offset,
unsigned long val)
{
unsigned long base = PWM_CH_REG_OFFSET + ch * PWM_CH_REG_SIZE;
atmel_pwm_writel(chip, base + offset, val);
}
static void atmel_pwm_update_pending(struct atmel_pwm_chip *chip)
{
/*
* Each channel that has its bit in ISR set started a new period since
* ISR was cleared and so there is no more update pending. Note that
* reading ISR clears it, so this needs to handle all channels to not
* loose information.
*/
u32 isr = atmel_pwm_readl(chip, PWM_ISR);
chip->update_pending &= ~isr;
}
static void atmel_pwm_set_pending(struct atmel_pwm_chip *chip, unsigned int ch)
{
/*
* Clear pending flags in hardware because otherwise there might still
* be a stale flag in ISR.
*/
atmel_pwm_update_pending(chip);
chip->update_pending |= (1 << ch);
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/err.h`, `linux/io.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pwm.h`.
- Detected declarations: `struct atmel_pwm_registers`, `struct atmel_pwm_config`, `struct atmel_pwm_data`, `struct atmel_pwm_chip`, `function atmel_pwm_readl`, `function atmel_pwm_writel`, `function atmel_pwm_ch_readl`, `function atmel_pwm_ch_writel`, `function atmel_pwm_update_pending`, `function atmel_pwm_set_pending`.
- 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.