Skip to content

Commit 2660b00

Browse files
vitor-soares-snpsjic23
authored andcommitted
iio: imu: st_lsm6dsx: add i3c basic support for LSM6DSO and LSM6DSR
For today the st_lsm6dsx driver support LSM6DSO and LSM6DSR sensor only in spi and i2c mode. The LSM6DSO and LSM6DSR are also i3c capable so let's give i3c support to them. Signed-off-by: Vitor Soares <[email protected]> Acked-by: Lorenzo Bianconi <[email protected]> Reviewed-by: Boris Brezillon <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 62f5b7c commit 2660b00

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

drivers/iio/imu/st_lsm6dsx/Kconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
config IIO_ST_LSM6DSX
44
tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors"
5-
depends on (I2C || SPI)
5+
depends on (I2C || SPI || I3C)
66
select IIO_BUFFER
77
select IIO_KFIFO_BUF
88
select IIO_ST_LSM6DSX_I2C if (I2C)
99
select IIO_ST_LSM6DSX_SPI if (SPI_MASTER)
10+
select IIO_ST_LSM6DSX_I3C if (I3C)
1011
help
1112
Say yes here to build support for STMicroelectronics LSM6DSx imu
1213
sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm,
@@ -24,3 +25,8 @@ config IIO_ST_LSM6DSX_SPI
2425
tristate
2526
depends on IIO_ST_LSM6DSX
2627
select REGMAP_SPI
28+
29+
config IIO_ST_LSM6DSX_I3C
30+
tristate
31+
depends on IIO_ST_LSM6DSX
32+
select REGMAP_I3C

drivers/iio/imu/st_lsm6dsx/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o \
55
obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o
66
obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o
77
obj-$(CONFIG_IIO_ST_LSM6DSX_SPI) += st_lsm6dsx_spi.o
8+
obj-$(CONFIG_IIO_ST_LSM6DSX_I3C) += st_lsm6dsx_i3c.o
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
4+
*
5+
* Author: Vitor Soares <[email protected]>
6+
*/
7+
8+
#include <linux/kernel.h>
9+
#include <linux/module.h>
10+
#include <linux/i3c/device.h>
11+
#include <linux/i3c/master.h>
12+
#include <linux/slab.h>
13+
#include <linux/of.h>
14+
#include <linux/regmap.h>
15+
16+
#include "st_lsm6dsx.h"
17+
18+
static const struct i3c_device_id st_lsm6dsx_i3c_ids[] = {
19+
I3C_DEVICE(0x0104, 0x006C, (void *)ST_LSM6DSO_ID),
20+
I3C_DEVICE(0x0104, 0x006B, (void *)ST_LSM6DSR_ID),
21+
{ /* sentinel */ },
22+
};
23+
MODULE_DEVICE_TABLE(i3c, st_lsm6dsx_i3c_ids);
24+
25+
static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
26+
{
27+
struct regmap_config st_lsm6dsx_i3c_regmap_config = {
28+
.reg_bits = 8,
29+
.val_bits = 8,
30+
};
31+
const struct i3c_device_id *id = i3c_device_match_id(i3cdev,
32+
st_lsm6dsx_i3c_ids);
33+
struct regmap *regmap;
34+
35+
regmap = devm_regmap_init_i3c(i3cdev, &st_lsm6dsx_i3c_regmap_config);
36+
if (IS_ERR(regmap)) {
37+
dev_err(&i3cdev->dev, "Failed to register i3c regmap %d\n",
38+
(int)PTR_ERR(regmap));
39+
return PTR_ERR(regmap);
40+
}
41+
42+
return st_lsm6dsx_probe(&i3cdev->dev, 0, (uintptr_t)id->data, regmap);
43+
}
44+
45+
static struct i3c_driver st_lsm6dsx_driver = {
46+
.driver = {
47+
.name = "st_lsm6dsx_i3c",
48+
.pm = &st_lsm6dsx_pm_ops,
49+
},
50+
.probe = st_lsm6dsx_i3c_probe,
51+
.id_table = st_lsm6dsx_i3c_ids,
52+
};
53+
module_i3c_driver(st_lsm6dsx_driver);
54+
55+
MODULE_AUTHOR("Vitor Soares <[email protected]>");
56+
MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i3c driver");
57+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)