drivers/w1/masters/ds2482.c
Source file repositories/reference/linux-study-clean/drivers/w1/masters/ds2482.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/w1/masters/ds2482.c- Extension
.c- Size
- 15253 bytes
- Lines
- 562
- 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.
- 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/module.hlinux/init.hlinux/slab.hlinux/i2c.hlinux/delay.hlinux/regulator/consumer.hlinux/w1.h
Detected Declarations
struct ds2482_datastruct ds2482_w1_chanstruct ds2482_datafunction ds2482_calculate_configfunction ds2482_select_registerfunction ds2482_send_cmdfunction ds2482_send_cmd_datafunction ds2482_wait_1wire_idlefunction ds2482_set_channelfunction ds2482_w1_touch_bitfunction ds2482_w1_tripletfunction ds2482_w1_write_bytefunction ds2482_w1_read_bytefunction ds2482_w1_reset_busfunction ds2482_w1_set_pullupfunction ds2482_probefunction ds2482_remove
Annotated Snippet
struct ds2482_w1_chan {
struct ds2482_data *pdev;
u8 channel;
struct w1_bus_master w1_bm;
};
struct ds2482_data {
struct i2c_client *client;
struct mutex access_lock;
/* 1-wire interface(s) */
int w1_count; /* 1 or 8 */
struct ds2482_w1_chan w1_ch[8];
/* per-device values */
u8 channel;
u8 read_prt; /* see DS2482_PTR_CODE_xxx */
u8 reg_config;
};
/**
* ds2482_calculate_config - Helper to calculate values for configuration register
* @conf: the raw config value
* Return: the value w/ complements that can be written to register
*/
static inline u8 ds2482_calculate_config(u8 conf)
{
conf |= extra_config;
if (ds2482_active_pullup)
conf |= DS2482_REG_CFG_APU;
return conf | ((~conf & 0x0f) << 4);
}
/**
* ds2482_select_register - Sets the read pointer.
* @pdev: The ds2482 client pointer
* @read_ptr: see DS2482_PTR_CODE_xxx above
* Return: -1 on failure, 0 on success
*/
static inline int ds2482_select_register(struct ds2482_data *pdev, u8 read_ptr)
{
if (pdev->read_prt != read_ptr) {
if (i2c_smbus_write_byte_data(pdev->client,
DS2482_CMD_SET_READ_PTR,
read_ptr) < 0)
return -1;
pdev->read_prt = read_ptr;
}
return 0;
}
/**
* ds2482_send_cmd - Sends a command without a parameter
* @pdev: The ds2482 client pointer
* @cmd: DS2482_CMD_RESET,
* DS2482_CMD_1WIRE_RESET,
* DS2482_CMD_1WIRE_READ_BYTE
* Return: -1 on failure, 0 on success
*/
static inline int ds2482_send_cmd(struct ds2482_data *pdev, u8 cmd)
{
if (i2c_smbus_write_byte(pdev->client, cmd) < 0)
return -1;
pdev->read_prt = DS2482_PTR_CODE_STATUS;
return 0;
}
/**
* ds2482_send_cmd_data - Sends a command with a parameter
* @pdev: The ds2482 client pointer
* @cmd: DS2482_CMD_WRITE_CONFIG,
* DS2482_CMD_1WIRE_SINGLE_BIT,
* DS2482_CMD_1WIRE_WRITE_BYTE,
* DS2482_CMD_1WIRE_TRIPLET
* @byte: The data to send
* Return: -1 on failure, 0 on success
*/
static inline int ds2482_send_cmd_data(struct ds2482_data *pdev,
u8 cmd, u8 byte)
{
if (i2c_smbus_write_byte_data(pdev->client, cmd, byte) < 0)
return -1;
/* all cmds leave in STATUS, except CONFIG */
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/i2c.h`, `linux/delay.h`, `linux/regulator/consumer.h`, `linux/w1.h`.
- Detected declarations: `struct ds2482_data`, `struct ds2482_w1_chan`, `struct ds2482_data`, `function ds2482_calculate_config`, `function ds2482_select_register`, `function ds2482_send_cmd`, `function ds2482_send_cmd_data`, `function ds2482_wait_1wire_idle`, `function ds2482_set_channel`, `function ds2482_w1_touch_bit`.
- 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.