// SPDX-License-Identifier: GPL-2.0-or-later /* * Hardware monitoring driver for the STPDDC60 controller * * Copyright (c) 2021 Flextronics International Sweden AB.
*/
/* * Calculate the closest absolute offset between commanded vout value * and limit value in steps of 50mv in the range 0 (50mv) to 7 (400mv). * Return 0 if the upper limit is lower than vout or if the lower limit * is higher than vout.
*/ static u8 stpddc60_get_offset(int vout, u16 limit, bool over)
{ int offset; long v, l;
v = 250 + (vout - 1) * 5; /* Convert VID to mv */
l = (limit * 1000L) >> 8; /* Convert LINEAR to mv */
if (over == (l < v)) return 0;
offset = DIV_ROUND_CLOSEST(abs(l - v), 50);
if (offset > 0)
offset--;
return clamp_val(offset, 0, 7);
}
/* * Adjust the linear format word to use the given fixed exponent.
*/ static u16 stpddc60_adjust_linear(u16 word, s16 fixed)
{
s16 e, m, d;
e = ((s16)word) >> 11;
m = ((s16)((word & 0x7ff) << 5)) >> 5;
d = e - fixed;
/* * The VOUT_COMMAND register uses the VID format but the vout alarm limit * registers use the LINEAR format so we override VOUT_MODE here to force * LINEAR format for all registers.
*/ staticint stpddc60_read_byte_data(struct i2c_client *client, int page, int reg)
{ int ret;
if (page > 0) return -ENXIO;
switch (reg) { case PMBUS_VOUT_MODE:
ret = 0x18; break; default:
ret = -ENODATA; break;
}
return ret;
}
/* * The vout related registers return values in LINEAR11 format when LINEAR16 * is expected. Clear the top 5 bits to set the exponent part to zero to * convert the value to LINEAR16 format.
*/ staticint stpddc60_read_word_data(struct i2c_client *client, int page, int phase, int reg)
{ int ret;
if (page > 0) return -ENXIO;
switch (reg) { case PMBUS_READ_VOUT:
ret = pmbus_read_word_data(client, page, phase,
STPDDC60_MFR_READ_VOUT); if (ret < 0) return ret;
ret &= 0x7ff; break; case PMBUS_VOUT_OV_FAULT_LIMIT: case PMBUS_VOUT_UV_FAULT_LIMIT:
ret = pmbus_read_word_data(client, page, phase, reg); if (ret < 0) return ret;
ret &= 0x7ff; break; default:
ret = -ENODATA; break;
}
return ret;
}
/* * The vout under- and over-voltage limits are set as an offset relative to * the commanded vout voltage. The vin, iout, pout and temp limits must use * the same fixed exponent the chip uses to encode the data when read.
*/ staticint stpddc60_write_word_data(struct i2c_client *client, int page, int reg, u16 word)
{ int ret;
u8 offset;
if (page > 0) return -ENXIO;
switch (reg) { case PMBUS_VOUT_OV_FAULT_LIMIT:
ret = pmbus_read_word_data(client, page, 0xff,
PMBUS_VOUT_COMMAND); if (ret < 0) return ret;
offset = stpddc60_get_offset(ret, word, true);
ret = pmbus_write_byte_data(client, page,
STPDDC60_MFR_OV_LIMIT_OFFSET,
offset); break; case PMBUS_VOUT_UV_FAULT_LIMIT:
ret = pmbus_read_word_data(client, page, 0xff,
PMBUS_VOUT_COMMAND); if (ret < 0) return ret;
offset = stpddc60_get_offset(ret, word, false);
ret = pmbus_write_byte_data(client, page,
STPDDC60_MFR_UV_LIMIT_OFFSET,
offset); break; case PMBUS_VIN_OV_FAULT_LIMIT: case PMBUS_VIN_UV_FAULT_LIMIT: case PMBUS_OT_FAULT_LIMIT: case PMBUS_OT_WARN_LIMIT: case PMBUS_IOUT_OC_FAULT_LIMIT: case PMBUS_IOUT_OC_WARN_LIMIT: case PMBUS_POUT_OP_FAULT_LIMIT:
ret = pmbus_read_word_data(client, page, 0xff, reg); if (ret < 0) return ret;
word = stpddc60_adjust_linear(word, ret >> 11);
ret = pmbus_write_word_data(client, page, reg, word); break; default:
ret = -ENODATA; break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.