drivers/iio/light/st_uvis25_core.c

Source file repositories/reference/linux-study-clean/drivers/iio/light/st_uvis25_core.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/st_uvis25_core.c
Extension
.c
Size
8355 bytes
Lines
358
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

// SPDX-License-Identifier: GPL-2.0-only
/*
 * STMicroelectronics uvis25 sensor driver
 *
 * Copyright 2017 STMicroelectronics Inc.
 *
 * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/iio/sysfs.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/interrupt.h>
#include <linux/irqreturn.h>
#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include <linux/iio/buffer.h>
#include <linux/regmap.h>

#include "st_uvis25.h"

#define ST_UVIS25_REG_WHOAMI_ADDR	0x0f
#define ST_UVIS25_REG_WHOAMI_VAL	0xca
#define ST_UVIS25_REG_CTRL1_ADDR	0x20
#define ST_UVIS25_REG_ODR_MASK		BIT(0)
#define ST_UVIS25_REG_BDU_MASK		BIT(1)
#define ST_UVIS25_REG_CTRL2_ADDR	0x21
#define ST_UVIS25_REG_BOOT_MASK		BIT(7)
#define ST_UVIS25_REG_CTRL3_ADDR	0x22
#define ST_UVIS25_REG_HL_MASK		BIT(7)
#define ST_UVIS25_REG_STATUS_ADDR	0x27
#define ST_UVIS25_REG_UV_DA_MASK	BIT(0)
#define ST_UVIS25_REG_OUT_ADDR		0x28

static const struct iio_chan_spec st_uvis25_channels[] = {
	{
		.type = IIO_UVINDEX,
		.address = ST_UVIS25_REG_OUT_ADDR,
		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
		.scan_index = 0,
		.scan_type = {
			.sign = 'u',
			.realbits = 8,
			.storagebits = 8,
		},
	},
	IIO_CHAN_SOFT_TIMESTAMP(1),
};

static int st_uvis25_check_whoami(struct st_uvis25_hw *hw)
{
	int err, data;

	err = regmap_read(hw->regmap, ST_UVIS25_REG_WHOAMI_ADDR, &data);
	if (err < 0) {
		dev_err(regmap_get_device(hw->regmap),
			"failed to read whoami register\n");
		return err;
	}

	if (data != ST_UVIS25_REG_WHOAMI_VAL) {
		dev_err(regmap_get_device(hw->regmap),
			"wrong whoami {%02x vs %02x}\n",
			data, ST_UVIS25_REG_WHOAMI_VAL);
		return -ENODEV;
	}

	return 0;
}

static int st_uvis25_set_enable(struct st_uvis25_hw *hw, bool enable)
{
	int err;

	err = regmap_update_bits(hw->regmap, ST_UVIS25_REG_CTRL1_ADDR,
				 ST_UVIS25_REG_ODR_MASK, enable);
	if (err < 0)
		return err;

	hw->enabled = enable;

	return 0;
}

static int st_uvis25_read_oneshot(struct st_uvis25_hw *hw, u8 addr, int *val)
{

Annotation

Implementation Notes