drivers/hwmon/sht15.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/sht15.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/sht15.c- Extension
.c- Size
- 27879 bytes
- Lines
- 1061
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/interrupt.hlinux/irq.hlinux/module.hlinux/init.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/mutex.hlinux/platform_device.hlinux/sched.hlinux/delay.hlinux/jiffies.hlinux/err.hlinux/regulator/consumer.hlinux/slab.hlinux/atomic.hlinux/bitrev.hlinux/gpio/consumer.hlinux/of.h
Detected Declarations
struct sht15_temppairstruct sht15_dataenum sht15_chipsenum sht15_statefunction sht15_crc8function sht15_connection_resetfunction sht15_send_bitfunction sht15_transmission_startfunction sht15_send_bytefunction sht15_wait_for_responsefunction sht15_send_cmdfunction sht15_soft_resetfunction sht15_ackfunction sht15_end_transmissionfunction sht15_read_bytefunction sht15_send_statusfunction sht15_update_statusfunction sht15_measurementfunction sht15_update_measurementsfunction sht15_calc_tempfunction sht15_calc_humidfunction sht15_status_showfunction sht15_status_storefunction sht15_temp_showfunction sht15_humidity_showfunction name_showfunction sht15_interrupt_firedfunction sht15_bh_read_datafunction sht15_update_voltagefunction sht15_invalidate_voltagefunction sht15_probefunction sht15_remove
Annotated Snippet
struct sht15_temppair {
int vdd; /* microvolts */
int d1;
};
/* Table 9 from datasheet - relates temperature calculation to supply voltage */
static const struct sht15_temppair temppoints[] = {
{ 2500000, -39400 },
{ 3000000, -39600 },
{ 3500000, -39700 },
{ 4000000, -39800 },
{ 5000000, -40100 },
};
/* Table from CRC datasheet, section 2.4 */
static const u8 sht15_crc8_table[] = {
0, 49, 98, 83, 196, 245, 166, 151,
185, 136, 219, 234, 125, 76, 31, 46,
67, 114, 33, 16, 135, 182, 229, 212,
250, 203, 152, 169, 62, 15, 92, 109,
134, 183, 228, 213, 66, 115, 32, 17,
63, 14, 93, 108, 251, 202, 153, 168,
197, 244, 167, 150, 1, 48, 99, 82,
124, 77, 30, 47, 184, 137, 218, 235,
61, 12, 95, 110, 249, 200, 155, 170,
132, 181, 230, 215, 64, 113, 34, 19,
126, 79, 28, 45, 186, 139, 216, 233,
199, 246, 165, 148, 3, 50, 97, 80,
187, 138, 217, 232, 127, 78, 29, 44,
2, 51, 96, 81, 198, 247, 164, 149,
248, 201, 154, 171, 60, 13, 94, 111,
65, 112, 35, 18, 133, 180, 231, 214,
122, 75, 24, 41, 190, 143, 220, 237,
195, 242, 161, 144, 7, 54, 101, 84,
57, 8, 91, 106, 253, 204, 159, 174,
128, 177, 226, 211, 68, 117, 38, 23,
252, 205, 158, 175, 56, 9, 90, 107,
69, 116, 39, 22, 129, 176, 227, 210,
191, 142, 221, 236, 123, 74, 25, 40,
6, 55, 100, 85, 194, 243, 160, 145,
71, 118, 37, 20, 131, 178, 225, 208,
254, 207, 156, 173, 58, 11, 88, 105,
4, 53, 102, 87, 192, 241, 162, 147,
189, 140, 223, 238, 121, 72, 27, 42,
193, 240, 163, 146, 5, 52, 103, 86,
120, 73, 26, 43, 188, 141, 222, 239,
130, 179, 224, 209, 70, 119, 36, 21,
59, 10, 89, 104, 255, 206, 157, 172
};
/**
* struct sht15_data - device instance specific data
* @sck: clock GPIO line
* @data: data GPIO line
* @read_work: bh of interrupt handler.
* @wait_queue: wait queue for getting values from device.
* @val_temp: last temperature value read from device.
* @val_humid: last humidity value read from device.
* @val_status: last status register value read from device.
* @checksum_ok: last value read from the device passed CRC validation.
* @checksumming: flag used to enable the data validation with CRC.
* @state: state identifying the action the driver is doing.
* @measurements_valid: are the current stored measures valid (start condition).
* @status_valid: is the current stored status valid (start condition).
* @last_measurement: time of last measure.
* @last_status: time of last status reading.
* @read_lock: mutex to ensure only one read in progress at a time.
* @dev: associate device structure.
* @hwmon_dev: device associated with hwmon subsystem.
* @reg: associated regulator (if specified).
* @nb: notifier block to handle notifications of voltage
* changes.
* @supply_uv: local copy of supply voltage used to allow use of
* regulator consumer if available.
* @supply_uv_valid: indicates that an updated value has not yet been
* obtained from the regulator and so any calculations
* based upon it will be invalid.
* @update_supply_work: work struct that is used to update the supply_uv.
* @interrupt_handled: flag used to indicate a handler has been scheduled.
*/
struct sht15_data {
struct gpio_desc *sck;
struct gpio_desc *data;
struct work_struct read_work;
wait_queue_head_t wait_queue;
uint16_t val_temp;
uint16_t val_humid;
u8 val_status;
bool checksum_ok;
bool checksumming;
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/irq.h`, `linux/module.h`, `linux/init.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/mutex.h`, `linux/platform_device.h`.
- Detected declarations: `struct sht15_temppair`, `struct sht15_data`, `enum sht15_chips`, `enum sht15_state`, `function sht15_crc8`, `function sht15_connection_reset`, `function sht15_send_bit`, `function sht15_transmission_start`, `function sht15_send_byte`, `function sht15_wait_for_response`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.