drivers/pwm/pwm-rzg2l-gpt.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-rzg2l-gpt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-rzg2l-gpt.c- Extension
.c- Size
- 13734 bytes
- Lines
- 457
- 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/bitfield.hlinux/clk.hlinux/io.hlinux/limits.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pwm.hlinux/reset.hlinux/time.hlinux/units.h
Detected Declarations
struct rzg2l_gpt_chipfunction rzg2l_gpt_subchannelfunction rzg2l_gpt_siblingfunction rzg2l_gpt_writefunction rzg2l_gpt_readfunction rzg2l_gpt_modifyfunction rzg2l_gpt_calculate_prescalefunction rzg2l_gpt_requestfunction rzg2l_gpt_freefunction rzg2l_gpt_is_ch_enabledfunction rzg2l_gpt_enablefunction rzg2l_gpt_disablefunction rzg2l_gpt_calculate_period_or_dutyfunction rzg2l_gpt_get_statefunction rzg2l_gpt_calculate_pv_or_dcfunction rzg2l_gpt_configfunction rzg2l_gpt_applyfunction rzg2l_gpt_probe
Annotated Snippet
struct rzg2l_gpt_chip {
void __iomem *mmio;
struct mutex lock; /* lock to protect shared channel resources */
unsigned long rate_khz;
u32 period_ticks[RZG2L_MAX_HW_CHANNELS];
u32 channel_request_count[RZG2L_MAX_HW_CHANNELS];
u32 channel_enable_count[RZG2L_MAX_HW_CHANNELS];
};
static inline struct rzg2l_gpt_chip *to_rzg2l_gpt_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static inline unsigned int rzg2l_gpt_subchannel(unsigned int hwpwm)
{
return hwpwm & 0x1;
}
static inline unsigned int rzg2l_gpt_sibling(unsigned int hwpwm)
{
return hwpwm ^ 0x1;
}
static void rzg2l_gpt_write(struct rzg2l_gpt_chip *rzg2l_gpt, u32 reg, u32 data)
{
writel(data, rzg2l_gpt->mmio + reg);
}
static u32 rzg2l_gpt_read(struct rzg2l_gpt_chip *rzg2l_gpt, u32 reg)
{
return readl(rzg2l_gpt->mmio + reg);
}
static void rzg2l_gpt_modify(struct rzg2l_gpt_chip *rzg2l_gpt, u32 reg, u32 clr,
u32 set)
{
rzg2l_gpt_write(rzg2l_gpt, reg,
(rzg2l_gpt_read(rzg2l_gpt, reg) & ~clr) | set);
}
static u8 rzg2l_gpt_calculate_prescale(struct rzg2l_gpt_chip *rzg2l_gpt,
u64 period_ticks)
{
u32 prescaled_period_ticks;
u8 prescale;
prescaled_period_ticks = period_ticks >> 32;
if (prescaled_period_ticks >= 256)
prescale = 5;
else
prescale = (fls(prescaled_period_ticks) + 1) / 2;
return prescale;
}
static int rzg2l_gpt_request(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct rzg2l_gpt_chip *rzg2l_gpt = to_rzg2l_gpt_chip(chip);
u32 ch = RZG2L_GET_CH(pwm->hwpwm);
guard(mutex)(&rzg2l_gpt->lock);
rzg2l_gpt->channel_request_count[ch]++;
return 0;
}
static void rzg2l_gpt_free(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct rzg2l_gpt_chip *rzg2l_gpt = to_rzg2l_gpt_chip(chip);
u32 ch = RZG2L_GET_CH(pwm->hwpwm);
guard(mutex)(&rzg2l_gpt->lock);
rzg2l_gpt->channel_request_count[ch]--;
}
static bool rzg2l_gpt_is_ch_enabled(struct rzg2l_gpt_chip *rzg2l_gpt, u8 hwpwm)
{
u8 ch = RZG2L_GET_CH(hwpwm);
u32 val;
val = rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCR(ch));
if (!(val & RZG2L_GTCR_CST))
return false;
val = rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTIOR(ch));
return val & RZG2L_GTIOR_OxE(rzg2l_gpt_subchannel(hwpwm));
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/io.h`, `linux/limits.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pwm.h`.
- Detected declarations: `struct rzg2l_gpt_chip`, `function rzg2l_gpt_subchannel`, `function rzg2l_gpt_sibling`, `function rzg2l_gpt_write`, `function rzg2l_gpt_read`, `function rzg2l_gpt_modify`, `function rzg2l_gpt_calculate_prescale`, `function rzg2l_gpt_request`, `function rzg2l_gpt_free`, `function rzg2l_gpt_is_ch_enabled`.
- 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.