drivers/hwspinlock/sprd_hwspinlock.c
Source file repositories/reference/linux-study-clean/drivers/hwspinlock/sprd_hwspinlock.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwspinlock/sprd_hwspinlock.c- Extension
.c- Size
- 4159 bytes
- Lines
- 158
- Domain
- Driver Families
- Bucket
- drivers/hwspinlock
- 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.
- 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/device.hlinux/hwspinlock.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_device.hlinux/platform_device.hhwspinlock_internal.h
Detected Declarations
struct sprd_hwspinlock_devfunction sprd_hwspinlock_trylockfunction sprd_hwspinlock_unlockfunction sprd_hwspinlock_relaxfunction sprd_hwspinlock_disablefunction sprd_hwspinlock_probe
Annotated Snippet
struct sprd_hwspinlock_dev {
void __iomem *base;
struct clk *clk;
struct hwspinlock_device bank;
};
/* try to lock the hardware spinlock */
static int sprd_hwspinlock_trylock(struct hwspinlock *lock)
{
struct sprd_hwspinlock_dev *sprd_hwlock =
dev_get_drvdata(lock->bank->dev);
void __iomem *addr = lock->priv;
int user_id, lock_id;
if (!readl(addr))
return 1;
lock_id = hwlock_to_id(lock);
/* get the hardware spinlock master/user id */
user_id = readl(sprd_hwlock->base + HWSPINLOCK_MASTERID(lock_id));
dev_warn(sprd_hwlock->bank.dev,
"hwspinlock [%d] lock failed and master/user id = %d!\n",
lock_id, user_id);
return 0;
}
/* unlock the hardware spinlock */
static void sprd_hwspinlock_unlock(struct hwspinlock *lock)
{
void __iomem *lock_addr = lock->priv;
writel(HWSPINLOCK_NOTTAKEN, lock_addr);
}
/* The specs recommended below number as the retry delay time */
static void sprd_hwspinlock_relax(struct hwspinlock *lock)
{
ndelay(10);
}
static const struct hwspinlock_ops sprd_hwspinlock_ops = {
.trylock = sprd_hwspinlock_trylock,
.unlock = sprd_hwspinlock_unlock,
.relax = sprd_hwspinlock_relax,
};
static void sprd_hwspinlock_disable(void *data)
{
struct sprd_hwspinlock_dev *sprd_hwlock = data;
clk_disable_unprepare(sprd_hwlock->clk);
}
static int sprd_hwspinlock_probe(struct platform_device *pdev)
{
struct sprd_hwspinlock_dev *sprd_hwlock;
struct hwspinlock *lock;
int i, ret;
if (!pdev->dev.of_node)
return -ENODEV;
sprd_hwlock = devm_kzalloc(&pdev->dev,
struct_size(sprd_hwlock, bank.lock, SPRD_HWLOCKS_NUM),
GFP_KERNEL);
if (!sprd_hwlock)
return -ENOMEM;
sprd_hwlock->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(sprd_hwlock->base))
return PTR_ERR(sprd_hwlock->base);
sprd_hwlock->clk = devm_clk_get(&pdev->dev, "enable");
if (IS_ERR(sprd_hwlock->clk)) {
dev_err(&pdev->dev, "get hwspinlock clock failed!\n");
return PTR_ERR(sprd_hwlock->clk);
}
ret = clk_prepare_enable(sprd_hwlock->clk);
if (ret)
return ret;
ret = devm_add_action_or_reset(&pdev->dev, sprd_hwspinlock_disable,
sprd_hwlock);
if (ret) {
dev_err(&pdev->dev,
"Failed to add hwspinlock disable action\n");
return ret;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/hwspinlock.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct sprd_hwspinlock_dev`, `function sprd_hwspinlock_trylock`, `function sprd_hwspinlock_unlock`, `function sprd_hwspinlock_relax`, `function sprd_hwspinlock_disable`, `function sprd_hwspinlock_probe`.
- Atlas domain: Driver Families / drivers/hwspinlock.
- Implementation status: source 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.