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>
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 };
120 info
= pmbus_get_driver_info(psu
->client
);
121 data
= to_max20730_data(info
);
124 case MAX20730_DEBUGFS_VOUT_MIN
:
125 ret
= VOLT_FROM_REG(data
->mfr_voutmin
* 10000);
126 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d.%d\n",
127 ret
/ 10000, ret
% 10000);
129 case MAX20730_DEBUGFS_FREQUENCY
:
130 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_FSW_MASK
)
131 >> MAX20730_MFR_DEVSET1_FSW_BIT_POS
;
137 else if (val
== 2 || val
== 3)
145 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
147 case MAX20730_DEBUGFS_PG_DELAY
:
148 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_TSTAT_MASK
)
149 >> MAX20730_MFR_DEVSET1_TSTAT_BIT_POS
;
160 case MAX20730_DEBUGFS_INTERNAL_GAIN
:
161 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_RGAIN_MASK
)
162 >> MAX20730_MFR_DEVSET1_RGAIN_BIT_POS
;
164 if (data
->id
== max20734
) {
174 } else if (data
->id
== max20730
|| data
->id
== max20710
) {
175 /* AN6042 or AN6140 */
184 } else if (data
->id
== max20743
) {
195 result
= "Not supported\n";
198 case MAX20730_DEBUGFS_BOOT_VOLTAGE
:
199 val
= (data
->mfr_devset1
& MAX20730_MFR_DEVSET1_VBOOT_MASK
)
200 >> MAX20730_MFR_DEVSET1_VBOOT_BIT_POS
;
209 result
= "Invalid\n";
211 case MAX20730_DEBUGFS_OUT_V_RAMP_RATE
:
212 val
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_VRATE
)
213 >> MAX20730_MFR_DEVSET2_VRATE_BIT_POS
;
222 result
= "Invalid\n";
224 case MAX20730_DEBUGFS_OC_PROTECT_MODE
:
225 ret
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_OCPM_MASK
)
226 >> MAX20730_MFR_DEVSET2_OCPM_BIT_POS
;
227 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
229 case MAX20730_DEBUGFS_SS_TIMING
:
230 val
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_SS_MASK
)
231 >> MAX20730_MFR_DEVSET2_SS_BIT_POS
;
242 case MAX20730_DEBUGFS_IMAX
:
243 ret
= (data
->mfr_devset2
& MAX20730_MFR_DEVSET2_IMAX_MASK
)
244 >> MAX20730_MFR_DEVSET2_IMAX_BIT_POS
;
245 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
247 case MAX20730_DEBUGFS_OPERATION
:
248 ret
= i2c_smbus_read_byte_data(psu
->client
, PMBUS_OPERATION
);
251 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
253 case MAX20730_DEBUGFS_ON_OFF_CONFIG
:
254 ret
= i2c_smbus_read_byte_data(psu
->client
, PMBUS_ON_OFF_CONFIG
);
257 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
259 case MAX20730_DEBUGFS_SMBALERT_MASK
:
260 ret
= i2c_smbus_read_word_data(psu
->client
,
261 PMBUS_SMB_ALERT_MASK
);
264 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
266 case MAX20730_DEBUGFS_VOUT_MODE
:
267 ret
= i2c_smbus_read_byte_data(psu
->client
, PMBUS_VOUT_MODE
);
270 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
, "%d\n", ret
);
272 case MAX20730_DEBUGFS_VOUT_COMMAND
:
273 ret
= i2c_smbus_read_word_data(psu
->client
, PMBUS_VOUT_COMMAND
);
277 ret
= VOLT_FROM_REG(ret
* 10000);
278 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
,
279 "%d.%d\n", ret
/ 10000, ret
% 10000);
281 case MAX20730_DEBUGFS_VOUT_MAX
:
282 ret
= i2c_smbus_read_word_data(psu
->client
, PMBUS_VOUT_MAX
);
286 ret
= VOLT_FROM_REG(ret
* 10000);
287 len
= scnprintf(tbuf
, DEBUG_FS_DATA_MAX
,
288 "%d.%d\n", ret
/ 10000, ret
% 10000);
291 result
= "Invalid\n";
294 len
= strlen(result
);
295 return simple_read_from_buffer(buf
, count
, ppos
, result
, len
);
298 static const struct file_operations max20730_fops
= {
299 .llseek
= noop_llseek
,
300 .read
= max20730_debugfs_read
,
305 static int max20730_init_debugfs(struct i2c_client
*client
,
306 struct max20730_data
*data
)
309 struct dentry
*debugfs
;
310 struct dentry
*max20730_dir
;
311 struct max20730_debugfs_data
*psu
;
313 ret
= i2c_smbus_read_word_data(client
, MAX20730_MFR_DEVSET2
);
316 data
->mfr_devset2
= ret
;
318 ret
= i2c_smbus_read_word_data(client
, MAX20730_MFR_VOUT_MIN
);
321 data
->mfr_voutmin
= ret
;
323 psu
= devm_kzalloc(&client
->dev
, sizeof(*psu
), GFP_KERNEL
);
326 psu
->client
= client
;
328 debugfs
= pmbus_get_debugfs_dir(client
);
332 max20730_dir
= debugfs_create_dir(client
->name
, debugfs
);
334 for (i
= 0; i
< MAX20730_DEBUGFS_NUM_ENTRIES
; ++i
)
335 psu
->debugfs_entries
[i
] = i
;
337 debugfs_create_file("vout_min", 0444, max20730_dir
,
338 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_MIN
],
340 debugfs_create_file("frequency", 0444, max20730_dir
,
341 &psu
->debugfs_entries
[MAX20730_DEBUGFS_FREQUENCY
],
343 debugfs_create_file("power_good_delay", 0444, max20730_dir
,
344 &psu
->debugfs_entries
[MAX20730_DEBUGFS_PG_DELAY
],
346 debugfs_create_file("internal_gain", 0444, max20730_dir
,
347 &psu
->debugfs_entries
[MAX20730_DEBUGFS_INTERNAL_GAIN
],
349 debugfs_create_file("boot_voltage", 0444, max20730_dir
,
350 &psu
->debugfs_entries
[MAX20730_DEBUGFS_BOOT_VOLTAGE
],
352 debugfs_create_file("out_voltage_ramp_rate", 0444, max20730_dir
,
353 &psu
->debugfs_entries
[MAX20730_DEBUGFS_OUT_V_RAMP_RATE
],
355 debugfs_create_file("oc_protection_mode", 0444, max20730_dir
,
356 &psu
->debugfs_entries
[MAX20730_DEBUGFS_OC_PROTECT_MODE
],
358 debugfs_create_file("soft_start_timing", 0444, max20730_dir
,
359 &psu
->debugfs_entries
[MAX20730_DEBUGFS_SS_TIMING
],
361 debugfs_create_file("imax", 0444, max20730_dir
,
362 &psu
->debugfs_entries
[MAX20730_DEBUGFS_IMAX
],
364 debugfs_create_file("operation", 0444, max20730_dir
,
365 &psu
->debugfs_entries
[MAX20730_DEBUGFS_OPERATION
],
367 debugfs_create_file("on_off_config", 0444, max20730_dir
,
368 &psu
->debugfs_entries
[MAX20730_DEBUGFS_ON_OFF_CONFIG
],
370 debugfs_create_file("smbalert_mask", 0444, max20730_dir
,
371 &psu
->debugfs_entries
[MAX20730_DEBUGFS_SMBALERT_MASK
],
373 debugfs_create_file("vout_mode", 0444, max20730_dir
,
374 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_MODE
],
376 debugfs_create_file("vout_command", 0444, max20730_dir
,
377 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_COMMAND
],
379 debugfs_create_file("vout_max", 0444, max20730_dir
,
380 &psu
->debugfs_entries
[MAX20730_DEBUGFS_VOUT_MAX
],
386 static int max20730_init_debugfs(struct i2c_client
*client
,
387 struct max20730_data
*data
)
391 #endif /* CONFIG_DEBUG_FS */
393 static const struct i2c_device_id max20730_id
[];
396 * Convert discreet value to direct data format. Strictly speaking, all passed
397 * values are constants, so we could do that calculation manually. On the
398 * downside, that would make the driver more difficult to maintain, so lets
401 static u16
val_to_direct(int v
, enum pmbus_sensor_classes
class,
402 const struct pmbus_driver_info
*info
)
404 int R
= info
->R
[class] - 3; /* take milli-units into account */
405 int b
= info
->b
[class] * 1000;
408 d
= v
* info
->m
[class] + b
;
410 * R < 0 is true for all callers, so we don't need to bother
411 * about the R > 0 case.
414 d
= DIV_ROUND_CLOSEST(d
, 10);
420 static long direct_to_val(u16 w
, enum pmbus_sensor_classes
class,
421 const struct pmbus_driver_info
*info
)
423 int R
= info
->R
[class] - 3;
424 int b
= info
->b
[class] * 1000;
425 int m
= info
->m
[class];
439 static u32 max_current
[][5] = {
440 [max20710
] = { 6200, 8000, 9700, 11600 },
441 [max20730
] = { 13000, 16600, 20100, 23600 },
442 [max20734
] = { 21000, 27000, 32000, 38000 },
443 [max20743
] = { 18900, 24100, 29200, 34100 },
446 static int max20730_read_word_data(struct i2c_client
*client
, int page
,
449 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
450 const struct max20730_data
*data
= to_max20730_data(info
);
455 case PMBUS_OT_FAULT_LIMIT
:
456 switch ((data
->mfr_devset1
>> 11) & 0x3) {
458 ret
= val_to_direct(150000, PSC_TEMPERATURE
, info
);
461 ret
= val_to_direct(130000, PSC_TEMPERATURE
, info
);
468 case PMBUS_IOUT_OC_FAULT_LIMIT
:
469 max_c
= max_current
[data
->id
][(data
->mfr_devset1
>> 5) & 0x3];
470 ret
= val_to_direct(max_c
, PSC_CURRENT_OUT
, info
);
472 case PMBUS_READ_VOUT
:
473 ret
= pmbus_read_word_data(client
, page
, phase
, reg
);
474 if (ret
> 0 && data
->vout_voltage_divider
[0] && data
->vout_voltage_divider
[1]) {
475 u64 temp
= DIV_ROUND_CLOSEST_ULL((u64
)ret
* data
->vout_voltage_divider
[1],
476 data
->vout_voltage_divider
[0]);
477 ret
= clamp_val(temp
, 0, 0xffff);
487 static int max20730_write_word_data(struct i2c_client
*client
, int page
,
490 struct pmbus_driver_info
*info
;
491 struct max20730_data
*data
;
496 info
= (struct pmbus_driver_info
*)pmbus_get_driver_info(client
);
497 data
= to_max20730_data(info
);
499 mutex_lock(&data
->lock
);
500 devset1
= data
->mfr_devset1
;
503 case PMBUS_OT_FAULT_LIMIT
:
504 devset1
&= ~(BIT(11) | BIT(12));
505 if (direct_to_val(word
, PSC_TEMPERATURE
, info
) < 140000)
508 case PMBUS_IOUT_OC_FAULT_LIMIT
:
509 devset1
&= ~(BIT(5) | BIT(6));
511 idx
= find_closest(direct_to_val(word
, PSC_CURRENT_OUT
, info
),
512 max_current
[data
->id
], 4);
513 devset1
|= (idx
<< 5);
520 if (!ret
&& devset1
!= data
->mfr_devset1
) {
521 ret
= i2c_smbus_write_word_data(client
, MAX20730_MFR_DEVSET1
,
524 data
->mfr_devset1
= devset1
;
525 pmbus_clear_cache(client
);
528 mutex_unlock(&data
->lock
);
532 static const struct pmbus_driver_info max20730_info
[] = {
535 .read_word_data
= max20730_read_word_data
,
536 .write_word_data
= max20730_write_word_data
,
538 /* Source : Maxim AN6140 and AN6042 */
539 .format
[PSC_TEMPERATURE
] = direct
,
540 .m
[PSC_TEMPERATURE
] = 21,
541 .b
[PSC_TEMPERATURE
] = 5887,
542 .R
[PSC_TEMPERATURE
] = -1,
544 .format
[PSC_VOLTAGE_IN
] = direct
,
545 .m
[PSC_VOLTAGE_IN
] = 3609,
546 .b
[PSC_VOLTAGE_IN
] = 0,
547 .R
[PSC_VOLTAGE_IN
] = -2,
549 .format
[PSC_CURRENT_OUT
] = direct
,
550 .m
[PSC_CURRENT_OUT
] = 153,
551 .b
[PSC_CURRENT_OUT
] = 4976,
552 .R
[PSC_CURRENT_OUT
] = -1,
554 .format
[PSC_VOLTAGE_OUT
] = linear
,
556 .func
[0] = PMBUS_HAVE_VIN
|
557 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
558 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
559 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
560 PMBUS_HAVE_STATUS_INPUT
,
564 .read_word_data
= max20730_read_word_data
,
565 .write_word_data
= max20730_write_word_data
,
567 /* Source : Maxim AN6042 */
568 .format
[PSC_TEMPERATURE
] = direct
,
569 .m
[PSC_TEMPERATURE
] = 21,
570 .b
[PSC_TEMPERATURE
] = 5887,
571 .R
[PSC_TEMPERATURE
] = -1,
573 .format
[PSC_VOLTAGE_IN
] = direct
,
574 .m
[PSC_VOLTAGE_IN
] = 3609,
575 .b
[PSC_VOLTAGE_IN
] = 0,
576 .R
[PSC_VOLTAGE_IN
] = -2,
579 * Values in the datasheet are adjusted for temperature and
580 * for the relationship between Vin and Vout.
581 * Unfortunately, the data sheet suggests that Vout measurement
582 * may be scaled with a resistor array. This is indeed the case
583 * at least on the evaulation boards. As a result, any in-driver
584 * adjustments would either be wrong or require elaborate means
585 * to configure the scaling. Instead of doing that, just report
586 * raw values and let userspace handle adjustments.
588 .format
[PSC_CURRENT_OUT
] = direct
,
589 .m
[PSC_CURRENT_OUT
] = 153,
590 .b
[PSC_CURRENT_OUT
] = 4976,
591 .R
[PSC_CURRENT_OUT
] = -1,
593 .format
[PSC_VOLTAGE_OUT
] = linear
,
595 .func
[0] = PMBUS_HAVE_VIN
|
596 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
597 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
598 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
599 PMBUS_HAVE_STATUS_INPUT
,
603 .read_word_data
= max20730_read_word_data
,
604 .write_word_data
= max20730_write_word_data
,
606 /* Source : Maxim AN6209 */
607 .format
[PSC_TEMPERATURE
] = direct
,
608 .m
[PSC_TEMPERATURE
] = 21,
609 .b
[PSC_TEMPERATURE
] = 5887,
610 .R
[PSC_TEMPERATURE
] = -1,
612 .format
[PSC_VOLTAGE_IN
] = direct
,
613 .m
[PSC_VOLTAGE_IN
] = 3592,
614 .b
[PSC_VOLTAGE_IN
] = 0,
615 .R
[PSC_VOLTAGE_IN
] = -2,
617 .format
[PSC_CURRENT_OUT
] = direct
,
618 .m
[PSC_CURRENT_OUT
] = 111,
619 .b
[PSC_CURRENT_OUT
] = 3461,
620 .R
[PSC_CURRENT_OUT
] = -1,
622 .format
[PSC_VOLTAGE_OUT
] = linear
,
624 .func
[0] = PMBUS_HAVE_VIN
|
625 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
626 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
627 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
628 PMBUS_HAVE_STATUS_INPUT
,
632 .read_word_data
= max20730_read_word_data
,
633 .write_word_data
= max20730_write_word_data
,
635 /* Source : Maxim AN6042 */
636 .format
[PSC_TEMPERATURE
] = direct
,
637 .m
[PSC_TEMPERATURE
] = 21,
638 .b
[PSC_TEMPERATURE
] = 5887,
639 .R
[PSC_TEMPERATURE
] = -1,
641 .format
[PSC_VOLTAGE_IN
] = direct
,
642 .m
[PSC_VOLTAGE_IN
] = 3597,
643 .b
[PSC_VOLTAGE_IN
] = 0,
644 .R
[PSC_VOLTAGE_IN
] = -2,
646 .format
[PSC_CURRENT_OUT
] = direct
,
647 .m
[PSC_CURRENT_OUT
] = 95,
648 .b
[PSC_CURRENT_OUT
] = 5014,
649 .R
[PSC_CURRENT_OUT
] = -1,
651 .format
[PSC_VOLTAGE_OUT
] = linear
,
653 .func
[0] = PMBUS_HAVE_VIN
|
654 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
655 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
656 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
|
657 PMBUS_HAVE_STATUS_INPUT
,
661 static int max20730_probe(struct i2c_client
*client
)
663 struct device
*dev
= &client
->dev
;
664 u8 buf
[I2C_SMBUS_BLOCK_MAX
+ 1];
665 struct max20730_data
*data
;
669 if (!i2c_check_functionality(client
->adapter
,
670 I2C_FUNC_SMBUS_READ_BYTE_DATA
|
671 I2C_FUNC_SMBUS_READ_WORD_DATA
|
672 I2C_FUNC_SMBUS_BLOCK_DATA
))
675 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_ID
, buf
);
677 dev_err(&client
->dev
, "Failed to read Manufacturer ID\n");
680 if (ret
!= 5 || strncmp(buf
, "MAXIM", 5)) {
682 dev_err(dev
, "Unsupported Manufacturer ID '%s'\n", buf
);
687 * The chips support reading PMBUS_MFR_MODEL. On both MAX20730
688 * and MAX20734, reading it returns M20743. Presumably that is
689 * the reason why the command is not documented. Unfortunately,
690 * that means that there is no reliable means to detect the chip.
691 * However, we can at least detect the chip series. Compare
692 * the returned value against 'M20743' and bail out if there is
693 * a mismatch. If that doesn't work for all chips, we may have
694 * to remove this check.
696 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_MODEL
, buf
);
698 dev_err(dev
, "Failed to read Manufacturer Model\n");
701 if (ret
!= 6 || strncmp(buf
, "M20743", 6)) {
703 dev_err(dev
, "Unsupported Manufacturer Model '%s'\n", buf
);
707 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_REVISION
, buf
);
709 dev_err(dev
, "Failed to read Manufacturer Revision\n");
712 if (ret
!= 1 || buf
[0] != 'F') {
714 dev_err(dev
, "Unsupported Manufacturer Revision '%s'\n", buf
);
718 if (client
->dev
.of_node
)
719 chip_id
= (uintptr_t)of_device_get_match_data(dev
);
721 chip_id
= i2c_match_id(max20730_id
, client
)->driver_data
;
723 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
727 mutex_init(&data
->lock
);
728 memcpy(&data
->info
, &max20730_info
[chip_id
], sizeof(data
->info
));
729 if (of_property_read_u32_array(client
->dev
.of_node
, "vout-voltage-divider",
730 data
->vout_voltage_divider
,
731 ARRAY_SIZE(data
->vout_voltage_divider
)) != 0)
732 memset(data
->vout_voltage_divider
, 0, sizeof(data
->vout_voltage_divider
));
733 if (data
->vout_voltage_divider
[1] < data
->vout_voltage_divider
[0]) {
735 "The total resistance of voltage divider is less than output resistance\n");
739 ret
= i2c_smbus_read_word_data(client
, MAX20730_MFR_DEVSET1
);
742 data
->mfr_devset1
= ret
;
744 ret
= pmbus_do_probe(client
, &data
->info
);
748 ret
= max20730_init_debugfs(client
, data
);
750 dev_warn(dev
, "Failed to register debugfs: %d\n",
756 static const struct i2c_device_id max20730_id
[] = {
757 { "max20710", max20710
},
758 { "max20730", max20730
},
759 { "max20734", max20734
},
760 { "max20743", max20743
},
764 MODULE_DEVICE_TABLE(i2c
, max20730_id
);
766 static const struct of_device_id max20730_of_match
[] = {
767 { .compatible
= "maxim,max20710", .data
= (void *)max20710
},
768 { .compatible
= "maxim,max20730", .data
= (void *)max20730
},
769 { .compatible
= "maxim,max20734", .data
= (void *)max20734
},
770 { .compatible
= "maxim,max20743", .data
= (void *)max20743
},
774 MODULE_DEVICE_TABLE(of
, max20730_of_match
);
776 static struct i2c_driver max20730_driver
= {
779 .of_match_table
= max20730_of_match
,
781 .probe
= max20730_probe
,
782 .id_table
= max20730_id
,
785 module_i2c_driver(max20730_driver
);
787 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
788 MODULE_DESCRIPTION("PMBus driver for Maxim MAX20710 / MAX20730 / MAX20734 / MAX20743");
789 MODULE_LICENSE("GPL");
790 MODULE_IMPORT_NS("PMBUS");