drivers/hwmon/aht10.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/aht10.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/aht10.c- Extension
.c- Size
- 9828 bytes
- Lines
- 401
- 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.
- 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/delay.hlinux/hwmon.hlinux/i2c.hlinux/ktime.hlinux/module.hlinux/crc8.h
Detected Declarations
struct aht10_dataenum aht10_variantfunction aht10_initfunction aht10_polltime_expiredfunction crc8_checkfunction aht10_read_valuesfunction aht10_interval_writefunction aht10_interval_readfunction aht10_temperature1_readfunction aht10_humidity1_readfunction aht10_hwmon_visiblefunction aht10_hwmon_readfunction aht10_hwmon_writefunction aht10_probe
Annotated Snippet
struct aht10_data {
struct i2c_client *client;
ktime_t min_poll_interval;
ktime_t previous_poll_time;
int temperature;
int humidity;
bool crc8;
unsigned int meas_size;
u8 init_cmd;
};
/*
* aht10_init() - Initialize an AHT10/AHT20 chip
* @data: the data associated with this AHT10/AHT20 chip
* Return: 0 if successful, 1 if not
*/
static int aht10_init(struct aht10_data *data)
{
const u8 cmd_init[] = {data->init_cmd, AHT10_CAL_ENABLED | AHT10_MODE_CYC,
0x00};
int res;
u8 status;
struct i2c_client *client = data->client;
res = i2c_master_send(client, cmd_init, sizeof(cmd_init));
if (res < 0)
return res;
usleep_range(AHT10_CMD_DELAY, AHT10_CMD_DELAY +
AHT10_DELAY_EXTRA);
res = i2c_master_recv(client, &status, 1);
if (res != 1)
return -ENODATA;
if (status & AHT10_BUSY)
return -EBUSY;
return 0;
}
/*
* aht10_polltime_expired() - check if the minimum poll interval has
* expired
* @data: the data containing the time to compare
* Return: 1 if the minimum poll interval has expired, 0 if not
*/
static int aht10_polltime_expired(struct aht10_data *data)
{
ktime_t current_time = ktime_get_boottime();
ktime_t difference = ktime_sub(current_time, data->previous_poll_time);
return ktime_after(difference, data->min_poll_interval);
}
DECLARE_CRC8_TABLE(crc8_table);
/*
* crc8_check() - check crc of the sensor's measurements
* @raw_data: data frame received from sensor(including crc as the last byte)
* @count: size of the data frame
* Return: 0 if successful, 1 if not
*/
static int crc8_check(u8 *raw_data, int count)
{
/*
* crc calculated on the whole frame(including crc byte) should yield
* zero in case of correctly received bytes
*/
return crc8(crc8_table, raw_data, count, CRC8_INIT_VALUE);
}
/*
* aht10_read_values() - read and parse the raw data from the AHT10/AHT20
* @data: the struct aht10_data to use for the lock
* Return: 0 if successful, 1 if not
*/
static int aht10_read_values(struct aht10_data *data)
{
const u8 cmd_meas[] = {AHT10_CMD_MEAS, 0x33, 0x00};
u32 temp, hum;
int res;
u8 raw_data[AHT20_MEAS_SIZE];
struct i2c_client *client = data->client;
if (!aht10_polltime_expired(data))
return 0;
res = i2c_master_send(client, cmd_meas, sizeof(cmd_meas));
if (res < 0)
Annotation
- Immediate include surface: `linux/delay.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/ktime.h`, `linux/module.h`, `linux/crc8.h`.
- Detected declarations: `struct aht10_data`, `enum aht10_variant`, `function aht10_init`, `function aht10_polltime_expired`, `function crc8_check`, `function aht10_read_values`, `function aht10_interval_write`, `function aht10_interval_read`, `function aht10_temperature1_read`, `function aht10_humidity1_read`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
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.