GNU Linux-libre 4.9.282-gnu1
[releases.git] / drivers / iio / accel / kxsd9-i2c.c
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                 .pm = &kxsd9_dev_pm_ops,
59         },
60         .probe          = kxsd9_i2c_probe,
61         .remove         = kxsd9_i2c_remove,
62         .id_table       = kxsd9_i2c_id,
63 };
64 module_i2c_driver(kxsd9_i2c_driver);