drivers/iio/chemical/atlas-ezo-sensor.c

Source file repositories/reference/linux-study-clean/drivers/iio/chemical/atlas-ezo-sensor.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/chemical/atlas-ezo-sensor.c
Extension
.c
Size
5497 bytes
Lines
245
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 atlas_ezo_device {
	const struct iio_chan_spec *channels;
	int num_channels;
	int delay;
};

struct atlas_ezo_data {
	struct i2c_client *client;
	const struct atlas_ezo_device *chip;

	/* lock to avoid multiple concurrent read calls */
	struct mutex lock;

	u8 buffer[8];
};

#define ATLAS_CONCENTRATION_CHANNEL(_modifier) \
	{ \
		.type = IIO_CONCENTRATION, \
		.modified = 1,\
		.channel2 = _modifier, \
		.info_mask_separate = \
			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
		.scan_index = 0, \
		.scan_type =  { \
			.sign = 'u', \
			.realbits = 32, \
			.storagebits = 32, \
			.endianness = IIO_CPU, \
		}, \
	}

static const struct iio_chan_spec atlas_co2_ezo_channels[] = {
	ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2),
};

static const struct iio_chan_spec atlas_o2_ezo_channels[] = {
	ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2),
};

static const struct iio_chan_spec atlas_hum_ezo_channels[] = {
	{
		.type = IIO_HUMIDITYRELATIVE,
		.info_mask_separate =
			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
		.scan_index = 0,
		.scan_type =  {
			.sign = 'u',
			.realbits = 32,
			.storagebits = 32,
			.endianness = IIO_CPU,
		},
	},
};

static const struct atlas_ezo_device atlas_ezo_devices[] = {
	[ATLAS_CO2_EZO] = {
		.channels = atlas_co2_ezo_channels,
		.num_channels = 1,
		.delay = ATLAS_INT_TIME_IN_MS,
	},
	[ATLAS_O2_EZO] = {
		.channels = atlas_o2_ezo_channels,
		.num_channels = 1,
		.delay = ATLAS_INT_TIME_IN_MS,
	},
	[ATLAS_HUM_EZO] = {
		.channels = atlas_hum_ezo_channels,
		.num_channels = 1,
		.delay = ATLAS_INT_HUM_TIME_IN_MS,
	},
};

static void atlas_ezo_sanitize(char *buf)
{
	char *ptr = strchr(buf, '.');

	if (!ptr)
		return;

	memmove(ptr, ptr + 1, strlen(ptr));
}

static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
			  struct iio_chan_spec const *chan,
			  int *val, int *val2, long mask)
{
	struct atlas_ezo_data *data = iio_priv(indio_dev);
	struct i2c_client *client = data->client;

Annotation

Implementation Notes