drivers/hwmon/stts751.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/stts751.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/stts751.c- Extension
.c- Size
- 21279 bytes
- Lines
- 835
- 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/bitops.hlinux/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/jiffies.hlinux/module.hlinux/mutex.hlinux/property.hlinux/slab.hlinux/sysfs.hlinux/util_macros.h
Detected Declarations
struct stts751_privfunction stts751_to_degfunction stts751_to_hwfunction stts751_adjust_resolutionfunction stts751_update_tempfunction stts751_set_temp_reg16function stts751_set_temp_reg8function stts751_read_reg16function stts751_read_reg8function stts751_update_alertfunction stts751_alertfunction stts751_updatefunction max_alarm_showfunction min_alarm_showfunction input_showfunction therm_showfunction therm_storefunction hyst_showfunction hyst_storefunction therm_trip_showfunction max_showfunction max_storefunction min_showfunction min_storefunction interval_showfunction interval_storefunction stts751_detectfunction stts751_read_chip_configfunction stts751_probe
Annotated Snippet
struct stts751_priv {
struct device *dev;
struct i2c_client *client;
struct mutex access_lock;
u8 interval;
int res;
int event_max, event_min;
int therm;
int hyst;
int temp;
unsigned long last_update, last_alert_update;
u8 config;
bool min_alert, max_alert, therm_trip;
bool data_valid, alert_valid;
bool notify_max, notify_min;
};
/*
* These functions converts temperature from HW format to integer format and
* vice-vers. They are (mostly) taken from lm90 driver. Unit is in mC.
*/
static int stts751_to_deg(s16 hw_val)
{
return hw_val * 125 / 32;
}
static s32 stts751_to_hw(int val)
{
return DIV_ROUND_CLOSEST(val, 125) * 32;
}
static int stts751_adjust_resolution(struct stts751_priv *priv)
{
u8 res;
switch (priv->interval) {
case 9:
/* 10 bits */
res = 0;
break;
case 8:
/* 11 bits */
res = 1;
break;
default:
/* 12 bits */
res = 3;
break;
}
if (priv->res == res)
return 0;
priv->config &= ~STTS751_CONF_RES_MASK;
priv->config |= res << STTS751_CONF_RES_SHIFT;
dev_dbg(&priv->client->dev, "setting res %d. config %x",
res, priv->config);
priv->res = res;
return i2c_smbus_write_byte_data(priv->client,
STTS751_REG_CONF, priv->config);
}
static int stts751_update_temp(struct stts751_priv *priv)
{
s32 integer1, integer2, frac;
/*
* There is a trick here, like in the lm90 driver. We have to read two
* registers to get the sensor temperature, but we have to beware a
* conversion could occur between the readings. We could use the
* one-shot conversion register, but we don't want to do this (disables
* hardware monitoring). So the solution used here is to read the high
* byte once, then the low byte, then the high byte again. If the new
* high byte matches the old one, then we have a valid reading. Else we
* have to read the low byte again, and now we believe we have a correct
* reading.
*/
integer1 = i2c_smbus_read_byte_data(priv->client, STTS751_REG_TEMP_H);
if (integer1 < 0) {
dev_dbg(&priv->client->dev,
"I2C read failed (temp H). ret: %x\n", integer1);
return integer1;
}
frac = i2c_smbus_read_byte_data(priv->client, STTS751_REG_TEMP_L);
if (frac < 0) {
dev_dbg(&priv->client->dev,
"I2C read failed (temp L). ret: %x\n", frac);
return frac;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/err.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`, `linux/jiffies.h`.
- Detected declarations: `struct stts751_priv`, `function stts751_to_deg`, `function stts751_to_hw`, `function stts751_adjust_resolution`, `function stts751_update_temp`, `function stts751_set_temp_reg16`, `function stts751_set_temp_reg8`, `function stts751_read_reg16`, `function stts751_read_reg8`, `function stts751_update_alert`.
- 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.