Skip to content

Commit a483ab7

Browse files
Linus Walleijjic23
authored andcommitted
iio: accel: kxsd9: Add I2C transport
This adds I2C regmap transport for the KXSD9 driver. Tested on the KXSD9 sensor on the APQ8060 Dragonboard. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 0d1fb2d commit a483ab7

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

drivers/iio/accel/Kconfig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ config KXSD9
121121
tristate "Kionix KXSD9 Accelerometer Driver"
122122
help
123123
Say yes here to build support for the Kionix KXSD9 accelerometer.
124-
Currently this only supports the device via an SPI interface.
124+
It can be accessed using an (optional) SPI or I2C interface.
125125

126126
To compile this driver as a module, choose M here: the module
127127
will be called kxsd9.
@@ -136,6 +136,16 @@ config KXSD9_SPI
136136
Say yes here to enable the Kionix KXSD9 accelerometer
137137
SPI transport channel.
138138

139+
config KXSD9_I2C
140+
tristate "Kionix KXSD9 I2C transport"
141+
depends on KXSD9
142+
depends on I2C
143+
default KXSD9
144+
select REGMAP_I2C
145+
help
146+
Say yes here to enable the Kionix KXSD9 accelerometer
147+
I2C transport channel.
148+
139149
config KXCJK1013
140150
tristate "Kionix 3-Axis Accelerometer Driver"
141151
depends on I2C

drivers/iio/accel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
1414
obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
1515
obj-$(CONFIG_KXSD9) += kxsd9.o
1616
obj-$(CONFIG_KXSD9_SPI) += kxsd9-spi.o
17+
obj-$(CONFIG_KXSD9_I2C) += kxsd9-i2c.o
1718

1819
obj-$(CONFIG_MMA7455) += mma7455_core.o
1920
obj-$(CONFIG_MMA7455_I2C) += mma7455_i2c.o

drivers/iio/accel/kxsd9-i2c.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <linux/device.h>
2+
#include <linux/kernel.h>
3+
#include <linux/module.h>
4+
#include <linux/slab.h>
5+
#include <linux/i2c.h>
6+
#include <linux/delay.h>
7+
#include <linux/regmap.h>
8+
9+
#include "kxsd9.h"
10+
11+
static int kxsd9_i2c_probe(struct i2c_client *i2c,
12+
const struct i2c_device_id *id)
13+
{
14+
static const struct regmap_config config = {
15+
.reg_bits = 8,
16+
.val_bits = 8,
17+
.max_register = 0x0e,
18+
};
19+
struct regmap *regmap;
20+
21+
regmap = devm_regmap_init_i2c(i2c, &config);
22+
if (IS_ERR(regmap)) {
23+
dev_err(&i2c->dev, "Failed to register i2c regmap %d\n",
24+
(int)PTR_ERR(regmap));
25+
return PTR_ERR(regmap);
26+
}
27+
28+
return kxsd9_common_probe(&i2c->dev,
29+
regmap,
30+
i2c->name);
31+
}
32+
33+
static int kxsd9_i2c_remove(struct i2c_client *client)
34+
{
35+
return kxsd9_common_remove(&client->dev);
36+
}
37+
38+
#ifdef CONFIG_OF
39+
static const struct of_device_id kxsd9_of_match[] = {
40+
{ .compatible = "kionix,kxsd9", },
41+
{ },
42+
};
43+
MODULE_DEVICE_TABLE(of, kxsd9_of_match);
44+
#else
45+
#define kxsd9_of_match NULL
46+
#endif
47+
48+
static const struct i2c_device_id kxsd9_i2c_id[] = {
49+
{"kxsd9", 0},
50+
{ },
51+
};
52+
MODULE_DEVICE_TABLE(i2c, kxsd9_i2c_id);
53+
54+
static struct i2c_driver kxsd9_i2c_driver = {
55+
.driver = {
56+
.name = "kxsd9",
57+
.of_match_table = of_match_ptr(kxsd9_of_match),
58+
},
59+
.probe = kxsd9_i2c_probe,
60+
.remove = kxsd9_i2c_remove,
61+
.id_table = kxsd9_i2c_id,
62+
};
63+
module_i2c_driver(kxsd9_i2c_driver);

0 commit comments

Comments
 (0)