treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
[sfrench/cifs-2.6.git] / drivers / hwmon / pmbus / tps53679.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Hardware monitoring driver for Texas Instruments TPS53679
4  *
5  * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
6  * Copyright (c) 2017 Vadim Pasternak <vadimp@mellanox.com>
7  */
8
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"
15
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
22
23 static int tps53679_identify(struct i2c_client *client,
24                              struct pmbus_driver_info *info)
25 {
26         u8 vout_params;
27         int ret;
28
29         /* Read the register with VOUT scaling value.*/
30         ret = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
31         if (ret < 0)
32                 return ret;
33
34         vout_params = ret & GENMASK(4, 0);
35
36         switch (vout_params) {
37         case TPS53679_PROT_VR13_10MV:
38         case TPS53679_PROT_VR12_5_10MV:
39                 info->vrm_version = vr13;
40                 break;
41         case TPS53679_PROT_VR13_5MV:
42         case TPS53679_PROT_VR12_5MV:
43         case TPS53679_PROT_IMVP8_5MV:
44                 info->vrm_version = vr12;
45                 break;
46         default:
47                 return -EINVAL;
48         }
49
50         return 0;
51 }
52
53 static struct pmbus_driver_info tps53679_info = {
54         .pages = TPS53679_PAGE_NUM,
55         .format[PSC_VOLTAGE_IN] = linear,
56         .format[PSC_VOLTAGE_OUT] = vid,
57         .format[PSC_TEMPERATURE] = linear,
58         .format[PSC_CURRENT_OUT] = linear,
59         .format[PSC_POWER] = linear,
60         .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
61                 PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
62                 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
63                 PMBUS_HAVE_POUT,
64         .func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
65                 PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
66                 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP |
67                 PMBUS_HAVE_POUT,
68         .identify = tps53679_identify,
69 };
70
71 static int tps53679_probe(struct i2c_client *client,
72                           const struct i2c_device_id *id)
73 {
74         struct pmbus_driver_info *info;
75
76         info = devm_kmemdup(&client->dev, &tps53679_info, sizeof(*info),
77                             GFP_KERNEL);
78         if (!info)
79                 return -ENOMEM;
80
81         return pmbus_do_probe(client, id, info);
82 }
83
84 static const struct i2c_device_id tps53679_id[] = {
85         {"tps53679", 0},
86         {}
87 };
88
89 MODULE_DEVICE_TABLE(i2c, tps53679_id);
90
91 static const struct of_device_id __maybe_unused tps53679_of_match[] = {
92         {.compatible = "ti,tps53679"},
93         {}
94 };
95 MODULE_DEVICE_TABLE(of, tps53679_of_match);
96
97 static struct i2c_driver tps53679_driver = {
98         .driver = {
99                 .name = "tps53679",
100                 .of_match_table = of_match_ptr(tps53679_of_match),
101         },
102         .probe = tps53679_probe,
103         .remove = pmbus_do_remove,
104         .id_table = tps53679_id,
105 };
106
107 module_i2c_driver(tps53679_driver);
108
109 MODULE_AUTHOR("Vadim Pasternak <vadimp@mellanox.com>");
110 MODULE_DESCRIPTION("PMBus driver for Texas Instruments TPS53679");
111 MODULE_LICENSE("GPL");