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