drivers/iio/imu/bno055/bno055.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/imu/bno055/bno055.c
Extension
.c
Size
46713 bytes
Lines
1694
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations bno055_fw_version_ops = {
	.open = simple_open,
	.read = bno055_show_fw_version,
	.llseek = default_llseek,
	.owner = THIS_MODULE,
};

static void bno055_debugfs_remove(void *_priv)
{
	struct bno055_priv *priv = _priv;

	debugfs_remove(priv->debugfs);
	priv->debugfs = NULL;
}

static void bno055_debugfs_init(struct iio_dev *iio_dev)
{
	struct bno055_priv *priv = iio_priv(iio_dev);

	priv->debugfs = debugfs_create_file("firmware_version", 0400,
					    iio_get_debugfs_dentry(iio_dev),
					    priv, &bno055_fw_version_ops);
	if (!IS_ERR(priv->debugfs))
		devm_add_action_or_reset(priv->dev, bno055_debugfs_remove,
					 priv);
	if (IS_ERR_OR_NULL(priv->debugfs))
		dev_warn(priv->dev, "failed to setup debugfs");
}

static IIO_DEVICE_ATTR_RW(fusion_enable, 0);
static IIO_DEVICE_ATTR_RW(in_magn_calibration_fast_enable, 0);
static IIO_DEVICE_ATTR_RW(in_accel_range_raw, 0);

static IIO_DEVICE_ATTR_RO(in_accel_range_raw_available, 0);
static IIO_DEVICE_ATTR_RO(sys_calibration_auto_status, 0);
static IIO_DEVICE_ATTR_RO(in_accel_calibration_auto_status, 0);
static IIO_DEVICE_ATTR_RO(in_gyro_calibration_auto_status, 0);
static IIO_DEVICE_ATTR_RO(in_magn_calibration_auto_status, 0);
static IIO_DEVICE_ATTR_RO(serialnumber, 0);

static struct attribute *bno055_attrs[] = {
	&iio_dev_attr_in_accel_range_raw_available.dev_attr.attr,
	&iio_dev_attr_in_accel_range_raw.dev_attr.attr,
	&iio_dev_attr_fusion_enable.dev_attr.attr,
	&iio_dev_attr_in_magn_calibration_fast_enable.dev_attr.attr,
	&iio_dev_attr_sys_calibration_auto_status.dev_attr.attr,
	&iio_dev_attr_in_accel_calibration_auto_status.dev_attr.attr,
	&iio_dev_attr_in_gyro_calibration_auto_status.dev_attr.attr,
	&iio_dev_attr_in_magn_calibration_auto_status.dev_attr.attr,
	&iio_dev_attr_serialnumber.dev_attr.attr,
	NULL
};

static const BIN_ATTR_RO(calibration_data, BNO055_CALDATA_LEN);

static const struct bin_attribute *const bno055_bin_attrs[] = {
	&bin_attr_calibration_data,
	NULL
};

static const struct attribute_group bno055_attrs_group = {
	.attrs = bno055_attrs,
	.bin_attrs = bno055_bin_attrs,
};

static const struct iio_info bno055_info = {
	.read_raw_multi = bno055_read_raw_multi,
	.read_avail = bno055_read_avail,
	.write_raw = bno055_write_raw,
	.attrs = &bno055_attrs_group,
	.debugfs_reg_access = bno055_debugfs_reg_access,
};

/*
 * Reads len samples from the HW, stores them in buf starting from buf_idx,
 * and applies mask to cull (skip) unneeded samples.
 * Updates buf_idx incrementing with the number of stored samples.
 * Samples from HW are transferred into buf, then in-place copy on buf is
 * performed in order to cull samples that need to be skipped.
 * This avoids copies of the first samples until we hit the 1st sample to skip,
 * and also avoids having an extra bounce buffer.
 * buf must be able to contain len elements in spite of how many samples we are
 * going to cull.
 */
static int bno055_scan_xfer(struct bno055_priv *priv,
			    int start_ch, int len, unsigned long mask,
			    __le16 *buf, int *buf_idx)
{
	const int base = BNO055_ACC_DATA_X_LSB_REG;
	bool quat_in_read = false;

Annotation

Implementation Notes