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/device.h>
11 #include <linux/err.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14 #include <linux/regulator/consumer.h>
16 #include <linux/iio/common/st_sensors.h>
17 #include <linux/iio/iio.h>
19 #include "st_lsm9ds0.h"
21 static int st_lsm9ds0_probe_accel(struct st_lsm9ds0 *lsm9ds0, struct regmap *regmap)
23 const struct st_sensor_settings *settings;
24 struct device *dev = lsm9ds0->dev;
25 struct st_sensor_data *data;
27 settings = st_accel_get_settings(lsm9ds0->name);
29 dev_err(dev, "device name %s not recognized.\n", lsm9ds0->name);
33 lsm9ds0->accel = devm_iio_device_alloc(dev, sizeof(*data));
37 lsm9ds0->accel->name = lsm9ds0->name;
39 data = iio_priv(lsm9ds0->accel);
40 data->sensor_settings = (struct st_sensor_settings *)settings;
41 data->irq = lsm9ds0->irq;
42 data->regmap = regmap;
44 return st_accel_common_probe(lsm9ds0->accel);
47 static int st_lsm9ds0_probe_magn(struct st_lsm9ds0 *lsm9ds0, struct regmap *regmap)
49 const struct st_sensor_settings *settings;
50 struct device *dev = lsm9ds0->dev;
51 struct st_sensor_data *data;
53 settings = st_magn_get_settings(lsm9ds0->name);
55 dev_err(dev, "device name %s not recognized.\n", lsm9ds0->name);
59 lsm9ds0->magn = devm_iio_device_alloc(dev, sizeof(*data));
63 lsm9ds0->magn->name = lsm9ds0->name;
65 data = iio_priv(lsm9ds0->magn);
66 data->sensor_settings = (struct st_sensor_settings *)settings;
67 data->irq = lsm9ds0->irq;
68 data->regmap = regmap;
70 return st_magn_common_probe(lsm9ds0->magn);
73 int st_lsm9ds0_probe(struct st_lsm9ds0 *lsm9ds0, struct regmap *regmap)
75 struct device *dev = lsm9ds0->dev;
76 static const char * const regulator_names[] = { "vdd", "vddio" };
79 /* Regulators not mandatory, but if requested we should enable them. */
80 ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names),
83 return dev_err_probe(dev, ret,
84 "unable to enable Vdd supply\n");
86 /* Setup accelerometer device */
87 ret = st_lsm9ds0_probe_accel(lsm9ds0, regmap);
91 /* Setup magnetometer device */
92 return st_lsm9ds0_probe_magn(lsm9ds0, regmap);
94 EXPORT_SYMBOL_NS_GPL(st_lsm9ds0_probe, IIO_ST_SENSORS);
96 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
97 MODULE_DESCRIPTION("STMicroelectronics LSM9DS0 IMU core driver");
98 MODULE_LICENSE("GPL v2");
99 MODULE_IMPORT_NS(IIO_ST_SENSORS);