drivers/w1/slaves/w1_ds2405.c
Source file repositories/reference/linux-study-clean/drivers/w1/slaves/w1_ds2405.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/w1/slaves/w1_ds2405.c- Extension
.c- Size
- 4344 bytes
- Lines
- 219
- Domain
- Driver Families
- Bucket
- drivers/w1
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/kernel.hlinux/module.hlinux/moduleparam.hlinux/mutex.hlinux/string.hlinux/types.hlinux/w1.h
Detected Declarations
function w1_ds2405_selectfunction w1_ds2405_read_piofunction state_showfunction output_showfunction output_store
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* w1_ds2405.c
*
* Copyright (c) 2017 Maciej S. Szmigiero <mail@maciej.szmigiero.name>
* Based on w1_therm.c copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net>
*/
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/mutex.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/w1.h>
#define W1_FAMILY_DS2405 0x05
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Maciej S. Szmigiero <mail@maciej.szmigiero.name>");
MODULE_DESCRIPTION("Driver for 1-wire Dallas DS2405 PIO.");
MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2405));
static int w1_ds2405_select(struct w1_slave *sl, bool only_active)
{
struct w1_master *dev = sl->master;
u64 dev_addr = le64_to_cpu(*(u64 *)&sl->reg_num);
unsigned int bit_ctr;
if (w1_reset_bus(dev) != 0)
return 0;
/*
* We cannot use a normal Match ROM command
* since doing so would toggle PIO state
*/
w1_write_8(dev, only_active ? W1_ALARM_SEARCH : W1_SEARCH);
for (bit_ctr = 0; bit_ctr < 64; bit_ctr++) {
int bit2send = !!(dev_addr & BIT(bit_ctr));
u8 ret;
ret = w1_triplet(dev, bit2send);
if ((ret & (BIT(0) | BIT(1))) ==
(BIT(0) | BIT(1))) /* no devices found */
return 0;
if (!!(ret & BIT(2)) != bit2send)
/* wrong direction taken - no such device */
return 0;
}
return 1;
}
static int w1_ds2405_read_pio(struct w1_slave *sl)
{
if (w1_ds2405_select(sl, true))
return 0; /* "active" means PIO is low */
if (w1_ds2405_select(sl, false))
return 1;
return -ENODEV;
}
static ssize_t state_show(struct device *device,
struct device_attribute *attr, char *buf)
{
struct w1_slave *sl = dev_to_w1_slave(device);
struct w1_master *dev = sl->master;
int ret;
ssize_t f_retval;
u8 state;
ret = mutex_lock_interruptible(&dev->bus_mutex);
if (ret)
return ret;
if (!w1_ds2405_select(sl, false)) {
f_retval = -ENODEV;
goto out_unlock;
}
state = w1_read_8(dev);
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/mutex.h`, `linux/string.h`, `linux/types.h`, `linux/w1.h`.
- Detected declarations: `function w1_ds2405_select`, `function w1_ds2405_read_pio`, `function state_show`, `function output_show`, `function output_store`.
- Atlas domain: Driver Families / drivers/w1.
- 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.