From: Titus Rwantare <titusr@google.com>
To: peter.maydell@linaro.org
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, kfting@nuvoton.com,
imaginos32@gmail.com, wuhaotsh@google.com, philmd@mailo.com,
Titus Rwantare <titusr@google.com>
Subject: [PATCH 5/5] hw/i2c: pmbus: add Linear11 format helpers
Date: Mon, 6 Jul 2026 23:00:54 +0000 [thread overview]
Message-ID: <20260706230056.1888992-6-titusr@google.com> (raw)
In-Reply-To: <20260706230056.1888992-1-titusr@google.com>
Signed-off-by: Titus Rwantare <titusr@google.com>
---
hw/i2c/pmbus_device.c | 12 +++++++++
include/hw/i2c/pmbus_device.h | 46 +++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c
index 8befc27895..5039975520 100644
--- a/hw/i2c/pmbus_device.c
+++ b/hw/i2c/pmbus_device.c
@@ -39,6 +39,12 @@ uint16_t pmbus_data2linear_mode(uint16_t value, int exp)
return value >> exp;
}
+uint16_t pmbus_data2linear11(uint16_t value, int exp)
+{
+ return (uint16_t)((exp & 0x1F) << 11 |
+ (pmbus_data2linear_mode(value, exp) & 0x7FF));
+}
+
uint16_t pmbus_milliunits2linear_mode(uint32_t value, int exp)
{
uint32_t ret;
@@ -58,6 +64,12 @@ uint16_t pmbus_milliunits2linear_mode(uint32_t value, int exp)
return ret;
}
+uint16_t pmbus_milliunits2linear11(uint32_t value, int exp)
+{
+ return (uint16_t)((exp & 0x1F) << 11 |
+ (pmbus_milliunits2linear_mode(value, exp) & 0x7FF));
+}
+
uint16_t pmbus_linear_mode2data(uint16_t value, int exp)
{
/* D = L * 2^e */
diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h
index 9f3569e997..44cd908fe7 100644
--- a/include/hw/i2c/pmbus_device.h
+++ b/include/hw/i2c/pmbus_device.h
@@ -477,10 +477,56 @@ uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value);
*
* L = D * 2^(-e)
*
+ * Exponent is retrieved from VOUT_MODE register
+ *
+ * 7 6 5 4 3 2 1 0
+ * +---+---+---+---+---+---+---+---+
+ * | 0 | 0 | 0 | N |
+ * +---+---+---+---+---+---+---+---+
+ * |_______| |_______________|
+ * Mode Exponent (N)
+ * = 000b
+ *
* @return uint16
*/
uint16_t pmbus_data2linear_mode(uint16_t value, int exp);
+/**
+ * Convert sensor values to linear11 format
+ *
+ * L = e << 11 | D * 2^(-e)
+ *
+ * | Data Byte High | Data Byte Low |
+ * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+
+ * | 7 | 6 | 5 | 4 | 3 | | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+
+ * | MSB | | MSB |
+ * |_________ _________| |_____________________ _____________________|
+ * N Y
+ * Exponent Mantissa
+ *
+ * @return uint16
+ */
+uint16_t pmbus_data2linear11(uint16_t value, int exp);
+
+/**
+ * Convert sensor values in milliunits to linear11 format
+ *
+ * L = e << 11 | D * 2^(-e)
+ *
+ * | Data Byte High | Data Byte Low |
+ * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+
+ * | 7 | 6 | 5 | 4 | 3 | | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+
+ * | MSB | | MSB |
+ * |_________ _________| |_____________________ _____________________|
+ * N Y
+ * Exponent Mantissa
+ *
+ * @return uint16
+ */
+uint16_t pmbus_milliunits2linear11(uint32_t value, int exp);
+
/**
* Convert milliunit sensor value to linear mode format
*
--
2.55.0.rc2.803.g1fd1e6609c-goog
next prev parent reply other threads:[~2026-07-06 23:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 23:00 [PATCH 0/5] hw/i2c: PMBus updates Titus Rwantare
2026-07-06 23:00 ` [PATCH 1/5] osdep: add DIV_ROUND_CLOSEST Titus Rwantare
2026-07-09 11:09 ` Peter Maydell
2026-07-09 11:16 ` Peter Maydell
2026-07-06 23:00 ` [PATCH 2/5] hw/i2c: pmbus: add milliunits linear mode functions Titus Rwantare
2026-07-06 23:00 ` [PATCH 3/5] hw/i2c: pmbus: clear output buffer on write Titus Rwantare
2026-07-07 9:20 ` Philippe Mathieu-Daudé
2026-07-09 15:35 ` Peter Maydell
2026-07-06 23:00 ` [PATCH 4/5] hw/i2c: smbus: increase MAX_DATA_LEN Titus Rwantare
2026-07-07 9:18 ` Philippe Mathieu-Daudé
2026-07-09 11:25 ` Peter Maydell
2026-07-06 23:00 ` Titus Rwantare [this message]
2026-07-09 11:14 ` [PATCH 5/5] hw/i2c: pmbus: add Linear11 format helpers Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260706230056.1888992-6-titusr@google.com \
--to=titusr@google.com \
--cc=imaginos32@gmail.com \
--cc=kfting@nuvoton.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@mailo.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=wuhaotsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.