blob: 8ad688fe75f90a19d8378542c9058ad5403ba333 [file] [log] [blame]
Keerthy1e349602017-06-13 10:28:40 +05301/*
2 * Copyright (C) 2017 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
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
19static const struct regmap_config lp87565_regmap_config = {
20 .reg_bits = 8,
21 .val_bits = 8,
22 .max_register = LP87565_REG_MAX,
23};
24
25static const struct mfd_cell lp87565_cells[] = {
26 { .name = "lp87565-q1-regulator", },
27 { .name = "lp87565-q1-gpio", },
28};
29
30static 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 },
Keerthy013e8682019-05-15 15:38:47 +053036 {
37 .compatible = "ti,lp87561-q1",
38 .data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1,
39 },
Keerthy1e349602017-06-13 10:28:40 +053040 {}
41};
42MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
43
44static int lp87565_probe(struct i2c_client *client,
45 const struct i2c_device_id *ids)
46{
47 struct lp87565 *lp87565;
48 const struct of_device_id *of_id;
49 int ret;
50 unsigned int otpid;
51
52 lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
53 if (!lp87565)
54 return -ENOMEM;
55
56 lp87565->dev = &client->dev;
57
58 lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
59 if (IS_ERR(lp87565->regmap)) {
60 ret = PTR_ERR(lp87565->regmap);
61 dev_err(lp87565->dev,
62 "Failed to initialize register map: %d\n", ret);
63 return ret;
64 }
65
66 ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
67 if (ret) {
68 dev_err(lp87565->dev, "Failed to read OTP ID\n");
69 return ret;
70 }
71
72 lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
73
74 of_id = of_match_device(of_lp87565_match_table, &client->dev);
75 if (of_id)
76 lp87565->dev_type = (enum lp87565_device_type)of_id->data;
77
78 i2c_set_clientdata(client, lp87565);
79
Axel Linea3993a2017-07-30 18:58:15 +080080 return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
81 lp87565_cells, ARRAY_SIZE(lp87565_cells),
82 NULL, 0, NULL);
Keerthy1e349602017-06-13 10:28:40 +053083}
84
85static const struct i2c_device_id lp87565_id_table[] = {
86 { "lp87565-q1", 0 },
87 { },
88};
89MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
90
91static struct i2c_driver lp87565_driver = {
92 .driver = {
93 .name = "lp87565",
94 .of_match_table = of_lp87565_match_table,
95 },
96 .probe = lp87565_probe,
97 .id_table = lp87565_id_table,
98};
99module_i2c_driver(lp87565_driver);
100
101MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
102MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
103MODULE_LICENSE("GPL v2");