drivers/hwspinlock/stm32_hwspinlock.c
Source file repositories/reference/linux-study-clean/drivers/hwspinlock/stm32_hwspinlock.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwspinlock/stm32_hwspinlock.c- Extension
.c- Size
- 4240 bytes
- Lines
- 176
- Domain
- Driver Families
- Bucket
- drivers/hwspinlock
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/delay.hlinux/hwspinlock.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm_runtime.hhwspinlock_internal.h
Detected Declarations
struct stm32_hwspinlockfunction stm32_hwspinlock_trylockfunction stm32_hwspinlock_unlockfunction stm32_hwspinlock_relaxfunction stm32_hwspinlock_disable_clkfunction stm32_hwspinlock_probefunction stm32_hwspinlock_runtime_suspendfunction stm32_hwspinlock_runtime_resumefunction stm32_hwspinlock_initfunction stm32_hwspinlock_exit
Annotated Snippet
struct stm32_hwspinlock {
struct clk *clk;
struct hwspinlock_device bank;
};
static int stm32_hwspinlock_trylock(struct hwspinlock *lock)
{
void __iomem *lock_addr = lock->priv;
u32 status;
writel(STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID, lock_addr);
status = readl(lock_addr);
return status == (STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID);
}
static void stm32_hwspinlock_unlock(struct hwspinlock *lock)
{
void __iomem *lock_addr = lock->priv;
writel(STM32_MUTEX_COREID, lock_addr);
}
static void stm32_hwspinlock_relax(struct hwspinlock *lock)
{
ndelay(50);
}
static const struct hwspinlock_ops stm32_hwspinlock_ops = {
.trylock = stm32_hwspinlock_trylock,
.unlock = stm32_hwspinlock_unlock,
.relax = stm32_hwspinlock_relax,
};
static void stm32_hwspinlock_disable_clk(void *data)
{
struct platform_device *pdev = data;
struct stm32_hwspinlock *hw = platform_get_drvdata(pdev);
struct device *dev = &pdev->dev;
pm_runtime_get_sync(dev);
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
pm_runtime_put_noidle(dev);
clk_disable_unprepare(hw->clk);
}
static int stm32_hwspinlock_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct stm32_hwspinlock *hw;
void __iomem *io_base;
int i, ret;
io_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(io_base))
return PTR_ERR(io_base);
hw = devm_kzalloc(dev, struct_size(hw, bank.lock, STM32_MUTEX_NUM_LOCKS), GFP_KERNEL);
if (!hw)
return -ENOMEM;
hw->clk = devm_clk_get(dev, "hsem");
if (IS_ERR(hw->clk))
return PTR_ERR(hw->clk);
ret = clk_prepare_enable(hw->clk);
if (ret) {
dev_err(dev, "Failed to prepare_enable clock\n");
return ret;
}
platform_set_drvdata(pdev, hw);
pm_runtime_get_noresume(dev);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
pm_runtime_put(dev);
ret = devm_add_action_or_reset(dev, stm32_hwspinlock_disable_clk, pdev);
if (ret) {
dev_err(dev, "Failed to register action\n");
return ret;
}
for (i = 0; i < STM32_MUTEX_NUM_LOCKS; i++)
hw->bank.lock[i].priv = io_base + i * sizeof(u32);
ret = devm_hwspin_lock_register(dev, &hw->bank, &stm32_hwspinlock_ops,
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/hwspinlock.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct stm32_hwspinlock`, `function stm32_hwspinlock_trylock`, `function stm32_hwspinlock_unlock`, `function stm32_hwspinlock_relax`, `function stm32_hwspinlock_disable_clk`, `function stm32_hwspinlock_probe`, `function stm32_hwspinlock_runtime_suspend`, `function stm32_hwspinlock_runtime_resume`, `function stm32_hwspinlock_init`, `function stm32_hwspinlock_exit`.
- Atlas domain: Driver Families / drivers/hwspinlock.
- Implementation status: integration 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.