drivers/iio/light/max44000.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/max44000.c
Extension
.c
Size
16627 bytes
Lines
626
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 max44000_data {
	struct mutex lock;
	struct regmap *regmap;
};

/* Default scale is set to the minimum of 0.03125 or 1 / (1 << 5) lux */
#define MAX44000_ALS_TO_LUX_DEFAULT_FRACTION_LOG2 5

/* Scale can be multiplied by up to 128x via ALSPGA for measurement gain */
static const int max44000_alspga_shift[] = {0, 2, 4, 7};
#define MAX44000_ALSPGA_MAX_SHIFT 7

/*
 * Scale can be multiplied by up to 64x via ALSTIM because of lost resolution
 *
 * This scaling factor is hidden from userspace and instead accounted for when
 * reading raw values from the device.
 *
 * This makes it possible to cleanly expose ALSPGA as IIO_CHAN_INFO_SCALE and
 * ALSTIM as IIO_CHAN_INFO_INT_TIME without the values affecting each other.
 *
 * Handling this internally is also required for buffer support because the
 * channel's scan_type can't be modified dynamically.
 */
#define MAX44000_ALSTIM_SHIFT(alstim) (2 * (alstim))

/* Available integration times with pretty manual alignment: */
static const int max44000_int_time_avail_ns_array[] = {
	   100000000,
	    25000000,
	     6250000,
	     1562500,
};
static const char max44000_int_time_avail_str[] =
	"0.100 "
	"0.025 "
	"0.00625 "
	"0.0015625";

/* Available scales (internal to ulux) with pretty manual alignment: */
static const int max44000_scale_avail_ulux_array[] = {
	    31250,
	   125000,
	   500000,
	  4000000,
};
static const char max44000_scale_avail_str[] =
	"0.03125 "
	"0.125 "
	"0.5 "
	 "4";

#define MAX44000_SCAN_INDEX_ALS 0
#define MAX44000_SCAN_INDEX_PRX 1

static const struct iio_chan_spec max44000_channels[] = {
	{
		.type = IIO_LIGHT,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
					    BIT(IIO_CHAN_INFO_INT_TIME),
		.scan_index = MAX44000_SCAN_INDEX_ALS,
		.scan_type = {
			.sign		= 'u',
			.realbits	= 14,
			.storagebits	= 16,
		}
	},
	{
		.type = IIO_PROXIMITY,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
		.scan_index = MAX44000_SCAN_INDEX_PRX,
		.scan_type = {
			.sign		= 'u',
			.realbits	= 8,
			.storagebits	= 16,
		}
	},
	IIO_CHAN_SOFT_TIMESTAMP(2),
	{
		.type = IIO_CURRENT,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				      BIT(IIO_CHAN_INFO_SCALE),
		.extend_name = "led",
		.output = 1,
		.scan_index = -1,
	},
};

static int max44000_read_alstim(struct max44000_data *data)

Annotation

Implementation Notes