blob: 9c21483d96535cedc48c73bc23d7e5289389b0e0 [file] [log] [blame]
Thomas Gleixnera10e7632019-05-31 01:09:32 -07001// SPDX-License-Identifier: GPL-2.0-only
Keerthy1e349602017-06-13 10:28:40 +05302/*
Alexander A. Klimov4f4ed4542020-07-22 21:24:54 +02003 * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
Keerthy1e349602017-06-13 10:28:40 +05304 *
5 * Author: Keerthy <j-keerthy@ti.com>
Keerthy1e349602017-06-13 10:28:40 +05306 */
7
8#include <linux/interrupt.h>
9#include <linux/mfd/core.h>
10#include <linux/module.h>
11#include <linux/of_device.h>
12#include <linux/regmap.h>
13
14#include <linux/mfd/lp87565.h>
15
16static const struct regmap_config lp87565_regmap_config = {
17 .reg_bits = 8,
18 .val_bits = 8,
19 .max_register = LP87565_REG_MAX,
20};
21
22static const struct mfd_cell lp87565_cells[] = {
23 { .name = "lp87565-q1-regulator", },
24 { .name = "lp87565-q1-gpio", },
25};
26
27static const struct of_device_id of_lp87565_match_table[] = {
28 { .compatible = "ti,lp87565", },
29 {
Luca Ceresoli4b6ec082020-09-02 16:22:59 +020030 .compatible = "ti,lp87524-q1",
31 .data = (void *)LP87565_DEVICE_TYPE_LP87524_Q1,
32 },
33 {
Keerthy1e349602017-06-13 10:28:40 +053034 .compatible = "ti,lp87565-q1",
35 .data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1,
36 },
Keerthy013e8682019-05-15 15:38:47 +053037 {
38 .compatible = "ti,lp87561-q1",
39 .data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1,
40 },
Keerthy1e349602017-06-13 10:28:40 +053041 {}
42};
43MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
44
45static int lp87565_probe(struct i2c_client *client,
46 const struct i2c_device_id *ids)
47{
48 struct lp87565 *lp87565;
49 const struct of_device_id *of_id;
50 int ret;
51 unsigned int otpid;
52
53 lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
54 if (!lp87565)
55 return -ENOMEM;
56
57 lp87565->dev = &client->dev;
58
59 lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
60 if (IS_ERR(lp87565->regmap)) {
61 ret = PTR_ERR(lp87565->regmap);
62 dev_err(lp87565->dev,
63 "Failed to initialize register map: %d\n", ret);
64 return ret;
65 }
66
67 ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
68 if (ret) {
69 dev_err(lp87565->dev, "Failed to read OTP ID\n");
70 return ret;
71 }
72
73 lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
74
75 of_id = of_match_device(of_lp87565_match_table, &client->dev);
76 if (of_id)
77 lp87565->dev_type = (enum lp87565_device_type)of_id->data;
78
79 i2c_set_clientdata(client, lp87565);
80
Axel Linea3993a2017-07-30 18:58:15 +080081 return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
82 lp87565_cells, ARRAY_SIZE(lp87565_cells),
83 NULL, 0, NULL);
Keerthy1e349602017-06-13 10:28:40 +053084}
85
86static const struct i2c_device_id lp87565_id_table[] = {
87 { "lp87565-q1", 0 },
88 { },
89};
90MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
91
92static struct i2c_driver lp87565_driver = {
93 .driver = {
94 .name = "lp87565",
95 .of_match_table = of_lp87565_match_table,
96 },
97 .probe = lp87565_probe,
98 .id_table = lp87565_id_table,
99};
100module_i2c_driver(lp87565_driver);
101
102MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
103MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
104MODULE_LICENSE("GPL v2");