1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics LSM9DS0 IMU driver
5 * Copyright (C) 2021, Intel Corporation
7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
10 #include <linux/i2c.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/regmap.h>
16 #include <linux/iio/common/st_sensors_i2c.h>
18 #include "st_lsm9ds0.h"
20 static const struct of_device_id st_lsm9ds0_of_match[] = {
22 .compatible = "st,lsm9ds0-imu",
23 .data = LSM9DS0_IMU_DEV_NAME,
27 MODULE_DEVICE_TABLE(of, st_lsm9ds0_of_match);
29 static const struct i2c_device_id st_lsm9ds0_id_table[] = {
30 { LSM9DS0_IMU_DEV_NAME },
33 MODULE_DEVICE_TABLE(i2c, st_lsm9ds0_id_table);
35 static const struct regmap_config st_lsm9ds0_regmap_config = {
38 .read_flag_mask = 0x80,
41 static int st_lsm9ds0_i2c_probe(struct i2c_client *client)
43 const struct regmap_config *config = &st_lsm9ds0_regmap_config;
44 struct device *dev = &client->dev;
45 struct st_lsm9ds0 *lsm9ds0;
46 struct regmap *regmap;
48 st_sensors_dev_name_probe(dev, client->name, sizeof(client->name));
50 lsm9ds0 = devm_kzalloc(dev, sizeof(*lsm9ds0), GFP_KERNEL);
55 lsm9ds0->name = client->name;
56 lsm9ds0->irq = client->irq;
58 regmap = devm_regmap_init_i2c(client, config);
60 return PTR_ERR(regmap);
62 i2c_set_clientdata(client, lsm9ds0);
64 return st_lsm9ds0_probe(lsm9ds0, regmap);
67 static int st_lsm9ds0_i2c_remove(struct i2c_client *client)
69 return st_lsm9ds0_remove(i2c_get_clientdata(client));
72 static struct i2c_driver st_lsm9ds0_driver = {
74 .name = "st-lsm9ds0-i2c",
75 .of_match_table = st_lsm9ds0_of_match,
77 .probe_new = st_lsm9ds0_i2c_probe,
78 .remove = st_lsm9ds0_i2c_remove,
79 .id_table = st_lsm9ds0_id_table,
81 module_i2c_driver(st_lsm9ds0_driver);
83 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
84 MODULE_DESCRIPTION("STMicroelectronics LSM9DS0 IMU I2C driver");
85 MODULE_LICENSE("GPL v2");