xref: /openbmc/linux/drivers/hwmon/pmbus/max34440.c (revision 55fd7e02)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Hardware monitoring driver for Maxim MAX34440/MAX34441
4  *
5  * Copyright (c) 2011 Ericsson AB.
6  * Copyright (c) 2012 Guenter Roeck
7  */
8 
9 #include <linux/bitops.h>
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 chips { max34440, max34441, max34446, max34451, max34460, max34461 };
18 
19 #define MAX34440_MFR_VOUT_PEAK		0xd4
20 #define MAX34440_MFR_IOUT_PEAK		0xd5
21 #define MAX34440_MFR_TEMPERATURE_PEAK	0xd6
22 #define MAX34440_MFR_VOUT_MIN		0xd7
23 
24 #define MAX34446_MFR_POUT_PEAK		0xe0
25 #define MAX34446_MFR_POUT_AVG		0xe1
26 #define MAX34446_MFR_IOUT_AVG		0xe2
27 #define MAX34446_MFR_TEMPERATURE_AVG	0xe3
28 
29 #define MAX34440_STATUS_OC_WARN		BIT(0)
30 #define MAX34440_STATUS_OC_FAULT	BIT(1)
31 #define MAX34440_STATUS_OT_FAULT	BIT(5)
32 #define MAX34440_STATUS_OT_WARN		BIT(6)
33 
34 #define MAX34451_MFR_CHANNEL_CONFIG	0xe4
35 #define MAX34451_MFR_CHANNEL_CONFIG_SEL_MASK	0x3f
36 
37 struct max34440_data {
38 	int id;
39 	struct pmbus_driver_info info;
40 };
41 
42 #define to_max34440_data(x)  container_of(x, struct max34440_data, info)
43 
44 static int max34440_read_word_data(struct i2c_client *client, int page,
45 				   int phase, int reg)
46 {
47 	int ret;
48 	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
49 	const struct max34440_data *data = to_max34440_data(info);
50 
51 	switch (reg) {
52 	case PMBUS_VIRT_READ_VOUT_MIN:
53 		ret = pmbus_read_word_data(client, page, phase,
54 					   MAX34440_MFR_VOUT_MIN);
55 		break;
56 	case PMBUS_VIRT_READ_VOUT_MAX:
57 		ret = pmbus_read_word_data(client, page, phase,
58 					   MAX34440_MFR_VOUT_PEAK);
59 		break;
60 	case PMBUS_VIRT_READ_IOUT_AVG:
61 		if (data->id != max34446 && data->id != max34451)
62 			return -ENXIO;
63 		ret = pmbus_read_word_data(client, page, phase,
64 					   MAX34446_MFR_IOUT_AVG);
65 		break;
66 	case PMBUS_VIRT_READ_IOUT_MAX:
67 		ret = pmbus_read_word_data(client, page, phase,
68 					   MAX34440_MFR_IOUT_PEAK);
69 		break;
70 	case PMBUS_VIRT_READ_POUT_AVG:
71 		if (data->id != max34446)
72 			return -ENXIO;
73 		ret = pmbus_read_word_data(client, page, phase,
74 					   MAX34446_MFR_POUT_AVG);
75 		break;
76 	case PMBUS_VIRT_READ_POUT_MAX:
77 		if (data->id != max34446)
78 			return -ENXIO;
79 		ret = pmbus_read_word_data(client, page, phase,
80 					   MAX34446_MFR_POUT_PEAK);
81 		break;
82 	case PMBUS_VIRT_READ_TEMP_AVG:
83 		if (data->id != max34446 && data->id != max34460 &&
84 		    data->id != max34461)
85 			return -ENXIO;
86 		ret = pmbus_read_word_data(client, page, phase,
87 					   MAX34446_MFR_TEMPERATURE_AVG);
88 		break;
89 	case PMBUS_VIRT_READ_TEMP_MAX:
90 		ret = pmbus_read_word_data(client, page, phase,
91 					   MAX34440_MFR_TEMPERATURE_PEAK);
92 		break;
93 	case PMBUS_VIRT_RESET_POUT_HISTORY:
94 		if (data->id != max34446)
95 			return -ENXIO;
96 		ret = 0;
97 		break;
98 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
99 	case PMBUS_VIRT_RESET_IOUT_HISTORY:
100 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
101 		ret = 0;
102 		break;
103 	default:
104 		ret = -ENODATA;
105 		break;
106 	}
107 	return ret;
108 }
109 
110 static int max34440_write_word_data(struct i2c_client *client, int page,
111 				    int reg, u16 word)
112 {
113 	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
114 	const struct max34440_data *data = to_max34440_data(info);
115 	int ret;
116 
117 	switch (reg) {
118 	case PMBUS_VIRT_RESET_POUT_HISTORY:
119 		ret = pmbus_write_word_data(client, page,
120 					    MAX34446_MFR_POUT_PEAK, 0);
121 		if (ret)
122 			break;
123 		ret = pmbus_write_word_data(client, page,
124 					    MAX34446_MFR_POUT_AVG, 0);
125 		break;
126 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
127 		ret = pmbus_write_word_data(client, page,
128 					    MAX34440_MFR_VOUT_MIN, 0x7fff);
129 		if (ret)
130 			break;
131 		ret = pmbus_write_word_data(client, page,
132 					    MAX34440_MFR_VOUT_PEAK, 0);
133 		break;
134 	case PMBUS_VIRT_RESET_IOUT_HISTORY:
135 		ret = pmbus_write_word_data(client, page,
136 					    MAX34440_MFR_IOUT_PEAK, 0);
137 		if (!ret && (data->id == max34446 || data->id == max34451))
138 			ret = pmbus_write_word_data(client, page,
139 					MAX34446_MFR_IOUT_AVG, 0);
140 
141 		break;
142 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
143 		ret = pmbus_write_word_data(client, page,
144 					    MAX34440_MFR_TEMPERATURE_PEAK,
145 					    0x8000);
146 		if (!ret && data->id == max34446)
147 			ret = pmbus_write_word_data(client, page,
148 					MAX34446_MFR_TEMPERATURE_AVG, 0);
149 		break;
150 	default:
151 		ret = -ENODATA;
152 		break;
153 	}
154 	return ret;
155 }
156 
157 static int max34440_read_byte_data(struct i2c_client *client, int page, int reg)
158 {
159 	int ret = 0;
160 	int mfg_status;
161 
162 	if (page >= 0) {
163 		ret = pmbus_set_page(client, page, 0xff);
164 		if (ret < 0)
165 			return ret;
166 	}
167 
168 	switch (reg) {
169 	case PMBUS_STATUS_IOUT:
170 		mfg_status = pmbus_read_word_data(client, 0, 0xff,
171 						  PMBUS_STATUS_MFR_SPECIFIC);
172 		if (mfg_status < 0)
173 			return mfg_status;
174 		if (mfg_status & MAX34440_STATUS_OC_WARN)
175 			ret |= PB_IOUT_OC_WARNING;
176 		if (mfg_status & MAX34440_STATUS_OC_FAULT)
177 			ret |= PB_IOUT_OC_FAULT;
178 		break;
179 	case PMBUS_STATUS_TEMPERATURE:
180 		mfg_status = pmbus_read_word_data(client, 0, 0xff,
181 						  PMBUS_STATUS_MFR_SPECIFIC);
182 		if (mfg_status < 0)
183 			return mfg_status;
184 		if (mfg_status & MAX34440_STATUS_OT_WARN)
185 			ret |= PB_TEMP_OT_WARNING;
186 		if (mfg_status & MAX34440_STATUS_OT_FAULT)
187 			ret |= PB_TEMP_OT_FAULT;
188 		break;
189 	default:
190 		ret = -ENODATA;
191 		break;
192 	}
193 	return ret;
194 }
195 
196 static int max34451_set_supported_funcs(struct i2c_client *client,
197 					 struct max34440_data *data)
198 {
199 	/*
200 	 * Each of the channel 0-15 can be configured to monitor the following
201 	 * functions based on MFR_CHANNEL_CONFIG[5:0]
202 	 * 0x10: Sequencing + voltage monitoring (only valid for PAGES 0–11)
203 	 * 0x20: Voltage monitoring (no sequencing)
204 	 * 0x21: Voltage read only
205 	 * 0x22: Current monitoring
206 	 * 0x23: Current read only
207 	 * 0x30: General-purpose input active low
208 	 * 0x34: General-purpose input active high
209 	 * 0x00:  Disabled
210 	 */
211 
212 	int page, rv;
213 
214 	for (page = 0; page < 16; page++) {
215 		rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
216 		if (rv < 0)
217 			return rv;
218 
219 		rv = i2c_smbus_read_word_data(client,
220 					      MAX34451_MFR_CHANNEL_CONFIG);
221 		if (rv < 0)
222 			return rv;
223 
224 		switch (rv & MAX34451_MFR_CHANNEL_CONFIG_SEL_MASK) {
225 		case 0x10:
226 		case 0x20:
227 			data->info.func[page] = PMBUS_HAVE_VOUT |
228 				PMBUS_HAVE_STATUS_VOUT;
229 			break;
230 		case 0x21:
231 			data->info.func[page] = PMBUS_HAVE_VOUT;
232 			break;
233 		case 0x22:
234 			data->info.func[page] = PMBUS_HAVE_IOUT |
235 				PMBUS_HAVE_STATUS_IOUT;
236 			break;
237 		case 0x23:
238 			data->info.func[page] = PMBUS_HAVE_IOUT;
239 			break;
240 		default:
241 			break;
242 		}
243 	}
244 
245 	return 0;
246 }
247 
248 static struct pmbus_driver_info max34440_info[] = {
249 	[max34440] = {
250 		.pages = 14,
251 		.format[PSC_VOLTAGE_IN] = direct,
252 		.format[PSC_VOLTAGE_OUT] = direct,
253 		.format[PSC_TEMPERATURE] = direct,
254 		.format[PSC_CURRENT_OUT] = direct,
255 		.m[PSC_VOLTAGE_IN] = 1,
256 		.b[PSC_VOLTAGE_IN] = 0,
257 		.R[PSC_VOLTAGE_IN] = 3,	    /* R = 0 in datasheet reflects mV */
258 		.m[PSC_VOLTAGE_OUT] = 1,
259 		.b[PSC_VOLTAGE_OUT] = 0,
260 		.R[PSC_VOLTAGE_OUT] = 3,    /* R = 0 in datasheet reflects mV */
261 		.m[PSC_CURRENT_OUT] = 1,
262 		.b[PSC_CURRENT_OUT] = 0,
263 		.R[PSC_CURRENT_OUT] = 3,    /* R = 0 in datasheet reflects mA */
264 		.m[PSC_TEMPERATURE] = 1,
265 		.b[PSC_TEMPERATURE] = 0,
266 		.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_VOUT | PMBUS_HAVE_STATUS_VOUT
278 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
279 		.func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
280 		.func[7] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
281 		.func[8] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
282 		.func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
283 		.func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
284 		.func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
285 		.func[12] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
286 		.func[13] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
287 		.read_byte_data = max34440_read_byte_data,
288 		.read_word_data = max34440_read_word_data,
289 		.write_word_data = max34440_write_word_data,
290 	},
291 	[max34441] = {
292 		.pages = 12,
293 		.format[PSC_VOLTAGE_IN] = direct,
294 		.format[PSC_VOLTAGE_OUT] = direct,
295 		.format[PSC_TEMPERATURE] = direct,
296 		.format[PSC_CURRENT_OUT] = direct,
297 		.format[PSC_FAN] = direct,
298 		.m[PSC_VOLTAGE_IN] = 1,
299 		.b[PSC_VOLTAGE_IN] = 0,
300 		.R[PSC_VOLTAGE_IN] = 3,
301 		.m[PSC_VOLTAGE_OUT] = 1,
302 		.b[PSC_VOLTAGE_OUT] = 0,
303 		.R[PSC_VOLTAGE_OUT] = 3,
304 		.m[PSC_CURRENT_OUT] = 1,
305 		.b[PSC_CURRENT_OUT] = 0,
306 		.R[PSC_CURRENT_OUT] = 3,
307 		.m[PSC_TEMPERATURE] = 1,
308 		.b[PSC_TEMPERATURE] = 0,
309 		.R[PSC_TEMPERATURE] = 2,
310 		.m[PSC_FAN] = 1,
311 		.b[PSC_FAN] = 0,
312 		.R[PSC_FAN] = 0,
313 		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
314 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
315 		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
316 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
317 		.func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
318 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
319 		.func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
320 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
321 		.func[4] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
322 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
323 		.func[5] = PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12,
324 		.func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
325 		.func[7] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
326 		.func[8] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
327 		.func[9] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
328 		.func[10] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
329 		.func[11] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
330 		.read_byte_data = max34440_read_byte_data,
331 		.read_word_data = max34440_read_word_data,
332 		.write_word_data = max34440_write_word_data,
333 	},
334 	[max34446] = {
335 		.pages = 7,
336 		.format[PSC_VOLTAGE_IN] = direct,
337 		.format[PSC_VOLTAGE_OUT] = direct,
338 		.format[PSC_TEMPERATURE] = direct,
339 		.format[PSC_CURRENT_OUT] = direct,
340 		.format[PSC_POWER] = direct,
341 		.m[PSC_VOLTAGE_IN] = 1,
342 		.b[PSC_VOLTAGE_IN] = 0,
343 		.R[PSC_VOLTAGE_IN] = 3,
344 		.m[PSC_VOLTAGE_OUT] = 1,
345 		.b[PSC_VOLTAGE_OUT] = 0,
346 		.R[PSC_VOLTAGE_OUT] = 3,
347 		.m[PSC_CURRENT_OUT] = 1,
348 		.b[PSC_CURRENT_OUT] = 0,
349 		.R[PSC_CURRENT_OUT] = 3,
350 		.m[PSC_POWER] = 1,
351 		.b[PSC_POWER] = 0,
352 		.R[PSC_POWER] = 3,
353 		.m[PSC_TEMPERATURE] = 1,
354 		.b[PSC_TEMPERATURE] = 0,
355 		.R[PSC_TEMPERATURE] = 2,
356 		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
357 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_POUT,
358 		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
359 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
360 		.func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
361 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_POUT,
362 		.func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
363 		  | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
364 		.func[4] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
365 		.func[5] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
366 		.func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
367 		.read_byte_data = max34440_read_byte_data,
368 		.read_word_data = max34440_read_word_data,
369 		.write_word_data = max34440_write_word_data,
370 	},
371 	[max34451] = {
372 		.pages = 21,
373 		.format[PSC_VOLTAGE_OUT] = direct,
374 		.format[PSC_TEMPERATURE] = direct,
375 		.format[PSC_CURRENT_OUT] = direct,
376 		.m[PSC_VOLTAGE_OUT] = 1,
377 		.b[PSC_VOLTAGE_OUT] = 0,
378 		.R[PSC_VOLTAGE_OUT] = 3,
379 		.m[PSC_CURRENT_OUT] = 1,
380 		.b[PSC_CURRENT_OUT] = 0,
381 		.R[PSC_CURRENT_OUT] = 2,
382 		.m[PSC_TEMPERATURE] = 1,
383 		.b[PSC_TEMPERATURE] = 0,
384 		.R[PSC_TEMPERATURE] = 2,
385 		/* func 0-15 is set dynamically before probing */
386 		.func[16] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
387 		.func[17] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
388 		.func[18] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
389 		.func[19] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
390 		.func[20] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
391 		.read_byte_data = max34440_read_byte_data,
392 		.read_word_data = max34440_read_word_data,
393 		.write_word_data = max34440_write_word_data,
394 	},
395 	[max34460] = {
396 		.pages = 18,
397 		.format[PSC_VOLTAGE_OUT] = direct,
398 		.format[PSC_TEMPERATURE] = direct,
399 		.m[PSC_VOLTAGE_OUT] = 1,
400 		.b[PSC_VOLTAGE_OUT] = 0,
401 		.R[PSC_VOLTAGE_OUT] = 3,
402 		.m[PSC_TEMPERATURE] = 1,
403 		.b[PSC_TEMPERATURE] = 0,
404 		.R[PSC_TEMPERATURE] = 2,
405 		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
406 		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
407 		.func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
408 		.func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
409 		.func[4] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
410 		.func[5] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
411 		.func[6] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
412 		.func[7] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
413 		.func[8] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
414 		.func[9] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
415 		.func[10] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
416 		.func[11] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
417 		.func[13] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
418 		.func[14] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
419 		.func[15] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
420 		.func[16] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
421 		.func[17] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
422 		.read_byte_data = max34440_read_byte_data,
423 		.read_word_data = max34440_read_word_data,
424 		.write_word_data = max34440_write_word_data,
425 	},
426 	[max34461] = {
427 		.pages = 23,
428 		.format[PSC_VOLTAGE_OUT] = direct,
429 		.format[PSC_TEMPERATURE] = direct,
430 		.m[PSC_VOLTAGE_OUT] = 1,
431 		.b[PSC_VOLTAGE_OUT] = 0,
432 		.R[PSC_VOLTAGE_OUT] = 3,
433 		.m[PSC_TEMPERATURE] = 1,
434 		.b[PSC_TEMPERATURE] = 0,
435 		.R[PSC_TEMPERATURE] = 2,
436 		.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
437 		.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
438 		.func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
439 		.func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
440 		.func[4] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
441 		.func[5] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
442 		.func[6] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
443 		.func[7] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
444 		.func[8] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
445 		.func[9] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
446 		.func[10] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
447 		.func[11] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
448 		.func[12] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
449 		.func[13] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
450 		.func[14] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
451 		.func[15] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
452 		/* page 16 is reserved */
453 		.func[17] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
454 		.func[18] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
455 		.func[19] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
456 		.func[20] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
457 		.func[21] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
458 		.read_byte_data = max34440_read_byte_data,
459 		.read_word_data = max34440_read_word_data,
460 		.write_word_data = max34440_write_word_data,
461 	},
462 };
463 
464 static int max34440_probe(struct i2c_client *client,
465 			  const struct i2c_device_id *id)
466 {
467 	struct max34440_data *data;
468 	int rv;
469 
470 	data = devm_kzalloc(&client->dev, sizeof(struct max34440_data),
471 			    GFP_KERNEL);
472 	if (!data)
473 		return -ENOMEM;
474 	data->id = id->driver_data;
475 	data->info = max34440_info[id->driver_data];
476 
477 	if (data->id == max34451) {
478 		rv = max34451_set_supported_funcs(client, data);
479 		if (rv)
480 			return rv;
481 	}
482 
483 	return pmbus_do_probe(client, id, &data->info);
484 }
485 
486 static const struct i2c_device_id max34440_id[] = {
487 	{"max34440", max34440},
488 	{"max34441", max34441},
489 	{"max34446", max34446},
490 	{"max34451", max34451},
491 	{"max34460", max34460},
492 	{"max34461", max34461},
493 	{}
494 };
495 MODULE_DEVICE_TABLE(i2c, max34440_id);
496 
497 /* This is the driver that will be inserted */
498 static struct i2c_driver max34440_driver = {
499 	.driver = {
500 		   .name = "max34440",
501 		   },
502 	.probe = max34440_probe,
503 	.remove = pmbus_do_remove,
504 	.id_table = max34440_id,
505 };
506 
507 module_i2c_driver(max34440_driver);
508 
509 MODULE_AUTHOR("Guenter Roeck");
510 MODULE_DESCRIPTION("PMBus driver for Maxim MAX34440/MAX34441");
511 MODULE_LICENSE("GPL");
512