treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / hwmon / pmbus / tps53679.c
blob9c22e9013dd7404e1c3828b07a8d73532f0f795e
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Hardware monitoring driver for Texas Instruments TPS53679
5 * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2017 Vadim Pasternak <vadimp@mellanox.com>
7 */
9 #include <linux/err.h>
10 #include <linux/i2c.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include "pmbus.h"
16 #define TPS53679_PROT_VR12_5MV 0x01 /* VR12.0 mode, 5-mV DAC */
17 #define TPS53679_PROT_VR12_5_10MV 0x02 /* VR12.5 mode, 10-mV DAC */
18 #define TPS53679_PROT_VR13_10MV 0x04 /* VR13.0 mode, 10-mV DAC */
19 #define TPS53679_PROT_IMVP8_5MV 0x05 /* IMVP8 mode, 5-mV DAC */
20 #define TPS53679_PROT_VR13_5MV 0x07 /* VR13.0 mode, 5-mV DAC */
21 #define TPS53679_PAGE_NUM 2
23 static int tps53679_identify(struct i2c_client *client,
24 struct pmbus_driver_info *info)
26 u8 vout_params;
27 int i, ret;
29 for (i = 0; i < TPS53679_PAGE_NUM; i++) {
30 /* Read the register with VOUT scaling value.*/
31 ret = pmbus_read_byte_data(client, i, PMBUS_VOUT_MODE);
32 if (ret < 0)
33 return ret;
35 vout_params = ret & GENMASK(4, 0);
37 switch (vout_params) {
38 case TPS53679_PROT_VR13_10MV:
39 case TPS53679_PROT_VR12_5_10MV:
40 info->vrm_version[i] = vr13;
41 break;
42 case TPS53679_PROT_VR13_5MV:
43 case TPS53679_PROT_VR12_5MV:
44 case TPS53679_PROT_IMVP8_5MV:
45 info->vrm_version[i] = vr12;
46 break;
47 default:
48 return -EINVAL;
52 return 0;
55 static struct pmbus_driver_info tps53679_info = {
56 .pages = TPS53679_PAGE_NUM,
57 .format[PSC_VOLTAGE_IN] = linear,
58 .format[PSC_VOLTAGE_OUT] = vid,
59 .format[PSC_TEMPERATURE] = linear,
60 .format[PSC_CURRENT_OUT] = linear,
61 .format[PSC_POWER] = linear,
62 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
63 PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
64 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
65 PMBUS_HAVE_POUT,
66 .func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
67 PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
68 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
69 PMBUS_HAVE_POUT,
70 .identify = tps53679_identify,
73 static int tps53679_probe(struct i2c_client *client,
74 const struct i2c_device_id *id)
76 struct pmbus_driver_info *info;
78 info = devm_kmemdup(&client->dev, &tps53679_info, sizeof(*info),
79 GFP_KERNEL);
80 if (!info)
81 return -ENOMEM;
83 return pmbus_do_probe(client, id, info);
86 static const struct i2c_device_id tps53679_id[] = {
87 {"tps53679", 0},
88 {"tps53688", 0},
92 MODULE_DEVICE_TABLE(i2c, tps53679_id);
94 static const struct of_device_id __maybe_unused tps53679_of_match[] = {
95 {.compatible = "ti,tps53679"},
96 {.compatible = "ti,tps53688"},
99 MODULE_DEVICE_TABLE(of, tps53679_of_match);
101 static struct i2c_driver tps53679_driver = {
102 .driver = {
103 .name = "tps53679",
104 .of_match_table = of_match_ptr(tps53679_of_match),
106 .probe = tps53679_probe,
107 .remove = pmbus_do_remove,
108 .id_table = tps53679_id,
111 module_i2c_driver(tps53679_driver);
113 MODULE_AUTHOR("Vadim Pasternak <vadimp@mellanox.com>");
114 MODULE_DESCRIPTION("PMBus driver for Texas Instruments TPS53679");
115 MODULE_LICENSE("GPL");