drivers/counter/interrupt-cnt.c
Source file repositories/reference/linux-study-clean/drivers/counter/interrupt-cnt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/counter/interrupt-cnt.c- Extension
.c- Size
- 6613 bytes
- Lines
- 265
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cleanup.hlinux/counter.hlinux/gpio/consumer.hlinux/interrupt.hlinux/irq.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/types.h
Detected Declarations
struct interrupt_cnt_privfunction interrupt_cnt_isrfunction interrupt_cnt_enable_readfunction interrupt_cnt_enable_writefunction interrupt_cnt_action_readfunction interrupt_cnt_readfunction interrupt_cnt_writefunction interrupt_cnt_function_readfunction interrupt_cnt_signal_readfunction interrupt_cnt_watch_validatefunction interrupt_cnt_probe
Annotated Snippet
struct interrupt_cnt_priv {
atomic_long_t count;
struct gpio_desc *gpio;
int irq;
bool enabled;
struct mutex lock;
struct counter_signal signals;
struct counter_synapse synapses;
struct counter_count cnts;
};
static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id)
{
struct counter_device *counter = dev_id;
struct interrupt_cnt_priv *priv = counter_priv(counter);
atomic_long_inc(&priv->count);
counter_push_event(counter, COUNTER_EVENT_CHANGE_OF_STATE, 0);
return IRQ_HANDLED;
}
static int interrupt_cnt_enable_read(struct counter_device *counter,
struct counter_count *count, u8 *enable)
{
struct interrupt_cnt_priv *priv = counter_priv(counter);
guard(mutex)(&priv->lock);
*enable = priv->enabled;
return 0;
}
static int interrupt_cnt_enable_write(struct counter_device *counter,
struct counter_count *count, u8 enable)
{
struct interrupt_cnt_priv *priv = counter_priv(counter);
guard(mutex)(&priv->lock);
if (priv->enabled == enable)
return 0;
if (enable) {
priv->enabled = true;
enable_irq(priv->irq);
} else {
disable_irq(priv->irq);
priv->enabled = false;
}
return 0;
}
static struct counter_comp interrupt_cnt_ext[] = {
COUNTER_COMP_ENABLE(interrupt_cnt_enable_read,
interrupt_cnt_enable_write),
};
static const enum counter_synapse_action interrupt_cnt_synapse_actions[] = {
COUNTER_SYNAPSE_ACTION_RISING_EDGE,
};
static int interrupt_cnt_action_read(struct counter_device *counter,
struct counter_count *count,
struct counter_synapse *synapse,
enum counter_synapse_action *action)
{
*action = COUNTER_SYNAPSE_ACTION_RISING_EDGE;
return 0;
}
static int interrupt_cnt_read(struct counter_device *counter,
struct counter_count *count, u64 *val)
{
struct interrupt_cnt_priv *priv = counter_priv(counter);
*val = atomic_long_read(&priv->count);
return 0;
}
static int interrupt_cnt_write(struct counter_device *counter,
struct counter_count *count, const u64 val)
{
struct interrupt_cnt_priv *priv = counter_priv(counter);
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/counter.h`, `linux/gpio/consumer.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct interrupt_cnt_priv`, `function interrupt_cnt_isr`, `function interrupt_cnt_enable_read`, `function interrupt_cnt_enable_write`, `function interrupt_cnt_action_read`, `function interrupt_cnt_read`, `function interrupt_cnt_write`, `function interrupt_cnt_function_read`, `function interrupt_cnt_signal_read`, `function interrupt_cnt_watch_validate`.
- Atlas domain: Driver Families / drivers/counter.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.