/** * float_to_long - Convert ieee754 reading from hardware to an integer * * @data: Value read from the hardware * @precision: Units to multiply up to eg. 1000 = milli, 1000000 = micro * * Return: Converted integer reading * * Depending on the measurement type the hardware returns an ieee754 * floating point value in either volts, amps or celsius. This function * will convert that into an integer in a smaller unit such as micro-amps * or milli-celsius. The hardware does not return NaN, so consideration of * that is not required.
*/ staticlong float_to_long(u32 data, u32 precision)
{
u64 man = data & 0x007FFFFF; int exp = ((data & 0x7F800000) >> 23) - 127 - 23; bool negative = data & 0x80000000; long result;
man = (man + (1 << 23)) * precision;
if (fls64(man) + exp > (int)sizeof(long) * 8 - 1)
result = LONG_MAX; elseif (exp < 0)
result = (man + (1ull << (-exp - 1))) >> -exp; else
result = man << exp;
return negative ? -result : result;
}
staticint do_measurement(struct regmap *regmap, int chan, enum lochnagar_measure_mode mode, int nsamples)
{ unsignedint val; int ret;
ret = regmap_write(regmap, LOCHNAGAR2_IMON_CTRL1,
LOCHNAGAR2_IMON_ENA_MASK | chan | mode); if (ret < 0) return ret;
ret = regmap_write(regmap, LOCHNAGAR2_IMON_CTRL2, nsamples); if (ret < 0) return ret;
ret = regmap_write(regmap, LOCHNAGAR2_IMON_CTRL3,
LOCHNAGAR2_IMON_CONFIGURE_MASK); if (ret < 0) return ret;
ret = regmap_read_poll_timeout(regmap, LOCHNAGAR2_IMON_CTRL3, val,
val & LOCHNAGAR2_IMON_DONE_MASK, 1000, 10000); if (ret < 0) return ret;
ret = regmap_write(regmap, LOCHNAGAR2_IMON_CTRL3,
LOCHNAGAR2_IMON_MEASURE_MASK); if (ret < 0) return ret;
/* * Actual measurement time is ~1.67mS per sample, approximate this * with a 1.5mS per sample msleep and then poll for success up to * ~0.17mS * 1023 (LN2_MAX_NSAMPLES). Normally for smaller values * of nsamples the poll will complete on the first loop due to * other latency in the system.
*/
msleep((nsamples * 3) / 2);
ret = regmap_read_poll_timeout(regmap, LOCHNAGAR2_IMON_CTRL3, val,
val & LOCHNAGAR2_IMON_DONE_MASK, 5000, 200000); if (ret < 0) return ret;
¤ 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.0.22Bemerkung:
(vorverarbeitet am 2026-06-07)
¤
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.