drivers/pwm/pwm-omap-dmtimer.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-omap-dmtimer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-omap-dmtimer.c- Extension
.c- Size
- 13518 bytes
- Lines
- 467
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/err.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_platform.hclocksource/timer-ti-dm.hlinux/platform_data/dmtimer-omap.hlinux/platform_device.hlinux/pm_runtime.hlinux/pwm.hlinux/slab.hlinux/time.h
Detected Declarations
struct pwm_omap_dmtimer_chipfunction to_pwm_omap_dmtimer_chipfunction pwm_omap_dmtimer_get_clock_cyclesfunction pwm_omap_dmtimer_startfunction pwm_omap_dmtimer_is_enabledfunction pwm_omap_dmtimer_polarityfunction pwm_omap_dmtimer_configfunction pwm_omap_dmtimer_set_polarityfunction pwm_omap_dmtimer_applyfunction pwm_omap_dmtimer_probefunction pwm_omap_dmtimer_remove
Annotated Snippet
struct pwm_omap_dmtimer_chip {
/* Mutex to protect pwm apply state */
struct omap_dm_timer *dm_timer;
const struct omap_dm_timer_ops *pdata;
struct platform_device *dm_timer_pdev;
};
static inline struct pwm_omap_dmtimer_chip *
to_pwm_omap_dmtimer_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
/**
* pwm_omap_dmtimer_get_clock_cycles() - Get clock cycles in a time frame
* @clk_rate: pwm timer clock rate
* @ns: time frame in nano seconds.
*
* Return number of clock cycles in a given period(ins ns).
*/
static u32 pwm_omap_dmtimer_get_clock_cycles(unsigned long clk_rate, int ns)
{
return DIV_ROUND_CLOSEST_ULL((u64)clk_rate * ns, NSEC_PER_SEC);
}
/**
* pwm_omap_dmtimer_start() - Start the pwm omap dm timer in pwm mode
* @omap: Pointer to pwm omap dm timer chip
*/
static void pwm_omap_dmtimer_start(struct pwm_omap_dmtimer_chip *omap)
{
/*
* According to OMAP 4 TRM section 22.2.4.10 the counter should be
* started at 0xFFFFFFFE when overflow and match is used to ensure
* that the PWM line is toggled on the first event.
*
* Note that omap_dm_timer_enable/disable is for register access and
* not the timer counter itself.
*/
omap->pdata->enable(omap->dm_timer);
omap->pdata->write_counter(omap->dm_timer, DM_TIMER_LOAD_MIN);
omap->pdata->disable(omap->dm_timer);
omap->pdata->start(omap->dm_timer);
}
/**
* pwm_omap_dmtimer_is_enabled() - Detect if the pwm is enabled.
* @omap: Pointer to pwm omap dm timer chip
*
* Return true if pwm is enabled else false.
*/
static bool pwm_omap_dmtimer_is_enabled(struct pwm_omap_dmtimer_chip *omap)
{
u32 status;
status = omap->pdata->get_pwm_status(omap->dm_timer);
return !!(status & OMAP_TIMER_CTRL_ST);
}
/**
* pwm_omap_dmtimer_polarity() - Detect the polarity of pwm.
* @omap: Pointer to pwm omap dm timer chip
*
* Return the polarity of pwm.
*/
static int pwm_omap_dmtimer_polarity(struct pwm_omap_dmtimer_chip *omap)
{
u32 status;
status = omap->pdata->get_pwm_status(omap->dm_timer);
return !!(status & OMAP_TIMER_CTRL_SCPWM);
}
/**
* pwm_omap_dmtimer_config() - Update the configuration of pwm omap dm timer
* @chip: Pointer to PWM controller
* @pwm: Pointer to PWM channel
* @duty_ns: New duty cycle in nano seconds
* @period_ns: New period in nano seconds
*
* Return 0 if successfully changed the period/duty_cycle else appropriate
* error.
*/
static int pwm_omap_dmtimer_config(struct pwm_chip *chip,
struct pwm_device *pwm,
int duty_ns, int period_ns)
{
Annotation
- Immediate include surface: `linux/clk.h`, `linux/err.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/of_platform.h`, `clocksource/timer-ti-dm.h`, `linux/platform_data/dmtimer-omap.h`.
- Detected declarations: `struct pwm_omap_dmtimer_chip`, `function to_pwm_omap_dmtimer_chip`, `function pwm_omap_dmtimer_get_clock_cycles`, `function pwm_omap_dmtimer_start`, `function pwm_omap_dmtimer_is_enabled`, `function pwm_omap_dmtimer_polarity`, `function pwm_omap_dmtimer_config`, `function pwm_omap_dmtimer_set_polarity`, `function pwm_omap_dmtimer_apply`, `function pwm_omap_dmtimer_probe`.
- 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.