drivers/w1/slaves/w1_ds2780.c
Source file repositories/reference/linux-study-clean/drivers/w1/slaves/w1_ds2780.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/w1/slaves/w1_ds2780.c- Extension
.c- Size
- 3552 bytes
- Lines
- 161
- Domain
- Driver Families
- Bucket
- drivers/w1
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/module.hlinux/device.hlinux/types.hlinux/platform_device.hlinux/mutex.hlinux/idr.hlinux/w1.hw1_ds2780.h
Detected Declarations
function Copyrightfunction w1_ds2780_iofunction w1_ds2780_eeprom_cmdfunction w1_slave_readfunction w1_ds2780_add_slavefunction w1_ds2780_remove_slaveexport w1_ds2780_ioexport w1_ds2780_eeprom_cmd
Annotated Snippet
if (io) {
w1_write_8(sl->master, W1_DS2780_WRITE_DATA);
w1_write_8(sl->master, addr);
w1_write_block(sl->master, buf, count);
} else {
w1_write_8(sl->master, W1_DS2780_READ_DATA);
w1_write_8(sl->master, addr);
count = w1_read_block(sl->master, buf, count);
}
}
return count;
}
int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
int io)
{
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
int ret;
if (!dev)
return -ENODEV;
mutex_lock(&sl->master->bus_mutex);
ret = w1_ds2780_do_io(dev, buf, addr, count, io);
mutex_unlock(&sl->master->bus_mutex);
return ret;
}
EXPORT_SYMBOL(w1_ds2780_io);
int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd)
{
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
if (!dev)
return -EINVAL;
mutex_lock(&sl->master->bus_mutex);
if (w1_reset_select_slave(sl) == 0) {
w1_write_8(sl->master, cmd);
w1_write_8(sl->master, addr);
}
mutex_unlock(&sl->master->bus_mutex);
return 0;
}
EXPORT_SYMBOL(w1_ds2780_eeprom_cmd);
static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct device *dev = kobj_to_dev(kobj);
return w1_ds2780_io(dev, buf, off, count, 0);
}
static const BIN_ATTR_RO(w1_slave, DS2780_DATA_SIZE);
static const struct bin_attribute *const w1_ds2780_bin_attrs[] = {
&bin_attr_w1_slave,
NULL,
};
static const struct attribute_group w1_ds2780_group = {
.bin_attrs = w1_ds2780_bin_attrs,
};
static const struct attribute_group *w1_ds2780_groups[] = {
&w1_ds2780_group,
NULL,
};
static int w1_ds2780_add_slave(struct w1_slave *sl)
{
int ret;
struct platform_device *pdev;
pdev = platform_device_alloc("ds2780-battery", PLATFORM_DEVID_AUTO);
if (!pdev)
return -ENOMEM;
pdev->dev.parent = &sl->dev;
ret = platform_device_add(pdev);
if (ret)
goto pdev_add_failed;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/device.h`, `linux/types.h`, `linux/platform_device.h`, `linux/mutex.h`, `linux/idr.h`, `linux/w1.h`.
- Detected declarations: `function Copyright`, `function w1_ds2780_io`, `function w1_ds2780_eeprom_cmd`, `function w1_slave_read`, `function w1_ds2780_add_slave`, `function w1_ds2780_remove_slave`, `export w1_ds2780_io`, `export w1_ds2780_eeprom_cmd`.
- Atlas domain: Driver Families / drivers/w1.
- Implementation status: integration 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.