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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/mutex.hlinux/sysfs.hlinux/slab.hlinux/acpi.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/common/st_sensors.hst_accel.h
Detected Declarations
function st_accel_get_mount_matrixfunction st_accel_read_rawfunction st_accel_write_rawfunction apply_acpi_orientationfunction apply_acpi_orientationfunction st_accel_get_settingsfunction st_accel_common_probe
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
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/sysfs.h`, `linux/slab.h`, `linux/acpi.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `function st_accel_get_mount_matrix`, `function st_accel_read_raw`, `function st_accel_write_raw`, `function apply_acpi_orientation`, `function apply_acpi_orientation`, `function st_accel_get_settings`, `function st_accel_common_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.