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.

Dependency Surface

Detected Declarations

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

Implementation Notes