xref: /openbmc/linux/drivers/hwmon/pmbus/max16064.c (revision 12eb4683)
1 /*
2  * Hardware monitoring driver for Maxim MAX16064
3  *
4  * Copyright (c) 2011 Ericsson AB.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/err.h>
25 #include <linux/i2c.h>
26 #include "pmbus.h"
27 
28 #define MAX16064_MFR_VOUT_PEAK		0xd4
29 #define MAX16064_MFR_TEMPERATURE_PEAK	0xd6
30 
31 static int max16064_read_word_data(struct i2c_client *client, int page, int reg)
32 {
33 	int ret;
34 
35 	switch (reg) {
36 	case PMBUS_VIRT_READ_VOUT_MAX:
37 		ret = pmbus_read_word_data(client, page,
38 					   MAX16064_MFR_VOUT_PEAK);
39 		break;
40 	case PMBUS_VIRT_READ_TEMP_MAX:
41 		ret = pmbus_read_word_data(client, page,
42 					   MAX16064_MFR_TEMPERATURE_PEAK);
43 		break;
44 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
45 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
46 		ret = 0;
47 		break;
48 	default:
49 		ret = -ENODATA;
50 		break;
51 	}
52 	return ret;
53 }
54 
55 static int max16064_write_word_data(struct i2c_client *client, int page,
56 				    int reg, u16 word)
57 {
58 	int ret;
59 
60 	switch (reg) {
61 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
62 		ret = pmbus_write_word_data(client, page,
63 					    MAX16064_MFR_VOUT_PEAK, 0);
64 		break;
65 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
66 		ret = pmbus_write_word_data(client, page,
67 					    MAX16064_MFR_TEMPERATURE_PEAK,
68 					    0xffff);
69 		break;
70 	default:
71 		ret = -ENODATA;
72 		break;
73 	}
74 	return ret;
75 }
76 
77 static struct pmbus_driver_info max16064_info = {
78 	.pages = 4,
79 	.format[PSC_VOLTAGE_IN] = direct,
80 	.format[PSC_VOLTAGE_OUT] = direct,
81 	.format[PSC_TEMPERATURE] = direct,
82 	.m[PSC_VOLTAGE_IN] = 19995,
83 	.b[PSC_VOLTAGE_IN] = 0,
84 	.R[PSC_VOLTAGE_IN] = -1,
85 	.m[PSC_VOLTAGE_OUT] = 19995,
86 	.b[PSC_VOLTAGE_OUT] = 0,
87 	.R[PSC_VOLTAGE_OUT] = -1,
88 	.m[PSC_TEMPERATURE] = -7612,
89 	.b[PSC_TEMPERATURE] = 335,
90 	.R[PSC_TEMPERATURE] = -3,
91 	.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP
92 		| PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP,
93 	.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
94 	.func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
95 	.func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
96 	.read_word_data = max16064_read_word_data,
97 	.write_word_data = max16064_write_word_data,
98 };
99 
100 static int max16064_probe(struct i2c_client *client,
101 			  const struct i2c_device_id *id)
102 {
103 	return pmbus_do_probe(client, id, &max16064_info);
104 }
105 
106 static const struct i2c_device_id max16064_id[] = {
107 	{"max16064", 0},
108 	{}
109 };
110 
111 MODULE_DEVICE_TABLE(i2c, max16064_id);
112 
113 /* This is the driver that will be inserted */
114 static struct i2c_driver max16064_driver = {
115 	.driver = {
116 		   .name = "max16064",
117 		   },
118 	.probe = max16064_probe,
119 	.remove = pmbus_do_remove,
120 	.id_table = max16064_id,
121 };
122 
123 module_i2c_driver(max16064_driver);
124 
125 MODULE_AUTHOR("Guenter Roeck");
126 MODULE_DESCRIPTION("PMBus driver for Maxim MAX16064");
127 MODULE_LICENSE("GPL");
128