drivers/hwmon/sht3x.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/sht3x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/sht3x.c- Extension
.c- Size
- 23116 bytes
- Lines
- 953
- 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
asm/page.hlinux/crc8.hlinux/debugfs.hlinux/delay.hlinux/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/i2c.hlinux/init.hlinux/kernel.hlinux/module.hlinux/slab.hlinux/jiffies.h
Detected Declarations
struct sht3x_limit_commandsstruct sht3x_dataenum sht3x_chipsenum sht3x_limitsenum sht3x_repeatabilityfunction get_mode_from_update_intervalfunction sht3x_read_from_commandfunction sht3x_extract_temperaturefunction sht3x_extract_humidityfunction temp1_input_readfunction humidity1_input_readfunction limits_updatefunction temp1_limit_readfunction humidity1_limit_readfunction limit_writefunction temp1_limit_writefunction humidity1_limit_writefunction sht3x_select_commandfunction status_register_readfunction temp1_alarm_readfunction humidity1_alarm_readfunction heater_enable_showfunction heater_enable_storefunction update_interval_readfunction update_interval_writefunction shotfunction repeatability_showfunction repeatability_storefunction sht3x_is_visiblefunction sht3x_readfunction sht3x_writefunction sht3x_serial_number_readfunction sht3x_probe
Annotated Snippet
struct sht3x_limit_commands {
const char read_command[SHT3X_CMD_LENGTH];
const char write_command[SHT3X_CMD_LENGTH];
};
static const struct sht3x_limit_commands limit_commands[] = {
/* temp1_max, humidity1_max */
[limit_max] = { {0xe1, 0x1f}, {0x61, 0x1d} },
/* temp_1_max_hyst, humidity1_max_hyst */
[limit_max_hyst] = { {0xe1, 0x14}, {0x61, 0x16} },
/* temp1_min, humidity1_min */
[limit_min] = { {0xe1, 0x02}, {0x61, 0x00} },
/* temp_1_min_hyst, humidity1_min_hyst */
[limit_min_hyst] = { {0xe1, 0x09}, {0x61, 0x0B} },
};
#define SHT3X_NUM_LIMIT_CMD ARRAY_SIZE(limit_commands)
static const u16 mode_to_update_interval[] = {
0,
2000,
1000,
500,
250,
100,
};
static const struct hwmon_channel_info * const sht3x_channel_info[] = {
HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL),
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_MIN |
HWMON_T_MIN_HYST | HWMON_T_MAX |
HWMON_T_MAX_HYST | HWMON_T_ALARM),
HWMON_CHANNEL_INFO(humidity, HWMON_H_INPUT | HWMON_H_MIN |
HWMON_H_MIN_HYST | HWMON_H_MAX |
HWMON_H_MAX_HYST | HWMON_H_ALARM),
NULL,
};
struct sht3x_data {
struct i2c_client *client;
enum sht3x_chips chip_id;
struct mutex i2c_lock; /* lock for sending i2c commands */
struct mutex data_lock; /* lock for updating driver data */
u8 mode;
const unsigned char *command;
u32 wait_time; /* in us*/
unsigned long last_update; /* last update in periodic mode*/
enum sht3x_repeatability repeatability;
u32 serial_number;
/*
* cached values for temperature and humidity and limits
* the limits arrays have the following order:
* max, max_hyst, min, min_hyst
*/
int temperature;
int temperature_limits[SHT3X_NUM_LIMIT_CMD];
u32 humidity;
u32 humidity_limits[SHT3X_NUM_LIMIT_CMD];
};
static u8 get_mode_from_update_interval(u16 value)
{
size_t index;
u8 number_of_modes = ARRAY_SIZE(mode_to_update_interval);
if (value == 0)
return 0;
/* find next faster update interval */
for (index = 1; index < number_of_modes; index++) {
if (mode_to_update_interval[index] <= value)
return index;
}
return number_of_modes - 1;
}
static int sht3x_read_from_command(struct i2c_client *client,
struct sht3x_data *data,
const char *command,
char *buf, int length, u32 wait_time)
{
int ret;
mutex_lock(&data->i2c_lock);
ret = i2c_master_send(client, command, SHT3X_CMD_LENGTH);
if (ret != SHT3X_CMD_LENGTH) {
Annotation
- Immediate include surface: `asm/page.h`, `linux/crc8.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/err.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/i2c.h`.
- Detected declarations: `struct sht3x_limit_commands`, `struct sht3x_data`, `enum sht3x_chips`, `enum sht3x_limits`, `enum sht3x_repeatability`, `function get_mode_from_update_interval`, `function sht3x_read_from_command`, `function sht3x_extract_temperature`, `function sht3x_extract_humidity`, `function temp1_input_read`.
- 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.