mp2975.c (c7506a2b5a8233c32bd05353aac7c7b3af05d85f) mp2975.c (d2bc4a994a1eb34cf35615af86445d105f419192)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers
4 *
5 * Copyright (C) 2020 Nvidia Technologies Ltd.
6 */
7
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers
4 *
5 * Copyright (C) 2020 Nvidia Technologies Ltd.
6 */
7
8#include <linux/bitops.h>
8#include <linux/err.h>
9#include <linux/i2c.h>
10#include <linux/init.h>
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/of_device.h>
14#include "pmbus.h"
15

--- 375 unchanged lines hidden (view full) ---

391
392 return ret;
393}
394
395static int mp2973_write_word_data(struct i2c_client *client, int page,
396 int reg, u16 word)
397{
398 u8 target, mask;
9#include <linux/err.h>
10#include <linux/i2c.h>
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/of_device.h>
15#include "pmbus.h"
16

--- 375 unchanged lines hidden (view full) ---

392
393 return ret;
394}
395
396static int mp2973_write_word_data(struct i2c_client *client, int page,
397 int reg, u16 word)
398{
399 u8 target, mask;
399 int ret;
400 long ret;
400
401 if (reg != PMBUS_SMBALERT_MASK)
402 return -ENODATA;
403
404 /*
405 * Vendor-specific SMBALERT_MASK register with 16 maskable bits.
406 */
407 ret = pmbus_read_word_data(client, 0, 0, PMBUS_SMBALERT_MASK);
408 if (ret < 0)
409 return ret;
410
411 target = word & 0xff;
412 mask = word >> 8;
413
414/*
415 * Set/Clear 'bit' in 'ret' based on condition followed by define for each bit in SMBALERT_MASK.
416 * Also bit 2 & 15 are reserved.
417 */
401
402 if (reg != PMBUS_SMBALERT_MASK)
403 return -ENODATA;
404
405 /*
406 * Vendor-specific SMBALERT_MASK register with 16 maskable bits.
407 */
408 ret = pmbus_read_word_data(client, 0, 0, PMBUS_SMBALERT_MASK);
409 if (ret < 0)
410 return ret;
411
412 target = word & 0xff;
413 mask = word >> 8;
414
415/*
416 * Set/Clear 'bit' in 'ret' based on condition followed by define for each bit in SMBALERT_MASK.
417 * Also bit 2 & 15 are reserved.
418 */
418#define SWAP(val, mask, cond, bit) (((mask) & (cond)) ? ((val) & ~BIT(bit)) : ((val) | BIT(bit)))
419
420#define MP2973_TEMP_OT 0
421#define MP2973_VIN_UVLO 1
422#define MP2973_VIN_OVP 3
423#define MP2973_MTP_FAULT 4
424#define MP2973_OTHER_COMM 5
425#define MP2973_MTP_BLK_TRIG 6
426#define MP2973_PACKET_ERROR 7
427#define MP2973_INVALID_DATA 8
428#define MP2973_INVALID_COMMAND 9
429#define MP2973_IOUT_OC_LV 10
430#define MP2973_IOUT_OC 11
431#define MP2973_VOUT_MAX_MIN_WARNING 12
432#define MP2973_VOLTAGE_UV 13
433#define MP2973_VOLTAGE_OV 14
434
435 switch (target) {
436 case PMBUS_STATUS_CML:
419
420#define MP2973_TEMP_OT 0
421#define MP2973_VIN_UVLO 1
422#define MP2973_VIN_OVP 3
423#define MP2973_MTP_FAULT 4
424#define MP2973_OTHER_COMM 5
425#define MP2973_MTP_BLK_TRIG 6
426#define MP2973_PACKET_ERROR 7
427#define MP2973_INVALID_DATA 8
428#define MP2973_INVALID_COMMAND 9
429#define MP2973_IOUT_OC_LV 10
430#define MP2973_IOUT_OC 11
431#define MP2973_VOUT_MAX_MIN_WARNING 12
432#define MP2973_VOLTAGE_UV 13
433#define MP2973_VOLTAGE_OV 14
434
435 switch (target) {
436 case PMBUS_STATUS_CML:
437 ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_DATA, MP2973_INVALID_DATA);
438 ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_COMMAND, MP2973_INVALID_COMMAND);
439 ret = SWAP(ret, mask, PB_CML_FAULT_OTHER_COMM, MP2973_OTHER_COMM);
440 ret = SWAP(ret, mask, PB_CML_FAULT_PACKET_ERROR, MP2973_PACKET_ERROR);
437 __assign_bit(MP2973_INVALID_DATA, &ret, !(mask & PB_CML_FAULT_INVALID_DATA));
438 __assign_bit(MP2973_INVALID_COMMAND, &ret, !(mask & PB_CML_FAULT_INVALID_COMMAND));
439 __assign_bit(MP2973_OTHER_COMM, &ret, !(mask & PB_CML_FAULT_OTHER_COMM));
440 __assign_bit(MP2973_PACKET_ERROR, &ret, !(mask & PB_CML_FAULT_PACKET_ERROR));
441 break;
442 case PMBUS_STATUS_VOUT:
441 break;
442 case PMBUS_STATUS_VOUT:
443 ret = SWAP(ret, mask, PB_VOLTAGE_UV_FAULT, MP2973_VOLTAGE_UV);
444 ret = SWAP(ret, mask, PB_VOLTAGE_OV_FAULT, MP2973_VOLTAGE_OV);
443 __assign_bit(MP2973_VOLTAGE_UV, &ret, !(mask & PB_VOLTAGE_UV_FAULT));
444 __assign_bit(MP2973_VOLTAGE_OV, &ret, !(mask & PB_VOLTAGE_OV_FAULT));
445 break;
446 case PMBUS_STATUS_IOUT:
445 break;
446 case PMBUS_STATUS_IOUT:
447 ret = SWAP(ret, mask, PB_IOUT_OC_FAULT, MP2973_IOUT_OC);
448 ret = SWAP(ret, mask, PB_IOUT_OC_LV_FAULT, MP2973_IOUT_OC_LV);
447 __assign_bit(MP2973_IOUT_OC, &ret, !(mask & PB_IOUT_OC_FAULT));
448 __assign_bit(MP2973_IOUT_OC_LV, &ret, !(mask & PB_IOUT_OC_LV_FAULT));
449 break;
450 case PMBUS_STATUS_TEMPERATURE:
449 break;
450 case PMBUS_STATUS_TEMPERATURE:
451 ret = SWAP(ret, mask, PB_TEMP_OT_FAULT, MP2973_TEMP_OT);
451 __assign_bit(MP2973_TEMP_OT, &ret, !(mask & PB_TEMP_OT_FAULT));
452 break;
453 /*
454 * Map remaining bits to MFR specific to let the PMBUS core mask
455 * those bits by default.
456 */
457 case PMBUS_STATUS_MFR_SPECIFIC:
452 break;
453 /*
454 * Map remaining bits to MFR specific to let the PMBUS core mask
455 * those bits by default.
456 */
457 case PMBUS_STATUS_MFR_SPECIFIC:
458 ret = SWAP(ret, mask, BIT(1), MP2973_VIN_UVLO);
459 ret = SWAP(ret, mask, BIT(3), MP2973_VIN_OVP);
460 ret = SWAP(ret, mask, BIT(4), MP2973_MTP_FAULT);
461 ret = SWAP(ret, mask, BIT(6), MP2973_MTP_BLK_TRIG);
458 __assign_bit(MP2973_VIN_UVLO, &ret, !(mask & BIT(1)));
459 __assign_bit(MP2973_VIN_OVP, &ret, !(mask & BIT(3)));
460 __assign_bit(MP2973_MTP_FAULT, &ret, !(mask & BIT(4)));
461 __assign_bit(MP2973_MTP_BLK_TRIG, &ret, !(mask & BIT(6)));
462 break;
463 default:
464 return 0;
465 }
462 break;
463 default:
464 return 0;
465 }
466#undef SWAP
467
468 return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret);
469}
470
471static int mp2975_read_word_data(struct i2c_client *client, int page,
472 int phase, int reg)
473{
474 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);

--- 621 unchanged lines hidden ---
466
467 return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret);
468}
469
470static int mp2975_read_word_data(struct i2c_client *client, int page,
471 int phase, int reg)
472{
473 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);

--- 621 unchanged lines hidden ---