1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for MAX20710, MAX20730, MAX20734, and MAX20743 Integrated,
4 * Step-Down Switching Regulators
6 * Copyright 2019 Google LLC.
7 * Copyright 2020 Maxim Integrated
10 #include <linux/bits.h>
11 #include <linux/debugfs.h>
12 #include <linux/err.h>
13 #include <linux/i2c.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/mutex.h>
18 #include <linux/of_device.h>
19 #include <linux/pmbus.h>
20 #include <linux/util_macros.h>
31 MAX20730_DEBUGFS_VOUT_MIN
= 0,
32 MAX20730_DEBUGFS_FREQUENCY
,
33 MAX20730_DEBUGFS_PG_DELAY
,
34 MAX20730_DEBUGFS_INTERNAL_GAIN
,
35 MAX20730_DEBUGFS_BOOT_VOLTAGE
,
36 MAX20730_DEBUGFS_OUT_V_RAMP_RATE
,
37 MAX20730_DEBUGFS_OC_PROTECT_MODE
,
38 MAX20730_DEBUGFS_SS_TIMING
,
39 MAX20730_DEBUGFS_IMAX
,
40 MAX20730_DEBUGFS_OPERATION
,
41 MAX20730_DEBUGFS_ON_OFF_CONFIG
,
42 MAX20730_DEBUGFS_SMBALERT_MASK
,
43 MAX20730_DEBUGFS_VOUT_MODE
,
44 MAX20730_DEBUGFS_VOUT_COMMAND
,
45 MAX20730_DEBUGFS_VOUT_MAX
,
46 MAX20730_DEBUGFS_NUM_ENTRIES
49 struct max20730_data
{
51 struct pmbus_driver_info info
;
52 struct mutex lock
; /* Used to protect against parallel writes */
56 u32 vout_voltage_divider
[2];
59 #define to_max20730_data(x) container_of(x, struct max20730_data, info)
61 #define VOLT_FROM_REG(val) DIV_ROUND_CLOSEST((val), 1 << 9)
63 #define PMBUS_SMB_ALERT_MASK 0x1B
65 #define MAX20730_MFR_VOUT_MIN 0xd1
66 #define MAX20730_MFR_DEVSET1 0xd2
67 #define MAX20730_MFR_DEVSET2 0xd3
69 #define MAX20730_MFR_VOUT_MIN_MASK GENMASK(9, 0)
70 #define MAX20730_MFR_VOUT_MIN_BIT_POS 0
72 #define MAX20730_MFR_DEVSET1_RGAIN_MASK (BIT(13) | BIT(14))
73 #define MAX20730_MFR_DEVSET1_OTP_MASK (BIT(11) | BIT(12))
74 #define MAX20730_MFR_DEVSET1_VBOOT_MASK (BIT(8) | BIT(9))
75 #define MAX20730_MFR_DEVSET1_OCP_MASK (BIT(5) | BIT(6))
76 #define MAX20730_MFR_DEVSET1_FSW_MASK GENMASK(4, 2)
77 #define MAX20730_MFR_DEVSET1_TSTAT_MASK (BIT(0) | BIT(1))
79 #define MAX20730_MFR_DEVSET1_RGAIN_BIT_POS 13
80 #define MAX20730_MFR_DEVSET1_OTP_BIT_POS 11
81 #define MAX20730_MFR_DEVSET1_VBOOT_BIT_POS 8
82 #define MAX20730_MFR_DEVSET1_OCP_BIT_POS 5
83 #define MAX20730_MFR_DEVSET1_FSW_BIT_POS 2
84 #define MAX20730_MFR_DEVSET1_TSTAT_BIT_POS 0
86 #define MAX20730_MFR_DEVSET2_IMAX_MASK GENMASK(10, 8)
87 #define MAX20730_MFR_DEVSET2_VRATE (BIT(6) | BIT(7))
88 #define MAX20730_MFR_DEVSET2_OCPM_MASK BIT(5)
89 #define MAX20730_MFR_DEVSET2_SS_MASK (BIT(0) | BIT(1))
91 #define MAX20730_MFR_DEVSET2_IMAX_BIT_POS 8
92 #define MAX20730_MFR_DEVSET2_VRATE_BIT_POS 6
93 #define MAX20730_MFR_DEVSET2_OCPM_BIT_POS 5
94 #define MAX20730_MFR_DEVSET2_SS_BIT_POS 0
96 #define DEBUG_FS_DATA_MAX 16
98 struct max20730_debugfs_data
{
99 struct i2c_client
*client
;
100 int debugfs_entries
[MAX20730_DEBUGFS_NUM_ENTRIES
];
103 #define to_psu(x, y) container_of((x), \
104 struct max20730_debugfs_data, debugfs_entries[(y)])
106 #ifdef CONFIG_DEBUG_FS
107 static ssize_t
max20730_debugfs_read(struct file
*file
, char __user
*buf
,
108 size_t count
, loff_t
*ppos
)
111 int *idxp
= file
->private_data
;
113 struct max20730_debugfs_data
*psu
= to_psu(idxp
, idx
);
114 const struct pmbus_driver_info
*info
;
115 const struct max20730_data
*data
;
116 char tbuf
[DEBUG_FS_DATA_MAX
] = { 0 };
119 info
= pmbus_get_driver_info(psu
->client
);
120 data
= to_max20730_data(info
);
123 case MAX20730_DEBUGFS_VOUT_MIN
:
124 ret
= VOLT_FROM_REG(data
->mfr_voutmin
* 10000);
125 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d.%d\n",
126 ret
/ 10000, ret
% 10000);
128 case MAX20730_DEBUGFS_FREQUENCY
:
129 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_FSW_MASK
)
130 >> MAX20730_MFR_DEVSET1_FSW_BIT_POS
;
136 else if (val
== 2 || val
== 3)
144 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
146 case MAX20730_DEBUGFS_PG_DELAY
:
147 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_TSTAT_MASK
)
148 >> MAX20730_MFR_DEVSET1_TSTAT_BIT_POS
;
151 len
= strlcpy(tbuf
, "2000\n", DEBUG_FS_DATA_MAX
);
153 len
= strlcpy(tbuf
, "125\n", DEBUG_FS_DATA_MAX
);
155 len
= strlcpy(tbuf
, "62.5\n", DEBUG_FS_DATA_MAX
);
157 len
= strlcpy(tbuf
, "32\n", DEBUG_FS_DATA_MAX
);
159 case MAX20730_DEBUGFS_INTERNAL_GAIN
:
160 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_RGAIN_MASK
)
161 >> MAX20730_MFR_DEVSET1_RGAIN_BIT_POS
;
163 if (data
->id
== max20734
) {
166 len
= strlcpy(tbuf
, "0.8\n", DEBUG_FS_DATA_MAX
);
168 len
= strlcpy(tbuf
, "3.2\n", DEBUG_FS_DATA_MAX
);
170 len
= strlcpy(tbuf
, "1.6\n", DEBUG_FS_DATA_MAX
);
172 len
= strlcpy(tbuf
, "6.4\n", DEBUG_FS_DATA_MAX
);
173 } else if (data
->id
== max20730
|| data
->id
== max20710
) {
174 /* AN6042 or AN6140 */
176 len
= strlcpy(tbuf
, "0.9\n", DEBUG_FS_DATA_MAX
);
178 len
= strlcpy(tbuf
, "3.6\n", DEBUG_FS_DATA_MAX
);
180 len
= strlcpy(tbuf
, "1.8\n", DEBUG_FS_DATA_MAX
);
182 len
= strlcpy(tbuf
, "7.2\n", DEBUG_FS_DATA_MAX
);
183 } else if (data
->id
== max20743
) {
186 len
= strlcpy(tbuf
, "0.45\n", DEBUG_FS_DATA_MAX
);
188 len
= strlcpy(tbuf
, "1.8\n", DEBUG_FS_DATA_MAX
);
190 len
= strlcpy(tbuf
, "0.9\n", DEBUG_FS_DATA_MAX
);
192 len
= strlcpy(tbuf
, "3.6\n", DEBUG_FS_DATA_MAX
);
194 len
= strlcpy(tbuf
, "Not supported\n", DEBUG_FS_DATA_MAX
);
197 case MAX20730_DEBUGFS_BOOT_VOLTAGE
:
198 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_VBOOT_MASK
)
199 >> MAX20730_MFR_DEVSET1_VBOOT_BIT_POS
;
202 len
= strlcpy(tbuf
, "0.6484\n", DEBUG_FS_DATA_MAX
);
204 len
= strlcpy(tbuf
, "0.8984\n", DEBUG_FS_DATA_MAX
);
206 len
= strlcpy(tbuf
, "1.0\n", DEBUG_FS_DATA_MAX
);
208 len
= strlcpy(tbuf
, "Invalid\n", DEBUG_FS_DATA_MAX
);
210 case MAX20730_DEBUGFS_OUT_V_RAMP_RATE
:
211 val
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_VRATE
)
212 >> MAX20730_MFR_DEVSET2_VRATE_BIT_POS
;
215 len
= strlcpy(tbuf
, "4\n", DEBUG_FS_DATA_MAX
);
217 len
= strlcpy(tbuf
, "2\n", DEBUG_FS_DATA_MAX
);
219 len
= strlcpy(tbuf
, "1\n", DEBUG_FS_DATA_MAX
);
221 len
= strlcpy(tbuf
, "Invalid\n", DEBUG_FS_DATA_MAX
);
223 case MAX20730_DEBUGFS_OC_PROTECT_MODE
:
224 ret
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_OCPM_MASK
)
225 >> MAX20730_MFR_DEVSET2_OCPM_BIT_POS
;
226 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
228 case MAX20730_DEBUGFS_SS_TIMING
:
229 val
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_SS_MASK
)
230 >> MAX20730_MFR_DEVSET2_SS_BIT_POS
;
233 len
= strlcpy(tbuf
, "0.75\n", DEBUG_FS_DATA_MAX
);
235 len
= strlcpy(tbuf
, "1.5\n", DEBUG_FS_DATA_MAX
);
237 len
= strlcpy(tbuf
, "3\n", DEBUG_FS_DATA_MAX
);
239 len
= strlcpy(tbuf
, "6\n", DEBUG_FS_DATA_MAX
);
241 case MAX20730_DEBUGFS_IMAX
:
242 ret
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_IMAX_MASK
)
243 >> MAX20730_MFR_DEVSET2_IMAX_BIT_POS
;
244 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
246 case MAX20730_DEBUGFS_OPERATION
:
247 ret
= i2c_smbus_read_byte_data(psu
->client
, PMBUS_OPERATION
);
250 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
252 case MAX20730_DEBUGFS_ON_OFF_CONFIG
:
253 ret
= i2c_smbus_read_byte_data(psu
->client
, PMBUS_ON_OFF_CONFIG
);
256 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
258 case MAX20730_DEBUGFS_SMBALERT_MASK
:
259 ret
= i2c_smbus_read_word_data(psu
->client
,
260 PMBUS_SMB_ALERT_MASK
);
263 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
265 case MAX20730_DEBUGFS_VOUT_MODE
:
266 ret
= i2c_smbus_read_byte_data(psu
->client
, PMBUS_VOUT_MODE
);
269 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
271 case MAX20730_DEBUGFS_VOUT_COMMAND
:
272 ret
= i2c_smbus_read_word_data(psu
->client
, PMBUS_VOUT_COMMAND
);
276 ret
= VOLT_FROM_REG(ret
* 10000);
277 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
,
278 "%d.%d\n", ret
/ 10000, ret
% 10000);
280 case MAX20730_DEBUGFS_VOUT_MAX
:
281 ret
= i2c_smbus_read_word_data(psu
->client
, PMBUS_VOUT_MAX
);
285 ret
= VOLT_FROM_REG(ret
* 10000);
286 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
,
287 "%d.%d\n", ret
/ 10000, ret
% 10000);
290 len
= strlcpy(tbuf
, "Invalid\n", DEBUG_FS_DATA_MAX
);
293 return simple_read_from_buffer(buf
, count
, ppos
, tbuf
, len
);
296 static const struct file_operations max20730_fops
= {
297 .llseek
= noop_llseek
,
298 .read
= max20730_debugfs_read
,
303 static int max20730_init_debugfs(struct i2c_client
*client
,
304 struct max20730_data
*data
)
307 struct dentry
*debugfs
;
308 struct dentry
*max20730_dir
;
309 struct max20730_debugfs_data
*psu
;
311 ret
= i2c_smbus_read_word_data(client
, MAX20730_MFR_DEVSET2
);
314 data
->mfr_devset2
= ret
;
316 ret
= i2c_smbus_read_word_data(client
, MAX20730_MFR_VOUT_MIN
);
319 data
->mfr_voutmin
= ret
;
321 psu
= devm_kzalloc(&client
->dev
, sizeof(*psu
), GFP_KERNEL
);
324 psu
->client
= client
;
326 debugfs
= pmbus_get_debugfs_dir(client
);
330 max20730_dir
= debugfs_create_dir(client
->name
, debugfs
);
332 for (i
= 0; i
< MAX20730_DEBUGFS_NUM_ENTRIES
; ++i
)
333 psu
->debugfs_entries
[i
] = i
;
335 debugfs_create_file("vout_min", 0444, max20730_dir
,
336 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_MIN
],
338 debugfs_create_file("frequency", 0444, max20730_dir
,
339 &psu
->debugfs_entries
[MAX20730_DEBUGFS_FREQUENCY
],
341 debugfs_create_file("power_good_delay", 0444, max20730_dir
,
342 &psu
->debugfs_entries
[MAX20730_DEBUGFS_PG_DELAY
],
344 debugfs_create_file("internal_gain", 0444, max20730_dir
,
345 &psu
->debugfs_entries
[MAX20730_DEBUGFS_INTERNAL_GAIN
],
347 debugfs_create_file("boot_voltage", 0444, max20730_dir
,
348 &psu
->debugfs_entries
[MAX20730_DEBUGFS_BOOT_VOLTAGE
],
350 debugfs_create_file("out_voltage_ramp_rate", 0444, max20730_dir
,
351 &psu
->debugfs_entries
[MAX20730_DEBUGFS_OUT_V_RAMP_RATE
],
353 debugfs_create_file("oc_protection_mode", 0444, max20730_dir
,
354 &psu
->debugfs_entries
[MAX20730_DEBUGFS_OC_PROTECT_MODE
],
356 debugfs_create_file("soft_start_timing", 0444, max20730_dir
,
357 &psu
->debugfs_entries
[MAX20730_DEBUGFS_SS_TIMING
],
359 debugfs_create_file("imax", 0444, max20730_dir
,
360 &psu
->debugfs_entries
[MAX20730_DEBUGFS_IMAX
],
362 debugfs_create_file("operation", 0444, max20730_dir
,
363 &psu
->debugfs_entries
[MAX20730_DEBUGFS_OPERATION
],
365 debugfs_create_file("on_off_config", 0444, max20730_dir
,
366 &psu
->debugfs_entries
[MAX20730_DEBUGFS_ON_OFF_CONFIG
],
368 debugfs_create_file("smbalert_mask", 0444, max20730_dir
,
369 &psu
->debugfs_entries
[MAX20730_DEBUGFS_SMBALERT_MASK
],
371 debugfs_create_file("vout_mode", 0444, max20730_dir
,
372 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_MODE
],
374 debugfs_create_file("vout_command", 0444, max20730_dir
,
375 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_COMMAND
],
377 debugfs_create_file("vout_max", 0444, max20730_dir
,
378 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_MAX
],
384 static int max20730_init_debugfs(struct i2c_client
*client
,
385 struct max20730_data
*data
)
389 #endif /* CONFIG_DEBUG_FS */
391 static const struct i2c_device_id max20730_id
[];
394 * Convert discreet value to direct data format. Strictly speaking, all passed
395 * values are constants, so we could do that calculation manually. On the
396 * downside, that would make the driver more difficult to maintain, so lets
399 static u16
val_to_direct(int v
, enum pmbus_sensor_classes
class,
400 const struct pmbus_driver_info
*info
)
402 int R
= info
->R
[class] - 3; /* take milli-units into account */
403 int b
= info
->b
[class] * 1000;
406 d
= v
* info
->m
[class] + b
;
408 * R < 0 is true for all callers, so we don't need to bother
409 * about the R > 0 case.
412 d
= DIV_ROUND_CLOSEST(d
, 10);
418 static long direct_to_val(u16 w
, enum pmbus_sensor_classes
class,
419 const struct pmbus_driver_info
*info
)
421 int R
= info
->R
[class] - 3;
422 int b
= info
->b
[class] * 1000;
423 int m
= info
->m
[class];
437 static u32 max_current
[][5] = {
438 [max20710
] = { 6200, 8000, 9700, 11600 },
439 [max20730
] = { 13000, 16600, 20100, 23600 },
440 [max20734
] = { 21000, 27000, 32000, 38000 },
441 [max20743
] = { 18900, 24100, 29200, 34100 },
444 static int max20730_read_word_data(struct i2c_client
*client
, int page
,
447 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
448 const struct max20730_data
*data
= to_max20730_data(info
);
453 case PMBUS_OT_FAULT_LIMIT
:
454 switch ((data
->mfr_devset1
>> 11) & 0x3) {
456 ret
= val_to_direct(150000, PSC_TEMPERATURE
, info
);
459 ret
= val_to_direct(130000, PSC_TEMPERATURE
, info
);
466 case PMBUS_IOUT_OC_FAULT_LIMIT
:
467 max_c
= max_current
[data
->id
][(data
->mfr_devset1
>> 5) & 0x3];
468 ret
= val_to_direct(max_c
, PSC_CURRENT_OUT
, info
);
470 case PMBUS_READ_VOUT
:
471 ret
= pmbus_read_word_data(client
, page
, phase
, reg
);
472 if (ret
> 0 && data
->vout_voltage_divider
[0] && data
->vout_voltage_divider
[1]) {
473 u64 temp
= DIV_ROUND_CLOSEST_ULL((u64
)ret
* data
->vout_voltage_divider
[1],
474 data
->vout_voltage_divider
[0]);
475 ret
= clamp_val(temp
, 0, 0xffff);
485 static int max20730_write_word_data(struct i2c_client
*client
, int page
,
488 struct pmbus_driver_info
*info
;
489 struct max20730_data
*data
;
494 info
= (struct pmbus_driver_info
*)pmbus_get_driver_info(client
);
495 data
= to_max20730_data(info
);
497 mutex_lock(&data
->lock
);
498 devset1
= data
->mfr_devset1
;
501 case PMBUS_OT_FAULT_LIMIT
:
502 devset1
&= ~(BIT(11) | BIT(12));
503 if (direct_to_val(word
, PSC_TEMPERATURE
, info
) < 140000)
506 case PMBUS_IOUT_OC_FAULT_LIMIT
:
507 devset1
&= ~(BIT(5) | BIT(6));
509 idx
= find_closest(direct_to_val(word
, PSC_CURRENT_OUT
, info
),
510 max_current
[data
->id
], 4);
511 devset1
|= (idx
<< 5);
518 if (!ret
&& devset1
!= data
->mfr_devset1
) {
519 ret
= i2c_smbus_write_word_data(client
, MAX20730_MFR_DEVSET1
,
522 data
->mfr_devset1
= devset1
;
523 pmbus_clear_cache(client
);
526 mutex_unlock(&data
->lock
);
530 static const struct pmbus_driver_info max20730_info
[] = {
533 .read_word_data
= max20730_read_word_data
,
534 .write_word_data
= max20730_write_word_data
,
536 /* Source : Maxim AN6140 and AN6042 */
537 .format
[PSC_TEMPERATURE
] = direct
,
538 .m
[PSC_TEMPERATURE
] = 21,
539 .b
[PSC_TEMPERATURE
] = 5887,
540 .R
[PSC_TEMPERATURE
] = -1,
542 .format
[PSC_VOLTAGE_IN
] = direct
,
543 .m
[PSC_VOLTAGE_IN
] = 3609,
544 .b
[PSC_VOLTAGE_IN
] = 0,
545 .R
[PSC_VOLTAGE_IN
] = -2,
547 .format
[PSC_CURRENT_OUT
] = direct
,
548 .m
[PSC_CURRENT_OUT
] = 153,
549 .b
[PSC_CURRENT_OUT
] = 4976,
550 .R
[PSC_CURRENT_OUT
] = -1,
552 .format
[PSC_VOLTAGE_OUT
] = linear
,
554 .func
[0] = PMBUS_HAVE_VIN
|
555 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
556 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
557 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
558 PMBUS_HAVE_STATUS_INPUT
,
562 .read_word_data
= max20730_read_word_data
,
563 .write_word_data
= max20730_write_word_data
,
565 /* Source : Maxim AN6042 */
566 .format
[PSC_TEMPERATURE
] = direct
,
567 .m
[PSC_TEMPERATURE
] = 21,
568 .b
[PSC_TEMPERATURE
] = 5887,
569 .R
[PSC_TEMPERATURE
] = -1,
571 .format
[PSC_VOLTAGE_IN
] = direct
,
572 .m
[PSC_VOLTAGE_IN
] = 3609,
573 .b
[PSC_VOLTAGE_IN
] = 0,
574 .R
[PSC_VOLTAGE_IN
] = -2,
577 * Values in the datasheet are adjusted for temperature and
578 * for the relationship between Vin and Vout.
579 * Unfortunately, the data sheet suggests that Vout measurement
580 * may be scaled with a resistor array. This is indeed the case
581 * at least on the evaulation boards. As a result, any in-driver
582 * adjustments would either be wrong or require elaborate means
583 * to configure the scaling. Instead of doing that, just report
584 * raw values and let userspace handle adjustments.
586 .format
[PSC_CURRENT_OUT
] = direct
,
587 .m
[PSC_CURRENT_OUT
] = 153,
588 .b
[PSC_CURRENT_OUT
] = 4976,
589 .R
[PSC_CURRENT_OUT
] = -1,
591 .format
[PSC_VOLTAGE_OUT
] = linear
,
593 .func
[0] = PMBUS_HAVE_VIN
|
594 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
595 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
596 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
597 PMBUS_HAVE_STATUS_INPUT
,
601 .read_word_data
= max20730_read_word_data
,
602 .write_word_data
= max20730_write_word_data
,
604 /* Source : Maxim AN6209 */
605 .format
[PSC_TEMPERATURE
] = direct
,
606 .m
[PSC_TEMPERATURE
] = 21,
607 .b
[PSC_TEMPERATURE
] = 5887,
608 .R
[PSC_TEMPERATURE
] = -1,
610 .format
[PSC_VOLTAGE_IN
] = direct
,
611 .m
[PSC_VOLTAGE_IN
] = 3592,
612 .b
[PSC_VOLTAGE_IN
] = 0,
613 .R
[PSC_VOLTAGE_IN
] = -2,
615 .format
[PSC_CURRENT_OUT
] = direct
,
616 .m
[PSC_CURRENT_OUT
] = 111,
617 .b
[PSC_CURRENT_OUT
] = 3461,
618 .R
[PSC_CURRENT_OUT
] = -1,
620 .format
[PSC_VOLTAGE_OUT
] = linear
,
622 .func
[0] = PMBUS_HAVE_VIN
|
623 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
624 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
625 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
626 PMBUS_HAVE_STATUS_INPUT
,
630 .read_word_data
= max20730_read_word_data
,
631 .write_word_data
= max20730_write_word_data
,
633 /* Source : Maxim AN6042 */
634 .format
[PSC_TEMPERATURE
] = direct
,
635 .m
[PSC_TEMPERATURE
] = 21,
636 .b
[PSC_TEMPERATURE
] = 5887,
637 .R
[PSC_TEMPERATURE
] = -1,
639 .format
[PSC_VOLTAGE_IN
] = direct
,
640 .m
[PSC_VOLTAGE_IN
] = 3597,
641 .b
[PSC_VOLTAGE_IN
] = 0,
642 .R
[PSC_VOLTAGE_IN
] = -2,
644 .format
[PSC_CURRENT_OUT
] = direct
,
645 .m
[PSC_CURRENT_OUT
] = 95,
646 .b
[PSC_CURRENT_OUT
] = 5014,
647 .R
[PSC_CURRENT_OUT
] = -1,
649 .format
[PSC_VOLTAGE_OUT
] = linear
,
651 .func
[0] = PMBUS_HAVE_VIN
|
652 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
653 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
654 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
655 PMBUS_HAVE_STATUS_INPUT
,
659 static int max20730_probe(struct i2c_client
*client
)
661 struct device
*dev
= &client
->dev
;
662 u8 buf
[I2C_SMBUS_BLOCK_MAX
+ 1];
663 struct max20730_data
*data
;
667 if (!i2c_check_functionality(client
->adapter
,
668 I2C_FUNC_SMBUS_READ_BYTE_DATA
|
669 I2C_FUNC_SMBUS_READ_WORD_DATA
|
670 I2C_FUNC_SMBUS_BLOCK_DATA
))
673 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_ID
, buf
);
675 dev_err(&client
->dev
, "Failed to read Manufacturer ID\n");
678 if (ret
!= 5 || strncmp(buf
, "MAXIM", 5)) {
680 dev_err(dev
, "Unsupported Manufacturer ID '%s'\n", buf
);
685 * The chips support reading PMBUS_MFR_MODEL. On both MAX20730
686 * and MAX20734, reading it returns M20743. Presumably that is
687 * the reason why the command is not documented. Unfortunately,
688 * that means that there is no reliable means to detect the chip.
689 * However, we can at least detect the chip series. Compare
690 * the returned value against 'M20743' and bail out if there is
691 * a mismatch. If that doesn't work for all chips, we may have
692 * to remove this check.
694 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_MODEL
, buf
);
696 dev_err(dev
, "Failed to read Manufacturer Model\n");
699 if (ret
!= 6 || strncmp(buf
, "M20743", 6)) {
701 dev_err(dev
, "Unsupported Manufacturer Model '%s'\n", buf
);
705 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_REVISION
, buf
);
707 dev_err(dev
, "Failed to read Manufacturer Revision\n");
710 if (ret
!= 1 || buf
[0] != 'F') {
712 dev_err(dev
, "Unsupported Manufacturer Revision '%s'\n", buf
);
716 if (client
->dev
.of_node
)
717 chip_id
= (enum chips
)of_device_get_match_data(dev
);
719 chip_id
= i2c_match_id(max20730_id
, client
)->driver_data
;
721 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
725 mutex_init(&data
->lock
);
726 memcpy(&data
->info
, &max20730_info
[chip_id
], sizeof(data
->info
));
727 if (of_property_read_u32_array(client
->dev
.of_node
, "vout-voltage-divider",
728 data
->vout_voltage_divider
,
729 ARRAY_SIZE(data
->vout_voltage_divider
)) != 0)
730 memset(data
->vout_voltage_divider
, 0, sizeof(data
->vout_voltage_divider
));
731 if (data
->vout_voltage_divider
[1] < data
->vout_voltage_divider
[0]) {
733 "The total resistance of voltage divider is less than output resistance\n");
737 ret
= i2c_smbus_read_word_data(client
, MAX20730_MFR_DEVSET1
);
740 data
->mfr_devset1
= ret
;
742 ret
= pmbus_do_probe(client
, &data
->info
);
746 ret
= max20730_init_debugfs(client
, data
);
748 dev_warn(dev
, "Failed to register debugfs: %d\n",
754 static const struct i2c_device_id max20730_id
[] = {
755 { "max20710", max20710
},
756 { "max20730", max20730
},
757 { "max20734", max20734
},
758 { "max20743", max20743
},
762 MODULE_DEVICE_TABLE(i2c
, max20730_id
);
764 static const struct of_device_id max20730_of_match
[] = {
765 { .compatible
= "maxim,max20710", .data
= (void *)max20710
},
766 { .compatible
= "maxim,max20730", .data
= (void *)max20730
},
767 { .compatible
= "maxim,max20734", .data
= (void *)max20734
},
768 { .compatible
= "maxim,max20743", .data
= (void *)max20743
},
772 MODULE_DEVICE_TABLE(of
, max20730_of_match
);
774 static struct i2c_driver max20730_driver
= {
777 .of_match_table
= max20730_of_match
,
779 .probe_new
= max20730_probe
,
780 .id_table
= max20730_id
,
783 module_i2c_driver(max20730_driver
);
785 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
786 MODULE_DESCRIPTION("PMBus driver for Maxim MAX20710 / MAX20730 / MAX20734 / MAX20743");
787 MODULE_LICENSE("GPL");