drivers/counter/counter-sysfs.c

Source file repositories/reference/linux-study-clean/drivers/counter/counter-sysfs.c

File Facts

System
Linux kernel
Corpus path
drivers/counter/counter-sysfs.c
Extension
.c
Size
32549 bytes
Lines
1175
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 counter_attribute {
	struct device_attribute dev_attr;
	struct list_head l;

	struct counter_comp comp;
	enum counter_scope scope;
	void *parent;
};

#define to_counter_attribute(_dev_attr) \
	container_of(_dev_attr, struct counter_attribute, dev_attr)

/**
 * struct counter_attribute_group - container for attribute group
 * @name:	name of the attribute group
 * @attr_list:	list to keep track of created attributes
 * @num_attr:	number of attributes
 */
struct counter_attribute_group {
	const char *name;
	struct list_head attr_list;
	size_t num_attr;
};

static const char *const counter_function_str[] = {
	[COUNTER_FUNCTION_INCREASE] = "increase",
	[COUNTER_FUNCTION_DECREASE] = "decrease",
	[COUNTER_FUNCTION_PULSE_DIRECTION] = "pulse-direction",
	[COUNTER_FUNCTION_QUADRATURE_X1_A] = "quadrature x1 a",
	[COUNTER_FUNCTION_QUADRATURE_X1_B] = "quadrature x1 b",
	[COUNTER_FUNCTION_QUADRATURE_X2_A] = "quadrature x2 a",
	[COUNTER_FUNCTION_QUADRATURE_X2_B] = "quadrature x2 b",
	[COUNTER_FUNCTION_QUADRATURE_X4] = "quadrature x4"
};

static const char *const counter_signal_value_str[] = {
	[COUNTER_SIGNAL_LEVEL_LOW] = "low",
	[COUNTER_SIGNAL_LEVEL_HIGH] = "high"
};

static const char *const counter_synapse_action_str[] = {
	[COUNTER_SYNAPSE_ACTION_NONE] = "none",
	[COUNTER_SYNAPSE_ACTION_RISING_EDGE] = "rising edge",
	[COUNTER_SYNAPSE_ACTION_FALLING_EDGE] = "falling edge",
	[COUNTER_SYNAPSE_ACTION_BOTH_EDGES] = "both edges"
};

static const char *const counter_count_direction_str[] = {
	[COUNTER_COUNT_DIRECTION_FORWARD] = "forward",
	[COUNTER_COUNT_DIRECTION_BACKWARD] = "backward"
};

static const char *const counter_count_mode_str[] = {
	[COUNTER_COUNT_MODE_NORMAL] = "normal",
	[COUNTER_COUNT_MODE_RANGE_LIMIT] = "range limit",
	[COUNTER_COUNT_MODE_NON_RECYCLE] = "non-recycle",
	[COUNTER_COUNT_MODE_MODULO_N] = "modulo-n",
	[COUNTER_COUNT_MODE_INTERRUPT_ON_TERMINAL_COUNT] = "interrupt on terminal count",
	[COUNTER_COUNT_MODE_HARDWARE_RETRIGGERABLE_ONESHOT] = "hardware retriggerable one-shot",
	[COUNTER_COUNT_MODE_RATE_GENERATOR] = "rate generator",
	[COUNTER_COUNT_MODE_SQUARE_WAVE_MODE] = "square wave mode",
	[COUNTER_COUNT_MODE_SOFTWARE_TRIGGERED_STROBE] = "software triggered strobe",
	[COUNTER_COUNT_MODE_HARDWARE_TRIGGERED_STROBE] = "hardware triggered strobe",
};

static const char *const counter_signal_polarity_str[] = {
	[COUNTER_SIGNAL_POLARITY_POSITIVE] = "positive",
	[COUNTER_SIGNAL_POLARITY_NEGATIVE] = "negative"
};

static ssize_t counter_comp_u8_show(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	const struct counter_attribute *const a = to_counter_attribute(attr);
	struct counter_device *const counter = counter_from_dev(dev);
	int err;
	u8 data = 0;

	switch (a->scope) {
	case COUNTER_SCOPE_DEVICE:
		err = a->comp.device_u8_read(counter, &data);
		break;
	case COUNTER_SCOPE_SIGNAL:
		err = a->comp.signal_u8_read(counter, a->parent, &data);
		break;
	case COUNTER_SCOPE_COUNT:
		err = a->comp.count_u8_read(counter, a->parent, &data);
		break;
	default:
		return -EINVAL;

Annotation

Implementation Notes