1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics st_lsm6dsx spi driver
5 * Copyright 2016 STMicroelectronics Inc.
7 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
8 * Denis Ciocca <denis.ciocca@st.com>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/spi/spi.h>
14 #include <linux/slab.h>
15 #include <linux/regmap.h>
17 #include "st_lsm6dsx.h"
19 static const struct regmap_config st_lsm6dsx_spi_regmap_config
= {
24 static int st_lsm6dsx_spi_probe(struct spi_device
*spi
)
26 const struct spi_device_id
*id
= spi_get_device_id(spi
);
27 int hw_id
= id
->driver_data
;
28 struct regmap
*regmap
;
30 regmap
= devm_regmap_init_spi(spi
, &st_lsm6dsx_spi_regmap_config
);
32 dev_err(&spi
->dev
, "Failed to register spi regmap %ld\n", PTR_ERR(regmap
));
33 return PTR_ERR(regmap
);
36 return st_lsm6dsx_probe(&spi
->dev
, spi
->irq
, hw_id
, regmap
);
39 static const struct of_device_id st_lsm6dsx_spi_of_match
[] = {
41 .compatible
= "st,lsm6ds3",
42 .data
= (void *)ST_LSM6DS3_ID
,
45 .compatible
= "st,lsm6ds3h",
46 .data
= (void *)ST_LSM6DS3H_ID
,
49 .compatible
= "st,lsm6dsl",
50 .data
= (void *)ST_LSM6DSL_ID
,
53 .compatible
= "st,lsm6dsm",
54 .data
= (void *)ST_LSM6DSM_ID
,
57 .compatible
= "st,ism330dlc",
58 .data
= (void *)ST_ISM330DLC_ID
,
61 .compatible
= "st,lsm6dso",
62 .data
= (void *)ST_LSM6DSO_ID
,
65 .compatible
= "st,asm330lhh",
66 .data
= (void *)ST_ASM330LHH_ID
,
69 .compatible
= "st,lsm6dsox",
70 .data
= (void *)ST_LSM6DSOX_ID
,
73 .compatible
= "st,lsm6dsr",
74 .data
= (void *)ST_LSM6DSR_ID
,
77 .compatible
= "st,lsm6ds3tr-c",
78 .data
= (void *)ST_LSM6DS3TRC_ID
,
81 .compatible
= "st,ism330dhcx",
82 .data
= (void *)ST_ISM330DHCX_ID
,
85 .compatible
= "st,lsm9ds1-imu",
86 .data
= (void *)ST_LSM9DS1_ID
,
89 .compatible
= "st,lsm6ds0",
90 .data
= (void *)ST_LSM6DS0_ID
,
93 .compatible
= "st,lsm6dsrx",
94 .data
= (void *)ST_LSM6DSRX_ID
,
97 .compatible
= "st,lsm6dst",
98 .data
= (void *)ST_LSM6DST_ID
,
101 .compatible
= "st,lsm6dsop",
102 .data
= (void *)ST_LSM6DSOP_ID
,
105 .compatible
= "st,asm330lhhx",
106 .data
= (void *)ST_ASM330LHHX_ID
,
109 .compatible
= "st,lsm6dstx",
110 .data
= (void *)ST_LSM6DSTX_ID
,
113 .compatible
= "st,lsm6dsv",
114 .data
= (void *)ST_LSM6DSV_ID
,
117 .compatible
= "st,lsm6dsv16x",
118 .data
= (void *)ST_LSM6DSV16X_ID
,
121 .compatible
= "st,lsm6dso16is",
122 .data
= (void *)ST_LSM6DSO16IS_ID
,
125 .compatible
= "st,ism330is",
126 .data
= (void *)ST_ISM330IS_ID
,
129 .compatible
= "st,asm330lhb",
130 .data
= (void *)ST_ASM330LHB_ID
,
133 .compatible
= "st,asm330lhhxg1",
134 .data
= (void *)ST_ASM330LHHXG1_ID
,
138 MODULE_DEVICE_TABLE(of
, st_lsm6dsx_spi_of_match
);
140 static const struct spi_device_id st_lsm6dsx_spi_id_table
[] = {
141 { ST_LSM6DS3_DEV_NAME
, ST_LSM6DS3_ID
},
142 { ST_LSM6DS3H_DEV_NAME
, ST_LSM6DS3H_ID
},
143 { ST_LSM6DSL_DEV_NAME
, ST_LSM6DSL_ID
},
144 { ST_LSM6DSM_DEV_NAME
, ST_LSM6DSM_ID
},
145 { ST_ISM330DLC_DEV_NAME
, ST_ISM330DLC_ID
},
146 { ST_LSM6DSO_DEV_NAME
, ST_LSM6DSO_ID
},
147 { ST_ASM330LHH_DEV_NAME
, ST_ASM330LHH_ID
},
148 { ST_LSM6DSOX_DEV_NAME
, ST_LSM6DSOX_ID
},
149 { ST_LSM6DSR_DEV_NAME
, ST_LSM6DSR_ID
},
150 { ST_LSM6DS3TRC_DEV_NAME
, ST_LSM6DS3TRC_ID
},
151 { ST_ISM330DHCX_DEV_NAME
, ST_ISM330DHCX_ID
},
152 { ST_LSM9DS1_DEV_NAME
, ST_LSM9DS1_ID
},
153 { ST_LSM6DS0_DEV_NAME
, ST_LSM6DS0_ID
},
154 { ST_LSM6DSRX_DEV_NAME
, ST_LSM6DSRX_ID
},
155 { ST_LSM6DST_DEV_NAME
, ST_LSM6DST_ID
},
156 { ST_LSM6DSOP_DEV_NAME
, ST_LSM6DSOP_ID
},
157 { ST_ASM330LHHX_DEV_NAME
, ST_ASM330LHHX_ID
},
158 { ST_LSM6DSTX_DEV_NAME
, ST_LSM6DSTX_ID
},
159 { ST_LSM6DSV_DEV_NAME
, ST_LSM6DSV_ID
},
160 { ST_LSM6DSV16X_DEV_NAME
, ST_LSM6DSV16X_ID
},
161 { ST_LSM6DSO16IS_DEV_NAME
, ST_LSM6DSO16IS_ID
},
162 { ST_ISM330IS_DEV_NAME
, ST_ISM330IS_ID
},
163 { ST_ASM330LHB_DEV_NAME
, ST_ASM330LHB_ID
},
164 { ST_ASM330LHHXG1_DEV_NAME
, ST_ASM330LHHXG1_ID
},
167 MODULE_DEVICE_TABLE(spi
, st_lsm6dsx_spi_id_table
);
169 static struct spi_driver st_lsm6dsx_driver
= {
171 .name
= "st_lsm6dsx_spi",
172 .pm
= pm_sleep_ptr(&st_lsm6dsx_pm_ops
),
173 .of_match_table
= st_lsm6dsx_spi_of_match
,
175 .probe
= st_lsm6dsx_spi_probe
,
176 .id_table
= st_lsm6dsx_spi_id_table
,
178 module_spi_driver(st_lsm6dsx_driver
);
180 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
181 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
182 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
183 MODULE_LICENSE("GPL v2");
184 MODULE_IMPORT_NS("IIO_LSM6DSX");