drivers/counter/stm32-lptimer-cnt.c
Source file repositories/reference/linux-study-clean/drivers/counter/stm32-lptimer-cnt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/counter/stm32-lptimer-cnt.c- Extension
.c- Size
- 13593 bytes
- Lines
- 530
- Domain
- Driver Families
- Bucket
- drivers/counter
- 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/counter.hlinux/mfd/stm32-lptimer.hlinux/mod_devicetable.hlinux/module.hlinux/pinctrl/consumer.hlinux/platform_device.hlinux/types.h
Detected Declarations
struct stm32_lptim_cntfunction stm32_lptim_is_enabledfunction stm32_lptim_set_enable_statefunction stm32_lptim_setupfunction stm32_lptim_cnt_readfunction stm32_lptim_cnt_function_readfunction stm32_lptim_cnt_function_writefunction stm32_lptim_cnt_enable_readfunction stm32_lptim_cnt_enable_writefunction stm32_lptim_cnt_ceiling_readfunction stm32_lptim_cnt_ceiling_writefunction stm32_lptim_cnt_action_readfunction stm32_lptim_cnt_action_writefunction stm32_lptim_cnt_probefunction stm32_lptim_cnt_suspendfunction stm32_lptim_cnt_resume
Annotated Snippet
struct stm32_lptim_cnt {
struct device *dev;
struct regmap *regmap;
struct clk *clk;
u32 ceiling;
u32 polarity;
u32 quadrature_mode;
bool enabled;
};
static int stm32_lptim_is_enabled(struct stm32_lptim_cnt *priv)
{
u32 val;
int ret;
ret = regmap_read(priv->regmap, STM32_LPTIM_CR, &val);
if (ret)
return ret;
return FIELD_GET(STM32_LPTIM_ENABLE, val);
}
static int stm32_lptim_set_enable_state(struct stm32_lptim_cnt *priv,
int enable)
{
int ret;
u32 val;
val = FIELD_PREP(STM32_LPTIM_ENABLE, enable);
ret = regmap_write(priv->regmap, STM32_LPTIM_CR, val);
if (ret)
return ret;
if (!enable) {
clk_disable(priv->clk);
priv->enabled = false;
return 0;
}
ret = clk_enable(priv->clk);
if (ret)
goto disable_cnt;
/* LP timer must be enabled before writing CMP & ARR */
ret = regmap_write(priv->regmap, STM32_LPTIM_ARR, priv->ceiling);
if (ret)
goto disable_clk;
ret = regmap_write(priv->regmap, STM32_LPTIM_CMP, 0);
if (ret)
goto disable_clk;
/* ensure CMP & ARR registers are properly written */
ret = regmap_read_poll_timeout(priv->regmap, STM32_LPTIM_ISR, val,
(val & STM32_LPTIM_CMPOK_ARROK) == STM32_LPTIM_CMPOK_ARROK,
100, 1000);
if (ret)
goto disable_clk;
ret = regmap_write(priv->regmap, STM32_LPTIM_ICR,
STM32_LPTIM_CMPOKCF_ARROKCF);
if (ret)
goto disable_clk;
priv->enabled = true;
/* Start LP timer in continuous mode */
return regmap_update_bits(priv->regmap, STM32_LPTIM_CR,
STM32_LPTIM_CNTSTRT, STM32_LPTIM_CNTSTRT);
disable_clk:
clk_disable(priv->clk);
disable_cnt:
regmap_write(priv->regmap, STM32_LPTIM_CR, 0);
return ret;
}
static int stm32_lptim_setup(struct stm32_lptim_cnt *priv, int enable)
{
u32 mask = STM32_LPTIM_ENC | STM32_LPTIM_COUNTMODE |
STM32_LPTIM_CKPOL | STM32_LPTIM_PRESC;
u32 val;
/* Setup LP timer encoder/counter and polarity, without prescaler */
if (priv->quadrature_mode)
val = enable ? STM32_LPTIM_ENC : 0;
else
val = enable ? STM32_LPTIM_COUNTMODE : 0;
val |= FIELD_PREP(STM32_LPTIM_CKPOL, enable ? priv->polarity : 0);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/counter.h`, `linux/mfd/stm32-lptimer.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/pinctrl/consumer.h`, `linux/platform_device.h`, `linux/types.h`.
- Detected declarations: `struct stm32_lptim_cnt`, `function stm32_lptim_is_enabled`, `function stm32_lptim_set_enable_state`, `function stm32_lptim_setup`, `function stm32_lptim_cnt_read`, `function stm32_lptim_cnt_function_read`, `function stm32_lptim_cnt_function_write`, `function stm32_lptim_cnt_enable_read`, `function stm32_lptim_cnt_enable_write`, `function stm32_lptim_cnt_ceiling_read`.
- Atlas domain: Driver Families / drivers/counter.
- 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.