drivers/hwmon/hih6130.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/hih6130.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/hih6130.c- Extension
.c- Size
- 7229 bytes
- Lines
- 261
- 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/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/mutex.hlinux/device.hlinux/delay.hlinux/jiffies.h
Detected Declarations
struct hih6130function hih6130_temp_ticks_to_millicelsiusfunction hih6130_rh_ticks_to_per_cent_millefunction hih6130_update_measurementsfunction hih6130_temperature_showfunction hih6130_humidity_showfunction hih6130_probe
Annotated Snippet
struct hih6130 {
struct i2c_client *client;
struct mutex lock;
bool valid;
unsigned long last_update;
int temperature;
int humidity;
size_t write_length;
};
/**
* hih6130_temp_ticks_to_millicelsius() - convert raw temperature ticks to
* milli celsius
* @ticks: temperature ticks value received from sensor
*/
static inline int hih6130_temp_ticks_to_millicelsius(int ticks)
{
ticks = ticks >> 2;
/*
* from data sheet section 5.0
* Formula T = ( ticks / ( 2^14 - 2 ) ) * 165 -40
*/
return (DIV_ROUND_CLOSEST(ticks * 1650, 16382) - 400) * 100;
}
/**
* hih6130_rh_ticks_to_per_cent_mille() - convert raw humidity ticks to
* one-thousandths of a percent relative humidity
* @ticks: humidity ticks value received from sensor
*/
static inline int hih6130_rh_ticks_to_per_cent_mille(int ticks)
{
ticks &= ~0xC000; /* clear status bits */
/*
* from data sheet section 4.0
* Formula RH = ( ticks / ( 2^14 -2 ) ) * 100
*/
return DIV_ROUND_CLOSEST(ticks * 1000, 16382) * 100;
}
/**
* hih6130_update_measurements() - get updated measurements from device
* @dev: device
*
* Returns 0 on success, else negative errno.
*/
static int hih6130_update_measurements(struct device *dev)
{
struct hih6130 *hih6130 = dev_get_drvdata(dev);
struct i2c_client *client = hih6130->client;
int ret = 0;
int t;
unsigned char tmp[4];
struct i2c_msg msgs[1] = {
{
.addr = client->addr,
.flags = I2C_M_RD,
.len = 4,
.buf = tmp,
}
};
mutex_lock(&hih6130->lock);
/*
* While the measurement can be completed in ~40ms the sensor takes
* much longer to react to a change in external conditions. How quickly
* it reacts depends on airflow and other factors outwith our control.
* The datasheet specifies maximum 'Response time' for humidity at 8s
* and temperature at 30s under specified conditions.
* We therefore choose to only read the sensor at most once per second.
* This trades off pointless activity polling the sensor much faster
* than it can react against better response times in conditions more
* favourable than specified in the datasheet.
*/
if (time_after(jiffies, hih6130->last_update + HZ) || !hih6130->valid) {
/*
* Write to slave address to request a measurement.
* According with the datasheet it should be with no data, but
* for systems with I2C bus drivers that do not allow zero
* length packets we write one dummy byte to allow sensor
* measurements on them.
*/
tmp[0] = 0;
ret = i2c_master_send(client, tmp, hih6130->write_length);
if (ret < 0)
goto out;
/* measurement cycle time is ~36.65msec */
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`, `linux/mutex.h`.
- Detected declarations: `struct hih6130`, `function hih6130_temp_ticks_to_millicelsius`, `function hih6130_rh_ticks_to_per_cent_mille`, `function hih6130_update_measurements`, `function hih6130_temperature_show`, `function hih6130_humidity_show`, `function hih6130_probe`.
- 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.