Merge branch 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / drivers / hwmon / pmbus / max31785.c
1 /*
2  * Copyright (C) 2017 IBM Corp.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  */
9
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/err.h>
14 #include <linux/i2c.h>
15 #include "pmbus.h"
16
17 enum max31785_regs {
18         MFR_REVISION            = 0x9b,
19 };
20
21 #define MAX31785_NR_PAGES               23
22
23 #define MAX31785_FAN_FUNCS \
24         (PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12)
25
26 #define MAX31785_TEMP_FUNCS \
27         (PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP)
28
29 #define MAX31785_VOUT_FUNCS \
30         (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT)
31
32 static const struct pmbus_driver_info max31785_info = {
33         .pages = MAX31785_NR_PAGES,
34
35         /* RPM */
36         .format[PSC_FAN] = direct,
37         .m[PSC_FAN] = 1,
38         .b[PSC_FAN] = 0,
39         .R[PSC_FAN] = 0,
40         .func[0] = MAX31785_FAN_FUNCS,
41         .func[1] = MAX31785_FAN_FUNCS,
42         .func[2] = MAX31785_FAN_FUNCS,
43         .func[3] = MAX31785_FAN_FUNCS,
44         .func[4] = MAX31785_FAN_FUNCS,
45         .func[5] = MAX31785_FAN_FUNCS,
46
47         .format[PSC_TEMPERATURE] = direct,
48         .m[PSC_TEMPERATURE] = 1,
49         .b[PSC_TEMPERATURE] = 0,
50         .R[PSC_TEMPERATURE] = 2,
51         .func[6]  = MAX31785_TEMP_FUNCS,
52         .func[7]  = MAX31785_TEMP_FUNCS,
53         .func[8]  = MAX31785_TEMP_FUNCS,
54         .func[9]  = MAX31785_TEMP_FUNCS,
55         .func[10] = MAX31785_TEMP_FUNCS,
56         .func[11] = MAX31785_TEMP_FUNCS,
57         .func[12] = MAX31785_TEMP_FUNCS,
58         .func[13] = MAX31785_TEMP_FUNCS,
59         .func[14] = MAX31785_TEMP_FUNCS,
60         .func[15] = MAX31785_TEMP_FUNCS,
61         .func[16] = MAX31785_TEMP_FUNCS,
62
63         .format[PSC_VOLTAGE_OUT] = direct,
64         .m[PSC_VOLTAGE_OUT] = 1,
65         .b[PSC_VOLTAGE_OUT] = 0,
66         .R[PSC_VOLTAGE_OUT] = 0,
67         .func[17] = MAX31785_VOUT_FUNCS,
68         .func[18] = MAX31785_VOUT_FUNCS,
69         .func[19] = MAX31785_VOUT_FUNCS,
70         .func[20] = MAX31785_VOUT_FUNCS,
71         .func[21] = MAX31785_VOUT_FUNCS,
72         .func[22] = MAX31785_VOUT_FUNCS,
73 };
74
75 static int max31785_probe(struct i2c_client *client,
76                           const struct i2c_device_id *id)
77 {
78         struct device *dev = &client->dev;
79         struct pmbus_driver_info *info;
80         s64 ret;
81
82         info = devm_kzalloc(dev, sizeof(struct pmbus_driver_info), GFP_KERNEL);
83         if (!info)
84                 return -ENOMEM;
85
86         *info = max31785_info;
87
88         ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 255);
89         if (ret < 0)
90                 return ret;
91
92         return pmbus_do_probe(client, id, info);
93 }
94
95 static const struct i2c_device_id max31785_id[] = {
96         { "max31785", 0 },
97         { "max31785a", 0 },
98         { },
99 };
100
101 MODULE_DEVICE_TABLE(i2c, max31785_id);
102
103 static struct i2c_driver max31785_driver = {
104         .driver = {
105                 .name = "max31785",
106         },
107         .probe = max31785_probe,
108         .remove = pmbus_do_remove,
109         .id_table = max31785_id,
110 };
111
112 module_i2c_driver(max31785_driver);
113
114 MODULE_AUTHOR("Andrew Jeffery <andrew@aj.id.au>");
115 MODULE_DESCRIPTION("PMBus driver for the Maxim MAX31785");
116 MODULE_LICENSE("GPL");