drm/modes: Fix drm_mode_vrefres() docs
[drm/drm-misc.git] / drivers / iio / imu / st_lsm9ds0 / st_lsm9ds0_i2c.c
blob0732cfa258c4a79b03fa8368f3acd5b08a788f26
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics LSM9DS0 IMU driver
5 * Copyright (C) 2021, Intel Corporation
7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
8 */
10 #include <linux/device.h>
11 #include <linux/err.h>
12 #include <linux/gfp_types.h>
13 #include <linux/i2c.h>
14 #include <linux/module.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/regmap.h>
18 #include <linux/iio/common/st_sensors_i2c.h>
20 #include "st_lsm9ds0.h"
22 static const struct of_device_id st_lsm9ds0_of_match[] = {
24 .compatible = "st,lsm303d-imu",
25 .data = LSM303D_IMU_DEV_NAME,
28 .compatible = "st,lsm9ds0-imu",
29 .data = LSM9DS0_IMU_DEV_NAME,
33 MODULE_DEVICE_TABLE(of, st_lsm9ds0_of_match);
35 static const struct i2c_device_id st_lsm9ds0_id_table[] = {
36 { LSM303D_IMU_DEV_NAME },
37 { LSM9DS0_IMU_DEV_NAME },
40 MODULE_DEVICE_TABLE(i2c, st_lsm9ds0_id_table);
42 static const struct acpi_device_id st_lsm9ds0_acpi_match[] = {
43 {"ACCL0001", (kernel_ulong_t)LSM303D_IMU_DEV_NAME},
46 MODULE_DEVICE_TABLE(acpi, st_lsm9ds0_acpi_match);
48 static const struct regmap_config st_lsm9ds0_regmap_config = {
49 .reg_bits = 8,
50 .val_bits = 8,
51 .read_flag_mask = 0x80,
54 static int st_lsm9ds0_i2c_probe(struct i2c_client *client)
56 const struct regmap_config *config = &st_lsm9ds0_regmap_config;
57 struct device *dev = &client->dev;
58 struct st_lsm9ds0 *lsm9ds0;
59 struct regmap *regmap;
61 st_sensors_dev_name_probe(dev, client->name, sizeof(client->name));
63 lsm9ds0 = devm_kzalloc(dev, sizeof(*lsm9ds0), GFP_KERNEL);
64 if (!lsm9ds0)
65 return -ENOMEM;
67 lsm9ds0->dev = dev;
68 lsm9ds0->name = client->name;
69 lsm9ds0->irq = client->irq;
71 regmap = devm_regmap_init_i2c(client, config);
72 if (IS_ERR(regmap))
73 return PTR_ERR(regmap);
75 i2c_set_clientdata(client, lsm9ds0);
77 return st_lsm9ds0_probe(lsm9ds0, regmap);
80 static struct i2c_driver st_lsm9ds0_driver = {
81 .driver = {
82 .name = "st-lsm9ds0-i2c",
83 .of_match_table = st_lsm9ds0_of_match,
84 .acpi_match_table = st_lsm9ds0_acpi_match,
86 .probe = st_lsm9ds0_i2c_probe,
87 .id_table = st_lsm9ds0_id_table,
89 module_i2c_driver(st_lsm9ds0_driver);
91 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
92 MODULE_DESCRIPTION("STMicroelectronics LSM9DS0 IMU I2C driver");
93 MODULE_LICENSE("GPL v2");
94 MODULE_IMPORT_NS("IIO_ST_SENSORS");