xref: /openbmc/linux/drivers/hwmon/pmbus/max16064.c (revision b830f94f)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Hardware monitoring driver for Maxim MAX16064
4  *
5  * Copyright (c) 2011 Ericsson AB.
6  */
7 
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/err.h>
12 #include <linux/i2c.h>
13 #include "pmbus.h"
14 
15 #define MAX16064_MFR_VOUT_PEAK		0xd4
16 #define MAX16064_MFR_TEMPERATURE_PEAK	0xd6
17 
18 static int max16064_read_word_data(struct i2c_client *client, int page, int reg)
19 {
20 	int ret;
21 
22 	switch (reg) {
23 	case PMBUS_VIRT_READ_VOUT_MAX:
24 		ret = pmbus_read_word_data(client, page,
25 					   MAX16064_MFR_VOUT_PEAK);
26 		break;
27 	case PMBUS_VIRT_READ_TEMP_MAX:
28 		ret = pmbus_read_word_data(client, page,
29 					   MAX16064_MFR_TEMPERATURE_PEAK);
30 		break;
31 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
32 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
33 		ret = 0;
34 		break;
35 	default:
36 		ret = -ENODATA;
37 		break;
38 	}
39 	return ret;
40 }
41 
42 static int max16064_write_word_data(struct i2c_client *client, int page,
43 				    int reg, u16 word)
44 {
45 	int ret;
46 
47 	switch (reg) {
48 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
49 		ret = pmbus_write_word_data(client, page,
50 					    MAX16064_MFR_VOUT_PEAK, 0);
51 		break;
52 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
53 		ret = pmbus_write_word_data(client, page,
54 					    MAX16064_MFR_TEMPERATURE_PEAK,
55 					    0xffff);
56 		break;
57 	default:
58 		ret = -ENODATA;
59 		break;
60 	}
61 	return ret;
62 }
63 
64 static struct pmbus_driver_info max16064_info = {
65 	.pages = 4,
66 	.format[PSC_VOLTAGE_IN] = direct,
67 	.format[PSC_VOLTAGE_OUT] = direct,
68 	.format[PSC_TEMPERATURE] = direct,
69 	.m[PSC_VOLTAGE_IN] = 19995,
70 	.b[PSC_VOLTAGE_IN] = 0,
71 	.R[PSC_VOLTAGE_IN] = -1,
72 	.m[PSC_VOLTAGE_OUT] = 19995,
73 	.b[PSC_VOLTAGE_OUT] = 0,
74 	.R[PSC_VOLTAGE_OUT] = -1,
75 	.m[PSC_TEMPERATURE] = -7612,
76 	.b[PSC_TEMPERATURE] = 335,
77 	.R[PSC_TEMPERATURE] = -3,
78 	.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP
79 		| PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP,
80 	.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
81 	.func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
82 	.func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
83 	.read_word_data = max16064_read_word_data,
84 	.write_word_data = max16064_write_word_data,
85 };
86 
87 static int max16064_probe(struct i2c_client *client,
88 			  const struct i2c_device_id *id)
89 {
90 	return pmbus_do_probe(client, id, &max16064_info);
91 }
92 
93 static const struct i2c_device_id max16064_id[] = {
94 	{"max16064", 0},
95 	{}
96 };
97 
98 MODULE_DEVICE_TABLE(i2c, max16064_id);
99 
100 /* This is the driver that will be inserted */
101 static struct i2c_driver max16064_driver = {
102 	.driver = {
103 		   .name = "max16064",
104 		   },
105 	.probe = max16064_probe,
106 	.remove = pmbus_do_remove,
107 	.id_table = max16064_id,
108 };
109 
110 module_i2c_driver(max16064_driver);
111 
112 MODULE_AUTHOR("Guenter Roeck");
113 MODULE_DESCRIPTION("PMBus driver for Maxim MAX16064");
114 MODULE_LICENSE("GPL");
115