mp2975.c (07749061b837a1268146dc8a620a522253cea877) mp2975.c (c7506a2b5a8233c32bd05353aac7c7b3af05d85f)
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/err.h>

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

387 return -ENXIO;
388 default:
389 return -ENODATA;
390 }
391
392 return ret;
393}
394
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/err.h>

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

387 return -ENXIO;
388 default:
389 return -ENODATA;
390 }
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;
399 int 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 */
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:
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);
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);
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);
449 break;
450 case PMBUS_STATUS_TEMPERATURE:
451 ret = SWAP(ret, mask, PB_TEMP_OT_FAULT, MP2973_TEMP_OT);
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);
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
395static int mp2975_read_word_data(struct i2c_client *client, int page,
396 int phase, int reg)
397{
398 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
399 struct mp2975_data *data = to_mp2975_data(info);
400 int ret;
401
402 switch (reg) {

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

902 .format[PSC_POWER] = linear,
903 .m[PSC_VOLTAGE_OUT] = 1,
904 .R[PSC_VOLTAGE_OUT] = 3,
905 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
906 PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
907 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT |
908 PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
909 .read_word_data = mp2973_read_word_data,
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);
475 struct mp2975_data *data = to_mp2975_data(info);
476 int ret;
477
478 switch (reg) {

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

978 .format[PSC_POWER] = linear,
979 .m[PSC_VOLTAGE_OUT] = 1,
980 .R[PSC_VOLTAGE_OUT] = 3,
981 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
982 PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
983 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT |
984 PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
985 .read_word_data = mp2973_read_word_data,
986 .write_word_data = mp2973_write_word_data,
910#if IS_ENABLED(CONFIG_SENSORS_MP2975_REGULATOR)
911 .num_regulators = 1,
912 .reg_desc = mp2975_reg_desc,
913#endif
914};
915
916static int mp2975_probe(struct i2c_client *client)
917{

--- 101 unchanged lines hidden ---
987#if IS_ENABLED(CONFIG_SENSORS_MP2975_REGULATOR)
988 .num_regulators = 1,
989 .reg_desc = mp2975_reg_desc,
990#endif
991};
992
993static int mp2975_probe(struct i2c_client *client)
994{

--- 101 unchanged lines hidden ---