1fda8d26eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2290a6ce1SLorenzo Bianconi /*
3290a6ce1SLorenzo Bianconi * STMicroelectronics st_lsm6dsx i2c driver
4290a6ce1SLorenzo Bianconi *
5290a6ce1SLorenzo Bianconi * Copyright 2016 STMicroelectronics Inc.
6290a6ce1SLorenzo Bianconi *
7290a6ce1SLorenzo Bianconi * Lorenzo Bianconi <lorenzo.bianconi@st.com>
8290a6ce1SLorenzo Bianconi * Denis Ciocca <denis.ciocca@st.com>
9290a6ce1SLorenzo Bianconi */
10290a6ce1SLorenzo Bianconi
11290a6ce1SLorenzo Bianconi #include <linux/kernel.h>
12290a6ce1SLorenzo Bianconi #include <linux/module.h>
13290a6ce1SLorenzo Bianconi #include <linux/i2c.h>
14290a6ce1SLorenzo Bianconi #include <linux/slab.h>
1551a8b707SLorenzo Bianconi #include <linux/regmap.h>
16290a6ce1SLorenzo Bianconi
17290a6ce1SLorenzo Bianconi #include "st_lsm6dsx.h"
18290a6ce1SLorenzo Bianconi
1951a8b707SLorenzo Bianconi static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
2051a8b707SLorenzo Bianconi .reg_bits = 8,
2151a8b707SLorenzo Bianconi .val_bits = 8,
22290a6ce1SLorenzo Bianconi };
23290a6ce1SLorenzo Bianconi
st_lsm6dsx_i2c_probe(struct i2c_client * client)24b7dbc0aeSUwe Kleine-König static int st_lsm6dsx_i2c_probe(struct i2c_client *client)
25290a6ce1SLorenzo Bianconi {
26bd66b6acSJonathan Cameron int hw_id;
2751a8b707SLorenzo Bianconi struct regmap *regmap;
2851a8b707SLorenzo Bianconi
29bd66b6acSJonathan Cameron hw_id = (kernel_ulong_t)device_get_match_data(&client->dev);
30bd66b6acSJonathan Cameron if (!hw_id)
31bd66b6acSJonathan Cameron hw_id = i2c_client_get_device_id(client)->driver_data;
32bd66b6acSJonathan Cameron if (!hw_id)
33bd66b6acSJonathan Cameron return -EINVAL;
34bd66b6acSJonathan Cameron
3551a8b707SLorenzo Bianconi regmap = devm_regmap_init_i2c(client, &st_lsm6dsx_i2c_regmap_config);
3651a8b707SLorenzo Bianconi if (IS_ERR(regmap)) {
379e301ea7SAndy Shevchenko dev_err(&client->dev, "Failed to register i2c regmap %ld\n", PTR_ERR(regmap));
3851a8b707SLorenzo Bianconi return PTR_ERR(regmap);
3951a8b707SLorenzo Bianconi }
4051a8b707SLorenzo Bianconi
4181956a93SLorenzo Bianconi return st_lsm6dsx_probe(&client->dev, client->irq, hw_id, regmap);
42290a6ce1SLorenzo Bianconi }
43290a6ce1SLorenzo Bianconi
44290a6ce1SLorenzo Bianconi static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
45290a6ce1SLorenzo Bianconi {
46290a6ce1SLorenzo Bianconi .compatible = "st,lsm6ds3",
47290a6ce1SLorenzo Bianconi .data = (void *)ST_LSM6DS3_ID,
48290a6ce1SLorenzo Bianconi },
49290a6ce1SLorenzo Bianconi {
50df47710aSLorenzo Bianconi .compatible = "st,lsm6ds3h",
51df47710aSLorenzo Bianconi .data = (void *)ST_LSM6DS3H_ID,
52df47710aSLorenzo Bianconi },
53df47710aSLorenzo Bianconi {
540b2a3e5fSLorenzo Bianconi .compatible = "st,lsm6dsl",
550b2a3e5fSLorenzo Bianconi .data = (void *)ST_LSM6DSL_ID,
560b2a3e5fSLorenzo Bianconi },
570b2a3e5fSLorenzo Bianconi {
58290a6ce1SLorenzo Bianconi .compatible = "st,lsm6dsm",
59290a6ce1SLorenzo Bianconi .data = (void *)ST_LSM6DSM_ID,
60290a6ce1SLorenzo Bianconi },
61179c8d60SLorenzo Bianconi {
62179c8d60SLorenzo Bianconi .compatible = "st,ism330dlc",
63179c8d60SLorenzo Bianconi .data = (void *)ST_ISM330DLC_ID,
64179c8d60SLorenzo Bianconi },
65801a6e0aSLorenzo Bianconi {
66801a6e0aSLorenzo Bianconi .compatible = "st,lsm6dso",
67801a6e0aSLorenzo Bianconi .data = (void *)ST_LSM6DSO_ID,
68801a6e0aSLorenzo Bianconi },
693054c4ffSLorenzo Bianconi {
703054c4ffSLorenzo Bianconi .compatible = "st,asm330lhh",
713054c4ffSLorenzo Bianconi .data = (void *)ST_ASM330LHH_ID,
723054c4ffSLorenzo Bianconi },
736af0e8a9SLorenzo Bianconi {
746af0e8a9SLorenzo Bianconi .compatible = "st,lsm6dsox",
756af0e8a9SLorenzo Bianconi .data = (void *)ST_LSM6DSOX_ID,
766af0e8a9SLorenzo Bianconi },
7743901008SLorenzo Bianconi {
7843901008SLorenzo Bianconi .compatible = "st,lsm6dsr",
7943901008SLorenzo Bianconi .data = (void *)ST_LSM6DSR_ID,
8043901008SLorenzo Bianconi },
81dbcd2088SLorenzo Bianconi {
82dbcd2088SLorenzo Bianconi .compatible = "st,lsm6ds3tr-c",
83dbcd2088SLorenzo Bianconi .data = (void *)ST_LSM6DS3TRC_ID,
84dbcd2088SLorenzo Bianconi },
85db947a79SLorenzo Bianconi {
86db947a79SLorenzo Bianconi .compatible = "st,ism330dhcx",
87db947a79SLorenzo Bianconi .data = (void *)ST_ISM330DHCX_ID,
88db947a79SLorenzo Bianconi },
8952f4b1f1SMartin Kepplinger {
9052f4b1f1SMartin Kepplinger .compatible = "st,lsm9ds1-imu",
9152f4b1f1SMartin Kepplinger .data = (void *)ST_LSM9DS1_ID,
9252f4b1f1SMartin Kepplinger },
93fa060a3dSLorenzo Bianconi {
94fa060a3dSLorenzo Bianconi .compatible = "st,lsm6ds0",
95fa060a3dSLorenzo Bianconi .data = (void *)ST_LSM6DS0_ID,
96fa060a3dSLorenzo Bianconi },
97cf9c71b3SLorenzo Bianconi {
98cf9c71b3SLorenzo Bianconi .compatible = "st,lsm6dsrx",
99cf9c71b3SLorenzo Bianconi .data = (void *)ST_LSM6DSRX_ID,
100cf9c71b3SLorenzo Bianconi },
1014393e4c5SLorenzo Bianconi {
1024393e4c5SLorenzo Bianconi .compatible = "st,lsm6dst",
1034393e4c5SLorenzo Bianconi .data = (void *)ST_LSM6DST_ID,
1044393e4c5SLorenzo Bianconi },
1052c57d265SLorenzo Bianconi {
1062c57d265SLorenzo Bianconi .compatible = "st,lsm6dsop",
1072c57d265SLorenzo Bianconi .data = (void *)ST_LSM6DSOP_ID,
1082c57d265SLorenzo Bianconi },
109fdd70d7aSLorenzo Bianconi {
110fdd70d7aSLorenzo Bianconi .compatible = "st,asm330lhhx",
111fdd70d7aSLorenzo Bianconi .data = (void *)ST_ASM330LHHX_ID,
112fdd70d7aSLorenzo Bianconi },
113186b9e38SLorenzo Bianconi {
114186b9e38SLorenzo Bianconi .compatible = "st,lsm6dstx",
115186b9e38SLorenzo Bianconi .data = (void *)ST_LSM6DSTX_ID,
116186b9e38SLorenzo Bianconi },
117a1c6d631SLorenzo Bianconi {
118a1c6d631SLorenzo Bianconi .compatible = "st,lsm6dsv",
119a1c6d631SLorenzo Bianconi .data = (void *)ST_LSM6DSV_ID,
120a1c6d631SLorenzo Bianconi },
12146975081SLorenzo Bianconi {
12246975081SLorenzo Bianconi .compatible = "st,lsm6dsv16x",
12346975081SLorenzo Bianconi .data = (void *)ST_LSM6DSV16X_ID,
12446975081SLorenzo Bianconi },
125f35e1ee9SLorenzo Bianconi {
126f35e1ee9SLorenzo Bianconi .compatible = "st,lsm6dso16is",
127f35e1ee9SLorenzo Bianconi .data = (void *)ST_LSM6DSO16IS_ID,
128f35e1ee9SLorenzo Bianconi },
1293a042fdaSLorenzo Bianconi {
1303a042fdaSLorenzo Bianconi .compatible = "st,ism330is",
1313a042fdaSLorenzo Bianconi .data = (void *)ST_ISM330IS_ID,
1323a042fdaSLorenzo Bianconi },
13318462d08SLorenzo Bianconi {
13418462d08SLorenzo Bianconi .compatible = "st,asm330lhb",
13518462d08SLorenzo Bianconi .data = (void *)ST_ASM330LHB_ID,
13618462d08SLorenzo Bianconi },
137*16ac43a1SLorenzo Bianconi {
138*16ac43a1SLorenzo Bianconi .compatible = "st,asm330lhhxg1",
139*16ac43a1SLorenzo Bianconi .data = (void *)ST_ASM330LHHXG1_ID,
140*16ac43a1SLorenzo Bianconi },
141290a6ce1SLorenzo Bianconi {},
142290a6ce1SLorenzo Bianconi };
143290a6ce1SLorenzo Bianconi MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
144290a6ce1SLorenzo Bianconi
145bd66b6acSJonathan Cameron static const struct acpi_device_id st_lsm6dsx_i2c_acpi_match[] = {
146bd66b6acSJonathan Cameron { "SMO8B30", ST_LSM6DS3TRC_ID, },
147bd66b6acSJonathan Cameron {}
148bd66b6acSJonathan Cameron };
149bd66b6acSJonathan Cameron MODULE_DEVICE_TABLE(acpi, st_lsm6dsx_i2c_acpi_match);
150bd66b6acSJonathan Cameron
151290a6ce1SLorenzo Bianconi static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
152290a6ce1SLorenzo Bianconi { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
153df47710aSLorenzo Bianconi { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
1540b2a3e5fSLorenzo Bianconi { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
155290a6ce1SLorenzo Bianconi { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
156179c8d60SLorenzo Bianconi { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
157801a6e0aSLorenzo Bianconi { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
1583054c4ffSLorenzo Bianconi { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
1596af0e8a9SLorenzo Bianconi { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
16043901008SLorenzo Bianconi { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
161dbcd2088SLorenzo Bianconi { ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID },
162db947a79SLorenzo Bianconi { ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID },
16352f4b1f1SMartin Kepplinger { ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID },
164fa060a3dSLorenzo Bianconi { ST_LSM6DS0_DEV_NAME, ST_LSM6DS0_ID },
165cf9c71b3SLorenzo Bianconi { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID },
1664393e4c5SLorenzo Bianconi { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID },
1672c57d265SLorenzo Bianconi { ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID },
168fdd70d7aSLorenzo Bianconi { ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID },
169186b9e38SLorenzo Bianconi { ST_LSM6DSTX_DEV_NAME, ST_LSM6DSTX_ID },
170a1c6d631SLorenzo Bianconi { ST_LSM6DSV_DEV_NAME, ST_LSM6DSV_ID },
17146975081SLorenzo Bianconi { ST_LSM6DSV16X_DEV_NAME, ST_LSM6DSV16X_ID },
172f35e1ee9SLorenzo Bianconi { ST_LSM6DSO16IS_DEV_NAME, ST_LSM6DSO16IS_ID },
1733a042fdaSLorenzo Bianconi { ST_ISM330IS_DEV_NAME, ST_ISM330IS_ID },
17418462d08SLorenzo Bianconi { ST_ASM330LHB_DEV_NAME, ST_ASM330LHB_ID },
175*16ac43a1SLorenzo Bianconi { ST_ASM330LHHXG1_DEV_NAME, ST_ASM330LHHXG1_ID },
176290a6ce1SLorenzo Bianconi {},
177290a6ce1SLorenzo Bianconi };
178290a6ce1SLorenzo Bianconi MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
179290a6ce1SLorenzo Bianconi
180290a6ce1SLorenzo Bianconi static struct i2c_driver st_lsm6dsx_driver = {
181290a6ce1SLorenzo Bianconi .driver = {
182290a6ce1SLorenzo Bianconi .name = "st_lsm6dsx_i2c",
183acc416ffSJonathan Cameron .pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
184e3da4307SAndy Shevchenko .of_match_table = st_lsm6dsx_i2c_of_match,
185bd66b6acSJonathan Cameron .acpi_match_table = st_lsm6dsx_i2c_acpi_match,
186290a6ce1SLorenzo Bianconi },
1877cf15f42SUwe Kleine-König .probe = st_lsm6dsx_i2c_probe,
188290a6ce1SLorenzo Bianconi .id_table = st_lsm6dsx_i2c_id_table,
189290a6ce1SLorenzo Bianconi };
190290a6ce1SLorenzo Bianconi module_i2c_driver(st_lsm6dsx_driver);
191290a6ce1SLorenzo Bianconi
192290a6ce1SLorenzo Bianconi MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
193290a6ce1SLorenzo Bianconi MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
194290a6ce1SLorenzo Bianconi MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver");
195290a6ce1SLorenzo Bianconi MODULE_LICENSE("GPL v2");
1962b059449SJonathan Cameron MODULE_IMPORT_NS(IIO_LSM6DSX);
197