drivers/iio/accel/st_accel_core.c

Source file repositories/reference/linux-study-clean/drivers/iio/accel/st_accel_core.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/accel/st_accel_core.c
Extension
.c
Size
35309 bytes
Lines
1623
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

switch (matrix_val) {
			case -1:
				str_value = "-1";
				break;
			case 0:
				str_value = "0";
				break;
			case 1:
				str_value = "1";
				break;
			default:
				goto out;
			}
			adata->mount_matrix.rotation[i * 3 + j] = str_value;
		}
	}

	ret = 0;
	dev_info(parent, "computed mount matrix from ACPI\n");

out:
	kfree(buffer.pointer);
	if (ret)
		dev_dbg(parent,
			"failed to apply ACPI orientation data: %d\n", ret);

	return ret;
}
#else /* !CONFIG_ACPI */
static int apply_acpi_orientation(struct iio_dev *indio_dev)
{
	return -EINVAL;
}
#endif

/*
 * st_accel_get_settings() - get sensor settings from device name
 * @name: device name buffer reference.
 *
 * Return: valid reference on success, NULL otherwise.
 */
const struct st_sensor_settings *st_accel_get_settings(const char *name)
{
	int index = st_sensors_get_settings_index(name,
					st_accel_sensors_settings,
					ARRAY_SIZE(st_accel_sensors_settings));
	if (index < 0)
		return NULL;

	return &st_accel_sensors_settings[index];
}
EXPORT_SYMBOL_NS(st_accel_get_settings, "IIO_ST_SENSORS");

int st_accel_common_probe(struct iio_dev *indio_dev)
{
	struct st_sensor_data *adata = iio_priv(indio_dev);
	struct device *parent = indio_dev->dev.parent;
	struct st_sensors_platform_data *pdata = dev_get_platdata(parent);
	int err;

	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->info = &accel_info;

	err = st_sensors_verify_id(indio_dev);
	if (err < 0)
		return err;

	adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
	indio_dev->channels = adata->sensor_settings->ch;
	indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;

	/*
	 * First try specific ACPI methods to retrieve orientation then try the
	 * generic function.
	 */
	err = apply_acpi_orientation(indio_dev);
	if (err) {
		err = iio_read_mount_matrix(parent, &adata->mount_matrix);
		if (err)
			return err;
	}

	adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0];
	adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;

	if (!pdata)
		pdata = (struct st_sensors_platform_data *)&default_accel_pdata;

	err = st_sensors_init_sensor(indio_dev, pdata);
	if (err < 0)

Annotation

Implementation Notes