Merge tag 'hsi-for-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-hsi
[cascardo/linux.git] / drivers / mfd / lp873x.c
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * Author: Keerthy <j-keerthy@ti.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation version 2.
9  *
10  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11  * kind, whether express or implied; without even the implied warranty
12  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15
16 #include <linux/interrupt.h>
17 #include <linux/mfd/core.h>
18 #include <linux/module.h>
19 #include <linux/of_device.h>
20 #include <linux/regmap.h>
21
22 #include <linux/mfd/lp873x.h>
23
24 static const struct regmap_config lp873x_regmap_config = {
25         .reg_bits = 8,
26         .val_bits = 8,
27         .max_register = LP873X_REG_MAX,
28 };
29
30 static const struct mfd_cell lp873x_cells[] = {
31         { .name = "lp873x-regulator", },
32         { .name = "lp873x-gpio", },
33 };
34
35 static int lp873x_probe(struct i2c_client *client,
36                         const struct i2c_device_id *ids)
37 {
38         struct lp873x *lp873;
39         int ret;
40         unsigned int otpid;
41
42         lp873 = devm_kzalloc(&client->dev, sizeof(*lp873), GFP_KERNEL);
43         if (!lp873)
44                 return -ENOMEM;
45
46         lp873->dev = &client->dev;
47
48         lp873->regmap = devm_regmap_init_i2c(client, &lp873x_regmap_config);
49         if (IS_ERR(lp873->regmap)) {
50                 ret = PTR_ERR(lp873->regmap);
51                 dev_err(lp873->dev,
52                         "Failed to initialize register map: %d\n", ret);
53                 return ret;
54         }
55
56         mutex_init(&lp873->lock);
57
58         ret = regmap_read(lp873->regmap, LP873X_REG_OTP_REV, &otpid);
59         if (ret) {
60                 dev_err(lp873->dev, "Failed to read OTP ID\n");
61                 return ret;
62         }
63
64         lp873->rev = otpid & LP873X_OTP_REV_OTP_ID;
65
66         i2c_set_clientdata(client, lp873);
67
68         ret = mfd_add_devices(lp873->dev, PLATFORM_DEVID_AUTO, lp873x_cells,
69                               ARRAY_SIZE(lp873x_cells), NULL, 0, NULL);
70
71         return ret;
72 }
73
74 static const struct of_device_id of_lp873x_match_table[] = {
75         { .compatible = "ti,lp8733", },
76         { .compatible = "ti,lp8732", },
77         {}
78 };
79 MODULE_DEVICE_TABLE(of, of_lp873x_match_table);
80
81 static const struct i2c_device_id lp873x_id_table[] = {
82         { "lp873x", 0 },
83         { },
84 };
85 MODULE_DEVICE_TABLE(i2c, lp873x_id_table);
86
87 static struct i2c_driver lp873x_driver = {
88         .driver = {
89                 .name   = "lp873x",
90                 .of_match_table = of_lp873x_match_table,
91         },
92         .probe          = lp873x_probe,
93         .id_table       = lp873x_id_table,
94 };
95 module_i2c_driver(lp873x_driver);
96
97 MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
98 MODULE_DESCRIPTION("LP873X chip family Multi-Function Device driver");
99 MODULE_LICENSE("GPL v2");