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/gfp_types.h>
13 #include <linux/module.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/regmap.h>
16 #include <linux/spi/spi.h>
18 #include <linux/iio/common/st_sensors_spi.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 spi_device_id st_lsm9ds0_id_table
[] = {
36 { LSM303D_IMU_DEV_NAME
},
37 { LSM9DS0_IMU_DEV_NAME
},
40 MODULE_DEVICE_TABLE(spi
, st_lsm9ds0_id_table
);
42 static const struct regmap_config st_lsm9ds0_regmap_config
= {
45 .read_flag_mask
= 0xc0,
48 static int st_lsm9ds0_spi_probe(struct spi_device
*spi
)
50 struct device
*dev
= &spi
->dev
;
51 struct st_lsm9ds0
*lsm9ds0
;
52 struct regmap
*regmap
;
54 st_sensors_dev_name_probe(dev
, spi
->modalias
, sizeof(spi
->modalias
));
56 lsm9ds0
= devm_kzalloc(dev
, sizeof(*lsm9ds0
), GFP_KERNEL
);
61 lsm9ds0
->name
= spi
->modalias
;
62 lsm9ds0
->irq
= spi
->irq
;
64 regmap
= devm_regmap_init_spi(spi
, &st_lsm9ds0_regmap_config
);
66 return PTR_ERR(regmap
);
68 spi_set_drvdata(spi
, lsm9ds0
);
70 return st_lsm9ds0_probe(lsm9ds0
, regmap
);
73 static struct spi_driver st_lsm9ds0_driver
= {
75 .name
= "st-lsm9ds0-spi",
76 .of_match_table
= st_lsm9ds0_of_match
,
78 .probe
= st_lsm9ds0_spi_probe
,
79 .id_table
= st_lsm9ds0_id_table
,
81 module_spi_driver(st_lsm9ds0_driver
);
83 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
84 MODULE_DESCRIPTION("STMicroelectronics LSM9DS0 IMU SPI driver");
85 MODULE_LICENSE("GPL v2");
86 MODULE_IMPORT_NS("IIO_ST_SENSORS");