2 * Copyright (C) 2017 IBM Corp.
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.
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>
21 #define MAX31785_NR_PAGES 23
23 #define MAX31785_FAN_FUNCS \
24 (PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12)
26 #define MAX31785_TEMP_FUNCS \
27 (PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP)
29 #define MAX31785_VOUT_FUNCS \
30 (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT)
32 static const struct pmbus_driver_info max31785_info = {
33 .pages = MAX31785_NR_PAGES,
36 .format[PSC_FAN] = direct,
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,
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,
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,
75 static int max31785_probe(struct i2c_client *client,
76 const struct i2c_device_id *id)
78 struct device *dev = &client->dev;
79 struct pmbus_driver_info *info;
82 info = devm_kzalloc(dev, sizeof(struct pmbus_driver_info), GFP_KERNEL);
86 *info = max31785_info;
88 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 255);
92 return pmbus_do_probe(client, id, info);
95 static const struct i2c_device_id max31785_id[] = {
101 MODULE_DEVICE_TABLE(i2c, max31785_id);
103 static struct i2c_driver max31785_driver = {
107 .probe = max31785_probe,
108 .remove = pmbus_do_remove,
109 .id_table = max31785_id,
112 module_i2c_driver(max31785_driver);
114 MODULE_AUTHOR("Andrew Jeffery <andrew@aj.id.au>");
115 MODULE_DESCRIPTION("PMBus driver for the Maxim MAX31785");
116 MODULE_LICENSE("GPL");