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