drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c- Extension
.c- Size
- 2322 bytes
- Lines
- 95
- 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device/devres.hlinux/err.hlinux/gfp_types.hlinux/i2c.hlinux/module.hlinux/mod_devicetable.hlinux/regmap.hlinux/iio/common/st_sensors_i2c.hst_lsm9ds0.h
Detected Declarations
function st_lsm9ds0_i2c_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* STMicroelectronics LSM9DS0 IMU driver
*
* Copyright (C) 2021, Intel Corporation
*
* Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
*/
#include <linux/device/devres.h>
#include <linux/err.h>
#include <linux/gfp_types.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/regmap.h>
#include <linux/iio/common/st_sensors_i2c.h>
#include "st_lsm9ds0.h"
static const struct of_device_id st_lsm9ds0_of_match[] = {
{
.compatible = "st,lsm303d-imu",
.data = LSM303D_IMU_DEV_NAME,
},
{
.compatible = "st,lsm9ds0-imu",
.data = LSM9DS0_IMU_DEV_NAME,
},
{ }
};
MODULE_DEVICE_TABLE(of, st_lsm9ds0_of_match);
static const struct i2c_device_id st_lsm9ds0_id_table[] = {
{ LSM303D_IMU_DEV_NAME },
{ LSM9DS0_IMU_DEV_NAME },
{ }
};
MODULE_DEVICE_TABLE(i2c, st_lsm9ds0_id_table);
static const struct acpi_device_id st_lsm9ds0_acpi_match[] = {
{"ACCL0001", (kernel_ulong_t)LSM303D_IMU_DEV_NAME},
{ }
};
MODULE_DEVICE_TABLE(acpi, st_lsm9ds0_acpi_match);
static const struct regmap_config st_lsm9ds0_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.read_flag_mask = 0x80,
};
static int st_lsm9ds0_i2c_probe(struct i2c_client *client)
{
const struct regmap_config *config = &st_lsm9ds0_regmap_config;
struct device *dev = &client->dev;
struct st_lsm9ds0 *lsm9ds0;
struct regmap *regmap;
st_sensors_dev_name_probe(dev, client->name, sizeof(client->name));
lsm9ds0 = devm_kzalloc(dev, sizeof(*lsm9ds0), GFP_KERNEL);
if (!lsm9ds0)
return -ENOMEM;
lsm9ds0->dev = dev;
lsm9ds0->name = client->name;
lsm9ds0->irq = client->irq;
regmap = devm_regmap_init_i2c(client, config);
if (IS_ERR(regmap))
return PTR_ERR(regmap);
i2c_set_clientdata(client, lsm9ds0);
return st_lsm9ds0_probe(lsm9ds0, regmap);
}
static struct i2c_driver st_lsm9ds0_driver = {
.driver = {
.name = "st-lsm9ds0-i2c",
.of_match_table = st_lsm9ds0_of_match,
.acpi_match_table = st_lsm9ds0_acpi_match,
},
.probe = st_lsm9ds0_i2c_probe,
.id_table = st_lsm9ds0_id_table,
};
module_i2c_driver(st_lsm9ds0_driver);
Annotation
- Immediate include surface: `linux/device/devres.h`, `linux/err.h`, `linux/gfp_types.h`, `linux/i2c.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/regmap.h`, `linux/iio/common/st_sensors_i2c.h`.
- Detected declarations: `function st_lsm9ds0_i2c_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source 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.