drivers/base/regmap/regmap-w1.c
Source file repositories/reference/linux-study-clean/drivers/base/regmap/regmap-w1.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/regmap/regmap-w1.c- Extension
.c- Size
- 5562 bytes
- Lines
- 239
- Domain
- Driver Families
- Bucket
- drivers/base
- 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/regmap.hlinux/module.hlinux/w1.hinternal.h
Detected Declarations
function w1_reg_a8_v8_readfunction w1_reg_a8_v8_writefunction w1_reg_a8_v16_readfunction w1_reg_a8_v16_writefunction w1_reg_a16_v16_readfunction w1_reg_a16_v16_writeexport __regmap_init_w1export __devm_regmap_init_w1
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
//
// Register map access API - W1 (1-Wire) support
//
// Copyright (c) 2017 Radioavionica Corporation
// Author: Alex A. Mihaylov <minimumlaw@rambler.ru>
#include <linux/regmap.h>
#include <linux/module.h>
#include <linux/w1.h>
#include "internal.h"
#define W1_CMD_READ_DATA 0x69
#define W1_CMD_WRITE_DATA 0x6C
/*
* 1-Wire slaves registers with addess 8 bit and data 8 bit
*/
static int w1_reg_a8_v8_read(void *context, unsigned int reg, unsigned int *val)
{
struct device *dev = context;
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
int ret = 0;
if (reg > 255)
return -EINVAL;
mutex_lock(&sl->master->bus_mutex);
if (!w1_reset_select_slave(sl)) {
w1_write_8(sl->master, W1_CMD_READ_DATA);
w1_write_8(sl->master, reg);
*val = w1_read_8(sl->master);
} else {
ret = -ENODEV;
}
mutex_unlock(&sl->master->bus_mutex);
return ret;
}
static int w1_reg_a8_v8_write(void *context, unsigned int reg, unsigned int val)
{
struct device *dev = context;
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
int ret = 0;
if (reg > 255)
return -EINVAL;
mutex_lock(&sl->master->bus_mutex);
if (!w1_reset_select_slave(sl)) {
w1_write_8(sl->master, W1_CMD_WRITE_DATA);
w1_write_8(sl->master, reg);
w1_write_8(sl->master, val);
} else {
ret = -ENODEV;
}
mutex_unlock(&sl->master->bus_mutex);
return ret;
}
/*
* 1-Wire slaves registers with addess 8 bit and data 16 bit
*/
static int w1_reg_a8_v16_read(void *context, unsigned int reg,
unsigned int *val)
{
struct device *dev = context;
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
int ret = 0;
if (reg > 255)
return -EINVAL;
mutex_lock(&sl->master->bus_mutex);
if (!w1_reset_select_slave(sl)) {
w1_write_8(sl->master, W1_CMD_READ_DATA);
w1_write_8(sl->master, reg);
*val = w1_read_8(sl->master);
*val |= w1_read_8(sl->master)<<8;
} else {
ret = -ENODEV;
}
mutex_unlock(&sl->master->bus_mutex);
return ret;
Annotation
- Immediate include surface: `linux/regmap.h`, `linux/module.h`, `linux/w1.h`, `internal.h`.
- Detected declarations: `function w1_reg_a8_v8_read`, `function w1_reg_a8_v8_write`, `function w1_reg_a8_v16_read`, `function w1_reg_a8_v16_write`, `function w1_reg_a16_v16_read`, `function w1_reg_a16_v16_write`, `export __regmap_init_w1`, `export __devm_regmap_init_w1`.
- Atlas domain: Driver Families / drivers/base.
- 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.