Linux-libre 5.0.14-gnu
[librecmc/linux-libre.git] / drivers / iio / light / st_uvis25_i2c.c
1 /*
2  * STMicroelectronics uvis25 i2c driver
3  *
4  * Copyright 2017 STMicroelectronics Inc.
5  *
6  * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
7  *
8  * Licensed under the GPL-2.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/acpi.h>
14 #include <linux/i2c.h>
15 #include <linux/slab.h>
16 #include <linux/regmap.h>
17
18 #include "st_uvis25.h"
19
20 #define UVIS25_I2C_AUTO_INCREMENT       BIT(7)
21
22 static const struct regmap_config st_uvis25_i2c_regmap_config = {
23         .reg_bits = 8,
24         .val_bits = 8,
25         .write_flag_mask = UVIS25_I2C_AUTO_INCREMENT,
26         .read_flag_mask = UVIS25_I2C_AUTO_INCREMENT,
27 };
28
29 static int st_uvis25_i2c_probe(struct i2c_client *client,
30                                const struct i2c_device_id *id)
31 {
32         struct regmap *regmap;
33
34         regmap = devm_regmap_init_i2c(client, &st_uvis25_i2c_regmap_config);
35         if (IS_ERR(regmap)) {
36                 dev_err(&client->dev, "Failed to register i2c regmap %d\n",
37                         (int)PTR_ERR(regmap));
38                 return PTR_ERR(regmap);
39         }
40
41         return st_uvis25_probe(&client->dev, client->irq, regmap);
42 }
43
44 static const struct of_device_id st_uvis25_i2c_of_match[] = {
45         { .compatible = "st,uvis25", },
46         {},
47 };
48 MODULE_DEVICE_TABLE(of, st_uvis25_i2c_of_match);
49
50 static const struct i2c_device_id st_uvis25_i2c_id_table[] = {
51         { ST_UVIS25_DEV_NAME },
52         {},
53 };
54 MODULE_DEVICE_TABLE(i2c, st_uvis25_i2c_id_table);
55
56 static struct i2c_driver st_uvis25_driver = {
57         .driver = {
58                 .name = "st_uvis25_i2c",
59                 .pm = &st_uvis25_pm_ops,
60                 .of_match_table = of_match_ptr(st_uvis25_i2c_of_match),
61         },
62         .probe = st_uvis25_i2c_probe,
63         .id_table = st_uvis25_i2c_id_table,
64 };
65 module_i2c_driver(st_uvis25_driver);
66
67 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
68 MODULE_DESCRIPTION("STMicroelectronics uvis25 i2c driver");
69 MODULE_LICENSE("GPL v2");