0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/spi/spi.h>
0014 #include <linux/slab.h>
0015 #include <linux/regmap.h>
0016
0017 #include "st_lsm6dsx.h"
0018
0019 static const struct regmap_config st_lsm6dsx_spi_regmap_config = {
0020 .reg_bits = 8,
0021 .val_bits = 8,
0022 };
0023
0024 static int st_lsm6dsx_spi_probe(struct spi_device *spi)
0025 {
0026 const struct spi_device_id *id = spi_get_device_id(spi);
0027 int hw_id = id->driver_data;
0028 struct regmap *regmap;
0029
0030 regmap = devm_regmap_init_spi(spi, &st_lsm6dsx_spi_regmap_config);
0031 if (IS_ERR(regmap)) {
0032 dev_err(&spi->dev, "Failed to register spi regmap %ld\n", PTR_ERR(regmap));
0033 return PTR_ERR(regmap);
0034 }
0035
0036 return st_lsm6dsx_probe(&spi->dev, spi->irq, hw_id, regmap);
0037 }
0038
0039 static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
0040 {
0041 .compatible = "st,lsm6ds3",
0042 .data = (void *)ST_LSM6DS3_ID,
0043 },
0044 {
0045 .compatible = "st,lsm6ds3h",
0046 .data = (void *)ST_LSM6DS3H_ID,
0047 },
0048 {
0049 .compatible = "st,lsm6dsl",
0050 .data = (void *)ST_LSM6DSL_ID,
0051 },
0052 {
0053 .compatible = "st,lsm6dsm",
0054 .data = (void *)ST_LSM6DSM_ID,
0055 },
0056 {
0057 .compatible = "st,ism330dlc",
0058 .data = (void *)ST_ISM330DLC_ID,
0059 },
0060 {
0061 .compatible = "st,lsm6dso",
0062 .data = (void *)ST_LSM6DSO_ID,
0063 },
0064 {
0065 .compatible = "st,asm330lhh",
0066 .data = (void *)ST_ASM330LHH_ID,
0067 },
0068 {
0069 .compatible = "st,lsm6dsox",
0070 .data = (void *)ST_LSM6DSOX_ID,
0071 },
0072 {
0073 .compatible = "st,lsm6dsr",
0074 .data = (void *)ST_LSM6DSR_ID,
0075 },
0076 {
0077 .compatible = "st,lsm6ds3tr-c",
0078 .data = (void *)ST_LSM6DS3TRC_ID,
0079 },
0080 {
0081 .compatible = "st,ism330dhcx",
0082 .data = (void *)ST_ISM330DHCX_ID,
0083 },
0084 {
0085 .compatible = "st,lsm9ds1-imu",
0086 .data = (void *)ST_LSM9DS1_ID,
0087 },
0088 {
0089 .compatible = "st,lsm6ds0",
0090 .data = (void *)ST_LSM6DS0_ID,
0091 },
0092 {
0093 .compatible = "st,lsm6dsrx",
0094 .data = (void *)ST_LSM6DSRX_ID,
0095 },
0096 {
0097 .compatible = "st,lsm6dst",
0098 .data = (void *)ST_LSM6DST_ID,
0099 },
0100 {
0101 .compatible = "st,lsm6dsop",
0102 .data = (void *)ST_LSM6DSOP_ID,
0103 },
0104 {
0105 .compatible = "st,asm330lhhx",
0106 .data = (void *)ST_ASM330LHHX_ID,
0107 },
0108 {},
0109 };
0110 MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
0111
0112 static const struct spi_device_id st_lsm6dsx_spi_id_table[] = {
0113 { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
0114 { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
0115 { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
0116 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
0117 { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
0118 { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
0119 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
0120 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
0121 { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
0122 { ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID },
0123 { ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID },
0124 { ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID },
0125 { ST_LSM6DS0_DEV_NAME, ST_LSM6DS0_ID },
0126 { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID },
0127 { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID },
0128 { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID },
0129 { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID },
0130 {},
0131 };
0132 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
0133
0134 static struct spi_driver st_lsm6dsx_driver = {
0135 .driver = {
0136 .name = "st_lsm6dsx_spi",
0137 .pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
0138 .of_match_table = st_lsm6dsx_spi_of_match,
0139 },
0140 .probe = st_lsm6dsx_spi_probe,
0141 .id_table = st_lsm6dsx_spi_id_table,
0142 };
0143 module_spi_driver(st_lsm6dsx_driver);
0144
0145 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
0146 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
0147 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
0148 MODULE_LICENSE("GPL v2");
0149 MODULE_IMPORT_NS(IIO_LSM6DSX);