drivers/soundwire/sysfs_slave_dpn.c
Source file repositories/reference/linux-study-clean/drivers/soundwire/sysfs_slave_dpn.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/soundwire/sysfs_slave_dpn.c- Extension
.c- Size
- 7461 bytes
- Lines
- 305
- Domain
- Driver Families
- Bucket
- drivers/soundwire
- 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.
- 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/device.hlinux/mod_devicetable.hlinux/slab.hlinux/sysfs.hlinux/soundwire/sdw.hlinux/soundwire/sdw_type.hbus.hsysfs_local.h
Detected Declarations
struct dpn_attributefunction add_all_attributesfunction sdw_slave_sysfs_dpn_init
Annotated Snippet
struct dpn_attribute {
struct device_attribute dev_attr;
int N;
int dir;
const char *format_string;
};
/*
* Since we can't use ARRAY_SIZE, hard-code number of dpN attributes.
* This needs to be updated when adding new attributes - an error will be
* flagged on a mismatch.
*/
#define SDW_DPN_ATTRIBUTES 15
#define sdw_dpn_attribute_alloc(field) \
static int field##_attribute_alloc(struct device *dev, \
struct attribute **res, \
int N, int dir, \
const char *format_string) \
{ \
struct dpn_attribute *dpn_attr; \
\
dpn_attr = devm_kzalloc(dev, sizeof(*dpn_attr), GFP_KERNEL); \
if (!dpn_attr) \
return -ENOMEM; \
dpn_attr->N = N; \
dpn_attr->dir = dir; \
sysfs_attr_init(&dpn_attr->dev_attr.attr); \
dpn_attr->format_string = format_string; \
dpn_attr->dev_attr.attr.name = __stringify(field); \
dpn_attr->dev_attr.attr.mode = 0444; \
dpn_attr->dev_attr.show = field##_show; \
\
*res = &dpn_attr->dev_attr.attr; \
\
return 0; \
}
#define sdw_dpn_attr(field) \
\
static ssize_t field##_dpn_show(struct sdw_slave *slave, \
int N, \
int dir, \
const char *format_string, \
char *buf) \
{ \
struct sdw_dpn_prop *dpn; \
unsigned long mask; \
int bit; \
int i; \
\
if (dir) { \
dpn = slave->prop.src_dpn_prop; \
mask = slave->prop.source_ports; \
} else { \
dpn = slave->prop.sink_dpn_prop; \
mask = slave->prop.sink_ports; \
} \
\
i = 0; \
for_each_set_bit(bit, &mask, 32) { \
if (bit == N) { \
return sprintf(buf, format_string, \
dpn[i].field); \
} \
i++; \
} \
return -EINVAL; \
} \
\
static ssize_t field##_show(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
struct sdw_slave *slave = dev_to_sdw_dev(dev); \
struct dpn_attribute *dpn_attr = \
container_of(attr, struct dpn_attribute, dev_attr); \
\
return field##_dpn_show(slave, \
dpn_attr->N, dpn_attr->dir, \
dpn_attr->format_string, \
buf); \
} \
sdw_dpn_attribute_alloc(field)
sdw_dpn_attr(imp_def_interrupts);
sdw_dpn_attr(max_word);
sdw_dpn_attr(min_word);
sdw_dpn_attr(type);
sdw_dpn_attr(max_grouping);
Annotation
- Immediate include surface: `linux/device.h`, `linux/mod_devicetable.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/soundwire/sdw.h`, `linux/soundwire/sdw_type.h`, `bus.h`, `sysfs_local.h`.
- Detected declarations: `struct dpn_attribute`, `function add_all_attributes`, `function sdw_slave_sysfs_dpn_init`.
- Atlas domain: Driver Families / drivers/soundwire.
- Implementation status: source implementation candidate.
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.