]>
Commit | Line | Data |
---|---|---|
1e349600 K |
1 | /* |
2 | * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ | |
3 | * | |
4 | * Author: Keerthy <[email protected]> | |
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 | ||
11 | #include <linux/interrupt.h> | |
12 | #include <linux/mfd/core.h> | |
13 | #include <linux/module.h> | |
14 | #include <linux/of_device.h> | |
15 | #include <linux/regmap.h> | |
16 | ||
17 | #include <linux/mfd/lp87565.h> | |
18 | ||
19 | static const struct regmap_config lp87565_regmap_config = { | |
20 | .reg_bits = 8, | |
21 | .val_bits = 8, | |
22 | .max_register = LP87565_REG_MAX, | |
23 | }; | |
24 | ||
25 | static const struct mfd_cell lp87565_cells[] = { | |
26 | { .name = "lp87565-q1-regulator", }, | |
27 | { .name = "lp87565-q1-gpio", }, | |
28 | }; | |
29 | ||
30 | static const struct of_device_id of_lp87565_match_table[] = { | |
31 | { .compatible = "ti,lp87565", }, | |
32 | { | |
33 | .compatible = "ti,lp87565-q1", | |
34 | .data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1, | |
35 | }, | |
36 | {} | |
37 | }; | |
38 | MODULE_DEVICE_TABLE(of, of_lp87565_match_table); | |
39 | ||
40 | static int lp87565_probe(struct i2c_client *client, | |
41 | const struct i2c_device_id *ids) | |
42 | { | |
43 | struct lp87565 *lp87565; | |
44 | const struct of_device_id *of_id; | |
45 | int ret; | |
46 | unsigned int otpid; | |
47 | ||
48 | lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL); | |
49 | if (!lp87565) | |
50 | return -ENOMEM; | |
51 | ||
52 | lp87565->dev = &client->dev; | |
53 | ||
54 | lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config); | |
55 | if (IS_ERR(lp87565->regmap)) { | |
56 | ret = PTR_ERR(lp87565->regmap); | |
57 | dev_err(lp87565->dev, | |
58 | "Failed to initialize register map: %d\n", ret); | |
59 | return ret; | |
60 | } | |
61 | ||
62 | ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid); | |
63 | if (ret) { | |
64 | dev_err(lp87565->dev, "Failed to read OTP ID\n"); | |
65 | return ret; | |
66 | } | |
67 | ||
68 | lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID; | |
69 | ||
70 | of_id = of_match_device(of_lp87565_match_table, &client->dev); | |
71 | if (of_id) | |
72 | lp87565->dev_type = (enum lp87565_device_type)of_id->data; | |
73 | ||
74 | i2c_set_clientdata(client, lp87565); | |
75 | ||
ea3993a9 AL |
76 | return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO, |
77 | lp87565_cells, ARRAY_SIZE(lp87565_cells), | |
78 | NULL, 0, NULL); | |
1e349600 K |
79 | } |
80 | ||
81 | static const struct i2c_device_id lp87565_id_table[] = { | |
82 | { "lp87565-q1", 0 }, | |
83 | { }, | |
84 | }; | |
85 | MODULE_DEVICE_TABLE(i2c, lp87565_id_table); | |
86 | ||
87 | static struct i2c_driver lp87565_driver = { | |
88 | .driver = { | |
89 | .name = "lp87565", | |
90 | .of_match_table = of_lp87565_match_table, | |
91 | }, | |
92 | .probe = lp87565_probe, | |
93 | .id_table = lp87565_id_table, | |
94 | }; | |
95 | module_i2c_driver(lp87565_driver); | |
96 | ||
97 | MODULE_AUTHOR("J Keerthy <[email protected]>"); | |
98 | MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver"); | |
99 | MODULE_LICENSE("GPL v2"); |