drivers/iio/humidity/hdc2010.c

Source file repositories/reference/linux-study-clean/drivers/iio/humidity/hdc2010.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/humidity/hdc2010.c
Extension
.c
Size
8476 bytes
Lines
347
Domain
Driver Families
Bucket
drivers/iio
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct hdc2010_data {
	struct i2c_client *client;
	struct mutex lock;
	u8 measurement_config;
	u8 drdy_config;
};

enum hdc2010_addr_groups {
	HDC2010_GROUP_TEMP = 0,
	HDC2010_GROUP_HUMIDITY,
};

struct hdc2010_reg_record {
	unsigned long primary;
	unsigned long peak;
};

static const struct hdc2010_reg_record hdc2010_reg_translation[] = {
	[HDC2010_GROUP_TEMP] = {
		.primary = HDC2010_REG_TEMP_LOW,
		.peak = HDC2010_REG_TEMP_MAX,
	},
	[HDC2010_GROUP_HUMIDITY] = {
		.primary = HDC2010_REG_HUMIDITY_LOW,
		.peak = HDC2010_REG_HUMIDITY_MAX,
	},
};

static IIO_CONST_ATTR(out_current_heater_raw_available, "0 1");

static struct attribute *hdc2010_attributes[] = {
	&iio_const_attr_out_current_heater_raw_available.dev_attr.attr,
	NULL
};

static const struct attribute_group hdc2010_attribute_group = {
	.attrs = hdc2010_attributes,
};

static const struct iio_chan_spec hdc2010_channels[] = {
	{
		.type = IIO_TEMP,
		.address = HDC2010_GROUP_TEMP,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
			BIT(IIO_CHAN_INFO_PEAK) |
			BIT(IIO_CHAN_INFO_OFFSET) |
			BIT(IIO_CHAN_INFO_SCALE),
	},
	{
		.type = IIO_HUMIDITYRELATIVE,
		.address = HDC2010_GROUP_HUMIDITY,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
			BIT(IIO_CHAN_INFO_PEAK) |
			BIT(IIO_CHAN_INFO_SCALE),
	},
	{
		.type = IIO_CURRENT,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
		.extend_name = "heater",
		.output = 1,
	},
};

static int hdc2010_update_drdy_config(struct hdc2010_data *data,
					     char mask, char val)
{
	u8 tmp = (~mask & data->drdy_config) | val;
	int ret;

	ret = i2c_smbus_write_byte_data(data->client,
					HDC2010_REG_RESET_DRDY_INT_CONF, tmp);
	if (ret)
		return ret;

	data->drdy_config = tmp;

	return 0;
}

static int hdc2010_get_prim_measurement_word(struct hdc2010_data *data,
					     struct iio_chan_spec const *chan)
{
	struct i2c_client *client = data->client;
	s32 ret;

	ret = i2c_smbus_read_word_data(client,
			hdc2010_reg_translation[chan->address].primary);

	if (ret < 0)
		dev_err(&client->dev, "Could not read sensor measurement word\n");

Annotation

Implementation Notes