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