gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / mfd / lp87565.c
blob4a5c8ade4ae032ff792064aa6a6435c1005a11c5
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
5 * Author: Keerthy <j-keerthy@ti.com>
6 */
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>
14 #include <linux/mfd/lp87565.h>
16 static const struct regmap_config lp87565_regmap_config = {
17 .reg_bits = 8,
18 .val_bits = 8,
19 .max_register = LP87565_REG_MAX,
22 static const struct mfd_cell lp87565_cells[] = {
23 { .name = "lp87565-q1-regulator", },
24 { .name = "lp87565-q1-gpio", },
27 static const struct of_device_id of_lp87565_match_table[] = {
28 { .compatible = "ti,lp87565", },
30 .compatible = "ti,lp87565-q1",
31 .data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1,
34 .compatible = "ti,lp87561-q1",
35 .data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1,
39 MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
41 static int lp87565_probe(struct i2c_client *client,
42 const struct i2c_device_id *ids)
44 struct lp87565 *lp87565;
45 const struct of_device_id *of_id;
46 int ret;
47 unsigned int otpid;
49 lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
50 if (!lp87565)
51 return -ENOMEM;
53 lp87565->dev = &client->dev;
55 lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
56 if (IS_ERR(lp87565->regmap)) {
57 ret = PTR_ERR(lp87565->regmap);
58 dev_err(lp87565->dev,
59 "Failed to initialize register map: %d\n", ret);
60 return ret;
63 ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
64 if (ret) {
65 dev_err(lp87565->dev, "Failed to read OTP ID\n");
66 return ret;
69 lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
71 of_id = of_match_device(of_lp87565_match_table, &client->dev);
72 if (of_id)
73 lp87565->dev_type = (enum lp87565_device_type)of_id->data;
75 i2c_set_clientdata(client, lp87565);
77 return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
78 lp87565_cells, ARRAY_SIZE(lp87565_cells),
79 NULL, 0, NULL);
82 static const struct i2c_device_id lp87565_id_table[] = {
83 { "lp87565-q1", 0 },
84 { },
86 MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
88 static struct i2c_driver lp87565_driver = {
89 .driver = {
90 .name = "lp87565",
91 .of_match_table = of_lp87565_match_table,
93 .probe = lp87565_probe,
94 .id_table = lp87565_id_table,
96 module_i2c_driver(lp87565_driver);
98 MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
99 MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
100 MODULE_LICENSE("GPL v2");