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.
- 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/counter.hlinux/device.hlinux/err.hlinux/gfp.hlinux/kernel.hlinux/kfifo.hlinux/kstrtox.hlinux/list.hlinux/mutex.hlinux/spinlock.hlinux/string.hlinux/sysfs.hlinux/types.hcounter-sysfs.h
Detected Declarations
struct counter_attributestruct counter_attribute_groupfunction Copyrightfunction counter_comp_u8_showfunction counter_comp_u8_storefunction counter_comp_u32_showfunction counter_find_enumfunction counter_comp_u32_storefunction counter_comp_u64_showfunction counter_comp_u64_storefunction counter_comp_array_u32_showfunction counter_comp_array_u32_storefunction counter_comp_array_u64_showfunction counter_comp_array_u64_storefunction enums_available_showfunction strs_available_showfunction counter_comp_available_showfunction counter_avail_attr_createfunction counter_attr_createfunction counter_comp_name_showfunction counter_name_attr_createfunction counter_comp_id_showfunction counter_comp_id_attr_createfunction counter_ext_attrs_createfunction counter_array_attrs_createfunction counter_sysfs_exts_addfunction counter_signal_attrs_createfunction counter_sysfs_signals_addfunction counter_sysfs_synapses_addfunction counter_count_attrs_createfunction counter_sysfs_counts_addfunction counter_num_signals_readfunction counter_num_counts_readfunction counter_events_queue_size_readfunction counter_events_queue_size_writefunction counter_sysfs_attr_addfunction needed
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
- Immediate include surface: `linux/counter.h`, `linux/device.h`, `linux/err.h`, `linux/gfp.h`, `linux/kernel.h`, `linux/kfifo.h`, `linux/kstrtox.h`, `linux/list.h`.
- Detected declarations: `struct counter_attribute`, `struct counter_attribute_group`, `function Copyright`, `function counter_comp_u8_show`, `function counter_comp_u8_store`, `function counter_comp_u32_show`, `function counter_find_enum`, `function counter_comp_u32_store`, `function counter_comp_u64_show`, `function counter_comp_u64_store`.
- 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.
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.