drivers/iio/imu/smi330/smi330_core.c

Source file repositories/reference/linux-study-clean/drivers/iio/imu/smi330/smi330_core.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/imu/smi330/smi330_core.c
Extension
.c
Size
23110 bytes
Lines
914
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

struct smi330_attributes {
	int *reg_vals;
	int *vals;
	int len;
	int type;
	int mask;
};

struct smi330_cfg {
	enum smi330_operation_mode op_mode;
	enum smi330_int_out data_irq;
};

struct smi330_data {
	struct regmap *regmap;
	struct smi330_cfg cfg;
	struct iio_trigger *trig;
	IIO_DECLARE_BUFFER_WITH_TS(__le16, buf, SMI330_SCAN_LEN);
};

const struct regmap_config smi330_regmap_config = {
	.reg_bits = 8,
	.val_bits = 16,
	.val_format_endian = REGMAP_ENDIAN_LITTLE,
};
EXPORT_SYMBOL_NS_GPL(smi330_regmap_config, "IIO_SMI330");

static const struct iio_chan_spec smi330_channels[] = {
	SMI330_ACCEL_CHANNEL(X),
	SMI330_ACCEL_CHANNEL(Y),
	SMI330_ACCEL_CHANNEL(Z),
	SMI330_GYRO_CHANNEL(X),
	SMI330_GYRO_CHANNEL(Y),
	SMI330_GYRO_CHANNEL(Z),
	SMI330_TEMP_CHANNEL(-1), /* No buffer support */
	IIO_CHAN_SOFT_TIMESTAMP(SMI330_SCAN_TIMESTAMP),
};

static const unsigned long smi330_avail_scan_masks[] = {
	(BIT(SMI330_SCAN_ACCEL_X) | BIT(SMI330_SCAN_ACCEL_Y) |
	 BIT(SMI330_SCAN_ACCEL_Z) | BIT(SMI330_SCAN_GYRO_X) |
	 BIT(SMI330_SCAN_GYRO_Y) | BIT(SMI330_SCAN_GYRO_Z)),
	0
};

static const struct smi330_attributes smi330_accel_scale_attr = {
	.reg_vals = (int[]){ SMI330_ACCEL_RANGE_2G, SMI330_ACCEL_RANGE_4G,
			     SMI330_ACCEL_RANGE_8G, SMI330_ACCEL_RANGE_16G },
	.vals = (int[]){ 0, 61035, 0, 122070, 0, 244140, 0, 488281 },
	.len = 8,
	.type = IIO_VAL_INT_PLUS_NANO,
	.mask = SMI330_CFG_RANGE_MASK
};

static const struct smi330_attributes smi330_gyro_scale_attr = {
	.reg_vals = (int[]){ SMI330_GYRO_RANGE_125, SMI330_GYRO_RANGE_250,
			     SMI330_GYRO_RANGE_500 },
	.vals = (int[]){ 0, 3814697, 0, 7629395, 0, 15258789 },
	.len = 6,
	.type = IIO_VAL_INT_PLUS_NANO,
	.mask = SMI330_CFG_RANGE_MASK
};

static const struct smi330_attributes smi330_average_attr = {
	.reg_vals = (int[]){ SMI330_AVG_NUM_1, SMI330_AVG_NUM_2,
			     SMI330_AVG_NUM_4, SMI330_AVG_NUM_8,
			     SMI330_AVG_NUM_16, SMI330_AVG_NUM_32,
			     SMI330_AVG_NUM_64 },
	.vals = (int[]){ 1, 2, 4, 8, 16, 32, 64 },
	.len = 7,
	.type = IIO_VAL_INT,
	.mask = SMI330_CFG_AVG_NUM_MASK
};

static const struct smi330_attributes smi330_bandwidth_attr = {
	.reg_vals = (int[]){ SMI330_BW_2, SMI330_BW_4 },
	.vals = (int[]){ 2, 4 },
	.len = 2,
	.type = IIO_VAL_INT,
	.mask = SMI330_CFG_BW_MASK
};

static const struct smi330_attributes smi330_odr_attr = {
	.reg_vals = (int[]){ SMI330_ODR_12_5_HZ, SMI330_ODR_25_HZ,
			     SMI330_ODR_50_HZ, SMI330_ODR_100_HZ,
			     SMI330_ODR_200_HZ, SMI330_ODR_400_HZ,
			     SMI330_ODR_800_HZ, SMI330_ODR_1600_HZ,
			     SMI330_ODR_3200_HZ, SMI330_ODR_6400_HZ },
	.vals = (int[]){ 12, 25, 50, 100, 200, 400, 800, 1600, 3200, 6400 },
	.len = 10,

Annotation

Implementation Notes