drivers/pwm/pwm-samsung.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-samsung.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-samsung.c- Extension
.c- Size
- 17795 bytes
- Lines
- 649
- 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/bitops.hlinux/clk.hlinux/export.hlinux/err.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pwm.hlinux/slab.hlinux/spinlock.hlinux/time.hclocksource/samsung_pwm.h
Detected Declarations
struct samsung_pwm_channelstruct samsung_pwm_chipfunction to_tcon_channelfunction __pwm_samsung_manual_updatefunction pwm_samsung_set_divisorfunction pwm_samsung_is_tdivfunction pwm_samsung_get_tin_ratefunction pwm_samsung_calc_tinfunction pwm_samsung_requestfunction pwm_samsung_enablefunction pwm_samsung_disablefunction pwm_samsung_manual_updatefunction __pwm_samsung_configfunction updatefunction pwm_samsung_configfunction pwm_samsung_set_invertfunction pwm_samsung_set_polarityfunction pwm_samsung_applyfunction pwm_samsung_parse_dtfunction of_property_for_each_u32function pwm_samsung_parse_dtfunction pwm_samsung_probefunction pwm_samsung_resume
Annotated Snippet
struct samsung_pwm_channel {
u32 period_ns;
u32 duty_ns;
u32 tin_ns;
};
/**
* struct samsung_pwm_chip - private data of PWM chip
* @variant: local copy of hardware variant data
* @inverter_mask: inverter status for all channels - one bit per channel
* @disabled_mask: disabled status for all channels - one bit per channel
* @base: base address of mapped PWM registers
* @base_clk: base clock used to drive the timers
* @tclk0: external clock 0 (can be ERR_PTR if not present)
* @tclk1: external clock 1 (can be ERR_PTR if not present)
* @channel: per channel driver data
*/
struct samsung_pwm_chip {
struct samsung_pwm_variant variant;
u8 inverter_mask;
u8 disabled_mask;
void __iomem *base;
struct clk *base_clk;
struct clk *tclk0;
struct clk *tclk1;
struct samsung_pwm_channel channel[SAMSUNG_PWM_NUM];
};
#ifndef CONFIG_CLKSRC_SAMSUNG_PWM
/*
* PWM block is shared between pwm-samsung and samsung_pwm_timer drivers
* and some registers need access synchronization. If both drivers are
* compiled in, the spinlock is defined in the clocksource driver,
* otherwise following definition is used.
*
* Currently we do not need any more complex synchronization method
* because all the supported SoCs contain only one instance of the PWM
* IP. Should this change, both drivers will need to be modified to
* properly synchronize accesses to particular instances.
*/
static DEFINE_SPINLOCK(samsung_pwm_lock);
#endif
static inline
struct samsung_pwm_chip *to_samsung_pwm_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static inline unsigned int to_tcon_channel(unsigned int channel)
{
/* TCON register has a gap of 4 bits (1 channel) after channel 0 */
return (channel == 0) ? 0 : (channel + 1);
}
static void __pwm_samsung_manual_update(struct samsung_pwm_chip *our_chip,
struct pwm_device *pwm)
{
unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm);
u32 tcon;
tcon = readl(our_chip->base + REG_TCON);
tcon |= TCON_MANUALUPDATE(tcon_chan);
writel(tcon, our_chip->base + REG_TCON);
tcon &= ~TCON_MANUALUPDATE(tcon_chan);
writel(tcon, our_chip->base + REG_TCON);
}
static void pwm_samsung_set_divisor(struct samsung_pwm_chip *our_chip,
unsigned int channel, u8 divisor)
{
u8 shift = TCFG1_SHIFT(channel);
unsigned long flags;
u32 reg;
u8 bits;
bits = (fls(divisor) - 1) - our_chip->variant.div_base;
spin_lock_irqsave(&samsung_pwm_lock, flags);
reg = readl(our_chip->base + REG_TCFG1);
reg &= ~(TCFG1_MUX_MASK << shift);
reg |= bits << shift;
writel(reg, our_chip->base + REG_TCFG1);
spin_unlock_irqrestore(&samsung_pwm_lock, flags);
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/clk.h`, `linux/export.h`, `linux/err.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct samsung_pwm_channel`, `struct samsung_pwm_chip`, `function to_tcon_channel`, `function __pwm_samsung_manual_update`, `function pwm_samsung_set_divisor`, `function pwm_samsung_is_tdiv`, `function pwm_samsung_get_tin_rate`, `function pwm_samsung_calc_tin`, `function pwm_samsung_request`, `function pwm_samsung_enable`.
- 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.