xref: /linux/drivers/iio/accel/kxsd9-i2c.c (revision 26fbb4c8c7c3ee9a4c3b4de555a8587b5a19154e)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/device.h>
3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/mod_devicetable.h>
6 #include <linux/slab.h>
7 #include <linux/i2c.h>
8 #include <linux/delay.h>
9 #include <linux/regmap.h>
10 
11 #include "kxsd9.h"
12 
13 static int kxsd9_i2c_probe(struct i2c_client *i2c,
14 			   const struct i2c_device_id *id)
15 {
16 	static const struct regmap_config config = {
17 		.reg_bits = 8,
18 		.val_bits = 8,
19 		.max_register = 0x0e,
20 	};
21 	struct regmap *regmap;
22 
23 	regmap = devm_regmap_init_i2c(i2c, &config);
24 	if (IS_ERR(regmap)) {
25 		dev_err(&i2c->dev, "Failed to register i2c regmap: %pe\n",
26 			regmap);
27 		return PTR_ERR(regmap);
28 	}
29 
30 	return kxsd9_common_probe(&i2c->dev,
31 				  regmap,
32 				  i2c->name);
33 }
34 
35 static int kxsd9_i2c_remove(struct i2c_client *client)
36 {
37 	return kxsd9_common_remove(&client->dev);
38 }
39 
40 static const struct of_device_id kxsd9_of_match[] = {
41 	{ .compatible = "kionix,kxsd9", },
42 	{ },
43 };
44 MODULE_DEVICE_TABLE(of, kxsd9_of_match);
45 
46 static const struct i2c_device_id kxsd9_i2c_id[] = {
47 	{"kxsd9", 0},
48 	{ },
49 };
50 MODULE_DEVICE_TABLE(i2c, kxsd9_i2c_id);
51 
52 static struct i2c_driver kxsd9_i2c_driver = {
53 	.driver = {
54 		.name	= "kxsd9",
55 		.of_match_table = kxsd9_of_match,
56 		.pm = &kxsd9_dev_pm_ops,
57 	},
58 	.probe		= kxsd9_i2c_probe,
59 	.remove		= kxsd9_i2c_remove,
60 	.id_table	= kxsd9_i2c_id,
61 };
62 module_i2c_driver(kxsd9_i2c_driver);
63 
64 MODULE_LICENSE("GPL v2");
65 MODULE_DESCRIPTION("KXSD9 accelerometer I2C interface");
66