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