drivers/w1/w1.c
Source file repositories/reference/linux-study-clean/drivers/w1/w1.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/w1/w1.c- Extension
.c- Size
- 32332 bytes
- Lines
- 1272
- Domain
- Driver Families
- Bucket
- drivers/w1
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/delay.hlinux/kernel.hlinux/module.hlinux/moduleparam.hlinux/list.hlinux/interrupt.hlinux/spinlock.hlinux/timer.hlinux/device.hlinux/slab.hlinux/sched.hlinux/kthread.hlinux/freezer.hlinux/hwmon.hlinux/of.hlinux/atomic.hw1_internal.hw1_netlink.h
Detected Declarations
function w1_master_probefunction w1_master_releasefunction w1_slave_releasefunction name_showfunction id_showfunction rw_writefunction rw_readfunction w1_master_attribute_show_namefunction w1_master_attribute_store_searchfunction w1_master_attribute_show_searchfunction w1_master_attribute_store_pullupfunction w1_master_attribute_show_pullupfunction w1_master_attribute_show_pointerfunction w1_master_attribute_show_timeoutfunction w1_master_attribute_show_timeout_usfunction w1_master_attribute_store_max_slave_countfunction w1_master_attribute_show_max_slave_countfunction w1_master_attribute_show_attemptsfunction w1_master_attribute_show_slave_countfunction w1_master_attribute_show_slavesfunction list_for_each_safefunction w1_master_attribute_show_addfunction w1_atoreg_numfunction w1_master_attribute_store_addfunction w1_master_attribute_show_removefunction w1_master_attribute_store_removefunction w1_create_master_attributesfunction w1_destroy_master_attributesfunction w1_ueventfunction w1_family_notifyfunction __w1_attach_slave_devicefunction w1_attach_slave_devicefunction w1_unref_slavefunction w1_slave_detachfunction list_for_each_entryfunction w1_reconnect_slavesfunction list_for_each_entry_safefunction w1_addr_crc_is_validfunction DS28E04function w1_slave_foundfunction w1_searchfunction w1_search_process_cbfunction w1_search_processfunction w1_process_callbacksfunction list_for_each_entry_safefunction w1_processfunction w1_initfunction w1_fini
Annotated Snippet
static const struct bus_type w1_bus_type = {
.name = "w1",
.uevent = w1_uevent,
};
struct device_driver w1_master_driver = {
.name = "w1_master_driver",
.bus = &w1_bus_type,
.probe = w1_master_probe,
};
struct device w1_master_device = {
.parent = NULL,
.bus = &w1_bus_type,
.init_name = "w1 bus master",
.driver = &w1_master_driver,
.release = &w1_master_release
};
static struct device_driver w1_slave_driver = {
.name = "w1_slave_driver",
.bus = &w1_bus_type,
};
#if 0
struct device w1_slave_device = {
.parent = NULL,
.bus = &w1_bus_type,
.init_name = "w1 bus slave",
.driver = &w1_slave_driver,
.release = &w1_slave_release
};
#endif /* 0 */
static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf)
{
struct w1_master *md = dev_to_w1_master(dev);
ssize_t count;
mutex_lock(&md->mutex);
count = sysfs_emit(buf, "%s\n", md->name);
mutex_unlock(&md->mutex);
return count;
}
static ssize_t w1_master_attribute_store_search(struct device * dev,
struct device_attribute *attr,
const char * buf, size_t count)
{
long tmp;
struct w1_master *md = dev_to_w1_master(dev);
int ret;
ret = kstrtol(buf, 0, &tmp);
if (ret)
return ret;
mutex_lock(&md->mutex);
md->search_count = tmp;
mutex_unlock(&md->mutex);
/* Only wake if it is going to be searching. */
if (tmp)
wake_up_process(md->thread);
return count;
}
static ssize_t w1_master_attribute_show_search(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct w1_master *md = dev_to_w1_master(dev);
ssize_t count;
mutex_lock(&md->mutex);
count = sysfs_emit(buf, "%d\n", md->search_count);
mutex_unlock(&md->mutex);
return count;
}
static ssize_t w1_master_attribute_store_pullup(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
long tmp;
struct w1_master *md = dev_to_w1_master(dev);
int ret;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/kernel.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/list.h`, `linux/interrupt.h`, `linux/spinlock.h`, `linux/timer.h`.
- Detected declarations: `function w1_master_probe`, `function w1_master_release`, `function w1_slave_release`, `function name_show`, `function id_show`, `function rw_write`, `function rw_read`, `function w1_master_attribute_show_name`, `function w1_master_attribute_store_search`, `function w1_master_attribute_show_search`.
- Atlas domain: Driver Families / drivers/w1.
- Implementation status: pattern 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.