2 * Hardware monitoring driver for Maxim MAX34440/MAX34441
4 * Copyright (c) 2011 Ericsson AB.
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.
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.
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.
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>
28 enum chips
{ max34440
, max34441
, max34446
};
30 #define MAX34440_MFR_VOUT_PEAK 0xd4
31 #define MAX34440_MFR_IOUT_PEAK 0xd5
32 #define MAX34440_MFR_TEMPERATURE_PEAK 0xd6
33 #define MAX34440_MFR_VOUT_MIN 0xd7
35 #define MAX34446_MFR_POUT_PEAK 0xe0
36 #define MAX34446_MFR_POUT_AVG 0xe1
37 #define MAX34446_MFR_IOUT_AVG 0xe2
38 #define MAX34446_MFR_TEMPERATURE_AVG 0xe3
40 #define MAX34440_STATUS_OC_WARN (1 << 0)
41 #define MAX34440_STATUS_OC_FAULT (1 << 1)
42 #define MAX34440_STATUS_OT_FAULT (1 << 5)
43 #define MAX34440_STATUS_OT_WARN (1 << 6)
45 struct max34440_data
{
47 struct pmbus_driver_info info
;
50 #define to_max34440_data(x) container_of(x, struct max34440_data, info)
52 static int max34440_read_word_data(struct i2c_client
*client
, int page
, int reg
)
55 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
56 const struct max34440_data
*data
= to_max34440_data(info
);
59 case PMBUS_VIRT_READ_VOUT_MIN
:
60 ret
= pmbus_read_word_data(client
, page
,
61 MAX34440_MFR_VOUT_MIN
);
63 case PMBUS_VIRT_READ_VOUT_MAX
:
64 ret
= pmbus_read_word_data(client
, page
,
65 MAX34440_MFR_VOUT_PEAK
);
67 case PMBUS_VIRT_READ_IOUT_AVG
:
68 if (data
->id
!= max34446
)
70 ret
= pmbus_read_word_data(client
, page
,
71 MAX34446_MFR_IOUT_AVG
);
73 case PMBUS_VIRT_READ_IOUT_MAX
:
74 ret
= pmbus_read_word_data(client
, page
,
75 MAX34440_MFR_IOUT_PEAK
);
77 case PMBUS_VIRT_READ_POUT_AVG
:
78 if (data
->id
!= max34446
)
80 ret
= pmbus_read_word_data(client
, page
,
81 MAX34446_MFR_POUT_AVG
);
83 case PMBUS_VIRT_READ_POUT_MAX
:
84 if (data
->id
!= max34446
)
86 ret
= pmbus_read_word_data(client
, page
,
87 MAX34446_MFR_POUT_PEAK
);
89 case PMBUS_VIRT_READ_TEMP_AVG
:
90 if (data
->id
!= max34446
)
92 ret
= pmbus_read_word_data(client
, page
,
93 MAX34446_MFR_TEMPERATURE_AVG
);
95 case PMBUS_VIRT_READ_TEMP_MAX
:
96 ret
= pmbus_read_word_data(client
, page
,
97 MAX34440_MFR_TEMPERATURE_PEAK
);
99 case PMBUS_VIRT_RESET_POUT_HISTORY
:
100 if (data
->id
!= max34446
)
104 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
105 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
106 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
116 static int max34440_write_word_data(struct i2c_client
*client
, int page
,
119 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
120 const struct max34440_data
*data
= to_max34440_data(info
);
124 case PMBUS_VIRT_RESET_POUT_HISTORY
:
125 ret
= pmbus_write_word_data(client
, page
,
126 MAX34446_MFR_POUT_PEAK
, 0);
129 ret
= pmbus_write_word_data(client
, page
,
130 MAX34446_MFR_POUT_AVG
, 0);
132 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
133 ret
= pmbus_write_word_data(client
, page
,
134 MAX34440_MFR_VOUT_MIN
, 0x7fff);
137 ret
= pmbus_write_word_data(client
, page
,
138 MAX34440_MFR_VOUT_PEAK
, 0);
140 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
141 ret
= pmbus_write_word_data(client
, page
,
142 MAX34440_MFR_IOUT_PEAK
, 0);
143 if (!ret
&& data
->id
== max34446
)
144 ret
= pmbus_write_word_data(client
, page
,
145 MAX34446_MFR_IOUT_AVG
, 0);
148 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
149 ret
= pmbus_write_word_data(client
, page
,
150 MAX34440_MFR_TEMPERATURE_PEAK
,
152 if (!ret
&& data
->id
== max34446
)
153 ret
= pmbus_write_word_data(client
, page
,
154 MAX34446_MFR_TEMPERATURE_AVG
, 0);
163 static int max34440_read_byte_data(struct i2c_client
*client
, int page
, int reg
)
169 ret
= pmbus_set_page(client
, page
);
175 case PMBUS_STATUS_IOUT
:
176 mfg_status
= pmbus_read_word_data(client
, 0,
177 PMBUS_STATUS_MFR_SPECIFIC
);
180 if (mfg_status
& MAX34440_STATUS_OC_WARN
)
181 ret
|= PB_IOUT_OC_WARNING
;
182 if (mfg_status
& MAX34440_STATUS_OC_FAULT
)
183 ret
|= PB_IOUT_OC_FAULT
;
185 case PMBUS_STATUS_TEMPERATURE
:
186 mfg_status
= pmbus_read_word_data(client
, 0,
187 PMBUS_STATUS_MFR_SPECIFIC
);
190 if (mfg_status
& MAX34440_STATUS_OT_WARN
)
191 ret
|= PB_TEMP_OT_WARNING
;
192 if (mfg_status
& MAX34440_STATUS_OT_FAULT
)
193 ret
|= PB_TEMP_OT_FAULT
;
202 static struct pmbus_driver_info max34440_info
[] = {
205 .format
[PSC_VOLTAGE_IN
] = direct
,
206 .format
[PSC_VOLTAGE_OUT
] = direct
,
207 .format
[PSC_TEMPERATURE
] = direct
,
208 .format
[PSC_CURRENT_OUT
] = direct
,
209 .m
[PSC_VOLTAGE_IN
] = 1,
210 .b
[PSC_VOLTAGE_IN
] = 0,
211 .R
[PSC_VOLTAGE_IN
] = 3, /* R = 0 in datasheet reflects mV */
212 .m
[PSC_VOLTAGE_OUT
] = 1,
213 .b
[PSC_VOLTAGE_OUT
] = 0,
214 .R
[PSC_VOLTAGE_OUT
] = 3, /* R = 0 in datasheet reflects mV */
215 .m
[PSC_CURRENT_OUT
] = 1,
216 .b
[PSC_CURRENT_OUT
] = 0,
217 .R
[PSC_CURRENT_OUT
] = 3, /* R = 0 in datasheet reflects mA */
218 .m
[PSC_TEMPERATURE
] = 1,
219 .b
[PSC_TEMPERATURE
] = 0,
220 .R
[PSC_TEMPERATURE
] = 2,
221 .func
[0] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
222 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
223 .func
[1] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
224 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
225 .func
[2] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
226 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
227 .func
[3] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
228 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
229 .func
[4] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
230 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
231 .func
[5] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
232 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
233 .func
[6] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
234 .func
[7] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
235 .func
[8] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
236 .func
[9] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
237 .func
[10] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
238 .func
[11] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
239 .func
[12] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
240 .func
[13] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
241 .read_byte_data
= max34440_read_byte_data
,
242 .read_word_data
= max34440_read_word_data
,
243 .write_word_data
= max34440_write_word_data
,
247 .format
[PSC_VOLTAGE_IN
] = direct
,
248 .format
[PSC_VOLTAGE_OUT
] = direct
,
249 .format
[PSC_TEMPERATURE
] = direct
,
250 .format
[PSC_CURRENT_OUT
] = direct
,
251 .format
[PSC_FAN
] = direct
,
252 .m
[PSC_VOLTAGE_IN
] = 1,
253 .b
[PSC_VOLTAGE_IN
] = 0,
254 .R
[PSC_VOLTAGE_IN
] = 3,
255 .m
[PSC_VOLTAGE_OUT
] = 1,
256 .b
[PSC_VOLTAGE_OUT
] = 0,
257 .R
[PSC_VOLTAGE_OUT
] = 3,
258 .m
[PSC_CURRENT_OUT
] = 1,
259 .b
[PSC_CURRENT_OUT
] = 0,
260 .R
[PSC_CURRENT_OUT
] = 3,
261 .m
[PSC_TEMPERATURE
] = 1,
262 .b
[PSC_TEMPERATURE
] = 0,
263 .R
[PSC_TEMPERATURE
] = 2,
267 .func
[0] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
268 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
269 .func
[1] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
270 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
271 .func
[2] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
272 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
273 .func
[3] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
274 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
275 .func
[4] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
276 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
277 .func
[5] = PMBUS_HAVE_FAN12
| PMBUS_HAVE_STATUS_FAN12
,
278 .func
[6] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
279 .func
[7] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
280 .func
[8] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
281 .func
[9] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
282 .func
[10] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
283 .func
[11] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
284 .read_byte_data
= max34440_read_byte_data
,
285 .read_word_data
= max34440_read_word_data
,
286 .write_word_data
= max34440_write_word_data
,
290 .format
[PSC_VOLTAGE_IN
] = direct
,
291 .format
[PSC_VOLTAGE_OUT
] = direct
,
292 .format
[PSC_TEMPERATURE
] = direct
,
293 .format
[PSC_CURRENT_OUT
] = direct
,
294 .format
[PSC_POWER
] = direct
,
295 .m
[PSC_VOLTAGE_IN
] = 1,
296 .b
[PSC_VOLTAGE_IN
] = 0,
297 .R
[PSC_VOLTAGE_IN
] = 3,
298 .m
[PSC_VOLTAGE_OUT
] = 1,
299 .b
[PSC_VOLTAGE_OUT
] = 0,
300 .R
[PSC_VOLTAGE_OUT
] = 3,
301 .m
[PSC_CURRENT_OUT
] = 1,
302 .b
[PSC_CURRENT_OUT
] = 0,
303 .R
[PSC_CURRENT_OUT
] = 3,
307 .m
[PSC_TEMPERATURE
] = 1,
308 .b
[PSC_TEMPERATURE
] = 0,
309 .R
[PSC_TEMPERATURE
] = 2,
310 .func
[0] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
311 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
| PMBUS_HAVE_POUT
,
312 .func
[1] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
313 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
314 .func
[2] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
315 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
| PMBUS_HAVE_POUT
,
316 .func
[3] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
317 | PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
,
318 .func
[4] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
319 .func
[5] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
320 .func
[6] = PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
,
321 .read_byte_data
= max34440_read_byte_data
,
322 .read_word_data
= max34440_read_word_data
,
323 .write_word_data
= max34440_write_word_data
,
327 static int max34440_probe(struct i2c_client
*client
,
328 const struct i2c_device_id
*id
)
330 struct max34440_data
*data
;
332 data
= devm_kzalloc(&client
->dev
, sizeof(struct max34440_data
),
336 data
->id
= id
->driver_data
;
337 data
->info
= max34440_info
[id
->driver_data
];
339 return pmbus_do_probe(client
, id
, &data
->info
);
342 static const struct i2c_device_id max34440_id
[] = {
343 {"max34440", max34440
},
344 {"max34441", max34441
},
345 {"max34446", max34446
},
348 MODULE_DEVICE_TABLE(i2c
, max34440_id
);
350 /* This is the driver that will be inserted */
351 static struct i2c_driver max34440_driver
= {
355 .probe
= max34440_probe
,
356 .remove
= pmbus_do_remove
,
357 .id_table
= max34440_id
,
360 module_i2c_driver(max34440_driver
);
362 MODULE_AUTHOR("Guenter Roeck");
363 MODULE_DESCRIPTION("PMBus driver for Maxim MAX34440/MAX34441");
364 MODULE_LICENSE("GPL");