drivers/hwmon/ds1621.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ds1621.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ds1621.c- Extension
.c- Size
- 11319 bytes
- Lines
- 393
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/mutex.hlinux/sysfs.hlinux/kernel.h
Detected Declarations
struct ds1621_dataenum chipsfunction DS1621_TEMP_FROM_REGfunction DS1621_TEMP_TO_REGfunction ds1621_init_clientfunction temp_showfunction temp_storefunction alarms_showfunction alarm_showfunction update_interval_showfunction update_interval_storefunction ds1621_attribute_visiblefunction ds1621_probe
Annotated Snippet
struct ds1621_data {
struct i2c_client *client;
struct mutex update_lock;
bool valid; /* true if following fields are valid */
unsigned long last_updated; /* In jiffies */
enum chips kind; /* device type */
u16 temp[3]; /* Register values, word */
u8 conf; /* Register encoding, combined */
u8 zbits; /* Resolution encoded as number of
* zero bits */
u16 update_interval; /* Conversion rate in milliseconds */
};
static inline int DS1621_TEMP_FROM_REG(u16 reg)
{
return DIV_ROUND_CLOSEST(((s16)reg / 16) * 625, 10);
}
/*
* TEMP: 0.001C/bit (-55C to +125C)
* REG:
* - 1621, 1625: 0.5C/bit, 7 zero-bits
* - 1631, 1721, 1731: 0.0625C/bit, 4 zero-bits
*/
static inline u16 DS1621_TEMP_TO_REG(long temp, u8 zbits)
{
temp = clamp_val(temp, DS1621_TEMP_MIN, DS1621_TEMP_MAX);
temp = DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits;
return temp;
}
static void ds1621_init_client(struct ds1621_data *data,
struct i2c_client *client)
{
u8 conf, new_conf, sreg, resol;
new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
/* switch to continuous conversion mode */
new_conf &= ~DS1621_REG_CONFIG_1SHOT;
/* setup output polarity */
if (polarity == 0)
new_conf &= ~DS1621_REG_CONFIG_POLARITY;
else if (polarity == 1)
new_conf |= DS1621_REG_CONFIG_POLARITY;
if (conf != new_conf)
i2c_smbus_write_byte_data(client, DS1621_REG_CONF, new_conf);
switch (data->kind) {
case ds1625:
data->update_interval = DS1625_CONVERSION_MAX;
data->zbits = 7;
sreg = DS1621_COM_START;
break;
case ds1631:
case ds1721:
case ds1731:
resol = (new_conf & DS1621_REG_CONFIG_RESOL) >>
DS1621_REG_CONFIG_RESOL_SHIFT;
data->update_interval = ds1721_convrates[resol];
data->zbits = 7 - resol;
sreg = DS1721_COM_START;
break;
default:
data->update_interval = DS1621_CONVERSION_MAX;
data->zbits = 7;
sreg = DS1621_COM_START;
break;
}
/* start conversion */
i2c_smbus_write_byte(client, sreg);
}
static struct ds1621_data *ds1621_update_client(struct device *dev)
{
struct ds1621_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
u8 new_conf;
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + data->update_interval) ||
!data->valid) {
int i;
dev_dbg(&client->dev, "Starting ds1621 update\n");
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`.
- Detected declarations: `struct ds1621_data`, `enum chips`, `function DS1621_TEMP_FROM_REG`, `function DS1621_TEMP_TO_REG`, `function ds1621_init_client`, `function temp_show`, `function temp_store`, `function alarms_show`, `function alarm_show`, `function update_interval_show`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.