drivers/iio/light/as73211.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/as73211.c
Extension
.c
Size
24680 bytes
Lines
898
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 as73211_spec_dev_data {
	int (*intensity_scale)(struct as73211_data *data, int chan, int *val, int *val2);
	struct iio_chan_spec const *channels;
	int num_channels;
};

/**
 * struct as73211_data - Instance data for one AS73211
 * @client: I2C client.
 * @osr:    Cached Operational State Register.
 * @creg1:  Cached Configuration Register 1.
 * @creg2:  Cached Configuration Register 2.
 * @creg3:  Cached Configuration Register 3.
 * @mutex:  Keeps cached registers in sync with the device.
 * @completion: Completion to wait for interrupt.
 * @int_time_avail: Available integration times (depend on sampling frequency).
 * @spec_dev: device-specific configuration.
 */
struct as73211_data {
	struct i2c_client *client;
	u8 osr;
	u8 creg1;
	u8 creg2;
	u8 creg3;
	struct mutex mutex;
	struct completion completion;
	int int_time_avail[AS73211_SAMPLE_TIME_NUM * 2];
	const struct as73211_spec_dev_data *spec_dev;
};

#define AS73211_COLOR_CHANNEL(_color, _si, _addr) { \
	.type = IIO_INTENSITY, \
	.modified = 1, \
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
	.info_mask_shared_by_type = \
		BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
		BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \
		BIT(IIO_CHAN_INFO_INT_TIME), \
	.info_mask_shared_by_type_available = \
		BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
		BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \
		BIT(IIO_CHAN_INFO_INT_TIME), \
	.channel2 = IIO_MOD_##_color, \
	.address = _addr, \
	.scan_index = _si, \
	.scan_type = { \
		.sign = 'u', \
		.realbits = 16, \
		.storagebits = 16, \
		.endianness = IIO_LE, \
	}, \
}

#define AS73211_OFFSET_TEMP_INT    (-66)
#define AS73211_OFFSET_TEMP_MICRO  900000
#define AS73211_SCALE_TEMP_INT     0
#define AS73211_SCALE_TEMP_MICRO   50000

#define AS73211_SCALE_X 277071108  /* nW/m^2 */
#define AS73211_SCALE_Y 298384270  /* nW/m^2 */
#define AS73211_SCALE_Z 160241927  /* nW/m^2 */

#define AS7331_SCALE_UVA 340000  /* nW/cm^2 */
#define AS7331_SCALE_UVB 378000  /* nW/cm^2 */
#define AS7331_SCALE_UVC 166000  /* nW/cm^2 */

/* Channel order MUST match devices result register order */
#define AS73211_SCAN_INDEX_TEMP 0
#define AS73211_SCAN_INDEX_X    1
#define AS73211_SCAN_INDEX_Y    2
#define AS73211_SCAN_INDEX_Z    3
#define AS73211_SCAN_INDEX_TS   4

#define AS73211_SCAN_MASK_COLOR ( \
	BIT(AS73211_SCAN_INDEX_X) |   \
	BIT(AS73211_SCAN_INDEX_Y) |   \
	BIT(AS73211_SCAN_INDEX_Z))

#define AS73211_SCAN_MASK_ALL (    \
	BIT(AS73211_SCAN_INDEX_TEMP) | \
	AS73211_SCAN_MASK_COLOR)

static const unsigned long as73211_scan_masks[] = {
	AS73211_SCAN_MASK_COLOR,
	AS73211_SCAN_MASK_ALL,
	0
};

static const struct iio_chan_spec as73211_channels[] = {
	{

Annotation

Implementation Notes