drivers/mfd/stm32-lptimer.c
Source file repositories/reference/linux-study-clean/drivers/mfd/stm32-lptimer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mfd/stm32-lptimer.c- Extension
.c- Size
- 3266 bytes
- Lines
- 134
- Domain
- Driver Families
- Bucket
- drivers/mfd
- 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/bitfield.hlinux/mfd/stm32-lptimer.hlinux/module.hlinux/of_platform.hlinux/platform_device.h
Detected Declarations
function stm32_lptimer_detect_encoderfunction stm32_lptimer_detect_hwcfgrfunction stm32_lptimer_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* STM32 Low-Power Timer parent driver.
* Copyright (C) STMicroelectronics 2017
* Author: Fabrice Gasnier <fabrice.gasnier@st.com>
* Inspired by Benjamin Gaignard's stm32-timers driver
*/
#include <linux/bitfield.h>
#include <linux/mfd/stm32-lptimer.h>
#include <linux/module.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#define STM32_LPTIM_MAX_REGISTER 0x3fc
static const struct regmap_config stm32_lptimer_regmap_cfg = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = sizeof(u32),
.max_register = STM32_LPTIM_MAX_REGISTER,
};
static int stm32_lptimer_detect_encoder(struct stm32_lptimer *ddata)
{
u32 val;
int ret;
/*
* Quadrature encoder mode bit can only be written and read back when
* Low-Power Timer supports it.
*/
ret = regmap_update_bits(ddata->regmap, STM32_LPTIM_CFGR,
STM32_LPTIM_ENC, STM32_LPTIM_ENC);
if (ret)
return ret;
ret = regmap_read(ddata->regmap, STM32_LPTIM_CFGR, &val);
if (ret)
return ret;
ret = regmap_update_bits(ddata->regmap, STM32_LPTIM_CFGR,
STM32_LPTIM_ENC, 0);
if (ret)
return ret;
ddata->has_encoder = !!(val & STM32_LPTIM_ENC);
return 0;
}
static int stm32_lptimer_detect_hwcfgr(struct stm32_lptimer *ddata)
{
u32 val;
int ret;
ret = regmap_read(ddata->regmap, STM32_LPTIM_VERR, &ddata->version);
if (ret)
return ret;
/* Try to guess parameters from HWCFGR: e.g. encoder mode (STM32MP15) */
ret = regmap_read(ddata->regmap, STM32_LPTIM_HWCFGR1, &val);
if (ret)
return ret;
/* Fallback to legacy init if HWCFGR isn't present */
if (!val)
return stm32_lptimer_detect_encoder(ddata);
ddata->has_encoder = FIELD_GET(STM32_LPTIM_HWCFGR1_ENCODER, val);
ret = regmap_read(ddata->regmap, STM32_LPTIM_HWCFGR2, &val);
if (ret)
return ret;
/* Number of capture/compare channels */
ddata->num_cc_chans = FIELD_GET(STM32_LPTIM_HWCFGR2_CHAN_NUM, val);
return 0;
}
static int stm32_lptimer_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct stm32_lptimer *ddata;
void __iomem *mmio;
int ret;
ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
if (!ddata)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/mfd/stm32-lptimer.h`, `linux/module.h`, `linux/of_platform.h`, `linux/platform_device.h`.
- Detected declarations: `function stm32_lptimer_detect_encoder`, `function stm32_lptimer_detect_hwcfgr`, `function stm32_lptimer_probe`.
- Atlas domain: Driver Families / drivers/mfd.
- 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.